Author: ogrisel
Date: Tue Mar 27 14:25:49 2012
New Revision: 1305850
URL: http://svn.apache.org/viewvc?rev=1305850&view=rev
Log:
cosmit
Modified:
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
Modified:
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java?rev=1305850&r1=1305849&r2=1305850&view=diff
==============================================================================
---
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
(original)
+++
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
Tue Mar 27 14:25:49 2012
@@ -1,24 +1,24 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.stanbol.commons.web.base.writers;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N3;
import static
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N_TRIPLE;
import static
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_JSON;
@@ -35,7 +35,6 @@ import java.util.HashSet;
import java.util.Set;
import javax.servlet.ServletContext;
-import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@@ -45,16 +44,14 @@ import javax.ws.rs.ext.Provider;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
@Provider
-//@Produces({TEXT_PLAIN, N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON,
APPLICATION_JSON})
+// @Produces({TEXT_PLAIN, N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON,
APPLICATION_JSON})
public class GraphWriter implements MessageBodyWriter<TripleCollection> {
-
+
private final Logger log = LoggerFactory.getLogger(GraphWriter.class);
public static final Set<String> supportedMediaTypes;
static {
@@ -72,7 +69,7 @@ public class GraphWriter implements Mess
}
public static final String ENCODING = "UTF-8";
-
+
@Context
protected ServletContext servletContext;
@@ -80,32 +77,36 @@ public class GraphWriter implements Mess
return ContextHelper.getServiceFromContext(Serializer.class,
servletContext);
}
- public boolean isWriteable(Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
- String mediaTypeString =
mediaType.getType()+'/'+mediaType.getSubtype();
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mediaType) {
+ String mediaTypeString = mediaType.getType() + '/' +
mediaType.getSubtype();
return TripleCollection.class.isAssignableFrom(type) &&
supportedMediaTypes.contains(mediaTypeString);
}
- public long getSize(TripleCollection t, Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
+ public long getSize(TripleCollection t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
return -1;
}
- public void writeTo(TripleCollection t, Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType,
- MultivaluedMap<String, Object> httpHeaders,
- OutputStream entityStream) throws IOException,
- WebApplicationException {
-
+ public void writeTo(TripleCollection t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String,Object> httpHeaders,
+ OutputStream entityStream) throws IOException,
WebApplicationException {
+
long start = System.currentTimeMillis();
- String mediaTypeString =
mediaType.getType()+'/'+mediaType.getSubtype();
- if (mediaType.isWildcardType() || TEXT_PLAIN.equals(mediaTypeString)
|| APPLICATION_OCTET_STREAM.equals(mediaTypeString)) {
+ String mediaTypeString = mediaType.getType() + '/' +
mediaType.getSubtype();
+ if (mediaType.isWildcardType() || TEXT_PLAIN.equals(mediaTypeString)
+ || APPLICATION_OCTET_STREAM.equals(mediaTypeString)) {
httpHeaders.putSingle("Content-Type", APPLICATION_JSON);
getSerializer().serialize(entityStream, t, APPLICATION_JSON);
} else {
getSerializer().serialize(entityStream, t, mediaTypeString);
}
-
- log.debug("Serialized {} in
{}ms",t.size(),System.currentTimeMillis()-start);
+ log.debug("Serialized {} in {}ms", t.size(),
System.currentTimeMillis() - start);
}
}