Skip to content

Commit 11778a9

Browse files
committed
Merge branch 'master' of github.com:OpenGrok/OpenGrok
2 parents 6ca97f8 + adb00c8 commit 11778a9

File tree

18 files changed

+165
-83
lines changed

18 files changed

+165
-83
lines changed

opengrok-web-nbproject/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dist.javadoc.dir=${dist.dir}/javadoc
2525
dist.war=${dist.dir}/${war.name}
2626
endorsed.classpath=
2727
excludes=
28-
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat7-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
28+
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.1.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar
2929
lucene.version=4.6.0
3030
lucene-core.jar=lucene-core-${lucene.version}.jar
3131
lucene-analyzers-common.jar=lucene-analyzers-common-${lucene.version}.jar

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ public String getHeaderIncludeFileContent() {
657657
* contains definition tags.
658658
*/
659659
public static final String EFTAR_DTAGS_FILE = "index/dtags.eftar";
660-
private transient String dtagsEftar = null;
660+
private transient File dtagsEftar = null;
661661

662662
/**
663663
* Get the eftar file, which contains definition tags.
@@ -668,12 +668,10 @@ public File getDtagsEftar() {
668668
if (dtagsEftar == null) {
669669
File tmp = new File(getDataRoot() + "/" + EFTAR_DTAGS_FILE);
670670
if (tmp.canRead()) {
671-
dtagsEftar = tmp.getName();
672-
} else {
673-
dtagsEftar = "";
671+
dtagsEftar = tmp;
674672
}
675673
}
676-
return dtagsEftar.isEmpty() ? null : new File(dtagsEftar);
674+
return dtagsEftar;
677675
}
678676

679677
public String getDatabaseDriver() {

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 rawPrefixE = ctxE + Prefix.RAW_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(rawPrefixE);
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/PageConfig.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.regex.Pattern;
4545
import javax.servlet.http.Cookie;
4646
import javax.servlet.http.HttpServletRequest;
47+
import javax.servlet.ServletRequest;
4748
import org.apache.commons.jrcs.diff.Diff;
4849
import org.apache.commons.jrcs.diff.DifferentiationFailedException;
4950
import org.opensolaris.opengrok.analysis.AnalyzerGuru;
@@ -58,10 +59,10 @@
5859
import org.opensolaris.opengrok.util.IOUtils;
5960

6061
/**
61-
* A simple container to lazy initialize common vars wrt. a single request. It
62-
* MUST NOT be shared between several requests and {@link #cleanup()} should be
63-
* called before the page context gets destroyed (e.g. by overwriting
64-
* {@code jspDestroy()} or when leaving the {@code service} method. <p> Purpose
62+
* A simple container to lazy initialize common vars wrt. a single request.
63+
* It MUST NOT be shared between several requests and
64+
* {@link #cleanup(ServletRequest)} should be called before the page context
65+
* gets destroyed (e.g.when leaving the {@code service} method). <p> Purpose
6566
* is to decouple implementation details from web design, so that the JSP
6667
* developer does not need to know every implementation detail and normally has
6768
* to deal with this class/wrapper, only (so some people may like to call this
@@ -311,8 +312,9 @@ public String canProcess() {
311312
&& !getRequestedRevision().isEmpty() && !hasHistory()) {
312313
return null;
313314
}
314-
} else if (getPrefix() == Prefix.RAW_P) {
315-
return null;
315+
} else if ((getPrefix() == Prefix.RAW_P) ||
316+
(getPrefix() == Prefix.DOWNLOAD_P)) {
317+
return null;
316318
}
317319
}
318320
return redir == null ? "" : redir;
@@ -1201,6 +1203,7 @@ public static PageConfig get(HttpServletRequest request) {
12011203
request.setAttribute(ATTR_NAME, pcfg);
12021204
return pcfg;
12031205
}
1206+
12041207
private static final String ATTR_NAME = PageConfig.class.getCanonicalName();
12051208
private HttpServletRequest req;
12061209

@@ -1209,17 +1212,24 @@ private PageConfig(HttpServletRequest req) {
12091212
}
12101213

12111214
/**
1212-
* Cleanup all allocated resources. Should always be called right before
1213-
* leaving the _jspService / service.
1215+
* Cleanup all allocated resources (if any) from the instance attached to
1216+
* the given request.
1217+
* @param sr request to check, cleanup. Ignored if {@code null}.
1218+
* @see PageConfig#get(HttpServletRequest)
1219+
*
12141220
*/
1215-
public void cleanup() {
1216-
if (req != null) {
1217-
req.removeAttribute(ATTR_NAME);
1218-
req = null;
1221+
public static void cleanup(ServletRequest sr) {
1222+
if (sr == null) {
1223+
return;
12191224
}
1220-
env = null;
1221-
if (eftarReader != null) {
1222-
eftarReader.close();
1225+
PageConfig cfg = (PageConfig) sr.getAttribute(ATTR_NAME);
1226+
if (cfg == null) {
1227+
return;
1228+
}
1229+
sr.removeAttribute(ATTR_NAME);
1230+
cfg.env = null;
1231+
if (cfg.eftarReader != null) {
1232+
cfg.eftarReader.close();
12231233
}
12241234
}
12251235
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public enum Prefix {
6060
/** RSS XML Feed of latest changes (link prefix) */
6161
RSS_P("/rss"),
6262
/** Download file (link prefix) */
63+
DOWNLOAD_P("/download"),
64+
/** Raw file display (link prefix) */
6365
RAW_P("/raw"),
6466
/** full blown search from main page or top bar (link prefix) */
6567
SEARCH_P("/search"),

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},

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import javax.servlet.ServletContext;
3333
import javax.servlet.ServletContextEvent;
3434
import javax.servlet.ServletContextListener;
35+
import javax.servlet.ServletRequestEvent;
36+
import javax.servlet.ServletRequestListener;
3537
import org.opensolaris.opengrok.OpenGrokLogger;
3638
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
3739

@@ -40,7 +42,8 @@
4042
*
4143
* @author Trond Norbye
4244
*/
43-
public final class WebappListener implements ServletContextListener {
45+
public final class WebappListener
46+
implements ServletContextListener, ServletRequestListener {
4447

4548
@Override
4649
public void contextInitialized(final ServletContextEvent servletContextEvent) {
@@ -86,4 +89,20 @@ public void contextInitialized(final ServletContextEvent servletContextEvent) {
8689
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
8790
RuntimeEnvironment.getInstance().stopConfigurationListenerThread();
8891
}
92+
93+
/**
94+
* {@inheritDoc}
95+
*/
96+
@Override
97+
public void requestDestroyed(ServletRequestEvent e) {
98+
PageConfig.cleanup(e.getServletRequest());
99+
}
100+
101+
/**
102+
* {@inheritDoc}
103+
*/
104+
@Override
105+
public void requestInitialized(ServletRequestEvent e) {
106+
// pass through
107+
}
89108
}

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();

0 commit comments

Comments
 (0)