chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1481420 [4/7] - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src: main/java/org/apache/chemistry/opencmis/server/impl/ main/java/org/apache/chemistry/opencmis/server/impl/atompub/ main/java/org/...
Date Sat, 11 May 2013 21:19:48 GMT
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java Sat May 11 21:19:48 2013
@@ -18,30 +18,6 @@
  */
 package org.apache.chemistry.opencmis.server.impl.atompub;
 
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.PAGE_SIZE;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_BULK_UPDATE;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHANGES;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHECKEDOUT;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CHILDREN;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_DESCENDANTS;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_FOLDERTREE;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_OBJECTBYID;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_OBJECTBYPATH;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_QUERY;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_TYPE;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_TYPES;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_TYPESDESC;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_UNFILED;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.TYPE_AUTHOR;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrlBuilder;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.getNamespaces;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.writeTypeEntry;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
-
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.GregorianCalendar;
@@ -68,436 +44,446 @@ import org.apache.chemistry.opencmis.ser
 /**
  * Repository Service operations.
  */
-public final class RepositoryService {
-
-    /**
-     * Private constructor.
-     */
-    private RepositoryService() {
-    }
+public class RepositoryService {
 
     /**
      * Renders the service document.
      */
-    public static void getRepositories(CallContext context, CmisService service, HttpServletRequest request,
-            HttpServletResponse response) throws Exception {
-        // get parameters
-        String repositoryId = getStringParameter(request, Constants.PARAM_REPOSITORY_ID);
-
-        // execute
-        List<RepositoryInfo> infoDataList = null;
-
-        if (repositoryId == null) {
-            infoDataList = service.getRepositoryInfos(null);
-        } else {
-            infoDataList = Collections.singletonList(service.getRepositoryInfo(repositoryId, null));
-            if (context instanceof CallContextImpl) {
-                ((CallContextImpl) context).put(CallContext.REPOSITORY_ID, repositoryId);
-            }
-        }
-
-        // set headers
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_SERVICE);
-
-        // write XML
-        ServiceDocument serviceDoc = new ServiceDocument();
-
-        serviceDoc.startDocument(response.getOutputStream(), getNamespaces(service));
-        serviceDoc.startServiceDocument();
-
-        if (infoDataList != null) {
-            CmisVersion cmisVersion = context.getCmisVersion();
-            for (RepositoryInfo infoData : infoDataList) {
-                if (infoData == null) {
-                    continue;
+    public static class GetRepositories extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            repositoryId = getStringParameter(request, Constants.PARAM_REPOSITORY_ID);
+
+            // execute
+            List<RepositoryInfo> infoDataList = null;
+
+            if (repositoryId == null) {
+                infoDataList = service.getRepositoryInfos(null);
+            } else {
+                infoDataList = Collections.singletonList(service.getRepositoryInfo(repositoryId, null));
+                if (context instanceof CallContextImpl) {
+                    ((CallContextImpl) context).put(CallContext.REPOSITORY_ID, repositoryId);
                 }
+            }
 
-                String repId = infoData.getId();
-                UrlBuilder baseUrl = compileBaseUrl(request, repId);
-
-                boolean supportsQuery = false;
-                boolean supportsUnFiling = false;
-                boolean supportsMultifiling = false;
-                boolean supportsFolderTree = false;
-                boolean supportsRootDescendants = false;
-                boolean supportsChanges = false;
+            // set headers
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_SERVICE);
+
+            // write XML
+            ServiceDocument serviceDoc = new ServiceDocument();
+
+            serviceDoc.startDocument(response.getOutputStream(), getNamespaces(service));
+            serviceDoc.startServiceDocument();
+
+            if (infoDataList != null) {
+                CmisVersion cmisVersion = context.getCmisVersion();
+                for (RepositoryInfo infoData : infoDataList) {
+                    if (infoData == null) {
+                        continue;
+                    }
 
-                if (infoData.getCapabilities() != null) {
-                    RepositoryCapabilities cap = infoData.getCapabilities();
+                    String repId = infoData.getId();
+                    UrlBuilder baseUrl = compileBaseUrl(request, repId);
 
-                    if (cap.getQueryCapability() != null) {
-                        supportsQuery = (cap.getQueryCapability() != CapabilityQuery.NONE);
+                    boolean supportsQuery = false;
+                    boolean supportsUnFiling = false;
+                    boolean supportsMultifiling = false;
+                    boolean supportsFolderTree = false;
+                    boolean supportsRootDescendants = false;
+                    boolean supportsChanges = false;
+
+                    if (infoData.getCapabilities() != null) {
+                        RepositoryCapabilities cap = infoData.getCapabilities();
+
+                        if (cap.getQueryCapability() != null) {
+                            supportsQuery = (cap.getQueryCapability() != CapabilityQuery.NONE);
+                        }
+
+                        if (cap.isUnfilingSupported() != null) {
+                            supportsUnFiling = cap.isUnfilingSupported();
+                        }
+
+                        if (cap.isMultifilingSupported() != null) {
+                            supportsMultifiling = cap.isMultifilingSupported();
+                        }
+
+                        if (cap.isGetFolderTreeSupported() != null) {
+                            supportsFolderTree = cap.isGetFolderTreeSupported();
+                        }
+
+                        if (cap.isGetDescendantsSupported() != null) {
+                            supportsRootDescendants = cap.isGetDescendantsSupported();
+                        }
+
+                        if (cap.getChangesCapability() != null) {
+                            supportsChanges = (cap.getChangesCapability() != CapabilityChanges.NONE);
+                        }
                     }
 
-                    if (cap.isUnfilingSupported() != null) {
-                        supportsUnFiling = cap.isUnfilingSupported();
-                    }
+                    serviceDoc.startWorkspace(infoData.getId());
 
-                    if (cap.isMultifilingSupported() != null) {
-                        supportsMultifiling = cap.isMultifilingSupported();
-                    }
+                    // add collections
 
-                    if (cap.isGetFolderTreeSupported() != null) {
-                        supportsFolderTree = cap.isGetFolderTreeSupported();
+                    // - root collection
+                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_CHILDREN, infoData.getRootFolderId()),
+                            Constants.COLLECTION_ROOT, "Root Collection", Constants.MEDIATYPE_ENTRY,
+                            Constants.MEDIATYPE_CMISATOM);
+
+                    // - types collection
+                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_TYPES, null), Constants.COLLECTION_TYPES,
+                            "Types Collection", "");
+
+                    // - query collection
+                    if (supportsQuery) {
+                        serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_QUERY, null),
+                                Constants.COLLECTION_QUERY, "Query Collection", Constants.MEDIATYPE_QUERY);
                     }
 
-                    if (cap.isGetDescendantsSupported() != null) {
-                        supportsRootDescendants = cap.isGetDescendantsSupported();
+                    // - checked out collection collection
+                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_CHECKEDOUT, null),
+                            Constants.COLLECTION_CHECKEDOUT, "Checked Out Collection", Constants.MEDIATYPE_CMISATOM);
+
+                    // - unfiled collection collection
+                    if (supportsUnFiling || supportsMultifiling) {
+                        serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_UNFILED, null),
+                                Constants.COLLECTION_UNFILED, "Unfiled Collection", Constants.MEDIATYPE_CMISATOM);
                     }
 
-                    if (cap.getChangesCapability() != null) {
-                        supportsChanges = (cap.getChangesCapability() != CapabilityChanges.NONE);
-                    }
-                }
+                    // - bulk update collection
+                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_BULK_UPDATE, null),
+                            Constants.COLLECTION_BULK_UPDATE, "Bulk Update Collection", Constants.MEDIATYPE_CMISATOM);
 
