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 java.util.ArrayList;
027: import jeeves.exceptions.BadInputEx;
028: import jeeves.utils.Util;
029: import org.fao.geonet.kernel.DataManager;
030: import org.fao.geonet.kernel.harvest.harvester.AbstractParams;
031: import org.jdom.Element;
032:
033: //=============================================================================
034:
035: public class OaiPmhParams extends AbstractParams {
036: //--------------------------------------------------------------------------
037: //---
038: //--- Constructor
039: //---
040: //--------------------------------------------------------------------------
041:
042: public OaiPmhParams(DataManager dm) {
043: super (dm);
044: }
045:
046: //---------------------------------------------------------------------------
047: //---
048: //--- Create : called when a new entry must be added. Reads values from the
049: //--- provided entry, providing default values
050: //---
051: //---------------------------------------------------------------------------
052:
053: public void create(Element node) throws BadInputEx {
054: super .create(node);
055:
056: Element site = node.getChild("site");
057: Element options = node.getChild("options");
058: Element searches = node.getChild("searches");
059:
060: url = Util.getParam(site, "url", "");
061: icon = Util.getParam(site, "icon", "");
062:
063: validate = Util.getParam(options, "validate", false);
064:
065: addSearches(searches);
066: }
067:
068: //---------------------------------------------------------------------------
069: //---
070: //--- Update : called when an entry has changed and variables must be updated
071: //---
072: //---------------------------------------------------------------------------
073:
074: public void update(Element node) throws BadInputEx {
075: super .update(node);
076:
077: Element site = node.getChild("site");
078: Element options = node.getChild("options");
079: Element searches = node.getChild("searches");
080:
081: url = Util.getParam(site, "url", url);
082: icon = Util.getParam(site, "icon", icon);
083:
084: validate = Util.getParam(options, "validate", validate);
085:
086: //--- if some search queries are given, we drop the previous ones and
087: //--- set these new ones
088:
089: if (searches != null)
090: addSearches(searches);
091: }
092:
093: //---------------------------------------------------------------------------
094: //---
095: //--- Other API methods
096: //---
097: //---------------------------------------------------------------------------
098:
099: public Iterable<Search> getSearches() {
100: return alSearches;
101: }
102:
103: //---------------------------------------------------------------------------
104:
105: public boolean isSearchEmpty() {
106: return alSearches.isEmpty();
107: }
108:
109: //---------------------------------------------------------------------------
110:
111: public OaiPmhParams copy() {
112: OaiPmhParams copy = new OaiPmhParams(dm);
113: copyTo(copy);
114:
115: copy.url = url;
116: copy.icon = icon;
117:
118: copy.validate = validate;
119:
120: for (Search s : alSearches)
121: copy.alSearches.add(s.copy());
122:
123: return copy;
124: }
125:
126: //---------------------------------------------------------------------------
127: //---
128: //--- Private methods
129: //---
130: //---------------------------------------------------------------------------
131:
132: private void addSearches(Element searches) throws BadInputEx {
133: alSearches.clear();
134:
135: if (searches == null)
136: return;
137:
138: for (Object o : searches.getChildren("search")) {
139: Element search = (Element) o;
140:
141: alSearches.add(new Search(search));
142: }
143: }
144:
145: //---------------------------------------------------------------------------
146: //---
147: //--- Variables
148: //---
149: //---------------------------------------------------------------------------
150:
151: public String url;
152: public String icon;
153:
154: public boolean validate;
155:
156: private ArrayList<Search> alSearches = new ArrayList<Search>();
157: }
158:
159: //=============================================================================
|