Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public static void register() {
register(RDFXML_StAX_sr, ReaderRDFXML_StAX_SR.factory);

// ARP using IRIx
register(RDFXML_ARP1, ReaderRDFXML_ARP1.factory);

@SuppressWarnings("removal")
var arpFactory = ReaderRDFXML_ARP1.factory;
register(RDFXML_ARP1, arpFactory);
}

private static void register(Lang lang, ReaderRIOTFactory factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.apache.jena.graph.Triple ;
import org.apache.jena.irix.IRIs;
import org.apache.jena.rdf.model.RDFErrorHandler ;
import org.apache.jena.rdfxml.xmlinput1.*;
import org.apache.jena.rdfxml.xmlinput1.impl.ARPSaxErrorHandler;
import org.apache.jena.rdfxml.arp1.*;
import org.apache.jena.rdfxml.arp1.impl.ARPSaxErrorHandler;
import org.apache.jena.riot.*;
import org.apache.jena.riot.system.ErrorHandler;
import org.apache.jena.riot.system.FactoryRDF;
Expand All @@ -48,12 +48,13 @@
* <p>
* <b>LEGACY</b>
* <p>
* Uses xmlinput1 - the version of ARP from Jena 4.7.0 to Jena 4.10.0.
* Uses ARP1 - the version of ARP from Jena 4.7.0 to Jena 4.10.0.
* <p>
* Replaced at Jena 5 by RRX.
*
* @see <a href="http://www.w3.org/TR/rdf-syntax-grammar/">http://www.w3.org/TR/rdf-syntax-grammar/</a>
*/
@Deprecated(forRemoval = true)
public class ReaderRDFXML_ARP1 implements ReaderRIOT
{
public static ReaderRIOTFactory factory = (Lang language, ParserProfile parserProfile) -> {
Expand Down Expand Up @@ -133,13 +134,13 @@ private void oneProperty(ARPOptions options, String pName, Object value) {
options.setErrorMode(cond, val);
}

@SuppressWarnings({"deprecation"})
private void parse(InputStream input, Reader reader, String xmlBase, ContentType ct, StreamRDF sink, Context context) {
// Hacked out of ARP because of all the "private" methods
// JenaReader has reset the options since new ARP() was called.
sink.start() ;
HandlerSink rslt = new HandlerSink(sink, parserProfile) ;

@SuppressWarnings("removal")
ARP arp = new ARP();
arp.getHandlers().setStatementHandler(rslt) ;
arp.getHandlers().setErrorHandler(rslt) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class RDFXMLAbbrevWriter extends AdapterRDFWriter {

public RDFXMLAbbrevWriter() {}

@SuppressWarnings("deprecation")
@Override
protected RDFWriterI create() {
return new RDFXML_Abbrev();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class RDFXMLPlainWriter extends AdapterRDFWriter {
public RDFXMLPlainWriter() {}

@SuppressWarnings("deprecation")
@Override
protected RDFWriterI create() {
return new RDFXML_Basic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Scripts_ARP1_RDFXML {
@TestFactory
@DisplayName("ARP1 (legacy)")
public Stream<DynamicNode> testFactoryARP1() {
return withAltParserFactory(Lang.RDFXML, ReaderRDFXML_ARP1.factory, TestConsts.RDF11_TESTS_DIR+"rdf-xml/manifest.ttl");
@SuppressWarnings("removal")
var factory = ReaderRDFXML_ARP1.factory;
return withAltParserFactory(Lang.RDFXML, factory, TestConsts.RDF11_TESTS_DIR+"rdf-xml/manifest.ttl");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
/** Ways to run tests on parsers. */
public class RunTestRDFXML {

@SuppressWarnings("removal")
static ReaderRIOTFactory arpFactory = ReaderRDFXML_ARP1.factory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFReaderF;
import org.apache.jena.rdf.model.impl.RDFReaderFImpl;
import org.apache.jena.riot.IO_Jena;
import org.apache.jena.riot.adapters.RDFReaderRIOT;
import org.apache.jena.shared.NoReaderForLangException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestIO_JenaReaders {
@BeforeAll public static void beforeClass() { }
Expand Down Expand Up @@ -59,20 +64,31 @@ public void wireIntoJena() {
public void resetJena() {
IO_Jena.wireIntoJena();
IO_Jena.resetJena();
RDFReaderF readerF = new RDFReaderFImpl();
try {
RDFReaderF readerF = new RDFReaderFImpl();
Model model = ModelFactory.createDefaultModel();
Logger logger = LoggerFactory.getLogger("RDFReader");

assertNotEquals(RDFReaderRIOT.class, readerF.getReader(null).getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("RDF/XML-ABBREV").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLES").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-Triples").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLE").getClass());
LogCtl.withLevel(logger, "off", ()->{
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("RDF"));
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("RDF/XML"));
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("RDF/XML-ABBREV"));

try { readerF.getReader("NT") ; fail("Exception expected"); } catch (NoReaderForLangException e) {}
try { readerF.getReader("JSON_LD"); fail("Exception expected"); } catch (NoReaderForLangException e) {}
try { readerF.getReader("RDF/JSON"); fail("Exception expected"); } catch (NoReaderForLangException e) {}
assertThrows(NoReaderForLangException.class, ()->model.read("http://example/"));
assertThrows(NoReaderForLangException.class, ()->model.read("http://example/", "RDF/XML"));
});

IO_Jena.wireIntoJena();
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLES").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-Triples").getClass());
assertNotEquals(RDFReaderRIOT.class, readerF.getReader("N-TRIPLE").getClass());

// It's not called "NT" in jena-core on it's own.
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("NT"));
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("TURTLE"));
assertThrows(NoReaderForLangException.class, ()->readerF.getReader("JSON-LD"));
} finally {
IO_Jena.wireIntoJena();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFWriterF;
import org.apache.jena.rdf.model.impl.RDFWriterFImpl;
import org.apache.jena.riot.IO_Jena;
import org.apache.jena.riot.adapters.RDFWriterRIOT;
import org.apache.jena.shared.NoWriterForLangException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestIO_JenaWriters {

Expand Down Expand Up @@ -57,30 +62,34 @@ public void testWireIntoJena() {
assertEquals(RDFWriterRIOT.class, writerF.getWriter("RDFJSON").getClass());
}

@SuppressWarnings("removal")
@Test
public void testResetJena() {
IO_Jena.wireIntoJena();
IO_Jena.resetJena();
RDFWriterF writerF = new RDFWriterFImpl();
try {
RDFWriterF writerF = new RDFWriterFImpl();
Model model = ModelFactory.createDefaultModel();
Logger logger = LoggerFactory.getLogger("RDFWriter");

assertNotEquals(RDFWriterRIOT.class, writerF.getWriter(null).getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("RDF/XML-ABBREV").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-Triples").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
LogCtl.withLevel(logger, "off", ()->{
assertThrows(NoWriterForLangException.class, ()->writerF.getWriter("RDF/XML"));
assertThrows(NoWriterForLangException.class, ()->writerF.getWriter("RDF/XML-ABBREV"));

//N3 , Turtle in jena-core removed.
// assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N3").getClass());
// assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("TURTLE").getClass());
// assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("Turtle").getClass());
// assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("TTL").getClass());

try { writerF.getWriter("NT"); fail("Exception expected"); } catch (NoWriterForLangException ex) {}
try { writerF.getWriter("RDF/JSON"); fail("Exception expected"); } catch (NoWriterForLangException ex) {}
try { writerF.getWriter("RDFJSON"); fail("Exception expected"); } catch (NoWriterForLangException ex) {}
IO_Jena.wireIntoJena();
}
assertThrows(NoWriterForLangException.class, ()->model.write(System.err));
assertThrows(NoWriterForLangException.class, ()->model.write(System.err, "RDF/XML"));
});

assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-Triples").getClass());
assertNotEquals(RDFWriterRIOT.class, writerF.getWriter("N-TRIPLE").getClass());

// It's not called "NT" in jena-core on it's own.
assertThrows(NoWriterForLangException.class, ()->writerF.getWriter("NT"));
assertThrows(NoWriterForLangException.class, ()->writerF.getWriter("TURTLE"));
assertThrows(NoWriterForLangException.class, ()->writerF.getWriter("JSON-LD"));
} finally {
IO_Jena.wireIntoJena();
}
}
}
4 changes: 1 addition & 3 deletions jena-core/src/main/java/org/apache/jena/rdf/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ update interface (which means turning them into triples in one form or
*/
@Deprecated(forRemoval = true)
public default Model write(Writer writer) { return write(writer, "RDF/XML"); }

/**
* <p>Write a serialized representation of a model in a specified language.
* It is often better to use an OutputStream rather than a Writer, since this
Expand Down Expand Up @@ -585,13 +585,11 @@ update interface (which means turning them into triples in one form or
*/
public Model write( Writer writer, String lang, String base );


/**
* <p>Write a serialization of this model as an XML document.s</p>
* @deprecated Use {@code write(OutputStream, "RDF/XML")}
*/
@Deprecated(forRemoval = true)

public default Model write(OutputStream out) { return write(out, "RDF/XML"); }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public interface RDFReaderI {
* <dt>N-TRIPLE</dt>
* <dd>No properties.</dd>
* <dt>RDF/XML</dt><dt>RDF/XML-ABBREV</dt>
* <dd>See {@link org.apache.jena.rdfxml.xmlinput1.RDFXMLReader#setProperty(String,Object)}
* <dd>See {@link org.apache.jena.rdfxml.arp1.RDFXMLReader#setProperty(String,Object)}
* </dl>
* @param propName the name of the property
* @param propValue the value of the property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.jena.rdf.model.impl;

import org.apache.jena.rdf.model.* ;
import org.apache.jena.rdfxml.xmlinput1.ParseException;
import org.apache.jena.rdfxml.arp1.ParseException;
import org.apache.jena.shared.* ;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,82 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.apache.jena.atlas.logging.Log ;
import org.apache.jena.atlas.lib.Creator;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.rdf.model.RDFReaderF;
import org.apache.jena.rdf.model.RDFReaderI;
import org.apache.jena.rdfxml.arp1.RDFXMLReader;
import org.apache.jena.shared.JenaException;
import org.apache.jena.shared.NoReaderForLangException;

public class RDFReaderFImpl extends Object implements RDFReaderF {
public static final String DEFAULTLANG = "RDF/XML" ;
private static Map<String, Class<? extends RDFReaderI>> custom = new LinkedHashMap<>();
private static RDFReaderF rewiredAlternative = null ;
public static final String DEFAULTLANG = "RDF/XML";
private static Map<String, Creator<RDFReaderI>> custom = new LinkedHashMap<>();
private static RDFReaderF rewiredAlternative = null;

// Jena6
private static final boolean includeRDFXML = false;

/** Rewire to use an external RDFReaderF (typically, RIOT).
* Set to null to use old jena-core setup.
* @param other
*/
public static void alternative(RDFReaderF other) {
rewiredAlternative = other ;
rewiredAlternative = other;
}

private static String msgNoRDFXML = "RDF/XML is no longer supported in jena-core. Add jena-arq to the classpath";
private static Set<String> removedLangs = Set.of("RDF", "RDF/XML", "RDF/XML-ABBREV");

/** Creates new RDFReaderFImpl */
public RDFReaderFImpl() {}

static { setup(); }

@Override
public RDFReaderI getReader(String lang) {
// Jena model.read rule for defaulting.
if (lang==null || lang.equals(""))
lang = DEFAULTLANG ;
lang = DEFAULTLANG;
// if RIOT ->
if ( rewiredAlternative != null )
return rewiredAlternative.getReader(lang) ;
Class<? extends RDFReaderI> c = custom.get(lang);
return rewiredAlternative.getReader(lang);

if ( ! includeRDFXML ) {
// Jena6: reading RDF/XML removed from jena-core
if ( removedLangs.contains(lang) )
Log.error("RDFReader", msgNoRDFXML);
}

Creator<RDFReaderI> c = custom.get(lang);
if ( c == null )
throw new NoReaderForLangException("Reader not found: " + lang);

try {
return c.getConstructor().newInstance();
return c.create();
}
catch (Exception e) {
catch (RuntimeException e) {
throw new JenaException(e);
}
}

static {
// static initializer - set default readers
reset();
}

private static void reset() {
Class<? extends RDFReaderI> rdfxmlReader = org.apache.jena.rdfxml.xmlinput1.RDFXMLReader.class;
Class<? extends RDFReaderI> ntReader = org.apache.jena.rdf.model.impl.NTripleReader.class;
private static void setup() {
// Turtle moved to test-only
// Jena6: ARP1 (RDF/XML) not installed except for tests

custom.put("RDF", rdfxmlReader);
custom.put("RDF/XML", rdfxmlReader);
custom.put("RDF/XML-ABBREV", rdfxmlReader);

custom.put("N-TRIPLE", ntReader);
Creator<RDFReaderI> ntReader = NTripleReader::new;
custom.put("N-TRIPLE", ntReader);
custom.put("N-TRIPLES", ntReader);
custom.put("N-Triples", ntReader);
}

private static String currentEntry(String lang) {
Class<? extends RDFReaderI> oldClass = custom.get(lang);
if ( oldClass != null )
return oldClass.getName();
else
return null;
}

private static String remove(String lang) {
if ( rewiredAlternative != null )
Log.error(RDFReaderFImpl.class, "Rewired RDFReaderFImpl - configuration changes have no effect on reading");

String oldClassName = currentEntry(lang);
custom.remove(lang);
return oldClassName;
if ( includeRDFXML ) {
@SuppressWarnings("removal")
Creator<RDFReaderI> rdfxmlReader = RDFXMLReader::new;
custom.put("RDF", rdfxmlReader);
custom.put("RDF/XML", rdfxmlReader);
custom.put("RDF/XML-ABBREV", rdfxmlReader);
}
}
}
Loading
Loading