use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class TaglibModelQueryExtension method getAvailableElementContent.
/**
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMElement) {
// get the trackers
IDOMElement elem = (IDOMElement) parentElement;
IStructuredDocument structDoc = elem.getModel().getStructuredDocument();
TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(structDoc);
if (manager != null) {
List trackers = new ArrayList(manager.getTaglibTrackers());
Set prefixes = new HashSet();
// for each tracker add each of its elements to the node list
for (int trackerIndex = 0; trackerIndex < trackers.size(); ++trackerIndex) {
TaglibTracker tracker = ((TaglibTracker) trackers.get(trackerIndex));
CMNamedNodeMap elements = tracker.getElements();
for (int elementIndex = 0; elementIndex < elements.getLength(); ++elementIndex) {
nodeList.add(elements.item(elementIndex));
}
prefixes.add(tracker.getPrefix());
}
String prefix = parentElement.getPrefix();
if (prefixes.contains(prefix)) {
Node parent = parentElement;
while ((parent = parent.getParentNode()) != null && parent.getNodeType() == Node.ELEMENT_NODE) {
prefix = parent.getPrefix();
if (prefix == null || !prefixes.contains(prefix)) {
ModelQuery query = ModelQueryUtil.getModelQuery(parentElement.getOwnerDocument());
if (query != null) {
CMElementDeclaration decl = query.getCMElementDeclaration((Element) parent);
if (decl != null && !fExtensions.contains(this)) {
fExtensions.push(this);
nodeList.addAll(query.getAvailableContent((Element) parent, decl, includeOptions));
fExtensions.pop();
}
}
break;
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLDocumentAdapter method addStyleSheet.
/**
*/
private void addStyleSheet(Element node) {
IDOMElement element = (IDOMElement) node;
String tagName = element.getTagName();
if (tagName == null)
return;
boolean isContainer = false;
if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.NOSCRIPT) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.BASE) || tagName.equalsIgnoreCase(JSP11Namespace.ElementName.ROOT) || (!element.isGlobalTag() && element.isContainer())) {
isContainer = true;
} else if (element.isCommentTag()) {
Node parent = element.getParentNode();
if (parent == element.getOwnerDocument()) {
// This condition is too severe, actually do not work for JSF template.
// But above (! globalTag() && isContainer()) cover JSF template + tpl template
isContainer = true;
} else if (parent.getNodeType() == Node.ELEMENT_NODE) {
tagName = ((Element) parent).getTagName();
if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD)) {
isContainer = true;
}
}
} else {
String localName = element.getLocalName();
if (localName != null && localName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML)) {
// taglib html tag
isContainer = true;
} else {
INodeNotifier notifier = element;
INodeAdapter adapter = notifier.getAdapterFor(IStyleSheetAdapter.class);
if (adapter != null && adapter instanceof IStyleSheetAdapter) {
this.styleAdapters.addElement(adapter);
}
}
}
if (isContainer) {
INodeNotifier notifier = element;
if (notifier.getExistingAdapter(IStyleSheetListAdapter.class) == null) {
notifier.addAdapter(this);
}
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE)
continue;
addStyleSheet((Element) child);
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLElementFormatter method formatEndTag.
/**
*/
private void formatEndTag(IDOMElement element, HTMLFormatContraints contraints) {
Node lastChild = element.getLastChild();
if (lastChild != null && lastChild instanceof IDOMElement && lastChild.getNodeName().equals("jsp:scriptlet")) {
// $NON-NLS-1$
insertBreakAfter((IDOMElement) lastChild, contraints);
return;
}
IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion == null)
return;
if (element.isJSPTag() || element.isCommentTag()) {
String endTag = endStructuredDocumentRegion.getText();
if (endTag != null && endTag.length() > 0) {
setWidth(contraints, endTag);
}
return;
}
ITextRegion prevRegion = null;
ITextRegionList regions = endStructuredDocumentRegion.getRegions();
Iterator e = regions.iterator();
while (e.hasNext()) {
ITextRegion region = (ITextRegion) e.next();
if (region == null)
continue;
String regionType = region.getType();
if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTag(regionType)) {
if (prevRegion != null && prevRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
} else if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
}
prevRegion = region;
}
if (prevRegion != null && (prevRegion.getType() == DOMRegionContext.XML_TAG_NAME || isNestedRootTag(prevRegion.getType()))) {
removeTailingSpaces(endStructuredDocumentRegion, prevRegion);
}
// BUG123890 (end tag length was already prefactored into
// formatStartTag so no need to do it here)
// String newEndTag = endStructuredDocumentRegion.getText();
// if (newEndTag != null && newEndTag.length() > 0) {
// setWidth(contraints, newEndTag);
// }
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLElementFormatter method formatNode.
/**
*/
protected void formatNode(IDOMNode node, HTMLFormatContraints contraints) {
if (node == null)
return;
IDOMElement element = (IDOMElement) node;
formatStartTag(element, contraints);
formatChildNodes(element, contraints);
formatEndTag(element, contraints);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.
the class HTMLTextFormatter method canFormatText.
/**
*/
private boolean canFormatText(IDOMText text) {
if (text == null)
return false;
IStructuredDocumentRegion flatNode = text.getFirstStructuredDocumentRegion();
if (flatNode != null) {
String type = flatNode.getType();
if (isUnparsedRegion(type))
return false;
}
Node parent = text.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) parent;
if (!element.isGlobalTag() && !text.isElementContentWhitespace())
return false;
}
return canFormatChild(parent);
}
Aggregations