incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvazq...@apache.org
Subject svn commit: r756250 - in /incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc: ./ src/main/java/org/apache/sling/scripting/xproc/xpl/ src/main/java/org/apache/sling/scripting/xproc/xpl/api/ src/main/java/org/apache/sling/scripting/xpro...
Date Thu, 19 Mar 2009 22:59:06 GMT
Author: jvazquez
Date: Thu Mar 19 22:59:05 2009
New Revision: 756250

URL: http://svn.apache.org/viewvc?rev=756250&view=rev
Log:
beginning with unit testing

Added:
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/XplBuilderTest.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/html.xpl
Modified:
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/pom.xml
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/XplBuilder.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/api/XplElement.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/AbstractXplElementImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/DocumentImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/InputImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/PipelineImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XplElementFactoryImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XsltImpl.java
    incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/html.xpl

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/pom.xml?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/pom.xml (original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/pom.xml Thu Mar 19
22:59:05 2009
@@ -101,6 +101,7 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        
         <!-- Testing -->
         <dependency>
             <groupId>org.apache.sling</groupId>
@@ -108,6 +109,13 @@
             <version>2.0.3-incubator-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+		<dependency>
+			<groupId>xmlunit</groupId>
+			<artifactId>xmlunit</artifactId>
+			<version>1.2</version>
+			<scope>test</scope>
+		</dependency>
+		
     </dependencies>
     
     <profiles>

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/XplBuilder.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/XplBuilder.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/XplBuilder.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/XplBuilder.java
Thu Mar 19 22:59:05 2009
@@ -57,8 +57,8 @@
 		return xplHandler.getRootStep();
 	}
 	
-	protected XplElement createXplElement(String localName, Map<String, String> parameters)
{
-        return XplBuilder.this.xplElementFactory.createXplElement(new QName(XplConstants.NS_XPROC,
localName), parameters);
+	protected XplElement createXplElement(String localName, Map<String, String> attributes)
{
+        return XplBuilder.this.xplElementFactory.createXplElement(new QName(XplConstants.NS_XPROC,
localName), attributes);
     }
 	
 	class XplHandler extends DefaultHandler {
@@ -95,13 +95,13 @@
 				throw new IllegalStateException("Expected 'pipeline' as first element, but received '"
+ localName + "'");
 			}
 			
-			Map<String, String> parameters = new HashMap<String, String>();
+			Map<String, String> atts = new HashMap<String, String>();
             int length = attributes.getLength();
             for (int i = 0; i < length; i++) {
-                parameters.put(attributes.getQName(i), attributes.getValue(i));
+            	atts.put(attributes.getQName(i), attributes.getValue(i));
             }
 			
-			XplElement xplElement = createXplElement(localName, parameters);
+			XplElement xplElement = createXplElement(localName, atts);
 			this.currentXplElement.addChild(xplElement);
 			this.currentXplElement = xplElement;
 		}

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/api/XplElement.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/api/XplElement.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/api/XplElement.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/api/XplElement.java
Thu Mar 19 22:59:05 2009
@@ -21,11 +21,15 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+import javax.xml.namespace.QName;
+
 public interface XplElement {
 	
+	QName getQName();
+	
 	XplElement getParent();
 	
-	void setParameters(Map<String, String> parameters);
+	void setAttributes(Map<String, String> attributes);
 	
 	void setParent(XplElement parent);
 	
@@ -33,4 +37,8 @@
 	
 	void addChild(XplElement child);
 	
+	int getDepth();
+
+	void setDepth(int depth);
+	
 }

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/AbstractXplElementImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/AbstractXplElementImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/AbstractXplElementImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/AbstractXplElementImpl.java
Thu Mar 19 22:59:05 2009
@@ -26,6 +26,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.xml.namespace.QName;
+
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.scripting.xproc.xpl.api.XplElement;
 import org.slf4j.Logger;
@@ -36,11 +38,11 @@
 	protected final Logger log = LoggerFactory.getLogger(this.getClass());
 	
 	private SlingScriptHelper sling;
-
-	private final Map<String, String> parameters = new HashMap<String, String>();

