Search in sources :

Example 46 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 47 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 48 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 49 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 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)

Example 50 with IDOMDocument

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

the class JSDTContentAssistantProcessor method computeCompletionProposals.

/**
 * Returns a list of completion proposals based on the specified location
 * within the document that corresponds to the current cursor position
 * within the text viewer.
 *
 * @param viewer
 *            the viewer whose document is used to compute the proposals
 * @param documentPosition
 *            an offset within the document for which completions should be
 *            computed
 * @return an array of completion proposals or <code>null</code> if no
 *         proposals are possible
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos) {
    initialize(pos);
    JSDTProposalCollector collector = null;
    IDOMModel xmlModel = null;
    try {
        fViewer = viewer;
        xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument());
        IDOMDocument xmlDoc = xmlModel.getDocument();
        JsTranslationAdapterFactory.setupAdapterFactory(xmlModel);
        JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
        if (translationAdapter != null) {
            IJsTranslation translation = translationAdapter.getJsTranslation(true);
            fJavaPosition = translation.getJavaScriptOffset(getDocumentPosition());
            try {
                IJavaScriptUnit cu = translation.getCompilationUnit();
                // or without a valid position
                if (cu == null || -1 == fJavaPosition) {
                    return new ICompletionProposal[0];
                }
                collector = getProposalCollector();
                synchronized (cu) {
                    cu.codeComplete(fJavaPosition, collector, null);
                }
            } catch (CoreException coreEx) {
                // a possible Java Model Exception due to not being a Web
                // (Java) Project
                coreEx.printStackTrace();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    // throw out exceptions on code assist.
    } finally {
        if (xmlModel != null) {
            xmlModel.releaseFromRead();
        }
    }
    ICompletionProposal[] results = new ICompletionProposal[0];
    if (collector != null) {
        results = collector.getJSPCompletionProposals();
        if (results == null || results.length < 1) {
            fErrorMessage = JsUIMessages.Java_Content_Assist_is_not_UI_;
        }
    }
    return results;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IJavaScriptUnit(org.eclipse.wst.jsdt.core.IJavaScriptUnit) CoreException(org.eclipse.core.runtime.CoreException)

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