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.geonet20;
025:
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import jeeves.exceptions.BadInputEx;
029: import jeeves.exceptions.BadParameterEx;
030: import jeeves.utils.Util;
031: import org.fao.geonet.kernel.DataManager;
032: import org.fao.geonet.kernel.harvest.harvester.AbstractParams;
033: import org.fao.geonet.lib.Lib;
034: import org.jdom.Element;
035:
036: //=============================================================================
037:
038: public class GeonetParams extends AbstractParams {
039: //--------------------------------------------------------------------------
040: //---
041: //--- Constructor
042: //---
043: //--------------------------------------------------------------------------
044:
045: public GeonetParams(DataManager dm) {
046: super (dm);
047: }
048:
049: //---------------------------------------------------------------------------
050: //---
051: //--- Create : called when a new entry must be added. Reads values from the
052: //--- provided entry, providing default values
053: //---
054: //---------------------------------------------------------------------------
055:
056: public void create(Element node) throws BadInputEx {
057: super .create(node);
058:
059: Element site = node.getChild("site");
060: Element searches = node.getChild("searches");
061:
062: host = Util.getParam(site, "host", "");
063: port = Util.getParam(site, "port", 80);
064: servlet = Util.getParam(site, "servlet", "geonetwork");
065:
066: checkPort(port);
067: addSearches(searches);
068: }
069:
070: //---------------------------------------------------------------------------
071: //---
072: //--- Update : called when an entry has changed and variables must be updated
073: //---
074: //---------------------------------------------------------------------------
075:
076: public void update(Element node) throws BadInputEx {
077: super .update(node);
078:
079: Element site = node.getChild("site");
080: Element searches = node.getChild("searches");
081:
082: host = Util.getParam(site, "host", host);
083: port = Util.getParam(site, "port", port);
084: servlet = Util.getParam(site, "servlet", servlet);
085:
086: checkPort(port);
087:
088: //--- if some search queries are given, we drop the previous ones and
089: //--- set these new ones
090:
091: if (searches != null)
092: addSearches(searches);
093: }
094:
095: //---------------------------------------------------------------------------
096: //---
097: //--- Other API methods
098: //---
099: //---------------------------------------------------------------------------
100:
101: public Iterable<Search> getSearches() {
102: return alSearches;
103: }
104:
105: //---------------------------------------------------------------------------
106:
107: public GeonetParams copy() {
108: GeonetParams copy = new GeonetParams(dm);
109: copyTo(copy);
110:
111: copy.host = host;
112: copy.port = port;
113: copy.servlet = servlet;
114:
115: for (Search s : alSearches)
116: copy.alSearches.add(s.copy());
117:
118: return copy;
119: }
120:
121: //---------------------------------------------------------------------------
122: //---
123: //--- Private methods
124: //---
125: //---------------------------------------------------------------------------
126:
127: private void addSearches(Element searches) throws BadInputEx {
128: alSearches.clear();
129:
130: if (searches == null)
131: return;
132:
133: Iterator searchList = searches.getChildren("search").iterator();
134:
135: while (searchList.hasNext()) {
136: Element search = (Element) searchList.next();
137:
138: Search s = new Search();
139:
140: s.freeText = Util.getParam(search, "freeText", "");
141: s.title = Util.getParam(search, "title", "");
142: s.abstrac = Util.getParam(search, "abstract", "");
143: s.keywords = Util.getParam(search, "keywords", "");
144: s.digital = Util.getParam(search, "digital", false);
145: s.hardcopy = Util.getParam(search, "hardcopy", false);
146: s.siteId = Util.getParam(search, "siteId", "");
147:
148: alSearches.add(s);
149:
150: if (s.siteId.equals(""))
151: throw new BadParameterEx("siteId", "");
152: }
153: }
154:
155: //---------------------------------------------------------------------------
156: //---
157: //--- Variables
158: //---
159: //---------------------------------------------------------------------------
160:
161: public String host;
162: public int port;
163: public String servlet;
164:
165: private ArrayList<Search> alSearches = new ArrayList<Search>();
166: }
167:
168: //=============================================================================
169:
170: class Search {
171: //---------------------------------------------------------------------------
172: //---
173: //--- API methods
174: //---
175: //---------------------------------------------------------------------------
176:
177: public Search copy() {
178: Search s = new Search();
179:
180: s.freeText = freeText;
181: s.title = title;
182: s.abstrac = abstrac;
183: s.keywords = keywords;
184: s.digital = digital;
185: s.hardcopy = hardcopy;
186: s.siteId = siteId;
187:
188: return s;
189: }
190:
191: //---------------------------------------------------------------------------
192:
193: public Element createRequest() {
194: Element req = new Element("request");
195:
196: Lib.element.add(req, "any", freeText);
197: Lib.element.add(req, "title", title);
198: Lib.element.add(req, "abstract", abstrac);
199: Lib.element.add(req, "themekey", keywords);
200: Lib.element.add(req, "siteId", siteId);
201:
202: if (digital)
203: Lib.element.add(req, "digital", "on");
204:
205: if (hardcopy)
206: Lib.element.add(req, "paper", "on");
207:
208: return req;
209: }
210:
211: //---------------------------------------------------------------------------
212: //---
213: //--- Variables
214: //---
215: //---------------------------------------------------------------------------
216:
217: public String freeText;
218: public String title;
219: public String abstrac;
220: public String keywords;
221: public boolean digital;
222: public boolean hardcopy;
223: public String siteId;
224: }
225:
226: //=============================================================================
|