Skip to content

Commit b10b75f

Browse files
committed
showDotfiles
1 parent bd725de commit b10b75f

File tree

5 files changed

+61
-36
lines changed

5 files changed

+61
-36
lines changed

src/main/java/de/jwi/jfm/Folder.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
import java.io.File;
27+
import java.io.FilenameFilter;
2728
import java.io.FileInputStream;
2829
import java.io.FileNotFoundException;
2930
import java.io.FileOutputStream;
@@ -81,6 +82,8 @@ public class Folder
8182
String url;
8283

8384
private File myFile;
85+
86+
private Map<String,String> options;
8487

8588
File[] children;
8689

@@ -119,12 +122,13 @@ private Folder()
119122
// NOP
120123
}
121124

122-
public Folder(File f, String path, String url)
125+
public Folder(File f, String path, String url, Map<String,String> options)
123126
throws IOException
124127
{
125128
myFile = f;
126129
this.path = path;
127130
this.url = url;
131+
this.options = options;
128132

129133
if (!myFile.exists())
130134
{
@@ -140,7 +144,18 @@ public List<FileWrapper> getFiles()
140144
public void load()
141145
{
142146

143-
children = myFile.listFiles();
147+
children = myFile.listFiles(new FilenameFilter()
148+
{
149+
public boolean accept(File dir, String name)
150+
{
151+
if (name.startsWith(".") && null == options.get("showDotfiles"))
152+
{
153+
return false;
154+
}
155+
return true;
156+
}
157+
}
158+
);
144159

145160
if (children == null)
146161
{

src/main/java/de/jwi/jfm/servlets/Controller.java

+22-23
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.Date;
3434
import java.util.Iterator;
3535
import java.util.List;
36+
import java.util.Map;
37+
import java.util.HashMap;
3638
import java.util.Properties;
3739
import java.util.StringTokenizer;
3840

@@ -63,9 +65,6 @@ public class Controller extends HttpServlet {
6365

6466
private static final String FILE_DOWNLOAD_SERVLET = "/dlf";
6567

66-
private static String version = "unknown";
67-
private static String builddate = "unknown";
68-
6968
private static final String VERSIONCONFIGFILE = "/version.txt";
7069

7170
public static final int NOP_ACTION = 0;
@@ -108,6 +107,8 @@ public class Controller extends HttpServlet {
108107

109108
private String filebase = null;
110109

110+
private Properties versionProperties;
111+
111112
public void init() throws ServletException {
112113
tempDir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir");
113114

@@ -134,23 +135,12 @@ public void init() throws ServletException {
134135
InputStream is = getClass().getResourceAsStream(VERSIONCONFIGFILE);
135136

136137
if (is != null) {
137-
Properties versionProperties = new Properties();
138+
versionProperties = new Properties();
138139
versionProperties.load(is);
139140
is.close();
140-
141-
s = versionProperties.getProperty("version");
142-
if (null != s) {
143-
version = s;
144-
}
145-
146-
s = versionProperties.getProperty("build.date");
147-
if (null != s) {
148-
builddate = s;
149-
}
150-
151141
}
152142
} catch (Exception e) {
153-
e.printStackTrace(System.err);
143+
throw new ServletException(VERSIONCONFIGFILE,e);
154144
}
155145

156146
}
@@ -181,6 +171,19 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
181171

182172
return;
183173
}
174+
175+
String showDotfiles = request.getParameter("showDotfiles");
176+
177+
HttpSession session = request.getSession();
178+
179+
Map<String,String> options = (Map<String,String>)session.getAttribute("options");
180+
if (options == null)
181+
{
182+
options = new HashMap<String,String>();
183+
session.setAttribute("options", options);
184+
}
185+
186+
options.put("showDotfiles", showDotfiles);
184187

185188
File f = new File(filebase, pathInfo);
186189

@@ -213,7 +216,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
213216
String fileURL = requestURI.replaceFirst(contextPath, "");
214217
fileURL = fileURL.replaceFirst(servletPath, "");
215218

216-
folder = new Folder(f, pathInfo, fileURL);
219+
folder = new Folder(f, pathInfo, fileURL, options);
217220

218221
folder.load();
219222

@@ -258,16 +261,12 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
258261

259262
request.setAttribute("date", s);
260263

261-
request.setAttribute("version", version);
264+
request.setAttribute("versionInfo", versionProperties);
262265

263-
request.setAttribute("builddate", builddate);
264-
265266
request.setAttribute("javaversion", System.getProperty("java.version"));
266267

267268
request.setAttribute("serverInfo", getServletContext().getServerInfo());
268269

269-
request.setAttribute("jfmhome", "https://java.net/projects/jfm");
270-
271270
request.setAttribute("url", contextPath);
272271

273272
request.setAttribute("path", pathInfo);
@@ -295,7 +294,7 @@ private String handleQuery(HttpServletRequest request, HttpServletResponse respo
295294
String rc = "";
296295

297296
HttpSession session = request.getSession();
298-
297+
299298
String target = null;
300299
int action = NOP_ACTION;
301300
String[] selectedfiles = request.getParameterValues("index");

src/main/resources/version.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
version=${pom.version}
2-
build.date=${timestamp}
2+
buildDate=${timestamp}
3+
jfmHome=${project.url}
4+
copyRight=2004,2019 J&uuml;rgen Weber

src/main/webapp/WEB-INF/fm.jsp

+19-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313

1414

1515
<body bgcolor="#FFFFFF">
16-
<h3>jFM - File Manager </h3>
17-
18-
<c:if test="${!principal}">
19-
<a href="${self}${path}?logout=t" title="Log out">log out ${principal}</a>
20-
</c:if>
21-
<p>
16+
<h3>jFM - File Manager</h3>
2217

2318
<span style="color: rgb(255, 0, 0);">${actionresult}</span>
2419

@@ -342,11 +337,28 @@ File upload and unzip to current directory
342337

343338
</c:if>
344339

340+
<table>
341+
<tbody>
342+
343+
<tr>
344+
<td colspan="4" class="header-left">Options</td>
345+
</tr>
346+
<tr>
347+
<td class="row-center"><form name="options" action="${self}${path}"><input type="checkbox" <c:if test="${not empty options.showDotfiles}">checked="on"</c:if> name="showDotfiles" title="show dot files">show dot files
348+
<input type="submit" value="setoptions" /> </form>
349+
</td>
350+
</tr>
351+
352+
</tbody>
353+
</table>
354+
355+
356+
345357
<table border="0">
346358
<tbody>
347359
<tr>
348360

349-
<td class="row-left"><small><a href="${jfmhome}" title="${jfmhome}">jFM ${version}</a>(${builddate}) Copyright &copy; 2004,2016 J&uuml;rgen Weber</small></td>
361+
<td class="row-left"><small><a href="${versionInfo.jfmHome}" title="${versionInfo.jfmHome}">jFM ${versionInfo.version}</a> (${versionInfo.buildDate}) Copyright &copy; ${versionInfo.copyRight}</small></td>
350362

351363
<td class="row-right"><small>jFM running on Java ${javaversion}, ${serverInfo}</small></td>
352364

src/main/webapp/WEB-INF/version.properties

-3
This file was deleted.

0 commit comments

Comments
 (0)