commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gu...@apache.org
Subject svn commit: r951835 - in /commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram: ./ META-INF/ lib/ src/org/apache/commons/scxml/modeling/export/ xslt/
Date Sun, 06 Jun 2010 06:58:54 GMT
Author: guixl
Date: Sun Jun  6 06:58:53 2010
New Revision: 951835

URL: http://svn.apache.org/viewvc?rev=951835&view=rev
Log:
implement SCXML data model export function (not finished)

Added:
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/serializer.jar
  (with props)
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/xalan.jar
  (with props)
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
  (with props)
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl
  (with props)
Modified:
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/.classpath
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/build.properties
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java

Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/.classpath
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/.classpath?rev=951835&r1=951834&r2=951835&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/.classpath
(original)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/.classpath
Sun Jun  6 06:58:53 2010
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src"/>
+	<classpathentry exported="true" kind="lib" path="lib/serializer.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/xalan.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="output" path="bin"/>

Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF?rev=951835&r1=951834&r2=951835&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF
(original)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/META-INF/MANIFEST.MF
Sun Jun  6 06:58:53 2010
@@ -3,7 +3,9 @@ Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.apache.commons.scxml.modeling.diagram; singleton:=true
 Bundle-Version: 1.0.0.qualifier
-Bundle-ClassPath: .
+Bundle-ClassPath: .,
+ lib/xalan.jar,
+ lib/serializer.jar
 Bundle-Activator: org.apache.commons.scxml.modeling.diagram.part.ModelingDiagramEditorPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin

Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/build.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/build.properties?rev=951835&r1=951834&r2=951835&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/build.properties
(original)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/build.properties
Sun Jun  6 06:58:53 2010
@@ -4,7 +4,9 @@ bin.includes = .,\
                plugin.xml,\
                plugin.properties,\
                messages.properties,\
