Skip to content

Commit 9043f99

Browse files
committed
GH-3526: Remove alternative relativization of XML output
1 parent 57cc799 commit 9043f99

File tree

2 files changed

+13
-316
lines changed

2 files changed

+13
-316
lines changed

jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/BaseXMLWriter.java

Lines changed: 13 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,12 @@ final synchronized public Object setProperty( String propName, Object propValue
635635
return result;
636636
} else if (propName.equalsIgnoreCase("prettyTypes")) {
637637
return setTypes((Resource[]) propValue);
638-
} else if (propName.equalsIgnoreCase("relativeURIs")) {
639-
int old = relativeFlags;
640-
relativeFlags = str2flags((String) propValue);
641-
return flags2str(old);
642638
} else if (propName.equalsIgnoreCase("blockRules")) {
643639
return setBlockRules(propValue);
640+
} else if (propName.equalsIgnoreCase("relativeURIs")) {
641+
logger.warn("Ignored property: relativeURIs");
642+
// Jena6 - now done if base is set otherwise, not done.
643+
return null;
644644
} else {
645645
logger.warn("Unsupported property: " + propName);
646646
return null;
@@ -751,83 +751,16 @@ Resource[] setBlockRules(Object o) {
751751
return rslt;
752752
}
753753

754-
// Copy from jena-iri IRIRelativize for isolation from IRIx provider usge.
755-
private class IRIRelativize {
756-
/** Allow same document references (e.g. "" or "#frag").*/
757-
static final public int SAMEDOCUMENT = 1;
758-
759-
/** Allow network relative references (e.g. "//example.org/a/b/c"). */
760-
static final public int NETWORK = 2;
761-
762-
/** Allow absolute relative references (e.g. "/a/b/c"). */
763-
static final public int ABSOLUTE = 4;
764-
765-
/** Allow child relative references (e.g. "b/c"). */
766-
static final public int CHILD = 8;
767-
768-
/** Allow parent relative references (e.g. "../b/c"). */
769-
770-
static final public int PARENT = 16;
771-
772-
/** Allow grandparent relative references (e.g. "../../b/c"). */
773-
static final public int GRANDPARENT = 32;
774-
}
775-
776-
/*
777-
private boolean sameDocument = true;
778-
private boolean network = false;
779-
private boolean absolute = true;
780-
private boolean relative = true;
781-
private boolean parent = true;
782-
private boolean grandparent = false;
783-
*/
784-
//private int relativeFlags = 0;
785-
private int dftRelativeFlags = IRIRelativize.SAMEDOCUMENT | IRIRelativize.ABSOLUTE | IRIRelativize.CHILD | IRIRelativize.PARENT;
786-
private int relativeFlags = dftRelativeFlags;
787-
788-
/**
789-
Answer the form of the URI after relativiation according to the relativeFlags set
790-
by properties. If the flags are 0 or the base URI is null, answer the original URI.
791-
Throw an exception if the URI is "bad" and we demandGoodURIs.
792-
*/
793-
protected String relativize( String uri ) {
794-
return relativeFlags != 0 && baseURI != null
795-
? relativize( baseURI, uri )
796-
: checkURI( uri );
797-
}
798-
799-
/**
800-
Answer the relative form of the URI against the base, according to the relativeFlags.
801-
*/
802-
private String relativize( IRIx base, String uri ) {
803-
if ( relativeFlags == 0 )
804-
return uri;
754+
/**
755+
Answer the form of the URI after relativization according to the relativeFlags set
756+
by properties. If the flags are 0 or the base URI is null, answer the original URI.
757+
Throw an exception if the URI is "bad" and we demandGoodURIs.
758+
*/
759+
protected String relativize( String uri ) {
760+
if ( baseURI == null )
761+
return checkURI( uri );
805762
try {
806-
// if ( relativeFlags != dftRelativeFlags ) {
807-
// // Use jena-iri for relativization. Backwards compatibility.
808-
// org.apache.jena.iri.IRI baseImpl = org.apache.jena.iri.IRIFactory.iriImplementation().create(base.str());
809-
// return baseImpl.relativize(uri, relativeFlags).toString();
810-
// }
811-
// if ( relativeFlags == 1 ) {
812-
// IRI3986 iri1 = IRI3986.create(base.str());
813-
// IRI3986 iri2 = IRI3986.create(uri);
814-
// IRI3986 x = AlgIRI2.relativeSameDocument(iri1, iri2);
815-
// return x!=null ? x.str() : uri;
816-
// }
817-
// if ( relativeFlags == 4 ) {
818-
// IRI3986 iri1 = IRI3986.create(base.str());
819-
// IRI3986 iri2 = IRI3986.create(uri);
820-
// IRI3986 x = AlgIRI2.relativeResource(iri1, iri2);
821-
// return x!=null ? x.str() : uri;
822-
// }
823-
// if ( relativeFlags == 8 ) {
824-
// IRI3986 iri1 = IRI3986.create(base.str());
825-
// IRI3986 iri2 = IRI3986.create(uri);
826-
// IRI3986 x = AlgIRI2.relativePath(iri1, iri2);
827-
// return x!=null ? x.str() : uri;
828-
// }
829-
830-
IRIx x = base.relativize( IRIx.create(uri) );
763+
IRIx x = baseURI.relativize( IRIx.create(uri) );
831764
return x != null ? x.str() : uri ;
832765
} catch (IRIException ex) {
833766
return uri;
@@ -865,49 +798,4 @@ else if (jenaNamespace.matcher(prefix).matches())
865798
return false;
866799
}
867800

868-
static private String flags2str(int f) {
869-
StringBuilder oldValue = new StringBuilder(64);
870-
if ( (f&IRIRelativize.SAMEDOCUMENT)!=0 )
871-
oldValue.append( "same-document, " );
872-
if ( (f&IRIRelativize.NETWORK)!=0 )
873-
oldValue.append( "network, ");
874-
if ( (f&IRIRelativize.ABSOLUTE)!=0 )
875-
oldValue.append("absolute, ");
876-
if ( (f&IRIRelativize.CHILD)!=0 )
877-
oldValue.append("relative, ");
878-
if ((f&IRIRelativize.PARENT)!=0)
879-
oldValue.append("parent, ");
880-
if ((f&IRIRelativize.GRANDPARENT)!=0)
881-
oldValue.append("grandparent, ");
882-
if (oldValue.length() > 0)
883-
oldValue.setLength(oldValue.length()-2);
884-
return oldValue.toString();
885-
}
886-
887-
public static int str2flags(String pv){
888-
StringTokenizer tkn = new StringTokenizer(pv,", ");
889-
int rslt = 0;
890-
while ( tkn.hasMoreElements() ) {
891-
String flag = tkn.nextToken();
892-
if ( flag.equals("same-document") )
893-
rslt |= IRIRelativize.SAMEDOCUMENT;
894-
else if ( flag.equals("network") )
895-
rslt |= IRIRelativize.NETWORK;
896-
else if ( flag.equals("absolute") )
897-
rslt |= IRIRelativize.ABSOLUTE;
898-
else if ( flag.equals("relative") )
899-
rslt |= IRIRelativize.CHILD;
900-
else if ( flag.equals("parent") )
901-
rslt |= IRIRelativize.PARENT;
902-
else if ( flag.equals("grandparent") )
903-
rslt |= IRIRelativize.GRANDPARENT;
904-
else
905-
906-
logger.warn(
907-
"Incorrect property value for relativeURIs: " + flag
908-
);
909-
}
910-
return rslt;
911-
}
912-
913801
}

jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures.java

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
package org.apache.jena.rdfxml.xmloutput;
2020

2121
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;
2822

2923
import org.apache.jena.graph.*;
3024
import org.apache.jena.irix.IRIException;
@@ -33,7 +27,6 @@
3327
import org.apache.jena.rdf.model.RDFReaderI;
3428
import org.apache.jena.rdf.model.RDFWriterI;
3529
import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler;
36-
import org.apache.jena.rdf.model.impl.Util;
3730
import org.apache.jena.rdfxml.xmlinput1.RDFXMLReader;
3831
import org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter;
3932
import org.apache.jena.rdfxml.xmloutput.impl.SimpleLogger;
@@ -469,188 +462,4 @@ public void testDescriptionAsProperty() throws IOException {
469462
public void testBadProperty1() throws IOException {
470463
checkPropURI("http://x/a.b/", null, null, BadPropURI);
471464
}
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", };
656465
}

0 commit comments

Comments
 (0)