chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r934881 [5/12] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src: main/java/org/apache/chemistry/opencmis/client/bindings/cache/ main/java/org/apache/chemistry/opencmis/client/bindings...
Date Fri, 16 Apr 2010 14:02:40 GMT
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/MultiFilingServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/MultiFilingServiceImpl.java?rev=934881&r1=934880&r2=934881&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/MultiFilingServiceImpl.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/MultiFilingServiceImpl.java
Fri Apr 16 14:02:38 2010
@@ -36,77 +36,79 @@ import org.apache.chemistry.opencmis.com
  */
 public class MultiFilingServiceImpl extends AbstractAtomPubService implements MultiFilingService
{
 
-  /**
-   * Constructor.
-   */
-  public MultiFilingServiceImpl(Session session) {
-    setSession(session);
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.MultiFilingService#addObjectToFolder(java.lang.String,
-   * java.lang.String, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public void addObjectToFolder(String repositoryId, String objectId, String folderId,
-      Boolean allVersions, ExtensionsData extension) {
-    if (objectId == null) {
-      throw new CmisInvalidArgumentException("Object id must be set!");
-    }
-
-    // find the link
-    String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
-
-    if (link == null) {
-      throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
-
-    // set up object and writer
-    final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
-
-    // post addObjectToFolder request
-    post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
-      public void write(OutputStream out) throws Exception {
-        entryWriter.write(out);
-      }
-    });
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.MultiFilingService#removeObjectFromFolder(java.lang.String,
-   * java.lang.String, java.lang.String, org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public void removeObjectFromFolder(String repositoryId, String objectId, String folderId,
-      ExtensionsData extension) {
-    if (objectId == null) {
-      throw new CmisInvalidArgumentException("Object id must be set!");
-    }
-
-    // find the link
-    String link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
-
-    if (link == null) {
-      throw new CmisObjectNotFoundException("Unknown repository or unfiling not supported!");
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_REMOVE_FROM, folderId);
-
-    // set up object and writer
-    final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
-
-    // post removeObjectFromFolder request
-    post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
-      public void write(OutputStream out) throws Exception {
-        entryWriter.write(out);
-      }
-    });
-  }
+	/**
+	 * Constructor.
+	 */
+	public MultiFilingServiceImpl(Session session) {
+		setSession(session);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.MultiFilingService#addObjectToFolder
+	 * (java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean,
+	 * org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean
allVersions,
+			ExtensionsData extension) {
+		if (objectId == null) {
+			throw new CmisInvalidArgumentException("Object id must be set!");
+		}
+
+		// find the link
+		String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+		if (link == null) {
+			throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
+
+		// set up object and writer
+		final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
+
+		// post addObjectToFolder request
+		post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
+			public void write(OutputStream out) throws Exception {
+				entryWriter.write(out);
+			}
+		});
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.MultiFilingService#removeObjectFromFolder
+	 * (java.lang.String, java.lang.String, java.lang.String,
+	 * org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public void removeObjectFromFolder(String repositoryId, String objectId, String folderId,
ExtensionsData extension) {
+		if (objectId == null) {
+			throw new CmisInvalidArgumentException("Object id must be set!");
+		}
+
+		// find the link
+		String link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
+
+		if (link == null) {
+			throw new CmisObjectNotFoundException("Unknown repository or unfiling not supported!");
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_REMOVE_FROM, folderId);
+
+		// set up object and writer
+		final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
+
+		// post removeObjectFromFolder request
+		post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
+			public void write(OutputStream out) throws Exception {
+				entryWriter.write(out);
+			}
+		});
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/NavigationServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/NavigationServiceImpl.java?rev=934881&r1=934880&r2=934881&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/NavigationServiceImpl.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/NavigationServiceImpl.java
Fri Apr 16 14:02:38 2010
@@ -58,469 +58,452 @@ import org.apache.chemistry.opencmis.com
  */
 public class NavigationServiceImpl extends AbstractAtomPubService implements NavigationService
{
 
-  /**
-   * Constructor.
-   */
-  public NavigationServiceImpl(Session session) {
-    setSession(session);
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getChildren(java.lang.String,
-   * java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.lang.Boolean,
-   * java.math.BigInteger, java.math.BigInteger, org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter,
-      String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
-      String renditionFilter, Boolean includePathSegment, BigInteger maxItems,
-      BigInteger skipCount, ExtensionsData extension) {
-    ObjectInFolderListImpl result = new ObjectInFolderListImpl();
-
-    // find the link
-    String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
-
-    if (link == null) {
-      throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-    url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
-    url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-    url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
-    url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
-    url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
-    url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
-
-    // read and parse
-    HttpUtils.Response resp = read(url);
-    AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
-
-    // handle top level
-    for (AtomElement element : feed.getElements()) {
-      if (element.getObject() instanceof AtomLink) {
-        if (isNextLink(element)) {
-          result.setHasMoreItems(Boolean.TRUE);
-        }
-      }
-      else if (isInt(NAME_NUM_ITEMS, element)) {
-        result.setNumItems((BigInteger) element.getObject());
-      }
-    }
-
-    // get the children
-    if (!feed.getEntries().isEmpty()) {
-      result.setObjects(new ArrayList<ObjectInFolderData>(feed.getEntries().size()));
-
-      for (AtomEntry entry : feed.getEntries()) {
-        ObjectInFolderDataImpl child = null;
-        String pathSegment = null;
-
-        lockLinks();
-        try {
-          // clean up cache
-          removeLinks(repositoryId, entry.getId());
-
-          // walk through the entry
-          for (AtomElement element : entry.getElements()) {
-            if (element.getObject() instanceof AtomLink) {
-              addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
-            }
-            else if (isStr(NAME_PATH_SEGMENT, element)) {
-              pathSegment = (String) element.getObject();
-            }
-            else if (element.getObject() instanceof CmisObjectType) {
-              child = new ObjectInFolderDataImpl();
-              child.setObject(convert((CmisObjectType) element.getObject()));
-            }
-          }
-        }
-        finally {
-          unlockLinks();
-        }
-
-        if (child != null) {
-          child.setPathSegment(pathSegment);
-          result.getObjects().add(child);
-        }
-      }
-    }
-
-    return result;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getDescendants(java.lang.String,
-   * java.lang.String, java.math.BigInteger, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId,
-      BigInteger depth, String filter, Boolean includeAllowableActions,
-      IncludeRelationships includeRelationships, String renditionFilter,
-      Boolean includePathSegment, ExtensionsData extension) {
-    List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
-
-    // find the link
-    String link = loadLink(repositoryId, folderId, Constants.REL_DOWN,
-        Constants.MEDIATYPE_DESCENDANTS);
-
-    if (link == null) {
-      throwLinkException(repositoryId, folderId, Constants.REL_DOWN,
-          Constants.MEDIATYPE_DESCENDANTS);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_DEPTH, depth);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-    url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-    url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
-    url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
-
-    // read and parse
-    HttpUtils.Response resp = read(url);
-    AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
-
-    // process tree
-    addDescendantsLevel(repositoryId, feed, result);
-
-    return result;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getFolderParent(java.lang.String,
-   * java.lang.String, java.lang.String, org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public ObjectData getFolderParent(String repositoryId, String folderId, String filter,
-      ExtensionsData extension) {
-    ObjectData result = null;
-
-    // find the link
-    String link = loadLink(repositoryId, folderId, Constants.REL_UP, Constants.MEDIATYPE_ENTRY);
-
-    if (link == null) {
-      throwLinkException(repositoryId, folderId, Constants.REL_UP, Constants.MEDIATYPE_ENTRY);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-
-    // read
-    HttpUtils.Response resp = read(url);
-
-    AtomBase base = parse(resp.getStream(), AtomBase.class);
-
-    // get the entry
-    AtomEntry entry = null;
-    if (base instanceof AtomFeed) {
-      AtomFeed feed = (AtomFeed) base;
-      if (feed.getEntries().isEmpty()) {
-        throw new CmisRuntimeException("Parent feed is empty!");
-      }
-      entry = feed.getEntries().get(0);
-    }
-    else if (base instanceof AtomEntry) {
-      entry = (AtomEntry) base;
-    }
-    else {
-      throw new CmisRuntimeException("Unexpected document!");
-    }
-
-    lockLinks();
-    try {
-      // clean up cache
-      removeLinks(repositoryId, entry.getId());
-
-      // walk through the entry
-      for (AtomElement element : entry.getElements()) {
-        if (element.getObject() instanceof AtomLink) {
-          addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
-        }
-        else if (element.getObject() instanceof CmisObjectType) {
-          result = convert((CmisObjectType) element.getObject());
-        }
-      }
-    }
-    finally {
-      unlockLinks();
-    }
-
-    return result;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getFolderTree(java.lang.String,
-   * java.lang.String, java.math.BigInteger, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId,
-      BigInteger depth, String filter, Boolean includeAllowableActions,
-      IncludeRelationships includeRelationships, String renditionFilter,
-      Boolean includePathSegment, ExtensionsData extension) {
-    List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
-
-    // find the link
-    String link = loadLink(repositoryId, folderId, Constants.REL_FOLDERTREE,
-        Constants.MEDIATYPE_DESCENDANTS);
-
-    if (link == null) {
-      throwLinkException(repositoryId, folderId, Constants.REL_FOLDERTREE,
-          Constants.MEDIATYPE_DESCENDANTS);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_DEPTH, depth);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-    url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-    url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
-    url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
-
-    // read and parse
-    HttpUtils.Response resp = read(url);
-    AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
-
-    // process tree
-    addDescendantsLevel(repositoryId, feed, result);
-
-    return result;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getObjectParents(java.lang.String,
-   * java.lang.String, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public List<ObjectParentData> getObjectParents(String repositoryId, String objectId,
-      String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
-      String renditionFilter, Boolean includeRelativePathSegment, ExtensionsData extension)
{
-    List<ObjectParentData> result = new ArrayList<ObjectParentData>();
-
-    // find the link
-    String link = loadLink(repositoryId, objectId, Constants.REL_UP, Constants.MEDIATYPE_FEED);
-
-    if (link == null) {
-      throwLinkException(repositoryId, objectId, Constants.REL_UP, Constants.MEDIATYPE_FEED);
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-    url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-    url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
-    url.addParameter(Constants.PARAM_RELATIVE_PATH_SEGMENT, includeRelativePathSegment);
-
-    // read and parse
-    HttpUtils.Response resp = read(url);
-
-    AtomBase base = parse(resp.getStream(), AtomBase.class);
-
-    if (base instanceof AtomFeed) {
-      // it's a feed
-      AtomFeed feed = (AtomFeed) base;
-
-      // walk through the feed
-      for (AtomEntry entry : feed.getEntries()) {
-        ObjectParentDataImpl objectParent = processParentEntry(entry, repositoryId);
-
-        if (objectParent != null) {
-          result.add(objectParent);
-        }
-      }
-    }
-    else if (base instanceof AtomEntry) {
-      // it's an entry
-      AtomEntry entry = (AtomEntry) base;
-
-      ObjectParentDataImpl objectParent = processParentEntry(entry, repositoryId);
-
-      if (objectParent != null) {
-        result.add(objectParent);
-      }
-    }
-
-    return result;
-  }
-
-  private ObjectParentDataImpl processParentEntry(AtomEntry entry, String repositoryId) {
-    ObjectParentDataImpl result = null;
-    String relativePathSegment = null;
-
-    lockLinks();
-    try {
-      // clean up cache
-      removeLinks(repositoryId, entry.getId());
-
-      // walk through the entry
-      for (AtomElement element : entry.getElements()) {
-        if (element.getObject() instanceof AtomLink) {
-          addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
-        }
-        else if (element.getObject() instanceof CmisObjectType) {
-          result = new ObjectParentDataImpl(convert((CmisObjectType) element.getObject()));
-        }
-        else if (is(NAME_RELATIVE_PATH_SEGMENT, element)) {
-          relativePathSegment = (String) element.getObject();
-        }
-      }
-    }
-    finally {
-      unlockLinks();
-    }
-
-    if (result != null) {
-      result.setRelativePathSegment(relativePathSegment);
-    }
-
-    return result;
-  }
-
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.opencmis.client.provider.NavigationService#getCheckedOutDocs(java.lang.String,
-   * java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean,
-   * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.math.BigInteger,
-   * java.math.BigInteger, org.apache.opencmis.client.provider.ExtensionsData)
-   */
-  public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter,
-      String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
-      String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
{
-    ObjectListImpl result = new ObjectListImpl();
-
-    // find the link
-    String link = loadCollection(repositoryId, Constants.COLLECTION_CHECKEDOUT);
-
-    if (link == null) {
-      throw new CmisObjectNotFoundException(
-          "Unknown repository or checkedout collection not supported!");
-    }
-
-    UrlBuilder url = new UrlBuilder(link);
-    url.addParameter(Constants.PARAM_FOLDER_ID, folderId);
-    url.addParameter(Constants.PARAM_FILTER, filter);
-    url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
-    url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-    url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
-    url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
-    url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
-
-    // read and parse
-    HttpUtils.Response resp = read(url);
-    AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
-
-    // handle top level
-    for (AtomElement element : feed.getElements()) {
-      if (element.getObject() instanceof AtomLink) {
-        if (isNextLink(element)) {
-          result.setHasMoreItems(Boolean.TRUE);
-        }
-      }
-      else if (isInt(NAME_NUM_ITEMS, element)) {
-        result.setNumItems((BigInteger) element.getObject());
-      }
-    }
-
-    // get the documents
-    if (!feed.getEntries().isEmpty()) {
-      result.setObjects(new ArrayList<ObjectData>(feed.getEntries().size()));
-
-      for (AtomEntry entry : feed.getEntries()) {
-        ObjectData child = null;
-
-        lockLinks();
-        try {
-          // clean up cache
-          removeLinks(repositoryId, entry.getId());
-
-          // walk through the entry
-          for (AtomElement element : entry.getElements()) {
-            if (element.getObject() instanceof AtomLink) {
-              addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
-            }
-            else if (element.getObject() instanceof CmisObjectType) {
-              child = convert((CmisObjectType) element.getObject());
-            }
-          }
-        }
-        finally {
-          unlockLinks();
-        }
-
-        if (child != null) {
-          result.getObjects().add(child);
-        }
-      }
-    }
-
-    return result;
-  }
-
-  // ---- internal ----
-
-  /**
-   * Adds descendants level recursively.
-   */
-  private void addDescendantsLevel(String repositoryId, AtomFeed feed,
-      List<ObjectInFolderContainer> containerList) {
-    if ((feed == null) || (feed.getEntries().isEmpty())) {
-      return;
-    }
-
-    // walk through the feed
-    for (AtomEntry entry : feed.getEntries()) {
-      ObjectInFolderDataImpl objectInFolder = null;
-      String pathSegment = null;
-      List<ObjectInFolderContainer> childContainerList = new ArrayList<ObjectInFolderContainer>();
-
-      lockLinks();
-      try {
-        // clean up cache
-        removeLinks(repositoryId, entry.getId());
-
-        // walk through the entry
-        for (AtomElement element : entry.getElements()) {
-          if (element.getObject() instanceof AtomLink) {
-            addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
-          }
-          else if (element.getObject() instanceof CmisObjectType) {
-            objectInFolder = new ObjectInFolderDataImpl(convert((CmisObjectType) element
-                .getObject()));
-          }
-          else if (is(NAME_PATH_SEGMENT, element)) {
-            pathSegment = (String) element.getObject();
-          }
-          else if (element.getObject() instanceof AtomFeed) {
-            addDescendantsLevel(repositoryId, (AtomFeed) element.getObject(), childContainerList);
-          }
-        }
-      }
-      finally {
-        unlockLinks();
-      }
-
-      if (objectInFolder != null) {
-        objectInFolder.setPathSegment(pathSegment);
-        ObjectInFolderContainerImpl childContainer = new ObjectInFolderContainerImpl(objectInFolder);
-        childContainer.setChildren(childContainerList);
-        containerList.add(childContainer);
-      }
-    }
-  }
+	/**
+	 * Constructor.
+	 */
+	public NavigationServiceImpl(Session session) {
+		setSession(session);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getChildren(java
+	 * .lang.String, java.lang.String, java.lang.String, java.lang.String,
+	 * java.lang.Boolean,
+	 * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String,
+	 * java.lang.Boolean, java.math.BigInteger, java.math.BigInteger,
+	 * org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter,
String orderBy,
+			Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
+			Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData
extension) {
+		ObjectInFolderListImpl result = new ObjectInFolderListImpl();
+
+		// find the link
+		String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+		if (link == null) {
+			throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+		url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
+		url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+		url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
+		url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
+		url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+		url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
+
+		// read and parse
+		HttpUtils.Response resp = read(url);
+		AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+
+		// handle top level
+		for (AtomElement element : feed.getElements()) {
+			if (element.getObject() instanceof AtomLink) {
+				if (isNextLink(element)) {
+					result.setHasMoreItems(Boolean.TRUE);
+				}
+			} else if (isInt(NAME_NUM_ITEMS, element)) {
+				result.setNumItems((BigInteger) element.getObject());
+			}
+		}
+
+		// get the children
+		if (!feed.getEntries().isEmpty()) {
+			result.setObjects(new ArrayList<ObjectInFolderData>(feed.getEntries().size()));
+
+			for (AtomEntry entry : feed.getEntries()) {
+				ObjectInFolderDataImpl child = null;
+				String pathSegment = null;
+
+				lockLinks();
+				try {
+					// clean up cache
+					removeLinks(repositoryId, entry.getId());
+
+					// walk through the entry
+					for (AtomElement element : entry.getElements()) {
+						if (element.getObject() instanceof AtomLink) {
+							addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+						} else if (isStr(NAME_PATH_SEGMENT, element)) {
+							pathSegment = (String) element.getObject();
+						} else if (element.getObject() instanceof CmisObjectType) {
+							child = new ObjectInFolderDataImpl();
+							child.setObject(convert((CmisObjectType) element.getObject()));
+						}
+					}
+				} finally {
+					unlockLinks();
+				}
+
+				if (child != null) {
+					child.setPathSegment(pathSegment);
+					result.getObjects().add(child);
+				}
+			}
+		}
+
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getDescendants(
+	 * java.lang.String, java.lang.String, java.math.BigInteger,
+	 * java.lang.String, java.lang.Boolean,
+	 * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String,
+	 * java.lang.Boolean, org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId,
BigInteger depth,
+			String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
+			String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
+		List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
+
+		// find the link
+		String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_DESCENDANTS);
+
+		if (link == null) {
+			throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_DESCENDANTS);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_DEPTH, depth);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+		url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+		url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
+		url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
+
+		// read and parse
+		HttpUtils.Response resp = read(url);
+		AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+
+		// process tree
+		addDescendantsLevel(repositoryId, feed, result);
+
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getFolderParent
+	 * (java.lang.String, java.lang.String, java.lang.String,
+	 * org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData
extension) {
+		ObjectData result = null;
+
+		// find the link
+		String link = loadLink(repositoryId, folderId, Constants.REL_UP, Constants.MEDIATYPE_ENTRY);
+
+		if (link == null) {
+			throwLinkException(repositoryId, folderId, Constants.REL_UP, Constants.MEDIATYPE_ENTRY);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+
+		// read
+		HttpUtils.Response resp = read(url);
+
+		AtomBase base = parse(resp.getStream(), AtomBase.class);
+
+		// get the entry
+		AtomEntry entry = null;
+		if (base instanceof AtomFeed) {
+			AtomFeed feed = (AtomFeed) base;
+			if (feed.getEntries().isEmpty()) {
+				throw new CmisRuntimeException("Parent feed is empty!");
+			}
+			entry = feed.getEntries().get(0);
+		} else if (base instanceof AtomEntry) {
+			entry = (AtomEntry) base;
+		} else {
+			throw new CmisRuntimeException("Unexpected document!");
+		}
+
+		lockLinks();
+		try {
+			// clean up cache
+			removeLinks(repositoryId, entry.getId());
+
+			// walk through the entry
+			for (AtomElement element : entry.getElements()) {
+				if (element.getObject() instanceof AtomLink) {
+					addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+				} else if (element.getObject() instanceof CmisObjectType) {
+					result = convert((CmisObjectType) element.getObject());
+				}
+			}
+		} finally {
+			unlockLinks();
+		}
+
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getFolderTree(java
+	 * .lang.String, java.lang.String, java.math.BigInteger, java.lang.String,
+	 * java.lang.Boolean,
+	 * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String,
+	 * java.lang.Boolean, org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public List<ObjectInFolderContainer> getFolderTree(String repositoryId, String folderId,
BigInteger depth,
+			String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
+			String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
+		List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
+
+		// find the link
+		String link = loadLink(repositoryId, folderId, Constants.REL_FOLDERTREE, Constants.MEDIATYPE_DESCENDANTS);
+
+		if (link == null) {
+			throwLinkException(repositoryId, folderId, Constants.REL_FOLDERTREE, Constants.MEDIATYPE_DESCENDANTS);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_DEPTH, depth);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+		url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+		url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
+		url.addParameter(Constants.PARAM_PATH_SEGMENT, includePathSegment);
+
+		// read and parse
+		HttpUtils.Response resp = read(url);
+		AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+
+		// process tree
+		addDescendantsLevel(repositoryId, feed, result);
+
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getObjectParents
+	 * (java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean,
+	 * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String,
+	 * java.lang.Boolean, org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public List<ObjectParentData> getObjectParents(String repositoryId, String objectId,
String filter,
+			Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
+			Boolean includeRelativePathSegment, ExtensionsData extension) {
+		List<ObjectParentData> result = new ArrayList<ObjectParentData>();
+
+		// find the link
+		String link = loadLink(repositoryId, objectId, Constants.REL_UP, Constants.MEDIATYPE_FEED);
+
+		if (link == null) {
+			throwLinkException(repositoryId, objectId, Constants.REL_UP, Constants.MEDIATYPE_FEED);
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+		url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+		url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
+		url.addParameter(Constants.PARAM_RELATIVE_PATH_SEGMENT, includeRelativePathSegment);
+
+		// read and parse
+		HttpUtils.Response resp = read(url);
+
+		AtomBase base = parse(resp.getStream(), AtomBase.class);
+
+		if (base instanceof AtomFeed) {
+			// it's a feed
+			AtomFeed feed = (AtomFeed) base;
+
+			// walk through the feed
+			for (AtomEntry entry : feed.getEntries()) {
+				ObjectParentDataImpl objectParent = processParentEntry(entry, repositoryId);
+
+				if (objectParent != null) {
+					result.add(objectParent);
+				}
+			}
+		} else if (base instanceof AtomEntry) {
+			// it's an entry
+			AtomEntry entry = (AtomEntry) base;
+
+			ObjectParentDataImpl objectParent = processParentEntry(entry, repositoryId);
+
+			if (objectParent != null) {
+				result.add(objectParent);
+			}
+		}
+
+		return result;
+	}
+
+	private ObjectParentDataImpl processParentEntry(AtomEntry entry, String repositoryId) {
+		ObjectParentDataImpl result = null;
+		String relativePathSegment = null;
+
+		lockLinks();
+		try {
+			// clean up cache
+			removeLinks(repositoryId, entry.getId());
+
+			// walk through the entry
+			for (AtomElement element : entry.getElements()) {
+				if (element.getObject() instanceof AtomLink) {
+					addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+				} else if (element.getObject() instanceof CmisObjectType) {
+					result = new ObjectParentDataImpl(convert((CmisObjectType) element.getObject()));
+				} else if (is(NAME_RELATIVE_PATH_SEGMENT, element)) {
+					relativePathSegment = (String) element.getObject();
+				}
+			}
+		} finally {
+			unlockLinks();
+		}
+
+		if (result != null) {
+			result.setRelativePathSegment(relativePathSegment);
+		}
+
+		return result;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.opencmis.client.provider.NavigationService#getCheckedOutDocs
+	 * (java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+	 * java.lang.Boolean,
+	 * org.apache.opencmis.commons.enums.IncludeRelationships, java.lang.String,
+	 * java.math.BigInteger, java.math.BigInteger,
+	 * org.apache.opencmis.client.provider.ExtensionsData)
+	 */
+	public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter,
String orderBy,
+			Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
+			BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
+		ObjectListImpl result = new ObjectListImpl();
+
+		// find the link
+		String link = loadCollection(repositoryId, Constants.COLLECTION_CHECKEDOUT);
+
+		if (link == null) {
+			throw new CmisObjectNotFoundException("Unknown repository or checkedout collection not
supported!");
+		}
+
+		UrlBuilder url = new UrlBuilder(link);
+		url.addParameter(Constants.PARAM_FOLDER_ID, folderId);
+		url.addParameter(Constants.PARAM_FILTER, filter);
+		url.addParameter(Constants.PARAM_ORDER_BY, orderBy);
+		url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+		url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
+		url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+		url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
+
+		// read and parse
+		HttpUtils.Response resp = read(url);
+		AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+
+		// handle top level
+		for (AtomElement element : feed.getElements()) {
+			if (element.getObject() instanceof AtomLink) {
+				if (isNextLink(element)) {
+					result.setHasMoreItems(Boolean.TRUE);
+				}
+			} else if (isInt(NAME_NUM_ITEMS, element)) {
+				result.setNumItems((BigInteger) element.getObject());
+			}
+		}
+
+		// get the documents
+		if (!feed.getEntries().isEmpty()) {
+			result.setObjects(new ArrayList<ObjectData>(feed.getEntries().size()));
+
+			for (AtomEntry entry : feed.getEntries()) {
+				ObjectData child = null;
+
+				lockLinks();
+				try {
+					// clean up cache
+					removeLinks(repositoryId, entry.getId());
+
+					// walk through the entry
+					for (AtomElement element : entry.getElements()) {
+						if (element.getObject() instanceof AtomLink) {
+							addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+						} else if (element.getObject() instanceof CmisObjectType) {
+							child = convert((CmisObjectType) element.getObject());
+						}
+					}
+				} finally {
+					unlockLinks();
+				}
+
+				if (child != null) {
+					result.getObjects().add(child);
+				}
+			}
+		}
+
+		return result;
+	}
+
+	// ---- internal ----
+
+	/**
+	 * Adds descendants level recursively.
+	 */
+	private void addDescendantsLevel(String repositoryId, AtomFeed feed, List<ObjectInFolderContainer>
containerList) {
+		if ((feed == null) || (feed.getEntries().isEmpty())) {
+			return;
+		}
+
+		// walk through the feed
+		for (AtomEntry entry : feed.getEntries()) {
+			ObjectInFolderDataImpl objectInFolder = null;
+			String pathSegment = null;
+			List<ObjectInFolderContainer> childContainerList = new ArrayList<ObjectInFolderContainer>();
+
+			lockLinks();
+			try {
+				// clean up cache
+				removeLinks(repositoryId, entry.getId());
+
+				// walk through the entry
+				for (AtomElement element : entry.getElements()) {
+					if (element.getObject() instanceof AtomLink) {
+						addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+					} else if (element.getObject() instanceof CmisObjectType) {
+						objectInFolder = new ObjectInFolderDataImpl(convert((CmisObjectType) element.getObject()));
+					} else if (is(NAME_PATH_SEGMENT, element)) {
+						pathSegment = (String) element.getObject();
+					} else if (element.getObject() instanceof AtomFeed) {
+						addDescendantsLevel(repositoryId, (AtomFeed) element.getObject(), childContainerList);
+					}
+				}
+			} finally {
+				unlockLinks();
+			}
+
+			if (objectInFolder != null) {
+				objectInFolder.setPathSegment(pathSegment);
+				ObjectInFolderContainerImpl childContainer = new ObjectInFolderContainerImpl(objectInFolder);
+				childContainer.setChildren(childContainerList);
+				containerList.add(childContainer);
+			}
+		}
+	}
 }



Mime
View raw message