List of usage examples for org.apache.commons.jxpath Pointer asPath
String asPath();
From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java
/** * Tests some variations of obtaining the last node within a nodeset. * * @throws Exception if any error occurred during the test. *///w ww .j a v a2s . c o m public void testLast() throws Exception { Pointer pointer1 = this.context.getPointer("//my:order/my:item[2]"); assertEquals("/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]", pointer1.asPath()); Pointer pointer2 = this.context.getPointer("//my:order/my:item[position()=count(../*)]"); assertEquals("/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]", pointer2.asPath()); Pointer pointer3 = this.context.getPointer("//my:order/my:item[position()=2]"); assertEquals("/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]", pointer3.asPath()); Pointer pointer4 = this.context.getPointer("//my:order[1]/my:item[last()]"); assertEquals("/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]", pointer4.asPath()); Pointer pointer5 = this.context.getPointer("//my:order[1]/my:item[position()=last()]"); assertEquals("/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]", pointer5.asPath()); }
From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java
/** * Tests relative pathes./*from w w w . ja va2s. c o m*/ * * @throws Exception if any error occurred during the test. */ public void testRelativePathes() throws Exception { Pointer pointer1 = this.context.getPointer("//my:item[2]/my:discount/../my:amount"); assertEquals( "/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]/my:amount[1]", pointer1.asPath()); Pointer pointer2 = this.context.getPointer("//my:item[2]/./my:discount/../my:amount/."); assertEquals( "/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]/my:amount[1]", pointer2.asPath()); Pointer pointer3 = this.context.getPointer("//my:item[@my:money=../@my:money]/my:discount/../my:amount"); assertEquals( "/html:html[1]/html:head[1]/xf:model[1]/xf:instance[1]/data[1]/my:order[1]/my:item[2]/my:amount[1]", pointer3.asPath()); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathCreatePath(JXPathContext ctx, String xpath, Object expectedValue, String expectedPath) {// ww w .j a v a 2 s .co m Pointer pointer = ctx.createPath(xpath); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", expectedValue, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", expectedValue, ctx.getValue(pointer.asPath())); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathCreatePathAndSetValue(JXPathContext ctx, String xpath, Object value, String expectedPath) {/*from w w w.j a v a 2s.co m*/ Pointer pointer = ctx.createPathAndSetValue(xpath, value); assertEquals("Creating path <" + xpath + ">", expectedPath, pointer.asPath()); assertEquals("Creating path (pointer value) <" + xpath + ">", value, pointer.getValue()); assertEquals("Creating path (context value) <" + xpath + ">", value, ctx.getValue(pointer.asPath())); }
From source file:org.onecmdb.core.utils.xpath.generator.DebugContentGenerator.java
public void transfer(OutputStream out) { log.debug("Debug Query path <" + cmd.getPath() + ">"); PrintWriter text = new PrintWriter(new OutputStreamWriter(out), true); Double count = (Double) cmd.getXPathContext().getValue("count(" + cmd.getPath() + ")"); Iterator<Pointer> iter = cmd.getPathPointers(); out(text, cmd.getPath() + "[" + count + "]"); boolean first = true; while (iter.hasNext()) { Pointer p = (Pointer) iter.next(); log.debug(p.asPath()); out(text, "\t" + p.asPath() + "=" + p.getNode()); String[] outputAttributes = cmd.getOutputAttributeAsArray(); for (String outputAttribute : outputAttributes) { Iterator<Pointer> outputAttrPointersIter = cmd.getRelativePointers(p, outputAttribute); while (outputAttrPointersIter.hasNext()) { Pointer outputPointer = outputAttrPointersIter.next(); // Try to create some path. out(text, "\t\t" + outputPointer.asPath() + "=" + outputPointer.getNode()); }//from w w w . j a va 2 s. c om } } }
From source file:pt.webdetails.cdf.dd.model.meta.reader.datasources.DataSourcesModelReader.java
/** * @param model where component type builders are placed * @param pointer/*from www. ja v a 2 s . co 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.render.CdaRenderer.java
private Element exportConnection(Document doc, JXPathContext context, String id) throws Exception { JXPathContext cda = JsonUtils.toJXPathContext(cdaDefinitions); String type = ((String) context.getValue("type", String.class)).replaceAll("Components(.*)", "$1"); String conntype = ((String) context.getValue("meta_conntype", String.class)); if (conntype.isEmpty() || conntype.equals("null")) { throw new Exception("No connection here!"); }/*from www . j av a2 s. c o m*/ JXPathContext conn = JXPathContext.newContext(cda.getValue(type + "/definition/connection")); Element connection = doc.createElement("Connection"); connection.setAttribute("id", id); connection.setAttribute("type", conntype); Iterator<Pointer> params = conn.iteratePointers("*"); while (params.hasNext()) { Pointer pointer = params.next(); //JSONObject param = (JSONObject) pointer.getNode(); String paramName = pointer.asPath().replaceAll(".*name='(.*?)'.*", "$1"); String placement = ((String) conn.getValue(pointer.asPath() + "/placement", String.class)) .toLowerCase(); if (placement.equals("attrib")) { if (paramName.equals("id")) { continue; } else { String value = (String) context.getValue("properties/.[name='" + paramName + "']/value", String.class); connection.setAttribute(paramName, value); } } else if (paramName.equals("variables")) { Variables vars = new Variables(); vars.setContext(context); renderProperty(vars, context, paramName, connection); } else if (paramName.matches("olap4j.*")) { renderProperty(new Olap4jProperties(paramName), context, paramName, connection); } else if (paramName.equals("dataFile")) { renderProperty(new DataFile(), context, paramName, connection); } else if (paramName.equals("property") && isValidJsonArray(context, paramName)) { Object array = context.getValue("properties/.[name='" + paramName + "']/value"); JSONArray jsonArray = array instanceof String ? new JSONArray(array.toString()) : new JSONArray(array); for (int i = 0; i < jsonArray.length(); i++) { JSONArray json = (JSONArray) jsonArray.get(i); String name = json.getString(0); // property name String value = json.getString(1); // property value Element child = doc.createElement(Utils.toFirstUpperCase(paramName)); child.setAttribute("name", name); child.appendChild(doc.createTextNode(value)); connection.appendChild(child); } } else { String value = (String) context.getValue("properties/.[name='" + paramName + "']/value", String.class); Element child = doc.createElement(Utils.toFirstUpperCase(paramName)); child.appendChild(doc.createTextNode(value)); connection.appendChild(child); } } return connection; }
From source file:pt.webdetails.cdf.dd.render.CdaRenderer.java
private Element exportDataAccess(Document doc, JXPathContext context, String connectionId) throws JSONException { String tagName = "DataAccess"; // Boolean compound = false; JXPathContext cda = JsonUtils.toJXPathContext(cdaDefinitions); String type = ((String) context.getValue("type", String.class)).replaceAll("Components(.*)", "$1"); String daType = ((String) context.getValue("meta_datype", String.class)); if (type.equals("join") || type.equals("union")) { tagName = "CompoundDataAccess"; // compound = true; }/*w w w.j a v a 2 s .co m*/ String name = (String) context.getValue("properties/.[name='name']/value", String.class); JXPathContext conn = JXPathContext.newContext(cda.getValue(type + "/definition/dataaccess")); Element dataAccess = doc.createElement(tagName); dataAccess.setAttribute("id", name); dataAccess.setAttribute("type", daType); if (connectionId != null && !connectionId.equals("")) { dataAccess.setAttribute("connection", connectionId); } Element elName = doc.createElement("Name"); elName.appendChild(doc.createTextNode(name)); dataAccess.appendChild(elName); @SuppressWarnings("unchecked") Iterator<Pointer> params = conn.iteratePointers("*"); Pointer pointer; String paramName; while (params.hasNext()) { pointer = params.next(); paramName = pointer.asPath().replaceAll(".*name='(.*?)'.*", "$1"); if (((String) conn.getValue(pointer.asPath() + "/placement", String.class)).toLowerCase() .equals("attrib")) { if (paramName.equals("id") || paramName.equals("connection") || paramName.equals("cacheDuration")) { continue; } else { dataAccess.setAttribute(paramName, (String) context .getValue("properties/.[name='" + paramName + "']/value", String.class)); } } else if (paramName.equals("parameters")) { renderProperty(new Parameters(), context, paramName, dataAccess); } else if (paramName.equals("output")) { renderProperty(new Output(context), context, paramName, dataAccess); } else if (paramName.equals("variables")) { renderProperty(new Variables(context), context, paramName, dataAccess); } else if (paramName.equals("outputMode")) { // Skip over outputMode, it's handled by output. continue; } else if (paramName.equals("cacheKeys")) { // Skip over cacheKeys, it's handled by cache. continue; } else if (paramName.equals("cache")) { renderProperty(new Cache(context), context, paramName, dataAccess); } else if (paramName.equals("columns")) { Element cols = dataAccess.getOwnerDocument().createElement("Columns"); renderProperty(new Columns(), context, "cdacolumns", cols); renderProperty(new CalculatedColumns(), context, "cdacalculatedcolumns", cols); dataAccess.appendChild(cols); } else if (paramName.equals("top") || paramName.equals("bottom") || paramName.equals("left") || paramName.equals("right")) { Element compoundElem = dataAccess.getOwnerDocument() .createElement(Utils.toFirstUpperCase(paramName)); renderProperty(new CompoundComponent(), context, paramName, compoundElem); dataAccess.appendChild(compoundElem); if (paramName.equals("left")) { renderProperty(new Keys(), context, "leftkeys", compoundElem); } else if (paramName.equals("right")) { renderProperty(new Keys(), context, "rightkeys", compoundElem); } } else { String value = (String) context.getValue("properties/.[name='" + paramName + "']/value", String.class); if (paramName.equals("query")) { value = value.trim(); } Element child = doc.createElement(Utils.toFirstUpperCase(paramName)); child.appendChild(doc.createTextNode(value)); dataAccess.appendChild(child); } } return dataAccess; }