Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgkessler2010-03-29 17:13:30 +0000
committergkessler2010-03-29 17:13:30 +0000
commitd9af055f02173ba1f30360cb380e973b21176420 (patch)
treec41820c9083774b73f315bd4d5d15b2507ec0ee9
parent45810f454bb515ff2c7b62eb1c6e4f975bccde26 (diff)
downloadwebtools.jsf-d9af055f02173ba1f30360cb380e973b21176420.tar.gz
webtools.jsf-d9af055f02173ba1f30360cb380e973b21176420.tar.xz
webtools.jsf-d9af055f02173ba1f30360cb380e973b21176420.zip
[306312] Remove containment validation on f:view tag in an XHTML Facelet doc
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/ContainmentValidatingStrategy.java37
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/DiagnosticFactory.java169
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/Messages.java16
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/messages.properties4
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.ui/src/org/eclipse/jst/jsf/facelet/ui/internal/validation/ValidationReporter.java33
5 files changed, 231 insertions, 28 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/ContainmentValidatingStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/ContainmentValidatingStrategy.java
index aff0083dc..f7062d5f0 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/ContainmentValidatingStrategy.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/ContainmentValidatingStrategy.java
@@ -10,11 +10,9 @@
*******************************************************************************/
package org.eclipse.jst.jsf.validation.internal.strategy;
-import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jst.jsf.common.dom.DOMAdapter;
import org.eclipse.jst.jsf.common.dom.TagIdentifier;
@@ -30,6 +28,7 @@ import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocume
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.core.internal.region.Region2ElementAdapter;
+import org.eclipse.jst.jsf.core.internal.tld.IJSFConstants;
import org.eclipse.jst.jsf.core.internal.tld.TagIdentifierFactory;
import org.eclipse.jst.jsf.core.set.constraint.MemberConstraint;
import org.eclipse.jst.jsf.core.set.mapping.ElementToTagIdentifierMapping;
@@ -191,38 +190,36 @@ public class ContainmentValidatingStrategy extends
final TagIdentifier missingParent = (TagIdentifier) it
.next();
- reportContainmentProblem(context, node.getNodeName(),
- Diagnostic.WARNING,
- missingParent.getTagName(), missingParent
- .getUri());
+ reportContainmentProblem(context, node, missingParent);
}
}
}
}
}
- private static final String MESSAGE_PATTERN =
- "Tag {0} is missing required parent tag \"{1}\" ({2})"; //$NON-NLS-1$
-
- // TODO: need a diagnostic factory
private void reportContainmentProblem(
final IStructuredDocumentContext context,
- final String nodeName, final int severity,
- final String tagName, final String uri)
+ final Node node,
+ final TagIdentifier missingParent)
{
- final String msg = MessageFormat.format(
- MESSAGE_PATTERN, new Object[]
- {nodeName, tagName, uri});
+ Diagnostic diagnostic = null;
+ if (missingParent.equals(IJSFConstants.TAG_IDENTIFIER_VIEW)) {
+ diagnostic = DiagnosticFactory.create_CONTAINMENT_ERROR_MISSING_VIEW(node.getNodeName());
+ }
+ else if (missingParent.equals(IJSFConstants.TAG_IDENTIFIER_FORM)) {
+ diagnostic = DiagnosticFactory.create_CONTAINMENT_ERROR_MISSING_FORM(node.getNodeName());
+ }
+ else {
+ diagnostic = DiagnosticFactory.create_CONTAINMENT_ERROR_MISSING_ANCESTOR(node.getNodeName(), missingParent);
+ }
- final Diagnostic problem =
- new BasicDiagnostic(severity, "", -1, msg, null); //$NON-NLS-1$
// add one so that the start offset is at the node name, rather
// than the opening brace.
final int start = context.getDocumentPosition()+1;
- final int length = nodeName.length();
+ final int length = node.getNodeName().length();
- _jsfValidationContext.getReporter().report(problem, start, length);
+ _jsfValidationContext.getReporter().report(diagnostic, start, length);
}
-
+
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/DiagnosticFactory.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/DiagnosticFactory.java
new file mode 100644
index 000000000..809bff237
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/DiagnosticFactory.java
@@ -0,0 +1,169 @@
+package org.eclipse.jst.jsf.validation.internal.strategy;
+
+import java.util.Locale;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.jst.jsf.common.dom.TagIdentifier;
+import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
+import org.eclipse.jst.jsf.validation.internal.appconfig.ILocalizedMessage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.validation.internal.core.Message;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+
+/**
+ * Diagnostic factory for JSF views
+ *
+ */
+public final class DiagnosticFactory {
+
+ /**
+ * The id used in the source field of all Diagnostic's created by this factory
+ * to uniquely identify tag validation as their source type.
+ */
+ public final static String SOURCE_ID = "org.eclipse.jst.jsf.validation.tag.Diagnostics";//$NON-NLS-1$
+
+ /**
+ * Problem id
+ */
+ public final static int CONTAINMENT_ERROR_MISSING_VIEW = 1;
+
+ /**
+ * Problem id
+ */
+ public final static int CONTAINMENT_ERROR_MISSING_FORM = 2;
+
+ /**
+ * Problem id
+ */
+ public static final int CONTAINMENT_ERROR_MISSING_ANCESTOR = 3;
+
+
+ /**
+ * @param tagName
+ * @return message indicating a JSF view tag is missing as an ancestor
+ */
+ public static Diagnostic create_CONTAINMENT_ERROR_MISSING_VIEW(final String tagName)
+ {
+ return create(CONTAINMENT_ERROR_MISSING_VIEW,
+ NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_VIEW, tagName));
+ }
+
+ /**
+ * @param tagName
+ * @return message indicating a JSF form tag is missing as an ancestor
+ */
+ public static Diagnostic create_CONTAINMENT_ERROR_MISSING_FORM(final String tagName)
+ {
+ return create(CONTAINMENT_ERROR_MISSING_FORM,
+ NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_FORM, tagName));
+ }
+
+ /**
+ * @param tagName
+ * @param missingTag
+ * @return message indicating some tag is missing as an ancestor
+ */
+ public static Diagnostic create_CONTAINMENT_ERROR_MISSING_ANCESTOR(final String tagName, final TagIdentifier missingTag)
+ {
+
+ return create(CONTAINMENT_ERROR_MISSING_ANCESTOR,
+ NLS.bind(Messages.CONTAINMENT_ERROR_MISSING_ANCESTOR,
+ new Object[]{ tagName, missingTag.getUri(), missingTag.getTagName()}));
+ }
+
+ private static BasicDiagnostic create(final int diagnosticId, final String message)
+ {
+ final int severity = IMessage.NORMAL_SEVERITY;//ELValidationPreferences.getDefaultSeverity(diagnosticId);
+ return new BasicDiagnostic(severity, SOURCE_ID
+ , diagnosticId
+ , message
+ , null);
+ }
+ /**
+ * Customized localizable message for view validation
+ * @author cbateman
+ *
+ */
+ static class MyLocalizedMessage extends Message implements ILocalizedMessage
+ {
+ private final String _message;
+ private final int _errorCode;
+
+ /**
+ * @param severity
+ * @param messageText
+ * @param targetObject
+ * @param errorCode
+ */
+ public MyLocalizedMessage(int severity, String messageText, IResource targetObject, int errorCode) {
+ this(severity, messageText, (Object) targetObject, errorCode);
+ }
+
+ /**
+ * @param severity
+ * @param messageText
+ * @param targetObject
+ * @param errorCode
+ */
+ private MyLocalizedMessage(int severity, String messageText, Object targetObject, int errorCode) {
+ super(JSFCorePlugin.getDefault().getBundle().getSymbolicName(), severity,
+ messageText);
+ _message = messageText;
+ setTargetObject(targetObject);
+ _errorCode = errorCode;
+ }
+
+ /**
+ * @return the localized message
+ */
+ public String getLocalizedMessage() {
+ return _message;
+ }
+
+ /**
+ * @see org.eclipse.wst.validation.internal.core.Message#getText()
+ */
+ public String getText() {
+ return getLocalizedMessage();
+ }
+
+ /**
+ * @see org.eclipse.wst.validation.internal.core.Message#getText(java.lang.ClassLoader)
+ */
+ public String getText(ClassLoader cl) {
+ return getLocalizedMessage();
+ }
+
+ /**
+ * @see org.eclipse.wst.validation.internal.core.Message#getText(java.util.Locale)
+ */
+ public String getText(Locale l) {
+ return getLocalizedMessage();
+ }
+
+ public String getText(Locale l, ClassLoader cl) {
+ return getLocalizedMessage();
+ }
+
+ /**
+ * @return the error code related to this message
+ */
+ public int getErrorCode() {
+ return _errorCode;
+ }
+
+
+ /**
+ * @param offset
+ * @return true if this message applies to document offset
+ */
+ public boolean appliesTo(int offset)
+ {
+ return (offset >= getOffset() && offset < getOffset()+getLength());
+ }
+ }
+
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/Messages.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/Messages.java
index 2bf113d9f..6d8801714 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/Messages.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/Messages.java
@@ -22,10 +22,26 @@ public class Messages extends NLS {
* see messages.properties
*/
public static String AttributeValidatingStrategy_DisplayName;
+
/**
* see messages.properties
*/
public static String ContainmentValidatingStrategy_DisplayName;
+
+ /**
+ * see messages.properties
+ */
+ public static String CONTAINMENT_ERROR_MISSING_VIEW;
+
+ /**
+ * see messages.properties
+ */
+ public static String CONTAINMENT_ERROR_MISSING_FORM;
+
+ /**
+ * see messages.properties
+ */
+ public static String CONTAINMENT_ERROR_MISSING_ANCESTOR;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/messages.properties b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/messages.properties
index fbb4eed0c..71e68e3b8 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/messages.properties
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/messages.properties
@@ -1,2 +1,6 @@
AttributeValidatingStrategy_DisplayName=Attribute Validator
ContainmentValidatingStrategy_DisplayName=Tag Containment Validator
+
+CONTAINMENT_ERROR_MISSING_VIEW={0} requires f:view ancestor
+CONTAINMENT_ERROR_MISSING_FORM={0} requires h:form ancestor
+CONTAINMENT_ERROR_MISSING_ANCESTOR={0} requires {1} ancestor
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.ui/src/org/eclipse/jst/jsf/facelet/ui/internal/validation/ValidationReporter.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.ui/src/org/eclipse/jst/jsf/facelet/ui/internal/validation/ValidationReporter.java
index 297167f87..cee0fc0e2 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.ui/src/org/eclipse/jst/jsf/facelet/ui/internal/validation/ValidationReporter.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.ui/src/org/eclipse/jst/jsf/facelet/ui/internal/validation/ValidationReporter.java
@@ -5,6 +5,7 @@ import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jst.jsf.ui.internal.validation.ValidationMessageFactory;
import org.eclipse.jst.jsf.validation.internal.IJSFViewValidator;
import org.eclipse.jst.jsf.validation.internal.ValidationPreferences;
+import org.eclipse.jst.jsf.validation.internal.strategy.DiagnosticFactory;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
@@ -31,17 +32,33 @@ import org.eclipse.wst.validation.internal.provisional.core.IValidator;
public void report(final Diagnostic problem, final int start,
final int length)
{
- final IMessage message = _factory.createFromDiagnostic(
- problem, start, length, _file);
-
- if ((message.getSeverity() & IMessage.ALL_MESSAGES) != 0)
- {
- _reporter.addMessage(_validator, message);
- }
+ if (shouldReportProblem(problem.getCode())) {
+ final IMessage message = _factory.createFromDiagnostic(
+ problem, start, length, _file);
+
+ if ((message.getSeverity() & IMessage.ALL_MESSAGES) != 0)
+ {
+ _reporter.addMessage(_validator, message);
+ }
+ }
}
- public void report(IMessage message)
+ /**
+ * @param problemCode
+ * @return filters out problems to be reported by code
+ */
+ private boolean shouldReportProblem(final int problemCode) {
+ switch (problemCode) {
+ case DiagnosticFactory.CONTAINMENT_ERROR_MISSING_VIEW:
+ return false;
+ default:
+ return true;
+ }
+ }
+
+ public void report(IMessage message)
{
+ //not capable of filtering problems by code... should not be used
if ((message.getSeverity() & IMessage.ALL_MESSAGES) != 0)
{
_reporter.addMessage(_validator, message);

Back to the top