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.HashMap;
027: import java.util.Map;
028: import org.fao.geonet.util.ISODate;
029: import org.fao.oaipmh.OaiPmh;
030: import org.jdom.Attribute;
031: import org.jdom.Element;
032:
033: //=============================================================================
034:
035: public abstract class AbstractResponse {
036: //---------------------------------------------------------------------------
037: //---
038: //--- Constructor
039: //---
040: //---------------------------------------------------------------------------
041:
042: public AbstractResponse() {
043: responseDate = new ISODate();
044: }
045:
046: //---------------------------------------------------------------------------
047:
048: public AbstractResponse(Element response) {
049: this .response = response;
050: build(response);
051: }
052:
053: //---------------------------------------------------------------------------
054: //---
055: //--- API methods
056: //---
057: //---------------------------------------------------------------------------
058:
059: public Element getResponse() {
060: return response;
061: }
062:
063: public ISODate getResponseDate() {
064: return responseDate;
065: }
066:
067: public abstract Element toXml();
068:
069: //---------------------------------------------------------------------------
070:
071: public void setResponseDate(ISODate date) {
072: responseDate = date;
073: }
074:
075: //---------------------------------------------------------------------------
076: //---
077: //--- Protected methods
078: //---
079: //---------------------------------------------------------------------------
080:
081: protected void add(Element parent, String name, String value) {
082: parent.addContent(new Element(name, OaiPmh.Namespaces.OAI_PMH)
083: .setText(value));
084: }
085:
086: //---------------------------------------------------------------------------
087: //---
088: //--- Private methods
089: //---
090: //---------------------------------------------------------------------------
091:
092: private void build(Element response) {
093: //--- save response date
094:
095: responseDate = new ISODate(response.getChildText(
096: "responseDate", OaiPmh.Namespaces.OAI_PMH));
097:
098: //--- save request parameters
099:
100: Element req = response.getChild("request",
101: OaiPmh.Namespaces.OAI_PMH);
102:
103: for (Object o : req.getAttributes()) {
104: Attribute attr = (Attribute) o;
105: request.put(attr.getName(), attr.getValue());
106: }
107: }
108:
109: //---------------------------------------------------------------------------
110: //---
111: //--- Variables
112: //---
113: //---------------------------------------------------------------------------
114:
115: private Element response;
116: private ISODate responseDate;
117:
118: private Map<String, String> request = new HashMap<String, String>();
119: }
120:
121: //=============================================================================
|