Search in sources :

Example 31 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager 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 32 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager 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 33 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestModelManager method testCopyJSPModelForEdit.

public void testCopyJSPModelForEdit() throws IOException {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForEdit("test.jsp", new NullInputStream(), null);
        IStructuredModel modelCopy = modelManager.copyModelForEdit(model.getId(), getName() + ".newId");
        assertNotNull("copied JSP model was null", modelCopy);
        assertEquals("ModelHandlers differ", model.getModelHandler(), modelCopy.getModelHandler());
        assertEquals("StructuredDocument RegionParsers differ", model.getStructuredDocument().getParser().getClass(), modelCopy.getStructuredDocument().getParser().getClass());
        assertEquals("Text document contents differ", model.getStructuredDocument().get(), modelCopy.getStructuredDocument().get());
    } catch (ResourceInUse e) {
        fail("Resource in use reported for " + model.getId());
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 34 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestOfThreadLocalWithChanges method getDocument.

private IStructuredDocument getDocument(String content) throws IOException {
    if (fDocument == null) {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        fDocument = modelManager.createStructuredDocumentFor("testPerf.xml", content, null);
    }
    return fDocument;
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager)

Example 35 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestModelClone method testCreateStructuredModelJSPWML.

public void testCreateStructuredModelJSPWML() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    assertTrue("model could not be created!", model != null);
    // Now, assigning use a page directive, but leaving embedded type the same as default
    model.getStructuredDocument().setText(this, "<%@ page contentType=\"text/vnd.wap.wml\" %>\n" + "\n" + "  <jsp:useBean id=\"beanInstanceName\" scope=\"session\" class=\"package.class\" />\n" + "  <jsp:getProperty name=\"beanInstanceName\" property=\"*\" />\n" + "\n" + "  <?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "  <!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\">\n" + "  <wml>\n" + "\n" + "    <template>\n" + "      <!-- Template implementation here. -->\n" + "      <do type=\"prev\"><prev/></do>\n" + "    </template>\n" + "\n" + "  <%\n" + "  if (session.isNew() || session.getAttribute(\"userid\")==null ) {\n" + "  %>\n" + "    <card id=\"card1\" title=\"Card #1\">\n" + "\n" + "      <do type=\"unknown\" label=\"Next\">\n" + "        <go href=\"#card2\"/>\n" + "      </do>\n" + "      <p align=\"center\">\n" + "        <big><b>First Card</b></big>\n" + "      </p>\n" + "    </card>\n" + "\n" + "  <%\n" + "  } else {\n" + "  %>\n" + "    <card id=\"card2\" title=\"Card #2\">\n" + "\n" + "      <p align=\"center\">\n" + "        <big><b> <%= beanInstanceName.getUserid() %> </b></big>\n" + "      </p>\n" + "    </card>\n" + "  <%\n" + "  }\n" + "  %>\n" + "  </wml>");
    checkEmbeddedType(model, EmbeddedHTML.class);
    checkModelQuery(model, JSPModelQueryImpl.class);
    checkEmbeddedModelQuery(model, JSPModelQueryAdapterImpl.class, JSPModelQueryImpl.class, HTMLModelQueryImpl.class);
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)139 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)102 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)45 IOException (java.io.IOException)37 InputStream (java.io.InputStream)27 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)27 IFile (org.eclipse.core.resources.IFile)23 CoreException (org.eclipse.core.runtime.CoreException)21 BadLocationException (org.eclipse.jface.text.BadLocationException)13 FileNotFoundException (java.io.FileNotFoundException)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)11 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 IProject (org.eclipse.core.resources.IProject)9 StringBufferInputStream (java.io.StringBufferInputStream)8 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)7 IDocument (org.eclipse.jface.text.IDocument)6 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)6 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5