Author: scabanovich
Date: 2011-11-22 19:51:59 -0500 (Tue, 22 Nov 2011)
New Revision: 36552
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/Check.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckFilterMappingName.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckResource.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckRoleReferenceName.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLCoreValidator.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferenceInitializer.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferences.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLValidatorMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/messages.properties
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.web/plugin.properties
trunk/jst/plugins/org.jboss.tools.jst.web/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/model/project/ext/store/XMLValueInfo.java
Log:
JBIDE-10190
https://issues.jboss.org/browse/JBIDE-10190
Migrated validator for web.xml.
Modified: trunk/jst/plugins/org.jboss.tools.jst.web/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web/META-INF/MANIFEST.MF 2011-11-23 00:11:35 UTC
(rev 36551)
+++ trunk/jst/plugins/org.jboss.tools.jst.web/META-INF/MANIFEST.MF 2011-11-23 00:51:59 UTC
(rev 36552)
@@ -10,6 +10,7 @@
Bundle-Localization: plugin
Require-Bundle: org.jboss.tools.common.model;visibility:=reexport,
org.jboss.tools.common.projecttemplates;visibility:=reexport,
+ org.jboss.tools.common.validation,
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.jdt.launching;bundle-version="3.6.0",
org.eclipse.debug.ui;bundle-version="3.7.0",
@@ -54,6 +55,7 @@
org.jboss.tools.jst.web.tld.model,
org.jboss.tools.jst.web.tld.model.handlers,
org.jboss.tools.jst.web.tld.model.helpers,
+ org.jboss.tools.jst.web.validation,
org.jboss.tools.jst.web.webapp.model,
org.jboss.tools.jst.web.webapp.model.handlers
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified: trunk/jst/plugins/org.jboss.tools.jst.web/plugin.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web/plugin.properties 2011-11-23 00:11:35 UTC
(rev 36551)
+++ trunk/jst/plugins/org.jboss.tools.jst.web/plugin.properties 2011-11-23 00:51:59 UTC
(rev 36552)
@@ -4,3 +4,5 @@
# END NON-TRANSLATABLE
strutsProblemName=Verification Problem
constraintProblemName=Constraint Problem
+WebXMLCoreValidator=Web XML Validator
+WebXMLProblemName=Web XML Problem
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.web/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web/plugin.xml 2011-11-23 00:11:35 UTC (rev
36551)
+++ trunk/jst/plugins/org.jboss.tools.jst.web/plugin.xml 2011-11-23 00:51:59 UTC (rev
36552)
@@ -315,4 +315,24 @@
</persistent>
</extension>
+ <extension id="webxmlproblem" name="%WebXMLProblemName"
point="org.eclipse.core.resources.markers">
+ <super
type="org.jboss.tools.common.validation.JBTValidationProblem">
+ </super>
+ <persistent value="true">
+ </persistent>
+ </extension>
+
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer
class="org.jboss.tools.jst.web.validation.WebXMLPreferenceInitializer"/>
+ </extension>
+
+ <extension
+ point="org.jboss.tools.common.validation.validator">
+ <validator
+ class="org.jboss.tools.jst.web.validation.WebXMLCoreValidator"
+ name="%WebXMLCoreValidator"
+ id="org.jboss.tools.jst.web.validation.WebXMLCoreValidator">
+ </validator>
+ </extension>
+
</plugin>
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/model/project/ext/store/XMLValueInfo.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/model/project/ext/store/XMLValueInfo.java 2011-11-23
00:11:35 UTC (rev 36551)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/model/project/ext/store/XMLValueInfo.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -82,7 +82,7 @@
}
public IFile getResource() {
- return object == null ? null : (IFile)object.getAdapter(File.class);
+ return object == null ? null : (IFile)object.getAdapter(IFile.class);
}
}
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/Check.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/Check.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/Check.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.WebModelPlugin;
+import org.jboss.tools.jst.web.model.project.ext.store.XMLValueInfo;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class Check {
+ static String ATTR_PATH = "path"; //$NON-NLS-1$
+ static String ATTR_ATTRIBUTE = "attribute"; //$NON-NLS-1$
+ protected String preference;
+ protected String attr;
+ ValidationErrorManager manager;
+
+ public Check(ValidationErrorManager manager, String preference, String attr) {
+ this.manager = manager;
+ this.preference = preference;
+ this.attr = attr;
+ }
+
+ public void check(XModelObject object) {
+ }
+
+ protected void fireMessage(XModelObject object, String message) {
+ ITextSourceReference ref = getSourceReference(object, attr);
+ IMarker m = manager.addError(message, preference, ref, ref.getResource());
+ bindMarkerToPathAndAttribute(m, object, attr);
+ }
+
+ ITextSourceReference getSourceReference(XModelObject o, String attr) {
+ return new XMLValueInfo(o, attr);
+ }
+
+ public static void bindMarkerToPathAndAttribute(IMarker marker, XModelObject object,
String attr) {
+ if(marker != null) {
+ try {
+ marker.setAttribute(ATTR_PATH, object.getPath());
+ marker.setAttribute(ATTR_ATTRIBUTE, attr);
+ } catch (CoreException e) {
+ WebModelPlugin.getDefault().logError(e);
+ }
+ }
+ }
+
+}
+
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/Check.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.log.LogHelper;
+import org.jboss.tools.common.meta.constraint.impl.XAttributeConstraintQClassName;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.WebModelPlugin;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class CheckClass extends Check {
+ XAttributeConstraintQClassName constraint = new XAttributeConstraintQClassName();
+ boolean allowsPrimitive = false;
+ String implementsType = null;
+ String extendsType = null;
+
+ public CheckClass(ValidationErrorManager manager, String preference, String attr) {
+ super(manager, preference, attr);
+ }
+
+ public CheckClass(ValidationErrorManager manager, String preference, String attr,
boolean allowsPrimitive, String implementsType, String extendsType) {
+ super(manager, preference, attr);
+ this.allowsPrimitive = allowsPrimitive;
+ this.implementsType = implementsType;
+ this.extendsType = extendsType;
+ }
+
+ public void check(XModelObject object) {
+ if(attr == null) return;
+ String value = object.getAttributeValue(attr);
+ if(value.length() == 0 || isJavaLang(value)) return;
+ if(isPrimitive(value)) {
+ if(!allowsPrimitive) {
+ fireNotExist(object, preference, attr, value);
+ }
+ return;
+ }
+ if(!checkQualifiedName(value)) {
+ fireInvalid(object, attr, attr, value);
+ return;
+ }
+ IType type = getValidType(value, object);
+
+ IFile f = (IFile)object.getAdapter(IFile.class);
+ if(f != null) {
+ IProjectValidationContext context = manager.getValidationContext();
+ if(context != null) {
+ context.addLinkedCoreResource(WebXMLCoreValidator.SHORT_ID, value, f.getFullPath(),
true);
+ if(type != null && type.getResource() != null && type.exists()) {
+ context.addLinkedCoreResource(WebXMLCoreValidator.SHORT_ID,
type.getResource().getFullPath().toOSString(), f.getFullPath(), true);
+ }
+ }
+ }
+
+ if(type != null) {
+ String mustImpl = null;
+ try { mustImpl = checkImplements(object, type); } catch (Exception e) {
+ LogHelper.logError("org.jboss.tools.jst.web.verification", e);
//$NON-NLS-1$
+ }
+ if(mustImpl != null) {
+ fireImplements(object, preference, attr, value, mustImpl);
+ }
+ String mustExtend = null;
+ try { mustExtend = checkExtends(object, type); } catch (Exception e) {
+ LogHelper.logError("org.jboss.tools.jst.web.verification", e);
//$NON-NLS-1$
+ }
+ if(mustExtend != null) {
+ fireExtends(object, preference, attr, value, mustExtend);
+ }
+ return;
+ }
+ fireNotExist(object, preference, attr, value);
+ }
+
+ private boolean checkQualifiedName(String value) {
+ return constraint.accepts(value);
+ }
+
+ private String checkImplements(XModelObject object, IType type) throws Exception {
+ if("java.lang.Class".equals(type.getFullyQualifiedName())) return null;
//$NON-NLS-1$
+ String impl = implementsType;
+ if(impl == null || impl.length() == 0) return null;
+ String[] is = type.getSuperInterfaceNames();
+ for (int i = 0; i < is.length; i++) {
+ String f = EclipseJavaUtil.resolveType(type, is[i]);
+ if(f != null && f.equals(impl)) return null;
+ }
+ if(type.isInterface()) return impl;
+ String f = type.getSuperclassName();
+ if(f == null || f.length() == 0 || "java.lang.Object".equals(f)) return impl;
//$NON-NLS-1$
+ f = EclipseJavaUtil.resolveType(type, f);
+ if(f == null || f.length() == 0 || "java.lang.Object".equals(f)) return impl;
//$NON-NLS-1$
+ type = getValidType(f, object);
+ if(type == null) return impl;
+ return checkImplements(object, type);
+ }
+
+ private String checkExtends(XModelObject object, IType type) throws Exception {
+ if(type.isInterface()) return null;
+ if("java.lang.Class".equals(type.getFullyQualifiedName())) return null;
//$NON-NLS-1$
+ String ext = extendsType;
+ if(ext == null || ext.length() == 0 || ext.equals(type.getFullyQualifiedName())) return
null;
+ String f = type.getSuperclassName();
+ if(f == null || f.length() == 0 || "java.lang.Object".equals(f)) return ext;
//$NON-NLS-1$
+ if(f.equals(ext)) return null;
+ f = EclipseJavaUtil.resolveType(type, f);
+ if(f == null || f.length() == 0 || "java.lang.Object".equals(f)) return ext;
//$NON-NLS-1$
+ if(f.equals(ext)) return null;
+ type = getValidType(f, object);
+ if(type == null) return ext;
+ return checkExtends(object, type);
+ }
+
+ private boolean isPrimitive(String value) {
+ return
".int.boolean.char.byte.double.float.long.short.".indexOf("." + value
+ ".") >= 0; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ private boolean isJavaLang(String value) {
+ if(value.indexOf('.') < 0) {
+ return
".String.Integer.Boolean.Character.Byte.Double.Float.Long.Short.".indexOf("."
+ value + ".") >= 0; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else if(value.startsWith("java.lang.")) { //$NON-NLS-1$
+ return isJavaLang(value.substring(10));
+ } else {
+ return false;
+ }
+ }
+
+ protected void fireImplements(XModelObject object, String id, String attr, String value,
String interfaceName) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.CLASS_NOT_IMPLEMENTS, new Object[]
{attr, value, interfaceName}));
+ }
+
+ protected void fireExtends(XModelObject object, String id, String attr, String value,
String superName) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.CLASS_NOT_EXTENDS, new Object[]
{attr, value, superName}));
+ }
+ protected void fireInvalid(XModelObject object, String id, String attr, String value) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.CLASS_NOT_VALID, attr, value));
+ }
+ protected void fireNotExist(XModelObject object, String id, String attr, String value)
{
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.CLASS_NOT_EXISTS, attr, value));
+ }
+
+ public IType getValidType(String className, XModelObject o) {
+ IProject project = EclipseResourceUtil.getProject(o);
+ if(project == null) return null;
+ IType type = EclipseResourceUtil.getValidType(project, className);
+ if(type != null) return type;
+ IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
+ if(javaProject != null) {
+ try {
+ type = EclipseJavaUtil.findType(javaProject, className);
+ } catch (JavaModelException e) {
+ WebModelPlugin.getDefault().logError(e);
+ }
+ if(type != null) return type;
+ }
+ if(EclipseResourceUtil.isContainedInOutput(project, className)) {
+ // Eclipse does not have type in this case,
+ // so we return something instead of null
+ // This is ok while result is only compared to null
+ return EclipseResourceUtil.getValidType(project, "java.lang.Class");
//$NON-NLS-1$
+ }
+ return null;
+ }
+
+}
+
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckFilterMappingName.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckFilterMappingName.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckFilterMappingName.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class CheckFilterMappingName extends Check {
+ static String ATTR = "filter-name"; //$NON-NLS-1$
+
+ public CheckFilterMappingName(ValidationErrorManager manager, String preference) {
+ super(manager, preference, ATTR);
+ }
+
+ public void check(XModelObject object) {
+ String filterName = object.getAttributeValue(ATTR);
+ if(filterName == null) return;
+ if(filterName.length() == 0) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.EMPTY, ATTR));
+ } else if(findFilter(object, filterName) == null) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.FILTER_NOT_EXISTS, ATTR,
filterName));
+ }
+ }
+
+ XModelObject findFilter(XModelObject mapping, String name) {
+ XModelObject webxml = WebAppHelper.getParentFile(mapping);
+ XModelObject[] cs = WebAppHelper.getFilters(webxml);
+ if(cs != null) for (int i = 0; i < cs.length; i++) {
+ if(name.equals(cs[i].getAttributeValue(ATTR))) return cs[i];
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckFilterMappingName.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckResource.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckResource.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckResource.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
+import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class CheckResource extends Check {
+ boolean acceptEmpty = true;
+ String extensions = null;
+ String extensionMessage = null;
+
+ public CheckResource(ValidationErrorManager manager, String preference, String attr) {
+ super(manager, preference, attr);
+ }
+
+ public CheckResource(ValidationErrorManager manager, String preference, String attr,
boolean acceptEmpty, String extensions, String extensionMessage) {
+ super(manager, preference, attr);
+ this.acceptEmpty = acceptEmpty;
+ this.extensions = extensions;
+ this.extensionMessage = extensionMessage;
+ }
+
+ public void check(XModelObject object) {
+ String value = object.getAttributeValue(attr);
+ XModel model = object.getModel();
+ XModelObject webRoot = model == null ? null :
model.getByPath("FileSystems/WEB-ROOT"); //$NON-NLS-1$
+ if(webRoot == null) return;
+
+ if(object.getModelEntity().getName().startsWith("WebAppErrorPage")) {
//$NON-NLS-1$
+ if(value != null && value.indexOf("?") > 0) { //$NON-NLS-1$
+ value = value.substring(0, value.indexOf("?")); //$NON-NLS-1$
+ }
+ if(isMappedToServlet(object, value)) {
+ return;
+ }
+ }
+
+ List<Object> list = WebPromptingProvider.getInstance().getList(model,
IWebPromptingProvider.JSF_CONVERT_URL_TO_PATH, value, null);
+ if(list != null && list.size() > 0) {
+ value = list.get(0).toString();
+ }
+
+ if(value == null || value.trim().length() == 0) {
+ if(!acceptEmpty) {
+ fireEmpty(object, preference, attr);
+ }
+ return;
+ }
+
+ XModelObject o = null;
+ for (Object v: list) {
+ String valuei = v.toString();
+ String value2 = valuei.startsWith("/") ? valuei.substring(1) : valuei;
//$NON-NLS-1$
+ o = webRoot.getChildByPath(value2);
+ if(o != null) break;
+ }
+ if(o == null) {
+ fireExists(object, preference, attr, value);
+ } else if(!checkExtensions(value)) {
+ fireExtension(object, preference, attr, value);
+ }
+ }
+
+ boolean checkExtensions(String value) {
+ value = value.toLowerCase();
+ if(extensions == null || extensions.trim().length() == 0) return true;
+ StringTokenizer st = new StringTokenizer(extensions, " "); //$NON-NLS-1$
+ while(st.hasMoreTokens()) {
+ String ext = st.nextToken();
+ if(value.endsWith(ext)) return true;
+ }
+ return false;
+ }
+
+ boolean isMappedToServlet(XModelObject o, String value) {
+ XModelObject webxml = FileSystemsHelper.getFile(o);
+ if(webxml == null) return false;
+ XModelObject[] ms = WebAppHelper.getServletMappings(webxml);
+ if(ms != null) for (XModelObject m: ms) {
+ String url = m.getAttributeValue("url-pattern"); //$NON-NLS-1$
+ if(value != null && value.equals(url)) return true;
+ }
+ return false;
+ }
+
+ protected void fireEmpty(XModelObject object, String id, String attr) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.PATH_EMPTY, attr));
+ }
+ protected void fireExists(XModelObject object, String id, String attr, String value) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.PATH_NOT_EXISTS, attr, value));
+ }
+ protected void fireExtension(XModelObject object, String id, String attr, String value)
{
+ fireMessage(object, NLS.bind(extensionMessage, attr, value));
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckResource.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckRoleReferenceName.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckRoleReferenceName.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckRoleReferenceName.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class CheckRoleReferenceName extends Check {
+ static String ATTR = "role-name"; //$NON-NLS-1$
+
+ public CheckRoleReferenceName(ValidationErrorManager manager, String preference, String
attr) {
+ super(manager, preference, attr);
+ }
+
+ public void check(XModelObject object) {
+ String roleName = object.getAttributeValue(attr);
+ if(roleName == null) return;
+ if(roleName.length() == 0) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.EMPTY, attr));
+ } else if(!isRoleNameOk(object, roleName)) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.ROLE_NOT_EXISTS, attr,
roleName));
+ }
+ }
+
+ boolean isRoleNameOk(XModelObject mapping, String roleName) {
+ if(roleName.equalsIgnoreCase("NONE")) return true; //$NON-NLS-1$
+ if("*".equals(roleName)) return true; //$NON-NLS-1$
+ if(findRole(mapping, roleName) != null) return true;
+ return false;
+ }
+
+ XModelObject findRole(XModelObject mapping, String name) {
+ XModelObject webxml = WebAppHelper.getParentFile(mapping);
+ if(webxml == null) return null;
+ XModelObject[] cs = WebAppHelper.getRoles(webxml);
+ for (int i = 0; i < cs.length; i++) {
+ if(name.equals(cs[i].getAttributeValue(attr))) return cs[i];
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckRoleReferenceName.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class CheckServletMappingName extends Check {
+ static String ATTR = "servlet-name"; //$NON-NLS-1$
+ boolean acceptEmpty = false;
+
+ public CheckServletMappingName(ValidationErrorManager manager, String preference,
boolean acceptEmpty) {
+ super(manager, preference, ATTR);
+ this.acceptEmpty = acceptEmpty;
+ }
+
+ public void check(XModelObject object) {
+ String servletName = object.getAttributeValue(ATTR);
+ if(servletName == null) return;
+ if(servletName.length() == 0) {
+ if(acceptEmpty) return;
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.EMPTY, attr));
+ } else if(findServlet(object, servletName) == null) {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.SERVLET_NOT_EXISTS, attr,
servletName));
+ }
+ }
+
+ XModelObject findServlet(XModelObject mapping, String name) {
+ XModelObject webxml = WebAppHelper.getParentFile(mapping);
+ XModelObject[] cs = WebAppHelper.getServlets(webxml);
+ for (int i = 0; i < cs.length; i++) {
+ if(name.equals(cs[i].getAttributeValue(ATTR))) return cs[i];
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLCoreValidator.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLCoreValidator.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLCoreValidator.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.validation.ContextValidationHelper;
+import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.common.validation.IValidatingProjectSet;
+import org.jboss.tools.common.validation.IValidatingProjectTree;
+import org.jboss.tools.common.validation.IValidator;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.common.validation.ValidatorManager;
+import org.jboss.tools.common.validation.internal.ProjectValidationContext;
+import org.jboss.tools.common.validation.internal.SimpleValidatingProjectTree;
+import org.jboss.tools.common.validation.internal.ValidatingProjectSet;
+import org.jboss.tools.common.web.WebUtils;
+import org.jboss.tools.jst.web.WebModelPlugin;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class WebXMLCoreValidator extends ValidationErrorManager implements IValidator {
+ public static final String ID =
"org.jboss.tools.esb.validator.ESBCoreValidator"; //$NON-NLS-1$
+ public static final String PROBLEM_TYPE =
"org.jboss.tools.jst.web.webxmlproblem"; //$NON-NLS-1$
+ public static final String PREFERENCE_PAGE_ID =
"org.jboss.tools.jst.web.ui.WebXMLValidatorPreferencePage"; //$NON-NLS-1$
+
+ public static String SHORT_ID = "verification"; //$NON-NLS-1$
+
+ static String XML_EXT = ".xml"; //$NON-NLS-1$
+
+ String projectName;
+ Map<IProject, IProjectValidationContext> contexts = new HashMap<IProject,
IProjectValidationContext>();
+
+ Map<String, Set<Check>> checks = new HashMap<String,
Set<Check>>();
+
+ public WebXMLCoreValidator() {
+ createChecks();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getPreference(org.eclipse.core.resources.IProject,
java.lang.String)
+ */
+ @Override
+ protected String getPreference(IProject project, String preferenceKey) {
+ return WebXMLPreferences.getInstance().getProjectPreference(project, preferenceKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getMaxNumberOfMarkersPerFile(org.eclipse.core.resources.IProject)
+ */
+ @Override
+ public int getMaxNumberOfMarkersPerFile(IProject project) {
+ return WebXMLPreferences.getMaxNumberOfProblemMarkersPerFile(project);
+ }
+
+ private void addCheck(Check check, String... entities) {
+ for (String entity: entities) {
+ Set<Check> cs = checks.get(entity);
+ if(cs == null) {
+ cs = new HashSet<Check>();
+ checks.put(entity, cs);
+ }
+ cs.add(check);
+ }
+ }
+
+ void createChecks() {
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_EXCEPTION_TYPE,
"exception-type", false, null, "java.lang.Exception"),
+ "WebAppErrorPage");
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_FILTER_CLASS,
"filter-class"),
+ WebAppHelper.FILTER_ENTITY, WebAppHelper.FILTER_30_ENTITY);
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_SERVLET_CLASS,
"servlet-class", false, "javax.servlet.Servlet", null),
+ WebAppHelper.SERVLET_ENTITY, WebAppHelper.SERVLET_30_ENTITY);
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_LISTENER_CLASS,
"listener-class"),
+ WebAppHelper.LISTENER_ENTITY, WebAppHelper.LISTENER_24_ENTITY);
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_EXCEPTION_TYPE,
"res-type"),
+ "WebAppResourceRef");
+ addCheck(new CheckClass(this, WebXMLPreferences.INVALID_MESSAGE_DESTINATION_TYPE,
"message-destination-type"),
+ "WebAppMessageDestinationRef");
+
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_TAGLIB_REF,
"taglib-location", false, ".tld",
WebXMLValidatorMessages.PATH_NOT_TAGLIB),
+ WebAppHelper.TAGLIB_ENTITY);
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_WELCOME_FILE_REF, "file
name", false, ".jsp .html .htm .jspx",
WebXMLValidatorMessages.PATH_NOT_PAGE),
+ "WebAppWelcomFile");
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_ERROR_PAGE_REF,
"location", false, null, null),
+ "WebAppErrorPage");
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_FORM_ERROR_PAGE_REF,
"form-error-page"),
+ "WebAppLoginConfig");
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_FORM_LOGIN_PAGE_REF,
"form-login-page"),
+ "WebAppLoginConfig");
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_JSP_FILE_REF,
"jsp-file"),
+ WebAppHelper.SERVLET_ENTITY, WebAppHelper.SERVLET_30_ENTITY);
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_ICON_REF,
"small-icon", true, ".jpg .gif .png",
WebXMLValidatorMessages.PATH_NOT_ICON),
+ WebAppHelper.SERVLET_ENTITY, WebAppHelper.SERVLET_30_ENTITY,
WebAppHelper.FILTER_ENTITY, WebAppHelper.FILTER_30_ENTITY, "FileWebApp",
"FileWebApp24", "FileWebApp25", "FileWebApp30");
+ addCheck(new CheckResource(this, WebXMLPreferences.INVALID_ICON_REF,
"large-icon", true, ".jpg .gif .png",
WebXMLValidatorMessages.PATH_NOT_ICON),
+ WebAppHelper.SERVLET_ENTITY, WebAppHelper.SERVLET_30_ENTITY,
WebAppHelper.FILTER_ENTITY, WebAppHelper.FILTER_30_ENTITY, "FileWebApp",
"FileWebApp24", "FileWebApp25", "FileWebApp30");
+
+ addCheck(new CheckServletMappingName(this, WebXMLPreferences.INVALID_SERVLET_REF,
false),
+ WebAppHelper.SERVLET_MAPPING_ENTITY);
+ addCheck(new CheckServletMappingName(this, WebXMLPreferences.INVALID_SERVLET_REF,
true),
+ WebAppHelper.FILTER_MAPPING_ENTITY, WebAppHelper.FILTER_MAPPING_24_ENTITY);
+ addCheck(new CheckFilterMappingName(this, WebXMLPreferences.INVALID_FILTER_REF),
+ WebAppHelper.FILTER_MAPPING_ENTITY, WebAppHelper.FILTER_MAPPING_24_ENTITY);
+ addCheck(new CheckRoleReferenceName(this, WebXMLPreferences.INVALID_ROLE_REF,
"role-link"),
+ "WebAppSecurityRoleRef");
+ addCheck(new CheckRoleReferenceName(this, WebXMLPreferences.INVALID_ROLE_REF,
"role-name"),
+ "WebAppRunAs", "WebAppRoleName");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getMarkerType()
+ */
+ @Override
+ public String getMarkerType() {
+ return PROBLEM_TYPE;
+ }
+
+ public String getId() {
+ return ID;
+ }
+
+ public String getBuilderId() {
+ return null;
+ }
+
+ public IValidatingProjectTree getValidatingProjects(IProject project) {
+ IProjectValidationContext rootContext = contexts.get(project);
+ if(rootContext == null) {
+ rootContext = new ProjectValidationContext();
+ contexts.put(project, rootContext);
+ }
+
+ Set<IProject> projects = new HashSet<IProject>();
+ projects.add(project);
+
+ IValidatingProjectSet projectSet = new ValidatingProjectSet(project, projects,
rootContext);
+ return new SimpleValidatingProjectTree(projectSet);
+ }
+
+ public boolean shouldValidate(IProject project) {
+ if(!project.isAccessible()) {
+ return false;
+ }
+
+ try {
+ IFacetedProject fp = ProjectFacetsManager.create(project);
+ IProjectFacet f = ProjectFacetsManager.getProjectFacet("jst.web");
+ if(fp != null && f != null && fp.getInstalledVersion(f) != null) {
+ return true;
+ }
+ } catch (CoreException e) {
+ WebModelPlugin.getDefault().logError(e);
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#init(org.eclipse.core.resources.IProject,
org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper,
org.jboss.tools.jst.web.kb.validation.IProjectValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IValidator,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ @Override
+ public void init(IProject project, ContextValidationHelper validationHelper,
IProjectValidationContext context,
org.eclipse.wst.validation.internal.provisional.core.IValidator manager, IReporter
reporter) {
+ super.init(project, validationHelper, context, manager, reporter);
+ projectName = project.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidator#validate(java.util.Set,
org.eclipse.core.resources.IProject,
org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper,
org.jboss.tools.jst.web.kb.validation.IProjectValidationContext,
org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public IStatus validate(Set<IFile> changedFiles, IProject project,
+ ContextValidationHelper validationHelper, IProjectValidationContext context,
ValidatorManager manager,
+ IReporter reporter) throws ValidationException {
+ init(project, validationHelper, context, manager, reporter);
+
+ for (IFile file: changedFiles) {
+ if(file.getName().endsWith(XML_EXT)) {
+ XModelObject o = EclipseResourceUtil.createObjectForResource(file);
+ if(o != null &&
o.getModelEntity().getName().startsWith("FileWebApp")) {
+ validateWebXMLFile(o, file);
+ }
+ }
+ }
+ return OK_STATUS;
+ }
+
+ private void validateWebXMLFile(XModelObject object, IFile file) {
+ validateObject(object);
+ }
+
+ private void validateObject(XModelObject object) {
+ String entity = object.getModelEntity().getName();
+ Set<Check> ch = checks.get(entity);
+ if(ch != null) {
+ for (Check c: ch) {
+ c.check(object);
+ }
+ }
+ XModelObject[] cs = object.getChildren();
+ for (XModelObject c: cs) {
+ validateObject(c);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#validateAll(org.eclipse.core.resources.IProject,
org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper,
org.jboss.tools.jst.web.kb.validation.IProjectValidationContext,
org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public IStatus validateAll(IProject project,
+ ContextValidationHelper validationHelper, IProjectValidationContext context,
ValidatorManager manager,
+ IReporter reporter) throws ValidationException {
+ init(project, validationHelper, context, manager, reporter);
+ displaySubtask(WebXMLValidatorMessages.VALIDATING_PROJECT, new String[]{projectName});
+
+ IPath webContentPath = WebUtils.getFirstWebContentPath(project);
+ IFolder webInf = null;
+ try {
+
+ // This code line never return null
+ webInf = project.getFolder(webContentPath.append("WEB-INF")); //$NON-NLS-1$
+ // so never check it for null
+ if(webInf.isAccessible()) {
+ IResource[] rs = webInf.members();
+ // exception is not required here because if esbContent is not exist control
+ // never gets here
+ for (IResource r: rs) {
+ if(r instanceof IFile) {
+ IFile file = (IFile)r;
+ String name = file.getName();
+ if(name.endsWith(XML_EXT)) {
+ XModelObject o = EclipseResourceUtil.createObjectForResource(file);
+ if(o != null &&
o.getModelEntity().getName().startsWith("FileWebApp")) {
+ validateWebXMLFile(o, file);
+ }
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ // hiding exceptions is the evil so lets return EROOR Status with exception
+ return new
Status(IStatus.ERROR,WebModelPlugin.PLUGIN_ID,MessageFormat.format("Validation error
for project {0}",project.getLocation().toString()),e);
+ }
+
+ return OK_STATUS;
+ }
+
+
+
+ public boolean isEnabled(IProject project) {
+ return WebXMLPreferences.isValidationEnabled(project);
+ }
+
+ @Override
+ protected String getPreferencePageId() {
+ return PREFERENCE_PAGE_ID;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLCoreValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferenceInitializer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferenceInitializer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferenceInitializer.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.jboss.tools.common.preferences.SeverityPreferences;
+import org.jboss.tools.jst.web.WebModelPlugin;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class WebXMLPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ IEclipsePreferences defaultPreferences = ((IScopeContext) new
DefaultScope()).getNode(WebModelPlugin.PLUGIN_ID);
+ defaultPreferences.putBoolean(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, true);
+ for (String name : WebXMLPreferences.SEVERITY_OPTION_NAMES) {
+ defaultPreferences.put(name, SeverityPreferences.WARNING);
+ }
+ defaultPreferences.putInt(SeverityPreferences.MAX_NUMBER_OF_MARKERS_PREFERENCE_NAME,
SeverityPreferences.DEFAULT_MAX_NUMBER_OF_MARKERS_PER_FILE);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferenceInitializer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferences.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferences.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferences.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.jboss.tools.common.preferences.SeverityPreferences;
+import org.jboss.tools.jst.web.WebModelPlugin;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class WebXMLPreferences extends SeverityPreferences {
+
+ public static final Set<String> SEVERITY_OPTION_NAMES = new
HashSet<String>();
+
+ private static WebXMLPreferences INSTANCE = new WebXMLPreferences();
+
+ //Class References group
+ public static final String INVALID_EXCEPTION_TYPE =
INSTANCE.createSeverityOption("invalidExceptionType"); //$NON-NLS-1$
+ public static final String INVALID_FILTER_CLASS =
INSTANCE.createSeverityOption("invalidFilterClass"); //$NON-NLS-1$
+ public static final String INVALID_LISTENER_CLASS =
INSTANCE.createSeverityOption("invalidListenerClass"); //$NON-NLS-1$
+ public static final String INVALID_MESSAGE_DESTINATION_TYPE =
INSTANCE.createSeverityOption("invalidMessageDestinationType"); //$NON-NLS-1$
+ public static final String INVALID_RES_TYPE =
INSTANCE.createSeverityOption("invalidResType"); //$NON-NLS-1$
+ public static final String INVALID_SERVLET_CLASS =
INSTANCE.createSeverityOption("invalidServletClass"); //$NON-NLS-1$
+
+ //Resource References group
+ public static final String INVALID_ERROR_PAGE_REF =
INSTANCE.createSeverityOption("invalidErrorPageRef"); //$NON-NLS-1$
+ public static final String INVALID_FORM_ERROR_PAGE_REF =
INSTANCE.createSeverityOption("invalidFormErrorPageRef"); //$NON-NLS-1$
+ public static final String INVALID_FORM_LOGIN_PAGE_REF =
INSTANCE.createSeverityOption("invalidFormLoginPageRef"); //$NON-NLS-1$
+ public static final String INVALID_JSP_FILE_REF =
INSTANCE.createSeverityOption("invalidJspFileRef"); //$NON-NLS-1$
+ public static final String INVALID_ICON_REF =
INSTANCE.createSeverityOption("invalidIconRef"); //$NON-NLS-1$
+ public static final String INVALID_TAGLIB_REF =
INSTANCE.createSeverityOption("invalidTaglibRef"); //$NON-NLS-1$
+ public static final String INVALID_WELCOME_FILE_REF =
INSTANCE.createSeverityOption("invalidWelcomeFileRef"); //$NON-NLS-1$
+
+ //Object References group
+ public static final String INVALID_SERVLET_REF =
INSTANCE.createSeverityOption("invalidServletRef"); //$NON-NLS-1$
+ public static final String INVALID_FILTER_REF =
INSTANCE.createSeverityOption("invalidFilterRef"); //$NON-NLS-1$
+ public static final String INVALID_ROLE_REF =
INSTANCE.createSeverityOption("invalidRoleRef"); //$NON-NLS-1$
+
+ /**
+ * @return the only instance of CDIPreferences
+ */
+ public static WebXMLPreferences getInstance() {
+ return INSTANCE;
+ }
+
+ private WebXMLPreferences() {
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.common.preferences.SeverityPreferences#createSeverityOption(java.lang.String)
+ */
+ @Override
+ protected String createSeverityOption(String shortName) {
+ String name = getPluginId() + ".validator.problem." + shortName;
//$NON-NLS-1$
+ SEVERITY_OPTION_NAMES.add(name);
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.common.preferences.SeverityPreferences#getPluginId()
+ */
+ @Override
+ protected String getPluginId() {
+ return WebModelPlugin.PLUGIN_ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.common.preferences.SeverityPreferences#getSeverityOptionNames()
+ */
+ @Override
+ protected Set<String> getSeverityOptionNames() {
+ return SEVERITY_OPTION_NAMES;
+ }
+
+ public static boolean shouldValidateCore(IProject project) {
+ return true;
+ }
+
+ public static boolean isValidationEnabled(IProject project) {
+ return INSTANCE.isEnabled(project);
+ }
+
+ public static int getMaxNumberOfProblemMarkersPerFile(IProject project) {
+ return INSTANCE.getMaxNumberOfProblemMarkersPerResource(project);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLPreferences.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLValidatorMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLValidatorMessages.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLValidatorMessages.java 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.validation;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class WebXMLValidatorMessages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.jst.web.validation.messages"; //$NON-NLS-1$
+
+ public static String WEB_XML_PLUGIN_NO_MESSAGE;
+
+ public static String VALIDATING_RESOURCE;
+ public static String VALIDATING_PROJECT;
+
+ public static String PATH_EMPTY;
+ public static String PATH_NOT_EXISTS;
+ public static String PATH_NOT_TAGLIB;
+ public static String PATH_NOT_ICON;
+ public static String PATH_NOT_PAGE;
+
+ public static String CLASS_NOT_EXISTS;
+ public static String CLASS_NOT_IMPLEMENTS;
+ public static String CLASS_NOT_EXTENDS;
+ public static String CLASS_NOT_VALID;
+
+ public static String EMPTY;
+ public static String SERVLET_NOT_EXISTS;
+ public static String FILTER_NOT_EXISTS;
+ public static String ROLE_NOT_EXISTS;
+
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, WebXMLValidatorMessages.class);
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/WebXMLValidatorMessages.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/messages.properties
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/messages.properties 2011-11-23
00:51:59 UTC (rev 36552)
@@ -0,0 +1,17 @@
+WEB_XML_PLUGIN_NO_MESSAGE=No message
+VALIDATING_RESOURCE=project "{0}"; resource "{1}"
+VALIDATING_PROJECT=project "{0}"
+
+PATH_EMPTY=Attribute {0} is empty
+PATH_NOT_EXISTS=Attribute {0} references to {1} that does not exist in web content
+PATH_NOT_TAGLIB=Attribute {0} references to {1} that is not tag library
+PATH_NOT_ICON=Attribute {0} references to {1} that is not an icon file
+PATH_NOT_PAGE=Attribute {0} references to {1} that is not a page file
+CLASS_NOT_EXISTS=Attribute {0} references to non-existent class {1}
+CLASS_NOT_IMPLEMENTS=Attribute {0} references to {1} that does not implement interface
{2}
+CLASS_NOT_EXTENDS=Attribute {0} references to {1} that does not extend {2}
+CLASS_NOT_VALID=Attribute {0} must be valid fully qualified class name
+EMPTY=Attribute {0} is empty
+SERVLET_NOT_EXISTS=Attribute {0} references to {1} that is not a servlet
+FILTER_NOT_EXISTS=Attribute {0} references to {1} that is not a filter
+ROLE_NOT_EXISTS=Attribute {0} references to {1} that is not a role
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/messages.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain