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. package org.apache.tools.ant.taskdefs.optional;
  18. import com.kvisco.xsl.XSLProcessor;
  19. import com.kvisco.xsl.XSLReader;
  20. import com.kvisco.xsl.XSLStylesheet;
  21. import java.io.File;
  22. import java.io.FileOutputStream;
  23. import java.io.OutputStreamWriter;
  24. import org.apache.tools.ant.taskdefs.XSLTLiaison;
  25. /**
  26. * Concrete liaison for XSLP
  27. *
  28. * @since Ant 1.1
  29. */
  30. public class XslpLiaison implements XSLTLiaison {
  31. protected XSLProcessor processor;
  32. protected XSLStylesheet xslSheet;
  33. public XslpLiaison() {
  34. processor = new XSLProcessor();
  35. // uh ?! I'm forced to do that otherwise a setProperty crashes
  36. // with NPE ! I don't understand why the property map is static
  37. // though... how can we do multithreading w/ multiple identical
  38. // parameters ?
  39. processor.getProperty("dummy-to-init-properties-map");
  40. }
  41. public void setStylesheet(File fileName) throws Exception {
  42. XSLReader xslReader = new XSLReader();
  43. // a file:/// + getAbsolutePath() does not work here
  44. // it is really the pathname
  45. xslSheet = xslReader.read(fileName.getAbsolutePath());
  46. }
  47. public void transform(File infile, File outfile) throws Exception {
  48. FileOutputStream fos = new FileOutputStream(outfile);
  49. // XSLP does not support encoding...we're in hot water.
  50. OutputStreamWriter out = new OutputStreamWriter(fos, "UTF8");
  51. processor.process(infile.getAbsolutePath(), xslSheet, out);
  52. }
  53. public void addParam(String name, String expression) {
  54. processor.setProperty(name, expression);
  55. }
  56. } //-- XSLPLiaison