Search in sources :

Example 26 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class URIReference method fromQName.

public static URIReference fromQName(Frame f, String ns, String local) throws SAXParseException {
    URIReference rslt = new URIReference(ns + local);
    f.checkEncoding(rslt, local);
    // TODO: not for 2.3 move some of the check upwards ...
    IRI iri = f.arp.iriFactory().create(ns + local);
    AbsXMLContext.checkURI(f.arp, rslt, iri);
    return rslt;
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 27 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class XMLBaselessContext method withBase.

@Override
public AbsXMLContext withBase(XMLHandler forErrors, String b) throws SAXParseException {
    TaintImpl taintB = new TaintImpl();
    IRI newB = resolveAsURI(forErrors, taintB, b, false);
    if (newB.isRelative())
        return new XMLBaselessContext(forErrors, errno, newB.create(""));
    if (newB.hasViolation(false))
        return new XMLBaselessContext(forErrors, ERR_RESOLVING_AGAINST_MALFORMED_BASE, newB);
    return new XMLContext(keepDocument(forErrors), document, newB.create(""), taintB, lang, langTaint);
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 28 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class Unparser method setLocalName.

/**
     * Note: must work with uri being null.
     */
private void setLocalName(String uri) {
    if (uri == null || uri.equals(""))
        localName = "";
    else //            try 
    {
        IRI u = BaseXMLWriter.factory.create(uri);
        u = u.create("");
        localName = u.toString();
    }
//        catch (MalformedURIException e) {
//                throw new BadURIException(uri, e);
//            }
}
Also used : IRI(org.apache.jena.iri.IRI)

Example 29 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class SPARQL_Upload method uploadWorker.

/** Process an HTTP file upload of RDF with additiona name field for the graph name.
     *  We can't stream straight into a dataset because the graph name can be after the data.
     *  @return graph name and count
     */
// ?? Combine with Upload.fileUploadWorker
// Difference is the handling of names for graphs.
private static UploadDetails uploadWorker(HttpAction action, String base) {
    DatasetGraph dsgTmp = DatasetGraphFactory.create();
    ServletFileUpload upload = new ServletFileUpload();
    String graphName = null;
    boolean isQuads = false;
    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))
                            ServletOps.errorBadRequest("Bad IRI: " + graphName);
                        if (iri.getScheme() == null)
                            ServletOps.errorBadRequest("Bad IRI: no IRI scheme name: " + graphName);
                        if (iri.getScheme().equalsIgnoreCase("http") || iri.getScheme().equalsIgnoreCase("https")) {
                            // Redundant??
                            if (iri.getRawHost() == null)
                                ServletOps.errorBadRequest("Bad IRI: no host name: " + graphName);
                            if (iri.getRawPath() == null || iri.getRawPath().length() == 0)
                                ServletOps.errorBadRequest("Bad IRI: no path: " + graphName);
                            if (iri.getRawPath().charAt(0) != '/')
                                ServletOps.errorBadRequest("Bad IRI: Path does not start '/': " + graphName);
                        }
                    }
                } else if (fieldName.equals(HttpNames.paramDefaultGraphURI))
                    graphName = null;
                else
                    // Add file type?
                    action.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"))
                    ServletOps.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);
                    // present we wrap the stream accordingly
                    if (name.endsWith(".gz"))
                        stream = new GZIPInputStream(stream);
                }
                if (lang == null)
                    // Desperate.
                    lang = RDFLanguages.RDFXML;
                isQuads = RDFLanguages.isQuads(lang);
                action.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.dataset(dsgTmp);
                StreamRDFCounting dest = StreamRDFLib.count(x);
                ActionSPARQL.parse(action, dest, stream, lang, base);
                count = dest.count();
            }
        }
        if (graphName == null || graphName.equals(""))
            graphName = HttpNames.valueDefault;
        if (isQuads)
            graphName = null;
        return new UploadDetails(graphName, dsgTmp, count);
    } catch (ActionErrorException ex) {
        throw ex;
    } catch (Exception ex) {
        ServletOps.errorOccurred(ex);
        return null;
    }
}
Also used : IRI(org.apache.jena.iri.IRI) ContentType(org.apache.jena.atlas.web.ContentType) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) Lang(org.apache.jena.riot.Lang) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) GZIPInputStream(java.util.zip.GZIPInputStream) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) StreamRDF(org.apache.jena.riot.system.StreamRDF) StreamRDFCounting(org.apache.jena.riot.lang.StreamRDFCounting) FileItemIterator(org.apache.commons.fileupload.FileItemIterator)

Example 30 with IRI

use of org.apache.jena.iri.IRI in project jena by apache.

the class FusekiVocab method iri.

private static String iri(String localname) {
    String uri = NS + localname;
    IRI iri = IRIResolver.parseIRI(uri);
    if (iri.hasViolation(true))
        throw new FusekiException("Bad IRI: " + iri);
    if (!iri.isAbsolute())
        throw new FusekiException("Bad IRI: " + iri);
    return uri;
}
Also used : IRI(org.apache.jena.iri.IRI) FusekiException(org.apache.jena.fuseki.FusekiException)

Aggregations

IRI (org.apache.jena.iri.IRI)51 Violation (org.apache.jena.iri.Violation)12 IRIFactory (org.apache.jena.iri.IRIFactory)9 IOException (java.io.IOException)3 Node (org.apache.jena.graph.Node)3 Test (org.junit.Test)3 PrintStream (java.io.PrintStream)2 MalformedURLException (java.net.MalformedURLException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 CheckerIRI (org.apache.jena.riot.checker.CheckerIRI)2 IRI (org.apache.jena.riot.tokens.TokenType.IRI)2 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URL (java.net.URL)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 Time (java.sql.Time)1