Search in sources :

Example 1 with NodeImpl

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);
    }
}
Also used : NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Collection(java.util.Collection) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 2 with NodeImpl

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);
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 3 with NodeImpl

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);
}
Also used : UserDataHandler(org.w3c.dom.UserDataHandler) NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) Node(org.w3c.dom.Node)

Example 4 with NodeImpl

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;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement)

Example 5 with NodeImpl

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);
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) NodeImpl(org.eclipse.wst.xml.core.internal.document.NodeImpl) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) JavaScriptModelException(org.eclipse.wst.jsdt.core.JavaScriptModelException)

Aggregations

NodeImpl (org.eclipse.wst.xml.core.internal.document.NodeImpl)6 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)2 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)2 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Position (org.eclipse.jface.text.Position)1 IMember (org.eclipse.wst.jsdt.core.IMember)1 ISourceRange (org.eclipse.wst.jsdt.core.ISourceRange)1 Member (org.eclipse.wst.jsdt.internal.core.Member)1