KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > query > JRXPathQueryExecuter


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.query;
29
30 import java.util.Locale JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.TimeZone JavaDoc;
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 JavaDoc;
42
43 /**
44  * XPath query executer implementation.
45  * <p/>
46  * The XPath query of the report is executed against the document specified by the
47  * {@link net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory#PARAMETER_XML_DATA_DOCUMENT PARAMETER_XML_DATA_DOCUMENT}
48  * parameter.
49  * <p/>
50  * All the paramters in the XPath query are replaced by calling <code>String.valueOf(Object)</code>
51  * on the parameter value.
52  *
53  * @author Lucian Chirita (lucianc@users.sourceforge.net)
54  * @version $Id: JRXPathQueryExecuter.java 1538 2006-12-22 17:04:25 +0200 (Fri, 22 Dec 2006) teodord $
55  */

56 public class JRXPathQueryExecuter extends JRAbstractQueryExecuter
57 {
58     private static final Log log = LogFactory.getLog(JRXPathQueryExecuter.class);
59     
60     private final Document JavaDoc document;
61     
62     public JRXPathQueryExecuter(JRDataset dataset, Map JavaDoc parametersMap)
63     {
64         super(dataset, parametersMap);
65                 
66         document = (Document JavaDoc) 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 JavaDoc getParameterReplacement(String JavaDoc parameterName)
77     {
78         return String.valueOf(getParameterValue(parameterName));
79     }
80
81     public JRDataSource createDatasource() throws JRException
82     {
83         JRXmlDataSource datasource = null;
84         
85         String JavaDoc 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 JavaDoc)getParameterValue(JRXPathQueryExecuterFactory.XML_LOCALE));
96             datasource.setDatePattern((String JavaDoc)getParameterValue(JRXPathQueryExecuterFactory.XML_DATE_PATTERN));
97             datasource.setNumberPattern((String JavaDoc)getParameterValue(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN));
98             datasource.setTimeZone((TimeZone JavaDoc)getParameterValue(JRXPathQueryExecuterFactory.XML_TIME_ZONE));
99         }
100         
101         return datasource;
102     }
103
104     public void close()
105     {
106         //nothing to do
107
}
108
109     public boolean cancelQuery() throws JRException
110     {
111         //nothing to cancel
112
return false;
113     }
114     
115 }
116
Popular Tags