Package org.apache.jena.atlas.web

Examples of org.apache.jena.atlas.web.ContentType


            InputStream in = IO.openFileEx(fn) ;

            if ( StreamManager.logAllLookups && log.isTraceEnabled() )
                log.trace("Found: "+filenameIRI+thisDirLogStr) ;
           
            ContentType ct = RDFLanguages.guessContentType(filenameIRI) ;
            return new TypedInputStream(in, ct, filenameIRI) ;
        } catch (IOException ioEx)
        {
            // Includes FileNotFoundException
            // We already tested whether the file exists or not.
View Full Code Here


    // We could have had two step design - ReaderFactory-ReaderInstance
    // no - put the bruden on complicated readers, not everyone.
   
    private static void process(StreamRDF destination , TypedInputStream in , String baseUri , Lang hintLang , Context context )
    {
        ContentType ct = determineCT(baseUri, in.getContentType(), hintLang ) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the triples content type: (URI="+baseUri+" : stream="+in.getContentType()+" : hint="+hintLang+")") ;

        ReaderRIOT reader = getReader(ct) ;
        if ( reader == null )
        {
            throw new RiotException("No triples reader for content type: "+ct.getContentType()) ;
        }
        reader.read(in, baseUri, ct, destination, context) ;
    }
View Full Code Here

    // java.io.Readers are NOT preferred.
    @SuppressWarnings("deprecation")
    private static void processTriples(StreamRDF output, String base, Reader in, Lang lang, Context context)
    {
        // Not as good as from an InputStream - RDF/XML not supported
        ContentType ct = determineCT(base, null, lang) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the triples content type: (URI="+base+" : hint="+lang+")") ;
        LangRIOT parser ;
        if ( lang == null )
            throw new RiotException("No language specificied") ;
View Full Code Here

    {
        boolean isTextPlain = WebContent.contentTypeTextPlain.equals(ctStr) ;
       
        if ( ctStr != null )
            ctStr = WebContent.contentTypeCanonical(ctStr) ;
        ContentType ct = (ctStr==null) ? null : ContentType.parse(ctStr) ;
       
        // If it's text plain, we ignore it because a lot of naive
        // server setups return text/plain for any file type.
        // We use the file extension.
       
View Full Code Here

    {
        ServletFileUpload upload = new ServletFileUpload();
        // Locking only needed over the insert into the dataset
        String graphName = null ;
        String name = null
        ContentType ct = null ;
        Lang lang = null ;
        int tripleCount = 0 ;

        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(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.parse(contentTypeHeader) ;

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

                    // We read into a in-memory graph, then (if successful) update the dataset.
                    // This isolates errors.
                    StreamRDF dest = StreamRDFLib.graph(graphDst) ;
                    LangRIOT parser = RiotReader.createParser(stream, lang, base, dest) ;
                    parser.getProfile().setHandler(errorHandler) ;
                    log.info(format("[%d] Upload: Filename: %s, Content-Type=%s, Charset=%s => %s",
                                    action.id, name,  ct.getContentType(), ct.getCharset(), lang.getName())) ;
                    try { parser.parse() ; }
                    catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage()) ; }
                }
            }   
View Full Code Here

    {
        // I ti s shame we effectively duplicate deciding thelnaguage but we want to control the
        // pasrer at a deep level (in validation, we want line numbers get into error message)
        // This code predates RDFDataMgr.
       
        ContentType ct = in.getMediaType() ;
       
        baseURI = SysRIOT.chooseBaseIRI(baseURI, filename) ;
       
        boolean checking = true ;
        if ( modLangParse.explicitChecking() )  checking = true ;
View Full Code Here

    // We could have had two step design - ReaderFactory-ReaderInstance
    // no - put the bruden on complicated readers, not everyone.
   
    private static void process(StreamRDF destination, TypedInputStream in, String baseUri, Lang hintLang, Context context)
    {
        ContentType ct = determineCT(baseUri, in.getContentType(), hintLang) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : stream="+in.getContentType()+" : hint="+hintLang+")") ;

        ReaderRIOT reader = getReader(ct) ;
        if ( reader == null )
            throw new RiotException("No parser registered for content type: "+ct.getContentType()) ;
        reader.read(in, baseUri, ct, destination, context) ;
    }
View Full Code Here

    // java.io.Readers are NOT preferred.
    private static void process(StreamRDF destination, Reader in, String baseUri, Lang lang, Context context )
    {
        // Not as good as from an InputStream
        ContentType ct = determineCT(baseUri, null, lang) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : hint="+lang+")") ;
        ReaderRIOT reader = getReader(ct) ;
        if ( reader == null )
            throw new RiotException("No parser registered for content type: "+ct.getContentType()) ;
        reader.read(in, baseUri, ct, destination, context) ;
    }
View Full Code Here

        return r.create(lang) ;
    }

    /** Determine the Lang, given the URI target, any content type header string and a hint */
    public static Lang determineLang(String target, String ctStr, Lang hintLang) {
        ContentType ct = determineCT(target, ctStr, hintLang) ;
        if ( ct == null )
            return hintLang ;
        Lang lang = RDFLanguages.contentTypeToLang(ct) ;
        if (lang == null )
            return hintLang ;
View Full Code Here

        // If it's text plain, we ignore it because a lot of naive
        // server setups return text/plain for any file type.
        // (It was never registered as being N-triples;
        // that was only for RDF 2004 testing.)
        ContentType ct = null ;
        if ( ! isTextPlain )
            // Not guaranteed to be registered as a language here.
            ct = (ctStr==null) ? null : ContentType.create(ctStr) ;
       
        if ( ct == null && hintLang != null )
View Full Code Here

TOP

Related Classes of org.apache.jena.atlas.web.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.