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 org.fao.geonet.util.ISODate;
027: import org.fao.oaipmh.OaiPmh;
028: import org.jdom.Element;
029:
030: //=============================================================================
031:
032: public class ResumptionToken {
033: //---------------------------------------------------------------------------
034: //---
035: //--- Constructor
036: //---
037: //---------------------------------------------------------------------------
038:
039: public ResumptionToken() {
040: }
041:
042: //---------------------------------------------------------------------------
043:
044: public ResumptionToken(String token) {
045: this .token = token;
046: }
047:
048: //---------------------------------------------------------------------------
049:
050: public ResumptionToken(Element rt) {
051: build(rt);
052: }
053:
054: //---------------------------------------------------------------------------
055: //---
056: //--- API methods
057: //---
058: //---------------------------------------------------------------------------
059:
060: public String getToken() {
061: return token;
062: }
063:
064: public ISODate getExpirDate() {
065: return expirDate;
066: }
067:
068: public Integer getCompleteListSize() {
069: return listSize;
070: }
071:
072: public Integer getCursor() {
073: return cursor;
074: }
075:
076: public boolean isTokenEmpty() {
077: return token.length() == 0;
078: }
079:
080: //---------------------------------------------------------------------------
081:
082: public void setToken(String token) {
083: this .token = token;
084: }
085:
086: //---------------------------------------------------------------------------
087:
088: public Element toXml() {
089: Element root = new Element("resumptionToken",
090: OaiPmh.Namespaces.OAI_PMH);
091:
092: root.setText(token);
093:
094: if (expirDate != null)
095: root.setAttribute("expirationDate", expirDate.toString());
096:
097: if (listSize != null)
098: root.setAttribute("completeListSize", listSize.toString());
099:
100: if (cursor != null)
101: root.setAttribute("cursor", cursor.toString());
102:
103: return root;
104: }
105:
106: //---------------------------------------------------------------------------
107: //---
108: //--- Private methods
109: //---
110: //---------------------------------------------------------------------------
111:
112: private void build(Element rt) {
113: token = rt.getText();
114:
115: String expDt = rt.getAttributeValue("expirationDate");
116: String listSz = rt.getAttributeValue("completeListSize");
117: String curs = rt.getAttributeValue("cursor");
118:
119: expirDate = (expDt == null) ? null : new ISODate(expDt);
120: listSize = (listSz == null) ? null : new Integer(listSz);
121: cursor = (curs == null) ? null : new Integer(curs);
122: }
123:
124: //---------------------------------------------------------------------------
125: //---
126: //--- Variables
127: //---
128: //---------------------------------------------------------------------------
129:
130: private String token;
131: private ISODate expirDate;
132: private Integer listSize;
133: private Integer cursor;
134: }
135:
136: //=============================================================================
|