diff options
Diffstat (limited to 'bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate')
24 files changed, 0 insertions, 2947 deletions
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java deleted file mode 100644 index 3e9d85d028..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import org.eclipse.wst.sse.core.internal.validate.ErrorInfo; - -abstract class AbstractErrorInfo implements ErrorInfo, ErrorState { - - - private int state = NONE_ERROR; - private Segment seg = null; - - public AbstractErrorInfo(int state, Segment seg) { - super(); - this.state = state; - this.seg = seg; - } - - abstract public String getHint(); - - abstract public short getTargetType(); - - public int getLength() { - return (seg == null) ? 0 : seg.getLength(); - } - - public int getOffset() { - return (seg == null) ? 0 : seg.getOffset(); - } - - public int getState() { - return this.state; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CMUtil.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CMUtil.java deleted file mode 100644 index 1809abdaf3..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CMUtil.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import java.util.Iterator; - -import org.eclipse.wst.html.core.internal.modelquery.HMQUtil; -import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -final class CMUtil { - - /** - * Never instantiate! - */ - private CMUtil() { - super(); - } - - /** - * You cannot always retrieve HTMLElementDeclaration via an Element instance. - * Because, it occasionally a JSP custom tag. -- 9/7/2001 - */ - public static CMElementDeclaration getDeclaration(Element target) { - Document doc = target.getOwnerDocument(); - ModelQuery query = ModelQueryUtil.getModelQuery(doc); - return query.getCMElementDeclaration(target); - } - - /** - */ - public static boolean isCaseSensitive(CMElementDeclaration decl) { - if (decl == null || (!decl.supports(HTMLCMProperties.SHOULD_IGNORE_CASE))) - return false; - return !((Boolean) decl.getProperty(HTMLCMProperties.SHOULD_IGNORE_CASE)).booleanValue(); - } - - /** - */ - private static boolean isChild(CMContent content, CMElementDeclaration target) { - switch (content.getNodeType()) { - case CMNode.ELEMENT_DECLARATION : - if (isWholeTagOmissible((CMElementDeclaration) content)) - if (isChild(((CMElementDeclaration) content).getContent(), target)) - return true; - return isSameDeclaration((CMElementDeclaration) content, target); - case CMNode.GROUP : - CMNodeList children = ((CMGroup) content).getChildNodes(); - for (int i = 0; i < children.getLength(); i++) { - CMNode child = children.item(i); - switch (child.getNodeType()) { - case CMNode.ELEMENT_DECLARATION : - if (isWholeTagOmissible((CMElementDeclaration) child)) - if (isChild(((CMElementDeclaration) child).getContent(), target)) - return true; - if (isSameDeclaration((CMElementDeclaration) child, target)) - return true; - continue; // Go next child. - case CMNode.GROUP : - if (isChild((CMContent) child, target)) - return true; - continue; // Go next child. - default : - continue; // Go next child. - } - } - } - return false; - } - - /** - */ - public static boolean isEndTagOmissible(CMElementDeclaration decl) { - if (!(decl.supports(HTMLCMProperties.OMIT_TYPE))) - return false; - String omitType = (String) decl.getProperty(HTMLCMProperties.OMIT_TYPE); - return !omitType.equals(HTMLCMProperties.Values.OMIT_NONE); - } - - /** - */ - public static boolean isWholeTagOmissible(CMElementDeclaration decl) { - if (!(decl.supports(HTMLCMProperties.OMIT_TYPE))) - return false; - String omitType = (String) decl.getProperty(HTMLCMProperties.OMIT_TYPE); - return omitType.equals(HTMLCMProperties.Values.OMIT_BOTH); - } - - /** - */ - public static boolean isJSP(CMElementDeclaration decl) { - if (!decl.supports(HTMLCMProperties.IS_JSP)) - return false; - return ((Boolean) decl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue(); - } - - /** - */ - public static boolean isXHTML(CMElementDeclaration decl) { - if (!decl.supports(HTMLCMProperties.IS_XHTML)) - return false; - return ((Boolean) decl.getProperty(HTMLCMProperties.IS_XHTML)).booleanValue(); - } - - /** - * The method to distinguish HTML and XHTML from other mark up. - * This method returns true if the target is, - * (1) not JSP, - * (2) not SSI. - */ - public static boolean isHTML(CMElementDeclaration decl) { - return (!isJSP(decl)) && (!isSSI(decl)); - } - - /** - */ - private static boolean isSameDeclaration(CMElementDeclaration aDec, CMElementDeclaration otherDec) { - return aDec.getElementName() == otherDec.getElementName(); - } - - /** - */ - public static boolean isSSI(CMElementDeclaration edec) { - if (edec == null) - return false; - if (!edec.supports(HTMLCMProperties.IS_SSI)) - return false; - return ((Boolean) edec.getProperty(HTMLCMProperties.IS_SSI)).booleanValue(); - } - - /** - * Call this method only when the parent content type is one of - * the following: ANY, ELEMENT, or MIXED. - */ - public static boolean isValidChild(CMElementDeclaration parent, CMElementDeclaration child) { - if (parent == null || child == null) - return false; - if (isHTML(parent) && (!isHTML(child))) - return true; - CMContent content = parent.getContent(); - if (content == null) - return false; - return isChild(content, child); - } - - public static boolean isForeign(Element target) { - if (!(target instanceof IDOMElement)) - return true; - IDOMElement element = (IDOMElement) target; - return !element.isGlobalTag(); - } - - /** - * This method returns true if all of the following conditions are met: - * (1) value type is ENUM, - * (2) only one value is defined in the enumeration, - * (3) the value has same name to the attribute name. - */ - public static boolean isBooleanAttr(CMAttributeDeclaration adec) { - CMDataType attrtype = adec.getAttrType(); - if (attrtype == null) - return false; - if (attrtype.getDataTypeName() != CMDataType.ENUM) - return false; - String[] values = attrtype.getEnumeratedValues(); - if (values.length != 1) - return false; - return values[0].equals(adec.getAttrName()); - } - - public static boolean isValidInclusion(CMElementDeclaration decl, Element parent) { - Iterator iter = HMQUtil.getInclusions(parent).iterator(); - while (iter.hasNext()) { - CMElementDeclaration inclusion = (CMElementDeclaration) iter.next(); - if (isSameDeclaration(decl, inclusion)) - return true; - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CompositeValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CompositeValidator.java deleted file mode 100644 index b0e752305f..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/CompositeValidator.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; -import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -abstract class CompositeValidator extends ValidationComponent { - - protected Vector components = new Vector(); - - /** - * CompositeValidator constructor comment. - */ - public CompositeValidator() { - super(); - } - - /** - */ - public void setReporter(ValidationReporter reporter) { - super.setReporter(reporter); - - Iterator i = components.iterator(); - while (i.hasNext()) { - ValidationAdapter component = (ValidationAdapter) i.next(); - if (component == null) - continue; - component.setReporter(reporter); - } - } - - /** - */ - public void validate(IndexedRegion node) { - Iterator i = components.iterator(); - while (i.hasNext()) { - ValidationComponent component = (ValidationComponent) i.next(); - if (component == null) - continue; - component.validate(node); - } - } - - /** - */ - void add(ValidationComponent validator) { - components.add(validator); - } - - /** - * This method registers all components in 'validators'. - * Each derivative must call this methid in its constructor. - */ - protected void register(ValidationComponent[] validators) { - for (int i = 0; i < validators.length; i++) { - if (validators[i] != null) - add(validators[i]); - } - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/DocumentPropagatingValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/DocumentPropagatingValidator.java deleted file mode 100644 index 562915b136..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/DocumentPropagatingValidator.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; -import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; -import org.eclipse.wst.xml.core.internal.validate.AbstractPropagatingValidator; -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -class DocumentPropagatingValidator extends AbstractPropagatingValidator { - - - private ValidationComponent validator = new HTMLSimpleDocumentValidator(); - private ElementPropagatingValidator propagatee = new ElementPropagatingValidator(); - - public DocumentPropagatingValidator() { - super(); - } - - public void validate(IndexedRegion node) { - getPropagatee().setReporter(this.reporter); - super.validate(node); - } - - public boolean isAdapterForType(Object type) { - return (type == DocumentPropagatingValidator.class || super.isAdapterForType(type)); - } - - public void setReporter(ValidationReporter reporter) { - super.setReporter(reporter); - validator.setReporter(reporter); - propagatee.setReporter(reporter); - } - - protected final ValidationComponent getPropagatee() { - return propagatee; - } - - protected final ValidationAdapter getValidator() { - return validator; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ElementPropagatingValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ElementPropagatingValidator.java deleted file mode 100644 index c290b6230d..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ElementPropagatingValidator.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; -import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; -import org.eclipse.wst.xml.core.internal.validate.AbstractPropagatingValidator; -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -class ElementPropagatingValidator extends AbstractPropagatingValidator { - - - private ValidationComponent validator = new HTMLSimpleValidator(); - - public ElementPropagatingValidator() { - super(); - } - - public boolean isAdapterForType(Object type) { - return (type == ElementPropagatingValidator.class || super.isAdapterForType(type)); - } - - public void setReporter(ValidationReporter reporter) { - super.setReporter(reporter); - validator.setReporter(reporter); - } - - protected ValidationComponent getPropagatee() { - return this; - } - - protected ValidationAdapter getValidator() { - return validator; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java deleted file mode 100644 index 4710a1eee8..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.w3c.dom.Attr; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -final class ErrorInfoImpl extends AbstractErrorInfo { - - private Node target = null; - - // private Segment seg = null; - /** - */ - public ErrorInfoImpl(int state, Segment errorSeg, Node target) { - super(state, errorSeg); - this.target = target; - } - - /** - */ - public String getHint() { - switch (target.getNodeType()) { - case Node.ATTRIBUTE_NODE : - switch (getState()) { - case UNDEFINED_VALUE_ERROR : - case MISMATCHED_VALUE_ERROR : - case UNCLOSED_ATTR_VALUE : - case RESOURCE_NOT_FOUND : - //D210422 - return ((Attr) target).getValue(); - default : - return target.getNodeName(); - } - case Node.TEXT_NODE : - return ((Text) target).getData(); - case Node.ELEMENT_NODE : - default : - return target.getNodeName(); - } - } - - public short getTargetType() { - return target.getNodeType(); - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java deleted file mode 100644 index 03183ead34..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -interface ErrorState { - static final int NONE_ERROR = 0; - // generic error - static final int UNDEFINED_NAME_ERROR = 11; - static final int UNDEFINED_VALUE_ERROR = 12; - static final int MISMATCHED_VALUE_ERROR = 13; - // format error - static final int FORMAT_ERROR_LEVEL = 100; - static final int INVALID_NAME_ERROR = 101; - static final int INVALID_CHAR_ERROR = 102; - static final int MISMATCHED_ERROR = 103; - static final int MISMATCHED_END_TAG_ERROR = 104; - static final int MISSING_START_TAG_ERROR = 105; - static final int MISSING_END_TAG_ERROR = 106; - static final int UNNECESSARY_END_TAG_ERROR = 107; - static final int INVALID_ATTR_ERROR = 108; - static final int INVALID_DIRECTIVE_ERROR = 109; - static final int UNCLOSED_TAG_ERROR = 110; - static final int UNCLOSED_END_TAG_ERROR = 111; - static final int INVALID_EMPTY_ELEMENT_TAG = 112; - static final int UNCLOSED_ATTR_VALUE = 113; //D210422 - static final int RESOURCE_NOT_FOUND = 114; //D210422 - // layout error - static final int LAYOUT_ERROR_LEVEL = 1000; - static final int INVALID_CONTENT_ERROR = 1001; - static final int DUPLICATE_ERROR = 1002; - static final int COEXISTENCE_ERROR = 1003; -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/FMUtil.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/FMUtil.java deleted file mode 100644 index f3ee02a826..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/FMUtil.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; - -final class FMUtil { - - public final static int SEG_NONE = 0; - public final static int SEG_WHOLE_TAG = 1; - public final static int SEG_START_TAG = 2; - public final static int SEG_END_TAG = 3; - public final static int SEG_START_TAG_NAME = 4; - public final static int SEG_END_TAG_NAME = 5; - - /** - */ - private FMUtil() { - super(); - } - - /** - */ - public final static Segment getSegment(IDOMNode target, int segType) { - if (target == null) - return new Segment(0, 0); - Segment seg = null; - IStructuredDocumentRegion startTag = null; - IStructuredDocumentRegion endTag = null; - switch (segType) { - case SEG_WHOLE_TAG : - startTag = target.getFirstStructuredDocumentRegion(); - if (startTag != null) { - endTag = target.getLastStructuredDocumentRegion(); - seg = new Segment(startTag, endTag); - } - else { - int startOffset = target.getStartOffset(); - int endOffset = target.getEndOffset(); - seg = new Segment(startOffset, endOffset - startOffset); - } - break; - case SEG_START_TAG : - startTag = target.getStartStructuredDocumentRegion(); - if (startTag != null) { - seg = new Segment(startTag); - } - else { - seg = new Segment(target.getStartOffset(), 1); - } - break; - case SEG_END_TAG : - endTag = target.getEndStructuredDocumentRegion(); - if (endTag != null) { - seg = new Segment(endTag); - } - else { - seg = new Segment(target.getEndOffset(), 1); - } - break; - case SEG_START_TAG_NAME : - startTag = target.getStartStructuredDocumentRegion(); - if (startTag != null) { - ITextRegion nameRegion = getNameRegion(startTag); - if (nameRegion != null) { - seg = new Segment(startTag.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - } - if (seg == null) { - seg = getSegment(target, SEG_START_TAG); - } - break; - case SEG_END_TAG_NAME : - endTag = target.getEndStructuredDocumentRegion(); - if (endTag != null) { - ITextRegion nameRegion = getNameRegion(endTag); - if (nameRegion != null) { - seg = new Segment(endTag.getStartOffset(nameRegion), nameRegion.getTextLength()); - } - } - if (seg == null) { - seg = getSegment(target, SEG_END_TAG); - } - break; - case SEG_NONE : - default : - return new Segment(0, 0); - } - return seg; - } - - private static ITextRegion getNameRegion(ITextRegionCollection containerRegion) { - ITextRegionList regions = containerRegion.getRegions(); - ITextRegion nameRegion = null; - for (int i = 0; i < regions.size(); i++) { - ITextRegion r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - nameRegion = r; - break; - } - } - return nameRegion ; - } - -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java deleted file mode 100644 index f96eaf4a07..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.util.List; -import java.util.Locale; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - -public class HTMLAttributeValidator extends PrimeValidator { - - private static final int REGION_NAME = 1; - private static final int REGION_VALUE = 2; - // <<D210422 - private static final char SINGLE_QUOTE = '\''; - private static final char DOUBLE_QUOTE = '\"'; - - // D210422 - /** - * HTMLAttributeValidator constructor comment. - */ - public HTMLAttributeValidator() { - super(); - } - - /** - */ - private Segment getErrorSegment(IDOMNode errorNode, int regionType) { - ITextRegion rgn = null; - switch (regionType) { - case REGION_NAME : - rgn = errorNode.getNameRegion(); - break; - case REGION_VALUE : - rgn = errorNode.getValueRegion(); - break; - default : - // nothing to do. - break; - } - if (rgn != null) { - if (errorNode instanceof IDOMAttr) { - IDOMElement ownerElement = (IDOMElement) ((IDOMAttr) errorNode).getOwnerElement(); - if (ownerElement != null) { - int regionStartOffset = ownerElement.getFirstStructuredDocumentRegion().getStartOffset(rgn); - int regionLength = rgn.getTextLength(); - return new Segment(regionStartOffset, regionLength); - } - } - } - return new Segment(errorNode.getStartOffset(), 1); - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLAttributeValidator.class) || super.isAdapterForType(type)); - } - - /** - */ - public void validate(IndexedRegion node) { - Element target = (Element) node; - if (CMUtil.isForeign(target)) - return; - CMElementDeclaration edec = CMUtil.getDeclaration(target); - if (edec == null) - return; - CMNamedNodeMap declarations = edec.getAttributes(); - - List modelQueryNodes = null; - NamedNodeMap attrs = target.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - int rgnType = REGION_NAME; - int state = ErrorState.NONE_ERROR; - Attr a = (Attr) attrs.item(i); - // D203637; If the target attr has prefix, the validator should - // not - // warn about it. That is, just ignore. It is able to check - // whether - // an attr has prefix or not by calling XMLAttr#isGlobalAttr(). - // When a attr has prefix (not global), it returns false. - boolean isXMLAttr = a instanceof IDOMAttr; - if (isXMLAttr) { - IDOMAttr xmlattr = (IDOMAttr) a; - if (!xmlattr.isGlobalAttr()) - continue; // skip futher validation and begin next loop. - } - - CMAttributeDeclaration adec = (CMAttributeDeclaration) declarations.getNamedItem(a.getName()); - - /* Check the modelquery if nothing is declared by the element declaration */ - if (adec == null) { - if (modelQueryNodes == null) - modelQueryNodes = ModelQueryUtil.getModelQuery(target.getOwnerDocument()).getAvailableContent((Element) node, edec, ModelQuery.INCLUDE_ATTRIBUTES); - - String attrName = a.getName().toLowerCase(Locale.US); - for (int k = 0; k < modelQueryNodes.size(); k++) { - CMNode cmnode = (CMNode) modelQueryNodes.get(k); - if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION && cmnode.getNodeName().toLowerCase(Locale.US).equals(attrName)) { - adec = (CMAttributeDeclaration) cmnode; - break; - } - } - } - - if (adec == null) { - // No attr declaration was found. That is, the attr name is - // undefined. - // but not regard it as undefined name if it includes nested - // region - if (!hasNestedRegion(((IDOMNode) a).getNameRegion())) { - rgnType = REGION_NAME; - state = ErrorState.UNDEFINED_NAME_ERROR; - } - } else { - // The attr declaration was found. - // At 1st, the name should be checked. - if (CMUtil.isHTML(edec) && (!CMUtil.isXHTML(edec))) { - // If the target element is pure HTML (not XHTML), some - // attributes - // might be written in boolean format. It should be check - // specifically. - if (CMUtil.isBooleanAttr(adec) && ((IDOMAttr) a).hasNameOnly()) - continue; // OK, keep going. No more check is needed - // against this attr. - } else { - // If the target is other than pure HTML (JSP or XHTML), - // the name - // must be checked exactly (ie in case sensitive way). - String actual = a.getName(); - String desired = adec.getAttrName(); - if (!actual.equals(desired)) { // case mismatch - rgnType = REGION_NAME; - state = ErrorState.MISMATCHED_ERROR; - } - } - // Then, the value must be checked. - if (state == ErrorState.NONE_ERROR) { // Need more check. - // Now, the value should be checked, if the type is ENUM. - CMDataType attrType = adec.getAttrType(); - String actualValue = a.getValue(); - if (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED) { - // Check FIXED value. - String validValue = attrType.getImpliedValue(); - if (!actualValue.equals(validValue)) { - rgnType = REGION_VALUE; - state = ErrorState.UNDEFINED_VALUE_ERROR; - } - } - else if (CMDataType.URI.equals(attrType.getDataTypeName())) { - // TODO: URI validation? - if (false && actualValue.indexOf('#') < 0 && actualValue.indexOf(":/") == -1 && CMUtil.isHTML(edec)) { //$NON-NLS-1$ //$NON-NLS-2$ - IStructuredDocumentRegion start = ((IDOMNode) node).getStartStructuredDocumentRegion(); - if (start != null && start.getFirstRegion().getTextLength() == 1) { - IPath basePath = new Path(((IDOMNode) node).getModel().getBaseLocation()); - if (basePath.segmentCount() > 1) { - IPath path = ModuleCoreSupport.resolve(basePath, actualValue); - IResource found = ResourcesPlugin.getWorkspace().getRoot().findMember(path); - if (found == null || !found.isAccessible()) { - rgnType = REGION_VALUE; - state = ErrorState.RESOURCE_NOT_FOUND; - } - } - } - } - } - else if (CMDataType.ENUM.equals(attrType.getDataTypeName())) { - /* - * Check current value is valid among a known list. - * There may be enumerated values provided even when - * the datatype is not ENUM, but we'll only validate - * against that list if the type matches. - */ - String[] enumeratedValues = attrType.getEnumeratedValues(); - // several candidates are found. - boolean found = false; - for (int j = 0; j < enumeratedValues.length; j++) { - // At 1st, compare ignoring case. - if (actualValue.equalsIgnoreCase(enumeratedValues[j])) { - found = true; - if (CMUtil.isCaseSensitive(edec) && (!actualValue.equals(enumeratedValues[j]))) { - rgnType = REGION_VALUE; - state = ErrorState.MISMATCHED_VALUE_ERROR; - } - break; // exit the loop. - } - } - if (!found) { - // retrieve and check extended values (retrieval can call extensions, which may take longer) - String[] modelQueryExtensionValues = ModelQueryUtil.getModelQuery(target.getOwnerDocument()).getPossibleDataTypeValues((Element) node, adec); - // copied loop from above - for (int j = 0; j < modelQueryExtensionValues.length; j++) { - // At 1st, compare ignoring case. - if (actualValue.equalsIgnoreCase(modelQueryExtensionValues[j])) { - found = true; - if (CMUtil.isCaseSensitive(edec) && (!actualValue.equals(modelQueryExtensionValues[j]))) { - rgnType = REGION_VALUE; - state = ErrorState.MISMATCHED_VALUE_ERROR; - } - break; // exit the loop. - } - } - // No candidate was found. That is, - // actualValue is invalid. - // but not regard it as undefined value if it - // includes nested region. - if (!hasNestedRegion(((IDOMNode) a).getValueRegion())) { - rgnType = REGION_VALUE; - state = ErrorState.UNDEFINED_VALUE_ERROR; - } - } - } - } - // <<D210422 - if (state == ErrorState.NONE_ERROR) { // Need more check. - if (isXMLAttr) { - String source = ((IDOMAttr) a).getValueRegionText(); - if (source != null) { - char firstChar = source.charAt(0); - char lastChar = source.charAt(source.length() - 1); - if (isQuote(firstChar) || isQuote(lastChar)) { - if (lastChar != firstChar) { - rgnType = REGION_VALUE; - state = ErrorState.UNCLOSED_ATTR_VALUE; - } - } - } - } - } - // D210422 - } - if (state != ErrorState.NONE_ERROR) { - Segment seg = getErrorSegment((IDOMNode) a, rgnType); - if (seg != null) - reporter.report(new ErrorInfoImpl(state, seg, a)); - } - } - } - - /** - * True if container has nested regions, meaning container is probably too - * complicated (like JSP regions) to validate with this validator. - */ - private boolean hasNestedRegion(ITextRegion container) { - if (!(container instanceof ITextRegionContainer)) - return false; - ITextRegionList regions = ((ITextRegionContainer) container).getRegions(); - if (regions == null) - return false; - // BUG207194: return true by default as long as container is an - // ITextRegionContainer with at least 1 region - return true; - } - - // <<D214022 - private boolean isQuote(char c) { - return (c == SINGLE_QUOTE) || (c == DOUBLE_QUOTE); - } - // D210422 -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLDocumentContentValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLDocumentContentValidator.java deleted file mode 100644 index cb6cab3115..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLDocumentContentValidator.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class HTMLDocumentContentValidator extends PrimeValidator { - - - private final static class Division { - private Vector explicitHtmls = new Vector(); - private Vector rest = new Vector(); - - public Division(Document document, NodeList children) { - String rootTagName = getRootTagName(document); - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (isHtmlTag(child, rootTagName)) { - explicitHtmls.add(child); - } - else { - rest.add(child); - } - } - } - - public boolean hasExplicitHtmls() { - return explicitHtmls.size() > 0; - } - - public List getExplicitHtmls() { - return explicitHtmls; - } - - public Iterator getRestNodes() { - return rest.iterator(); - } - - /* utilities */ - private static boolean isHtmlTag(Node node, String tagName) { - if (node.getNodeType() != Node.ELEMENT_NODE) - return false; - return ((Element) node).getTagName().equalsIgnoreCase(tagName); - } - - private static String getRootTagName(Document document) { - DocumentTypeAdapter adapter = (DocumentTypeAdapter) ((IDOMDocument) document).getAdapterFor(DocumentTypeAdapter.class); - if (adapter != null) { - DocumentType docType = adapter.getDocumentType(); - if (docType != null) { - return docType.getName(); - } - } - - return HTML40Namespace.ElementName.HTML; - } - } - - /** - * HTMLDocumentContentValidator constructor comment. - */ - public HTMLDocumentContentValidator() { - super(); - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLDocumentContentValidator.class) || super.isAdapterForType(type)); - } - - /** - */ - public void validate(IndexedRegion node) { - // isFragment check should be more intelligent. - boolean isFragment = true; - - Document target = (Document) node; - NodeList children = target.getChildNodes(); - if (children == null) - return; - - Division division = new Division(target, children); - if (division.hasExplicitHtmls()) { - isFragment = false; - - List explicits = division.getExplicitHtmls(); - if (explicits.size() > 1) { - for (int i = 1; i < explicits.size(); i++) { - Element html = (Element) explicits.get(i); - // report error (duplicate) - Segment errorSeg = FMUtil.getSegment((IDOMNode) html, FMUtil.SEG_START_TAG); - if (errorSeg != null) - reporter.report(new ErrorInfoImpl(ErrorState.DUPLICATE_ERROR, errorSeg, html)); - } - } - } - validateContent(division.getRestNodes(), isFragment); - } - - /* - * This methods validate nodes other than HTML elements. - */ - private void validateContent(Iterator children, boolean isFragment) { - boolean foundDoctype = false; - while (children.hasNext()) { - IDOMNode child = (IDOMNode) children.next(); - - int error = ErrorState.NONE_ERROR; - int segType = FMUtil.SEG_WHOLE_TAG; - - switch (child.getNodeType()) { - case Node.ELEMENT_NODE : - if (!isFragment) { - Element childElem = (Element) child; - CMElementDeclaration ced = CMUtil.getDeclaration(childElem); - // Undefined element is valid. - if (ced == null) - continue; - // JSP (includes custom tags) and SSI are valid. - if (CMUtil.isForeign(childElem) || CMUtil.isSSI(ced)) - continue; // Defect 186774 - - // report error (invalid content) - error = ErrorState.INVALID_CONTENT_ERROR; - // mark the whole start tag as error. - segType = FMUtil.SEG_START_TAG; - } - break; - case Node.TEXT_NODE : - if (!isFragment) { - // TEXT node is valid when it contains white space - // characters only. - // Otherwise, it is invalid content. - if (((IDOMText) child).isElementContentWhitespace()) - continue; - error = ErrorState.INVALID_CONTENT_ERROR; - segType = FMUtil.SEG_WHOLE_TAG; - } - break; - case Node.DOCUMENT_TYPE_NODE : - // DOCTYPE is also valid when it appears once and only - // once. - if (!foundDoctype) { - foundDoctype = true; - continue; - } - error = ErrorState.DUPLICATE_ERROR; - segType = FMUtil.SEG_WHOLE_TAG; - break; - case Node.COMMENT_NODE : - // always valid. - case Node.PROCESSING_INSTRUCTION_NODE : - continue; - default : - if (!isFragment) { - error = ErrorState.INVALID_CONTENT_ERROR; - segType = FMUtil.SEG_WHOLE_TAG; - } - break; - } - if (error != ErrorState.NONE_ERROR) { - Segment errorSeg = FMUtil.getSegment(child, segType); - if (errorSeg != null) - reporter.report(new ErrorInfoImpl(error, errorSeg, child)); - } - } - } - -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementAncestorValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementAncestorValidator.java deleted file mode 100644 index 0c61edd80a..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementAncestorValidator.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Element; - -public class HTMLElementAncestorValidator extends PrimeValidator { - - /** - * HTMLElementAncestorValidator constructor comment. - */ - public HTMLElementAncestorValidator() { - super(); - } - - /** - * Allowing the INodeAdapter to compare itself against the type - * allows it to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLElementAncestorValidator.class) || super.isAdapterForType(type)); - } - - /** - * Check exclusion which is defined in only HTML DTD (SGML). - */ - public void validate(IndexedRegion node) { - Element target = (Element) node; - if (CMUtil.isForeign(target)) - return; - CMElementDeclaration dec = CMUtil.getDeclaration(target); - if (dec == null) - return; // cannot validate. - if (!CMUtil.isHTML(dec)) - return; // no need to validate - if (!dec.supports(HTMLCMProperties.PROHIBITED_ANCESTORS)) - return; // cannot validate. - CMNamedNodeMap prohibited = (CMNamedNodeMap) dec.getProperty(HTMLCMProperties.PROHIBITED_ANCESTORS); - if (prohibited.getLength() <= 0) - return; // no prohibited ancestors. - - Element parent = SMUtil.getParentElement(target); - while (parent != null) { - CMNode pdec = prohibited.getNamedItem(parent.getNodeName()); - if (pdec != null) { // prohibited element is found in ancestors. - Segment errorSeg = FMUtil.getSegment((IDOMNode) node, FMUtil.SEG_START_TAG); - if (errorSeg != null) - reporter.report(new ErrorInfoImpl(ErrorState.INVALID_CONTENT_ERROR, errorSeg, target)); - break; // If one prohibited ancestor is found, it's enough. - } - parent = SMUtil.getParentElement(parent); - } - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementContentValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementContentValidator.java deleted file mode 100644 index 78b707b037..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLElementContentValidator.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.util.List; -import java.util.Locale; - -import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class HTMLElementContentValidator extends PrimeValidator { - - /** - * HTMLElementContentValidator constructor comment. - */ - public HTMLElementContentValidator() { - super(); - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLElementContentValidator.class) || super.isAdapterForType(type)); - } - - /** - */ - public void validate(IndexedRegion node) { - Element target = (Element) node; - if (CMUtil.isForeign(target)) - return; - - validateContent(target, target.getFirstChild()); - } - - private void validateContent(Element parent, Node child) { - if (child == null) - return; - - CMElementDeclaration ed = CMUtil.getDeclaration(parent); - if(ed == null || ed.getContentType() == CMElementDeclaration.ANY) - return; - - List[] extendedContent = new List[1]; - while (child != null) { - // perform actual validation - validateNode(parent, child, ed, extendedContent); - child = child.getNextSibling(); - } - } - - // private int countExplicitSiblings(Element parent, String tagName) { - // NodeList children = parent.getChildNodes(); - // int count = 0; - // for (int i = 0; i < children.getLength(); i++) { - // Node child = children.item(i); - // if (child.getNodeType() != Node.ELEMENT_NODE) - // continue; - // if (tagName.equalsIgnoreCase(((Element) child).getTagName())) { - // count++; - // } - // } - // return count; - // } - - /* - * The implementation of the following method is practical but accurate. - * The accurate maximum occurrence should be retrieve from the content - * model. However, it is useful enough, since almost implicit elements are - * HTML, HEAD, or BODY. - */ - // private int getMaxOccur(Element parent, String childTag) { - // return 1; - // } - -// private boolean containsName(String name, Object[] possible) { -// if (name != null && possible != null) { -// for (int i = 0; i < possible.length; i++) { -// if(name.equals(possible[i])) -// return true; -// } -// } -// return false; -// } - - private void validateNode(Element target, Node child, CMElementDeclaration edec, List[] extendedContent) { - // NOTE: If the target element is 'UNKNOWN', that is, it has no - // element declaration, the content type of the element should be - // regarded as 'ANY'. -- 9/10/2001 - int contentType = CMElementDeclaration.ANY; - if (edec != null) - contentType = edec.getContentType(); - - int error = ErrorState.NONE_ERROR; - int segType = FMUtil.SEG_WHOLE_TAG; - - switch (child.getNodeType()) { - case Node.ELEMENT_NODE : - Element childElem = (Element) child; - // Defect 200321: - // This validator cares only HTML/XHTML elements. If a child - // is - // an element of foreign markup languages, just ignore it. - if (CMUtil.isForeign(childElem)) - return; - - CMElementDeclaration ced = CMUtil.getDeclaration((Element) child); - // Defect 186774: If a child is not one of HTML elements, - // it should be regarded as a valid child regardless the - // type of the parent content model. -- 10/12/2001 - if (ced == null || CMUtil.isSSI(ced) || (!CMUtil.isHTML(ced))) - return; - - switch (contentType) { - case CMElementDeclaration.ANY : - // Keep going. - return; - case CMElementDeclaration.ELEMENT : - case CMElementDeclaration.MIXED : - if (ced == null) - return; - if (CMUtil.isValidChild(edec, ced)) - return; - // Now, it is the time to check inclusion, unless the - // target - // document is not a XHTML. - if (!CMUtil.isXHTML(edec)) { - // pure HTML - if (CMUtil.isValidInclusion(ced, target)) - return; - } - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=218143 - - * ModelQuery use not pervasive enough - */ - if (extendedContent[0] == null) { - extendedContent[0] = ModelQueryUtil.getModelQuery(target.getOwnerDocument()).getAvailableContent(target, edec, ModelQuery.INCLUDE_CHILD_NODES); - } - - List availableChildElementDeclarations = extendedContent[0]; - /* - * Retrieve and set aside just the element names for faster checking - * later. - */ - int availableChildCount = availableChildElementDeclarations.size(); - String elementName = ced.getElementName().toLowerCase(Locale.US); - for (int i = 0; i < availableChildCount; i++) { - CMNode cmnode = (CMNode) availableChildElementDeclarations.get(i); - if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION && cmnode.getNodeName().toLowerCase(Locale.US).equals(elementName)) { - return; - } - } - - error = ErrorState.INVALID_CONTENT_ERROR; - break; - default : - error = ErrorState.INVALID_CONTENT_ERROR; - break; - } - // Mark the whole START tag as an error segment. - segType = FMUtil.SEG_START_TAG; - break; - case Node.TEXT_NODE : - switch (contentType) { - case CMElementDeclaration.ANY : - case CMElementDeclaration.MIXED : - case CMElementDeclaration.PCDATA : - case CMElementDeclaration.CDATA : - // D184339 - // Keep going. - return; - case CMElementDeclaration.ELEMENT : - case CMElementDeclaration.EMPTY : - if (((IDOMText) child).isElementContentWhitespace()) - return; - error = ErrorState.INVALID_CONTENT_ERROR; - break; - default : - error = ErrorState.INVALID_CONTENT_ERROR; - break; - } - // Mark the whole node as an error segment. - segType = FMUtil.SEG_WHOLE_TAG; - break; - case Node.COMMENT_NODE : - case Node.PROCESSING_INSTRUCTION_NODE : - if (contentType != CMElementDeclaration.EMPTY) - return; - error = ErrorState.INVALID_CONTENT_ERROR; - // Mark the whole node as an error segment. - segType = FMUtil.SEG_WHOLE_TAG; - break; - case Node.CDATA_SECTION_NODE : - if (edec.supports(HTMLCMProperties.IS_XHTML) && Boolean.TRUE.equals(edec.getProperty(HTMLCMProperties.IS_XHTML))) - return; - // Mark the whole CDATA section as an error segment - error = ErrorState.INVALID_CONTENT_ERROR; - segType = FMUtil.SEG_WHOLE_TAG; - break; - default : - error = ErrorState.INVALID_CONTENT_ERROR; - // Mark the whole node as an error segment. - segType = FMUtil.SEG_WHOLE_TAG; - break; - } - if (error != ErrorState.NONE_ERROR) { - Segment errorSeg = FMUtil.getSegment((IDOMNode) child, segType); - if (errorSeg != null) - reporter.report(new ErrorInfoImpl(error, errorSeg, child)); - } - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleDocumentValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleDocumentValidator.java deleted file mode 100644 index 65795b3d69..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleDocumentValidator.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -class HTMLSimpleDocumentValidator extends CompositeValidator { - - /** - * HTMLSimpleDocumentValidator constructor comment. - */ - public HTMLSimpleDocumentValidator() { - super(); - - ValidationComponent[] validators = new ValidationComponent[2]; - - validators[0] = new HTMLDocumentContentValidator(); - validators[1] = new SyntaxValidator(); - - register(validators); - } - - /** - * Allowing the INodeAdapter to compare itself against the type - * allows it to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLSimpleDocumentValidator.class) || super.isAdapterForType(type)); - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleValidator.java deleted file mode 100644 index 7276fd81fb..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLSimpleValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -class HTMLSimpleValidator extends CompositeValidator { - - /** - * HTMLSimpleValidator constructor comment. - */ - public HTMLSimpleValidator() { - super(); - - ValidationComponent[] validators = new ValidationComponent[5]; - - validators[0] = new HTMLAttributeValidator(); - validators[1] = new HTMLElementContentValidator(); - validators[2] = new SyntaxValidator(); - validators[3] = new HTMLElementAncestorValidator(); - validators[4] = new NamespaceValidator(); - - register(validators); - } - - /** - * Allowing the INodeAdapter to compare itself against the type - * allows it to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - return ((type == HTMLSimpleValidator.class) || super.isAdapterForType(type)); - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java deleted file mode 100644 index 1010e0473c..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; -import org.w3c.dom.Node; - -public class HTMLValidationAdapterFactory extends AbstractAdapterFactory { - - private static HTMLValidationAdapterFactory instance = null; - - /** - * HTMLValidationAdapterFactory constructor comment. - */ - public HTMLValidationAdapterFactory() { - super(ValidationAdapter.class, true); - } - - /** - * HTMLValidationAdapterFactory constructor comment. - * @param adapterKey java.lang.Object - * @param registerAdapters boolean - */ - public HTMLValidationAdapterFactory(Object adapterKey, boolean registerAdapters) { - super(adapterKey, registerAdapters); - } - - /** - */ - protected INodeAdapter createAdapter(INodeNotifier target) { - Node node = (Node) target; - switch (node.getNodeType()) { - case Node.DOCUMENT_NODE : - return new DocumentPropagatingValidator(); - case Node.ELEMENT_NODE : - return new ElementPropagatingValidator(); - default : - return new NullValidator(); - } - } - - /** - */ - public synchronized static HTMLValidationAdapterFactory getInstance() { - if (instance != null) - return instance; - instance = new HTMLValidationAdapterFactory(); - return instance; - } - - /** - * Overriding Object's clone() method - * This is used in IModelManager's IStructuredModel copying. - */ - public INodeAdapterFactory copy() { - return getInstance(); - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java deleted file mode 100644 index 06771b7c21..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.util.Hashtable; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.html.core.internal.HTMLCoreMessages; -import org.eclipse.wst.html.core.internal.HTMLCorePlugin; -import org.eclipse.wst.html.core.internal.Logger; -import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; -import org.eclipse.wst.sse.core.internal.validate.ErrorInfo; -import org.eclipse.wst.sse.core.internal.validate.ValidationMessage; -import org.w3c.dom.Node; - -public class MessageFactory implements ErrorState { - - - private IProject fProject; - private IScopeContext[] fLookupOrder; - private IPreferencesService fPreferenceService; - - public MessageFactory() { - init(); - } - - public MessageFactory(IProject project) { - fProject = project; - init(); - } - - protected Preferences getModelPreferences() { - return HTMLCorePlugin.getDefault().getPluginPreferences(); - } - - /** - * Creates a packet for the error table based on the state, message, and the - * severity defined in the preference store. This packet, in addition to - * being added to the error table, is also placed in a map based on the - * supplied preference key - * - * @param key the preference key for the error severity - * @param errorTable the error table to store the packet information in - * @param state the error state - * @param msg the message for the error - */ - private void mapToKey(String key, ErrorTable errorTable, int state, String msg) { - int severity = ValidationMessage.WARNING; - severity = fPreferenceService.getInt(HTMLCorePlugin.getDefault().getBundle().getSymbolicName(), key, ValidationMessage.WARNING, fLookupOrder); - errorTable.put(state, msg, severity); - } - - private void init() { - fPreferenceService = Platform.getPreferencesService(); - fLookupOrder = new IScopeContext[] {new InstanceScope(), new DefaultScope()}; - - if (fProject != null) { - ProjectScope projectScope = new ProjectScope(fProject); - if(projectScope.getNode(HTMLCorePlugin.getDefault().getBundle().getSymbolicName()).getBoolean(HTMLCorePreferenceNames.USE_PROJECT_SETTINGS, false)) - fLookupOrder = new IScopeContext[] {projectScope, new InstanceScope(), new DefaultScope()}; - } - - for (int i = 0; i < NodeType.MAX_TYPE; i++) { - errTables[i] = new ErrorTable(); - } - // NOTE: The severities are just stub. They must be reviewed. - // -- 8/30/2001 - - // attribute error map - ErrorTable attrTable = errTables[NodeType.ATTRIBUTE];// short hand - attrTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_UNDEFINED_NAME, attrTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_ATTR_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_UNDEFINED_VALUE, attrTable, UNDEFINED_VALUE_ERROR, MSG_UNDEFINED_VALUE_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_NAME_MISMATCH, attrTable, MISMATCHED_ERROR, MSG_MISMATCHED_ATTR_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_INVALID_NAME, attrTable, INVALID_NAME_ERROR, MSG_INVALID_ATTR_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_INVALID_VALUE, attrTable, INVALID_ATTR_ERROR, MSG_ATTR_NO_VALUE_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_DUPLICATE, attrTable, DUPLICATE_ERROR, MSG_DUPLICATE_ATTR_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_MISMATCH, attrTable, MISMATCHED_VALUE_ERROR, MSG_MISMATCHED_ATTR_VALUE_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_UNCLOSED, attrTable, UNCLOSED_ATTR_VALUE, MSG_UNCLOSED_ATTR_VALUE_ERROR); - mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, attrTable, RESOURCE_NOT_FOUND, MSG_RESOURCE_NOT_FOUND); - - // element error map - ErrorTable elemTable = errTables[NodeType.ELEMENT];// short hand - elemTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.ELEM_UNKNOWN_NAME, elemTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_NAME, elemTable, INVALID_NAME_ERROR, MSG_INVALID_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_START_INVALID_CASE, elemTable, MISMATCHED_ERROR, MSG_MISMATCHED_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_END_INVALID_CASE, elemTable, MISMATCHED_END_TAG_ERROR, MSG_MISMATCHED_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_MISSING_START, elemTable, MISSING_START_TAG_ERROR, MSG_MISSING_START_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_MISSING_END, elemTable, MISSING_END_TAG_ERROR, MSG_MISSING_END_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_UNNECESSARY_END, elemTable, UNNECESSARY_END_TAG_ERROR, MSG_UNNECESSARY_END_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_DIRECTIVE, elemTable, INVALID_DIRECTIVE_ERROR, MSG_INVALID_DIRECTIVE_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_CONTENT, elemTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_DUPLICATE, elemTable, DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_COEXISTENCE, elemTable, COEXISTENCE_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_UNCLOSED_START_TAG, elemTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_START_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_UNCLOSED_END_TAG, elemTable, UNCLOSED_END_TAG_ERROR, MSG_UNCLOSED_END_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_EMPTY_TAG, elemTable, INVALID_EMPTY_ELEMENT_TAG, MSG_INVALID_EMPTY_ELEMENT_TAG); - - // document type error map - ErrorTable docTable = errTables[NodeType.DOCUMENT_TYPE];// short hand - docTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.DOC_DUPLICATE, docTable, DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.DOC_INVALID_CONTENT, docTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.DOC_DOCTYPE_UNCLOSED, docTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_DOCTYPE_ERROR); - - // text error map - ErrorTable textTable = errTables[NodeType.TEXT]; - textTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.TEXT_INVALID_CONTENT, textTable, INVALID_CONTENT_ERROR, MSG_INVALID_TEXT_ERROR); - mapToKey(HTMLCorePreferenceNames.TEXT_INVALID_CHAR, textTable, INVALID_CHAR_ERROR, MSG_INVALID_CHAR_ERROR); - - // comment error map - ErrorTable commTable = errTables[NodeType.COMMENT]; - commTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.COMMENT_INVALID_CONTENT, commTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.COMMENT_UNCLOSED, commTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_COMMENT_ERROR); - - // cdata section error map - ErrorTable cdatTable = errTables[NodeType.CDATA_SECTION]; - cdatTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.CDATA_INVALID_CONTENT, cdatTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.CDATA_UNCLOSED, cdatTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_CDATA_SECTION_ERROR); - - // processing instruction error map - ErrorTable piTable = errTables[NodeType.PROCESSING_INSTRUCTION]; - piTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.PI_INVALID_CONTENT, piTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - mapToKey(HTMLCorePreferenceNames.PI_UNCLOSED, piTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_PI_ERROR); - - // entity reference error map - ErrorTable erTable = errTables[NodeType.ENTITY_REFERENCE]; - erTable.put(NONE_ERROR, MSG_NO_ERROR, 0); - mapToKey(HTMLCorePreferenceNames.REF_UNDEFINED, erTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR); - mapToKey(HTMLCorePreferenceNames.REF_INVALID_CONTENT, erTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR); - } - - private static class ErrorTable { - private class Packet { - public Packet(String msg, int severity) { - this.msg = msg; - this.severity = severity; - } - - public String getMessage() { - return msg; - } - - public int getSeverity() { - return severity; - } - - private String msg = null; - private int severity = -1; - } - - public ErrorTable() { - } - - public Packet put(int state, String msg, int severity) { - Packet packet = new Packet(msg, severity); - map.put(new Integer(state), packet); - return packet; - } - - public String getMessage(int state) { - return getPacket(state).getMessage(); - } - - public int getSeverity(int state) { - return getPacket(state).getSeverity(); - } - - private Packet getPacket(int state) { - return (Packet) map.get(new Integer(state)); - } - - private Hashtable map = new Hashtable(); - } - - private static interface NodeType { - static final int ATTRIBUTE = 0; - static final int ELEMENT = 1; - static final int DOCUMENT_TYPE = 2; - static final int TEXT = 3; - static final int COMMENT = 4; - static final int CDATA_SECTION = 5; - static final int PROCESSING_INSTRUCTION = 6; - static final int ENTITY_REFERENCE = 7; - - static final int MAX_TYPE = 8; - } - - // error messages - private static final String MSG_NO_ERROR = HTMLCoreMessages.No_error__UI_; - private static final String MSG_UNDEFINED_ATTR_ERROR = HTMLCoreMessages.Undefined_attribute_name___ERROR_; - private static final String MSG_UNDEFINED_VALUE_ERROR = HTMLCoreMessages.Undefined_attribute_value__ERROR_; - private static final String MSG_DUPLICATE_ATTR_ERROR = HTMLCoreMessages.Multiple_values_specified__ERROR_; - private static final String MSG_MISMATCHED_ATTR_ERROR = HTMLCoreMessages.Attribute_name___0___uses__ERROR_; - private static final String MSG_INVALID_ATTR_ERROR = HTMLCoreMessages.Invalid_attribute_name___0_ERROR_; - private static final String MSG_ATTR_NO_VALUE_ERROR = HTMLCoreMessages.Invalid_attribute___0____ERROR_; - private static final String MSG_INVALID_CONTENT_ERROR = HTMLCoreMessages.Invalid_location_of_tag____ERROR_; - private static final String MSG_DUPLICATE_TAG_ERROR = HTMLCoreMessages.Duplicate_tag___0____ERROR_; - private static final String MSG_MISSING_START_TAG_ERROR = HTMLCoreMessages.No_start_tag____0_____ERROR_; - private static final String MSG_MISSING_END_TAG_ERROR = HTMLCoreMessages.No_end_tag_____0_____ERROR_; - private static final String MSG_UNNECESSARY_END_TAG_ERROR = HTMLCoreMessages.End_tag_____0____not_neede_ERROR_; - private static final String MSG_UNDEFINED_TAG_ERROR = HTMLCoreMessages.Unknown_tag___0____ERROR_; - private static final String MSG_MISMATCHED_TAG_ERROR = HTMLCoreMessages.Tag_name___0___uses_wrong__ERROR_; - private static final String MSG_INVALID_TAG_ERROR = HTMLCoreMessages.Invalid_tag_name___0____ERROR_; - private static final String MSG_INVALID_DIRECTIVE_ERROR = HTMLCoreMessages.Invalid_JSP_directive___0__ERROR_; - private static final String MSG_INVALID_TEXT_ERROR = HTMLCoreMessages.Invalid_text_string___0____ERROR_; - private static final String MSG_INVALID_CHAR_ERROR = HTMLCoreMessages.Invalid_character_used_in__ERROR_; - private static final String MSG_UNKNOWN_ERROR = HTMLCoreMessages.Unknown_error__ERROR_; - private static final String MSG_UNCLOSED_START_TAG_ERROR = HTMLCoreMessages.Start_tag____0____not_clos_ERROR_; - private static final String MSG_UNCLOSED_END_TAG_ERROR = HTMLCoreMessages.End_tag_____0____not_close_ERROR_; - private static final String MSG_MISMATCHED_ATTR_VALUE_ERROR = HTMLCoreMessages.Attribute_value___0___uses_ERROR_; - private static final String MSG_UNCLOSED_COMMENT_ERROR = HTMLCoreMessages.Comment_not_closed__ERROR_; - private static final String MSG_UNCLOSED_DOCTYPE_ERROR = HTMLCoreMessages.DOCTYPE_declaration_not_cl_ERROR_; - private static final String MSG_UNCLOSED_PI_ERROR = HTMLCoreMessages.Processing_instruction_not_ERROR_; - private static final String MSG_UNCLOSED_CDATA_SECTION_ERROR = HTMLCoreMessages.CDATA_section_not_closed__ERROR_; - private static final String MSG_INVALID_EMPTY_ELEMENT_TAG = HTMLCoreMessages._ERROR_Tag___0___should_be_an_empty_element_tag_1; - private static final String MSG_UNCLOSED_ATTR_VALUE_ERROR = HTMLCoreMessages._ERROR_Attribute_value___0___not_closed__1; - private static final String MSG_RESOURCE_NOT_FOUND = HTMLCoreMessages._ERROR_Resource_not_found_0; - - private ErrorTable[] errTables = new ErrorTable[NodeType.MAX_TYPE]; - -// static { -// for (int i = 0; i < NodeType.MAX_TYPE; i++) { -// errTables[i] = new ErrorTable(); -// } -// // NOTE: The severities are just stub. They must be reviewed. -// // -- 8/30/2001 -// -// // attribute error map -// ErrorTable attrTable = errTables[NodeType.ATTRIBUTE];// short hand -// attrTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// attrTable.put(UNDEFINED_NAME_ERROR, MSG_UNDEFINED_ATTR_ERROR, ValidationMessage.WARNING); -// attrTable.put(UNDEFINED_VALUE_ERROR, MSG_UNDEFINED_VALUE_ERROR, ValidationMessage.WARNING); -// attrTable.put(MISMATCHED_ERROR, MSG_MISMATCHED_ATTR_ERROR, ValidationMessage.WARNING); -// attrTable.put(INVALID_NAME_ERROR, MSG_INVALID_ATTR_ERROR, ValidationMessage.WARNING); -// attrTable.put(INVALID_ATTR_ERROR, MSG_ATTR_NO_VALUE_ERROR, ValidationMessage.WARNING); -// attrTable.put(DUPLICATE_ERROR, MSG_DUPLICATE_ATTR_ERROR, ValidationMessage.WARNING); -// attrTable.put(MISMATCHED_VALUE_ERROR, MSG_MISMATCHED_ATTR_VALUE_ERROR, ValidationMessage.ERROR); -// //<<D210422 -// attrTable.put(UNCLOSED_ATTR_VALUE, MSG_UNCLOSED_ATTR_VALUE_ERROR, ValidationMessage.WARNING); -// //D210422 -// // element error map -// ErrorTable elemTable = errTables[NodeType.ELEMENT];// short hand -// elemTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// elemTable.put(UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR, ValidationMessage.WARNING); -// elemTable.put(INVALID_NAME_ERROR, MSG_INVALID_TAG_ERROR, ValidationMessage.ERROR); -// elemTable.put(MISMATCHED_ERROR, MSG_MISMATCHED_TAG_ERROR, ValidationMessage.WARNING); -// elemTable.put(MISMATCHED_END_TAG_ERROR, MSG_MISMATCHED_TAG_ERROR, ValidationMessage.ERROR); -// elemTable.put(MISSING_START_TAG_ERROR, MSG_MISSING_START_TAG_ERROR, ValidationMessage.ERROR); -// elemTable.put(MISSING_END_TAG_ERROR, MSG_MISSING_END_TAG_ERROR, ValidationMessage.WARNING); -// elemTable.put(UNNECESSARY_END_TAG_ERROR, MSG_UNNECESSARY_END_TAG_ERROR, ValidationMessage.WARNING); -// elemTable.put(INVALID_DIRECTIVE_ERROR, MSG_INVALID_DIRECTIVE_ERROR, ValidationMessage.ERROR); -// elemTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// elemTable.put(DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR, ValidationMessage.WARNING); -// elemTable.put(COEXISTENCE_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// elemTable.put(UNCLOSED_TAG_ERROR, MSG_UNCLOSED_START_TAG_ERROR, ValidationMessage.ERROR); -// elemTable.put(UNCLOSED_END_TAG_ERROR, MSG_UNCLOSED_END_TAG_ERROR, ValidationMessage.ERROR); -// elemTable.put(INVALID_EMPTY_ELEMENT_TAG, MSG_INVALID_EMPTY_ELEMENT_TAG, ValidationMessage.WARNING); -// -// // document type error map -// ErrorTable docTable = errTables[NodeType.DOCUMENT_TYPE];// short hand -// docTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// docTable.put(DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR, ValidationMessage.ERROR); -// docTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// docTable.put(UNCLOSED_TAG_ERROR, MSG_UNCLOSED_DOCTYPE_ERROR, ValidationMessage.ERROR); -// -// // text error map -// ErrorTable textTable = errTables[NodeType.TEXT]; -// textTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// textTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_TEXT_ERROR, ValidationMessage.WARNING); -// textTable.put(INVALID_CHAR_ERROR, MSG_INVALID_CHAR_ERROR, ValidationMessage.WARNING); -// -// // comment error map -// ErrorTable commTable = errTables[NodeType.COMMENT]; -// commTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// commTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// commTable.put(UNCLOSED_TAG_ERROR, MSG_UNCLOSED_COMMENT_ERROR, ValidationMessage.ERROR); -// -// // cdata section error map -// ErrorTable cdatTable = errTables[NodeType.CDATA_SECTION]; -// cdatTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// cdatTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// cdatTable.put(UNCLOSED_TAG_ERROR, MSG_UNCLOSED_CDATA_SECTION_ERROR, ValidationMessage.ERROR); -// -// // processing instruction error map -// ErrorTable piTable = errTables[NodeType.PROCESSING_INSTRUCTION]; -// piTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// piTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// piTable.put(UNCLOSED_TAG_ERROR, MSG_UNCLOSED_PI_ERROR, ValidationMessage.ERROR); -// -// // entity reference error map -// ErrorTable erTable = errTables[NodeType.ENTITY_REFERENCE]; -// erTable.put(NONE_ERROR, MSG_NO_ERROR, 0); -// erTable.put(UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR, ValidationMessage.WARNING); -// erTable.put(INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR, ValidationMessage.WARNING); -// } - - /** - */ - public ValidationMessage createMessage(ErrorInfo info) { - String errorMsg = getErrorMessage(info); - int errorSeverity = getErrorSeverity(info); - return new ValidationMessage(errorMsg, info.getOffset(), info.getLength(), errorSeverity); - } - - private String getErrorMessage(ErrorInfo info) { - ErrorTable tab = getErrorTable(info.getTargetType()); - if (tab == null) - return MSG_UNKNOWN_ERROR; - - String template = tab.getMessage(info.getState()); - Object[] arguments = {info.getHint()}; - String s = null; - try { - s = NLS.bind(template, arguments); - } - catch (IllegalArgumentException e) { - Logger.logException(e); - s = template + ":" + arguments.toString(); //$NON-NLS-1$ - } - return s; - } - - /** - */ - private int getErrorSeverity(ErrorInfo info) { - ErrorTable tab = getErrorTable(info.getTargetType()); - if (tab == null) - return 0; - return tab.getSeverity(info.getState()); - } - - private ErrorTable getErrorTable(short nodetype) { - ErrorTable tab = null; - switch (nodetype) { - case Node.ATTRIBUTE_NODE : - tab = errTables[NodeType.ATTRIBUTE]; - break; - case Node.ELEMENT_NODE : - tab = errTables[NodeType.ELEMENT]; - break; - case Node.DOCUMENT_TYPE_NODE : - tab = errTables[NodeType.DOCUMENT_TYPE]; - break; - case Node.TEXT_NODE : - tab = errTables[NodeType.TEXT]; - break; - case Node.COMMENT_NODE : - tab = errTables[NodeType.COMMENT]; - break; - case Node.CDATA_SECTION_NODE : - tab = errTables[NodeType.CDATA_SECTION]; - break; - case Node.PROCESSING_INSTRUCTION_NODE : - tab = errTables[NodeType.PROCESSING_INSTRUCTION]; - break; - case Node.ENTITY_REFERENCE_NODE : - tab = errTables[NodeType.ENTITY_REFERENCE]; - break; - default : - return null; - } - return tab; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupport.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupport.java deleted file mode 100644 index 1bce59a6fd..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupport.java +++ /dev/null @@ -1,198 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.validate;
-
-import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.resources.IContainer;
-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.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * This class encapsulates any used Module Core APIs along with fallbacks for
- * use on non-compliant projects and when those services are not available at
- * runtime.
- *
- * Because ModuleCore API calls can result in locks needing to be acquired,
- * none of these methods should be called while other thread locks have
- * already been acquired.
- */
-public final class ModuleCoreSupport {
- static final boolean _dump_NCDFE = false;
- private static final String WEB_INF = "WEB-INF"; //$NON-NLS-1$
- private static final IPath WEB_INF_PATH = new Path(WEB_INF);
-
- /**
- * @param project
- * @return the computed IPath to the "root" of the web contents, either
- * from facet knowledge or hueristics, or null if one can not be
- * determined
- */
- public static IPath computeWebContentRootPath(IPath path) {
- IPath root = null;
- try {
- root = ModuleCoreSupportDelegate.getWebContentRootPath(ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)));
- }
- catch (NoClassDefFoundError e) {
- if (_dump_NCDFE)
- e.printStackTrace();
- }
- if (root == null) {
- /*
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=213245
- *
- * NPE in JSPTaglibDirectiveContentAssistProcessor with
- * non-faceted project
- */
- root = getLocalRoot(path);
- }
- return root;
- }
-
- /**
- * @param project
- * @return the IPath to the "root" of the web contents
- */
- public static IPath getWebContentRootPath(IProject project) {
- if (project == null)
- return null;
-
- IPath path = null;
- try {
- path = ModuleCoreSupportDelegate.getWebContentRootPath(project);
- }
- catch (NoClassDefFoundError e) {
- if (_dump_NCDFE)
- e.printStackTrace();
- }
- return path;
- }
-
- /**
- * @param path
- * - the full path to a resource within the workspace
- * @return - the runtime path of the resource if one exists, null
- * otherwise
- */
- public static IPath getRuntimePath(IPath path) {
- IPath result = null;
- try {
- result = ModuleCoreSupportDelegate.getRuntimePath(path);
- }
- catch (NoClassDefFoundError e) {
- if (_dump_NCDFE)
- e.printStackTrace();
- }
- if (result == null) {
- IPath root = getLocalRoot(path);
- result = path.removeFirstSegments(root.segmentCount()).makeAbsolute();
- }
- return result;
- }
-
- /**
- * @param basePath
- * - the full path to a resource within the workspace
- * @param reference
- * - the reference string to resolve
- * @return - the full path within the workspace that corresponds to the
- * given reference according to the virtual pathing support
- */
- public static IPath resolve(IPath basePath, String reference) {
- IPath resolvedPath = null;
- try {
- resolvedPath = ModuleCoreSupportDelegate.resolve(basePath, reference);
- }
- catch (NoClassDefFoundError e) {
- if (_dump_NCDFE)
- e.printStackTrace();
- }
-
- if (resolvedPath == null) {
- IPath rootPath = getLocalRoot(basePath);
- if (reference.startsWith(Path.ROOT.toString())) {
- resolvedPath = rootPath.append(reference);
- }
- else {
- resolvedPath = basePath.removeLastSegments(1).append(reference);
- }
- }
-
- return resolvedPath;
- }
-
- /**
- * @param basePath
- * @return the applicable Web context root path, if one exists
- */
- private static IPath getLocalRoot(IPath basePath) {
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
-
- // existing workspace resources - this is the 93% case
- IResource file = FileBuffers.getWorkspaceFileAtLocation(basePath);
-
- // Try the base path as a folder first
- if (file == null && basePath.segmentCount() > 1) {
- file = workspaceRoot.getFolder(basePath);
- }
- // If not a folder, then try base path as a file
- if (file != null && !file.exists() && basePath.segmentCount() > 1) {
- file = workspaceRoot.getFile(basePath);
- }
-
- if (file == null && basePath.segmentCount() == 1) {
- file = workspaceRoot.getProject(basePath.segment(0));
- }
-
- if (file == null) {
- /*
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=116529
- *
- * This method produces a less accurate result, but doesn't
- * require that the file exist yet.
- */
- IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(basePath);
- if (files.length > 0)
- file = files[0];
- }
-
- while (file != null) {
- /**
- * Treat any parent folder with a WEB-INF subfolder as a web-app
- * root
- */
- IContainer folder = null;
- if ((file.getType() & IResource.FOLDER) != 0) {
- folder = (IContainer) file;
- }
- else {
- folder = file.getParent();
- }
- // getFolder on a workspace root must use a full path, skip
- if (folder != null && (folder.getType() & IResource.ROOT) == 0) {
- IFolder webinf = folder.getFolder(WEB_INF_PATH);
- if (webinf != null && webinf.exists()) {
- return folder.getFullPath();
- }
- }
- file = file.getParent();
- }
-
- return basePath.uptoSegment(1);
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupportDelegate.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupportDelegate.java deleted file mode 100644 index 818d340423..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ModuleCoreSupportDelegate.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; - -/** - * Wrapper class for all Facet-related calls. If the Facet or ModuleCore - * bundles are not available, this class will not load, or if it does, its - * methods will cause NoClassDefFoundErrors. This allows us to - * compartmentalize the dependencies. - * - */ -final class ModuleCoreSupportDelegate { - private static final String SLASH = "/"; - private static Map fResolvedMap = new HashMap(); - - /** - * @param path - * - the full path to a resource within the workspace - * @return - the runtime path of the resource if one exists, null - * otherwise - */ - static IPath getRuntimePath(IPath path) { - if (path == null) - return null; - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); - - if (!ModuleCoreNature.isFlexibleProject(project)) - return null; - - IVirtualResource[] virtualResources = ComponentCore.createResources(ResourcesPlugin.getWorkspace().getRoot().getFile(path)); - if (virtualResources != null && virtualResources.length > 0) { - return virtualResources[0].getRuntimePath(); - } - return null; - } - - /** - * @param project - * @return the IPath to the "root" of the web contents - */ - static IPath getWebContentRootPath(IProject project) { - if (project == null) - return null; - - if (!ModuleCoreNature.isFlexibleProject(project)) - return null; - - IPath path = null; - IVirtualComponent component = ComponentCore.createComponent(project); - if (component != null && component.exists()) { - path = component.getRootFolder().getWorkspaceRelativePath(); - } - return path; - } - - /** - * @param basePath - * - the full path to a resource within the workspace - * @param reference - * - the reference string to resolve - * @return - the full path within the workspace that corresponds to the - * given reference according to the virtual pathing support - */ - static IPath resolve(IPath basePath, String reference) { - if (reference == null || basePath == null || basePath.segmentCount() == 0) - return null; - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0)); - - if (!ModuleCoreNature.isFlexibleProject(project)) - return null; - - if (basePath.segmentCount() > 1) { - /* - * It can take the better part of a full second to do this, so - * cache the result. - */ - IPath resolved = null; - Map mapForBaseResource = null; - mapForBaseResource = (Map) fResolvedMap.get(basePath); - if (mapForBaseResource != null) { - Reference resolvedReference = (Reference) mapForBaseResource.get(reference); - if (resolvedReference != null) - resolved = (IPath) resolvedReference.get(); - } - else { - mapForBaseResource = new HashMap(); - fResolvedMap.put(basePath, mapForBaseResource); - } - - if (resolved == null) { - IFile baseFile = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath); - IVirtualResource[] virtualResources = ComponentCore.createResources(baseFile); - for (int i = 0; i < virtualResources.length; i++) { - IPath baseRuntimePath = virtualResources[i].getRuntimePath(); - IPath referenceRuntimePath = null; - if (reference.startsWith(SLASH)) { - referenceRuntimePath = new Path(reference); - } - else { - referenceRuntimePath = baseRuntimePath.removeLastSegments(1).append(reference); - } - IVirtualFile virtualFile = ComponentCore.createFile(project, referenceRuntimePath); - if (virtualFile != null && virtualFile.exists()) { - IFile[] underlyingFiles = virtualFile.getUnderlyingFiles(); - for (int j = 0; j < underlyingFiles.length; j++) { - if (underlyingFiles[j].getProject().equals(project) && underlyingFiles[j].exists()) { - mapForBaseResource.put(reference, new SoftReference(underlyingFiles[j].getFullPath())); - resolved = underlyingFiles[j].getFullPath(); - } - - } - } - } - } - return resolved; - } - else { - IVirtualFile virtualFile = ComponentCore.createFile(project, new Path(reference)); - if (virtualFile != null && virtualFile.exists()) { - return virtualFile.getUnderlyingFile().getFullPath(); - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NamespaceValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NamespaceValidator.java deleted file mode 100644 index 0df91b78ed..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NamespaceValidator.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -public class NamespaceValidator extends PrimeValidator implements ErrorState { - - private final static String XMLNS_PREFIX = "xmlns";//$NON-NLS-1$ - private final static String NS_SEPARATOR = ":";//$NON-NLS-1$ - - public NamespaceValidator() { - super(); - } - - public boolean isAdapterForType(Object type) { - return ((type == NamespaceValidator.class) || super.isAdapterForType(type)); - } - - public void validate(IndexedRegion node) { - Element target = (Element) node; - if (isXMLElement(target) && hasUnknownPrefix(target)) { - IDOMElement e = (IDOMElement) target; - if (!isValidPrefix(e.getPrefix(), target) && !e.isCommentTag()) { - // report unknown tag error. - Segment errorSeg = null; - if (e.hasStartTag()) - errorSeg = FMUtil.getSegment(e, FMUtil.SEG_START_TAG); - else if (e.hasEndTag()) - errorSeg = FMUtil.getSegment(e, FMUtil.SEG_END_TAG); - - if (errorSeg != null) - reporter.report(new ErrorInfoImpl(UNDEFINED_NAME_ERROR, errorSeg, e)); - } - } - // (2) check prefix of each attr - NamedNodeMap attrs = target.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - Node n = attrs.item(i); - if (!(n instanceof IDOMAttr)) - continue; - IDOMAttr a = (IDOMAttr) n; - String prefix = a.getPrefix(); - if ((prefix != null) && isUnknownAttr(a, target)) { - // The attr has unknown prefix. So, check it. - if (!isValidPrefix(prefix, target)) { - // report unknown attr error. - ITextRegion r = a.getNameRegion(); - if (r == null) - continue; - int a_offset = a.getNameRegionStartOffset(); - int a_length = a.getNameRegion().getLength(); - reporter.report(new ErrorInfoImpl(UNDEFINED_NAME_ERROR, new Segment(a_offset, a_length), a)); - } - } - } - } - - // private methods - private boolean isXMLElement(Element target) { - return target instanceof IDOMElement; - } - - private boolean hasUnknownPrefix(Element target) { - return isUnknownElement(target) && CMUtil.isForeign(target); - } - - private boolean isUnknownElement(Element target) { - CMElementDeclaration dec = CMUtil.getDeclaration(target); - return dec == null; - } - - private boolean isUnknownAttr(IDOMAttr attr, Element target) { - CMElementDeclaration dec = CMUtil.getDeclaration(target); - if (dec == null) - return true; // unknown. - CMNamedNodeMap adecls = dec.getAttributes(); - CMAttributeDeclaration adec = (CMAttributeDeclaration) adecls.getNamedItem(attr.getName()); - return adec == null; - } - - private boolean isValidPrefix(String prefix, Element e) { - if (prefix.equals(XMLNS_PREFIX)) - return true; // "xmlns:foo" attr is always valid. - - // (1) check the element has the namespace definition or not. - if (isValidPrefixWithinElement(prefix, e)) - return true; - - // (2) check ancestors of the element have the namespace definition or not. - Element parent = SMUtil.getParentElement(e); - while (parent != null) { - if (isValidPrefixWithinElement(prefix, parent)) - return true; - parent = SMUtil.getParentElement(parent); - } - return false; - } - - private boolean isValidPrefixWithinElement(String prefix, Element e) { - String ns = XMLNS_PREFIX + NS_SEPARATOR + prefix; - NamedNodeMap attrs = e.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - Node n = attrs.item(i); - if (n == null) - continue; - if (n.getNodeType() != Node.ATTRIBUTE_NODE) - continue; - if (ns.equals(((Attr) n).getName())) - return true; - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NullValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NullValidator.java deleted file mode 100644 index 165c4a656e..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/NullValidator.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.validate.ValidationReporter; -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -/** - * NullValidator class is intended to be a replacement of null - * for ValidationComponent type. - */ -final class NullValidator extends ValidationComponent { - - public NullValidator() { - super(); - } - - public void validate(IndexedRegion node) { - return; - } - - public void setReporter(ValidationReporter reporter) { - return; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/PrimeValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/PrimeValidator.java deleted file mode 100644 index f9aa0e52db..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/PrimeValidator.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.eclipse.wst.xml.core.internal.validate.ValidationComponent; - -abstract class PrimeValidator extends ValidationComponent { - - /** - * PrimeValidator constructor comment. - */ - public PrimeValidator() { - super(); - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SMUtil.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SMUtil.java deleted file mode 100644 index 8d3b9c066b..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SMUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -final class SMUtil { - - private SMUtil() { - super(); - } - - /* get an ancestor element ignoring implicit ones. */ - public static Element getParentElement(Node child) { - if (child == null) - return null; - - Node p = child.getParentNode(); - while (p != null) { - if (p.getNodeType() == Node.ELEMENT_NODE) { - return (Element) p; - } - p = p.getParentNode(); - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/Segment.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/Segment.java deleted file mode 100644 index 48baf4e227..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/Segment.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - - - -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; - -public class Segment { - - private int offset = 0; - private int length = 0; - - /** - */ - public Segment(int offset, int length) { - super(); - this.offset = offset; - this.length = length; - } - - public Segment(IStructuredDocumentRegion region) { - super(); - this.offset = region.getStartOffset(); - this.length = region.getLength(); - } - - /** - * NOTE: 'start' and 'end' must be the start and end of the contiguous regions. - * Otherwise, this class cannot work correctly. - */ - public Segment(IStructuredDocumentRegion start, IStructuredDocumentRegion end) { - super(); - this.offset = start.getStartOffset(); - int endOffset = (end == null) ? start.getEndOffset() : end.getEndOffset(); - this.length = endOffset - this.offset; - } - - //public Segment(ITextRegion start, ITextRegion end) { - // super(); - // this.offset = start.getStartOffset(); - // int endOffset = (end == null) ? start.getEndOffset() : end.getEndOffset(); - // this.length = endOffset - this.offset; - //} - /** - */ - public int getLength() { - return this.length; - } - - /** - */ - public int getOffset() { - return this.offset; - } -} diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java deleted file mode 100644 index 7739a2d810..0000000000 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.html.core.internal.validate; - -import java.util.Iterator; - -import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeEntry; -import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeRegistry; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.internal.validate.ErrorInfo; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.document.InvalidCharacterException; -import org.eclipse.wst.xml.core.internal.document.SourceValidator; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -class SyntaxValidator extends PrimeValidator implements ErrorState { - - - static private boolean isValidRegion(ITextRegion rgn) { - String type = rgn.getType(); - if (type == null) - return false; // no type is invalid. - if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_TAG_NAME || type == DOMRegionContext.XML_TAG_CLOSE) { - return true; - } - return false; - } - - static private String getTagName(IStructuredDocumentRegion tag) { - ITextRegionList regions = tag.getRegions(); - Iterator iter = regions.iterator(); - while (iter.hasNext()) { - ITextRegion rgn = (ITextRegion) iter.next(); - if (rgn.getType() == DOMRegionContext.XML_TAG_NAME) - return tag.getText(rgn); - } - return "";//$NON-NLS-1$ - } - - static private boolean isEmptyContent(CMElementDeclaration decl) { - return (decl != null) && (decl.getContentType() == CMElementDeclaration.EMPTY); - } - - public SyntaxValidator() { - super(); - } - - public boolean isAdapterForType(Object type) { - return ((type == SyntaxValidator.class) || super.isAdapterForType(type)); - } - - class ElementInfo { - public ElementInfo() { - super(); - } - - public IDOMElement target = null; - public CMElementDeclaration decl = null; - public IStructuredDocumentRegion startTag = null; - public IStructuredDocumentRegion endTag = null; - public boolean hasStartTag() {return startTag != null;} - public boolean hasEndTag() {return endTag != null;} - public boolean isXHTML = false; - } - - public void validate(IndexedRegion indexedNode) { - Node node = (Node) indexedNode; - validateChildren(node); - - if (node.getNodeType() != Node.ELEMENT_NODE) - return; - if (!(node instanceof IDOMElement)) - return; - - ElementInfo info = new ElementInfo(); - info.target = (IDOMElement) node; - - // gather information to validate from target at once. - getInfo(info); - - validateTags(info); - if (info.target.isGlobalTag()) { - validateNames(info); - if (info.decl != null && info.isXHTML) { - validateTagCase(info); - } - } - } - - private void getInfo(ElementInfo info) { - info.decl = CMUtil.getDeclaration(info.target); - info.startTag = info.target.getStartStructuredDocumentRegion(); - info.endTag = info.target.getEndStructuredDocumentRegion(); - - Document doc = info.target.getOwnerDocument(); - if (!(doc instanceof IDOMDocument)) - return; - String typeid = ((IDOMDocument) doc).getDocumentTypeId(); - if (typeid != null) { - HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(typeid); - info.isXHTML = (entry != null && entry.isXMLType()); - } - } - - class TagErrorInfoImpl extends AbstractErrorInfo { - private String hint = null; - - public TagErrorInfoImpl(int state, IStructuredDocumentRegion tag, String hint) { - super(state, new Segment(tag)); - this.hint = hint; - } - - public String getHint() { - return hint; - } - - public short getTargetType() { - return Node.ELEMENT_NODE; - } - } - - private boolean isEndTagCorrupted(ElementInfo info) { - ITextRegionList regions = info.endTag.getRegions(); - if (regions == null || regions.isEmpty()) - return false; - Iterator iter = regions.iterator(); - while (iter.hasNext()) { - ITextRegion rgn = (ITextRegion) iter.next(); - if (!isValidRegion(rgn)) - return true; // found invalid region type. - } - return false; // all regions are valid. - } - - private String getEndTagFullText(ElementInfo info) { - String hint = "";//$NON-NLS-1$ - ITextRegionList regions = info.endTag.getRegions(); - Iterator iter = regions.iterator(); - while (iter.hasNext()) { - ITextRegion rgn = (ITextRegion) iter.next(); - String type = rgn.getType(); - if (type == null) - continue; - if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_TAG_CLOSE) - continue; - hint += info.endTag.getFullText(rgn); - } - return hint; - } - - private void reportCorruptedEndTagError(ElementInfo info) { - String hint = getEndTagFullText(info); - TagErrorInfoImpl error = new TagErrorInfoImpl(UNDEFINED_NAME_ERROR, info.endTag, hint); - this.reporter.report(error); - } - - private void validateTags(ElementInfo info) { - if (info.hasStartTag()) { - if (!info.target.isStartTagClosed()) { - // Mark the whole START tag as an error segment. - Segment errorSeg = new Segment(info.startTag); - report(UNCLOSED_TAG_ERROR, errorSeg, info.target); - } - } - else { - if (info.hasEndTag()) { - if (info.decl != null) { - if (/*CMUtil.isHTML(info.decl) &&*/ !info.target.hasChildNodes()) { - if (info.target.isContainer()) { - // Set the error mark to the start of the element. - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_END_TAG); - report(MISSING_START_TAG_ERROR, errorSeg, info.target); - } - else { - // Mark the whole END tag as an error segment. - Segment errorSeg = new Segment(info.endTag); - report(UNNECESSARY_END_TAG_ERROR, errorSeg, info.target); - } - } - else if (info.isXHTML) { - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_END_TAG_NAME); - report(MISSING_START_TAG_ERROR, errorSeg, info.target); - } - } - } - } - - if (info.hasEndTag()) { - if (!info.target.isClosed()) { - // Set the whole END tag as error segment. - Segment errorSeg = new Segment(info.endTag); - report(UNCLOSED_END_TAG_ERROR, errorSeg, info.target); - } - } - else { - if (info.isXHTML) { // XHTML - if (!info.target.isEmptyTag() && DOMRegionContext.XML_TAG_OPEN.equals(info.target.getStartStructuredDocumentRegion().getFirstRegion().getType())) { - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248963 : - * report empty tags not written as such, but only when - * they follow actual XML/HTML syntax - */ - if (isEmptyContent(info.decl)) { - // EMPTY element should be written in <.../> form - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_START_TAG); - report(INVALID_EMPTY_ELEMENT_TAG, errorSeg, info.target); - } - else { - // end tag is required. - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_START_TAG); - report(MISSING_END_TAG_ERROR, errorSeg, info.target); - } - } - } - else { // HTML - if (info.hasStartTag()) { - if (info.decl != null && CMUtil.isHTML(info.decl) && !info.target.isEmptyTag() && !CMUtil.isEndTagOmissible(info.decl) && DOMRegionContext.XML_TAG_OPEN.equals(info.startTag.getFirstRegion().getType())) { - // Set the error mark to the end of the element. - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_START_TAG); - report(MISSING_END_TAG_ERROR, errorSeg, info.target); - } - } - } - } - } - - /* perform validation about tag name definition. */ - private void validateNames(ElementInfo info) { - boolean corrupted = info.hasEndTag() && isEndTagCorrupted(info); - if (info.decl == null) { - // If no declaration is retrieved, the target is really - // unknown element. - if (!info.hasStartTag() && corrupted) { - reportCorruptedEndTagError(info); - } - else { - Segment errorSeg = FMUtil.getSegment(info.target, FMUtil.SEG_START_TAG_NAME); - report(UNDEFINED_NAME_ERROR, errorSeg, info.target); - } - } - else { - // Even if a declaration could be retrieved, if the end - // tag is corrupted, it should be reported as undefined - // name. (D202493) - if (corrupted) { - reportCorruptedEndTagError(info); - } - } - } - - /* perform validation tag case only for XHTML document */ - private void validateTagCase(ElementInfo info) { - String declared = info.decl.getElementName(); - String startTagName = "";//$NON-NLS-1$ - String endTagName = "";//$NON-NLS-1$ - if (declared == null) - return; - - // start tag - if (info.hasStartTag()) { - startTagName = getTagName(info.startTag); - if (!declared.equals(startTagName)) { - TagErrorInfoImpl error = new TagErrorInfoImpl(MISMATCHED_ERROR, info.startTag, startTagName); - this.reporter.report(error); - } - } - // end tag - if (info.hasEndTag()) { - endTagName = getTagName(info.endTag); - if (!info.hasStartTag() || (!endTagName.equals(startTagName))) { - if (!declared.equals(endTagName)) { - TagErrorInfoImpl error = new TagErrorInfoImpl(MISMATCHED_ERROR, info.endTag, endTagName); - this.reporter.report(error); - } - } - } - } - - private void validateChildren(Node target) { - if ((target.getNodeType() == Node.ELEMENT_NODE) && CMUtil.isForeign((Element) target)) - return; - - for (Node child = target.getFirstChild(); child != null; child = child.getNextSibling()) { - switch (child.getNodeType()) { - case Node.TEXT_NODE : - { - IDOMNode text = (IDOMNode) child; - int charOffset = validateTextSource(text); - if (charOffset >= 0) { - charOffset += text.getStartOffset(); - Segment errorSeg = new Segment(charOffset, 1); - if (errorSeg != null) - report(INVALID_CHAR_ERROR, errorSeg, text); - } - break; - } - case Node.COMMENT_NODE : - case Node.DOCUMENT_TYPE_NODE : - case Node.PROCESSING_INSTRUCTION_NODE : - case Node.CDATA_SECTION_NODE : - { - IDOMNode tag = (IDOMNode) child; - if (!tag.isClosed()) { - Segment errorSeg = FMUtil.getSegment(tag, FMUtil.SEG_WHOLE_TAG); - if (errorSeg != null) - report(UNCLOSED_TAG_ERROR, errorSeg, tag); - } - break; - } - default : - break; - } - } - } - - private int validateTextSource(IDOMNode text) { - try { - SourceValidator validator = new SourceValidator(text); - validator.validateSource(text.getSource()); - } - catch (InvalidCharacterException ex) { - return ex.getOffset(); - } - return -1; - } - - private void report(int state, Segment errorSeg, Node node) { - ErrorInfo info = new ErrorInfoImpl(state, errorSeg, node); - reporter.report(info); - } -} |