001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036:
037: package com.sun.portal.search.providers.faces;
038:
039: import com.sun.portal.search.demo.Search;
040: import com.sun.portal.search.soif.SOIF;
041: import com.sun.portal.search.soif.SOIFInputStream;
042: import java.util.ArrayList;
043: import java.util.HashSet;
044: import java.util.List;
045: import java.util.logging.Level;
046: import java.util.logging.Logger;
047: import javax.faces.model.ArrayDataModel;
048:
049: public class TaxonomyDatabase extends SearchDatabase {
050: private static Logger logger = SearchLogger
051: .getLogger(TaxonomyDatabase.class);
052:
053: /** Creates a new instance of TaxonomyDatabase */
054: public TaxonomyDatabase(SearchHandler searchHandler,
055: String searchUrl, String database, String displayName) {
056: super (searchHandler, searchUrl, database, displayName);
057: }
058:
059: public ArrayList findChildren(String categoryId) {
060: ArrayList kids = new ArrayList();
061: Search search = new Search();
062: search.setRDMServer(rdmServer);
063: search.setRDMType("taxonomy-request");
064: search.setQueryLanguage("taxonomy-basic");
065: search.setScope("children* " + categoryId);
066: try {
067: search.doQuery(false);
068: SOIFInputStream resultStream = search.getResultStream();
069: if (resultStream == null) {
070: logger.severe("PSCPL_CSPACF00103");
071: } else {
072: SOIF soif;
073:
074: for (soif = resultStream.readSOIF(); soif != null; soif = resultStream
075: .readSOIF()) {
076: if (soif.getSchemaName().equalsIgnoreCase(
077: "classification")) {
078: String cid = soif.getValue("id");
079: Category kid = new Category(searchHandler,
080: searchHandler.getCategoryRoot(), cid);
081: String[] grandkids = soif
082: .getStringValues("child");
083: List gkidsList = new ArrayList();
084: if (grandkids != null) {
085: for (int i = 0; i < grandkids.length; i++) {
086: Category gkid = new Category(
087: searchHandler, searchHandler
088: .getCategoryRoot(), cid
089: + ":" + grandkids[i]);
090: gkidsList.add(gkid);
091: }
092: }
093: kid.setChildrenList(gkidsList);
094: kids.add(kid);
095: }
096: }
097: }
098: } catch (Exception e) {
099: logger.log(Level.SEVERE, "PSCPL_CSPACF00103", e);
100: }
101: return kids;
102: }
103:
104: public ArrayDataModel getHits() {
105: if (hits != null) {
106: return hits;
107: }
108: ArrayList rds = new ArrayList();
109: HashSet ctyIds = new HashSet();
110: Search s = new Search();
111: s.setRDMServer(rdmServer);
112: s.setSessionID(searchHandler.getSessionId());
113:
114: s.setRDMType("taxonomy-request");
115: s.setViewAttributes(null);
116: s.setQueryLanguage("search");
117: s.setScope(this .getQuery());
118:
119: s.setFirstHit((currentPage - 1) * getNumberPerPage() + 1);
120: s.setViewHits(getNumberPerPage());
121: if (viewOrder != null) {
122: s.setViewOrder(viewOrder);
123: }
124:
125: s.setDatabase(databases[0]);
126:
127: s.doQuery();
128: this .total = s.getHitCount();
129: SOIFInputStream resultStream = s.getResultStream();
130: if (resultStream == null) {
131: logger.severe("PSCPL_CSPACF00104");
132: } else {
133: SOIF soif;
134: try {
135: for (soif = resultStream.readSOIF(); soif != null; soif = resultStream
136: .readSOIF()) {
137: String schemaName = soif.getSchemaName();
138: if (schemaName.equalsIgnoreCase("CLASSIFICATION")) {
139: SearchHit hit = SearchHitFactory.getInstance()
140: .createHit(soif,
141: SearchHitFactory.HIT_CATEGORY);
142: hit.setSourceDatabase(this );
143: rds.add(hit);
144: }
145: }
146: } catch (java.io.IOException e) {
147: logger.log(Level.SEVERE, "PSCPL_CSPACF00105", e);
148: }
149: }
150:
151: hits = new ArrayDataModel(rds.toArray());
152: return hits;
153:
154: }
155: }
|