Package org.apache.jena.riot

Examples of org.apache.jena.riot.Lang


            String filename = getValue(argFile) ;
            log.info("Dataset: in-memory: load file: "+filename) ;
            if ( ! FileOps.exists(filename) )
                throw new CmdException("File not found: "+filename) ;

            Lang language = RDFLanguages.filenameToLang(filename) ;
            if ( language == null )
                throw new CmdException("Can't guess language for file: "+filename) ;
            InputStream input = IO.openFile(filename) ;
           
            if ( RDFLanguages.isQuads(language) )
View Full Code Here


           
            String syntax = FusekiLib.safeParameter(httpRequest, paramSyntax) ;
            if ( syntax == null || syntax.equals("") )
                syntax = RDFLanguages.NQUADS.getName() ;

            Lang language = RDFLanguages.shortnameToLang(syntax) ;
            if ( language == null )
            {
                httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown syntax: "+syntax) ;
                return ;
            }
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 = RDFLanguages.contentTypeToLang(ct.getContentType()) ;

                    if ( lang == null ) {
                        lang = RDFLanguages.filenameToLang(name) ;
                       
                        //JENA-600 filenameToLang() strips off certain extensions such as .gz and
                        //we need to ensure that if there was a .gz extension present we wrap the stream accordingly
                        if (name.endsWith(".gz"))
                            stream = new GZIPInputStream(stream);
                    }
                    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

    }
   
    private static void incomingData(HttpAction action, StreamRDF dest) {
        String base = wholeRequestURL(action.request) ;
        ContentType ct = FusekiLib.getContentType(action) ;
        Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType()) ;
        if ( lang == null ) {
            errorBadRequest("Unknown content type for triples: " + ct) ;
            return ;
        }
        InputStream input = null ;
        try { input = action.request.getInputStream() ; }
        catch (IOException ex) { IO.exception(ex) ; }
   
        int len = action.request.getContentLength() ;
        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())) ;
        }
   
        parse(action, dest, input, lang, base) ;
    }
View Full Code Here

        {
            contentType = forceAccept ;
            charset = WebContent.charsetUTF8 ;
        }

        Lang lang = RDFLanguages.contentTypeToLang(contentType) ;
        if ( lang == null )
            errorBadRequest("Can't determine output content type: "+contentType) ;
       
//        if ( rdfw instanceof RDFXMLWriterI )
//            rdfw.setProperty("showXmlDeclaration", "true") ;
View Full Code Here

        ServletOutputStream output ;
        try { output = action.response.getOutputStream() ; }
        catch (IOException ex) { errorOccurred(ex) ; output = null ; }
       
        TypedOutputStream out = new TypedOutputStream(output, mediaType) ;
        Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType()) ;
        if ( lang == null )
            lang = RDFLanguages.TRIG ;

        if ( action.verbose )
            log.info(format("[%d]   Get: Content-Type=%s, Charset=%s => %s",
                                  action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName())) ;
        if ( ! RDFLanguages.isQuads(lang) )
            errorBadRequest("Not a quads format: "+mediaType) ;
       
        action.beginRead() ;
        try {
View Full Code Here

        String x = action.request.getContentType() ;
        if ( x == null )
            errorBadRequest("Content-type required for data format") ;
       
        MediaType mediaType = MediaType.create(x) ;
        Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType()) ;
        if ( lang == null )
            lang = RDFLanguages.TRIG ;

        if ( action.verbose )
            log.info(format("[%d]   Post: Content-Type=%s, Charset=%s => %s",
                                  action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName())) ;
       
        if ( RDFLanguages.isQuads(lang) )
            doPostQuads(action, lang) ;
        else if ( gspMode && RDFLanguages.isTriples(lang) )
            doPostTriplesGSP(action, lang) ;
View Full Code Here

//        if ( false )
//            SetupTDB.makeNodeTable(location, locationString, 0, outputFile, 0) ;

        for( String filename : datafiles)
        {
            Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS) ;
            if ( lang == null )
                // Does not happen due to default above.
                cmdError("File suffix not recognized: " +filename) ;
            if ( ! filename.equals("-") && ! FileOps.exists(filename) )
                cmdError("File does not exist: "+filename) ;
View Full Code Here

    /** Load into a graph */
    private static void loadTriples$(BulkStreamRDF dest, List<String> urls) {
        dest.startBulk() ;
        for ( String url : urls ) {
            loadLogger.info("Load: " + url + " -- " + Utils.nowAsString()) ;
            Lang lang = RDFLanguages.filenameToLang(url, Lang.NTRIPLES) ;
            RDFDataMgr.parse(dest, url, lang) ;
        }
        dest.finishBulk() ;
    }
View Full Code Here

    /** Load quads into a dataset */
    private static void loadQuads$(BulkStreamRDF dest, List<String> urls) {
        dest.startBulk() ;
        for ( String url : urls ) {
            loadLogger.info("Load: " + url + " -- " + Utils.nowAsString()) ;
            Lang lang = RDFLanguages.filenameToLang(url, Lang.NQUADS) ;
            RDFDataMgr.parse(dest, url, lang) ;
        }
        dest.finishBulk() ;
    }
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.