Author: scabanovich
Date: 2011-11-23 17:34:15 -0500 (Wed, 23 Nov 2011)
New Revision: 36587
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/FacesConfigValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFSeverityPreferences.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFValidationMessage.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/messages.properties
Log:
JBIDE-10190
https://issues.jboss.org/browse/JBIDE-10190
Partially migrated validation for faces-config.xml.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/FacesConfigValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/FacesConfigValidator.java 2011-11-23
22:33:38 UTC (rev 36586)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/FacesConfigValidator.java 2011-11-23
22:34:15 UTC (rev 36587)
@@ -15,6 +15,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -24,12 +25,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
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.XModel;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.impl.XModelImpl;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.validation.ContextValidationHelper;
import org.jboss.tools.common.validation.IProjectValidationContext;
@@ -43,10 +47,16 @@
import org.jboss.tools.common.validation.internal.ValidatingProjectSet;
import org.jboss.tools.common.web.WebUtils;
import org.jboss.tools.jsf.model.JSFConstants;
+import org.jboss.tools.jsf.model.pv.JSFProjectsTree;
+import org.jboss.tools.jsf.web.JSFWebHelper;
+import org.jboss.tools.jsf.web.JSFWebProject;
+import org.jboss.tools.jsf.web.pattern.JSFUrlPattern;
+import org.jboss.tools.jsf.web.validation.composite.CompositeComponentValidator;
import org.jboss.tools.jst.web.WebModelPlugin;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+import org.jboss.tools.jst.web.model.pv.WebProjectNode;
import org.jboss.tools.jst.web.validation.Check;
import org.jboss.tools.jst.web.validation.CheckClass;
-import org.jboss.tools.jst.web.validation.WebXMLPreferences;
/**
* @author Viacheslav Kabanovich
@@ -54,7 +64,7 @@
public class FacesConfigValidator extends ValidationErrorManager implements IValidator,
JSFConstants {
public static final String ID =
"org.jboss.tools.esb.validator.ESBCoreValidator"; //$NON-NLS-1$
public static final String PROBLEM_TYPE =
"org.jboss.tools.jsf.facesconfigproblem"; //$NON-NLS-1$
- public static final String PREFERENCE_PAGE_ID =
"org.jboss.tools.jsf.ui.FacesConfigValidatorPreferencePage"; //$NON-NLS-1$
+ public static final String PREFERENCE_PAGE_ID =
CompositeComponentValidator.PREFERENCE_PAGE_ID;
public static String SHORT_ID = "verification"; //$NON-NLS-1$
@@ -75,7 +85,7 @@
*/
@Override
protected String getPreference(IProject project, String preferenceKey) {
- return WebXMLPreferences.getInstance().getProjectPreference(project, preferenceKey);
+ return JSFSeverityPreferences.getInstance().getProjectPreference(project,
preferenceKey);
}
/*
@@ -84,7 +94,7 @@
*/
@Override
public int getMaxNumberOfMarkersPerFile(IProject project) {
- return WebXMLPreferences.getMaxNumberOfProblemMarkersPerFile(project);
+ return JSFSeverityPreferences.getMaxNumberOfProblemMarkersPerFile(project);
}
private void addCheck(Check check, String... entities) {
@@ -106,6 +116,42 @@
addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_STATE_MANAGER,
"state-manager", false, "javax.faces.application.StateManager", null),
ENT_APP, ENT_APP_12, ENT_APP_20);
addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_VARIABLE_RESOLVER,
"variable-resolver", false, "javax.faces.el.VariableResolver", null),
ENT_APP, ENT_APP_12, ENT_APP_20);
addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_VIEW_HANDLER,
"view-handler", false, "javax.faces.application.ViewHandler", null),
ENT_APP, ENT_APP_12, ENT_APP_20);
+
+ String ENT_COMPONENT = "JSFComponent", ENT_COMPONENT_11 = ENT_COMPONENT +
SUFF_11;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_COMPONENT_CLASS,
"component-class", false, null, "javax.faces.component.UIComponent"),
ENT_COMPONENT, ENT_COMPONENT_11);
+
+ String ENT_CONVERTER = "JSFConverter";
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_CONVERTER_CLASS,
"converter-class", false, "javax.faces.convert.Converter", null),
ENT_CONVERTER);
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_CONVERTER_FOR_CLASS,
"converter-for-class", true, null, null), ENT_CONVERTER);
+
+ String ENT_FACTORY = "JSFFactory", ENT_FACTORY_20 = ENT_FACTORY + SUFF_20;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_APPLICATION_FACTORY,
"application-factory", false, null,
"javax.faces.application.ApplicationFactory"), ENT_FACTORY, ENT_FACTORY_20);
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_FACES_CONTEXT_FACTORY,
"faces-context-factory", false, null,
"javax.faces.context.FacesContextFactory"), ENT_FACTORY, ENT_FACTORY_20);
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_LIFECYCLE_FACTORY,
"lifecycle-factory", false, null,
"javax.faces.lifecycle.LifecycleFactory"), ENT_FACTORY, ENT_FACTORY_20);
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_RENDER_KIT_FACTORY,
"render-kit-factory", false, null,
"javax.faces.render.RenderKitFactory"), ENT_FACTORY, ENT_FACTORY_20);
+
+ String ENT_LIST_ENTRIES = "JSFListEntries", ENT_MAP_ENTRIES =
"JSFMapEntries";
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_KEY_CLASS,
"key-class", true, null, null), ENT_MAP_ENTRIES);
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_KEY_CLASS,
"value-class", true, null, null), ENT_LIST_ENTRIES, ENT_MAP_ENTRIES);
+
+ String ENT_MANAGED_BEAN = "JSFManagedBean", ENT_MANAGED_BEAN_20 =
ENT_MANAGED_BEAN + SUFF_20;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_BEAN_CLASS,
"managed-bean-class", false, null, null), ENT_MANAGED_BEAN,
ENT_MANAGED_BEAN_20);
+ String ENT_MANAGED_PROPERTY = "JSFManagedProperty";
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_PROPERTY_CLASS,
"property-class", false, null, null), ENT_MANAGED_PROPERTY);
+ String ENT_REFERENCED_BEAN = "JSFReferencedBean";
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_BEAN_CLASS,
"referenced-bean-class", false, null, null), ENT_REFERENCED_BEAN);
+
+ String ENT_PHASE_LISTENER = "JSFPhaseListener";
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_PHASE_LISTENER,
"phase-listener", false, null, "javax.faces.event.PhaseListener"),
ENT_PHASE_LISTENER);
+ String ENT_RENDER_KIT = "JSFRenderKit", ENT_RENDER_KIT_11 = ENT_RENDER_KIT +
SUFF_11, ENT_RENDER_KIT_12 = ENT_RENDER_KIT + SUFF_12, ENT_RENDER_KIT_20 = ENT_RENDER_KIT
+ SUFF_20;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_RENDER_KIT_CLASS,
"render-kit-class", false, null, "javax.faces.render.RenderKit"),
ENT_RENDER_KIT, ENT_RENDER_KIT_11, ENT_RENDER_KIT_12, ENT_RENDER_KIT_20);
+ String ENT_RENDERER = "JSFRenderer", ENT_RENDERER_11 = ENT_RENDERER +
SUFF_11;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_RENDERER_CLASS,
"renderer-class", false, null, "javax.faces.render.Renderer"),
ENT_RENDERER, ENT_RENDERER_11);
+ String ENT_VALIDATOR = "JSFValidator", ENT_VALIDATOR_12 = ENT_VALIDATOR +
SUFF_12;
+ addCheck(new CheckClass(this, JSFSeverityPreferences.INVALID_VALIDATOR_CLASS,
"validator-class", false, null, "javax.faces.validator.Validator"),
ENT_VALIDATOR, ENT_VALIDATOR_12);
+
+ addCheck(new JSFCheckFromViewId(this), new String[]{ENT_NAVIGATION_CASE,
ENT_NAVIGATION_CASE_20, ENT_NAVIGATION_RULE, ENT_NAVIGATION_RULE_20});
+ addCheck(new JSFCheckToViewId(this), new String[]{ENT_NAVIGATION_CASE,
ENT_NAVIGATION_CASE_20, ENT_NAVIGATION_RULE, ENT_NAVIGATION_RULE_20});
}
/*
@@ -178,8 +224,13 @@
for (IFile file: changedFiles) {
if(file.getName().endsWith(XML_EXT)) {
XModelObject o = EclipseResourceUtil.createObjectForResource(file);
- if(o != null &&
o.getModelEntity().getName().startsWith("FacesConfig")) {
- validateFile(o, file);
+ if(o != null) {
+ String entity = o.getModelEntity().getName();
+ if(entity.startsWith("FacesConfig")) {
+ validateFile(o, file);
+ } else if(entity.startsWith("FileWebApp")) {
+ new CheckContextParam(this).check(o);
+ }
}
}
}
@@ -219,7 +270,7 @@
try {
// This code line never return null
- webInf = project.getFolder(webContentPath.append("WEB-INF")); //$NON-NLS-1$
+ 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();
@@ -236,7 +287,7 @@
if(entity.startsWith("FacesConfig")) {
validateFile(o, file);
} else if(entity.startsWith("FileWebApp")) {
- //TODO
+ new CheckContextParam(this).check(o);
}
}
}
@@ -263,3 +314,124 @@
}
}
+
+class JSFCheckFromViewId extends Check {
+
+ public JSFCheckFromViewId(ValidationErrorManager manager) {
+ super(manager, JSFSeverityPreferences.INVALID_FROM_VIEW_ID,
JSFConstants.ATT_FROM_VIEW_ID);
+ }
+
+ public void check(XModelObject object) {
+ String value = object.getAttributeValue(attr);
+ if(value == null) {
+ return;
+ }
+ if(value != null && value.length() > 0 &&
!value.startsWith("*") && !value.startsWith("/")) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.VIEW_ID_NO_SLASH, attr));
+ }
+ }
+}
+
+class JSFCheckToViewId extends Check {
+
+ public JSFCheckToViewId(ValidationErrorManager manager) {
+ super(manager, JSFSeverityPreferences.INVALID_TO_VIEW_ID,
JSFConstants.ATT_TO_VIEW_ID);
+ }
+
+ public void check(XModelObject object) {
+ String value = object.getAttributeValue(attr);
+ if(value == null) {
+ return;
+ }
+ if(value.length() == 0) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.TO_VIEW_ID_EMPTY, attr));
+ } else if(!value.startsWith("/")) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.VIEW_ID_NO_SLASH, attr));
+ } else if(value.indexOf("*") >= 0) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.TO_VIEW_ID_STAR, attr));
+ } else {
+ checkEsists(object, value);
+ }
+ }
+
+ void checkEsists(XModelObject object, String value) {
+ if(value.indexOf('?') >= 0) {
+ value = value.substring(0, value.indexOf('?'));
+ }
+ XModel model = object.getModel();
+ XModelObject o = model.getByPath(value);
+ if(o == null) {
+ JSFUrlPattern pattern = JSFWebProject.getInstance(model).getUrlPattern();
+ if(pattern != null && pattern.isJSFUrl(value)) {
+ attr = pattern.getJSFPath(value);
+ o = model.getByPath(value);
+ }
+ }
+ if(o != null) {
+ IFile f = (IFile)o.getAdapter(IFile.class);
+ if(f != null) {
+ String path = f.getLocation().toOSString().replace('\\', '/');
+ if(path.endsWith(value)) return;
+ }
+ } else if(checkTiles(model, value)) {
+ return;
+ }
+ fireMessage(object, NLS.bind(JSFValidationMessage.VIEW_NOT_EXISTS, attr, value));
+ }
+
+ private boolean checkTiles(XModel model, String path) {
+ XModelObject root = JSFProjectsTree.getProjectsRoot(model);
+ if(root == null) return false;
+ XModelObject tiles = root.getChildByPath("Tiles"); //$NON-NLS-1$
+ if(tiles == null) return false;
+ XModelObject[] ts = ((WebProjectNode)tiles).getTreeChildren();
+ if(ts.length == 0) return false;
+ int d = path.lastIndexOf('.');
+ if(d < 0) return false;
+ String tileName = path.substring(0, d + 1) + "tiles"; //$NON-NLS-1$
+ tileName = tileName.replace('/', '#');
+ for (int i = 0; i < ts.length; i++) {
+ if(ts[i].getChildByPath(tileName) != null) return true;
+ }
+ return false;
+ }
+}
+
+class CheckContextParam extends Check {
+ static String CONFIG_FILES_PARAM = JSFWebHelper.FACES_CONFIG_DATA.param;
+
+ public CheckContextParam(ValidationErrorManager manager) {
+ super(manager, JSFSeverityPreferences.INVALID_CONFIG_FILES, "param-value");
+ }
+
+ public void check(XModelObject webapp) {
+ XModelObject object = WebAppHelper.findWebAppContextParam(webapp, CONFIG_FILES_PARAM);
+ if(object == null) return;
+// if(!CONFIG_FILES_PARAM.equals(object.getAttributeValue("param-name")))
return; //$NON-NLS-1$
+ String value = object.getAttributeValue("param-value"); //$NON-NLS-1$
+ if(value == null || value.length() == 0) return;
+ XModel model = object.getModel();
+ XModelObject webRoot = model == null ? null :
model.getByPath("FileSystems/WEB-ROOT"); //$NON-NLS-1$
+ if(webRoot == null) return;
+ StringTokenizer st = new StringTokenizer(value, ","); //$NON-NLS-1$
+ while(st.hasMoreTokens()) {
+ String path = st.nextToken().trim();
+ if(path.length() == 0) continue;
+ XModelObject fc = XModelImpl.getByRelativePath(model, path);
+ if(fc == null) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.INVALID_FACES_CONFIG_REFERENCE,
"param-value", path));
+ return;
+ }
+ String path2 = path.startsWith("/") ? path.substring(1) : path;
//$NON-NLS-1$
+ XModelObject fc2 = webRoot.getChildByPath(path2);
+ if(fc2 == null) {
+ fireMessage(object, NLS.bind(JSFValidationMessage.INVALID_FACES_CONFIG_REFERENCE,
"param-value", path));
+ return;
+ }
+ if(!fc2.getModelEntity().getName().startsWith("FacesConfig")) {
//$NON-NLS-1$
+ fireMessage(object, NLS.bind(JSFValidationMessage.INVALID_FACES_CONFIG_REFERENCE,
"param-value", path));
+ return;
+ }
+ }
+ }
+}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFSeverityPreferences.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFSeverityPreferences.java 2011-11-23
22:33:38 UTC (rev 36586)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFSeverityPreferences.java 2011-11-23
22:34:15 UTC (rev 36587)
@@ -40,8 +40,36 @@
public static final String INVALID_STATE_MANAGER =
INSTANCE.createSeverityOption("invalidStateManager"); //$NON-NLS-1$
public static final String INVALID_VARIABLE_RESOLVER =
INSTANCE.createSeverityOption("invalidVariableResolver"); //$NON-NLS-1$
public static final String INVALID_VIEW_HANDLER =
INSTANCE.createSeverityOption("invalidViewHandler"); //$NON-NLS-1$
+ //Component
+ public static final String INVALID_COMPONENT_CLASS =
INSTANCE.createSeverityOption("invalidComponentClass"); //$NON-NLS-1$
+ //Converter
+ public static final String INVALID_CONVERTER_CLASS =
INSTANCE.createSeverityOption("invalidConverterClass"); //$NON-NLS-1$
+ public static final String INVALID_CONVERTER_FOR_CLASS =
INSTANCE.createSeverityOption("invalidConverterForClass"); //$NON-NLS-1$
+ //Factory
+ public static final String INVALID_APPLICATION_FACTORY =
INSTANCE.createSeverityOption("invalidApplicationFactory"); //$NON-NLS-1$
+ public static final String INVALID_FACES_CONTEXT_FACTORY =
INSTANCE.createSeverityOption("invalidFacesContextFactory"); //$NON-NLS-1$
+ public static final String INVALID_LIFECYCLE_FACTORY =
INSTANCE.createSeverityOption("invalidLifecycleFactory"); //$NON-NLS-1$
+ public static final String INVALID_RENDER_KIT_FACTORY =
INSTANCE.createSeverityOption("invalidRenderKitFactory"); //$NON-NLS-1$
+ //List/Map entries
+ public static final String INVALID_VALUE_CLASS =
INSTANCE.createSeverityOption("invalidValueClass"); //$NON-NLS-1$
+ public static final String INVALID_KEY_CLASS =
INSTANCE.createSeverityOption("invalidKeyClass"); //$NON-NLS-1$
+ //Beans
+ public static final String INVALID_BEAN_CLASS =
INSTANCE.createSeverityOption("invalidBeanClass"); //$NON-NLS-1$
+ public static final String INVALID_PROPERTY_CLASS =
INSTANCE.createSeverityOption("invalidPropertyClass"); //$NON-NLS-1$
+ //Phase Listener
+ public static final String INVALID_PHASE_LISTENER =
INSTANCE.createSeverityOption("invalidPhaseListener"); //$NON-NLS-1$
+ //Render Kit
+ public static final String INVALID_RENDER_KIT_CLASS =
INSTANCE.createSeverityOption("invalidRenderKitClass"); //$NON-NLS-1$
+ //Renderer
+ public static final String INVALID_RENDERER_CLASS =
INSTANCE.createSeverityOption("invalidRendererClass"); //$NON-NLS-1$
+ //Validator
+ public static final String INVALID_VALIDATOR_CLASS =
INSTANCE.createSeverityOption("invalidValidatorClass"); //$NON-NLS-1$
+ //web.xml
+ public static final String INVALID_CONFIG_FILES =
INSTANCE.createSeverityOption("invalidConfigFiles"); //$NON-NLS-1$
+ //Navigation
+ public static final String INVALID_FROM_VIEW_ID =
INSTANCE.createSeverityOption("invalidFromViewId"); //$NON-NLS-1$
+ public static final String INVALID_TO_VIEW_ID =
INSTANCE.createSeverityOption("invalidToViewId"); //$NON-NLS-1$
-
/**
* @return the only instance of JSFSeverityPreferences
*/
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFValidationMessage.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFValidationMessage.java 2011-11-23
22:33:38 UTC (rev 36586)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/JSFValidationMessage.java 2011-11-23
22:34:15 UTC (rev 36587)
@@ -16,7 +16,13 @@
public static String XHTML_VALIDATION;
public static String XHTML_VALIDATION_NO_START_TAG;
public static String XHTML_VALIDATION_NO_END_TAG;
-
+
+ public static String VIEW_ID_NO_SLASH;
+ public static String TO_VIEW_ID_EMPTY;
+ public static String TO_VIEW_ID_STAR;
+ public static String VIEW_NOT_EXISTS;
+ public static String INVALID_FACES_CONFIG_REFERENCE;
+
static {
NLS.initializeMessages(BUNDLE_NAME, JSFValidationMessage.class);
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/messages.properties
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/messages.properties 2011-11-23
22:33:38 UTC (rev 36586)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/messages.properties 2011-11-23
22:34:15 UTC (rev 36587)
@@ -9,4 +9,10 @@
XHTML_VALIDATION=XHTML Syntax Validation: {0}
XHTML_VALIDATION_NO_START_TAG=No start tag for element "{0}"
-XHTML_VALIDATION_NO_END_TAG=No end tag for element "{0}"
\ No newline at end of file
+XHTML_VALIDATION_NO_END_TAG=No end tag for element "{0}"
+
+VIEW_ID_NO_SLASH=Attribute {0} must start with \/
+TO_VIEW_ID_EMPTY=Attribute {0} must not be empty
+TO_VIEW_ID_STAR=Attribute {0} must not contain *
+VIEW_NOT_EXISTS=Attribute {0} references to {1} that does not exist
+INVALID_FACES_CONFIG_REFERENCE=Attribute {0} references to {1} that is not a valid faces
config file
\ No newline at end of file