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
20 changes: 10 additions & 10 deletions core/src/main/java/org/smooks/engine/delivery/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void attachXMLReader(XMLReader xmlReader, ExecutionContext execCon

NamespaceDeclarationStack namespaceDeclarationStack = execContext.get(NamespaceManager.NAMESPACE_DECLARATION_STACK_TYPED_KEY);
if (namespaceDeclarationStack == null) {
throw new IllegalStateException("No NamespaceDeclarationStack attached to the ExecutionContext.");
throw new IllegalStateException("No NamespaceDeclarationStack attached to the ExecutionContext");
}
namespaceDeclarationStack.pushReader(xmlReader);
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public static void setReaders(Stack<XMLReader> readers, ExecutionContext executi
*/
public static ResourceConfig getSAXParserConfiguration(ContentDeliveryConfig deliveryConfig) {
if (deliveryConfig == null) {
throw new IllegalArgumentException("null 'deliveryConfig' arg in method call.");
throw new IllegalArgumentException("null 'deliveryConfig' arg in method call");
}

ResourceConfig saxDriverConfig = null;
Expand All @@ -210,7 +210,7 @@ protected InputStream urlToStream(URL url) {
try {
return url.openStream();
} catch (IOException e) {
throw new SmooksException("Invalid URL on StreamSource: '" + url + "'. Unable to open stream to resource.", e);
throw new SmooksException("Invalid URL on StreamSource: '" + url + "'. Unable to open stream to resource", e);
}
}

Expand All @@ -222,7 +222,7 @@ protected Reader streamToReader(InputStream inputStream, String contentEncoding)
return new InputStreamReader(inputStream, StandardCharsets.UTF_8);
}
} catch (UnsupportedEncodingException e) {
throw new SmooksException("Unable to decode input stream.", e);
throw new SmooksException("Unable to decode input stream", e);
}
}