-                serviceDoc.startWorkspace(infoData.getId());
+                    // add repository info
+                    serviceDoc.writeRepositoryInfo(infoData, cmisVersion);
 
-                // add collections
+                    // add links
 
-                // - root collection
-                serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_CHILDREN, infoData.getRootFolderId()),
-                        Constants.COLLECTION_ROOT, "Root Collection", Constants.MEDIATYPE_ENTRY,
-                        Constants.MEDIATYPE_CMISATOM);
-
-                // - types collection
-                serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_TYPES, null), Constants.COLLECTION_TYPES,
-                        "Types Collection", "");
-
-                // - query collection
-                if (supportsQuery) {
-                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_QUERY, null), Constants.COLLECTION_QUERY,
-                            "Query Collection", Constants.MEDIATYPE_QUERY);
-                }
+                    // - types descendants
+                    serviceDoc.writeLink(Constants.REP_REL_TYPEDESC, compileUrl(baseUrl, RESOURCE_TYPESDESC, null),
+                            Constants.MEDIATYPE_FEED, null);
 
-                // - checked out collection collection
-                serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_CHECKEDOUT, null),
-                        Constants.COLLECTION_CHECKEDOUT, "Checked Out Collection", Constants.MEDIATYPE_CMISATOM);
-
-                // - unfiled collection collection
-                if (supportsUnFiling || supportsMultifiling) {
-                    serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_UNFILED, null),
-                            Constants.COLLECTION_UNFILED, "Unfiled Collection", Constants.MEDIATYPE_CMISATOM);
-                }
+                    // - folder tree
+                    if (supportsFolderTree) {
+                        serviceDoc.writeLink(Constants.REP_REL_FOLDERTREE,
+                                compileUrl(baseUrl, RESOURCE_FOLDERTREE, infoData.getRootFolderId()),
+                                Constants.MEDIATYPE_DESCENDANTS, null);
+                    }
 
-                // - bulk update collection
-                serviceDoc.writeCollection(compileUrl(baseUrl, RESOURCE_BULK_UPDATE, null),
-                        Constants.COLLECTION_BULK_UPDATE, "Bulk Update Collection", Constants.MEDIATYPE_CMISATOM);
-
-                // add repository info
-                serviceDoc.writeRepositoryInfo(infoData, cmisVersion);
-
-                // add links
-
-                // - types descendants
-                serviceDoc.writeLink(Constants.REP_REL_TYPEDESC, compileUrl(baseUrl, RESOURCE_TYPESDESC, null),
-                        Constants.MEDIATYPE_FEED, null);
-
-                // - folder tree
-                if (supportsFolderTree) {
-                    serviceDoc.writeLink(Constants.REP_REL_FOLDERTREE,
-                            compileUrl(baseUrl, RESOURCE_FOLDERTREE, infoData.getRootFolderId()),
-                            Constants.MEDIATYPE_DESCENDANTS, null);
-                }
+                    // - root descendants
+                    if (supportsRootDescendants) {
+                        serviceDoc.writeLink(Constants.REP_REL_ROOTDESC,
+                                compileUrl(baseUrl, RESOURCE_DESCENDANTS, infoData.getRootFolderId()),
+                                Constants.MEDIATYPE_DESCENDANTS, infoData.getRootFolderId());
+                    }
 
-                // - root descendants
-                if (supportsRootDescendants) {
-                    serviceDoc.writeLink(Constants.REP_REL_ROOTDESC,
-                            compileUrl(baseUrl, RESOURCE_DESCENDANTS, infoData.getRootFolderId()),
-                            Constants.MEDIATYPE_DESCENDANTS, infoData.getRootFolderId());
-                }
+                    // - changes
+                    if (supportsChanges) {
+                        serviceDoc.writeLink(Constants.REP_REL_CHANGES, compileUrl(baseUrl, RESOURCE_CHANGES, null),
+                                Constants.MEDIATYPE_FEED, null);
+                    }
 
-                // - changes
-                if (supportsChanges) {
-                    serviceDoc.writeLink(Constants.REP_REL_CHANGES, compileUrl(baseUrl, RESOURCE_CHANGES, null),
-                            Constants.MEDIATYPE_FEED, null);
-                }
+                    // add URI templates
 
-                // add URI templates
+                    // - object by id
+                    String url = compileUrl(baseUrl, RESOURCE_OBJECTBYID, null)
+                            + "?id={id}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}&includePolicyIds={includePolicyIds}&includeRelationships={includeRelationships}&renditionFilter={renditionFilter}";
+                    serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_OBJECT_BY_ID, Constants.MEDIATYPE_ENTRY);
+
+                    // - object by path
+                    url = compileUrl(baseUrl, RESOURCE_OBJECTBYPATH, null)
+                            + "?path={path}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}&includePolicyIds={includePolicyIds}&includeRelationships={includeRelationships}&renditionFilter={renditionFilter}";
+                    serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_OBJECT_BY_PATH, Constants.MEDIATYPE_ENTRY);
+
+                    // - type by id
+                    url = compileUrl(baseUrl, RESOURCE_TYPE, null) + "?id={id}";
+                    serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_TYPE_BY_ID, Constants.MEDIATYPE_ENTRY);
+
+                    // - query
+                    if (supportsQuery) {
+                        url = compileUrl(baseUrl, RESOURCE_QUERY, null)
+                                + "?q={q}&searchAllVersions={searchAllVersions}&includeAllowableActions={includeAllowableActions}&includeRelationships={includeRelationships}&maxItems={maxItems}&skipCount={skipCount}";
+                        serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_QUERY, Constants.MEDIATYPE_FEED);
+                    }
 
-                // - object by id
-                String url = compileUrl(baseUrl, RESOURCE_OBJECTBYID, null)
-                        + "?id={id}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}&includePolicyIds={includePolicyIds}&includeRelationships={includeRelationships}&renditionFilter={renditionFilter}";
-                serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_OBJECT_BY_ID, Constants.MEDIATYPE_ENTRY);
-
-                // - object by path
-                url = compileUrl(baseUrl, RESOURCE_OBJECTBYPATH, null)
-                        + "?path={path}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}&includePolicyIds={includePolicyIds}&includeRelationships={includeRelationships}&renditionFilter={renditionFilter}";
-                serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_OBJECT_BY_PATH, Constants.MEDIATYPE_ENTRY);
-
-                // - type by id
-                url = compileUrl(baseUrl, RESOURCE_TYPE, null) + "?id={id}";
-                serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_TYPE_BY_ID, Constants.MEDIATYPE_ENTRY);
-
-                // - query
-                if (supportsQuery) {
-                    url = compileUrl(baseUrl, RESOURCE_QUERY, null)
-                            + "?q={q}&searchAllVersions={searchAllVersions}&includeAllowableActions={includeAllowableActions}&includeRelationships={includeRelationships}&maxItems={maxItems}&skipCount={skipCount}";
-                    serviceDoc.writeUriTemplate(url, Constants.TEMPLATE_QUERY, Constants.MEDIATYPE_FEED);
+                    serviceDoc.endWorkspace();
                 }
-
-                serviceDoc.endWorkspace();
             }
-        }
 
-        serviceDoc.endServiceDocument();
-        serviceDoc.endDocument();
+            serviceDoc.endServiceDocument();
+            serviceDoc.endDocument();
+        }
     }
 
     /**
      * Renders a type children collection.
      */
