diff --git a/IF3110-02-Simple-Blog-Java/build.xml b/IF3110-02-Simple-Blog-Java/build.xml new file mode 100644 index 00000000..ec29b4ea --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project IF3110-02-Simple-Blog-Java. + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/AddNewPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/AddNewPost.jsp new file mode 100644 index 00000000..4dc1b654 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/AddNewPost.jsp @@ -0,0 +1,84 @@ +<%-- + Document : AddNewPost + Created on : Nov 23, 2014, 7:41:49 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Editor")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+

-

+ +
+
+

Add New Post

+ +
+
+ + + + + + +
+ + + +
+
+
+
+
+ + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/AddNewPostStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/AddNewPostStatus.jsp new file mode 100644 index 00000000..83c5129b --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/AddNewPostStatus.jsp @@ -0,0 +1,75 @@ +<%-- + Document : AddNewPostStatus + Created on : Nov 23, 2014, 8:41:53 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Editor")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Owner"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("AddNewPostStatus") %>

+

Continue...

+
+
+ + +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/DeletePostStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/DeletePostStatus.jsp new file mode 100644 index 00000000..05fd22de --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/DeletePostStatus.jsp @@ -0,0 +1,76 @@ +<%-- + Document : DeletePostStatus + Created on : Nov 23, 2014, 10:08:40 PM + Author : Asep Saepudin +--%> + +<%-- + Document : AddNewPostStatus + Created on : Nov 23, 2014, 8:41:53 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Delete Post + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("DeletePostStatus") %>

+

Continue...

+
+
+ + +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/DeletionStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/DeletionStatus.jsp new file mode 100644 index 00000000..7cc60c28 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/DeletionStatus.jsp @@ -0,0 +1,69 @@ +<%-- + Document : DeletionFailed + Created on : Nov 23, 2014, 6:23:16 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Delete User + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("deleteUser") %>

+

Continue...

+
+
+ + +
+ + + +
+ + diff --git a/IF3110-02-Simple-Blog-Java/build/web/EditPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/EditPost.jsp new file mode 100644 index 00000000..46148d96 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/EditPost.jsp @@ -0,0 +1,97 @@ +<%-- + Document : EditPost + Created on : Nov 23, 2014, 10:12:56 PM + Author : Asep Saepudin +--%> + +<%@page import="java.text.Format"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Edit Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + + Post editedPost = (Post)request.getSession().getAttribute("editedPost"); + if (editedPost == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+

-

+ +
+
+

Edit Post

+ +
+
+ + + + + + + <% + Date date = editedPost.getTanggal(); + Format formatter = new SimpleDateFormat("MM/dd/yyyy"); + %> + + + +
+ + + +
+
+
+
+
+ + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/EditUser.jsp b/IF3110-02-Simple-Blog-Java/build/web/EditUser.jsp new file mode 100644 index 00000000..3ad3b321 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/EditUser.jsp @@ -0,0 +1,104 @@ +<%-- + Document : EditUser + Created on : Nov 23, 2014, 6:41:33 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Edit User + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + request.getSession().setAttribute("adminOnly", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "AdminOnly.jsp"); + } + User editedUser = (User)request.getSession().getAttribute("editedUser"); + if (editedUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "UserManagement"); + } + %> + + +
+ + + +
+ + +

-

+ +
+
+

Edit User

+ +
+
+
+ + + + + + + + + + + + +
+ +
+
+
+
+ +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/Login.jsp b/IF3110-02-Simple-Blog-Java/build/web/Login.jsp new file mode 100644 index 00000000..d0d98197 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/Login.jsp @@ -0,0 +1,73 @@ +<%-- + Document : LoginPage + Created on : Nov 20, 2014, 8:30:01 PM + Author : Asep Saepudin +--%> + +<%@page import="org.apache.jasper.tagplugins.jstl.ForEach"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Login + + <% if (request.getSession().getAttribute("currentUser") != null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+

-

+ +
+
+

Login

+ +
+
+ + + + + + + +
+
+
+
+
+ + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/META-INF/MANIFEST.MF b/IF3110-02-Simple-Blog-Java/build/web/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/IF3110-02-Simple-Blog-Java/build/web/PublishPostStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/PublishPostStatus.jsp new file mode 100644 index 00000000..57cfa881 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/PublishPostStatus.jsp @@ -0,0 +1,74 @@ +<%-- + Document : PublishPostStatus + Created on : Nov 23, 2014, 9:44:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Publish Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Owner")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("PublishPostStatus") %>

+

Continue...

+
+
+ + +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/PublishedPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/PublishedPost.jsp new file mode 100644 index 00000000..08da2680 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/PublishedPost.jsp @@ -0,0 +1,95 @@ +<%-- + Document : PublishedPost + Created on : Nov 23, 2014, 9:38:08 PM + Author : Asep Saepudin +--%> + +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Published Posts + + <% User currentUser = (User)request.getSession().getAttribute("currentUser"); %> + +
+ + + +
+
+ +
+
+ + + +
+ + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/Register.jsp b/IF3110-02-Simple-Blog-Java/build/web/Register.jsp new file mode 100644 index 00000000..c7952841 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/Register.jsp @@ -0,0 +1,97 @@ +<%-- + Document : register + Created on : Nov 20, 2014, 10:35:52 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New User + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + request.getSession().setAttribute("adminOnly", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "AdminOnly.jsp"); + } + %> + + +
+ + + +
+ + +

-

+ +
+
+

Add New User

+ +
+
+ + + + + + + + + + + +
+ +
+
+
+
+ +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/RegistrationStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/RegistrationStatus.jsp new file mode 100644 index 00000000..ecdd4c66 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/RegistrationStatus.jsp @@ -0,0 +1,68 @@ +<%-- + Document : registerfailed + Created on : Nov 20, 2014, 10:52:29 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("registerUser") %>

+

Continue...

+
+
+ + +
+ + + +
+ + diff --git a/IF3110-02-Simple-Blog-Java/build/web/SoftDeletedPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/SoftDeletedPost.jsp new file mode 100644 index 00000000..8b8d46f8 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/SoftDeletedPost.jsp @@ -0,0 +1,100 @@ +<%-- + Document : UnpublishedPost + Created on : Nov 23, 2014, 9:27:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Deleted Posts + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Editor"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+
+ +
+
+ + + +
+ + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/UndeletePostStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/UndeletePostStatus.jsp new file mode 100644 index 00000000..54721288 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/UndeletePostStatus.jsp @@ -0,0 +1,74 @@ +<%-- + Document : PublishPostStatus + Created on : Nov 23, 2014, 9:44:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Undelete Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("UndeletePostStatus") %>

+

Continue...

+
+
+ + +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/UnpublishedPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/UnpublishedPost.jsp new file mode 100644 index 00000000..12b667fe --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/UnpublishedPost.jsp @@ -0,0 +1,107 @@ +<%-- + Document : UnpublishedPost + Created on : Nov 23, 2014, 9:27:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Unpublished Posts + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Owner")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Editor"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
+ + + +
+
+ +
+
+ + + +
+ + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/UpdatePostStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/UpdatePostStatus.jsp new file mode 100644 index 00000000..112a970c --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/UpdatePostStatus.jsp @@ -0,0 +1,69 @@ +<%-- + Document : UpdatePostStatus + Created on : Nov 23, 2014, 10:25:28 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Update Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("UpdatePostStatus") %>

+

Continue...

+
+
+ + +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/UpdateUserStatus.jsp b/IF3110-02-Simple-Blog-Java/build/web/UpdateUserStatus.jsp new file mode 100644 index 00000000..04b03b69 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/UpdateUserStatus.jsp @@ -0,0 +1,68 @@ +<%-- + Document : SuccessfullyUpdated + Created on : Nov 23, 2014, 7:04:52 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("updateUser") %>

+

Continue...

