Package org.apache.jena.riot

Examples of org.apache.jena.riot.Lang


        String mappedURI = mapURI(filenameOrURI) ;

        if ( log.isDebugEnabled() && !mappedURI.equals(filenameOrURI) )
            log.debug("Map: " + filenameOrURI + " => " + mappedURI) ;

        Lang lang =
            syntax != null
            ? RDFLanguages.nameToLang(syntax)
            : RDFLanguages.resourceNameToLang(mappedURI, Lang.RDFXML) ;
           
        RDFDataMgr.read(model, mappedURI, baseURI, lang);
View Full Code Here


            try {
                Graph g = GraphFactory.createDefaultGraph() ;
                HttpEntity entity = response.getEntity() ;
                // org.apache.http.entity.ContentType ;
                String ct = contentType(response) ;
                Lang lang = RDFLanguages.contentTypeToLang(ct) ;
                StreamRDF dest = StreamRDFLib.graph(g) ;
                InputStream in = entity.getContent() ;
                RDFDataMgr.parse(dest, in, baseIRI, lang) ;
                in.close() ;
                this.graph = g ;
View Full Code Here

            throw new NotFoundException(url) ;
        String contentType = in.getContentType() ;
       
        // Reading a URL, no hint language provided.
        // Use the URL structure as the hint.
        Lang lang = null ;
        if ( ! Lib.equal(contentType, WebContent.contentTypeTextPlain) )
            lang = RDFLanguages.contentTypeToLang(contentType) ;
       
        if ( lang == null )
            lang = RDFLanguages.filenameToLang(url) ;
View Full Code Here

        String source = update.getSource() ;
        Node dest = update.getDest() ;
        try {
            // Read into temporary storage to protect against parse errors.
            TypedInputStream s = RDFDataMgr.open(source) ;
            Lang lang = RDFDataMgr.determineLang(source, s.getContentType(), null) ;
           
            if ( RDFLanguages.isTriples(lang) ) {
                // Triples
                Graph g = GraphFactory.createGraphMem() ;
                StreamRDF stream = StreamRDFLib.graph(g) ;
View Full Code Here

                Lang.RDFXML.getContentType().getSubType()),
            null, null));

        while (it.hasNext())
        {
            Lang lang = it.next();
            if (!lang.equals(Lang.RDFNULL) && !lang.equals(Lang.RDFXML))
            {
                ContentType ct = lang.getContentType();
                //List<String> altTypes = lang.getAltContentTypes();
                MediaType mediaType = new MediaType(ct.getType(), ct.getSubType()); // MediaType.valueOf(ct.getContentType()
                variants.add(new Variant(mediaType, null, null));
            }
        }
View Full Code Here

                Lang.RDFXML.getContentType().getSubType()),
            null, null));

        while (it.hasNext())
        {
            Lang lang = it.next();
            if (!lang.equals(Lang.RDFNULL) && !lang.equals(Lang.RDFXML))
            {
                ContentType ct = lang.getContentType();
                //List<String> altTypes = lang.getAltContentTypes();
                MediaType mediaType = new MediaType(ct.getType(), ct.getSubType()); // MediaType.valueOf(ct.getContentType()
                variants.add(new Variant(mediaType, null, null));
            }
        }
