Package org.apache.marmotta.commons.http

Examples of org.apache.marmotta.commons.http.ContentType


public class VimeoGroupEndpoint extends Endpoint {

    public VimeoGroupEndpoint() {
        super("Vimeo Channel (Group)", "Vimeo Channel", "^http://vimeo\\.com/groups/.*", null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("application","xml"));
    }
View Full Code Here


public class VimeoChannelEndpoint extends Endpoint {

    public VimeoChannelEndpoint() {
        super("Vimeo Channel (Channel)", "Vimeo Channel", "^http://vimeo\\.com/channels/.*", null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("application","xml"));
    }
View Full Code Here

        } else {
            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
        }
        List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(exportService.getProducedTypes());

        final ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);

        // create a file name for the export, preferrably with a good extension ...
        String fileName;
        if(context_string != null) {
            String[] components = context_string.split("/");
            fileName = components[components.length-1] + "-export-" + DateUtils.FILENAME_FORMAT.format(new Date());
        } else {
            fileName = "lmf-export-" + DateUtils.FILENAME_FORMAT.format(new Date());
        }

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

            URI context = null;
            if(context_string != null) {
                try {
                    RepositoryConnection conn = sesameService.getConnection();
                    try {
                        conn.begin();
                        context = conn.getValueFactory().createURI(context_string);
                    } finally {
                        conn.commit();
                        conn.close();
                    }
                } catch (RepositoryException e) {
                    handleRepositoryException(e,ExportWebService.class);
                }

                if(context == null) return Response.status(Response.Status.NOT_FOUND).entity("the context given as argument could not be found").build();

            } else {
                context = null;
            }
            final URI fcontext = context;

            StreamingOutput entity = new StreamingOutput() {
                @Override
                public void write(OutputStream output) throws IOException, WebApplicationException {
                    try {
                        //FIXME: html should not be exported, but rendered?
                        exportService.exportData(output,fcontext,bestType.getMime());
                    } catch (UnsupportedExporterException e) {
                        throw new WebApplicationException(e, Response.Status.NOT_ACCEPTABLE);
                    }
                }
            };

            return Response
                    .status(Response.Status.OK)
                    .header("Content-Type", bestType.getMime())
                    .header("Content-Disposition", "attachment; filename=\""+fileName+"\"")
                    .entity(entity)
                    .build();

        } else
View Full Code Here

                for (ContentType t : offeredTypes) {
                    t.setParameter("rel", "meta");
                }
                String contentmime = contentService.getContentType(r);
                if (contentmime != null) {
                    ContentType tContent = MarmottaHttpUtils.parseContentType(contentmime);
                    tContent.setParameter("rel", "content");
                    offeredTypes.add(0, tContent);
                }

                if (types == null || types.equals("")) {
                    return build406(Collections.<ContentType>emptyList(), offeredTypes);
                }

                List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
                ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);

                log.debug("identified best type: {}", bestType);

                if (bestType != null) {
                    Response response = buildGetResponse(r, bestType);
View Full Code Here

            // much about the order ...
            List<ContentType> acceptable = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
            for (ContentType a : acceptable) {
                a.setParameter("rel", "meta");
            }
            ContentType allContent = new ContentType("*", "*");
            allContent.setParameter("rel", "content");
            acceptable.add(0, allContent);

            // determine the best match between the offered types and the acceptable types
            ContentType bestType = MarmottaHttpUtils.bestContentType(types, acceptable);

            if (bestType != null) {
                if (configurationService.getBooleanConfiguration("linkeddata.redirect.put", true)) {
                    final RepositoryConnection con = sesameService.getConnection();
                    try {
                        con.begin();
                        URI resource = ResourceUtils.getUriResource(con, uri);
                        con.commit();
                        return Response
                                .status(configurationService.getIntConfiguration("linkeddata.redirect.status", 303))
                                        // .location(new URI(configurationService.getBaseUri() +
                                        // bestType.getParameter("rel") + "/" + bestType.getMime() + appendix))
                                .location(new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource, bestType, configurationService)))
                                .build();
                    } finally {
                        con.close();
                    }
                } else {
                    if ("content".equalsIgnoreCase(bestType.getParameter("rel")))
                        return contentWebService.putContent(uri, bestType.getMime(), request);
                    else if ("meta".equalsIgnoreCase(bestType.getParameter("rel")))
                        return metaWebService.putMeta(uri, bestType.getMime(), request);
                    else
                        return Response.serverError().entity("request did not specify whether it uploads content or metadata; use rel=content|meta attribute in Content-Type header").build();
                }
            } else {
                Response response = Response.status(415).entity("type " + mimetype + " not supported").build();
View Full Code Here

            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(format);
        } else {
            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(accept);
        }
        List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(exportService.getProducedTypes());
        offeredTypes.removeAll(Collections.unmodifiableList(Arrays.asList(new ContentType("text", "html"), new ContentType("application", "xhtml+xml"))));
        final ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
        return new URI(configurationService.getBaseUri() + "export/download?context=" + uri + "&format=" + bestType.getMime());
    }
View Full Code Here

public class PHPBBTopicEndpoint extends Endpoint {

    public PHPBBTopicEndpoint(String name, String urlPattern) {
        super(name, PHPBBTopicProvider.PROVIDER_NAME, urlPattern, null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("text", "html"));
    }
View Full Code Here

public class PHPBBPostEndpoint extends Endpoint {

    public PHPBBPostEndpoint(String name, String urlPattern) {
        super(name, PHPBBPostProvider.PROVIDER_NAME, urlPattern, null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("text", "html"));
    }
View Full Code Here

public class PHPBBForumEndpoint extends Endpoint {

    public PHPBBForumEndpoint(String name, String urlPattern) {
        super(name, PHPBBForumProvider.PROVIDER_NAME, urlPattern, null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("text", "html"));
    }
View Full Code Here

public class LinkedDataEndpoint extends Endpoint {

    public LinkedDataEndpoint() {
        super("Linked Data", "Linked Data", "http(s?)://.*", null, 86400L);
        setPriority(PRIORITY_LOW);
        addContentType(new ContentType("application", "rdf+xml", 0.8));
        addContentType(new ContentType("text", "turtle", 1.0));
        addContentType(new ContentType("text", "n3", 0.8));
        addContentType(new ContentType("text", "rdf+n3", 0.8));
        addContentType(new ContentType("application", "ld+json", 0.5));
        addContentType(new ContentType("application","rdf+json",0.8));
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.commons.http.ContentType

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.