Skip to content

Commit

Permalink
chore: reference latest Smooks artifacts (#150)
Browse files Browse the repository at this point in the history
* chore: reference latest Smooks artifacts

* fix: solve compilation errors
  • Loading branch information
cjmamo authored Jan 2, 2025
1 parent 2f5d574 commit c2d34cd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.smooks.cartridges</groupId>
<artifactId>smooks-templating-cartridge</artifactId>
<version>2.1.0</version>
<version>2.1.1-SNAPSHOT</version>

<name>Smooks Templating Cartridge</name>
<url>https://www.smooks.org</url>
Expand Down Expand Up @@ -46,12 +46,12 @@
<dependency>
<groupId>org.smooks</groupId>
<artifactId>smooks-core</artifactId>
<version>2.1.0</version>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.smooks.cartridges</groupId>
<artifactId>smooks-javabean-cartridge</artifactId>
<version>2.0.1</version>
<version>2.0.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.smooks.cartridges.templating.AbstractTemplateProcessor;
import org.smooks.engine.delivery.AbstractParser;
import org.smooks.engine.delivery.dom.serialize.GhostElementSerializerVisitor;
import org.smooks.engine.resource.config.ParameterAccessor;
import org.smooks.engine.lookup.GlobalParamsLookup;
import org.smooks.io.sink.DOMSink;
import org.smooks.io.sink.StreamSink;
import org.smooks.io.sink.WriterSink;
Expand Down Expand Up @@ -203,9 +203,9 @@ protected void applyTemplate(Element element, ExecutionContext executionContext,
} catch (TransformerException e) {
throw new SmooksException("Error applying XSLT to node [" + executionContext.getDocumentSource() + ":" + DomUtils.getXPath(element) + "]", e);
}

final boolean closeEmptyElements = Boolean.parseBoolean(executionContext.getApplicationContext().getRegistry().lookup(new GlobalParamsLookup()).getParameterValue(Filter.CLOSE_EMPTY_ELEMENTS));
try {
writer.write(XmlUtils.serialize(ghostElement.getChildNodes(), Boolean.parseBoolean(ParameterAccessor.getParameterValue(Filter.CLOSE_EMPTY_ELEMENTS, String.class, "false", executionContext.getContentDeliveryRuntime().getContentDeliveryConfig()))));
writer.write(XmlUtils.serialize(ghostElement.getChildNodes(), closeEmptyElements));
} catch (IOException e) {
throw new SmooksException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.smooks.cartridges.templating.MyBean;
import org.smooks.cartridges.templating.TemplatingConfiguration;
import org.smooks.engine.DefaultApplicationContextBuilder;
import org.smooks.engine.DefaultFilterSettings;
import org.smooks.engine.resource.visitor.smooks.NestedSmooksVisitor;
import org.smooks.io.sink.StringSink;
import org.smooks.io.source.ReaderSource;
Expand All @@ -74,12 +75,12 @@ public class FreeMarkerProgramaticConfigTestCase {

@Test
public void testFreeMarkerTrans_01() throws SAXException, IOException {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.REPLACE));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
Bean bean = new Bean(MyBean.class, "myBeanData", "c", smooks.getApplicationContext().getRegistry());
Expand All @@ -93,13 +94,13 @@ public void testFreeMarkerTrans_01() throws SAXException, IOException {

@Test
public void test_nodeModel_1() {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<#foreach c in a.b.c>'${c}'</#foreach>")), "a");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<#foreach c in a.b.c>'${c}'</#foreach>")), "a");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setMaxNodeDepth(Integer.MAX_VALUE);
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.REPLACE));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
smooks.addVisitor(nestedSmooksVisitor, "a");
Expand All @@ -111,13 +112,13 @@ public void test_nodeModel_1() {

@Test
public void test_nodeModel_2() throws IOException, SAXException {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<x>'${c}'</x>")), "c");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<x>'${c}'</x>")), "c");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setMaxNodeDepth(Integer.MAX_VALUE);
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.REPLACE));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
smooks.addVisitor(nestedSmooksVisitor, "c");
Expand All @@ -127,43 +128,43 @@ public void test_nodeModel_2() throws IOException, SAXException {

@Test
public void testFreeMarkerTrans_bind() {
StringReader input;
ExecutionContext context;
StringReader stringReader;
ExecutionContext executionContext;

Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<mybean>${myBeanData.x}</mybean>")), "c");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("<mybean>${myBeanData.x}</mybean>")), "c");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setMaxNodeDepth(Integer.MAX_VALUE);
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.BIND_TO));
nestedSmooksVisitor.setBindIdOptional(Optional.of("mybeanTemplate"));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
Bean bean = new Bean(MyBean.class, "myBeanData", "c", smooks.getApplicationContext().getRegistry());
smooks.addVisitors(bean.bindTo("x", "c/@x"));
smooks.addVisitor(nestedSmooksVisitor, "c");

