Search in sources :

Example 1 with Violation

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

the class IRIValidator method execute.

@Override
protected void execute(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    try {
        String[] args = httpRequest.getParameterValues(paramIRI);
        ServletOutputStream outStream = httpResponse.getOutputStream();
        PrintStream stdout = System.out;
        PrintStream stderr = System.err;
        System.setOut(new PrintStream(outStream));
        System.setErr(new PrintStream(outStream));
        setHeaders(httpResponse);
        outStream.println("<html>");
        printHead(outStream, "Jena IRI Validator Report");
        outStream.println("<body>");
        outStream.println("<h1>IRI Report</h1>");
        startFixed(outStream);
        try {
            boolean first = true;
            for (String iriStr : args) {
                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: " + iriStr);
                Iterator<Violation> vIter = iri.violations(true);
                for (; vIter.hasNext(); ) {
                    String str = vIter.next().getShortMessage();
                    str = htmlQuote(str);
                    System.out.println(str);
                }
            }
        } finally {
            finishFixed(outStream);
            System.out.flush();
            System.err.flush();
            System.setOut(stdout);
            System.setErr(stdout);
        }
        outStream.println("</body>");
        outStream.println("</html>");
    } catch (IOException ex) {
    }
}
Also used : Violation(org.apache.jena.iri.Violation) PrintStream(java.io.PrintStream) IRI(org.apache.jena.iri.IRI) ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException)

Example 2 with Violation

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

the class MainGenerateLexers method checkOne.

static void checkOne(String s) {
    IRI iri = IRIFactory.iriImplementation().create(s);
    System.out.println(">> " + iri);
    for (Iterator<Violation> iter = iri.violations(true); iter.hasNext(); ) {
        Violation v = iter.next();
        System.out.println(v.getShortMessage());
    }
    System.out.println("<< " + iri);
    System.out.println();
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

Example 3 with Violation

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

the class RunIRI method processIRI.

private static void processIRI(String iriStr) {
    IRI iri = IRIFactory.iriImplementation().create(iriStr);
    System.out.println(iri);
    System.out.println("Relative: " + iri.isRelative());
    Iterator<Violation> vIter = iri.violations(true);
    for (; vIter.hasNext(); ) {
        System.out.println("** " + vIter.next().getShortMessage());
    }
    System.out.println(iriStr + " ==> " + iri);
    System.exit(0);
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

Example 4 with Violation

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

the class MoreTests method testNotIDN.

public void testNotIDN() {
    @SuppressWarnings("deprecation") IRIFactory f = IRIFactory.jenaImplementation();
    IRI base = f.create("http://example.org/");
    IRI frag = base.resolve("outbind://4-00000000C45F478BF9F2A048A7A59DE" + "3AE35F7230700D3E3AEE226D20A49A390BCD779EC5D4700" + "00003DB3650000D3E3AEE226D20A49A390BCD779EC5D470" + "00001182DB0000/www.uconnectevent.org");
    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 5 with Violation

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

the class TestExample method runTest.

private void runTest(IRIFactory f, boolean expectError, boolean expectWarning, String desc) {
    IRI iri = f.create(uri);
    boolean implemented = violation.isImplemented();
    expectError = expectError && implemented;
    expectWarning = expectWarning && (!expectError) && implemented;
    if (good) {
        expectError = expectWarning = false;
    }
    boolean hasError = false;
    boolean hasWarning = false;
    Iterator<Violation> it = iri.violations(true);
    while (it.hasNext()) {
        Violation v = it.next();
        if (v.getViolationCode() == violation.getCode()) {
            if (v.isError()) {
                if (!expectError)
                    fail("Unexpected error, " + desc);
                hasError = true;
            } else {
                if (!expectWarning)
                    fail("Unexpected warning, " + desc);
                hasWarning = true;
            }
            break;
        }
    }
    if (expectWarning && !hasWarning)
        fail("No warning detected: " + expectError);
    if (expectError && !hasError)
        fail("No error detected: " + expectError);
}
Also used : Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI)

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