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());
}
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");
}
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);
}
}
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 <testsuite>
* elements wrapped into the top-level <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;
}
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);
}
}
Aggregations