+	private final Map<String, String> attributes = new HashMap<String, String>();

 	private XplElement parent; 
 	private final LinkedList<XplElement> children = new LinkedList<XplElement>();
-	
+	private int depth = 0;
+
 	public LinkedList<XplElement> getChildren() {
 		return children;
 	}
@@ -63,45 +65,43 @@
             } catch (IllegalAccessException e) {
                 this.log.error("Failed to set child field for child class '" + child.getClass().getName(),
e);
             }
-        } else {
-            this.children.add(child);
         }
-		
+        child.setDepth(this.getDepth() + 1);
+        this.children.add(child);
 		child.setParent(this);
 		
 	}
 	
-	public void setParameters(Map<String, String> parameters) {
-		if (parameters == null || parameters.isEmpty()) {
+	public void setAttributes(Map<String, String> attributes) {
+		if (attributes == null || attributes.isEmpty()) {
             // nothing to do
             return;
         }
 
-        // check for special parameter fields
-        Map<String, Field> parameterFields = this.getParameterFields();
-        for (Entry<String, String> entry : parameters.entrySet()) {
+        // check for special attribute fields
+        Map<String, Field> attributeFields = this.getAttributeFields();
+        for (Entry<String, String> entry : attributes.entrySet()) {
             String key = entry.getKey();
             String value = entry.getValue();
 
-            Field parameterField = parameterFields.get(key);
-            if (parameterField != null) {
-                parameterField.setAccessible(true);
+            Field attributeField = attributeFields.get(key);
+            if (attributeField != null) {
+            	attributeField.setAccessible(true);
                 try {
-                    parameterField.set(this, value);
+                	attributeField.set(this, value);
                 } catch (IllegalArgumentException e) {
-                    String message = "Failed to set parameter field " + key;
+                    String message = "Failed to set attribute field " + key;
                     this.log.error(message, e);
                     throw new RuntimeException(message, e);
                 } catch (IllegalAccessException e) {
-                    String message = "Failed to set parameter field " + key;
+                    String message = "Failed to set attribute field " + key;
                     this.log.error(message, e);
                     throw new RuntimeException(message, e);
                 }
-                continue;
-            }
+             }
 
-            // default parameter processing
-            this.processParameter(key, value);
+            // default attribute processing
+            this.processAttribute(key, value);
         }
 	}
 	
@@ -109,6 +109,8 @@
 		return sling;
 	}
 	
+	public abstract QName getQName();
+	
 	public XplElement getParent() {
 		return parent;
 	}
@@ -117,8 +119,54 @@
 		this.parent = parent;
 	}
 	
-	protected void processParameter(String key, String value) {
-        this.parameters.put(key, value);
+	public int getDepth() {
+		return depth;
+	}
+
+	public void setDepth(int depth) {
+		this.depth = depth;
+	}
+	
+	@Override
+	public String toString() {
+		StringBuffer sbXplElement = new StringBuffer();
+//		if (getDepth() == 0)
+//			sbXplElement.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+//		addTabs(sbXplElement, getDepth());
+		sbXplElement.append("<");
+		sbXplElement.append("p:" + this.getQName().getLocalPart());
+		if (getDepth() == 0) {
+			sbXplElement.append(" xmlns:p=\"http://www.w3.org/ns/xproc\"");
+		}
+		for (String attribute : this.attributes.keySet()) {
+			sbXplElement.append(" ");
+			sbXplElement.append(attribute + "=" + "\"" + this.attributes.get(attribute) + "\"");
+		}
+		if (getChildren().size() == 0) {
+			sbXplElement.append(" />");
+			return sbXplElement.toString();
+		}
+		sbXplElement.append(">");
+		for (XplElement child : this.getChildren()) {
+//			sbXplElement.append("\r\n");
+			sbXplElement.append(child.toString());
+		}
+//		sbXplElement.append("\r\n");
+//		addTabs(sbXplElement, getDepth());
+		sbXplElement.append("</");
+		sbXplElement.append("p:" + this.getQName().getLocalPart());
+		sbXplElement.append(">");
+		
+		return sbXplElement.toString();
+	}
+	
+	private void addTabs(StringBuffer sb, int num) {
+		for (int i = 0; i < num; i++) 
+			sb.append("\t");
+	}
+	
+	protected void processAttribute(String key, String value) {
+        this.attributes.put(key, value);
     }
 	
 	private Field getChildField(XplElement child) {
@@ -134,21 +182,21 @@
         return null;
     }
 	
-    private Map<String, Field> getParameterFields() {
-        Map<String, Field> parameterFields = new HashMap<String, Field>();
+    private Map<String, Field> getAttributeFields() {
+        Map<String, Field> attributeFields = new HashMap<String, Field>();
 
         Class<?> currentClass = this.getClass();
         while (currentClass != null) {
             Field[] declaredFields = currentClass.getDeclaredFields();
             for (Field declaredField : declaredFields) {              
                 String fieldName = this.convertCamelCase(declaredField.getName());
-                parameterFields.put(fieldName, declaredField);
+                attributeFields.put(fieldName, declaredField);
             }
 
             currentClass = currentClass.getSuperclass();
         }
 
-        return parameterFields;
+        return attributeFields;
     }
 
     private String convertCamelCase(String name) {

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/DocumentImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/DocumentImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/DocumentImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/DocumentImpl.java
Thu Mar 19 22:59:05 2009
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.scripting.xproc.xpl.impl;
 
+import javax.xml.namespace.QName;
+
+import org.apache.sling.scripting.xproc.xpl.XplConstants;
 import org.apache.sling.scripting.xproc.xpl.api.Document;
 
 public class DocumentImpl extends AbstractXplElementImpl implements Document {
@@ -32,4 +35,9 @@
 		this.href = href;
 	}
 	
+	@Override
+	public QName getQName() {
+		return XplConstants.QNAME_DOCUMENT;
+	}
+	
 }

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/InputImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/InputImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/InputImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/InputImpl.java
Thu Mar 19 22:59:05 2009
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.scripting.xproc.xpl.impl;
 
+import javax.xml.namespace.QName;
+
+import org.apache.sling.scripting.xproc.xpl.XplConstants;
 import org.apache.sling.scripting.xproc.xpl.api.Document;
 import org.apache.sling.scripting.xproc.xpl.api.Input;
 
@@ -42,4 +45,9 @@
 		this.document = document;
 	}
 	
+	@Override
+	public QName getQName() {
+		return XplConstants.QNAME_INPUT;
+	}
+	
 }

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/PipelineImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/PipelineImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/PipelineImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/PipelineImpl.java
Thu Mar 19 22:59:05 2009
@@ -20,10 +20,13 @@
 
 import java.io.OutputStream;
 
+import javax.xml.namespace.QName;
+
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.component.sax.AbstractGenerator;
 import org.apache.cocoon.pipeline.component.sax.XMLSerializer;
 import org.apache.sling.scripting.xproc.cocoon.generator.SlingGenerator;
+import org.apache.sling.scripting.xproc.xpl.XplConstants;
 import org.apache.sling.scripting.xproc.xpl.api.Pipeline;
 import org.apache.sling.scripting.xproc.xpl.api.Step;
 
@@ -55,5 +58,10 @@
 		}
 		
 	}
