List of usage examples for org.apache.commons.jxpath JXPathContext getValue
public abstract Object getValue(String xpath);
From source file:pt.webdetails.cdf.dd.render.Renderer.java
protected Object getRender(JXPathContext context) throws Exception { String renderType = null;/*from w ww . j av a 2 s.com*/ try { renderType = (String) context.getValue("type"); if (!renderType.equals("Label")) { Class<?> rendererClass = Class.forName(getRenderClassName(renderType)); Constructor<?> constructor = rendererClass.getConstructor(rendererConstructorArgs); return constructor.newInstance(new Object[] { context }); } } catch (InstantiationException e) { logger.error(e.getStackTrace()); } catch (IllegalAccessException e) { // TODO Auto-generated catch block logger.error(e.getStackTrace()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block logger.error("Class not found: " + renderType); //throw new RenderException("Render not found for: " + renderType); } return null; }
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();//from w ww. jav a 2s . c om 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();/*from ww w. ja v a2 s.c om*/ 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()); } }
From source file:pt.webdetails.cdf.dd.render.RenderResources.java
public ResourceMap renderResources(final String alias) throws Exception { final Iterator resourceRows = getResourcesRows(); ResourceMap resources = new ResourceMap(); while (resourceRows.hasNext()) { JXPathContext context = getRelativeContext((Pointer) resourceRows.next()); resources.add(// www . java2 s. c o m getResourceType(context).equals(CdeConstants.JAVASCRIPT) ? ResourceMap.ResourceKind.JAVASCRIPT : ResourceMap.ResourceKind.CSS, context.getValue("type").equals("LayoutResourceFile") ? ResourceMap.ResourceType.FILE : ResourceMap.ResourceType.CODE, getResourceName(context), getResourcePath(context), processResource(context, alias, 4)); } return resources; }
From source file:pt.webdetails.cdf.dd.util.JsonUtilsTest.java
@Test public void testToJXPathContext() throws JSONException { JXPathContext jxPathContext = JsonUtils.toJXPathContext(createTestJSON()); Assert.assertEquals("simple", jxPathContext.getValue("/property1")); Assert.assertEquals("simple", jxPathContext.getValue("//property2")); Assert.assertEquals("test", jxPathContext.getValue("//property4")); Assert.assertEquals("test", jxPathContext.getValue("//property4")); ArrayList<Object> array = (ArrayList<Object>) jxPathContext.getValue("//array2"); Assert.assertEquals("inside json", array.get(0)); Assert.assertEquals(3, array.get(1)); Map<String, Object> map = (Map<String, Object>) array.get(2); Assert.assertEquals("property4", map.keySet().toArray()[0]); Assert.assertEquals("test", map.get("property4")); }
From source file:pt.webdetails.cdf.dd.util.XPathUtils.java
public static String getStringValue(JXPathContext node, String xPath) { String value = ""; try {// ww w.j a va 2 s .co m Object val = node.getValue(xPath); value = val != null ? val.toString() : value; } catch (JXPathException e) { // Property not found; Should not be an error } return value; }
From source file:pt.webdetails.cdf.dd.util.XPathUtils.java
public static boolean exists(JXPathContext node, String xPath) { try {//from w w w . j a v a 2 s. c o m return ((String) node.getValue(xPath)).length() > 0 ? true : false; } catch (JXPathException e) { return false; } }
From source file:pt.webdetails.cdf.dd.util.XPathUtils.java
public static boolean getBooleanValue(JXPathContext node, String xPath) { boolean value = false; try {/*from w ww.j ava 2 s . c o m*/ value = ((Boolean) node.getValue("boolean(" + xPath + " = \"true\")")).booleanValue(); } catch (JXPathException e) { logger.error(e.getMessage()); } return value; }
From source file:pt.webdetails.cdf.dd.util.XPathUtils.java
public static String getValue(JXPathContext node, String xPath) { String value = ""; try {/* www .j a va2 s . c o m*/ value = node.getValue(xPath).toString(); } catch (JXPathException e) { // Property not found; Should not be an error } return value; }
From source file:se.cambio.cds.gdl.editor.view.panels.DescriptionPanel.java
private void connect(JXPathContext context, String xPath, JComponent component) { component.addFocusListener(new ComponentFocusAdapter(context, xPath)); String value = null;/*from www. j a v a2s.c o m*/ try { value = (String) context.getValue(xPath); } catch (JXPathNotFoundException e) { //Value not found } if (value != null) { if (component instanceof JTextComponent) { value = value.replace("\\\"", "\""); ((JTextComponent) component).setText(value); } else if (component instanceof JComboBox) { ((JComboBox) component).setSelectedItem(value); } } }