Search in sources :

Example 1 with DocumentTypeAdapter

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.

the class XMLPropertySource method getDocTypeFromDOMNode.

/**
 * by "internal spec" the DOCTYPE adapter is only available from Document
 * Node
 *
 * @return {@link DocumentTypeAdapter}
 */
private DocumentTypeAdapter getDocTypeFromDOMNode(Node node) {
    DocumentTypeAdapter adapter = null;
    Document ownerDocument = node.getOwnerDocument();
    if (ownerDocument == null) {
        // ... but, maybe a separate issue).
        if (node instanceof Document) {
            ownerDocument = (Document) node;
        }
    }
    if (ownerDocument != null) {
        adapter = (DocumentTypeAdapter) ((INodeNotifier) ownerDocument).getAdapterFor(DocumentTypeAdapter.class);
    }
    return adapter;
}
Also used : Document(org.w3c.dom.Document) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 2 with DocumentTypeAdapter

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForHTMLTag method getCandidates.

/**
 * getCandidates method comment.
 */
protected Iterator getCandidates() {
    List candidates = new ArrayList();
    if (checkLeadingColon()) {
        return candidates.iterator();
    }
    boolean bLowerCase = CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_SELECTOR) == CSSCorePreferenceNames.LOWER;
    // XHTML requires lower case
    if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
        Node domNode = fContext.getModel().getOwnerDOMNode();
        if (domNode != null && !(domNode instanceof Document)) {
            domNode = domNode.getOwnerDocument();
            if (domNode instanceof IDOMDocument) {
                DocumentTypeAdapter adapter = (DocumentTypeAdapter) ((IDOMDocument) domNode).getAdapterFor(DocumentTypeAdapter.class);
                if (adapter != null)
                    bLowerCase = (adapter.getTagNameCase() == DocumentTypeAdapter.LOWER_CASE);
            }
        }
    }
    int length = fHTMLTags.length;
    for (int i = 0; i < length; i++) {
        String tagText = fHTMLTags[i];
        if (bLowerCase) {
            tagText = tagText.toLowerCase();
        }
        if (!isMatch(tagText)) {
            continue;
        }
        int cursorPos = 0;
        StringBuffer buf = new StringBuffer();
        buf.append(tagText);
        cursorPos += tagText.length();
        boolean inRule = (fContext.getTargetNode() instanceof ICSSStyleRule);
        if (!inRule || fContext.getTextToReplace().length() == 0) {
            // $NON-NLS-1$
            buf.append(" ");
            cursorPos += 1;
        }
        if (!inRule) {
            StringAndOffset sao = generateBraces();
            buf.append(sao.fString);
            cursorPos += sao.fOffset;
        }
        CSSCACandidate item = new CSSCACandidate();
        item.setReplacementString(buf.toString());
        item.setCursorPosition(cursorPos);
        item.setDisplayString(tagText);
        item.setImageType(CSSImageType.SELECTOR_TAG);
        candidates.add(item);
    }
    return candidates.iterator();
}
Also used : Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) ArrayList(java.util.ArrayList) List(java.util.List) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter)

Example 3 with DocumentTypeAdapter

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.

the class HTMLDocumentTypeAdapterFactory method adapt.

/**
 * Method that returns the adapter associated with the given object. It
 * may be a singleton or not ... depending on the needs of the
 * INodeAdapter ... but in general it is recommended for an adapter to be
 * stateless, so the efficiencies of a singleton can be gained.
 *
 * The implementation of this method should call addAdapter on the adapted
 * object with the correct instance of the adapter.
 */
public INodeAdapter adapt(INodeNotifier notifier) {
    INodeAdapter result = null;
    // only adapt IDOMDocument
    if (notifier instanceof IDOMDocument) {
        // if already has an adapter, no need to recreate/initialize.
        // Note: this means if "doctype" for DOM changes,
        // theDocumentTypeAdatper for that DOM
        // should be removed (and released) and it will be re-created next
        // time required.
        DocumentTypeAdapter oldAdapter = (DocumentTypeAdapter) notifier.getExistingAdapter(DocumentTypeAdapter.class);
        if (oldAdapter != null) {
            result = oldAdapter;
        } else {
            // if there already was an adapter
            // if(fAdapter != null)
            // fAdapter.release();
            // note, the factory is included in this case to have a central place
            // to come back to for case preferences.
            result = new HTMLDocumentTypeAdapter((IDOMDocument) notifier, this);
            notifier.addAdapter(result);
        }
    }
    return result;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter)

Example 4 with DocumentTypeAdapter

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter in project webtools.sourceediting by eclipse.

the class URLModelProvider method isHTMLFamily.

/**
 * Utility to check the model is HTML family or not
 */
private static boolean isHTMLFamily(IStructuredModel model) {
    if (model instanceof IDOMModel) {
        IDOMDocument document = ((IDOMModel) model).getDocument();
        DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class);
        if (adapter != null)
            return adapter.hasFeature(HTMLDocumentTypeConstants.HTML);
    }
    return false;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter)

Aggregations

DocumentTypeAdapter (org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter)4 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)3 Document (org.w3c.dom.Document)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)1 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 Node (org.w3c.dom.Node)1