Example usage for org.springframework.util.xml DomUtils getTextValue

List of usage examples for org.springframework.util.xml DomUtils getTextValue

Introduction

In this page you can find the example usage for org.springframework.util.xml DomUtils getTextValue.

Prototype

public static String getTextValue(Element valueEle) 

Source Link

Document

Extracts the text value from the given DOM element, ignoring XML comments.

Usage

From source file:org.eobjects.datacleaner.monitor.pentaho.PentahoJobEngine.java

/**
 * Fires the HTTP request to the Carte server to get the updated status of
 * the execution/*from   ww w . j a v  a 2 s  .co  m*/
 * 
 * @param carteClient
 * @param pentahoJobType
 * @param executionLogger
 * @param execution
 * @param progressUpdate
 * @return
 * @throws Exception
 */
private boolean transStatus(PentahoCarteClient carteClient, PentahoJobType pentahoJobType,
        ExecutionLogger executionLogger, TenantContext tenantContext, ExecutionLog execution,
        boolean progressUpdate) throws Exception {
    final String transStatusUrl = carteClient.getUrl("transStatus");
    final HttpGet request = new HttpGet(transStatusUrl);
    try {
        final HttpResponse response = carteClient.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            final Document doc = carteClient.parse(response.getEntity());
            final Element webresultElement = doc.getDocumentElement();

            final String statusDescription = DomUtils
                    .getTextValue(DomUtils.getChildElementByTagName(webresultElement, "status_desc"));
            if ("Running".equalsIgnoreCase(statusDescription)) {
                // the job is still running

                if (progressUpdate) {
                    logTransStatus("progress", pentahoJobType, executionLogger, doc);
                }

                return true;
            } else if ("Waiting".equalsIgnoreCase(statusDescription)) {
                // the job has finished - serialize and return succesfully

                logTransStatus("finished", pentahoJobType, executionLogger, doc);

                final String documentString = createDocumentString(doc);
                final PentahoJobResult result = new PentahoJobResult(documentString);

                executionLogger.setStatusSuccess(result);
                return false;
            } else if ("Paused".equalsIgnoreCase(statusDescription)) {
                executionLogger.setStatusFailed(null, transStatusUrl,
                        new PentahoJobException("The transformation was paused by a third-party actor"));
                return false;
            } else {
                executionLogger.setStatusFailed(null, transStatusUrl, new PentahoJobException(
                        "Encountered unexpected status_desc from Carte when updating transformation status: "
                                + statusDescription));
                return false;
            }
        } else {
            String responseString = EntityUtils.toString(response.getEntity());
            executionLogger.log(responseString);
            executionLogger.setStatusFailed(null, transStatusUrl, new PentahoJobException(
                    "Unexpected response status when updating transformation status: " + statusCode));
            return false;
        }
    } finally {
        request.releaseConnection();
    }
}

From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse the <code>class</code> XML elements.
 *///  w  ww.  j  a  v a 2  s  .c o  m
@SuppressWarnings("unchecked")
protected void parseClass(Element persistenceUnit, MySpringPersistenceUnitInfo unitInfo) {
    List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME);
    for (Element element : classes) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value))
            unitInfo.addManagedClassName(value);
    }
}

From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java

/**
 * Parse the <code>class</code> XML elements.
 *//*from   w  ww.j av  a 2  s.co  m*/
@SuppressWarnings("unchecked")
protected void parseManagedClasses(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) {
    List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME);
    for (Element element : classes) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value))
            unitInfo.addManagedClassName(value);
    }
}

From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse the <code>jar-file</code> XML elements.
 *///  w  ww .  j a  v a  2s.co m
@SuppressWarnings("unchecked")
protected void parseJarFiles(Element persistenceUnit, MySpringPersistenceUnitInfo unitInfo) throws IOException {
    List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL);
    for (Element element : jars) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value)) {
            Resource[] resources = this.resourcePatternResolver.getResources(value);
            for (Resource resource : resources) {
                unitInfo.addJarFileUrl(resource.getURL());
            }
        }
    }
}

From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java

/**
 * Parse the <code>jar-file</code> XML elements.
 *//*w ww  .j  av a 2 s  .c  o m*/
@SuppressWarnings("unchecked")
protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException {
    List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL);
    for (Element element : jars) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value)) {
            Resource[] resources = this.resourcePatternResolver.getResources(value);
            boolean found = false;
            for (Resource resource : resources) {
                if (resource.exists()) {
                    found = true;
                    unitInfo.addJarFileUrl(resource.getURL());
                }
            }
            if (!found) {
                // relative to the persistence unit root, according to the JPA spec
                URL rootUrl = unitInfo.getPersistenceUnitRootUrl();
                if (rootUrl != null) {
                    unitInfo.addJarFileUrl(new URL(rootUrl, value));
                } else {
                    logger.warn("Cannot resolve jar-file entry [" + value + "] in persistence unit '"
                            + unitInfo.getPersistenceUnitName() + "' without root URL");
                }
            }
        }
    }
}

