use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class NamespaceValidator method validate.
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);
// some containers will contain languages that also use ':'
if (!(n instanceof IDOMAttr) || ((IDOMAttr) n).getNameRegion() instanceof ITextRegionContainer)
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));
}
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class SyntaxValidator method validate.
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;
if (info.target.getModel().isModelStateChanging()) {
return;
}
// 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);
}
}
// validate the syntax of the attributes
validateAttributes(info);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLFormatter method canInsertBreakAfter.
/**
*/
protected boolean canInsertBreakAfter(Node node) {
if (node == null)
return false;
Node parent = node.getParentNode();
if (parent == null)
return false;
Node next = node.getNextSibling();
// special exception if this node is a non-HTML tag (like JSP
// elements)
// BUG188093 - only preserve whitespace for jsp (not custom) tags
String prefix = node.getPrefix();
if (prefix != null && JSP.equals(prefix)) {
boolean canInsertBreakAfter = false;
// if a whitespace does not exist after it, do not add one
if (next != null && next.getNodeType() == Node.TEXT_NODE) {
String theText = ((Text) next).getData();
if (theText != null && theText.length() > 0) {
char theChar = theText.charAt(0);
canInsertBreakAfter = Character.isWhitespace(theChar);
}
}
// continue processing)
if (!canInsertBreakAfter)
return false;
}
// BUG188093 - only preserve whitespace for jsp (not custom) tags
if (next != null) {
prefix = next.getPrefix();
if (prefix != null && JSP.equals(prefix)) {
boolean canInsertBreakAfterPrevious = false;
// if a whitespace does not exist before it, do not add one
if (node.getNodeType() == Node.TEXT_NODE) {
String theText = ((Text) node).getData();
if (theText != null && theText.length() > 0) {
char theChar = theText.charAt(theText.length() - 1);
canInsertBreakAfterPrevious = Character.isWhitespace(theChar);
}
}
// continue processing)
if (!canInsertBreakAfterPrevious)
return false;
}
}
if (parent.getNodeType() == Node.DOCUMENT_NODE) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
// do not insert break after unclosed tag
if (!((IDOMElement) node).isClosed())
return false;
}
return true;
} else if (parent.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) parent;
// do not insert break before missing end tag
if (next == null && element.getEndStructuredDocumentRegion() == null)
return false;
// elements
if (element.getPrefix() != null)
return true;
CMElementDeclaration decl = getElementDeclaration(element);
if (decl != null) {
if (decl.getContentType() == CMElementDeclaration.ELEMENT)
return true;
// causes all closing tags to wrap to a new line
boolean allowsText = decl.getContentType() == CMElementDeclaration.MIXED || decl.getContentType() == CMElementDeclaration.PCDATA;
if (allowsNewlineAfter(allowsText, node, element, decl))
return true;
String tagName = element.getTagName();
// special for direct children under BODY
if (tagName != null && tagName.equalsIgnoreCase(BODY_NAME))
return true;
}
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) node;
CMElementDeclaration decl = getElementDeclaration(element);
if (canInsertBreakAfter(decl)) {
// spcial for BR
return canFormatChild(parent);
}
}
if (next != null && next.getNodeType() == Node.ELEMENT_NODE) {
CMElementDeclaration decl = getElementDeclaration((Element) next);
if (canInsertBreakBefore(decl))
return true;
}
return false;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLFormatter method getBreakSpaces.
/**
*/
protected String getBreakSpaces(Node node) {
if (node == null)
return null;
StringBuffer buffer = new StringBuffer();
String delim = ((IDOMNode) node).getModel().getStructuredDocument().getLineDelimiter();
if (delim != null && delim.length() > 0)
buffer.append(delim);
String indent = getIndent();
if (indent != null && indent.length() > 0) {
for (Node parent = node.getParentNode(); parent != null; parent = parent.getParentNode()) {
if (parent.getNodeType() != Node.ELEMENT_NODE)
break;
// ignore omitted tag
if (((IDOMNode) parent).getStartStructuredDocumentRegion() == null)
continue;
IDOMElement element = (IDOMElement) parent;
if (element.getPrefix() != null) {
String localName = element.getLocalName();
// special for html:html
if (localName != null && !localName.equals(HTML_NAME)) {
buffer.append(indent);
}
continue;
} else {
String localName = element.getLocalName();
if (HTML_NAME.equalsIgnoreCase(localName) || HEAD_NAME.equalsIgnoreCase(localName))
break;
}
CMElementDeclaration decl = getElementDeclaration(element);
if (decl != null && decl.supports(HTMLCMProperties.SHOULD_INDENT_CHILD_SOURCE)) {
boolean shouldIndent = isIdentable(node, parent);
if (shouldIndent)
buffer.append(indent);
}
}
}
return buffer.toString();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class JSPActionValidator method processDirective.
private void processDirective(IReporter reporter, IFile file, IStructuredModel model, IStructuredDocumentRegion documentRegion) {
IndexedRegion ir = model.getIndexedRegion(documentRegion.getStartOffset());
if (ir instanceof IDOMElement) {
IDOMElement element = (IDOMElement) ir;
ModelQuery query = ModelQueryUtil.getModelQuery(model);
if (query != null) {
CMElementDeclaration cmElement = query.getCMElementDeclaration(element);
if (cmElement != null) {
CMNamedNodeMap cmAttributes = null;
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl();
List nodes = query.getAvailableContent(element, cmElement, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
cmAttributes = allAttributes;
boolean foundjspattribute = checkUnknownAttributes(element, cmElement, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
// missing required attributes
if (!foundjspattribute && fSeverityMissingRequiredAttribute != ValidationMessage.IGNORE)
checkRequiredAttributes(element, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
if (fSeverityNonEmptyInlineTag != ValidationMessage.IGNORE)
checkNonEmptyInlineTag(element, cmElement, reporter, file, model.getStructuredDocument());
}
}
}
}
Aggregations