Search in sources :

Example 61 with IDOMDocument

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

the class AdapterFactoryProviderForJSP method addPropagatingAdapters.

protected void addPropagatingAdapters(IStructuredModel structuredModel) {
    if (structuredModel instanceof IDOMModel) {
        IDOMModel xmlModel = (IDOMModel) structuredModel;
        IDOMDocument document = xmlModel.getDocument();
        PropagatingAdapter propagatingAdapter = (PropagatingAdapter) document.getAdapterFor(PropagatingAdapter.class);
        if (propagatingAdapter != null) {
        // what to do?
        }
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PropagatingAdapter(org.eclipse.wst.sse.core.internal.PropagatingAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 62 with IDOMDocument

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

the class XMLJavaHyperlinkDetector method isJspJavaContent.

private boolean isJspJavaContent(IDocument document, IRegion region) {
    JSPTranslation translation = null;
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model instanceof IDOMModel) {
            IDOMModel xmlModel = (IDOMModel) model;
            if (xmlModel != null) {
                final IDOMDocument xmlDoc = xmlModel.getDocument();
                final JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
                if (adapter != null) {
                    translation = adapter.getJSPTranslation();
                    if (translation != null) {
                        int javaOffset = translation.getJavaOffset(region.getOffset());
                        if (javaOffset > -1) {
                            return true;
                        }
                    }
                }
            }
        }
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return false;
}
Also used : IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 63 with IDOMDocument

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

the class JSPJavaSelectionProvider method getSelection.

static IJavaElement[] getSelection(ITextEditor textEditor) {
    IJavaElement[] elements = null;
    IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    if (selection instanceof ITextSelection) {
        ITextSelection textSelection = (ITextSelection) selection;
        // get the JSP translation object for this editor's document
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        try {
            if (model instanceof IDOMModel) {
                IDOMModel xmlModel = (IDOMModel) model;
                IDOMDocument xmlDoc = xmlModel.getDocument();
                JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
                if (adapter != null) {
                    JSPTranslation translation = adapter.getJSPTranslation();
                    elements = translation.getElementsFromJspRange(textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
                }
            }
        } finally {
            if (model != null)
                model.releaseFromRead();
        }
    }
    if (elements == null) {
        elements = new IJavaElement[0];
    }
    return elements;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ISelection(org.eclipse.jface.viewers.ISelection) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 64 with IDOMDocument

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

the class TestFormatUtility method testInlineNode.

public void testInlineNode() {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    IDOMDocument document = model.getDocument();
    HTMLFormattingUtil util = new HTMLFormattingUtil();
    assertTrue("Anchor tag must be inline", util.isInline(document.createElement("a")));
    assertFalse("Div tag must not be inline", util.isInline(document.createElement("div")));
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) HTMLFormattingUtil(org.eclipse.wst.html.core.internal.format.HTMLFormattingUtil)

Example 65 with IDOMDocument

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

the class BUG124835SetStyleAttributeValueTest method testSetAttributeValue.

/**
 * Tests setting some css attribute values including setting the same
 * value several times for different attributes
 */
public void testSetAttributeValue() {
    final String ABSOLUTE = "absolute";
    final String ONE = "1";
    final String PX = "50px";
    IDOMModel model = FileUtil.createHTMLModel();
    try {
        IDOMDocument doc = model.getDocument();
        Element element = doc.createElement(HTML40Namespace.ElementName.DIV);
        element.setAttribute(HTML40Namespace.ATTR_NAME_ID, "Layer0");
        element.setAttribute(HTML40Namespace.ATTR_NAME_STYLE, "");
        setInlineStyle(element, PropCMProperty.P_POSITION, ABSOLUTE);
        setInlineStyle(element, PropCMProperty.P_Z_INDEX, ONE);
        setInlineStyle(element, PropCMProperty.P_WIDTH, PX);
        setInlineStyle(element, PropCMProperty.P_HEIGHT, PX);
        setInlineStyle(element, PropCMProperty.P_TOP, PX);
        setInlineStyle(element, PropCMProperty.P_LEFT, PX);
        assertEquals(ABSOLUTE, getInlineStyle(element, PropCMProperty.P_POSITION));
        assertEquals(ONE, getInlineStyle(element, PropCMProperty.P_Z_INDEX));
        assertEquals(PX, getInlineStyle(element, PropCMProperty.P_WIDTH));
        assertEquals(PX, getInlineStyle(element, PropCMProperty.P_HEIGHT));
        assertEquals(PX, getInlineStyle(element, PropCMProperty.P_TOP));
        assertEquals(PX, getInlineStyle(element, PropCMProperty.P_LEFT));
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9