You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/06/27 08:50:03 UTC
[2/2] git commit: implemented the particular ldp content negotiation
style, where turtle has more priority than in a raw linked data scenario
implemented the particular ldp content negotiation style, where turtle has more priority than in a raw linked data scenario
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/5d7f00d7
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/5d7f00d7
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/5d7f00d7
Branch: refs/heads/ldp
Commit: 5d7f00d70a7373c7881635d80f6f4b1f5799d31a
Parents: 1c907ae
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Jun 26 16:49:42 2014 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Jun 26 16:49:42 2014 +0200
----------------------------------------------------------------------
.../commons/http/MarmottaHttpUtils.java | 12 ++++++++--
.../platform/ldp/webservices/LdpWebService.java | 23 +++++++++++++++-----
2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/5d7f00d7/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
index 5817200..568829d 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
import org.openrdf.query.resultio.QueryResultFormat;
/**
@@ -41,8 +42,6 @@ public class MarmottaHttpUtils {
* string argument.
* <p/>
* Author: Sebastian Schaffert
- *
- *
*/
public static List<ContentType> parseAcceptHeader(String header) {
String[] components = header.split(",");
@@ -171,4 +170,13 @@ public class MarmottaHttpUtils {
return null;
}
+ public static ContentType performContentNegotiation(String accept, Collection<String> producedContentTypes) {
+ return performContentNegotiation(accept, MarmottaHttpUtils.parseStringList(producedContentTypes));
+ }
+
+ public static ContentType performContentNegotiation(String accept, List<ContentType> producedContentTypes) {
+ List<ContentType> acceptedContentTypes = MarmottaHttpUtils.parseAcceptHeader(StringUtils.defaultString(accept, ""));
+ return MarmottaHttpUtils.bestContentType(producedContentTypes, acceptedContentTypes);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/5d7f00d7/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
index b996de0..9bbecdd 100644
--- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
+++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
@@ -18,8 +18,11 @@
package org.apache.marmotta.platform.ldp.webservices;
import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
import org.apache.marmotta.commons.vocabulary.LDP;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.exporter.ExportService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
import org.apache.marmotta.platform.ldp.api.LdpService;
import org.apache.marmotta.platform.ldp.exceptions.IncompatibleResourceTypeException;
@@ -75,6 +78,9 @@ public class LdpWebService {
private LdpService ldpService;
@Inject
+ private ExportService exportService;
+
+ @Inject
private SesameService sesameService;
@PostConstruct
@@ -113,14 +119,19 @@ public class LdpWebService {
}
final RDFFormat format;
- if (type.isWildcardType()) { // No explicit Accept Header
- format = ( ldpService.isRdfSourceResource(conn, resource) ? RDFFormat.TURTLE : null );
+ if (type.isWildcardSubtype()) {
+ if (type.isWildcardType() || "text".equals(type.getType())) {
+ format = RDFFormat.TURTLE;
+ } else {
+ ContentType contentType = MarmottaHttpUtils.performContentNegotiation(LdpUtils.getMimeType(type), exportService.getProducedTypes());
+ format = (contentType != null ? Rio.getWriterFormatForMIMEType(contentType.getMime(), RDFFormat.TURTLE) : null);
+ }
} else {
- format = Rio.getWriterFormatForMIMEType(LdpUtils.getMimeType(type), null);
+ format = Rio.getWriterFormatForMIMEType(LdpUtils.getMimeType(type), RDFFormat.TURTLE);
}
if (format == null) {
- log.debug("GET to <{}> with non-RDF format {}, so looking for a LDP-BR", resource, type);
+ log.debug("GET to <{}> with non-RDF format {} of a LDP-NR", resource, type);
final StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
@@ -142,12 +153,12 @@ public class LdpWebService {
}
};
final String realType = ldpService.getMimeType(conn, resource);
- final Response.ResponseBuilder resp = createResponse(conn, Response.Status.OK, resource).entity(entity).type(realType!=null?MediaType.valueOf(realType):type);
+ final Response.ResponseBuilder resp = createResponse(conn, Response.Status.OK, resource).entity(entity).type(realType != null ? MediaType.valueOf(realType) : type);
conn.commit();
return resp;
} else {
// Deliver all triples from the <subject> context.
- log.debug("GET to <{}> with RDF format {}, providing LPD-RR data", resource, format.getDefaultMIMEType());
+ log.debug("GET to <{}> with RDF format {} of a LPD-R", resource, format.getDefaultMIMEType());
final StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {