View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2005 Open World Ltd
4   // Copyright (C) 2005 Kevin Rogers
5   //
6   // This file is part of MillScript.
7   //
8   // MillScript is free software; you can redistribute it and/or modify it under
9   // the terms of the GNU General Public License as published by the Free
10  // Software Foundation; either version 2 of the License, or (at your option)
11  // any later version.
12  //
13  // MillScript is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  // more details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA  02111-1307  USA
21  ////////////////////////////////////////////////////////////////////////////////
22  package org.millscript.millscript.render;
23  
24  import org.millscript.commons.vfs.VFile;
25  import org.millscript.millscript.conf.Configuration;
26  import org.millscript.millscript.datatypes.XmlComment;
27  
28  import java.io.IOException;
29  
30  /**
31   * This class implements MillScripts XSLT renderer. It renders to the XSLT 1.0
32   * specification, but may not always render valid XSLT 1.0.
33   * <p>
34   * The main issue with writing valid XSLT documents is exactly the same as with
35   * XML documents, so please read the documentation for the XML10Renderer class.
36   * </p>
37   * <p>
38   * The difference between an XML renderer and an XSLT renderer is that XML
39   * comments are rendered differently. For XSLT, an XML comment is rendered as
40   * and XSLT &lt;xsl:comment&gt; tag. The means that an XML comment rendered
41   * as XSLT via MillScript will be preserved through the XSLT transformation.
42   * </p>
43   */
44  public final class XSLTRenderer extends XML10Renderer {
45  
46      /**
47       * Constructs a new XSLT renderer, to render to the specified virtual file
48       * using the given confguration.
49       *
50       * @param conf  the configuration to get rendering parameters from
51       * @param file  the virtual output file
52       */
53      public XSLTRenderer( final Configuration conf, final VFile file ) {
54          super( conf, file );
55      }
56  
57      /**
58       * @see org.millscript.millscript.render.Renderer#renderXMLComment(org.millscript.millscript.datatypes.XmlComment)
59       */
60      @Override
61      public void renderXMLComment( final XmlComment c ) throws IOException {
62          // We specifically render a normal XML comment using the XSLT comment
63          // element, as XML comments in the input should be preserved through
64          // the output. e.g. consider an XML comment containing some JavaScript
65          // in a template, which is rendered into XSLT in the output. We would
66          // want the XML comment to appear in the output of the XSLT renderer so
67          // the JavaScript would still work.
68          this.appendNoEscape( "<xsl:comment>" );
69          this.append( c.getText() );
70          this.appendNoEscape( "</xsl:comment>" );
71      }
72  
73  }