+
+
+ + +
+ + + +
+ + diff --git a/IF3110-02-Simple-Blog-Java/build/web/UserManagement.jsp b/IF3110-02-Simple-Blog-Java/build/web/UserManagement.jsp new file mode 100644 index 00000000..c6db74b1 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/UserManagement.jsp @@ -0,0 +1,96 @@ +<%-- + Document : UserManagement + Created on : Nov 23, 2014, 5:12:43 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.UserDAO"%> +<%@page import="org.apache.jasper.tagplugins.jstl.ForEach"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPostsLogin.jsp"); + } + if (!currentUser.getRole().equals("Admin")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts.jsp"); + } + %> + + +
+ + + +
+
+ +
+
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/Uuuppssss.jsp b/IF3110-02-Simple-Blog-Java/build/web/Uuuppssss.jsp new file mode 100644 index 00000000..df6b229d --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/Uuuppssss.jsp @@ -0,0 +1,60 @@ +<%-- + Document : AdminOnly + Created on : Nov 23, 2014, 5:10:08 PM + Author : Asep Saepudin +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Ups + + +
+ + + +
+ +
+
+ +

<%= (String)request.getSession().getAttribute("forbidden") %>

+

Continue...

+
+
+ + +
+ + + +
+ + diff --git a/IF3110-02-Simple-Blog-Java/build/web/ViewPost.jsp b/IF3110-02-Simple-Blog-Java/build/web/ViewPost.jsp new file mode 100644 index 00000000..b4fd5a11 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/ViewPost.jsp @@ -0,0 +1,115 @@ +<%-- + Document : ViewPost + Created on : Nov 23, 2014, 11:27:55 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | View Post + + <% + Post post = (Post)request.getSession().getAttribute("post"); + if (post == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + %> + + +
+ + + +
+ +
+
+ +

<%= post.getJudul() %>

+

+
+
+ +
+
+
+

<%= post.getKonten() %>

+ +
+ + <% if (post.getStatus().equals("Published")) { %> +

Komentar

+ +
+
+ + + + <% if (currentUser == null) { %> + + <% } else {%> + + <% }%> + + + <% if (currentUser == null) { %> + + <% } else {%> + + <% }%> + +
+ + + +
+
+ +
    + +
+ <% } %> +
+
+ +
+ + + +
+ + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/.netbeans_automatic_build b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/.netbeans_update_resources b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/AddNewPostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/AddNewPostServlet.class new file mode 100644 index 00000000..1908212b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/AddNewPostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Comment.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Comment.class new file mode 100644 index 00000000..5fd94d10 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Comment.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CommentDAO.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CommentDAO.class new file mode 100644 index 00000000..454029c6 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CommentDAO.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ConnectionManager.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ConnectionManager.class new file mode 100644 index 00000000..8691ec04 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ConnectionManager.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CookieManager.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CookieManager.class new file mode 100644 index 00000000..8d218e38 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CookieManager.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomHttpSessionListener.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomHttpSessionListener.class new file mode 100644 index 00000000..b3811fc4 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomHttpSessionListener.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomServletContextListener.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomServletContextListener.class new file mode 100644 index 00000000..3365051f Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/CustomServletContextListener.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeletePostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeletePostServlet.class new file mode 100644 index 00000000..408fa268 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeletePostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeleteUserServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeleteUserServlet.class new file mode 100644 index 00000000..51d0e6fb Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/DeleteUserServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoadCommentServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoadCommentServlet.class new file mode 100644 index 00000000..e980792b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoadCommentServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoginServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoginServlet.class new file mode 100644 index 00000000..8d30afbf Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LoginServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LogoutServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LogoutServlet.class new file mode 100644 index 00000000..d475c966 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/LogoutServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Post.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Post.class new file mode 100644 index 00000000..ebde255e Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/Post.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PostDAO.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PostDAO.class new file mode 100644 index 00000000..da5babab Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PostDAO.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishPostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishPostServlet.class new file mode 100644 index 00000000..7f61621b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishPostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishedPostsServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishedPostsServlet.class new file mode 100644 index 00000000..c685e6b9 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/PublishedPostsServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/RegisterServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/RegisterServlet.class new file mode 100644 index 00000000..1d88f603 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/RegisterServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SaveCommentServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SaveCommentServlet.class new file mode 100644 index 00000000..9526c993 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SaveCommentServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SofDeletePostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SofDeletePostServlet.class new file mode 100644 index 00000000..be86e4ab Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SofDeletePostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SoftDeleteServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SoftDeleteServlet.class new file mode 100644 index 00000000..eaa21ab3 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/SoftDeleteServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UndeletePostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UndeletePostServlet.class new file mode 100644 index 00000000..50440182 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UndeletePostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UnpublishedPostsServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UnpublishedPostsServlet.class new file mode 100644 index 00000000..f1f94871 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UnpublishedPostsServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdatePostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdatePostServlet.class new file mode 100644 index 00000000..ebdfbbb7 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdatePostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdateUserServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdateUserServlet.class new file mode 100644 index 00000000..ae420d0b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UpdateUserServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/User.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/User.class new file mode 100644 index 00000000..f1382853 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/User.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserDAO.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserDAO.class new file mode 100644 index 00000000..05c12651 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserDAO.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserManagementServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserManagementServlet.class new file mode 100644 index 00000000..bf7bd68d Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/UserManagementServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ViewPostServlet.class b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ViewPostServlet.class new file mode 100644 index 00000000..84277179 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/classes/wbd/tubesII/ViewPostServlet.class differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar new file mode 100644 index 00000000..dd2585e0 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/sun-web.xml b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/sun-web.xml new file mode 100644 index 00000000..1ac7af40 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/sun-web.xml @@ -0,0 +1,11 @@ + + + + + + + Keep a copy of the generated servlet class' java code. + + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/web.xml b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/web.xml new file mode 100644 index 00000000..d310ba83 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/PublishedPosts + + + + wbd.tubesII.CustomServletContextListener + + + + + + wbd.tubesII.CustomHttpSessionListener + + + diff --git a/IF3110-02-Simple-Blog-Java/build/web/assets/css/screen.css b/IF3110-02-Simple-Blog-Java/build/web/assets/css/screen.css new file mode 100644 index 00000000..ea2188e4 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/assets/css/screen.css @@ -0,0 +1,862 @@ +@import url(http://fonts.googleapis.com/css?family=Open+Sans); +@import url(http://fonts.googleapis.com/css?family=Questrial); + +/* Reset & Basics (Inspired by E. Meyers) +================================================== */ +html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, address, cite, code, em, img, small, strong, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, embed, figure, figcaption, footer, header, hgroup, menu, nav, section, summary, time, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; } +article, aside, details, figcaption, figure, footer, header, hgroup, menu, time, nav, section { + display: block; } +html, body, .wrapper { + min-height: 100%; +} + + +/* Body +================================================== */ +html, body { + height: 100%; +} +.wrapper { + min-height: 100%; +} +body { + overflow-x: hidden; + font: 17px/28px ff-meta-serif-web-pro, "Georgia", serif; + color: #333; + background: #fff; +} + + +/* Typography +================================================== */ +h1, h2, h3, h4, h5, h6 { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-weight: normal; + text-transform: uppercase; + font-weight: 700; + color: #000; + text-rendering: optimizeLegibility; +} + +h1 { + font-size: 50px; + padding-bottom: 30px; +} + +h2 { + font-size: 45px; + padding-bottom: 10px; + padding-top: 50px; +} + +h3 { + font-size: 40px; + /* padding-bottom: 60px; */ +} + +h4 { + font-size: 35px; + padding-bottom: 15px; +} + +h5 { + font-size: 30px; + padding-bottom: 10px; +} + +p { + margin: 0 0 28px 0; +} + +strong { + font-weight: bold; +} +em { + font-style: italic; +} +sup { + line-height: 0; +} + +small { + font-size: 70%; +} + +cite { + font-size: 80%; + font-style: italic; + } + +/* Teaser +================================================== */ + +header#teaser h1 { + text-transform: none !important; + color: #333; + font-size: 28px !important; + font-weight: 300 !important; +} + + +/* Links +================================================== */ +a { + color: #F40034; + text-decoration: none; + -webkit-transition: color .2s ease-in-out; + -moz-transition: color .2s ease-in-out; + transition: color .2s ease-in-out; +} +a:hover { + color: #F40034; +} + +/* Layout +================================================== */ +/* White container that is the "page" */ +.wrapper { + max-width: 1500px; + margin: 0 auto; + background: #fff; +} + +/* Containers to keep content to a set width */ +.nav, +.art-header-inner, +.footer, +.art-list, +.abt, +.fourohfour { + width: 980px; +} +.nav, +.art-body-inner, +.footer, +.art-list, +.abt, +.fourohfour { + position: relative; + margin: 0 auto; +} + +/* Nav +================================================== */ +.nav { + position: absolute; + top: 0; + left: 50%; + height: 70px; + padding-top: 40px; + margin-left: -490px; /* Half width of nav */ + border-bottom: 1px solid #333; + z-index: 2; +} +.nav.fixed { + position: fixed; +} +#logo { + float: left; +} +.nav-primary { + float: right; +} +.nav-primary li { + display: inline-block; + margin-left: 10px; + font-weight: 500; +} +#logo h1, +.nav-primary li, +.nav-primary li a { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-weight: 700; + font-size: 13px; + line-height: 30px; + color: #000; + text-transform: uppercase; +} + +#logo h1 { + height: 30px; + margin-left: 0px; + letter-spacing: 1px; + font-family: 'Questrial', sans-serif; + font-size: 30px; +} + +#logo h1 span{ + color: #F40034 !important; +} + +.nav li:first-child { + margin-left: 0; /* Remove left margin from the first nav li */ +} + +/* Home Page +================================================== */ + +div#home {} + +#home > div.cover { + max-width: 980px; + margin: 0px auto; + /*padding-top: 110px;*/ +} + +div.cover { + +} + +div.cover > img { + width: 100%; + height: 100%; +} + + +/* Article +================================================== */ +.art { + margin-top: -131px; +} +/* Header */ +.art-header { + height: 700px; + /* Background image is defined in the post */ + background-position: top center; + background-attachment: fixed; + overflow: hidden; +} +/* Contains the time, title and subtitle for an article */ +.art-header-inner { + position: absolute; + top: 300px; + left: 50%; + margin-left: -490px; +} +.art-time, +.art-title, +.art-subtitle { + text-align: center; + text-transform: uppercase; +} +.art-time { + font-size: 14px; + line-height: 1.8; + letter-spacing: 4px; +} +.art-title { + font-size: 50px; + line-height: .9; + letter-spacing: -2px; + width: 100%; +} +.art-subtitle { + margin-top: 4px; + font-size: 14px; + line-height: 1.3; + letter-spacing: 4px; +} + +/* If small header, make few adjustments */ +.small .art-title { + font-size: 70px; + line-height: 65px; +} +.small.art-header-inner { + top: 320px; +} + +/* Body */ +.art-body { + position: relative; + width: 100%; + background: #fff; + z-index: 100; + -webkit-box-shadow: 0 -3px 3px rgba(0,0,0,.2); + -moz-box-shadow: 0 -3px 3px rgba(0,0,0,.2); + box-shadow: 0 -3px 3px rgba(0,0,0,.2); +} +.art-body-inner { + font-family: Georgia,Cambria,"Times New Roman",Times,serif; + max-width: 640px; + padding: 80px 0 50px; + letter-spacing: 0.01rem; + font-weight: 400; + font-style: normal; + font-size: 21px; + line-height: 1.5; +} +.art-body-inner a:hover { + border-bottom: 1px solid #F40034; + padding-bottom:2px; +} +.art-body-inner ul, +.art-body-inner ol { /* For lists in the article body */ + margin-bottom: 26px; +} +.art-body-inner ul li { + list-style: disc; +} + +.art-body-inner mark { + background-color: #fdffb6; + padding: 2px; + -webkit-box-shadow: #fdffb6 0 0 5px; + -moz-box-shadow: #fdffb6 0 0 5px; + box-shadow: #fdffb6 0 0 5px; +} + +.art-body-inner blockquote { + font-size: 16px; + background: #f9f9f9; + border-left: 10px solid #ccc; + margin: 1.5em 10px; + padding: 0.5em 10px; + quotes: "\201C""\201D""\2018""\2019"; +} + +.art-body-inner blockquote p:first-child:before { + color: #ccc; + content: "?"; + font-size: 4em; + line-height: 0.1em; + margin-right: 0.25em; + vertical-align: -0.4em; +} + +.art-body-inner blockquote p { + margin-bottom: 1.5em; +} + +.art-body-inner blockquote p:last-child { + margin-bottom: 0; +} + + +.dropcap { /* First character on articles */ + float: left; + margin: 47px 10px 20px 0; + font-size: 100px; + line-height: 0; +} +.art-subhead { /* Subheads are used to break up sections of an article */ + margin: 60px 0 15px; + font-size: 20px; + line-height: 28px; + letter-spacing: 3px; +} +.callout { /* Callouts are like large pullquotes */ + font-weight: bold; +} +.art-body-inner img { + max-width: 100%; + max-height: 600px; + margin-bottom: 26px; +} +.art-body-inner img.center { + display: block; + margin-left: auto; + margin-right: auto; +} +.art-body-inner .art-reference { + font-size: 80%; + color: #999; + margin-top: 50px; +} + +/* For simple, white background posts */ +.simple .art-body { + background: none; + -webkit-box-shadow: none; + -moz-box-shadow: none; + box-shadow: none; +} + + +/* List of Articles +================================================== */ +.art-list { + padding: 120px 0 0; +} +.art-list-body { + position: relative; + overflow: hidden; +} +.art-list-item { + padding: 40px 0; + list-style: none; + overflow: hidden; + border-bottom: 1px solid #ccc; +} +.art-list-item:last-child { + border-bottom: none; +} +.art-list-title { + font-size: 26px; + line-height: 26px; + font-weight: 700; +} +.art-list-item-title-and-time { + float: left; + width: 30%; + margin-bottom: 10px; +} +.art-list-time { + font-size: 12px; + line-height: 20px; + letter-spacing: 2px; + text-transform: uppercase; + color: #999; +} +.art-list-title a { + color: #000; +} +.art-list-title a:hover { + color: #F40034; +} +.art-list-item p { + width: 65%; + float: left; + margin-left: 5%; + margin-bottom: 0; + font-size: 16px; + line-height: 24px; +} + + +/* Footer +================================================== */ +.footer { + padding: 30px 40px; + overflow: hidden; + border-top: 1px solid #ccc; +} +.footer, +.footer a { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-size: 13px; + text-transform: uppercase; + color: #777; +} +.footer a:hover { + color: #000; +} +.back-to-top, +.footer-nav, +.offsite-links { + width: 45%; + float: left; +} +.psi { + width:10%; + float:left; + text-align: center; +} +.footer-nav { + text-align: center; +} +.offsite-links { + text-align: right; +} +.footer .twitter-link:hover { + color: #0084B4; +} +.footer .instagram-link:hover { + color: #3F729B; +} +.footer .github-link:hover { + color: #c5376d; +} +.footer .caffein8-link:hover{ + color: black; +} +.footer .rss-link:hover { + color: #e85d24; +} +/* Remove prev & next links on loop */ +.art-list + .footer .footer-nav, +.abt + .footer .footer-nav { + text-indent: -9999px; + text-align: left; +} + + +/* White Reverse Theme +================================================== */ +/* Nav */ +.nav.white { + border-bottom-color: #fff; + border-bottom-color: rgba(255,255,255,.3); +} +.nav.white li a, +.nav.white li, +.nav.white #logo h1 { + color: #fff; + text-shadow: 0 0 8px rgba(0,0,0,.5); +} +.nav.white #logo h1 { + background-position: top center; +} + +nav.pagination{ + text-align: right; + padding-bottom: 25px; +} +/* Art header */ +.art-header.white { + background-color: #111; +} +.art-header.white .art-time, +.art-header.white .art-title, +.art-header.white .art-subtitle { + color: #fff; + text-shadow: 0 0 8px rgba(0,0,0,.5); +} + + +/* About page +================================================== */ +.abt { + padding: 200px 0 100px; + list-style: none; +} +.abt .abt-header { + font-size: 140px; + line-height: 1; + text-transform: none; +} +.abt .abt-subheader { + font-size: 24px; + font-style: italic; + text-transform: none; + color: #777; +} +.abt-body { + -moz-column-count: 2; + -moz-column-gap: 20px; + -webkit-column-count: 2; + -webkit-column-gap: 20px; + margin-bottom: 28px; +} +.abt-signoff { + line-height: 1.3; + font-style: italic; + color: #777; +} + +/* 404 page +================================================== */ +.fourohfour { + padding: 240px 0 100px; + text-align: center; +} + +/* Code +================================================== */ + +code, tt { +background: #ededee; +color: #3C4043; +font-size: 90%; +padding: 1px 3px; +} + +pre { + width: 92%; + overflow: auto; + margin: 2rem 0; + padding: 1rem 0.8rem 1rem 1.2rem; + color: #3f3b36; + border: 1px solid #ccc; + border-left: 1rem solid #ccc; + font: lighter 1.2rem/2rem monospace; + background: url(/assets/img/pre.png) repeat 0 -0.9rem; + background-size: 1px 4rem; +} + +pre code, tt { +font-size: inherit; +white-space: -moz-pre-wrap; +white-space: pre-wrap; +background: transparent; +border: none; +padding: 0; +} + + +.gist { + font-size: 14px; +} + + +/* Responsive +================================================== */ +@media only screen and (max-width: 1080px) { + /* Set all of the 980 containers to flexible width */ + .nav, + .art-body-inner, + .art-header-inner, + .footer, + .art-list, + .abt, + .fourohfour { + width: 90%; + } + .nav, + .art-header-inner { + margin-left: -45%; + } +} + +@media only screen and (max-width: 1024px) { + /* Everything becomes scrolling and non-fading */ + .nav, + .nav.fixed { + position: relative; + opacity: 1 !important; /* Important to override JS values */ + display: inline-block; + } + .art-header-inner { + position: relative; + top: 0 !important; /* Important to override JS values */ + margin-top: 240px !important; /* Important to override JS values */ + opacity: 1 !important; /* Important to override JS values */ + } + /* Articles no longer have fixed heights */ + .art-header { + height: auto; + padding-bottom: 100px; + background-size: cover !important; + background-attachment: scroll; + } + /* Remove bottom space out if articles doesn't have a background */ + .simple .art-header { + padding-bottom: 0; + } + .art-list { + padding-top: 0; + } + .abt { + padding: 40px 0; + } + .fourohfour { + padding: 80px 0 60px; + } +} + +@media only screen and (max-width: 780px) { + .art-body-inner ul, + .art-body-inner ol { + margin-left: 20px; + } + .art-title { + letter-spacing: 0; + } + .art-subtitle, + .art-time { + font-size: 12px; + } + .nav { + padding-top: 25px; + height: 55px; + } + .art-list-item-title-and-time, + .art-list-item p { + float: none; + width: auto; + margin-left: 0; + } + .abt-body { + -moz-column-count: 1; + -webkit-column-count: 1; + } +} + +@media only screen and (max-width: 500px) { + .nav-primary li { + margin-left: 10px; + } + .nav #logo h1 { + font-size: 16px; + letter-spacing: -1px; + } + .nav li a { + font-size: 12px; + } + .art-header { + padding-bottom: 50px; + } + .art-header-inner { + margin-top: 190px !important; + } + .art-body-inner { + padding-top: 30px; + } + body { + font-size: 15px; + line-height: 24px; + } + p { + margin-bottom: 24px; + } + .footer { + padding: 10px 0 20px; + } + .back-to-top, + .footer-nav { + width: 50%; + } + .back-to-top { + text-align: left; + } + .footer-nav { + text-align: right; + } + .offsite-links { + float: left; + width: 100%; + text-align: left; + } + .offsite-links a { + font-size: 12px; + } + .art-list + .footer .footer-nav { + display: none; + } + .abt .abt-header { + font-size: 80px; + } + .abt .abt-subheader { + font-size: 18px; + } +} + + +/* Misc +================================================== */ +::selection { + background: #000; + color: #fff; +} +::-moz-selection { + background: #000; + color: #fff; +} +img.left { + float: left; + margin-right: 20px; +} +img.right { + float: right; + margin-left: 20px; +} +/* Clearfixing pile */ +.nav:before, +.art-body-inner:before, +.footer:before, +.art-list:before { + content:""; + display:table; +} +.nav:after, +.art-body-inner:after, +.footer:after, +.art-list:after { + clear:both; +} +.nav, +.art-body-inner, +.footer, +.art-list { + zoom:1; /* For IE 6/7 (trigger hasLayout) */ +} + + +@-webkit-keyframes le-fade { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@-moz-keyframes le-fade { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +.art-header-inner { + -webkit-animation: le-fade .5s 0 1 ease-out; + -moz-animation: le-fade .5s 0 1 ease-out; +} + +.art-list, +.nav, +.abt, +.art-body { + -webkit-animation: le-fade .5s 0s 1 ease-out; + -moz-animation: le-fade .5s 0s 1 ease-out; +} + +hr.featured-article { + padding: 0; + border: none; + border-top: medium double #bbb; + color: #bbb; + text-align: center; +} +hr.featured-article:after { + content: "? Featured Article ?"; + display: inline-block; + position: relative; + top: -0.8em; + font-size: 1.2em; + padding: 0 0.6em; + background: white; +} + +/* FORM */ + +#contact-area { + width: 600px; + margin-top: 25px; +} + +#contact-area input, #contact-area textarea { + padding: 5px; + width: 471px; + font-family: Helvetica, sans-serif; + margin: 0px 0px 10px 0px; + border: 2px solid #ccc; +} + +#contact-area textarea { + height: 90px; +} + +#contact-area textarea:focus, #contact-area input:focus { + border: 2px solid #900; +} + +#contact-area input.submit-button { + width: 100px; + +} + +label { + float: left; + text-align: right; + margin-right: 15px; + width: 100px; + padding-top: 5px; +} \ No newline at end of file diff --git a/IF3110-02-Simple-Blog-Java/build/web/assets/img/favicon.ico b/IF3110-02-Simple-Blog-Java/build/web/assets/img/favicon.ico new file mode 100644 index 00000000..40b40ed3 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/assets/img/favicon.ico differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/assets/img/pre.png b/IF3110-02-Simple-Blog-Java/build/web/assets/img/pre.png new file mode 100644 index 00000000..7f48517b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/build/web/assets/img/pre.png differ diff --git a/IF3110-02-Simple-Blog-Java/build/web/assets/js/myjs.js b/IF3110-02-Simple-Blog-Java/build/web/assets/js/myjs.js new file mode 100644 index 00000000..db656f16 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/build/web/assets/js/myjs.js @@ -0,0 +1,167 @@ +function validateEmail() { + var email = document.getElementById("email").value; + var pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + var result = pattern.test(email); + + if (!result) { + document.getElementById("email").style.backgroundColor = "#ffaaaa"; + document.getElementById("submitKomentar").disabled = true; + } else { + document.getElementById("email").style.backgroundColor = "#aaffaa"; + document.getElementById("submitKomentar").disabled = false; + } + return result; +} + +function sendComment() { + var idPost = encodeURIComponent(document.getElementById("id").value); + var nama = encodeURIComponent(document.getElementById("nama").value); + var email = encodeURIComponent(document.getElementById("email").value); + var komentar = encodeURIComponent(document.getElementById("komentar").value); + + if (!validateKomentar(nama, email, komentar)) { + return false; + } + + var xmlhttp; + if (window.XMLHttpRequest) { + xmlhttp = new XMLHttpRequest(); + } else { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + existingComment = document.getElementById("komentar-placeholder").innerHTML; + document.getElementById("komentar-placeholder").innerHTML = xmlhttp.responseText; + + if (!document.getElementById("nama").disabled) + document.getElementById("nama").value = ''; + if (!document.getElementById("email").disabled) + document.getElementById("email").value = ''; + document.getElementById("komentar").value = ''; + } + } + + var parameters = "idpost=" + idPost + "&nama=" + nama + "&email=" + email + "&komentar=" + komentar; + xmlhttp.open("POST", "SaveComment", true); + xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xmlhttp.send(parameters); +} + +window.onload = loadComment(); + +function loadComment() { + var idPost = encodeURIComponent(document.getElementById("id").value); + + var xmlhttp; + if (window.XMLHttpRequest) { + xmlhttp = new XMLHttpRequest(); + } else { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("komentar-placeholder").innerHTML = xmlhttp.responseText; + } + } + + var parameters = "idpost=" + idPost; + xmlhttp.open("GET", "LoadComment?" + parameters, true); + xmlhttp.send(null); +} + +function validateKomentar(nama, email, komentar) { + if (isEmpty(nama)) { + alert('Kolom nama tidak boleh kosong'); + return false; + } + if (isEmpty(email)) { + alert('Kolom email tidak boleh kosong'); + return false; + } + if (isEmpty(komentar)) { + alert('Kolom komentar tidak boleh kosong'); + return false; + } + if (!validateEmail()) { + alert('Email tidak valid'); + return false; + } + + return true; +} + +function confirmDeletion(postId) { + var confirm = window.confirm("Apakah Anda yakin menghapus post ini?"); + if (confirm == true) { + window.location = "DeletePost?id=" + postId; + } else { + return false; + } +} + +function confirmSoftDeletion(postId) { + var confirm = window.confirm("Apakah Anda yakin menghapus post ini?"); + if (confirm == true) { + window.location = "SoftDelete?id=" + postId; + } else { + return false; + } +} + +function validate() { + var judul = document.getElementById("judul").value; + var content = document.getElementById("konten").value; + var validDateFormat = true; + var rawDate, tanggal; + try { + rawDate = document.getElementById("tanggal").value.split("/"); + if (rawDate[2] < 1990 || rawDate[2] > 2099 || rawDate[0] < 0 || rawDate[0] > 12 || rawDate[1] < 0 || rawDate[1] > 31) { + validDateFormat = false; + } else { + tanggal = new Date(rawDate[2], rawDate[0] - 1, rawDate[1]); + } + } catch(exception) { + validDateFormat = false; + } + var today = new Date(); + + if (isEmpty(judul)) { + alert("Judul tidak boleh kosong"); + return false; + } + if (validDateFormat) { + if (!compareDate(tanggal, today)) { + alert("Format tanggal tidak valid"); + return false; + } + } else { + alert("Format tanggal tidak valid"); + return false; + } + if (isEmpty(content)) { + alert("Konten tidak boleh kosong"); + return false; + } + + return true; +} + +function compareDate(tanggal, today) { + if (tanggal.getFullYear() > today.getFullYear()) + return true; + if (tanggal.getFullYear() < today.getFullYear()) + return false; + if (tanggal.getMonth() > today.getMonth()) + return true; + if (tanggal.getMonth() < today.getMonth()) + return false; + if (tanggal.getDate() >= today.getDate()) + return true; + if (tanggal.getDate() < today.getDate()) + return false; +} + +function isEmpty(val){ + return (val === undefined || val == null || val.length <= 0) ? true : false; +} \ No newline at end of file diff --git a/IF3110-02-Simple-Blog-Java/build/web/gfv3ee6.dpf b/IF3110-02-Simple-Blog-Java/build/web/gfv3ee6.dpf new file mode 100644 index 00000000..e69de29b diff --git a/IF3110-02-Simple-Blog-Java/db/schema v2.sql b/IF3110-02-Simple-Blog-Java/db/schema v2.sql new file mode 100644 index 00000000..8695215e --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/db/schema v2.sql @@ -0,0 +1,122 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.4.1 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Dec 01, 2014 at 07:17 PM +-- Server version: 5.6.11 +-- PHP Version: 5.5.0 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `wbdhebat` +-- +CREATE DATABASE IF NOT EXISTS `wbdhebat` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +USE `wbdhebat`; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `komentar` +-- + +CREATE TABLE IF NOT EXISTS `komentar` ( + `name` varchar(100) DEFAULT NULL, + `email` varchar(100) DEFAULT NULL, + `tanggal` datetime DEFAULT NULL, + `komentar` text, + `post_id` int(11) NOT NULL, + KEY `fk_komentar_post_idx` (`post_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `komentar` +-- + +INSERT INTO `komentar` (`name`, `email`, `tanggal`, `komentar`, `post_id`) VALUES +('Editor I', 'editor@wbd.com', '2014-11-24 05:58:15', 'Ahey', 5), +('Editor I', 'editor@wbd.com', '2014-11-24 05:58:20', 'Woi', 5), +('Editor I', 'editor@wbd.com', '2014-11-24 05:58:26', 'Blaem', 5), +('a', 'asep@gmail.com', '2014-12-02 01:14:00', 'haha', 2); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `post` +-- + +CREATE TABLE IF NOT EXISTS `post` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `judul` varchar(200) DEFAULT NULL, + `tanggal` datetime DEFAULT NULL, + `konten` text, + `status` varchar(20) DEFAULT NULL, + `image` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; + +-- +-- Dumping data for table `post` +-- + +INSERT INTO `post` (`id`, `judul`, `tanggal`, `konten`, `status`, `image`) VALUES +(2, 'Unpublished', '2015-11-02 00:00:00', 'Hahayyyy', 'Published', 'Gods-Valley-Dawn.jpg'), +(5, 'Tes Siomay Note', '2015-01-23 00:00:00', 'Hahaa', 'Published', ''), +(6, 'Tes Lagi', '2016-11-11 00:00:00', 'Uhuk', 'Published', ''), +(7, 'Tes Lagi 2', '2017-11-11 00:00:00', 'Uhuk 2', 'Unpublished', 'lib.PNG'), +(8, 'Uhuk 2', '2019-11-11 00:00:00', 'Jebret', 'Published', ''), +(9, 'Teskjlsdk ', '2019-11-11 00:00:00', 'Jskads', 'Unpublished', ''), +(10, 'Hahay', '2015-11-12 00:00:00', 'KHDsa', 'Unpublished', ''), +(11, 'Uhuyyyy', '2016-11-11 00:00:00', 'Uhuy', 'Published', ''), +(12, 'Upload', '2016-11-01 00:00:00', 'Aheyy', 'Unpublished', NULL), +(13, 'Aa', '2016-12-13 00:00:00', 'Hahayyyy', 'Unpublished', NULL); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `email` varchar(100) NOT NULL, + `password` varchar(100) NOT NULL, + `name` varchar(45) DEFAULT NULL, + `role` varchar(20) DEFAULT NULL, + PRIMARY KEY (`id`,`email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`id`, `email`, `password`, `name`, `role`) VALUES +(1, 'ibnu.komarudin@gmail.com', 'bandung', 'Asep Saepudin', 'Admin'), +(3, 'owner@wbd.com', 'owner', 'Owner I', 'Owner'), +(4, 'editor@wbd.com', 'editor', 'Editor I', 'Editor'), +(5, 'admin@wbd.com', 'admin', 'Admin I', 'Admin'), +(8, 'admin2@wbd.com', 'admin2', 'Admin II', 'Admin'), +(9, 'editor2@wbd.com', 'editor2', 'Editor II', 'Editor'), +(10, 'owner2@wbd.com', 'owner2', 'Owner II', 'Owner'); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `komentar` +-- +ALTER TABLE `komentar` + ADD CONSTRAINT `fk_komentar_post` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/IF3110-02-Simple-Blog-Java/db/schema.sql b/IF3110-02-Simple-Blog-Java/db/schema.sql new file mode 100644 index 00000000..92228517 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/db/schema.sql @@ -0,0 +1,56 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +CREATE SCHEMA IF NOT EXISTS `wbdhebat` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ; +USE `wbdhebat` ; + +-- ----------------------------------------------------- +-- Table `wbdhebat`.`user` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wbdhebat`.`user` ( + `id` INT NOT NULL AUTO_INCREMENT , + `email` VARCHAR(100) NOT NULL , + `password` VARCHAR(100) NOT NULL , + `name` VARCHAR(45) NULL , + `role` VARCHAR(20) NULL , + PRIMARY KEY (`id`, `email`) ) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `wbdhebat`.`post` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wbdhebat`.`post` ( + `id` INT NOT NULL AUTO_INCREMENT , + `judul` VARCHAR(200) NULL , + `tanggal` DATETIME NULL , + `konten` TEXT NULL , + `status` VARCHAR(20) NULL , + PRIMARY KEY (`id`) ) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `wbdhebat`.`komentar` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `wbdhebat`.`komentar` ( + `name` VARCHAR(100) NULL , + `email` VARCHAR(100) NULL , + `tanggal` DATETIME NULL , + `komentar` TEXT NULL , + `post_id` INT NOT NULL , + INDEX `fk_komentar_post_idx` (`post_id` ASC) , + CONSTRAINT `fk_komentar_post` + FOREIGN KEY (`post_id` ) + REFERENCES `wbdhebat`.`post` (`id` ) + ON DELETE CASCADE + ON UPDATE NO ACTION) +ENGINE = InnoDB; + +USE `wbdhebat` ; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/IF3110-02-Simple-Blog-Java/nbproject/ant-deploy.xml b/IF3110-02-Simple-Blog-Java/nbproject/ant-deploy.xml new file mode 100644 index 00000000..2d5f8778 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/ant-deploy.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IF3110-02-Simple-Blog-Java/nbproject/build-impl.xml b/IF3110-02-Simple-Blog-Java/nbproject/build-impl.xml new file mode 100644 index 00000000..b3b847c9 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/build-impl.xml @@ -0,0 +1,1444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IF3110-02-Simple-Blog-Java/nbproject/genfiles.properties b/IF3110-02-Simple-Blog-Java/nbproject/genfiles.properties new file mode 100644 index 00000000..0e387884 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=74ac68de +build.xml.script.CRC32=a9410f96 +build.xml.stylesheet.CRC32=651128d4@1.68.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=74ac68de +nbproject/build-impl.xml.script.CRC32=9106d273 +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 diff --git a/IF3110-02-Simple-Blog-Java/nbproject/licenseheader.txt b/IF3110-02-Simple-Blog-Java/nbproject/licenseheader.txt new file mode 100644 index 00000000..e69de29b diff --git a/IF3110-02-Simple-Blog-Java/nbproject/private/private.properties b/IF3110-02-Simple-Blog-Java/nbproject/private/private.properties new file mode 100644 index 00000000..6a210ebf --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/private/private.properties @@ -0,0 +1,7 @@ +deploy.ant.properties.file=C:\\Users\\DiePiePaw\\AppData\\Roaming\\NetBeans\\8.0.1\\config\\GlassFishEE6\\Properties\\gfv3-68613151.properties +j2ee.platform.is.jsr109=true +j2ee.server.domain=C:/Program Files/glassfish-4.1/glassfish/domains/domain1 +j2ee.server.home=C:/Program Files/glassfish-4.1/glassfish +j2ee.server.instance=[C:\\Program Files\\glassfish-4.1\\glassfish;C:\\Program Files\\glassfish-4.1\\glassfish\\domains\\domain1]deployer:gfv3ee6:localhost:4848 +j2ee.server.middleware=C:/Program Files/glassfish-4.1 +user.properties.file=C:\\Users\\DiePiePaw\\AppData\\Roaming\\NetBeans\\8.0.1\\build.properties diff --git a/IF3110-02-Simple-Blog-Java/nbproject/private/private.xml b/IF3110-02-Simple-Blog-Java/nbproject/private/private.xml new file mode 100644 index 00000000..3b5534ed --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/D:/Project/Java/Web/IF3110-02-Simple-Blog-Java-0.2/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeletePostServlet.java + + + diff --git a/IF3110-02-Simple-Blog-Java/nbproject/project.properties b/IF3110-02-Simple-Blog-Java/nbproject/project.properties new file mode 100644 index 00000000..c301af60 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/project.properties @@ -0,0 +1,93 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +auxiliary.org-netbeans-modules-projectapi.jsf_2e_language=JSP +auxiliary.org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder=js/libs +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${libs.MySQLDriver.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +project.license=default +project.licensePath=./nbproject/licenseheader.txt +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=IF3110-02-Simple-Blog-Java.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/IF3110-02-Simple-Blog-Java/nbproject/project.xml b/IF3110-02-Simple-Blog-Java/nbproject/project.xml new file mode 100644 index 00000000..170c78dd --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.web.project + + + IF3110-02-Simple-Blog-Java + 1.6.5 + + + ${libs.MySQLDriver.classpath} + WEB-INF/lib + + + + + + + + + + + + diff --git a/IF3110-02-Simple-Blog-Java/src/conf/MANIFEST.MF b/IF3110-02-Simple-Blog-Java/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddImagePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddImagePostServlet.java new file mode 100644 index 00000000..4b46a1d2 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddImagePostServlet.java @@ -0,0 +1,142 @@ +package wbd.tubesII; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +/** + * + * @author Asus + */ +@WebServlet(name = "AddImagePost", urlPatterns = {"/AddImagePost"}) +@MultipartConfig(fileSizeThreshold=1024*1024*2, + maxFileSize=1024*1024*10, + maxRequestSize=1024*1024*50, + location="E:\\workspace\\NetBeansProjects\\IF3110-02-Simple-Blog-Java\\IF3110-02-Simple-Blog-Java\\build\\web\\upload") // DEVELOPMENT ONLY!!! NEVER EVER EVER EVER USE THIS PATH IN PRODUCTION!!! EVER!!! +public class AddImagePostServlet extends HttpServlet { + private static final String SAVE_DIR = "upload"; + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet AddImagePostServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AddImagePostServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null) { + response.sendRedirect("PublishedPosts"); + } else { + Post editedPost = PostDAO.getPost(Integer.valueOf(id)); + if (editedPost != null) { + request.getSession().setAttribute("editedImagePost", editedPost); + response.sendRedirect("AddImagePost.jsp"); + } else { + response.sendRedirect("PublishedPosts"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String appPath = request.getServletContext().getRealPath(""); + System.out.println("APPPATH = " + appPath); + String savePath = appPath + File.separator + SAVE_DIR; + System.out.println("SAVEPATH = " + savePath); + + // creates the save directory if it does not exists + File fileSaveDir = new File(savePath); + if (!fileSaveDir.exists()) { + fileSaveDir.mkdir(); + } + Part part = request.getPart("file"); + System.out.println(part.getName()); + System.out.println(part.getSize()); + System.out.println(part.getSubmittedFileName()); + String fileName = extractFileName(part); + System.out.println("WRITEPATH = " + savePath + File.separator + fileName); + System.out.println(fileName); + part.write(fileName); + + if (PostDAO.addImage(fileName, Integer.valueOf(request.getParameter("id")))) { + request.getSession().setAttribute("ImagePostStatus", "Gambar post berhasil disimpan"); + response.sendRedirect("ImagePostStatus.jsp"); + } else { + request.getSession().setAttribute("ImagePostStatus", "Gambar post tidak berhasil disimpan"); + response.sendRedirect("ImagePostStatus.jsp"); + } + + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String extractFileName(Part part) { + String contentDisp = part.getHeader("content-disposition"); + String[] items = contentDisp.split(";"); + for (String s : items) { + if (s.trim().startsWith("filename")) { + return s.substring(s.indexOf("=") + 2, s.length()-1); + } + } + return ""; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddNewPostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddNewPostServlet.java new file mode 100644 index 00000000..7ebb121b --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/AddNewPostServlet.java @@ -0,0 +1,111 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "AddNewPost", urlPatterns = {"/AddNewPost"}) +public class AddNewPostServlet extends HttpServlet { + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet AddNewPostServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AddNewPostServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getSession().getAttribute("currentUser") == null || + ((User)request.getSession().getAttribute("currentUser")).getRole().equals("Editor")) { + response.sendRedirect("PublishedPosts"); + } else { + response.sendRedirect("AddNewPost.jsp"); + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + try { + System.out.println("TANGGAL PARAMETER => " + request.getParameter("tanggal")); + Post post = new Post(); + post.setJudul(request.getParameter("judul")); + post.setTanggal(new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("tanggal"))); + post.setKonten(request.getParameter("konten")); + post.setStatus("Unpublished"); + + if (!PostDAO.add(post)) { + request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal disimpan"); + } else { + request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil disimpan"); + } + response.sendRedirect("AddNewPostStatus.jsp"); + processRequest(request, response); + } catch (ParseException ex) { + Logger.getLogger(AddNewPostServlet.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Comment.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Comment.java new file mode 100644 index 00000000..f5265ac3 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Comment.java @@ -0,0 +1,55 @@ +package wbd.tubesII; + +import java.util.Date; + +/** + * + * @author Asep Saepudin + */ +public class Comment { + private int id; + private String name; + private String email; + private Date tanggal; + private String komentar; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Date getTanggal() { + return tanggal; + } + + public void setTanggal(Date tanggal) { + this.tanggal = tanggal; + } + + public String getKomentar() { + return komentar; + } + + public void setKomentar(String komentar) { + this.komentar = komentar; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CommentDAO.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CommentDAO.java new file mode 100644 index 00000000..f5f2dea5 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CommentDAO.java @@ -0,0 +1,69 @@ +package wbd.tubesII; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Asep Saepudin + */ +public class CommentDAO { + private static Connection currentCon = null; + private static ResultSet rs = null; + + public static boolean save(Comment comment) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("INSERT INTO `komentar` " + + "(`name`, `email`, `tanggal`, `komentar`, `post_id`) VALUES " + + "(?, ?, ?, ?, ?)"); + statement.setString(1, comment.getName()); + statement.setString(2, comment.getEmail()); + statement.setString(3, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(comment.getTanggal())); + statement.setString(4, comment.getKomentar()); + statement.setString(5, String.valueOf(comment.getId())); + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + public static ArrayList get(int id) { + ArrayList comments = new ArrayList(); + PreparedStatement statement = null; + ResultSet rs = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `komentar` WHERE `post_id`=" + id); + rs = statement.executeQuery(); + while (rs.next()) { + Comment comment = new Comment(); + comment.setEmail(rs.getString("email")); + comment.setName(rs.getString("name")); + comment.setId(Integer.valueOf(rs.getString("post_id"))); + comment.setKomentar(rs.getString("komentar")); + comment.setTanggal(rs.getDate("tanggal")); + comments.add(comment); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return null; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + return comments; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ConnectionManager.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ConnectionManager.java new file mode 100644 index 00000000..b95bf5fc --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ConnectionManager.java @@ -0,0 +1,35 @@ +package wbd.tubesII; + +/** + * + * @author Asep Saepudin + */ + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class ConnectionManager { + private static Connection con; + private static final String USERNAME = "root"; + private static final String PASSWORD = ""; + private static final String M_CONN_STRING = "jdbc:mysql://localhost:3306/wbdhebat"; + + public static Connection getConnection() throws ClassNotFoundException { + try { + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection(M_CONN_STRING, USERNAME, PASSWORD); + } catch (SQLException e) { + processException(e); + return null; + } + return con; + } + + public static void processException(SQLException e) { + System.err.println("Error message: " + e.getMessage()); + System.err.println("Error code: " + e.getErrorCode()); + System.err.println("SQL state: " + e.getSQLState()); + } + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CookieManager.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CookieManager.java new file mode 100644 index 00000000..b451a15a --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CookieManager.java @@ -0,0 +1,43 @@ +package wbd.tubesII; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +public class CookieManager { + public static String getCookieValue(HttpServletRequest request, String name) { + Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (Cookie cookie : cookies) { + if (name.equals(cookie.getName())) { + return cookie.getValue(); + } + } + } + return null; + } + + /** + * + * @author BalusC + */ + public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) { + Cookie cookie = new Cookie(name, value); + cookie.setPath("/"); + cookie.setMaxAge(maxAge); + response.addCookie(cookie); + } + + /** + * + * @author BalusC + */ + public static void removeCookie(HttpServletResponse response, String name) { + addCookie(response, name, null, 0); + } + +} \ No newline at end of file diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomHttpSessionListener.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomHttpSessionListener.java new file mode 100644 index 00000000..13bce2d8 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomHttpSessionListener.java @@ -0,0 +1,34 @@ +package wbd.tubesII; + +import java.util.HashMap; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +/** + * + * @author Asep Saepudin + */ +public class CustomHttpSessionListener implements HttpSessionListener { + + @Override + public void sessionCreated(HttpSessionEvent se) { + HttpSession session = se.getSession(); + ServletContext context = session.getServletContext(); + HashMap activeUsers = (HashMap) context.getAttribute("activeUsers"); + + activeUsers.put(session.getId(), session); + context.setAttribute("activeUsers", activeUsers); + } + + @Override + public void sessionDestroyed(HttpSessionEvent se) { + HttpSession session = se.getSession(); + ServletContext context = session.getServletContext(); + HashMap activeUsers = (HashMap) context.getAttribute("activeUsers"); + + activeUsers.remove(session.getId()); + } + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomServletContextListener.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomServletContextListener.java new file mode 100644 index 00000000..2e2d1897 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/CustomServletContextListener.java @@ -0,0 +1,26 @@ +package wbd.tubesII; + +import java.util.HashMap; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * + * @author Asep Saepudin + */ +public class CustomServletContextListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + HashMap activeUsers = new HashMap(); + context.setAttribute("activeUsers", activeUsers); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeletePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeletePostServlet.java new file mode 100644 index 00000000..b7a88f3d --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeletePostServlet.java @@ -0,0 +1,96 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "DeletePost", urlPatterns = {"/DeletePost"}) +public class DeletePostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet DeletePostServlet"); + out.println(""); + out.println(""); + out.println("

Servlet DeletePostServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null) { + response.sendRedirect("PublishedPosts"); + } else { + if (!PostDAO.delete(Integer.valueOf(id))) { + request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") tidak berhasil dihapus"); + response.sendRedirect("DeletePostStatus.jsp"); + } else { + request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") berhasil dihapus"); + response.sendRedirect("DeletePostStatus.jsp"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeleteUserServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeleteUserServlet.java new file mode 100644 index 00000000..44423377 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/DeleteUserServlet.java @@ -0,0 +1,100 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "DeleteUser", urlPatterns = {"/DeleteUser"}) +public class DeleteUserServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet DeleteUser"); + out.println(""); + out.println(""); + out.println("

Servlet DeleteUser at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String email = URLDecoder.decode(request.getParameter("email"), "UTF-8"); + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin") || + email.equals("") || email == null) { + response.sendRedirect("PublishedPosts"); + } else { + if (!UserDAO.delete(email)) { + request.getSession().setAttribute("deleteUser", "User dengan email " + email + " tidak ditemukan"); + response.sendRedirect("DeletionStatus.jsp"); + } else { + request.getSession().setAttribute("deleteUser", "User dengan email " + email + " berhasil dihapus"); + response.sendRedirect("DeletionStatus.jsp"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoadCommentServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoadCommentServlet.java new file mode 100644 index 00000000..90cffcce --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoadCommentServlet.java @@ -0,0 +1,89 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "LoadComment", urlPatterns = {"/LoadComment"}) +public class LoadCommentServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + ArrayList comments = CommentDAO.get(Integer.valueOf(request.getParameter("idpost"))); + StringBuffer sb = new StringBuffer(); + for (Comment komentar : comments) { + String name = komentar.getName(); + String date = komentar.getTanggal().toString(); + String isiKomentar = komentar.getKomentar(); +// sb.append("Nama: " + name + "
"); +// sb.append("Tanggal: " + date + "
"); +// sb.append("Komentar: " + isiKomentar + "

"); + sb.append("
  • "+name+"

    "+date+"

    "+isiKomentar+"

  • "); + } + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(sb.toString()); + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }//
    + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoginServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoginServlet.java new file mode 100644 index 00000000..6a953c6a --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LoginServlet.java @@ -0,0 +1,142 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import java.util.HashMap; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.Cookie; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "LoginServlet", urlPatterns = {"/Login"}) +public class LoginServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet LoginServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet LoginServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + try { + HttpSession session = null; + String sessionCookie = CookieManager.getCookieValue(request, "JSESSIONID"); + String persistentCookie = CookieManager.getCookieValue(request, "wbdahey"); + + if (sessionCookie != null) { + if (persistentCookie == null) { + CookieManager.addCookie(response, "wbdahey", sessionCookie, 3600*24*365*1000); + } + } + + if (persistentCookie != null) { + HashMap activeUsers = (HashMap) request.getServletContext().getAttribute("activeUsers"); + session = activeUsers.get(persistentCookie); + } + + if (session == null) { + session = request.getSession(); + } + + User user = (User)session.getAttribute("currentUser"); + if (user == null) { + response.sendRedirect("Login.jsp"); + } else { + session.setAttribute("currentUser", user); + response.sendRedirect("PublishedPosts"); + } + + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + try { + User user = new User(); + user.setEmail(URLDecoder.decode(request.getParameter("email"), "UTF-8")); + user.setPassword(request.getParameter("password")); + + user = UserDAO.login(user); + + if (user.getValid()) { + Cookie wbdCookie = new Cookie("wbdahey", user.getEmail()); + wbdCookie.setMaxAge(3600*24*365*1000); + response.addCookie(wbdCookie); + + request.getSession().setAttribute("currentUser", user); +// this.getServletConfig().getServletContext().setAttribute("currentUser", user); + + response.sendRedirect("PublishedPosts"); + } else if (!user.getValid()) { + request.getSession().setAttribute("forbidden", "Username/Password tidak valid"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.sendRedirect("Uuuppssss.jsp"); + } + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LogoutServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LogoutServlet.java new file mode 100644 index 00000000..f1316079 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/LogoutServlet.java @@ -0,0 +1,94 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "LogoutServlet", urlPatterns = {"/Logout"}) +public class LogoutServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet LogoutServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet LogoutServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + CookieManager.removeCookie(response, "JSESSIONID"); + CookieManager.removeCookie(response, "wbdahey"); + + request.getSession().setAttribute("currentUser", null); + + response.sendRedirect("PublishedPosts"); + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Post.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Post.java new file mode 100644 index 00000000..ccc9b74d --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/Post.java @@ -0,0 +1,64 @@ +package wbd.tubesII; + +import java.util.Date; + +/** + * + * @author Asep Saepudin + */ +public class Post { + private int id; + private String judul; + private Date tanggal; + private String konten; + private String status; + private String image; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getJudul() { + return judul; + } + + public void setJudul(String judul) { + this.judul = judul; + } + + public Date getTanggal() { + return tanggal; + } + + public void setTanggal(Date tanggal) { + this.tanggal = tanggal; + } + + public String getKonten() { + return konten; + } + + public void setKonten(String konten) { + this.konten = konten; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PostDAO.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PostDAO.java new file mode 100644 index 00000000..b0651657 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PostDAO.java @@ -0,0 +1,268 @@ +package wbd.tubesII; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Asep Saepudin + */ +public class PostDAO { + private static Connection currentCon = null; + private static ResultSet rs = null; + + public static boolean add(Post post) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("INSERT INTO `post` " + + "(`judul`, `tanggal`, `konten`, `status`) VALUES " + + "(?, ?, ?, ?)"); + statement.setString(1, post.getJudul()); + statement.setString(2, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(post.getTanggal())); + statement.setString(3, post.getKonten()); + statement.setString(4, post.getStatus()); + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + public static boolean update(Post post) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` " + + "SET `judul`=?, `tanggal`=?, `konten`=?, `status`=? " + + "WHERE `id`=? "); + statement.setString(1, post.getJudul()); + statement.setString(2, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(post.getTanggal())); + statement.setString(3, post.getKonten()); + statement.setString(4, post.getStatus()); + statement.setString(5, String.valueOf(post.getId())); + + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + public static boolean delete(int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("DELETE FROM `post` WHERE `id`=" + id); + statement.executeUpdate(); + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + return true; + } + + public static Post getPost(int id) { + PreparedStatement statement = null; + ResultSet rs = null; + Post post = new Post(); + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `post` WHERE `id`=" + id); + rs = statement.executeQuery(); + + if (!rs.next()) { + return null; + } else { + post.setId(Integer.valueOf(rs.getString("id"))); + post.setJudul(rs.getString("judul")); + post.setTanggal(rs.getDate("tanggal")); +// post.setTanggal(new SimpleDateFormat("MM/dd/yyyy").parse(rs.getString("tanggal"))); + post.setKonten(rs.getString("konten")); + post.setStatus(rs.getString("status")); + post.setImage(rs.getString("image")); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return null; + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + return null; + } +// } catch (ParseException ex) { +// Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); +// } + return post; + } + + public static ArrayList getAllPosts() { + ArrayList posts = new ArrayList(); + PreparedStatement statement = null; + ResultSet rs = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `post`"); + rs = statement.executeQuery(); + while (rs.next()) { + posts.add(getPost(rs.getInt("id"))); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } + return posts; + } + + public static ArrayList getAllPublishedPosts() { + ArrayList posts = new ArrayList(); + PreparedStatement statement = null; + ResultSet rs = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `post` where `status`='Published'"); + rs = statement.executeQuery(); + while (rs.next()) { + posts.add(getPost(rs.getInt("id"))); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } + return posts; + } + + public static ArrayList getAllUnpublishedPosts() { + ArrayList posts = new ArrayList(); + PreparedStatement statement = null; + ResultSet rs = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `post` where `status`='Unpublished'"); + rs = statement.executeQuery(); + while (rs.next()) { + posts.add(getPost(rs.getInt("id"))); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } + return posts; + } + + public static ArrayList getAllDeletedPosts() { + ArrayList posts = new ArrayList(); + PreparedStatement statement = null; + ResultSet rs = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("SELECT * FROM `post` where `status`='Deleted'"); + rs = statement.executeQuery(); + while (rs.next()) { + posts.add(getPost(rs.getInt("id"))); + } + } catch (SQLException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(PostDAO.class.getName()).log(Level.SEVERE, null, ex); + } + return posts; + } + + public static boolean publish(int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` SET `status`='Published' WHERE id=" + id); + statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public static boolean softDelete(int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` SET `status`='Deleted' WHERE id=" + id); + statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public static boolean unDelete(int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` SET `status`='Unpublished' WHERE id=" + id); + statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public static boolean hasImage(Post post) { + try { + return !post.getImage().equals("") && post.getImage() != null; + } catch (Exception e){ + + } + return false; + } + + public static boolean addImage(String image, int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` SET `image`='" + image + "' WHERE id=" + id); + statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public static boolean removeImage(int id) { + PreparedStatement statement = null; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.prepareStatement("UPDATE `post` SET `image`='' WHERE id=" + id); + statement.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishPostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishPostServlet.java new file mode 100644 index 00000000..4b36f145 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishPostServlet.java @@ -0,0 +1,98 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "PublishPost", urlPatterns = {"/PublishPost"}) +public class PublishPostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet PublishPostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet PublishPostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null || + ((User)request.getSession().getAttribute("currentUser")).getRole().equals("Owner")) { + response.sendRedirect("PublishedPosts"); + } else { + if (!PostDAO.publish(Integer.valueOf(id))) { + request.getSession().setAttribute("PublishPostStatus", "Post (id = " + id + ") tidak berhasil di-publish"); + response.sendRedirect("PublishPostStatus.jsp"); + } else { + request.getSession().setAttribute("PublishPostStatus", "Post (id = " + id + ") berhasil di-publish"); + response.sendRedirect("PublishPostStatus.jsp"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishedPostsServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishedPostsServlet.java new file mode 100644 index 00000000..f8ccacd6 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/PublishedPostsServlet.java @@ -0,0 +1,89 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "PublishedPosts", urlPatterns = {"/PublishedPosts"}) +public class PublishedPostsServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet PublishedPostsServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet PublishedPostsServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + ArrayList publishedPosts = PostDAO.getAllPublishedPosts(); + request.getSession().setAttribute("allPublishedPosts", publishedPosts); + response.sendRedirect("PublishedPost.jsp"); + + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RegisterServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RegisterServlet.java new file mode 100644 index 00000000..dc0d57c4 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RegisterServlet.java @@ -0,0 +1,104 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "RegisterServlet", urlPatterns = {"/Register"}) +public class RegisterServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet RegisterServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet RegisterServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.sendRedirect("PublishedPosts"); + } else { + response.sendRedirect("Register.jsp"); + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + User user = new User(); + user.setEmail(request.getParameter("email")); + user.setPassword(request.getParameter("password")); + user.setName(request.getParameter("name")); + user.setRole(request.getParameter("role")); + + if (UserDAO.register(user)) { + request.getSession().setAttribute("registerUser", "User dengan email " + request.getParameter("email") + " berhasil ditambahkan"); + response.sendRedirect("RegistrationStatus.jsp"); + } else { + request.getSession().setAttribute("registerUser", "Email " + request.getParameter("email") + " telah digunakan"); + response.sendRedirect("RegistrationStatus.jsp"); + } + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RemoveImagePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RemoveImagePostServlet.java new file mode 100644 index 00000000..ec480a8c --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/RemoveImagePostServlet.java @@ -0,0 +1,97 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asus + */ +@WebServlet(name = "RemoveImagePost", urlPatterns = {"/RemoveImagePost"}) +public class RemoveImagePostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet RemoveImagePostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet RemoveImagePostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null) { + response.sendRedirect("PublishedPosts"); + } else { + if (PostDAO.removeImage(Integer.valueOf(id))) { + request.getSession().setAttribute("ImagePostStatus", "Gambar post berhasil dihapus"); + response.sendRedirect("ImagePostStatus.jsp"); + } else { + request.getSession().setAttribute("ImagePostStatus", "Gambar post tidak berhasil dihapus"); + response.sendRedirect("ImagePostStatus.jsp"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SaveCommentServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SaveCommentServlet.java new file mode 100644 index 00000000..bf453d63 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SaveCommentServlet.java @@ -0,0 +1,118 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "SaveComment", urlPatterns = {"/SaveComment"}) +public class SaveCommentServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ +// out.println(""); +// out.println(""); +// out.println(""); +// out.println("Servlet SaveCommentServlet"); +// out.println(""); +// out.println(""); +// out.println("

    Servlet SaveCommentServlet at " + request.getContextPath() + "

    "); +// out.println(""); +// out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + Comment comment = new Comment(); + comment.setEmail(request.getParameter("email")); + comment.setName(request.getParameter("nama")); + comment.setTanggal(new Date()); + comment.setKomentar(request.getParameter("komentar")); + comment.setId(Integer.valueOf(request.getParameter("idpost"))); + System.out.println(CommentDAO.save(comment)); +// if (!CommentDAO.save(comment)) { +// request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal disimpan"); +// } else { +// request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil disimpan"); +// } +// response.sendRedirect("AddNewPostStatus.jsp"); +// processRequest(request, response); + ArrayList comments = CommentDAO.get(Integer.valueOf(request.getParameter("idpost"))); + StringBuffer sb = new StringBuffer(); + for (Comment komentar : comments) { + String name = komentar.getName(); + String date = komentar.getTanggal().toString(); + String isiKomentar = komentar.getKomentar(); +// sb.append("Nama: " + name + "
    "); +// sb.append("Tanggal: " + date + "
    "); +// sb.append("Komentar: " + isiKomentar + "

    "); + sb.append("
  • "+name+"

    "+date+"

    "+isiKomentar+"

  • "); + } + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(sb.toString()); + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }//
    + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SofDeletePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SofDeletePostServlet.java new file mode 100644 index 00000000..2808c7de --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SofDeletePostServlet.java @@ -0,0 +1,96 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "SoftDeletedPost", urlPatterns = {"/SoftDeletedPost"}) +public class SofDeletePostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet PublishedPostsServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet PublishedPostsServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.sendRedirect("PublishedPosts"); + } else { + + ArrayList deletedPosts = PostDAO.getAllDeletedPosts(); + request.getSession().setAttribute("allDeletedPosts", deletedPosts); + response.sendRedirect("SoftDeletedPost.jsp"); + + } + + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SoftDeleteServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SoftDeleteServlet.java new file mode 100644 index 00000000..2bc5dd03 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/SoftDeleteServlet.java @@ -0,0 +1,104 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author DiePiePaw + */ +@WebServlet(urlPatterns = {"/SoftDelete"}) +public class SoftDeleteServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet SoftDeleteServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet SoftDeleteServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.sendRedirect("PublishedPosts"); + } else { + + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null) { + response.sendRedirect("PublishedPosts"); + } else { + if (!PostDAO.softDelete(Integer.valueOf(id))) { + request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") tidak berhasil dihapus"); + response.sendRedirect("DeletePostStatus.jsp"); + } else { + request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") berhasil dihapus"); + response.sendRedirect("DeletePostStatus.jsp"); + } + } + } + processRequest(request, response); + + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UndeletePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UndeletePostServlet.java new file mode 100644 index 00000000..7dc3653a --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UndeletePostServlet.java @@ -0,0 +1,98 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "UndeletePost", urlPatterns = {"/UndeletePost"}) +public class UndeletePostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet PublishPostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet PublishPostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.sendRedirect("PublishedPosts"); + } else { + if (!PostDAO.unDelete(Integer.valueOf(id))) { + request.getSession().setAttribute("UndeletePostStatus", "Post (id = " + id + ") tidak berhasil di-undelete"); + response.sendRedirect("UndeletePostStatus.jsp"); + } else { + request.getSession().setAttribute("UndeletePostStatus", "Post (id = " + id + ") berhasil di-undelete"); + response.sendRedirect("UndeletePostStatus.jsp"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UnpublishedPostsServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UnpublishedPostsServlet.java new file mode 100644 index 00000000..50dab234 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UnpublishedPostsServlet.java @@ -0,0 +1,93 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "UnpublishedPosts", urlPatterns = {"/UnpublishedPosts"}) +public class UnpublishedPostsServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet UnpublishedPostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet UnpublishedPostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + if (request.getSession().getAttribute("currentUser") == null || + ((User)request.getSession().getAttribute("currentUser")).getPassword().equals("Owner")) { + response.sendRedirect("PublishedPosts"); + } else { + ArrayList unpublishedPosts = PostDAO.getAllUnpublishedPosts(); + request.getSession().setAttribute("allUnpublishedPosts", unpublishedPosts); + response.sendRedirect("UnpublishedPost.jsp"); + } + + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdatePostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdatePostServlet.java new file mode 100644 index 00000000..e5a8630f --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdatePostServlet.java @@ -0,0 +1,120 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "UpdatePost", urlPatterns = {"/UpdatePost"}) +public class UpdatePostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet UpdatePostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet UpdatePostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String id = request.getParameter("id"); + + if (request.getSession().getAttribute("currentUser") == null) { + response.sendRedirect("PublishedPosts"); + } else { + Post editedPost = PostDAO.getPost(Integer.valueOf(id)); + if (editedPost != null) { + request.getSession().setAttribute("editedPost", editedPost); + response.sendRedirect("EditPost.jsp"); + } else { + response.sendRedirect("PublishedPosts"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + try { + Post post = new Post(); + post.setId(Integer.valueOf(request.getParameter("id"))); + post.setJudul(request.getParameter("judul")); + post.setTanggal(new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("tanggal"))); + post.setKonten(request.getParameter("konten")); + post.setStatus(request.getParameter("status")); + + if (!PostDAO.update(post)) { + request.getSession().setAttribute("UpdatePostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal di-update"); + } else { + request.getSession().setAttribute("UpdatePostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil di-update"); + } + response.sendRedirect("UpdatePostStatus.jsp"); + processRequest(request, response); + } catch (ParseException ex) { + Logger.getLogger(AddNewPostServlet.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdateUserServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdateUserServlet.java new file mode 100644 index 00000000..8bb39582 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UpdateUserServlet.java @@ -0,0 +1,115 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URLDecoder; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "UpdateUser", urlPatterns = {"/UpdateUser"}) +public class UpdateUserServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet UpdateUserServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet UpdateUserServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String email = URLDecoder.decode(request.getParameter("email"), "UTF-8"); + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin") || + email.equals("") || email == null) { + response.sendRedirect("PublishedPosts"); + } else { + User editedUser = UserDAO.getUser(email); + if (editedUser != null) { + request.getSession().setAttribute("editedUser", editedUser); + response.sendRedirect("EditUser.jsp"); + } else { + response.sendRedirect("PublishedPosts"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + User user = new User(); + user.setId(Integer.parseInt(request.getParameter("id"))); + user.setEmail(request.getParameter("email")); + user.setPassword(request.getParameter("password")); + user.setName(request.getParameter("name")); + user.setRole(request.getParameter("role")); + + if (UserDAO.update(user)) { + request.getSession().setAttribute("updateUser", "User (id = " + request.getParameter("id") + ") berhasil di-update"); + response.sendRedirect("UpdateUserStatus.jsp"); + } else { + request.getSession().setAttribute("updateUser", "User (id = " + request.getParameter("id") + ") tidak berhasil di-update"); + response.sendRedirect("UpdateUserStatus.jsp"); + } + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/User.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/User.java new file mode 100644 index 00000000..5331dc2d --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/User.java @@ -0,0 +1,64 @@ +package wbd.tubesII; + +import java.io.Serializable; + +/** + * + * @author Asep Saepudin + */ +public class User { + private int id; + private String email; + private String password; + private String name; + private String role; + private boolean valid; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public boolean getValid() { + return this.valid; + } + + public void setValid(boolean valid) { + this.valid = valid; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserDAO.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserDAO.java new file mode 100644 index 00000000..62dae3f4 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserDAO.java @@ -0,0 +1,319 @@ +package wbd.tubesII; + +/** + * + * @author Asep Saepudin + */ + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; + +public class UserDAO { + private static Connection currentCon = null; + private static ResultSet rs = null; + + public static User login(User user) { + Statement statement = null; + + String email = user.getEmail(); + String password = user.getPassword(); + + String searchQuery = "SELECT * FROM `user` WHERE `email` = '" + email + "'" + + " AND `password` = '" + password + "'"; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + rs = statement.executeQuery(searchQuery); + if (!rs.next()) { + System.err.println("Invalid email/password"); + user.setValid(false); + } else { + String name = rs.getString("name"); + String role = rs.getString("role"); + + user.setName(name); + user.setRole(role); + user.setValid(true); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return user; + } + + public static boolean register(User user) { + Statement statement = null; + + String email = user.getEmail(); + String password = user.getPassword(); + String name = user.getName(); + String role = user.getRole(); + + String searchQuery = "SELECT * FROM `user` WHERE `email` = '" + email + "'"; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + rs = statement.executeQuery(searchQuery); + if (rs.next()) { + System.err.println("Email has been used"); + return false; + } else { + searchQuery = "INSERT INTO `user` (`email`, `password`, `name`, `role`) VALUES ('" + + email + "', '" + password + "', '" + name + "', '" + role + "')"; + statement.executeUpdate(searchQuery); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return true; + } + + public static ArrayList getAllUsers() { + ArrayList users = new ArrayList(); + Statement statement = null; + String searchQuery = "SELECT * FROM `user`"; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + rs = statement.executeQuery(searchQuery); + while (rs.next()) { + User user = new User(); + user.setId(rs.getInt("id")); + user.setEmail(rs.getString("email")); + user.setPassword(rs.getString("password")); + user.setName(rs.getString("name")); + user.setRole(rs.getString("role")); + user.setValid(true); + users.add(user); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return users; + } + + public static boolean delete(String email) { + Statement statement = null; + + String searchQuery = "SELECT * FROM `user` WHERE `email` = '" + email + "'"; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + rs = statement.executeQuery(searchQuery); + if (!rs.next()) { + System.err.println("User doesn't exist"); + return false; + } else { + searchQuery = "DELETE FROM `user` where `email`='" + + email + "'"; + statement.executeUpdate(searchQuery); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return true; + } + + public static User getUser(String email) { + Statement statement = null; + String searchQuery = "SELECT * FROM `user` WHERE `email`='" + email +"'"; + User user = new User(); + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + rs = statement.executeQuery(searchQuery); + if (rs.next()) { + user.setId(rs.getInt("id")); + user.setEmail(rs.getString("email")); + user.setPassword(rs.getString("password")); + user.setName(rs.getString("name")); + user.setRole(rs.getString("role")); + user.setValid(true); + } else { + return null; + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return user; + } + + public static boolean update(User user) { + Statement statement = null; + + int id = user.getId(); + String email = user.getEmail(); + String password = user.getPassword(); + String name = user.getName(); + String role = user.getRole(); + + String searchQuery = "UPDATE `user` SET `email`='" + email + "', `password`='" + password + + "', name='" + name + "', `role`='" + role + "' WHERE `id` = " + id; + try { + currentCon = ConnectionManager.getConnection(); + statement = currentCon.createStatement(); + + statement.executeUpdate(searchQuery); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (Exception e) { + rs = null; + } + } + + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + statement = null; + } + } + + if (currentCon != null) { + try { + currentCon.close(); + } catch (Exception e) { + + } + currentCon = null; + } + } + return true; + } +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserManagementServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserManagementServlet.java new file mode 100644 index 00000000..dfd79019 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/UserManagementServlet.java @@ -0,0 +1,96 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "UserManagement", urlPatterns = {"/UserManagement"}) +public class UserManagementServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet UserManagement"); + out.println(""); + out.println(""); + out.println("

    Servlet UserManagement at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getSession().getAttribute("currentUser") == null || + !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.sendRedirect("PublishedPosts"); + } else { + ArrayList users = UserDAO.getAllUsers(); + request.getSession().setAttribute("allUsers", users); + response.sendRedirect("UserManagement.jsp"); + } + + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + processRequest(request, response); + + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ViewPostServlet.java b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ViewPostServlet.java new file mode 100644 index 00000000..c35ae6df --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/src/java/wbd/tubesII/ViewPostServlet.java @@ -0,0 +1,97 @@ +package wbd.tubesII; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Asep Saepudin + */ +@WebServlet(name = "ViewPost", urlPatterns = {"/ViewPost"}) +public class ViewPostServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet ViewPostServlet"); + out.println(""); + out.println(""); + out.println("

    Servlet ViewPostServlet at " + request.getContextPath() + "

    "); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String id = request.getParameter("id"); + + if (id == null || id.equals("")) { + response.sendRedirect("PublishedPosts"); + } else { + Post post = PostDAO.getPost(Integer.valueOf(id)); + if (post != null) { + request.getSession().setAttribute("post", post); + response.sendRedirect("ViewPost.jsp"); + } else { + response.sendRedirect("PublishedPosts"); + } + } + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/IF3110-02-Simple-Blog-Java/web/AddImagePost.jsp b/IF3110-02-Simple-Blog-Java/web/AddImagePost.jsp new file mode 100644 index 00000000..4d94b021 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/AddImagePost.jsp @@ -0,0 +1,81 @@ +<%-- + Document : AddImagePost + Created on : Dec 1, 2014, 10:18:26 PM + Author : Asep Saepudin +--%> + +<%@page import="java.text.Format"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add Image Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + Post editedPost = (Post)request.getSession().getAttribute("editedImagePost"); + %> + +
    + + + +
    +

    -

    + +
    +
    +

    Edit Post

    + +
    +
    + + + + + + +
    +
    +
    +
    +
    + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/AddNewPost.jsp b/IF3110-02-Simple-Blog-Java/web/AddNewPost.jsp new file mode 100644 index 00000000..4dc1b654 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/AddNewPost.jsp @@ -0,0 +1,84 @@ +<%-- + Document : AddNewPost + Created on : Nov 23, 2014, 7:41:49 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Editor")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    +

    -

    + +
    +
    +

    Add New Post

    + +
    +
    + + + + + + +
    + + + +
    +
    +
    +
    +
    + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/AddNewPostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/AddNewPostStatus.jsp new file mode 100644 index 00000000..83c5129b --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/AddNewPostStatus.jsp @@ -0,0 +1,75 @@ +<%-- + Document : AddNewPostStatus + Created on : Nov 23, 2014, 8:41:53 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Editor")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Owner"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("AddNewPostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/DeletePostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/DeletePostStatus.jsp new file mode 100644 index 00000000..05fd22de --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/DeletePostStatus.jsp @@ -0,0 +1,76 @@ +<%-- + Document : DeletePostStatus + Created on : Nov 23, 2014, 10:08:40 PM + Author : Asep Saepudin +--%> + +<%-- + Document : AddNewPostStatus + Created on : Nov 23, 2014, 8:41:53 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Delete Post + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("DeletePostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/DeletionStatus.jsp b/IF3110-02-Simple-Blog-Java/web/DeletionStatus.jsp new file mode 100644 index 00000000..7cc60c28 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/DeletionStatus.jsp @@ -0,0 +1,69 @@ +<%-- + Document : DeletionFailed + Created on : Nov 23, 2014, 6:23:16 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Delete User + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("deleteUser") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + diff --git a/IF3110-02-Simple-Blog-Java/web/EditPost.jsp b/IF3110-02-Simple-Blog-Java/web/EditPost.jsp new file mode 100644 index 00000000..46148d96 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/EditPost.jsp @@ -0,0 +1,97 @@ +<%-- + Document : EditPost + Created on : Nov 23, 2014, 10:12:56 PM + Author : Asep Saepudin +--%> + +<%@page import="java.text.Format"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.Date"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Edit Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + + Post editedPost = (Post)request.getSession().getAttribute("editedPost"); + if (editedPost == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    +

    -

    + +
    +
    +

    Edit Post

    + +
    +
    + + + + + + + <% + Date date = editedPost.getTanggal(); + Format formatter = new SimpleDateFormat("MM/dd/yyyy"); + %> + + + +
    + + + +
    +
    +
    +
    +
    + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/EditUser.jsp b/IF3110-02-Simple-Blog-Java/web/EditUser.jsp new file mode 100644 index 00000000..3ad3b321 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/EditUser.jsp @@ -0,0 +1,104 @@ +<%-- + Document : EditUser + Created on : Nov 23, 2014, 6:41:33 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Edit User + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + request.getSession().setAttribute("adminOnly", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "AdminOnly.jsp"); + } + User editedUser = (User)request.getSession().getAttribute("editedUser"); + if (editedUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "UserManagement"); + } + %> + + +
    + + + +
    + + +

    -

    + +
    +
    +

    Edit User

    + +
    +
    +
    + + + + + + + + + + + + +
    + +
    +
    +
    +
    + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/ImagePostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/ImagePostStatus.jsp new file mode 100644 index 00000000..ef7513ca --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/ImagePostStatus.jsp @@ -0,0 +1,70 @@ +<%-- + Document : ImagePostStatus + Created on : Dec 2, 2014, 12:48:34 AM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add Image Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("ImagePostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/Login.jsp b/IF3110-02-Simple-Blog-Java/web/Login.jsp new file mode 100644 index 00000000..d0d98197 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/Login.jsp @@ -0,0 +1,73 @@ +<%-- + Document : LoginPage + Created on : Nov 20, 2014, 8:30:01 PM + Author : Asep Saepudin +--%> + +<%@page import="org.apache.jasper.tagplugins.jstl.ForEach"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Login + + <% if (request.getSession().getAttribute("currentUser") != null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    +

    -

    + +
    +
    +

    Login

    + +
    +
    + + + + + + + +
    +
    +
    +
    +
    + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/PublishPostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/PublishPostStatus.jsp new file mode 100644 index 00000000..57cfa881 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/PublishPostStatus.jsp @@ -0,0 +1,74 @@ +<%-- + Document : PublishPostStatus + Created on : Nov 23, 2014, 9:44:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Publish Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Owner")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("PublishPostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/PublishedPost.jsp b/IF3110-02-Simple-Blog-Java/web/PublishedPost.jsp new file mode 100644 index 00000000..ae1b1f49 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/PublishedPost.jsp @@ -0,0 +1,98 @@ +<%-- + Document : PublishedPost + Created on : Nov 23, 2014, 9:38:08 PM + Author : Asep Saepudin +--%> + +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Published Posts + + <% User currentUser = (User)request.getSession().getAttribute("currentUser"); %> + +
    + + + +
    +
    + +
    +
    + + + +
    + + + + diff --git a/IF3110-02-Simple-Blog-Java/web/Register.jsp b/IF3110-02-Simple-Blog-Java/web/Register.jsp new file mode 100644 index 00000000..c7952841 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/Register.jsp @@ -0,0 +1,97 @@ +<%-- + Document : register + Created on : Nov 20, 2014, 10:35:52 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Add New User + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + request.getSession().setAttribute("adminOnly", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "AdminOnly.jsp"); + } + %> + + +
    + + + +
    + + +

    -

    + +
    +
    +

    Add New User

    + +
    +
    + + + + + + + + + + + +
    + +
    +
    +
    +
    + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/RegistrationStatus.jsp b/IF3110-02-Simple-Blog-Java/web/RegistrationStatus.jsp new file mode 100644 index 00000000..ecdd4c66 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/RegistrationStatus.jsp @@ -0,0 +1,68 @@ +<%-- + Document : registerfailed + Created on : Nov 20, 2014, 10:52:29 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("registerUser") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + diff --git a/IF3110-02-Simple-Blog-Java/web/SoftDeletedPost.jsp b/IF3110-02-Simple-Blog-Java/web/SoftDeletedPost.jsp new file mode 100644 index 00000000..ad5bd1e4 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/SoftDeletedPost.jsp @@ -0,0 +1,103 @@ +<%-- + Document : UnpublishedPost + Created on : Nov 23, 2014, 9:27:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Deleted Posts + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Editor"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    +
    + +
    +
    + + + +
    + + + + diff --git a/IF3110-02-Simple-Blog-Java/web/UndeletePostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/UndeletePostStatus.jsp new file mode 100644 index 00000000..54721288 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/UndeletePostStatus.jsp @@ -0,0 +1,74 @@ +<%-- + Document : PublishPostStatus + Created on : Nov 23, 2014, 9:44:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Undelete Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (!currentUser.getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("UndeletePostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/UnpublishedPost.jsp b/IF3110-02-Simple-Blog-Java/web/UnpublishedPost.jsp new file mode 100644 index 00000000..4e98ad5a --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/UnpublishedPost.jsp @@ -0,0 +1,114 @@ +<%-- + Document : UnpublishedPost + Created on : Nov 23, 2014, 9:27:46 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Unpublished Posts + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + if (currentUser.getRole().equals("Owner")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin dan Editor"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + + +
    + + + +
    +
    + +
    +
    + + + +
    + + + + diff --git a/IF3110-02-Simple-Blog-Java/web/UpdatePostStatus.jsp b/IF3110-02-Simple-Blog-Java/web/UpdatePostStatus.jsp new file mode 100644 index 00000000..112a970c --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/UpdatePostStatus.jsp @@ -0,0 +1,69 @@ +<%-- + Document : UpdatePostStatus + Created on : Nov 23, 2014, 10:25:28 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Update Post + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("UpdatePostStatus") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/UpdateUserStatus.jsp b/IF3110-02-Simple-Blog-Java/web/UpdateUserStatus.jsp new file mode 100644 index 00000000..04b03b69 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/UpdateUserStatus.jsp @@ -0,0 +1,68 @@ +<%-- + Document : SuccessfullyUpdated + Created on : Nov 23, 2014, 7:04:52 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + <% + if (request.getSession().getAttribute("currentUser") == null + || !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("updateUser") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + diff --git a/IF3110-02-Simple-Blog-Java/web/UserManagement.jsp b/IF3110-02-Simple-Blog-Java/web/UserManagement.jsp new file mode 100644 index 00000000..c6db74b1 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/UserManagement.jsp @@ -0,0 +1,96 @@ +<%-- + Document : UserManagement + Created on : Nov 23, 2014, 5:12:43 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.UserDAO"%> +<%@page import="org.apache.jasper.tagplugins.jstl.ForEach"%> +<%@page import="java.util.ArrayList"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | User Management + + + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + if (currentUser == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPostsLogin.jsp"); + } + if (!currentUser.getRole().equals("Admin")) { +// request.getSession().setAttribute("forbidden", "Psst! Halaman khusus Admin"); + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts.jsp"); + } + %> + + +
    + + + +
    +
    + +
    +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/Uuuppssss.jsp b/IF3110-02-Simple-Blog-Java/web/Uuuppssss.jsp new file mode 100644 index 00000000..df6b229d --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/Uuuppssss.jsp @@ -0,0 +1,60 @@ +<%-- + Document : AdminOnly + Created on : Nov 23, 2014, 5:10:08 PM + Author : Asep Saepudin +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | Ups + + +
    + + + +
    + +
    +
    + +

    <%= (String)request.getSession().getAttribute("forbidden") %>

    +

    Continue...

    +
    +
    + + +
    + + + +
    + + diff --git a/IF3110-02-Simple-Blog-Java/web/ViewPost.jsp b/IF3110-02-Simple-Blog-Java/web/ViewPost.jsp new file mode 100644 index 00000000..a436e924 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/ViewPost.jsp @@ -0,0 +1,122 @@ +<%-- + Document : ViewPost + Created on : Nov 23, 2014, 11:27:55 PM + Author : Asep Saepudin +--%> + +<%@page import="wbd.tubesII.PostDAO"%> +<%@page import="wbd.tubesII.Post"%> +<%@page import="wbd.tubesII.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + Simple Blog | View Post + + <% + Post post = (Post)request.getSession().getAttribute("post"); + if (post == null) { + response.setStatus(response.SC_MOVED_TEMPORARILY); + response.setHeader("Location", "PublishedPosts"); + } + %> + <% + User currentUser = (User)request.getSession().getAttribute("currentUser"); + %> + + +
    + + + +
    + +
    +
    + +

    <%= post.getJudul() %>

    +

    +
    +
    + +
    +
    +
    + <% if (PostDAO.hasImage(post)) { %> +
    +
    +

    +
    + <% } %> +

    <%= post.getKonten() %>

    + +
    + + <% if (post.getStatus().equals("Published")) { %> +

    Komentar

    + +
    +
    + + + + <% if (currentUser == null) { %> + + <% } else {%> + + <% }%> + + + <% if (currentUser == null) { %> + + <% } else {%> + + <% }%> + +
    + + + +
    +
    + +
      + +
    + <% } %> +
    +
    + +
    + + + +
    + + + diff --git a/IF3110-02-Simple-Blog-Java/web/WEB-INF/web.xml b/IF3110-02-Simple-Blog-Java/web/WEB-INF/web.xml new file mode 100644 index 00000000..d310ba83 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/PublishedPosts + + + + wbd.tubesII.CustomServletContextListener + + + + + + wbd.tubesII.CustomHttpSessionListener + + + diff --git a/IF3110-02-Simple-Blog-Java/web/assets/css/screen.css b/IF3110-02-Simple-Blog-Java/web/assets/css/screen.css new file mode 100644 index 00000000..cc53838e --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/assets/css/screen.css @@ -0,0 +1,862 @@ +@import url(http://fonts.googleapis.com/css?family=Open+Sans); +@import url(http://fonts.googleapis.com/css?family=Questrial); + +/* Reset & Basics (Inspired by E. Meyers) +================================================== */ +html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, address, cite, code, em, img, small, strong, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, embed, figure, figcaption, footer, header, hgroup, menu, nav, section, summary, time, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; } +article, aside, details, figcaption, figure, footer, header, hgroup, menu, time, nav, section { + display: block; } +html, body, .wrapper { + min-height: 100%; +} + + +/* Body +================================================== */ +html, body { + height: 100%; +} +.wrapper { + min-height: 100%; +} +body { + overflow-x: hidden; + font: 17px/28px ff-meta-serif-web-pro, "Georgia", serif; + color: #333; + background: #fff; +} + + +/* Typography +================================================== */ +h1, h2, h3, h4, h5, h6 { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-weight: normal; + text-transform: uppercase; + font-weight: 700; + color: #000; + text-rendering: optimizeLegibility; +} + +h1 { + font-size: 50px; + padding-bottom: 30px; +} + +h2 { + font-size: 45px; + padding-bottom: 10px; + padding-top: 50px; +} + +h3 { + font-size: 40px; + /* padding-bottom: 60px; */ +} + +h4 { + font-size: 35px; + padding-bottom: 15px; +} + +h5 { + font-size: 30px; + padding-bottom: 10px; +} + +p { + margin: 0 0 28px 0; +} + +strong { + font-weight: bold; +} +em { + font-style: italic; +} +sup { + line-height: 0; +} + +small { + font-size: 70%; +} + +cite { + font-size: 80%; + font-style: italic; + } + +/* Teaser +================================================== */ + +header#teaser h1 { + text-transform: none !important; + color: #333; + font-size: 28px !important; + font-weight: 300 !important; +} + + +/* Links +================================================== */ +a { + color: #F40034; + text-decoration: none; + -webkit-transition: color .2s ease-in-out; + -moz-transition: color .2s ease-in-out; + transition: color .2s ease-in-out; +} +a:hover { + color: #F40034; +} + +/* Layout +================================================== */ +/* White container that is the "page" */ +.wrapper { + max-width: 1500px; + margin: 0 auto; + background: #fff; +} + +/* Containers to keep content to a set width */ +.nav, +.art-header-inner, +.footer, +.art-list, +.abt, +.fourohfour { + width: 980px; +} +.nav, +.art-body-inner, +.footer, +.art-list, +.abt, +.fourohfour { + position: relative; + margin: 0 auto; +} + +/* Nav +================================================== */ +.nav { + position: absolute; + top: 0; + left: 50%; + height: 70px; + padding-top: 40px; + margin-left: -490px; /* Half width of nav */ + border-bottom: 1px solid #333; + z-index: 2; +} +.nav.fixed { + position: fixed; +} +#logo { + float: left; +} +.nav-primary { + float: right; +} +.nav-primary li { + display: inline-block; + margin-left: 10px; + font-weight: 500; +} +#logo h1, +.nav-primary li, +.nav-primary li a { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-weight: 700; + font-size: 13px; + line-height: 30px; + color: #000; + text-transform: uppercase; +} + +#logo h1 { + height: 30px; + margin-left: 0px; + letter-spacing: 1px; + font-family: 'Questrial', sans-serif; + font-size: 20px; +} + +#logo h1 span{ + color: #F40034 !important; +} + +.nav li:first-child { + margin-left: 0; /* Remove left margin from the first nav li */ +} + +/* Home Page +================================================== */ + +div#home {} + +#home > div.cover { + max-width: 980px; + margin: 0px auto; + /*padding-top: 110px;*/ +} + +div.cover { + +} + +div.cover > img { + width: 100%; + height: 100%; +} + + +/* Article +================================================== */ +.art { + margin-top: -131px; +} +/* Header */ +.art-header { + height: 700px; + /* Background image is defined in the post */ + background-position: top center; + background-attachment: fixed; + overflow: hidden; +} +/* Contains the time, title and subtitle for an article */ +.art-header-inner { + position: absolute; + top: 300px; + left: 50%; + margin-left: -490px; +} +.art-time, +.art-title, +.art-subtitle { + text-align: center; + text-transform: uppercase; +} +.art-time { + font-size: 14px; + line-height: 1.8; + letter-spacing: 4px; +} +.art-title { + font-size: 50px; + line-height: .9; + letter-spacing: -2px; + width: 100%; +} +.art-subtitle { + margin-top: 4px; + font-size: 14px; + line-height: 1.3; + letter-spacing: 4px; +} + +/* If small header, make few adjustments */ +.small .art-title { + font-size: 70px; + line-height: 65px; +} +.small.art-header-inner { + top: 320px; +} + +/* Body */ +.art-body { + position: relative; + width: 100%; + background: #fff; + z-index: 100; + -webkit-box-shadow: 0 -3px 3px rgba(0,0,0,.2); + -moz-box-shadow: 0 -3px 3px rgba(0,0,0,.2); + box-shadow: 0 -3px 3px rgba(0,0,0,.2); +} +.art-body-inner { + font-family: Georgia,Cambria,"Times New Roman",Times,serif; + max-width: 640px; + padding: 80px 0 50px; + letter-spacing: 0.01rem; + font-weight: 400; + font-style: normal; + font-size: 21px; + line-height: 1.5; +} +.art-body-inner a:hover { + border-bottom: 1px solid #F40034; + padding-bottom:2px; +} +.art-body-inner ul, +.art-body-inner ol { /* For lists in the article body */ + margin-bottom: 26px; +} +.art-body-inner ul li { + list-style: disc; +} + +.art-body-inner mark { + background-color: #fdffb6; + padding: 2px; + -webkit-box-shadow: #fdffb6 0 0 5px; + -moz-box-shadow: #fdffb6 0 0 5px; + box-shadow: #fdffb6 0 0 5px; +} + +.art-body-inner blockquote { + font-size: 16px; + background: #f9f9f9; + border-left: 10px solid #ccc; + margin: 1.5em 10px; + padding: 0.5em 10px; + quotes: "\201C""\201D""\2018""\2019"; +} + +.art-body-inner blockquote p:first-child:before { + color: #ccc; + content: "?"; + font-size: 4em; + line-height: 0.1em; + margin-right: 0.25em; + vertical-align: -0.4em; +} + +.art-body-inner blockquote p { + margin-bottom: 1.5em; +} + +.art-body-inner blockquote p:last-child { + margin-bottom: 0; +} + + +.dropcap { /* First character on articles */ + float: left; + margin: 47px 10px 20px 0; + font-size: 100px; + line-height: 0; +} +.art-subhead { /* Subheads are used to break up sections of an article */ + margin: 60px 0 15px; + font-size: 20px; + line-height: 28px; + letter-spacing: 3px; +} +.callout { /* Callouts are like large pullquotes */ + font-weight: bold; +} +.art-body-inner img { + max-width: 100%; + max-height: 600px; + margin-bottom: 26px; +} +.art-body-inner img.center { + display: block; + margin-left: auto; + margin-right: auto; +} +.art-body-inner .art-reference { + font-size: 80%; + color: #999; + margin-top: 50px; +} + +/* For simple, white background posts */ +.simple .art-body { + background: none; + -webkit-box-shadow: none; + -moz-box-shadow: none; + box-shadow: none; +} + + +/* List of Articles +================================================== */ +.art-list { + padding: 120px 0 0; +} +.art-list-body { + position: relative; + overflow: hidden; +} +.art-list-item { + padding: 40px 0; + list-style: none; + overflow: hidden; + border-bottom: 1px solid #ccc; +} +.art-list-item:last-child { + border-bottom: none; +} +.art-list-title { + font-size: 26px; + line-height: 26px; + font-weight: 700; +} +.art-list-item-title-and-time { + float: left; + width: 30%; + margin-bottom: 10px; +} +.art-list-time { + font-size: 12px; + line-height: 20px; + letter-spacing: 2px; + text-transform: uppercase; + color: #999; +} +.art-list-title a { + color: #000; +} +.art-list-title a:hover { + color: #F40034; +} +.art-list-item p { + width: 65%; + float: left; + margin-left: 5%; + margin-bottom: 0; + font-size: 16px; + line-height: 24px; +} + + +/* Footer +================================================== */ +.footer { + padding: 30px 40px; + overflow: hidden; + border-top: 1px solid #ccc; +} +.footer, +.footer a { + font-family: "proxima-nova", "helvetica neue", "helvetica", sans-serif; + font-size: 13px; + text-transform: uppercase; + color: #777; +} +.footer a:hover { + color: #000; +} +.back-to-top, +.footer-nav, +.offsite-links { + width: 45%; + float: left; +} +.psi { + width:10%; + float:left; + text-align: center; +} +.footer-nav { + text-align: center; +} +.offsite-links { + text-align: right; +} +.footer .twitter-link:hover { + color: #0084B4; +} +.footer .instagram-link:hover { + color: #3F729B; +} +.footer .github-link:hover { + color: #c5376d; +} +.footer .caffein8-link:hover{ + color: black; +} +.footer .rss-link:hover { + color: #e85d24; +} +/* Remove prev & next links on loop */ +.art-list + .footer .footer-nav, +.abt + .footer .footer-nav { + text-indent: -9999px; + text-align: left; +} + + +/* White Reverse Theme +================================================== */ +/* Nav */ +.nav.white { + border-bottom-color: #fff; + border-bottom-color: rgba(255,255,255,.3); +} +.nav.white li a, +.nav.white li, +.nav.white #logo h1 { + color: #fff; + text-shadow: 0 0 8px rgba(0,0,0,.5); +} +.nav.white #logo h1 { + background-position: top center; +} + +nav.pagination{ + text-align: right; + padding-bottom: 25px; +} +/* Art header */ +.art-header.white { + background-color: #111; +} +.art-header.white .art-time, +.art-header.white .art-title, +.art-header.white .art-subtitle { + color: #fff; + text-shadow: 0 0 8px rgba(0,0,0,.5); +} + + +/* About page +================================================== */ +.abt { + padding: 200px 0 100px; + list-style: none; +} +.abt .abt-header { + font-size: 140px; + line-height: 1; + text-transform: none; +} +.abt .abt-subheader { + font-size: 24px; + font-style: italic; + text-transform: none; + color: #777; +} +.abt-body { + -moz-column-count: 2; + -moz-column-gap: 20px; + -webkit-column-count: 2; + -webkit-column-gap: 20px; + margin-bottom: 28px; +} +.abt-signoff { + line-height: 1.3; + font-style: italic; + color: #777; +} + +/* 404 page +================================================== */ +.fourohfour { + padding: 240px 0 100px; + text-align: center; +} + +/* Code +================================================== */ + +code, tt { +background: #ededee; +color: #3C4043; +font-size: 90%; +padding: 1px 3px; +} + +pre { + width: 92%; + overflow: auto; + margin: 2rem 0; + padding: 1rem 0.8rem 1rem 1.2rem; + color: #3f3b36; + border: 1px solid #ccc; + border-left: 1rem solid #ccc; + font: lighter 1.2rem/2rem monospace; + background: url(/assets/img/pre.png) repeat 0 -0.9rem; + background-size: 1px 4rem; +} + +pre code, tt { +font-size: inherit; +white-space: -moz-pre-wrap; +white-space: pre-wrap; +background: transparent; +border: none; +padding: 0; +} + + +.gist { + font-size: 14px; +} + + +/* Responsive +================================================== */ +@media only screen and (max-width: 1080px) { + /* Set all of the 980 containers to flexible width */ + .nav, + .art-body-inner, + .art-header-inner, + .footer, + .art-list, + .abt, + .fourohfour { + width: 90%; + } + .nav, + .art-header-inner { + margin-left: -45%; + } +} + +@media only screen and (max-width: 1024px) { + /* Everything becomes scrolling and non-fading */ + .nav, + .nav.fixed { + position: relative; + opacity: 1 !important; /* Important to override JS values */ + display: inline-block; + } + .art-header-inner { + position: relative; + top: 0 !important; /* Important to override JS values */ + margin-top: 240px !important; /* Important to override JS values */ + opacity: 1 !important; /* Important to override JS values */ + } + /* Articles no longer have fixed heights */ + .art-header { + height: auto; + padding-bottom: 100px; + background-size: cover !important; + background-attachment: scroll; + } + /* Remove bottom space out if articles doesn't have a background */ + .simple .art-header { + padding-bottom: 0; + } + .art-list { + padding-top: 0; + } + .abt { + padding: 40px 0; + } + .fourohfour { + padding: 80px 0 60px; + } +} + +@media only screen and (max-width: 780px) { + .art-body-inner ul, + .art-body-inner ol { + margin-left: 20px; + } + .art-title { + letter-spacing: 0; + } + .art-subtitle, + .art-time { + font-size: 12px; + } + .nav { + padding-top: 25px; + height: 55px; + } + .art-list-item-title-and-time, + .art-list-item p { + float: none; + width: auto; + margin-left: 0; + } + .abt-body { + -moz-column-count: 1; + -webkit-column-count: 1; + } +} + +@media only screen and (max-width: 500px) { + .nav-primary li { + margin-left: 10px; + } + .nav #logo h1 { + font-size: 16px; + letter-spacing: -1px; + } + .nav li a { + font-size: 12px; + } + .art-header { + padding-bottom: 50px; + } + .art-header-inner { + margin-top: 190px !important; + } + .art-body-inner { + padding-top: 30px; + } + body { + font-size: 15px; + line-height: 24px; + } + p { + margin-bottom: 24px; + } + .footer { + padding: 10px 0 20px; + } + .back-to-top, + .footer-nav { + width: 50%; + } + .back-to-top { + text-align: left; + } + .footer-nav { + text-align: right; + } + .offsite-links { + float: left; + width: 100%; + text-align: left; + } + .offsite-links a { + font-size: 12px; + } + .art-list + .footer .footer-nav { + display: none; + } + .abt .abt-header { + font-size: 80px; + } + .abt .abt-subheader { + font-size: 18px; + } +} + + +/* Misc +================================================== */ +::selection { + background: #000; + color: #fff; +} +::-moz-selection { + background: #000; + color: #fff; +} +img.left { + float: left; + margin-right: 20px; +} +img.right { + float: right; + margin-left: 20px; +} +/* Clearfixing pile */ +.nav:before, +.art-body-inner:before, +.footer:before, +.art-list:before { + content:""; + display:table; +} +.nav:after, +.art-body-inner:after, +.footer:after, +.art-list:after { + clear:both; +} +.nav, +.art-body-inner, +.footer, +.art-list { + zoom:1; /* For IE 6/7 (trigger hasLayout) */ +} + + +@-webkit-keyframes le-fade { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@-moz-keyframes le-fade { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +.art-header-inner { + -webkit-animation: le-fade .5s 0 1 ease-out; + -moz-animation: le-fade .5s 0 1 ease-out; +} + +.art-list, +.nav, +.abt, +.art-body { + -webkit-animation: le-fade .5s 0s 1 ease-out; + -moz-animation: le-fade .5s 0s 1 ease-out; +} + +hr.featured-article { + padding: 0; + border: none; + border-top: medium double #bbb; + color: #bbb; + text-align: center; +} +hr.featured-article:after { + content: "? Featured Article ?"; + display: inline-block; + position: relative; + top: -0.8em; + font-size: 1.2em; + padding: 0 0.6em; + background: white; +} + +/* FORM */ + +#contact-area { + width: 600px; + margin-top: 25px; +} + +#contact-area input, #contact-area textarea { + padding: 5px; + width: 471px; + font-family: Helvetica, sans-serif; + margin: 0px 0px 10px 0px; + border: 2px solid #ccc; +} + +#contact-area textarea { + height: 90px; +} + +#contact-area textarea:focus, #contact-area input:focus { + border: 2px solid #900; +} + +#contact-area input.submit-button { + width: 100px; + +} + +label { + float: left; + text-align: right; + margin-right: 15px; + width: 100px; + padding-top: 5px; +} \ No newline at end of file diff --git a/IF3110-02-Simple-Blog-Java/web/assets/img/favicon.ico b/IF3110-02-Simple-Blog-Java/web/assets/img/favicon.ico new file mode 100644 index 00000000..40b40ed3 Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/web/assets/img/favicon.ico differ diff --git a/IF3110-02-Simple-Blog-Java/web/assets/img/pre.png b/IF3110-02-Simple-Blog-Java/web/assets/img/pre.png new file mode 100644 index 00000000..7f48517b Binary files /dev/null and b/IF3110-02-Simple-Blog-Java/web/assets/img/pre.png differ diff --git a/IF3110-02-Simple-Blog-Java/web/assets/js/myjs.js b/IF3110-02-Simple-Blog-Java/web/assets/js/myjs.js new file mode 100644 index 00000000..f33aef56 --- /dev/null +++ b/IF3110-02-Simple-Blog-Java/web/assets/js/myjs.js @@ -0,0 +1,176 @@ +function validateEmail() { + var email = document.getElementById("email").value; + var pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + var result = pattern.test(email); + + if (!result) { + document.getElementById("email").style.backgroundColor = "#ffaaaa"; + document.getElementById("submitKomentar").disabled = true; + } else { + document.getElementById("email").style.backgroundColor = "#aaffaa"; + document.getElementById("submitKomentar").disabled = false; + } + return result; +} + +function sendComment() { + var idPost = encodeURIComponent(document.getElementById("id").value); + var nama = encodeURIComponent(document.getElementById("nama").value); + var email = encodeURIComponent(document.getElementById("email").value); + var komentar = encodeURIComponent(document.getElementById("komentar").value); + + if (!validateKomentar(nama, email, komentar)) { + return false; + } + + var xmlhttp; + if (window.XMLHttpRequest) { + xmlhttp = new XMLHttpRequest(); + } else { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + existingComment = document.getElementById("komentar-placeholder").innerHTML; + document.getElementById("komentar-placeholder").innerHTML = xmlhttp.responseText; + + if (!document.getElementById("nama").disabled) + document.getElementById("nama").value = ''; + if (!document.getElementById("email").disabled) + document.getElementById("email").value = ''; + document.getElementById("komentar").value = ''; + } + } + + var parameters = "idpost=" + idPost + "&nama=" + nama + "&email=" + email + "&komentar=" + komentar; + xmlhttp.open("POST", "SaveComment", true); + xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xmlhttp.send(parameters); +} + +window.onload = loadComment(); + +function loadComment() { + var idPost = encodeURIComponent(document.getElementById("id").value); + + var xmlhttp; + if (window.XMLHttpRequest) { + xmlhttp = new XMLHttpRequest(); + } else { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("komentar-placeholder").innerHTML = xmlhttp.responseText; + } + } + + var parameters = "idpost=" + idPost; + xmlhttp.open("GET", "LoadComment?" + parameters, true); + xmlhttp.send(null); +} + +function validateKomentar(nama, email, komentar) { + if (isEmpty(nama)) { + alert('Kolom nama tidak boleh kosong'); + return false; + } + if (isEmpty(email)) { + alert('Kolom email tidak boleh kosong'); + return false; + } + if (isEmpty(komentar)) { + alert('Kolom komentar tidak boleh kosong'); + return false; + } + if (!validateEmail()) { + alert('Email tidak valid'); + return false; + } + + return true; +} + +function confirmDeletion(postId) { + var confirm = window.confirm("Apakah Anda yakin menghapus post ini secara permanen?"); + if (confirm == true) { + window.location = "DeletePost?id=" + postId; + } else { + return false; + } +} + +function confirmSoftDeletion(postId) { + var confirm = window.confirm("Apakah Anda yakin menghapus post ini?"); + if (confirm == true) { + window.location = "SoftDelete?id=" + postId; + } else { + return false; + } +} + +function confirmRemoveImagePost(postId) { + var confirm = window.confirm("Apakah Anda yakin menghapus image post ini?"); + if (confirm == true) { + window.location = "RemoveImagePost?id=" + postId; + } else { + return false; + } +} + +function validate() { + var judul = document.getElementById("judul").value; + var content = document.getElementById("konten").value; + var validDateFormat = true; + var rawDate, tanggal; + try { + rawDate = document.getElementById("tanggal").value.split("/"); + if (rawDate[2] < 1990 || rawDate[2] > 2099 || rawDate[0] < 0 || rawDate[0] > 12 || rawDate[1] < 0 || rawDate[1] > 31) { + validDateFormat = false; + } else { + tanggal = new Date(rawDate[2], rawDate[0] - 1, rawDate[1]); + } + } catch(exception) { + validDateFormat = false; + } + var today = new Date(); + + if (isEmpty(judul)) { + alert("Judul tidak boleh kosong"); + return false; + } + if (validDateFormat) { + if (!compareDate(tanggal, today)) { + alert("Format tanggal tidak valid"); + return false; + } + } else { + alert("Format tanggal tidak valid"); + return false; + } + if (isEmpty(content)) { + alert("Konten tidak boleh kosong"); + return false; + } + + return true; +} + +function compareDate(tanggal, today) { + if (tanggal.getFullYear() > today.getFullYear()) + return true; + if (tanggal.getFullYear() < today.getFullYear()) + return false; + if (tanggal.getMonth() > today.getMonth()) + return true; + if (tanggal.getMonth() < today.getMonth()) + return false; + if (tanggal.getDate() >= today.getDate()) + return true; + if (tanggal.getDate() < today.getDate()) + return false; +} + +function isEmpty(val){ + return (val === undefined || val == null || val.length <= 0) ? true : false; +} \ No newline at end of file