List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:org.openadaptor.auxil.connector.jms.JMSPropertiesMessageGeneratorTestCase.java
License:Open Source License
/** * Ensure that a Dom4j Document can be used. *//*from w w w . j a v a2s . c o m*/ public void testSendDocument() { Document doc = null; try { doc = DocumentHelper.parseText(messageText); } catch (DocumentException e) { fail("Test text isn't valid xml"); } Mock sessionMock = new Mock(Session.class); Mock textMessageMock = new Mock(TextMessage.class); TextMessage message = (TextMessage) textMessageMock.proxy(); sessionMock.expects(once()).method("createTextMessage").will(returnValue(message)); textMessageMock.expects(once()).method("setText").with(eq(doc.asXML())); Message generatedMessage = null; try { generatedMessage = testInstance.createMessage(doc, (Session) sessionMock.proxy()); } catch (JMSException e) { fail("Unexpected JMSException: " + e); } assertEquals("Didn't return the expected TextMessage.", message, generatedMessage); }
From source file:org.openadaptor.auxil.convertor.map.DocumentMapFacadeTestCase.java
License:Open Source License
protected static Document generateDocument(int index) { try {//from w w w . j a v a2 s . com return DocumentHelper.parseText(XML[index]); } catch (DocumentException de) { fail(de.toString()); return null; } }
From source file:org.openadaptor.auxil.convertor.map.Dom4JDocumentMapFacadeTestCase.java
License:Open Source License
protected static Document generateDocument(String text) { try {// w w w. jav a 2s.co m return DocumentHelper.parseText(text); } catch (DocumentException de) { fail(de.toString()); return null; } }
From source file:org.openadaptor.auxil.convertor.xml.AbstractTestXmlConvertor.java
License:Open Source License
protected static Document generateXmlDocument(String xml) { Document document = null;//w ww . j ava2 s.c om try { return (DocumentHelper.parseText(xml)); } catch (DocumentException de) { fail("Unit test problem - " + de.toString()); } return document; }
From source file:org.openadaptor.auxil.processor.xml.XsltProcessor.java
License:Open Source License
/** * Use the XML supplied to create a DOM document * /*from w w w .jav a2 s. c om*/ * @param xml * valid XML * * @return dom4j document object * * @throws ProcessingException * if the supplied XML cannot be parsed */ private Document createDOMFromString(String xml) { try { return DocumentHelper.parseText(xml); } catch (DocumentException e) { throw new ProcessingException("Failed to parse XML: " + e.getMessage(), this); } }
From source file:org.openadaptor.thirdparty.dom4j.Dom4jUtils.java
License:Open Source License
/** * This will parse an XML String into a Dom4j Document. If it fails it will throw a RecordFormatException * //from w w w .ja va 2s . c o m * @param xmlString * An XML document as a String * @return Dom4j document representing the XML. */ private static Document createDom4jDocument(String xmlString) throws RecordFormatException { try { log.debug("Parsing XML string into dom4j document"); if (xmlString != null) { xmlString = xmlString.trim(); } return (DocumentHelper.parseText(xmlString)); } catch (DocumentException de) { throw new RecordFormatException(de.toString(), de); } }
From source file:org.openbravo.dal.xml.XMLEntityConverter.java
License:Open Source License
/** * The main entry point. This method creates a Dom4j Document and then calls * {@link #process(Document)}./* w ww . j av a 2s.c o m*/ * * @param xml * the xml string * @return the list of BaseOBObject present in the root of the xml. This list contains the * to-be-updated, to-be-inserted as well as the unchanged business objects */ public List<BaseOBObject> process(String xml) { try { final Document doc = DocumentHelper.parseText(xml); final List<BaseOBObject> result = process(doc); return result; } catch (final Exception e) { throw new EntityXMLException(e); } }
From source file:org.openbravo.service.db.DataImportService.java
License:Open Source License
/** * Imports the business objects using the client/organization. If there are no error messages and * no Exception occurred then the import method will persist the imported business objects. * However, the import method does not do a commit. It is the callers responsibility to call * commit (if the ImportResult does not contain error messages). * /*from w w w .j a v a 2s . c o m*/ * @param client * the client in which the import takes place * @param organization * the organization in which the business objects are created * @param xml * the xml containing the data * @param module * the module is used to update the AD_REF_DATA_LOADED table during the import action * @return the result of the import (error, log and warning messages, to-be-inserted and * to-be-updated business objects */ public ImportResult importDataFromXML(Client client, Organization organization, String xml, Module module, boolean filterOrganizations) { try { final Document doc = DocumentHelper.parseText(xml); return importDataFromXML(client, organization, doc, true, module, null, false, false, filterOrganizations); } catch (final Exception e) { throw new OBException(e); } }
From source file:org.openbravo.service.web.WebServiceUtil.java
License:Open Source License
/** * Applies an XSLT template on the XML in the sourceDocument. The resulting Dom4j Document is * returned./*from w w w . ja v a 2s. c o m*/ * * @param xml * the source xml * @param template * the XSLT template * @return the resulting XML */ public String applyTemplate(String xml, InputStream template, String url) { try { boolean hasId; // This regular expression has been created to find out if there is an id after // the entity name in the url. For example: // https://livebuilds.openbravo.com/erp_main_pgsql/ws/dal/ADUser/100 String regExp = "^(.*)[dal]+[\\/][A-Za-z0-9]+[\\/][A-Za-z0-9]+"; final TransformerFactory factory = TransformerFactory.newInstance(); final Transformer transformer = factory.newTransformer(new StreamSource(template)); final DocumentSource source = new DocumentSource(DocumentHelper.parseText(xml)); final StringWriter sw = new StringWriter(); final StreamResult response = new StreamResult(sw); if (url.matches(regExp)) { hasId = true; } else { hasId = false; } transformer.setParameter("hasId", hasId); transformer.setParameter("url", url); transformer.transform(source, response); return sw.toString(); } catch (final Exception e) { throw new OBException(e); } }
From source file:org.opendaylight.releng.autorelease.autonotes.service.ProjectService.java
License:Open Source License
/** * Load the project active state based on inclusion in auto-release *///from w ww . j a v a 2 s . co m @SuppressWarnings("rawtypes") private void loadStates() { LogUtils.step("Start loading project state"); InputStream input = null; try { input = new URL(this.controller.getPropertyService().getProperties().getProperty(ACTIVE_PROJECT_LIST)) .openStream(); String activeProjectString = IOUtils.toString(input); Document document = DocumentHelper.parseText(activeProjectString); Element root = document.getRootElement(); Element modules = root.element("modules"); for (Iterator i = modules.elementIterator("module"); i.hasNext();) { Element module = (Element) i.next(); String projectName = module.getText(); this.projects.get(projectName).setActive(true); } } catch (Exception e) { LogUtils.log(e); } finally { if (input != null) { try { IOUtils.closeQuietly(input); } catch (Exception e) { LogUtils.log(e); } } } LogUtils.step("Completed loading project state"); }