chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r880738 - /incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
Date Mon, 16 Nov 2009 13:19:19 GMT
Author: fguillaume
Date: Mon Nov 16 13:19:18 2009
New Revision: 880738

URL: http://svn.apache.org/viewvc?rev=880738&view=rev
Log:
CMIS-55: make JCR node types discovered dynamically (by Michael Mertins)

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java?rev=880738&r1=880737&r2=880738&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
Mon Nov 16 13:19:18 2009
@@ -30,6 +30,7 @@
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 
 import org.apache.chemistry.CapabilityACL;
@@ -132,7 +133,6 @@
     public List<Type> getTypes(String typeId, int depth,
             boolean returnPropertyDefinitions) {
 
-        // TODO dynamically discover and return types.
         // TODO depth, returnPropertyDefinitions
 
         try {
@@ -144,14 +144,24 @@
 
             Session session = repository.login(creds, workspace);
 
-            // TODO fetch the types only once, include other types
-            NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();
-            result.add(new JcrType(ntmgr.getNodeType("rep:root"),
-                    BaseType.FOLDER));
-            result.add(new JcrType(ntmgr.getNodeType(JcrConstants.NT_FOLDER),
-                    BaseType.FOLDER));
-            result.add(new JcrType(ntmgr.getNodeType(JcrConstants.NT_FILE),
-                    BaseType.DOCUMENT));
+            NodeTypeIterator nodeTypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes();
+            while (nodeTypes.hasNext()) {
+                NodeType nodeType = nodeTypes.nextNodeType();
+                if (nodeType.isMixin()) {
+                    // Mixing Types will be ignored
+                    continue;
+                }
+                BaseType baseType = BaseType.FOLDER;
+                if (nodeType.getName().equals(JcrConstants.NT_FILE)) {
+                    baseType = BaseType.DOCUMENT;
+                }
+                // If typeId is provided, only the specific type and its
+                // descendants are returned, otherwise all types are returned.
+                if (typeId == null || typeId.equals(baseType.getId())) {
+                    result.add(new JcrType(nodeType, baseType));
+                }
+            }
+
             return result;
         } catch (RepositoryException e) {
             String msg = "Unable to retrieve node types.";



Mime
View raw message