Search in sources :

Example 56 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class JsJfaceNode method getTranslation.

// private Method[] getMethods(){
// // returns the methods this class supports (as declared in interfaces)
// Class[] interfaces = getClass().getInterfaces();
// Vector vMethods = new Vector();
// for(int i = 0;i<interfaces.length;i++){
// Method methods[] = interfaces[i].getDeclaredMethods();
// vMethods.addAll(Arrays.asList(methods));
// }
// 
// return (Method[])vMethods.toArray();
// }
// public Object invoke(Object proxy, Method method, Object[] args) throws
// Throwable {
// Object result;
// Method[] myMethods = getMethods();
// 
// try {
// for(int i = 0;i<myMethods.length;i++){
// if(myMethods[i]==method){
// return method.invoke(this, args);
// }
// }
// result = method.invoke(parentType, args);
// } catch (InvocationTargetException e) {
// throw e.getTargetException();
// } catch (Exception e) {
// throw new RuntimeException("unexpected invocation exception: " +
// e.getMessage());
// }
// 
// return result;
// }
/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.xml.core.internal.document.NodeImpl#getStructuredDocument()
	 */
public IJsTranslation getTranslation() {
    IStructuredModel model = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMDocument xmlDoc = null;
    try {
        if (modelManager != null) {
            IStructuredDocument doc = 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) 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)

Example 57 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 58 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class JSPContentSourceValidator method validate.

/**
 * This validate call is for the ISourceValidator partial document
 * validation approach
 *
 * @param dirtyRegion
 * @param helper
 * @param reporter
 * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator
 */
public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {
    if (helper == null || fDocument == null || !fEnableSourceValidation)
        return;
    if ((reporter != null) && (reporter.isCancelled() == true)) {
        throw new OperationCanceledException();
    }
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
    if (model == null)
        // error
        return;
    try {
        IDOMDocument document = null;
        if (model instanceof IDOMModel) {
            document = ((IDOMModel) model).getDocument();
        }
        if (document == null || !hasHTMLFeature(document))
            // ignore
            return;
        ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument);
        if (fb == null)
            return;
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fb.getLocation());
        if (file == null || !file.exists())
            return;
        // this will be the wrong region if it's Text (instead of Element)
        // we don't know how to validate Text
        // model.getIndexedRegion(dirtyRegion.getOffset());
        IndexedRegion ir = getCoveringNode(dirtyRegion);
        if (ir instanceof Text) {
            while (ir != null && ir instanceof Text) {
                // it's assumed that this gets the IndexedRegion to
                // the right of the end offset
                ir = model.getIndexedRegion(ir.getEndOffset());
            }
        }
        if (ir instanceof INodeNotifier) {
            INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
            ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir);
            if (adapter == null)
                // error
                return;
            if (reporter != null) {
                HTMLValidationReporter rep = null;
                rep = getReporter(reporter, file, (IDOMModel) model);
                rep.clear();
                adapter.setReporter(rep);
                Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
                reporter.displaySubtask(this, mess);
            }
            adapter.validate(ir);
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Text(org.w3c.dom.Text) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 59 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class PageImport method isXMLDocument.

/**
 * Determines if the document is an XML-style JSP
 *
 * @param model the JSP's dom model
 * @return true is the document is an xml-style JSP
 */
private boolean isXMLDocument(IDOMModel model) {
    final IDOMDocument documentNode = model.getDocument();
    final Element docElement = documentNode.getDocumentElement();
    // $NON-NLS-1$  //$NON-NLS-2$
    return docElement != null && ((docElement.getNodeName().equals("jsp:root")) || docElement.getAttributeNode("xmlns:jsp") != null || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() == null && ((IDOMNode) docElement).getEndStructuredDocumentRegion() == null)));
}
Also used : Element(org.w3c.dom.Element) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 60 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class PageImport method getInsertPosition.

private int getInsertPosition(IDOMModel model, boolean isXML) {
    int pos = 0;
    IDOMDocument documentNode = model.getDocument();
    /*
		 * document element must be sole Element child of Document
		 * to remain valid
		 */
    Node targetElement = null;
    if (isXML) {
        targetElement = documentNode.getDocumentElement();
    }
    if (targetElement == null)
        targetElement = getInsertNode(documentNode);
    if (targetElement != null) {
        IStructuredDocumentRegion sdRegion = ((IDOMNode) targetElement).getFirstStructuredDocumentRegion();
        if (isXML) {
            /*
				 * document Element must be sole Element child of
				 * Document to remain valid, so insert after
				 */
            pos = sdRegion.getEndOffset();
            try {
                final IStructuredDocument doc = model.getStructuredDocument();
                while (pos < doc.getLength() && (doc.getChar(pos) == '\r' || doc.getChar(pos) == '\n')) {
                    pos++;
                }
            } catch (BadLocationException e) {
            // not important, use pos as determined earlier
            }
        } else {
            // insert before target element
            pos = sdRegion.getStartOffset();
        }
    } else {
        pos = 0;
    }
    return pos;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9