-               .options
+               .options,\
+               lib/xalan.jar,\
+               lib/serializer.jar
 jars.compile.order = .
 source.. = src/
 output.. = bin/

Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/serializer.jar
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/serializer.jar?rev=951835&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/serializer.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/xalan.jar
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/xalan.jar?rev=951835&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/lib/xalan.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java?rev=951835&r1=951834&r2=951835&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
(original)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
Sun Jun  6 06:58:53 2010
@@ -19,6 +19,7 @@ package org.apache.commons.scxml.modelin
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -167,7 +168,15 @@ public class ModelingDocumentExportWizar
 							.newErrorCommandResult(Messages.ModelingNewScxmlFileWizard_IncorrectRootError);
 				}
 				try {
-					xmlFile.setContents(modelFile.getContents(), 1, null);
+					//get target list by regular expression
+					ScxmlExportStreamHandlerAction shc=new ScxmlExportStreamHandlerAction(modelFile.getContents());
+					shc.getTargetList();
+					shc.transferToXpath();
+					shc.getIdMap(modelFile.getContents());
+					shc.updateTargetId();
+					System.out.println(shc.getStreamContnet());
+					String content=shc.ExecuteXSL(shc.getStreamContnet(),this.getClass().getClassLoader().getResourceAsStream("xslt/export.xsl"));
+					xmlFile.setContents(shc.string2InputStream(content), 1, null);
 				}  catch (CoreException e) {
 					e.printStackTrace();
 				}

Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java?rev=951835&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
(added)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
Sun Jun  6 06:58:53 2010
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.scxml.modeling.export;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.xpath.XPathAPI;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+import org.xml.sax.SAXException;
+
+/**
+ * Scxml document export wizard
+ * 
+ * @author Gui Xun Long (guixl@apache.org)
+ */
+public class ScxmlExportStreamHandlerAction {
+	private InputStream input;
+	private String streamContnet;
+	private ArrayList<XpathMapClass> targetList = new ArrayList<XpathMapClass>();
+
+	public InputStream getInput() {
+		return input;
+	}
+
+	public void setInput(InputStream input) {
+		this.input = input;
+	}
+
+	public String getStreamContnet() {
+		return streamContnet;
+	}
+
+	public void setStreamContnet(String streamContnet) {
+		this.streamContnet = streamContnet;
+	}
+
+	public ScxmlExportStreamHandlerAction(InputStream in) {
+		input = in;
+		inputStream2String(input);
+	}
+
+	public void getTargetList() {
+		String regx = "targetStatus=\"\\S+\"";
+		Pattern p = Pattern.compile(regx);
+		Matcher m = p.matcher(streamContnet);
+		while (m.find()) {
+			String each = m.group();
+			String target = each.substring(14, each.lastIndexOf("\""));
+			XpathMapClass map = new XpathMapClass();
+			map.setTarget(target);
+			targetList.add(map);
+		}
+	}
+
+	public void transferToXpath() {
+		for (int i = 0; i < targetList.size(); i++) {
+			XpathMapClass map = targetList.get(i);
+			String each = map.getTarget();
+			each = each.replace("//",
+					"/org.apache.commons.scxml:ServiceTemplate/");
+			each = each.replace("@", "");
+			for (int j = 1000; j >= 0; j--) {
+				if (each.indexOf("." + String.valueOf(j)) > -1)
+					each = each.replace("." + String.valueOf(j), "["
+							+ String.valueOf(j + 1) + "]");
+			}
+			map.setXpath(each);
+			targetList.set(i, map);
+		}
+	}
+
+	public void getIdMap(InputStream inputStream) {
+		DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+		dfactory.setNamespaceAware(true);
+		Document doc;
+		try {
+			doc = dfactory.newDocumentBuilder().parse(inputStream);
+			/*
+			 * Transformer serializer =
+			 * TransformerFactory.newInstance().newTransformer();
+			 * serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
+			 * "yes"); serializer.transform(new DOMSource(doc), new
+			 * StreamResult(new OutputStreamWriter(System.out)));
+			 */
+			for (int i = 0; i < targetList.size(); i++) {
+				XpathMapClass map = targetList.get(i);
+				String xpath = map.getXpath();
+				NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
+				Node n = nl.nextNode();
+				if (n != null) {
+					String id = ((Element) n).getAttribute("id");
+					map.setId(id);
+					targetList.set(i, map);
+				}
+			}
+		} catch (SAXException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
+		} catch (TransformerConfigurationException e) {
+			e.printStackTrace();
+		} catch (TransformerFactoryConfigurationError e) {
+			e.printStackTrace();
+		} catch (TransformerException e) {
+			e.printStackTrace();
+		}
+
+	}
+
+	/**
+	 * update target id info
+	 */
+	public void updateTargetId() {
+		for (int i = 0; i < targetList.size(); i++) {
+			XpathMapClass map = targetList.get(i);
+			String target = map.getTarget();
+			streamContnet = streamContnet.replace("targetStatus=\"" + target
+					+ "\"", "target=\"" + map.getId() + "\"");
+		}
+	}
+
+	/**
+	 * 
+	 * @param xmlFileContent
+	 * @param xslfile
+	 * @return XSLT transfer content
+	 */
+	public String ExecuteXSL(String xmlFileContent, InputStream xslfile) {
+		try {
+			ByteArrayOutputStream byteRep = new ByteArrayOutputStream();
+			TransformerFactory transformerFactory = TransformerFactory
+					.newInstance();
+			StreamSource source = new StreamSource(string2InputStream(xmlFileContent));
+			StreamResult result = new StreamResult(byteRep);
+			StreamSource style = new StreamSource(xslfile);
+			Transformer transformer = transformerFactory.newTransformer(style);
+			transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING, "utf-8"); // \u8BBE\u7F6E\u7F16\u7801
+			transformer.transform(source, result);
+			return byteRep.toString();
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+
+	}
+
+	public InputStream string2InputStream(String str) {
+		ByteArrayInputStream stream = null;
+		try {
+			stream = new ByteArrayInputStream(str.getBytes("UTF-8"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		if (stream != null)
+			return stream;
+		else {
+			System.out.println("stream is null");
+			return null;
+		}
+	}
+
+	public void inputStream2String(InputStream is) {
+		BufferedReader in = new BufferedReader(new InputStreamReader(is));
+		StringBuffer buffer = new StringBuffer();
+		String line = "";
+		try {
+			while ((line = in.readLine()) != null) {
+				buffer.append(line);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		streamContnet = buffer.toString();
+	}
+
+	class XpathMapClass {
+		private String target;
+		private String xpath;
+		private String id;
+
+		public String getTarget() {
+			return target;
+		}
+
+		public void setTarget(String target) {
+			this.target = target;
+		}
+
+		public String getXpath() {
+			return xpath;
+		}
+
+		public void setXpath(String xpath) {
+			this.xpath = xpath;
+		}
+
+		public String getId() {
+			return id;
+		}
+
+		public void setId(String id) {
+			this.id = id;
+		}
+	}
+}

Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl?rev=951835&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl
(added)
+++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl
Sun Jun  6 06:58:53 2010
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="xml" encoding="utf-8"/>
+
+<xsl:template match="/">
+	<xsl:element name="scxml">
+		<xsl:apply-templates/>
+	</xsl:element>
+</xsl:template>
+
+<xsl:template match="stateList">
+	<xsl:element name="state">
+		<xsl:attribute name="id"><xsl:value-of  select="@id"/></xsl:attribute>
+	</xsl:element>
+</xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file

Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/xslt/export.xsl
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message