+
+	@Override
+	public QName getQName() {
+		return XplConstants.QNAME_PIPELINE;
+	}
 	
 }
\ No newline at end of file

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XplElementFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XplElementFactoryImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XplElementFactoryImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XplElementFactoryImpl.java
Thu Mar 19 22:59:05 2009
@@ -28,7 +28,7 @@
 
 public class XplElementFactoryImpl implements XplElementFactory {
 	
-	public XplElement createXplElement(QName type, Map<String, String> parameters) {
+	public XplElement createXplElement(QName type, Map<String, String> attributes) {
 		
 		XplElement xplElement;
 		
@@ -44,7 +44,7 @@
 			throw new IllegalArgumentException("An xpl element of type '" + type + "' could not be
created.");
 		}
 		
-		xplElement.setParameters(parameters);
+		xplElement.setAttributes(attributes);
 		
 		return xplElement;
 	}

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XsltImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XsltImpl.java?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XsltImpl.java
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/scripting/xproc/xpl/impl/XsltImpl.java
Thu Mar 19 22:59:05 2009
@@ -18,7 +18,10 @@
  */
 package org.apache.sling.scripting.xproc.xpl.impl;
 
+import javax.xml.namespace.QName;
+
 import org.apache.sling.scripting.xproc.cocoon.transform.SlingTransformer;
+import org.apache.sling.scripting.xproc.xpl.XplConstants;
 import org.apache.sling.scripting.xproc.xpl.api.Input;
 import org.apache.sling.scripting.xproc.xpl.api.Xslt;
 
@@ -40,4 +43,9 @@
 		this.stylesheet = stylesheet;
 	}
 	
+	@Override
+	public QName getQName() {
+		return XplConstants.QNAME_XSLT;
+	}
+	
 }
