Search in sources :

Example 26 with IDOMElement

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

the class XMLGeneratorImpl method generateTagName.

/**
 */
public String generateTagName(Element element) {
    if (element == null)
        return null;
    IDOMElement xe = (IDOMElement) element;
    String tagName = element.getTagName();
    if (tagName == null)
        return null;
    if (xe.isJSPTag()) {
        if (tagName.equals(JSPTag.JSP_EXPRESSION))
            return JSPTag.EXPRESSION_TOKEN;
        if (tagName.equals(JSPTag.JSP_DECLARATION))
            return JSPTag.DECLARATION_TOKEN;
        if (tagName.equals(JSPTag.JSP_DIRECTIVE))
            return JSPTag.DIRECTIVE_TOKEN;
        if (tagName.startsWith(JSPTag.JSP_DIRECTIVE)) {
            // after '.'
            int offset = JSPTag.JSP_DIRECTIVE.length() + 1;
            return (JSPTag.DIRECTIVE_TOKEN + tagName.substring(offset));
        }
        return (xe.isCommentTag()) ? tagName : null;
    } else if (tagName.startsWith(JSPTag.TAG_OPEN)) {
        if (!tagName.endsWith(JSPTag.TAG_CLOSE)) {
            // close JSP
            return (tagName + JSPTag.TAG_CLOSE);
        }
    } else if (xe.isCommentTag()) {
        String prefix = element.getPrefix();
        if (prefix.equals(SSI_PREFIX)) {
            return (SSI_TOKEN + element.getLocalName());
        }
    } else {
        if (// global tag
        !xe.isJSPTag() && xe.isGlobalTag() && CMNodeUtil.getElementDeclaration(xe) != null) {
            String newName = tagName;
            switch(getTagNameCase(xe)) {
                case DocumentTypeAdapter.UPPER_CASE:
                    newName = tagName.toUpperCase(Locale.ENGLISH);
                    break;
                case DocumentTypeAdapter.LOWER_CASE:
                    newName = tagName.toLowerCase(Locale.ENGLISH);
                    break;
            }
            if (newName != tagName) {
                tagName = newName;
                setTagName(element, tagName);
            }
        }
    }
    return tagName;
}
Also used : IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 27 with IDOMElement

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

the class TestAttributesOrder method ensureDocumentHasGrammar.

/**
 * Reusable test to make sure the XML model for the given file has a grammar.
 *
 * @param file
 *          the file containing the XML document.
 */
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
        assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) 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) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 28 with IDOMElement

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

the class TestCyclicGroupReferences method testCyclicGroupReferences.

/**
 * Test CMVisitor for cyclic group references.
 */
public void testCyclicGroupReferences() {
    // $NON-NLS-1$
    IFile file = getFile("Test.xml");
    CMVisitor cmVisitor = new CMVisitor();
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        cmElementDeclaration);
        cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
    } catch (Throwable th) {
        fail("Test failed :" + th.getClass().getName());
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CMVisitor(org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor) 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) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 29 with IDOMElement

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

the class TestOpenEditorXML method testBug151069.

/**
 * Test structured document is reloaded on resource change
 */
public void testBug151069() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    // set h1 to readonly
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getExistingModelForEdit(doc);
        if (model != null) {
            NodeList nl = model.getDocument().getElementsByTagName("h1");
            IDOMElement h1 = (IDOMElement) nl.item(0);
            h1.setEditable(false, true);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
    String newContent = "new content";
    ((IDocumentExtension4) doc).set(newContent, fFile.getModificationStamp());
    assertEquals("Set contents in document with read only regions failed", newContent, doc.get());
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDocument(org.eclipse.jface.text.IDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 30 with IDOMElement

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

the class EXSLTContentAssistRequestFactory method getContentAssistRequest.

/**
 * Get the appropriate content assist request class for the XSL request.
 * @return
 */
public IContentAssistProposalRequest getContentAssistRequest() {
    NamedNodeMap nodeMap = xmlNode.getAttributes();
    IDOMElement element = (IDOMElement) xmlNode;
    IContentAssistProposalRequest proposal = commonAttributeProposals(nodeMap);
    if (proposal instanceof NullContentAssistRequest) {
        if (isElementProposal(element)) {
            proposal = getNullProposal();
        }
    }
    return proposal;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IContentAssistProposalRequest(org.eclipse.wst.xsl.ui.provisional.contentassist.IContentAssistProposalRequest) NullContentAssistRequest(org.eclipse.wst.xsl.ui.provisional.contentassist.NullContentAssistRequest) 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