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