author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 27 Sep 2010 11:43:44 -0700 | |
changeset 490 | 17d65127bce4 |
parent 484 | f5df819c1852 |
permissions | -rw-r--r-- |
17
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
1 |
/** |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
8 |
* |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
11 |
* Contributors: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
12 |
* Description: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
13 |
* Overview: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
14 |
* Details: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
17 |
* Failures and causes: |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
18 |
*/ |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
19 |
package org.symbian.tools.wrttools.util; |
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
20 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
483
diff
changeset
|
21 |
public final class Util { |
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
22 |
public static String removeSpaces(String widgetName) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
23 |
return widgetName != null ? widgetName.replace(" ", "") : ""; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
24 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
25 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
26 |
/* Validation tests for both Windows & Mac OS */ |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
27 |
private static String commonValidate(String argName) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
28 |
if (argName.length() == 0) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
29 |
return ("Can not be empty"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
30 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
31 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
32 |
// filenames starting with dot are not valid for both Widget name & UID |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
33 |
if (argName.charAt(0) == '.') { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
34 |
return ("Can not begin with a dot"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
35 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
36 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
37 |
final char lastChar = argName.charAt(argName.length() - 1); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
38 |
// filenames ending in dot are not valid for both Widget name & UID |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
39 |
if (lastChar == '.') { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
40 |
return ("Can not end with dot"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
41 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
42 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
43 |
return null; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
44 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
45 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
46 |
public static String validateWidgetName(String widgetName) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
47 |
String strError = null; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
48 |
if ((strError = commonValidate(widgetName)) != null) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
49 |
return "Invalid Widget name. " + strError; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
50 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
51 |
if (widgetName.indexOf("<") > -1 || widgetName.indexOf(">") > -1) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
52 |
return ("Invalid Widget name. Angle brackets are not allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
53 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
54 |
final char lastChar = widgetName.charAt(widgetName.length() - 1); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
55 |
// trailing or beginning space is not valid in filenames for Widget name |
483
109da596fa9d
Fixed relevant FindBug messages
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
56 |
if ((Character.isWhitespace(widgetName.charAt(0)) || Character.isWhitespace(lastChar))) { |
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
57 |
return ("Invalid Widget name. Beginning or trailing spaces are not allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
58 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
59 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
60 |
if (widgetName.indexOf('\n') != -1 || widgetName.indexOf('\t') != -1) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
61 |
return ("Invalid Widget name. newline character is not allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
62 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
63 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
64 |
return null; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
65 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
66 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
67 |
public static String validateWidgetID(String widgetID) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
68 |
String strError = null; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
69 |
if ((strError = commonValidate(widgetID)) != null) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
70 |
return "Invalid Widget identifier. " + strError; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
71 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
72 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
73 |
// file names with white spaces are not allowed for Widget Identifier |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
74 |
// (UID) |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
75 |
if (widgetID.indexOf(" ") > -1) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
76 |
return ("Invalid Widget identifier. Whitespaces are not allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
77 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
78 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
79 |
if (widgetID.length() > 78) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
80 |
return ("Invalid Widget identifier. Maximum string length exceeded"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
81 |
} |
50
0560e98b9bf6
Added widget project nature and WRT validators
tasneems@symbian.org
parents:
17
diff
changeset
|
82 |
|
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
83 |
/* test invalid characters, allows only alphanumeric and '.' for UID */ |
490
17d65127bce4
Bug 3735 - info.plist validation regression
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
484
diff
changeset
|
84 |
String alphnum = "._0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
439
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
85 |
for (int i = 0; i < widgetID.length(); i++) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
86 |
if (alphnum.indexOf(widgetID.charAt(i), 0) == -1) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
87 |
return ("Invalid Widget identifier. Only alphanumeric or '.' is allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
88 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
89 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
90 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
91 |
if (widgetID.matches(".*[.]{2,}.*")) { |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
92 |
return ("Invalid Widget identifier. Consecutive dots are not allowed"); |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
93 |
} |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
94 |
|
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
95 |
return null; |
57fff6202b74
Bug 3184 - Reorganize new project wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
50
diff
changeset
|
96 |
} |
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
483
diff
changeset
|
97 |
|
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
483
diff
changeset
|
98 |
private Util() { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
483
diff
changeset
|
99 |
// Do not instantiate |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
483
diff
changeset
|
100 |
} |
17
f1b0259bb410
Validation was added to new project creation wizard
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
diff
changeset
|
101 |
} |