|
19 | 19 | package org.apache.jena.rdfxml.xmloutput; |
20 | 20 |
|
21 | 21 | import java.io.*; |
22 | | -import java.nio.charset.StandardCharsets; |
23 | | -import java.util.Collection; |
24 | | -import java.util.HashSet; |
25 | | -import java.util.Iterator; |
26 | | -import java.util.Set; |
27 | | -import java.util.regex.Pattern; |
28 | 22 |
|
29 | 23 | import org.apache.jena.graph.*; |
30 | 24 | import org.apache.jena.irix.IRIException; |
|
33 | 27 | import org.apache.jena.rdf.model.RDFReaderI; |
34 | 28 | import org.apache.jena.rdf.model.RDFWriterI; |
35 | 29 | import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler; |
36 | | -import org.apache.jena.rdf.model.impl.Util; |
37 | 30 | import org.apache.jena.rdfxml.xmlinput1.RDFXMLReader; |
38 | 31 | import org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter; |
39 | 32 | import org.apache.jena.rdfxml.xmloutput.impl.SimpleLogger; |
@@ -469,188 +462,4 @@ public void testDescriptionAsProperty() throws IOException { |
469 | 462 | public void testBadProperty1() throws IOException { |
470 | 463 | checkPropURI("http://x/a.b/", null, null, BadPropURI); |
471 | 464 | } |
472 | | - |
473 | | - /* |
474 | | - * public void testBadProperty2() throws IOException { |
475 | | - * checkPropURI("http:/a.b/", "brickley", "http://example.org/b#", |
476 | | - * ExtraTriples); } |
477 | | - * |
478 | | - */ |
479 | | - public void testRelativeAPI() { |
480 | | - @SuppressWarnings("deprecation") |
481 | | - RDFWriterI w = createMemModel().getWriter(lang); |
482 | | - String old = (String) w.setProperty("relativeURIs", ""); |
483 | | - assertEquals("default value check", old, |
484 | | - "same-document, absolute, relative, parent"); |
485 | | - w.setProperty("relativeURIs", "network, grandparent,relative, "); |
486 | | - w.setProperty("relativeURIs", |
487 | | - " parent, same-document, network, parent, absolute "); |
488 | | - // TestLogger tl = new TestLogger(URI.class); |
489 | | - blockLogger(); |
490 | | - w.setProperty("relativeURIs", "foo"); // will get warning |
491 | | - assertTrue("A warning should have been generated.", unblockLogger()); |
492 | | - } |
493 | | - |
494 | | - private void relative(String relativeParam, String base, |
495 | | - Collection<String> regexesPresent, Collection<String> regexesAbsent) |
496 | | - throws IOException { |
497 | | - |
498 | | - Model m = createMemModel(); |
499 | | - m.read("file:testing/abbreviated/relative-uris.rdf"); |
500 | | - |
501 | | - String contents; |
502 | | - try ( ByteArrayOutputStream bos = new ByteArrayOutputStream() ) { |
503 | | - @SuppressWarnings("deprecation") |
504 | | - RDFWriterI writer = m.getWriter(lang); |
505 | | - writer.setProperty("relativeURIs", relativeParam); |
506 | | - writer.write(m, bos, base); |
507 | | - contents = bos.toString(StandardCharsets.UTF_8); |
508 | | - } |
509 | | - |
510 | | - try { |
511 | | - Model m2 = createMemModel(); |
512 | | - m2.read(new StringReader(contents), base); |
513 | | - assertTrue(m.isIsomorphicWith(m2)); |
514 | | - Iterator<String> it = regexesPresent.iterator(); |
515 | | - while (it.hasNext()) { |
516 | | - String regexPresent = it.next(); |
517 | | - assertTrue("Looking for /" + regexPresent + "/", Pattern |
518 | | - .compile(Util.substituteStandardEntities(regexPresent), |
519 | | - Pattern.DOTALL).matcher(contents).find() |
520 | | - // |
521 | | - // matcher.contains( |
522 | | - // contents, |
523 | | - // awk.compile( |
524 | | - // Util.substituteStandardEntities(regexPresent))) |
525 | | - ); |
526 | | - } |
527 | | - it = regexesAbsent.iterator(); |
528 | | - while (it.hasNext()) { |
529 | | - String regexAbsent = it.next(); |
530 | | - assertTrue( |
531 | | - "Looking for (not) /" + regexAbsent + "/", |
532 | | - !Pattern.compile("[\"']"+ Util.substituteStandardEntities(regexAbsent)+ "[\"']", Pattern.DOTALL) |
533 | | - .matcher(contents).find() |
534 | | - |
535 | | - // matcher.contains( |
536 | | - // contents, |
537 | | - // awk.compile( |
538 | | - // "[\"']" |
539 | | - // + Util.substituteStandardEntities(regexAbsent) |
540 | | - // + "[\"']")) |
541 | | - ); |
542 | | - } |
543 | | - contents = null; |
544 | | - } finally { |
545 | | - if (contents != null) { |
546 | | - System.err.println("==================="); |
547 | | - System.err.println("Offending content - " + toString()); |
548 | | - System.err.println("==================="); |
549 | | - System.err.println(contents); |
550 | | - System.err.println("==================="); |
551 | | - } |
552 | | - } |
553 | | - } |
554 | | - |
555 | | - static String rData1[][] = { |
556 | | - // http://www.example.org/a/b/c/d/ |
557 | | - { "", "http://www.example.org/a/b/c/d/", |
558 | | - "http://www.example.org/a/b/c/d/e/f/g/", |
559 | | - "http://www.example.org/a/b/C/D", |
560 | | - "http://www.example.org/A/B#foo/", |
561 | | - "http://www.example.org/a/b/c/d/X#bar", |
562 | | - "http://example.com/A", |
563 | | - "http://www.example.org/a/b/c/d/z[?]x=a", }, |
564 | | - { "same-document", "", null, null, null, null, null, null, }, |
565 | | - { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D", |
566 | | - "/A/B#foo/", "/a/b/c/d/X#bar", null, "/a/b/c/d/z[?]x=a", }, |
567 | | - { "relative", "[.]", "e/f/g/", null, null, "X#bar", null, |
568 | | - "z[?]x=a", }, |
569 | | - { "parent", "[.][.]/d/", "[.][.]/d/e/f/g/", null, null, |
570 | | - "[.][.]/d/X#bar", null, "[.][.]/d/z[?]x=a", }, |
571 | | - { "network", "//www.example.org/a/b/c/d/", |
572 | | - "//www.example.org/a/b/c/d/e/f/g/", |
573 | | - "//www.example.org/a/b/C/D", "//www.example.org/A/B#foo/", |
574 | | - "//www.example.org/a/b/c/d/X#bar", "//example.com/A", |
575 | | - "//www.example.org/a/b/c/d/z[?]x=a", }, |
576 | | - { "grandparent", "[.][.]/[.][.]/c/d/", "[.][.]/[.][.]/c/d/e/f/g/", |
577 | | - "[.][.]/[.][.]/C/D", null, "[.][.]/[.][.]/c/d/X#bar", null, |
578 | | - "[.][.]/[.][.]/c/d/z[?]x=a", }, }; |
579 | | - |
580 | | - static String rData2[][] = { |
581 | | - // http://www.example.org/a/b/c/d |
582 | | - { "", "http://www.example.org/a/b/c/d/", |
583 | | - "http://www.example.org/a/b/c/d/e/f/g/", |
584 | | - "http://www.example.org/a/b/C/D", |
585 | | - "http://www.example.org/A/B#foo/", |
586 | | - "http://www.example.org/a/b/c/d/X#bar", |
587 | | - "http://example.com/A", |
588 | | - "http://www.example.org/a/b/c/d/z[?]x=a", }, |
589 | | - { "same-document", null, null, null, null, null, null, null, }, |
590 | | - { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D", |
591 | | - "/A/B#foo/", "/a/b/c/d/X#bar", null, "/a/b/c/d/z[?]x=a", }, |
592 | | - { "relative", "d/", "d/e/f/g/", null, null, "d/X#bar", null, |
593 | | - "d/z[?]x=a", }, |
594 | | - { "parent", "[.][.]/c/d/", "[.][.]/c/d/e/f/g/", "[.][.]/C/D", null, |
595 | | - "[.][.]/c/d/X#bar", null, "[.][.]/c/d/z[?]x=a", }, |
596 | | - { "network", "//www.example.org/a/b/c/d/", |
597 | | - "//www.example.org/a/b/c/d/e/f/g/", |
598 | | - "//www.example.org/a/b/C/D", "//www.example.org/A/B#foo/", |
599 | | - "//www.example.org/a/b/c/d/X#bar", "//example.com/A", |
600 | | - "//www.example.org/a/b/c/d/z[?]x=a", }, |
601 | | - { "grandparent", "[.][.]/[.][.]/b/c/d/", |
602 | | - "[.][.]/[.][.]/b/c/d/e/f/g/", "[.][.]/[.][.]/b/C/D", null, |
603 | | - "[.][.]/[.][.]/b/c/d/X#bar", null, |
604 | | - "[.][.]/[.][.]/b/c/d/z[?]x=a", }, }; |
605 | | - |
606 | | - static String rData3[][] = { |
607 | | - // http://www.example.org/A/B# |
608 | | - { "", "http://www.example.org/a/b/c/d/", |
609 | | - "http://www.example.org/a/b/c/d/e/f/g/", |
610 | | - "http://www.example.org/a/b/C/D", |
611 | | - "http://www.example.org/A/B#foo/", |
612 | | - "http://www.example.org/a/b/c/d/X#bar", |
613 | | - "http://example.com/A", |
614 | | - "http://www.example.org/a/b/c/d/z[?]x=a", }, |
615 | | - { "same-document", null, null, null, "#foo/", null, null, null, }, |
616 | | - { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", "/a/b/C/D", |
617 | | - "/A/B#foo/", "/a/b/c/d/X#bar", null, "/a/b/c/d/z[?]x=a", }, |
618 | | - { "relative", null, null, null, "B#foo/", null, null, null, }, |
619 | | - { "parent", "[.][.]/a/b/c/d/", "[.][.]/a/b/c/d/e/f/g/", |
620 | | - "[.][.]/a/b/C/D", "[.][.]/A/B#foo/", |
621 | | - "[.][.]/a/b/c/d/X#bar", null, "[.][.]/a/b/c/d/z[?]x=a", }, |
622 | | - { "network", "//www.example.org/a/b/c/d/", |
623 | | - "//www.example.org/a/b/c/d/e/f/g/", |
624 | | - "//www.example.org/a/b/C/D", "//www.example.org/A/B#foo/", |
625 | | - "//www.example.org/a/b/c/d/X#bar", "//example.com/A", |
626 | | - "//www.example.org/a/b/c/d/z[?]x=a", }, |
627 | | - { "grandparent", null, null, null, null, null, null, null, }, }; |
628 | | - |
629 | | - private void relative(int i, String base, String d[][]) throws IOException { |
630 | | - Set<String> in = new HashSet<>(); |
631 | | - Set<String> out = new HashSet<>(); |
632 | | - for (int j = 1; j < d[i].length; j++) { |
633 | | - |
634 | | - in.add(d[i][j] == null ? d[0][j] : d[i][j]); |
635 | | - if (i != 0 && d[i][j] != null) |
636 | | - out.add(d[0][j]); |
637 | | - } |
638 | | - // System.out.println(base + "["+i+"]"); |
639 | | - relative(d[i][0], base, in, out); |
640 | | - } |
641 | | - |
642 | | - public void testRelative() throws Exception { |
643 | | - for (int i = 0; i < 7; i++) { |
644 | | - relative(i, "http://www.example.org/a/b/c/d/", rData1); |
645 | | - relative(i, "http://www.example.org/a/b/c/d", rData2); |
646 | | - relative(i, "http://www.example.org/A/B#", rData3); |
647 | | - } |
648 | | - } |
649 | | - |
650 | | - private static String uris[] = { "http://www.example.org/a/b/c/d/", |
651 | | - "http://www.example.org/a/b/c/d/e/f/g/", |
652 | | - "http://www.example.org/a/b/C/D", |
653 | | - "http://www.example.org/A/B#foo/", |
654 | | - "http://www.example.org/a/b/c/d/X#bar", "http://example.com/A", |
655 | | - "http://www.example.org/a/b/c/d/z?x=a", }; |
656 | 465 | } |
0 commit comments