List of usage examples for org.apache.commons.jxpath JXPathContext setLenient
public synchronized void setLenient(boolean lenient)
From source file:org.openconcerto.xml.JXPathXPath.java
private JXPathContext getJXPath(final Object context) { final JXPathContext newContext = JXPathContext.newContext(context); for (final Namespace ns : this.namespaces) newContext.registerNamespace(ns.getPrefix(), ns.getURI()); for (final Entry<String, Object> e : this.variables.entrySet()) newContext.getVariables().declareVariable(e.getKey(), e.getValue()); // otherwise /a/b on an empty document throws an exception newContext.setLenient(true); return newContext; }
From source file:org.openvpms.component.system.common.jxpath.JXPathHelper.java
/** * Create a new context for the specified object that has access to the supplied functions. * * @param object the context bean/* w w w . ja v a2 s.c om*/ * @param functions the functions * @return JXPathContext the context object */ public static JXPathContext newContext(Object object, Functions functions) { JXPathContext context = JXPathContext.newContext(object); FunctionLibrary lib = new FunctionLibrary(); lib.addFunctions(context.getFunctions()); lib.addFunctions(functions); context.setFunctions(lib); context.setLenient(true); return context; }
From source file:org.talend.mdm.webapp.browserecords.server.util.DynamicLabelUtil.java
private static String getFKInfo(String key, String foreignkey, List<String> fkInfos) { try {//from w ww .j a v a 2 s . c om if (key == null || key.trim().length() == 0) return null; List<String> ids = new ArrayList<String>(); if (!key.matches("^\\[(.*?)\\]$")) { //$NON-NLS-1$ ids.add(key); } else { Pattern p = Pattern.compile("\\[(.*?)\\]"); //$NON-NLS-1$ Matcher m = p.matcher(key); while (m.find()) { ids.add(m.group(1)); } } // Collections.reverse(ids); String concept = Util.getForeignPathFromPath(foreignkey); concept = concept.split("/")[0]; //$NON-NLS-1$ Configuration config = Configuration.getConfiguration(); String dataClusterPK = config.getCluster(); WSItemPK wsItem = new WSItemPK(new WSDataClusterPK(dataClusterPK), concept, (String[]) ids.toArray(new String[ids.size()])); WSItem item = Util.getPort().getItem(new WSGetItem(wsItem)); if (item != null) { String content = item.getContent(); Node node = Util.parse(content).getDocumentElement(); if (fkInfos.size() > 0) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < fkInfos.size(); i++) { String info = fkInfos.get(i); JXPathContext jxpContext = JXPathContext.newContext(node); jxpContext.setLenient(true); info = info.replaceFirst(concept + "/", ""); //$NON-NLS-1$ //$NON-NLS-2$ String fkinfo = (String) jxpContext.getValue(info, String.class); if (fkinfo != null && fkinfo.length() != 0) { sb.append(fkinfo); } if (i < fkInfos.size() - 1 && fkInfos.size() > 1) { sb.append("-"); //$NON-NLS-1$ } } return sb.toString(); } else { return key; } } } catch (Exception e) { LOG.error(e.getMessage(), e); return key; } return null; }
From source file:org.xsystem.sql2.http.impl.HttpHelper.java
public static int getThumb(FileFormat fileFormat, Map<String, Object> reqContext) { if (fileFormat == null) { return -1; }/*from w w w . j a v a 2 s .c om*/ String eval = fileFormat.getPreview(); if (eval.isEmpty()) { return 200; } JXPathContext context = JXPathContext.newContext(reqContext); context.setLenient(true); Object obj = context.getValue(eval); if (obj == null) { return 200; } Integer ret = Integer.valueOf(obj.toString().trim()); return ret; }
From source file:org.xsystem.sql2.http.impl.HttpHelper.java
public static FileTransfer getFileTransfer(FileFormat fileFormat, Object value, BiFunction<String, Object, byte[]> bi) { Map row = null;/*from ww w . ja v a2 s . c o m*/ if (value instanceof List) { List lst = (List) value; if (!lst.isEmpty()) { Object test = lst.get(0); if (test instanceof Map) { row = (Map) test; } } } else if (value instanceof Map) { row = (Map) value; } if (row == null) { return null; } String evalContenttype = fileFormat.getContenttype(); String evalFilename = fileFormat.getFilename(); String evalContent = fileFormat.getContent(); String evalFormat = fileFormat.getFormat(); JXPathContext context = JXPathContext.newContext(row); context.setLenient(true); String contenttype = (String) context.getValue(evalContenttype); String filename = (String) context.getValue(evalFilename); //byte[] content = (byte[]) context.getValue(evalContent); String format = (String) context.getValue(evalFormat); Object data = context.getValue(evalContent); byte[] content = bi.apply(fileFormat.getStorage(), data); if (content == null) { return null; } FileTransfer ret = new FileTransfer(); ret.setContentType(contenttype); ret.setData(content); ret.setFileName(filename); ret.setFileType(format); return ret; }
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); 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);//from w ww . ja va 2 s . c om }); return ret; }
From source file:org.xsystem.sql2.page.functions.PageFunctions.java
public Object path(String path) { JXPathContext context = JXPathContext.newContext(actionContext); context.setLenient(true); Object ret = context.getValue(path); return ret;/* w w w. ja v a2s.com*/ }
From source file:org.xsystem.sql2.page.functions.PageFunctions.java
public Boolean exist(String path) { JXPathContext context = JXPathContext.newContext(actionContext); context.setLenient(true); boolean ret = context.getValue(path) != null; return ret;//from w w w .j a v a 2 s . co m }
From source file:terrastore.store.conditions.JXPathCondition.java
@Override public boolean isSatisfied(String key, Map<String, Object> value, String expression) { JXPathContext context = JXPathContext.newContext(value); context.setLenient(true); List selection = context.selectNodes(expression); return selection != null && selection.size() > 0; }