Skip to content

Commit

Permalink
apacheGH-1773: Convert xmlinput to use IRIx
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Mar 2, 2023
1 parent ca703d9 commit febf8f6
Show file tree
Hide file tree
Showing 1,899 changed files with 132,539 additions and 1,368 deletions.
1 change: 1 addition & 0 deletions build-files/rat-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ archive.md
**/src/test/files/**/*
**/src/test/resources/**/*
**/testing/**/*
jena-core/testing0/**

## Databases
**/DB/**/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.Reader ;
import java.util.Map;

import org.apache.jena.JenaRuntime;
import org.apache.jena.atlas.lib.Pair ;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.atlas.web.ContentType;
Expand All @@ -33,7 +32,6 @@
import org.apache.jena.graph.NodeFactory ;
import org.apache.jena.graph.Triple ;
import org.apache.jena.irix.IRIs;
import org.apache.jena.irix.SetupJenaIRI;
import org.apache.jena.rdf.model.RDFErrorHandler ;
import org.apache.jena.rdfxml.xmlinput.* ;
import org.apache.jena.rdfxml.xmlinput.impl.ARPSaxErrorHandler ;
Expand Down Expand Up @@ -98,7 +96,7 @@ public void read(Reader reader, String baseURI, ContentType ct, StreamRDF output
// RDF 1.0 (and RDF/XML) was based on "RDF URI References" which did allow spaces.

// Use with TDB requires this to be "true" - it is set by InitTDB.
public static boolean RiotUniformCompatibility = false ;
public static boolean RiotUniformCompatibility = true ;
// Warnings in ARP that should be errors to be compatible with
// non-XML-based languages. e.g. language tags should be
// syntactically valid.
Expand Down Expand Up @@ -162,9 +160,6 @@ public void parse() {
arpOptions.setErrorMode(code, ARPErrorNumbers.EM_ERROR) ;
}

if ( JenaRuntime.isRDF11 )
arp.getOptions().setIRIFactory(SetupJenaIRI.iriFactory_RDFXML());

if ( context != null ) {
Map<String, Object> properties = null;
try {
Expand Down Expand Up @@ -201,8 +196,8 @@ public void parse() {
private static String baseURI_RDFXML(String baseIRI) {
if ( baseIRI == null )
return IRIs.getBaseStr();
else
return IRIs.toBase(baseIRI) ;
// RDFParserBuidler resolved the baseIRI
return baseIRI;
}

private static class HandlerSink extends ARPSaxErrorHandler implements StatementHandler, NamespaceHandler {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ private IRIx internalMakeIRI(String uriStr, long line, long col) {
}

private void doChecking(IRIx irix, String uriStr, long line, long col) {
// Should become ...
// irix.handleViolations((isError, message)->{
// if ( isError )
// errorHandler.error(message, line, col);
// });

IRI iri;
if ( irix instanceof IRIProviderJenaIRI.IRIxJena )
iri = (IRI)irix.getImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.jena.datatypes.xsd.XSDDatatype ;
import org.apache.jena.graph.Node ;
import org.apache.jena.graph.NodeFactory ;
import org.apache.jena.iri.IRI ;
import org.apache.jena.irix.IRIx;
import org.apache.jena.rdf.model.impl.Util;
import org.apache.jena.sparql.expr.ExprEvalException ;
import org.apache.jena.sparql.expr.NodeValue ;
Expand All @@ -40,8 +40,12 @@
*/
public class NodeUtils
{
/** IRI to Node */
public static Node asNode(IRI iri) {
/**
* IRI to Node
* @deprecated Do not use org.apache.jena.iri.IRI. Use {@link IRIx}.
*/
@Deprecated
public static Node asNode(org.apache.jena.iri.IRI iri) {
return NodeFactory.createURI(iri.toString()) ;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@
* by use of <code>rdf:parsetype='literal'</code>.
*/
public class XMLLiteralType extends BaseDatatype implements RDFDatatype {


public static String XMLLiteralTypeURI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral";
/** Singleton instance */
// Include the string for the RDF namespace, not use RDF.getURI(), to avoid an initializer circularity
public static final RDFDatatype theXMLLiteralType = new XMLLiteralType("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
public static final RDFDatatype theXMLLiteralType = new XMLLiteralType(XMLLiteralTypeURI);

/**
* Private constructor.
*/
private XMLLiteralType(String uri) {
super(uri);
}

/**
* Convert a serialize a value of this datatype out
* to lexical form.
Expand All @@ -57,7 +60,7 @@ private XMLLiteralType(String uri) {
public String unparse(Object value) {
return value.toString();
}

/**
* Parse a lexical form of this datatype to a value
* @throws DatatypeFormatException if the lexical form is not legal
Expand All @@ -68,7 +71,7 @@ public Object parse(String lexicalForm) throws DatatypeFormatException {
throw new DatatypeFormatException("Bad rdf:XMLLiteral");
return lexicalForm;
}

/**
* Test whether the given string is a legal lexical form
* of this datatype.
Expand All @@ -89,9 +92,9 @@ public boolean isValid(final String lexicalForm) {
// status[0] true on error or other reason to know that this is not well-formed
// status[1] true once first triple found
// status[2] the result (good if status[1] and not status[0]).

ARP arp = new ARP();

arp.getHandlers().setErrorHandler(new ErrorHandler(){
@Override
public void fatalError(SAXParseException e){
Expand All @@ -112,7 +115,7 @@ public void statement(AResource a, AResource b, ALiteral l){
/* this method is invoked exactly once
* while parsing the dummy document.
* The l argument is in exclusive canonical XML and
* corresponds to where the lexical form has been
* corresponds to where the lexical form has been
* in the dummy document. The lexical form is valid
* iff it is unchanged.
*/
Expand All @@ -130,24 +133,24 @@ public void statement(AResource a, AResource b, AResource l){
}
});
try {

arp.load(new StringReader(
"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
+"<rdf:Description><rdf:value rdf:parseType='Literal'>"
+lexicalForm+"</rdf:value>\n"
+"</rdf:Description></rdf:RDF>"
));

}
catch (IOException ioe){
throw new BrokenException(ioe);
throw new BrokenException(ioe);
}
catch (SAXException s){
return false;
}


return (!status[0])&&status[1]&&status[2];
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public String toString() {
return this.getClass().getSimpleName();
}

private static IRI baseIRI = null;

// -----------------------------

private static IRIFactory iriFactory() {
Expand Down
2 changes: 2 additions & 0 deletions jena-core/src/main/java/org/apache/jena/irix/IRIs.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static String getBaseStr() {
* turn it into a IRI suitable as a base IRI.
*/
public static String toBase(String baseURI) {
if ( baseURI == null )
return getBaseStr();
String scheme = scheme(baseURI);
if ( Sys.isWindows ) {
// Assume a scheme of one letter is a Windows drive letter.
Expand Down
4 changes: 2 additions & 2 deletions jena-core/src/main/java/org/apache/jena/irix/IRIx.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ protected IRIx(String string) {
public abstract boolean hasViolations();

/**
* Handle violations by sending a boolean, indicating whether this is an error or
* a warning, and string message to a handler.
* Handle violations by sending a boolean, indicating whether this is an error (true) or
* a warning (false), and string message to a handler.
*/
public abstract void handleViolations(BiConsumer<Boolean, String> violation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
/** Setup of jena-iri package IRI Factory for parsing and for checking. */
public class SetupJenaIRI {

// Currently, the same.
// The difference is the treatment in IRIProviderJenaIRI and ParserProfileStd.internalMakeIRI
// both of which can be scheme and component sensitive.

private static final IRIFactory iriFactoryInst = setupIRIFactory();
private static final IRIFactory iriCheckerInst = setupCheckerIRIFactory();

Expand All @@ -43,11 +39,6 @@ public static IRIFactory iriFactory() {
return iriFactoryInst;
}

public static IRIFactory iriFactory_RDFXML() {
// Used in ReaderRiotRDFXML
return iriFactory();
}

/**
* An IRIFactory with more detailed warnings.
*/
Expand Down
37 changes: 23 additions & 14 deletions jena-core/src/main/java/org/apache/jena/irix/SystemIRIx.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,39 @@
public class SystemIRIx {

// -- Providers
private static IRIProvider providerJenaIRI = new IRIProviderJenaIRI();
static {
providerJenaIRI.strictMode("urn", false);
providerJenaIRI.strictMode("http", false);
providerJenaIRI.strictMode("file", false);
private static IRIProvider makeProviderJenaIRI() {
IRIProvider newProviderJenaIRI = new IRIProviderJenaIRI();
newProviderJenaIRI.strictMode("urn", false);
newProviderJenaIRI.strictMode("http", false);
newProviderJenaIRI.strictMode("file", false);
return newProviderJenaIRI;
}
private static IRIProvider providerJenaIRI = makeProviderJenaIRI();

private static IRIProvider providerJDK = new IRIProviderJDK();
// ** Do not use IRIProviderJDK in production. **
static {}
private static IRIProvider makeProviderJDK() { return new IRIProviderJDK(); }

// private static IRIProvider providerIRI3986 = new IRIProvider3986();
// static {
// providerIRI3986.strictMode("urn", true);
// providerIRI3986.strictMode("http", true);
// providerIRI3986.strictMode("file", true);
// private static IRIProvider makeProviderIRI3986() {
// IRIProvider newProviderIRI3986 = new IRIProvider3986();
// newProviderIRI3986.strictMode("urn", true);
// newProviderIRI3986.strictMode("http", true);
// newProviderIRI3986.strictMode("file", true);
// }
// private static IRIProvider providerIRI3986 = makeProviderIRI3986();

// -- System-wide provider.

private static IRIProvider provider = providerJenaIRI;
//private static IRIProvider provider = providerIRI3986;
public static IRIProvider makeFreshSystemProvider() {
// Choice point.
return makeProviderJenaIRI();
}

private static IRIProvider provider = makeFreshSystemProvider();

public static void init() {}
public static void reset() {
provider = makeFreshSystemProvider();
}

public static void setProvider(IRIProvider aProvider) {
provider = aProvider;
Expand Down
Loading

0 comments on commit febf8f6

Please sign in to comment.