View Javadoc

1   /*
2    * Copyright Emmanouil Batsis
3    * 
4    * Licensed under the GNU General Public 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.gnu.org/licenses/gpl.txt
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 com.geekologue.md4j.generators;
18  
19  import java.util.Map;
20  import org.apache.tools.ant.util.FileNameMapper;
21  import org.apache.tools.ant.util.RegexpPatternMapper;
22  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason;
23  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorTask;
24  
25  /***
26   * Creates View, Create or Update JSP 2.0 pages depending on the "actionType"
27   * XSLT param (see constructor. StrutsAction1Generator uses instances of this
28   * class as nested generators to create it's JSPs.
29   * 
30   * @author manos
31   */
32  public class StrutsAction1NestedJsp2Generator extends
33          AbstractXsltBasedGenerator implements HibernateMappingProcessorLiason {
34      private static final String XSLT_PATH = "md4j-strutsaction1-jsp2.xsl";
35  
36      /***
37       * 
38       */
39      public StrutsAction1NestedJsp2Generator(Map xslParams) {
40          super(StrutsAction1NestedJsp2Generator.XSLT_PATH);
41          this.styleParameters = xslParams;
42      }
43  
44      /***
45       * Equal to <regexpmapper handledirsep="true" from="(.*)/(.*).hbm.xml"
46       * to="jsp\2/@{actionType}.jsp" />
47       * 
48       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
49       */
50      public FileNameMapper getSimpleMapper() {
51          RegexpPatternMapper simpleMapper = new RegexpPatternMapper();
52          simpleMapper.setHandleDirSep(true);
53          simpleMapper.setFrom("(.*)/(.*).hbm.xml");
54          simpleMapper.setTo("jsp///2/" + this.styleParameters.get("actionType")
55                  + ".jsp");
56          return simpleMapper;
57      }
58  
59      /***
60       * 
61       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
62       */
63      public FileNameMapper getNestedMapper() {
64          throw new RuntimeException("Nested mapppers are yet to be suported");
65      }
66  
67      public void init(Map context) {
68          this.styleParameters.put("package", context.get("package"));
69          super.init(context);
70      }
71  }