Search in sources :

Example 1 with IStyleSheetAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter in project webtools.sourceediting by eclipse.

the class CSSStyleSheetImpl method getOwnerNodes.

/**
 * @return org.w3c.dom.NodeList
 * @param doc
 *            org.w3c.dom.Document
 */
public NodeList getOwnerNodes(Document doc) {
    List list = (getModel().getStyleListeners() != null) ? new Vector(getModel().getStyleListeners()) : null;
    if (list == null)
        return null;
    InternalNodeList nodes = new InternalNodeList();
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Object obj = it.next();
        if (obj instanceof IStyleSheetAdapter) {
            Element ele = ((IStyleSheetAdapter) obj).getElement();
            if (ele.getOwnerDocument() == doc)
                nodes.nodes.add(ele);
        }
    }
    if (nodes.getLength() > 0)
        return nodes;
    else
        return null;
}
Also used : Element(org.w3c.dom.Element) Iterator(java.util.Iterator) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList) CSSRuleList(org.w3c.dom.css.CSSRuleList) MediaList(org.w3c.dom.stylesheets.MediaList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Vector(java.util.Vector) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)

Example 2 with IStyleSheetAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter in project webtools.sourceediting by eclipse.

the class HTMLDocumentAdapter method releaseStyleSheets.

/**
 */
public void releaseStyleSheets() {
    releaseOldStyleSheets();
    if (this.styleAdapters == null)
        return;
    Iterator it = this.styleAdapters.iterator();
    while (it.hasNext()) {
        IStyleSheetAdapter adapter = (IStyleSheetAdapter) it.next();
        if (adapter != null)
            adapter.released();
    }
    this.styleAdapters = null;
}
Also used : Iterator(java.util.Iterator) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)

Example 3 with IStyleSheetAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter 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 4 with IStyleSheetAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter in project webtools.sourceediting by eclipse.

the class HTMLDocumentAdapter method item.

/**
 */
public StyleSheet item(int index) {
    if (this.styleAdapters == null)
        return null;
    List validAdapters = getValidAdapters();
    if (index < 0 || index >= validAdapters.size())
        return null;
    StyleSheet sheet = ((IStyleSheetAdapter) validAdapters.get(index)).getSheet();
    if (sheet == null) {
        // for LINK element whose link is broken
        ICSSModel model = ((AbstractStyleSheetAdapter) validAdapters.get(index)).createModel();
        sheet = ((model != null) ? (StyleSheet) model.getDocument() : null);
    }
    return sheet;
}
Also used : StyleSheet(org.w3c.dom.stylesheets.StyleSheet) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList) ArrayList(java.util.ArrayList) List(java.util.List) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)

Example 5 with IStyleSheetAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter in project webtools.sourceediting by eclipse.

the class HTMLDocumentAdapter method releaseOldStyleSheets.

/**
 */
private void releaseOldStyleSheets() {
    if (this.oldStyleAdapters == null)
        return;
    Iterator it = this.oldStyleAdapters.iterator();
    while (it.hasNext()) {
        IStyleSheetAdapter adapter = (IStyleSheetAdapter) it.next();
        if (adapter == null)
            continue;
        // do not release
        if (this.styleAdapters != null && this.styleAdapters.contains(adapter))
            continue;
        adapter.released();
    }
    this.oldStyleAdapters = null;
}
Also used : Iterator(java.util.Iterator) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)

Aggregations

IStyleSheetAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)9 Iterator (java.util.Iterator)5 List (java.util.List)3 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)3 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)3 StyleSheetList (org.w3c.dom.stylesheets.StyleSheetList)3 Vector (java.util.Vector)2 NodeList (org.w3c.dom.NodeList)2 CSSRuleList (org.w3c.dom.css.CSSRuleList)2 MediaList (org.w3c.dom.stylesheets.MediaList)2 ArrayList (java.util.ArrayList)1 IStyleSheetListAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter)1 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 StyleSheet (org.w3c.dom.stylesheets.StyleSheet)1