Search in sources :

Example 66 with IDOMModel

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

the class AttrValueTest method testModel.

/* (non-Javadoc)
	 * @see org.eclipse.wst.html.core.tests.parser.ModelTest#testModel()
	 */
public void testModel() {
    IDOMModel model = createHTMLModel();
    try {
        assertNotNull(model);
        IStructuredDocument document = model.getStructuredDocument();
        assertNotNull(document);
        document.setText(this, "<button value=\"" + VALUES[0] + "\"></button><button value=\"" + VALUES[1] + "\"></button><button value=\"" + VALUES[2] + "\"></button>");
        IDOMDocument dom = model.getDocument();
        NodeList nodes = dom.getElementsByTagName("button");
        assertTrue("Must be 3 button elements in the document.", nodes.getLength() == 3);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            Node attr = node.getAttributes().getNamedItem("value");
            assertTrue("Attribute 'value' not present.", attr != null && attr.getNodeValue().length() > 0);
            assertEquals("Attribute values are not equal", VALUES[i], attr.getNodeValue());
        }
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 67 with IDOMModel

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

the class CDATASectionTest2 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Element a = document.createElement("a");
        document.appendChild(a);
        CDATASection cdata = document.createCDATASection("contentOfCDATASection");
        a.appendChild(cdata);
        printSource(model);
        printTree(model);
        fOutputWriter.writeln(cdata.getData());
        cdata.setData("new content");
        printSource(model);
        printTree(model);
        fOutputWriter.writeln(cdata.getData());
        cdata.setData("new content");
        printSource(model);
        printTree(model);
        fOutputWriter.writeln(cdata.getData());
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : CDATASection(org.w3c.dom.CDATASection) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 68 with IDOMModel

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

the class EleTest method testModel.

public void testModel() {
    IDOMModel model = createHTMLModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        Document document = model.getDocument();
        structuredDocument.replaceText(null, 0, 0, "<html><body><DL>\n\n<DD>Add a \"set top\" rule for the specified parameters1.\n<DD>Add a \"set top\" rule for the specified parameters2.\n<DD>Add a \"set top\" rule for the specified parameters3.\n<DD>Add a \"set top\" rule for the specified parameters4.\n<DD>Add a \"set top\" rule for the specified parameters5.\n<DD>Add a \"set top\" rule for the specified parameters6.\n<DD>Add a \"set top\" rule for the specified parameters7.\n<DD>Add a \"set top\" rule for the specified parameters8.\n<DD>Add a \"set top\" rule for the specified parameters9.\n<DD>Add a \"set top\" rule for the specified parameters10.\n<DD>Add a \"set top\" rule for the specified parameters11.\n<DD>Add a \"set top\" rule for the specified parameters12.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n<DD>Add a \"set top\" rule for the specified parameters.\n</DL></body></html>");
        Node a = document.getElementsByTagName("DL").item(0);
        System.out.println(((Element) a).getElementsByTagName("DD").getLength());
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 69 with IDOMModel

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

the class ElementTest2 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Element a = document.createElement("a");
        Element b = document.createElement("b");
        Text t = document.createTextNode("c");
        document.appendChild(a);
        a.appendChild(b);
        b.appendChild(t);
        printSource(model);
        printTree(model);
        a.setPrefix("x");
        fOutputWriter.writeln("a.tagName=" + a.getTagName());
        printSource(model);
        printTree(model);
        b.setPrefix("y");
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 70 with IDOMModel

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

the class EmptyTextTest3 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Text text = document.createTextNode("");
        document.appendChild(text);
        printSource(model);
        printTree(model);
        Element a = document.createElement("a");
        document.insertBefore(a, text);
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25