use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TextTest2 method testModel.
public void testModel() {
IDOMModel model = createXMLModel();
try {
Document document = model.getDocument();
Element a = document.createElement("a");
document.appendChild(a);
CharacterData text = document.createTextNode("text");
a.appendChild(text);
text.setNodeValue("hello <");
printSource(model);
printTree(model);
fOutputWriter.writeln(text.getNodeValue());
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class UpdaterTest method testModel.
public void testModel() {
IDOMModel model = createHTMLModel();
try {
Document document = model.getDocument();
Element html = document.createElement("HTML");
document.appendChild(html);
printSource(model);
printTree(model);
Element body = document.createElement("BODY");
html.appendChild(body);
printSource(model);
printTree(model);
Element p = document.createElement("P");
body.appendChild(p);
printSource(model);
printTree(model);
Text text = document.createTextNode("text");
p.appendChild(text);
printSource(model);
printTree(model);
Element br = document.createElement("BR");
p.insertBefore(br, text);
printSource(model);
printTree(model);
Element img = document.createElement("IMG");
p.appendChild(img);
printSource(model);
printTree(model);
p.removeChild(text);
printSource(model);
printTree(model);
p.insertBefore(text, img);
printSource(model);
printTree(model);
body.removeChild(p);
printSource(model);
printTree(model);
body.appendChild(p);
printSource(model);
printTree(model);
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class UpdaterTest13 method testModel.
public void testModel() {
IDOMModel model = createXMLModel();
try {
IStructuredDocument structuredDocument = model.getStructuredDocument();
Document document = model.getDocument();
structuredDocument.replaceText(null, 0, 0, "<a>\r\n<b>\r\n</a>");
Element a = (Element) document.getFirstChild();
Element b = (Element) a.getLastChild();
Text text = document.createTextNode(" ");
a.appendChild(text);
printSource(model);
printTree(model);
a.removeChild(b);
printSource(model);
printTree(model);
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class UpdaterTest5 method testModel.
public void testModel() {
IDOMModel model = createXMLModel();
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a>'</a>");
printSource(model);
printTree(model);
Node a = document.getFirstChild();
Node t = a.getFirstChild();
a.removeChild(t);
a.appendChild(t);
printSource(model);
printTree(model);
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JsValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model, boolean inBatch) {
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
JsTranslationAdapterFactory.setupAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
// translationAdapter.resourceChanged();
IJsTranslation translation = translationAdapter.getJsTranslation(false);
if (!reporter.isCancelled()) {
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// only update task markers if the model is the same as what's on disk
boolean updateTasks = !domModel.isDirty() && f != null && f.isAccessible();
if (updateTasks) {
// remove old JavaScript task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVASCRIPT_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateTasks) {
// add new JavaScript task marker
try {
IMarker task = f.createMarker(JAVASCRIPT_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);
}
}
}
}
}
}
Aggregations