001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet.csw.common;
025:
026: import java.util.HashSet;
027: import java.util.Set;
028: import java.util.StringTokenizer;
029: import org.fao.geonet.csw.common.exceptions.InvalidParameterValueEx;
030: import org.fao.geonet.csw.common.exceptions.MissingParameterValueEx;
031: import org.jdom.Namespace;
032:
033: //=============================================================================
034:
035: public class Csw {
036: //---------------------------------------------------------------------------
037: //---
038: //--- Namespaces
039: //---
040: //---------------------------------------------------------------------------
041:
042: public static final Namespace NAMESPACE_CSW = Namespace
043: .getNamespace("csw", "http://www.opengis.net/cat/csw");
044: public static final Namespace NAMESPACE_OGC = Namespace
045: .getNamespace("ogc", "http://www.opengis.net/ogc");
046: public static final Namespace NAMESPACE_OWS = Namespace
047: .getNamespace("ows", "http://www.opengis.net/ows");
048: public static final Namespace NAMESPACE_ENV = Namespace
049: .getNamespace("env",
050: "http://www.w3.org/2003/05/soap-envelope");
051:
052: //---------------------------------------------------------------------------
053: //---
054: //--- Strings
055: //---
056: //---------------------------------------------------------------------------
057:
058: public static final String SCHEMA_LANGUAGE = "http://www.w3.org/XML/Schema";
059: public static final String SERVICE = "CSW";
060:
061: public static final String CSW_VERSION = "2.0.1";
062: public static final String OWS_VERSION = "1.0.0";
063: public static final String FILTER_VERSION = "1.1.0";
064:
065: //---------------------------------------------------------------------------
066: //---
067: //--- Section
068: //---
069: //---------------------------------------------------------------------------
070:
071: public enum Section {
072: ServiceIdentification, ServiceProvider, OperationsMetadata, Filter_Capabilities
073: }
074:
075: //---------------------------------------------------------------------------
076: //---
077: //--- TypeName
078: //---
079: //---------------------------------------------------------------------------
080:
081: public enum TypeName {
082: DATASET("dataset"), DATASET_COLLECTION("datasetcollection"), SERVICE(
083: "service"), APPLICATION("application");
084:
085: //------------------------------------------------------------------------
086:
087: private TypeName(String typeName) {
088: this .typeName = typeName;
089: }
090:
091: //------------------------------------------------------------------------
092:
093: public String toString() {
094: return typeName;
095: }
096:
097: //------------------------------------------------------------------------
098:
099: public static Set<TypeName> parse(String typeNames)
100: throws InvalidParameterValueEx {
101: HashSet<TypeName> hs = new HashSet<TypeName>();
102:
103: if (typeNames != null) {
104: StringTokenizer st = new StringTokenizer(typeNames, " ");
105:
106: while (st.hasMoreTokens()) {
107: String typeName = st.nextToken();
108:
109: if (typeName.equals(DATASET.toString()))
110: hs.add(DATASET);
111:
112: else if (typeName.equals(DATASET_COLLECTION
113: .toString()))
114: hs.add(DATASET_COLLECTION);
115:
116: else if (typeName.equals(SERVICE.toString()))
117: hs.add(SERVICE);
118:
119: else if (typeName.equals(APPLICATION.toString()))
120: hs.add(APPLICATION);
121:
122: //--- avoid exception because the typeName is too ambiguous and not used now
123: //FIXME else throw new InvalidParameterValueEx("typeName", typeName);
124: }
125: }
126:
127: return hs;
128: }
129:
130: //------------------------------------------------------------------------
131:
132: private String typeName;
133: }
134:
135: //---------------------------------------------------------------------------
136: //---
137: //--- ElementSetName
138: //---
139: //---------------------------------------------------------------------------
140:
141: public enum ElementSetName {
142: BRIEF("brief"), SUMMARY("summary"), FULL("full");
143:
144: //------------------------------------------------------------------------
145:
146: private ElementSetName(String setName) {
147: this .setName = setName;
148: }
149:
150: //------------------------------------------------------------------------
151:
152: public String toString() {
153: return setName;
154: }
155:
156: //------------------------------------------------------------------------
157:
158: public static ElementSetName parse(String setName)
159: throws InvalidParameterValueEx {
160: if (setName == null)
161: return FULL;
162: if (setName.equals(BRIEF.toString()))
163: return BRIEF;
164: if (setName.equals(SUMMARY.toString()))
165: return SUMMARY;
166: if (setName.equals(FULL.toString()))
167: return FULL;
168:
169: throw new InvalidParameterValueEx("elementSetName", setName);
170: }
171:
172: //------------------------------------------------------------------------
173:
174: private String setName;
175: }
176:
177: //---------------------------------------------------------------------------
178: //---
179: //--- ResultType
180: //---
181: //---------------------------------------------------------------------------
182:
183: public enum ResultType {
184: HITS("hits"), RESULTS("results"), VALIDATE("validate");
185:
186: //------------------------------------------------------------------------
187:
188: private ResultType(String type) {
189: this .type = type;
190: }
191:
192: //------------------------------------------------------------------------
193:
194: public String toString() {
195: return type;
196: }
197:
198: //------------------------------------------------------------------------
199:
200: public static ResultType parse(String type)
201: throws InvalidParameterValueEx {
202: if (type == null)
203: return HITS;
204: if (type.equals(HITS.toString()))
205: return HITS;
206: if (type.equals(RESULTS.toString()))
207: return RESULTS;
208: if (type.equals(VALIDATE.toString()))
209: return VALIDATE;
210:
211: throw new InvalidParameterValueEx("resultType", type);
212: }
213:
214: //------------------------------------------------------------------------
215:
216: private String type;
217: }
218:
219: //---------------------------------------------------------------------------
220: //---
221: //--- OutputSchema
222: //---
223: //---------------------------------------------------------------------------
224:
225: public enum OutputSchema {
226: OGC_CORE("Record"), ISO_PROFILE("IsoRecord");
227:
228: //------------------------------------------------------------------------
229:
230: private OutputSchema(String schema) {
231: this .schema = schema;
232: }
233:
234: //------------------------------------------------------------------------
235:
236: public String toString() {
237: return schema;
238: }
239:
240: //------------------------------------------------------------------------
241:
242: public static OutputSchema parse(String schema)
243: throws InvalidParameterValueEx {
244: if (schema == null)
245: return OGC_CORE;
246: if (schema.equals("csw:Record"))
247: return OGC_CORE;
248: if (schema.equals("csw:IsoRecord"))
249: return ISO_PROFILE;
250:
251: throw new InvalidParameterValueEx("outputSchema", schema);
252: }
253:
254: //------------------------------------------------------------------------
255:
256: private String schema;
257: }
258:
259: //---------------------------------------------------------------------------
260: //---
261: //--- ConstraintLanguage
262: //---
263: //---------------------------------------------------------------------------
264:
265: public enum ConstraintLanguage {
266: CQL("CQL_TEXT"), FILTER("FILTER");
267:
268: //------------------------------------------------------------------------
269:
270: private ConstraintLanguage(String language) {
271: this .language = language;
272: }
273:
274: //------------------------------------------------------------------------
275:
276: public String toString() {
277: return language;
278: }
279:
280: //------------------------------------------------------------------------
281:
282: public static ConstraintLanguage parse(String language)
283: throws MissingParameterValueEx, InvalidParameterValueEx {
284: if (language == null)
285: throw new MissingParameterValueEx("constraintLanguage");
286:
287: if (language.equals(CQL.toString()))
288: return CQL;
289: if (language.equals(FILTER.toString()))
290: return FILTER;
291:
292: throw new InvalidParameterValueEx("constraintLanguage",
293: language);
294: }
295:
296: //------------------------------------------------------------------------
297:
298: private String language;
299: }
300: }
301:
302: //=============================================================================
|