Source Code Cross Referenced for JspNameMangler.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » jsp » 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 » Build » ANT » org.apache.tools.ant.taskdefs.optional.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant.taskdefs.optional.jsp;
019:
020:        import java.io.File;
021:
022:        /**
023:         * This is a class derived from the Jasper code
024:         * (org.apache.jasper.compiler.CommandLineCompiler) to map from a JSP filename
025:         * to a valid Java classname.
026:         *
027:         */
028:        public class JspNameMangler implements  JspMangler {
029:
030:            // CheckStyle:ConstantNameCheck OFF - bc
031:
032:            /**
033:             * this is the list of keywords which can not be used as classnames
034:             */
035:            public static final String[] keywords = { "assert", "abstract",
036:                    "boolean", "break", "byte", "case", "catch", "char",
037:                    "class", "const", "continue", "default", "do", "double",
038:                    "else", "extends", "final", "finally", "float", "for",
039:                    "goto", "if", "implements", "import", "instanceof", "int",
040:                    "interface", "long", "native", "new", "package", "private",
041:                    "protected", "public", "return", "short", "static",
042:                    "super", "switch", "synchronized", "this", "throw",
043:                    "throws", "transient", "try", "void", "volatile", "while" };
044:
045:            // CheckStyle:ConstantNameCheck ON
046:
047:            /**
048:             * map from a jsp file to a java filename; does not do packages
049:             *
050:             * @param jspFile file
051:             * @return java filename
052:             */
053:            public String mapJspToJavaName(File jspFile) {
054:                return mapJspToBaseName(jspFile) + ".java";
055:            }
056:
057:            /**
058:             * map from a jsp file to a base name; does not deal with extensions
059:             *
060:             * @param jspFile jspFile file
061:             * @return exensionless potentially remapped name
062:             */
063:            private String mapJspToBaseName(File jspFile) {
064:                String className;
065:                className = stripExtension(jspFile);
066:
067:                // since we don't mangle extensions like the servlet does,
068:                // we need to check for keywords as class names
069:                for (int i = 0; i < keywords.length; ++i) {
070:                    if (className.equals(keywords[i])) {
071:                        className += "%";
072:                        break;
073:                    }
074:                }
075:
076:                // Fix for invalid characters. If you think of more add to the list.
077:                StringBuffer modifiedClassName = new StringBuffer(className
078:                        .length());
079:                // first char is more restrictive than the rest
080:                char firstChar = className.charAt(0);
081:                if (Character.isJavaIdentifierStart(firstChar)) {
082:                    modifiedClassName.append(firstChar);
083:                } else {
084:                    modifiedClassName.append(mangleChar(firstChar));
085:                }
086:                // this is the rest
087:                for (int i = 1; i < className.length(); i++) {
088:                    char subChar = className.charAt(i);
089:                    if (Character.isJavaIdentifierPart(subChar)) {
090:                        modifiedClassName.append(subChar);
091:                    } else {
092:                        modifiedClassName.append(mangleChar(subChar));
093:                    }
094:                }
095:                return modifiedClassName.toString();
096:            }
097:
098:            /**
099:             * get short filename from file
100:             *
101:             * @param jspFile file in
102:             * @return file without any jsp extension
103:             */
104:            private String stripExtension(File jspFile) {
105:                String className;
106:                String filename = jspFile.getName();
107:                if (filename.endsWith(".jsp")) {
108:                    className = filename.substring(0, filename.length() - 4);
109:                } else {
110:                    className = filename;
111:                }
112:                return className;
113:            }
114:
115:            /**
116:             * definition of the char escaping algorithm
117:             *
118:             * @param ch char to mangle
119:             * @return mangled string; 5 digit hex value
120:             */
121:            private static String mangleChar(char ch) {
122:
123:                if (ch == File.separatorChar) {
124:                    ch = '/';
125:                }
126:                String s = Integer.toHexString(ch);
127:                int nzeros = 5 - s.length();
128:                char[] result = new char[6];
129:                result[0] = '_';
130:                for (int i = 1; i <= nzeros; ++i) {
131:                    result[i] = '0';
132:                }
133:                int resultIndex = 0;
134:                for (int i = nzeros + 1; i < 6; ++i) {
135:                    result[i] = s.charAt(resultIndex++);
136:                }
137:                return new String(result);
138:            }
139:
140:            /**
141:             * taking in the substring representing the path relative to the source dir
142:             * return a new string representing the destination path
143:             * not supported, as jasper in tomcat4.0 doesnt either
144:             * @param path not used
145:             * @return null always.
146:             */
147:            public String mapPath(String path) {
148:                return null;
149:            }
150:        }
w_ww__.j__a__v___a2_s.__c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.