content: /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  package org.apache.chemistry.opencmis.client.bindings.spi.browser;
  
  import java.io.IOException;
  import java.io.OutputStream;
  
  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
  import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
  import org.apache.chemistry.opencmis.commons.impl.Constants;
  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
  import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
  
  /**
   * MultiFiling Service Browser Binding client.
   */
  public class MultiFilingServiceImpl extends AbstractBrowserBindingService implements MultiFilingService {
  
      /**
       * Constructor.
       */
      public MultiFilingServiceImpl(BindingSession session) {
          setSession(session);
      }
  
      @Override
      public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions,
              ExtensionsData extension) {
          // build URL
          UrlBuilder url = getObjectUrl(repositoryId, objectId);
  
          // prepare form data
          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_ADD_OBJECT_TO_FOLDER);
          formData.addParameter(Constants.PARAM_FOLDER_ID, folderId);
          formData.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
  
          // send and parse
          postAndConsume(url, formData.getContentType(), new Output() {
              @Override
              public void write(OutputStream out) throws IOException {
                  formData.write(out);
              }
          });
      }
  
      @Override
      public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension) {
          // build URL
          UrlBuilder url = getObjectUrl(repositoryId, objectId);
  
          // prepare form data
          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_REMOVE_OBJECT_FROM_FOLDER);
          formData.addParameter(Constants.PARAM_FOLDER_ID, folderId);
  
          // send and parse
          postAndConsume(url, formData.getContentType(), new Output() {
              @Override
              public void write(OutputStream out) throws IOException {
                  formData.write(out);
              }
          });
      }
  }
  