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