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()]);
}
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;
}
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;
}
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;
}
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;
}
Aggregations