-    public static void getTypeChildren(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
-        boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS, false);
-        BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
-        BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
-
-        // execute
-        TypeDefinitionList typeList = service.getTypeChildren(repositoryId, typeId, includePropertyDefinitions,
-                maxItems, skipCount, null);
-
-        BigInteger numItems = (typeList == null ? null : typeList.getNumItems());
-        Boolean hasMoreItems = (typeList == null ? null : typeList.hasMoreItems());
-
-        String parentTypeId = null;
-        String typeName = "Type Children";
-
-        // in order to get the parent type, we need the type definition of this
-        // type as well
-        if (typeId != null) {
-            TypeDefinition typeDefinition = service.getTypeDefinition(repositoryId, typeId, null);
+    public static class GetTypeChildren extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+            boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS,
+                    false);
+            BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
+            BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
+
+            // execute
+            TypeDefinitionList typeList = service.getTypeChildren(repositoryId, typeId, includePropertyDefinitions,
+                    maxItems, skipCount, null);
+
+            BigInteger numItems = (typeList == null ? null : typeList.getNumItems());
+            Boolean hasMoreItems = (typeList == null ? null : typeList.hasMoreItems());
+
+            String parentTypeId = null;
+            String typeName = "Type Children";
+
+            // in order to get the parent type, we need the type definition of
+            // this type as well
+            if (typeId != null) {
+                TypeDefinition typeDefinition = service.getTypeDefinition(repositoryId, typeId, null);
 
-            parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
-            typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
-        }
+                parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
+                typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
+            }
 
-        // write XML
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_FEED);
+            // write XML
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_FEED);
 
-        AtomFeed feed = new AtomFeed();
-        feed.startDocument(response.getOutputStream(), getNamespaces(service));
-        feed.startFeed(true);
+            AtomFeed feed = new AtomFeed();
+            feed.startDocument(response.getOutputStream(), getNamespaces(service));
+            feed.startFeed(true);
 
-        // write basic Atom feed elements
-        feed.writeFeedElements(typeId, null, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, numItems);
+            // write basic Atom feed elements
+            feed.writeFeedElements(typeId, null, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, numItems);
 
-        // write links
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+            // write links
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
 
-        feed.writeServiceLink(baseUrl.toString(), repositoryId);
+            feed.writeServiceLink(baseUrl.toString(), repositoryId);
 
-        UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
-        selfLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        selfLink.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
-        selfLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
-        selfLink.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
-        feed.writeSelfLink(selfLink.toString(), typeId);
+            UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
+            selfLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            selfLink.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
+            selfLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+            selfLink.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
+            feed.writeSelfLink(selfLink.toString(), typeId);
 
-        feed.writeViaLink(compileUrl(baseUrl, RESOURCE_TYPE, typeId));
+            feed.writeViaLink(compileUrl(baseUrl, RESOURCE_TYPE, typeId));
 
-        UrlBuilder downLink = compileUrlBuilder(baseUrl, RESOURCE_TYPESDESC, null);
-        downLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        feed.writeDownLink(downLink.toString(), Constants.MEDIATYPE_DESCENDANTS);
+            UrlBuilder downLink = compileUrlBuilder(baseUrl, RESOURCE_TYPESDESC, null);
+            downLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            feed.writeDownLink(downLink.toString(), Constants.MEDIATYPE_DESCENDANTS);
 
-        if (parentTypeId != null) {
-            feed.writeUpLink(compileUrl(baseUrl, RESOURCE_TYPE, parentTypeId), Constants.MEDIATYPE_ENTRY);
-        }
+            if (parentTypeId != null) {
+                feed.writeUpLink(compileUrl(baseUrl, RESOURCE_TYPE, parentTypeId), Constants.MEDIATYPE_ENTRY);
+            }
 
-        // write paging links
-        UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
-        pagingUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        pagingUrl.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
-        feed.writePagingLinks(pagingUrl, maxItems, skipCount, numItems, hasMoreItems, PAGE_SIZE);
-
-        // write collection
-        UrlBuilder collectionUrl = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
-        collectionUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        feed.writeCollection(collectionUrl.toString(), null, "Types Collection", "");
-
-        // write type entries
-        if ((typeList != null) && (typeList.getList() != null)) {
-            AtomEntry entry = new AtomEntry(feed.getWriter());
-            for (TypeDefinition type : typeList.getList()) {
-                writeTypeEntry(entry, type, null, repositoryId, baseUrl, false, context.getCmisVersion());
+            // write paging links
+            UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
+            pagingUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            pagingUrl.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
+            feed.writePagingLinks(pagingUrl, maxItems, skipCount, numItems, hasMoreItems, PAGE_SIZE);
+
+            // write collection
+            UrlBuilder collectionUrl = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
+            collectionUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            feed.writeCollection(collectionUrl.toString(), null, "Types Collection", "");
+
+            // write type entries
+            if ((typeList != null) && (typeList.getList() != null)) {
+                AtomEntry entry = new AtomEntry(feed.getWriter());
+                for (TypeDefinition type : typeList.getList()) {
+                    writeTypeEntry(entry, type, null, repositoryId, baseUrl, false, context.getCmisVersion());
+                }
             }
-        }
 
-        // we are done
-        feed.endFeed();
-        feed.endDocument();
+            // we are done
+            feed.endFeed();
+            feed.endDocument();
+        }
     }
 
     /**
      * Renders a type descendants feed.
      */
-    public static void getTypeDescendants(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
-        BigInteger depth = getBigIntegerParameter(request, Constants.PARAM_DEPTH);
-        boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS, false);
-
-        // execute
-        List<TypeDefinitionContainer> typeTree = service.getTypeDescendants(repositoryId, typeId, depth,
-                includePropertyDefinitions, null);
-
-        String parentTypeId = null;
-        String typeName = "Type Children";
-
-        // in order to get the parent type, we need the type definition of this
-        // type as well
-        if (typeId != null) {
-            TypeDefinition typeDefinition = service.getTypeDefinition(repositoryId, typeId, null);
+    public static class GetTypeDescendants extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+            BigInteger depth = getBigIntegerParameter(request, Constants.PARAM_DEPTH);
+            boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS,
+                    false);
+
+            // execute
+            List<TypeDefinitionContainer> typeTree = service.getTypeDescendants(repositoryId, typeId, depth,
+                    includePropertyDefinitions, null);
+
+            String parentTypeId = null;
+            String typeName = "Type Children";
+
+            // in order to get the parent type, we need the type definition of
+            // this type as well
+            if (typeId != null) {
+                TypeDefinition typeDefinition = service.getTypeDefinition(repositoryId, typeId, null);
 
-            parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
-            typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
-        }
+                parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
+                typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
+            }
 
-        // write XML
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_FEED);
+            // write XML
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_FEED);
 
-        AtomFeed feed = new AtomFeed();
-        feed.startDocument(response.getOutputStream(), getNamespaces(service));
-        feed.startFeed(true);
+            AtomFeed feed = new AtomFeed();
+            feed.startDocument(response.getOutputStream(), getNamespaces(service));
+            feed.startFeed(true);
 
-        // write basic Atom feed elements
-        feed.writeFeedElements(typeId, null, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, null);
+            // write basic Atom feed elements
+            feed.writeFeedElements(typeId, null, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, null);
 
-        // write links
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+            // write links
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
 
-        feed.writeServiceLink(baseUrl.toString(), repositoryId);
+            feed.writeServiceLink(baseUrl.toString(), repositoryId);
 
-        UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_TYPESDESC, null);
-        selfLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        selfLink.addParameter(Constants.PARAM_DEPTH, depth);
-        selfLink.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
-        feed.writeSelfLink(selfLink.toString(), typeId);
+            UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_TYPESDESC, null);
+            selfLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            selfLink.addParameter(Constants.PARAM_DEPTH, depth);
+            selfLink.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
+            feed.writeSelfLink(selfLink.toString(), typeId);
 
