commit f4802257370ee9a612614713e9a2e4a91120ad41 parent 15f4ff3c9d77f061c86a4f60bd29d85bbc0fce3e Author: Dan Callaghan <djc@djc.id.au> Date: Sun, 6 Dec 2009 14:12:46 +1000 removed XMLEventDestination, just discovered there is already an interface for this Diffstat:
6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/main/java/au/com/miskinhill/rdftemplate/ContentAction.java b/src/main/java/au/com/miskinhill/rdftemplate/ContentAction.java @@ -8,6 +8,7 @@ import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Attribute; import javax.xml.stream.events.StartElement; +import javax.xml.stream.util.XMLEventConsumer; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -31,7 +32,7 @@ public class ContentAction extends TemplateAction { this.selector = selector; } - public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventDestination writer, XMLEventFactory eventFactory) + public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventConsumer writer, XMLEventFactory eventFactory) throws XMLStreamException { Object replacement = selector.singleResult(node); StartElement start = interpolator.interpolateAttributes(this.start, node); diff --git a/src/main/java/au/com/miskinhill/rdftemplate/ForAction.java b/src/main/java/au/com/miskinhill/rdftemplate/ForAction.java @@ -6,12 +6,12 @@ import java.util.logging.Logger; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; - -import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.vocabulary.RDF; +import javax.xml.stream.util.XMLEventConsumer; import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Seq; +import com.hp.hpl.jena.vocabulary.RDF; import org.apache.commons.lang.builder.ToStringBuilder; import au.com.miskinhill.rdftemplate.selector.Selector; @@ -30,7 +30,7 @@ public class ForAction extends TemplateAction { this.selector = selector; } - public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventDestination writer) + public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventConsumer writer) throws XMLStreamException { List<RDFNode> result = selector.result(node); if (result.size() == 1 && result.get(0).canAs(Resource.class)) { diff --git a/src/main/java/au/com/miskinhill/rdftemplate/IfAction.java b/src/main/java/au/com/miskinhill/rdftemplate/IfAction.java @@ -5,10 +5,10 @@ import java.util.List; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; - -import org.apache.commons.lang.builder.ToStringBuilder; +import javax.xml.stream.util.XMLEventConsumer; import com.hp.hpl.jena.rdf.model.RDFNode; +import org.apache.commons.lang.builder.ToStringBuilder; import au.com.miskinhill.rdftemplate.selector.Selector; @@ -27,7 +27,7 @@ public class IfAction extends TemplateAction { this.negate = negate; } - public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventDestination writer) + public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventConsumer writer) throws XMLStreamException { List<?> selectorResult = condition.result(node); if (negate ? selectorResult.isEmpty() : !selectorResult.isEmpty()) { diff --git a/src/main/java/au/com/miskinhill/rdftemplate/JoinAction.java b/src/main/java/au/com/miskinhill/rdftemplate/JoinAction.java @@ -7,13 +7,12 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; - -import com.hp.hpl.jena.vocabulary.RDF; - -import com.hp.hpl.jena.rdf.model.Resource; +import javax.xml.stream.util.XMLEventConsumer; import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Seq; +import com.hp.hpl.jena.vocabulary.RDF; import org.apache.commons.lang.builder.ToStringBuilder; import au.com.miskinhill.rdftemplate.selector.Selector; @@ -34,7 +33,7 @@ public class JoinAction extends TemplateAction { this.separator = separator; } - public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventDestination writer, XMLEventFactory eventFactory) + public void evaluate(TemplateInterpolator interpolator, RDFNode node, XMLEventConsumer writer, XMLEventFactory eventFactory) throws XMLStreamException { List<RDFNode> result = selector.result(node); if (result.size() == 1 && result.get(0).canAs(Resource.class)) { diff --git a/src/main/java/au/com/miskinhill/rdftemplate/TemplateInterpolator.java b/src/main/java/au/com/miskinhill/rdftemplate/TemplateInterpolator.java @@ -28,6 +28,7 @@ import javax.xml.stream.events.EndElement; import javax.xml.stream.events.Namespace; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; +import javax.xml.stream.util.XMLEventConsumer; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -56,7 +57,7 @@ public class TemplateInterpolator { try { StringWriter writer = new StringWriter(); final XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); - XMLEventDestination destination = new XMLEventDestination() { + XMLEventConsumer destination = new XMLEventConsumer() { @Override public void add(XMLEvent event) throws XMLStreamException { eventWriter.add(event); @@ -70,7 +71,7 @@ public class TemplateInterpolator { } @SuppressWarnings("unchecked") - public void interpolate(Reader reader, RDFNode node, XMLEventDestination writer) { + public void interpolate(Reader reader, RDFNode node, XMLEventConsumer writer) { try { interpolate(inputFactory.createXMLEventReader(reader), node, writer); } catch (XMLStreamException e) { @@ -79,7 +80,7 @@ public class TemplateInterpolator { } public void interpolate(Reader reader, RDFNode node, final Collection<XMLEvent> destination) { - interpolate(reader, node, new XMLEventDestination() { + interpolate(reader, node, new XMLEventConsumer() { @Override public void add(XMLEvent event) { destination.add(event); @@ -87,7 +88,7 @@ public class TemplateInterpolator { }); } - public void interpolate(Iterator<XMLEvent> reader, RDFNode node, XMLEventDestination writer) + public void interpolate(Iterator<XMLEvent> reader, RDFNode node, XMLEventConsumer writer) throws XMLStreamException { while (reader.hasNext()) { XMLEvent event = reader.next(); @@ -331,7 +332,7 @@ public class TemplateInterpolator { return substituted.toString(); } - private void interpolateCharacters(XMLEventDestination writer, Characters characters, RDFNode node) throws XMLStreamException { + private void interpolateCharacters(XMLEventConsumer writer, Characters characters, RDFNode node) throws XMLStreamException { String template = characters.getData(); if (!SUBSTITUTION_PATTERN.matcher(template).find()) { writer.add(characters); // fast path @@ -359,7 +360,7 @@ public class TemplateInterpolator { writer.add(eventFactory.createCharacters(template.substring(lastAppendedPos))); } - protected void writeTreeForContent(XMLEventDestination writer, Object replacement) + protected void writeTreeForContent(XMLEventConsumer writer, Object replacement) throws XMLStreamException { if (replacement instanceof RDFNode) { RDFNode replacementNode = (RDFNode) replacement; @@ -394,7 +395,7 @@ public class TemplateInterpolator { return attributes; } - private void writeXMLLiteral(String literal, XMLEventDestination writer) + private void writeXMLLiteral(String literal, XMLEventConsumer writer) throws XMLStreamException { XMLEventReader reader = inputFactory.createXMLEventReader(new StringReader(literal)); while (reader.hasNext()) { diff --git a/src/main/java/au/com/miskinhill/rdftemplate/XMLEventDestination.java b/src/main/java/au/com/miskinhill/rdftemplate/XMLEventDestination.java @@ -1,11 +0,0 @@ -package au.com.miskinhill.rdftemplate; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.XMLEvent; - -/** Common superinterface which can be implemented by XMLEventWriter or List<XMLEvent>. */ -public interface XMLEventDestination { - - void add(XMLEvent event) throws XMLStreamException; - -}