Author: scabanovich
Date: 2011-11-29 17:13:05 -0500 (Tue, 29 Nov 2011)
New Revision: 36750
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionForwardCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionNameCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionRefsCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionTypeCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/CheckInitParam.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalExceptionCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalForwardCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ResourceCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigControllerCheck.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsCoreValidator.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferenceInitializer.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferences.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsValidatorMessages.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ValidateTypeUtil.java
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/messages.properties
Modified:
trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF
trunk/struts/plugins/org.jboss.tools.struts/plugin.properties
trunk/struts/plugins/org.jboss.tools.struts/plugin.xml
Log:
JBIDE-10190
https://issues.jboss.org/browse/JBIDE-10190
Partially migrated validation for struts-config.xml.
Modified: trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF
===================================================================
--- trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF 2011-11-29 21:52:18
UTC (rev 36749)
+++ trunk/struts/plugins/org.jboss.tools.struts/META-INF/MANIFEST.MF 2011-11-29 22:13:05
UTC (rev 36750)
@@ -29,6 +29,7 @@
org.jboss.tools.struts.validators.model,
org.jboss.tools.struts.validators.model.handlers,
org.jboss.tools.struts.validators.model.helpers,
+ org.jboss.tools.struts.validation,
org.jboss.tools.struts.webprj.model,
org.jboss.tools.struts.webprj.model.handlers,
org.jboss.tools.struts.webprj.model.helpers,
@@ -44,10 +45,12 @@
org.jboss.tools.common.model,
org.jboss.tools.jst.web,
org.jboss.tools.jst.web.tiles,
+ org.jboss.tools.common.validation,
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.debug.core;bundle-version="3.7.0",
org.eclipse.wst.sse.core;bundle-version="1.1.600",
org.eclipse.wst.xml.core;bundle-version="1.1.600",
+ org.eclipse.wst.validation,
org.jboss.tools.common.projecttemplates,
org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
org.eclipse.ltk.ui.refactoring;bundle-version="3.5.100",
Modified: trunk/struts/plugins/org.jboss.tools.struts/plugin.properties
===================================================================
--- trunk/struts/plugins/org.jboss.tools.struts/plugin.properties 2011-11-29 21:52:18 UTC
(rev 36749)
+++ trunk/struts/plugins/org.jboss.tools.struts/plugin.properties 2011-11-29 22:13:05 UTC
(rev 36750)
@@ -1,2 +1,4 @@
providerName=JBoss by Red Hat
-Bundle-Name.0 = JBoss Tools Struts
\ No newline at end of file
+Bundle-Name.0 = JBoss Tools Struts
+
+StrutsCoreValidator=Struts Core Validator
\ No newline at end of file
Modified: trunk/struts/plugins/org.jboss.tools.struts/plugin.xml
===================================================================
--- trunk/struts/plugins/org.jboss.tools.struts/plugin.xml 2011-11-29 21:52:18 UTC (rev
36749)
+++ trunk/struts/plugins/org.jboss.tools.struts/plugin.xml 2011-11-29 22:13:05 UTC (rev
36750)
@@ -411,4 +411,16 @@
</contribution>
</extension>
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer
class="org.jboss.tools.struts.validation.StrutsPreferenceInitializer"/>
+ </extension>
+ <extension
+ point="org.jboss.tools.common.validation.validator">
+ <validator
+ class="org.jboss.tools.struts.validation.StrutsCoreValidator"
+ name="%StrutsCoreValidator"
+ id="org.jboss.tools.struts.validation.StrutsCoreValidator">
+ </validator>
+ </extension>
+
</plugin>
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionForwardCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionForwardCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionForwardCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import java.util.*;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.jst.web.validation.Check;
+import org.jboss.tools.struts.*;
+import org.jboss.tools.struts.model.helpers.*;
+import org.jboss.tools.struts.webprj.model.helpers.WebModulesHelper;
+import org.jboss.tools.struts.webprj.pattern.UrlPattern;
+import org.jboss.tools.struts.model.handlers.*;
+
+public class ActionForwardCheck extends Check {
+ XModelObject object;
+ protected XModel model;
+ protected XModelObject forward;
+ protected XModelObject config;
+ protected String path;
+ protected String module;
+ protected Set modules;
+ protected String pathModule = null;
+ protected static StrutsProcessStructureHelper h = new
StrutsProcessStructureHelper();
+
+ protected String pathEmpty = StrutsValidatorMessages.ACTION_FORWARD_PATH_EMPTY;
+ protected String pathExists = StrutsValidatorMessages.ACTION_FORWARD_PATH_EXISTS;
+ protected String classNameExists =
StrutsValidatorMessages.ACTION_FORWARD_CLASSNAME_EXISTS;
+ protected String contextRelativeCross =
StrutsValidatorMessages.ACTION_FORWARD_CONTEXT_RELATIVE_CROSS;
+ protected String contextRelativeMono =
StrutsValidatorMessages.ACTION_FORWARD_CONTEXT_RELATIVE_MONO;
+
+ public ActionForwardCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference, "");
+ }
+
+ protected boolean isRelevant(XModelObject object) {
+ return object.getParent() != null &&
object.getParent().getModelEntity().getName().startsWith("StrutsAction");
+ }
+
+ public void check(XModelObject object) {
+ this.object = object;
+ if(!isRelevant(object)) {
+ return;
+ }
+ forward = object;
+ model = forward.getModel();
+ path = JumpByForwardPathHandler.getResourcePath("" +
forward.getAttributeValue("path"));
+ if(!checkPath()) return;
+ checkClasses();
+ }
+
+ protected void checkClasses() {
+ checkClass("className", classNameExists);
+ }
+
+ // compare find with JumpByForwardPathHandler
+
+ protected boolean isAllowedEmptyPath() {
+ return false;
+ }
+
+ protected boolean checkPath() {
+ if(path.length() == 0) {
+ if(isAllowedEmptyPath()) {
+ return true;
+ } else {
+ fire(pathEmpty, "path", null);
+ return false;
+ }
+ }
+ config = StrutsProcessStructureHelper.instance.getParentFile(forward);
+ WebModulesHelper wh = WebModulesHelper.getInstance(model);
+ if(TilesHelper.findTile(config, path) != null) return true;
+ module = StrutsProcessStructureHelper.instance.getProcessModule(forward);
+ modules = wh.getModules();
+ pathModule = wh.getModuleForPath(path, module);
+ if(pathModule == null) pathModule = "";
+ if(StrutsProcessHelper.isHttp(path)) return true;
+ UrlPattern up = wh.getUrlPattern(module);
+ boolean isFolder = path.endsWith("/") &&
path.startsWith("/");
+ boolean isAction = !isFolder && up.isActionUrl(path);
+ boolean isPage = path.endsWith(".jsp") || path.indexOf(".htm") >
0 || path.endsWith(".css");
+ String s = forward.getAttributeValue("contextRelative");
+ boolean cR = ("true".equals(s) || "yes".equals(s));
+ if(isFolder || isAction || isPage) {
+ if(forward.getModelEntity().getAttribute("contextRelative") != null) {
+ if(!cR && pathModule.length() > 0 && path.startsWith(pathModule +
"/")) {
+ fire(contextRelativeCross, "contextRelative", null);
+ return false;
+ }
+ if(cR && pathModule.length() > 0 && !path.startsWith(pathModule +
"/")) {
+ fire(contextRelativeMono, "contextRelative", null);
+ return false;
+ }
+ } else {
+ if(!pathModule.equals(module) || (pathModule.length() > 0 &&
path.startsWith(pathModule + "/"))) {
+ fire(contextRelativeMono, "path", null);
+ return false;
+ }
+ }
+ }
+ XModelObject target = null;
+ String kind = "tile";
+ if(isFolder) {
+ kind = "resource folder";
+ target = model.getByPath(path.substring(0, path.length() - 1));
+ } else if(isAction) {
+ kind = "action";
+ path = up.getActionPath(path);
+ if(!cR) {
+ target = config.getChildByPath(StrutsConstants.ELM_ACTIONMAP +
"/" + path.replace('/', '#'));
+ if(target == null) {
+ XModelObject[] cgs = wh.getConfigsForModule(model, pathModule);
+ for (int i = 0; i < cgs.length && target == null; i++) {
+ if(cgs[i] == config) continue;
+ target = cgs[i].getChildByPath(StrutsConstants.ELM_ACTIONMAP + "/" +
path.replace('/', '#'));
+ }
+ }
+ } else {
+ XModelObject[] cgs = wh.getConfigsForModule(model, pathModule);
+ if(cgs.length > 0) {
+ if(pathModule.length() > 0 && path.startsWith(pathModule)) path =
path.substring(pathModule.length());
+ }
+ for (int i = 0; i < cgs.length && target == null; i++) {
+ target = cgs[i].getChildByPath(StrutsConstants.ELM_ACTIONMAP +
"/" + path.replace('/', '#'));
+ }
+ }
+ } else /*if(isPage) */{
+ kind = (isPage) ? "page" : "tile or page";
+ if(path.endsWith(".css")) kind = "resource";
+ XModelObject fs = wh.getRootFileSystemForModule(model, pathModule);
+ if(fs != null) {
+ if(pathModule.length() > 0 && path.startsWith(pathModule))
path = path.substring(pathModule.length());
+ if(path.startsWith("/")) path = path.substring(1);
+ target = fs.getChildByPath(path);
+ }
+ }
+ if(target != null) {
+ return true;
+ }
+ fire(pathExists, "path", kind);
+ return false;
+ }
+
+ protected boolean checkClass(String attr, String id) {
+ ValidateTypeUtil tv = new ValidateTypeUtil();
+ int tvr = tv.checkClass(object, attr,
"org.apache.struts.action.ActionForward");
+ if(tvr == ValidateTypeUtil.NOT_FOUND) {
+ fire(id, attr, null);
+ return false;
+ } else if(tvr == ValidateTypeUtil.NOT_UPTODATE) {
+ //not implemented
+ }
+ return true;
+ }
+
+ protected void fire(String id, String attr, String info) {
+ this.attr = attr;
+ String oTitle = DefaultCreateHandler.title(object, true);
+ String pTitle = DefaultCreateHandler.title(object.getParent(), true);
+ Object[] os = (info == null) ? new Object[] {oTitle, pTitle}
+ : new Object[] {oTitle, pTitle, info};
+ String message = NLS.bind(id, os);
+ fireMessage(object, message);
+ }
+
+}
+
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionForwardCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionNameCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionNameCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionNameCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.validation.Check;
+
+/**
+ *
+ * @author valera
+ */
+public class ActionNameCheck extends Check {
+
+ /** Creates a new instance of ActionNameCheck */
+ public ActionNameCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference, "name");
+ }
+
+ public void check(XModelObject object) {
+ String name = (String)object.getAttributeValue("name");
+ if (name.length() == 0) {
+ String valid = (String)object.getAttributeValue("validate");
+ if ("yes".equals(valid) || "true".equals(valid)) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_NAME_EMPTY, new
Object[] {DefaultCreateHandler.title(object, true)});
+ fireMessage(object, message);
+ }
+ } else {
+ XModelObject bean = object.getParent().getParent()
+ .getChildByPath("form-beans").getChildByPath(name);
+ if (bean == null) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_NAME_EXISTS, new
Object[] {DefaultCreateHandler.title(object, true), name});
+ fireMessage(object, message);
+ }
+ }
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionNameCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionRefsCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionRefsCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionRefsCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import java.util.*;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.jst.web.validation.Check;
+import org.jboss.tools.struts.webprj.model.helpers.WebModulesHelper;
+import org.jboss.tools.struts.webprj.pattern.UrlPattern;
+import org.jboss.tools.struts.model.helpers.*;
+import org.jboss.tools.struts.*;
+
+/**
+ *
+ * @author valera
+ */
+public class ActionRefsCheck extends Check {
+ protected XModelObject object;
+ protected XModel model;
+ protected XModelObject action;
+ protected XModelObject config;
+ protected String path;
+ protected String module;
+ protected Set modules;
+ protected String pathModule = null;
+ protected static StrutsProcessStructureHelper h = new StrutsProcessStructureHelper();
+
+ /** Creates a new instance of ActionRefsCheck */
+ public ActionRefsCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference, "");
+ }
+
+ public void check(XModelObject object) {
+ this.object = object;
+ action = object;
+ model = action.getModel();
+
+ if(!isInputReferencingForwardOrEmpty()) {
+ checkPath(StrutsValidatorMessages.ACTION_INPUT, "input");
+ }
+ checkPath(StrutsValidatorMessages.ACTION_FORWARD, "forward");
+ checkPath(StrutsValidatorMessages.ACTION_INCLUDE, "include");
+ }
+
+ boolean isInputReferencingForwardOrEmpty() {
+ String v = action.getAttributeValue("input");
+ if(v == null || v.length() == 0) return true;
+ if(v.indexOf('/') < 0 && v.indexOf('.') < 0) {
+ XModelObject f = action.getChildByPath(v);
+ if(f != null) return true;
+ XModelObject cfg = action.getParent().getParent();
+ f = cfg.getChildByPath("global-forwards/" + v);
+ if(f != null) return true;
+ WebModulesHelper h = WebModulesHelper.getInstance(action.getModel());
+ XModelObject[] cfgs = h.getConfigsForModule(cfg.getModel(),
h.getModuleForConfig(cfg));
+ if(cfgs == null || cfgs.length < 2) return false;
+ for (int i = 0; i < cfgs.length; i++) {
+ f = cfgs[i].getChildByPath("global-forwards/" + v);
+ if(f != null) return true;
+ }
+ }
+ return false;
+ }
+
+ protected void checkPath(String id, String attr) {
+ this.attr = attr;
+ path = action.getAttributeValue(attr);
+ if(path == null || path.length() == 0) return;
+ config = StrutsProcessStructureHelper.instance.getParentFile(action);
+ WebModulesHelper wh = WebModulesHelper.getInstance(model);
+ if(TilesHelper.findTile(config, path) != null) return;
+ module = StrutsProcessStructureHelper.instance.getProcessModule(action);
+ modules = wh.getModules();
+ pathModule = wh.getModuleForPath(path, module);
+ if(StrutsProcessHelper.isHttp(path)) return;
+ UrlPattern up = wh.getUrlPattern(module);
+ boolean isFolder = path.endsWith("/") &&
path.startsWith("/");
+ boolean isAction = !isFolder && up.isActionUrl(path);
+ boolean isPage = path.endsWith(".jsp") || path.indexOf(".htm") >
0 || path.endsWith(".css");
+ XModelObject target = null;
+ String kind = "tile";
+ if(isFolder) {
+ kind = "resource folder";
+ path = path.substring(0, path.length() - 1);
+ target = model.getByPath(path);
+ } else if(isAction) {
+ kind = "action";
+ path = up.getActionPath(path);
+ XModelObject[] cgs = wh.getConfigsForModule(model, pathModule);
+ if(cgs.length > 0) {
+ if(pathModule.length() > 0 && path.startsWith(pathModule)) path =
path.substring(pathModule.length());
+ }
+ for (int i = 0; i < cgs.length && target == null; i++) {
+ target = cgs[i].getChildByPath(StrutsConstants.ELM_ACTIONMAP + "/" +
path.replace('/', '#'));
+ }
+ } else /*if(isPage) */{
+ kind = (isPage) ? "page" : "tile or page";
+ if(path.endsWith(".css")) kind = "resource";
+ XModelObject fs = wh.getRootFileSystemForModule(model, pathModule);
+ if(fs != null) {
+ if(pathModule.length() > 0 && path.startsWith(pathModule)) path =
path.substring(pathModule.length());
+ if(path.startsWith("/")) path = path.substring(1);
+ target = fs.getChildByPath(path);
+ }
+ }
+ if(target == null) {
+ fire(id, attr, kind + " " + path);
+ }
+ }
+
+ protected void fire(String id, String attr, String value) {
+ Object[] os = new Object[] {DefaultCreateHandler.title(object, true), value};
+ String message = NLS.bind(id, os);
+ fireMessage(object, message);
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionRefsCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionTypeCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionTypeCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionTypeCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.validation.Check;
+
+/**
+ *
+ * @author valera
+ */
+public class ActionTypeCheck extends Check {
+
+ /** Creates a new instance of ActionTypeCheck */
+ public ActionTypeCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference, "type");
+ }
+
+ public void check(XModelObject object) {
+ String forward = (String)object.getAttributeValue("forward");
+ String include = (String)object.getAttributeValue("include");
+ if (forward.length() > 0 || include.length() > 0) return;
+ String type = (String)object.getAttributeValue("type");
+ String sup = "org.apache.struts.action.Action";
+ ValidateTypeUtil tv = new ValidateTypeUtil();
+ int tvr = tv.checkClass(object, "type", sup);
+ String oTitle = DefaultCreateHandler.title(object, true);
+ if(tvr == ValidateTypeUtil.EMPTY) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_TYPE_EMPTY, oTitle);
+ fireMessage(object, message);
+ } else if(tvr == ValidateTypeUtil.NOT_FOUND) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_TYPE_EXISTS, new
Object[] {oTitle, type});
+ fireMessage(object, message);
+ } else if(tvr == ValidateTypeUtil.WRONG_SUPER) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_TYPE_EXTENDS, new
Object[] {oTitle, type, sup});
+ fireMessage(object, message);
+ } else if(tvr == ValidateTypeUtil.NOT_UPTODATE) {
+ String message = NLS.bind(StrutsValidatorMessages.ACTION_TYPE_UPTODATE, new
Object[] {oTitle, type});
+ fireMessage(object, message);
+ }
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ActionTypeCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/CheckInitParam.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/CheckInitParam.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/CheckInitParam.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+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.impl.XModelImpl;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.validation.Check;
+
+public class CheckInitParam extends Check {
+
+ public CheckInitParam(ValidationErrorManager manager, String preference) {
+ super(manager, preference, "param-value");
+ }
+
+ public void check(XModelObject object) {
+ XModelObject o = object;
+ String paramName = object.getAttributeValue("param-name");
+ if(paramName == null) return;
+ XModelObject parent = object.getParent();
+ if(parent == null ||
!"WebAppServlet".equals(parent.getModelEntity().getName())) {
+ return;
+ }
+ if(!paramName.equals("config") &&
!paramName.startsWith("config/")) return;
+
+ String value = o.getAttributeValue("param-value");
+ if(value == null || value.length() == 0) return;
+ XModel model = object.getModel();
+ XModelObject webRoot = model == null ? null :
model.getByPath("FileSystems/WEB-ROOT");
+ if(webRoot == null) return;
+ StringTokenizer st = new StringTokenizer(value, ",");
+ while(st.hasMoreTokens()) {
+ String path = st.nextToken().trim();
+ if(path.length() == 0) continue;
+ XModelObject fc = XModelImpl.getByRelativePath(model, path);
+ if(fc == null) {
+ String message = NLS.bind(StrutsValidatorMessages.RESOURCE_EXISTS, path);
+ fireMessage(object, message);
+ }
+ String path2 = path.startsWith("/") ? path.substring(1) : path;
+ XModelObject fc2 = webRoot.getChildByPath(path2);
+ if(fc2 == null) {
+ String message = NLS.bind(StrutsValidatorMessages.RESOURCE_EXISTS, path);
+ fireMessage(object, message);
+ } else if(!fc2.getModelEntity().getName().startsWith("StrutsConfig")) {
+ String message = NLS.bind(StrutsValidatorMessages.CONFIG_VALID,
"param-value", path);
+ fireMessage(object, message);
+ }
+ }
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/CheckInitParam.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalExceptionCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalExceptionCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalExceptionCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.jboss.tools.common.validation.ValidationErrorManager;
+
+public class GlobalExceptionCheck extends GlobalForwardCheck {
+
+ public GlobalExceptionCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference);
+ }
+
+ protected void checkClasses() {
+ boolean b = checkClass("className",
StrutsValidatorMessages.GLOBAL_EXCEPTION_CLASSNAME_EXISTS);
+ if(b) {
+ checkClass("handler",
StrutsValidatorMessages.GLOBAL_EXCEPTION_HANDLER_EXISTS);
+ }
+ }
+
+ protected boolean isAllowedEmptyPath() {
+ return true;
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalExceptionCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalForwardCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalForwardCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalForwardCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+
+public class GlobalForwardCheck extends ActionForwardCheck {
+
+ public GlobalForwardCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference);
+ pathEmpty = StrutsValidatorMessages.GLOBAL_FORWARD_PATH_EMPTY;
+ pathExists = StrutsValidatorMessages.GLOBAL_FORWARD_PATH_EXISTS;
+ classNameExists = StrutsValidatorMessages.GLOBAL_FORWARD_CLASSNAME_EXISTS;
+ contextRelativeCross = StrutsValidatorMessages.GLOBAL_FORWARD_CONTEXT_RELATIVE_CROSS;
+ contextRelativeMono = StrutsValidatorMessages.GLOBAL_FORWARD_CONTEXT_RELATIVE_MONO;
+ }
+
+ protected boolean isRelevant(XModelObject object) {
+ return object.getParent() != null &&
!object.getParent().getModelEntity().getName().startsWith("StrutsAction");
+ }
+
+ protected void fire(String id, String attr, String info) {
+ this.attr = attr;
+ String oTitle = DefaultCreateHandler.title(object, true);
+ Object[] os = (info == null) ? new Object[] {oTitle}
+ : new Object[] {oTitle, info};
+ String message = NLS.bind(id, os);
+ fireMessage(object, message);
+ }
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/GlobalForwardCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ResourceCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ResourceCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ResourceCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.struts.model.handlers.OpenMessageResourcesHandler;
+
+public class ResourceCheck extends StrutsConfigControllerCheck {
+
+ public ResourceCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference);
+ attr = "parameter";
+ }
+
+ public void check(XModelObject object) {
+ this.object = object;
+ if(!OpenMessageResourcesHandler.isReferencingResourceObject(object)) return;
+ if(OpenMessageResourcesHandler.getResourceObject(object) != null) return;
+ String message = NLS.bind(StrutsValidatorMessages.RESOURCE_EXISTS,
object.getAttributeValue("parameter"));
+ fireMessage(object, message);
+ }
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ResourceCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.model.AbstractWebFileImpl;
+import org.jboss.tools.jst.web.validation.Check;
+
+public class StrutsConfigCheck extends Check {
+
+ public StrutsConfigCheck(ValidationErrorManager manager, String preference) {
+ super(manager, preference, null);
+ }
+
+ public void check(XModelObject object) {
+ if(!(object instanceof AbstractWebFileImpl)) return;
+ AbstractWebFileImpl f = (AbstractWebFileImpl)object;
+ if(!f.isIncorrect()) return;
+ String oTitle = DefaultCreateHandler.title(object, true);
+ String errors = "\n" + f.get("errors");
+ String message = NLS.bind(StrutsValidatorMessages.CONFIG_VALID, oTitle, errors);
+ fireMessage(object, message);
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigControllerCheck.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigControllerCheck.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigControllerCheck.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.validation.Check;
+
+public class StrutsConfigControllerCheck extends Check {
+ XModelObject object;
+
+ public StrutsConfigControllerCheck(ValidationErrorManager manager, String preference)
{
+ super(manager, preference, "");
+ }
+
+ public void check(XModelObject object) {
+ this.object = object;
+ ValidateTypeUtil tv = new ValidateTypeUtil();
+ int tvr = tv.checkClass(object, "className", null);
+ if(ValidateTypeUtil.NOT_FOUND == tvr) {
+ fire(StrutsValidatorMessages.CONTROLLER_CLASSNAME_EXISTS,
"className");
+ return;
+ }
+ tvr = tv.checkClass(object, "multipartClass", null);
+ if(ValidateTypeUtil.NOT_FOUND == tvr) {
+ fire(StrutsValidatorMessages.CONTROLLER_MULTIPART_CLASS_EXISTS,
"multipartClass");
+ return;
+ }
+ tvr = tv.checkClass(object, "processorClass", null);
+ if(ValidateTypeUtil.NOT_FOUND == tvr) {
+ fire(StrutsValidatorMessages.CONTROLLER_PROCESSOR_CLASS_EXISTS,
"processorClass");
+ return;
+ }
+ }
+
+ protected void fire(String id, String attr) {
+ this.attr = attr;
+ String oTitle = DefaultCreateHandler.title(object, true);
+ String pTitle = DefaultCreateHandler.title(object.getParent(), true);
+ Object[] os = new Object[] {oTitle, pTitle};
+ String message = NLS.bind(id, os);
+ fireMessage(object, message);
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsConfigControllerCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsCoreValidator.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsCoreValidator.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsCoreValidator.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * 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.struts.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.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;
+import org.jboss.tools.jst.web.validation.Check;
+import org.jboss.tools.jst.web.validation.CheckClass;
+import org.jboss.tools.jst.web.validation.CheckResource;
+import org.jboss.tools.jst.web.webapp.model.WebAppConstants;
+import org.jboss.tools.struts.StrutsConstants;
+import org.jboss.tools.struts.StrutsModelPlugin;
+import org.jboss.tools.struts.StrutsProject;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class StrutsCoreValidator extends ValidationErrorManager implements IValidator,
StrutsConstants {
+ public static final String ID =
"org.jboss.tools.struts.validation.StrutsCoreValidator"; //$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.struts.ui.StrutsValidatorPreferencePage"; //$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 StrutsCoreValidator() {
+ 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 StrutsPreferences.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 StrutsPreferences.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 ActionForwardCheck(this, StrutsPreferences.INVALID_ACTION_FORWARD),
+ ENT_FORWARD + VER_SUFFIX_10, ENT_FORWARD + VER_SUFFIX_11, ENT_FORWARD +
VER_SUFFIX_12);
+ addCheck(new ActionNameCheck(this, StrutsPreferences.INVALID_ACTION_NAME),
+ ENT_ACTION + VER_SUFFIX_10, ENT_ACTION + VER_SUFFIX_11, ENT_ACTION + VER_SUFFIX_12);
+ addCheck(new ActionRefsCheck(this,
StrutsPreferences.INVALID_ACTION_REFERENCE_ATTRIBUTE),
+ ENT_ACTION + VER_SUFFIX_10, ENT_ACTION + VER_SUFFIX_11, ENT_ACTION + VER_SUFFIX_12);
+ addCheck(new ActionTypeCheck(this, StrutsPreferences.INVALID_ACTION_TYPE),
+ ENT_ACTION + VER_SUFFIX_10, ENT_ACTION + VER_SUFFIX_11, ENT_ACTION + VER_SUFFIX_12);
+ addCheck(new GlobalExceptionCheck(this, StrutsPreferences.INVALID_GLOBAL_EXCEPTION),
+ ENT_EXCEPTION + VER_SUFFIX_11);
+ addCheck(new GlobalForwardCheck(this, StrutsPreferences.INVALID_GLOBAL_FORWARD),
+ ENT_FORWARD + VER_SUFFIX_10, ENT_FORWARD + VER_SUFFIX_11, ENT_FORWARD +
VER_SUFFIX_12);
+ addCheck(new StrutsConfigControllerCheck(this, StrutsPreferences.INVALID_CONTROLLER),
+ "StrutsController11", "StrutsController12");
+ addCheck(new ResourceCheck(this, StrutsPreferences.INVALID_MESSAGE_RESOURCES),
+ "StrutsMessageResources11");
+
+ addCheck(new StrutsConfigCheck(this, StrutsPreferences.INVALID_INIT_PARAM),
+ ENT_STRUTSCONFIG + VER_SUFFIX_10, ENT_STRUTSCONFIG + VER_SUFFIX_11, ENT_STRUTSCONFIG
+ VER_SUFFIX_12);
+ }
+
+ /*
+ * (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 {
+ return project.hasNature(StrutsProject.NATURE_ID);
+ } 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(ENT_STRUTSCONFIG)) {
+ validateStrutsConfigFile(o, file);
+ } else if(o != null &&
o.getModelEntity().getName().startsWith("FileWebApp")) {
+ validateWebXMLFile(o);
+ }
+ }
+ }
+ return OK_STATUS;
+ }
+
+ private void validateStrutsConfigFile(XModelObject object, IFile file) {
+ validateObject(object);
+ }
+
+ private void validateWebXMLFile(XModelObject object) {
+ XModelObject[] ss = WebAppHelper.getServlets(object);
+ for (XModelObject servlet: ss) {
+ for(XModelObject p: servlet.getChildren()) {
+ new CheckInitParam(this, StrutsPreferences.INVALID_INIT_PARAM).check(p);
+ }
+ }
+ }
+
+ 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(StrutsValidatorMessages.VALIDATING_PROJECT, new String[]{projectName});
+
+ IPath webContentPath = WebUtils.getFirstWebContentPath(project);
+ IFolder webInf = null;
+ try {
+
+ // This code line never return null
+ webInf =
project.getFolder(webContentPath.removeFirstSegments(1).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(StrutsConstants.ENT_STRUTSCONFIG)) {
+ validateStrutsConfigFile(o, file);
+ }
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ // hiding exceptions is the evil so lets return EROOR Status with exception
+ return new
Status(IStatus.ERROR,StrutsModelPlugin.PLUGIN_ID,MessageFormat.format("Validation
error for project {0}",project.getLocation().toString()),e);
+ }
+
+ return OK_STATUS;
+ }
+
+ public boolean isEnabled(IProject project) {
+ return StrutsPreferences.isValidationEnabled(project);
+ }
+
+ @Override
+ protected String getPreferencePageId() {
+ return PREFERENCE_PAGE_ID;
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsCoreValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferenceInitializer.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferenceInitializer.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferenceInitializer.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -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.struts.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 StrutsPreferenceInitializer 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 : StrutsPreferences.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);
+ }
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferenceInitializer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferences.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferences.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferences.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.struts.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 StrutsPreferences extends SeverityPreferences {
+
+ public static final Set<String> SEVERITY_OPTION_NAMES = new
HashSet<String>();
+
+ private static StrutsPreferences INSTANCE = new StrutsPreferences();
+
+ public static final String INVALID_ACTION_FORWARD =
INSTANCE.createSeverityOption("invalidActionForward"); //$NON-NLS-1$
+
+ public static final String INVALID_ACTION_NAME =
INSTANCE.createSeverityOption("invalidActionName"); //$NON-NLS-1$
+ public static final String INVALID_ACTION_REFERENCE_ATTRIBUTE =
INSTANCE.createSeverityOption("invalidActionReferenceAttribute"); //$NON-NLS-1$
+ public static final String INVALID_ACTION_TYPE =
INSTANCE.createSeverityOption("invalidActionType"); //$NON-NLS-1$
+
+ public static final String INVALID_GLOBAL_FORWARD =
INSTANCE.createSeverityOption("invalidGlobalForward"); //$NON-NLS-1$
+ public static final String INVALID_GLOBAL_EXCEPTION =
INSTANCE.createSeverityOption("invalidGlobalException"); //$NON-NLS-1$
+
+ public static final String INVALID_CONTROLLER =
INSTANCE.createSeverityOption("invalidController"); //$NON-NLS-1$
+ public static final String INVALID_MESSAGE_RESOURCES =
INSTANCE.createSeverityOption("invalidMessageResources"); //$NON-NLS-1$
+
+ public static final String INVALID_INIT_PARAM =
INSTANCE.createSeverityOption("invalidInitParam"); //$NON-NLS-1$
+
+ /**
+ * @return the only instance of CDIPreferences
+ */
+ public static StrutsPreferences getInstance() {
+ return INSTANCE;
+ }
+
+ private StrutsPreferences() {
+ }
+
+ /* (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/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsPreferences.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsValidatorMessages.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsValidatorMessages.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsValidatorMessages.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class StrutsValidatorMessages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.struts.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 ACTION_TYPE_EMPTY;
+ public static String ACTION_TYPE_EXISTS;
+ public static String ACTION_TYPE_EXTENDS;
+ public static String ACTION_TYPE_UPTODATE;
+ public static String ACTION_NAME_EXISTS;
+ public static String ACTION_NAME_EMPTY;
+ public static String ACTION_INPUT;
+
+ public static String ACTION_FORWARD;
+ public static String ACTION_INCLUDE;
+ public static String ACTION_FORWARD_PATH_EMPTY;
+ public static String ACTION_FORWARD_PATH_EXISTS;
+ public static String ACTION_FORWARD_CLASSNAME_EXISTS;
+ public static String ACTION_FORWARD_CONTEXT_RELATIVE_CROSS;
+ public static String ACTION_FORWARD_CONTEXT_RELATIVE_MONO;
+ public static String GLOBAL_FORWARD_PATH_EMPTY;
+ public static String GLOBAL_FORWARD_PATH_EXISTS;
+ public static String GLOBAL_FORWARD_CLASSNAME_EXISTS;
+ public static String GLOBAL_FORWARD_CONTEXT_RELATIVE_CROSS;
+ public static String GLOBAL_FORWARD_CONTEXT_RELATIVE_MONO;
+ public static String GLOBAL_EXCEPTION_PATH_EXISTS;
+ public static String GLOBAL_EXCEPTION_CLASSNAME_EXISTS;
+ public static String GLOBAL_EXCEPTION_HANDLER_EXISTS;
+ public static String GLOBAL_EXCEPTION_MODULE_RELATIVE;
+ public static String CONFIG_FILE_XML;
+ public static String CONTROLLER_CLASSNAME_EXISTS;
+ public static String CONTROLLER_MULTIPART_CLASS_EXISTS;
+ public static String CONTROLLER_PROCESSOR_CLASS_EXISTS;
+ public static String RESOURCE_EXISTS;
+ public static String CONFIG_VALID;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, StrutsValidatorMessages.class);
+ }
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/StrutsValidatorMessages.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ValidateTypeUtil.java
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ValidateTypeUtil.java
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ValidateTypeUtil.java 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.struts.validation;
+
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.jst.web.validation.CheckClass;
+import org.jboss.tools.struts.StrutsModelPlugin;
+
+public class ValidateTypeUtil {
+ public static int OK = 0;
+ public static int EMPTY = 1;
+ public static int NOT_FOUND = 2;
+ public static int WRONG_SUPER = 3;
+ public static int NOT_UPTODATE = 4;
+
+ public ValidateTypeUtil() {}
+
+ public int checkClass(XModelObject o, String attr, String sup) {
+ String type = "" + o.getAttributeValue(attr);
+ if(type.length() == 0) return EMPTY;
+ IType c = CheckClass.getValidType(type, o);
+ if(c == null) return NOT_FOUND;
+ if(sup != null) try {
+// IType sc = o.getModel().getValidType(sup);
+
+ ///if(!sc.isAssignableFrom(c)) return WRONG_SUPER;
+ } catch (Exception t) {
+ StrutsModelPlugin.getPluginLog().logError(t);
+ }
+/*
+ VObject cls = model.getObjectByPath("/"+type.replace('.',
'/')+".class");
+ src = model.getObjectByPath("/"+type.replace('.',
'/')+".java");
+ if (cls != null && src != null) {
+ if (cls.getTimeStamp() < src.getTimeStamp()) {
+ VResult result = factory.getResult("uptodate", object,
+ "type", src, null, new Object[] {object, type});
+ return NOT_UPTODATE;
+ }
+ }
+*/
+ return OK;
+ }
+
+}
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/ValidateTypeUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/messages.properties
===================================================================
---
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/messages.properties
(rev 0)
+++
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/messages.properties 2011-11-29
22:13:05 UTC (rev 36750)
@@ -0,0 +1,33 @@
+WEB_XML_PLUGIN_NO_MESSAGE=No message
+VALIDATING_RESOURCE=project "{0}"; resource "{1}"
+VALIDATING_PROJECT=project "{0}"
+
+ACTION_TYPE_EMPTY={0} should have type attribute filled when input or forward attribute
are empty
+ACTION_TYPE_EXISTS=class {1} referenced in {0} type attribute is not compiled
+ACTION_TYPE_EXTENDS={0} action type class {1} must be inherited from {2}
+ACTION_TYPE_UPTODATE={0} action type class {1} is modified, but not yet compiled
+ACTION_NAME_EXISTS={0} name attribute references Form-Bean {1} that does not exist
+ACTION_NAME_EMPTY={0} name attribute is empty, but validate attribute is set to true
(yes)
+ACTION_INPUT=Attribute input of {0} references to non-existent {1}
+ACTION_FORWARD=Attribute forward of {0} references to non-existent {1}
+ACTION_INCLUDE=Attribute include of {0} references to non-existent {1}
+ACTION_FORWARD_PATH_EMPTY={0} of {1} path attribute must be defined
+ACTION_FORWARD_PATH_EXISTS={0} of {1} path attribute reference to non-existent {2}
+ACTION_FORWARD_CLASSNAME_EXISTS={0} of {1} className attribute reference to non-existent
class
+ACTION_FORWARD_CONTEXT_RELATIVE_CROSS={0} of {1} contextRelative must be set to yes(true)
for cross-modular reference
+ACTION_FORWARD_CONTEXT_RELATIVE_MONO={0} of {1} contextRelative must be set to no(false)
for mono-modular reference
+GLOBAL_FORWARD_PATH_EMPTY={0} path attribute must be defined
+GLOBAL_FORWARD_PATH_EXISTS={0} path attribute reference to non-existent {1}
+GLOBAL_FORWARD_CLASSNAME_EXISTS={0} className attribute reference to non-existent class
+GLOBAL_FORWARD_CONTEXT_RELATIVE_CROSS={0} contextRelative must be set to yes(true) for
cross-modular reference
+GLOBAL_FORWARD_CONTEXT_RELATIVE_MONO={0} contextRelative must be set to no(false) for
mono-modular reference
+GLOBAL_EXCEPTION_PATH_EXISTS={0} path attribute reference to non-existent {1}
+GLOBAL_EXCEPTION_CLASSNAME_EXISTS={0} className attribute reference to non-existent
class
+GLOBAL_EXCEPTION_HANDLER_EXISTS={0} handler attribute reference to non-existent class
+GLOBAL_EXCEPTION_MODULE_RELATIVE={0} path attribute should be module-relative
+CONFIG_FILE_XML=Configuration file {0} is invalid. {1}
+CONTROLLER_CLASSNAME_EXISTS={0} className attribute of configuration file {1} reference
to non-existent class
+CONTROLLER_MULTIPART_CLASS_EXISTS={0} multipartClass attribute of configuration file {1}
reference to non-existent class
+CONTROLLER_PROCESSOR_CLASS_EXISTS={0} processorClass attribute of configuration file {1}
reference to non-existent class
+RESOURCE_EXISTS=resource {0} does not exist
+CONFIG_VALID=Attribute {0} references to {1} that is not a valid struts config file
\ No newline at end of file
Property changes on:
trunk/struts/plugins/org.jboss.tools.struts/src/org/jboss/tools/struts/validation/messages.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain