Search in sources :

Example 86 with IModelManager

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

the class StructuredDocumentToDOMUnitTests method testNodeDeletion3.

/**
 * Unit test -- tests basic parsing results of inserting a test string
 * into an initial string.
 */
void testNodeDeletion3() {
    String initialString = getTestString3();
    // print out what we always can
    System.out.println();
    System.out.println("----------------");
    System.out.println("Test Node Deletion");
    String outString = StringUtils.escape(initialString);
    System.out.println("Initial String: " + outString);
    // always start with fresh model
    IStructuredDocument f = null;
    IModelManager mm = StructuredModelManager.getModelManager();
    try {
        f = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
    } catch (IOException e) {
    // do nothing, since dummy
    }
    // 
    // we'll listen to structuredDocument events to print out diagnostics
    f.addDocumentChangedListener(this);
    // 
    IDOMModel tree = new DOMModelImpl();
    f.addDocumentChangingListener((IStructuredDocumentListener) tree);
    // set text to structuredDocument (which updates tree)
    f.setText(null, initialString);
    // dump initial structuredDocument
    Debug.dump(f);
    // dump initial dom
    DebugDocument.dump(tree.getDocument());
    // 
    // 
    // makeChange1(tree);
    makeChange3(tree);
    // display resulting text
    System.out.println("resultString (from structuredDocument): ");
    System.out.println(StringUtils.escape(f.getText()));
    // 
    // 
    // dump post change structuredDocument
    Debug.dump(f);
    // dump post change DOM
    DebugDocument.dump(tree.getDocument());
// 
}
Also used : InputStream(java.io.InputStream) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IOException(java.io.IOException)

Example 87 with IModelManager

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

the class TestPageDirective method testBasicChangedPDBack.

public void testBasicChangedPDBack() 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/html\" language=\"java\" %>");
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class);
    String contentType = pageDirectiveAdapter.getContentType();
    String language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertTrue("language should be java", "java".equals(language));
    // change to javascript
    model.getStructuredDocument().replaceText(this, 43, 4, "javascript");
    contentType = pageDirectiveAdapter.getContentType();
    language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertTrue("language should be javascript", "javascript".equals(language));
    // change back to java
    model.getStructuredDocument().replaceText(this, 43, 10, "java");
    contentType = pageDirectiveAdapter.getContentType();
    language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertEquals("java", language);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 88 with IModelManager

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

the class TestPageDirective method testBasicChangedPD.

public void testBasicChangedPD() 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/html\" language=\"java\" %>");
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class);
    String contentType = pageDirectiveAdapter.getContentType();
    String language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertTrue("language should be java", "java".equals(language));
    // change to javascript
    model.getStructuredDocument().replaceText(this, 43, 4, "javascript");
    contentType = pageDirectiveAdapter.getContentType();
    language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertTrue("language should be javascript", "javascript".equals(language));
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 89 with IModelManager

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

the class TestPageDirective method createUnmanagedHTMLModel.

private IDOMModel createUnmanagedHTMLModel() {
    // 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/html\" language=\"java\" %>");
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 90 with IModelManager

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

the class TestModelEmbeddedContentType method testStructuredModelEmbeddedHTML.

public void testStructuredModelEmbeddedHTML() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForHTML.ContentTypeID_HTML);
    assertTrue("model could not be created!", model != null);
    // should NOT have an embedded type
    Document doc = ((IDOMModel) model).getDocument();
    EmbeddedTypeHandler embeddedHandler = (EmbeddedTypeHandler) ((INodeNotifier) doc).getAdapterFor(EmbeddedTypeHandler.class);
    assertTrue("embededHanlder should be null for HTML", embeddedHandler == null);
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document)

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