01: /*
02: * ============================================================================
03: * GNU Lesser General Public License
04: * ============================================================================
05: *
06: * JasperReports - Free Java report-generating library.
07: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
08: *
09: * 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.util.xml;
29:
30: import net.sf.jasperreports.engine.JRException;
31: import net.sf.jasperreports.engine.util.JRProperties;
32: import net.sf.jasperreports.engine.util.JRSingletonCache;
33:
34: /**
35: * Helper class used to instantiate {@link JRXPathExecuter XPath executers}.
36: * <p/>
37: * The {@link JRXPathExecuterFactory XPath executer factory} class name is given by the
38: * {@link #PROPERTY_XPATH_EXECUTER_FACTORY net.sf.jasperreports.xpath.executer.factory} property.
39: * The class should have a public default constructor so that it can be instantiated via reflection.
40: * <p/>
41: * By default, {@link XalanXPathExecuter XPath executers} based on <a href="http://xml.apache.org/xalan-j/" target="_blank">Apache Xalan</a>
42: * are used.
43: *
44: * @author Lucian Chirita (lucianc@users.sourceforge.net)
45: * @version $Id: JRXPathExecuterUtils.java 1754 2007-06-14 08:49:36Z lucianc $
46: */
47: public class JRXPathExecuterUtils {
48:
49: /**
50: * Property that holds the {@link JRXPathExecuterFactory XPath executer factory} class name.
51: */
52: public static final String PROPERTY_XPATH_EXECUTER_FACTORY = JRProperties.PROPERTY_PREFIX
53: + "xpath.executer.factory";
54:
55: private static final JRSingletonCache cache = new JRSingletonCache(
56: JRXPathExecuterFactory.class);
57:
58: /**
59: * Return an {@link JRXPathExecuterFactory XPath executer factory} instance.
60: *
61: * @return a JRXPathExecuterFactory instance
62: * @throws JRException if the {@link #PROPERTY_XPATH_EXECUTER_FACTORY XPath factory property} is not defined
63: * or the factory cannot be instantiated.
64: */
65: public static JRXPathExecuterFactory getXPathExecuterFactory()
66: throws JRException {
67: String factoryClassName = JRProperties
68: .getProperty(PROPERTY_XPATH_EXECUTER_FACTORY);
69: if (factoryClassName == null) {
70: throw new JRException(
71: "XPath executer factory property not found. "
72: + "Create a propery named "
73: + PROPERTY_XPATH_EXECUTER_FACTORY + ".");
74: }
75:
76: return (JRXPathExecuterFactory) cache
77: .getCachedInstance(factoryClassName);
78: }
79:
80: /**
81: * Produces an {@link JRXPathExecuter XPath executer} instance by means of the factory
82: * returned by {@link #getXPathExecuterFactory() getXPathExecuterFactory()}.
83: *
84: * @return an JRXPathExecuter instance
85: * @throws JRException if the {@link #PROPERTY_XPATH_EXECUTER_FACTORY XPath factory property} is not defined
86: * or the factory cannot be instantiated.
87: */
88: public static JRXPathExecuter getXPathExecuter() throws JRException {
89: JRXPathExecuterFactory executerFactory = getXPathExecuterFactory();
90: return executerFactory.getXPathExecuter();
91: }
92:
93: }
|