Search in sources :

Example 41 with SAXReader

use of org.dom4j.io.SAXReader 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 42 with SAXReader

use of org.dom4j.io.SAXReader 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)

Example 43 with SAXReader

use of org.dom4j.io.SAXReader in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method appendRawXml.

/**
   * Append raw XML configuration. 
   */
private void appendRawXml(PlexusConfiguration config, Element elem) {
    try {
        if (config == null) {
            return;
        }
        StringWriter writer = new StringWriter();
        AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
        xmlWriter.write(config, writer);
        Element root = new SAXReader().read(new StringReader(writer.toString())).getRootElement();
        root.detach();
        elem.add(root);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StringWriter(java.io.StringWriter) AntrunXmlPlexusConfigurationWriter(org.apache.maven.plugin.antrun.AntrunXmlPlexusConfigurationWriter) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 44 with SAXReader

use of org.dom4j.io.SAXReader in project hudson-2.x by hudson.

the class SuiteResult method parse.

/**
     * Parses the JUnit XML file into {@link SuiteResult}s.
     * This method returns a collection, as a single XML may have multiple &lt;testsuite>
     * elements wrapped into the top-level &lt;testsuites>.
     */
static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException {
    List<SuiteResult> r = new ArrayList<SuiteResult>();
    // parse into DOM
    SAXReader saxReader = new SAXReader();
    // install EntityResolver for resolving DTDs, which are in files created by TestNG.
    XMLEntityResolver resolver = new XMLEntityResolver();
    saxReader.setEntityResolver(resolver);
    Document result = saxReader.read(xmlReport);
    Element root = result.getRootElement();
    getTestSuites(root, r, xmlReport, keepLongStdio);
    return r;
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document)

Example 45 with SAXReader

use of org.dom4j.io.SAXReader in project Openfire by igniterealtime.

the class CrowdVCardProvider method loadVCard.

/**
	 * @see org.jivesoftware.openfire.vcard.DefaultVCardProvider#loadVCard(java.lang.String)
	 */
@Override
public Element loadVCard(String username) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("loadvcard:" + username);
    }
    if (MUTEX.containsKey(username)) {
        // preventing looping
        return null;
    }
    try {
        MUTEX.put(username, username);
        Element vcard = super.loadVCard(username);
        if (vcard == null) {
            CrowdUserProvider userProvider = (CrowdUserProvider) UserManager.getUserProvider();
            try {
                User user = userProvider.getCrowdUser(username);
                String str = VCARD_TEMPLATE.replace("@displayname@", user.displayName).replace("@lastname@", user.lastName).replace("@firstname@", user.firstName).replace("@email@", user.email).replace("@nickname@", username);
                SAXReader xmlReader = new SAXReader();
                xmlReader.setEncoding("UTF-8");
                vcard = xmlReader.read(new StringReader(str)).getRootElement();
            } catch (UserNotFoundException unfe) {
                LOG.error("Unable to find user:" + String.valueOf(username) + " for loading its vcard", unfe);
                return null;
            } catch (DocumentException de) {
                LOG.error("vcard parsing error", de);
                return null;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(vcard != null ? vcard.asXML() : "vcard is null");
            }
            // store this new vcard
            if (vcard != null) {
                try {
                    createVCard(username, vcard);
                } catch (AlreadyExistsException aee) {
                    LOG.error("Unable to create and store a new vcard for user:" + username + "; one already exists", aee);
                }
            }
        }
        return vcard;
    } catch (RuntimeException re) {
        LOG.error("Failure occured when loading a vcard for user:" + username, re);
        throw re;
    } finally {
        MUTEX.remove(username);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.crowd.jaxb.User) AlreadyExistsException(org.jivesoftware.util.AlreadyExistsException) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader)

Aggregations

SAXReader (org.dom4j.io.SAXReader)173 Document (org.dom4j.Document)143 Element (org.dom4j.Element)128 StringReader (java.io.StringReader)98 Test (org.junit.Test)78 ArrayList (java.util.ArrayList)35 List (java.util.List)35 File (java.io.File)28 DocumentException (org.dom4j.DocumentException)21 IOException (java.io.IOException)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Node (org.dom4j.Node)14 HashMap (java.util.HashMap)12 Map (java.util.Map)10 Attribute (org.dom4j.Attribute)10 InputStream (java.io.InputStream)9 XMLWriter (org.dom4j.io.XMLWriter)9 OutputFormat (org.dom4j.io.OutputFormat)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6