01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19: package de.schlund.pfixcore.util;
20:
21: import java.io.File;
22:
23: import org.apache.tools.ant.BuildException;
24:
25: /**
26: * @author adam
27: *
28: * To change the template for this generated type comment go to
29: * Window - Preferences - Java - Code Generation - Code and Comments
30: */
31: public class XsltIWrapperTask extends XsltGenericTask {
32:
33: protected String packagename;
34: protected String classname;
35:
36: protected void doTransformation() throws BuildException {
37: try {
38: int sepPos = infilenameNoExt
39: .lastIndexOf(File.separatorChar);
40: if (sepPos > 0) {
41: // qualified package
42: packagename = infilenameNoExt.substring(0, sepPos);
43: classname = infilenameNoExt.substring(sepPos + 1);
44: } else {
45: // default package
46: packagename = "";
47: classname = infilenameNoExt;
48: }
49: packagename = packagename.replace(File.separatorChar, '.');
50: } catch (IndexOutOfBoundsException ioobe) {
51: // This should never happen
52: throw new BuildException("Input filename \"" + inname
53: + "\" is of unexpected form", ioobe);
54: }
55:
56: // For parameter names see example/core/build/iwrapper.xsl
57: // <xsl:param name="classname"/>
58: // <xsl:param name="package"/>
59: getTransformer().setParameter(
60: new XsltParam("classname", classname));
61: getTransformer().setParameter(
62: new XsltParam("package", packagename));
63: try {
64: getTransformer().transform(in, out);
65: } finally {
66: getTransformer().clearParameters();
67: }
68: }
69:
70: }
|