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