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);
}
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);
}
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();
}
}
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;
}
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);
}
Aggregations