View Full Code Here

    {
  if (log.isTraceEnabled()) log.trace("Reading Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);
 
  Model model = ModelFactory.createDefaultModel()

        Lang lang = RDFLanguages.contentTypeToLang(mediaType.toString());
        if (lang == null)
        {
            Throwable ex = new NoReaderForLangException("Media type not supported");
            if (log.isErrorEnabled()) log.error("MediaType {} not supported by Jena", mediaType);
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
  String syntax = lang.getName();
  if (log.isDebugEnabled()) log.debug("Syntax used to read Model: {}", syntax);

  // extract base URI from httpHeaders?
  return model.read(entityStream, null, syntax);
    }
View Full Code Here

    @Override
    public void writeTo(Model model, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
    {
  if (log.isTraceEnabled()) log.trace("Writing Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);

        Lang lang = RDFLanguages.contentTypeToLang(mediaType.toString());
        if (lang == null)
        {
            Throwable ex = new NoWriterForLangException("Media type not supported");
            if (log.isErrorEnabled()) log.error("MediaType {} not supported by Jena", mediaType);
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
  String syntax = lang.getName();
  if (log.isDebugEnabled()) log.debug("Syntax used to write Model: {}", syntax);

  model.write(entityStream, syntax);
    }
View Full Code Here

                Lang.RDFXML.getContentType().getSubType()),
            null, null));

        while (it.hasNext())
        {
            Lang lang = it.next();
            if (!lang.equals(Lang.RDFNULL) && !lang.equals(Lang.RDFXML))
            {
                ContentType ct = lang.getContentType();
                //List<String> altTypes = lang.getAltContentTypes();
                MediaType mediaType = new MediaType(ct.getType(), ct.getSubType()); // MediaType.valueOf(ct.getContentType()
                variants.add(new Variant(mediaType, null, null));
            }
        }
View Full Code Here

        String graphName = null ;
        long count = -1 ;
       
        String name = null
        ContentType ct = null ;
        Lang lang = null ;

        try {
            FileItemIterator iter = upload.getItemIterator(action.request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField())
                {
                    // Graph name.
                    String value = Streams.asString(stream, "UTF-8") ;
                    if ( fieldName.equals(HttpNames.paramGraph) )
                    {
                        graphName = value ;
                        if ( graphName != null && ! graphName.equals("") && ! graphName.equals(HttpNames.valueDefault) )
                        {
                            IRI iri = IRIResolver.parseIRI(value) ;
                            if ( iri.hasViolation(false) )
                                errorBadRequest("Bad IRI: "+graphName) ;
                            if ( iri.getScheme() == null )
                                errorBadRequest("Bad IRI: no IRI scheme name: "+graphName) ;
                            if ( iri.getScheme().equalsIgnoreCase("http") || iri.getScheme().equalsIgnoreCase("https"))
                            {
                                // Redundant??
                                if ( iri.getRawHost() == null )
                                    errorBadRequest("Bad IRI: no host name: "+graphName) ;
                                if ( iri.getRawPath() == null || iri.getRawPath().length() == 0 )
                                    errorBadRequest("Bad IRI: no path: "+graphName) ;
                                if ( iri.getRawPath().charAt(0) != '/' )
                                    errorBadRequest("Bad IRI: Path does not start '/': "+graphName) ;
                            }
                        }
                    }
                    else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                        graphName = null ;
                    else
                        // Add file type?
                        log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName)) ;
                } else {
                    // Process the input stream
                    name = item.getName() ;
                    if ( name == null || name.equals("") || name.equals("UNSET FILE NAME") )
                        errorBadRequest("No name for content - can't determine RDF syntax") ;

                    String contentTypeHeader = item.getContentType() ;
                    ct = ContentType.create(contentTypeHeader) ;

                    lang = WebContent.contentTypeToLang(ct.getContentType()) ;
                    if ( lang == null )
                        lang = RDFLanguages.filenameToLang(name) ;
                    if ( lang == null )
                        // Desperate.
                        lang = RDFLanguages.RDFXML ;

                    log.info(format("[%d] Upload: Filename: %s, Content-Type=%s, Charset=%s => %s",
                                    action.id, name,  ct.getContentType(), ct.getCharset(), lang.getName())) ;
                   
                    StreamRDF x = StreamRDFLib.graph(graphTmp) ;
                    StreamRDFCounting dest =  StreamRDFLib.count(x) ;
                    SPARQL_REST.parse(action, dest, stream, lang, base);
                    count = dest.count() ;
View Full Code Here

TOP

Related Classes of org.apache.jena.riot.Lang

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.