context = smooks.createExecutionContext();
input = new StringReader("<a><b><c x='xvalueonc2'/></b></a>");
smooks.filterSource(context, new ReaderSource<>(input), null);
executionContext = smooks.createExecutionContext();
stringReader = new StringReader("<a><b><c x='xvalueonc2'/></b></a>");
smooks.filterSource(executionContext, new ReaderSource<>(stringReader), null);

assertEquals("<mybean>xvalueonc2</mybean>", context.getBeanContext().getBean("mybeanTemplate"));
assertEquals("<mybean>xvalueonc2</mybean>", executionContext.getBeanContext().getBean("mybeanTemplate"));

context = smooks.createExecutionContext();
input = new StringReader("<c x='xvalueonc1'/>");
smooks.filterSource(context, new ReaderSource<>(input), null);
assertEquals("<mybean>xvalueonc1</mybean>", context.getBeanContext().getBean("mybeanTemplate"));
executionContext = smooks.createExecutionContext();
stringReader = new StringReader("<c x='xvalueonc1'/>");
smooks.filterSource(executionContext, new ReaderSource<>(stringReader), null);
assertEquals("<mybean>xvalueonc1</mybean>", executionContext.getBeanContext().getBean("mybeanTemplate"));
}

@Test
public void testInsertBefore() throws SAXException, IOException {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.PREPEND_BEFORE));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
Bean bean = new Bean(MyBean.class, "myBeanData", "b", smooks.getApplicationContext().getRegistry());
Expand All @@ -184,12 +185,12 @@ public void testInsertBefore() throws SAXException, IOException {

@Test
public void testInsertAfter() throws SAXException, IOException {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")), "c");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.APPEND_AFTER));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
Bean bean = new Bean(MyBean.class, "myBeanData", "b", smooks.getApplicationContext().getRegistry());
Expand All @@ -208,8 +209,8 @@ public void testInsertAfter() throws SAXException, IOException {

@Test
public void testAddTo() throws SAXException, IOException {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addVisitor(
new FreeMarkerTemplateProcessor(
new TemplatingConfiguration("/org/smooks/cartridges/templating/freemarker/test-template.ftl")
),
Expand All @@ -218,7 +219,7 @@ public void testAddTo() throws SAXException, IOException {

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.PREPEND_AFTER));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
Bean bean = new Bean(MyBean.class, "myBeanData", "b", smooks.getApplicationContext().getRegistry());
Expand Down Expand Up @@ -251,12 +252,12 @@ public void testAddTo() throws SAXException, IOException {

@Test
public void test_outputTo_Stream() {
Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("data to outstream")), "#document");
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).withFilterSettings(new DefaultFilterSettings().setCloseSink(false)).build());
pipeline.addVisitor(new FreeMarkerTemplateProcessor(new TemplatingConfiguration("data to outstream")), "#document");

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(NestedSmooksVisitor.Action.OUTPUT_TO));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);
nestedSmooksVisitor.setOutputStreamResourceOptional(Optional.of("outRes"));

Smooks smooks = new Smooks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public void testXslUnitTrans_parambased(NestedSmooksVisitor.Action action, Strin
res.setResourceType("xsl");
res.setParameter(XslContentHandlerFactory.IS_XSLT_TEMPLATELET, "true");

Smooks nestedSmooks = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
nestedSmooks.addResourceConfig(res);
Smooks pipeline = new Smooks(new DefaultApplicationContextBuilder().withSystemResources(false).build());
pipeline.addResourceConfig(res);

NestedSmooksVisitor nestedSmooksVisitor = new NestedSmooksVisitor();
nestedSmooksVisitor.setAction(Optional.of(action));
nestedSmooksVisitor.setNestedSmooks(nestedSmooks);
nestedSmooksVisitor.setPipeline(pipeline);

Smooks smooks = new Smooks();
smooks.addVisitor(nestedSmooksVisitor, "p");
Expand Down

0 comments on commit c2d34cd

Please sign in to comment.