/* * GS2Retrieve.java * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org * * 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.greenstone.gsdl3.service; // Greenstone classes import org.greenstone.gdbm.*; import org.greenstone.gsdl3.util.*; // XML classes import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; // General Java classes import java.io.File; import java.util.StringTokenizer; import java.util.Vector; import java.util.Set; import java.util.Iterator; import java.util.ArrayList; /** Implements the generic retrieval and classifier services for GS2 * collections. * * @author Katherine Don * @author Michael Dewsnip * @version $Revision: 6873 $ */ public abstract class GS2Retrieve extends ServiceRack { // the services on offer // these strings must match what is found in the properties file protected static final String DOCUMENT_STRUCTURE_RETRIEVE_SERVICE = "DocumentStructureRetrieve"; protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve"; protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve"; // the browsing services - now in here, these will only be advertised if classifiers have been specified in the config file private static final String CLASSIFIER_SERVICE = "ClassifierBrowse"; private static final String CLASSIFIER_METADATA_SERVICE = "ClassifierBrowseMetadataRetrieve"; protected static final String STRUCT_PARAM = "structure"; protected static final String INFO_PARAM = "info"; protected static final String STRUCT_ANCESTORS = "ancestors"; protected static final String STRUCT_PARENT = "parent"; protected static final String STRUCT_SIBS = "siblings"; protected static final String STRUCT_CHILDREN = "children"; protected static final String STRUCT_DESCENDS = "descendants"; protected static final String STRUCT_ENTIRE = "entire"; protected static final String INFO_NUM_SIBS = "numSiblings"; protected static final String INFO_NUM_CHILDREN = "numChildren"; protected static final String INFO_SIB_POS = "siblingPosition"; protected static final int DOCUMENT=1; protected static final int CLASSIFIER=2; protected GDBMWrapper gdbm_src = null; protected Element config_info = null; // the xml from the config file protected ArrayList replacements = null; /** constructor */ protected GS2Retrieve() { this.gdbm_src = new GDBMWrapper(); } /** configure this service */ public boolean configure(Element info, Element extra_info) { System.out.println("Configuring GS2Retrieve..."); this.config_info = info; // set up short_service_info_ - for now just has name and type Element dsr_service = this.doc.createElement(GSXML.SERVICE_ELEM); dsr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE); dsr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_STRUCTURE_RETRIEVE_SERVICE); this.short_service_info.appendChild(dsr_service); Element dmr_service = this.doc.createElement(GSXML.SERVICE_ELEM); dmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE); dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE); this.short_service_info.appendChild(dmr_service); Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM); dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE); dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE); this.short_service_info.appendChild(dcr_service); // Open GDBM database for querying String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name); if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) { System.err.println("GS2Retrieve Error: Could not open GDBM database!"); return false; } // now do the classifier browse service // check that there are classifiers specified Element class_list = (Element)GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER); if (class_list == null) { // no classifiers specified return true; } // get the display and format elements from the coll config file for // the classifiers extractExtraClassifierInfo(info, extra_info); this.config_info = info; // short_service_info_ - the browse one Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM); cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE); cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE); this.short_service_info.appendChild(cb_service); // metadata retrieval for the browsing Element cbmr_service = this.doc.createElement(GSXML.SERVICE_ELEM); cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE); cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE); this.short_service_info.appendChild(cbmr_service); // the format info Element cb_format_info = this.doc.createElement(GSXML.FORMAT_ELEM); boolean format_found = false; // try the default format first Element def_format = (Element) GSXML.getChildByTagName(info, GSXML.FORMAT_ELEM); if (def_format != null) { cb_format_info.appendChild(GSXML.duplicateWithNewName(this.doc, def_format, GSXML.DEFAULT_ELEM, true)); format_found = true; } // add in to the description a simplified list of classifiers NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM); for(int i=0; i=0; i--) { result.insert(0, separator); result.insert(0, replaceMacros((String)values.elementAt(i))); } } } current_id = relation_id; relation_id = OID.getParent(current_id); } return result.toString(); } protected String replaceMacros(String text) { if (this.replacements == null) { return text; } for (int i=0; i