Example usage for org.apache.commons.jxpath JXPathContext setLenient

List of usage examples for org.apache.commons.jxpath JXPathContext setLenient

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext setLenient.

Prototype

public synchronized void setLenient(boolean lenient) 

Source Link

Document

If the context is in the lenient mode, then getValue() returns null for inexistent paths.

Usage

From source file:jp.go.nict.langrid.commons.jxpath.BPELUtil.java

/**
 * //  w  ww  . j a va 2s. co  m
 * 
 */
public static JXPathContext newBPELContext(InputStream bpel, String bpelNSPrefix)
        throws IOException, SAXException {
    JXPathContext context = JXPathUtil.newXMLContext(bpel);
    context.setLenient(true);
    context.registerNamespace(bpelNSPrefix, Constants.BPEL_URI);
    return context;
}

From source file:jp.go.nict.langrid.commons.jxpath.BPELUtil.java

/**
 * //  w  w w  . jav  a 2s  . c o m
 * 
 */
public static JXPathContext newWSBPEL_2_0_Context(InputStream bpel, String bpelNSPrefix)
        throws IOException, SAXException {
    JXPathContext context = JXPathUtil.newXMLContext(bpel);
    context.setLenient(true);
    context.registerNamespace(bpelNSPrefix, Constants.WSBPEL_2_0_URI);
    return context;
}

From source file:jp.go.nict.langrid.commons.jxpath.WSDLUtil.java

/**
 * //from  w  w  w .  j a  v a2s . c o  m
 * 
 */
public static JXPathContext newWSDLContext(InputStream wsdl, String wsdlNSPrefix)
        throws IOException, SAXException {
    JXPathContext context = JXPathUtil.newXMLContext(wsdl);
    context.setLenient(true);
    context.registerNamespace(wsdlNSPrefix, Constants.WSDL_URI);
    return context;
}

From source file:jp.go.nict.langrid.bpel.deploy.BPRDeployer.java

/**
 * /*  w w w .  ja v a 2s .  c  o  m*/
 * 
 */
static DeploymentResult parseResult(String aResult) throws SAXException, IOException {
    DeploymentResult result = new DeploymentResult();
    result.setSourceString(aResult);

    JXPathContext context = JXPathUtil.newXMLContext(aResult);
    context.setLenient(true);

    JXPathContext summary = JXPathContext.newContext(context,
            context.getPointer("/deploymentSummary").getNode());
    result.setSummaryErrorCount(Integer.parseInt(summary.getValue("/@numErrors").toString()));
    result.setSummaryWarningCount(Integer.parseInt(summary.getValue("/@numWarnings").toString()));
    result.setSummaryMessages(summary.getValue("/globalMessages").toString());

    summary.setLenient(true);
    Node deploymentInfoNode = (Node) summary.getPointer("/deploymentInfo").getNode();
    if (deploymentInfoNode != null) {
        JXPathContext info = JXPathContext.newContext(summary, deploymentInfoNode);
        result.setDeploymentErrorCount(Integer.parseInt(info.getValue("/@numErrors").toString()));
        result.setDeploymentWarningCount(Integer.parseInt(info.getValue("/@numWarnings").toString()));
        result.setDeployed(Boolean.parseBoolean(info.getValue("/@deployed").toString()));
        result.setPddFilename(info.getValue("/@pddName").toString());
        result.setDeploymentLog(info.getValue("/log").toString());
    }
    return result;
}

From source file:com.ebay.jetstream.epl.EPLUtilities.java

/**
 * transformToObject - This method converts incoming JsonString to HashMap. Need/use of this method is, in EPL we need
 * to use pass Objects through window. But EPL allows primitives type alone. For that we 'll convert Obejct to
 * JsonString and pass it to the stream. After that we need to convert back the Json String to original Object type.
 * /*w w w .  jav a  2s . c  om*/
 */
@SuppressWarnings("unchecked")
public static HashMap<String, Object> transformToObjectAndRemoveKey(String jsonStr, String key)
        throws Exception {
    if (jsonStr != null) {
        ObjectMapper mapper = new ObjectMapper();
        HashMap<String, Object> event = mapper.readValue(jsonStr, HashMap.class);
        if (key != null && !key.equals("")) {
            JXPathContext context = JXPathContext.newContext(event);
            context.setLenient(true);
            context.removePath(key);
        }
        return event;
    }
    return null;
}

From source file:com.ebay.jetstream.epl.EPLUtilities.java

public static Object getAttribute(Object object, String key) {
    try {/*from   w  w w . j av a2 s . c o m*/
        Object event = object;
        if (object instanceof String) {
            ObjectMapper mapper = new ObjectMapper();
            event = mapper.readValue(object.toString(), HashMap.class);
        }
        if (event != null) {
            JXPathContext context = JXPathContext.newContext(event);
            context.setLenient(true);
            return context.getValue(key);
        }
    } catch (Exception e) { // NOPMD
        return null;
    }
    return null;
}

From source file:de.iai.ilcd.xml.read.DataSetReader.java

