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

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

Introduction

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

Prototype

public abstract Iterator iterate(String xpath);

Source Link

Document

Traverses the xpath and returns an Iterator of all results found for the path.

Usage

From source file:org.toobsframework.pres.util.ParameterUtil.java

public static void mapOutputParameters(IRequest request, Parameter[] paramMap, Map paramsIn, String scopeId,
        List<IDataProviderObject> objects) {
    for (int j = 0; j < paramMap.length; j++) {
        Parameter thisParam = paramMap[j];
        if (thisParam.getScope() != null && !thisParam.getScope().equalsIgnoreCase("all")
                && !thisParam.getScope().equalsIgnoreCase(scopeId)) {
            continue;
        }/*www .  j  a  v  a 2  s  .  co  m*/
        if (!thisParam.getOverwriteExisting() && paramsIn.get(thisParam.getName()) != null) {
            continue;
        }
        if (thisParam.getObjectIndex() >= objects.size()) {
            continue;
        }
        JXPathContext context = null;
        Object value = null;
        String paramName = resolveParam(request, thisParam.getName(), paramsIn)[0];
        try {
            String thisPath = resolveParam(request, thisParam.getPath(), paramsIn)[0];
            if (thisParam.getIsStatic()) {
                value = thisPath;
            } else {
                if (thisParam.getIsList()) {
                    value = new ArrayList();
                    if (thisParam.getObjectIndex() == -1) {
                        for (int i = 0; i < objects.size(); i++) {
                            context = JXPathContext.newContext(objects.get(i));
                            ((ArrayList) value).add(context.getValue(thisPath));
                        }
                    } else {
                        context = JXPathContext.newContext(objects.get(thisParam.getObjectIndex()));
                        Iterator iter = context.iterate(thisPath);
                        while (iter.hasNext()) {
                            ((ArrayList) value).add(iter.next());
                        }
                    }
                    if (((ArrayList) value).size() == 0) {
                        if (thisParam.getDefault() != null) {
                            try {
                                ((ArrayList) value).add(Integer.parseInt(thisParam.getDefault()));
                            } catch (NumberFormatException nfe) {
                                ((ArrayList) value).add(thisParam.getDefault());
                            }
                        } else {
                            value = null;
                        }
                    }
                } else {
                    context = JXPathContext.newContext(objects.get(thisParam.getObjectIndex()));
                    value = context.getValue(thisPath);
                }
            }
            if (value != null && List.class.isAssignableFrom(value.getClass()) && ((List) value).size() == 0
                    && thisParam.getDefault() != null) {
                ((List) value).add(thisPath);
            }
            paramsIn.put(paramName, value);
        } catch (JXPathException e) {
            if (thisParam.getDefault() != null) {
                String[] def = resolveParam(request, thisParam.getDefault(), paramsIn);
                if (def != null && def.length > 0) {
                    paramsIn.put(paramName, def[0]);
                }
            } else if (!thisParam.getIgnoreNull()) {
                log.error("JXPathException for parameter " + paramName + " in scope " + scopeId);
                // TODO This should be a BaseException
                throw e;
            }
        }
    }
}

From source file:pt.webdetails.cdf.dd.model.inst.reader.cdfdejs.CdfdeJsComponentReader.java

public void read(TM builder, IThingReadContext context, JXPathContext source, String sourcePath) {
    // TODO: Other CDFDE component properties are not relevant now, 
    // but revisit this in the future.

    // Property Bindings
    Iterator<Map<String, Object>> mapIterator = source.iterate("properties");
    while (mapIterator.hasNext()) {
        Map<String, Object> map = mapIterator.next();
        Object name = map.get("name");
        Object type = map.get("type");
        Object value = map.get("value");

        builder.addPropertyBinding(/*from  w  w w .j  ava  2  s.c  om*/
                new UnresolvedPropertyBinding.Builder().setAlias(name != null ? name.toString() : "") // matches prop/name
                        .setInputType(type != null ? type.toString() : "")
                        .setValue(value != null ? value.toString() : ""));
    }

    // Attributes
    Map<String, Object> jsComp = (Map<String, Object>) source.getContextBean();
    Set<String> keys = jsComp.keySet();
    for (String key : keys) {
        if (key.startsWith("meta_")) {
            String name = key.substring("meta_".length());
            builder.addAttribute(name, jsComp.get(key).toString());
        }
    }
}