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 2007/01/05 14:22:42 UTC

svn commit: r493026 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config: ConfigurationEntityResolver.java ConfigurationParser.java config.dtd repository-1.0.dtd repository-1.2.dtd

Author: jukka
Date: Fri Jan  5 05:22:42 2007
New Revision: 493026

URL: http://svn.apache.org/viewvc?view=rev&rev=493026
Log:
JCR-695: Map configuration file entities to local files.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/repository-1.0.dtd
      - copied unchanged from r493009, jackrabbit/trunk/src/site/resources/dtd/repository-1.0.dtd
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/repository-1.2.dtd
      - copied unchanged from r493009, jackrabbit/trunk/src/site/resources/dtd/repository-1.2.dtd
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/config.dtd
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationParser.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java?view=diff&rev=493026&r1=493025&r2=493026
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationEntityResolver.java Fri Jan  5 05:22:42 2007
@@ -22,42 +22,68 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Entity resolver for Jackrabbit configuration files.
  * This simple resolver contains mappings for the following
- * public identifiers used for the Jackrabbit configuration files.
+ * 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>
+ * <li><code>-//The Apache Software Foundation//DTD Jackrabbit 1.0//EN</code></li>
+ * <li><code>-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN</code></li>
  * </ul>
  * <p>
- * The public identifiers are mapped to a document type definition
- * file included in the Jackrabbit jar archive.
+ * Also the following system identifiers are mapped to local resources:
+ * <ul>
+ * <li><code>http://jackrabbit.apache.org/dtd/repository-1.2.dtd</code></li>
+ * <li><code>http://jackrabbit.apache.org/dtd/repository-1.0.dtd</code></li>
+ * </ul>
+ * <p>
+ * The public identifiers are mapped to document type definition
+ * files included in the Jackrabbit jar archive.
  */
 class ConfigurationEntityResolver implements EntityResolver {
 
     /**
-     * Public identifier of the repository configuration DTD.
+     * The singleton instance of this class.
      */
-    public static final String REPOSITORY_ID =
-        "-//The Apache Software Foundation//DTD Repository//EN";
+    public static final EntityResolver INSTANCE =
+        new ConfigurationEntityResolver();
 
     /**
-     * Public identifier of the workspace configuration DTD.
+     * Public identifiers.
      */
-    public static final String WORKSPACE_ID =
-        "-//The Apache Software Foundation//DTD Workspace//EN";
+    private final Map publicIds = new HashMap();
 
     /**
-     * Resource path of the internal configuration DTD file.
+     * System identifiers.
      */
-    private static final String CONFIG_DTD =
-            "org/apache/jackrabbit/core/config/config.dtd";
+    private final Map systemIds = new HashMap();
+
+    /**
+     * Creates the singleton instance of this class.
+     */
+    private ConfigurationEntityResolver() {
+        // Apache Jackrabbit 1.2 DTD
+        publicIds.put(
+                "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN",
+                "repository-1.2.dtd");
+        systemIds.put(
+                "http://jackrabbit.apache.org/dtd/repository-1.2.dtd",
+                "repository-1.2.dtd");
+
+        // Apache Jackrabbit 1.0 DTD
+        publicIds.put(
+                "-//The Apache Software Foundation//DTD Jackrabbit 1.0//EN",
+                "repository-1.0.dtd");
+        systemIds.put(
+                "http://jackrabbit.apache.org/dtd/repository-1.0.dtd",
+                "repository-1.0.dtd");
+    }
 
     /**
      * Resolves an entity to the corresponding input source.
-     * {@inheritDoc}
      *
      * @param publicId public identifier
      * @param systemId system identifier
@@ -67,13 +93,25 @@
      */
     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;
+        String name;
+
+        name = (String) publicIds.get(publicId);
+        if (name != null) {
+            InputStream stream = getClass().getResourceAsStream(name);
+            if (stream != null) {
+                return new InputSource(stream);
+            }
         }
+
+        name = (String) systemIds.get(systemId);
+        if (name != null) {
+            InputStream stream = getClass().getResourceAsStream(name);
+            if (stream != null) {
+                return new InputSource(stream);
+            }
+        }
+
+        return null;
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationParser.java?view=diff&rev=493026&r1=493025&r2=493026
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationParser.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ConfigurationParser.java Fri Jan  5 05:22:42 2007
@@ -189,7 +189,7 @@
             DocumentBuilderFactory factory =
                 DocumentBuilderFactory.newInstance();
             DocumentBuilder builder = factory.newDocumentBuilder();
-            builder.setEntityResolver(new ConfigurationEntityResolver());
+            builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE);
             Document document = builder.parse(xml);
             return document.getDocumentElement();
         } catch (ParserConfigurationException e) {