From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse the <code>mapping-file</code> XML elements.
 *//* w w  w  . j  a va 2 s. c o m*/
@SuppressWarnings("unchecked")
protected void parseMappingFiles(Element persistenceUnit, MySpringPersistenceUnitInfo unitInfo) {
    List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME);
    for (Element element : files) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value)) {
            unitInfo.addMappingFileName(value);
        }
    }
}

From source file:com.apdplat.platform.spring.APDPlatPersistenceUnitReader.java

/**
 * Parse the <code>class</code> XML elements.
 *//* w w  w . ja  va  2 s .c  o m*/
@SuppressWarnings("unchecked")
protected void parseClass(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) {
    List<Element> classes = DomUtils.getChildElementsByTagName(persistenceUnit, MANAGED_CLASS_NAME);
    for (Element element : classes) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value))
            unitInfo.addManagedClassName(value);
    }
}

From source file:com.apdplat.platform.spring.APDPlatPersistenceUnitReader.java

/**
 * Parse the <code>jar-file</code> XML elements.
 *///w  ww  .  j a v a  2 s .  c  om
@SuppressWarnings("unchecked")
protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) throws IOException {
    List<Element> jars = DomUtils.getChildElementsByTagName(persistenceUnit, JAR_FILE_URL);
    for (Element element : jars) {
        logger.info(
                "apdplatspring jpa2(2. Start to execute custom modifications  of APDPlat for Spring JPA )");
        String jarHolder = DomUtils.getTextValue(element).trim();
        if (jarHolder == null || "".equals(jarHolder.trim())) {
            continue;
        }
        logger.info("??(Content of placeholder is): " + jarHolder);
        //${}??
        String realJars = PropertyHolder.getProperty(jarHolder.substring(2, jarHolder.length() - 1));
        logger.info(
                "???(Content of config file related to placeholder is): "
                        + realJars);
        String[] jarArray = realJars.split(",");
        for (String jar : jarArray) {
            if (StringUtils.hasText(jar)) {
                FileSystemResource resource = new FileSystemResource(FileUtils.getAbsolutePath(jar));
                unitInfo.addJarFileUrl(resource.getURL());
            }
        }
    }
}

From source file:org.eobjects.datacleaner.monitor.pentaho.PentahoJobEngine.java

/**
 * Fires the HTTP request to Carte to start processing the transformation.
 * /*from  w w w .  j a  va  2 s.  co  m*/
 * @param carteClient
 * @param pentahoJobType
 * @param executionLogger
 * @return
 * @throws Exception
 */
private boolean startTrans(PentahoCarteClient carteClient, PentahoJobType pentahoJobType,
        ExecutionLogger executionLogger) throws Exception {
    final String startTransUrl = carteClient.getUrl("startTrans");
    final HttpGet request = new HttpGet(startTransUrl);
    try {
        final HttpResponse response = carteClient.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            final Document doc = carteClient.parse(response.getEntity());
            final Element webresultElement = doc.getDocumentElement();

            final String message = DomUtils
                    .getTextValue(DomUtils.getChildElementByTagName(webresultElement, "message"));
            if (!StringUtils.isNullOrEmpty(message)) {
                executionLogger.log(message);
            }
            final String result = DomUtils
                    .getTextValue(DomUtils.getChildElementByTagName(webresultElement, "result"));
            if ("OK".equalsIgnoreCase(result)) {
                executionLogger.setStatusRunning();
                executionLogger.flushLog();
                return true;
            } else if ("ERROR".equalsIgnoreCase(result)) {
                executionLogger.setStatusFailed(null, startTransUrl, new PentahoJobException(
                        "The Carte service reported an 'ERROR' result when starting transformation"));
                return false;
            } else {
                executionLogger.setStatusFailed(null, startTransUrl, new PentahoJobException(
                        "Encountered unexpected result from Carte when starting transformation: " + result));
                return false;
            }
        } else {
            String responseString = EntityUtils.toString(response.getEntity());
            executionLogger.log(responseString);
            executionLogger.setStatusFailed(null, startTransUrl, new PentahoJobException(
                    "Unexpected response status when starting transformation: " + statusCode));
            return false;
        }
    } finally {
        request.releaseConnection();
    }
}

From source file:com.apdplat.platform.spring.APDPlatPersistenceUnitReader.java

/**
 * Parse the <code>mapping-file</code> XML elements.
 *///  ww  w .j av a2 s.com
@SuppressWarnings("unchecked")
protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) {
    List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME);
    for (Element element : files) {
        String value = DomUtils.getTextValue(element).trim();
        if (StringUtils.hasText(value)) {
            unitInfo.addMappingFileName(value);
        }
    }
}