Package org.openrdf.rio

Examples of org.openrdf.rio.RDFFormat


    }



    private Repository parseRDFResponse(final URI resource, InputStream in, String contentType) throws RepositoryException, IOException, RDFParseException {
        RDFFormat format = RDFParserRegistry.getInstance().getFileFormatForMIMEType(contentType, RDFFormat.RDFXML);

        Repository triples = new SailRepository(new MemoryStore());
        triples.initialize();

        InterceptingRepositoryConnection con =
View Full Code Here


                conn.begin();
                // FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
                // "/" + uuid;
                URI resource = conn.getValueFactory().createURI(uri);
                // create parser
                final RDFFormat serializer = kiWiIOService.getSerializer(mimetype);
                if (serializer == null) {
                    Response response = Response.status(406).entity("mimetype can not be processed").build();
                    ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
                    return response;
                }

                if(resource != null) {

                    final Resource subject = resource;

                    StreamingOutput entity = new StreamingOutput() {
                        @Override
                        public void write(OutputStream output) throws IOException, WebApplicationException {
                            // FIXME: This method is executed AFTER the @Transactional!
                            RDFWriter writer = Rio.createWriter(serializer,output);
                            try {
                                RepositoryConnection connection = sesameService.getConnection();
                                try {
                                    connection.begin();
                                    connection.exportStatements(subject,null,null,true,writer);
                                } finally {
                                    connection.commit();
                                    connection.close();
                                }
                            } catch (RepositoryException e) {
                                throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
                            } catch (RDFHandlerException e) {
                                throw new IOException("error while writing RDF data to stream", e);
                            }

                        }
                    };

                    // build response
                    Response response = Response.ok(entity).lastModified(KiWiSesameUtil.lastModified(resource, conn)).build();
                    response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, resource) + "\"");
                   
                    if (!mimetype.contains("html")) { // then create a proper filename
                      String[] components;
                      if (uri.contains("#")) {
                        components = uri.split("#");                       
                      } else {
                        components = uri.split("/");
                      }
                      final String fileName = components[components.length-1] + "." + serializer.getDefaultFileExtension();  
                      response.getMetadata().add("Content-Disposition", "attachment; filename=\""+fileName+"\"");
                    }

                    // create the Content-Type header for the response
                    if (mimetype.startsWith("text/") || mimetype.startsWith("application/")) {
View Full Code Here

    }

    public Response putMeta(String uri, String mimetype, HttpServletRequest request) {
        try {
            // 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, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
                return response;
            }
View Full Code Here

        for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) {
          if (entry.isDirectory()) {
            continue;
          }

          RDFFormat format = Rio.getParserFormatForFileName(entry.getName(), dataFormat);

          try {
            // Prevent parser (Xerces) from closing the input stream
            FilterInputStream wrapper = new FilterInputStream(zipIn) {
View Full Code Here

            // do nothing
        }
    }

    public static RDFFormat detectFileFormat(String filename) {
        RDFFormat result = Rio.getParserFormatForFileName(filename);
        if (result == null) {
            throw new IllegalArgumentException("Unknown file format");
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.