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