Search in sources :

Example 26 with CMDocument

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

the class JSPContentAssistProcessor method getDefaultJSPCMDocument.

/**
 * For JSP files and segments, this is just the JSP
 *         document, but when editing tag files and their fragments, it
 *         should be the tag document.
 *
 * It may also vary based on the model being edited in the future.
 *
 * @return the default non-embedded CMDocument for the document being
 *         edited.
 */
CMDocument getDefaultJSPCMDocument(IDOMNode node) {
    // handle tag files here
    String contentType = node.getModel().getContentTypeIdentifier();
    if (ContentTypeIdForJSP.ContentTypeID_JSPTAG.equals(contentType))
        return JSPCMDocumentFactory.getCMDocument(CMDocType.TAG20_DOC_TYPE);
    CMDocument jcmdoc = null;
    String modelPath = node.getModel().getBaseLocation();
    if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
        float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
        jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
    }
    if (jcmdoc == null) {
        jcmdoc = JSPCMDocumentFactory.getCMDocument();
    }
    return jcmdoc;
}
Also used : JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path)

Example 27 with CMDocument

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

the class LibraryTagsCompletionProposalComputer method getDefaultJSPCMDocument.

/**
 * <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
 *
 * For JSP files and segments, this is just the JSP document, but when
 * editing tag files and their fragments, it should be the tag document.
 *
 * It may also vary based on the model being edited in the future.
 *
 * @return the default non-embedded CMDocument for the document being
 *         edited.
 */
private CMDocument getDefaultJSPCMDocument(IDOMNode node) {
    // handle tag files here
    String contentType = node.getModel().getContentTypeIdentifier();
    if (ContentTypeIdForJSP.ContentTypeID_JSPTAG.equals(contentType))
        return JSPCMDocumentFactory.getCMDocument(CMDocType.TAG20_DOC_TYPE);
    CMDocument jcmdoc = null;
    String modelPath = node.getModel().getBaseLocation();
    if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
        float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
        jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
    }
    if (jcmdoc == null) {
        jcmdoc = JSPCMDocumentFactory.getCMDocument();
    }
    return jcmdoc;
}
Also used : JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path)

Example 28 with CMDocument

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

the class TestCatalogContentModels method assertIsNotXHTMLContentModel.

private void assertIsNotXHTMLContentModel(IDOMModel htmlModel) {
    Element html = htmlModel.getDocument().getDocumentElement();
    CMDocument correspondingCMDocument = ModelQueryUtil.getModelQuery(htmlModel).getCorrespondingCMDocument(html);
    assertNotNull("content model document not found", correspondingCMDocument);
    assertTrue("document is unexpectedly XHTML", correspondingCMDocument.supports(HTMLCMProperties.IS_XHTML));
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Element(org.w3c.dom.Element)

Example 29 with CMDocument

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

the class DocumentImpl method getCharValue.

/**
 * getCharValue method
 *
 * @return java.lang.String
 * @param name
 *            java.lang.String
 */
protected String getCharValue(String name) {
    if (name == null)
        return null;
    int length = name.length();
    if (length == 0)
        return null;
    if (name.charAt(0) == '#') {
        // character reference
        if (length == 1)
            return null;
        int radix = 10;
        String s = null;
        // now allow hexadecimal also for non XML document
        if (name.charAt(1) == 'x') {
            // hexadecimal
            radix = 16;
            s = name.substring(2);
        } else {
            // decimal
            s = name.substring(1);
        }
        if (s == null || s.length() == 0)
            return null;
        if (s.charAt(0) == '-')
            // no minus accepted
            return null;
        char c = 0;
        try {
            c = (char) Integer.parseInt(s, radix);
        } catch (NumberFormatException ex) {
        }
        if (c == 0)
            return null;
        return String.valueOf(c);
    }
    // implicit character entities for XML
    if (name.equals(IXMLCharEntity.LT_NAME))
        return IXMLCharEntity.LT_VALUE;
    if (name.equals(IXMLCharEntity.GT_NAME))
        return IXMLCharEntity.GT_VALUE;
    if (name.equals(IXMLCharEntity.AMP_NAME))
        return IXMLCharEntity.AMP_VALUE;
    if (name.equals(IXMLCharEntity.QUOT_NAME))
        return IXMLCharEntity.QUOT_VALUE;
    if (isXMLType()) {
        if (name.equals(IXMLCharEntity.APOS_NAME))
            return IXMLCharEntity.APOS_VALUE;
    }
    CMDocument cm = getCMDocument();
    if (cm != null) {
        CMNamedNodeMap map = cm.getEntities();
        if (map != null) {
            CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
            if (decl != null) {
                String value = decl.getValue();
                if (value == null)
                    return null;
                int valueLength = value.length();
                if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
                    // character reference
                    return getCharValue(value.substring(1, valueLength - 1));
                }
                return value;
            }
        }
    }
    return null;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 30 with CMDocument

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

the class DOMContentBuilderImpl method visitCMAnyElement.

public void visitCMAnyElement(CMAnyElement anyElement) {
    // ingnore buildPolicy for ANY elements... only create elements if
    // absolutely needed
    // 
    int forcedMin = alwaysVisit ? 1 : 0;
    int min = Math.max(anyElement.getMinOccur(), forcedMin);
    alwaysVisit = false;
    String uri = anyElement.getNamespaceURI();
    // $NON-NLS-1$
    String targetNSProperty = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
    // $NON-NLS-1$
    CMDocument parentCMDocument = (CMDocument) anyElement.getProperty("CMDocument");
    CMElementDeclaration ed = null;
    // //$NON-NLS-1$
    if (parentCMDocument != null) {
        if (// $NON-NLS-1$
        uri == null || uri.startsWith("##") || uri.equals(parentCMDocument.getProperty(targetNSProperty))) {
            ed = getSuitableElement(getParentCMElementDeclaration(), parentCMDocument);
        }
    }
    if (// $NON-NLS-1$
    ed == null && externalCMDocumentSupport != null && uri != null && !uri.startsWith("##") && currentParent instanceof Element) {
        CMDocument externalCMDocument = externalCMDocumentSupport.getCMDocument((Element) currentParent, uri);
        if (externalCMDocument != null) {
            ed = getSuitableElement(null, externalCMDocument);
        }
    }
    for (int i = 1; i <= min; i++) {
        if (ed != null) {
            visitCMElementDeclaration(ed);
        } else {
            // $NON-NLS-1$
            Element element = document.createElement("ANY-ELEMENT");
            linkNode(element);
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element)

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