checkRepositoryURL();
String uploadURL = Protocol.getStatementsLocation(getRepositoryURL());
// Select appropriate HTTP method
EntityEnclosingMethod method;
if (overwrite) {
method = new PutMethod(uploadURL);
}
else {
method = new PostMethod(uploadURL);
}
setDoAuthentication(method);
// Set relevant query parameters
List<NameValuePair> params = new ArrayList<NameValuePair>(5);
for (String encodedContext : Protocol.encodeContexts(contexts)) {
params.add(new NameValuePair(Protocol.CONTEXT_PARAM_NAME, encodedContext));
}
if (baseURI != null && baseURI.trim().length() != 0) {
String encodedBaseURI = Protocol.encodeValue(new URIImpl(baseURI));
params.add(new NameValuePair(Protocol.BASEURI_PARAM_NAME, encodedBaseURI));
}
method.setQueryString(params.toArray(new NameValuePair[params.size()]));
// Set payload
method.setRequestEntity(reqEntity);
// Send request
try {
int httpCode = httpClient.executeMethod(method);
if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new UnauthorizedException();
}
else if (httpCode == HttpURLConnection.HTTP_UNSUPPORTED_TYPE) {
throw new UnsupportedRDFormatException(method.getResponseBodyAsString());
}
else if (!HttpClientUtil.is2xx(httpCode)) {
ErrorInfo errInfo = ErrorInfo.parse(method.getResponseBodyAsString());
if (errInfo.getErrorType() == ErrorType.MALFORMED_DATA) {
throw new RDFParseException(errInfo.getErrorMessage());
}
else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_FILE_FORMAT) {