View Javadoc

1   /***
2    * Copyright 2004 Fabrizio Giustina.
3    *
4    * Licensed under the Artistic License; you may not use this file
5    * except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://maven-taglib.sourceforge.net/license.html
9    *
10   * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12   * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13   */
14  package net.sf.maventaglib;
15  
16  import java.io.File;
17  
18  
19  /***
20   * Converter between dfferent versions of tlds.
21   * @author Fabrizio Giustina
22   * @version $Id: TaglibConvertPlugin.java,v 1.5 2005/08/23 12:29:52 fgiust Exp $
23   */
24  public class TaglibConvertPlugin extends TaglibPlugin
25  {
26  
27      /***
28       * output version for the converted tld.
29       */
30      private String outputVersion;
31  
32      /***
33       * input version for the converted tld.
34       */
35      private String inputVersion;
36  
37      /***
38       * Sets the output version for the converted tld.
39       * @param version output version for the converted tld
40       */
41      public void setOutputVersion(String version)
42      {
43          this.outputVersion = version;
44      }
45  
46      /***
47       * Sets the input version for the converted tld.
48       * @param version input version for the converted tld
49       */
50      public void setInputVersion(String version)
51      {
52          this.inputVersion = version;
53      }
54  
55      /***
56       * @see net.sf.maventaglib.TaglibPlugin#execute()
57       */
58      public void execute() throws Exception
59      {
60  
61          if (this.inputVersion == null)
62          {
63              throw new IllegalArgumentException("Input version not set.");
64          }
65          if (this.outputVersion == null)
66          {
67              throw new IllegalArgumentException("Output version not set.");
68          }
69  
70          String stylesheet = null;
71  
72          if ("1.2".equals(this.inputVersion) && "1.1".equals(this.outputVersion))
73          {
74              stylesheet = "/tld1_2-tld1_1.xsl";
75          }
76          else if ("1.1".equals(this.inputVersion) && "1.2".equals(this.outputVersion))
77          {
78              stylesheet = "/tld1_1-tld1_2.xsl";
79          }
80          else if ("1.2".equals(this.inputVersion) && "2.0".equals(this.outputVersion))
81          {
82              stylesheet = "/tld1_2-tld2_0.xsl";
83          }
84          else
85          {
86              throw new IllegalArgumentException("Conversion from version "
87                  + this.inputVersion
88                  + " to "
89                  + this.outputVersion
90                  + " not supported");
91          }
92  
93          File inputFile = new File(srcDir + "/" + tldSrc);
94          File outputFile = new File(outputDir + "/" + tldOut);
95  
96          echo("Generating " + tldOut + " [" + this.outputVersion + "] from " + tldSrc + " [" + this.inputVersion + "]");
97          applyXslt(inputFile, stylesheet, outputFile);
98      }
99  
100 }