This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit b72c874081e1759d86a82527227dfb3aec9ee207
Author: Andy Seaborne <[email protected]>
AuthorDate: Mon Oct 20 19:14:36 2025 +0100

    GH-3526: Remove alternative relativization of XML output
---
 .../jena/rdfxml/xmloutput/impl/BaseXMLWriter.java  | 138 ++-------------
 .../jena/rdfxml/xmloutput/TestXMLFeatures.java     | 191 ---------------------
 2 files changed, 13 insertions(+), 316 deletions(-)

diff --git 
a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/BaseXMLWriter.java
 
b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/BaseXMLWriter.java
index bf24df42b4..c6ba7b3d29 100644
--- 
a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/BaseXMLWriter.java
+++ 
b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/BaseXMLWriter.java
@@ -635,12 +635,12 @@ abstract public class BaseXMLWriter implements 
RDFXMLWriterI {
                        return result;
                } else if (propName.equalsIgnoreCase("prettyTypes")) {
                        return setTypes((Resource[]) propValue);
-               } else if (propName.equalsIgnoreCase("relativeURIs")) {
-                       int old = relativeFlags;
-                       relativeFlags = str2flags((String) propValue);
-                       return flags2str(old);
                } else if (propName.equalsIgnoreCase("blockRules")) {
                        return setBlockRules(propValue);
+        } else if (propName.equalsIgnoreCase("relativeURIs")) {
+            logger.warn("Ignored property: relativeURIs");
+            // Jena6 - now done if base is set otherwise, not done.
+            return null;
                } else {
                        logger.warn("Unsupported property: " + propName);
                        return null;
@@ -751,83 +751,16 @@ abstract public class BaseXMLWriter implements 
RDFXMLWriterI {
                return rslt;
        }
 
-       // Copy from jena-iri IRIRelativize for isolation from IRIx provider 
usge.
-       private class IRIRelativize {
-           /** Allow same document references (e.g. "" or "#frag").*/
-           static final public int SAMEDOCUMENT = 1;
-
-           /** Allow network relative references (e.g. "//example.org/a/b/c"). 
*/
-           static final public int NETWORK = 2;
-
-           /** Allow absolute relative references (e.g. "/a/b/c"). */
-           static final public int ABSOLUTE = 4;
-
-           /** Allow child relative references (e.g. "b/c"). */
-           static final public int CHILD = 8;
-
-           /** Allow parent relative references (e.g. "../b/c"). */
-
-           static final public int PARENT = 16;
-
-           /** Allow grandparent relative references (e.g. "../../b/c"). */
-           static final public int GRANDPARENT = 32;
-       }
-
-       /*
-       private boolean sameDocument = true;
-       private boolean network = false;
-       private boolean absolute = true;
-       private boolean relative = true;
-       private boolean parent = true;
-       private boolean grandparent = false;
-       */
-       //private int relativeFlags = 0;
-       private int dftRelativeFlags = IRIRelativize.SAMEDOCUMENT | 
IRIRelativize.ABSOLUTE | IRIRelativize.CHILD | IRIRelativize.PARENT;
-       private int relativeFlags = dftRelativeFlags;
-
-    /**
-        Answer the form of the URI after relativiation according to the 
relativeFlags set
-        by properties. If the flags are 0 or the base URI is null, answer the 
original URI.
-        Throw an exception if the URI is "bad" and we demandGoodURIs.
-    */
-    protected String relativize( String uri ) {
-        return relativeFlags != 0 && baseURI != null
-            ? relativize( baseURI, uri )
-            : checkURI( uri );
-    }
-
-    /**
-        Answer the relative form of the URI against the base, according to the 
relativeFlags.
-    */
-    private String relativize( IRIx base, String uri )  {
-        if ( relativeFlags == 0 )
-            return uri;
+       /**
+    Answer the form of the URI after relativization according to the 
relativeFlags set
+    by properties. If the flags are 0 or the base URI is null, answer the 
original URI.
+    Throw an exception if the URI is "bad" and we demandGoodURIs.
+        */
+       protected String relativize( String uri ) {
+           if ( baseURI == null )
+               return checkURI( uri );
         try {
-//            if ( relativeFlags != dftRelativeFlags ) {
-//                // Use jena-iri for relativization. Backwards compatibility.
-//                org.apache.jena.iri.IRI baseImpl = 
org.apache.jena.iri.IRIFactory.iriImplementation().create(base.str());
-//                return baseImpl.relativize(uri, relativeFlags).toString();
-//            }
-//            if ( relativeFlags == 1 ) {
-//                IRI3986 iri1 = IRI3986.create(base.str());
-//                IRI3986 iri2 = IRI3986.create(uri);
-//                IRI3986 x = AlgIRI2.relativeSameDocument(iri1, iri2);
-//                return x!=null ? x.str() : uri;
-//            }
-//            if ( relativeFlags == 4 ) {
-//                IRI3986 iri1 = IRI3986.create(base.str());
-//                IRI3986 iri2 = IRI3986.create(uri);
-//                IRI3986 x = AlgIRI2.relativeResource(iri1, iri2);
-//                return x!=null ? x.str() : uri;
-//            }
-//            if ( relativeFlags == 8 ) {
-//                IRI3986 iri1 = IRI3986.create(base.str());
-//                IRI3986 iri2 = IRI3986.create(uri);
-//                IRI3986 x = AlgIRI2.relativePath(iri1, iri2);
-//                return x!=null ? x.str() : uri;
-//            }
-
-            IRIx x = base.relativize( IRIx.create(uri) );
+            IRIx x = baseURI.relativize( IRIx.create(uri) );
             return x != null ? x.str() : uri ;
         } catch (IRIException ex) {
             return uri;
@@ -865,49 +798,4 @@ abstract public class BaseXMLWriter implements 
RDFXMLWriterI {
         return false;
     }
 
-    static private String flags2str(int f) {
-       StringBuilder oldValue = new StringBuilder(64);
-       if ( (f&IRIRelativize.SAMEDOCUMENT)!=0 )
-          oldValue.append( "same-document, " );
-       if ( (f&IRIRelativize.NETWORK)!=0 )
-          oldValue.append( "network, ");
-       if ( (f&IRIRelativize.ABSOLUTE)!=0 )
-          oldValue.append("absolute, ");
-       if ( (f&IRIRelativize.CHILD)!=0 )
-          oldValue.append("relative, ");
-       if ((f&IRIRelativize.PARENT)!=0)
-          oldValue.append("parent, ");
-       if ((f&IRIRelativize.GRANDPARENT)!=0)
-          oldValue.append("grandparent, ");
-       if (oldValue.length() > 0)
-          oldValue.setLength(oldValue.length()-2);
-          return oldValue.toString();
-       }
-
-       public static int str2flags(String pv){
-       StringTokenizer tkn = new StringTokenizer(pv,", ");
-       int rslt = 0;
-       while ( tkn.hasMoreElements() ) {
-           String flag = tkn.nextToken();
-           if ( flag.equals("same-document") )
-              rslt |= IRIRelativize.SAMEDOCUMENT;
-           else if ( flag.equals("network") )
-              rslt |= IRIRelativize.NETWORK;
-           else if ( flag.equals("absolute") )
-              rslt |= IRIRelativize.ABSOLUTE;
-           else if ( flag.equals("relative") )
-              rslt |= IRIRelativize.CHILD;
-           else if ( flag.equals("parent") )
-              rslt |= IRIRelativize.PARENT;
-           else if ( flag.equals("grandparent") )
-              rslt |= IRIRelativize.GRANDPARENT;
-           else
-
-           logger.warn(
-               "Incorrect property value for relativeURIs: " + flag
-               );
-       }
-       return rslt;
-       }
-
 }
diff --git 
a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures.java 
b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures.java
index 2d80809d8c..4c964df514 100644
--- 
a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures.java
+++ 
b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures.java
@@ -19,12 +19,6 @@
 package org.apache.jena.rdfxml.xmloutput;
 
 import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.regex.Pattern;
 
 import org.apache.jena.graph.*;
 import org.apache.jena.irix.IRIException;
@@ -33,7 +27,6 @@ import org.apache.jena.rdf.model.ModelFactory;
 import org.apache.jena.rdf.model.RDFReaderI;
 import org.apache.jena.rdf.model.RDFWriterI;
 import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler;
-import org.apache.jena.rdf.model.impl.Util;
 import org.apache.jena.rdfxml.xmlinput1.RDFXMLReader;
 import org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter;
 import org.apache.jena.rdfxml.xmloutput.impl.SimpleLogger;
@@ -469,188 +462,4 @@ public class TestXMLFeatures extends XMLOutputTestBase {
        public void testBadProperty1() throws IOException {
                checkPropURI("http://x/a.b/";, null, null, BadPropURI);
        }
-
-       /*
-        * public void testBadProperty2() throws IOException {
-        * checkPropURI("http:/a.b/", "brickley", "http://example.org/b#";,
-        * ExtraTriples); }
-        *
-        */
-       public void testRelativeAPI() {
-        @SuppressWarnings("deprecation")
-               RDFWriterI w = createMemModel().getWriter(lang);
-               String old = (String) w.setProperty("relativeURIs", "");
-               assertEquals("default value check", old,
-                               "same-document, absolute, relative, parent");
-               w.setProperty("relativeURIs", "network, grandparent,relative,  
");
-               w.setProperty("relativeURIs",
-                               "  parent, same-document, network, parent, 
absolute ");
-               // TestLogger tl = new TestLogger(URI.class);
-               blockLogger();
-               w.setProperty("relativeURIs", "foo"); // will get warning
-               assertTrue("A warning should have been generated.", 
unblockLogger());
-       }
-
-       private void relative(String relativeParam, String base,
-                       Collection<String> regexesPresent, Collection<String> 
regexesAbsent)
-                       throws IOException {
-
-               Model m = createMemModel();
-               m.read("file:testing/abbreviated/relative-uris.rdf");
-
-               String contents;
-               try ( ByteArrayOutputStream bos = new ByteArrayOutputStream() ) 
{
-               @SuppressWarnings("deprecation")
-                   RDFWriterI writer = m.getWriter(lang);
-                   writer.setProperty("relativeURIs", relativeParam);
-                   writer.write(m, bos, base);
-               contents = bos.toString(StandardCharsets.UTF_8);
-               }
-
-               try {
-                       Model m2 = createMemModel();
-                       m2.read(new StringReader(contents), base);
-                       assertTrue(m.isIsomorphicWith(m2));
-                       Iterator<String> it = regexesPresent.iterator();
-                       while (it.hasNext()) {
-                               String regexPresent = it.next();
-                               assertTrue("Looking for /" + regexPresent + 
"/", Pattern
-                                               
.compile(Util.substituteStandardEntities(regexPresent),
-                                                               
Pattern.DOTALL).matcher(contents).find()
-                               //
-                               // matcher.contains(
-                               // contents,
-                               // awk.compile(
-                               // 
Util.substituteStandardEntities(regexPresent)))
-                               );
-                       }
-                       it = regexesAbsent.iterator();
-                       while (it.hasNext()) {
-                               String regexAbsent = it.next();
-                               assertTrue(
-                                               "Looking for (not) /" + 
regexAbsent + "/",
-                                               !Pattern.compile("[\"']"+ 
Util.substituteStandardEntities(regexAbsent)+ "[\"']", Pattern.DOTALL)
-                                                               
.matcher(contents).find()
-
-                               // matcher.contains(
-                               // contents,
-                               // awk.compile(
-                               // "[\"']"
-                               // + 
Util.substituteStandardEntities(regexAbsent)
-                               // + "[\"']"))
-                               );
-                       }
-                       contents = null;
-               } finally {
-                       if (contents != null) {
-                               System.err.println("===================");
-                               System.err.println("Offending content - " + 
toString());
-                               System.err.println("===================");
-                               System.err.println(contents);
-                               System.err.println("===================");
-                       }
-               }
-       }
-
-       static String rData1[][] = {
-                       // http://www.example.org/a/b/c/d/
-                       { "", "http://www.example.org/a/b/c/d/";,
-                                       "http://www.example.org/a/b/c/d/e/f/g/";,
-                                       "http://www.example.org/a/b/C/D";,
-                                       "http://www.example.org/A/B#foo/";,
-                                       "http://www.example.org/a/b/c/d/X#bar";,
-                                       "http://example.com/A";,
-                                       
"http://www.example.org/a/b/c/d/z[?]x=a";, },
-                       { "same-document", "", null, null, null, null, null, 
null, },
-                       { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", 
"/a/b/C/D",
-                                       "/A/B#foo/", "/a/b/c/d/X#bar", null, 
"/a/b/c/d/z[?]x=a", },
-                       { "relative", "[.]", "e/f/g/", null, null, "X#bar", 
null,
-                                       "z[?]x=a", },
-                       { "parent", "[.][.]/d/", "[.][.]/d/e/f/g/", null, null,
-                                       "[.][.]/d/X#bar", null, 
"[.][.]/d/z[?]x=a", },
-                       { "network", "//www.example.org/a/b/c/d/",
-                                       "//www.example.org/a/b/c/d/e/f/g/",
-                                       "//www.example.org/a/b/C/D", 
"//www.example.org/A/B#foo/",
-                                       "//www.example.org/a/b/c/d/X#bar", 
"//example.com/A",
-                                       "//www.example.org/a/b/c/d/z[?]x=a", },
-                       { "grandparent", "[.][.]/[.][.]/c/d/", 
"[.][.]/[.][.]/c/d/e/f/g/",
-                                       "[.][.]/[.][.]/C/D", null, 
"[.][.]/[.][.]/c/d/X#bar", null,
-                                       "[.][.]/[.][.]/c/d/z[?]x=a", }, };
-
-       static String rData2[][] = {
-                       // http://www.example.org/a/b/c/d
-                       { "", "http://www.example.org/a/b/c/d/";,
-                                       "http://www.example.org/a/b/c/d/e/f/g/";,
-                                       "http://www.example.org/a/b/C/D";,
-                                       "http://www.example.org/A/B#foo/";,
-                                       "http://www.example.org/a/b/c/d/X#bar";,
-                                       "http://example.com/A";,
-                                       
"http://www.example.org/a/b/c/d/z[?]x=a";, },
-                       { "same-document", null, null, null, null, null, null, 
null, },
-                       { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", 
"/a/b/C/D",
-                                       "/A/B#foo/", "/a/b/c/d/X#bar", null, 
"/a/b/c/d/z[?]x=a", },
-                       { "relative", "d/", "d/e/f/g/", null, null, "d/X#bar", 
null,
-                                       "d/z[?]x=a", },
-                       { "parent", "[.][.]/c/d/", "[.][.]/c/d/e/f/g/", 
"[.][.]/C/D", null,
-                                       "[.][.]/c/d/X#bar", null, 
"[.][.]/c/d/z[?]x=a", },
-                       { "network", "//www.example.org/a/b/c/d/",
-                                       "//www.example.org/a/b/c/d/e/f/g/",
-                                       "//www.example.org/a/b/C/D", 
"//www.example.org/A/B#foo/",
-                                       "//www.example.org/a/b/c/d/X#bar", 
"//example.com/A",
-                                       "//www.example.org/a/b/c/d/z[?]x=a", },
-                       { "grandparent", "[.][.]/[.][.]/b/c/d/",
-                                       "[.][.]/[.][.]/b/c/d/e/f/g/", 
"[.][.]/[.][.]/b/C/D", null,
-                                       "[.][.]/[.][.]/b/c/d/X#bar", null,
-                                       "[.][.]/[.][.]/b/c/d/z[?]x=a", }, };
-
-       static String rData3[][] = {
-                       // http://www.example.org/A/B#
-                       { "", "http://www.example.org/a/b/c/d/";,
-                                       "http://www.example.org/a/b/c/d/e/f/g/";,
-                                       "http://www.example.org/a/b/C/D";,
-                                       "http://www.example.org/A/B#foo/";,
-                                       "http://www.example.org/a/b/c/d/X#bar";,
-                                       "http://example.com/A";,
-                                       
"http://www.example.org/a/b/c/d/z[?]x=a";, },
-                       { "same-document", null, null, null, "#foo/", null, 
null, null, },
-                       { "absolute", "/a/b/c/d/", "/a/b/c/d/e/f/g/", 
"/a/b/C/D",
-                                       "/A/B#foo/", "/a/b/c/d/X#bar", null, 
"/a/b/c/d/z[?]x=a", },
-                       { "relative", null, null, null, "B#foo/", null, null, 
null, },
-                       { "parent", "[.][.]/a/b/c/d/", "[.][.]/a/b/c/d/e/f/g/",
-                                       "[.][.]/a/b/C/D", "[.][.]/A/B#foo/",
-                                       "[.][.]/a/b/c/d/X#bar", null, 
"[.][.]/a/b/c/d/z[?]x=a", },
-                       { "network", "//www.example.org/a/b/c/d/",
-                                       "//www.example.org/a/b/c/d/e/f/g/",
-                                       "//www.example.org/a/b/C/D", 
"//www.example.org/A/B#foo/",
-                                       "//www.example.org/a/b/c/d/X#bar", 
"//example.com/A",
-                                       "//www.example.org/a/b/c/d/z[?]x=a", },
-                       { "grandparent", null, null, null, null, null, null, 
null, }, };
-
-       private void relative(int i, String base, String d[][]) throws 
IOException {
-               Set<String> in = new HashSet<>();
-               Set<String> out = new HashSet<>();
-               for (int j = 1; j < d[i].length; j++) {
-
-                       in.add(d[i][j] == null ? d[0][j] : d[i][j]);
-                       if (i != 0 && d[i][j] != null)
-                               out.add(d[0][j]);
-               }
-               // System.out.println(base + "["+i+"]");
-               relative(d[i][0], base, in, out);
-       }
-
-       public void testRelative() throws Exception {
-               for (int i = 0; i < 7; i++) {
-                       relative(i, "http://www.example.org/a/b/c/d/";, rData1);
-                       relative(i, "http://www.example.org/a/b/c/d";, rData2);
-                       relative(i, "http://www.example.org/A/B#";, rData3);
-               }
-       }
-
-       private static String uris[] = { "http://www.example.org/a/b/c/d/";,
-                       "http://www.example.org/a/b/c/d/e/f/g/";,
-                       "http://www.example.org/a/b/C/D";,
-                       "http://www.example.org/A/B#foo/";,
-                       "http://www.example.org/a/b/c/d/X#bar";, 
"http://example.com/A";,
-                       "http://www.example.org/a/b/c/d/z?x=a";, };
 }

Reply via email to