Source Code Cross Referenced for Utils.java in  » Ajax » zk » org » zkoss » zul » impl » 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 » zk » org.zkoss.zul.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Utils.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Wed Mar 14 15:30:49     2007, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zul.impl;
020:
021:        import java.util.List;
022:        import java.util.LinkedList;
023:        import java.util.Iterator;
024:
025:        import org.zkoss.lang.Strings;
026:
027:        import org.zkoss.zk.ui.Desktop;
028:        import org.zkoss.zk.ui.AbstractComponent;
029:        import org.zkoss.zk.ui.WrongValueException;
030:
031:        /**
032:         * A collection of utilities.
033:         *
034:         * @author tomyeh
035:         */
036:        public class Utils {
037:            /** Parse a list of numbers.
038:             *
039:             * @param defaultValue the value if a number is omitted. For example, ",2"
040:             * means "1,2" if defafultValue is 1
041:             * @return an array of int, or null if no integer at all
042:             */
043:            public static final int[] stringToInts(String numbers,
044:                    int defaultValue) throws WrongValueException {
045:                if (numbers == null)
046:                    return null;
047:
048:                List list = new LinkedList();
049:                for (int j = 0;;) {
050:                    int k = numbers.indexOf(',', j);
051:                    final String s = (k >= 0 ? numbers.substring(j, k)
052:                            : numbers.substring(j)).trim();
053:                    if (s.length() == 0) {
054:                        if (k < 0)
055:                            break;
056:                        list.add(null);
057:                    } else {
058:                        try {
059:                            list.add(Integer.valueOf(s));
060:                        } catch (Throwable ex) {
061:                            throw new WrongValueException(
062:                                    "Not a valid number list: " + numbers);
063:                        }
064:                    }
065:
066:                    if (k < 0)
067:                        break;
068:                    j = k + 1;
069:                }
070:
071:                int[] ary;
072:                final int sz = list.size();
073:                if (sz > 0) {
074:                    ary = new int[sz];
075:                    int j = 0;
076:                    for (Iterator it = list.iterator(); it.hasNext(); ++j) {
077:                        final Integer i = (Integer) it.next();
078:                        ary[j] = i != null ? i.intValue() : defaultValue;
079:                    }
080:                } else {
081:                    ary = null;
082:                }
083:                return ary;
084:            }
085:
086:            /** Converts an array of numbers to a string.
087:             */
088:            public static final String intsToString(int[] ary) {
089:                if (ary == null || ary.length == 0)
090:                    return "";
091:
092:                final StringBuffer sb = new StringBuffer(50);
093:                for (int j = 0; j < ary.length; ++j) {
094:                    if (j > 0)
095:                        sb.append(',');
096:                    sb.append(ary[j]);
097:                }
098:                return sb.toString();
099:            }
100:
101:            /** Parse a list of numbers.
102:             *
103:             * @param defaultValue the value used if an empty string is fund.
104:             * For example, ",2" means "1,2" if defafultValue is "1"
105:             * @return an array of string, or null if no data at all
106:             */
107:            public static final String[] stringToArray(String src,
108:                    String defaultValue) {
109:                if (src == null)
110:                    return null;
111:
112:                List list = new LinkedList();
113:                for (int j = 0;;) {
114:                    int k = src.indexOf(',', j);
115:                    final String s = (k >= 0 ? src.substring(j, k) : src
116:                            .substring(j)).trim();
117:                    if (s.length() == 0) {
118:                        if (k < 0)
119:                            break;
120:                        list.add(defaultValue);
121:                    } else {
122:                        list.add(s);
123:                    }
124:
125:                    if (k < 0)
126:                        break;
127:                    j = k + 1;
128:                }
129:
130:                return (String[]) list.toArray(new String[list.size()]);
131:            }
132:
133:            /** Converts an array of objects to a string, by catenating them
134:             * together and separated with comma.
135:             */
136:            public static final String arrayToString(Object[] ary) {
137:                if (ary == null || ary.length == 0)
138:                    return "";
139:
140:                final StringBuffer sb = new StringBuffer(50);
141:                for (int j = 0; j < ary.length; ++j) {
142:                    if (j > 0)
143:                        sb.append(',');
144:                    if (ary[j] != null)
145:                        sb.append(ary[j]);
146:                }
147:                return sb.toString();
148:            }
149:
150:            /** Returns the encoded URL for the dynamic generated content, or empty
151:             * the component doesn't belong to any desktop.
152:             *
153:             * @since 3.0.2
154:             */
155:            public static String getDynamicMediaURI(AbstractComponent comp,
156:                    int version, String name, String format) {
157:                final Desktop desktop = comp.getDesktop();
158:                if (desktop == null)
159:                    return ""; //no avail at client
160:
161:                final StringBuffer sb = new StringBuffer(64).append('/');
162:                Strings.encode(sb, version);
163:                if (name != null || format != null) {
164:                    sb.append('/');
165:                    boolean bExtRequired = true;
166:                    if (name != null && name.length() != 0) {
167:                        sb.append(name.replace('\\', '/'));
168:                        bExtRequired = name.lastIndexOf('.') < 0;
169:                    } else {
170:                        sb.append(comp.getId());
171:                    }
172:                    if (bExtRequired && format != null)
173:                        sb.append('.').append(format);
174:                }
175:                return desktop.getDynamicMediaURI(comp, sb.toString()); //already encoded
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.