-        feed.writeViaLink(compileUrl(baseUrl, RESOURCE_TYPE, typeId));
+            feed.writeViaLink(compileUrl(baseUrl, RESOURCE_TYPE, typeId));
 
-        UrlBuilder downLink = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
-        downLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
-        feed.writeDownLink(downLink.toString(), Constants.MEDIATYPE_FEED);
+            UrlBuilder downLink = compileUrlBuilder(baseUrl, RESOURCE_TYPES, null);
+            downLink.addParameter(Constants.PARAM_TYPE_ID, typeId);
+            feed.writeDownLink(downLink.toString(), Constants.MEDIATYPE_FEED);
 
-        if (parentTypeId != null) {
-            feed.writeUpLink(compileUrl(baseUrl, RESOURCE_TYPE, parentTypeId), Constants.MEDIATYPE_ENTRY);
-        }
+            if (parentTypeId != null) {
+                feed.writeUpLink(compileUrl(baseUrl, RESOURCE_TYPE, parentTypeId), Constants.MEDIATYPE_ENTRY);
+            }
 
-        // write tree
-        if (typeTree != null) {
-            AtomEntry entry = new AtomEntry(feed.getWriter());
-
-            for (TypeDefinitionContainer container : typeTree) {
-                if ((container != null) && (container.getTypeDefinition() != null)) {
-                    writeTypeEntry(entry, container.getTypeDefinition(), container.getChildren(), repositoryId,
-                            baseUrl, false, context.getCmisVersion());
+            // write tree
+            if (typeTree != null) {
+                AtomEntry entry = new AtomEntry(feed.getWriter());
+
+                for (TypeDefinitionContainer container : typeTree) {
+                    if ((container != null) && (container.getTypeDefinition() != null)) {
+                        writeTypeEntry(entry, container.getTypeDefinition(), container.getChildren(), repositoryId,
+                                baseUrl, false, context.getCmisVersion());
+                    }
                 }
             }
-        }
 
-        // we are done
-        feed.endFeed();
-        feed.endDocument();
+            // we are done
+            feed.endFeed();
+            feed.endDocument();
+        }
     }
 
     /**
      * Renders a type definition.
      */
-    public static void getTypeDefinition(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String typeId = getStringParameter(request, Constants.PARAM_ID);
-
-        // execute
-        TypeDefinition type = service.getTypeDefinition(repositoryId, typeId, null);
-
-        // write XML
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_ENTRY);
-
-        AtomEntry entry = new AtomEntry();
-        entry.startDocument(response.getOutputStream(), getNamespaces(service));
-        writeTypeEntry(entry, type, null, repositoryId, compileBaseUrl(request, repositoryId), true,
-                context.getCmisVersion());
-        entry.endDocument();
+    public static class GetTypeDefinition extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String typeId = getStringParameter(request, Constants.PARAM_ID);
+
+            // execute
+            TypeDefinition type = service.getTypeDefinition(repositoryId, typeId, null);
+
+            // write XML
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_ENTRY);
+
+            AtomEntry entry = new AtomEntry();
+            entry.startDocument(response.getOutputStream(), getNamespaces(service));
+            writeTypeEntry(entry, type, null, repositoryId, compileBaseUrl(request, repositoryId), true,
+                    context.getCmisVersion());
+            entry.endDocument();
+        }
     }
 
     /**
      * Creates a type.
      */
-    public static void createType(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // parse entry
-        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
-                .get(CallContext.STREAM_FACTORY);
-        AtomEntryParser parser = new AtomEntryParser(streamFactory);
-        parser.parse(request.getInputStream());
-
-        // execute
-        TypeDefinition newType = service.createType(repositoryId, parser.getTypeDefinition(), null);
-
-        // set headers
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-        response.setStatus(HttpServletResponse.SC_CREATED);
-        response.setContentType(Constants.MEDIATYPE_ENTRY);
-        response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
-
-        // write XML
-        AtomEntry entry = new AtomEntry();
-        entry.startDocument(response.getOutputStream(), getNamespaces(service));
-        writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
-                context.getCmisVersion());
-        entry.endDocument();
+    public static class CreateType extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // parse entry
+            ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                    .get(CallContext.STREAM_FACTORY);
+            AtomEntryParser parser = new AtomEntryParser(streamFactory);
+            parser.parse(request.getInputStream());
+
+            // execute
+            TypeDefinition newType = service.createType(repositoryId, parser.getTypeDefinition(), null);
+
+            // set headers
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+            response.setStatus(HttpServletResponse.SC_CREATED);
+            response.setContentType(Constants.MEDIATYPE_ENTRY);
+            response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
+
+            // write XML
+            AtomEntry entry = new AtomEntry();
+            entry.startDocument(response.getOutputStream(), getNamespaces(service));
+            writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
+                    context.getCmisVersion());
+            entry.endDocument();
+        }
     }
 
     /**
      * Updates a type.
      */
-    public static void updateType(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // parse entry
-        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
-                .get(CallContext.STREAM_FACTORY);
-        AtomEntryParser parser = new AtomEntryParser(streamFactory);
-        parser.parse(request.getInputStream());
-
-        // execute
-        TypeDefinition newType = service.updateType(repositoryId, parser.getTypeDefinition(), null);
-
-        // set headers
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_ENTRY);
-        response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
-
-        // write XML
-        AtomEntry entry = new AtomEntry();
-        entry.startDocument(response.getOutputStream(), getNamespaces(service));
-        writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
-                context.getCmisVersion());
-        entry.endDocument();
+    public static class UpdateType extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // parse entry
+            ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                    .get(CallContext.STREAM_FACTORY);
+            AtomEntryParser parser = new AtomEntryParser(streamFactory);
+            parser.parse(request.getInputStream());
+
+            // execute
+            TypeDefinition newType = service.updateType(repositoryId, parser.getTypeDefinition(), null);
+
+            // set headers
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_ENTRY);
+            response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
+
+            // write XML
+            AtomEntry entry = new AtomEntry();
+            entry.startDocument(response.getOutputStream(), getNamespaces(service));
+            writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
+                    context.getCmisVersion());
+            entry.endDocument();
+        }
     }
 
     /**
      * Deletes a type.
      */
-    public static void deleteType(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String typeId = getStringParameter(request, Constants.PARAM_ID);
+    public static class DeleteType extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String typeId = getStringParameter(request, Constants.PARAM_ID);
 
-        // execute
-        service.deleteType(repositoryId, typeId, null);
+            // execute
+            service.deleteType(repositoryId, typeId, null);
 
-        // set headers
-        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+            // set headers
+            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+        }
     }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java Sat May 11 21:19:48 2013
@@ -18,14 +18,6 @@
  */
 package org.apache.chemistry.opencmis.server.impl.atompub;
 
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_ENTRY;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.getNamespaces;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.writeObjectEntry;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
-
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -44,129 +36,132 @@ import org.apache.chemistry.opencmis.ser
 /**
  * Versioning Service operations.
  */
