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

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

Introduction

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

Prototype

public abstract Object getValue(String xpath);

Source Link

Document

Evaluates the xpath and returns the resulting object.

Usage

From source file:org.xsystem.sql2.http.PageServlet2.java

static Map<String, Object> getContext(Map<String, String> evals, Map<String, Object> reqContext) {
    JXPathContext context = JXPathContext.newContext(reqContext);
    context.setFunctions(new ClassFunctions(Base64Decode.class, "BASE64"));
    context.setLenient(true);// w  ww.  j  av  a 2  s. co m

    Map ret = new HashMap();
    evals.entrySet().forEach(entry -> {
        String key = entry.getKey();
        String eval = entry.getValue();
        Object value = context.getValue(eval);
        ret.put(key, value);
    });

    return ret;
}

From source file:org.xsystem.sql2.page.functions.PageFunctions.java

public Boolean in(String path, Object... values) {
    JXPathContext context = JXPathContext.newContext(actionContext);
    Object testvalue = context.getValue(path);
    if (testvalue == null) {
        return false;
    }//ww  w .ja  va 2  s  .  c  o  m
    int size = values.length;
    for (int i = 0; i < size; i++) {
        Object cur = values[i];
        if (cur instanceof List) {
            List lst = (List) cur;
            Set set = new HashSet(lst);
            if (set.contains(testvalue)) {
                return true;
            }
        } else if (cur instanceof Set) {
            Set set = (Set) cur;
            if (set.contains(testvalue)) {
                return true;
            }
        } else if (testvalue.equals(cur)) {
            return true;
        }
    }
    return false;
}

From source file:org.xsystem.sql2.page.functions.PageFunctions.java

public Object path(String path) {
    JXPathContext context = JXPathContext.newContext(actionContext);
    context.setLenient(true);/*  ww  w  .j a  va2s  .  c  o  m*/
    Object ret = context.getValue(path);
    return ret;
}

From source file:org.xsystem.sql2.page.functions.PageFunctions.java

public Boolean exist(String path) {
    JXPathContext context = JXPathContext.newContext(actionContext);
    context.setLenient(true);//  w ww  . j ava 2  s  .  com
    boolean ret = context.getValue(path) != null;
    return ret;
}

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

private void readKind(Dashboard.Builder builder, String thingKind, JXPathContext source,
        Iterator<Pointer> componentPointers, CdfdeJsReadContext context, String sourcePath)
        throws ThingReadException {
    while (componentPointers.hasNext()) {
        Pointer componentPointer = componentPointers.next();
        JXPathContext compXP = source.getRelativeContext(componentPointer);

        String className = (String) compXP.getValue("type");

        // Ignore label components (it's OK for current needs)
        if (className == null || !className.equalsIgnoreCase("label")) {
            IThingReader reader;/*w  w w .  j  a  va  2 s  .  c  o  m*/
            try {
                reader = context.getFactory().getReader(thingKind, className, null);
            } catch (UnsupportedThingException ex) {
                logger.error("While rendering dashboard. " + ex);
                continue;
            }

            Component.Builder compBuilder = (Component.Builder) reader.read(context, compXP, sourcePath);

            builder.addComponent(compBuilder);
        }
    }
}

From source file:pt.webdetails.cdf.dd.model.meta.reader.datasources.DataSourcesModelReader.java

/**
 * @param model      where component type builders are placed
 * @param pointer/*from   w  w  w .  j a  v a2  s . c o m*/
 * @param sourcePath sourcePath for all components
 */
