/* * SimpleGraphicalClient.java * Copyright (C) 2001 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.nzdl.gsdl.SimpleGraphicalClient; import java.util.*; import java.util.Set; import java.util.TreeSet; import java.util.Iterator; import java.util.Vector; // local libraries import org.nzdl.gsdl.service.NzdlService; import org.nzdl.gsdl.service.NzdlCollectionInfo; /** * Class * * A class to * * @author Dave Nichols (daven@cs.waikato.ac.nz) * @author stuart yeates (say1@cs.waikato.ac.nz) * @version $Revision: 2225 $ * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient */ class CSModel extends Object { Vector collectionList; TreeMap collectionInfoMap; HashMap collectionNameMap; String currentCollection; ResultModel results; NzdlService nzdl; QueryHistoryModel queryHistoryModel; public CSModel(NzdlService newNzdl) { nzdl = newNzdl; results = new ResultModel(); collectionList = new Vector(); collectionInfoMap = new TreeMap(); collectionNameMap = new HashMap(); queryHistoryModel = new QueryHistoryModel(); currentCollection = ""; initialiseCollection(); } public NzdlService getNzdlService() { return nzdl; } public QueryHistoryModel getQueryHistoryModel() { return queryHistoryModel; } /* Result methods */ public ResultModel getResultsModel() { return results; } public void addResult(Result result) { results.add(result); } public void clearResults() { //System.out.println("Clearing resultModel"); results.clear(); } /* collectionList methods */ public Vector getCollectionList() { return new Vector(collectionInfoMap.keySet()); } public Collection getCollectionAsCollection() { return (Collection)collectionInfoMap; } public int getCollectionListSize() { return collectionInfoMap.size(); } public NzdlCollectionInfo getCollectionInfo(String collectionName) { return (NzdlCollectionInfo) collectionInfoMap.get(collectionName); } public String getLongCollectionName(String collectionName) { return (String) collectionNameMap.get(collectionName); } public String getCollectionDescription(String collectionName) { Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra"); if (descSet.size() == 1) return (String) descSet.toArray()[0]; else return "collectionName has more than 1 collectionextra entry"; } public void setCurrentCollection(String collection ) { currentCollection = collection; } public String getCurrentCollection() { return currentCollection; } public String getFirstCollection() { if (getCollectionListSize() > 0) return (String)collectionInfoMap.firstKey(); else return "no collections"; } /** * */ public void initialiseCollection() { Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles TreeSet orderedCollectionSet = new TreeSet(collectionSet); // TreeSet automatically puts strings in alphabetical order System.out.println("Number of collections on the server: " + orderedCollectionSet.size()); Iterator collectionSetIterator = orderedCollectionSet.iterator(); while (collectionSetIterator.hasNext() ) { // object -> String String collectionName = (String)collectionSetIterator.next(); NzdlCollectionInfo info = nzdl.getCollectionInfo(collectionName); if (info != null && info.getBuildDate() != 0) { collectionInfoMap.put(collectionName, info); String longCollectionName = ""; Set n = nzdl.getMetaData(collectionName, "collection", "collectionname"); if (n.size() == 1) longCollectionName = (String) n.toArray()[0]; else longCollectionName = collectionName + " has more than 1 collectionname"; collectionNameMap.put(collectionName,longCollectionName ); System.err.println("Adding " + collectionName + " to collection list..."); } // end if else { System.err.println("Collection " + collectionName + " getBuildDate() returned 0"); } // end else } // end while setCurrentCollection(getFirstCollection()); //assume at least one collection } }