-public final class VersioningService {
-
-    private VersioningService() {
-    }
+public class VersioningService {
 
     /**
      * Check Out.
      */
-    public static void checkOut(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
-                .get(CallContext.STREAM_FACTORY);
-        AtomEntryParser parser = new AtomEntryParser(streamFactory);
-        parser.setIgnoreAtomContentSrc(true); // needed for some clients
-        parser.parse(request.getInputStream());
-
-        // execute
-        Holder<String> checkOutId = new Holder<String>(parser.getId());
-        service.checkOut(repositoryId, checkOutId, null, null);
-
-        ObjectInfo objectInfo = service.getObjectInfo(repositoryId, checkOutId.getValue());
-        if (objectInfo == null) {
-            throw new CmisRuntimeException("Object Info is missing!");
-        }
+    public static class CheckOut extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                    .get(CallContext.STREAM_FACTORY);
+            AtomEntryParser parser = new AtomEntryParser(streamFactory);
+            parser.setIgnoreAtomContentSrc(true); // needed for some clients
+            parser.parse(request.getInputStream());
+
+            // execute
+            Holder<String> checkOutId = new Holder<String>(parser.getId());
+            service.checkOut(repositoryId, checkOutId, null, null);
+
+            ObjectInfo objectInfo = service.getObjectInfo(repositoryId, checkOutId.getValue());
+            if (objectInfo == null) {
+                throw new CmisRuntimeException("Object Info is missing!");
+            }
 
-        ObjectData object = objectInfo.getObject();
-        if (object == null) {
-            throw new CmisRuntimeException("Object is null!");
-        }
+            ObjectData object = objectInfo.getObject();
+            if (object == null) {
+                throw new CmisRuntimeException("Object is null!");
+            }
 
-        if (object.getId() == null) {
-            throw new CmisRuntimeException("Object Id is null!");
-        }
+            if (object.getId() == null) {
+                throw new CmisRuntimeException("Object Id is null!");
+            }
 
-        // set headers
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-        String location = compileUrl(baseUrl, RESOURCE_ENTRY, object.getId());
-
-        response.setStatus(HttpServletResponse.SC_CREATED);
-        response.setContentType(Constants.MEDIATYPE_ENTRY);
-        response.setHeader("Content-Location", location);
-        response.setHeader("Location", location);
-
-        // write XML
-        AtomEntry entry = new AtomEntry();
-        entry.startDocument(response.getOutputStream(), getNamespaces(service));
-        writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl, true,
-                context.getCmisVersion());
-        entry.endDocument();
+            // set headers
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+            String location = compileUrl(baseUrl, RESOURCE_ENTRY, object.getId());
+
+            response.setStatus(HttpServletResponse.SC_CREATED);
+            response.setContentType(Constants.MEDIATYPE_ENTRY);
+            response.setHeader("Content-Location", location);
+            response.setHeader("Location", location);
+
+            // write XML
+            AtomEntry entry = new AtomEntry();
+            entry.startDocument(response.getOutputStream(), getNamespaces(service));
+            writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl, true,
+                    context.getCmisVersion());
+            entry.endDocument();
+        }
     }
 
     /**
      * Get all versions.
      */
-    public static void getAllVersions(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String objectId = getStringParameter(request, Constants.PARAM_ID);
-        String versionSeriesId = getStringParameter(request, Constants.PARAM_VERSION_SERIES_ID);
-        String filter = getStringParameter(request, Constants.PARAM_FILTER);
-        Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
-
-        // execute
-        List<ObjectData> versions = service.getAllVersions(repositoryId, objectId, versionSeriesId, filter,
-                includeAllowableActions, null);
+    public static class GetAllVersions extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String objectId = getStringParameter(request, Constants.PARAM_ID);
+            String versionSeriesId = getStringParameter(request, Constants.PARAM_VERSION_SERIES_ID);
+            String filter = getStringParameter(request, Constants.PARAM_FILTER);
+            Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
+
+            // execute
+            List<ObjectData> versions = service.getAllVersions(repositoryId, objectId, versionSeriesId, filter,
+                    includeAllowableActions, null);
 
-        if (versions == null || versions.isEmpty()) {
-            throw new CmisRuntimeException("Version list is null or empty!");
-        }
+            if (versions == null || versions.isEmpty()) {
+                throw new CmisRuntimeException("Version list is null or empty!");
+            }
 
-        // set headers
-        response.setStatus(HttpServletResponse.SC_OK);
-        response.setContentType(Constants.MEDIATYPE_FEED);
+            // set headers
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.setContentType(Constants.MEDIATYPE_FEED);
 
-        // write XML
-        AtomFeed feed = new AtomFeed();
-        feed.startDocument(response.getOutputStream(), getNamespaces(service));
-        feed.startFeed(true);
+            // write XML
+            AtomFeed feed = new AtomFeed();
+            feed.startDocument(response.getOutputStream(), getNamespaces(service));
+            feed.startFeed(true);
 
-        // write basic Atom feed elements
-        ObjectInfo latestObjectInfo = service.getObjectInfo(repositoryId, versions.get(0).getId());
-        ObjectInfo firstObjectInfo = service.getObjectInfo(repositoryId, versions.get(versions.size() - 1).getId());
+            // write basic Atom feed elements
+            ObjectInfo latestObjectInfo = service.getObjectInfo(repositoryId, versions.get(0).getId());
+            ObjectInfo firstObjectInfo = service.getObjectInfo(repositoryId, versions.get(versions.size() - 1).getId());
 
-        feed.writeFeedElements(versionSeriesId, null, firstObjectInfo.getCreatedBy(), latestObjectInfo.getName(),
-                latestObjectInfo.getLastModificationDate(), null, null);
+            feed.writeFeedElements(versionSeriesId, null, firstObjectInfo.getCreatedBy(), latestObjectInfo.getName(),
+                    latestObjectInfo.getLastModificationDate(), null, null);
 
-        // write links
-        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+            // write links
+            UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
 
-        feed.writeServiceLink(baseUrl.toString(), repositoryId);
+            feed.writeServiceLink(baseUrl.toString(), repositoryId);
 
-        if (objectId != null) {
-            feed.writeViaLink(compileUrl(baseUrl, RESOURCE_ENTRY, objectId));
-        }
+            if (objectId != null) {
+                feed.writeViaLink(compileUrl(baseUrl, RESOURCE_ENTRY, objectId));
+            }
 
-        // write entries
-        AtomEntry entry = new AtomEntry(feed.getWriter());
-        for (ObjectData object : versions) {
-            if (object == null) {
-                continue;
+            // write entries
+            AtomEntry entry = new AtomEntry(feed.getWriter());
+            for (ObjectData object : versions) {
+                if (object == null) {
+                    continue;
+                }
+                writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl, false,
+                        context.getCmisVersion());
             }
-            writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl, false,
-                    context.getCmisVersion());
-        }
 
-        // we are done
-        feed.endFeed();
-        feed.endDocument();
+            // we are done
+            feed.endFeed();
+            feed.endDocument();
+        }
     }
 
     /**
      * Delete object.
      */
-    public static void deleteAllVersions(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) {
-        // get parameters
-        String objectId = getStringParameter(request, Constants.PARAM_ID);
+    public static class DeleteAllVersions extends AbstractAtomPubServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String objectId = getStringParameter(request, Constants.PARAM_ID);
 
-        // execute
-        service.deleteObjectOrCancelCheckOut(repositoryId, objectId, Boolean.TRUE, null);
+            // execute
+            service.deleteObjectOrCancelCheckOut(repositoryId, objectId, Boolean.TRUE, null);
 
-        // set headers
-        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+            // set headers
+            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+        }
     }
 }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AbstractBrowserServiceCall.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AbstractBrowserServiceCall.java?rev=1481420&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AbstractBrowserServiceCall.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AbstractBrowserServiceCall.java Sat May 11 21:19:48 2013
