chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r934896 [4/12] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/ chemistry-opencmis-server-bindings/src/main/java/org/apache/chemi...
Date Fri, 16 Apr 2010 14:14:02 GMT
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java?rev=934896&r1=934895&r2=934896&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java Fri Apr 16 14:14:00 2010
@@ -72,491 +72,465 @@ import org.apache.chemistry.opencmis.ser
  */
 public final class ObjectService {
 
-  private static final int BUFFER_SIZE = 64 * 1024;
+	private static final int BUFFER_SIZE = 64 * 1024;
 
-  /**
-   * Create*.
-   */
-  public static void create(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-
-    // get parameters
-    String folderId = getStringParameter(request, Constants.PARAM_ID);
-    String sourceFolderId = getStringParameter(request, Constants.PARAM_SOURCE_FOLDER_ID);
-    VersioningState versioningState = getEnumParameter(request, Constants.PARAM_VERSIONIG_STATE,
-        VersioningState.class);
-
-    AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
-    String objectId = parser.getId();
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData object = null;
-
-    if (objectId == null) {
-      // create
-      CmisObjectService service = factory.getObjectService();
-      object = service.create(context, repositoryId, parser.getProperties(), folderId, parser
-          .getContentStream(), versioningState, parser.getPolicyIds(), null, objectInfoHolder);
-    }
-    else {
-      if ((sourceFolderId == null) || (sourceFolderId.trim().length() == 0)) {
-        // addObjectToFolder
-        CmisMultiFilingService service = factory.getMultiFilingService();
-        object = service.addObjectToFolder(context, repositoryId, objectId, sourceFolderId, null,
-            null, objectInfoHolder);
-      }
-      else {
-        // move
-        CmisObjectService service = factory.getObjectService();
-        object = service.moveObject(context, repositoryId, new Holder<String>(objectId), folderId,
-            sourceFolderId, null, objectInfoHolder);
-      }
-    }
-
-    if (object == null) {
-      throw new CmisRuntimeException("Object is null!");
-    }
-
-    if (object.getId() == null) {
-      throw new CmisRuntimeException("Object Id is null!");
-    }
-
-    // set headers
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    response.setStatus(HttpServletResponse.SC_CREATED);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-    response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
-
-    // write XML
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
-    entry.endDocument();
-  }
-
-  /**
-   * Create relationship.
-   */
-  public static void createRelationship(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData object = service.create(context, repositoryId, parser.getProperties(), null, null,
-        null, parser.getPolicyIds(), null, objectInfoHolder);
-
-    // set headers
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    response.setStatus(HttpServletResponse.SC_CREATED);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-    response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
-
-    // write XML
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
-    entry.endDocument();
-  }
-
-  /**
-   * Delete object.
-   */
-  public static void deleteObject(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
-
-    // execute
-    service.deleteObjectOrCancelCheckOut(context, repositoryId, objectId, allVersions, null);
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-  }
-
-  /**
-   * Delete content stream.
-   */
-  public static void deleteContentStream(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    String changeToken = getStringParameter(request, Constants.PARAM_CHANGE_TOKEN);
-
-    // execute
-    service.deleteContentStream(context, repositoryId, new Holder<String>(objectId),
-        changeToken == null ? null : new Holder<String>(changeToken), null);
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-  }
-
-  /**
-   * Set content stream.
-   */
-  public static void setContentStream(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    String changeToken = getStringParameter(request, Constants.PARAM_CHANGE_TOKEN);
-    Boolean overwriteFlag = getBooleanParameter(request, Constants.PARAM_OVERWRITE_FLAG);
-
-    ContentStreamImpl contentStream = new ContentStreamImpl();
-    contentStream.setStream(request.getInputStream());
-    contentStream.setMimeType(request.getHeader("Content-Type"));
-    String lengthStr = request.getHeader("Content-Length");
-    if (lengthStr != null) {
-      try {
-        contentStream.setLength(new BigInteger(lengthStr));
-      }
-      catch (NumberFormatException e) {
-      }
-    }
-
-    // execute
-    Holder<String> objectIdHolder = new Holder<String>(objectId);
-    service.setContentStream(context, repositoryId, objectIdHolder, overwriteFlag,
-        changeToken == null ? null : new Holder<String>(changeToken), contentStream, null);
-
-    // set headers
-    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
-    String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT,
-        newObjectId);
-
-    response.setStatus(HttpServletResponse.SC_CREATED);
-    response.setHeader("Content-Location", location);
-    response.setHeader("Location", location);
-  }
-
-  /**
-   * Delete tree.
-   */
-  public static void deleteTree(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String folderId = getStringParameter(request, Constants.PARAM_ID);
-    Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
-    UnfileObject unfileObjects = getEnumParameter(request, Constants.PARAM_UNFILE_OBJECTS,
-        UnfileObject.class);
-    Boolean continueOnFailure = getBooleanParameter(request, Constants.PARAM_CONTINUE_ON_FAILURE);
-
-    // execute
-    FailedToDeleteData ftd = service.deleteTree(context, repositoryId, folderId, allVersions,
-        unfileObjects, continueOnFailure, null);
-
-    if ((ftd != null) && (ftd.getIds() != null) && (ftd.getIds().size() > 0)) {
-      // print ids that could not be deleted
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-      response.setContentType("text/plain");
-
-      PrintWriter pw = response.getWriter();
-
-      pw.println("Failed to delete the following objects:");
-      for (String id : ftd.getIds()) {
-        pw.println(id);
-      }
-
-      pw.flush();
-
-      return;
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-  }
-
-  /**
-   * getObject.
-   */
-  public static void getObject(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    ReturnVersion returnVersion = getEnumParameter(request, Constants.PARAM_RETURN_VERSION,
-        ReturnVersion.class);
-    String filter = getStringParameter(request, Constants.PARAM_FILTER);
-    Boolean includeAllowableActions = getBooleanParameter(request,
-        Constants.PARAM_ALLOWABLE_ACTIONS);
-    IncludeRelationships includeRelationships = getEnumParameter(request,
-        Constants.PARAM_RELATIONSHIPS, IncludeRelationships.class);
-    String renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
-    Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
-    Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData object = null;
-
-    if ((returnVersion == ReturnVersion.LATEST) || (returnVersion == ReturnVersion.LASTESTMAJOR)) {
-      CmisVersioningService service = factory.getVersioningService();
-      object = service.getObjectOfLatestVersion(context, repositoryId, objectId,
-          returnVersion == ReturnVersion.LASTESTMAJOR, filter, includeAllowableActions,
-          includeRelationships, renditionFilter, includePolicyIds, includeAcl, null,
-          objectInfoHolder);
-    }
-    else {
-      CmisObjectService service = factory.getObjectService();
-      object = service.getObject(context, repositoryId, objectId, filter, includeAllowableActions,
-          includeRelationships, renditionFilter, includePolicyIds, includeAcl, null,
-          objectInfoHolder);
-    }
-
-    if (object == null) {
-      throw new CmisRuntimeException("Object is null!");
-    }
-
-    ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(object.getId());
-    if (objectInfo == null) {
-      throw new CmisRuntimeException("Object Info is missing!");
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-
-    // write XML
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
-    entry.endDocument();
-  }
-
-  /**
-   * objectByPath URI template.
-   */
-  public static void getObjectByPath(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String path = getStringParameter(request, Constants.PARAM_PATH);
-    String filter = getStringParameter(request, Constants.PARAM_FILTER);
-    Boolean includeAllowableActions = getBooleanParameter(request,
-        Constants.PARAM_ALLOWABLE_ACTIONS);
-    IncludeRelationships includeRelationships = getEnumParameter(request,
-        Constants.PARAM_RELATIONSHIPS, IncludeRelationships.class);
-    String renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
-    Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
-    Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData object = service.getObjectByPath(context, repositoryId, path, filter,
-        includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds,
-        includeAcl, null, objectInfoHolder);
-
-    if (object == null) {
-      throw new CmisRuntimeException("Object is null!");
-    }
-
-    ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(object.getId());
-    if (objectInfo == null) {
-      throw new CmisRuntimeException("Object Info is missing!");
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-
-    // write XML
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
-    entry.endDocument();
-  }
-
-  /**
-   * Allowable Actions.
-   */
-  public static void getAllowableActions(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-
-    // execute
-    AllowableActions allowableActions = service.getAllowableActions(context, repositoryId,
-        objectId, null);
-
-    if (allowableActions == null) {
-      throw new CmisRuntimeException("Allowable Actions is null!");
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_ALLOWABLEACTION);
-
-    // write XML
-    AllowableActionsDocument allowableActionsDocument = new AllowableActionsDocument();
-    allowableActionsDocument.writeAllowableActions(allowableActions, response.getOutputStream());
-  }
-
-  /**
-   * getContentStream.
-   */
-  public static void getContentStream(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisObjectService service = factory.getObjectService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    String streamId = getStringParameter(request, Constants.PARAM_STREAM_ID);
-
-    BigInteger offset = null;
-    String offsetStr = context.get(CallContext.OFFSET);
-    if (offsetStr != null) {
-      offset = new BigInteger(offsetStr);
-    }
-
-    BigInteger length = null;
-    String lengthStr = context.get(CallContext.LENGTH);
-    if (lengthStr != null) {
-      length = new BigInteger(offsetStr);
-    }
-
-    // execute
-    ContentStream content = service.getContentStream(context, repositoryId, objectId, streamId,
-        offset, length, null);
-
-    if ((content == null) || (content.getStream() == null)) {
-      throw new CmisRuntimeException("Content stream is null!");
-    }
-
-    String contentType = content.getMimeType();
-    if (contentType == null) {
-      contentType = Constants.MEDIATYPE_OCTETSTREAM;
-    }
-
-    // set headers
-    if ((offset == null) && (length == null)) {
-      response.setStatus(HttpServletResponse.SC_OK);
-    }
-    else {
-      response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
-    }
-    response.setContentType(contentType);
-
-    // send content
-    InputStream in = new BufferedInputStream(content.getStream(), BUFFER_SIZE);
-    OutputStream out = new BufferedOutputStream(response.getOutputStream());
-
-    byte[] buffer = new byte[BUFFER_SIZE];
-    int b;
-    while ((b = in.read(buffer)) > -1) {
-      out.write(buffer, 0, b);
-    }
-
-    in.close();
-    out.flush();
-  }
-
-  /**
-   * UpdateProperties.
-   */
-  public static void updateProperties(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    Boolean checkin = getBooleanParameter(request, Constants.PARAM_CHECK_IN);
-    String checkinComment = getStringParameter(request, Constants.PARAM_CHECKIN_COMMENT);
-    Boolean major = getBooleanParameter(request, Constants.PARAM_MAJOR);
-
-    AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData object = null;
-
-    if ((checkin != null) && (checkin.booleanValue())) {
-      CmisVersioningService service = factory.getVersioningService();
-      object = service.checkIn(context, repositoryId, new Holder<String>(objectId), major, parser
-          .getProperties(), parser.getContentStream(), checkinComment, parser.getPolicyIds(), null,
-          null, null, objectInfoHolder);
-    }
-    else {
-      String changeToken = extractChangeToken(parser.getProperties());
-
-      CmisObjectService service = factory.getObjectService();
-      object = service.updateProperties(context, repositoryId, new Holder<String>(objectId),
-          changeToken == null ? null : new Holder<String>(changeToken), parser.getProperties(),
-          parser.getAcl(), null, objectInfoHolder);
-    }
-
-    if (object == null) {
-      throw new CmisRuntimeException("Object 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());
-    writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
-    entry.endDocument();
-  }
-
-  /**
-   * Gets the change token from a property set.
-   */
-  private static String extractChangeToken(Properties properties) {
-    if (properties == null) {
-      return null;
-    }
-
-    Map<String, PropertyData<?>> propertiesMap = properties.getProperties();
-    if (propertiesMap == null) {
-      return null;
-    }
-
-    PropertyData<?> changeLogProperty = propertiesMap.get(PropertyIds.CHANGE_TOKEN);
-    if (!(changeLogProperty instanceof PropertyString)) {
-      return null;
-    }
+	/**
+	 * Create*.
+	 */
+	public static void create(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+		// get parameters
+		String folderId = getStringParameter(request, Constants.PARAM_ID);
+		String sourceFolderId = getStringParameter(request, Constants.PARAM_SOURCE_FOLDER_ID);
+		VersioningState versioningState = getEnumParameter(request, Constants.PARAM_VERSIONIG_STATE,
+				VersioningState.class);
+
+		AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+		String objectId = parser.getId();
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData object = null;
+
+		if (objectId == null) {
+			// create
+			CmisObjectService service = factory.getObjectService();
+			object = service.create(context, repositoryId, parser.getProperties(), folderId, parser.getContentStream(),
+					versioningState, parser.getPolicyIds(), null, objectInfoHolder);
+		} else {
+			if ((sourceFolderId == null) || (sourceFolderId.trim().length() == 0)) {
+				// addObjectToFolder
+				CmisMultiFilingService service = factory.getMultiFilingService();
+				object = service.addObjectToFolder(context, repositoryId, objectId, sourceFolderId, null, null,
+						objectInfoHolder);
+			} else {
+				// move
+				CmisObjectService service = factory.getObjectService();
+				object = service.moveObject(context, repositoryId, new Holder<String>(objectId), folderId,
+						sourceFolderId, null, objectInfoHolder);
+			}
+		}
+
+		if (object == null) {
+			throw new CmisRuntimeException("Object is null!");
+		}
+
+		if (object.getId() == null) {
+			throw new CmisRuntimeException("Object Id is null!");
+		}
+
+		// set headers
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		response.setStatus(HttpServletResponse.SC_CREATED);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+		response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
+
+		// write XML
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+		entry.endDocument();
+	}
+
+	/**
+	 * Create relationship.
+	 */
+	public static void createRelationship(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData object = service.create(context, repositoryId, parser.getProperties(), null, null, null, parser
+				.getPolicyIds(), null, objectInfoHolder);
+
+		// set headers
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		response.setStatus(HttpServletResponse.SC_CREATED);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+		response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
+
+		// write XML
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+		entry.endDocument();
+	}
+
+	/**
+	 * Delete object.
+	 */
+	public static void deleteObject(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
+
+		// execute
+		service.deleteObjectOrCancelCheckOut(context, repositoryId, objectId, allVersions, null);
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+	}
+
+	/**
+	 * Delete content stream.
+	 */
+	public static void deleteContentStream(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		String changeToken = getStringParameter(request, Constants.PARAM_CHANGE_TOKEN);
+
+		// execute
+		service.deleteContentStream(context, repositoryId, new Holder<String>(objectId), changeToken == null ? null
+				: new Holder<String>(changeToken), null);
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+	}
+
+	/**
+	 * Set content stream.
+	 */
+	public static void setContentStream(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		String changeToken = getStringParameter(request, Constants.PARAM_CHANGE_TOKEN);
+		Boolean overwriteFlag = getBooleanParameter(request, Constants.PARAM_OVERWRITE_FLAG);
+
+		ContentStreamImpl contentStream = new ContentStreamImpl();
+		contentStream.setStream(request.getInputStream());
+		contentStream.setMimeType(request.getHeader("Content-Type"));
+		String lengthStr = request.getHeader("Content-Length");
+		if (lengthStr != null) {
+			try {
+				contentStream.setLength(new BigInteger(lengthStr));
+			} catch (NumberFormatException e) {
+			}
+		}
+
+		// execute
+		Holder<String> objectIdHolder = new Holder<String>(objectId);
+		service.setContentStream(context, repositoryId, objectIdHolder, overwriteFlag, changeToken == null ? null
+				: new Holder<String>(changeToken), contentStream, null);
+
+		// set headers
+		String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
+		String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, newObjectId);
+
+		response.setStatus(HttpServletResponse.SC_CREATED);
+		response.setHeader("Content-Location", location);
+		response.setHeader("Location", location);
+	}
+
+	/**
+	 * Delete tree.
+	 */
+	public static void deleteTree(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String folderId = getStringParameter(request, Constants.PARAM_ID);
+		Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
+		UnfileObject unfileObjects = getEnumParameter(request, Constants.PARAM_UNFILE_OBJECTS, UnfileObject.class);
+		Boolean continueOnFailure = getBooleanParameter(request, Constants.PARAM_CONTINUE_ON_FAILURE);
+
+		// execute
+		FailedToDeleteData ftd = service.deleteTree(context, repositoryId, folderId, allVersions, unfileObjects,
+				continueOnFailure, null);
+
+		if ((ftd != null) && (ftd.getIds() != null) && (ftd.getIds().size() > 0)) {
+			// print ids that could not be deleted
+			response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+			response.setContentType("text/plain");
+
+			PrintWriter pw = response.getWriter();
+
+			pw.println("Failed to delete the following objects:");
+			for (String id : ftd.getIds()) {
+				pw.println(id);
+			}
+
+			pw.flush();
+
+			return;
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+	}
+
+	/**
+	 * getObject.
+	 */
+	public static void getObject(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		ReturnVersion returnVersion = getEnumParameter(request, Constants.PARAM_RETURN_VERSION, ReturnVersion.class);
+		String filter = getStringParameter(request, Constants.PARAM_FILTER);
+		Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
+		IncludeRelationships includeRelationships = getEnumParameter(request, Constants.PARAM_RELATIONSHIPS,
+				IncludeRelationships.class);
+		String renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
+		Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
+		Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData object = null;
+
+		if ((returnVersion == ReturnVersion.LATEST) || (returnVersion == ReturnVersion.LASTESTMAJOR)) {
+			CmisVersioningService service = factory.getVersioningService();
+			object = service.getObjectOfLatestVersion(context, repositoryId, objectId,
+					returnVersion == ReturnVersion.LASTESTMAJOR, filter, includeAllowableActions, includeRelationships,
+					renditionFilter, includePolicyIds, includeAcl, null, objectInfoHolder);
+		} else {
+			CmisObjectService service = factory.getObjectService();
+			object = service.getObject(context, repositoryId, objectId, filter, includeAllowableActions,
+					includeRelationships, renditionFilter, includePolicyIds, includeAcl, null, objectInfoHolder);
+		}
+
+		if (object == null) {
+			throw new CmisRuntimeException("Object is null!");
+		}
+
+		ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(object.getId());
+		if (objectInfo == null) {
+			throw new CmisRuntimeException("Object Info is missing!");
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+
+		// write XML
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+		entry.endDocument();
+	}
+
+	/**
+	 * objectByPath URI template.
+	 */
+	public static void getObjectByPath(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String path = getStringParameter(request, Constants.PARAM_PATH);
+		String filter = getStringParameter(request, Constants.PARAM_FILTER);
+		Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
+		IncludeRelationships includeRelationships = getEnumParameter(request, Constants.PARAM_RELATIONSHIPS,
+				IncludeRelationships.class);
+		String renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
+		Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
+		Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData object = service.getObjectByPath(context, repositoryId, path, filter, includeAllowableActions,
+				includeRelationships, renditionFilter, includePolicyIds, includeAcl, null, objectInfoHolder);
+
+		if (object == null) {
+			throw new CmisRuntimeException("Object is null!");
+		}
+
+		ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(object.getId());
+		if (objectInfo == null) {
+			throw new CmisRuntimeException("Object Info is missing!");
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+
+		// write XML
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+		entry.endDocument();
+	}
+
+	/**
+	 * Allowable Actions.
+	 */
+	public static void getAllowableActions(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+
+		// execute
+		AllowableActions allowableActions = service.getAllowableActions(context, repositoryId, objectId, null);
+
+		if (allowableActions == null) {
+			throw new CmisRuntimeException("Allowable Actions is null!");
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_ALLOWABLEACTION);
+
+		// write XML
+		AllowableActionsDocument allowableActionsDocument = new AllowableActionsDocument();
+		allowableActionsDocument.writeAllowableActions(allowableActions, response.getOutputStream());
+	}
+
+	/**
+	 * getContentStream.
+	 */
+	public static void getContentStream(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisObjectService service = factory.getObjectService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		String streamId = getStringParameter(request, Constants.PARAM_STREAM_ID);
+
+		BigInteger offset = null;
+		String offsetStr = context.get(CallContext.OFFSET);
+		if (offsetStr != null) {
+			offset = new BigInteger(offsetStr);
+		}
+
+		BigInteger length = null;
+		String lengthStr = context.get(CallContext.LENGTH);
+		if (lengthStr != null) {
+			length = new BigInteger(offsetStr);
+		}
+
+		// execute
+		ContentStream content = service.getContentStream(context, repositoryId, objectId, streamId, offset, length,
+				null);
+
+		if ((content == null) || (content.getStream() == null)) {
+			throw new CmisRuntimeException("Content stream is null!");
+		}
+
+		String contentType = content.getMimeType();
+		if (contentType == null) {
+			contentType = Constants.MEDIATYPE_OCTETSTREAM;
+		}
+
+		// set headers
+		if ((offset == null) && (length == null)) {
+			response.setStatus(HttpServletResponse.SC_OK);
+		} else {
+			response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
+		}
+		response.setContentType(contentType);
+
+		// send content
+		InputStream in = new BufferedInputStream(content.getStream(), BUFFER_SIZE);
+		OutputStream out = new BufferedOutputStream(response.getOutputStream());
+
+		byte[] buffer = new byte[BUFFER_SIZE];
+		int b;
+		while ((b = in.read(buffer)) > -1) {
+			out.write(buffer, 0, b);
+		}
+
+		in.close();
+		out.flush();
+	}
+
+	/**
+	 * UpdateProperties.
+	 */
+	public static void updateProperties(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		Boolean checkin = getBooleanParameter(request, Constants.PARAM_CHECK_IN);
+		String checkinComment = getStringParameter(request, Constants.PARAM_CHECKIN_COMMENT);
+		Boolean major = getBooleanParameter(request, Constants.PARAM_MAJOR);
+
+		AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData object = null;
+
+		if ((checkin != null) && (checkin.booleanValue())) {
+			CmisVersioningService service = factory.getVersioningService();
+			object = service.checkIn(context, repositoryId, new Holder<String>(objectId), major,
+					parser.getProperties(), parser.getContentStream(), checkinComment, parser.getPolicyIds(), null,
+					null, null, objectInfoHolder);
+		} else {
+			String changeToken = extractChangeToken(parser.getProperties());
+
+			CmisObjectService service = factory.getObjectService();
+			object = service.updateProperties(context, repositoryId, new Holder<String>(objectId),
+					changeToken == null ? null : new Holder<String>(changeToken), parser.getProperties(), parser
+							.getAcl(), null, objectInfoHolder);
+		}
+
+		if (object == null) {
+			throw new CmisRuntimeException("Object 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());
+		writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+		entry.endDocument();
+	}
+
+	/**
+	 * Gets the change token from a property set.
+	 */
+	private static String extractChangeToken(Properties properties) {
+		if (properties == null) {
+			return null;
+		}
+
+		Map<String, PropertyData<?>> propertiesMap = properties.getProperties();
+		if (propertiesMap == null) {
+			return null;
+		}
+
+		PropertyData<?> changeLogProperty = propertiesMap.get(PropertyIds.CHANGE_TOKEN);
+		if (!(changeLogProperty instanceof PropertyString)) {
+			return null;
+		}
 
-    return ((PropertyString) changeLogProperty).getFirstValue();
-  }
+		return ((PropertyString) changeLogProperty).getFirstValue();
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java?rev=934896&r1=934895&r2=934896&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java Fri Apr 16 14:14:00 2010
@@ -50,153 +50,150 @@ import org.apache.chemistry.opencmis.ser
  */
 public class PolicyService {
 
-  /**
-   * Get applied policies.
-   */
-  public static void getAppliedPolicies(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisPolicyService service = factory.getPolicyService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    String filter = getStringParameter(request, Constants.PARAM_FILTER);
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    List<ObjectData> policies = service.getAppliedPolicies(context, repositoryId, objectId, filter,
-        null, objectInfoHolder);
-
-    if (policies == null) {
-      throw new CmisRuntimeException("Policies are null!");
-    }
-
-    ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(objectId);
-    if (objectInfo == null) {
-      throw new CmisRuntimeException("Object Info is missing!");
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_FEED);
-
-    // write XML
-    AtomFeed feed = new AtomFeed();
-    feed.startDocument(response.getOutputStream());
-    feed.startFeed(true);
-
-    // write basic Atom feed elements
-    feed.writeFeedElements(objectInfo.getId(), objectInfo.getCreatedBy(), objectInfo.getName(),
-        objectInfo.getLastModificationDate(), null, null);
-
-    // write links
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    feed.writeServiceLink(baseUrl.toString(), repositoryId);
-
-    feed.writeSelfLink(compileUrl(baseUrl, RESOURCE_POLICIES, objectInfo.getId()), null);
-
-    // write entries
-    if (policies != null) {
-      AtomEntry entry = new AtomEntry(feed.getWriter());
-      for (ObjectData policy : policies) {
-        if (policy == null) {
-          continue;
-        }
-        writePolicyEntry(entry, objectInfo.getId(), policy, objectInfoHolder, baseUrl);
-      }
-    }
-
-    // we are done
-    feed.endFeed();
-    feed.endDocument();
-  }
-
-  /**
-   * Apply policy.
-   */
-  public static void applyPolicy(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisPolicyService service = factory.getPolicyService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-
-    AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectData policy = service.applyPolicy(context, repositoryId, parser.getId(), objectId, null,
-        objectInfoHolder);
-
-    if (policy == null) {
-      throw new CmisRuntimeException("Policy is null!");
-    }
-
-    // set headers
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-    UrlBuilder location = compileUrlBuilder(baseUrl, RESOURCE_POLICIES, objectId);
-    location.addParameter(Constants.PARAM_POLICY_ID, policy.getId());
-
-    response.setStatus(HttpServletResponse.SC_CREATED);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-    response.setHeader("Content-Location", location.toString());
-    response.setHeader("Location", location.toString());
-
-    // write XML
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writePolicyEntry(entry, objectId, policy, objectInfoHolder, baseUrl);
-    entry.endDocument();
-  }
-
-  /**
-   * Remove policy.
-   */
-  public static void removePolicy(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisPolicyService service = factory.getPolicyService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    String policyId = getStringParameter(request, Constants.PARAM_POLICY_ID);
-
-    // execute
-    service.removePolicy(context, repositoryId, policyId, objectId, null);
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-  }
-
-  /**
-   * Writes an entry that is attached to an object.
-   */
-  private static void writePolicyEntry(AtomEntry entry, String objectId, ObjectData policy,
-      ObjectInfoHolder infoHolder, UrlBuilder baseUrl) throws Exception {
-    CmisObjectType resultJaxb = convert(policy);
-    if (resultJaxb == null) {
-      return;
-    }
-
-    ObjectInfo info = infoHolder.getObjectInfo(policy.getId());
-    if (info == null) {
-      throw new CmisRuntimeException("Object Info not found!");
-    }
-
-    // start
-    entry.startEntry(false);
-
-    // write the object
-    entry.writeObject(policy, info, null, null, null, null);
-
-    // write links
-    UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_POLICIES, objectId);
-    selfLink.addParameter(Constants.PARAM_POLICY_ID, info.getId());
-    entry.writeSelfLink(selfLink.toString(), null);
-
-    // we are done
-    entry.endEntry();
-  }
+	/**
+	 * Get applied policies.
+	 */
+	public static void getAppliedPolicies(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisPolicyService service = factory.getPolicyService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		String filter = getStringParameter(request, Constants.PARAM_FILTER);
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		List<ObjectData> policies = service.getAppliedPolicies(context, repositoryId, objectId, filter, null,
+				objectInfoHolder);
+
+		if (policies == null) {
+			throw new CmisRuntimeException("Policies are null!");
+		}
+
+		ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(objectId);
+		if (objectInfo == null) {
+			throw new CmisRuntimeException("Object Info is missing!");
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_FEED);
+
+		// write XML
+		AtomFeed feed = new AtomFeed();
+		feed.startDocument(response.getOutputStream());
+		feed.startFeed(true);
+
+		// write basic Atom feed elements
+		feed.writeFeedElements(objectInfo.getId(), objectInfo.getCreatedBy(), objectInfo.getName(), objectInfo
+				.getLastModificationDate(), null, null);
+
+		// write links
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		feed.writeServiceLink(baseUrl.toString(), repositoryId);
+
+		feed.writeSelfLink(compileUrl(baseUrl, RESOURCE_POLICIES, objectInfo.getId()), null);
+
+		// write entries
+		if (policies != null) {
+			AtomEntry entry = new AtomEntry(feed.getWriter());
+			for (ObjectData policy : policies) {
+				if (policy == null) {
+					continue;
+				}
+				writePolicyEntry(entry, objectInfo.getId(), policy, objectInfoHolder, baseUrl);
+			}
+		}
+
+		// we are done
+		feed.endFeed();
+		feed.endDocument();
+	}
+
+	/**
+	 * Apply policy.
+	 */
+	public static void applyPolicy(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisPolicyService service = factory.getPolicyService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+
+		AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectData policy = service
+				.applyPolicy(context, repositoryId, parser.getId(), objectId, null, objectInfoHolder);
+
+		if (policy == null) {
+			throw new CmisRuntimeException("Policy is null!");
+		}
+
+		// set headers
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+		UrlBuilder location = compileUrlBuilder(baseUrl, RESOURCE_POLICIES, objectId);
+		location.addParameter(Constants.PARAM_POLICY_ID, policy.getId());
+
+		response.setStatus(HttpServletResponse.SC_CREATED);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+		response.setHeader("Content-Location", location.toString());
+		response.setHeader("Location", location.toString());
+
+		// write XML
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writePolicyEntry(entry, objectId, policy, objectInfoHolder, baseUrl);
+		entry.endDocument();
+	}
+
+	/**
+	 * Remove policy.
+	 */
+	public static void removePolicy(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisPolicyService service = factory.getPolicyService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		String policyId = getStringParameter(request, Constants.PARAM_POLICY_ID);
+
+		// execute
+		service.removePolicy(context, repositoryId, policyId, objectId, null);
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+	}
+
+	/**
+	 * Writes an entry that is attached to an object.
+	 */
+	private static void writePolicyEntry(AtomEntry entry, String objectId, ObjectData policy,
+			ObjectInfoHolder infoHolder, UrlBuilder baseUrl) throws Exception {
+		CmisObjectType resultJaxb = convert(policy);
+		if (resultJaxb == null) {
+			return;
+		}
+
+		ObjectInfo info = infoHolder.getObjectInfo(policy.getId());
+		if (info == null) {
+			throw new CmisRuntimeException("Object Info not found!");
+		}
+
+		// start
+		entry.startEntry(false);
+
+		// write the object
+		entry.writeObject(policy, info, null, null, null, null);
+
+		// write links
+		UrlBuilder selfLink = compileUrlBuilder(baseUrl, RESOURCE_POLICIES, objectId);
+		selfLink.addParameter(Constants.PARAM_POLICY_ID, info.getId());
+		entry.writeSelfLink(selfLink.toString(), null);
+
+		// we are done
+		entry.endEntry();
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RelationshipService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RelationshipService.java?rev=934896&r1=934895&r2=934896&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RelationshipService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RelationshipService.java Fri Apr 16 14:14:00 2010
@@ -54,86 +54,81 @@ import org.apache.chemistry.opencmis.ser
  */
 public class RelationshipService {
 
-  /**
-   * Get object relationships.
-   */
-  public static void getObjectRelationships(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisRelationshipService service = factory.getRelationshipService();
-
-    // get parameters
-    String objectId = getStringParameter(request, Constants.PARAM_ID);
-    Boolean includeSubRelationshipTypes = getBooleanParameter(request,
-        Constants.PARAM_SUB_RELATIONSHIP_TYPES);
-    RelationshipDirection relationshipDirection = getEnumParameter(request,
-        Constants.PARAM_RELATIONSHIP_DIRECTION, RelationshipDirection.class);
-    String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
-    String filter = getStringParameter(request, Constants.PARAM_FILTER);
-    Boolean includeAllowableActions = getBooleanParameter(request,
-        Constants.PARAM_ALLOWABLE_ACTIONS);
-    BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
-    BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
-
-    // execute
-    ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
-    ObjectList relationships = service.getObjectRelationships(context, repositoryId, objectId,
-        includeSubRelationshipTypes, relationshipDirection, typeId, filter,
-        includeAllowableActions, maxItems, skipCount, null, objectInfoHolder);
-
-    if (relationships == null) {
-      throw new CmisRuntimeException("Relationships are null!");
-    }
-
-    ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(objectId);
-    if (objectInfo == null) {
-      throw new CmisRuntimeException("Object Info is missing!");
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_FEED);
-
-    // write XML
-    AtomFeed feed = new AtomFeed();
-    feed.startDocument(response.getOutputStream());
-    feed.startFeed(true);
-
-    // write basic Atom feed elements
-    feed.writeFeedElements(objectInfo.getId(), objectInfo.getCreatedBy(), objectInfo.getName(),
-        objectInfo.getLastModificationDate(), null, relationships.getNumItems());
-
-    // write links
-    UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
-    feed.writeServiceLink(baseUrl.toString(), repositoryId);
-
-    feed.writeSelfLink(compileUrl(baseUrl, RESOURCE_RELATIONSHIPS, objectInfo.getId()), null);
-
-    UrlBuilder pagingUrl = new UrlBuilder(compileUrlBuilder(baseUrl, RESOURCE_RELATIONSHIPS,
-        objectInfo.getId()));
-    pagingUrl.addParameter(Constants.PARAM_SUB_RELATIONSHIP_TYPES, includeSubRelationshipTypes);
-    pagingUrl.addParameter(Constants.PARAM_RELATIONSHIP_DIRECTION, relationshipDirection);
-    pagingUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
-    pagingUrl.addParameter(Constants.PARAM_FILTER, filter);
-    pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
-    feed.writePagingLinks(pagingUrl, maxItems, skipCount, relationships.getNumItems(),
-        relationships.hasMoreItems(), AtomPubUtils.PAGE_SIZE);
-
-    // write entries
-    if (relationships != null) {
-      AtomEntry entry = new AtomEntry(feed.getWriter());
-      for (ObjectData object : relationships.getObjects()) {
-        if (object == null) {
-          continue;
-        }
-        writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl,
-            false);
-      }
-    }
-
-    // we are done
-    feed.endFeed();
-    feed.endDocument();
-  }
+	/**
+	 * Get object relationships.
+	 */
+	public static void getObjectRelationships(CallContext context, AbstractServicesFactory factory,
+			String repositoryId, HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisRelationshipService service = factory.getRelationshipService();
+
+		// get parameters
+		String objectId = getStringParameter(request, Constants.PARAM_ID);
+		Boolean includeSubRelationshipTypes = getBooleanParameter(request, Constants.PARAM_SUB_RELATIONSHIP_TYPES);
+		RelationshipDirection relationshipDirection = getEnumParameter(request, Constants.PARAM_RELATIONSHIP_DIRECTION,
+				RelationshipDirection.class);
+		String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+		String filter = getStringParameter(request, Constants.PARAM_FILTER);
+		Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
+		BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
+		BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
+
+		// execute
+		ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+		ObjectList relationships = service.getObjectRelationships(context, repositoryId, objectId,
+				includeSubRelationshipTypes, relationshipDirection, typeId, filter, includeAllowableActions, maxItems,
+				skipCount, null, objectInfoHolder);
+
+		if (relationships == null) {
+			throw new CmisRuntimeException("Relationships are null!");
+		}
+
+		ObjectInfo objectInfo = objectInfoHolder.getObjectInfo(objectId);
+		if (objectInfo == null) {
+			throw new CmisRuntimeException("Object Info is missing!");
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_FEED);
+
+		// write XML
+		AtomFeed feed = new AtomFeed();
+		feed.startDocument(response.getOutputStream());
+		feed.startFeed(true);
+
+		// write basic Atom feed elements
+		feed.writeFeedElements(objectInfo.getId(), objectInfo.getCreatedBy(), objectInfo.getName(), objectInfo
+				.getLastModificationDate(), null, relationships.getNumItems());
+
+		// write links
+		UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+		feed.writeServiceLink(baseUrl.toString(), repositoryId);
+
+		feed.writeSelfLink(compileUrl(baseUrl, RESOURCE_RELATIONSHIPS, objectInfo.getId()), null);
+
+		UrlBuilder pagingUrl = new UrlBuilder(compileUrlBuilder(baseUrl, RESOURCE_RELATIONSHIPS, objectInfo.getId()));
+		pagingUrl.addParameter(Constants.PARAM_SUB_RELATIONSHIP_TYPES, includeSubRelationshipTypes);
+		pagingUrl.addParameter(Constants.PARAM_RELATIONSHIP_DIRECTION, relationshipDirection);
+		pagingUrl.addParameter(Constants.PARAM_TYPE_ID, typeId);
+		pagingUrl.addParameter(Constants.PARAM_FILTER, filter);
+		pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+		feed.writePagingLinks(pagingUrl, maxItems, skipCount, relationships.getNumItems(),
+				relationships.hasMoreItems(), AtomPubUtils.PAGE_SIZE);
+
+		// write entries
+		if (relationships != null) {
+			AtomEntry entry = new AtomEntry(feed.getWriter());
+			for (ObjectData object : relationships.getObjects()) {
+				if (object == null) {
+					continue;
+				}
+				writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, false);
+			}
+		}
+
+		// we are done
+		feed.endFeed();
+		feed.endDocument();
+	}
 }

Modified: incubator/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/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java?rev=934896&r1=934895&r2=934896&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java Fri Apr 16 14:14:00 2010
@@ -69,370 +69,357 @@ import org.apache.chemistry.opencmis.ser
  */
 public final class RepositoryService {
 
-  /**
-   * Private constructor.
-   */
-  private RepositoryService() {
-  }
-
-  /**
-   * Renders the service document.
-   */
-  public static void getRepositories(CallContext context, AbstractServicesFactory factory,
-      HttpServletRequest request, HttpServletResponse response) throws Exception {
-    CmisRepositoryService service = factory.getRepositoryService();
-
-    // get parameters
-    String repositoryId = getStringParameter(request, Constants.PARAM_REPOSITORY_ID);
-
-    // execute
-    List<RepositoryInfo> infoDataList = null;
-
-    if (repositoryId == null) {
-      infoDataList = service.getRepositoryInfos(context, null);
-    }
-    else {
-      infoDataList = Collections.singletonList(service.getRepositoryInfo(context, repositoryId,
-          null));
-    }
-
-    // set headers
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_SERVICE);
-
-    // write XML
-    ServiceDocument serviceDoc = new ServiceDocument();
-
-    serviceDoc.startDocument(response.getOutputStream());
-    serviceDoc.startServiceDocument();
-
-    if (infoDataList != null) {
-      for (RepositoryInfo infoData : infoDataList) {
-        if (infoData == null) {
-          continue;
-        }
-
-        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;
-
-        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);
-          }
-        }
-
-        serviceDoc.startWorkspace(infoData.getId());
-
-        // add collections
-
-        // - 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);
-        }
-
-        // - 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);
-
-        }
-
-        // add repository info
-        serviceDoc.writeRepositoryInfo(infoData);
-
-        // 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());
-        }
-
-        // - changes
-        if (supportsChanges) {
-          serviceDoc.writeLink(Constants.REP_REL_CHANGES, compileUrl(baseUrl, RESOURCE_CHANGES,
-              null), Constants.MEDIATYPE_FEED, null);
-        }
-
-        // add URI templates
-
-        // - object by id
-        String url = compileUrl(baseUrl, RESOURCE_OBJECTBYID, null)
-            + "?id={id}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}";
-        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}";
-        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.endServiceDocument();
-    serviceDoc.endDocument();
-  }
-
-  /**
-   * Renders a type children collection.
-   */
-  public static void getTypeChildren(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisRepositoryService service = factory.getRepositoryService();
-
-    // 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(context, 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(context, repositoryId, typeId, null);
-
-      parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
-      typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
-    }
-
-    // write XML
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_FEED);
-
-    AtomFeed feed = new AtomFeed();
-    feed.startDocument(response.getOutputStream());
-    feed.startFeed(true);
-
-    // write basic Atom feed elements
-    feed.writeFeedElements(typeId, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, numItems);
-
-    // write links
-    UrlBuilder baseUrl = compileBaseUrl(request, 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);
-    feed.writeSelfLink(selfLink.toString(), 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);
-
-    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);
-      }
-    }
-
-    // we are done
-    feed.endFeed();
-    feed.endDocument();
-  }
-
-  /**
-   * Renders a type descendants feed.
-   */
-  public static void getTypeDescendants(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisRepositoryService service = factory.getRepositoryService();
-
-    // 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(context, 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(context, repositoryId, typeId, null);
-
-      parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
-      typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
-    }
-
-    // write XML
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_FEED);
-
-    AtomFeed feed = new AtomFeed();
-    feed.startDocument(response.getOutputStream());
-    feed.startFeed(true);
-
-    // write basic Atom feed elements
-    feed.writeFeedElements(typeId, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, null);
-
-    // write links
-    UrlBuilder baseUrl = compileBaseUrl(request, 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);
-
-    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);
-
-    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);
-        }
-      }
-    }
-
-    // we are done
-    feed.endFeed();
-    feed.endDocument();
-  }
-
-  /**
-   * Renders a type definition.
-   */
-  public static void getTypeDefinition(CallContext context, AbstractServicesFactory factory,
-      String repositoryId, HttpServletRequest request, HttpServletResponse response)
-      throws Exception {
-    CmisRepositoryService service = factory.getRepositoryService();
-
-    // get parameters
-    String typeId = getStringParameter(request, Constants.PARAM_ID);
-
-    // execute
-    TypeDefinition type = service.getTypeDefinition(context, repositoryId, typeId, null);
-
-    // write XML
-    response.setStatus(HttpServletResponse.SC_OK);
-    response.setContentType(Constants.MEDIATYPE_ENTRY);
-
-    AtomEntry entry = new AtomEntry();
-    entry.startDocument(response.getOutputStream());
-    writeTypeEntry(entry, type, null, repositoryId, compileBaseUrl(request, repositoryId), true);
-    entry.endDocument();
-  }
+	/**
+	 * Private constructor.
+	 */
+	private RepositoryService() {
+	}
+
+	/**
+	 * Renders the service document.
+	 */
+	public static void getRepositories(CallContext context, AbstractServicesFactory factory,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisRepositoryService service = factory.getRepositoryService();
+
+		// get parameters
+		String repositoryId = getStringParameter(request, Constants.PARAM_REPOSITORY_ID);
+
+		// execute
+		List<RepositoryInfo> infoDataList = null;
+
+		if (repositoryId == null) {
+			infoDataList = service.getRepositoryInfos(context, null);
+		} else {
+			infoDataList = Collections.singletonList(service.getRepositoryInfo(context, repositoryId, null));
+		}
+
+		// set headers
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_SERVICE);
+
+		// write XML
+		ServiceDocument serviceDoc = new ServiceDocument();
+
+		serviceDoc.startDocument(response.getOutputStream());
+		serviceDoc.startServiceDocument();
+
+		if (infoDataList != null) {
+			for (RepositoryInfo infoData : infoDataList) {
+				if (infoData == null) {
+					continue;
+				}
+
+				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;
+
+				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);
+					}
+				}
+
+				serviceDoc.startWorkspace(infoData.getId());
+
+				// add collections
+
+				// - 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);
+				}
+
+				// - 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);
+
+				}
+
+				// add repository info
+				serviceDoc.writeRepositoryInfo(infoData);
+
+				// 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());
+				}
+
+				// - changes
+				if (supportsChanges) {
+					serviceDoc.writeLink(Constants.REP_REL_CHANGES, compileUrl(baseUrl, RESOURCE_CHANGES, null),
+							Constants.MEDIATYPE_FEED, null);
+				}
+
+				// add URI templates
+
+				// - object by id
+				String url = compileUrl(baseUrl, RESOURCE_OBJECTBYID, null)
+						+ "?id={id}&filter={filter}&includeAllowableActions={includeAllowableActions}&includeACL={includeACL}";
+				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}";
+				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.endServiceDocument();
+		serviceDoc.endDocument();
+	}
+
+	/**
+	 * Renders a type children collection.
+	 */
+	public static void getTypeChildren(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisRepositoryService service = factory.getRepositoryService();
+
+		// 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(context, 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(context, repositoryId, typeId, null);
+
+			parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
+			typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
+		}
+
+		// write XML
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_FEED);
+
+		AtomFeed feed = new AtomFeed();
+		feed.startDocument(response.getOutputStream());
+		feed.startFeed(true);
+
+		// write basic Atom feed elements
+		feed.writeFeedElements(typeId, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, numItems);
+
+		// write links
+		UrlBuilder baseUrl = compileBaseUrl(request, 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);
+		feed.writeSelfLink(selfLink.toString(), 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);
+
+		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);
+			}
+		}
+
+		// we are done
+		feed.endFeed();
+		feed.endDocument();
+	}
+
+	/**
+	 * Renders a type descendants feed.
+	 */
+	public static void getTypeDescendants(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisRepositoryService service = factory.getRepositoryService();
+
+		// 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(context, 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(context, repositoryId, typeId, null);
+
+			parentTypeId = (typeDefinition == null ? null : typeDefinition.getParentTypeId());
+			typeName = (typeDefinition == null ? typeId : typeDefinition.getDisplayName());
+		}
+
+		// write XML
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_FEED);
+
+		AtomFeed feed = new AtomFeed();
+		feed.startDocument(response.getOutputStream());
+		feed.startFeed(true);
+
+		// write basic Atom feed elements
+		feed.writeFeedElements(typeId, TYPE_AUTHOR, typeName, new GregorianCalendar(), null, null);
+
+		// write links
+		UrlBuilder baseUrl = compileBaseUrl(request, 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);
+
+		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);
+
+		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);
+				}
+			}
+		}
+
+		// we are done
+		feed.endFeed();
+		feed.endDocument();
+	}
+
+	/**
+	 * Renders a type definition.
+	 */
+	public static void getTypeDefinition(CallContext context, AbstractServicesFactory factory, String repositoryId,
+			HttpServletRequest request, HttpServletResponse response) throws Exception {
+		CmisRepositoryService service = factory.getRepositoryService();
+
+		// get parameters
+		String typeId = getStringParameter(request, Constants.PARAM_ID);
+
+		// execute
+		TypeDefinition type = service.getTypeDefinition(context, repositoryId, typeId, null);
+
+		// write XML
+		response.setStatus(HttpServletResponse.SC_OK);
+		response.setContentType(Constants.MEDIATYPE_ENTRY);
+
+		AtomEntry entry = new AtomEntry();
+		entry.startDocument(response.getOutputStream());
+		writeTypeEntry(entry, type, null, repositoryId, compileBaseUrl(request, repositoryId), true);
+		entry.endDocument();
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ServiceDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ServiceDocument.java?rev=934896&r1=934895&r2=934896&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ServiceDocument.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ServiceDocument.java Fri Apr 16 14:14:00 2010
@@ -37,50 +37,47 @@ import org.apache.chemistry.opencmis.com
  */
 public class ServiceDocument extends AtomDocumentBase {
 
-  public ServiceDocument() {
-  }
+	public ServiceDocument() {
+	}
 
-  public void startServiceDocument() throws XMLStreamException {
-    XMLStreamWriter xsw = getWriter();
-    xsw.writeStartElement(Constants.NAMESPACE_APP, "service");
-    writeNamespace(Constants.NAMESPACE_APP);
-    writeNamespace(Constants.NAMESPACE_ATOM);
-    writeNamespace(Constants.NAMESPACE_CMIS);
-    writeNamespace(Constants.NAMESPACE_RESTATOM);
-  }
-
-  public void endServiceDocument() throws XMLStreamException {
-    getWriter().writeEndElement();
-  }
-
-  public void startWorkspace(String title) throws XMLStreamException {
-    getWriter().writeStartElement(Constants.NAMESPACE_APP, "workspace");
-    writeSimpleTag(Constants.NAMESPACE_ATOM, "title", title);
-  }
-
-  public void endWorkspace() throws XMLStreamException {
-    getWriter().writeEndElement();
-  }
-
-  public void writeRepositoryInfo(RepositoryInfo repInfo) throws XMLStreamException,
-      JAXBException {
-    CmisRepositoryInfoType repInfoJaxb = convert(repInfo);
-    if (repInfoJaxb == null) {
-      return;
-    }
-
-    JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createRepositoryInfo(repInfoJaxb),
-        getWriter(), true);
-  }
-
-  public void writeUriTemplate(String template, String type, String mediatype)
-      throws XMLStreamException {
-    XMLStreamWriter xsw = getWriter();
-
-    xsw.writeStartElement(Constants.NAMESPACE_RESTATOM, "uritemplate");
-    writeSimpleTag(Constants.NAMESPACE_RESTATOM, "template", template);
-    writeSimpleTag(Constants.NAMESPACE_RESTATOM, "type", type);
-    writeSimpleTag(Constants.NAMESPACE_RESTATOM, "mediatype", mediatype);
-    xsw.writeEndElement();
-  }
+	public void startServiceDocument() throws XMLStreamException {
+		XMLStreamWriter xsw = getWriter();
+		xsw.writeStartElement(Constants.NAMESPACE_APP, "service");
+		writeNamespace(Constants.NAMESPACE_APP);
+		writeNamespace(Constants.NAMESPACE_ATOM);
+		writeNamespace(Constants.NAMESPACE_CMIS);
+		writeNamespace(Constants.NAMESPACE_RESTATOM);
+	}
+
+	public void endServiceDocument() throws XMLStreamException {
+		getWriter().writeEndElement();
+	}
+
+	public void startWorkspace(String title) throws XMLStreamException {
+		getWriter().writeStartElement(Constants.NAMESPACE_APP, "workspace");
+		writeSimpleTag(Constants.NAMESPACE_ATOM, "title", title);
+	}
+
+	public void endWorkspace() throws XMLStreamException {
+		getWriter().writeEndElement();
+	}
+
+	public void writeRepositoryInfo(RepositoryInfo repInfo) throws XMLStreamException, JAXBException {
+		CmisRepositoryInfoType repInfoJaxb = convert(repInfo);
+		if (repInfoJaxb == null) {
+			return;
+		}
+
+		JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createRepositoryInfo(repInfoJaxb), getWriter(), true);
+	}
+
+	public void writeUriTemplate(String template, String type, String mediatype) throws XMLStreamException {
+		XMLStreamWriter xsw = getWriter();
+
+		xsw.writeStartElement(Constants.NAMESPACE_RESTATOM, "uritemplate");
+		writeSimpleTag(Constants.NAMESPACE_RESTATOM, "template", template);
+		writeSimpleTag(Constants.NAMESPACE_RESTATOM, "type", type);
+		writeSimpleTag(Constants.NAMESPACE_RESTATOM, "mediatype", mediatype);
+		xsw.writeEndElement();
+	}
 }



Mime
View raw message