Package org.apache.jena.atlas.web

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


    // 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


        parser.parse() ;
    }

    /** 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

    {
        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 ;

                    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

       
        if ( contentTypeHeader == null )
            errorBadRequest("No content type: "+contentTypeHeader) ;
            // lang = Lang.guess(action.request.getRequestURI()) ;
       
        ContentType ct = ContentType.parse(contentTypeHeader) ;
       
        String base = wholeRequestURL(action.request) ;
       
        // Use WebContent names
        if ( WebContent.contentTypeMultiFormData.equalsIgnoreCase(ct.getContentType()) )
        {
//            //log.warn("multipart/form-data not supported (yet)") ;
//            error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/form-data not supported") ;
            Graph graphTmp = SPARQL_Upload.upload(action.id,  action.getDatasetRef(), action.request, action.response, base) ;
            return DatasetGraphFactory.create(graphTmp) ;
        }
       
        if (WebContent.contentTypeMultiMixed.equals(ct.getContentType()) )
        {
            //log.warn("multipart/mixed not supported") ;
            error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/mixed not supported") ;
            return null ;
        }

        int len = action.request.getContentLength() ;
        Lang lang = WebContent.contentTypeToLang(ct.getContentType()) ;
        if ( lang == null )
        {
            errorBadRequest("Unknown content type for triples: "+contentTypeHeader) ;
            return null ;
        }

        if ( action.verbose )
        {
            if ( len >= 0 )
                log.info(format("[%d]   Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s",
                                      action.id, len, ct.getContentType(), ct.getCharset(), lang.getName())) ;
            else
                log.info(format("[%d]   Body: Content-Type=%s, Charset=%s => %s",
                                          action.id, ct.getContentType(), ct.getCharset(), lang.getName())) ;
        }
       
        try {
            InputStream input = action.request.getInputStream() ;
            boolean buffering = false ;
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

     
        // 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

    @Override
    protected void doPost(HttpAction action)     { doPutPost(action, false) ; }

    private void doPutPost(HttpAction action, boolean overwrite) {
        ContentType ct = FusekiLib.getContentType(action) ;
        if ( ct == null )
            errorBadRequest("No Content-Type:") ;

        // Helper case - if it's a possible HTTP file upload, pretend that's the action.
        if ( WebContent.contentTypeMultipartFormData.equalsIgnoreCase(ct.getContentType()) ) {
            String base = wholeRequestURL(action.request) ;
            SPARQL_Upload.upload(action, base) ;
            return ;
        }
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.