Search in sources :

Example 26 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveMultipleNode.

@Test
public void testResolveMultipleNode() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    NodeList nodelist = XpathQueryHelper.resolveNodeList(doc, xpathToUse, "//extra", false);
    assertNotNull(nodelist);
    assertEquals(3, nodelist.getLength());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) NodeList(org.w3c.dom.NodeList) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 27 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveSingleTextItem.

@Test
public void testResolveSingleTextItem() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    assertNotNull(XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//source-id", false));
    assertEquals("partnera", XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//source-id", false));
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 28 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class JdbcIteratingDataCaptureServiceImpl method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    log.trace("Beginning doService in {}", LoggingHelper.friendlyName(this));
    Connection conn = null;
    NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    try {
        DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
        XPath xpath = XPath.newXPathInstance(builder, namespaceCtx);
        conn = configureActor(msg).getSqlConnection();
        Document doc = createDocument(namespaceCtx, msg);
        NodeList nodes = nodesToProcess(doc, xpath);
        log.debug("Iterating {} times for statement [{}]", nodes.getLength(), getStatement());
        PreparedStatement insert = actor.getInsertStatement(msg);
        insert.clearParameters();
        long rowsUpdated = 0;
        for (int i = 0; i < nodes.getLength(); i++) {
            log.trace("---Start Iteration {}", i);
            Node n = nodes.item(i);
            getParameterApplicator().applyStatementParameters(msg, insert, createActualParams(xpath, n), getStatement());
            rowsUpdated += executeUpdate(insert);
            log.trace("---End Iteration {}", i);
        }
        rowsUpdated += finishUpdate(insert);
        // Will only store the generated keys from the last query
        saveKeys(msg, insert);
        JdbcUtil.commit(conn, msg);
        updateMetadata(msg, rowsUpdated);
    } catch (Exception e) {
        JdbcUtil.rollback(conn, msg);
        throw ExceptionHelper.wrapServiceException(e);
    } finally {
        JdbcUtil.closeQuietly(conn);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Connection(java.sql.Connection) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) PreparedStatement(java.sql.PreparedStatement) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SQLException(java.sql.SQLException) CoreException(com.adaptris.core.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 29 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class JdbcDataQueryService method initXmlHelper.

private void initXmlHelper(AdaptrisMessage msg) throws CoreException {
    NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
    if (namespaceCtx != null) {
        builder = builder.withNamespaceAware(true);
    }
    msg.getObjectHeaders().put(KEY_DOCBUILDER_FAC, builder);
    if (containsXpath(getStatementParameters())) {
        msg.getObjectHeaders().put(KEY_XML_UTILS, XmlHelper.createXmlUtils(msg, namespaceCtx, builder));
    }
    if (namespaceCtx != null) {
        msg.getObjectHeaders().put(KEY_NAMESPACE_CTX, namespaceCtx);
    }
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder)

Example 30 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XmlValidationServiceTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    ValidationStage vs = new ValidationStage();
    vs.setIterationXpath("/document/names");
    vs.setElementXpath("fullName");
    vs.addRule(new NotNullContentValidation());
    KeyValuePair disableExternalEntities = new KeyValuePair("http://xml.org/sax/features/external-general-entities", "false");
    KeyValuePair disableDoctypeDecl = new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true");
    return new XmlValidationService(new XmlBasicValidator(new DocumentBuilderFactoryBuilder().withNamespaceAware(true).withFeatures(new KeyValuePairSet(Arrays.asList(disableExternalEntities, disableDoctypeDecl)))), new BasicXmlSchemaValidator().withSchema("http://host/schema.xsd or %message{metadatKey}"), new XmlRuleValidator(vs));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) NotNullContentValidation(com.adaptris.transform.validate.NotNullContentValidation) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) ValidationStage(com.adaptris.transform.validate.ValidationStage)

Aggregations

DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)32 XPath (com.adaptris.util.text.xml.XPath)21 Document (org.w3c.dom.Document)21 Test (org.junit.Test)18 NamespaceContext (javax.xml.namespace.NamespaceContext)12 CoreException (com.adaptris.core.CoreException)10 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)10 ServiceException (com.adaptris.core.ServiceException)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 KeyValuePair (com.adaptris.util.KeyValuePair)4 NodeList (org.w3c.dom.NodeList)4 XpathQuery (com.adaptris.core.services.metadata.xpath.XpathQuery)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Node (org.w3c.dom.Node)3 XpathMetadataServiceTest (com.adaptris.core.services.metadata.XpathMetadataServiceTest)2 ConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery)2 MetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MetadataXpathQuery)2 MultiItemConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)2 MultiItemMetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery)2 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)2