@@ -0,0 +1,460 @@
+/*
+ * 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.server.impl.browser;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.impl.Base64;
+import org.apache.chemistry.opencmis.commons.impl.Constants;
+import org.apache.chemistry.opencmis.commons.impl.TypeCache;
+import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+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 org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONStreamAware;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+import org.apache.chemistry.opencmis.server.shared.AbstractServiceCall;
+import org.apache.chemistry.opencmis.server.shared.Dispatcher;
+
+public abstract class AbstractBrowserServiceCall extends AbstractServiceCall {
+
+    public static final String JSON_MIME_TYPE = "application/json";
+    public static final String HTML_MIME_TYPE = "text/html";
+
+    public static final String ROOT_PATH_FRAGMENT = "root";
+
+    public static final String REPOSITORY_PLACEHOLDER = "{repositoryId}";
+
+    /**
+     * Compiles the base URL for links, collections and templates.
+     */
+    public UrlBuilder compileBaseUrl(HttpServletRequest request, String repositoryId) {
+        String baseUrl = (String) request.getAttribute(Dispatcher.BASE_URL_ATTRIBUTE);
+        if (baseUrl != null) {
+            int repIdPos = baseUrl.indexOf(REPOSITORY_PLACEHOLDER);
+            if (repIdPos < 0) {
+                return new UrlBuilder(baseUrl);
+            } else {
+                return new UrlBuilder(baseUrl.substring(0, repIdPos) + repositoryId
+                        + baseUrl.substring(repIdPos + REPOSITORY_PLACEHOLDER.length()));
+            }
+        }
+
+        UrlBuilder url = new UrlBuilder(request.getScheme(), request.getServerName(), request.getServerPort(), null);
+
+        url.addPath(request.getContextPath());
+        url.addPath(request.getServletPath());
+        url.addPathSegment(repositoryId);
+
+        return url;
+    }
+
+    public UrlBuilder compileRepositoryUrl(HttpServletRequest request, String repositoryId) {
+        return compileBaseUrl(request, repositoryId);
+    }
+
+    public UrlBuilder compileRootUrl(HttpServletRequest request, String repositoryId) {
+        return compileRepositoryUrl(request, repositoryId).addPathSegment(ROOT_PATH_FRAGMENT);
+    }
+
+    public String compileObjectLocationUrl(HttpServletRequest request, String repositoryId, String objectId) {
+        return compileRootUrl(request, repositoryId).addParameter(Constants.PARAM_OBJECT_ID, objectId).toString();
+    }
+
+    public String compileTypeLocationUrl(HttpServletRequest request, String repositoryId, String typeId) {
+        return compileRepositoryUrl(request, repositoryId).addParameter(Constants.PARAM_TYPE_ID, typeId).toString();
+    }
+
+    /**
+     * Writes JSON to the servlet response and adds a callback wrapper if
+     * requested.
+     */
+    public void writeJSON(JSONStreamAware json, HttpServletRequest request, HttpServletResponse response)
+            throws IOException {
+        String token = getStringParameter(request, Constants.PARAM_TOKEN);
+
+        if (token != null && "POST".equals(request.getMethod())) {
+            response.setContentType(HTML_MIME_TYPE);
+            response.setContentLength(0);
+        } else {
+            response.setContentType(JSON_MIME_TYPE);
+            response.setCharacterEncoding("UTF-8");
+
+            String callback = getStringParameter(request, Constants.PARAM_CALLBACK);
+            if (callback != null) {
+                if (!callback.matches("[A-Za-z0-9._\\[\\]]*")) {
+                    throw new CmisInvalidArgumentException("Invalid callback name!");
+                }
+                response.getWriter().print(callback + "(");
+            }
+
+            json.writeJSONString(response.getWriter());
+
+            if (callback != null) {
+                response.getWriter().print(");");
+            }
+        }
+
+        response.getWriter().flush();
+    }
+
+    public void writeEmpty(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setContentLength(0);
+        response.setContentType(HTML_MIME_TYPE);
+        response.getWriter().flush();
+    }
+
+    public ObjectData getSimpleObject(CmisService service, String repositoryId, String objectId) {
+        return service.getObject(repositoryId, objectId, null, false, IncludeRelationships.NONE, "cmis:none", false,
+                false, null);
+    }
+
+    /**
+     * Sets the given HTTP status code if the surpessResponseCodes parameter is
+     * not set to true; otherwise sets HTTP status code 200 (OK).
+     */
+    public void setStatus(HttpServletRequest request, HttpServletResponse response, int statusCode) {
+        if (getBooleanParameter(request, Constants.PARAM_SUPPRESS_RESPONSE_CODES, false)) {
+            statusCode = HttpServletResponse.SC_OK;
+        }
+
+        response.setStatus(statusCode);
+    }
+
+    /**
+     * Transforms the transaction into a cookie name.
+     */
+    public String getCookieName(String token) {
+        if (token == null || token.length() == 0) {
+            return "cmis%";
+        }
+
+        return "cmis_" + Base64.encodeBytes(token.getBytes()).replace('=', '%');
+    }
+
+    /**
+     * Sets a transaction cookie.
+     */
+    public void setCookie(HttpServletRequest request, HttpServletResponse response, String repositoryId, String token,
+            String value) {
+        setCookie(request, response, repositoryId, token, value, 3600);
+    }
+
+    /**
+     * Deletes a transaction cookie.
+     */
+    public void deleteCookie(HttpServletRequest request, HttpServletResponse response, String repositoryId, String token) {
+        setCookie(request, response, repositoryId, token, "", 0);
+    }
+
+    /**
+     * Sets a transaction cookie.
+     */
+    public void setCookie(HttpServletRequest request, HttpServletResponse response, String repositoryId, String token,
+            String value, int expiry) {
+        if (token != null && token.length() > 0) {
+            String cookieValue = value;
+            try {
+                cookieValue = URLEncoder.encode(value, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+            }
+
+            Cookie transactionCookie = new Cookie(getCookieName(token), cookieValue);
+            transactionCookie.setMaxAge(expiry);
+            transactionCookie.setPath(request.getContextPath() + request.getServletPath() + "/" + repositoryId);
+            response.addCookie(transactionCookie);
+        }
+    }
+
+    public String createCookieValue(int code, String objectId, String ex, String message) {
+        JSONObject result = new JSONObject();
+
+        result.put("code", code);
+        result.put("objectId", objectId == null ? "" : objectId);
+        result.put("exception", ex == null ? "" : ex);
+        result.put("message", message == null ? "" : message);
+
+        return result.toJSONString();
+    }
+
+    public Properties createNewProperties(ControlParser controlParser, TypeCache typeCache) {
+        Map<String, List<String>> properties = controlParser.getProperties();
+        if (properties == null) {
+            return null;
+        }
+
+        // load primary type
+        List<String> objectTypeIdsValues = properties.get(PropertyIds.OBJECT_TYPE_ID);
+        if (objectTypeIdsValues != null && !objectTypeIdsValues.isEmpty()) {
+            TypeDefinition typeDef = typeCache.getTypeDefinition(objectTypeIdsValues.get(0));
+            if (typeDef == null) {
+                throw new CmisInvalidArgumentException("Invalid type: " + objectTypeIdsValues.get(0));
+            }
+        }
+
+        // load secondary types
+        List<String> secondaryObjectTypeIdsValues = properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+        if (secondaryObjectTypeIdsValues != null && !secondaryObjectTypeIdsValues.isEmpty()) {
+            for (String secTypeId : secondaryObjectTypeIdsValues) {
+                TypeDefinition typeDef = typeCache.getTypeDefinition(secTypeId);
+                if (typeDef == null) {
+                    throw new CmisInvalidArgumentException("Invalid type: " + secTypeId);
+                }
+            }
+        }
+
+        // create properties
+        PropertiesImpl result = new PropertiesImpl();
+        for (Map.Entry<String, List<String>> property : properties.entrySet()) {
+            PropertyDefinition<?> propDef = typeCache.getPropertyDefinition(property.getKey());
+            if (propDef == null) {
+                throw new CmisInvalidArgumentException(property.getKey() + " is unknown!");
+            }
+
+            result.addProperty(createPropertyData(propDef, property.getValue()));
+        }
+
+        return result;
+    }
+
+    public Properties createUpdateProperties(ControlParser controlParser, String typeId, List<String> secondaryTypeIds,
+            List<String> objectIds, TypeCache typeCache) {
+        Map<String, List<String>> properties = controlParser.getProperties();
+        if (properties == null) {
+            return null;
+        }
+
+        // load primary type
+        if (typeId != null) {
+            TypeDefinition typeDef = typeCache.getTypeDefinition(typeId);
+            if (typeDef == null) {
+                throw new CmisInvalidArgumentException("Invalid type: " + typeId);
+            }
+        }
+
+        // load secondary types
+        List<String> secondaryObjectTypeIdsValues = properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+        if (secondaryObjectTypeIdsValues != null && !secondaryObjectTypeIdsValues.isEmpty()) {
+            for (String secTypeId : secondaryObjectTypeIdsValues) {
+                TypeDefinition typeDef = typeCache.getTypeDefinition(secTypeId);
+                if (typeDef == null) {
+                    throw new CmisInvalidArgumentException("Invalid type: " + secTypeId);
+                }
+            }
+        }
+
+        if (secondaryTypeIds != null) {
+            for (String secTypeId : secondaryTypeIds) {
+                TypeDefinition typeDef = typeCache.getTypeDefinition(secTypeId);
+                if (typeDef == null) {
+                    throw new CmisInvalidArgumentException("Invalid secondary type: " + secTypeId);
+                }
+            }
+        }
+
+        // create properties
+        PropertiesImpl result = new PropertiesImpl();
+        for (Map.Entry<String, List<String>> property : properties.entrySet()) {
+            PropertyDefinition<?> propDef = typeCache.getPropertyDefinition(property.getKey());
+            if (propDef == null && objectIds != null) {
+                for (String objectId : objectIds) {
+                    typeCache.getTypeDefinitionForObject(objectId);
+                    propDef = typeCache.getPropertyDefinition(property.getKey());
+                    if (propDef != null) {
+                        break;
+                    }
+                }
+            }
+            if (propDef == null) {
+                throw new CmisInvalidArgumentException(property.getKey() + " is unknown!");
+            }
+
+            result.addProperty(createPropertyData(propDef, property.getValue()));
+        }
+
+        return result;
+    }
+
+    @SuppressWarnings("unchecked")
+    private PropertyData<?> createPropertyData(PropertyDefinition<?> propDef, Object value) {
+
+        List<String> strValues;
+        if (value == null) {
+            strValues = Collections.emptyList();
+        } else if (value instanceof String) {
+            strValues = new ArrayList<String>();
+            strValues.add((String) value);
+        } else {
+            strValues = (List<String>) value;
+        }
+
+        PropertyData<?> propertyData = null;
+        switch (propDef.getPropertyType()) {
+        case STRING:
+            propertyData = new PropertyStringImpl(propDef.getId(), strValues);
+            break;
+        case ID:
+            propertyData = new PropertyIdImpl(propDef.getId(), strValues);
+            break;
+        case BOOLEAN:
+            List<Boolean> boolValues = new ArrayList<Boolean>(strValues.size());
+            try {
+                for (String s : strValues) {
+                    boolValues.add(Boolean.valueOf(s));
+                }
+            } catch (NumberFormatException e) {
+                throw new CmisInvalidArgumentException(propDef.getId() + " value is not a boolean value!");
+            }
+            propertyData = new PropertyBooleanImpl(propDef.getId(), boolValues);
+            break;
+        case INTEGER:
+            List<BigInteger> intValues = new ArrayList<BigInteger>(strValues.size());
+            try {
+                for (String s : strValues) {
+                    intValues.add(new BigInteger(s));
+                }
+            } catch (NumberFormatException e) {
+                throw new CmisInvalidArgumentException(propDef.getId() + " value is not an integer value!");
+            }
+            propertyData = new PropertyIntegerImpl(propDef.getId(), intValues);
+            break;
+        case DECIMAL:
+            List<BigDecimal> decValues = new ArrayList<BigDecimal>(strValues.size());
+            try {
+                for (String s : strValues) {
+                    decValues.add(new BigDecimal(s));
+                }
+            } catch (NumberFormatException e) {
+                throw new CmisInvalidArgumentException(propDef.getId() + " value is not an integer value!");
+            }
+            propertyData = new PropertyDecimalImpl(propDef.getId(), decValues);
+            break;
+        case DATETIME:
+            List<GregorianCalendar> calValues = new ArrayList<GregorianCalendar>(strValues.size());
+            try {
+                for (String s : strValues) {
+                    GregorianCalendar cal = new GregorianCalendar();
+                    cal.setTimeInMillis(Long.parseLong(s));
+                    calValues.add(cal);
+                }
+            } catch (NumberFormatException e) {
+                throw new CmisInvalidArgumentException(propDef.getId() + " value is not an datetime value!");
+            }
+            propertyData = new PropertyDateTimeImpl(propDef.getId(), calValues);
+            break;
+        case HTML:
+            propertyData = new PropertyHtmlImpl(propDef.getId(), strValues);
+            break;
+        case URI:
+            propertyData = new PropertyUriImpl(propDef.getId(), strValues);
+            break;
+        }
+
+        return propertyData;
+    }
+
+    public List<String> createPolicies(ControlParser controlParser) {
+        return controlParser.getValues(Constants.CONTROL_POLICY);
+    }
+
+    public Acl createAddAcl(ControlParser controlParser) {
+        List<String> principals = controlParser.getValues(Constants.CONTROL_ADD_ACE_PRINCIPAL);
+        if (principals == null) {
+            return null;
+        }
+
+        List<Ace> aces = new ArrayList<Ace>();
+
+        int i = 0;
+        for (String principalId : principals) {
+            aces.add(new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(principalId), controlParser
+                    .getValues(Constants.CONTROL_ADD_ACE_PERMISSION, i)));
+            i++;
+        }
+
+        return new AccessControlListImpl(aces);
+    }
+
+    public Acl createRemoveAcl(ControlParser controlParser) {
+        List<String> principals = controlParser.getValues(Constants.CONTROL_REMOVE_ACE_PRINCIPAL);
+        if (principals == null) {
+            return null;
+        }
+
+        List<Ace> aces = new ArrayList<Ace>();
+
+        int i = 0;
+        for (String principalId : principals) {
+            aces.add(new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(principalId), controlParser
+                    .getValues(Constants.CONTROL_REMOVE_ACE_PERMISSION, i)));
+            i++;
+        }
+
+        return new AccessControlListImpl(aces);
+    }
+
+    public ContentStream createContentStream(HttpServletRequest request) {
+        ContentStreamImpl result = null;
+
+        if (request instanceof POSTHttpServletRequestWrapper) {
+            POSTHttpServletRequestWrapper post = (POSTHttpServletRequestWrapper) request;
+            if (post.getStream() != null) {
+                result = new ContentStreamImpl(post.getFilename(), post.getSize(), post.getContentType(),
+                        post.getStream());
+            }
+        }
+
+        return result;
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AclService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AclService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AclService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AclService.java Sat May 11 21:19:48 2013
@@ -18,14 +18,6 @@
  */
 package org.apache.chemistry.opencmis.server.impl.browser;
 
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createAddAcl;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createRemoveAcl;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setStatus;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -45,48 +37,54 @@ public class AclService {
     /**
      * getACL.
      */
-    public static void getACL(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String objectId = (String) context.get(CONTEXT_OBJECT_ID);
-        Boolean onlyBasicPermissions = getBooleanParameter(request, Constants.PARAM_ONLY_BASIC_PERMISSIONS);
-
-        // execute
-        Acl acl = service.getAcl(repositoryId, objectId, onlyBasicPermissions, null);
-
-        // return ACL
-        response.setStatus(HttpServletResponse.SC_OK);
-
-        JSONObject jsonObject = JSONConverter.convert(acl);
-        if (jsonObject == null) {
-            jsonObject = new JSONObject();
-        }
+    public static class GetACL extends AbstractBrowserServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String objectId = ((BrowserCallContextImpl) context).getObjectId();
+            Boolean onlyBasicPermissions = getBooleanParameter(request, Constants.PARAM_ONLY_BASIC_PERMISSIONS);
+
+            // execute
+            Acl acl = service.getAcl(repositoryId, objectId, onlyBasicPermissions, null);
+
+            // return ACL
+            response.setStatus(HttpServletResponse.SC_OK);
+
+            JSONObject jsonObject = JSONConverter.convert(acl);
+            if (jsonObject == null) {
+                jsonObject = new JSONObject();
+            }
 
-        writeJSON(jsonObject, request, response);
+            writeJSON(jsonObject, request, response);
+        }
     }
 
     /**
      * applyACL.
      */
-    public static void applyACL(CallContext context, CmisService service, String repositoryId,
-            HttpServletRequest request, HttpServletResponse response) throws Exception {
-        // get parameters
-        String objectId = (String) context.get(CONTEXT_OBJECT_ID);
-        AclPropagation aclPropagation = getEnumParameter(request, Constants.PARAM_ACL_PROPAGATION, AclPropagation.class);
-
-        // execute
-        ControlParser cp = new ControlParser(request);
-
-        Acl acl = service.applyAcl(repositoryId, objectId, createAddAcl(cp), createRemoveAcl(cp), aclPropagation, null);
-
-        // return ACL
-        setStatus(request, response, HttpServletResponse.SC_CREATED);
-
-        JSONObject jsonObject = JSONConverter.convert(acl);
-        if (jsonObject == null) {
-            jsonObject = new JSONObject();
-        }
+    public static class ApplyACL extends AbstractBrowserServiceCall {
+        public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+                HttpServletResponse response) throws Exception {
+            // get parameters
+            String objectId = ((BrowserCallContextImpl) context).getObjectId();
+            AclPropagation aclPropagation = getEnumParameter(request, Constants.PARAM_ACL_PROPAGATION,
+                    AclPropagation.class);
+
+            // execute
+            ControlParser cp = new ControlParser(request);
+
+            Acl acl = service.applyAcl(repositoryId, objectId, createAddAcl(cp), createRemoveAcl(cp), aclPropagation,
+                    null);
+
+            // return ACL
+            setStatus(request, response, HttpServletResponse.SC_CREATED);
+
+            JSONObject jsonObject = JSONConverter.convert(acl);
+            if (jsonObject == null) {
+                jsonObject = new JSONObject();
+            }
 
-        writeJSON(jsonObject, request, response);
+            writeJSON(jsonObject, request, response);
+        }
     }
 }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java?rev=1481420&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserCallContextImpl.java Sat May 11 21:19:48 2013