private DataSet parseStream(InputStream inputStream) {

    JDOMParser parser = new JDOMParser();
    parser.setValidating(false);//ww  w  . j ava  2 s. co  m
    Object doc = parser.parseXML(inputStream);
    JXPathContext context = JXPathContext.newContext(doc);
    context.setLenient(true);
    context.registerNamespace("common", "http://lca.jrc.it/ILCD/Common");

    parserHelper = new DataSetParsingHelper(context);
    commonReader = new CommonConstructsReader(parserHelper);

    return parse(context, out);
}

From source file:net.sf.oval.ogn.ObjectGraphNavigatorJXPathImpl.java

public ObjectGraphNavigationResult navigateTo(final Object root, final String xpath)
        throws InvalidConfigurationException {
    Assert.argumentNotNull("root", root);
    Assert.argumentNotNull("xpath", xpath);

    try {// ww  w  .j a  v a  2 s  .co m
        final JXPathContext ctx = JXPathContext.newContext(root);
        ctx.setLenient(true); // do not throw an exception if object graph is incomplete, e.g. contains null-values

        Pointer pointer = ctx.getPointer(xpath);

        // no match found or invalid xpath
        if (pointer instanceof NullPropertyPointer || pointer instanceof NullPointer)
            return null;

        if (pointer instanceof BeanPointer) {
            final Pointer parent = ((BeanPointer) pointer).getImmediateParentPointer();
            if (parent instanceof PropertyPointer) {
                pointer = parent;
            }
        }

        if (pointer instanceof PropertyPointer) {
            final PropertyPointer pp = (PropertyPointer) pointer;
            final Class<?> beanClass = pp.getBean().getClass();
            AccessibleObject accessor = ReflectionUtils.getField(beanClass, pp.getPropertyName());
            if (accessor == null) {
                accessor = ReflectionUtils.getGetter(beanClass, pp.getPropertyName());
            }
            return new ObjectGraphNavigationResult(root, xpath, pp.getBean(), accessor, pointer.getValue());
        }

        throw new InvalidConfigurationException("Don't know how to handle pointer [" + pointer + "] of type ["
                + pointer.getClass().getName() + "] for xpath [" + xpath + "]");
    } catch (final JXPathNotFoundException ex) {
        // thrown if the xpath is invalid
        throw new InvalidConfigurationException(ex);
    }
}

From source file:de.innovationgate.wga.server.api.Xml.java

/**
 * Executes an XPath expression on some XML text or JavaBean
 * This function always returns single values. If the xpath expression matches multiple values it will only return the first one. To retrieve lists of values use {@link #xpathList(Object, String)}.
 * The given object to parse as XML is either a dom4j branch object (mostly document or element), a String containing XML text or a JavaBean. In the last case this function uses JXPath functionality to find a bean property value.
 * This uses the Apache library JXPath under the hood. See their documentation for details how XPath is used to browser JavaBeans.
 * @param object Object to inspect//  w ww.j av a  2  s .c  o  m
 * @param xpath XPath expression
 * @param ns Map of namespace prefix declarations used in the XPath. Keys are prefixes, values are namespace URIs.
 * @return Returned value
 * @throws DocumentException
 */
public Object xpath(Object object, String xpath, Map<String, String> ns) throws WGException, DocumentException {
    Object result;
    if (object instanceof String || object instanceof Branch) {
        Branch branch = retrieveBranch(object);
        XPath xpathObj = createXPath(xpath, branch, ns);
        result = xpathObj.evaluate(branch);
    }

    // Do JXPath on Bean
    else {
        JXPathContext jxContext = JXPathContext.newContext(object);
        jxContext.setLenient(true);
        result = jxContext.getValue(xpath);
    }
    return convertXMLObjects(result, false);
}

From source file:de.innovationgate.wga.server.api.Xml.java

/**
 * Executes an XPath expression on some XML text or JavaBean
 * This function always returns lists. If the xpath expression matches only a single values it will return it as single element in a list. If you only want to retrieve single values use xpath().
 * The given object to parse as XML is either a dom4j branch object (mostly document or element), a String containing XML text or a JavaBean. In the last case this function uses JXPath functionality to find a bean property value.
 * This uses the Apache library JXPath under the hood. See their documentation for details how XPath is used to browser JavaBeans.
 * @param object Object to inspect//w  ww.j a v a2s . c  om
 * @param xpath XPath expression
 * @param ns Map of namespace prefix declarations used in the XPath. Keys are prefixes, values are namespace URIs.
 * @return Returned value
 * @throws DocumentException
 */
@SuppressWarnings("unchecked")
public Object xpathList(Object object, String xpath, Map<String, String> ns)
        throws WGException, DocumentException {
    List<Object> results;
    if (object instanceof String || object instanceof Branch) {
        Branch branch = retrieveBranch(object);
        XPath xpathObj = createXPath(xpath, branch, ns);
        results = xpathObj.selectNodes(branch);
    }

    // Do JXPath on Bean
    else {
        JXPathContext jxContext = JXPathContext.newContext(object);
        jxContext.setLenient(true);
        results = jxContext.selectNodes(xpath);
    }
    return convertXMLObjects(results, true);
}