chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1082139 [3/3] - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr: ./ util/
Date Wed, 16 Mar 2011 12:46:36 GMT
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java?rev=1082139&r1=1082138&r2=1082139&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java Wed Mar 16 12:46:36 2011
@@ -23,6 +23,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
+import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
 import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -38,6 +39,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.ServiceLoader;
 
+/**
+ * A {@link CmisServiceFactory} implementation which returns {@link JcrService} instances.  
+ */
 public class JcrServiceFactory extends AbstractServiceFactory {
     private static final Log log = LogFactory.getLog(JcrServiceFactory.class);
 
@@ -58,7 +62,7 @@ public class JcrServiceFactory extends A
     public void init(Map<String, String> parameters) {
         typeManager = new TypeManager();
         readConfiguration(parameters);
-        jcrRepository = new JcrRepository(acquireJcrRepository(jcrConfig), mountPath, typeManager);
+        jcrRepository = new JcrRepository(acquireJcrRepository(jcrConfig), mountPath, typeManager, new JcrNodeFactory());
     }
 
     @Override
@@ -79,6 +83,16 @@ public class JcrServiceFactory extends A
 
     //------------------------------------------< factories >---
 
+    /**
+     * Acquire the JCR repository given a configuration. This implementation used
+     * {@link java.util.ServiceLoader#load(Class)}  for locating <code>RepositoryFactory</code>
+     * instances. The first instance which can handle the <code>jcrConfig</code> parameters
+     * is used to acquire the repository. 
+     *
+     * @param jcrConfig  configuration determining the JCR repository to be returned
+     * @return
+     * @throws RepositoryException
+     */
     protected Repository acquireJcrRepository(Map<String, String> jcrConfig) {
         try {
             for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
@@ -100,6 +114,14 @@ public class JcrServiceFactory extends A
         }
     }
 
+    /**
+     * Create a <code>JcrService</code> from a <code>JcrRepository</code>JcrRepository> and
+     * <code>CallContext</code>.
+     * 
+     * @param jcrRepository
+     * @param context
+     * @return
+     */
     protected JcrService createJcrService(JcrRepository jcrRepository, CallContext context) {
         return new JcrService(jcrRepository);
     }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr;
+
+import org.apache.chemistry.opencmis.commons.enums.Action;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import java.util.Set;
+
+/**
+ * Instances of this class represent a non versionable cmis:document backed by an underlying JCR <code>Node</code>. 
+ */
+public class JcrUnversionedDocument extends JcrDocument {
+    private static final Log log = LogFactory.getLog(JcrUnversionedDocument.class);
+    
+    public JcrUnversionedDocument(Node node, TypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
+        super(node, typeManager, pathManager, nodeFactory);
+    }
+
+    //------------------------------------------< protected >--- 
+
+    @Override
+    protected Node getContextNode() throws RepositoryException {
+        return getNode().getNode(Node.JCR_CONTENT);
+    }
+
+    @Override
+    protected Set<Action> compileAllowableActions(Set<Action> aas) {
+        Set<Action> result = super.compileAllowableActions(aas);
+        setAction(result, Action.CAN_GET_ALL_VERSIONS, false);
+        setAction(result, Action.CAN_CHECK_OUT, false);
+        setAction(result, Action.CAN_CANCEL_CHECK_OUT, false);
+        setAction(result, Action.CAN_CHECK_IN, false);
+        return result;
+    }
+
+    @Override
+    protected String getTypeIdInternal() {
+        return TypeManager.DOCUMENT_UNVERSIONED_TYPE_ID;
+    }
+
+    @Override
+    protected boolean isLatestVersion() {
+        return true;
+    }
+
+    @Override
+    protected boolean isMajorVersion() {
+        return true;
+    }
+
+    @Override
+    protected boolean isLatestMajorVersion() {
+        return true;
+    }
+
+    @Override
+    protected String getVersionLabel() {
+        return "0.0";
+    }
+
+    @Override
+    protected boolean isCheckedOut() {
+        return false;
+    }
+
+    @Override
+    protected String getCheckedOutId() {
+        return null;   
+    }
+
+    @Override
+    protected String getCheckedOutBy() throws RepositoryException {
+        return null;
+    }
+
+    @Override
+    protected String getCheckInComment() {
+        return "";   
+    }
+
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Instances of this class represent a specific version of a cmis:document backed by an underlying
+ * JCR <code>Node</code>.
+ */
+public class JcrVersion extends JcrVersionBase {
+    private static final Log log = LogFactory.getLog(JcrVersion.class);
+
+    private static final Pattern VERSION_LABEL_PATTERN = Pattern.compile("(\\d+)(\\.(\\d+))?.*");
+    private static final int GROUP_MAJOR = 1;
+    private static final int GROUP_MINOR = 3;
+
+    private final Version version;
+
+    public JcrVersion(Node node, Version version, TypeManager typeManager, PathManager pathManager,
+            JcrNodeFactory nodeFactory) {
+
+        super(node, typeManager, pathManager, nodeFactory);
+        this.version = version;
+    }
+
+    //------------------------------------------< protected >---
+
+    @Override
+    protected Node getContextNode() throws RepositoryException {
+        Node frozen = version.getFrozenNode();
+        if (frozen.hasNode(Node.JCR_CONTENT)) {
+            return frozen.getNode(Node.JCR_CONTENT);
+        }
+        else {
+            return getNode().getNode(Node.JCR_CONTENT);  // root version
+        }
+    }
+    
+    @Override
+    protected String getObjectId() throws RepositoryException {
+        return getVersionSeriesId() + '/' + version.getName();
+    }
+
+    @Override
+    protected boolean isLatestVersion() throws RepositoryException {
+        Version baseVersion = getBaseVersion(getNode());
+        return baseVersion.isSame(version);
+    }
+
+    @Override
+    protected boolean isMajorVersion() {
+        return true;
+    }
+
+    @Override
+    protected boolean isLatestMajorVersion() throws RepositoryException {
+        return isLatestVersion();
+    }
+
+    @Override
+    protected String getVersionLabel() throws RepositoryException {
+        String name = version.getName();
+        String major = parseVersion(name, GROUP_MINOR);
+
+        return major == null
+                ? name
+                : (Integer.parseInt(major) + 1) + ".0";
+    }
+
+    @Override
+    protected String getCheckInComment() throws RepositoryException {
+        // todo set checkinComment
+        return "";
+    }
+
+    //------------------------------------------< private >---
+
+    private static String parseVersion(String name, int group) {
+        Matcher matcher = VERSION_LABEL_PATTERN.matcher(name);
+        return matcher.matches()
+                ? matcher.group(group)
+                : null;
+    }
+
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr;
+
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.enums.Action;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Instances of this class represent a versionable cmis:document and its versions backed by an underlying
+ * JCR <code>Node</code>. 
+ */
+public abstract class JcrVersionBase extends JcrDocument {
+    private static final Log log = LogFactory.getLog(JcrVersionBase.class);
+
+    private final JcrNodeFactory nodeFactory;
+
+    public JcrVersionBase(Node node, TypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
+        super(node, typeManager, pathManager, nodeFactory);
+        this.nodeFactory = nodeFactory;
+    }
+
+    /**
+     * See CMIS 1.0 section 2.2.7.6 getAllVersions
+     */
+    public Iterator<JcrVersion> getVersions() {
+        try {
+            VersionHistory versionHistory = getVersionHistory(getNode());
+            final VersionIterator versions = versionHistory.getAllLinearVersions();
+
+            return new Iterator<JcrVersion>() {
+                public boolean hasNext() {
+                    return versions.hasNext();
+                }
+
+                public JcrVersion next() {
+                    return new JcrVersion(getNode(), versions.nextVersion(), typeManager, pathManager, nodeFactory);
+                }
+
+                public void remove() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+    
+    @Override
+    public void delete(boolean allVersions, boolean isPwc) {
+        Node node = getNode();
+        try {
+            if (node.isCheckedOut()) {
+                if (isPwc) {
+                    cancelCheckout(node);
+                }
+                else {
+                    throw new CmisStorageException("Cannot delete checked out document: " + getId());
+                }
+            }
+            else if (allVersions) {
+                checkout(node);
+                node.remove();
+                node.getSession().save();
+            }
+            else {
+                throw new CmisRuntimeException("Cannot delete a single version");
+            }
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * See CMIS 1.0 section 2.2.7.1 checkOut
+     *
+     * @throws CmisRuntimeException
+     */
+    public JcrPrivateWorkingCopy checkout() {
+        Node node = getNode();
+        try {
+            if (node.isCheckedOut()) {
+                throw new CmisConstraintException("Document is already checked out " + getId());
+            }
+
+            checkout(node);
+            return getPwc();
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * See CMIS 1.0 section 2.2.7.3 checkedIn
+     *
+     * @throws CmisRuntimeException
+     */
+    public JcrVersion checkin(Properties properties, ContentStream contentStream, String checkinComment) {
+        Node node = getNode();
+
+        try {
+            if (!node.isCheckedOut()) {
+                throw new CmisStorageException("Not checked out: " + getId());
+            }
+
+            if (properties != null && !properties.getPropertyList().isEmpty()) {
+                updateProperties(properties);
+            }
+
+            if (contentStream != null) {
+                setContentStream(contentStream, true);
+            }
+
+            // todo handle checkinComment
+            checkin(node);
+            return (JcrVersion) create(node);
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * See CMIS 1.0 section 2.2.7.2 cancelCheckout
+     *
+     * @throws CmisRuntimeException
+     */
+    public void cancelCheckout() {
+        Node node = getNode();
+        try {
+            cancelCheckout(node);
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Get the private working copy of the versions series or throw an exception if not checked out.
+     *
+     * @return  a {@link JcrPrivateWorkingCopy} instance
+     * @throws CmisObjectNotFoundException  if not checked out
+     * @throws CmisRuntimeException
+     */
+    public JcrPrivateWorkingCopy getPwc() {
+        try {
+            Node node = getNode();
+            if (node.isCheckedOut()) {
+                return new JcrPrivateWorkingCopy(getNode(), typeManager, pathManager, nodeFactory);
+            }
+            else {
+                throw new CmisObjectNotFoundException("Not checked out document has no private working copy");
+            }
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Get a specific version by name
+     * @param name  name of the version to get
+     * @return  a {@link JcrVersion} instance for <code>name</code>
+     * @throws CmisObjectNotFoundException  if a version <code>name</code> does not exist
+     * @throws CmisRuntimeException
+     */
+    public JcrVersion getVersion(String name) {
+        try {
+            Node node = getNode();
+            VersionHistory versionHistory = getVersionHistory(node);
+            Version version = versionHistory.getVersion(name);
+            return new JcrVersion(node, version, typeManager, pathManager, nodeFactory);
+        }
+        catch (UnsupportedRepositoryOperationException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisObjectNotFoundException(e.getMessage(), e);
+        }
+        catch (VersionException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisObjectNotFoundException(e.getMessage(), e);
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    //------------------------------------------< protected >---
+
+    /**
+     * @return  Id of the version representing the base of this verions series
+     * @throws RepositoryException
+     */
+    protected String getBaseNodeId() throws RepositoryException {
+        Version baseVersion = getBaseVersion(getNode());
+        JcrNode baseNode = new JcrVersion(getNode(), baseVersion, typeManager, pathManager, nodeFactory);
+        return baseNode.getId();
+    }
+
+    /**
+     * @return  Id of the private working copy of this version series
+     * @throws RepositoryException
+     */
+    protected String getPwcId() throws RepositoryException {
+        return null;
+    }
+    
+    @Override
+    protected void compileProperties(PropertiesImpl properties, Set<String> filter, ObjectInfoImpl objectInfo)
+            throws RepositoryException {
+
+        super.compileProperties(properties, filter, objectInfo);
+
+        objectInfo.setWorkingCopyOriginalId(getBaseNodeId());
+        objectInfo.setWorkingCopyId(getPwcId());
+    }
+
+    @Override
+    protected Set<Action> compileAllowableActions(Set<Action> aas) {
+        Set<Action> result = super.compileAllowableActions(aas);
+        setAction(result, Action.CAN_GET_ALL_VERSIONS, true);
+        setAction(result, Action.CAN_CHECK_OUT, true);
+        setAction(result, Action.CAN_CANCEL_CHECK_OUT, true);
+        setAction(result, Action.CAN_CHECK_IN, true);
+        return result;
+    }
+    
+    @Override
+    protected String getTypeIdInternal() {
+        return TypeManager.DOCUMENT_TYPE_ID;
+    }
+
+    @Override
+    protected boolean isCheckedOut() throws RepositoryException {
+        return getNode().isCheckedOut();
+    }
+
+    @Override
+    protected String getCheckedOutId() throws RepositoryException {
+        return isCheckedOut()
+                ? getVersionSeriesId() + "/pwc"
+                : null;
+    }
+
+    @Override
+    protected String getCheckedOutBy() throws RepositoryException {
+        return isCheckedOut()
+                ? getNode().getSession().getUserID()
+                : null;
+    }
+    
+    //------------------------------------------< private >---
+
+    private static void checkout(Node node) throws RepositoryException {
+        getVersionManager(node).checkout(node.getPath());
+    }
+
+    private static void checkin(Node node) throws RepositoryException {
+        getVersionManager(node).checkin(node.getPath());
+    }
+
+    private static void cancelCheckout(Node node) throws RepositoryException {
+        Version base = getBaseVersion(node);
+        getVersionManager(node).restore(base, true);
+    }
+    
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Utility class for mapping JCR paths to CMIS paths
+ */
+public class PathManager {
+    private static final Log log = LogFactory.getLog(PathManager.class);
+
+    /**
+     * Identifier of the root folder
+     */
+    public static final String CMIS_ROOT_ID = "[root]";
+
+    /**
+     * Root path
+     */
+    public static final String CMIS_ROOT_PATH = "/";
+
+    private final String jcrRootPath;
+
+    /**
+     * Create a new <code>PathManager</code> instance for the given JCR root path.
+     * @param jcrRootPath
+     */
+    public PathManager(String jcrRootPath) {
+        this.jcrRootPath = normalize(jcrRootPath);
+    }
+
+    /**
+     * @return  the JCR root path
+     */
+    public String getJcrRootPath() {
+        return jcrRootPath;
+    }
+
+    /**
+     * Determines whether a JCR <code>Node</code> is the root node wrt. to this
+     * <code>PathManager</code> instance. That is, whether the path of the node is
+     * equal to this instance's JCR root path.
+     * 
+     * @param node
+     * @return  <code>true</code> iff <code>node</code> is the root node wrt. to
+     *      this <code>PathManager</code> instance.
+     */
+    public boolean isRoot(Node node) {
+        try {
+            return node.getPath().equals(jcrRootPath);
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Determine the CMIS path given a JCR <code>Node</code>.
+     *
+     * @param node
+     * @return
+     * @throws IllegalArgumentException  when <code>node</code> is not part of the hierarchy
+     */
+    public String getPath(Node node) {
+        try {
+            if (jcrRootPath.length() > node.getPath().length()) {
+                throw new IllegalArgumentException("Node is not part of the hierarchy: " + node.getPath());
+            }
+
+            String path = node.getPath().substring(jcrRootPath.length());
+            return path.startsWith("/") ? path : '/' + path;
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisRuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * @param cmisPath
+     * @return  <code>true</code> iff <code>cmisPath</code> equals {@link PathManager#CMIS_ROOT_PATH}
+     */
+    public static boolean isRoot(String cmisPath) {
+        return CMIS_ROOT_PATH.equals(cmisPath);
+    }
+
+    /**
+     * @param cmisPath
+     * @return  <code>true</code> iff <code>cmisPath</code>
+     */
+    public static boolean isAbsolute(String cmisPath) {
+        return cmisPath.startsWith(CMIS_ROOT_PATH);
+    }
+
+    /**
+     * Create a CMIS path from a parent path and a child element
+     * @param cmisPath  parent path
+     * @param child  child element
+     * @return
+     */
+    public static String createCmisPath(String cmisPath, String child) {
+        return cmisPath.length() > 0 && cmisPath.charAt(cmisPath.length() - 1) == '/'
+                ? cmisPath + child
+                : cmisPath + '/' + child;
+    }
+
+    /**
+     * Relativize an CMIS path wrt. to a prefix.  
+     * @param prefix
+     * @param cmisPath
+     * @return  a string <code>r</code> such that <code>prefix</code> + <code>r</code> = <code>cmisPath</code> 
+     * @throws IllegalArgumentException  if <code>prefix</code> is not a prefix of <code>cmisPath</code>
+     */
+    public static String relativize(String prefix, String cmisPath) {
+        if (cmisPath.startsWith(prefix)) {
+            return cmisPath.substring(prefix.length());
+        }
+        else {
+            throw new IllegalArgumentException(prefix + " is not a prefix of " + cmisPath);
+        }
+    }
+
+    //------------------------------------------< private >---
+
+    private static String normalize(String path) {
+        if (path == null || path.length() == 0) {
+            return "/";
+        }
+
+        if (!path.startsWith("/")) {
+            throw new CmisInvalidArgumentException("Root path must be absolute. Got: " + path);
+        }
+
+        while (path.length() > 1 && path.endsWith("/")) {
+            path = path.substring(0, path.length() - 1);
+        }
+        return path;
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PropertyHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PropertyHelper.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PropertyHelper.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PropertyHelper.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.data.PropertyString;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * Helper class with utility functions for handling {@link Properties}.
+ */
+public final class PropertyHelper {
+    private PropertyHelper() {
+    }
+
+    /**
+     * Retrieve a string value.
+     *
+     * @param properties
+     * @param name  the name of the value to retrieve
+     * @return  the first value of the given <code>name</code> or <code>null</code> if either
+     *      these are no string properties or no property of <code>name</code> exists. 
+     */
+    public static String getStringProperty(Properties properties, String name) {
+        PropertyData<?> property = properties.getProperties().get(name);
+        if (!(property instanceof PropertyString)) {
+            return null;
+        }
+
+        return ((PropertyString) property).getFirstValue();
+    }
+
+    /**
+     * Gets the type id from a set of properties.
+     */
+    public static String getTypeId(Properties properties) {
+        PropertyData<?> typeProperty = properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
+        if (!(typeProperty instanceof PropertyId)) {
+            throw new CmisInvalidArgumentException("Type id must be set!");
+        }
+
+        String typeId = ((PropertyId) typeProperty).getFirstValue();
+        if (typeId == null) {
+            throw new CmisInvalidArgumentException("Type id must be set!");
+        }
+
+        return typeId;
+    }
+
+    /**
+     * @param prop
+     * @return  <code>true</code> iff <code>prop</code> denotes an empty property data value
+     */
+    public static boolean isPropertyEmpty(PropertyData<?> prop) {
+        return prop == null || prop.getValues() == null || prop.getValues().isEmpty();
+    }
+
+    /**
+     * Determine the default property data value for a given property definition.
+     * @param propDef
+     * @return
+     * @throws CmisRuntimeException  if <code>propDef</code> is invalid or unknown.
+     */
+    @SuppressWarnings("unchecked")
+    public static PropertyData<?> getDefaultValue(PropertyDefinition<?> propDef) {
+        if (propDef == null) {
+            return null;
+        }
+
+        List<?> defaultValue = propDef.getDefaultValue();
+        if (defaultValue != null && !defaultValue.isEmpty()) {
+            switch (propDef.getPropertyType()) {
+                case BOOLEAN:
+                    return new PropertyBooleanImpl(propDef.getId(), (List<Boolean>) defaultValue);
+                case DATETIME:
+                    return new PropertyDateTimeImpl(propDef.getId(), (List<GregorianCalendar>) defaultValue);
+                case DECIMAL:
+                    return new PropertyDecimalImpl(propDef.getId(), (List<BigDecimal>) defaultValue);
+                case HTML:
+                    return new PropertyHtmlImpl(propDef.getId(), (List<String>) defaultValue);
+                case ID:
+                    return new PropertyIdImpl(propDef.getId(), (List<String>) defaultValue);
+                case INTEGER:
+                    return new PropertyIntegerImpl(propDef.getId(), (List<BigInteger>) defaultValue);
+                case STRING:
+                    return new PropertyStringImpl(propDef.getId(), (List<String>) defaultValue);
+                case URI:
+                    return new PropertyUriImpl(propDef.getId(), (List<String>) defaultValue);
+                default:
+                    throw new CmisRuntimeException("Unknown datatype: " + propDef.getPropertyType());
+            }
+        }
+        return null;
+    }
+
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/TypeManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/TypeManager.java?rev=1082139&r1=1082138&r2=1082139&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/TypeManager.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/TypeManager.java Wed Mar 16 12:46:36 2011
@@ -19,6 +19,7 @@
 package org.apache.chemistry.opencmis.jcr;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
@@ -61,6 +62,7 @@ public class TypeManager {
     private static final Log log = LogFactory.getLog(TypeManager.class);
 
     public static final String DOCUMENT_TYPE_ID = "cmis:document";
+    public static final String DOCUMENT_UNVERSIONED_TYPE_ID = "cmis:unversioned-document";
     public static final String FOLDER_TYPE_ID = "cmis:folder";
     public static final String RELATIONSHIP_TYPE_ID = "cmis:relationship";
     public static final String POLICY_TYPE_ID = "cmis:policy";
@@ -109,13 +111,32 @@ public class TypeManager {
         documentType.setIsQueryable(false);
         documentType.setQueryName("cmis:document");
         documentType.setId(DOCUMENT_TYPE_ID);
-        documentType.setIsVersionable(false);
+        documentType.setIsVersionable(true);
         documentType.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
 
         addBasePropertyDefinitions(documentType);
         addDocumentPropertyDefinitions(documentType);
 
         addTypeInternal(documentType);
+
+        // non versionable document type
+        DocumentTypeDefinitionImpl unversionedDocument = new DocumentTypeDefinitionImpl();
+        unversionedDocument.initialize(documentType);
+
+        unversionedDocument.setDescription("Unversioned document");
+        unversionedDocument.setDisplayName("Unversioned document");
+        unversionedDocument.setLocalName("Unversioned document");
+        unversionedDocument.setQueryName("cmis:unversioned-document");
+        unversionedDocument.setId(DOCUMENT_UNVERSIONED_TYPE_ID);
+        unversionedDocument.setParentTypeId(DOCUMENT_TYPE_ID);
+
+        unversionedDocument.setIsVersionable(false);
+        unversionedDocument.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
+
+        addBasePropertyDefinitions(unversionedDocument);
+        addDocumentPropertyDefinitions(unversionedDocument);
+
+        addTypeInternal(unversionedDocument);
     }
 
     /**
@@ -167,9 +188,9 @@ public class TypeManager {
     }
 
     /**
-     * CMIS getTypesChildren.
+     * See CMIS 1.0 section 2.2.2.3 getTypeChildren
      */
-    public TypeDefinitionList getTypesChildren(String typeId, boolean includePropertyDefinitions,
+    public TypeDefinitionList getTypeChildren(String typeId, boolean includePropertyDefinitions,
             BigInteger maxItems, BigInteger skipCount) {
 
         TypeDefinitionListImpl result = new TypeDefinitionListImpl(new ArrayList<TypeDefinition>());
@@ -231,7 +252,7 @@ public class TypeManager {
     }
 
     /**
-     * CMIS getTypesDescendants.
+     * See CMIS 1.0 section 2.2.2.4 getTypeDescendants
      */
     public List<TypeDefinitionContainer> getTypesDescendants(String typeId, BigInteger depth,
             Boolean includePropertyDefinitions) {
@@ -270,6 +291,12 @@ public class TypeManager {
         return copyTypeDefintion(tc.getTypeDefinition());
     }
 
+    public static boolean isVersionable(TypeDefinition typeDef) {
+        return typeDef instanceof DocumentTypeDefinition
+                ? ((DocumentTypeDefinition) typeDef).isVersionable()
+                : false;
+    }
+
     //------------------------------------------< internal >---
 
     /**
@@ -282,8 +309,8 @@ public class TypeManager {
         return tc == null ? null : tc.getTypeDefinition();
     }
 
-    //------------------------------------------< private >--- 
-    
+    //------------------------------------------< private >---
+
     private static void addBasePropertyDefinitions(AbstractTypeDefinition type) {
         type.addPropertyDefinition(createPropDef(PropertyIds.BASE_TYPE_ID, "Base Type Id", "Base Type Id",
                 PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, false, true));
@@ -487,5 +514,4 @@ public class TypeManager {
     private static TypeDefinition copyTypeDefintion(TypeDefinition type) {
         return Converter.convert(Converter.convert(type));
     }
-
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/Util.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/Util.java?rev=1082139&r1=1082138&r2=1082139&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/Util.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/Util.java Wed Mar 16 12:46:36 2011
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.chemistry.opencmis.jcr;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-
-public final class Util {
-    private Util() {}
-
-    public static GregorianCalendar toCalendar(Calendar date) {
-        if (date instanceof GregorianCalendar) {
-            return (GregorianCalendar) date;
-        }
-        else {
-            GregorianCalendar calendar = new GregorianCalendar();
-            calendar.setTimeZone(date.getTimeZone());
-            calendar.setTimeInMillis(date.getTimeInMillis());
-            return calendar;
-        }
-    }
-}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/FilterIterator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/FilterIterator.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/FilterIterator.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/FilterIterator.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Iterator filtering out items which do not match a given predicate.
+ * @param <T>
+ */
+public class FilterIterator<T> implements Iterator<T> {
+    private final Iterator<T> iterator;
+    private final Predicate<T> predicate;
+
+    private T next;
+
+    /**
+     * Create a new filtered iterator based on the given <code>iterator</code>.
+     *
+     * @param iterator  iterator to filter
+     * @param predicate  only item matching this predicate are included
+     */
+    public FilterIterator(Iterator<T> iterator, Predicate<T> predicate) {
+        this.iterator = iterator;
+        this.predicate = predicate;
+    }
+
+    public boolean hasNext() {
+        while (next == null && iterator.hasNext()) {
+            T e = iterator.next();
+            if (predicate.evaluate(e)) {
+                next = e;
+            }
+        }
+
+        return next != null;
+    }
+
+    public T next() {
+        if (hasNext()) {
+            T e = next;
+            next = null;
+            return e;
+        }
+        else {
+            throw new NoSuchElementException();
+        }
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr.util;
+
+/**
+ * Interface for predicates of type <code>T</code>, i.e. functions from <code>T</code>
+ * to <code>boolean</code>.
+ */
+public interface Predicate<T> {
+
+    /**
+     * Evaluates the predicate for the given object.
+     *
+     * @param t some object
+     * @return predicate result
+     */
+    boolean evaluate(T t);
+
+    /**
+     * Constant predicate that returns <code>true</code> for all objects.
+     */
+    Predicate TRUE = new Predicate<Object>() {
+        public boolean evaluate(Object object) {
+            return true;
+        }
+    };
+
+    /**
+     * Constant predicate that returns <code>false</code> for all objects.
+     */
+    Predicate FALSE = new Predicate<Object>() {
+        public boolean evaluate(Object object) {
+            return false;
+        }
+    };
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Util.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Util.java?rev=1082139&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Util.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Util.java Wed Mar 16 12:46:36 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.jcr.util;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+/**
+ * Miscellaneous utility functions
+ */
+public final class Util {
+    private Util() {}
+
+    /**
+     * Convert from <code>Calendar</code> to a <code>GregorianCalendar</code>.
+     * 
+     * @param date
+     * @return  <code>date</code> if it is an instance of <code>GregorianCalendar</code>.
+     *   Otherwise a new <code>GregorianCalendar</code> instance for <code>date</code>.
+     */
+    public static GregorianCalendar toCalendar(Calendar date) {
+        if (date instanceof GregorianCalendar) {
+            return (GregorianCalendar) date;
+        }
+        else {
+            GregorianCalendar calendar = new GregorianCalendar();
+            calendar.setTimeZone(date.getTimeZone());
+            calendar.setTimeInMillis(date.getTimeInMillis());
+            return calendar;
+        }
+    }
+
+    /**
+     * Replace every occurrence of <code>target</code> in <code>string</code> with
+     * <code>replacement</code>.
+     *
+     * @param string  string to do replacement on
+     * @param target  string to search for
+     * @param replacement  string to replace with
+     * @return  string with replacing done
+     */
+    public static String replace(String string, String target, String replacement) {
+        if ("".equals(target)) {
+            throw new IllegalArgumentException("target string must not be empty");
+        }
+        if ("".equals(replacement) || target.equals(replacement)) {
+            return string;
+        }
+
+        StringBuilder result = new StringBuilder();
+        int d = target.length();
+        int k = 0;
+        int j;
+        do {
+            j = string.indexOf(target, k);
+            if (j < 0) {
+                result.append(string.substring(k));
+            }
+            else {
+                result.append(string.substring(k, j)).append(replacement);
+            }
+
+            k = j + d;
+        } while (j >= 0);
+
+        return result.toString();
+    }
+
+}



Mime
View raw message