chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r890340 - in /incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr: JcrConnection.java JcrFolder.java JcrObjectEntry.java JcrPropertyDefinition.java JcrRepository.java JcrType.java
Date Mon, 14 Dec 2009 14:24:08 GMT
Author: fguillaume
Date: Mon Dec 14 14:24:07 2009
New Revision: 890340

URL: http://svn.apache.org/viewvc?rev=890340&view=rev
Log:
CMIS-46: use flexible map from JCR to CMIS property names

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java?rev=890340&r1=890339&r2=890340&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
Mon Dec 14 14:24:07 2009
@@ -13,6 +13,10 @@
  * 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.
+ *
+ * Authors:
+ *     Dominique Pfister, Day
+ *     Michael Mertins, Saperion
  */
 package org.apache.chemistry.jcr;
 
@@ -84,10 +88,10 @@
                 return getRootFolder();
             } else {
                 Node node = session.getRootNode().getNode(relPath);
-                if (node.isNodeType(JcrConstants.NT_FOLDER)) {
-                    return new JcrFolder(node);
-                } else if (node.isNodeType(JcrConstants.NT_FILE)) {
+                if (JcrCmisMap.isNodeDocument(node)) {
                     return new JcrDocument(node);
+                } else {
+                    return new JcrFolder(node);
                 }
             }
         } catch (RepositoryException e) {
@@ -148,8 +152,11 @@
     }
 
     public ObjectEntry newObjectEntry(String typeId) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        if (JcrCmisMap.isBaseTypeDocument(typeId)) {
+            return new JcrDocument();
+        } else {
+            return new JcrFolder();
+        }
     }
 
     public ObjectId newObjectId(String id) {
@@ -291,10 +298,10 @@
             SimpleListPage<ObjectEntry> result = new SimpleListPage<ObjectEntry>();
             while (result.size() < maxItems && iter.hasNext()) {
                 Node child = iter.nextNode();
-                if (child.isNodeType(JcrConstants.NT_FOLDER)) {
-                    result.add(new JcrFolder(child));
-                } else if (child.isNodeType(JcrConstants.NT_FILE)) {
+                if (JcrCmisMap.isNodeDocument(child)) {
                     result.add(new JcrDocument(child));
+                } else {
+                    result.add(new JcrFolder(child));
                 }
             }
             result.setHasMoreItems(iter.hasNext());
@@ -360,10 +367,10 @@
                 return (ObjectEntry) getRootFolder();
             } else {
                 Node node = session.getRootNode().getNode(relPath);
-                if (node.isNodeType(JcrConstants.NT_FOLDER)) {
-                    return new JcrFolder(node);
-                } else if (node.isNodeType(JcrConstants.NT_FILE)) {
+                if (JcrCmisMap.isNodeDocument(node)) {
                     return new JcrDocument(node);
+                } else {
+                    return new JcrFolder(node);
                 }
             }
         } catch (RepositoryException e) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java?rev=890340&r1=890339&r2=890340&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrFolder.java
Mon Dec 14 14:24:07 2009
@@ -13,6 +13,10 @@
  * 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.
+ *
+ * Authors:
+ *     Dominique Pfister, Day
+ *     Michael Mertins, Saperion
  */
 package org.apache.chemistry.jcr;
 
@@ -58,12 +62,10 @@
             while (iter.hasNext()) {
                 Node child = iter.nextNode();
                 CMISObject entry = null;
-                if (child.isNodeType(JcrConstants.NT_FOLDER)) {
-                    entry = new JcrFolder(child);
-                } else if (child.isNodeType(JcrConstants.NT_FILE)) {
+                if (JcrCmisMap.isNodeDocument(child)) {
                     entry = new JcrDocument(child);
                 } else {
-                    continue;
+                    entry = new JcrFolder(child);
                 }
                 result.add(entry);
             }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java?rev=890340&r1=890339&r2=890340&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
Mon Dec 14 14:24:07 2009
@@ -13,6 +13,10 @@
  * 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.
+ *
+ * Authors:
+ *     Dominique Pfister, Day
+ *     Michael Mertins, Saperion
  */
 package org.apache.chemistry.jcr;
 
@@ -69,7 +73,7 @@
 
     public Boolean getBoolean(String id) {
         try {
-            return Boolean.valueOf(node.getProperty(id).getBoolean());
+            return Boolean.valueOf(node.getProperty(JcrCmisMap.cmisToJcr(id)).getBoolean());
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -81,7 +85,7 @@
 
     public Boolean[] getBooleans(String id) {
         try {
-            Value[] values = node.getProperty(id).getValues();
+            Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
             Boolean[] result = new Boolean[values.length];
             for (int i = 0; i < values.length; i++) {
                 result[i] = Boolean.valueOf(values[i].getBoolean());
@@ -114,7 +118,7 @@
 
     public Calendar getDateTime(String id) {
         try {
-            return node.getProperty(id).getDate();
+            return node.getProperty(JcrCmisMap.cmisToJcr(id)).getDate();
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -126,7 +130,7 @@
 
     public Calendar[] getDateTimes(String id) {
         try {
-            Value[] values = node.getProperty(id).getValues();
+            Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
             Calendar[] result = new Calendar[values.length];
             for (int i = 0; i < values.length; i++) {
                 result[i] = values[i].getDate();
@@ -143,7 +147,7 @@
 
     public BigDecimal getDecimal(String id) {
         try {
-            return new BigDecimal(node.getProperty(id).getDouble());
+            return new BigDecimal(node.getProperty(JcrCmisMap.cmisToJcr(id)).getDouble());
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -155,7 +159,7 @@
 
     public BigDecimal[] getDecimals(String id) {
         try {
-            Value[] values = node.getProperty(id).getValues();
+            Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
             BigDecimal[] result = new BigDecimal[values.length];
             for (int i = 0; i < values.length; i++) {
                 result[i] = new BigDecimal(values[i].getDouble());
@@ -188,7 +192,7 @@
 
     public String getId(String id) {
         try {
-            javax.jcr.Property prop = node.getProperty(id);
+            javax.jcr.Property prop = node.getProperty(JcrCmisMap.cmisToJcr(id));
             return getItemId(prop);
         } catch (PathNotFoundException e) {
             /* property does not exist */
@@ -215,7 +219,7 @@
 
     public Integer getInteger(String id) {
         try {
-            return Integer.valueOf((int) node.getProperty(id).getLong());
+            return Integer.valueOf((int) node.getProperty(JcrCmisMap.cmisToJcr(id)).getLong());
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -227,7 +231,7 @@
 
     public Integer[] getIntegers(String id) {
         try {
-            Value[] values = node.getProperty(id).getValues();
+            Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
             Integer[] result = new Integer[values.length];
             for (int i = 0; i < values.length; i++) {
                 result[i] = Integer.valueOf((int) values[i].getLong());
@@ -295,7 +299,7 @@
 
     public Property getProperty(String id) {
         try {
-            return new JcrProperty(node.getProperty(id));
+            return new JcrProperty(node.getProperty(JcrCmisMap.cmisToJcr(id)));
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -315,7 +319,7 @@
 
     public String getString(String id) {
         try {
-            return node.getProperty(id).getString();
+            return node.getProperty(JcrCmisMap.cmisToJcr(id)).getString();
         } catch (PathNotFoundException e) {
             /* property does not exist */
         } catch (RepositoryException e) {
@@ -327,7 +331,7 @@
 
     public String[] getStrings(String id) {
         try {
-            Value[] values = node.getProperty(id).getValues();
+            Value[] values = node.getProperty(JcrCmisMap.cmisToJcr(id)).getValues();
             String[] result = new String[values.length];
             for (int i = 0; i < values.length; i++) {
                 result[i] = values[i].getString();
@@ -365,11 +369,23 @@
     }
 
     public Serializable getValue(String id) {
+        String name = JcrCmisMap.cmisToJcr(id);
         try {
-            if (node.hasProperty(id)) {
-                Value value = node.getProperty(id).getValue();
-                if (value instanceof Serializable) {
-                    return (Serializable) value;
+            if (node.hasProperty(name)) {
+                if (JcrCmisMap.isArray(name)) {
+                    // TODO: Array handling doesn't work yet
+                    // i.e. for (Value v : node.getProperty(name).getValues();
+                } else {
+                    Value value = node.getProperty(name).getValue();
+                    if (JcrCmisMap.isDate(name)) {
+                        return value.getDate();
+                    } else if (JcrCmisMap.isBool(name)) {
+                        return value.getBoolean();
+                    } else if (JcrCmisMap.isInt(name)) {
+                        return value.getLong();
+                    } else {
+                        return value.getString();
+                    }
                 }
             }
         } catch (PathNotFoundException e) {
@@ -385,7 +401,7 @@
         Map<String, Serializable> values = new HashMap<String, Serializable>();
         for (PropertyDefinition def : getType().getPropertyDefinitions()) {
             String id = def.getId();
-            values.put(id, getValue(id));
+            values.put(JcrCmisMap.cmisToJcr(id), getValue(id));
         }
         return values;
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java?rev=890340&r1=890339&r2=890340&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrPropertyDefinition.java
Mon Dec 14 14:24:07 2009
@@ -13,6 +13,10 @@
  * 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.
+ *
+ * Authors:
+ *     Dominique Pfister, Day
+ *     Michael Mertins, Saperion
  */
 package org.apache.chemistry.jcr;
 
@@ -20,6 +24,8 @@
 import java.net.URI;
 import java.util.List;
 
+import javax.jcr.Value;
+
 import org.apache.chemistry.Choice;
 import org.apache.chemistry.PropertyDefinition;
 import org.apache.chemistry.PropertyType;
@@ -39,20 +45,26 @@
     }
 
     public Serializable getDefaultValue() {
-        // TODO Auto-generated method stub
+        try {
+            Value[] values = propDef.getDefaultValues();
+            return values[0].getString();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
         return null;
     }
 
     public String getDescription() {
-        return propDef.getName();
+        return JcrCmisMap.jcrToCmis(propDef.getName());
     }
 
     public String getDisplayName() {
-        return propDef.getName();
+        return JcrCmisMap.jcrToCmis(propDef.getName());
     }
 
     public String getId() {
-        return propDef.getName();
+        return JcrCmisMap.jcrToCmis(propDef.getName());
     }
 
     public String getLocalName() {
@@ -79,7 +91,7 @@
     }
 
     public String getQueryName() {
-        return propDef.getName();
+        return JcrCmisMap.jcrToCmis(propDef.getName());
     }
 
     public int getPrecision() {
@@ -94,30 +106,31 @@
 
     public PropertyType getType() {
         switch (propDef.getRequiredType()) {
-            case javax.jcr.PropertyType.STRING:
-                return PropertyType.STRING;
-            case javax.jcr.PropertyType.LONG:
-                return PropertyType.INTEGER;
-            case javax.jcr.PropertyType.DOUBLE:
-                return PropertyType.DECIMAL;
-            case javax.jcr.PropertyType.DATE:
-                return PropertyType.DATETIME;
-            case javax.jcr.PropertyType.BOOLEAN:
-                return PropertyType.BOOLEAN;
-            case javax.jcr.PropertyType.REFERENCE:
-                return PropertyType.ID;
-            case javax.jcr.PropertyType.NAME:
-            case javax.jcr.PropertyType.BINARY:
-            case javax.jcr.PropertyType.PATH:
-            case javax.jcr.PropertyType.UNDEFINED:
-                return PropertyType.STRING;
-            default:
-                return null;
+        case javax.jcr.PropertyType.STRING:
+            return PropertyType.STRING;
+        case javax.jcr.PropertyType.LONG:
+            return PropertyType.INTEGER;
+        case javax.jcr.PropertyType.DOUBLE:
+            return PropertyType.DECIMAL;
+        case javax.jcr.PropertyType.DATE:
+            return PropertyType.DATETIME;
+        case javax.jcr.PropertyType.BOOLEAN:
+            return PropertyType.BOOLEAN;
+        case javax.jcr.PropertyType.REFERENCE:
+            return PropertyType.ID;
+        case javax.jcr.PropertyType.NAME:
+        case javax.jcr.PropertyType.BINARY:
+        case javax.jcr.PropertyType.PATH:
+        case javax.jcr.PropertyType.UNDEFINED:
+            return PropertyType.STRING;
+        default:
+            return null;
         }
     }
 
     public Updatability getUpdatability() {
-        return propDef.isProtected() ? Updatability.READ_ONLY : Updatability.READ_WRITE;
+        return propDef.isProtected() ? Updatability.READ_ONLY
+                : Updatability.READ_WRITE;
     }
 
     public boolean isInherited() {

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=890340&r1=890339&r2=890340&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 Dec 14 14:24:07 2009
@@ -37,15 +37,15 @@
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 
-import org.apache.chemistry.CapabilityACL;
 import org.apache.chemistry.ACLCapabilityType;
 import org.apache.chemistry.BaseType;
+import org.apache.chemistry.CapabilityACL;
 import org.apache.chemistry.CapabilityChange;
-import org.apache.chemistry.Connection;
 import org.apache.chemistry.CapabilityJoin;
-import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.CapabilityQuery;
 import org.apache.chemistry.CapabilityRendition;
+import org.apache.chemistry.Connection;
+import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.RepositoryCapabilities;
 import org.apache.chemistry.RepositoryEntry;
@@ -55,7 +55,6 @@
 import org.apache.chemistry.impl.simple.SimpleObjectId;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.JcrConstants;
 import org.w3c.dom.Document;
 
 public class JcrRepository implements Repository, RepositoryInfo,
@@ -121,7 +120,7 @@
             NodeType nt = ntmgr.getNodeType(typeId);
 
             BaseType baseType = BaseType.FOLDER;
-            if (nt.getName().equals(JcrConstants.NT_FILE)) {
+            if (JcrCmisMap.isBaseTypeDocument(nt.getName())) {
                 baseType = BaseType.DOCUMENT;
             }
             return new JcrType(nt, baseType);
@@ -181,7 +180,15 @@
     }
 
     public URI getThinClientURI() {
-        return null;
+        URI uri = null;
+        try {
+            uri = new URI(
+                    repository.getDescriptor(javax.jcr.Repository.REP_VENDOR_URL_DESC));
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            // e.printStackTrace();
+        }
+        return uri;
     }
 
     // ---------------------------------------------------------- RepositoryInfo

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java?rev=890340&r1=890339&r2=890340&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrType.java
Mon Dec 14 14:24:07 2009
@@ -13,12 +13,17 @@
  * 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.
+ *
+ * Authors:
+ *     Dominique Pfister, Day
+ *     Michael Mertins, Saperion
+ *     Florent Guillaume, Nuxeo
  */
 package org.apache.chemistry.jcr;
 
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 
 import javax.jcr.nodetype.NodeType;
 
@@ -85,13 +90,23 @@
     }
 
     public PropertyDefinition getPropertyDefinition(String id) {
-        // TODO Auto-generated method stub
+        String jcrName = JcrCmisMap.cmisToJcr(id);
+        for (javax.jcr.nodetype.PropertyDefinition prop : nodeType.getPropertyDefinitions())
{
+            if (prop.getName().equals(jcrName)) {
+                return new JcrPropertyDefinition(prop);
+            }
+        }
         return null;
     }
 
     public Collection<PropertyDefinition> getPropertyDefinitions() {
-        // TODO Auto-generated method stub
-        return Collections.emptyList();
+        javax.jcr.nodetype.PropertyDefinition[] props = nodeType.getPropertyDefinitions();
+        Collection<PropertyDefinition> result = new ArrayList<PropertyDefinition>(
+                props.length);
+        for (javax.jcr.nodetype.PropertyDefinition prop : props) {
+            result.add(new JcrPropertyDefinition(prop));
+        }
+        return result;
     }
 
     public String getQueryName() {



Mime
View raw message