Package org.apache.marmotta.commons.http

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


        Assert.assertTrue(type2.matchesSubtype(type1));
        Assert.assertFalse(type1.matchesSubtype(type2));
    }
    @Test
    public void testMatchQualifier2() throws Exception {
        ContentType type1 = new ContentType("application","rdf+json");
        ContentType type2 = new ContentType("application","*");

        Assert.assertTrue(type2.matchesWildcard(type1));
        Assert.assertFalse(type2.matchesSubtype(type1));
        Assert.assertFalse(type1.matchesSubtype(type2));
    }
View Full Code Here


    }


    @Test
    public void testGetBestMatch1() throws Exception {
        ContentType offered1 = new ContentType("text","html");
        ContentType offered2 = new ContentType("application","rdf+json");
        ContentType offered3 = new ContentType("application","ld+json");

        List<ContentType> offered = new ArrayList<ContentType>(3);
        offered.add(offered1);
        offered.add(offered2);
        offered.add(offered3);

        ContentType accepted1 = new ContentType("application","json");
        ContentType accepted2 = new ContentType("*","*");
        List<ContentType> accepted = new ArrayList<ContentType>(2);
        accepted.add(accepted1);
        accepted.add(accepted2);

        Assert.assertEquals(offered2, LMFHttpUtils.bestContentType(offered,accepted));
View Full Code Here

        Assert.assertEquals(offered2, LMFHttpUtils.bestContentType(offered,accepted));
    }

    @Test
    public void testGetBestMatch2() throws Exception {
        ContentType offered1 = new ContentType("text","html");
        ContentType offered2 = new ContentType("application","rdf+json");
        ContentType offered3 = new ContentType("application","ld+json");

        List<ContentType> offered = new ArrayList<ContentType>(3);
        offered.add(offered1);
        offered.add(offered2);
        offered.add(offered3);

        ContentType accepted1 = new ContentType("application","xml");
        ContentType accepted2 = new ContentType("*","*");
        List<ContentType> accepted = new ArrayList<ContentType>(2);
        accepted.add(accepted1);
        accepted.add(accepted2);

        Assert.assertEquals(offered1, LMFHttpUtils.bestContentType(offered,accepted));
View Full Code Here

        Assert.assertEquals(offered1, LMFHttpUtils.bestContentType(offered,accepted));
    }

    @Test
    public void testGetBestMatch3() throws Exception {
        ContentType offered1 = new ContentType("text","html");
        ContentType offered2 = new ContentType("application","rdf+json");
        ContentType offered3 = new ContentType("application","ld+json");

        List<ContentType> offered = new ArrayList<ContentType>(3);
        offered.add(offered1);
        offered.add(offered2);
        offered.add(offered3);

        ContentType accepted1 = new ContentType("application","ld+json");
        ContentType accepted2 = new ContentType("*","*");
        List<ContentType> accepted = new ArrayList<ContentType>(2);
        accepted.add(accepted1);
        accepted.add(accepted2);

        Assert.assertEquals(offered3, LMFHttpUtils.bestContentType(offered,accepted));
View Full Code Here

              producedTypes.remove("application/xhtml+xml");
              offeredTypes  = MarmottaHttpUtils.parseStringList(producedTypes);
            } else {
              return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
            }
              ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
              if (bestType == null) {
                return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity("no result format specified or unsupported result format").build();
              } else {
                return buildQueryResponse(bestType, query, queryType);
              }
View Full Code Here

                return Response.ok().build();
            } else {
                if (resultType == null) {
                    List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
                    List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html"));
                    ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
                    if (bestType != null) {
                        resultType = bestType.getMime();
                    }
                }
                if (parseSubType(resultType).equals("html"))
                    return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/update.html")).build();
                else
View Full Code Here

            acceptedTypes = Collections.singletonList(MarmottaHttpUtils.parseContentType(RDFXML.getDefaultMIMEType()));
        } else {
            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
        }
       
        ContentType _bestType = null;
        RDFFormat _format = null;
        for (ContentType ct : acceptedTypes) {
            final RDFFormat f = Rio.getWriterFormatForMIMEType(ct.getMime());
            if (f != null) {
                _bestType = ct;
                _format = f;
                break;
            }
        }
        if (_bestType == null || _format == null) {
            // FIXME: todo
            return Response.status(Status.BAD_REQUEST).entity("Could not determine Format").build();
        }
       
        final RDFFormat format = _format;
        final ContentType returnType = _bestType;
       
        final StreamingOutput entity = new StreamingOutput() {
            @Override
            public void write(OutputStream outputStream) throws IOException,
                    WebApplicationException {
                try {
                    final RDFWriter writer = Rio.createWriter(format, outputStream);
                    sparqlService.createServiceDescription(writer, request.getRequestURL().toString(), isUpdate);
                } catch (RDFHandlerException e) {
                    log.warn("Could not send SpaqlServiceDescription: {}", e);
                    throw new NoLogWebApplicationException(e, Response.serverError().entity(e).build());
                }
            }
        };

        return Response.ok(entity, new MediaType(returnType.getType(), returnType.getSubtype(), returnType.getCharset().name())).build();
    }
View Full Code Here

public class FreebaseEndpoint extends Endpoint {

    public FreebaseEndpoint() {
        super(FreebaseProvider.NAME, FreebaseProvider.NAME, FreebaseProvider.PATTERN, null, 86400L);
        setPriority(PRIORITY_MEDIUM);
        addContentType(new ContentType("text", "turtle", 1.0));
        addContentType(new ContentType("text", "plain", 0.2));
        addContentType(new ContentType("*", "*", 0.1));
    }
View Full Code Here

public class WikipediaPageEndpoint extends Endpoint {

    public WikipediaPageEndpoint() {
        super("Wikipedia Provider (Page)", MediawikiProvider.PROVIDER_NAME, "^http://([^.]+)\\.wikipedia\\.org/wiki/.*", "http://$1.wikipedia.org/w/api.php", 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("text", "xml"));
    }
View Full Code Here

public class VimeoVideoEndpoint extends Endpoint {

    public VimeoVideoEndpoint() {
        super("Vimeo Video", "Vimeo Video", "^http://vimeo\\.com/[0-9]+", null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("application","xml"));
    }
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.