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.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.List;
029: import org.fao.geonet.util.ISODate;
030: import org.fao.oaipmh.OaiPmh;
031: import org.fao.oaipmh.util.Lib;
032: import org.jdom.Element;
033:
034: //=============================================================================
035:
036: public class Header {
037: //---------------------------------------------------------------------------
038: //---
039: //--- Constructor
040: //---
041: //---------------------------------------------------------------------------
042:
043: public Header() {
044: }
045:
046: //---------------------------------------------------------------------------
047:
048: public Header(Element header) {
049: build(header);
050: }
051:
052: //---------------------------------------------------------------------------
053: //---
054: //--- API methods
055: //---
056: //---------------------------------------------------------------------------
057:
058: public String getIdentifier() {
059: return identifier;
060: }
061:
062: public ISODate getDateStamp() {
063: return dateStamp;
064: }
065:
066: public boolean isDeleted() {
067: return deleted;
068: }
069:
070: //---------------------------------------------------------------------------
071:
072: public Iterator<String> getSets() {
073: return sets.iterator();
074: }
075:
076: //---------------------------------------------------------------------------
077:
078: public void setIdentifier(String identifier) {
079: this .identifier = identifier;
080: }
081:
082: //---------------------------------------------------------------------------
083:
084: public void setDateStamp(ISODate dateStamp) {
085: this .dateStamp = dateStamp;
086: }
087:
088: //---------------------------------------------------------------------------
089:
090: public void clearSets() {
091: sets.clear();
092: }
093:
094: //---------------------------------------------------------------------------
095:
096: public void addSet(String set) {
097: sets.add(set);
098: }
099:
100: //---------------------------------------------------------------------------
101:
102: public void setDeleted(boolean yesno) {
103: deleted = yesno;
104: }
105:
106: //---------------------------------------------------------------------------
107:
108: public Element toXml() {
109: Element header = new Element("header",
110: OaiPmh.Namespaces.OAI_PMH);
111:
112: Lib.add(header, "identifier", identifier);
113: Lib.add(header, "datestamp", dateStamp + "Z");
114:
115: for (String set : sets)
116: Lib.add(header, "setSpec", set);
117:
118: if (deleted)
119: header.setAttribute("status", "deleted");
120:
121: return header;
122: }
123:
124: //---------------------------------------------------------------------------
125: //---
126: //--- Private methods
127: //---
128: //---------------------------------------------------------------------------
129:
130: private void build(Element header) {
131: Element ident = header.getChild("identifier",
132: OaiPmh.Namespaces.OAI_PMH);
133: Element date = header.getChild("datestamp",
134: OaiPmh.Namespaces.OAI_PMH);
135: String status = header.getAttributeValue("status");
136:
137: //--- store identifier & dateStamp
138:
139: identifier = ident.getText();
140: dateStamp = new ISODate(date.getText());
141: deleted = (status != null);
142:
143: //--- add set information
144:
145: for (Object o : header.getChildren("setSpec",
146: OaiPmh.Namespaces.OAI_PMH)) {
147: Element set = (Element) o;
148: sets.add(set.getText());
149: }
150: }
151:
152: //---------------------------------------------------------------------------
153: //---
154: //--- Variables
155: //---
156: //---------------------------------------------------------------------------
157:
158: private String identifier;
159: private ISODate dateStamp;
160: private boolean deleted;
161:
162: private List<String> sets = new ArrayList<String>();
163: }
164:
165: //=============================================================================
|