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