KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > ProjectTemplateFilter


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24
25 //
26
package org.enhydra.tool.codegen;
27
28 //
29
import org.enhydra.tool.ToolBoxInfo;
30 import org.enhydra.tool.common.Template;
31 import org.enhydra.tool.common.TemplateTool;
32 import org.enhydra.tool.common.TemplateFilter;
33 import org.enhydra.tool.common.PathHandle;
34
35 //
36
public class ProjectTemplateFilter implements TemplateFilter, Constants {
37     private TemplateTool tool = null;
38     private String JavaDoc destPath = null;
39     private String JavaDoc[] includes = new String JavaDoc[0];
40     private String JavaDoc[] excludes = new String JavaDoc[0];
41     private boolean tempIn = true;
42
43     public ProjectTemplateFilter(TemplateTool t, String JavaDoc dest) {
44         final String JavaDoc[] initExts = {
45             TYPE_TEMPLATE
46         };
47
48         tool = t;
49         tool.setInitExtensions(initExts);
50         tool.setInitDestination(dest);
51     }
52
53     public String JavaDoc getDestination() {
54         return tool.getInitDestination();
55     }
56
57     public boolean isIncludeTemplate() {
58         return tempIn;
59     }
60
61     public void setIncludeTemplate(boolean b) {
62         tempIn = b;
63     }
64
65     public TemplateTool getTemplateTool() {
66         return tool;
67     }
68
69     public String JavaDoc[] getOutputExcludes() {
70         return excludes;
71     }
72
73     public void setOutputExcludes(String JavaDoc[] ex) {
74         excludes = ex;
75     }
76
77     public void setInputIncludes(String JavaDoc[] in) {
78         includes = in;
79     }
80
81     public String JavaDoc[] getInputIncludes() {
82         return includes;
83     }
84
85     public boolean accept(Template template) {
86         int index = -1;
87         boolean include = false;
88         boolean dir = false;
89         PathHandle path = null;
90         String JavaDoc ext = new String JavaDoc();
91
92         if (template.isDirectory()) {
93             include = tempIn;
94             dir = true;
95         } else {
96             path = PathHandle.createPathHandle(template.toString());
97             ext = path.getExtension();
98             if (tempIn) {
99                 include = ext.startsWith(TYPE_TEMPLATE) && includeInput(ext);
100             } else {
101                 include = (!ext.startsWith(TYPE_TEMPLATE))
102                           && includeInput(ext);
103             }
104         }
105         if (include) {
106             path = PathHandle.createPathHandle(template.getOutput());
107             if (path.getPath() == null) {
108                 tool.initOutput(template);
109                 path = PathHandle.createPathHandle(template.getOutput());
110             }
111             ext = path.getExtension();
112             index = ext.indexOf('-');
113             if (index > -1) {
114                 path.setExtension(ext.substring(0, index));
115                 template.setOutput(path.getFile());
116             }
117             include = (!path.endsWith(getOutputExcludes()));
118         }
119         return include;
120     }
121
122     private boolean includeInput(String JavaDoc input) {
123         boolean include = false;
124         int index = -1;
125         String JavaDoc suffix = new String JavaDoc();
126
127         if (input == null) {
128             include = false;
129         } else {
130             index = input.indexOf('-');
131             if (index > 0) {
132                 suffix = input.substring(index);
133                 for (int i = 0; i < getInputIncludes().length; i++) {
134                     if (suffix.equalsIgnoreCase('-'
135                                                 + getInputIncludes()[i])) {
136                         include = true;
137                         break;
138                     }
139                 }
140             } else {
141                 include = true;
142             }
143         }
144         return include;
145     }
146
147 }
148
Popular Tags