@@ -0,0 +1,192 @@
+/*
+ * 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.server.impl.browser;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+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.impl.CallContextImpl;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
+
+/**
+ * A {@link CallContext} implementation that holds browser binding specific
+ * values
+ */
+public class BrowserCallContextImpl extends CallContextImpl {
+
+    private CmisService service;
+    private String objectId;
+    private String[] pathFragments;
+    private String typeId;
+    private BaseTypeId baseTypeId;
+    private String token;
+
+    public BrowserCallContextImpl(String binding, CmisVersion cmisVersion, String repositoryId,
+            ServletContext servletContext, HttpServletRequest request, HttpServletResponse response,
+            CmisServiceFactory factory, ThresholdOutputStreamFactory streamFactory) {
+        super(binding, cmisVersion, repositoryId, servletContext, request, response, factory, streamFactory);
+    }
+
+    /**
+     * Sets the necessary details to retrieve the object id, type id, and token
+     * if requested.
+     */
+    public void setCallDetails(CmisService service, String objectId, String[] pathFragments, String token) {
+        this.service = service;
+        this.objectId = objectId;
+        this.pathFragments = pathFragments;
+        this.token = token;
+    }
+
+    /**
+     * Returns the token.
+     */
+    public String getToken() {
+        return token;
+    }
+
+    /**
+     * Returns the object id of the current object. If the object is unknown,
+     * that is the object has been addressed by path, the object is loaded to
+     * get the object id.
+     */
+    public String getObjectId() {
+        if (objectId != null) {
+            return objectId;
+        }
+
+        loadObject();
+
+        return objectId;
+    }
+
+    /**
+     * Returns the type id of the current object.
+     */
+    public String getTypeId() {
+        return typeId;
+    }
+
+    /**
+     * Returns the base type id of the current object. If the base type is
+     * unknown, the object is loaded to get the base type id.
+     */
+    public BaseTypeId getBaseTypeId() {
+        if (baseTypeId != null) {
+            return baseTypeId;
+        }
+
+        loadObject();
+
+        return baseTypeId;
+    }
+
+    /**
+     * Loads the object.
+     */
+    private void loadObject() {
+        ObjectData object = null;
+
+        if (objectId != null) {
+            object = service.getObject(getRepositoryId(), objectId, "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId",
+                    false, IncludeRelationships.NONE, "cmis:none", false, false, null);
+        } else if (pathFragments != null) {
+            object = service.getObjectByPath(getRepositoryId(), getPath(),
+                    "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId", false, IncludeRelationships.NONE, "cmis:none",
+                    false, false, null);
+        } else {
+            // this is a repository URL call without object id
+            // -> there is nothing to load
+            return;
+        }
+
+        objectId = object.getId();
+        typeId = getStringPropertyValue(object, PropertyIds.OBJECT_TYPE_ID);
+        baseTypeId = BaseTypeId.fromValue(getStringPropertyValue(object, PropertyIds.BASE_TYPE_ID));
+    }
+
+    /**
+     * Builds the object path.
+     */
+    private String getPath() {
+        if (pathFragments.length < 2) {
+            throw new CmisRuntimeException("Internal error!");
+        }
+        if (pathFragments.length == 2) {
+            return "/";
+        }
+
+        StringBuilder sb = new StringBuilder();
+        for (int i = 2; i < pathFragments.length; i++) {
+            if (pathFragments[i].length() == 0) {
+                continue;
+            }
+
+            sb.append("/");
+            sb.append(pathFragments[i]);
+        }
+
+        return sb.toString();
+    }
+
+    /**
+     * Extracts a property from an object.
+     */
+    protected String getStringPropertyValue(ObjectData object, String name) {
+        if (object == null) {
+            return null;
+        }
+
+        Properties propData = object.getProperties();
+        if (propData == null) {
+            return null;
+        }
+
+        Map<String, PropertyData<?>> properties = propData.getProperties();
+        if (properties == null) {
+            return null;
+        }
+
+        PropertyData<?> property = properties.get(name);
+        if (property == null) {
+            return null;
+        }
+
+        Object value = property.getFirstValue();
+        if (!(value instanceof String)) {
+            return null;
+        }
+
+        return (String) value;
+    }
+}



Mime
View raw message