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.kernel.harvest.harvester.oaipmh;
025:
026: import jeeves.exceptions.BadInputEx;
027: import jeeves.exceptions.BadParameterEx;
028: import jeeves.utils.Util;
029: import org.fao.geonet.util.ISODate;
030: import org.jdom.Element;
031:
032: //=============================================================================
033:
034: class Search {
035: //---------------------------------------------------------------------------
036: //---
037: //--- Constructor
038: //---
039: //---------------------------------------------------------------------------
040:
041: private Search() {
042: }
043:
044: //---------------------------------------------------------------------------
045:
046: public Search(Element search) throws BadInputEx {
047: from = Util.getParam(search, "from", "");
048: until = Util.getParam(search, "until", "");
049: set = Util.getParam(search, "set", "");
050: prefix = Util.getParam(search, "prefix", "oai_dc");
051: stylesheet = Util.getParam(search, "stylesheet", "");
052:
053: //--- check from parameter
054:
055: ISODate fromDate = null;
056: ISODate untilDate = null;
057:
058: try {
059: if (from != "") {
060: fromDate = new ISODate(from);
061: from = fromDate.getDate();
062: }
063:
064: } catch (Exception e) {
065: throw new BadParameterEx("from", from);
066: }
067:
068: //--- check until parameter
069:
070: try {
071: if (until != "") {
072: untilDate = new ISODate(until);
073: until = untilDate.getDate();
074: }
075: } catch (Exception e) {
076: throw new BadParameterEx("until", until);
077: }
078:
079: //--- check from <= until
080:
081: if (fromDate != null && untilDate != null)
082: if (fromDate.sub(untilDate) > 0)
083: throw new BadParameterEx("from greater than until",
084: from + ">" + until);
085: }
086:
087: //---------------------------------------------------------------------------
088: //---
089: //--- API methods
090: //---
091: //---------------------------------------------------------------------------
092:
093: public Search copy() {
094: Search s = new Search();
095:
096: s.from = from;
097: s.until = until;
098: s.set = set;
099: s.prefix = prefix;
100: s.stylesheet = stylesheet;
101:
102: return s;
103: }
104:
105: //---------------------------------------------------------------------------
106:
107: public static Search createEmptySearch() throws BadInputEx {
108: Search s = new Search();
109:
110: s.from = "";
111: s.until = "";
112: s.set = "";
113: s.prefix = "oai_dc";
114: s.stylesheet = "";
115:
116: return s;
117: }
118:
119: //---------------------------------------------------------------------------
120: //---
121: //--- Variables
122: //---
123: //---------------------------------------------------------------------------
124:
125: public String from;
126: public String until;
127: public String set;
128: public String prefix;
129: public String stylesheet;
130: }
131:
132: //=============================================================================
|