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