jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r156082 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/config/ test/org/apache/jackrabbit/core/config/
Date Thu, 03 Mar 2005 20:58:16 GMT
Author: jukka
Date: Thu Mar  3 12:58:14 2005
New Revision: 156082

URL: http://svn.apache.org/viewcvs?view=rev&rev=156082
Log:
Refactoring step 4 (JCR-53)
 - Moved repository.xml parsing to ConfigurationParser
 - Moved workspace creation code to ConfigurationParser (TODO find a better place)
 - Removed AbstractConfig as it is no longer needed
 - Added the ConfigurationEntityResolver utility class
 - Fixed broken unit tests (need to call FileSystem.init()!)

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
Removed:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AbstractConfig.java
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java?view=diff&r1=156081&r2=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
Thu Mar  3 12:58:14 2005
@@ -16,13 +16,11 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Properties;
 
 import org.apache.commons.collections.BeanMap;
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.jdom.Element;
 
 /**
  * Bean configuration class. BeanConfig instances contain the class name

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java?view=auto&rev=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
Thu Mar  3 12:58:14 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Entity resolver for Jackrabbit configuration files.
+ * This simple resolver contains mappings for the following
+ * public identifiers used for the Jackrabbit configuration files.
+ * <ul>
+ * <li><code>-//The Apache Software Foundation//DTD Workspace//EN</code></li>
+ * <li><code>-//The Apache Software Foundation//DTD Repository//EN</code></li>
+ * </ul>
+ * <p>
+ * The public identifiers are mapped to a document type definition
+ * file included in the Jackrabbit jar archive.
+ */
+public class ConfigurationEntityResolver implements EntityResolver {
+
+    /**
+     * Public identifier of the repository configuration DTD.
+     */
+    public static final String REPOSITORY_ID =
+        "-//The Apache Software Foundation//DTD Repository//EN";
+
+    /**
+     * Public identifier of the workspace configuration DTD.
+     */
+    public static final String WORKSPACE_ID =
+        "-//The Apache Software Foundation//DTD Workspace//EN";
+
+    /**
+     * Resource path of the internal configuration DTD file.
+     */
+    private static final String CONFIG_DTD =
+            "org/apache/jackrabbit/core/config/config.dtd";
+
+    /**
+     * Resolves an entity to the corresponding input source.
+     * {@inheritDoc}
+     *
+     * @param publicId public identifier
+     * @param systemId system identifier
+     * @return resolved entity source
+     * @throws SAXException on SAX errors
+     * @throws IOException on IO errors
+     */
+    public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException, IOException {
+        if (REPOSITORY_ID.equals(publicId) || WORKSPACE_ID.equals(publicId)) {
+            InputStream dtd =
+                getClass().getClassLoader().getResourceAsStream(CONFIG_DTD);
+            return new InputSource(dtd);
+        } else {
+            return null;
+        }
+    }
+
+}

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java?view=diff&r1=156081&r2=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
Thu Mar  3 12:58:14 2005
@@ -17,9 +17,11 @@
 package org.apache.jackrabbit.core.config;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
@@ -27,27 +29,38 @@
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.util.Text;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
-import org.xml.sax.EntityResolver;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
 /**
  * TODO
  */
 public class ConfigurationParser {
 
+    private static final String SECURITY_ELEMENT = "Security";
+    private static final String APP_NAME_ATTRIB = "appName";
+    private static final String ACCESS_MANAGER_ELEMENT = "AccessManager";
+
+    private static final String WORKSPACES_ELEMENT = "Workspaces";
+    private static final String ROOT_PATH_ATTRIB = "rootPath";
+    private static final String DEFAULT_WORKSPACE_ATTRIB = "defaultWorkspace";
+
+    private static final String WORKSPACE_ELEMENT = "Workspace";
+
+    private static final String VERSIONING_ELEMENT = "Versioning";
+
     /**
-     * public id
+     * wellknown variables (will be replaced with their respective values
+     * whereever they occur within the configuration)
      */
-    public static final String PUBLIC_ID = "-//The Apache Software Foundation//DTD Workspace//EN";
-
-    public static final String CONFIG_DTD_RESOURCE_PATH =
-            "org/apache/jackrabbit/core/config/config.dtd";
+    public static final String REPOSITORY_HOME_VARIABLE = "${rep.home}";
 
     protected static final String FILE_SYSTEM_ELEMENT = "FileSystem";
     private static final String PERSISTENCE_MANAGER_ELEMENT = "PersistenceManager";
@@ -79,6 +92,192 @@
         this.variables = variables;
     }
 
