Search in sources :

Example 51 with Document

use of org.dom4j.Document in project spring-framework by spring-projects.

the class CheckboxTagTests method withSingleValueNotNull.

@Test
public void withSingleValueNotNull() throws Exception {
    this.bean.setName("Rob Harrop");
    this.tag.setPath("name");
    this.tag.setValue("Rob Harrop");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    // wrap the output so it is valid XML
    output = "<doc>" + output + "</doc>";
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element checkboxElement = (Element) document.getRootElement().elements().get(0);
    assertEquals("input", checkboxElement.getName());
    assertEquals("checkbox", checkboxElement.attribute("type").getValue());
    assertEquals("name", checkboxElement.attribute("name").getValue());
    assertEquals("checked", checkboxElement.attribute("checked").getValue());
    assertEquals("Rob Harrop", checkboxElement.attribute("value").getValue());
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Test(org.junit.Test)

Example 52 with Document

use of org.dom4j.Document in project spring-framework by spring-projects.

the class CheckboxTagTests method withObjectChecked.

@Test
public void withObjectChecked() throws Exception {
    this.tag.setPath("date");
    this.tag.setValue(getDate());
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    // wrap the output so it is valid XML
    output = "<doc>" + output + "</doc>";
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element checkboxElement = (Element) document.getRootElement().elements().get(0);
    assertEquals("input", checkboxElement.getName());
    assertEquals("checkbox", checkboxElement.attribute("type").getValue());
    assertEquals("date", checkboxElement.attribute("name").getValue());
    assertEquals("checked", checkboxElement.attribute("checked").getValue());
    assertEquals(getDate().toString(), checkboxElement.attribute("value").getValue());
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Test(org.junit.Test)

Example 53 with Document

use of org.dom4j.Document in project spring-framework by spring-projects.

the class CheckboxTagTests method collectionOfPetsAsString.

@Test
public void collectionOfPetsAsString() throws Exception {
    this.tag.setPath("pets");
    this.tag.setValue("Spot");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    // wrap the output so it is valid XML
    output = "<doc>" + output + "</doc>";
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element checkboxElement = (Element) document.getRootElement().elements().get(0);
    assertEquals("input", checkboxElement.getName());
    assertEquals("checkbox", checkboxElement.attribute("type").getValue());
    assertEquals("pets", checkboxElement.attribute("name").getValue());
    assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Test(org.junit.Test)

Example 54 with Document

use of org.dom4j.Document in project spring-framework by spring-projects.

the class CheckboxTagTests method collectionOfPetsWithEditor.

@Test
public void collectionOfPetsWithEditor() throws Exception {
    this.tag.setPath("pets");
    this.tag.setValue(new ItemPet("Rudiger"));
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    PropertyEditorSupport editor = new ItemPet.CustomEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(ItemPet.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    // wrap the output so it is valid XML
    output = "<doc>" + output + "</doc>";
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element checkboxElement = (Element) document.getRootElement().elements().get(0);
    assertEquals("input", checkboxElement.getName());
    assertEquals("checkbox", checkboxElement.attribute("type").getValue());
    assertEquals("pets", checkboxElement.attribute("name").getValue());
    assertEquals("Rudiger", checkboxElement.attribute("value").getValue());
    assertEquals("checked", checkboxElement.attribute("checked").getValue());
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) PropertyEditorSupport(java.beans.PropertyEditorSupport) Test(org.junit.Test)

Example 55 with Document

use of org.dom4j.Document in project spring-framework by spring-projects.

the class XsltViewTests method assertHtmlOutput.

@SuppressWarnings("rawtypes")
private void assertHtmlOutput(String output) throws Exception {
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    List nodes = document.getRootElement().selectNodes("/html/body/table/tr");
    Element tr1 = (Element) nodes.get(0);
    assertRowElement(tr1, "1", "Whatsit", "12.99");
    Element tr2 = (Element) nodes.get(1);
    assertRowElement(tr2, "2", "Thingy", "13.99");
    Element tr3 = (Element) nodes.get(2);
    assertRowElement(tr3, "3", "Gizmo", "14.99");
    Element tr4 = (Element) nodes.get(3);
    assertRowElement(tr4, "4", "Cranktoggle", "11.99");
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) List(java.util.List) Document(org.dom4j.Document)

Aggregations

Document (org.dom4j.Document)288 Element (org.dom4j.Element)192 SAXReader (org.dom4j.io.SAXReader)143 Test (org.junit.Test)102 StringReader (java.io.StringReader)88 File (java.io.File)57 ArrayList (java.util.ArrayList)47 List (java.util.List)40 IOException (java.io.IOException)27 DocumentException (org.dom4j.DocumentException)25 XMLWriter (org.dom4j.io.XMLWriter)22 HashMap (java.util.HashMap)19 Map (java.util.Map)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Attribute (org.dom4j.Attribute)15 Node (org.dom4j.Node)14 FileOutputStream (java.io.FileOutputStream)11 DavException (com.zimbra.cs.dav.DavException)10 OutputFormat (org.dom4j.io.OutputFormat)9