use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class HTMLValidator method validateFile.
/**
* @param result
*/
private void validateFile(IValidationContext helper, IReporter reporter, IFile file, ValidationResult result) {
if ((reporter != null) && (reporter.isCancelled() == true)) {
throw new OperationCanceledException();
}
if (!shouldValidate(file)) {
return;
}
IDOMModel model = getModel(file.getProject(), file);
if (model == null)
return;
try {
Collection dependencies = null;
NodeImpl document = null;
if (model.getDocument() instanceof NodeImpl) {
document = (NodeImpl) model.getDocument();
}
if (result != null && document != null) {
dependencies = new HashSet();
document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, dependencies, null);
}
validate(reporter, file, model);
if (result != null && document != null) {
document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, null, null);
result.setDependsOn((IResource[]) dependencies.toArray(new IResource[dependencies.size()]));
}
} finally {
releaseModel(model);
}
}
use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method getTranslation.
private IJsTranslation getTranslation(Node node) {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMDocument xmlDoc = null;
try {
if (modelManager != null) {
IStructuredDocument doc = ((NodeImpl) node).getStructuredDocument();
model = modelManager.getExistingModelForRead(doc);
// model = modelManager.getModelForRead(doc);
}
IDOMModel domModel = (IDOMModel) model;
xmlDoc = domModel.getDocument();
} catch (Exception e) {
Logger.logException(e);
} finally {
if (model != null) {
// model.changedModel();
model.releaseFromRead();
}
}
if (xmlDoc == null) {
return null;
}
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
return translationAdapter.getJsTranslation(true);
}
use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class NodeImplTestCase method testNotifyUserDataHandler2.
/*
* Test for notifying the UserDataHandler when importing
*/
public void testNotifyUserDataHandler2() {
elementToImport = document.createElement("ElementToImport");
((NodeImpl) elementToImport).setUserData(KEY, VALUE, new UserDataHandler() {
public void handle(short operation, String key, Object data, Node src, Node dst) {
// parameters
if (operation == UserDataHandler.NODE_IMPORTED) {
assertEquals(VALUE, data);
assertEquals(KEY, key);
assertEquals(src, elementToImport);
assertEquals(dst, null);
if (DEBUG)
System.out.println("Operation: " + operation + " Key:" + key + " Object:" + data + " SourceNode:" + src.getLocalName() + " DestinationNode:" + dst);
}
}
});
document.importNode(elementToImport, true);
}
use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method getJSElementsFromNode.
private synchronized Object[] getJSElementsFromNode(Node node) {
if (node == null) {
return new Object[0];
}
int startOffset = 0;
int endOffset = 0;
IJavaScriptElement[] result = new IJavaScriptElement[0];
IJsTranslation translation = null;
if (node.getNodeType() == Node.TEXT_NODE && (node instanceof NodeImpl)) {
translation = getTranslation(node);
startOffset = translation.getJavaScriptOffset(((NodeImpl) node).getStartOffset());
endOffset = translation.getJavaScriptOffset(((NodeImpl) node).getEndOffset() - 1);
if (startOffset >= 0 && endOffset >= 0)
result = translation.getAllElementsInJsRange(startOffset, endOffset);
}
return result;
//
// if (result == null) return null;
// Object[] newResults = new Object[result.length];
// for (int i = 0; i < result.length; i++) {
// int htmllength = 0;
// int htmloffset = 0;
// Position position = null;
// try {
// htmllength = ((SourceRefElement) (result[i])).getSourceRange().getLength();
// htmloffset = translation.getJspOffset(((SourceRefElement)
// (result[i])).getSourceRange().getOffset());
// position = new Position(htmloffset, htmllength);
// } catch (JavaScriptModelException e) {
// e.printStackTrace();
// }
// newResults[i] = getJsNode(node.getParentNode(), (IJavaScriptElement) result[i],
// position);
// }
// return newResults;
}
use of org.eclipse.wst.xml.core.internal.document.NodeImpl in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method getTranslation.
private IJsTranslation getTranslation(Node node) {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMDocument xmlDoc = null;
try {
if (modelManager != null) {
IStructuredDocument doc = ((NodeImpl) node).getStructuredDocument();
model = modelManager.getExistingModelForRead(doc);
// model = modelManager.getModelForRead(doc);
}
IDOMModel domModel = (IDOMModel) model;
if (domModel == null)
return null;
xmlDoc = domModel.getDocument();
} catch (Exception e) {
Logger.logException(e);
} finally {
if (model != null) {
// model.changedModel();
model.releaseFromRead();
}
}
if (xmlDoc == null) {
return null;
}
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
return translationAdapter.getJsTranslation(true);
}
Aggregations