Skip to content

Commit d7a54bb

Browse files
authored
Merge pull request #2 from snyk/master
Pull files
2 parents ee87510 + fbbccb5 commit d7a54bb

File tree

6 files changed

+151
-6
lines changed

6 files changed

+151
-6
lines changed

todolist-web-struts/public/good.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is a good one

todolist-web-struts/src/main/java/io/github/benas/todolist/web/action/todo/TodoAction.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,8 @@ public String doCreate() {
9191
public String doUpload() {
9292
if (this.contentType.equals("application/zip")) {
9393
System.out.println("extracting uploaded zip file");
94-
try {
95-
File safeDir = Files.createTempDirectory("safe").toFile();
96-
ZipUtil.unpack(this.file, safeDir);
97-
} catch (java.io.IOException e) {
98-
99-
}
94+
File publicDir = new File("public");
95+
ZipUtil.unpack(this.file, publicDir);
10096
}
10197
return Action.SUCCESS;
10298
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2015, Mahmoud Ben Hassine ([email protected])
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package io.github.benas.todolist.web.action.user;
26+
27+
import java.io.File;
28+
import java.util.List;
29+
30+
import com.opensymphony.xwork2.Action;
31+
32+
import io.github.benas.todolist.web.action.BaseAction;
33+
import io.github.benas.todolist.web.common.util.TodoListUtils;
34+
import io.github.todolist.core.domain.Todo;
35+
import io.github.todolist.core.domain.User;
36+
37+
/**
38+
* Action class to load user's todo list in home page.
39+
* <p/>
40+
41+
*/
42+
public class FilesAction extends BaseAction {
43+
44+
private List<Todo> todoList;
45+
46+
private int totalCount;
47+
48+
private int doneCount;
49+
50+
private int todoCount;
51+
52+
public String execute() {
53+
User user = getSessionUser();
54+
todoList = todoService.getTodoListByUser(user.getId());
55+
totalCount = todoList.size();
56+
doneCount = TodoListUtils.countTotalDone(todoList);
57+
todoCount = totalCount - doneCount;
58+
return Action.SUCCESS;
59+
}
60+
61+
/*
62+
* Getters for model attributes
63+
*/
64+
65+
public List<Todo> getTodoList() {
66+
return todoList;
67+
}
68+
69+
public String getHomeTabStyle() {
70+
return "active";
71+
}
72+
73+
public int getTotalCount() {
74+
return totalCount;
75+
}
76+
77+
public int getDoneCount() {
78+
return doneCount;
79+
}
80+
81+
public int getTodoCount() {
82+
return todoCount;
83+
}
84+
85+
}

todolist-web-struts/src/main/resources/struts.xml

+11
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
<result>/WEB-INF/views/user/home.jsp</result>
9595
</action>
9696

97+
<action name="files" class="io.github.benas.todolist.web.action.user.FilesAction">
98+
<interceptor-ref name="loginInterceptor"/>
99+
<interceptor-ref name="defaultStack"/>
100+
<result>/WEB-INF/views/user/files.jsp</result>
101+
</action>
102+
97103
<action name="logout" class="io.github.benas.todolist.web.action.user.SessionAction" method="doLogout">
98104
<interceptor-ref name="loginInterceptor"/>
99105
<interceptor-ref name="defaultStack"/>
@@ -146,6 +152,11 @@
146152
<result>/WEB-INF/views/about.jsp</result>
147153
</action>
148154

155+
<action name="files" class="io.github.benas.todolist.web.action.FilesAction">
156+
<result>/WEB-INF/views/files.jsp</result>
157+
</action>
158+
159+
149160
<action name="login" class="io.github.benas.todolist.web.action.user.SessionAction" method="login">
150161
<result>/WEB-INF/views/user/login.jsp</result>
151162
</action>

todolist-web-struts/src/main/webapp/WEB-INF/views/common/sidebar.jspf

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<li><a href="/user/account"><i class="icon-user"></i> My account</a></li>
1111
<li><a href="/todo/new"><i class="icon-file"></i> Create a todo</a></li>
1212
<li><a href="/todo/upload"><i class="icon-file"></i> Upload todo list</a></li>
13+
<li><a href="/user/files"><i class="icon-file"></i>My Files</a></li>
1314
<li class="divider"></li>
1415
<li class="nav-header">Search todo</li>
1516
<li>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2+
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
3+
<%@ taglib prefix="s" uri="/struts-tags"%>
4+
<%@ taglib prefix="tl" uri="http://todolist.org/taglib" %>
5+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
6+
<%@ include file="../common/header.jspf"%>
7+
8+
<div class="container">
9+
<div class="row">
10+
<div class="span3">
11+
<%@ include file="../common/sidebar.jspf"%>
12+
</div>
13+
<div class="span9">
14+
<div class="well">
15+
<div class="page-header">
16+
<h1>My Files</h1>
17+
</div>
18+
19+
<table class="table table-bordered table-striped">
20+
21+
<thead>
22+
<tr>
23+
<th>Files in public folder</th>
24+
</tr>
25+
</thead>
26+
27+
<tbody>
28+
<%@ page import="java.io.*" %>
29+
<%
30+
File f = new File("public");
31+
String [] fileNames = f.list();
32+
File [] fileObjects= f.listFiles();
33+
for (int i = 0; i < fileObjects.length; i++) {
34+
if(!fileObjects[i].isDirectory()){
35+
out.print("<tr>");
36+
out.print("<td>");
37+
out.print(fileNames[i]);
38+
out.print("</td>");
39+
out.print("</tr>");
40+
}
41+
}
42+
%>
43+
</tbody>
44+
</table>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
50+
<%--end content--%>
51+
<%@ include file="../common/footer.jspf"%>

0 commit comments

Comments
 (0)