Search in sources :

Example 11 with IDOMElement

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;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) Set(java.util.Set) HashSet(java.util.HashSet) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ArrayList(java.util.ArrayList) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) HashSet(java.util.HashSet)

Example 12 with IDOMElement

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);
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Node(org.w3c.dom.Node) IStyleSheetListAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 13 with IDOMElement

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);
// }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 14 with IDOMElement

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);
}
Also used : IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 15 with IDOMElement

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);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Node(org.w3c.dom.Node) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Aggregations

IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)59 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)20 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)19 Node (org.w3c.dom.Node)18 NodeList (org.w3c.dom.NodeList)13 Element (org.w3c.dom.Element)11 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)9 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)9 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)8 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)8 NamedNodeMap (org.w3c.dom.NamedNodeMap)8 ArrayList (java.util.ArrayList)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)6 List (java.util.List)5 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)5 Text (org.w3c.dom.Text)5 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)4