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.oaipmh.responses;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.List;
029: import org.fao.oaipmh.OaiPmh;
030: import org.fao.oaipmh.exceptions.OaiPmhException;
031: import org.fao.oaipmh.requests.ListRequest;
032: import org.fao.oaipmh.requests.ListSetsRequest;
033: import org.fao.oaipmh.responses.SetInfo;
034: import org.jdom.Element;
035: import org.jdom.JDOMException;
036: import org.xml.sax.SAXException;
037:
038: //=============================================================================
039:
040: public class ListSetsResponse extends ListResponse {
041: //---------------------------------------------------------------------------
042: //---
043: //--- Constructor
044: //---
045: //---------------------------------------------------------------------------
046:
047: public ListSetsResponse() {
048: }
049:
050: //---------------------------------------------------------------------------
051:
052: public ListSetsResponse(ListRequest lr, Element response) {
053: super (lr, response);
054: }
055:
056: //---------------------------------------------------------------------------
057: //---
058: //--- API methods
059: //---
060: //---------------------------------------------------------------------------
061:
062: public void clearSets() {
063: sets.clear();
064: }
065:
066: //---------------------------------------------------------------------------
067:
068: public void addSet(SetInfo si) {
069: sets.add(si);
070: }
071:
072: //---------------------------------------------------------------------------
073:
074: public SetInfo next() throws IOException, OaiPmhException,
075: JDOMException, SAXException, Exception {
076: return (SetInfo) super .next();
077: }
078:
079: //---------------------------------------------------------------------------
080:
081: public Element toXml() {
082: Element root = new Element(ListSetsRequest.VERB,
083: OaiPmh.Namespaces.OAI_PMH);
084:
085: for (SetInfo si : sets)
086: root.addContent(si.toXml());
087:
088: ResumptionToken token = getResumptionToken();
089:
090: if (token != null)
091: root.addContent(token.toXml());
092:
093: return root;
094: }
095:
096: //---------------------------------------------------------------------------
097: //---
098: //--- Protected methods
099: //---
100: //---------------------------------------------------------------------------
101:
102: protected Object createObject(Element object) {
103: return new SetInfo(object);
104: }
105:
106: //---------------------------------------------------------------------------
107:
108: protected String getListElementName() {
109: return "set";
110: }
111:
112: //---------------------------------------------------------------------------
113: //---
114: //--- Variables
115: //---
116: //---------------------------------------------------------------------------
117:
118: private List<SetInfo> sets = new ArrayList<SetInfo>();
119: }
120:
121: //=============================================================================
|