List of usage examples for org.apache.commons.jxpath JXPathContext iteratePointers
public abstract Iterator iteratePointers(String xpath);
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!"); }/* ww w . java2 s . c om*/ 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; }// www . j a v a 2s . c o 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; }
From source file:pt.webdetails.cdf.dd.render.components.ComponentManager.java
public void parseCdaDefinitions(JSON json) throws Exception { cdaSettings = json;/*from w w w. ja va 2 s . co m*/ final JXPathContext doc = JXPathContext.newContext(json); Iterator<Pointer> pointers = doc.iteratePointers("*"); while (pointers.hasNext()) { Pointer pointer = pointers.next(); CdaDatasource ds = new CdaDatasource(pointer); componentPool.put(ds.getName(), ds); } }
From source file:pt.webdetails.cdf.dd.render.RenderLayout.java
private void renderRows(final JXPathContext doc, final Iterator nodeIterator, final Map<String, CdfRunJsDashboardWriteResult> widgetsByContainerId, final String alias, final StringBuffer layout, final int indent) throws Exception { while (nodeIterator.hasNext()) { final Pointer pointer = (Pointer) nodeIterator.next(); final JXPathContext context = doc.getRelativeContext(pointer); final String rowId = (String) context.getValue("id"); final String rowName = XPathUtils.getStringValue(context, "properties[name='name']/value"); final Render renderer = (Render) getRender(context); renderer.processProperties();//w w w . ja v a 2 s .c o m renderer.aliasId(alias); // when rendering rows for the layout of a dashboard AMD module, skip NEWLINE and indentation if (indent > -1) { layout.append(NEWLINE).append(getIndent(indent)).append(renderer.renderStart()); if (widgetsByContainerId != null && widgetsByContainerId.containsKey(rowName)) { CdfRunJsDashboardWriteResult widgetResult = widgetsByContainerId.get(rowName); layout.append(widgetResult.getLayout()); } else { renderRows(context, context.iteratePointers(MessageFormat.format(XPATH_FILTER, rowId, "")), widgetsByContainerId, alias, layout, indent + 2); } layout.append(NEWLINE).append(getIndent(indent)).append(renderer.renderClose()); } else { layout.append(renderer.renderStart()); if (widgetsByContainerId != null && widgetsByContainerId.containsKey(rowName)) { CdfRunJsDashboardWriteResult widgetResult = widgetsByContainerId.get(rowName); layout.append(widgetResult.getLayout()); } else { renderRows(context, context.iteratePointers(MessageFormat.format(XPATH_FILTER, rowId, "")), widgetsByContainerId, alias, layout, -1); } layout.append(renderer.renderClose()); } } }
From source file:pt.webdetails.cdf.dd.render.RenderMobileLayout.java
private void renderRows(final JXPathContext doc, final Iterator<Pointer> nodeIterator, final StringBuffer layout, final int ident) throws Exception { while (nodeIterator.hasNext()) { final Pointer pointer = nodeIterator.next(); final JXPathContext context = doc.getRelativeContext(pointer); final String rowId = (String) context.getValue("id"); final Render renderer = (Render) getRender(context); renderer.processProperties();/* ww w. ja va 2 s . c o m*/ layout.append(NEWLINE).append(getIndent(ident)); layout.append(renderer.renderStart()); // Render Child Rows renderRows(context, context.iteratePointers(MessageFormat.format(XPATH_FILTER, rowId)), layout, ident + 2); layout.append(NEWLINE).append(getIndent(ident)); layout.append(renderer.renderClose()); } }