root/trunk/src/java/org/jcoderz/commons/taskdefs/SaxonTask.java

Revision 1011, 4.7 kB (checked in by amandel, 4 years ago)

Aligned svn keyword settings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 *
4 * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *    * Redistributions of source code must retain the above copyright
11 *      notice, this list of conditions and the following disclaimer.
12 *    * Redistributions in binary form must reproduce the above
13 *      copyright notice, this list of conditions and the following
14 *      disclaimer in the documentation and/or other materials
15 *      provided with the distribution.
16 *    * Neither the name of the jCoderZ.org Project nor the names of
17 *      its contributors may be used to endorse or promote products
18 *      derived from this software without specific prior written
19 *      permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33package org.jcoderz.commons.taskdefs;
34
35import java.io.File;
36import java.io.IOException;
37import org.apache.tools.ant.BuildException;
38import org.apache.tools.ant.Project;
39import org.apache.tools.ant.taskdefs.Java;
40import org.jcoderz.commons.util.IoUtil;
41
42
43/**
44 * Ant task wrapper for Saxon.
45 *
46 * @author Michael Griffel
47 */
48public class SaxonTask
49      extends Java
50{
51   private static final String SAXON_TRANSFORMER = "com.icl.saxon.StyleSheet";
52   /** The output file. */
53   private File mOutFile;
54   /** The input file. */
55   private File mInFile;
56   /** The XSL stylesheet file. */
57   private File mXslFile;
58   private File mHtmlStyleSheet;
59   private boolean mHaveRenderX;
60
61   /**
62    * Constructor.
63    */
64   public SaxonTask ()
65   {
66      super();
67      super.setClassname(SAXON_TRANSFORMER);
68      // defaults
69      setFork(true);
70      setFailonerror(true);
71   }
72
73   /**
74    * Sets the XML input file that contains the document.
75    * @param f the XML input file (log message info).
76    */
77   public void setIn (File f)
78   {
79      mInFile = f;
80
81   }
82
83   /**
84    * Set the destination file into which the result is written.
85    * @param f the name of the destination file.
86    **/
87   public void setOut (File f)
88   {
89       mOutFile = f;
90   }
91
92   /**
93    * Sets the XSL stylesheet file.
94    * @param f the XSL stylesheet file.
95    */
96   public void setXsl (File f)
97   {
98      mXslFile = f;
99   }
100
101   /**
102    * Sets the CSS stylesheet file.
103    * @param f the CSS stylesheet file.
104    */
105   public void setCss (File f)
106   {
107      mHtmlStyleSheet = f;
108   }
109
110   /** {@inheritDoc} */
111   public void setClassname (String arg0)
112         throws BuildException
113   {
114      throw new BuildException("classname attribute is not allowed!");
115   }
116
117   public void setHaveRenderX (boolean b)
118   {
119      mHaveRenderX = b;
120   }
121
122
123   /** {@inheritDoc} */
124   public void execute ()
125         throws BuildException
126   {
127      createArg().setValue("-x");
128      createArg().setValue("org.apache.xml.resolver.tools.ResolvingXMLReader");
129
130      createArg().setValue("-y");
131      createArg().setValue("org.apache.xml.resolver.tools.ResolvingXMLReader");
132
133      createArg().setValue("-r");
134      createArg().setValue("org.apache.xml.resolver.tools.CatalogResolver");
135
136      createArg().setValue("-u");
137
138      createArg().setValue("-o");
139      createArg().setFile(mOutFile);
140      createArg().setValue(mInFile.toURI().toString());
141      createArg().setValue(mXslFile.toURI().toString());
142
143      createJvmarg().setValue("-Djava.awt.headless=true");
144
145      if (mHtmlStyleSheet != null)
146      {
147         log("Using CSS stylesheet " + mHtmlStyleSheet, Project.MSG_VERBOSE);
148         final File out = new File(
149               mOutFile.getParent(), mHtmlStyleSheet.getName());
150         try
151         {
152            IoUtil.copy(mHtmlStyleSheet, out);
153         }
154         catch (IOException e)
155         {
156            throw new BuildException("Failed to copy CSS stylesheet "
157                  + mHtmlStyleSheet + " to " + out, e);
158         }
159         createArg().setValue(
160               "html.stylesheet=" + out.getName());
161      }
162
163      if (mHaveRenderX)
164      {
165         createArg().setValue(
166               "xep.extensions=1");
167      }
168
169      super.execute();
170   }
171}
Note: See TracBrowser for help on using the browser.