use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JSPJavaValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model) {
for (int i = 0; i < DEPEND_ONs.length; i++) {
addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
}
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
ModelHandlerForJSP.ensureTranslationAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
IJSPTranslation translation = translationAdapter.getJSPTranslation();
if (!reporter.isCancelled()) {
loadPreferences(f);
// only update task markers if the model is the same as what's on disk
boolean updateJavaTasks = UPDATE_JAVA_TASKS && !domModel.isDirty() && f != null && f.isAccessible();
if (updateJavaTasks) {
// remove old Java task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVA_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
/*
* Possible error in problem collection; EL translation is
* extensible, so we must be paranoid about this.
*/
if (problem == null)
continue;
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateJavaTasks) {
// add new Java task marker
try {
IMarker task = f.createMarker(JAVA_TASK_MARKER_TYPE);
task.setAttribute(IMarker.LINE_NUMBER, new Integer(m.getLineNumber()));
task.setAttribute(IMarker.CHAR_START, new Integer(m.getOffset()));
task.setAttribute(IMarker.CHAR_END, new Integer(m.getOffset() + m.getLength()));
task.setAttribute(IMarker.MESSAGE, m.getText());
task.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE);
switch(m.getSeverity()) {
case IMessage.HIGH_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
}
break;
case IMessage.LOW_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_LOW));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
}
break;
default:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_NORMAL));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
} else {
reporter.addMessage(fMessageOriginator, m);
}
}
}
}
}
unloadPreferences();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JSPJavaValidator method validateFile.
/**
* Validate one file. It's assumed that the file has JSP content type.
*
* @param f
* @param reporter
*/
protected void validateFile(IFile f, IReporter reporter) {
if (DEBUG) {
// $NON-NLS-1$
Logger.log(Logger.INFO, getClass().getName() + " validating: " + f);
}
IStructuredModel model = null;
try {
// get jsp model, get tranlsation
model = StructuredModelManager.getModelManager().getModelForRead(f);
if (!reporter.isCancelled() && model != null) {
for (int i = 0; i < DEPEND_ONs.length; i++) {
addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
}
// get jsp model, get translation
if (model instanceof IDOMModel) {
reporter.removeAllMessages(fMessageOriginator, f);
performValidation(f, reporter, 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 StyleElementAdapter method replaceData.
/**
* Apply changes from CSS sub-model to HTML model
*/
private void replaceData(int offset, int length, String data) {
IDOMNode element = (IDOMNode) getElement();
if (element == null)
return;
IDOMModel ownerModel = element.getModel();
if (ownerModel == null)
return;
IStructuredDocument structuredDocument = ownerModel.getStructuredDocument();
if (structuredDocument == null)
return;
IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
if (flatNode == null)
return;
int contentOffset = flatNode.getEndOffset();
if (data == null)
// $NON-NLS-1$
data = "";
this.ignoreNotification = true;
structuredDocument.replaceText(getRequesterC2H(), contentOffset + offset, length, data);
this.ignoreNotification = false;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class HTMLConverter method readModel.
/**
*/
private IDOMModel readModel(InputStream input) throws IOException, UnsupportedEncodingException {
if (input == null)
return null;
// create temporary model
// $NON-NLS-1$
String id = input.toString() + ".html";
IModelManager manager = StructuredModelManager.getModelManager();
IStructuredModel model = manager.getModelForEdit(id, input, null);
if (!(model instanceof IDOMModel)) {
if (model != null)
model.releaseFromEdit();
return null;
}
return (IDOMModel) model;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class HTMLConverter method readModel.
/**
*/
private IDOMModel readModel(IFile file) throws IOException, CoreException {
if (file == null)
return null;
IModelManager manager = StructuredModelManager.getModelManager();
IStructuredModel model = manager.getModelForEdit(file);
if (!(model instanceof IDOMModel)) {
if (model != null)
model.releaseFromEdit();
return null;
}
return (IDOMModel) model;
}
Aggregations