+    public Document parse(InputSource xml) throws IOException, JDOMException {
+        SAXBuilder builder = new SAXBuilder();
+        builder.setEntityResolver(new ConfigurationEntityResolver());
+        return builder.build(xml);
+    }
+    
+    /**
+     * Creates a new <code>RepositoryFactory</code> instance. The configuration
+     * is read from the specified configuration file.
+     *
+     * @param configFilePath path to the configuration file
+     * @param repHomeDir     repository home directory
+     * @return a new <code>RepositoryConfig</code> instance
+     * @throws RepositoryException If an error occurs
+     */
+    public RepositoryConfig parseRepositoryConfig(
+            String configFilePath, String repHomeDir) throws RepositoryException {
+        try {
+            File config = new File(configFilePath);
+            InputSource is = new InputSource(new FileReader(config));
+            is.setSystemId(config.toURI().toString());
+            return parseRepositoryConfig(is, repHomeDir);
+        } catch (IOException ioe) {
+            String msg = "error while reading config file " + configFilePath;
+            throw new RepositoryException(msg, ioe);
+        }
+    }
+
+    /**
+     * private constructor.
+     *
+     * @param is
+     * @param repHomeDir
+     * @throws RepositoryException
+     */
+    public RepositoryConfig parseRepositoryConfig(
+            InputSource xml, String repHomeDir)
+            throws RepositoryException {
+        Properties newVariables = new Properties(variables);
+        newVariables.setProperty(REPOSITORY_HOME_VARIABLE, repHomeDir);
+        ConfigurationParser parser = new ConfigurationParser(newVariables);
+        return parser.parseRepositoryConfig(xml);
+    }
+
+    public RepositoryConfig parseRepositoryConfig(InputSource xml)
+            throws RepositoryException {
+        try {
+            Document config = parse(xml);
+            Element root = config.getRootElement();
+
+            String home = variables.getProperty(REPOSITORY_HOME_VARIABLE);
+
+            // file system
+            BeanConfig fsc = parseBeanConfig(root, FILE_SYSTEM_ELEMENT);
+            FileSystem repFS = (FileSystem) fsc.newInstance();
+            repFS.init();
+
+            // security & access manager config
+            Element secEleme = root.getChild(SECURITY_ELEMENT);
+            String appName = secEleme.getAttributeValue(APP_NAME_ATTRIB);
+            BeanConfig amc = parseBeanConfig(secEleme, ACCESS_MANAGER_ELEMENT);
+
+            // workspaces
+            Element wspsElem = root.getChild(WORKSPACES_ELEMENT);
+            String wspConfigRootDir = replaceVariables(wspsElem.getAttributeValue(ROOT_PATH_ATTRIB));
+            String defaultWspName = replaceVariables(wspsElem.getAttributeValue(DEFAULT_WORKSPACE_ATTRIB));
+
+            // load wsp configs
+            Map wspConfigs = new HashMap();
+            File wspRoot = new File(wspConfigRootDir);
+            if (!wspRoot.exists()) {
+                wspRoot.mkdir();
+            }
+            File[] files = wspRoot.listFiles();
+            if (files == null) {
+                String msg = "invalid repsitory home directory";
+                throw new RepositoryException(msg);
+            }
+            for (int i = 0; i < files.length; i++) {
+                // check if <subfolder>/workspace.xml exists
+                File configFile = new File(files[i], "workspace.xml");
+                if (configFile.isFile()) {
+                    // create workspace config
+                    WorkspaceConfig wspConfig = parseWorkspaceConfig(
+                                configFile.getPath(), configFile.getParent());
+                    String wspName = wspConfig.getName();
+                    if (wspConfigs.containsKey(wspName)) {
+                        String msg = "duplicate workspace name: " + wspName;
+                        throw new RepositoryException(msg);
+                    }
+                    wspConfigs.put(wspName, wspConfig);
+                }
+            }
+            if (wspConfigs.isEmpty()) {
+                // create initial default workspace
+                wspConfigs.put(defaultWspName, createWorkspaceConfig(
+                        config, wspConfigRootDir, defaultWspName));
+            } else {
+                if (!wspConfigs.containsKey(defaultWspName)) {
+                    String msg = "no configuration found for default workspace: " + defaultWspName;
+                    throw new RepositoryException(msg);
+                }
+            }
+
+            // load versioning config
+            Element vElement = config.getRootElement().getChild(VERSIONING_ELEMENT);
+            VersioningConfig vc = parseVersioningConfig(vElement);
+
+            return new RepositoryConfig(config, this, home, appName, wspConfigs, repFS, wspConfigRootDir,
defaultWspName, amc, vc);
+        } catch (FileSystemException ex) {
+            throw new RepositoryException(ex);
+        } catch (JDOMException ex) {
+            throw new RepositoryException(ex);
+        } catch (IOException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassNotFoundException ex) {
+            throw new RepositoryException(ex);
+        } catch (InstantiationException ex) {
+            throw new RepositoryException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassCastException ex) {
+            throw new RepositoryException(ex);
+        }
+    }
+
+    /**
+     * Creates a new workspace configuration with the specified name.
+     *
+     * @param name workspace name
+     * @return a new <code>WorkspaceConfig</code> object.
+     * @throws RepositoryException if the specified name already exists or
+     *                             if an error occured during the creation.
+     */
+    public WorkspaceConfig createWorkspaceConfig(
+            Document config, String root, String name)
+            throws RepositoryException {
+        // create the workspace folder (i.e. the workspace home directory)
+        File wspFolder = new File(root, name);
+        if (!wspFolder.mkdir()) {
+            String msg = "Failed to create the workspace home directory: " + wspFolder.getPath();
+            throw new RepositoryException(msg);
+        }
+        // clone the workspace definition template
+        Element wspCongigElem =
+            (Element) config.getRootElement().getChild("Workspace").clone();
+        wspCongigElem.setAttribute("name", name);
+
+        // create workspace.xml file
+/*
+        DocType docType = new DocType(WORKSPACE_ELEMENT, null, WorkspaceConfig.PUBLIC_ID);
+        Document doc = new Document(wspCongigElem, docType);
+*/
+        Document doc = new Document(wspCongigElem);
+        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
+        File configFile = new File(wspFolder, "workspace.xml");
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(configFile);
+            out.output(doc, fos);
+        } catch (IOException ioe) {
+            String msg = "Failed to create workspace configuration file: " + configFile.getPath();
+            throw new RepositoryException(msg, ioe);
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
+
+        // create workspace config object
+        return parseWorkspaceConfig(configFile.getPath(), configFile.getParent());
+    }
+
+    /**
+     * Initializes this <code>RepositoryConfig</code> object.
+     *
+     * @param config
+     * @throws RepositoryException
+     */
+    protected void init(Document config) throws RepositoryException {
+    }
+
     /**
      * Creates a new <code>WorkspaceConfig</code> instance. The configuration
      * is read from the specified configuration file.
@@ -88,7 +287,7 @@
      * @return a new <code>WorkspaceConfig</code> instance
      * @throws RepositoryException If an error occurs
      */
