Package org.openrdf.rio

Examples of org.openrdf.rio.RDFFormat


  private void read(Repository m, String url) throws Exception {
    read(m, url, "RDFXML");
  }
 
  private void read(Repository m, String url, String syntax) throws Exception {
    RDFFormat format = null;
    if (syntax.equals("N3")) {
      format = RDFFormat.N3;
    } else if (syntax.equals("NTRIPLES")) {
      format = RDFFormat.NTRIPLES;
    } else if (syntax.equals("RDFXML")) {
View Full Code Here


                final URI resource = ResourceUtils.getUriResource(conn, resource_string);

                final ContentType type = getContentType(types_string);

                //get serializer
                final RDFFormat serializer = lmfIOService.getSerializer(type.getMime());

                //create response serialisation
                StreamingOutput entity = new StreamingOutput() {
                    @Override
                    public void write(OutputStream output) throws IOException, WebApplicationException {
View Full Code Here

    public List<String> getTypes(@QueryParam("filename") String filename) {
        if(filename == null)
            return new ArrayList<String>(importService.getAcceptTypes());
        else {
            List<String> result = new ArrayList<String>();
            RDFFormat format = Rio.getParserFormatForFileName(filename);
            if(format != null) {
                result.addAll(format.getMIMETypes());
            }
            return result;
        }
    }
View Full Code Here

        } else {
            fileName = "lmf-export-" + DateUtils.FILENAME_FORMAT.format(new Date());
        }

        if(bestType != null) {
            RDFFormat format = RDFFormat.forMIMEType(bestType.getMime());
            if(format != null) {
                fileName += "." + format.getDefaultFileExtension();
            }

            URI context = null;
            if(context_string != null) {
                try {
View Full Code Here

                if (r == null || !ResourceUtils.isUsed(conn, r)) {
                  return ResourceWebServiceHelper.buildErrorPage(resource, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "the requested resource could not be found in LMF right now, but may be available again in the future", configurationService, templatingService);
                }
             
                // 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(r != null) {

                    final Resource subject = r;

                    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(r, conn)).build();
                    response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
                   
                    if (!mimetype.contains("html")) { // then create a proper filename
                      String[] components;
                      if (resource.contains("#")) {
                        components = resource.split("#");                       
                      } else {
                        components = resource.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

     * @return an RDF repository containing an RDF representation of the dataset located at the remote resource.
     * @throws java.io.IOException in case an error occurs while reading the input stream
     */
    @Override
    public List<String> parseResponse(final String resourceUri, String requestUrl, Repository triples, InputStream in, String contentType) throws DataRetrievalException {
        RDFFormat format = RDFParserRegistry.getInstance().getFileFormatForMIMEType(contentType, RDFFormat.RDFXML);

        try {
            InterceptingRepositoryConnection con =
                    new InterceptingRepositoryConnectionWrapper(triples,triples.getConnection());

View Full Code Here

  private String detectFormat(File file) throws MarmottaImportException {
    String format = null;
    String fileName = file.getName();
   
    //mimetype detection
    RDFFormat rdfFormat = Rio.getParserFormatForFileName(fileName);
    if (rdfFormat != null && importService.getAcceptTypes().contains(rdfFormat.getDefaultMIMEType())) {
      format = rdfFormat.getDefaultMIMEType();
    } else {
      throw new MarmottaImportException("Suitable RDF parser not found");
    }

      //encoding detection
View Full Code Here

    }

    public FileBackend(File file, String mimetype) {
        super();

        RDFFormat format = null;

        if(mimetype != null) {
            format = RDFFormat.forMIMEType(mimetype);
        }
View Full Code Here

    }

    public FileBackend(URL url, String mimetype) {
        super();

        RDFFormat format = null;

        if(mimetype != null) {
            format = RDFFormat.forMIMEType(mimetype);
        }
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.