\ No newline at end of file

Modified: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/html.xpl
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/html.xpl?rev=756250&r1=756249&r2=756250&view=diff
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/html.xpl
(original)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/html.xpl
Thu Mar 19 22:59:05 2009
@@ -29,4 +29,4 @@
     </p:input>
   </p:xslt>
   
-</p:pipeline>
+</p:pipeline>
\ No newline at end of file

Added: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/XplBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/XplBuilderTest.java?rev=756250&view=auto
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/XplBuilderTest.java
(added)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/java/org/apache/sling/scripting/xproc/xpl/XplBuilderTest.java
Thu Mar 19 22:59:05 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.sling.scripting.xproc.xpl;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.sling.scripting.xproc.xpl.api.Step;
+import org.custommonkey.xmlunit.XMLAssert;
+
+import junit.framework.TestCase;
+
+public class XplBuilderTest extends TestCase {
+	
+	public void testBuild() throws Exception {		
+		String xplPath = "/xpl/html.xpl";		
+		XplBuilder builder = new XplBuilder();
+		Step pipeline = builder.build(getReaderFromPath(xplPath));
+		System.out.println(pipeline.toString());
+		String kk1 = "<p:pipeline xmlns:p=\"http://www.w3.org/ns/xproc\"><p:xslt><p:input
port=\"stylesheet\"><p:document href=\"/xpl-sample/xsl/test-content.xslt\"/></p:input></p:xslt></p:pipeline>";
+		String kk2 = "<p:pipeline xmlns:p=\"http://www.w3.org/ns/xproc\"><p:xslt><p:input
port=\"stylesheet\"><p:document href=\"/xpl-sample/xsl/test-content.xslt\"/></p:input></p:xslt></p:pipeline>";
+		XMLAssert.assertXMLEqual(getReaderFromString(kk1), getReaderFromString(kk2));
+//		XMLAssert.assertXMLEqual(getReaderFromPath(xplPath), getReaderFromString(pipeline.toString()));
+	}
+	
+	private Reader getReaderFromPath(String path) throws Exception {
+		InputStream is = getClass().getResourceAsStream(path);
+		Reader reader = new BufferedReader(new InputStreamReader(is, "utf-8"));
+		return reader;
+	}
+	
+	private Reader getReaderFromString(String str) throws Exception {
+		return new BufferedReader(new StringReader(str));
+	}
+
+	private String readerToString(Reader reader) throws Exception {
+		StringWriter sw = new StringWriter();
+		BufferedWriter bfw = new BufferedWriter(sw);
+		int c;
+		while ((c = reader.read()) != -1) {
+			bfw.write(c);
+		}
+		bfw.flush();
+		return sw.getBuffer().toString();
+	}
+}

Added: incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/html.xpl
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/html.xpl?rev=756250&view=auto
==============================================================================
--- incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/html.xpl
(added)
+++ incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/test/resources/xpl/html.xpl
Thu Mar 19 22:59:05 2009
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<p:pipeline xmlns:p="http://www.w3.org/ns/xproc">
+
+  <p:xslt>
+    <p:input port="stylesheet">
+      <p:document href="/xpl-sample/xsl/test-content.xslt"/>
+    </p:input>
+  </p:xslt>
+  
+  <p:xslt>
+    <p:input port="stylesheet">
+      <p:document href="/xpl-sample/xsl/test-html.xslt"/>
+    </p:input>
+  </p:xslt>
+  
+</p:pipeline>



Mime
View raw message