Source Code Cross Referenced for Utility.java in  » Web-Framework » roma-webwizard » org » romaframework » core » 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 » Web Framework » roma webwizard » org.romaframework.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.romaframework.core;
018:
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:
022:        import org.romaframework.core.config.RomaApplicationContext;
023:
024:        public class Utility {
025:
026:            private static final String ASPECT = "aspect";
027:            public static final String ROMA_PACKAGE = "org.romaframework";
028:            public static final char PACKAGE_SEPARATOR = '.';
029:            public static final String PACKAGE_SEPARATOR_STRING = ".";
030:            public static final char PATH_SEPARATOR = '/';
031:            public static final String PATH_SEPARATOR_STRING = "/";
032:            public static final char WINDOWS_SEPARATOR = '\\';
033:            public static final String CLASSPATH_PREFIX = "classpath:";
034:            public static final String FILE_PREFIX = "file:";
035:
036:            public static URL loadURL(String iPath) {
037:                URL url = null;
038:                try {
039:                    if (iPath.startsWith(CLASSPATH_PREFIX)) {
040:                        // BUILD URL FROM CLASS LOADER
041:                        url = Utility.class.getClassLoader().getResource(
042:                                iPath.substring(CLASSPATH_PREFIX.length()));
043:                    } else if (iPath.startsWith(FILE_PREFIX)) {
044:                        // LOAD FILE DIRECTLY
045:                        url = new URL(iPath);
046:                    }
047:                } catch (MalformedURLException e) {
048:                }
049:                return url;
050:            }
051:
052:            public static String getClearName(String iJavaName) {
053:                StringBuffer buffer = new StringBuffer();
054:
055:                char c;
056:                buffer.append(Character.toUpperCase(iJavaName.charAt(0)));
057:                for (int i = 1; i < iJavaName.length(); ++i) {
058:                    c = iJavaName.charAt(i);
059:
060:                    if (Character.isUpperCase(c))
061:                        buffer.append(' ');
062:
063:                    buffer.append(c);
064:                }
065:
066:                return buffer.toString();
067:            }
068:
069:            public static boolean isRomaClass(Class iClass) {
070:                return iClass.getName().startsWith(ROMA_PACKAGE);
071:            }
072:
073:            public static String[] getResourceNamesFirstSeparator(
074:                    String iResourceName, String iSeparator,
075:                    String iDefaultPrefixName) {
076:                if (iResourceName == null)
077:                    return null;
078:
079:                String names[] = new String[2];
080:                int pos = iResourceName.indexOf(iSeparator);
081:                names[0] = pos > -1 ? iResourceName.substring(0, pos)
082:                        : iDefaultPrefixName;
083:
084:                names[1] = iResourceName.substring(pos + 1);
085:                return names;
086:            }
087:
088:            public static String[] getResourceNamesLastSeparator(
089:                    String iResourceName, String iSeparator,
090:                    String iDefaultPrefixName) {
091:                if (iResourceName == null)
092:                    return null;
093:
094:                String names[] = new String[2];
095:                int pos = iResourceName.lastIndexOf(iSeparator);
096:                names[0] = pos > -1 ? iResourceName.substring(0, pos)
097:                        : iDefaultPrefixName;
098:
099:                names[1] = iResourceName.substring(pos + 1);
100:                return names;
101:            }
102:
103:            /**
104:             * Get the full package of aspect inside user application.
105:             * 
106:             * @param iAspectName
107:             *          Aspect name
108:             * @return
109:             */
110:            public static String getApplicationAspectPackage(String iAspectName) {
111:                return RomaApplicationContext.getInstance()
112:                        .getApplicationPackage()
113:                        + PACKAGE_SEPARATOR + iAspectName;
114:            }
115:
116:            /**
117:             * Get the full package of aspect inside Roma.
118:             * 
119:             * @param iAspectName
120:             *          Aspect name
121:             * @return
122:             */
123:            public static String getRomaAspectPackage(String iAspectName) {
124:                return ROMA_PACKAGE + PACKAGE_SEPARATOR + ASPECT
125:                        + PACKAGE_SEPARATOR + iAspectName;
126:            }
127:
128:            /**
129:             * Convert a package path style in resource path style. If the path starts with ".", then it means relative path.
130:             * 
131:             * @param iClassPath
132:             * @return
133:             */
134:            public static String getAbsoluteResourcePath(String iClassPath) {
135:                int pos = iClassPath.indexOf(FILE_PREFIX);
136:                String prefix = pos > -1 ? iClassPath.substring(0, pos
137:                        + FILE_PREFIX.length()) : "";
138:                String data = pos > -1 ? iClassPath.substring(pos
139:                        + FILE_PREFIX.length()) : iClassPath;
140:
141:                if (data.startsWith("."))
142:                    // RELATIVE PATH: CHANGE IN ABSOLUTE
143:                    data = RomaApplicationContext.getApplicationPath()
144:                            + data.substring(1);
145:
146:                if (prefix.length() > 0 && data.charAt(0) != PATH_SEPARATOR)
147:                    data = PATH_SEPARATOR + data;
148:
149:                data = data.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
150:
151:                return prefix + data;
152:            }
153:
154:            /**
155:             * Convert a package path style in resource path style.
156:             * 
157:             * @param iClassPath
158:             * @return
159:             */
160:            public static String getPackagePath(String iResourcePath) {
161:                String path = iResourcePath.charAt(0) == PATH_SEPARATOR ? iResourcePath
162:                        .substring(1)
163:                        : iResourcePath;
164:                return path.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
165:            }
166:
167:            public static String getResourcePath(String iClassPath) {
168:                return iClassPath.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
169:            }
170:
171:            /**
172:             * Convert a package path style in resource path style.
173:             * 
174:             * @param iResourcePath
175:             * @return
176:             */
177:            public static String getUniversalResourcePath(String iResourcePath) {
178:                return iResourcePath.replace(WINDOWS_SEPARATOR, PATH_SEPARATOR);
179:            }
180:
181:            public static String getContainerFile(String filePath) {
182:                return filePath;
183:            }
184:
185:            public static String removeLastSeparatorIfAny(String entryName) {
186:                if (entryName.endsWith(PATH_SEPARATOR_STRING))
187:                    entryName = entryName.substring(0, entryName.length() - 1);
188:                return entryName;
189:            }
190:
191:            public static String filePatternToRegExp(String iPattern) {
192:                iPattern = iPattern.replace(".", "\\.");
193:                iPattern = iPattern.replace("*", ".*");
194:                return iPattern;
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.