author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 02 Sep 2010 15:18:58 -0700 | |
changeset 484 | f5df819c1852 |
parent 470 | d4809db37847 |
permissions | -rw-r--r-- |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
1 |
/******************************************************************************* |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
3 |
* All rights reserved. |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
8 |
* |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
9 |
* Initial Contributors: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
11 |
* Contributors: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
12 |
* Description: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
13 |
* Overview: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
14 |
* Details: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
17 |
* Failures and causes: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
18 |
*******************************************************************************/ |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
19 |
package org.symbian.tools.wrttools.core.internal.validation; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
20 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
21 |
import java.io.IOException; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
22 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
23 |
import org.eclipse.core.resources.IMarker; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
24 |
import org.eclipse.core.resources.IResource; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
26 |
import org.eclipse.wst.validation.AbstractValidator; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
27 |
import org.eclipse.wst.validation.ValidationResult; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
28 |
import org.eclipse.wst.validation.ValidationState; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
29 |
import org.eclipse.wst.validation.ValidatorMessage; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
30 |
import org.symbian.tools.wrttools.Activator; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
31 |
import org.w3c.css.css.DocumentParser; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
32 |
import org.w3c.css.css.StyleSheet; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
33 |
import org.w3c.css.parser.CssError; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
34 |
import org.w3c.css.properties.PropertiesLoader; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
35 |
import org.w3c.css.util.ApplContext; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
36 |
import org.w3c.css.util.Warning; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
37 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
38 |
public class CssBuildValidator extends AbstractValidator { |
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
39 |
@Override |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
40 |
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
41 |
return main(resource.getLocationURI().toString(), resource); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
42 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
43 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
44 |
public ValidationResult main(String uri, IResource resource) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
45 |
String language = "en"; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
46 |
String profile = "css3"; // css2, css21 (default), css3, svg, svgbasic, |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
47 |
// svgtiny, atsc-tv, mobile, tv |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
48 |
String medium = ""; // (default), aural, braille, embossed, |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
49 |
// handheld, print, projection, screen, |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
50 |
// tty, tv, presentation |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
51 |
int warningLevel = 2; // -1 (no warning), 0, 1, 2 (default, all the |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
52 |
// warnings) |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
53 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
54 |
// first, we get the parameters and create an application context |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
55 |
ApplContext ac = new ApplContext(language); |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
56 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
57 |
if (profile != null && !"none".equals(profile)) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
58 |
if ("css1".equals(profile) || "css2".equals(profile) || "css21".equals(profile) || "css3".equals(profile) |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
59 |
|| "svg".equals(profile) || "svgbasic".equals(profile) || "svgtiny".equals(profile)) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
60 |
ac.setCssVersion(profile); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
61 |
} else { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
62 |
ac.setProfile(profile); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
63 |
ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile")); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
64 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
65 |
} else { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
66 |
ac.setProfile(profile); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
67 |
ac.setCssVersion(PropertiesLoader.config.getProperty("defaultProfile")); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
68 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
69 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
70 |
// medium to use |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
71 |
ac.setMedium(medium); |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
72 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
73 |
// HTML document |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
74 |
try { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
75 |
DocumentParser urlParser = new DocumentParser(ac, uri); |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
76 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
77 |
return handleRequest(ac, uri, urlParser.getStyleSheet(), warningLevel, true, resource); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
78 |
} catch (Exception e) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
79 |
Activator.log(e); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
80 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
81 |
return null; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
82 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
83 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
84 |
private ValidationResult handleRequest(ApplContext ac, String title, StyleSheet styleSheet, int warningLevel, |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
85 |
boolean errorReport, IResource resource) throws Exception { |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
86 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
87 |
if (styleSheet == null) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
88 |
throw new IOException(ac.getMsg().getServletString("process") + " " + title); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
89 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
90 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
91 |
styleSheet.findConflicts(ac); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
92 |
ValidationResult result = new ValidationResult(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
93 |
CssError[] errors = styleSheet.getErrors().getErrors(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
94 |
for (CssError cssError : errors) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
95 |
String msg = cssError.getException().getLocalizedMessage(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
96 |
if (msg != null && msg.trim().length() > 0) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
97 |
ValidatorMessage message = createMessage(resource, cssError.getLine(), msg, IMarker.SEVERITY_WARNING); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
98 |
result.add(message); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
99 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
100 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
101 |
Warning[] warnings = styleSheet.getWarnings().getWarnings(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
102 |
for (Warning warning : warnings) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
103 |
ValidatorMessage message = createMessage(resource, warning.getLine(), warning.getWarningMessage(), |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
104 |
IMarker.SEVERITY_WARNING); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
105 |
result.add(message); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
106 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
107 |
return result; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
108 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
109 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
110 |
private ValidatorMessage createMessage(IResource resource, int line, String msg, int severity) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
111 |
ValidatorMessage message = ValidatorMessage.create(msg, resource); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
112 |
message.setAttribute(IMarker.LINE_NUMBER, line); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
113 |
message.setAttribute(IMarker.SEVERITY, severity); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
114 |
return message; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
470
diff
changeset
|
115 |
} |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
116 |
} |