Skip to content

Commit adb00c8

Browse files
author
Vladimir Kotal
committed
Merge pull request #710 from vladak/HAD
add H A D links to directory listing
2 parents e2558a8 + eb7a02c commit adb00c8

File tree

6 files changed

+70
-33
lines changed

6 files changed

+70
-33
lines changed

src/org/opensolaris/opengrok/search/Results.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
143143
String xrefPrefix = sh.contextPath + Prefix.XREF_P;
144144
String morePrefix = sh.contextPath + Prefix.MORE_P;
145145
String xrefPrefixE = ctxE + Prefix.XREF_P;
146-
String histPrefixE = ctxE + Prefix.HIST_L;
147-
String downloadPrefixE = ctxE + Prefix.DOWNLOAD_P;
148146
File xrefDataDir = new File(sh.dataRoot, Prefix.XREF_P.toString());
149147

150148
for (Map.Entry<String, ArrayList<Document>> entry :
@@ -165,17 +163,8 @@ public static void prettyPrint(Writer out, SearchHelper sh, int start,
165163
for (Document doc : entry.getValue()) {
166164
String rpath = doc.get("path");
167165
String rpathE = Util.URIEncodePath(rpath);
168-
out.write("<tr><td class=\"q\"><a href=\"");
169-
out.write(histPrefixE);
170-
out.write(rpathE);
171-
out.write("\" title=\"History\">H</a> <a href=\"");
172-
out.write(xrefPrefixE);
173-
out.write(rpathE);
174-
out.write("?a=true\" title=\"Annotate\">A</a> <a href=\"");
175-
out.write(downloadPrefixE);
176-
out.write(rpathE);
177-
out.write("\" title=\"Download\">D</a>");
178-
out.write("</td>");
166+
out.write("<tr>");
167+
Util.writeHAD(out, sh.contextPath, rpathE, false);
179168
out.write("<td class=\"f\"><a href=\"");
180169
out.write(xrefPrefixE);
181170
out.write(rpathE);

src/org/opensolaris/opengrok/web/DirectoryListing.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private void PrintDateSize(Writer out, File child, Date modTime,
9090
/**
9191
* Write a htmlized listing of the given directory to the given destination.
9292
*
93+
* @param contextPath path used for link prefixes
9394
* @param dir the directory to list
9495
* @param out write destination
9596
* @param path virtual path of the directory (usually the path name of
@@ -103,7 +104,7 @@ private void PrintDateSize(Writer out, File child, Date modTime,
103104
* @throws NullPointerException if a parameter except <var>files</var>
104105
* is {@code null}
105106
*/
106-
public List<String> listTo(File dir, Writer out, String path, List<String> files)
107+
public List<String> listTo(String contextPath, File dir, Writer out, String path, List<String> files)
107108
throws HistoryException, IOException {
108109
// TODO this belongs to a jsp, not here
109110
ArrayList<String> readMes = new ArrayList<String>();
@@ -117,7 +118,7 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
117118
}
118119

119120
out.write("<table id=\"dirlist\">\n");
120-
out.write("<thead>\n<tr><th/><th>Name</th><th>Date</th><th>Size</th>");
121+
out.write("<thead>\n<tr><th/><th>Name</th><th></th><th>Date</th><th>Size</th>");
121122
if (offset > 0) {
122123
out.write("<th><tt>Description</tt></th>");
123124
}
@@ -129,7 +130,7 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
129130
// print the '..' entry even for empty directories
130131
if (path.length() != 0) {
131132
out.write("<tr><td><p class=\"'r'\"/></td><td>");
132-
out.write("<b><a href=\"..\">..</a></b></td>");
133+
out.write("<b><a href=\"..\">..</a></b></td><td></td>");
133134
PrintDateSize(out, dir.getParentFile(), null, dateFormatter);
134135
out.write("</tr>\n");
135136
}
@@ -152,9 +153,11 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
152153
readMes.add(file);
153154
}
154155
boolean isDir = child.isDirectory();
155-
out.write("<tr><td><p class=\"");
156+
out.write("<tr><td>");
157+
out.write("<p class=\"");
156158
out.write(isDir ? 'r' : 'p');
157-
out.write("\"/></td><td><a href=\"");
159+
out.write("\"/>");
160+
out.write("</td><td><a href=\"");
158161
out.write(Util.URIEncodePath(file));
159162
if (isDir) {
160163
out.write("/\"><b>");
@@ -166,6 +169,7 @@ public List<String> listTo(File dir, Writer out, String path, List<String> files
166169
out.write("</a>");
167170
}
168171
out.write("</td>");
172+
Util.writeHAD(out, contextPath, path + file, isDir);
169173
PrintDateSize(out, child, modTimes.get(file), dateFormatter);
170174
if (offset > 0) {
171175
String briefDesc = desc.getChildTag(parentFNode, file);

src/org/opensolaris/opengrok/web/Util.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@
5555
* Class for useful functions.
5656
*/
5757
public final class Util {
58+
private static final Charset UTF8 = Charset.forName("UTF-8");
59+
60+
private static final String SPAN_D = "<span class=\"d\">";
61+
private static final String SPAN_A = "<span class=\"a\">";
62+
private static final String SPAN_E = "</span>";
63+
private static final int SPAN_LEN = SPAN_D.length() + SPAN_E.length();
64+
5865
private Util() {
5966
// singleton
6067
}
6168

62-
private static final Charset UTF8 = Charset.forName("UTF-8");
63-
6469
/**
6570
* Return a string which represents a <code>CharSequence</code> in HTML.
6671
*
@@ -567,6 +572,42 @@ public static String uid2url(String uid) {
567572
return url.substring(0, url.lastIndexOf('/')); // remove date from end
568573
}
569574

575+
/**
576+
* Write the 'H A D' links. This is used for search results and directory
577+
* listings.
578+
*
579+
* @param out writer for producing output
580+
* @param ctxE URI encoded prefix
581+
* @param entry file/directory name to write
582+
* @param is_dir is directory
583+
* @throws IOException depends on the destination (<var>out</var>).
584+
*/
585+
public static void writeHAD(Writer out, String ctxE, String entry,
586+
boolean is_dir) throws IOException {
587+
588+
String histPrefixE = ctxE + Prefix.HIST_L;
589+
String downloadPrefixE = ctxE + Prefix.DOWNLOAD_P;
590+
String xrefPrefixE = ctxE + Prefix.XREF_P;
591+
592+
out.write("<td class=\"q\"><a href=\"");
593+
out.write(histPrefixE);
594+
out.write(entry);
595+
out.write("\" title=\"History\">H</a>");
596+
597+
if (!is_dir) {
598+
out.write(" <a href=\"");
599+
out.write(xrefPrefixE);
600+
out.write(entry);
601+
out.write("?a=true\" title=\"Annotate\">A</a> ");
602+
out.write("<a href=\"");
603+
out.write(downloadPrefixE);
604+
out.write(entry);
605+
out.write("\" title=\"Download\">D</a>");
606+
}
607+
608+
out.write("</td>");
609+
}
610+
570611
/**
571612
* wrapper arround UTF-8 URL encoding of a string
572613
*
@@ -675,11 +716,6 @@ public static String formQuoteEscape(String q) {
675716
return sb.toString();
676717
}
677718

678-
private static final String SPAN_D = "<span class=\"d\">";
679-
private static final String SPAN_A = "<span class=\"a\">";
680-
private static final String SPAN_E = "</span>";
681-
private static final int SPAN_LEN = SPAN_D.length() + SPAN_E.length();
682-
683719
/**
684720
* Tag changes in the given <var>line1</var> and <var>line2</var>
685721
* for highlighting. Removed parts are tagged with CSS class {@code d},

test/org/opensolaris/opengrok/web/DirectoryListingTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ private void validateEntry(Element element) throws Exception {
200200
FileEntry entry = new FileEntry();
201201
NodeList nl = element.getElementsByTagName("td");
202202
int len = nl.getLength();
203-
if (len < 4) {
203+
if (len < 5) {
204204
return;
205205
}
206-
assertEquals(4, len);
206+
assertEquals(5, len);
207207

208208
// item(0) is a decoration placeholder, i.e. no content
209209
entry.name = getFilename(nl.item(1));
210-
entry.lastModified = getLastModified(nl.item(2));
211-
entry.size = getSize(nl.item(3));
210+
entry.lastModified = getLastModified(nl.item(3));
211+
entry.size = getSize(nl.item(4));
212212

213213
// Try to look it up in the list of files
214214
for (int ii = 0; ii < entries.length; ++ii) {
@@ -232,7 +232,7 @@ public void directoryListing() throws Exception {
232232
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<start>\n");
233233

234234
DirectoryListing instance = new DirectoryListing();
235-
instance.listTo(directory, out, directory.getPath(),
235+
instance.listTo("ctx", directory, out, directory.getPath(),
236236
Arrays.asList(directory.list()));
237237

238238
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

web/default/style.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,20 @@ table#dirlist { /* the "Name" column */
438438
margin: 0 0 0 1em;
439439
}
440440

441-
#dirlist td:nth-child(n+2) { /* all but the first column */
441+
#dirlist td:nth-child(n+3) { /* all but the first 2 columns */
442442
padding-right: 1em;
443443
}
444444

445-
#dirlist tbody td:nth-child(4) {
445+
#dirlist tbody td:nth-child(5) {
446446
text-align: right; /* CSS3 may allow " " (single space char) */
447447
}
448448

449+
#dirlist td.q { /* 2nd column: H A D */
450+
white-space: nowrap;
451+
font-size: small;
452+
padding-left: 16px;
453+
width: 3em;
454+
}
449455

450456
/* file display */
451457
#src {

web/list.jsp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ document.pageReady.push(function() { pageReadyList();});
103103
DirectoryListing dl = new DirectoryListing(cfg.getEftarReader());
104104
List<String> files = cfg.getResourceFileList();
105105
if (!files.isEmpty()) {
106-
List<String> readMes = dl.listTo(resourceFile, out, path, files);
106+
List<String> readMes = dl.listTo(
107+
Util.URIEncodePath(request.getContextPath()),
108+
resourceFile, out, path, files);
107109
File[] catfiles = cfg.findDataFiles(readMes);
108110
for (int i=0; i < catfiles.length; i++) {
109111
if (catfiles[i] == null) {

0 commit comments

Comments
 (0)