GH-2387: Stop using Util.splitNamespaceXML. Reformat code.
diff --git a/jena-core/src/main/java/org/apache/jena/graph/Node_URI.java b/jena-core/src/main/java/org/apache/jena/graph/Node_URI.java
index 2f5c2c6..34c6ff1 100644
--- a/jena-core/src/main/java/org/apache/jena/graph/Node_URI.java
+++ b/jena-core/src/main/java/org/apache/jena/graph/Node_URI.java
@@ -20,8 +20,8 @@
import java.util.Objects;
-import org.apache.jena.rdf.model.impl.Util ;
-import org.apache.jena.shared.* ;
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.util.SplitIRI;
/**
RDF nodes with a global identity given by a URI.
@@ -73,12 +73,12 @@
@Override
public String getNameSpace() {
- return uriStr.substring(0, Util.splitNamespaceXML(uriStr));
+ return uriStr.substring(0, SplitIRI.splitXML(uriStr));
}
@Override
public String getLocalName() {
- return uriStr.substring(Util.splitNamespaceXML(uriStr));
+ return uriStr.substring(SplitIRI.splitXML(uriStr));
}
@Override
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
index 9de0851..7d5602d 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
@@ -18,6 +18,8 @@
package org.apache.jena.rdf.model.impl;
+import static org.apache.jena.shared.impl.PrefixMappingImpl.isNiceURI;
+
import java.io.*;
import java.net.URL;
import java.util.*;
@@ -35,9 +37,9 @@
import org.apache.jena.rdf.model.* ;
import org.apache.jena.shared.* ;
import org.apache.jena.shared.impl.JenaParameters;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
import org.apache.jena.sys.JenaSystem ;
import org.apache.jena.util.CollectionFactory ;
+import org.apache.jena.util.SplitIRI;
import org.apache.jena.util.iterator.ClosableIterator;
import org.apache.jena.util.iterator.ExtendedIterator;
import org.apache.jena.util.iterator.FilterIterator;
@@ -830,7 +832,7 @@
Node node = it.next();
if ( node.isURI() ) {
String uri = node.getURI();
- String ns = uri.substring(0, Util.splitNamespaceXML(uri));
+ String ns = uri.substring(0, SplitIRI.splitXML(uri));
// String ns = IteratorFactory.asResource( node, this
// ).getNameSpace();
set.add(ns);
@@ -953,9 +955,10 @@
Set<String> values = e.getValue();
Set<String> niceValues = CollectionFactory.createHashedSet();
for ( String uri : values ) {
- if ( PrefixMappingImpl.isNiceURI(uri) ) {
+ @SuppressWarnings("deprecation")
+ boolean b = isNiceURI(uri);
+ if ( b )
niceValues.add(uri);
- }
}
if ( niceValues.size() == 1 ) {
pm.setNsPrefix(key, niceValues.iterator().next());
diff --git a/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput0/JenaHandler.java b/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput0/JenaHandler.java
index 716a09a..feafcec 100644
--- a/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput0/JenaHandler.java
+++ b/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput0/JenaHandler.java
@@ -40,7 +40,7 @@
public JenaHandler( Graph g, Model m, RDFErrorHandler e )
{ this( g, modelToPrefixMapping( m ), e ); }
-
+
private JenaHandler( Graph graph, RDFErrorHandler e )
{ this( graph, graph.getPrefixMapping(), e ); }
@@ -48,13 +48,13 @@
{
super( errorHandler );
this.graph = graph ;
- this.prefixMapping = prefixMapping;
+ this.prefixMapping = prefixMapping;
}
-
+
private static PrefixMapping modelToPrefixMapping( Model model )
{
- return model == null
- ? PrefixMapping.Factory.create()
+ return model == null
+ ? PrefixMapping.Factory.create()
: model.getGraph().getPrefixMapping()
;
}
@@ -93,6 +93,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
public void startPrefixMapping( String prefix, String uri )
{
if (PrefixMappingImpl.isNiceURI( uri )) prefixMapping.setNsPrefix( prefix, uri );
diff --git a/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput1/JenaHandler.java b/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput1/JenaHandler.java
index 156a7b1..dd16ff8 100644
--- a/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput1/JenaHandler.java
+++ b/jena-core/src/main/java/org/apache/jena/rdfxml/xmlinput1/JenaHandler.java
@@ -90,6 +90,7 @@
}
@Override
+ @SuppressWarnings("deprecation")
public void startPrefixMapping(String prefix, String uri) {
if ( PrefixMappingImpl.isNiceURI(uri) )
prefixMapping.setNsPrefix(prefix, uri);
diff --git a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/RDFXMLWriterI.java b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/RDFXMLWriterI.java
index 15e6937..164dc5a 100644
--- a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/RDFXMLWriterI.java
+++ b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/RDFXMLWriterI.java
@@ -28,8 +28,6 @@
* set on RDF/XML and RDF/XML-ABBREV writers.
*/
public interface RDFXMLWriterI extends RDFWriterI {
- /** Suppress a compiler warning. */
- Object _NotInteresting = RDFSyntax.parseCollection;
/** Sets properties on this writer.
@@ -217,9 +215,6 @@
* @return the old value for this property, or <code>null</code>
* if no value was set.
*/
- @Override
-Object setProperty(
- String propName,
- Object propValue);
-
+ @Override
+ Object setProperty(String propName, Object propValue);
}
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 a4f054b..f3c90e3 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
@@ -39,6 +39,7 @@
import org.apache.jena.shared.* ;
import org.apache.jena.util.CharEncoding ;
import org.apache.jena.util.FileUtils ;
+import org.apache.jena.util.SplitIRI;
import org.apache.jena.util.XMLChar;
import org.apache.jena.vocabulary.* ;
import org.slf4j.Logger ;
@@ -101,7 +102,18 @@
abstract protected void writeBody
( Model mdl, PrintWriter pw, String baseUri, boolean inclXMLBase );
- static private Set<String> badRDF = new HashSet<>();
+ static private Set<String> badRDF = Set.of("RDF",
+ "Description",
+ "li",
+ "about",
+ "aboutEach",
+ "aboutEachPrefix",
+ "ID",
+ "nodeID",
+ "parseType",
+ "datatype",
+ "bagID",
+ "resource");
/**
Counter used for allocating Jena transient namespace declarations.
@@ -111,25 +123,7 @@
static String RDFNS = RDF.getURI();
- static private Pattern jenaNamespace;
-
- static {
- jenaNamespace =
- Pattern.compile("j\\.([1-9][0-9]*|cook\\.up)");
-
- badRDF.add("RDF");
- badRDF.add("Description");
- badRDF.add("li");
- badRDF.add("about");
- badRDF.add("aboutEach");
- badRDF.add("aboutEachPrefix");
- badRDF.add("ID");
- badRDF.add("nodeID");
- badRDF.add("parseType");
- badRDF.add("datatype");
- badRDF.add("bagID");
- badRDF.add("resource");
- }
+ static private final Pattern jenaNamespace = Pattern.compile("j\\.([1-9][0-9]*|cook\\.up)");
String xmlBase = null;
@@ -222,36 +216,30 @@
while (nsIter.hasNext()) this.addNameSpace( nsIter.nextNs() );
}
- private void primeNamespace( Model model )
- {
+ private void primeNamespace(Model model) {
Map<String, String> m = model.getNsPrefixMap();
- for ( Entry<String, String> e : m.entrySet() )
- {
+ for ( Entry<String, String> e : m.entrySet() ) {
String value = e.getValue();
- String already = this.getPrefixFor( value );
- if ( already == null )
- {
- this.setNsPrefix( model.getNsURIPrefix( value ), value );
- if ( writingAllModelPrefixNamespaces )
- {
- this.addNameSpace( value );
+ String already = this.getPrefixFor(value);
+ if ( already == null ) {
+ this.setNsPrefix(model.getNsURIPrefix(value), value);
+ if ( writingAllModelPrefixNamespaces ) {
+ this.addNameSpace(value);
}
}
}
- if ( usesPrefix(model, "") )
- {
- // Doing "" prefix. Ensure it is a non-clashing, non-empty entity name.
- String entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME ;
+ if ( usesPrefix(model, "") ) {
+ // Doing "" prefix. Ensure it is a non-clashing, non-empty entity name.
+ String entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME;
if ( usesPrefix(model, entityForEmptyPrefix) )
- entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME_ALT ;
- int i = 0 ;
- while ( usesPrefix(model,entityForEmptyPrefix) )
- {
- entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME_ALT+"."+i ;
- i++ ;
+ entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME_ALT;
+ int i = 0;
+ while (usesPrefix(model, entityForEmptyPrefix)) {
+ entityForEmptyPrefix = DEFAULT_NS_ENTITY_NAME_ALT + "." + i;
+ i++;
}
- defaultNSEntityName = entityForEmptyPrefix ;
+ defaultNSEntityName = entityForEmptyPrefix;
}
}
@@ -287,40 +275,34 @@
}
private void setFromGivenNamespaces( Map<String, String> ns, Set<String> prefixesUsed ) {
- for ( String uri : namespacesNeeded )
- {
- if ( ns.containsKey( uri ) )
- {
+ for ( String uri : namespacesNeeded ) {
+ if ( ns.containsKey(uri) ) {
continue;
}
String val = null;
- Set<String> s = nameSpaces.forward( uri );
- if ( s != null )
- {
+ Set<String> s = nameSpaces.forward(uri);
+ if ( s != null ) {
Iterator<String> it2 = s.iterator();
- if ( it2.hasNext() )
- {
+ if ( it2.hasNext() ) {
val = it2.next();
}
- if ( prefixesUsed.contains( val ) )
- {
+ if ( prefixesUsed.contains(val) ) {
val = null;
}
}
- if ( val == null )
- {
- // just in case the prefix has already been used, look for a free one.
- // (the usual source of such prefixes is reading in a model we wrote out earlier)
- do
- {
- val = "j." + ( jenaPrefixCount++ );
- }
- while ( prefixesUsed.contains( val ) );
+ if ( val == null ) {
+ // just in case the prefix has already been used, look for a free
+ // one.
+ // (the usual source of such prefixes is reading in a model we wrote
+ // out earlier)
+ do {
+ val = "j." + (jenaPrefixCount++);
+ } while (prefixesUsed.contains(val));
}
- ns.put( uri, val );
- prefixesUsed.add( val );
+ ns.put(uri, val);
+ prefixesUsed.add(val);
}
- }
+ }
final synchronized public void setNsPrefix(String prefix, String ns) {
if (checkLegalPrefix(prefix)) {
@@ -328,15 +310,14 @@
}
}
- final public String getPrefixFor( String uri )
- {
+ final public String getPrefixFor( String uri ) {
// xml and xmlns namespaces are pre-bound
if ("http://www.w3.org/XML/1998/namespace".equals(uri)) return "xml";
if ("http://www.w3.org/2000/xmlns/".equals(uri)) return "xmlns";
Set<String> s = nameSpaces.backward( uri );
if (s != null && s.size() == 1) return s.iterator().next();
return null;
- }
+ }
String xmlnsDecl() {
workOutNamespaces();
@@ -392,13 +373,12 @@
}
String splitTag(String uriref, int type) {
- int split = Util.splitNamespaceXML( uriref );
+ int split = SplitIRI.splitXML( uriref );
if (split == uriref.length()) throw new InvalidPropertyURIException( uriref );
return tag( uriref.substring( 0, split ), uriref.substring( split ), type, true );
}
- String tag( String namespace, String local, int type, boolean localIsQname) {
- String prefix = ns.get( namespace );
+ String tag( String namespace, String local, int type, boolean localIsQname) {
if (type != FAST && type != FASTATTR) {
if ((!localIsQname) && !XMLChar.isValidNCName(local))
return splitTag(namespace + local, type);
@@ -411,14 +391,12 @@
}
}
}
+ String prefix = ns.get( namespace );
boolean cookUp = false;
if (prefix == null) {
checkURI( namespace );
- logger.warn(
- "Internal error: unexpected QName URI: <"
- + namespace
- + ">. Fixing up with j.cook.up code.",
- new BrokenException( "unexpected QName URI " + namespace ));
+ logger.warn("Internal error: unexpected QName URI: <" + namespace + ">. Fixing up.",
+ new BrokenException( "unexpected QName URI " + namespace ));
cookUp = true;
} else if (prefix.length() == 0) {
if (type == ATTR || type == FASTATTR)
@@ -430,8 +408,7 @@
return prefix + ":" + local;
}
- private String cookUpAttribution( int type, String namespace, String local )
- {
+ private String cookUpAttribution( int type, String namespace, String local ) {
String prefix = "j.cook.up";
switch (type) {
case FASTATTR :
@@ -445,8 +422,8 @@
case FAST :
// logger.error("Unreachable code - reached.");
throw new BrokenException( "cookup reached final FAST" );
- }
}
+ }
/** Write out an XML serialization of a model.
* @param model the model to be serialized
@@ -455,37 +432,36 @@
*/
@Override
final public void write(Model model, OutputStream out, String base)
- { write( model, FileUtils.asUTF8(out), base ); }
+ { write( model, FileUtils.asUTF8(out), base ); }
/** Serialize Model <code>model</code> to Writer <code>out</code>.
* @param model The model to be written.
* @param out The Writer to which the serialization should be sent.
* @param base the base URI for relative URI calculations. <code>null</code> means use only absolute URI's.
*/
- @Override
- synchronized public void write(Model model, Writer out, String base)
- {
- setupNamespaces( model );
- PrintWriter pw = out instanceof PrintWriter ? (PrintWriter) out : new PrintWriter( out );
- if (!Boolean.FALSE.equals(showXmlDeclaration)) writeXMLDeclaration( out, pw );
- writeXMLBody( model, pw, base );
- pw.flush();
- }
+ @Override
+ synchronized public void write(Model model, Writer out, String base) {
+ setupNamespaces(model);
+ PrintWriter pw = out instanceof PrintWriter ? (PrintWriter)out : new PrintWriter(out);
+ if ( !Boolean.FALSE.equals(showXmlDeclaration) )
+ writeXMLDeclaration(out, pw);
+ writeXMLBody(model, pw, base);
+ pw.flush();
+ }
/**
@param baseModel
@param model
*/
- private void setupNamespaces( Model model )
- {
+ private void setupNamespaces(Model model) {
this.namespacesNeeded = new HashSet<>();
this.ns = null;
this.modelPrefixMapping = model;
- primeNamespace( model );
- addNameSpace( RDF.getURI() );
+ primeNamespace(model);
+ addNameSpace(RDF.getURI());
addNameSpaces(model);
jenaPrefixCount = 0;
- }
+ }
private void writeXMLBody( Model model, PrintWriter pw, String base ) {
if (showDoctypeDeclaration.booleanValue())
@@ -503,63 +479,55 @@
protected static final Pattern predefinedEntityNames = Pattern.compile( "amp|lt|gt|apos|quot" );
public boolean isPredefinedEntityName( String name )
- { return predefinedEntityNames.matcher( name ).matches(); }
+ { return predefinedEntityNames.matcher( name ).matches(); }
private String attributeQuoteChar ="\"";
protected String attributeQuoted( String s )
- { return attributeQuoteChar + s + attributeQuoteChar; }
+ { return attributeQuoteChar + s + attributeQuoteChar; }
- protected String substitutedAttribute( String s )
- {
+ protected String substitutedAttribute( String s ) {
String substituted = Util.substituteStandardEntities( s );
if (!showDoctypeDeclaration.booleanValue())
return attributeQuoted( substituted );
- else
- {
- int split = Util.splitNamespaceXML( substituted );
+ else {
+ int split = SplitIRI.splitXML( substituted );
String namespace = substituted.substring( 0, split );
String prefix = modelPrefixMapping.getNsURIPrefix( namespace );
return prefix == null || isPredefinedEntityName( prefix )
? attributeQuoted( substituted )
: attributeQuoted( "&" + strForPrefix(prefix) + ";" + substituted.substring( split ) )
;
- }
}
+ }
- private void generateDoctypeDeclaration( Model model, PrintWriter pw )
- {
+ private void generateDoctypeDeclaration( Model model, PrintWriter pw ) {
String rdfns = RDF.getURI();
- String rdfRDF = model.qnameFor( rdfns + "RDF" );
+ String rdfRDF = model.qnameFor( rdfns + "RDF" );
if ( rdfRDF == null ) {
- model.setNsPrefix("rdf",rdfns);
- rdfRDF = "rdf:RDF";
+ model.setNsPrefix("rdf",rdfns);
+ rdfRDF = "rdf:RDF";
}
Map<String, String> prefixes = model.getNsPrefixMap();
pw.print( "<!DOCTYPE " + rdfRDF +" [" );
- for ( String prefix : prefixes.keySet() )
- {
- if ( isPredefinedEntityName( prefix ) )
- {
- continue;
- }
- pw.print(
- newline + " <!ENTITY " + strForPrefix( prefix ) + " '" + Util.substituteEntitiesInEntityValue(
- prefixes.get( prefix ) ) + "'>" );
- }
- pw.print( "]>" + newline );
+ for ( String prefix : prefixes.keySet() ) {
+ if ( isPredefinedEntityName( prefix ) )
+ continue;
+ pw.print(newline
+ + " <!ENTITY " + strForPrefix( prefix ) + " '" + Util.substituteEntitiesInEntityValue(prefixes.get( prefix ) )
+ + "'>" );
}
-
- private String strForPrefix(String prefix)
- {
- if ( prefix.length() == 0 )
- return defaultNSEntityName ;
- return prefix ;
+ pw.print( "]>" + newline );
}
- private static boolean usesPrefix(Model model, String prefix)
- {
- return model.getNsPrefixURI(prefix) != null ;
+ private String strForPrefix(String prefix) {
+ if ( prefix.length() == 0 )
+ return defaultNSEntityName;
+ return prefix;
+ }
+
+ private static boolean usesPrefix(Model model, String prefix) {
+ return model.getNsPrefixURI(prefix) != null;
}
private void writeXMLDeclaration(Writer out, PrintWriter pw) {
@@ -711,19 +679,17 @@
return result;
}
- private String setShowDoctypeDeclaration( Object propValue )
- {
+ private String setShowDoctypeDeclaration(Object propValue) {
String oldValue = showDoctypeDeclaration.toString();
showDoctypeDeclaration = getBooleanValue( propValue, Boolean.FALSE );
return oldValue;
}
- private String setShowXmlDeclaration( Object propValue )
- {
+ private String setShowXmlDeclaration( Object propValue ) {
String oldValue = showXmlDeclaration == null ? null : showXmlDeclaration.toString();
showXmlDeclaration = getBooleanValue( propValue, null );
return oldValue;
- }
+ }
/**
Answer the boolean value corresponding to o, which must either be a Boolean,
@@ -732,8 +698,7 @@
static private boolean getBoolean( Object o )
{ return getBooleanValue( o, Boolean.FALSE ).booleanValue(); }
- private static Boolean getBooleanValue( Object propValue, Boolean theDefault )
- {
+ private static Boolean getBooleanValue( Object propValue, Boolean theDefault ) {
if (propValue == null)
return theDefault;
else if (propValue instanceof Boolean)
@@ -742,15 +707,14 @@
return stringToBoolean( (String) propValue, theDefault );
else
throw new JenaException( "cannot treat as boolean: " + propValue );
- }
+ }
- private static Boolean stringToBoolean( String b, Boolean theDefault )
- {
+ private static Boolean stringToBoolean( String b, Boolean theDefault ) {
if (b.equals( "default" )) return theDefault;
if (b.equalsIgnoreCase( "true" )) return Boolean.TRUE;
if (b.equalsIgnoreCase( "false" )) return Boolean.FALSE;
throw new BadBooleanException( b );
- }
+ }
Resource[] setTypes( Resource x[] ) {
logger.warn( "prettyTypes is not a property on the Basic RDF/XML writer." );
diff --git a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/RDFXML_Basic.java b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/RDFXML_Basic.java
index 14385c1..a6b85da 100644
--- a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/RDFXML_Basic.java
+++ b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/RDFXML_Basic.java
@@ -106,9 +106,7 @@
writeLiteral((Literal) object, writer);
writer.println(
"</"
- + endElementTag(
- predicate.getNameSpace(),
- predicate.getLocalName())
+ + endElementTag(predicate.getNameSpace(), predicate.getLocalName())
+ ">");
}
}
diff --git a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/Unparser.java b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/Unparser.java
index 0b2b71e..50722fc 100644
--- a/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/Unparser.java
+++ b/jena-core/src/main/java/org/apache/jena/rdfxml/xmloutput/impl/Unparser.java
@@ -127,6 +127,7 @@
import org.apache.jena.shared.BrokenException ;
import org.apache.jena.shared.JenaException ;
import org.apache.jena.shared.PropertyNotFoundException ;
+import org.apache.jena.util.SplitIRI;
import org.apache.jena.util.XMLChar;
import org.apache.jena.util.iterator.* ;
import org.apache.jena.vocabulary.RDF ;
@@ -1178,9 +1179,8 @@
throw new BrokenException("Internal error: getNameSpace(bNode)");
}
String uri = r.getURI();
- int split = Util.splitNamespaceXML(uri);
+ int split = SplitIRI.splitXML(uri);
return uri.substring(0, split);
-
}
/**
@@ -1215,7 +1215,7 @@
throw new BrokenException("Internal error: getLocalName(bNode)");
}
String uri = r.getURI();
- int split = Util.splitNamespaceXML(uri);
+ int split = SplitIRI.splitXML(uri);
return uri.substring(split);
}
@@ -1497,10 +1497,9 @@
// Only allow resources with namespace and fragment ID
String uri = ((Resource) n).getURI();
- int split = Util.splitNamespaceXML(uri);
+ int split = SplitIRI.splitXML(uri);
if (split == 0 || split == uri.length())
return -1;
-
return split;
}
diff --git a/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java b/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
index 4819812..7ec8555 100644
--- a/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
+++ b/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
@@ -24,9 +24,9 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.jena.rdf.model.impl.Util ;
import org.apache.jena.shared.PrefixMapping ;
import org.apache.jena.util.CollectionFactory ;
+import org.apache.jena.util.SplitIRI;
import org.apache.jena.util.XMLChar;
/**
@@ -126,9 +126,10 @@
}
/**
- * Test whether a URI is "nice" for RDF/XML (ends in a non NCName character).
+ * Test whether a URI is "nice" for RDF/XML (ends in a non-NCName character).
+ * @deprecated To be removed.
*/
-
+ @Deprecated
public static boolean isNiceURI(String uri) {
if ( uri.equals("") )
return false;
@@ -226,28 +227,25 @@
* Relies on <code>splitNamespace</code> to carve uri into namespace and
* localname components; this ensures that the localname is legal and we just
* have to (reverse-)lookup the namespace in the prefix table.
- *
- * @see org.apache.jena.shared.PrefixMapping#qnameFor(java.lang.String)
*/
@Override
public String qnameFor(String uri) {
- int split = Util.splitNamespaceXML(uri);
- String ns = uri.substring(0, split), local = uri.substring(split);
- if ( local.equals("") )
+ int split = SplitIRI.splitXML(uri);
+ if ( split == uri.length() )
return null;
+ String ns = uri.substring(0, split);
+ String local = uri.substring(split);
String prefix = URItoPrefix.get(ns);
return prefix == null ? null : prefix + ":" + local;
}
/**
- * Compress the URI using the prefix mapping. This version of the code looks
- * through all the maplets and checks each candidate prefix URI for being a
- * leading substring of the argument URI. There's probably a much more efficient
- * algorithm available, preprocessing the prefix strings into some kind of search
- * table, but for the moment we don't need it.
+ * Compress the URI using the prefix mapping.
*/
@Override
public String shortForm(String uri) {
+ // This version of the code looks through all the maplets and checks each
+ // candidate prefix URI for being a leading substring of the argument URI.
Entry<String, String> e = findMapping(uri, true);
return e == null ? uri : e.getKey() + ":" + uri.substring((e.getValue()).length());
}
diff --git a/jena-core/src/test/java/org/apache/jena/graph/test/TestNode.java b/jena-core/src/test/java/org/apache/jena/graph/test/TestNode.java
index a26adaa..554fc1b 100644
--- a/jena-core/src/test/java/org/apache/jena/graph/test/TestNode.java
+++ b/jena-core/src/test/java/org/apache/jena/graph/test/TestNode.java
@@ -20,7 +20,6 @@
import junit.framework.TestSuite ;
-
import org.apache.jena.atlas.lib.Creator;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.TypeMapper ;
@@ -28,9 +27,9 @@
import org.apache.jena.graph.* ;
import org.apache.jena.graph.impl.LiteralLabel ;
import org.apache.jena.graph.impl.LiteralLabelFactory ;
-import org.apache.jena.rdf.model.impl.Util ;
import org.apache.jena.shared.JenaException ;
import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.util.SplitIRI;
import org.apache.jena.vocabulary.* ;
/**
@@ -714,7 +713,7 @@
{
for ( String uri : someURIs )
{
- int split = Util.splitNamespaceXML( uri );
+ int split = SplitIRI.splitXML( uri );
Node n = NodeCreateUtils.create( uri );
assertEquals( "check namespace", uri.substring( 0, split ), n.getNameSpace() );
assertEquals( "check localname", uri.substring( split ), n.getLocalName() );
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
index a00b919..525d43a 100644
--- a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
+++ b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
@@ -18,10 +18,11 @@
package org.apache.jena.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import junit.framework.JUnit4TestAdapter;
-import org.apache.jena.rdf.model.impl.Util ;
import org.junit.Test;
-import static org.junit.Assert.*;
/**
* Tests of splitting with RDF/XML rules, where the local name is more restricted
@@ -33,110 +34,108 @@
public class TestSplitIRI_XML
{
public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(TestSplitIRI_XML.class) ;
+ return new JUnit4TestAdapter(TestSplitIRI_XML.class);
}
@Test public void splitNS_01()
- { split("http://example/xyz", "http://example/", "xyz") ; }
+ { split("http://example/xyz", "http://example/", "xyz"); }
@Test public void splitNS_02()
- { split("http://example/ns#xyz", "http://example/ns#", "xyz") ; }
+ { split("http://example/ns#xyz", "http://example/ns#", "xyz"); }
@Test public void splitNS_03()
- { no_split("http://example/ns#") ; }
+ { no_split("http://example/ns#"); }
@Test public void splitNS_04()
- { no_split("http://example/") ; }
+ { no_split("http://example/"); }
@Test public void splitNS_05() // Illegal URI
- { split("http://example", "http://", "example") ; }
+ { split("http://example", "http://", "example"); }
@Test public void splitNS_06() // localname must be at least the NCStartChar - not empty
- { split("mailto:me", "mailto:m", "e") ; }
+ { split("mailto:me", "mailto:m", "e"); }
@Test public void splitNS_07()
- { split("urn:abc:xyz","urn:abc:", "xyz") ; }
+ { split("urn:abc:xyz","urn:abc:", "xyz"); }
@Test public void splitNS_08()
- { no_split("urn:abc:xyz:") ; }
+ { no_split("urn:abc:xyz:"); }
@Test public void splitNS_09()
- { split("http://bio2rdf.org/pdb:Pentane-3%2C4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3%2C4-", "diol-5-phosphate") ; }
+ { split("http://bio2rdf.org/pdb:Pentane-3%2C4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3%2C4-", "diol-5-phosphate"); }
@Test public void splitNS_10()
- { split("http://bio2rdf.org/pdb:Pentane-3,4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3,4-", "diol-5-phosphate") ; }
+ { split("http://bio2rdf.org/pdb:Pentane-3,4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3,4-", "diol-5-phosphate"); }
// Don't split inside a %encoding.
@Test public void splitNS_11()
- { split("http://host/abc%AAdef", "http://host/abc%AA", "def") ; }
+ { split("http://host/abc%AAdef", "http://host/abc%AA", "def"); }
@Test public void splitNS_12()
- { split("http://host/abc%1Adef", "http://host/abc%1A", "def") ; }
+ { split("http://host/abc%1Adef", "http://host/abc%1A", "def"); }
@Test public void splitNS_13()
- { split("http://host/abc%A1def", "http://host/abc%A1", "def") ; }
+ { split("http://host/abc%A1def", "http://host/abc%A1", "def"); }
@Test public void splitNS_14()
- { split("http://host/abc%AA22def", "http://host/abc%AA22", "def") ; }
+ { split("http://host/abc%AA22def", "http://host/abc%AA22", "def"); }
@Test public void splitNS_15()
- { no_split("http://host/abc%AA22") ; }
+ { no_split("http://host/abc%AA22"); }
// Other schemes
@Test public void splitNS_50()
- { split("file:///x/y", "file:///x/", "y") ; }
+ { split("file:///x/y", "file:///x/", "y"); }
@Test public void splitNS_51()
- { split("file:///x", "file:///", "x") ; }
+ { split("file:///x", "file:///", "x"); }
@Test public void splitNS_52()
- { split("file:x", "file:", "x") ; }
+ { split("file:x", "file:", "x"); }
@Test public void splitNS_53()
// Not ideal but some URI schemes dislike a URI with just the scheme
- { split("file:foo", "file:", "foo") ; }
+ { split("file:foo", "file:", "foo"); }
@Test public void splitNS_54()
- { split("file:c:/foo", "file:c:/", "foo") ; }
+ { split("file:c:/foo", "file:c:/", "foo"); }
// urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449 - legal type 1 uuid as urn
// uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0 - legal type 4 uuid as uri
@Test public void splitNS_55()
- { split("urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449", "urn:uuid:", "d871c7f4-2926-11b2-8073-a5e169788449") ; }
+ { split("urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449", "urn:uuid:", "d871c7f4-2926-11b2-8073-a5e169788449"); }
@Test public void splitNS_56()
- { split("uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0", "uuid:3", "cf3e43a-3a5d-40d8-a93c-8697b162a1c0") ; }
+ { split("uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0", "uuid:3", "cf3e43a-3a5d-40d8-a93c-8697b162a1c0"); }
@Test public void splitNS_57()
- { split("urn:abc:def", "urn:abc:", "def") ; }
+ { split("urn:abc:def", "urn:abc:", "def"); }
// --------
static void no_split(String string)
- { split(string, null, null) ; }
+ { split(string, null, null); }
- static void split(String uriStr, String namespace, String localname)
- {
+ static void split(String uriStr, String namespace, String localname) {
if ( namespace == null && localname != null )
- fail("Bad test - namespace is null but local name is not") ;
+ fail("Bad test - namespace is null but local name is not");
if ( namespace != null && localname == null )
- fail("Bad test - namespace is not null but local name is") ;
+ fail("Bad test - namespace is not null but local name is");
- int idx = Util.splitNamespaceXML(uriStr) ;
- if ( idx == uriStr.length() )
- {
+ int idx = SplitIRI.splitXML(uriStr);
+ if ( idx == uriStr.length() ) {
// No split.
if ( namespace != null )
- fail("Expected a split ("+namespace+","+localname+") - but none found") ;
- return ;
+ fail("Expected a split (" + namespace + "," + localname + ") - but none found");
+ return;
}
// Split
- String ns = uriStr.substring(0,idx) ;
- String ln = uriStr.substring(idx) ;
- assertEquals(namespace, ns) ;
- assertEquals(localname, ln) ;
+ String ns = uriStr.substring(0, idx);
+ String ln = uriStr.substring(idx);
+ assertEquals(namespace, ns);
+ assertEquals(localname, ln);
}
}