01: //=============================================================================
02: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
03: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
04: //=== and United Nations Environment Programme (UNEP)
05: //===
06: //=== This program is free software; you can redistribute it and/or modify
07: //=== it under the terms of the GNU General Public License as published by
08: //=== the Free Software Foundation; either version 2 of the License, or (at
09: //=== your option) any later version.
10: //===
11: //=== This program is distributed in the hope that it will be useful, but
12: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
13: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: //=== General Public License for more details.
15: //===
16: //=== You should have received a copy of the GNU General Public License
17: //=== along with this program; if not, write to the Free Software
18: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19: //===
20: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
21: //=== Rome - Italy. email: geonetwork@osgeo.org
22: //==============================================================================
23:
24: package org.wfp.vam.intermap.kernel.map.mapServices.arcims;
25:
26: import java.io.File;
27: import jeeves.utils.Xml;
28: import org.jdom.Element;
29: import org.wfp.vam.intermap.util.XmlTransformer;
30:
31: public class AxlRequestBuilder {
32: private static File directory;
33:
34: /**
35: * Initializes the class with the stylesheets contained in the specified
36: * directory
37: *
38: * @param dir the directiry containing the stylesheets
39: *
40: */
41: public static void init(String dir) {
42: directory = new File(dir);
43: }
44:
45: /**
46: * Transform a data Element in the AXL request using a stylesheet
47: *
48: * @param fileName the file name of the stylesheet
49: * @param data the data Element
50: *
51: * @return the AXL request
52: *
53: * @throws Exception
54: *
55: */
56: public static Element getRequest(Element data, String fileName)
57: throws Exception {
58: try // DEBUG
59: {
60: Element stylesheet = Xml.loadFile(directory
61: + File.separator + fileName);
62: Element t = (Element) stylesheet.clone();
63: return XmlTransformer.transform(data, t);
64: } catch (Exception e) {
65: e.printStackTrace();
66: }
67: return null; // DEBUG
68: }
69:
70: /**
71: * Returns an AXL request
72: *
73: * @param fileName the name of the request file
74: *
75: * @return the AXL request (the file content)
76: *
77: */
78: public static Element getRequest(String fileName) throws Exception {
79: Element stylesheet = Xml.loadFile(directory + File.separator
80: + fileName);
81: return stylesheet;
82: }
83:
84: }
|