You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2006/07/28 10:37:54 UTC
svn commit: r426435 - in /jackrabbit/trunk/contrib/backup/src:
main/java/org/apache/jackrabbit/backup/ test/ test/java/org/
test/java/org/apache/ test/java/org/apache/jackrabbit/
test/java/org/apache/jackrabbit/backup/
Author: jukka
Date: Fri Jul 28 01:37:52 2006
New Revision: 426435
URL: http://svn.apache.org/viewvc?rev=426435&view=rev
Log:
JCR-442: Committed Nicolas' latest contrib/backup changes (patch-backup-060728.txt) with some modifications.
Added:
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java (with props)
jackrabbit/trunk/contrib/backup/src/test/backup.xml (with props)
jackrabbit/trunk/contrib/backup/src/test/java/org/
jackrabbit/trunk/contrib/backup/src/test/java/org/apache/
jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/
jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/
jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java (with props)
jackrabbit/trunk/contrib/backup/src/test/test.xml (with props)
Removed:
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ManagerBackup.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryConfigBackup.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/SizeException.java
Modified:
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationParser.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java
jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+/**
+ * @author ntoper
+ *
+ */
+public class AllWorkspacesBackup extends Backup {
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public AllWorkspacesBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+ }
+
+ public AllWorkspacesBackup() {
+ super();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException,
+ IOException {
+ Session s = this.getSession();
+ Workspace wsp = s.getWorkspace();
+ String[] allWsp = wsp.getAccessibleWorkspaceNames();
+
+ for (int i = 0; i < allWsp.length; i++) {
+ WorkspaceBackup wspb = new WorkspaceBackup(this.repo, this.conf, allWsp[i]);
+ wspb.backup(h);
+
+ WorkspaceConfigBackup wspConfb = new WorkspaceConfigBackup(this.repo, this.conf, allWsp[i]);
+ wspConfb.backup(h);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/AllWorkspacesBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/Backup.java Fri Jul 28 01:37:52 2006
@@ -16,31 +16,53 @@
*/
package org.apache.jackrabbit.backup;
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
import org.apache.jackrabbit.core.RepositoryImpl;
/**
* This class is the abstract class of all resources to backup. If you need to add a new backuped resource
* extend Backup and implement both the save and restore methods.
*
- * The constructor is called when instantiating the specific backup resource class through ManagerBackup.
+ * The constructor is called when instantiating the specific backup resource class through BackupManager.
*/
public abstract class Backup {
RepositoryImpl repo;
BackupConfig conf;
+ Session session;
/**
*
* @param repo The repository to backup
* @param conf The specific BackupConfig object (usually a subset of backup.xml)
* @param name Name of the resource to backup. Unique. Useful?
+ * @throws RepositoryException
+ * @throws LoginException
*/
- public Backup(RepositoryImpl repo, BackupConfig conf) {
+ //TODO Useful?
+ public Backup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
this.repo = repo;
this.conf = conf;
+ this.session = this.repo.login(
+ new SimpleCredentials(this.conf.getLogin(), this.conf.getPassword().toCharArray()));
+
}
public Backup() {
+
+ }
+
+ public void init(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ this.repo = repo;
+ this.conf = conf;
+ this.session = this.repo.login(
+ new SimpleCredentials(this.conf.getLogin(), this.conf.getPassword().toCharArray()));
}
public RepositoryImpl getRepo() {
@@ -48,7 +70,12 @@
}
/*
- * Each ResourceBackup is responsible to handle backup of their content + configuration
+ * Each ResourceBackup is responsible to handle the backup.
+ *
+ * We use file when we cannot assume anything on the size of the data or we know it's big. When
+ * we know the data is small we store it in RAM.
+ *
+ *
*
* For each resource
* Test maxFileSize
@@ -56,9 +83,14 @@
* check the checksum
* Send it to out
*/
- public abstract void backup(BackupIOHandler h);
+ public abstract void backup(BackupIOHandler h) throws RepositoryException, IOException;
public abstract void restore(BackupIOHandler h);
-
+ public Session getSession() {
+ return this.session;
+ }
+
+ //TODO call sesssion.logout or useless?
+
}
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfig.java Fri Jul 28 01:37:52 2006
@@ -18,11 +18,11 @@
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.util.Collection;
import java.util.Properties;
+
import org.apache.jackrabbit.core.config.ConfigurationException;
import org.apache.jackrabbit.core.config.PersistenceManagerConfig;
import org.xml.sax.InputSource;
@@ -33,81 +33,22 @@
* create configured backup objects.
* <p>
* It will send different backup object, according to the expected type
- * (ManagerBackup or WorkspaceBackup for instance).
+ * (BackupManager or WorkspaceBackup for instance).
*
*/
public class BackupConfig {
+ //TODO Useful?
private PersistenceManagerConfig pmc;
+ //Tused to backup a workspace first in a file
private File workFolder;
private Collection allResources;
- private String xml;
+ private File file;
+ private File repoConfFile;
+ private String login;
+ private String password;
/**
- * Convenience method that wraps the configuration file name into an
- * {@link InputSource} and invokes the
- * {@link #create(InputSource, String)} method.
- *
- * @param file repository configuration file name
- * @param home repository home directory
- * @return backup configuration
- * @throws ConfigurationException on configuration errors
- * @throws IllegalAccessException
- * @throws InstantiationException
- * @throws ClassNotFoundException
- * @throws SizeException
- * @throws IOException
- * @see #create(InputSource, String)
- */
- public static BackupConfig create(String file)
- throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
- URI uri = new File(file).toURI();
- return create(new InputSource(uri.toString()));
- }
-
- /**
- * Convenience method that wraps the configuration URI into an
- * {@link InputSource} and invokes the
- * {@link #create(InputSource, String)} method.
- *
- * @param uri repository configuration URI
- * @param home repository home directory
- * @return backup configuration
- * @throws ConfigurationException on configuration errors
- * @throws IllegalAccessException
- * @throws InstantiationException
- * @throws ClassNotFoundException
- * @throws SizeException
- * @throws IOException
- * @see #create(InputSource, String)
- */
- public static BackupConfig create(URI uri)
- throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
- return create(new InputSource(uri.toString()));
- }
-
- /**
- * Convenience method that wraps the configuration input stream into an
- * {@link InputSource} and invokes the
- * {@link #create(InputSource, String)} method.
- *
- * @param input repository configuration input stream
- * @param home repository home directory
- * @return backup configuration
- * @throws ConfigurationException on configuration errors
- * @throws IllegalAccessException
- * @throws InstantiationException
- * @throws ClassNotFoundException
- * @throws SizeException
- * @throws IOException
- * @see #create(InputSource, String)
- */
- public static BackupConfig create(InputStream input, String home)
- throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
- return create(new InputSource(input));
- }
-
- /**
* Parses the given repository configuration document and returns the
* parsed and initialized repository configuration. The given repository
* home directory workFolder will be used as the ${rep.home} parser variable.
@@ -116,6 +57,7 @@
* method also initializes the configuration (creates the configured
* directories, etc.). The {@link RepositoryConfigurationParser} class should be
* used directly to just parse the configuration.
+ * @param repoConfFile
*
* @param xml repository configuration document
* @param home repository home directory
@@ -124,14 +66,17 @@
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
- * @throws SizeException
* @throws IOException
*/
- public static BackupConfig create(InputSource xml)
- throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
+ public static BackupConfig create(String myFile, String repoConfFile, String login, String password)
+ throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+
+ URI uri = new File(myFile).toURI();
+ InputSource is = new InputSource(uri.toString());
+
BackupConfigurationParser parser = new BackupConfigurationParser(new Properties());
- BackupConfig config = parser.parseBackupConfig(xml);
+ BackupConfig config = parser.parseBackupConfig(is, myFile, repoConfFile, login, password);
return config;
}
@@ -139,7 +84,7 @@
//TODO see if path is really useful?
- public BackupConfig(PersistenceManagerConfig pmc, File path, Collection allResources) throws IOException {
+ public BackupConfig(PersistenceManagerConfig pmc, File path, Collection allResources, String myFile, String repoConfFile, String login, String password) throws IOException {
//Logic application: not in the parser: this code has to be here
if (!(path.isDirectory() && path.canWrite())) {
@@ -149,6 +94,10 @@
this.pmc = pmc;
this.workFolder = path;
this.allResources = allResources;
+ this.file = new File(myFile);
+ this.repoConfFile = new File(repoConfFile);
+ this.password = password;
+ this.login = login;
}
public Collection getAllResources() {
@@ -163,17 +112,28 @@
return pmc;
}
- /*
- * Useful?
- */
- public Backup getBackup() {
- // TODO Auto-generated method stub
- return null;
+ public File getFile() {
+ return this.file;
+ }
+
+
+
+ public File getRepoConfFile() {
+ return repoConfFile;
+ }
+
+
+
+ public String getPassword() {
+ return this.password;
}
- public String getXml() {
- return xml;
+
+
+ public String getLogin() {
+ return this.login;
}
+
}
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+/**
+ * Backup/Restore the XML file used to configure this backup.
+ *
+ * @author ntoper
+ *
+ */
+public class BackupConfigurationBackup extends Backup {
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public BackupConfigurationBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+
+ }
+
+ public BackupConfigurationBackup() {
+ super();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException,
+ IOException {
+ File file = conf.getFile();
+ h.write("backup.xml", file);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationParser.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationParser.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupConfigurationParser.java Fri Jul 28 01:37:52 2006
@@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.backup;
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
@@ -28,6 +27,7 @@
import org.apache.jackrabbit.core.config.ConfigurationException;
import org.apache.jackrabbit.core.config.ConfigurationParser;
import org.apache.jackrabbit.core.config.PersistenceManagerConfig;
+import org.apache.jackrabbit.core.config.RepositoryConfigurationParser;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -52,49 +52,27 @@
super(variables);
}
-
- /*
- * A static method to get the XML conf file and return it as a String.
- * It is static since it doesn't have to be used with this configuration XML file.
- *
- * TODO: where is the best place for this method?
- *
- * @param the InputSource
- */
- public static String toXmlString(InputSource xml) throws IOException {
-
- String line;
- StringBuffer content = new StringBuffer();
- BufferedReader readBuffer = new BufferedReader(xml.getCharacterStream());
-
- while((line = readBuffer.readLine()) != null){
- content.append(line);
- content.append("\r\n");
- }
- readBuffer.close();
- return content.toString();
- }
-
-
+
/**
* Parses backup? configuration. Backup configuration uses the
* following format:
* <p>
* TODO comment. See wiki for format
* @param xml repository configuration document
+ * @param myFile
+ * @param repoConfFile
* @return repository configuration
* @throws ConfigurationException if the configuration is broken
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
- * @throws SizeException
* @throws IOException
* @see #parseBeanConfig(Element, String)
* @see #parseVersioningConfig(Element)
*/
- public BackupConfig parseBackupConfig(InputSource xml)
- throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
-
+ public BackupConfig parseBackupConfig(InputSource xml, String myFile, String repoConfFile, String login, String password)
+ throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+ //TODO refactor dependency between this method and BackupConfig
Element root = parseXML(xml);
//Working Folder
@@ -108,7 +86,7 @@
Element resources = this.getElement(root, RESOURCES);
Collection allResources = this.parseResourcesConfig(resources);
- return new BackupConfig(pmc, path, allResources);
+ return new BackupConfig(pmc, path, allResources, myFile, repoConfFile, login, password);
}
@@ -145,16 +123,16 @@
/*
- * For now only support of all workspace backup. I think it is actually simpler to manage on the end-user side.
+ * For now only support of all workspace backup. I think it is actually simpler to manage on the end-user side. Be careful the objects aren't usable yet
*
* Pre-condition: there are resource tags in the conf file (otherwise there is a problem in the backup)
*/
- private Collection parseResourcesConfig( Element root) throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException {
+ private Collection parseResourcesConfig(Element root) throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException {
/*
* For each resource
* get class and instantiate
- * addResource to ManagerBackup
+ * addResource to BackupManager
*/
Vector objects = new Vector();
Vector resources = (Vector) this.getElements(root, RESOURCE);
@@ -166,11 +144,22 @@
Element resource = (Element) it.next();
String savingClass = resource.getAttribute(SAVING_CLASS);
Class c = Class.forName(savingClass);
- objects.addElement( (Backup) c.newInstance());
-
-
+ objects.addElement( (Backup) c.newInstance());
}
return objects;
+ }
+
+ /**
+ * Parses the PersistenceManager config.
+ *
+ * @param parent parent of the <code>PersistenceManager</code> element
+ * @return persistence manager configuration
+ * @throws ConfigurationException if the configuration is broken
+ */
+ protected PersistenceManagerConfig parsePersistenceManagerConfig(
+ Element parent) throws ConfigurationException {
+ return new PersistenceManagerConfig(
+ parseBeanConfig(parent, RepositoryConfigurationParser.PERSISTENCE_MANAGER_ELEMENT));
}
}
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupIOHandler.java Fri Jul 28 01:37:52 2006
@@ -16,17 +16,18 @@
*/
package org.apache.jackrabbit.backup;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;;
public interface BackupIOHandler {
- int getMaxFileSize();
- void setMaxFileSize(int i);
- //Add reference to the file
- // How to precise if in or out... Maybe not needed?
- void close();
- void initBackup() throws FileNotFoundException;
- void initRestore();
- void init();
-
+ //Add reference to the file
+ // How to precise if in or out... Maybe not needed?
+ void close() throws IOException;
+ void initBackup() throws FileNotFoundException, IOException;
+ void initRestore() throws FileNotFoundException;
+ void write(String name, File f) throws IOException;
+ void write(String name, ByteArrayOutputStream fos) throws IOException;
}
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+/**
+ * This class manages the backup/restore process. It is responsible to transmit it to the BackupIOHandler and to add the repository to the
+ * BackupConfig.
+ *
+ * It extends Backup since it is based on the same semantics. However it is not at the same type as a ResourceBackup (indicated by different names)
+ *
+ * It uses a work folder to get first all backup/restore information, zip them and send them to the handler.
+ *
+ * @author ntoper
+ *
+ */
+public class BackupManager extends Backup {
+
+ public BackupManager(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+
+ //Initiate correctly all objects in allResources
+ Iterator it = this.conf.getAllResources().iterator();
+
+ while(it.hasNext()) {
+ Backup b = (Backup) it.next();
+ b.init(repo, conf);
+ }
+ }
+
+
+ public static BackupManager create(RepositoryImpl impl, BackupConfig conf2) throws LoginException, RepositoryException {
+ return new BackupManager(impl, conf2);
+ }
+ /**
+ * Used to backup the repository and all subclasses. Call all classes when needed.
+ * This class stores the backup config file also. (simplify its fetching and logical since it's not a configurable resource)
+ *
+ * TODO visibility of the conf is huge: each ResourceBackup can get and set others resources modifiers. Is it really bad?
+ *
+ * @param The BackupIOHandler where the backup will be saved
+ * @throws RepositoryException
+ * @throws IOException
+ *
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException, IOException {
+ /* This method calls alternatively each backup method of each <Resource>Backup.
+ * It is responsible to initiate and close the zipFile.
+ * Each backup method, use the BackupIOHandler to write the file directly.
+ */
+
+ h.initBackup();
+ try {
+
+
+ Collection resources = this.conf.getAllResources();
+
+
+ Iterator it = resources.iterator();
+
+ while (it.hasNext()) {
+ Backup b = (Backup) it.next();
+ b.backup(h);
+ }
+ }
+ finally {
+ h.close();
+ }
+ }
+
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/BackupManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/LaunchBackup.java Fri Jul 28 01:37:52 2006
@@ -16,15 +16,14 @@
*/
package org.apache.jackrabbit.backup;
-import java.io.FileReader;
import java.io.IOException;
import javax.jcr.AccessDeniedException;
+import javax.jcr.LoginException;
import javax.jcr.RepositoryException;
import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.xml.sax.InputSource;
/**
* LaunchBackup is a command line tool and a demo tool for the backup tool. To
@@ -36,19 +35,19 @@
*/
public class LaunchBackup {
- static BackupIOHandler h;
- RepositoryImpl repo;
+ static BackupIOHandler h;
+ RepositoryImpl repo;
BackupConfig conf;
RepositoryConfig repoConf;
- ManagerBackup backup;
+ BackupManager backup;
/**
* The command line tool.
*
- * LaunchBackup --zip myzip.zip --size 2 --conf backup.xml backup repository.xml repository/
- * LaunchBackup --zip ./myzip.zip --size 2 --conf backup.xml restore repository.xml repository/
+ * LaunchBackup --zip myzip.zip --size 2 --conf backup.xml --login nico --password mlypass backup repository.xml repository/
+ * LaunchBackup --zip ./myzip.zip --size 2 --conf backup.xml --login nico --password restore repository.xml repository/
*
* --zip: where is the zip file (only implemented way to backup for now)
* --size in Go
@@ -69,90 +68,100 @@
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
- * @throws SizeException
*
*/
- public static void main(String[] args) throws RepositoryException, AccessDeniedException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException {
+ public static void main(String[] args) throws RepositoryException, AccessDeniedException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
// I have to declare all var here so they are not resetted out of the for.
- String zipFile = null;
+ String zipFile = null;
String confFile = null;
String home = null;
String repoConfFile = null;
+ String login = null;
+ String password = null;
//2 booleans in case the user specified nothing
boolean isBackup = false;
boolean isRestore = false;
//Parse the command line.
- for (int i = 0; i < args.length; i++) {
-
+ for (int i = 0; i < args.length; i++) {
+
if ( args[i].equals("--help") || args.length == 0) {
usage();
}
if (args[i].equals("--zip")){
- zipFile = args[i + 1];
- //We put it here because later we might offer other possibilities than only zip
- h = new ZipFileBackupIOHandler(zipFile);
+ zipFile = args[i + 1];
+ //We put it here because later we might offer other possibilities than only zip
+ LaunchBackup.h = new ZipFileBackupIOHandler(zipFile);
}
+ if (args[i].equals("--conf")){
+
+ confFile = args[i + 1];
+
+ }
- if (args[i].equals("--size") && (h != null)){
-
- Integer max = (new Integer(args[i+ 1]));
- h.setMaxFileSize(max.intValue());
+ if (args[i].equals("--login")){
+
+ login = args[i + 1];
+
}
-
- if (args[i].equals("--conf")){
-
- confFile = args[i + 1];
-
+ if (args[i].equals("--password")){
+
+ password = args[i + 1];
+
}
- if (args[i].equals("backup") && isRestore == false ){
- isBackup = true;
- repoConfFile = args[i + 1];
- home = args[i + 2];
-
+ if (args[i].equals("backup") && isRestore == false ){
+ isBackup = true;
+ repoConfFile = args[i + 1];
+ home = args[i + 2];
+
}
if (args[i].equals("restore") && isBackup == false ){
- isRestore = true;
- repoConfFile = args[i + 1];
- home = args[i + 2];
+ isRestore = true;
+ repoConfFile = args[i + 1];
+ home = args[i + 2];
}
}
-
- LaunchBackup launch = null;
-
- //We need to shutdown properly the repository whatever happens
- try {
- //Launch backup
- if (isBackup) {
- launch = new LaunchBackup(repoConfFile, home, confFile);
+
+ //Check if login and password are provided otherwise weird thing will happen
+ if (login == null || password == null) {
+ throw new LoginException();
+ }
+
+ LaunchBackup launch = null;
+
+ //We need to shutdown properly the repository whatever happens
+ try {
+ //Launch backup
+ if (isBackup) {
+ launch = new LaunchBackup(repoConfFile, home, confFile, login, password);
launch.backup(h);
- }
- //Launch restore
- else if (isRestore) {
- launch = new LaunchBackup();
- launch.restore(h);
- }
- //Launch nothing (if nothing specified
- else {
- usage();
- }
- }
- finally
- {
- if (launch !=null)
- launch.shutdown();
- }
+ }
+ //Launch restore
+ else if (isRestore) {
+ launch = new LaunchBackup();
+ launch.restore(h);
+ }
+ //Launch nothing (if nothing specified
+ else {
+ usage();
+ }
+ }
+ finally
+ {
+ if (launch !=null)
+ launch.shutdown();
+ }
}
- /**
+ /**
* Auxiliary method for main
*
*/
@@ -169,20 +178,17 @@
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
- * @throws SizeException
* @throws IOException
*/
- public LaunchBackup(String repoConfFile, String home, String backupConfFile) throws RepositoryException, ClassNotFoundException, InstantiationException, IllegalAccessException, SizeException, IOException {
- //Launch first the repository
- this.repoConf = RepositoryConfig.create(repoConfFile, home);
- this.repo = RepositoryImpl.create(this.repoConf);
-
- //Create the backupConfig object
-
- FileReader fr = new FileReader(backupConfFile);
- InputSource xml = new InputSource(fr);
- this.conf = BackupConfig.create(xml);
- this.backup = ManagerBackup.create(this.repo, this.conf);
+ public LaunchBackup(String repoConfFile, String home, String backupConfFile, String login, String password) throws RepositoryException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+ //Launch first the repository
+ this.repoConf = RepositoryConfig.create(repoConfFile, home);
+ this.repo = RepositoryImpl.create(this.repoConf);
+
+ //Create the backupConfig object
+ this.conf = BackupConfig.create(backupConfFile, repoConfFile, login, password);
+ this.backup = BackupManager.create(this.repo, this.conf);
+
}
/**
@@ -215,7 +221,7 @@
}
private void shutdown() {
- this.repo.shutdown();
- }
+ this.repo.shutdown();
+ }
}
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+
+import javax.jcr.LoginException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+
+
+/**
+ * This class handles backup of the namespaces of the repository.
+ *
+ * This class needs to be serializable so the internal class can be serialized (does anybody know why?)
+ *
+ * @author ntoper
+ *
+ */
+public class NamespaceBackup extends Backup implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4703796138774238005L;
+
+ /**
+ * This class holds all namespaces in a serializable way. We only put the relevant information.
+ * (Do not change this class or you might lose backward compatibility; instead use another version)
+ *
+ */
+ private class Namespaces implements Serializable {
+
+ private static final long serialVersionUID = 8384076353482950602L;
+
+ HashMap h;
+
+
+ public Namespaces() {
+ h = new HashMap();
+ }
+
+ public void addNamespace(String prefix, String uri) {
+ h.put(prefix, uri);
+ }
+
+ }
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public NamespaceBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+
+
+
+ }
+
+ public NamespaceBackup() {
+ super();
+ }
+
+
+ /* (non-Javadoc)
+ * TODO where do I find the local ns?
+ * TODO use a ByteArrayOutputStream?
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException, IOException {
+
+ Session s = this.getSession();
+ Workspace wsp = s.getWorkspace();
+ NamespaceRegistry ns = wsp.getNamespaceRegistry();
+
+ Namespaces myNs = new Namespaces();
+
+ String[] allPrefixes = ns.getPrefixes();
+
+ for (int i = 0; i < allPrefixes.length; i++) {
+ String prefix = allPrefixes[i];
+ myNs.addNamespace(prefix, ns.getURI(prefix));
+ }
+
+ String name = this.getClass().toString();
+
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(myNs);
+ h.write(name, fos);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NamespaceBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeWriter;
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * @author ntoper
+ *
+ */
+public class NodeTypeBackup extends Backup {
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public NodeTypeBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+ }
+
+ public NodeTypeBackup() {
+ super();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws IOException, RepositoryException {
+ //Can we assume the default wsp always exist?
+ Session s = this.getSession();
+ Workspace wsp = s.getWorkspace();
+
+ NodeTypeManagerImpl ntm = (NodeTypeManagerImpl) wsp.getNodeTypeManager();
+ NodeTypeRegistry ntreg = ntm.getNodeTypeRegistry();
+ NamespaceRegistry ns = wsp.getNamespaceRegistry();
+ NodeTypeDef[] ntd = getRegisteredNodesTypesDefs(ntreg);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ NodeTypeWriter.write(out, ntd, ns);
+ h.write("NodeType", out);
+ }
+
+
+ /**
+ * Returns the nodes types definitions of all registered node types.
+ *
+ * @return the node type definition of all registered node types.
+ * @throws NoSuchNodeTypeException
+ */
+ private static NodeTypeDef[] getRegisteredNodesTypesDefs(NodeTypeRegistry ntreg) throws NoSuchNodeTypeException {
+ QName[] qn = ntreg.getRegisteredNodeTypes();
+ NodeTypeDef[] ntd = new NodeTypeDef[qn.length];
+
+ for (int i=0; i < qn.length; i++) {
+ ntd[i] = ntreg.getNodeTypeDef(qn[i]);
+ }
+ return ntd;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeTypeBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+
+/**
+ * @author ntoper
+ *
+ */
+public class NodeVersionHistoriesBackup extends Backup {
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public NodeVersionHistoriesBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
+ super(repo, conf);
+ // TODO Auto-generated constructor stub
+ }
+
+ public NodeVersionHistoriesBackup() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException,
+ IOException {
+ Session s = this.getSession();
+
+ File temp = new File(this.conf.getWorkFolder() + "history.xml");
+
+ try {
+ FileOutputStream out = new FileOutputStream(temp);
+ s.exportSystemView("/jcr:system/jcr:versionStorage", out, false, false);
+ h.write("history.xml", temp);
+ }
+ finally {
+ temp.delete();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ //TODO find a way to put /jcr:system/jcr:versionStorage probably by instanciating as a repo/wsp the versioning pm
+
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/NodeVersionHistoriesBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/RepositoryBackup.java Fri Jul 28 01:37:52 2006
@@ -16,6 +16,18 @@
*/
package org.apache.jackrabbit.backup;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Properties;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeImpl;
import org.apache.jackrabbit.core.RepositoryImpl;
/**
@@ -24,28 +36,58 @@
*/
public class RepositoryBackup extends Backup {
+
/**
* @param repo
* @param conf
+ * @throws RepositoryException
+ * @throws LoginException
*/
- public RepositoryBackup(RepositoryImpl repo, BackupConfig conf) {
+ public RepositoryBackup(RepositoryImpl repo, BackupConfig conf) throws LoginException, RepositoryException {
super(repo, conf);
- // TODO Auto-generated constructor stub
}
-
- /**
- *
- */
+
public RepositoryBackup() {
super();
- // TODO Auto-generated constructor stub
}
+ /**
+ * Backup the repository config file
+ *
+ * TODO Backup properties? Metadata store? Other ressources?
+ * @throws IOException
+ * @throws RepositoryException
+ *
+ *
+ */
+ public void backup(BackupIOHandler h) throws IOException, RepositoryException {
+
+ File file = this.conf.getRepoConfFile();
- public void backup(BackupIOHandler h) {
- // TODO Auto-generated method stub
+ //Backup repository.xml
+ h.write("repository_xml", file);
+
+ //Properties
+ Properties p = new Properties();
+ String[] keys = repo.getDescriptorKeys();
+ for (int i = 0; i < keys.length; i++) {
+ p.setProperty(keys[i], repo.getDescriptor(keys[i]));
+ }
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ p.store(bos,"");
+ h.write("repository_properties", bos);
+
+ // Root node ID
+ NodeImpl nod = (NodeImpl) this.getSession().getRootNode();
+ NodeId n = nod.getNodeId();
+ //We persist the string as a serialized object to avoid compatibility issue
+ String s = n.toString();
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(s);
+ h.write("repository_rootNode", fos);
}
public void restore(BackupIOHandler h) {
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.jcr.Item;
+import javax.jcr.LoginException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.SimpleCredentials;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.xml.SysViewSAXEventGenerator;
+import org.xml.sax.SAXException;
+
+//TODO Wiki doc to update
+/**
+ * @author ntoper
+ *
+ */
+public class WorkspaceBackup extends Backup {
+
+ private static int called = 0;
+ private String wspName;
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public WorkspaceBackup(RepositoryImpl repo, BackupConfig conf, String name) throws LoginException, RepositoryException {
+ super(repo, conf);
+ this.wspName = name;
+ }
+
+ public void init(RepositoryImpl repo, BackupConfig conf, String name) throws LoginException, RepositoryException {
+ super.init(repo, conf);
+ this.wspName = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException,
+ IOException {
+ SessionImpl s = (SessionImpl) repo.login(new SimpleCredentials(this.conf.getLogin(), this.conf.getPassword().toCharArray()), this.wspName);
+
+ SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
+ File temp = new File(this.conf.getWorkFolder() + "wsp.xml");
+ try {
+ TransformerHandler th = stf.newTransformerHandler();
+ th.setResult(new StreamResult(new FileOutputStream(temp)));
+ th.getTransformer().setParameter(OutputKeys.METHOD, "xml");
+ th.getTransformer().setParameter(OutputKeys.ENCODING, "UTF-8");
+ th.getTransformer().setParameter(OutputKeys.INDENT, "no");
+
+ new SysViewSAXEventGenerator(
+ s.getRootNode(), false, false, th) {
+ protected void process(Node node, int level)
+ throws RepositoryException, SAXException {
+ if (!"/jcr:system".equals(node.getPath())) {
+ super.process(node, level);
+ }
+ }
+ }.serialize();
+ h.write("export"+ called +".xml", temp);
+ } catch (TransformerException te) {
+ throw new RepositoryException(te);
+ } catch (SAXException se) {
+ throw new RepositoryException(se);
+ } finally {
+ temp.delete();
+ called += 1;
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java (added)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.backup;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
+import org.apache.jackrabbit.backup.Backup;
+
+/**
+ * @author ntoper
+ *
+ */
+public class WorkspaceConfigBackup extends Backup {
+
+ private static int called = 0;
+ private String wspName;
+
+ /**
+ * @param repo
+ * @param conf
+ * @throws RepositoryException
+ * @throws LoginException
+ */
+ public WorkspaceConfigBackup(RepositoryImpl repo, BackupConfig conf, String name) throws LoginException, RepositoryException {
+ super(repo, conf);
+ this.wspName = name;
+ }
+
+ public void init(RepositoryImpl repo, BackupConfig conf, String name) throws LoginException, RepositoryException {
+ super.init(repo, conf);
+ this.wspName = name;
+ }
+
+ public WorkspaceConfigBackup() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#backup(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void backup(BackupIOHandler h) throws RepositoryException,
+ IOException {
+ Session s = repo.login(new SimpleCredentials(this.conf.getLogin(), this.conf.getPassword().toCharArray()), this.wspName);
+
+ WorkspaceImpl wsp = (WorkspaceImpl) s.getWorkspace();
+ WorkspaceConfig c = wsp.getConfig();
+
+ String home = c.getHomeDir();
+ File wspXml = new File (home + "/workspace.xml");
+ h.write("WspConf" + called , wspXml);
+ called += 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jackrabbit.backup.Backup#restore(org.apache.jackrabbit.backup.BackupIOHandler)
+ */
+ public void restore(BackupIOHandler h) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/WorkspaceConfigBackup.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java?rev=426435&r1=426434&r2=426435&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java (original)
+++ jackrabbit/trunk/contrib/backup/src/main/java/org/apache/jackrabbit/backup/ZipFileBackupIOHandler.java Fri Jul 28 01:37:52 2006
@@ -16,12 +16,20 @@
*/
package org.apache.jackrabbit.backup;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Checksum;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
/**
* Question: ZipFile
@@ -30,64 +38,55 @@
*
*/
public class ZipFileBackupIOHandler implements BackupIOHandler {
+
+ private static int BUFFER_SIZE = 1024;
- int maxFileSize;
- File zip;
- FileInputStream fin;
- FileChannel fc;
- private ByteBuffer buffer;
- private FileOutputStream fout;
-
-
- public ZipFileBackupIOHandler(String zipFile) {
- this.zip = new File(zipFile);
- this.buffer = ByteBuffer.allocateDirect(2048);
- }
-
- public void setMaxFileSize(int i) {
- this.maxFileSize = i;
- }
-
- public int getMaxFileSize() {
- return this.maxFileSize;
+ private File zip;
+ // private FileInputStream fin;
+ // private ByteBuffer buffer;
+ private FileOutputStream fout;
+ private ZipOutputStream zipOut;
+
+
+ public ZipFileBackupIOHandler(String zipFile) throws FileNotFoundException {
+ this.zip = new File(zipFile);
+ // this.buffer = ByteBuffer.allocateDirect(2048);
}
- public void close() {
- // TODO Auto-generated method stub
-
+ public void close() throws IOException {
+ zipOut.finish();
+ zipOut.close();
}
- public void init() {
+ /// private void init() {
//Useful?
- this.buffer.clear();
- }
+ // this.buffer.clear();
+ //}
- public void initBackup() throws FileNotFoundException {
+ public void initBackup() throws IOException {
+ boolean a = this.zip.createNewFile();
+
+ if (!a) {
+ throw new IOException();
+ }
+
this.fout = new FileOutputStream(this.zip);
- this.fc = this.fin.getChannel();
+ this.zipOut = new ZipOutputStream(this.fout);
}
- public void initRestore() {
- try {
- this.fin = new FileInputStream(this.zip);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- this.fc = this.fin.getChannel();
-
+ public void initRestore() throws FileNotFoundException {
+ // this.fin = new FileInputStream(this.zip);
+ // this.fcin = this.fin.getChannel();
+ //Restore zipFile
}
-
-
-
/**
* Create a directory per resources
* Backup the resource and zip it
* @param string
* @param content
*/
- /* private void writeFile(String string, String content) {
+ /*private void writeFile(String string, String content) {
File conf = new File();
FileWriter fw = new FileWriter(cheminAbstraitSortie);
BufferedWriter tamponEcriture = new BufferedWriter(fluxEcritureTexte);
@@ -96,5 +95,67 @@
tamponEcriture.close();
} */
+
+ public void read() {
+ }
+
+
+ public void write(String name, File f) throws IOException {
+ zipOut.flush();
+ ZipEntry e = new ZipEntry(name);
+ zipOut.putNextEntry(e);
+
+ Checksum crc = new CRC32();
+ CheckedInputStream i = new CheckedInputStream(new FileInputStream(f), crc);
+
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ int len;
+ while ( (len = i.read(buffer, 0, BUFFER_SIZE)) != -1) {
+ zipOut.write(buffer,0, len);
+ }
+
+ //Checksum management
+ // TODO Is crc up to date? To be checked...
+ long check = crc.getValue();
+ e.setCrc(check);
+ zipOut.closeEntry();
+ }
+
+
+ /**
+ *
+ * TODO: refactor this method with the one upper.
+ *
+ *
+ * Used for small I/O operations (no NIO used there). Take a file and zip it.
+ *
+ * Most I/O operations are operated on RAM.
+ *
+ */
+ public void write(String name, ByteArrayOutputStream fos) throws IOException {
+ zipOut.flush();
+ ZipEntry e = new ZipEntry(name);
+ zipOut.putNextEntry(e);
+
+ Checksum crc = new CRC32();
+
+ InputStream io = new ByteArrayInputStream(fos.toByteArray());
+
+ CheckedInputStream i = new CheckedInputStream(io, crc);
+
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int len;
+ while ( (len = i.read(buffer, 0, BUFFER_SIZE)) != -1) {
+ zipOut.write(buffer,0, len);
+ }
+
+ //Checksum management
+ // TODO Is crc up to date? To be checked...
+ long check = crc.getValue();
+ e.setCrc(check);
+ zipOut.closeEntry();
+ }
+
}
Added: jackrabbit/trunk/contrib/backup/src/test/backup.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/test/backup.xml?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/test/backup.xml (added)
+++ jackrabbit/trunk/contrib/backup/src/test/backup.xml Fri Jul 28 01:37:52 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+<Backup>
+<WorkingFolder path="tmp" />
+<!-- For now only ObjectPersistenceManager and XMLPersistenceManager -->
+<PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager" />
+
+ <Resources>
+ <Resource savingClass="org.apache.jackrabbit.backup.BackupConfigurationBackup" />
+ <Resource savingClass="org.apache.jackrabbit.backup.RepositoryBackup" />
+ <Resource savingClass="org.apache.jackrabbit.backup.NodeTypeBackup" />
+ <Resource savingClass="org.apache.jackrabbit.backup.NamespaceBackup" />
+ <Resource savingClass="org.apache.jackrabbit.backup.AllWorkspacesBackup" />
+ <Resource savingClass="org.apache.jackrabbit.backup.NodeVersionHistoriesBackup" />
+ </Resources>
+</Backup>
\ No newline at end of file
Propchange: jackrabbit/trunk/contrib/backup/src/test/backup.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java (added)
+++ jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java Fri Jul 28 01:37:52 2006
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.backup;
+
+import javax.jcr.*;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.name.QName;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+//TODO provide options to start up and put relative path
+
+/**
+ * Third Jackrabbit example application. Imports an example XML file
+ * and outputs the contents of the entire workspace.
+ */
+public class BackupTest {
+
+ /** Runs the ThirdHop example. */
+ public static void main(String[] args) throws Exception {
+ // Set up a Jackrabbit repository with the specified
+ // configuration file and repository directory
+ Repository repository = new TransientRepository();
+
+ // Login to the default workspace as a dummy user
+ Session session = repository.login(
+ new SimpleCredentials("username", "password".toCharArray()));
+ try {
+ // Use the root node as a starting point
+ Node root = session.getRootNode();
+
+ // Import the XML file unless already imported
+ if (!root.hasNode("importxml")) {
+ System.out.print("Importing xml... ");
+ // Create an unstructured node under which to import the XML
+ root.addNode("importxml", "nt:unstructured");
+ // Import the file "test.xml" under the created node
+ FileInputStream xml = new FileInputStream("src/test/test.xml");
+ session.importXML(
+ "/importxml", xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+ xml.close();
+ // Save the changes to the repository
+ session.save();
+ System.out.println("done.");
+ }
+
+ //Versionning
+ //create versionable node
+ Node n = root.addNode("childNode", "nt:unstructured");
+ n.addMixin("mix:versionable");
+ n.setProperty("anyProperty", "Blah");
+ session.save();
+ n.checkin();
+
+ //add new version
+ Node child = root.getNode("childNode");
+ child.checkout();
+ child.setProperty("anyProperty", "Blah2");
+ session.save();
+ child.checkin();
+
+ //Creating a second workspace
+ Workspace wsp = session.getWorkspace();
+ String[] allWsp = wsp.getAccessibleWorkspaceNames();
+
+ if (allWsp.length < 2) {
+ ((WorkspaceImpl)wsp).createWorkspace("secondTest");
+ session.logout();
+ Session session2 = repository.login(new SimpleCredentials("username", "password".toCharArray()), "secondTest");
+ root = session2.getRootNode();
+
+ System.out.print("Importing xml in workspace secondTest... ");
+
+ // Create an unstructured node under which to import the XML
+ root.addNode("importxml", "nt:unstructured");
+ // Import the file "test.xml" under the created node
+ FileInputStream xml = new FileInputStream("src/test/test.xml");
+ session2.importXML(
+ "/importxml", xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+ xml.close();
+ // Save the changes to the repository
+ session2.save();
+ System.out.println("done.");
+
+ }
+
+
+
+ //Registering a NodeType
+ /* System.out.print("Registering a test nodeType...\r\n ");
+
+ NodeTypeDef ntd = new NodeTypeDef();
+ ntd.setMixin(true);
+ ntd.setName(new QName("http://www.jcp.org/jcr/nt/1.0", "example"));
+ registerNodeType(ntd, session);
+
+ */
+
+ System.out.print("Launching backup...\r\n ");
+
+ /* Tested params:
+ * --zip myzip.zip --size 2 --conf backup.xml backup repository.xml repository/
+ */
+
+ //Delete the zip file if existing
+ File zip = new File("myzip.zip");
+ zip.delete();
+
+ String[] argsBackup ="--zip myzip.zip --login username --password password --conf src/test/backup.xml backup repository.xml repository/".split(" ");
+ LaunchBackup.main(argsBackup);
+ System.out.print("Backup done. ");
+
+
+ } finally {
+ session.logout();
+ }
+ }
+
+ private static void registerNodeType(NodeTypeDef nodeTypeDef, Session session) throws RepositoryException, InvalidNodeTypeDefException
+ {
+ //NodeTypeRegistry object
+ Workspace wsp = session.getWorkspace();
+ NodeTypeManager ntMgr = wsp.getNodeTypeManager();
+
+ //non-JSR 170 - jackrabbit specific
+ NodeTypeRegistry ntReg =
+ ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
+
+ ntReg.registerNodeType(nodeTypeDef);
+ }
+
+
+}
\ No newline at end of file
Propchange: jackrabbit/trunk/contrib/backup/src/test/java/org/apache/jackrabbit/backup/BackupTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/contrib/backup/src/test/test.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/backup/src/test/test.xml?rev=426435&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/backup/src/test/test.xml (added)
+++ jackrabbit/trunk/contrib/backup/src/test/test.xml Fri Jul 28 01:37:52 2006
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+<project>
+ <pomVersion>3</pomVersion>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-backup</artifactId>
+ <name>Jackrabbit Backup</name>
+ <currentVersion>SNAPSHOT</currentVersion>
+ <inceptionYear>2006</inceptionYear>
+ <package>org.apache.jackrabbit.backup.*</package>
+ <shortDescription>Backup tool for Jackrabbit repositories</shortDescription>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>/LICENSE.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <dependencies>
+ <dependency>
+ <groupId>jsr170</groupId>
+ <artifactId>jcr</artifactId>
+ <version>1.0</version>
+ <url>http://jcp.org/en/jsr/detail?id=170</url>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.0</version>
+ <url>http://www.slf4j.org/download.html</url>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.8</version>
+ <url>http://logging.apache.org/log4j</url>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
+ <resources>
+ <resource>
+ <targetPath>META-INF</targetPath>
+ <directory>.</directory>
+ <includes>
+ <include>README.txt</include>
+ </includes>
+ </resource>
+ </resources>
+ <unitTest>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ </unitTest>
+ </build>
+
+</project>
Propchange: jackrabbit/trunk/contrib/backup/src/test/test.xml
------------------------------------------------------------------------------
svn:eol-style = native