1 28 package net.sf.jasperreports.engine.query; 29 30 import java.util.Locale ; 31 import java.util.Map ; 32 import java.util.TimeZone ; 33 34 import net.sf.jasperreports.engine.JRDataSource; 35 import net.sf.jasperreports.engine.JRDataset; 36 import net.sf.jasperreports.engine.JRException; 37 import net.sf.jasperreports.engine.data.JRXmlDataSource; 38 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 import org.w3c.dom.Document ; 42 43 56 public class JRXPathQueryExecuter extends JRAbstractQueryExecuter 57 { 58 private static final Log log = LogFactory.getLog(JRXPathQueryExecuter.class); 59 60 private final Document document; 61 62 public JRXPathQueryExecuter(JRDataset dataset, Map parametersMap) 63 { 64 super(dataset, parametersMap); 65 66 document = (Document ) getParameterValue(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT); 67 68 if (document == null) 69 { 70 log.warn("The supplied org.w3c.dom.Document object is null."); 71 } 72 73 parseQuery(); 74 } 75 76 protected String getParameterReplacement(String parameterName) 77 { 78 return String.valueOf(getParameterValue(parameterName)); 79 } 80 81 public JRDataSource createDatasource() throws JRException 82 { 83 JRXmlDataSource datasource = null; 84 85 String xPath = getQueryString(); 86 87 if (log.isDebugEnabled()) 88 { 89 log.debug("XPath query: " + xPath); 90 } 91 92 if (document != null && xPath != null) 93 { 94 datasource = new JRXmlDataSource(document, xPath); 95 datasource.setLocale((Locale )getParameterValue(JRXPathQueryExecuterFactory.XML_LOCALE)); 96 datasource.setDatePattern((String )getParameterValue(JRXPathQueryExecuterFactory.XML_DATE_PATTERN)); 97 datasource.setNumberPattern((String )getParameterValue(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN)); 98 datasource.setTimeZone((TimeZone )getParameterValue(JRXPathQueryExecuterFactory.XML_TIME_ZONE)); 99 } 100 101 return datasource; 102 } 103 104 public void close() 105 { 106 } 108 109 public boolean cancelQuery() throws JRException 110 { 111 return false; 113 } 114 115 } 116 | Popular Tags |