Source Code Cross Referenced for Backward.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » enhydra IDE plugin » org.enhydra.kelp.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the license.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         *
021:         */
022:        package org.enhydra.kelp.common;
023:
024:        // ToolBox imports
025:        import org.enhydra.tool.common.PathHandle;
026:        import org.enhydra.tool.common.FileUtil;
027:        import org.enhydra.tool.common.ExtensionFilter;
028:        import org.enhydra.tool.configure.ConfigTool;
029:
030:        // Kelp imports
031:        import org.enhydra.kelp.common.Constants;
032:        import org.enhydra.kelp.common.importer.JavaFilter;
033:        import org.enhydra.kelp.common.node.OtterTemplateNode;
034:        import org.enhydra.kelp.common.node.OtterProject;
035:
036:        // Standard imports
037:        import java.io.BufferedReader;
038:        import java.io.IOException;
039:        import java.io.File;
040:        import java.io.FileFilter;
041:        import java.io.FileNotFoundException;
042:        import java.io.FileReader;
043:        import java.util.Vector;
044:
045:        //
046:        public class Backward {
047:
048:            // strings not to be resourced
049:            private final static String RELATIVE_CLASSES = "= ../classes";
050:
051:            //
052:            private Vector phVector = new Vector();
053:
054:            public static boolean createIsWebApp(String[] sourcePaths) {
055:                boolean webApp = true;
056:                PresentationFilter filter = new PresentationFilter();
057:
058:                for (int i = 0; i < sourcePaths.length; i++) {
059:                    File found = FileUtil.findFirst(filter, sourcePaths[i]);
060:
061:                    if (found != null) {
062:                        webApp = filter.isWebApp();
063:                        break;
064:                    }
065:                }
066:                return webApp;
067:            }
068:
069:            public static String createDefaultInputPath(String in,
070:                    String[] sourcePaths) {
071:                File file = null;
072:                String out = new String(in);
073:
074:                file = new File(out);
075:                if (file.isDirectory()) {
076:
077:                    // done
078:                } else if (file.getParentFile().exists()) {
079:                    file = new File(file.getParentFile(), Constants.DIR_INPUT);
080:                    if (file.exists()) {
081:                        out = file.getAbsolutePath();
082:
083:                        // done
084:                    } else {
085:                        ExtensionFilter filter = new ExtensionFilter();
086:                        StringBuffer mkIn = new StringBuffer();
087:
088:                        mkIn.append('.');
089:                        mkIn.append(Constants.TYPE_MK);
090:                        mkIn.append('.');
091:                        mkIn.append(Constants.TYPE_IN);
092:                        filter.setDirectoryValid(false);
093:                        filter.addExtension(Constants.TYPE_IN);
094:                        filter.addExclusion(mkIn.toString());
095:                        for (int i = 0; i < sourcePaths.length; i++) {
096:                            file = FileUtil.findFirst(filter, sourcePaths[i]);
097:                            if (file != null) {
098:                                out = file.getParent();
099:                                break;
100:                            }
101:                        }
102:                    }
103:                }
104:                out = PathHandle.createPathString(out);
105:                return out;
106:            }
107:
108:            public static String createDefaultBootstrapPath(String in,
109:                    OtterProject project) {
110:                String out = new String(in);
111:                String deployPath = new String();
112:                String inputPath = new String();
113:                File file = new File(out);
114:                BootstrapFilter filter = null;
115:
116:                if (file.isFile()) {
117:                    out = PathHandle.createPathString(file);
118:
119:                    // done
120:                } else {
121:                    deployPath = project.getDeployRootPath();
122:                    filter = new BootstrapFilter(false);
123:                    file = FileUtil.findFirst(filter, deployPath);
124:                    if (file != null && file.isFile()) {
125:                        out = PathHandle.createPathString(file);
126:
127:                        // done
128:                    } else {
129:                        inputPath = project.getDeployInputPath();
130:                        filter = new BootstrapFilter(true);
131:                        file = FileUtil.findFirst(filter, inputPath);
132:                        if (file != null && file.isFile()) {
133:                            out = PathHandle.createPathString(file);
134:                            out = deployPath
135:                                    + out.substring(inputPath.length(), out
136:                                            .length() - 3);
137:                        }
138:                    }
139:                }
140:                return out;
141:            }
142:
143:            public static String[][] createReplacementTable(String[][] tableIn,
144:                    OtterTemplateNode[] templates) {
145:                String[][] tableOut = new String[0][2];
146:                String[] placeholders = new String[0];
147:                Backward back = null;
148:
149:                back = new Backward();
150:                placeholders = back.findPlaceholders(templates);
151:                if (placeholders.length == 0) {
152:                    tableOut = tableIn;
153:                } else {
154:                    tableOut = new String[tableIn.length + placeholders.length][2];
155:                    for (int i = 0; i < placeholders.length; i++) {
156:                        tableOut[i][0] = placeholders[i];
157:
158:                        // strings not to be resourced
159:                        if (placeholders[i].equals(Backward.RELATIVE_CLASSES)) {
160:                            tableOut[i][1] = "= @JAVA_DEPLOY_PATH@/../classes";
161:                        } else if (placeholders[i].equals("@CLASSES@")) {
162:                            tableOut[i][1] = "@JAVA_DEPLOY_PATH@/../classes";
163:                        } else if (placeholders[i].equals("@SERVLET_CONF_DIR@")) {
164:                            tableOut[i][1] = "@JAVA_DEPLOY_PATH@/servlet";
165:                        } else if (placeholders[i].equals("@OUTPUT@")) {
166:                            tableOut[i][1] = "@JAVA_DEPLOY_PATH@";
167:                        } else {
168:                            tableOut[i][1] = placeholders[i];
169:                        }
170:                    }
171:                    for (int i = 0; i < tableIn.length; i++) {
172:                        tableOut[i + placeholders.length][0] = tableIn[i][0];
173:                        tableOut[i + placeholders.length][1] = tableIn[i][1];
174:                    }
175:                }
176:                return tableOut;
177:            }
178:
179:            private String[] findPlaceholders(OtterTemplateNode[] templates) {
180:                String placeholders[] = new String[0];
181:
182:                phVector.clear();
183:                for (int i = 0; i < templates.length; i++) {
184:                    findPlaceholdersInFile(templates[i].getFilePath());
185:                }
186:                placeholders = new String[phVector.size()];
187:                placeholders = (String[]) phVector.toArray(placeholders);
188:                phVector.clear();
189:                return placeholders;
190:            }
191:
192:            private void findPlaceholdersInFile(String path) {
193:                BufferedReader reader = null;
194:                File file = null;
195:                String line = null;
196:
197:                file = new File(path);
198:                if (file.isFile()) {
199:                    try {
200:                        reader = new BufferedReader(new FileReader(file));
201:                        line = reader.readLine();
202:                        while (line != null) {
203:                            findRelativeClasses(line);
204:                            findPlaceholdersInLine(line);
205:                            line = reader.readLine();
206:                        }
207:                        reader.close();
208:                    } catch (FileNotFoundException e) {
209:                        e.printStackTrace();
210:                    } catch (IOException e) {
211:                        e.printStackTrace();
212:                    }
213:                }
214:            }
215:
216:            private void findRelativeClasses(String line) {
217:                int index = line.indexOf(Backward.RELATIVE_CLASSES);
218:
219:                if (index > 0) {
220:                    if (!phVector.contains(Backward.RELATIVE_CLASSES)) {
221:                        phVector.insertElementAt(Backward.RELATIVE_CLASSES, 0);
222:                    }
223:                }
224:            }
225:
226:            private void findPlaceholdersInLine(String line) {
227:                String search = new String(line);
228:                String[] exclude = ConfigTool.getSuffixArray();
229:                StringBuffer ph = new StringBuffer();
230:                int index = -1;
231:                boolean start = false;
232:                boolean include = true;
233:
234:                index = search.indexOf('@');
235:                while (index > -1) {
236:                    if (start) {
237:                        ph.setLength(0);
238:                        ph.append('@');
239:                        ph.append(search.substring(0, index));
240:                        ph.append('@');
241:                        if (!phVector.contains(ph.toString())) {
242:                            include = true;
243:                            for (int i = 0; i < exclude.length; i++) {
244:                                if (ph.toString().endsWith(exclude[i])) {
245:                                    include = false;
246:                                    break;
247:                                }
248:                            }
249:                            if (include) {
250:                                phVector.addElement(ph.toString());
251:                            }
252:                        }
253:                    }
254:                    if (search.length() > index) {
255:                        search = search.substring(index + 1);
256:                    } else {
257:                        search = new String();
258:                    }
259:                    start = (!start);
260:                    index = search.indexOf('@');
261:                }
262:            }
263:
264:        }
265:
266:        //
267:        class BootstrapFilter implements  FileFilter {
268:            private boolean template = false;
269:
270:            public BootstrapFilter(boolean t) {
271:                template = true;
272:            }
273:
274:            public boolean accept(File file) {
275:                boolean accept = false;
276:                String path = file.getAbsolutePath().toLowerCase();
277:                StringBuffer multiserverBuf = new StringBuffer();
278:                StringBuffer servletBuf = new StringBuffer();
279:                StringBuffer kernelBuf = new StringBuffer();
280:                StringBuffer bootstrapBuf = new StringBuffer();
281:                StringBuffer bootstrap4Buf = new StringBuffer();
282:
283:                //
284:                multiserverBuf.append(Constants.FILE_MULTISERVER_CONF);
285:                servletBuf.append(Constants.FILE_SERVLET_CONF);
286:                kernelBuf.append(Constants.FILE_KERNEL_CONF);
287:                bootstrapBuf.append(Constants.FILE_BOOTSTRAP_CONF);
288:                bootstrap4Buf.append(Constants.FILE_BOOTSTRAP4_CONF);
289:                if (template) {
290:                    multiserverBuf.append('.');
291:                    multiserverBuf.append(Constants.TYPE_IN);
292:                    servletBuf.append('.');
293:                    servletBuf.append(Constants.TYPE_IN);
294:                    kernelBuf.append('.');
295:                    kernelBuf.append(Constants.TYPE_IN);
296:                    bootstrapBuf.append('.');
297:                    bootstrapBuf.append(Constants.TYPE_IN);
298:                    bootstrap4Buf.append('.');
299:                    bootstrap4Buf.append(Constants.TYPE_IN);
300:                }
301:                if (file.isFile()) {
302:                    if (path.endsWith(kernelBuf.toString())
303:                            || path.endsWith(bootstrapBuf.toString())
304:                            || path.endsWith(bootstrap4Buf.toString())) {
305:                        accept = true;
306:                    }
307:                }
308:                return accept;
309:            }
310:
311:        }
312:
313:        //
314:        class PresentationFilter extends JavaFilter {
315:
316:            // strings not to be resourced
317:            private final static String HTTP_PRESENTATION = "HttpPresentation";
318:            private final static String HTTP_SERVLET = "HttpServlet";
319:
320:            //
321:            private boolean webApp = true;
322:
323:            public boolean accept(File f) {
324:                boolean accept = super .accept(f);
325:
326:                if (accept && f.canRead()) {
327:                    accept = false;
328:                    BufferedReader reader = null;
329:                    String line = new String();
330:
331:                    try {
332:                        reader = new BufferedReader(new FileReader(f));
333:                        line = reader.readLine();
334:                        while (line != null) {
335:                            if (line.indexOf(HTTP_PRESENTATION) > -1) {
336:                                webApp = false;
337:                                accept = true;
338:                                break;
339:                            } else if (line.indexOf(HTTP_SERVLET) > -1) {
340:                                webApp = true;
341:                                accept = true;
342:                                break;
343:                            }
344:                            line = reader.readLine();
345:                        }
346:                        reader.close();
347:                    } catch (IOException e) {
348:                        e.printStackTrace();
349:                        accept = false;
350:                    }
351:                }
352:                return accept;
353:            }
354:
355:            protected boolean isWebApp() {
356:                return webApp;
357:            }
358:
359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.