Author: jeff.yuchang
Date: 2009-02-19 05:04:06 -0500 (Thu, 19 Feb 2009)
New Revision: 516
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/util/
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/util/XMLUtils.java
Modified:
cdl/trunk/install.xml
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/export/BPELLanguageModelStreamExportRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/generator/GeneratorTest.java
cdl/trunk/validator/jbossesb/pom.xml
Log:
* Fix the install.xml, update the validator jbossesb module name to cdl-jbossesb.
* Extract the XMLUtils.toText, so that the test class and the ExportRule can reuse.
Modified: cdl/trunk/install.xml
===================================================================
--- cdl/trunk/install.xml 2009-02-18 23:47:06 UTC (rev 515)
+++ cdl/trunk/install.xml 2009-02-19 10:04:06 UTC (rev 516)
@@ -34,7 +34,7 @@
<arg line="-c 'mvn install:install-file -DgroupId=org.eclipse.emf
-DartifactId=common -Dversion=2.3.0 -Dpackaging=jar
-Dfile=${libraries.dir}/eclipse-emf-common-2.3.0.jar'" />
</exec>
<exec executable="${shell}">
- <arg line="-c 'mvn install:install-file -DgroupId=org.eclipse.emf
-DartifactId=ecore -Dversion=2.3.1 -Dpackaging=jar
-Dfile=${libraries.dir}/eclipse-emf-common-2.3.0.jar'" />
+ <arg line="-c 'mvn install:install-file -DgroupId=org.eclipse.emf
-DartifactId=ecore -Dversion=2.3.1 -Dpackaging=jar
-Dfile=${libraries.dir}/eclipse-emf-ecore-2.3.1.jar'" />
</exec>
</target>
</project>
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/export/BPELLanguageModelStreamExportRule.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/export/BPELLanguageModelStreamExportRule.java 2009-02-18
23:47:06 UTC (rev 515)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/export/BPELLanguageModelStreamExportRule.java 2009-02-19
10:04:06 UTC (rev 516)
@@ -17,17 +17,17 @@
*/
package org.jboss.tools.overlord.cdl.bpel.export;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
-import org.jboss.tools.overlord.cdl.bpel.model.*;
-import org.scribble.export.*;
-import org.scribble.export.stream.*;
+import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
+import org.jboss.tools.overlord.cdl.bpel.model.BPELNotation;
+import org.jboss.tools.overlord.cdl.bpel.util.XMLUtils;
+import org.scribble.export.ExportRule;
+import org.scribble.export.ExporterContext;
+import org.scribble.export.Formatter;
+import org.scribble.export.stream.DefaultModelStreamExportRule;
import org.scribble.extensions.RegistryInfo;
-import org.scribble.model.*;
-import org.w3c.dom.Node;
+import org.scribble.model.ModelObject;
/**
* This class implements the stream based export rule for the
@@ -62,146 +62,12 @@
BPELLanguageModel model=(BPELLanguageModel)modelObject;
try {
- String text=getText(model.getBPELProcess());
-
+ String text=XMLUtils.toText(model.getBPELProcess());
context.getFormatter().record(text.getBytes());
} catch(Exception e) {
throw new java.io.IOException("Failed to get BPEL process text");
}
}
-
- /**
- * This class converts a DOM representation node to
- * text.
- *
- * @param node The DOM node
- * @return The text
- * @throws Exception Failed to convert
- */
- protected String getText(Node node) throws Exception {
- String ret=null;
-
- try {
- // Transform the DOM represent to text
- java.io.ByteArrayOutputStream xmlstr=
- new java.io.ByteArrayOutputStream();
-
- DOMSource source=new DOMSource();
- source.setNode(node);
-
- StreamResult result=new StreamResult(xmlstr);
-
- Transformer trans=
- TransformerFactory.newInstance().newTransformer();
- trans.transform(source, result);
-
- xmlstr.close();
-
- ret = new String(xmlstr.toByteArray());
-
- if ((node instanceof org.w3c.dom.Document) == false) {
-
- // Strip off any <?xml> header
- int index=ret.indexOf("<?xml");
- if (index != -1) {
- index = ret.indexOf("<", 1);
-
- if (index != -1) {
- ret = ret.substring(index);
- } else {
- index = ret.indexOf("?>");
-
- if (index != -1) {
- index += 2;
-
- // Remove any trailing whitespaces
- // after XML header
- while (index < ret.length() &&
- Character.isWhitespace(ret.charAt(index))) {
- index++;
- }
-
- ret = ret.substring(index);
- }
- }
- }
- }
- } catch(Exception e) {
- throw new Exception("Failed to transform " +
- "DOM representation into text", e);
- }
-
- int pos=0;
- int prevpos=0;
- StringBuffer buf=new StringBuffer();
- int level=0;
-
- while ((pos=ret.indexOf('<', prevpos)) != -1) {
-
- if (prevpos < pos &&
- ret.substring(prevpos, pos).trim().length() > 0 &&
- ret.charAt(prevpos-1) != '?') {
-
- if (ret.charAt(prevpos) == '\r' &&
- ret.charAt(prevpos+1) == '\n') {
- prevpos += 2;
- }
- for (int i=0; i < level; i++) {
- buf.append(" ");
- }
-
- buf.append(ret.substring(prevpos, pos).trim());
- buf.append("\r\n");
- }
-
- int endpos=ret.indexOf('>', pos);
-
- if (endpos > 0) {
- boolean noreturn=false;
-
- if (pos > 0 && ret.charAt(pos+1) == '/') {
- level--;
- }
-
- for (int i=0; i < level; i++) {
- buf.append(" ");
- }
- buf.append(ret.substring(pos, endpos+1));
-
- if (ret.charAt(endpos-1)== '?') {
- //noreturn = true;
-
- } else if (ret.charAt(endpos-1) == '/') {
- // Ignore
- } else if (pos > 0 && ret.charAt(pos+1) == '/') {
- // Ignore
-
- } else if (pos > 0 && ret.charAt(pos+1) == '!') {
- // Ignore
-
- } else {
- level++;
- }
-
- if (noreturn == false) {
- buf.append("\r\n");
- }
-
- pos = endpos+1;
- }
-
- prevpos = pos;
- }
-
- if (prevpos != -1 &&
- ret.substring(prevpos).trim().length() > 0) {
- buf.append(ret.substring(prevpos));
- }
-
- ret = buf.toString();
-
- return(ret);
- }
}
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/util/XMLUtils.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/util/XMLUtils.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/util/XMLUtils.java 2009-02-19
10:04:06 UTC (rev 516)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.tools.overlord.cdl.bpel.util;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public final class XMLUtils {
+
+ /**
+ * This class converts a DOM representation node to text.
+ * @param node
+ * @return
+ * @throws Exception
+ */
+ public static final String toText(Node node) throws Exception {
+ String ret = null;
+ try {
+ // Transform the DOM represent to text
+ ByteArrayOutputStream xmlstr= new ByteArrayOutputStream();
+ DOMSource source=new DOMSource();
+ source.setNode(node);
+
+ StreamResult result=new StreamResult(xmlstr);
+ Transformer trans= TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ ret = new String(xmlstr.toByteArray());
+
+ if ((node instanceof Document) == false) {
+ // Strip off any <?xml> header
+ int index=ret.indexOf("<?xml");
+ if (index != -1) {
+ index = ret.indexOf("<", 1);
+ if (index != -1) {
+ ret = ret.substring(index);
+ } else {
+ index = ret.indexOf("?>");
+ if (index != -1) {
+ index += 2;
+
+ // Remove any trailing whitespaces after XML header
+ while (index < ret.length() &&
+ Character.isWhitespace(ret.charAt(index))) {
+ index++;
+ }
+
+ ret = ret.substring(index);
+ }
+ }
+ }
+ }
+
+ } catch(Exception e) {
+ throw new Exception("Failed to transform DOM representation into text", e);
+ }
+ if (ret != null) {
+ return format(ret);
+ }
+ return ret;
+ }
+
+
+ /**
+ * Format the xml to well print.
+ *
+ * @param xmltext
+ * @return
+ */
+ public static final String format(String xmltext) {
+ String ret=xmltext;
+ int pos=0;
+ int prevpos=0;
+ StringBuffer buf=new StringBuffer();
+ int level=0;
+
+ while ((pos=ret.indexOf('<', prevpos)) != -1) {
+
+ if (prevpos < pos &&
+ ret.substring(prevpos, pos).trim().length() > 0 &&
+ ret.charAt(prevpos-1) != '?') {
+
+ if (ret.charAt(prevpos) == '\r' &&
+ ret.charAt(prevpos+1) == '\n') {
+ prevpos += 2;
+ }
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+
+ buf.append(ret.substring(prevpos, pos).trim());
+ buf.append("\r\n");
+ }
+
+ int endpos=ret.indexOf('>', pos);
+
+ if (endpos > 0) {
+ boolean noreturn=false;
+
+ if (pos > 0 && ret.charAt(pos+1) == '/') {
+ level--;
+ }
+
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+ buf.append(ret.substring(pos, endpos+1));
+
+ if (ret.charAt(endpos-1)== '?') {
+ //noreturn = true;
+
+ } else if (ret.charAt(endpos-1) == '/') {
+ // Ignore
+ } else if (pos > 0 && ret.charAt(pos+1) == '/') {
+ // Ignore
+
+ } else if (pos > 0 && ret.charAt(pos+1) == '!') {
+ // Ignore
+
+ } else {
+ level++;
+ }
+
+ if (noreturn == false) {
+ buf.append("\r\n");
+ }
+
+ pos = endpos+1;
+ }
+
+ prevpos = pos;
+ }
+
+ if (prevpos != -1 &&
+ ret.substring(prevpos).trim().length() > 0) {
+ buf.append(ret.substring(prevpos));
+ }
+
+ ret = buf.toString();
+
+ return(ret);
+ }
+
+ public static void main(String[] args) throws Exception {
+ String raw = "<?xml ?><books><book>The World is
Flat</book></books>";
+ String pretty = format(raw);
+ System.out.println(pretty);
+ }
+
+}
+
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/generator/GeneratorTest.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/generator/GeneratorTest.java 2009-02-18
23:47:06 UTC (rev 515)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/generator/GeneratorTest.java 2009-02-19
10:04:06 UTC (rev 516)
@@ -17,21 +17,18 @@
*/
package org.jboss.tools.overlord.cdl.bpel.generator;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
import org.jboss.tools.overlord.cdl.bpel.model.BPELNotation;
import org.jboss.tools.overlord.cdl.bpel.model.DefaultBPELLanguageModel;
+import org.jboss.tools.overlord.cdl.bpel.util.XMLUtils;
import org.scribble.conversation.model.ConversationNotation;
import org.scribble.extensions.RegistryFactory;
import org.scribble.model.ModelReference;
import org.scribble.model.change.ModelGenerator;
-import org.w3c.dom.Node;
-import junit.framework.*;
-
public class GeneratorTest extends TestCase {
public static TestSuite suite() {
@@ -101,8 +98,7 @@
if (target.getBPELProcess() != null) {
try {
- String text=getText(target.getBPELProcess(), true);
-
+ String text=XMLUtils.toText(target.getBPELProcess());
checkResults(result, text);
} catch(Exception e) {
result.addError(this, e);
@@ -165,171 +161,7 @@
"' not found for comparison"));
}
}
-
- /**
- * This class converts a DOM representation node to
- * text with appropriate presentation formatting.
- *
- * @param node The DOM node
- * @param pretty Whether to format the text for presentation
- * @return The text
- * @throws Exception Failed to convert
- */
- public static String getText(Node node, boolean pretty) throws Exception {
- String ret=getText(node);
-
- if (pretty) {
- ret = reformat(ret);
- }
-
- return(ret);
- }
- /**
- * This method reformats the XML text for presentation.
- *
- * @param xmltext The original XML text
- * @return The reformatted text
- */
- protected static String reformat(String xmltext) {
- String ret=xmltext;
- int pos=0;
- int prevpos=0;
- StringBuffer buf=new StringBuffer();
- int level=0;
-
- while ((pos=ret.indexOf('<', prevpos)) != -1) {
-
- if (prevpos < pos &&
- ret.substring(prevpos, pos).trim().length() > 0 &&
- ret.charAt(prevpos-1) != '?') {
-
- if (ret.charAt(prevpos) == '\r' &&
- ret.charAt(prevpos+1) == '\n') {
- prevpos += 2;
- }
- for (int i=0; i < level; i++) {
- buf.append(" ");
- }
-
- buf.append(ret.substring(prevpos, pos).trim());
- buf.append("\r\n");
- }
-
- int endpos=ret.indexOf('>', pos);
-
- if (endpos > 0) {
- boolean noreturn=false;
-
- if (pos > 0 && ret.charAt(pos+1) == '/') {
- level--;
- }
-
- for (int i=0; i < level; i++) {
- buf.append(" ");
- }
- buf.append(ret.substring(pos, endpos+1));
-
- if (ret.charAt(endpos-1)== '?') {
- //noreturn = true;
-
- } else if (ret.charAt(endpos-1) == '/') {
- // Ignore
- } else if (pos > 0 && ret.charAt(pos+1) == '/') {
- // Ignore
-
- } else if (pos > 0 && ret.charAt(pos+1) == '!') {
- // Ignore
-
- } else {
- level++;
- }
-
- if (noreturn == false) {
- buf.append("\r\n");
- }
-
- pos = endpos+1;
- }
-
- prevpos = pos;
- }
-
- if (prevpos != -1 &&
- ret.substring(prevpos).trim().length() > 0) {
- buf.append(ret.substring(prevpos));
- }
-
- ret = buf.toString();
-
- return(ret);
- }
-
- /**
- * This class converts a DOM representation node to
- * text.
- *
- * @param node The DOM node
- * @return The text
- * @throws Exception Failed to convert
- */
- public static String getText(Node node) throws Exception {
- String ret=null;
-
- try {
- // Transform the DOM represent to text
- java.io.ByteArrayOutputStream xmlstr=
- new java.io.ByteArrayOutputStream();
-
- DOMSource source=new DOMSource();
- source.setNode(node);
-
- StreamResult result=new StreamResult(xmlstr);
-
- Transformer trans=
- TransformerFactory.newInstance().newTransformer();
- trans.transform(source, result);
-
- xmlstr.close();
-
- ret = new String(xmlstr.toByteArray());
-
- if ((node instanceof org.w3c.dom.Document) == false) {
-
- // Strip off any <?xml> header
- int index=ret.indexOf("<?xml");
- if (index != -1) {
- index = ret.indexOf("<", 1);
-
- if (index != -1) {
- ret = ret.substring(index);
- } else {
- index = ret.indexOf("?>");
-
- if (index != -1) {
- index += 2;
-
- // Remove any trailing whitespaces
- // after XML header
- while (index < ret.length() &&
- Character.isWhitespace(ret.charAt(index))) {
- index++;
- }
-
- ret = ret.substring(index);
- }
- }
- }
- }
-
- } catch(Exception e) {
- throw new Exception("Failed to transform " +
- "DOM representation into text", e);
- }
-
- return(ret);
- }
-
private String m_name=null;
}
}
Modified: cdl/trunk/validator/jbossesb/pom.xml
===================================================================
--- cdl/trunk/validator/jbossesb/pom.xml 2009-02-18 23:47:06 UTC (rev 515)
+++ cdl/trunk/validator/jbossesb/pom.xml 2009-02-19 10:04:06 UTC (rev 516)
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.soa.overlord.cdl.validator</groupId>
- <artifactId>cdl-validator-jbossesb</artifactId>
+ <artifactId>cdl-jbossesb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Overlord::CDL::Validator::JBossESB</name>