summaryrefslogtreecommitdiffstats
path: root/src/syntaxParser/WCPSRequestProcessor.java
diff options
context:
space:
mode:
authorConstantin Jucovschi <cj@ubuntu.localdomain>2009-03-31 06:18:54 -0400
committerConstantin Jucovschi <cj@ubuntu.localdomain>2009-03-31 06:18:54 -0400
commit0f1055b8d7f97d86c66fa602c17666bc2ff9c437 (patch)
tree9c68fa99a97063bbe4a4231e04fc09329541ac71 /src/syntaxParser/WCPSRequestProcessor.java
Initial commit
Diffstat (limited to 'src/syntaxParser/WCPSRequestProcessor.java')
-rw-r--r--src/syntaxParser/WCPSRequestProcessor.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/syntaxParser/WCPSRequestProcessor.java b/src/syntaxParser/WCPSRequestProcessor.java
new file mode 100644
index 0000000..c6fc86f
--- /dev/null
+++ b/src/syntaxParser/WCPSRequestProcessor.java
@@ -0,0 +1,46 @@
+package syntaxParser;
+/**
+ * WCPSRequestProcessor = Sample source code which makes use of the generated parser to parse a WCPS request stored in script file (request.wcps)
+ * The result XML ProcessCoverage file is stored in the file wcpsRequest.xml
+ * Creation date: (3/3/2003 3:22:26 AM)
+ * @author: mattia parigiani
+ */
+import java.io.*;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.*;
+import javax.xml.parsers.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.StreamResult;
+import org.w3c.dom.*;
+
+class WCPSRequestProcessor {
+
+ public static void main(String[] args){
+ try {
+ File inputFile = new File ("request.wcps");
+ WCPSParser parser= new WCPSParser(new WCPSScanner(new FileInputStream(inputFile)));
+ WCPSRequest pm= (WCPSRequest)parser.parse().value;
+ String xmlString=pm.toXML();
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ factory.setAttribute("indent-number", new Integer(4));
+ DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = docBuilder.parse(new ByteArrayInputStream(xmlString.getBytes()));
+ Transformer transformer = factory.newTransformer();
+ transformer.setOutputProperty("omit-xml-declaration","no");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(doc), new StreamResult(sw));
+ String formattedXML = sw.toString();
+
+ FileWriter fstream = new FileWriter("wcpsRequest.xml");
+ BufferedWriter out = new BufferedWriter(fstream);
+ out.write(formattedXML);
+ out.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}