[jboss-svn-commits] JBL Code SVN: r12237 - in labs/jbossesb/trunk/product: samples/quickstarts/transform_CSV2XML and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 30 09:29:11 EDT 2007
Author: tfennelly
Date: 2007-05-30 09:29:11 -0400 (Wed, 30 May 2007)
New Revision: 12237
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/smooks-res.xml
labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/smooks-res.xml
labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/DateFormatter.groovy
labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/EnrichmentProcessor.groovy
Log:
Updated a few of the quickstarts in line with Smooks 0.8 to 0.9 upgrade
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2007-05-30 13:19:46 UTC (rev 12236)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2007-05-30 13:29:11 UTC (rev 12237)
@@ -37,9 +37,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
@@ -272,17 +270,24 @@
{
Transformer transformer;
- // There's a bug in Java 5 re this code (formatting).
- // See http://forum.java.sun.com/thread.jspa?threadID=562510&start=0
- // and it explains the
- // whys of the following code.
+ try {
+ factory.setAttribute("indent-number", new Integer(4));
+ } catch(Exception e) {
+ // Ignore... Xalan may throw on this!!
+ // We handle Xalan indentation below (yeuckkk) ...
+ }
transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ // There's a bug in Java 5 re this code (formatting).
+ // See http://forum.java.sun.com/thread.jspa?threadID=562510&start=0
+ // and it explains the
+ // whys of the following code.
transformer.setOutputProperty(
"{http://xml.apache.org/xalan}indent-amount", "4");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- transformer.transform(source, new StreamResult(outStream));
+ transformer.setErrorListener(new NullErrorListener());
+ transformer.transform(source, new StreamResult(outStream));
return outStream.toString();
}
@@ -292,9 +297,17 @@
}
}
- private static TransformerFactory factory = TransformerFactory.newInstance();
+ private static TransformerFactory factory = TransformerFactory.newInstance();
+ private static class NullErrorListener implements ErrorListener {
+ public void warning(TransformerException exception) throws TransformerException {
+ }
+ public void error(TransformerException exception) throws TransformerException {
+ }
+ public void fatalError(TransformerException exception) throws TransformerException {
+ }
+ }
- private static final SimpleDateFormat s_oTS = new SimpleDateFormat(
+ private static final SimpleDateFormat s_oTS = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss.SSS");
} // ____________________________________________________________________________
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/smooks-res.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/smooks-res.xml 2007-05-30 13:19:46 UTC (rev 12236)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/smooks-res.xml 2007-05-30 13:29:11 UTC (rev 12237)
@@ -1,9 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
-<!DOCTYPE smooks-resource-list PUBLIC "-//MILYN//DTD SMOOKS 1.0//EN" "http://www.milyn.org/dtd/smooksres-list-1.0.dtd">
-<smooks-resource-list>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
- <smooks-resource useragent="from-type:text/csv:order-list AND to-type:text/xml:smooks-order-xml" selector="org.xml.sax.driver" path="org.milyn.csv.CSVParser" >
- <param name="fields" type="string-list">
+ <resource-config target-profile="from-type:text/csv:order-list AND to-type:text/xml:smooks-order-xml" selector="org.xml.sax.driver">
+ <resource>org.milyn.csv.CSVParser</resource>
+ <param name="fields" type="string-list">
orderId,
orderDate,
statusCode,
@@ -25,38 +25,32 @@
orderLine2ProductTitle,
orderLine2ProductPrice
</param>
- </smooks-resource>
+ </resource-config>
- <smooks-resource useragent="from-type:text/xml:smooks-order-xml AND to-type:text/xml:canonical-order-xml" selector="csv-set" path="See 'resdata' parameter value" >
- <!--param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[XSLT (Templatelet)]]></param-->
- <param name="encoding">UTF-8</param>
- <param name="visitBefore">false</param>
- <param name="is-xslt-templatelet">true</param>
- <param name="restype">xsl</param>
- <param name="action">replace</param>
- <param name="encoding">UTF-8</param>
- <param name="resdata">
- <![CDATA[
- <xsl:for-each select="csv-record">
- <Order orderId="{orderId}"
- orderDate="{orderDate}"
- statusCode="{statusCode}"
- netAmount="{netAmount}"
- totalAmount="{totalAmount}"
- tax="{tax}" >
- <Customer userName="{userName}" firstName="{firstName}" lastName="{lastName}" state="{state}" />
- <OrderLines>
- <OrderLine posistion="{orderLine1Position}" quantity="{orderLine1Quantity}">
- <Product productId="{orderLine1ProductId}" title="{orderLine1Title}" price="{orderLine1Price}"/>
- </OrderLine>
- <OrderLine posistion="{orderLine1Position}" quantity="{orderLine1Quantity}">
- <Product productId="{orderLine1ProductId}" title="{orderLine1Title}" price="{orderLine1Price}"/>
- </OrderLine>
- </OrderLines>
- </Order>
- </xsl:for-each>
- ]]>
- </param>
- </smooks-resource>
+ <resource-config target-profile="from-type:text/xml:smooks-order-xml AND to-type:text/xml:canonical-order-xml" selector="csv-set">
+ <resource type="xsl">
+ <![CDATA[
+ <xsl:for-each select="csv-record">
+ <Order orderId="{orderId}"
+ orderDate="{orderDate}"
+ statusCode="{statusCode}"
+ netAmount="{netAmount}"
+ totalAmount="{totalAmount}"
+ tax="{tax}" >
+ <Customer userName="{userName}" firstName="{firstName}" lastName="{lastName}" state="{state}" />
+ <OrderLines>
+ <OrderLine posistion="{orderLine1Position}" quantity="{orderLine1Quantity}">
+ <Product productId="{orderLine1ProductId}" title="{orderLine1Title}" price="{orderLine1Price}"/>
+ </OrderLine>
+ <OrderLine posistion="{orderLine1Position}" quantity="{orderLine1Quantity}">
+ <Product productId="{orderLine1ProductId}" title="{orderLine1Title}" price="{orderLine1Price}"/>
+ </OrderLine>
+ </OrderLines>
+ </Order>
+ </xsl:for-each>
+ ]]>
+ </resource>
+ <param name="is-xslt-templatelet">true</param>
+ </resource-config>
</smooks-resource-list>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/smooks-res.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/smooks-res.xml 2007-05-30 13:19:46 UTC (rev 12236)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/smooks-res.xml 2007-05-30 13:29:11 UTC (rev 12237)
@@ -1,32 +1,30 @@
-<?xml version="1.0"?>
-<!DOCTYPE smooks-resource-list PUBLIC "-//MILYN//DTD SMOOKS 1.0//EN" "http://www.milyn.org/dtd/smooksres-list-1.0.dtd">
-<smooks-resource-list>
+<?xml version='1.0' encoding='UTF-8'?>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
- <smooks-resource selector="org.xml.sax.driver" useragent="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice" path="org.milyn.smooks.edi.SmooksEDIParser" >
- <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[EDI Message Parser]]></param>
+ <resource-config selector="org.xml.sax.driver" target-profile="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice">
+ <resource>org.milyn.smooks.edi.SmooksEDIParser</resource>
+ <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[EDI Message Parser]]></param>
<param name="mapping-model"><![CDATA[/org/jboss/xtrans/edi-to-xml-order-mapping.xml]]></param>
- </smooks-resource>
+ </resource-config>
- <smooks-resource selector="date" useragent="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice" path="org/jboss/xtrans/DateFormatter.groovy" >
- <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[Groovy Script (External)]]></param>
- <param name="restype"><![CDATA[groovy]]></param>
+ <resource-config selector="date" target-profile="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice">
+ <resource>org/jboss/xtrans/DateFormatter.groovy</resource>
+ <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[Groovy Script (External)]]></param>
<param name="input-format"><![CDATA[EEE MMM dd HH:mm:ss z yyyy]]></param>
- </smooks-resource>
+ </resource-config>
- <smooks-resource selector="state" useragent="from-type:text/xml:fullFillOrder AND from:DVDStore:OrderDispatchService AND to-type:text/xml:shipOrder AND to:DVDWarehouse_1:OrderHandlingService" path="/org/jboss/xtrans/EnrichmentProcessor.groovy" >
- <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[Groovy Script (External)]]></param>
- <param name="restype"><![CDATA[groovy]]></param>
+ <resource-config selector="state" target-profile="from-type:text/xml:fullFillOrder AND from:DVDStore:OrderDispatchService AND to-type:text/xml:shipOrder AND to:DVDWarehouse_1:OrderHandlingService">
+ <resource>/org/jboss/xtrans/EnrichmentProcessor.groovy</resource>
+ <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[Groovy Script (External)]]></param>
<param name="enrichments-uri"><![CDATA[/org/jboss/xtrans/us-state-codes.properties]]></param>
- </smooks-resource>
+ </resource-config>
- <smooks-resource selector="order" useragent="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice" path="org/jboss/xtrans/dispatch-to-handling.xsl" >
- <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[XSLT (Full Stylesheet - External)]]></param>
+ <resource-config selector="order" target-profile="from-type:text/xml:fullfillorder and from:dvdstore:orderdispatchservice and to-type:text/xml:shiporder and to:dvdwarehouse_1:orderhandlingservice">
+ <resource>org/jboss/xtrans/dispatch-to-handling.xsl</resource>
+ <param name="RESERVED:RESOURCE_NAME_PARAM"><![CDATA[XSLT (Full Stylesheet - External)]]></param>
<param name="encoding"><![CDATA[UTF-8]]></param>
- <param name="visitBefore"><![CDATA[false]]></param>
-
<param name="is-xslt-templatelet"><![CDATA[false]]></param>
- <param name="restype"><![CDATA[xsl]]></param>
<param name="action"><![CDATA[replace]]></param>
- </smooks-resource>
+ </resource-config>
</smooks-resource-list>
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/DateFormatter.groovy
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/DateFormatter.groovy 2007-05-30 13:19:46 UTC (rev 12236)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/DateFormatter.groovy 2007-05-30 13:29:11 UTC (rev 12237)
@@ -4,8 +4,8 @@
import java.text.SimpleDateFormat;
import org.milyn.cdr.SmooksResourceConfiguration;
-import org.milyn.container.ContainerRequest;
-import org.milyn.delivery.assemble.AssemblyUnit;
+import org.milyn.container.ExecutionContext;
+import org.milyn.delivery.dom.DOMElementVisitor;
import org.milyn.xml.DomUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -15,7 +15,7 @@
* Date Formatting class.
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-public class DateFormatter implements AssemblyUnit {
+public class DateFormatter implements DOMElementVisitor {
private SimpleDateFormat dateDecodeFormat;
private Properties outputFields;
@@ -30,7 +30,12 @@
outputFields = parseOutputFields(outputFormats);
}
- public void visit(Element element, ContainerRequest request) {
+ public void visitBefore(Element element, ExecutionContext execContext) {
+ // Not doing anything on this event - wait until after we've visited
+ // this elements child content...
+ }
+
+ public void visitAfter(Element element, ExecutionContext execContext) {
String dateString = null;
Date date = null;
@@ -68,8 +73,4 @@
properties.load(new ByteArrayInputStream(outputFormats.getBytes()));
return properties;
}
-
- public boolean visitBefore() {
- return false;
- }
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/EnrichmentProcessor.groovy
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/EnrichmentProcessor.groovy 2007-05-30 13:19:46 UTC (rev 12236)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_EDI2XML_Groovy_XSLT/src/org/jboss/xtrans/EnrichmentProcessor.groovy 2007-05-30 13:29:11 UTC (rev 12237)
@@ -25,8 +25,8 @@
import org.milyn.cdr.SmooksConfigurationException;
import org.milyn.cdr.SmooksResourceConfiguration;
-import org.milyn.container.ContainerRequest;
-import org.milyn.delivery.process.ProcessingUnit;
+import org.milyn.container.ExecutionContext;
+import org.milyn.delivery.dom.DOMElementVisitor;
import org.milyn.resource.URIResourceLocator;
import org.milyn.xml.DomUtils;
import org.w3c.dom.Element;
@@ -35,7 +35,7 @@
* Sample "simple" enrichment Java based processing unit.
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-public class EnrichmentProcessor implements ProcessingUnit {
+public class EnrichmentProcessor implements DOMElementVisitor {
private static final String ENRICHMENTS_URI = "enrichments-uri";
private Properties enrichments = new Properties();
@@ -59,7 +59,10 @@
attributeName = config.getStringParameter("attribute-name");
}
- public void visit(Element element, ContainerRequest request) {
+ public void visitBefore(Element element, ExecutionContext execContext) {
+ // We'll perfom the enrichment process as soon as we encouter the element
+ // and before we process the element's child nodes.
+
if(attributeName != null) {
String enrichmentKey = element.getAttribute(attributeName);
if(enrichmentKey != null) {
@@ -80,9 +83,6 @@
}
}
- public boolean visitBefore() {
- // We'll perfom the enrichment process as soon as we encouter the element
- // and before we process the element's child nodes.
- return true;
+ public void visitAfter(Element element, ExecutionContext execContext) {
}
}
More information about the jboss-svn-commits
mailing list