Search in sources :

Example 11 with Violation

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

the class MoreTests method testXPointer.

public void testXPointer() {
    @SuppressWarnings("deprecation") IRIFactory f = IRIFactory.jenaImplementation();
    IRI base = f.create("http://example.org/");
    IRI frag = base.resolve("http://eg.com/test.txt#xpointer(/unit[5])");
    Iterator<Violation> it = frag.violations(false);
    assertTrue(it.hasNext());
//		while (it.hasNext()) {
//			System.err.println(it.next().getLongMessage());
//		}
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) IRIFactory(org.apache.jena.iri.IRIFactory)

Example 12 with Violation

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

the class TestErrorMessages method runTest.

@Override
public void runTest() {
    IRI iri = f.create(uri);
    Iterator<Violation> it = iri.violations(true);
    while (it.hasNext()) {
        Violation v = it.next();
        printErrorMessages(v);
    }
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

Example 13 with Violation

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

the class NodeFunctions method iri.

public static Node iri(Node nv, String baseIRI) {
    if (nv.isURI())
        return nv;
    if (nv.isBlank()) {
        // Skolemization of blank nodes to IRIs : Don't ask, just don't ask.
        String x = nv.getBlankNodeLabel();
        return NodeFactory.createURI("_:" + x);
    }
    // Simple literal or xsd:string
    String str = simpleLiteralOrXSDString(nv);
    if (str == null)
        throw new ExprEvalException("Can't make an IRI from " + nv);
    IRI iri = null;
    String iriStr = nv.getLiteralLexicalForm();
    // Level of checking?
    if (baseIRI != null) {
        IRI base = iriFactory.create(baseIRI);
        iri = base.create(iriStr);
    } else
        iri = iriFactory.create(iriStr);
    if (!iri.isAbsolute())
        throw new ExprEvalException("Relative IRI string: " + iriStr);
    if (warningsForIRIs && iri.hasViolation(false)) {
        String msg = "unknown violation from IRI library";
        Iterator<Violation> iter = iri.violations(false);
        if (iter.hasNext()) {
            Violation viol = iter.next();
            msg = viol.getShortMessage();
        }
        Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri);
    }
    return NodeFactory.createURI(iri.toString());
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 14 with Violation

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

the class iri method main.

public static void main(String[] args) {
    //IRIFactory iriFactory = IRIFactory.iriImplementation() ;
    IRIFactory iriFactory = IRIResolver.iriFactory;
    boolean first = true;
    for (String iriStr : args) {
        if (iriStr.startsWith("<") && iriStr.endsWith(">"))
            iriStr = iriStr.substring(1, iriStr.length() - 1);
        if (!first)
            System.out.println();
        first = false;
        IRI iri = iriFactory.create(iriStr);
        System.out.println(iriStr + " ==> " + iri);
        if (iri.isRelative())
            System.out.println("Relative: " + iri.isRelative());
        Iterator<Violation> vIter = iri.violations(true);
        for (; vIter.hasNext(); ) {
            System.out.println(vIter.next().getShortMessage());
        }
    }
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) IRIFactory(org.apache.jena.iri.IRIFactory)

Aggregations

Violation (org.apache.jena.iri.Violation)14 IRI (org.apache.jena.iri.IRI)12 IRIFactory (org.apache.jena.iri.IRIFactory)3 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 ArrayList (java.util.ArrayList)1 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)1 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)1