private static List<OMElement> evaluateXPathToElements(String expression, OMElement root) throws Exception { String[] nsPrefixes = wsdlPrefixes; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < nsPrefixes.length; j ++) { xpathExpression.addNamespace(nsPrefixes[j++], nsPrefixes[j]); } return (List<OMElement>)xpathExpression.selectNodes(root); }
/** * Create an instance of EvaluatableSegment. * * @param name Name of segment. * @param expression Expression that needs evaluating to retrieve the value of segment. * @throws JaxenException on expression evalution error. */ protected EvaluatableSegment(String name, String expression) throws JaxenException { super(name); xpathProcessor = new AXIOMXPath(getNormalizedExpression(expression)); xpathProcessor.addNamespace(NAMESPACE_PREFIX, NAMESPACE_URL); }
import org.apache.axiom.om.OMElement; import org.apache.axiom.om.xpath.AXIOMXPath; import org.jaxen.JaxenException; public String hello(OMElement xmlElement) { try { AXIOMXPath someXPath = new AXIOMXPath("//root/child"); String str = ((OMElement)someXPath.selectSingleNode(node)).getText(); } catch (JaxenException e) { e.printStackTrace(); } }
private List<OMElement> splitToRecords(String recordsSrc) { OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(recordsSrc)); OMElement element = records.getDocumentElement(); AXIOMXPath xpath = null; try { xpath = new AXIOMXPath("//PubmedArticle"); List<OMElement> recordsList = xpath.selectNodes(element); return recordsList; } catch (JaxenException e) { return null; } }
private void updateSubReportPosition(OMElement subReportElement, int yPos) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:reportElement"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); List nodeList = xpathExpression.selectNodes(subReportElement); OMElement repElement = (OMElement) nodeList.get(0); repElement.getAttribute(new QName("y")).setAttributeValue(String.valueOf(yPos)); }
protected OMElement getCategorySeriesElement(String chartText, String chartDatasetText, String chartSeriesText) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:" + chartText + "//a:" + chartDatasetText + "//a:" + chartSeriesText); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement aCategorySeries = (OMElement) nodeList.get(0); return aCategorySeries; }
protected OMElement getSubDataSetElement() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:subDataset"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); return element; }
protected OMElement getComponentElement(String componentName) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:" + componentName); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); return element; }
private void setTableHeaderNames() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:componentElement//b:table//b:column" + "//b:columnHeader//a:text"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); xpathExpression.addNamespace("b", "http://jasperreports.sourceforge.net/jasperreports/components"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); for (int i = 0; i < nodeList.size(); i++) { OMElement textElement = (OMElement) nodeList.get(i); tableReport.getColumns()[i].setColumnHeaderName(textElement.getText()); } }
private void refreshReport() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); element.detach(); }
private TableReportDTO setTableOutlines() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:style//a:box//a:pen"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement penElement = (OMElement) nodeList.get(0); tableReport.setOutLineThickness(Double.parseDouble(penElement.getAttributeValue(new QName("lineWidth")))); tableReport.setOutLineColor(penElement.getAttributeValue(new QName("lineColor"))); return tableReport; }
private void reloadContent(OMElement loadedElement) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); List nodeList = xpathExpression.selectNodes(loadedElement); OMElement element = (OMElement) nodeList.get(0); document.getOMDocumentElement().addChild(element); }
protected void setBackgroundColor() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:background//a:band//a:staticText//a:reportElement"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); String backColor = element.getAttributeValue(new QName("backcolor")); report.setBackgroundColour(backColor); }
protected void handleBackgroundColor() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:background//a:band//a:staticText//a:reportElement"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); element.getAttribute(new QName("backcolor")).setAttributeValue(report.getBackgroundColour()); }
private void handleChartBackgroundColor(String chartText) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:" + chartText + "//a:chart//a:reportElement"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); element.getAttribute(new QName("backcolor")).setAttributeValue(chart.getChartBackColor()); }
private void handleTableOutlines() throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:style//a:box//a:pen"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement penElement = (OMElement) nodeList.get(0); penElement.getAttribute(new QName("lineWidth")).setAttributeValue(String.format("%.1g%n", tableReport.getOutLineThickness())); penElement.getAttribute(new QName("lineColor")).setAttributeValue(tableReport.getOutLineColor()); }
public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception { AXIOMXPath xpath = new AXIOMXPath(xpathExpression); if (nsURI != null) { SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace(null, nsURI); xpath.setNamespaceContext(nsContext); } return xpath.selectNodes(element); }
private void addParam(String dsname, String className) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:parameter"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); OMElement documentElement = document.getOMDocumentElement(); List nodeList = xpathExpression.selectNodes(documentElement); OMElement element = (OMElement) nodeList.get(0); OMElement newParam = element.cloneOMElement(); newParam.getAttribute(new QName("name")).setAttributeValue(dsname); newParam.getAttribute(new QName("class")).setAttributeValue(className); documentElement.addChild(newParam); }
private void updateSubReportExpression(OMElement subReportElement, String subReportName) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:subreportExpression"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); List nodeList = xpathExpression.selectNodes(subReportElement); OMElement element = (OMElement) nodeList.get(0); element.setText(""); OMFactory factory = document.getOMFactory(); OMText cdataField = factory.createOMText(element,"$P{" + subReportName + "}", OMText.CDATA_SECTION_NODE); element.addChild(cdataField); }
private void updateSubReportParamName(OMElement subReportElement, String paramName) throws JaxenException { AXIOMXPath xpathExpression = new AXIOMXPath("//a:subreportParameter//a:subreportParameterExpression"); xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports"); List nodeList = xpathExpression.selectNodes(subReportElement); OMElement repExp = (OMElement) nodeList.get(0); repExp.setText(""); OMFactory factory = document.getOMFactory(); OMText cdataField = factory.createOMText(repExp, "$P{" + paramName + "}", OMText.CDATA_SECTION_NODE); repExp.addChild(cdataField); }