-    public static WorkspaceConfig parseWorkspaceConfig(
+    public WorkspaceConfig parseWorkspaceConfig(
             String configFilePath, String wspHomeDir)
             throws RepositoryException {
         try {
@@ -111,28 +310,15 @@
      * @return a new <code>WorkspaceConfig</code> instance
      * @throws RepositoryException If an error occurs
      */
-    public static WorkspaceConfig parseWorkspaceConfig(
+    public WorkspaceConfig parseWorkspaceConfig(
             InputSource xml, String home)
             throws RepositoryException {
         try {
-            SAXBuilder builder = new SAXBuilder();
-            builder.setEntityResolver(new EntityResolver() {
-                public InputSource resolveEntity(String publicId, String systemId)
-                throws SAXException, IOException {
-                    if (publicId.equals(PUBLIC_ID)) {
-                        // load dtd resource
-                        return new InputSource(getClass().getClassLoader().getResourceAsStream(CONFIG_DTD_RESOURCE_PATH));
-                    } else {
-                        // use the default behaviour
-                        return null;
-                    }
-                }
-            });
-            Document config = builder.build(xml);
+            Document config = parse(xml);
 
-            Properties variables = new Properties();
-            variables.setProperty(WORKSPACE_HOME_VARIABLE, home);
-            ConfigurationParser parser = new ConfigurationParser(variables);
+            Properties newVariables = new Properties(variables);
+            newVariables.setProperty(WORKSPACE_HOME_VARIABLE, home);
+            ConfigurationParser parser = new ConfigurationParser(newVariables);
             return parser.parseWorkspaceConfig(config);
         } catch (JDOMException ex) {
             throw new RepositoryException(ex);
@@ -170,6 +356,7 @@
             // file system
             BeanConfig fsc = parser.parseBeanConfig(wspElem, FILE_SYSTEM_ELEMENT);
             FileSystem wspFS = (FileSystem) fsc.newInstance();
+            wspFS.init();
 
             // persistence manager config
             BeanConfig pmc =
@@ -181,8 +368,10 @@
             if (searchElem != null) {
                 sc = parser.parseSearchConfig(searchElem);
             }
-            
+
             return new WorkspaceConfig(wspHomeDir, wspName, wspFS, pmc, sc);
+        } catch (FileSystemException ex) {
+            throw new RepositoryException(ex);
         } catch (ClassNotFoundException ex) {
             throw new RepositoryException(ex);
         } catch (InstantiationException ex) {
@@ -205,6 +394,7 @@
             // create FileSystem
             BeanConfig fsc = parseBeanConfig(config, FILE_SYSTEM_ELEMENT);
             FileSystem fs = (FileSystem) fsc.newInstance();
+            fs.init();
 
             // handler class name
             String handlerClassName = config.getAttributeValue(CLASS_ATTRIBUTE,
@@ -214,6 +404,8 @@
             Properties params = parseParameters(config);
 
             return new SearchConfig(fs, handlerClassName, params);
+        } catch (FileSystemException ex) {
+            throw new RepositoryException(ex);
         } catch (ClassNotFoundException ex) {
             throw new RepositoryException(ex);
         } catch (InstantiationException ex) {
@@ -240,11 +432,14 @@
             // create FileSystem
             BeanConfig fsc = parseBeanConfig(config, FILE_SYSTEM_ELEMENT);
             FileSystem fs = (FileSystem) fsc.newInstance();
+            fs.init();
 
             // persistence manager config
             BeanConfig pmc = parseBeanConfig(config, PERSISTENCE_MANAGER_ELEMENT);
 
             return new VersioningConfig(homeDir, fs, pmc);
+        } catch (FileSystemException ex) {
+            throw new RepositoryException(ex);
         } catch (ClassNotFoundException ex) {
             throw new RepositoryException(ex);
         } catch (InstantiationException ex) {
@@ -264,7 +459,8 @@
             Properties properties = parseParameters(element);
             return new BeanConfig(className, properties);
         } else {
-            return null;
+            throw new IllegalArgumentException(name);
+            // return null;
         }
     }
 
@@ -292,10 +488,11 @@
      * @return
      */
     public String replaceVariables(String value) {
-        Iterator iterator = variables.keySet().iterator();
-        while (iterator.hasNext()) {
-            String varName = (String) iterator.next();
-            String varValue = (String) variables.get(varName);
+        String ovalue = value;
+        Enumeration e = variables.propertyNames();
+        while (e.hasMoreElements()) {
+            String varName = (String) e.nextElement();
+            String varValue = variables.getProperty(varName);
             value = Text.replace(value, varName, varValue);
         }
         return value;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?view=diff&r1=156081&r2=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Thu Mar  3 12:58:14 2005
@@ -16,67 +16,33 @@
  */
 package org.apache.jackrabbit.core.config;
 
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.log4j.Logger;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.jcr.RepositoryException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
 import java.util.Collection;
-import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.jdom.Document;
+
 /**
  * A <code>RepositoryConfig</code> ...
  */
-public class RepositoryConfig extends AbstractConfig {
-    private static Logger log = Logger.getLogger(RepositoryConfig.class);
-
-    /**
-     * name of repository configuration file
-     */
-    public static final String CONFIG_FILE_NAME = "repository.xml";
-
-    /**
-     * public id
-     */
-    public static final String PUBLIC_ID = "-//The Apache Software Foundation//DTD Repository//EN";
-
-    private static final String SECURITY_ELEMENT = "Security";
-    private static final String APP_NAME_ATTRIB = "appName";
-    private static final String ACCESS_MANAGER_ELEMENT = "AccessManager";
-
-    private static final String WORKSPACES_ELEMENT = "Workspaces";
-    private static final String ROOT_PATH_ATTRIB = "rootPath";
-    private static final String DEFAULT_WORKSPACE_ATTRIB = "defaultWorkspace";
-
-    private static final String WORKSPACE_ELEMENT = "Workspace";
-
-    private static final String VERSIONING_ELEMENT = "Versioning";
-
-    /**
-     * wellknown variables (will be replaced with their respective values
-     * whereever they occur within the configuration)
-     */
-    public static final String REPOSITORY_HOME_VARIABLE = "${rep.home}";
-
-    /**
-     * map of variable names and their respective values
-     */
-    private final Properties vars;
+public class RepositoryConfig {
+    
+    public static RepositoryConfig create(String file, String home)
+            throws RepositoryException {
+        ConfigurationParser parser = new ConfigurationParser(new Properties());
+        return parser.parseRepositoryConfig(file, home);
+    }
+    
+    private Document config;
+    private ConfigurationParser parser;
 
     /**
      * map of workspace names and workspace configurations
      */
-    private final HashMap wspConfigs;
+    private final Map wspConfigs;
 
     /**
      * repository home directory
@@ -115,136 +81,41 @@
      */
     private VersioningConfig vConfig;
 
-    /**
-     * private constructor.
-     *
-     * @param is
-     * @param repHomeDir
-     * @throws RepositoryException
-     */
-    private RepositoryConfig(InputSource is, String repHomeDir)
-            throws RepositoryException {
-        super(is);
-        this.repHomeDir = repHomeDir;
-        wspConfigs = new HashMap();
-        // initialize variables
-        vars = new Properties();
-        vars.put(REPOSITORY_HOME_VARIABLE, repHomeDir);
-        // read config
-        init(config);
+    public RepositoryConfig(
+            Document config, ConfigurationParser parser,
+            String home, String name, Map wspConfigs,
+            FileSystem fs, String root, String defaultWspName,
+            BeanConfig amc, VersioningConfig vc) {
+        this.config = config;
+        this.parser = parser;
+        this.repHomeDir = home;
+        this.appName = name;
+        this.wspConfigs = wspConfigs;
+        this.repFS = fs;
+        this.wspConfigRootDir = root;
+        this.defaultWspName = defaultWspName;
+        this.amConfig = amc;
+        this.vConfig = vc;
     }
-
+    
     /**
-     * Initializes this <code>RepositoryConfig</code> object.
+     * Creates a new workspace configuration with the specified name.
      *
-     * @param config
-     * @throws RepositoryException
+     * @param name workspace name
+     * @return a new <code>WorkspaceConfig</code> object.
+     * @throws RepositoryException if the specified name already exists or
+     *                             if an error occured during the creation.
      */
-    protected void init(Document config) throws RepositoryException {
-        try {
-            Element root = config.getRootElement();
-            ConfigurationParser parser = new ConfigurationParser(vars);
-
-            // file system
-            BeanConfig fsc = parser.parseBeanConfig(root, FILE_SYSTEM_ELEMENT);
-            repFS = (FileSystem) fsc.newInstance();
-
-            // security & access manager config
-            Element secEleme = root.getChild(SECURITY_ELEMENT);
-            appName = secEleme.getAttributeValue(APP_NAME_ATTRIB);
-            amConfig = parser.parseBeanConfig(secEleme, ACCESS_MANAGER_ELEMENT);
-
-            // workspaces
-            Element wspsElem = root.getChild(WORKSPACES_ELEMENT);
-            wspConfigRootDir = parser.replaceVariables(wspsElem.getAttributeValue(ROOT_PATH_ATTRIB));
-            defaultWspName = parser.replaceVariables(wspsElem.getAttributeValue(DEFAULT_WORKSPACE_ATTRIB));
-
-            // load wsp configs
-            File wspRoot = new File(wspConfigRootDir);
-            if (!wspRoot.exists()) {
-                wspRoot.mkdir();
-            }
-            File[] files = wspRoot.listFiles();
-            if (files == null) {
-                String msg = "invalid repsitory home directory";
-                log.debug(msg);
-                throw new RepositoryException(msg);
-            }
-            for (int i = 0; i < files.length; i++) {
-                // check if <subfolder>/workspace.xml exists
-                File configFile = new File(files[i], "workspace.xml");
-                if (configFile.isFile()) {
-                    // create workspace config
-                    WorkspaceConfig wspConfig =
-                        ConfigurationParser.parseWorkspaceConfig(
-                                configFile.getPath(), configFile.getParent());
-                    String wspName = wspConfig.getName();
-                    if (wspConfigs.containsKey(wspName)) {
-                        String msg = "duplicate workspace name: " + wspName;
-                        log.debug(msg);
-                        throw new RepositoryException(msg);
-                    }
-                    wspConfigs.put(wspName, wspConfig);
-                }
-            }
-            if (wspConfigs.isEmpty()) {
-                // create initial default workspace
-                createWorkspaceConfig(defaultWspName);
-            } else {
-                if (!wspConfigs.containsKey(defaultWspName)) {
-                    String msg = "no configuration found for default workspace: " + defaultWspName;
-                    log.debug(msg);
-                    throw new RepositoryException(msg);
-                }
-            }
-
-            // load versioning config
-            Element vElement = config.getRootElement().getChild(VERSIONING_ELEMENT);
-            vConfig = parser.parseVersioningConfig(vElement);
-        } catch (ClassNotFoundException ex) {
-            throw new RepositoryException(ex);
-        } catch (InstantiationException ex) {
-            throw new RepositoryException(ex);
-        } catch (IllegalAccessException ex) {
-            throw new RepositoryException(ex);
-        } catch (ClassCastException ex) {
-            throw new RepositoryException(ex);
-        }
-    }
-
-    /**
-     * Creates a new <code>RepositoryFactory</code> instance. The configuration
-     * is read from the specified configuration file.
-     *
-     * @param configFilePath path to the configuration file
-     * @param repHomeDir     repository home directory
-     * @return a new <code>RepositoryConfig</code> instance
-     * @throws RepositoryException If an error occurs
-     */
-    public static RepositoryConfig create(String configFilePath, String repHomeDir) throws
RepositoryException {
-        try {
-            File config = new File(configFilePath);
-            InputSource is = new InputSource(new FileReader(config));
-            is.setSystemId(config.toURI().toString());
-            return new RepositoryConfig(is, repHomeDir);
-        } catch (IOException ioe) {
-            String msg = "error while reading config file " + configFilePath;
-            log.debug(msg);
-            throw new RepositoryException(msg, ioe);
+    public synchronized WorkspaceConfig createWorkspaceConfig(String name)
+            throws RepositoryException {
+        if (wspConfigs.containsKey(name)) {
+            String msg = "A workspace with the specified name alreay exists";
+            throw new RepositoryException(msg);
         }
-    }
-
-    /**
-     * Creates a new <code>RepositoryConfig</code> instance. The configuration
-     * is read from the specified input source.
-     *
-     * @param is         <code>InputSource</code> where the configuration is
read from
-     * @param repHomeDir repository home directory
-     * @return a new <code>RepositoryConfig</code> instance
-     * @throws RepositoryException If an error occurs
-     */
-    public static RepositoryConfig create(InputSource is, String repHomeDir) throws RepositoryException
{
-        return new RepositoryConfig(is, repHomeDir);
+        WorkspaceConfig wspConfig =
+            parser.createWorkspaceConfig(config, wspConfigRootDir, name);
+        wspConfigs.put(name, wspConfig);
+        return wspConfig;
     }
 
     /**
@@ -330,65 +201,6 @@
      */
     public AccessManagerConfig getAccessManagerConfig() {
         return new AccessManagerConfig(amConfig);
-    }
-
-    /**
-     * Creates a new workspace configuration with the specified name.
-     *
-     * @param name workspace name
-     * @return a new <code>WorkspaceConfig</code> object.
-     * @throws RepositoryException if the specified name already exists or
-     *                             if an error occured during the creation.
-     */
-    public synchronized WorkspaceConfig createWorkspaceConfig(String name) throws RepositoryException
{
-        if (wspConfigs.containsKey(name)) {
-            String msg = "A workspace with the specified name alreay exists";
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        // create the workspace folder (i.e. the workspace home directory)
-        File wspFolder = new File(wspConfigRootDir, name);
-        if (!wspFolder.mkdir()) {
-            String msg = "Failed to create the workspace home directory: " + wspFolder.getPath();
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        // clone the workspace definition template
-        Element wspCongigElem = (Element) config.getRootElement().getChild(WORKSPACE_ELEMENT).clone();
-        wspCongigElem.setAttribute(NAME_ATTRIB, name);
-
-        // create workspace.xml file
-/*
-        DocType docType = new DocType(WORKSPACE_ELEMENT, null, WorkspaceConfig.PUBLIC_ID);
-        Document doc = new Document(wspCongigElem, docType);
-*/
-        Document doc = new Document(wspCongigElem);
-        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
-        File configFile = new File(wspFolder, "workspace.xml");
-        FileOutputStream fos = null;
-        try {
-            fos = new FileOutputStream(configFile);
-            out.output(doc, fos);
-        } catch (IOException ioe) {
-            String msg = "Failed to create workspace configuration file: " + configFile.getPath();
-            log.debug(msg);
-            throw new RepositoryException(msg, ioe);
-        } finally {
-            if (fos != null) {
-                try {
-                    fos.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
-        }
-
-        // create workspace config object
-        WorkspaceConfig wspConfig =
-            ConfigurationParser.parseWorkspaceConfig(
-                    configFile.getPath(), configFile.getParent());
-        wspConfigs.put(name, wspConfig);
-        return wspConfig;
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java?view=diff&r1=156081&r2=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
Thu Mar  3 12:58:14 2005
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.Properties;
 
 import org.xml.sax.InputSource;
 
@@ -28,6 +29,12 @@
  */
 public class RepositoryConfigTest extends TestCase {
 
+    private ConfigurationParser parser;
+
+    protected void setUp() {
+        parser = new ConfigurationParser(new Properties());
+    }
+
     /**
      * Test that a standard repository configuration file is
      * correctly parsed.
@@ -38,7 +45,7 @@
         InputStream xml = getClass().getClassLoader().getResourceAsStream(
                 "org/apache/jackrabbit/core/config/repository.xml");
         RepositoryConfig config =
-            RepositoryConfig.create(new InputSource(xml), "target");
+            parser.parseRepositoryConfig(new InputSource(xml), "target");
 
         assertEquals("target", config.getHomeDir());
         assertEquals("default", config.getDefaultWorkspaceName());

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java?view=diff&r1=156081&r2=156082
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
Thu Mar  3 12:58:14 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.config;
 
 import java.io.InputStream;
+import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -27,6 +28,12 @@
  */
 public class WorkspaceConfigTest extends TestCase {
 
+    private ConfigurationParser parser;
+
+    protected void setUp() {
+        parser = new ConfigurationParser(new Properties());
+    }
+
     /**
      * Test that a standard workspace configuration file is
      * correctly parsed.
@@ -36,7 +43,7 @@
     public void testWorkspaceXml() throws Exception {
         InputStream xml = getClass().getClassLoader().getResourceAsStream(
                 "org/apache/jackrabbit/core/config/workspace.xml");
-        WorkspaceConfig config = ConfigurationParser.parseWorkspaceConfig(
+        WorkspaceConfig config = parser.parseWorkspaceConfig(
                 new InputSource(xml), "target");
 
         assertEquals("target", config.getHomeDir());



Mime
View raw message