Search in sources :

Example 81 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class StyleAdapterFactory method isTagAvailable.

private static boolean isTagAvailable(Document document, String elementName) {
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery != null) {
        CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
        CMNamedNodeMap map = cmdoc.getElements();
        if ((CMElementDeclaration) map.getNamedItem(elementName) != null) {
            return true;
        }
    }
    return false;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 82 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class HTMLContentAssistProcessor method getXHTML.

/**
 * Determine if this Document is an XHTML Document. Oprates solely off of
 * the Document Type declaration
 */
protected boolean getXHTML(Node node) {
    if (node == null)
        return false;
    Document doc = null;
    if (node.getNodeType() != Node.DOCUMENT_NODE)
        doc = node.getOwnerDocument();
    else
        doc = ((Document) node);
    if (doc instanceof IDOMDocument)
        return ((IDOMDocument) doc).isXMLType();
    if (doc instanceof INodeNotifier) {
        ModelQueryAdapter adapter = (ModelQueryAdapter) ((INodeNotifier) doc).getAdapterFor(ModelQueryAdapter.class);
        CMDocument cmdoc = null;
        if (adapter != null && adapter.getModelQuery() != null)
            cmdoc = adapter.getModelQuery().getCorrespondingCMDocument(doc);
        if (cmdoc != null) {
            // model
            if (cmdoc instanceof HTMLCMDocument)
                return false;
            if (cmdoc.supports(HTMLCMProperties.IS_XHTML))
                return Boolean.TRUE.equals(cmdoc.getProperty(HTMLCMProperties.IS_XHTML));
        }
    }
    // this should never be reached
    DocumentType docType = doc.getDoctype();
    // $NON-NLS-1$
    return docType != null && docType.getPublicId() != null && docType.getPublicId().indexOf("-//W3C//DTD XHTML ") == 0;
}
Also used : HTMLCMDocument(org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) HTMLCMDocument(org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocument) DocumentType(org.w3c.dom.DocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) HTMLCMDocument(org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 83 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class HTMLContentAssistProcessor method getHTMLTagProposal.

/**
 * @return ICompletionProposal
 */
private ICompletionProposal getHTMLTagProposal(ITextViewer viewer, int documentPosition) {
    IModelManager mm = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    ICompletionProposal result = null;
    try {
        if (mm != null) {
            model = mm.getExistingModelForRead(viewer.getDocument());
            if (model != null) {
                IDOMDocument doc = ((IDOMModel) model).getDocument();
                ModelQuery mq = ModelQueryUtil.getModelQuery(doc);
                if (mq != null) {
                    // XHTML requires lowercase tagname for lookup
                    CMDocument correspondingCMDocument = mq.getCorrespondingCMDocument(doc);
                    if (correspondingCMDocument != null) {
                        CMElementDeclaration htmlDecl = (CMElementDeclaration) correspondingCMDocument.getElements().getNamedItem(HTML40Namespace.ElementName.HTML.toLowerCase());
                        if (htmlDecl != null) {
                            StringBuffer proposedTextBuffer = new StringBuffer();
                            getContentGenerator().generateTag(doc, htmlDecl, proposedTextBuffer);
                            String proposedText = proposedTextBuffer.toString();
                            String requiredName = getContentGenerator().getRequiredName(doc, htmlDecl);
                            CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, documentPosition, /* start pos */
                            0, /* replace length */
                            requiredName.length() + 2, /*
															 * cursor position
															 * after
															 * (relavtive to
															 * start)
															 */
                            HTMLEditorPluginImageHelper.getInstance().getImage(HTMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), requiredName, null, null, XMLRelevanceConstants.R_TAG_NAME);
                            result = proposal;
                        }
                    }
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
    return result;
}
Also used : HTMLCMDocument(org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5