Jump to content
We've recently updated our Privacy Statement, available here ×

tonynys

Members
  • Posts

    12
  • Joined

  • Last visited

tonynys's Achievements

Rookie

Rookie (2/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. I have exactly the same need; I have a field with an ID and want to use it like this <field name="guarantorName" class="java.lang.String"> <fieldDescription><![CDATA[data/Parties[identifiers/Primary/@Id=$F{guarantor}]/@Name]]></fieldDescription> </field> I've seen the OrdersReport sample in jasper, where a query string is used in the same way with $P{customerID} and this works.But inside the xpath expression above, it doesn't work. Any ideas ? Code: <field name="guarantorName" class="java.lang.String"> <fieldDescription><![CDATA[ResolvedDirectoryData/Parties[identifiers/Primary/@Id=$F{guarantor}]/@Name]]></fieldDescription> </field>
  2. <?xml version="1.0" encoding="UTF-8"?> <n:Northwind xmlns:n="http://www.integrationarchitects.be/ns/Northwind/root" xmlns:c="http://www.integrationarchitects.be/ns/Northwind/customer"> <c:Customers> <c:CustomerID>ALFKI</c:CustomerID> <c:CompanyName>Alfredooooo Futterkiste</c:CompanyName> <c:ContactName>Maria Anders</c:ContactName> <c:ContactTitle>Sales Representative</c:ContactTitle> <c:Address>Obere Str. 57</c:Address> <c:City>Berlin</c:City> <c:PostalCode>12209</c:PostalCode> <c:Country>Germany</c:Country> <c:Phone>030-0074321</c:Phone> <c:Fax>030-0076545</c:Fax> <o:Orders xmlns:o="http://www.integrationarchitects.be/ns/Northwind/order"> <o:OrderID>10954</o:OrderID> <o:CustomerID>LINOD</o:CustomerID> <o:EmployeeID>5</o:EmployeeID> <o:OrderDate>1998-03-17</o:OrderDate> <o:RequiredDate>1998-04-28</o:RequiredDate> <o:ShippedDate>1998-03-20</o:ShippedDate> <o:ShipVia>1</o:ShipVia> <o:Freight>27.91</o:Freight> <o:ShipName>LINO-Delicateses</o:ShipName> <o:ShipAddress>Ave. 5 de Mayo Porlamar</o:ShipAddress> <o:ShipCity>I. de Margarita</o:ShipCity> <o:ShipRegion>Nueva Esparta</o:ShipRegion> <o:ShipPostalCode>4980</o:ShipPostalCode> <o:ShipCountry>Venezuela</o:ShipCountry> </o:Orders>
  3. I got the report working in jasperreports 4.01 outside ireport , just from java commandline, using this as a guidance http://jasperforge.org/projects/jasperreports/tracker/view.php?id=4500 However, In IReport 4.0.1 If I set these properties net.sf.jasperreports.query.executer.factory.xPath=net.sf.jasperreports.engine.query.JaxenXPathQueryExecuterFactory net.sf.jasperreports.query.executer.factory.XPath=net.sf.jasperreports.engine.query.JaxenXPathQueryExecuterFactory net.sf.jasperreports.xml.detect.namespaces=true It doesn't work,, it fails with documentbuilder param not present @narcism: any ideas ?
  4. This is the workaround and it works !, for the moment I hardcode namespace mappings, but this could be set by using a threadlocale set by the client java program Code:import javax.xml.transform.TransformerException;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.util.xml.JRXPathExecuter;import net.sf.jasperreports.engine.util.xml.JRXPathExecuterFactory;import org.apache.xml.utils.PrefixResolver;import org.apache.xpath.CachedXPathAPI;import org.apache.xpath.objects.XObject;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/** * custom xpath exector factory to bypass the bug in jasper for namespace support in xml * datasources; namespaces are not supported at all. * * * run this to use a custom properties file: * System.setProperty("net.sf.jasperreports.properties", "/tmp/tony.jasperreports.properties"); * set this line in the jasper report properties file: * net.sf.jasperreports.xpath.executer.factory=MyXalanXPathExecuterFactory * * @author tony nys * */public class MyXalanXPathExecuterFactory implements JRXPathExecuterFactory{ public MyXalanXPathExecuterFactory(){ System.out.println("MyXalanXPathExecuterFactory............."); } @Override public JRXPathExecuter getXPathExecuter() { return new MyJRXPathExecuter(); } /** * source copied from XalanXPathExecuter from jasperreports * and then tweeked for namespace support * */ public class MyJRXPathExecuter implements JRXPathExecuter{ // XPath API facade private CachedXPathAPI xpathAPI = new CachedXPathAPI(); PrefixResolver resolver=null; public MyJRXPathExecuter(){ System.out.println("MyJRXPathExecuter............."); //maybe link resolver through threadlocale from calling client through a map, //so namespaces can be set dynamically by client program resolver=new MyPrefixResolver(); } public NodeList selectNodeList(Node contextNode, String expression) throws JRException { //System.out.println(",,,selectNodeList"); xpathAPI.getXPathContext().setNamespaceContext(resolver); try { return xpathAPI.selectNodeList(contextNode, expression); } catch (TransformerException e) { throw new JRException("XPath selection failed. Expression: " + expression, e); } } public Object selectObject(Node contextNode, String expression) throws JRException { try { //System.out.println(",,,selectObject"); //xpathAPI.getXPathContext().setNamespaceContext(resolver); Object value; XObject object = xpathAPI.eval(contextNode, expression,resolver); switch (object.getType()) { case XObject.CLASS_NODESET: value = object.nodeset().nextNode(); break; case XObject.CLASS_BOOLEAN: value = object.bool() ? Boolean.TRUE : Boolean.FALSE; break; case XObject.CLASS_NUMBER: value = new Double(object.num()); break; default: value = object.str(); break; } return value; } catch (TransformerException e) { throw new JRException("XPath selection failed. Expression: " + expression, e); } } } //public class MyPrefixResolver extends JAXPPrefixResolver{ public class MyPrefixResolver implements PrefixResolver{ public MyPrefixResolver(){ //super(); } @Override public String getBaseIdentifier() { //System.out.println("///////////////getBaseIdentifier"); return null; } @Override public String getNamespaceForPrefix(String arg0) { //System.out.println("///////////////getNamespaceForPrefix"); //TODO: use threadlocale here... if(arg0.equalsIgnoreCase("v210")){ return "http://wpm.ac.com/solutions/fl/l/core/types/v210"; }else if(arg0.equalsIgnoreCase("wpm-core-common")){ return "http://wpm.ac.com/core/common/types/v210"; }else if(arg0.equalsIgnoreCase("wpm-business-common")){ return "http://wpm.ac.com/business/common/types/v210"; }else if(arg0.equalsIgnoreCase("v2101")){ return "http://wpm.ac.com/solutions/fl/l/configuration/types/v210"; } return null; } @Override public String getNamespaceForPrefix(String arg0, Node arg1) { //System.out.println("///////////////getNamespaceForPrefix2"); //TODO: use threadlocale here... if(arg0.equalsIgnoreCase("v210")){ return "http://wpm.ac.com/solutions/fl/l/core/types/v210"; }else if(arg0.equalsIgnoreCase("wpm-core-common")){ return "http://wpm.ac.com/core/common/types/v210"; }else if(arg0.equalsIgnoreCase("wpm-business-common")){ return "http://wpm.ac.com/business/common/types/v210"; }else if(arg0.equalsIgnoreCase("v2101")){ return "http://wpm.ac.com/solutions/fl/l/configuration/types/v210"; } return null; } @Override public boolean handlesNullPrefixes() { return false; } }}
×
×
  • Create New...