Results.java revision 151
824N/A/*
824N/A * CDDL HEADER START
824N/A *
824N/A * The contents of this file are subject to the terms of the
824N/A * Common Development and Distribution License (the "License").
824N/A * You may not use this file except in compliance with the License.
824N/A *
824N/A * See LICENSE.txt included in this distribution for the specific
824N/A * language governing permissions and limitations under the License.
824N/A *
824N/A * When distributing Covered Code, include this CDDL HEADER in each
824N/A * file and include the License file at LICENSE.txt.
824N/A * If applicable, add the following below this CDDL HEADER, with the
824N/A * fields enclosed by brackets "[]" replaced with your own identifying
824N/A * information: Portions Copyright [yyyy] [name of copyright owner]
824N/A *
824N/A * CDDL HEADER END
824N/A */
824N/A
824N/A/*
824N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
824N/A * Use is subject to license terms.
824N/A */
824N/A
824N/A/*
824N/A * ident "@(#)Results.java 1.2 06/02/22 SMI"
824N/A */
824N/A
824N/Apackage org.opensolaris.opengrok.search;
824N/A
824N/Aimport java.io.*;
824N/Aimport java.util.*;
824N/A
824N/Aimport org.apache.lucene.search.*;
824N/Aimport org.apache.lucene.document.*;
824N/Aimport org.opensolaris.opengrok.analysis.TagFilter;
824N/Aimport org.opensolaris.opengrok.web.*;
824N/Aimport org.opensolaris.opengrok.search.context.HistoryContext;
824N/Aimport org.opensolaris.opengrok.search.context.Context;
824N/A
824N/Apublic class Results {
824N/A public static void prettyPrintHTML(Hits hits, int start, int end, Writer out,
824N/A Context sourceContext, HistoryContext historyContext,
824N/A Summarizer summer, String urlPrefix,
824N/A String morePrefix,
824N/A String srcRoot,
824N/A String dataRoot,
824N/A EftarFileReader desc
824N/A ) throws IOException {
824N/A char[] content = new char[1024*8];
824N/A LinkedHashMap<String, ArrayList<Document>> dirHash = new LinkedHashMap<String, ArrayList<Document>>();
824N/A for (int i = start; i < end; i++) {
824N/A Document doc = hits.doc(i);
824N/A String rpath = doc.get("path");
824N/A String parent = rpath.substring(0,rpath.lastIndexOf('/'));
824N/A ArrayList<Document> dirDocs = dirHash.get(parent);
824N/A if(dirDocs == null) {
824N/A dirDocs = new ArrayList<Document>();
824N/A dirHash.put(parent, dirDocs);
824N/A }
824N/A dirDocs.add(doc);
824N/A }
824N/A
824N/A for (String parent: dirHash.keySet()) {
824N/A String tag = (desc != null) ? " - <i>" + desc.get(parent) + "</i>": "";
824N/A
824N/A out.write("<tr class=\"dir\"><td colspan=\"2\">&nbsp;&nbsp;<a href=\"");
824N/A out.write(urlPrefix);
824N/A
824N/A File file = new File(parent);
824N/A String path = file.getParent();
824N/A if (path != null) {
824N/A out.write(path);
824N/A }
824N/A out.write('/');
824N/A out.write(Util.URIEncode(file.getName()));
824N/A out.write("/\">" + parent + "/</a>" + tag + "</td></tr>");
824N/A
824N/A boolean alt = false;
824N/A for (Document doc: dirHash.get(parent)) {
824N/A String rpath = doc.get("path");
824N/A String self = rpath.substring(rpath.lastIndexOf('/')+1, rpath.length());
824N/A String selfUrl = urlPrefix + Util.URIEncode(rpath);
824N/A out.write("<tr ");
824N/A if(alt)
824N/A out.write(" class=\"alt\"");
824N/A alt ^= true;
824N/A out.write("><td class=\"f\"><a href=\"" +
824N/A selfUrl + "\">"+self+"</a>&nbsp;</td><td><tt class=\"con\">");
824N/A if (sourceContext != null) {
824N/A String genre = doc.get("t");
824N/A String tags = doc.get("tags");
824N/A try {
824N/A if ("p".equals(genre) && srcRoot != null) {
824N/A sourceContext.getContext(new FileReader(srcRoot + rpath), out, urlPrefix, morePrefix, rpath,
824N/A tags, true, null);
824N/A } else if("x".equals(genre) && dataRoot != null && summer != null){
824N/A Reader r = new TagFilter(new BufferedReader(new FileReader(dataRoot + "/xref" + rpath)));
824N/A int len = r.read(content);
824N/A out.write(summer.getSummary(new String(content, 0, len)).toString());
824N/A } else if("h".equals(genre) && srcRoot != null && summer != null){
824N/A Reader r = new TagFilter(new BufferedReader(new FileReader(srcRoot + rpath)));
824N/A int len = r.read(content);
824N/A out.write(summer.getSummary(new String(content, 0, len)).toString());
824N/A } else {
824N/A sourceContext.getContext(null, out, urlPrefix, morePrefix, rpath, tags, true, null);
824N/A }
824N/A } catch (IOException e) {
824N/A
}
//out.write("Genre = " + genre);
}
if(historyContext != null) {
historyContext.getContext(srcRoot + parent, self, rpath, out);
}
out.write("</tt></td></tr>\n");
}
}
}
}