List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
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; }// w ww . j ava2 s .com 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); 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);/*from w w w . ja va 2 s. c om*/ boolean ret = context.getValue(path) != null; return ret; }
From source file:pt.webdetails.cdf.dd.AbstractDashboard.java
public static JXPathContext openDashboardAsJXPathContext(RepositoryAccess solutionRepository, String dashboardLocation, WcdfDescriptor wcdf) throws IOException, FileNotFoundException { final JSONObject json = (JSONObject) JsonUtils .readJsonFromInputStream(solutionRepository.getResourceInputStream(dashboardLocation)); if (wcdf != null) { json.put("settings", wcdf.toJSON()); }// www. ja v a 2 s . co m final JXPathContext doc = JXPathContext.newContext(json); return doc; }
From source file:pt.webdetails.cdf.dd.datasources.CdaManager.java
public void saveDefinition(String[] file, String jsonString, IPentahoSession userSession) throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(jsonString); JXPathContext.newContext(json); switch (RepositoryAccess.getRepository(userSession).publishFile(file[0], file[1], json.toString().getBytes("UTF-8"), true)) { case FAIL:/* w w w .j a va 2 s .c o m*/ logger.error("Could not save definition " + StringUtils.join(file, "/")); } }
From source file:pt.webdetails.cdf.dd.MobileDashboard.java
private void construct(boolean absolute, String absRoot) { RepositoryAccess solutionRepository = RepositoryAccess.getRepository(); final RenderMobileLayout layoutRenderer = new RenderMobileLayout(); final RenderComponents componentsRenderer = new RenderComponents(); try {/*from ww w . j a va2s . c om*/ final JSONObject json = (JSONObject) JsonUtils .readJsonFromInputStream(solutionRepository.getResourceInputStream(dashboardLocation)); json.put("settings", getWcdf().toJSON()); final JXPathContext doc = JXPathContext.newContext(json); // set all dashboard members this.layout = replaceTokens(layoutRenderer.render(doc), absolute, absRoot); this.components = replaceTokens(componentsRenderer.render(doc), absolute, absRoot); this.header = renderHeaders(this.layout + this.components); this.templateFile = MOBILE_TEMPLATE; this.template = replaceTokens(ResourceManager.getInstance().getResourceAsString(this.templateFile), absolute, absRoot); this.loaded = new Date(); } catch (Exception e) { logger.error(e); } }
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 ava 2 s. com*/ * @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 .j a va 2 s .c o 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.cda.CompoundComponent.java
public void renderInto(Element compound) { JXPathContext context = JXPathContext.newContext(definition); compound.setAttribute("id", (String) context.getValue("value", String.class)); }
From source file:pt.webdetails.cdf.dd.render.CdaRenderer.java
public String render() throws Exception { ByteArrayOutputStream result = new ByteArrayOutputStream(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document cdaFile = builder.newDocument(); Element root = cdaFile.createElement("CDADescriptor"); cdaFile.appendChild(root);//from www. j a va 2s . com Element connections = cdaFile.createElement("DataSources"); root.appendChild(connections); Iterator<Pointer> pointers = doc.iteratePointers(CDA_ELEMENTS_JXPATH); while (pointers.hasNext()) { Pointer pointer = pointers.next(); JXPathContext context = JXPathContext.newContext(pointer.getNode()); String connectionId = (String) context.getValue("properties/.[name='name']/value", String.class); Element conn; try { conn = exportConnection(cdaFile, context, connectionId); connections.appendChild(conn); } catch (Exception e) { // things without connections end up here. All is fine, // we just need to make sure exportDataAccess doesn't try to generate a connection link connectionId = null; } Element dataAccess = exportDataAccess(cdaFile, context, connectionId); if (dataAccess != null) { root.appendChild(dataAccess); } } TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(cdaFile); StreamResult res = new StreamResult(new OutputStreamWriter(result, CharsetHelper.getEncoding())); transformer.setOutputProperty(OutputKeys.ENCODING, CharsetHelper.getEncoding()); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "Query"); transformer.transform(source, res); return result.toString(); }