cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r453749 - in /cocoon/trunk: commons/status.xml core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java
Date Fri, 06 Oct 2006 20:20:27 GMT
Author: jbq
Date: Fri Oct  6 13:20:27 2006
New Revision: 453749

URL: http://svn.apache.org/viewvc?view=rev&rev=453749
Log:
<action dev="JBQ" type="update" fixes-bug="COCOON-1706" due-to="Philippe Gassmann" due-to-email="philippe.gassmann@anyware-tech.com">
  Allow TeeTransformer to run a system command for debugging purposes
</action>

Modified:
    cocoon/trunk/commons/status.xml
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java

Modified: cocoon/trunk/commons/status.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/commons/status.xml?view=diff&rev=453749&r1=453748&r2=453749
==============================================================================
--- cocoon/trunk/commons/status.xml (original)
+++ cocoon/trunk/commons/status.xml Fri Oct  6 13:20:27 2006
@@ -178,6 +178,9 @@
   <!-- These are the changes from the last 2.1.x version. -->
  <changes>
   <release version="@version@" date="@date@">
+    <action dev="JBQ" type="update" fixes-bug="COCOON-1706" due-to="Philippe Gassmann"
due-to-email="philippe.gassmann@anyware-tech.com">
+      Allow TeeTransformer to run a system command for debugging purposes
+    </action>
     <action dev="JBQ" type="update">
       Ported various caching pipeline fixes and improvements from branch 2.1:
       <ul>

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java?view=diff&rev=453749&r1=453748&r2=453749
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/TeeTransformer.java
Fri Oct  6 13:20:27 2006
@@ -38,6 +38,7 @@
 import org.apache.excalibur.source.ModifiableSource;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.impl.FileSource;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -50,13 +51,16 @@
  * The Teetransformer serializes SAX events as-is to the {@link org.apache.excalibur.source.ModifiableSource}
  * specified by its <code>src</code> parameter. 
  * It does not in any way change the events. 
- * <p/>
- * This transformer works just like the unix "tee" command and is useful for debugging
- * received XML streams.
- * <p/>
+ * <p>This transformer works just like the unix "tee" command and is useful for debugging
+ * received XML streams.</p>
+ * <p>It is also able to launch an optional system command to view or edit the generated
file, so that every time the
+ * pipeline is executed, your editor pops up.</p>
+ *
  * Usage:<br>
  * <pre>
- * &lt;map:transform type="tee" src="url"/&gt;
+ * &lt;map:transform type="tee" src="url"&gt;
+ * &nbsp;&nbsp;&lt;command&gt;emacs %s&gt;
+ * &lt;/map:transform&gt;
  * </pre>
  * 
  * @version $Id$
@@ -71,9 +75,11 @@
 
     /** the resolver */
     private SourceResolver resolver;
-    
+
     private OutputStream os;
 
+    private String osCommand; 
+    private String fileName = null;
     /*
      * (non-Javadoc)
      * 
@@ -94,8 +100,13 @@
             if (!(source instanceof ModifiableSource)) {
                 throw new ProcessingException("Source '" + systemId + "' is not writeable.");
             }
+            if (this.osCommand != null) {
+                // FileSource is the only option when using the system command feature
+                fileName = ((FileSource)source).getFile().getAbsolutePath();
+            }
             this.serializer = this.transformerFactory.newTransformerHandler();
             os = ((ModifiableSource) source).getOutputStream();
+
             this.serializer.setResult(new StreamResult(os));
         } catch (SourceException e) {
             throw SourceUtil.handle(e);
@@ -117,6 +128,7 @@
      */
     public void configure(Configuration configuration) throws ConfigurationException {
         String tFactoryClass = configuration.getChild("transformer-factory").getValue(null);
+        this.osCommand = configuration.getChild("command").getValue(null);
         if (tFactoryClass != null) {
             try {
                 this.transformerFactory = (SAXTransformerFactory) ClassUtils
@@ -152,6 +164,7 @@
 
     /**
      * Receive notification of the end of a document.
+     * Optionally execute a command to view the output file
      */
     public void endDocument() throws SAXException {
         super.contentHandler.endDocument();
@@ -159,6 +172,15 @@
         if (os != null) {
             try {
                 os.close();
+
+                if (this.osCommand != null) {
+                    String command = this.osCommand.replace("%s", this.fileName);
+                    try {
+                        (Runtime.getRuntime()).exec(command,null);
+                    } catch(Exception e) {
+                        throw new CascadingRuntimeException("Unable to lauch the specified
program : "+command, e);
+                    }
+                }
             } catch (IOException e) {
                 throw new CascadingRuntimeException("Error closing output stream.", e);
             }



Mime
View raw message