001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.fcrepo.client; 018 019import static org.fcrepo.client.FedoraHeaderConstants.PREFER; 020 021import java.io.File; 022import java.io.IOException; 023import java.io.InputStream; 024import java.net.URI; 025 026import org.apache.http.client.methods.HttpRequestBase; 027 028/** 029 * Builds a PUT request for interacting with the Fedora HTTP API in order to create a resource with a specified path, 030 * or replace the triples associated with a resource with the triples provided in the request body. 031 * 032 * @author bbpennel 033 */ 034public class PutBuilder extends BodyRequestBuilder { 035 036 /** 037 * Instantiate builder 038 * 039 * @param uri uri of the resource this request is being made to 040 * @param client the client 041 */ 042 public PutBuilder(final URI uri, final FcrepoClient client) { 043 super(uri, client); 044 } 045 046 @Override 047 protected HttpRequestBase createRequest() { 048 return HttpMethods.PUT.createRequest(targetUri); 049 } 050 051 @Override 052 public PutBuilder body(final InputStream stream, final String contentType) { 053 return (PutBuilder) super.body(stream, contentType); 054 } 055 056 @Override 057 public PutBuilder body(final File file, final String contentType) throws IOException { 058 return (PutBuilder) super.body(file, contentType); 059 } 060 061 @Override 062 public PutBuilder body(final InputStream stream) { 063 return (PutBuilder) super.body(stream); 064 } 065 066 @Override 067 public PutBuilder ifMatch(final String etag) { 068 return (PutBuilder) super.ifMatch(etag); 069 } 070 071 @Override 072 public PutBuilder ifUnmodifiedSince(final String modified) { 073 return (PutBuilder) super.ifUnmodifiedSince(modified); 074 } 075 076 @Override 077 public PutBuilder digest(final String digest) { 078 return (PutBuilder) super.digest(digest); 079 } 080 081 /** 082 * Set the prefer header for this request to lenient handling, to indicate that server-managed triples will not 083 * be included in the request body. 084 * 085 * @return this builder 086 */ 087 public BodyRequestBuilder preferLenient() { 088 request.setHeader(PREFER, "handling=lenient; received=\"minimal\""); 089 return this; 090 } 091}