Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GSDL2ClassifierService.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GSDL2ClassifierService.java	(revision 3453)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GSDL2ClassifierService.java	(revision 3453)
@@ -0,0 +1,230 @@
+/*
+ *    GSDL2ClassifierService.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;
+
+import org.greenstone.gdbm.*;
+import org.greenstone.gsdl3.util.*;
+
+import org.w3c.dom.Document; 
+import org.w3c.dom.Node; 
+import org.w3c.dom.Text; 
+import org.w3c.dom.Element; 
+import org.w3c.dom.NodeList; 
+/**
+ * A Service class for GSDL2-style Classifiers
+ *
+ * @author <a href="mailto:kjdon@cs.waikato.ac.nz">Katherine Don</a>
+ * @version $Revision$
+ */
+public class GSDL2ClassifierService 
+    extends ServiceModule {
+
+    /** gdbm wrapper */
+    private GDBMWrapper gdbm_src_=null;
+
+    public GSDL2ClassifierService() {
+	gdbm_src_ = new GDBMWrapper();
+
+    }
+ 
+    /** processes the request */
+    protected Element processService(String name, Element request) {
+
+	if (!name.equals("ClassifierBrowse")) {
+	    System.err.println("GSDL2ClassifierService:should never get here. service type wrong:"+name);
+	return null;
+	}
+	// the response element
+	Element result = doc_.createElement("response");
+	String from = GSPath.appendLink(collection_name_, "ClassifierBrowse");
+	result.setAttribute("from", from);
+	result.setAttribute("type", "query");
+	Element result_content = doc_.createElement("content");
+	result.appendChild(result_content);
+
+	// get the classifier name out of request content - assume only one for now
+	Element elem = (Element)GSXML.getNodeByPath(request, "content/resourceList/resource");
+	String elem_name = elem.getAttribute("name");
+	System.out.println("elem name="+elem_name);
+
+	if (OID.needsTranslating(elem_name)) {
+	    System.out.println("translating oid");
+	    elem_name = gdbm_src_.translateOID(elem_name);
+	}
+	// get the info from gdbm db
+	DBInfo info = gdbm_src_.getInfo(elem_name);
+
+	// build up the XML
+	Element classifier = doc_.createElement("classifier");
+	
+	String classifier_name = OID.getTop(elem_name);
+	classifier.setAttribute("name", classifier_name);
+	result_content.appendChild(classifier);
+	DBInfo top_info;
+
+	if (elem_name.equals(classifier_name)) { 
+	    top_info = info;
+	} else {
+	    top_info = gdbm_src_.getInfo(classifier_name);
+	}
+
+	// a substitute template - should be read from config file
+	//String extra = "<stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='resource' priority='3'><xsl:param name='collName'>coll-name</xsl:param><xsl:variable name='library' select='ancestor::page/config/library_name'/><td><a href='{$library}?a=r&amp;c={$collName}&amp;r={@name}'><img src='interfaces/default/images/book.gif' width='18' height='11' border='0'/></a></td><td>***</td><td><xsl:value-of select='metadataList/metadata[@name=\"Title\"]'/></td></xsl:template></stylesheet>";
+	//Element extra_doc = converter_.getDOM(extra).getDocumentElement();
+	//result.appendChild(doc_.importNode(extra_doc, true));
+	
+	// get the classifier attributes
+	String type = top_info.getInfo("childtype");
+	if (type.equals("VList")) {
+	    
+	    classifier.setAttribute("type", "vertical");
+	    classifier.setAttribute("interleave", "true");
+	    classifier.setAttribute("link", "icon");
+	}
+	else if (type.equals("HList")){
+	    classifier.setAttribute("type", "horizontal");
+	    classifier.setAttribute("interleave", "false");
+	    classifier.setAttribute("link", "name");
+	} else {
+	    System.out.println("unknown type!!! check this");
+	    classifier.setAttribute("type", "vertical");
+	    classifier.setAttribute("interleave", "true");
+	    classifier.setAttribute("link", "icon");
+	}
+
+	Element this_node;
+	if (elem_name.equals(classifier_name)) {
+	    this_node = classifier;
+	} else { // have to build up the parents 
+	    // the current node
+	    this_node = doc_.createElement("node");
+	    this_node.setAttribute("name", elem_name);
+	    type = info.getInfo("childtype");
+	    if (type.equals("VList")) {
+		this_node.setAttribute("type", "vertical");
+	    } else {
+		this_node.setAttribute("type", "horzizontal");
+	    }
+	    String title = info.getInfo("Title");
+	    Element meta_list = doc_.createElement("metadataList");
+	    GSXML.addMetadata(doc_, meta_list, "Title", title);
+	    this_node.appendChild(meta_list);
+
+	    System.out.println("classifier_name="+classifier_name);
+	    System.out.println("this name="+elem_name);
+	    // the parents
+	    String middle_name = OID.getParent(elem_name);
+	    Element middle_node = this_node;
+	    while (!middle_name.equals(classifier_name)) {
+		System.out.println("middle_name="+middle_name);
+		// add in a new node
+		Element temp_node = doc_.createElement("node");
+		temp_node.setAttribute("name", middle_name);
+		
+		DBInfo i = gdbm_src_.getInfo(middle_name);
+		type = i.getInfo("childtype");
+		if (type.equals("VList")) {
+		    temp_node.setAttribute("type", "vertical");
+		} else {
+		    temp_node.setAttribute("type", "horzizontal");
+		}
+		title = i.getInfo("Title");
+		meta_list = doc_.createElement("metadataList");
+		GSXML.addMetadata(doc_, meta_list, "Title", title);
+		temp_node.appendChild(meta_list);
+
+		// link into the tree
+		temp_node.appendChild(middle_node);
+		middle_node = temp_node;
+		middle_name = OID.getParent(middle_name);
+	    }
+	    classifier.appendChild(middle_node);
+	}
+	// get the child nodes
+	String contains = info.getInfo("contains");
+	// replace the " with parent name
+	contains = OID.translateParent(contains, elem_name);
+	String [] children = contains.split(";");
+	for (int i=0; i<children.length; i++) {
+	    String child = children[i];
+	    DBInfo child_info = gdbm_src_.getInfo(child);
+	    String title = child_info.getInfo("Title");
+	    Element node;
+	    if (child.startsWith("HASH")) {
+		// a resource
+		node = doc_.createElement("resource");
+	    } else { // a node in the classification
+		node = doc_.createElement("node");
+		
+	    }
+	    
+	    node.setAttribute("name", child);
+	    Element meta_list = doc_.createElement("metadataList");
+	    GSXML.addMetadata(doc_, meta_list, "Title", title);
+	    node.appendChild(meta_list);
+	    this_node.appendChild(node);
+	    
+	}
+	
+	System.out.println("classifier result:");
+	System.out.println(converter_.getString(result));
+	return result;
+	
+    }
+    
+
+    /** configure this service */
+    public boolean configure(Element info) {
+
+	System.out.println("configuring GSDL2ClassifierService");
+
+	Element e = null;
+	// these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
+	// set up short_service_info_ - for now just has name and type
+	e = doc_.createElement("service");
+	e.setAttribute("type", "query");
+	e.setAttribute("name", "ClassifierBrowse");
+	short_service_info_.appendChild(e);
+
+	// set up service_info_map_ - for now, just has the same elements as above
+	// should have full details about each service incl params lists etc.
+	e = doc_.createElement("service");
+	e.setAttribute("type", "query");
+	e.setAttribute("name", "ClassifierBrowse");
+
+	// get the classifier list out of the service info
+	Node classList = GSXML.getChildByTagName(info, "classifierList");
+	e.appendChild(doc_.importNode(classList, true));
+
+	service_info_map_.put("ClassifierBrowse", e);
+	
+	if (gdbm_src_.openDatabase(GSFile.GDBMDatabaseFile(site_home_, collection_name_), GDBMWrapper.READER)) {
+	    return true;
+	}
+	else {
+	    System.err.println("couldn't open gdbm database!");
+	    return false;
+	}
+	
+    }
+
+
+}  
+ 
+
