-
Notifications
You must be signed in to change notification settings - Fork 19
/
PostBuilder.java
144 lines (122 loc) · 4.35 KB
/
PostBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree.
*/
package org.fcrepo.client;
import static org.fcrepo.client.FedoraHeaderConstants.ATOMIC_ID;
import static org.fcrepo.client.FedoraHeaderConstants.CONTENT_DISPOSITION;
import static org.fcrepo.client.FedoraHeaderConstants.SLUG;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.http.client.methods.HttpRequestBase;
import org.fcrepo.client.FcrepoResponse.TransactionURI;
import org.springframework.http.ContentDisposition;
import org.springframework.http.ContentDisposition.Builder;
/**
* Builds a post request for interacting with the Fedora HTTP API in order to create a new resource within an LDP
* container.
*
* @author bbpennel
*/
public class PostBuilder extends BodyRequestBuilder {
/**
* Instantiate builder
*
* @param uri uri of the resource this request is being made to
* @param client the client
*/
public PostBuilder(final URI uri, final FcrepoClient client) {
super(uri, client);
}
@Override
protected HttpRequestBase createRequest() {
return HttpMethods.POST.createRequest(targetUri);
}
@Override
public PostBuilder body(final InputStream stream, final String contentType) {
return (PostBuilder) super.body(stream, contentType);
}
@Override
public PostBuilder body(final File file, final String contentType) throws IOException {
return (PostBuilder) super.body(file, contentType);
}
@Override
public PostBuilder body(final InputStream stream) {
return (PostBuilder) super.body(stream);
}
@Override
public PostBuilder externalContent(final URI contentURI, final String contentType, final String handling) {
return (PostBuilder) super.externalContent(contentURI, contentType, handling);
}
@Deprecated
@Override
public PostBuilder digest(final String digest) {
return (PostBuilder) super.digest(digest);
}
@Override
public PostBuilder digest(final String digest, final String alg) {
return (PostBuilder) super.digest(digest, alg);
}
@Override
public PostBuilder digestMd5(final String digest) {
return (PostBuilder) super.digestMd5(digest);
}
@Override
public PostBuilder digestSha1(final String digest) {
return (PostBuilder) super.digestSha1(digest);
}
@Override
public PostBuilder digestSha256(final String digest) {
return (PostBuilder) super.digestSha256(digest);
}
@Override
public PostBuilder addInteractionModel(final String interactionModelUri) {
return (PostBuilder) super.addInteractionModel(interactionModelUri);
}
@Override
public PostBuilder linkAcl(final String aclUri) {
return (PostBuilder) super.linkAcl(aclUri);
}
@Override
public PostBuilder addHeader(final String name, final String value) {
return (PostBuilder) super.addHeader(name, value);
}
public PostBuilder addTransaction(final TransactionURI transaction) {
request.addHeader(ATOMIC_ID, transaction.asString());
return this;
}
@Override
public PostBuilder addLinkHeader(final FcrepoLink linkHeader) {
return (PostBuilder) super.addLinkHeader(linkHeader);
}
/**
* Provide a content disposition header which will be used as the filename
*
* @param filename the name of the file being provided in the body of the request
* @return this builder
* @throws FcrepoOperationFailedException if unable to encode filename
*/
public PostBuilder filename(final String filename) throws FcrepoOperationFailedException {
final Builder builder = ContentDisposition.builder("attachment");
if (filename != null) {
builder.filename(filename);
}
request.addHeader(CONTENT_DISPOSITION, builder.build().toString());
return this;
}
/**
* Provide a suggested name for the new child resource, which the repository may ignore.
*
* @param slug value to supply as the slug header
* @return this builder
*/
public PostBuilder slug(final String slug) {
if (slug != null) {
request.addHeader(SLUG, slug);
}
return this;
}
}