private DOMModelForJSP getModelForFile(final IFile file) throws CoreException, IOException { final IModelManager modelManager = StructuredModelManager.getModelManager(); IStructuredModel model = modelManager.getModelForRead(file); if (model instanceof DOMModelForJSP) { return (DOMModelForJSP) model; } else if (model != null) { // only release from read if we don't find a DOMModelForJSP // if the model is correct, it will be released in dispose model.releaseFromRead(); } throw new CoreException (new Status(IStatus.ERROR , "org.eclipse.blah" , 0 //$NON-NLS-1$ ,"model not of expected type" , new Throwable())); //$NON-NLS-1$ }
private IPath getModelPath() { IPath path = null; IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(getStructuredDocument()); try { if (sModel != null) path = new Path(sModel.getBaseLocation()); } finally { if (sModel != null) sModel.releaseFromRead(); } return path; }
/** * @return Returns the fModelQuery. */ public ModelQuery getModelQuery(IDocument doc) { IStructuredModel model = null; ModelQuery mq = null; try { model = StructuredModelManager.getModelManager().getExistingModelForRead(doc); mq = ModelQueryUtil.getModelQuery(model); } finally { if (model != null) model.releaseFromRead(); } return mq; }
private IFile getFile() { IFile f = null; IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(getStructuredDocument()); try { if (sModel != null) f = FileBuffers.getWorkspaceFileAtLocation(new Path(sModel.getBaseLocation())); } finally { if (sModel != null) sModel.releaseFromRead(); } return f; }
/** * Returns the SSE DOM Node {@link IDOMNode} by offset from the * {@link IDocument} document and null if not found. * * @param document * the document. * @param offset * the offset. * @return */ public static final IDOMNode getNodeByOffset(IDocument document, int offset) { IStructuredModel model = null; try { model = StructuredModelManager.getModelManager() .getExistingModelForRead(document); return getNodeByOffset(model, offset); } finally { if (model != null) model.releaseFromRead(); } }
/** * Returns the SSE DOM Node {@link IDOMNode} by offset from the * {@link IDocument} document and null if not found. * * @param document * the document. * @param offset * the offset. * @return */ public static final IDOMNode getNodeByOffset(IDocument document, int offset) { IStructuredModel model = null; try { model = StructuredModelManager.getModelManager().getExistingModelForRead(document); return getNodeByOffset(model, offset); } finally { if (model != null) model.releaseFromRead(); } }
/** * Returns the owner file of the JFace document {@link IDocument}. * * @param document * @return */ public static final IFile getFile(IDocument document) { if (document == null) { return null; } IStructuredModel model = null; try { model = StructuredModelManager.getModelManager() .getExistingModelForRead(document); if (model != null) { return getFile(model); } } finally { if (model != null) model.releaseFromRead(); } return null; }
/** * Returns the owner file of the JFace document {@link IDocument}. * * @param document * @return */ public static final IFile getFile(IDocument document) { if (document == null) { return null; } IStructuredModel model = null; try { model = StructuredModelManager.getModelManager().getExistingModelForRead(document); if (model != null) { return getFile(model); } } finally { if (model != null) model.releaseFromRead(); } return null; }
public IDOMNode getXMLNode(int offset) { IStructuredModel xmlModel = null; IDOMNode xmlNode = null; try { xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); xmlNode = (IDOMNode) xmlModel.getIndexedRegion(offset); } finally { if (xmlModel != null) xmlModel.releaseFromRead(); } return xmlNode; } }
public ModelQuery getModelQuery() { ModelQuery mq = null; IStructuredModel xmlModel = null; try { xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); mq = ModelQueryUtil.getModelQuery(xmlModel); } finally { if (xmlModel != null) { xmlModel.releaseFromRead(); } } return mq; }
protected void validateFile(IFile f, IReporter reporter) { if (DEBUG) { Logger.log(Logger.INFO, getClass().getName() + " validating: " + f); //$NON-NLS-1$ } IStructuredModel sModel = null; try { sModel = StructuredModelManager.getModelManager().getModelForRead(f); if (sModel != null && !reporter.isCancelled()) { performValidation(f, reporter, sModel); } } catch (Exception e) { Logger.logException(e); } finally { if (sModel != null) sModel.releaseFromRead(); } } }
protected void validateFile(IFile file, IReporter reporter) { if (DEBUG) { Logger.log(Logger.INFO, getClass().getName() + " validating: " + file); //$NON-NLS-1$ } IStructuredModel model = null; try { model = StructuredModelManager.getModelManager().getModelForRead(file); if (!reporter.isCancelled() && model != null) { performValidation(file, reporter, model.getStructuredDocument()); } } catch (Exception e) { Logger.logException(e); } finally { if (null != model) model.releaseFromRead(); } }
/** * batch validation call */ protected void validateFile(IFile f, IReporter reporter) { if (DEBUG) { Logger.log(Logger.INFO, getClass().getName() + " validating: " + f); //$NON-NLS-1$ } IStructuredModel sModel = null; try { sModel = StructuredModelManager.getModelManager().getModelForRead(f); if (sModel != null && !reporter.isCancelled()) { performValidation(f, reporter, sModel.getStructuredDocument()); } } catch (Exception e) { Logger.logException(e); } finally { if (sModel != null) sModel.releaseFromRead(); } } }
private IDOMNode getXMLNode(IStructuredDocumentRegion sdRegion) { if (sdRegion == null) { return null; } IStructuredModel xModel = null; IDOMNode xmlNode = null; // get/release models should always be in a try/finally block try { xModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); // xModel is sometime null, when closing editor, for example if (xModel != null) { xmlNode = (IDOMNode) xModel.getIndexedRegion(sdRegion.getStart()); } } finally { if (xModel != null) { xModel.releaseFromRead(); } } return xmlNode; }
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { Object textEditor = getActiveTextEditor(); if (!((textEditor instanceof ITextEditorExtension3) && (((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT))) { return; } IStructuredModel model = null; try { model = StructuredModelManager.getModelManager().getExistingModelForRead(document); if (model != null) { if (command.text != null) { smartInsertForComment(command, document, model); smartInsertForEndTag(command, document, model); } } } finally { if (model != null) { model.releaseFromRead(); } } }
public void setDocument(IDocument document) { /* * let the text editor to be the one that manages the model's lifetime */ IStructuredModel model = null; try { model = StructuredModelManager.getModelManager().getExistingModelForRead(document); if ((model != null) && (model instanceof IDOMModel)) { Document domDoc = null; domDoc = ((IDOMModel) model).getDocument(); setInput(domDoc); treeExtension.setIsUnsupportedInput(false); } else { treeExtension.setIsUnsupportedInput(true); } } finally { if (model != null) { model.releaseFromRead(); } } }
protected void validateFile(IFile f, IReporter reporter) { IStructuredModel model = null; try { 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(); } } }
fStructuredModel.releaseFromRead();