Search in sources :

Example 1 with DOMModelImpl

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

the class StructuredDocumentToDOMUnitTests method testNodeDeletion.

/**
 * Unit test -- tests basic parsing results of inserting a test string
 * into an initial string.
 */
void testNodeDeletion() {
    // String initialString =
    // "<par><x>\ntextx\n</x>\n<y>\ntexty\n</y></par>";
    // String initialString = "<par><x>textx</x><y>texty</y></par>";
    // test cases for two text nodes left together (remove <b/>):
    // first case works, second doesn't
    // String initialString = "<a>a<b /></a>"; // -> <a>a</a>
    // String initialString = "<a>a<b />b</a>"; // -> <a>ab</a>
    // String initialString = getTestString1();
    String initialString = getTestString2();
    // 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);
    makeChange2(f);
    // 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 2 with DOMModelImpl

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

the class UnitTests method setUpXML.

/**
 * Set up an XML model
 */
protected void setUpXML() {
    IModelManager mm = StructuredModelManager.getModelManager();
    try {
        fModel = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
    } catch (IOException e) {
    // do nothing, since dummy
    }
    fModel.addDocumentChangedListener(proxy);
    tree = new DOMModelImpl();
    if (tree != null) {
        fModel.addDocumentChangingListener((IStructuredDocumentListener) tree);
        tree.setStructuredDocument(fModel);
    }
}
Also used : InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IOException(java.io.IOException)

Example 3 with DOMModelImpl

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

the class UnitTests method setUpJSP.

/**
 * Set up a JSP model
 */
protected void setUpJSP() {
    IModelManager mm = StructuredModelManager.getModelManager();
    try {
        fModel = mm.createStructuredDocumentFor("dummy.jsp", (InputStream) null, null);
    } catch (IOException e) {
    // do nothing, since dummy
    }
    fModel = StructuredDocumentFactory.getNewStructuredDocumentInstance(new JSPSourceParser());
    fModel.addDocumentChangedListener(proxy);
    tree = new DOMModelImpl();
    if (tree != null) {
        fModel.addDocumentChangingListener((IStructuredDocumentListener) tree);
        tree.setStructuredDocument(fModel);
    }
}
Also used : InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IOException(java.io.IOException) JSPSourceParser(org.eclipse.jst.jsp.core.internal.parser.JSPSourceParser)

Example 4 with DOMModelImpl

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

the class CleanupProcessorXML method cleanupModel.

public void cleanupModel(IStructuredModel structuredModel) {
    Preferences preferences = getModelPreferences();
    if (preferences != null && preferences.getBoolean(XMLCorePreferenceNames.FIX_XML_DECLARATION)) {
        IDOMDocument document = ((DOMModelImpl) structuredModel).getDocument();
        if (!fixExistingXmlDecl(document)) {
            String encoding = preferences.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            Node xml = document.createProcessingInstruction("xml", "version=\"1.0\" " + "encoding=\"" + encoding + "\"");
            document.insertBefore(xml, document.getFirstChild());
        }
    }
    super.cleanupModel(structuredModel);
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Preferences(org.eclipse.core.runtime.Preferences) IStructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences) StructuredCleanupPreferences(org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)

Example 5 with DOMModelImpl

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

the class DOMImplementationTests method testCreateDocumentWellformedQualifiedNames.

public void testCreateDocumentWellformedQualifiedNames() {
    final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    final String[] names = { "bar", "foo:bar" };
    for (int i = 0; i < names.length; i++) {
        try {
            model.createDocument("http://eclipse.org", names[i], null);
        } catch (DOMException e) {
            fail("[" + names[i] + "] flagged as an invalid qualified name");
        }
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl)

Aggregations

DOMModelImpl (org.eclipse.wst.xml.core.internal.document.DOMModelImpl)19 DOMException (org.w3c.dom.DOMException)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)5 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 Document (org.w3c.dom.Document)4 Node (org.w3c.dom.Node)3 DocumentType (org.w3c.dom.DocumentType)2 Preferences (org.eclipse.core.runtime.Preferences)1 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)1 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)1 JSPSourceParser (org.eclipse.jst.jsp.core.internal.parser.JSPSourceParser)1 StructuredTextPartitionerForJSP (org.eclipse.jst.jsp.core.internal.text.StructuredTextPartitionerForJSP)1 StructuredTextPartitionerForHTML (org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML)1 IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)1 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1