/* * 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 Katherine Don * @version $Revision: 3453 $ */ 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 = "coll-name***"; //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