Source Code Cross Referenced for Format.java in  » Ajax » MyGWT » net » mygwt » ui » client » 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 » Ajax » MyGWT » net.mygwt.ui.client.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MyGWT Widget Library
003:         * Copyright(c) 2007, MyGWT.
004:         * licensing@mygwt.net
005:         * 
006:         * http://mygwt.net/license
007:         */
008:        package net.mygwt.ui.client.util;
009:
010:        import java.util.Iterator;
011:        import java.util.Map;
012:
013:        /**
014:         * Formatting functions.
015:         */
016:        public class Format {
017:
018:            /**
019:             * Substitutes the indexed parameters.
020:             * 
021:             * @param text the text
022:             * @param param the parameter
023:             * @return the new text
024:             */
025:            public static String substitute(String text, int param) {
026:                return substitute(text, safeRegexReplacement("" + param));
027:            }
028:
029:            /**
030:             * Substitutes the named parameters. The passed keys and values must be
031:             * Strings.
032:             * 
033:             * @param text the text
034:             * @param params the parameters
035:             * @return the new text
036:             */
037:            public static String substitute(String text, Map params) {
038:                Iterator it = params.keySet().iterator();
039:                while (it.hasNext()) {
040:                    String key = (String) it.next();
041:                    text = text.replaceAll("\\{" + key + "}",
042:                            safeRegexReplacement((String) params.get(key)));
043:                }
044:                return text;
045:            }
046:
047:            /**
048:             * Substitutes the indexed parameters.
049:             * 
050:             * @param text the text
051:             * @param param the parameter
052:             * @return the new text
053:             */
054:            public static String substitute(String text, String param) {
055:                return text.replaceAll("\\{0}", safeRegexReplacement(param));
056:            }
057:
058:            /**
059:             * Substitutes the named parameter.
060:             * 
061:             * @param text the text
062:             * @param name the parameter name
063:             * @return the parameter value
064:             */
065:            public static String substitute(String text, String name,
066:                    String value) {
067:                return text = text.replaceAll("\\{" + name + "}",
068:                        safeRegexReplacement(value));
069:            }
070:
071:            /**
072:             * Substitutes the indexed parameters.
073:             * 
074:             * @param text the text
075:             * @param params the parameters
076:             * @return the new text
077:             */
078:            public static String substitute(String text, String[] params) {
079:                for (int i = 0; i < params.length; i++) {
080:                    String p = params[i];
081:                    if (p == null) {
082:                        p = "";
083:                    }
084:                    text = text.replaceAll("\\{" + i + "}",
085:                            safeRegexReplacement(p));
086:                }
087:                return text;
088:            }
089:
090:            /**
091:             * Substitutes the named parameters. The passed keys and values must be
092:             * Strings.
093:             * 
094:             * @param text the text
095:             * @param keys the parameter names
096:             * @param params the parameter values
097:             * @return the new text
098:             */
099:            public static String substitute(String text, String[] keys,
100:                    Map params) {
101:                for (int i = 0; i < keys.length; i++) {
102:                    text = text.replaceAll("\\{" + keys[i] + "}",
103:                            safeRegexReplacement((String) params.get(keys[i])));
104:                }
105:                return text;
106:            }
107:
108:            /**
109:             * Replace any \ or $ characters in the replacement string with an escaped \\
110:             * or \$.
111:             * 
112:             * @param replacement the regular expression replacement text
113:             * @return null if replacement is null or the result of escaping all \ and $
114:             *         characters
115:             */
116:            private static String safeRegexReplacement(String replacement) {
117:                if (replacement == null) {
118:                    return replacement;
119:                }
120:
121:                return replacement.replaceAll("\\\\", "\\\\\\\\").replaceAll(
122:                        "\\$", "\\\\\\$");
123:            }
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.