01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.workflow;
21:
22: import java.io.IOException;
23: import java.util.HashMap;
24:
25: import javax.xml.transform.TransformerConfigurationException;
26: import javax.xml.transform.TransformerException;
27:
28: import org.apache.log4j.Logger;
29: import org.xml.sax.SAXException;
30:
31: import de.schlund.pfixxml.resources.FileResource;
32: import de.schlund.pfixxml.resources.ResourceUtil;
33: import de.schlund.pfixxml.util.XsltVersion;
34:
35: /**
36: * @author jtl
37: *
38: */
39:
40: public class NavigationFactory {
41: private final static Logger LOG = Logger
42: .getLogger(NavigationFactory.class);
43: private static HashMap<String, Navigation> navis = new HashMap<String, Navigation>();
44: private static NavigationFactory instance = new NavigationFactory();
45:
46: public static NavigationFactory getInstance() {
47: return instance;
48: }
49:
50: public synchronized Navigation getNavigation(String navifilename,
51: XsltVersion xsltVersion) throws Exception {
52: FileResource navifile = ResourceUtil
53: .getFileResourceFromDocroot(navifilename);
54: return getNavigation(navifile, xsltVersion);
55: }
56:
57: public synchronized Navigation getNavigation(FileResource navifile,
58: XsltVersion xsltVersion)
59: throws NavigationInitializationException {
60:
61: Navigation navi = null;
62:
63: navi = navis.get(navifile.toURI().toString());
64:
65: if (navi == null || navi.needsReload()) {
66: LOG.warn("***** Creating Navigation object *******");
67: try {
68: navi = new Navigation(navifile, xsltVersion);
69: } catch (TransformerConfigurationException e) {
70: throw new NavigationInitializationException(
71: "Exception while loading navigation file "
72: + navifile, e);
73: } catch (IOException e) {
74: throw new NavigationInitializationException(
75: "Exception while loading navigation file "
76: + navifile, e);
77: } catch (SAXException e) {
78: throw new NavigationInitializationException(
79: "Exception while loading navigation file "
80: + navifile, e);
81: } catch (TransformerException e) {
82: throw new NavigationInitializationException(
83: "Exception while loading navigation file "
84: + navifile, e);
85: }
86: navis.put(navifile.toURI().toString(), navi);
87: }
88:
89: return navi;
90: }
91: }
|