Source Code Cross Referenced for Validator.java in  » Installer » launch4j » net » sf » launch4j » binding » 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 » Installer » launch4j » net.sf.launch4j.binding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        	Launch4j (http://launch4j.sourceforge.net/)
003:        	Cross-platform Java application wrapper for creating Windows native executables.
004:
005:        	Copyright (c) 2004, 2007 Grzegorz Kowal
006:
007:        	All rights reserved.
008:
009:        	Redistribution and use in source and binary forms, with or without modification,
010:        	are permitted provided that the following conditions are met:
011:
012:         * Redistributions of source code must retain the above copyright notice,
013:        	      this list of conditions and the following disclaimer.
014:         * Redistributions in binary form must reproduce the above copyright notice,
015:        	      this list of conditions and the following disclaimer in the documentation
016:        	      and/or other materials provided with the distribution.
017:         * Neither the name of the Launch4j nor the names of its contributors
018:        	      may be used to endorse or promote products derived from this software without
019:        	      specific prior written permission.
020:
021:        	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022:        	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023:        	LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024:        	A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
025:        	CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
026:        	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
027:        	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
028:        	PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
029:        	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
030:        	NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031:        	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032:         */
033:
034:        /*
035:         * Created on 2004-01-30
036:         */
037:        package net.sf.launch4j.binding;
038:
039:        import java.io.File;
040:        import java.util.Arrays;
041:        import java.util.Collection;
042:        import java.util.HashSet;
043:        import java.util.Iterator;
044:        import java.util.List;
045:
046:        import net.sf.launch4j.Util;
047:        import net.sf.launch4j.config.ConfigPersister;
048:
049:        /**
050:         * @author Copyright (C) 2004 Grzegorz Kowal
051:         */
052:        public class Validator {
053:            public static final String ALPHANUMERIC_PATTERN = "[\\w]*?";
054:            public static final String ALPHA_PATTERN = "[\\w&&\\D]*?";
055:            public static final String NUMERIC_PATTERN = "[\\d]*?";
056:            public static final String PATH_PATTERN = "[\\w|[ .,:\\-/\\\\]]*?";
057:
058:            public static final int MAX_STR = 128;
059:            public static final int MAX_PATH = 260;
060:            public static final int MAX_BIG_STR = 8192; // or 16384;
061:            public static final int MAX_ARGS = 32767 - 2048;
062:
063:            private Validator() {
064:            }
065:
066:            public static boolean isEmpty(String s) {
067:                return s == null || s.equals("");
068:            }
069:
070:            public static void checkNotNull(Object o, String property,
071:                    String name) {
072:                if (o == null) {
073:                    signalViolation(property, Messages.getString(
074:                            "Validator.empty.field", name));
075:                }
076:            }
077:
078:            public static void checkString(String s, int maxLength,
079:                    String property, String name) {
080:                if (s == null || s.length() == 0) {
081:                    signalViolation(property, Messages.getString(
082:                            "Validator.empty.field", name));
083:                }
084:                if (s.length() > maxLength) {
085:                    signalLengthViolation(property, name, maxLength);
086:                }
087:            }
088:
089:            public static void checkOptStrings(List strings, int maxLength,
090:                    int totalMaxLength, String property, String name) {
091:                if (strings == null) {
092:                    return;
093:                }
094:                int totalLength = 0;
095:                for (Iterator iter = strings.iterator(); iter.hasNext();) {
096:                    String s = (String) iter.next();
097:                    checkString(s, maxLength, property, name);
098:                    totalLength += s.length();
099:                    if (totalLength > totalMaxLength) {
100:                        signalLengthViolation(property, name, totalMaxLength);
101:                    }
102:                }
103:            }
104:
105:            public static void checkString(String s, int maxLength,
106:                    String pattern, String property, String name) {
107:                checkString(s, maxLength, property, name);
108:                if (!s.matches(pattern)) {
109:                    signalViolation(property, Messages.getString(
110:                            "Validator.invalid.data", name));
111:                }
112:            }
113:
114:            public static void checkOptStrings(List strings, int maxLength,
115:                    int totalMaxLength, String pattern, String property,
116:                    String name, String msg) {
117:                if (strings == null) {
118:                    return;
119:                }
120:                int totalLength = 0;
121:                for (Iterator iter = strings.iterator(); iter.hasNext();) {
122:                    String s = (String) iter.next();
123:                    checkString(s, maxLength, property, name);
124:                    if (!s.matches(pattern)) {
125:                        signalViolation(property, msg != null ? msg : Messages
126:                                .getString("Validator.invalid.data", name));
127:                    }
128:                    totalLength += s.length();
129:                    if (totalLength > totalMaxLength) {
130:                        signalLengthViolation(property, name, totalMaxLength);
131:                    }
132:                }
133:            }
134:
135:            public static void checkOptString(String s, int maxLength,
136:                    String property, String name) {
137:                if (s == null || s.length() == 0) {
138:                    return;
139:                }
140:                if (s.length() > maxLength) {
141:                    signalLengthViolation(property, name, maxLength);
142:                }
143:            }
144:
145:            public static void checkOptString(String s, int maxLength,
146:                    String pattern, String property, String name) {
147:                if (s == null || s.length() == 0) {
148:                    return;
149:                }
150:                if (s.length() > maxLength) {
151:                    signalLengthViolation(property, name, maxLength);
152:                }
153:                if (!s.matches(pattern)) {
154:                    signalViolation(property, Messages.getString(
155:                            "Validator.invalid.data", name));
156:                }
157:            }
158:
159:            public static void checkRange(int value, int min, int max,
160:                    String property, String name) {
161:                if (value < min || value > max) {
162:                    signalViolation(property, Messages.getString(
163:                            "Validator.must.be.in.range", name, String
164:                                    .valueOf(min), String.valueOf(max)));
165:                }
166:            }
167:
168:            public static void checkRange(char value, char min, char max,
169:                    String property, String name) {
170:                if (value < min || value > max) {
171:                    signalViolation(property, Messages.getString(
172:                            "Validator.must.be.in.range", name, String
173:                                    .valueOf(min), String.valueOf(max)));
174:                }
175:            }
176:
177:            public static void checkMin(int value, int min, String property,
178:                    String name) {
179:                if (value < min) {
180:                    signalViolation(property, Messages.getString(
181:                            "Validator.must.be.at.least", name, String
182:                                    .valueOf(min)));
183:                }
184:            }
185:
186:            public static void checkIn(String s, String[] strings,
187:                    String property, String name) {
188:                if (isEmpty(s)) {
189:                    signalViolation(property, Messages.getString(
190:                            "Validator.empty.field", name));
191:                }
192:                List list = Arrays.asList(strings);
193:                if (!list.contains(s)) {
194:                    signalViolation(property, Messages.getString(
195:                            "Validator.invalid.option", name, list.toString()));
196:                }
197:            }
198:
199:            public static void checkTrue(boolean condition, String property,
200:                    String msg) {
201:                if (!condition) {
202:                    signalViolation(property, msg);
203:                }
204:            }
205:
206:            public static void checkFalse(boolean condition, String property,
207:                    String msg) {
208:                if (condition) {
209:                    signalViolation(property, msg);
210:                }
211:            }
212:
213:            public static void checkElementsNotNullUnique(Collection c,
214:                    String property, String msg) {
215:                if (c.contains(null) || new HashSet(c).size() != c.size()) {
216:                    signalViolation(property, Messages.getString(
217:                            "Validator.already.exists", msg));
218:                }
219:            }
220:
221:            public static void checkElementsUnique(Collection c,
222:                    String property, String msg) {
223:                if (new HashSet(c).size() != c.size()) {
224:                    signalViolation(property, Messages.getString(
225:                            "Validator.already.exists", msg));
226:                }
227:            }
228:
229:            public static void checkFile(File f, String property,
230:                    String fileDescription) {
231:                File cfgPath = ConfigPersister.getInstance().getConfigPath();
232:                if (f == null
233:                        || f.getPath().equals("")
234:                        || (!f.exists() && !Util.getAbsoluteFile(cfgPath, f)
235:                                .exists())) {
236:                    signalViolation(property, Messages.getString(
237:                            "Validator.doesnt.exist", fileDescription));
238:                }
239:            }
240:
241:            public static void checkOptFile(File f, String property,
242:                    String fileDescription) {
243:                if (f != null && f.getPath().length() > 0) {
244:                    checkFile(f, property, fileDescription);
245:                }
246:            }
247:
248:            public static void checkRelativeWinPath(String path,
249:                    String property, String msg) {
250:                if (path == null || path.equals("") || path.startsWith("/")
251:                        || path.startsWith("\\") || path.indexOf(':') != -1) {
252:                    signalViolation(property, msg);
253:                }
254:            }
255:
256:            public static void signalLengthViolation(String property,
257:                    String name, int maxLength) {
258:                signalViolation(property, Messages.getString(
259:                        "Validator.exceeds.max.length", name, String
260:                                .valueOf(maxLength)));
261:            }
262:
263:            public static void signalViolation(String property, String msg) {
264:                throw new InvariantViolationException(property, msg);
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.