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/02/16 11:01:40 UTC

svn commit: r378211 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit: api/JackrabbitNodeTypeManager.java core/nodetype/NodeTypeManagerImpl.java

Author: jukka
Date: Thu Feb 16 02:01:38 2006
New Revision: 378211

URL: http://svn.apache.org/viewcvs?rev=378211&view=rev
Log:
JCR-309: Added the JackrabbitNodeTypeManager extension interface and a simple implementation in NodeTypeManagerImpl.

Added:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java   (with props)
Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java

Added: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java?rev=378211&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java (added)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java Thu Feb 16 02:01:38 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * The Jackrabbit node type manager interface. This interface contains the
+ * Jackrabbit-specific extensions to the JCR {@link NodeTypeManager} interface.
+ * <p>
+ * Currently Jackrabbit provides a mechanism to register new node types, but
+ * it is not possible to modify or remove existing node types.
+ */
+public interface JackrabbitNodeTypeManager extends NodeTypeManager {
+
+    /**
+     * The standard XML content type to be used with XML-formatted
+     * node type streams.
+     */
+    String TEXT_XML = "text/xml";
+
+    /**
+     * Registers node types from the given node type XML stream.
+     *
+     * @param in node type XML stream
+     * @return registered node types
+     * @throws SAXException if the XML stream could not be read or parsed
+     * @throws RepositoryException if the node types are invalid or another
+     *                             repository error occurs
+     */
+    NodeType[] registerNodeTypes(InputSource in)
+        throws SAXException, RepositoryException;
+
+    /**
+     * Registers node types from the given input stream of the given type.
+     *
+     * @param in node type stream
+     * @param contentType type of the input stream
+     * @return registered node types
+     * @throws IOException if the input stream could not be read or parsed
+     * @throws RepositoryException if the node types are invalid or another
+     *                             repository error occurs
+     */
+    NodeType[] registerNodeTypes(InputStream in, String contentType)
+        throws IOException, RepositoryException;
+
+}

Propchange: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java?rev=378211&r1=378210&r2=378211&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java Thu Feb 16 02:01:38 2006
@@ -22,26 +22,35 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
 import org.apache.jackrabbit.util.IteratorHelper;
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 import org.apache.jackrabbit.core.util.Dumpable;
 import org.apache.log4j.Logger;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.NodeTypeManager;
+
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * A <code>NodeTypeManagerImpl</code> implements a session dependant
  * NodeTypeManager.
  */
-public class NodeTypeManagerImpl implements NodeTypeManager, Dumpable,
-        NodeTypeRegistryListener {
+public class NodeTypeManagerImpl implements JackrabbitNodeTypeManager,
+        Dumpable, NodeTypeRegistryListener {
 
     /**
      * Logger instance for this class
@@ -286,6 +295,56 @@
             throw new NoSuchNodeTypeException(nodeTypeName, upe);
         } catch (IllegalNameException ine) {
             throw new NoSuchNodeTypeException(nodeTypeName, ine);
+        }
+    }
+
+    //--------------------------------------------< JackrabbitNodeTypeManager >
+
+    /**
+     * Registers the node types defined in the given XML stream. This is a
+     * trivial implementation that just invokes the existing
+     * {@link NodeTypeReader} and {@link NodeTypeRegistry} methods and
+     * heuristically creates the returned node type array.
+     *
+     * {@inheritDoc}
+     */
+    public NodeType[] registerNodeTypes(InputSource in)
+            throws SAXException, RepositoryException {
+        try {
+            NodeTypeDef[] defs = NodeTypeReader.read(in.getByteStream());
+            ntReg.registerNodeTypes(Arrays.asList(defs));
+
+            Set types = new HashSet();
+            for (int i = 0; i < defs.length; i++) {
+                try {
+                    types.add(getNodeType(defs[i].getName()));
+                } catch (NoSuchNodeTypeException e) {
+                    // ignore
+                }
+            }
+            return (NodeType[]) types.toArray(new NodeType[types.size()]);
+        } catch (InvalidNodeTypeDefException e) {
+            throw new RepositoryException("Invalid node type definition", e);
+        } catch (IOException e) {
+            throw new SAXException("Error reading node type stream", e);
+        }
+    }
+
+    private static final String APPLICATION_XML = "application/xml";
+
+    /** {@inheritDoc} */
+    public NodeType[] registerNodeTypes(InputStream in, String contentType)
+            throws IOException, RepositoryException {
+        if (contentType.equalsIgnoreCase(JackrabbitNodeTypeManager.TEXT_XML)
+            || contentType.equalsIgnoreCase(APPLICATION_XML)) {
+            try {
+                return registerNodeTypes(new InputSource(in));
+            } catch (SAXException e) {
+                throw new IOException(e.getMessage());
+            }
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported content type: " + contentType);
         }
     }