#{Post.fetchPost(param['id']).judul}
+ + ++ #{Post.fetchPost(param['id']).konten} +
+ +Untuk sementara hanya admin yang bisa akses semua page, + role number admin = 2
++ #{Post.fetchPost(param['id']).konten} +
+ +#{komentar.tanggal} | #{komentar.nama}
++ Yesterday at CSSConf, we launched Pure – a new CSS library. Phew! Here are the slides from the presentation. Although it looks pretty minimalist, we’ve been working on Pure for several months. After many iterations, we have released Pure as a set of small, responsive, CSS modules that you can use in every web project. +
++ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +
++ We are happy to announce the release of YUI 3.10.2! You can find it now on the Yahoo! CDN, download it directly, or pull it in via npm. We’ve also updated the YUI Library website with the latest documentation. +
+Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis aliquam minus consequuntur amet nulla eius, neque beatae, nostrum possimus, officiis eaque consectetur. Sequi sunt maiores dolore, illum quidem eos explicabo! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam consequuntur consequatur molestiae saepe sed, incidunt sunt inventore minima voluptatum adipisci hic, est ipsa iste. Nobis, aperiam provident quae. Reprehenderit, iste.
-Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores animi tenetur nam delectus eveniet iste non culpa laborum provident minima numquam excepturi rem commodi, officia accusamus eos voluptates obcaecati. Possimus?
- -Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis repudiandae quae natus quos alias eos repellendus a obcaecati cupiditate similique quibusdam, atque omnis illum, minus ex dolorem facilis tempora deserunt! …
-Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis repudiandae quae natus quos alias eos repellendus a obcaecati cupiditate similique quibusdam, atque omnis illum, minus ex dolorem facilis tempora deserunt! …
-This has been appended by an intrusive filter."); + */ + } + + /** + * + * @param request The servlet request we are processing + * @param response The servlet response we are creating + * @param chain The filter chain we are processing + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet error occurs + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) + throws IOException, ServletException { + + if (debug) { + log("AuthenticationFilter:doFilter()"); + } + + doBeforeProcessing(request, response); + + Throwable problem = null; + try { + + // check whether session variable is set + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse res = (HttpServletResponse) response; + HttpSession ses = req.getSession(); + UserBean user; + NavigationController nc = new NavigationController(); + user = (UserBean)ses.getAttribute("userBean"); + // allow user to proccede if url is Login.xhtml or List-Post.xhtml or View-Post.xhtml + // TODO ganti ini dengan navigation bean kalau navigation bean sudah selesai + String reqURI = req.getRequestURI(); + reqURI = reqURI.substring(reqURI.indexOf("/faces/")+"/faces/".length()); + if (reqURI.startsWith(nc.gotoLogin()) + || reqURI.startsWith(nc.gotoListPost()) + || reqURI.startsWith("css/") + || reqURI.startsWith(nc.gotoViewPost()) + || reqURI.startsWith("javax.faces.resource/")) + chain.doFilter(request, response); + else if (user==null) + res.sendRedirect(req.getContextPath() +"/faces/" +nc.gotoLogin()); // Anonymous user. Redirect to login page + else if ((user.getRole() == UserBean.getOwner()) + && (reqURI.startsWith(nc.gotoEditPost()) + || reqURI.startsWith(nc.gotoAddPost()) + ) + ) + chain.doFilter(request, response); + else if ((user.getRole() == UserBean.getEditor()) + && (reqURI.startsWith(nc.gotoEditPost()) + || reqURI.startsWith(nc.gotoUnpublishedPost()) + || reqURI.startsWith(nc.gotoViewUnpublished()) + ) + ) + chain.doFilter(request, response); + else if (user.getRole() == UserBean.getAdmin()) + chain.doFilter(request, response); + else { + res.sendRedirect(req.getContextPath() +"/faces/" +nc.gotoLogin()); // Anonymous user. Redirect to login page + } + } + catch(Throwable t) { + System.out.println( t.getMessage()); + } + + doAfterProcessing(request, response); + + // If there was a problem, we want to rethrow it if it is + // a known type, otherwise log it. + if (problem != null) { + if (problem instanceof ServletException) { + throw (ServletException) problem; + } + if (problem instanceof IOException) { + throw (IOException) problem; + } + sendProcessingError(problem, response); + } + } + + /** + * Return the filter configuration object for this filter. + */ + public FilterConfig getFilterConfig() { + return (this.filterConfig); + } + + /** + * Set the filter configuration object for this filter. + * + * @param filterConfig The filter configuration object + */ + public void setFilterConfig(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + + /** + * Destroy method for this filter + */ + public void destroy() { + } + + /** + * Init method for this filter + */ + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + if (filterConfig != null) { + if (debug) { + log("AuthenticationFilter:Initializing filter"); + } + } + } + + /** + * Return a String representation of this object. + */ + @Override + public String toString() { + if (filterConfig == null) { + return ("AuthenticationFilter()"); + } + StringBuffer sb = new StringBuffer("AuthenticationFilter("); + sb.append(filterConfig); + sb.append(")"); + return (sb.toString()); + } + + private void sendProcessingError(Throwable t, ServletResponse response) { + String stackTrace = getStackTrace(t); + + if (stackTrace != null && !stackTrace.equals("")) { + try { + response.setContentType("text/html"); + PrintStream ps = new PrintStream(response.getOutputStream()); + PrintWriter pw = new PrintWriter(ps); + pw.print("\n
\n\n");
+ pw.print(stackTrace);
+ pw.print("\n"); //NOI18N
+ pw.close();
+ ps.close();
+ response.getOutputStream().close();
+ } catch (Exception ex) {
+ }
+ } else {
+ try {
+ PrintStream ps = new PrintStream(response.getOutputStream());
+ t.printStackTrace(ps);
+ ps.close();
+ response.getOutputStream().close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ public static String getStackTrace(Throwable t) {
+ String stackTrace = null;
+ try {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ pw.close();
+ sw.close();
+ stackTrace = sw.getBuffer().toString();
+ } catch (Exception ex) {
+ }
+ return stackTrace;
+ }
+
+ public void log(String msg) {
+ filterConfig.getServletContext().log(msg);
+ }
+
+}
diff --git a/src/java/model/AddKomentar.java b/src/java/model/AddKomentar.java
new file mode 100644
index 00000000..0747b393
--- /dev/null
+++ b/src/java/model/AddKomentar.java
@@ -0,0 +1,56 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package model;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+/**
+ *
+ * @author Afik
+ */
+public class AddKomentar {
+
+ // TODO semua, sambungin ke List-User.xhtml, dao, dan teman - teman
+
+ private UserBean user;
+ public AddKomentar() {
+
+ }
+
+ public void add(Komentar komentar) throws IOException {
+ if (user.getRole()!=UserBean.getGuest()) {
+ komentar.setNama(user.getUsername());
+ komentar.setEmail(user.getEmail());
+ }
+ String Tanggal = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+ komentar.setTanggal(Tanggal);
+ System.out.println("FLAG : "+komentar.getPID());
+ DAO.CommentDAO DB = DAO.DAOFactory.getInstance("javabase.jdbc").getKomentarDAO();
+ DB.create(komentar);
+ }
+
+ public String submit(Komentar komentar) throws IOException{
+ add(komentar);
+ return "succes?faces-redirect=true&includeViewParams=true";
+
+ }
+
+ /**
+ * @return the user
+ */
+ public UserBean getUser() {
+ return user;
+ }
+
+ /**
+ * @param user the user to set
+ */
+ public void setUser(UserBean user) {
+ this.user = user;
+ }
+}
diff --git a/src/java/model/AddUserBean.java b/src/java/model/AddUserBean.java
new file mode 100644
index 00000000..5fd592bc
--- /dev/null
+++ b/src/java/model/AddUserBean.java
@@ -0,0 +1,49 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package model;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * @author calvin-pc
+ */
+public class AddUserBean {
+ // TODO semua, sambungin ke List-User.xhtml, dao, dan teman - teman
+ private UserBean user;
+ /**
+ * Creates a new instance of AddUserBean
+ */
+ public AddUserBean() {
+ user = new UserBean();
+ }
+
+ /**
+ * @return the user
+ */
+ public UserBean getUser() {
+ return user;
+ }
+
+ /**
+ * @param user the user to set
+ */
+ public void setUser(UserBean user) {
+ this.user = user;
+ }
+
+ public void add() {
+ DAO.UserDAO DB = DAO.DAOFactory.getInstance("javabase.jdbc").getUserDAO();
+ if (DB.find(getUser().getUsername()) != null) {
+ FacesContext.getCurrentInstance().addMessage(null,
+ new FacesMessage("Username already exists!"));
+ }
+ else {
+ DB.create(getUser());
+ }
+ }
+}
diff --git a/src/java/model/AllKomentar.java b/src/java/model/AllKomentar.java
new file mode 100644
index 00000000..6fa23a94
--- /dev/null
+++ b/src/java/model/AllKomentar.java
@@ -0,0 +1,43 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package model;
+
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Afik
+ */
+public class AllKomentar {
+
+ private int PID;
+ private ArrayList+ #{Post.fetchPost(param['id']).konten} +
+ +#{komentar.tanggal} | #{komentar.nama}
+ + ++ #{Post.fetchPost(param['id']).konten} +
+ ++ Yesterday at CSSConf, we launched Pure – a new CSS library. Phew! Here are the slides from the presentation. Although it looks pretty minimalist, we’ve been working on Pure for several months. After many iterations, we have released Pure as a set of small, responsive, CSS modules that you can use in every web project. +
++ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +
++ We are happy to announce the release of YUI 3.10.2! You can find it now on the Yahoo! CDN, download it directly, or pull it in via npm. We’ve also updated the YUI Library website with the latest documentation. +
+