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.oaipmh.OaiPmh;
030: import org.jdom.Element;
031:
032: //=============================================================================
033:
034: public class Record {
035: //---------------------------------------------------------------------------
036: //---
037: //--- Constructor
038: //---
039: //---------------------------------------------------------------------------
040:
041: public Record() {
042: }
043:
044: //---------------------------------------------------------------------------
045:
046: public Record(Element record) {
047: build(record);
048: }
049:
050: //---------------------------------------------------------------------------
051: //---
052: //--- API methods
053: //---
054: //---------------------------------------------------------------------------
055:
056: public Header getHeader() {
057: return header;
058: }
059:
060: public Element getMetadata() {
061: return metadata;
062: }
063:
064: //---------------------------------------------------------------------------
065:
066: public Iterator<Element> getAbouts() {
067: return abouts.iterator();
068: }
069:
070: //---------------------------------------------------------------------------
071:
072: public void setHeader(Header header) {
073: this .header = header;
074: }
075:
076: //---------------------------------------------------------------------------
077:
078: public void setMetadata(Element metadata) {
079: this .metadata = metadata;
080: }
081:
082: //---------------------------------------------------------------------------
083:
084: public Element toXml() {
085: Element rec = new Element("record", OaiPmh.Namespaces.OAI_PMH);
086: Element md = new Element("metadata", OaiPmh.Namespaces.OAI_PMH);
087:
088: rec.addContent(header.toXml());
089: rec.addContent(md);
090: md.addContent((Element) metadata.clone());
091:
092: for (Element about : abouts)
093: rec.addContent((Element) about.clone());
094:
095: return rec;
096: }
097:
098: //---------------------------------------------------------------------------
099: //---
100: //--- Private methods
101: //---
102: //---------------------------------------------------------------------------
103:
104: private void build(Element record) {
105: Element header = record.getChild("header",
106: OaiPmh.Namespaces.OAI_PMH);
107: Element mdata = record.getChild("metadata",
108: OaiPmh.Namespaces.OAI_PMH);
109:
110: //--- store header
111:
112: this .header = new Header(header);
113:
114: //--- store metadata
115:
116: List list = mdata.getChildren();
117:
118: if (list.size() != 0)
119: metadata = (Element) list.get(0);
120:
121: //--- add about information
122:
123: for (Object o : record.getChildren("about",
124: OaiPmh.Namespaces.OAI_PMH))
125: abouts.add((Element) o);
126: }
127:
128: //---------------------------------------------------------------------------
129: //---
130: //--- Variables
131: //---
132: //---------------------------------------------------------------------------
133:
134: private Header header;
135: private Element metadata;
136:
137: private List<Element> abouts = new ArrayList<Element>();
138: }
139:
140: //=============================================================================
|