Search in sources :

Example 91 with IDOMDocument

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

the class PrefixHandler method execute.

/**
 * This will use the active editor, and try and retrieve a structured
 * model from it.  If successful, it setups the namespace edit dialog
 * to capture the namespace information.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    XPathUIPlugin plugin = XPathUIPlugin.getDefault();
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    // suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
    if (activeEditor == null)
        return null;
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = plugin.getNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return null;
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) XPathUIPlugin(org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin) 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) IEditorPart(org.eclipse.ui.IEditorPart) EditNamespacePrefixDialog(org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 92 with IDOMDocument

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

the class XPathComputer method evaluateXPath.

protected IStatus evaluateXPath(SimpleXPathEngine engine) throws XPathExpressionException {
    IDOMDocument doc = null;
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        doc = (IDOMDocument) node;
    } else {
        doc = (IDOMDocument) node.getOwnerDocument();
    }
    updateNamespaces(engine, doc);
    try {
        this.nodeList = (NodeList) engine.execute(node);
        return Status.OK_STATUS;
    } catch (DynamicError de) {
        return new Status(IStatus.CANCEL, XPathCorePlugin.PLUGIN_ID, de.getMessage() + " (" + de.code() + ")");
    } catch (Throwable t) {
        return new Status(IStatus.ERROR, XPathCorePlugin.PLUGIN_ID, t.getMessage());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 93 with IDOMDocument

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

the class TestWTPDOMXPath2 method testWTPDOMWithTypes.

public void testWTPDOMWithTypes() throws Exception {
    // Test for the fix, for xpathDefaultNamespace
    bundle = Platform.getBundle("org.eclipse.wst.xml.xpath2.wtptypes.tests");
    URL fileURL = bundle.getEntry("/bugTestFiles/attrNodeTest.xml");
    super.domDoc = load(fileURL);
    // set up XPath default namespace in Dynamic Context
    DynamicContext dc = setupDynamicContext2(new XsdDOMTypeProvider.XsdTypeModel((IDOMDocument) domDoc));
    assertXPathTrue("/Example/x[1] instance of element(*, x_Type)", dc, domDoc);
    assertXPathTrue("not (/Example/x[1] instance of element(*, y_Type))", dc, domDoc);
    assertXPathTrue("/Example/x instance of x_Type+", dc, domDoc);
    assertXPathTrue("/Example/x instance of element(x, x_Type)+", dc, domDoc);
    assertXPathTrue("not (/Example/x instance of element(z, x_Type)+)", dc, domDoc);
    assertXPathTrue("/Example/x[2]/@mesg instance of mesg_Type", dc, domDoc);
    assertXPathTrue("/Example/x[2]/@mesg instance of attribute(mesg, mesg_Type)", dc, domDoc);
    assertXPathTrue("not (/Example/x[2]/@mesg instance of attribute(mesg, xs:integer))", dc, domDoc);
    assertXPathTrue("not (/Example/x[2]/@mesg instance of attribute(cesc, mesg_Type))", dc, domDoc);
    assertXPathTrue("/Example/y/@intAttr instance of attribute(intAttr, xs:integer)", dc, domDoc);
}
Also used : XsdDOMTypeProvider(org.eclipse.wst.xml.xpath2.wtptypes.XsdDOMTypeProvider) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Example 94 with IDOMDocument

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

the class StylesheetBuilder method parseModel.

private Stylesheet parseModel(IDOMModel model, IFile file) {
    IDOMDocument document = model.getDocument();
    Stylesheet sf = new Stylesheet(file);
    StylesheetParser walker = new StylesheetParser(sf);
    walker.walkDocument(document);
    return sf;
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Stylesheet(org.eclipse.wst.xsl.core.model.Stylesheet)

Example 95 with IDOMDocument

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

the class EditDoctypeAction method createDoctype.

protected DocumentType createDoctype(EditDoctypeDialog dialog, Document document) {
    DocumentType result = null;
    if (document instanceof DocumentImpl) {
        IDOMDocument documentImpl = (IDOMDocument) document;
        IDOMDocumentType doctypeImpl = (IDOMDocumentType) documentImpl.createDoctype(dialog.getName());
        doctypeImpl.setPublicId(dialog.getPublicId());
        doctypeImpl.setSystemId(dialog.getSystemId());
        result = doctypeImpl;
    }
    return result;
}
Also used : IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) DocumentType(org.w3c.dom.DocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

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