KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > XslpLiaison


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.taskdefs.optional;
19
20 import com.kvisco.xsl.XSLProcessor;
21 import com.kvisco.xsl.XSLReader;
22 import com.kvisco.xsl.XSLStylesheet;
23 import java.io.File JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.OutputStreamWriter JavaDoc;
26 import org.apache.tools.ant.taskdefs.XSLTLiaison;
27
28 /**
29  * Concrete liaison for XSLP
30  *
31  * @since Ant 1.1
32  */

33 public class XslpLiaison implements XSLTLiaison {
34
35     protected XSLProcessor processor;
36     protected XSLStylesheet xslSheet;
37
38     public XslpLiaison() {
39         processor = new XSLProcessor();
40         // uh ?! I'm forced to do that otherwise a setProperty crashes
41
// with NPE ! I don't understand why the property map is static
42
// though... how can we do multithreading w/ multiple identical
43
// parameters ?
44
processor.getProperty("dummy-to-init-properties-map");
45     }
46
47     public void setStylesheet(File JavaDoc fileName) throws Exception JavaDoc {
48         XSLReader xslReader = new XSLReader();
49         // a file:/// + getAbsolutePath() does not work here
50
// it is really the pathname
51
xslSheet = xslReader.read(fileName.getAbsolutePath());
52     }
53
54     public void transform(File JavaDoc infile, File JavaDoc outfile) throws Exception JavaDoc {
55         FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(outfile);
56         // XSLP does not support encoding...we're in hot water.
57
OutputStreamWriter JavaDoc out = new OutputStreamWriter JavaDoc(fos, "UTF8");
58         processor.process(infile.getAbsolutePath(), xslSheet, out);
59     }
60
61     public void addParam(String JavaDoc name, String JavaDoc expression) {
62         processor.setProperty(name, expression);
63     }
64
65 } //-- XSLPLiaison
66
Popular Tags