Source Code Cross Referenced for Strings.java in  » Aspect-oriented » aspectwerkz-2.0 » org » codehaus » aspectwerkz » util » 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 » Aspect oriented » aspectwerkz 2.0 » org.codehaus.aspectwerkz.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package org.codehaus.aspectwerkz.util;
008:
009:        import java.util.List;
010:        import java.util.ArrayList;
011:
012:        /**
013:         * Utility methods for strings.
014:         *
015:         * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016:         */
017:        public class Strings {
018:            /**
019:             * Private constructor to prevent instantiability.
020:             */
021:            private Strings() {
022:            }
023:
024:            /**
025:             * Removes newline, carriage return and tab characters from a string.
026:             *
027:             * @param toBeEscaped string to escape
028:             * @return the escaped string
029:             */
030:            public static String removeFormattingCharacters(
031:                    final String toBeEscaped) {
032:                StringBuffer escapedBuffer = new StringBuffer();
033:                for (int i = 0; i < toBeEscaped.length(); i++) {
034:                    if ((toBeEscaped.charAt(i) != '\n')
035:                            && (toBeEscaped.charAt(i) != '\r')
036:                            && (toBeEscaped.charAt(i) != '\t')) {
037:                        escapedBuffer.append(toBeEscaped.charAt(i));
038:                    }
039:                }
040:                String s = escapedBuffer.toString();
041:                return s;//
042:                // Strings.replaceSubString(s, "\"", "")
043:            }
044:
045:            /**
046:             * Replaces all occurences of a substring inside a string.
047:             *
048:             * @param str      the string to search and replace in
049:             * @param oldToken the string to search for
050:             * @param newToken the string to replace newToken
051:             * @return the new string
052:             */
053:            public static String replaceSubString(final String str,
054:                    final String oldToken, final String newToken) {
055:                return replaceSubString(str, oldToken, newToken, -1);
056:            }
057:
058:            /**
059:             * Replaces all occurences of a substring inside a string.
060:             *
061:             * @param str      the string to search and replace in
062:             * @param oldToken the string to search for
063:             * @param newToken the string to replace newToken
064:             * @param max      maximum number of values to replace (-1 => no maximum)
065:             * @return the new string
066:             */
067:            public static String replaceSubString(final String str,
068:                    final String oldToken, final String newToken, int max) {
069:                if ((str == null) || (oldToken == null) || (newToken == null)
070:                        || (oldToken.length() == 0)) {
071:                    return str;
072:                }
073:                StringBuffer buf = new StringBuffer(str.length());
074:                int start = 0;
075:                int end = 0;
076:                while ((end = str.indexOf(oldToken, start)) != -1) {
077:                    buf.append(str.substring(start, end)).append(newToken);
078:                    start = end + oldToken.length();
079:                    if (--max == 0) {
080:                        break;
081:                    }
082:                }
083:                buf.append(str.substring(start));
084:                return buf.toString();
085:            }
086:
087:            /**
088:             * String split on multicharacter delimiter. <p/>Written by Tim Quinn (tim.quinn@honeywell.com)
089:             *
090:             * @param stringToSplit
091:             * @param delimiter
092:             * @return
093:             */
094:            public static final String[] splitString(String stringToSplit,
095:                    String delimiter) {
096:                String[] aRet;
097:                int iLast;
098:                int iFrom;
099:                int iFound;
100:                int iRecords;
101:
102:                // return Blank Array if stringToSplit == "")
103:                if (stringToSplit.equals("")) {
104:                    return new String[0];
105:                }
106:
107:                // count Field Entries
108:                iFrom = 0;
109:                iRecords = 0;
110:                while (true) {
111:                    iFound = stringToSplit.indexOf(delimiter, iFrom);
112:                    if (iFound == -1) {
113:                        break;
114:                    }
115:                    iRecords++;
116:                    iFrom = iFound + delimiter.length();
117:                }
118:                iRecords = iRecords + 1;
119:
120:                // populate aRet[]
121:                aRet = new String[iRecords];
122:                if (iRecords == 1) {
123:                    aRet[0] = stringToSplit;
124:                } else {
125:                    iLast = 0;
126:                    iFrom = 0;
127:                    iFound = 0;
128:                    for (int i = 0; i < iRecords; i++) {
129:                        iFound = stringToSplit.indexOf(delimiter, iFrom);
130:                        if (iFound == -1) { // at End
131:                            aRet[i] = stringToSplit.substring(iLast
132:                                    + delimiter.length(), stringToSplit
133:                                    .length());
134:                        } else if (iFound == 0) { // at Beginning
135:                            aRet[i] = "";
136:                        } else { // somewhere in middle
137:                            aRet[i] = stringToSplit.substring(iFrom, iFound);
138:                        }
139:                        iLast = iFound;
140:                        iFrom = iFound + delimiter.length();
141:                    }
142:                }
143:                return aRet;
144:            }
145:
146:            /**
147:             * Parse a method signature or method call signature.
148:             * <br/>Given a call signature like "method(Type t)", extract the method name
149:             * and param type and parameter name: [method, Type, t]
150:             * <br/>Given a signature like "method(X x, Y)", extract the method name
151:             * and param name / param type - but leaving empty String if
152:             * the information is not available: [method, X, x, Y, ""]
153:             *
154:             * @param methodCallSignature
155:             * @return each element (2xp+1 sized) (see doc)
156:             */
157:            public static String[] extractMethodSignature(
158:                    String methodCallSignature) {
159:                List extracted = new ArrayList();
160:                String methodName = methodCallSignature;
161:                String methodCallDesc = null;
162:                if (methodCallSignature.indexOf("(") > 0) {
163:                    methodName = methodName.substring(0, methodCallSignature
164:                            .indexOf("("));
165:                    methodCallDesc = methodCallSignature.substring(
166:                            methodCallSignature.indexOf("(") + 1,
167:                            methodCallSignature.lastIndexOf(")"));
168:                }
169:                extracted.add(methodName);
170:                if (methodCallDesc != null) {
171:                    String[] parameters = Strings.splitString(methodCallDesc,
172:                            ",");
173:                    for (int i = 0; i < parameters.length; i++) {
174:                        String[] parameterInfo = Strings.splitString(Strings
175:                                .replaceSubString(parameters[i].trim(), "  ",
176:                                        " "), " ");
177:                        extracted.add(parameterInfo[0]);
178:                        extracted
179:                                .add((parameterInfo.length > 1) ? parameterInfo[1]
180:                                        : "");
181:                    }
182:                }
183:                return (String[]) extracted.toArray(new String[] {});
184:            }
185:
186:            public static boolean isNullOrEmpty(String s) {
187:                return (s == null) ? true : (s.length() <= 0);
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.