Search in sources :

Example 56 with IDOMModel

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

the class JSPContentValidator method validateFile.

protected void validateFile(IFile f, IReporter reporter) {
    IStructuredModel model = null;
    try {
        if (fragmentCheck(f) && !reporter.isCancelled()) {
            model = StructuredModelManager.getModelManager().getModelForRead(f);
            if (!reporter.isCancelled() && model instanceof IDOMModel) {
                reporter.removeAllMessages(this, f);
                validate(reporter, f, (IDOMModel) model);
            }
        }
    } catch (IOException e) {
        Logger.logException(e);
    } catch (CoreException e) {
        Logger.logException(e);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 57 with IDOMModel

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

the class TLDValidator method detectProblems.

private Map[] detectProblems(IJavaProject javaProject, IFile tld, IScopeContext[] preferenceScopes) throws CoreException {
    List problems = new ArrayList();
    IStructuredModel m = null;
    try {
        m = StructuredModelManager.getModelManager().getModelForRead(tld);
        if (m != null && m instanceof IDOMModel) {
            IDOMDocument document = ((IDOMModel) m).getDocument();
            for (int i = 0; i < classElementNames.length; i++) {
                NodeList classes = document.getElementsByTagName(classElementNames[i]);
                for (int j = 0; j < classes.getLength(); j++) {
                    Map problem = checkClass(javaProject, classes.item(j), preferenceScopes, missingClassSeverityPreferenceKeys[i], missingClassMessages[i]);
                    if (problem != null)
                        problems.add(problem);
                }
            }
        }
    } catch (IOException e) {
        Logger.logException(e);
    } finally {
        if (m != null)
            m.releaseFromRead();
    }
    return (Map[]) problems.toArray(new Map[problems.size()]);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with IDOMModel

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

the class JSPSearchDocument method getJSPTranslation.

/**
 * It's not recommended for clients to hold on to this JSPTranslation
 * since it's kind of large. If possible, hold on to the
 * JSPSearchDocument, which is more of a lightweight proxy.
 *
 * @return the JSPTranslation for the jsp file, or null if it's an
 *         unsupported file.
 */
public final JSPTranslationExtension getJSPTranslation() {
    JSPTranslationExtension translation = null;
    IFile jspFile = getFile();
    if (!JSPSearchSupport.isJsp(jspFile))
        return translation;
    IStructuredModel model = null;
    try {
        // get existing model for read, then get document from it
        IModelManager modelManager = getModelManager();
        if (modelManager != null) {
            jspFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
            model = modelManager.getModelForRead(jspFile);
        }
        // handle unsupported
        if (model instanceof IDOMModel) {
            IDOMModel xmlModel = (IDOMModel) model;
            setupAdapterFactory(xmlModel);
            IDOMDocument doc = xmlModel.getDocument();
            JSPTranslationAdapter adapter = (JSPTranslationAdapter) doc.getAdapterFor(IJSPTranslation.class);
            translation = adapter.getJSPTranslation();
        }
    } catch (IOException e) {
        Logger.logException(e);
    } catch (CoreException e) {
        Logger.logException(e);
    } catch (UnsupportedCharsetExceptionWithDetail e) {
    // no need to log this. Just consider it an invalid file for our
    // purposes.
    // Logger.logException(e);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
    return translation;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) 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) UnsupportedCharsetExceptionWithDetail(org.eclipse.wst.sse.core.internal.exceptions.UnsupportedCharsetExceptionWithDetail) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 59 with IDOMModel

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

the class JSDTHyperlinkDetector method getJsTranslation.

/**
 * Get JSP translation object
 *
 * @return JSPTranslation if one exists, null otherwise
 */
private IJsTranslation getJsTranslation(IDocument document) {
    IJsTranslation translation = null;
    IDOMModel xmlModel = null;
    try {
        xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (xmlModel != null) {
            IDOMDocument xmlDoc = xmlModel.getDocument();
            JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
            if (adapter != null) {
                translation = adapter.getJsTranslation(true);
            }
        }
    } finally {
        if (xmlModel != null) {
            xmlModel.releaseFromRead();
        }
    }
    return translation;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 60 with IDOMModel

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

the class JSPJavaSelectionProvider method getSelection.

static IJavaScriptElement[] getSelection(ITextEditor textEditor) {
    IJavaScriptElement[] 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 = null;
        try {
            model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
            if (model instanceof IDOMModel) {
                IDOMModel xmlModel = (IDOMModel) model;
                IDOMDocument xmlDoc = xmlModel.getDocument();
                JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
                if (adapter != null) {
                    IJsTranslation translation = adapter.getJsTranslation(true);
                    elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(textSelection.getOffset()), translation.getJavaScriptOffset(textSelection.getOffset() + textSelection.getLength()));
                }
            }
        } finally {
            if (model != null) {
                model.releaseFromRead();
            }
        }
    }
    if (elements == null) {
        elements = new IJavaScriptElement[0];
    }
    return elements;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) 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) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25