View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.bindings.spi.browser;
20  
21  import java.io.IOException;
22  import java.io.OutputStream;
23  
24  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
25  import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
26  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
27  import org.apache.chemistry.opencmis.commons.impl.Constants;
28  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
29  import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
30  
31  /**
32   * MultiFiling Service Browser Binding client.
33   */
34  public class MultiFilingServiceImpl extends AbstractBrowserBindingService implements MultiFilingService {
35  
36      /**
37       * Constructor.
38       */
39      public MultiFilingServiceImpl(BindingSession session) {
40          setSession(session);
41      }
42  
43      @Override
44      public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions,
45              ExtensionsData extension) {
46          // build URL
47          UrlBuilder url = getObjectUrl(repositoryId, objectId);
48  
49          // prepare form data
50          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_ADD_OBJECT_TO_FOLDER);
51          formData.addParameter(Constants.PARAM_FOLDER_ID, folderId);
52          formData.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
53  
54          // send and parse
55          postAndConsume(url, formData.getContentType(), new Output() {
56              @Override
57              public void write(OutputStream out) throws IOException {
58                  formData.write(out);
59              }
60          });
61      }
62  
63      @Override
64      public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension) {
65          // build URL
66          UrlBuilder url = getObjectUrl(repositoryId, objectId);
67  
68          // prepare form data
69          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_REMOVE_OBJECT_FROM_FOLDER);
70          formData.addParameter(Constants.PARAM_FOLDER_ID, folderId);
71  
72          // send and parse
73          postAndConsume(url, formData.getContentType(), new Output() {
74              @Override
75              public void write(OutputStream out) throws IOException {
76                  formData.write(out);
77              }
78          });
79      }
80  }