// (3) Parse the Representtion(s) form the entity stream
if(content.getMediaType().isCompatible(MediaType.APPLICATION_JSON_TYPE)){
//parse from json
throw new UnsupportedOperationException("Parsing of JSON not yet implemented :(");
} else if(isSupported(content.getMediaType())){ //from RDF serialisation
RdfValueFactory valueFactory = RdfValueFactory.getInstance();
Set<Representation> representations = new HashSet<Representation>();
Set<NonLiteral> processed = new HashSet<NonLiteral>();
Parser parser = ContextHelper.getServiceFromContext(Parser.class, servletContext);
MGraph graph = new IndexedMGraph();
try {
parser.parse(graph,content.getEntityStream(), content.getMediaType().toString());
} catch (UnsupportedParsingFormatException e) {
//String acceptedMediaType = httpHeaders.getFirst("Accept");
//throw an internal server Error, because we check in
//isReadable(..) for supported types and still we get here a
//unsupported format -> therefore it looks like an configuration
//error the server (e.g. a missing Bundle with the required bundle)
String message = "Unable to create the Parser for the supported format"
+content.getMediaType()+" ("+e+")";
log.error(message,e);
throw new WebApplicationException(
Response.status(Status.INTERNAL_SERVER_ERROR).
entity(message).
header(HttpHeaders.ACCEPT, acceptedMediaType).build());
} catch (Exception e){
String message = "Unable to create the Parser for the supported format "
+content.getMediaType()+" ("+e+")";
log.error(message,e);
throw new WebApplicationException(
Response.status(Status.INTERNAL_SERVER_ERROR).
entity(message).
header(HttpHeaders.ACCEPT, acceptedMediaType).build());
}
for(Iterator<Triple> st = graph.iterator();st.hasNext();){
NonLiteral resource = st.next().getSubject();
if(resource instanceof UriRef && processed.add(resource)){
//build a new representation
representations.add(
valueFactory.createRdfRepresentation((UriRef)resource, graph));
}
}
return representations;
} else { //unsupported media type
String message = String.format(