Expand All @@ -232,7 +232,7 @@ protected InputSource createInputSource(Source source, String contentEncoding) {
StreamSource streamSource = (StreamSource) source;
InputStream inputStream = streamSource.getInputStream();
if (inputStream == null) {
throw new SmooksException("Invalid StreamSource. Unable to extract an InputStream.");
throw new SmooksException("Invalid StreamSource. Unable to extract an InputStream");
}
Reader reader = streamToReader(inputStream, contentEncoding);

Expand Down Expand Up @@ -268,7 +268,7 @@ protected XMLReader createXMLReader() throws SAXException {
JavaSource javaSource = (JavaSource) source;

if (isFeatureOn(JavaSource.FEATURE_GENERATE_EVENT_STREAM, saxDriverConfig) && !javaSource.isEventStreamRequired()) {
throw new SmooksConfigException(String.format("Invalid Smooks configuration. Feature [%s] is explicitly configured 'on' in the Smooks configuration, while the supplied JavaSource has explicitly configured event streaming to be off (through a call to JavaSource.setEventStreamRequired).", JavaSource.FEATURE_GENERATE_EVENT_STREAM));
throw new SmooksConfigException(String.format("Invalid Smooks configuration. Feature [%s] is explicitly configured 'on' in the Smooks configuration, while the supplied JavaSource has explicitly configured event streaming to be off (through a call to JavaSource.setEventStreamRequired)", JavaSource.FEATURE_GENERATE_EVENT_STREAM));
}

// Event streaming must be explicitly turned off. If is on as long as it is (a) not configured "off" in
Expand Down Expand Up @@ -308,7 +308,7 @@ protected void attachNamespaceDeclarationStack(XMLReader reader, ExecutionContex
NamespaceDeclarationStack nsDeclarationStack = execContext.get(NamespaceManager.NAMESPACE_DECLARATION_STACK_TYPED_KEY);

if (nsDeclarationStack == null) {
throw new IllegalStateException("NamespaceDeclarationStack not configured on ExecutionContext.");
throw new IllegalStateException("NamespaceDeclarationStack not configured on ExecutionContext");
}

((NamespaceDeclarationStackAware) reader).setNamespaceDeclarationStack(nsDeclarationStack);
Expand All @@ -322,7 +322,7 @@ protected void configureReader(XMLReader xmlReader, DefaultHandler2 contentHandl

if (xmlReader instanceof JavaXMLReader) {
if (!(source instanceof JavaSource)) {
throw new SmooksException("A " + JavaSource.class.getName() + " source must be supplied for " + JavaXMLReader.class.getName() + " implementations.");
throw new SmooksException("A " + JavaSource.class.getName() + " source must be supplied for " + JavaXMLReader.class.getName() + " implementations");
}
((JavaXMLReader) xmlReader).setSourceObjects(((JavaSource) source).getSourceObjects());
}
Expand All @@ -332,7 +332,7 @@ protected void configureReader(XMLReader xmlReader, DefaultHandler2 contentHandl
try {
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", contentHandler);
} catch (SAXNotRecognizedException e) {
LOGGER.warn("XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader '" + xmlReader.getClass().getName() + "'.");
LOGGER.warn("XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader [{}]", xmlReader.getClass().getName());
}
}

Expand Down Expand Up @@ -363,7 +363,7 @@ private Object createHandler(String handlerName) {
try {
return ClassUtils.forName(handlerName, getClass()).newInstance();
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new SmooksException("Failed to create SAX Handler '" + handlerName + "'.", e);
throw new SmooksException("Failed to create SAX Handler '" + handlerName + "'", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.smooks.api.resource.visitor.dom.Phase;
import org.smooks.api.resource.visitor.dom.VisitPhase;
import org.smooks.engine.delivery.AbstractFilterProvider;
import org.smooks.engine.delivery.dom.serialize.DOMSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.DOMSerializerVisitor;
import org.smooks.engine.delivery.event.DefaultContentDeliveryConfigExecutionEvent;
import org.smooks.engine.lookup.GlobalParamsLookup;
import org.smooks.engine.lookup.NamespaceManagerLookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
import org.smooks.api.resource.visitor.dom.VisitPhase;
import org.smooks.engine.delivery.AbstractFilter;
import org.smooks.engine.delivery.ContentHandlerBindingIndex;
import org.smooks.engine.delivery.dom.serialize.Serializer;
import org.smooks.engine.delivery.dom.serialize.TextSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.Serializer;
import org.smooks.engine.resource.visitor.dom.TextSerializerVisitor;
import org.smooks.engine.delivery.event.*;
import org.smooks.engine.delivery.fragment.NodeFragment;
import org.smooks.engine.lifecycle.AssemblyStartedDOMFilterLifecyclePhase;
Expand Down Expand Up @@ -163,7 +163,7 @@
* </li>
* <li>
* <b><u>Serialisation</u></b>: This phase is executed by the {@link #serialize(Node, Writer)} method (which uses the
* {@link org.smooks.engine.delivery.dom.serialize.Serializer} class). The serialisation phase takes the processed DOM and
* {@link Serializer} class). The serialisation phase takes the processed DOM and
* iterates over it to apply all {@link SerializerVisitor SerializationUnits},
* which write the document to the target output stream.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.config.ResourceConfigChangeListener;
import org.smooks.api.resource.config.xpath.SelectorPath;
import org.smooks.engine.delivery.dom.serialize.DefaultDOMSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.smooks.engine.resource.config.xpath.SelectorPathFactory;
import org.smooks.resource.URIResourceLocator;
import org.smooks.support.ClassUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.sax.ng;
package org.smooks.engine.resource.visitor;

import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksException;
Expand All @@ -50,6 +50,7 @@
import org.smooks.api.resource.visitor.Visitor;
import org.smooks.api.resource.visitor.dom.DOMElementVisitor;
import org.smooks.engine.delivery.fragment.NodeFragment;
import org.smooks.engine.delivery.sax.ng.SaxNgContentDeliveryConfig;
import org.smooks.engine.memento.AbstractVisitorMemento;
import org.smooks.engine.memento.SimpleVisitorMemento;
import org.smooks.engine.memento.VisitorMemento;
Expand Down Expand Up @@ -103,20 +104,16 @@ public void setCloseEmptyElements(@Named(Filter.CLOSE_EMPTY_ELEMENTS) Optional<B
this.closeEmptyElements = closeEmptyElements.orElse(this.closeEmptyElements);
}

public void writeStartElement(final Element element, final ExecutionContext executionContext) {
protected void writeStartElement(final Element element, final ExecutionContext executionContext, final Writer writer) {
final Fragment<Node> nodeFragment = new NodeFragment(element);
executionContext.getMementoCaretaker().stash(new ElementMemento(nodeFragment, this, false), elementMemento -> {
if (!elementMemento.isOpen()) {
try {
writeStartElement(element, new FragmentWriter(executionContext, nodeFragment), executionContext);
} catch (IOException e) {
throw new SmooksException(e.getMessage(), e);
}

return new ElementMemento(nodeFragment, ConsumeSerializerVisitor.this, true);
} else {
return elementMemento;
try {
writeStartElement(element, writer, executionContext);
} catch (IOException e) {
throw new SmooksException(e.getMessage(), e);
}

return new ElementMemento(nodeFragment, ConsumeSerializerVisitor.this, true);
});
}

Expand All @@ -131,7 +128,7 @@ protected void closeElement(final Element element, final Writer writer, final Ex
writer.write("/>");
} else {
if (!elementMemento.isOpen()) {
writeStartElement(element, executionContext);
writeStartElement(element, executionContext, writer);
}
writer.write("</");
writer.write(element.getTagName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.sax.ng;
package org.smooks.engine.resource.visitor;

import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.sax.ng;
package org.smooks.engine.resource.visitor;

import org.smooks.api.ExecutionContext;
import org.w3c.dom.Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.smooks.api.resource.visitor.SerializerVisitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.smooks.api.ExecutionContext;
import org.smooks.api.delivery.Filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.smooks.api.SmooksException;
import org.smooks.api.ExecutionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* =========================LICENSE_END==================================
*/
package org.smooks.engine.delivery.dom.serialize;
package org.smooks.engine.resource.visitor.dom;

import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void postConstruct() throws SAXException, IOException, URISyntaxException
resourceConfigSeq = applicationContext.getResourceConfigLoader().load(smooksResourceList, "./", applicationContext.getClassLoader());
} else {
ResourceConfig resourceConfig = new DefaultResourceConfig("*", new Properties());
resourceConfig.setResource("org.smooks.engine.delivery.sax.ng.SimpleSerializerVisitor");
resourceConfig.setResource("org.smooks.engine.resource.visitor.SimpleSerializerVisitor");
resourceConfigSeq = new DefaultResourceConfigSeq("./");
resourceConfigSeq.add(resourceConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@

<resource-config selector="/smooks:smooks-resource-list/smooks-core:echo">
<resource>org.smooks.engine.resource.config.loader.xml.extension.NewResourceConfig</resource>
<param name="resource">org.smooks.engine.delivery.sax.ng.SimpleSerializerVisitor</param>
<param name="resource">org.smooks.engine.resource.visitor.SimpleSerializerVisitor</param>
</resource-config>
<resource-config selector="/smooks:smooks-resource-list/smooks-core:echo">
<resource>org.smooks.engine.resource.config.loader.xml.extension.SetOnResourceConfig</resource>
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/resources/system-serializers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@
default-target-profile="*">

<resource-config selector="smooks:context-object">
<resource>org.smooks.engine.delivery.dom.serialize.ContextObjectSerializerVisitor</resource>
<resource>org.smooks.engine.resource.visitor.dom.ContextObjectSerializerVisitor</resource>
</resource-config>

<resource-config selector="smooks:ghost-element">
<resource>org.smooks.engine.delivery.dom.serialize.GhostElementSerializerVisitor</resource>
<resource>org.smooks.engine.resource.visitor.dom.GhostElementSerializerVisitor</resource>
</resource-config>

<resource-config selector="smooks:text">
<resource>org.smooks.engine.delivery.dom.serialize.TextSerializerVisitor</resource>
<resource>org.smooks.engine.resource.visitor.dom.TextSerializerVisitor</resource>
<param name="entities.rewrite">false</param>
</resource-config>

<resource-config selector="*">
<resource>org.smooks.engine.delivery.sax.ng.SystemConsumeSerializerVisitor</resource>
<resource>org.smooks.engine.resource.visitor.SystemConsumeSerializerVisitor</resource>
</resource-config>

</smooks-resource-list>
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@
package org.smooks.JIRAs.MILYN_367;

import org.junit.jupiter.api.Test;
import org.smooks.FilterSettings;
import org.smooks.Smooks;
import org.smooks.StreamFilterType;
import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksException;
import org.smooks.api.resource.visitor.dom.DOMVisitAfter;
import org.smooks.api.resource.visitor.dom.DOMVisitBefore;
import org.smooks.engine.DefaultApplicationContext;
import org.smooks.engine.DefaultApplicationContextBuilder;
import org.smooks.engine.DefaultFilterSettings;
import org.smooks.engine.delivery.dom.DOMFilterType;
import org.smooks.engine.delivery.dom.serialize.DefaultDOMSerializerVisitor;
import org.smooks.engine.delivery.sax.ng.ConsumeSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.smooks.engine.resource.visitor.ConsumeSerializerVisitor;
import org.smooks.io.sink.StringSink;
import org.smooks.io.source.StreamSource;
import org.smooks.support.StreamUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import org.smooks.api.resource.visitor.dom.DOMVisitAfter;
import org.smooks.api.resource.visitor.dom.DOMVisitBefore;
import org.smooks.engine.delivery.dom.DOMContentDeliveryConfig;
import org.smooks.engine.delivery.dom.serialize.ContextObjectSerializerVisitor;
import org.smooks.engine.delivery.dom.serialize.DefaultDOMSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.ContextObjectSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.xml.sax.SAXException;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ public void test_close_io() throws IOException, SAXException {

public void test_close_io(String profile, int expectedCloseCallCount) throws IOException, SAXException {
Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-close-filter-io.xml"));
ExecutionContext execContext;
ExecutionContext executionContext;

// Test io stream close....
// We need to +1 this because Xerces always closes input streams/readers and there's no
// way of turning that off
TestInputStream inStream = new TestInputStream("<x/>".getBytes(), expectedCloseCallCount + 1);
TestOutputStream outStream = new TestOutputStream(expectedCloseCallCount);
execContext = smooks.createExecutionContext(profile);
smooks.filterSource(execContext, new StreamSource(inStream), new StreamSink(outStream));
executionContext = smooks.createExecutionContext(profile);
smooks.filterSource(executionContext, new StreamSource<>(inStream), new StreamSink<>(outStream));

// Test io reader/writer close...
// We need to +1 this because Xerces always closes input streams/readers and there's no
// way of turning that off
TestReader reader = new TestReader("<x/>", expectedCloseCallCount + 1);
TestWriter writer = new TestWriter(expectedCloseCallCount);
execContext = smooks.createExecutionContext(profile);
smooks.filterSource(execContext, new ReaderSource(reader), new WriterSink(writer));
executionContext = smooks.createExecutionContext(profile);
smooks.filterSource(executionContext, new ReaderSource<>(reader), new WriterSink<>(writer));
}

private static class TestInputStream extends ByteArrayInputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.smooks.engine.resource.config.DefaultResourceConfig;
import org.smooks.api.ExecutionContext;
import org.smooks.api.resource.visitor.dom.DOMElementVisitor;
import org.smooks.engine.delivery.dom.serialize.DefaultDOMSerializerVisitor;
import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.w3c.dom.Element;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
package org.smooks.engine.delivery.dom.serialize;

import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.smooks.io.DomSerializer;
import org.w3c.dom.NamedNodeMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
package org.smooks.engine.delivery.dom.serialize;

import org.smooks.api.ExecutionContext;
import org.smooks.engine.resource.visitor.dom.DefaultDOMSerializerVisitor;
import org.w3c.dom.*;

import javax.inject.Inject;
Expand Down
Loading
Loading