1 | package jp.co.orkney.restlet.util; |
---|
2 | |
---|
3 | import org.antlr.stringtemplate.StringTemplate; |
---|
4 | import org.antlr.stringtemplate.StringTemplateGroup; |
---|
5 | import org.jdom.Element; |
---|
6 | |
---|
7 | /** |
---|
8 | * Copyright (c) 2007 Orkney, Inc. <http://www.orkney.co.jp/> |
---|
9 | * |
---|
10 | * This program is free software: you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation, either version 3 of the License, or |
---|
13 | * (at your option) any later version. |
---|
14 | * |
---|
15 | * This program is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | */ |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | * <b>Format is a class which represents a data format (Geojson, Gml, Html, ...) .</b> |
---|
27 | * <p> |
---|
28 | * Format object is characterized by the following information: |
---|
29 | * <ul> |
---|
30 | * <li>A name</li> |
---|
31 | * <li>A srid (usually this variable is empty)</li> |
---|
32 | * <li>A boolean to enable or disable the format for input data</li> |
---|
33 | * <li>A boolean to enable or disable the format for output data</li> |
---|
34 | * </ul> |
---|
35 | * </p> |
---|
36 | * |
---|
37 | * @author Matthieu Bilbille - Orkney Inc. |
---|
38 | * @version 1.0 |
---|
39 | */ |
---|
40 | public class Format |
---|
41 | { |
---|
42 | private String name; |
---|
43 | private String srid; |
---|
44 | private boolean enableInput; |
---|
45 | private boolean enableOutput; |
---|
46 | private StringTemplate template; |
---|
47 | |
---|
48 | /** |
---|
49 | * Constructor Format. |
---|
50 | * <p> |
---|
51 | * Creates a new format with empty name and empty srid; "enableInput" and |
---|
52 | * "enableOutput" are initialized with FALSE value. Srid is only needed for |
---|
53 | * format using specific data projection (like KML) |
---|
54 | * </p> |
---|
55 | */ |
---|
56 | public Format() |
---|
57 | { |
---|
58 | name = ""; |
---|
59 | srid = ""; |
---|
60 | enableInput = false; |
---|
61 | enableOutput = false; |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * Constructor Format. |
---|
66 | * <p> |
---|
67 | * Creates a new format with the specified data |
---|
68 | * (name,enableInput,enableOutput). |
---|
69 | * </p> |
---|
70 | * |
---|
71 | * @param name |
---|
72 | * format name |
---|
73 | * @param srid |
---|
74 | * format specific srid (If there is not specific srid for this format, srid is null or empty) |
---|
75 | * @param enableInput |
---|
76 | * boolean to enable or disable the format for input data |
---|
77 | * @param enableOutput |
---|
78 | * boolean to enable or disable the format for output data |
---|
79 | */ |
---|
80 | public Format(String name, String srid, boolean enableInput, boolean enableOutput) |
---|
81 | { |
---|
82 | this.name = name; |
---|
83 | this.srid = srid; |
---|
84 | this.enableInput = enableInput; |
---|
85 | this.enableOutput = enableOutput; |
---|
86 | } |
---|
87 | |
---|
88 | public Format(String name, String srid, boolean enableInput, boolean enableOutput, String template) |
---|
89 | { |
---|
90 | this.name = name; |
---|
91 | this.srid = srid; |
---|
92 | this.enableInput = enableInput; |
---|
93 | this.enableOutput = enableOutput; |
---|
94 | |
---|
95 | StringTemplateGroup group = new StringTemplateGroup("formatGroup", "templates"); |
---|
96 | this.template = group.getInstanceOf(template); |
---|
97 | } |
---|
98 | |
---|
99 | public Format(Element format) |
---|
100 | { |
---|
101 | this.name = format.getAttributeValue("name"); |
---|
102 | this.srid = format.getAttributeValue("srid"); |
---|
103 | this.enableInput = new Boolean(format.getAttributeValue("input")); |
---|
104 | this.enableOutput = new Boolean(format.getAttributeValue("output")); |
---|
105 | |
---|
106 | try |
---|
107 | { |
---|
108 | String path = format.getAttributeValue("path"); |
---|
109 | if(path != null) |
---|
110 | path ="templates/"+path; |
---|
111 | else |
---|
112 | path = "templates"; |
---|
113 | |
---|
114 | StringTemplateGroup group = new StringTemplateGroup("formatGroup", path); |
---|
115 | this.template = group.getInstanceOf(format.getAttributeValue("template")); |
---|
116 | } |
---|
117 | catch (NullPointerException e) |
---|
118 | { |
---|
119 | //Format has no template. |
---|
120 | //Do nothing |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * Gets the name of the format |
---|
127 | * |
---|
128 | * @return this format's name |
---|
129 | */ |
---|
130 | public String getName() |
---|
131 | { |
---|
132 | return name; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * Sets the name of the format to the specified string. |
---|
137 | * |
---|
138 | * @param name |
---|
139 | * the string that is to be this format's name |
---|
140 | */ |
---|
141 | public void setName(String name) |
---|
142 | { |
---|
143 | this.name = name; |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * Gets the srid of the format |
---|
148 | * |
---|
149 | * @return this format's srid |
---|
150 | */ |
---|
151 | public String getSrid() |
---|
152 | { |
---|
153 | return srid; |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | * Sets the srid of the format to the specified string. |
---|
158 | * |
---|
159 | * @param srid |
---|
160 | * the string that is to be this format's srid |
---|
161 | */ |
---|
162 | public void setSrid(String srid) |
---|
163 | { |
---|
164 | this.srid = srid; |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | * Determines whether this format is enabled for input data. A format may be |
---|
169 | * enabled or disabled by calling its setEnableInput method. |
---|
170 | * |
---|
171 | * @return true if the format is enabled for input data, false otherwise |
---|
172 | */ |
---|
173 | public boolean isEnableInput() |
---|
174 | { |
---|
175 | return enableInput; |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Enables or disables this format for input data. Parameters are disabled |
---|
180 | * initially by default. |
---|
181 | * |
---|
182 | * @param enableInput |
---|
183 | * if true, this format is enabled for input data; otherwise this |
---|
184 | * format is disabled for input data |
---|
185 | */ |
---|
186 | public void setEnableInput(boolean enableInput) |
---|
187 | { |
---|
188 | this.enableInput = enableInput; |
---|
189 | } |
---|
190 | |
---|
191 | /** |
---|
192 | * Determines whether this format is enabled for output data. A format may |
---|
193 | * be enabled or disabled by calling its setEnableOutput method. |
---|
194 | * |
---|
195 | * @return true if the format is enabled for output data, false otherwise |
---|
196 | */ |
---|
197 | public boolean isEnableOutput() |
---|
198 | { |
---|
199 | return enableOutput; |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * Enables or disables this format for output data. Parameters are disabled |
---|
204 | * initially by default. |
---|
205 | * |
---|
206 | * @param enableOutput |
---|
207 | * if true, this format is enabled for output data; otherwise |
---|
208 | * this format is disabled for output data |
---|
209 | */ |
---|
210 | public void setEnableOutput(boolean enableOutput) |
---|
211 | { |
---|
212 | this.enableOutput = enableOutput; |
---|
213 | } |
---|
214 | |
---|
215 | public StringTemplate getTemplate() |
---|
216 | { |
---|
217 | return template; |
---|
218 | } |
---|
219 | } |
---|