private void readDataSourceComponent(MetaModel.Builder model, Pointer pointer, String sourcePath) {
    // TODO: What a generality...

    DataSourceComponentType.Builder builder = new DataSourceComponentType.Builder();

    Map<String, Object> def = (Map<String, Object>) pointer.getNode();
    JXPathContext jctx = JXPathContext.newContext(def);

    String label = (String) jctx.getValue("metadata/name");

    String dataSourceType = (String) jctx.getValue("metadata/datype");

    boolean isCPK = dataSourceType.equalsIgnoreCase("cpk");
    boolean isCDA = !isCPK;

    //TODO: oh so wrong
    PathOrigin origin = new OtherPluginStaticSystemOrigin(isCPK ? "cpk" : "cda", "");
    builder.setOrigin(origin);

    // This specific Data Source has special treatment below
    boolean isKettleOverX = isCDA && "kettle over kettleTransFromFile".equalsIgnoreCase(label);

    logger.debug(String.format("\t%s", label));

    String connType = (String) jctx.getValue("metadata/conntype");
    connType = connType != null ? connType : "";

    builder.setName(pointer.asPath().replaceAll(".*name='(.*?)'.*", "$1")).setLabel(label).setTooltip(label)
            .setCategory((String) jctx.getValue("metadata/group"))
            .setCategoryLabel((String) jctx.getValue("metadata/groupdesc")).setSourcePath(sourcePath)
            .addAttribute("", isCPK ? "CPK" : "CDA"); // meta: "CDA"

    if (isCDA) {
        builder.addAttribute("conntype", connType).addAttribute("datype", dataSourceType);
    } else if (isCPK) {
        builder.useProperty(null, "stepName").useProperty(null, "kettleOutput")
                .addAttribute("pluginId", (String) jctx.getValue("metadata/pluginId"))
                .addAttribute("endpoint", (String) jctx.getValue("metadata/endpoint"));
    }

    if (isCDA) {
        for (String cdaPropName : this.getCDAPropertyNames(def)) {
            if (cdaPropName.equals("id") || cdaPropName.equals("connection")) {
                continue;
            } else if (cdaPropName.equals("columns")) {
                builder.useProperty(null, "cdacolumns");
                builder.useProperty(null, "cdacalculatedcolumns");
            } else if (cdaPropName.equals("output")) {
                builder.useProperty(null, "output");
                builder.useProperty(null, "outputMode");
            } else if (cdaPropName.equals("left")) {
                builder.useProperty(null, "left");
                builder.useProperty(null, "leftkeys");
            } else if (cdaPropName.equals("right")) {
                builder.useProperty(null, "right");
                builder.useProperty(null, "rightkeys");
            } else if (isKettleOverX && cdaPropName.equalsIgnoreCase("query")) {
                builder.useProperty(cdaPropName, "kettleQuery");
            } else {
                builder.useProperty(null, cdaPropName);
            }
        }
    }
    model.addComponent(builder);
}

From source file:pt.webdetails.cdf.dd.model.meta.reader.datasources.DataSourcesModelReader.java

private List<String> getCDAPropertyNames(Map<String, Object> def) {
    ArrayList<String> props = new ArrayList<String>();

    JXPathContext context = JXPathContext.newContext(def);

    Map<String, Object> connection = (Map<String, Object>) context.getValue("definition/connection");
    if (connection != null) {
        props.addAll(connection.keySet());
    }/*from   w  ww  .jav a2  s .co m*/

    Map<String, Object> dataaccess = (Map<String, Object>) context.getValue("definition/dataaccess");
    if (dataaccess != null) {
        props.addAll(dataaccess.keySet());
    }

    return props;
}

From source file:pt.webdetails.cdf.dd.render.CdaRenderer.java

private void renderProperty(CdaElementRenderer renderer, JXPathContext context, String propertyName,
        Element element) throws JSONException {
    renderer.setDefinition((Map<String, Object>) context.getValue("properties/.[name='" + propertyName + "']"));
    renderer.renderInto(element);/*  w w  w.j a  v  a 2  s  .  c  o m*/
}

From source file:pt.webdetails.cdf.dd.render.CdaRenderer.java

public boolean isValidJsonArray(JXPathContext context, String paramName) {
    return context != null && context.getValue("properties/.[name='" + paramName + "']/value") != null && Utils
            .isValidJsonArray(context.getValue("properties/.[name='" + paramName + "']/value").toString());
}

From source file:pt.webdetails.cdf.dd.render.components.ComponentManager.java

public BaseComponent getRenderer(JXPathContext context) {
    String renderType = ((String) context.getValue("type")).replace("Components", "");
    return componentPool.get(renderType);
}