Source Code Cross Referenced for Utils.java in  » J2EE » jag » com » finalist » jaggenerator » 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 » jag » com.finalist.jaggenerator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.jaggenerator;
019:
020:        import java.text.StringCharacterIterator;
021:
022:        /**
023:         *
024:         * @author  hillie
025:         */
026:        public class Utils {
027:
028:            public static String toClassName(String unformatted) {
029:                try {
030:                    if (unformatted.startsWith("T_")) {
031:                        unformatted = unformatted.substring(2);
032:                    }
033:                    String s = format(unformatted);
034:                    s = initCap(s);
035:                    return s;
036:                } catch (Exception e) {
037:                    return unformatted;
038:                }
039:            }
040:
041:            /**
042:             * Format the name by only allowing lowercase.
043:             */
044:            public static String formatLowercase(String unformatted) {
045:                try {
046:                    if (unformatted == null) {
047:                        return null;
048:                    }
049:                    StringBuffer sb = new StringBuffer(unformatted
050:                            .toLowerCase());
051:                    StringBuffer formattedString = new StringBuffer();
052:                    //remove underscores
053:                    for (int i = 0; i < sb.length(); i++) {
054:                        char c = sb.charAt(i);
055:                        if (c >= 'a' && c <= 'z') {
056:                            formattedString.append(c);
057:                        }
058:                    }
059:                    return formattedString.toString();
060:                } catch (Exception e) {
061:                    return unformatted;
062:                }
063:            }
064:
065:            /**
066:             * Format the name by only allowing lowercase and uppercase and 
067:             * always start with uppercase.
068:             */
069:            public static String formatLowerAndUpperCase(String unformatted) {
070:                try {
071:                    if (unformatted == null) {
072:                        return null;
073:                    }
074:                    StringBuffer sb = new StringBuffer(unformatted);
075:                    StringBuffer formattedString = new StringBuffer();
076:                    //remove underscores
077:                    for (int i = 0; i < sb.length(); i++) {
078:                        char c = sb.charAt(i);
079:                        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
080:                            formattedString.append(c);
081:                        }
082:                    }
083:                    return firstToUpperCase(formattedString.toString());
084:                } catch (Exception e) {
085:                    return unformatted;
086:                }
087:            }
088:
089:            public static String format(String unformatted) {
090:                try {
091:                    StringBuffer sb = new StringBuffer(unformatted
092:                            .toLowerCase());
093:                    //remove underscore and capitalize nest character
094:                    int i = sb.toString().indexOf("_");
095:                    while (i >= 0) {
096:                        if (i > -1)
097:                            sb.replace(i, i + 2, sb.substring(i + 1, i + 2)
098:                                    .toUpperCase());
099:                        i = sb.toString().indexOf("_");
100:                    }
101:                    //remove dash and capitalize nest character
102:                    i = sb.toString().indexOf("-");
103:                    while (i >= 0) {
104:                        if (i > -1)
105:                            sb.replace(i, i + 2, sb.substring(i + 1, i + 2)
106:                                    .toUpperCase());
107:                        i = sb.toString().indexOf("-");
108:                    }
109:                    return sb.toString();
110:                } catch (Exception e) {
111:                    return unformatted;
112:                }
113:            }
114:
115:            /**
116:             * Undoes a format.  Everything is capitalised and any uppercase character
117:             * forces a '_' to be prefixed, e.g. "theColumnName" is unformatted to "THE_COLUMN_NAME", and
118:             * "theATrain" unformats to "THE_A_TRAIN".
119:             * @param formatted
120:             * @return the unformatted String.
121:             */
122:            public static String unformat(String formatted) {
123:                StringBuffer result = new StringBuffer();
124:                for (int i = 0; i < formatted.length(); i++) {
125:                    if (Character.isUpperCase(formatted.charAt(i))) {
126:                        result.append('_');
127:                    }
128:                    result.append(Character.toUpperCase(formatted.charAt(i)));
129:                }
130:                return result.toString();
131:            }
132:
133:            public static String initCap(String unformatted) {
134:                StringBuffer sb = new StringBuffer(unformatted);
135:                //capitalize first character
136:                if ((unformatted != null) && (unformatted.length() > 0)) {
137:                    sb.replace(0, 1, sb.substring(0, 1).toUpperCase());
138:                    return sb.toString();
139:                } else
140:                    return unformatted;
141:            }
142:
143:            public static String formatFKName(String fkColumnName) {
144:                return format(fkColumnName) + "FK";
145:            }
146:
147:            public static String firstToLowerCase(String text) {
148:                return (text == null || text.length() == 0) ? "" : Character
149:                        .toLowerCase(text.charAt(0))
150:                        + (text.length() > 1 ? text.substring(1) : "");
151:            }
152:
153:            public static String firstToUpperCase(String text) {
154:                return (text == null || text.length() == 0) ? "" : Character
155:                        .toUpperCase(text.charAt(0))
156:                        + (text.length() > 1 ? text.substring(1) : "");
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.