You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/11/11 17:45:17 UTC
marmotta git commit: cleanups, move some constants to CoreOptions
Repository: marmotta
Updated Branches:
refs/heads/develop 0556482ff -> 0b1db3700
cleanups, move some constants to CoreOptions
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/0b1db370
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/0b1db370
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/0b1db370
Branch: refs/heads/develop
Commit: 0b1db370055322b914e4e7475f0ac51d608b6f8a
Parents: 0556482
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Nov 11 17:45:56 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Nov 11 17:45:56 2014 +0100
----------------------------------------------------------------------
.../platform/core/model/config/CoreOptions.java | 6 ++
.../webservices/resource/ContentWebService.java | 21 ++---
.../webservices/resource/MetaWebService.java | 37 ++++-----
.../resource/ResourceWebService.java | 85 ++++++++------------
.../resource/ResourceWebServiceHelper.java | 47 +++--------
5 files changed, 74 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0b1db370/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
index 38c7a2b..44725d2 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
@@ -33,4 +33,10 @@ public class CoreOptions {
public static final String HTTP_MAX_CONNECTIONS = "core.http.max_connections";
public static final String HTTP_MAX_CONNECTIONS_PER_ROUTE = "core.http.max_connections_per_route";
public static final String HTTP_CLIENT_CACHE_ENABLE = "core.http.client_cache_enable";
+
+ // webservices
+ public static final String HTTP_ALLOW_ORIGIN = "kiwi.allow_origin";
+ public static final String LINKEDDATA_REDIRECT_PUT = "linkeddata.redirect.put";
+ public static final String LINKEDDATA_REDIRECT_STATUS = "linkeddata.redirect.status";
+ public static final String LINKEDDATA_MIME_REL_DEFAULT = "linkeddata.mime.rel.default";
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0b1db370/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
index 9c55439..9ce164a 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
@@ -27,6 +27,7 @@ import org.apache.marmotta.platform.core.events.ContentCreatedEvent;
import org.apache.marmotta.platform.core.exception.HttpErrorException;
import org.apache.marmotta.platform.core.exception.MarmottaException;
import org.apache.marmotta.platform.core.exception.WritingNotSupportedException;
+import org.apache.marmotta.platform.core.model.config.CoreOptions;
import org.apache.marmotta.platform.core.qualifiers.event.ContentCreated;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
@@ -63,8 +64,6 @@ import static org.apache.marmotta.platform.core.webservices.resource.ResourceWeb
@Path("/" + ConfigurationService.CONTENT_PATH)
public class ContentWebService {
- private static final String ENHANCER_STANBOL_ENHANCER_ENABLED = "enhancer.stanbol.enhancer.enabled";
-
@Inject
private ConfigurationService configurationService;
@@ -154,8 +153,7 @@ public class ContentWebService {
final String mimeType = contentService.getContentType(resource);
if (mimeType != null) {
return Response
- .status(configurationService.getIntConfiguration(
- "linkeddata.redirect.status", 303))
+ .status(configurationService.getIntConfiguration(CoreOptions.LINKEDDATA_REDIRECT_STATUS, 303))
.header(VARY, ACCEPT)
.header(CONTENT_TYPE, mimeType + "; rel=content")
.location(
@@ -171,9 +169,7 @@ public class ContentWebService {
} finally {
conn.close();
}
- } catch (RepositoryException ex) {
- return Response.serverError().entity(ex.getMessage()).build();
- } catch (URISyntaxException ex) {
+ } catch (RepositoryException | URISyntaxException ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
@@ -271,9 +267,7 @@ public class ContentWebService {
conn.commit();
conn.close();
}
- } catch (MarmottaException ex) {
- return Response.serverError().entity(ex.getMessage()).build();
- } catch (RepositoryException ex) {
+ } catch (MarmottaException | RepositoryException ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
@@ -362,9 +356,7 @@ public class ContentWebService {
} finally {
conn.close();
}
- } catch (IOException e) {
- return Response.serverError().entity(e.getMessage()).build();
- } catch (RepositoryException e) {
+ } catch (IOException | RepositoryException e) {
return Response.serverError().entity(e.getMessage()).build();
}
}
@@ -391,9 +383,6 @@ public class ContentWebService {
throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "content may not be empty for writing");
}
contentService.setContentStream(resource, request.getInputStream(), mimetype); // store content
- if(configurationService.getBooleanConfiguration(ENHANCER_STANBOL_ENHANCER_ENABLED, false)) {
- afterContentCreated.fire(new ContentCreatedEvent(resource)); //enhancer
- }
return Response.ok().build();
} catch (IOException e) {
throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "could not read request body");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0b1db370/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
index 6e7b8d9..a74cc28 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
@@ -19,7 +19,6 @@ package org.apache.marmotta.platform.core.webservices.resource;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
-import com.google.common.net.HttpHeaders;
import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.commons.http.ETagGenerator;
import org.apache.marmotta.commons.http.UriUtil;
@@ -45,7 +44,7 @@ import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.Response.*;
import javax.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.OutputStream;
@@ -55,8 +54,8 @@ import java.net.URLDecoder;
import java.util.LinkedList;
import java.util.List;
-import static com.google.common.net.HttpHeaders.ACCEPT;
-import static com.google.common.net.HttpHeaders.LINK;
+import static com.google.common.net.HttpHeaders.*;
+import static javax.ws.rs.core.Response.*;
import static org.apache.marmotta.platform.core.webservices.resource.ResourceWebService.CHARSET;
import static org.apache.marmotta.platform.core.webservices.resource.ResourceWebServiceHelper.appendMetaTypes;
@@ -204,7 +203,7 @@ public class MetaWebService {
// delete all triples for given subject
connection.remove(subject, null, null);
- return Response.ok().build();
+ return ok().build();
} finally {
connection.commit();
connection.close();
@@ -246,13 +245,13 @@ public class MetaWebService {
}
if (r == null || !ResourceUtils.isUsed(conn, r)) {
- throw new HttpErrorException(Response.Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future", ImmutableMap.of(ACCEPT, mimetype));
+ throw new HttpErrorException(Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future", ImmutableMap.of(ACCEPT, mimetype));
}
// create parser
final RDFFormat serializer = kiWiIOService.getSerializer(mimetype);
if (serializer == null) {
- ImmutableMap<String, String> headers = ImmutableMap.of(HttpHeaders.CONTENT_TYPE, appendMetaTypes(kiWiIOService.getProducedTypes()));
+ ImmutableMap<String, String> headers = ImmutableMap.of(CONTENT_TYPE, appendMetaTypes(kiWiIOService.getProducedTypes()));
throw new HttpErrorException(Status.NOT_ACCEPTABLE, resource, "mimetype can not be processed", headers);
}
@@ -282,8 +281,10 @@ public class MetaWebService {
};
// build response
- Response response = Response.ok(entity).lastModified(ResourceUtils.getLastModified(conn, r)).build();
- response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
+ ResponseBuilder response =
+ ok(entity)
+ .lastModified(ResourceUtils.getLastModified(conn, r));
+ response.header(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
if (!mimetype.contains("html")) { // then create a proper filename
String[] components;
@@ -293,14 +294,14 @@ public class MetaWebService {
components = resource.split("/");
}
final String fileName = components[components.length - 1] + "." + serializer.getDefaultFileExtension();
- response.getMetadata().add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"");
+ response.header(CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"");
}
// create the Content-Type header for the response
if (mimetype.startsWith("text/") || mimetype.startsWith("application/")) {
- response.getMetadata().add(HttpHeaders.CONTENT_TYPE, mimetype + "; charset=" + CHARSET);
+ response.header(CONTENT_TYPE, mimetype + "; charset=" + CHARSET);
} else {
- response.getMetadata().add(HttpHeaders.CONTENT_TYPE, mimetype);
+ response.header(CONTENT_TYPE, mimetype);
}
// create the Link headers for the response
@@ -313,9 +314,9 @@ public class MetaWebService {
}
if (links.size() > 0) {
- response.getMetadata().add(LINK, Joiner.on(", ").join(links));
+ response.header(LINK, Joiner.on(", ").join(links));
}
- return response;
+ return response.build();
} finally {
if (conn.isOpen()) {
conn.commit();
@@ -332,9 +333,9 @@ public class MetaWebService {
// create parser
RDFFormat parser = kiWiIOService.getParser(mimetype);
if (parser == null) {
- Response response = Response.status(Status.UNSUPPORTED_MEDIA_TYPE).entity("media type " + mimetype + " not supported").build();
- ResourceWebServiceHelper.addHeader(response, HttpHeaders.CONTENT_TYPE, appendMetaTypes(kiWiIOService.getProducedTypes()));
- return response;
+ return status(Status.UNSUPPORTED_MEDIA_TYPE)
+ .header(CONTENT_TYPE, appendMetaTypes(kiWiIOService.getProducedTypes()))
+ .entity("media type " + mimetype + " not supported").build();
}
if (request.getContentLength() == 0) {
throw new HttpErrorException(Status.BAD_REQUEST, uri, "content may not be empty in resource update", ImmutableMap.of(ACCEPT, mimetype));
@@ -359,7 +360,7 @@ public class MetaWebService {
connection.commit();
connection.close();
}
- return Response.ok().build();
+ return ok().build();
} catch (URISyntaxException e) {
throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, "invalid target context", ImmutableMap.of(ACCEPT, mimetype));
} catch (IOException | RDFParseException e) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0b1db370/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
index d2e4a7f..7758987 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
@@ -53,6 +53,7 @@ import java.util.UUID;
import static com.google.common.net.HttpHeaders.*;
import static javax.ws.rs.core.Response.status;
+import static org.apache.marmotta.platform.core.model.config.CoreOptions.*;
import static org.apache.marmotta.platform.core.webservices.resource.ResourceWebServiceHelper.appendMetaTypes;
/**
@@ -110,14 +111,10 @@ public class ResourceWebService {
reqHeaders = "Accept, Content-Type";
}
- if (uri == null)
- return Response.ok()
- .header(ALLOW, "POST")
- .header(ACCESS_CONTROL_ALLOW_METHODS, "POST")
- .header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
- .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
- .build();
- else {
+ String methods;
+ if (uri == null) {
+ methods = "POST";
+ } else {
try {
uri = URLDecoder.decode(uri, "utf-8");
@@ -127,30 +124,22 @@ public class ResourceWebService {
URI resource = ResourceUtils.getUriResource(conn, uri);
conn.commit();
- if (resource != null) return Response.ok()
- .header(ALLOW, "PUT, GET, DELETE")
- .header(ACCESS_CONTROL_ALLOW_METHODS, "PUT, GET, DELETE")
- .header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
- .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
- .build();
- else
- return Response.ok()
- .header(ALLOW, "POST")
- .header(ACCESS_CONTROL_ALLOW_METHODS, "POST")
- .header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
- .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
- .build();
+ methods = resource != null ? "PUT, GET, DELETE" : "POST";
} finally {
conn.close();
}
-
- } catch (UnsupportedEncodingException ex) {
- return Response.serverError().entity(ex.getMessage()).build();
- } catch (RepositoryException ex) {
+ } catch (UnsupportedEncodingException | RepositoryException ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
+ return Response.ok()
+ .header(ALLOW, methods)
+ .header(ACCESS_CONTROL_ALLOW_METHODS, methods)
+ .header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
+ .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration(HTTP_ALLOW_ORIGIN, "*"))
+ .build();
+
}
/**
@@ -182,27 +171,20 @@ public class ResourceWebService {
URI resource = ResourceUtils.getUriResource(conn, uri);
conn.commit();
+ String methods = resource != null ? "PUT, GET, DELETE" : "POST";
+
- if (resource != null) return Response.ok()
- .header(ALLOW, "PUT, GET, DELETE")
- .header(ACCESS_CONTROL_ALLOW_METHODS, "PUT, GET, DELETE")
+ return Response.ok()
+ .header(ALLOW, methods)
+ .header(ACCESS_CONTROL_ALLOW_METHODS, methods)
.header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
- .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
+ .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration(HTTP_ALLOW_ORIGIN, "*"))
.build();
- else
- return Response.ok()
- .header(ALLOW, "POST")
- .header(ACCESS_CONTROL_ALLOW_METHODS, "POST")
- .header(ACCESS_CONTROL_ALLOW_HEADERS, reqHeaders)
- .header(ACCESS_CONTROL_ALLOW_ORIGIN, configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
- .build();
} finally {
conn.close();
}
- } catch (UnsupportedEncodingException ex) {
- return Response.serverError().entity(ex.getMessage()).build();
- } catch (RepositoryException ex) {
+ } catch (UnsupportedEncodingException | RepositoryException ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
@@ -265,10 +247,11 @@ public class ResourceWebService {
conn.getValueFactory().createURI(uri);
status = Status.CREATED;
}
- Response response = status(status).entity(uri).build();
- response.getMetadata().add(LOCATION, location);
- response.getMetadata().add(VARY, CONTENT_TYPE);
- return response;
+ return status(status)
+ .header(LOCATION, location)
+ .header(VARY, CONTENT_TYPE)
+ .entity(uri)
+ .build();
} finally {
conn.commit();
conn.close();
@@ -403,8 +386,8 @@ public class ResourceWebService {
if (bestType != null) {
Response response = buildGetResponse(r, bestType);
- response.getMetadata().add("Last-Modified", ResourceUtils.getLastModified(conn, r));
- response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
+ response.getMetadata().add(LAST_MODIFIED, ResourceUtils.getLastModified(conn, r));
+ response.getMetadata().add(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
return response;
} else {
return build406(acceptedTypes, offeredTypes);
@@ -457,7 +440,7 @@ public class ResourceWebService {
*/
@PUT
@Path(UUID_PATTERN)
- public Response putLocal(@PathParam("uuid") String uuid, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
+ public Response putLocal(@PathParam("uuid") String uuid, @HeaderParam(CONTENT_TYPE) String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
try {
return put(uri, type, uuid, request);
@@ -485,7 +468,7 @@ public class ResourceWebService {
* @ResponseHeader Location (for HTTP 303) the url where data can be put
*/
@PUT
- public Response putRemote(@QueryParam("uri") String uri, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
+ public Response putRemote(@QueryParam("uri") String uri, @HeaderParam(CONTENT_TYPE) String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
try {
if (uri != null) return put(URLDecoder.decode(uri, "utf-8"), type, null, request);
else
@@ -507,7 +490,7 @@ public class ResourceWebService {
List<ContentType> types = MarmottaHttpUtils.parseAcceptHeader(mimetype);
for (ContentType type : types) {
if (type.getParameter("rel") == null) {
- type.setParameter("rel", configurationService.getStringConfiguration("linkeddata.mime.rel.default", "meta"));
+ type.setParameter("rel", configurationService.getStringConfiguration(LINKEDDATA_MIME_REL_DEFAULT, "meta"));
}
}
@@ -525,14 +508,14 @@ public class ResourceWebService {
ContentType bestType = MarmottaHttpUtils.bestContentType(types, acceptable);
if (bestType != null) {
- if (configurationService.getBooleanConfiguration("linkeddata.redirect.put", true)) {
+ if (configurationService.getBooleanConfiguration(LINKEDDATA_REDIRECT_PUT, true)) {
final RepositoryConnection con = sesameService.getConnection();
try {
con.begin();
URI resource = ResourceUtils.getUriResource(con, uri);
con.commit();
return Response
- .status(configurationService.getIntConfiguration("linkeddata.redirect.status", 303))
+ .status(configurationService.getIntConfiguration(LINKEDDATA_REDIRECT_STATUS, 303))
// .location(new URI(configurationService.getBaseUri() +
// bestType.getParameter("rel") + "/" + bestType.getMime() + appendix))
.location(new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource, bestType, configurationService)))
@@ -618,7 +601,7 @@ public class ResourceWebService {
return Response
.status(configurationService.getIntConfiguration(
- "linkeddata.redirect.status", 303))
+ LINKEDDATA_REDIRECT_STATUS, 303))
.header("Vary", ACCEPT)
.header(CONTENT_TYPE, type.toString())
// .location(new URI(configurationService.getBaseUri() +
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0b1db370/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
index 5c57c59..99d0fe5 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
@@ -17,20 +17,18 @@
*/
package org.apache.marmotta.platform.core.webservices.resource;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.api.templating.TemplatingService;
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* Helper methods shared accross the difference resource web services
@@ -43,23 +41,13 @@ public class ResourceWebServiceHelper {
response.getMetadata().add(name, value);
}
- public static String appendTypes(List<String> datamimes, String mime) {
- StringBuilder sb = new StringBuilder();
- sb.append(appendContentTypes(mime));
- sb.append(appendMetaTypes(datamimes));
- return sb.toString();
- }
-
public static String appendMetaTypes(List<String> datamimes) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < datamimes.size(); i++) {
- sb.append(datamimes.get(i));
- sb.append(";rel=meta");
- if (i < datamimes.size() - 1) {
- sb.append(",");
+ return Joiner.on(',').join(Iterables.transform(datamimes, new Function<String, String>() {
+ @Override
+ public String apply(String input) {
+ return input + ";rel=meta";
}
- }
- return sb.toString();
+ }));
}
public static String appendContentTypes(String mime) {
@@ -70,13 +58,6 @@ public class ResourceWebServiceHelper {
}
}
- /**
- * @deprecated Use {@link #buildContentLink(URI, String, ConfigurationService)} instead
- */
- public static String buildContentLink(URI resource, String uuid, String mime, ConfigurationService configurationService) {
- return buildContentLink(resource, mime, configurationService);
- }
-
public static String buildContentLink(Resource resource, String mime, ConfigurationService configurationService) {
//TODO: test if there is content
StringBuffer b = new StringBuffer();
@@ -93,13 +74,6 @@ public class ResourceWebServiceHelper {
return b.toString();
}
- /**
- * @deprecated Use {@link #buildMetaLinks(URI, List<String>,ConfigurationService)} instead
- */
- public static String buildMetaLinks(URI resource, String uuid, List<String> datamimes, ConfigurationService configurationService) {
- return buildMetaLinks(resource, datamimes, configurationService);
- }
-
public static String buildMetaLinks(URI resource, List<String> datamimes, ConfigurationService configurationService) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < datamimes.size(); i++) {
@@ -119,8 +93,7 @@ public class ResourceWebServiceHelper {
}
public static String buildResourceLink(URI resource, ContentType cType, ConfigurationService configurationService) {
- return buildResourceLink(resource, cType.getParameter("rel"),
- cType.getMime(), configurationService);
+ return buildResourceLink(resource, cType.getParameter("rel"), cType.getMime(), configurationService);
}
public static String buildResourceLink(Resource resource, String rel, String mime, ConfigurationService configurationService) {