Search in sources :

Example 6 with DOMModelImpl

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

the class DOMImplementationTests method testCreateDocumentIllegalNamespace.

public void testCreateDocumentIllegalNamespace() {
    final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    try {
        model.createDocument(null, "foo:bar", null);
    } catch (DOMException e) {
        assertEquals("Did not receive the correct DOMException", DOMException.NAMESPACE_ERR, e.code);
        return;
    }
    fail("No exceptions for illegal input");
}
Also used : DOMException(org.w3c.dom.DOMException) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl)

Example 7 with DOMModelImpl

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

the class DOMImplementationTests method testCreateDocumentNoDocumentType.

public void testCreateDocumentNoDocumentType() {
    final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    final Document document = model.createDocument("http://eclipse.org", "foo:bar", null);
    final Node node = document.getFirstChild();
    assertNotNull("Document should not be empty", node);
    assertEquals("Element qualified name is not equal", "foo:bar", node.getNodeName());
    assertEquals("Element namespace URI is not equal", "http://eclipse.org", node.getNamespaceURI());
}
Also used : Node(org.w3c.dom.Node) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 8 with DOMModelImpl

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

the class DOMImplementationTests method testCreateDocumentNamespaceWithNoQualifiedName.

public void testCreateDocumentNamespaceWithNoQualifiedName() {
    final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    try {
        model.createDocument("http://eclipse.org", null, null);
    } catch (DOMException e) {
        assertEquals("Did not receive the correct DOMException", DOMException.NAMESPACE_ERR, e.code);
        return;
    }
    fail("No exceptions for illegal input");
}
Also used : DOMException(org.w3c.dom.DOMException) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl)

Example 9 with DOMModelImpl

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

the class DOMImplementationTests method testCreateDocumentEmpty.

public void testCreateDocumentEmpty() {
    final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    final Document document = model.createDocument(null, null, null);
    assertNull("The document should be empty", document.getFirstChild());
}
Also used : DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 10 with DOMModelImpl

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

the class StructuredDocumentToDOMUnitTests method testNodeDeletion4.

/**
 * Unit test -- test insert followed by delete at beginning of string.
 */
void testNodeDeletion4() {
    String initialString = getTestString4();
    // print out what we always can
    System.out.println();
    System.out.println("----------------");
    System.out.println("Test Node Insert and Delete");
    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());
    // 
    // 
    f.replaceText(null, 0, 0, "a");
    System.out.println(" ==== Results after insert");
    // 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());
    // 
    f.replaceText(null, 0, 1, "");
    System.out.println(" ==== Results after delete");
    // 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)

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