diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bc82db15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# NetBeans specific # +simple-blog/nbproject/ +simple-blog/nbproject/private/ +simple-blog/build/ +simple-blog/nbbuild/ +simple-blog/dist/ +simple-blog/nbdist/ +simple-blog/nbactions.xml +simple-blog/nb-configuration.xml + +# Class Files # +*.class diff --git a/simple-blog/build.xml b/simple-blog/build.xml new file mode 100644 index 00000000..9359e537 --- /dev/null +++ b/simple-blog/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project simple-blog. + + + diff --git a/simple-blog/build/web/META-INF/MANIFEST.MF b/simple-blog/build/web/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/simple-blog/build/web/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/simple-blog/build/web/META-INF/context.xml b/simple-blog/build/web/META-INF/context.xml new file mode 100644 index 00000000..dd73d3e1 --- /dev/null +++ b/simple-blog/build/web/META-INF/context.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/simple-blog/build/web/WEB-INF/classes/.netbeans_automatic_build b/simple-blog/build/web/WEB-INF/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/simple-blog/build/web/WEB-INF/classes/.netbeans_update_resources b/simple-blog/build/web/WEB-INF/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/simple-blog/build/web/WEB-INF/lib/javax.faces.jar b/simple-blog/build/web/WEB-INF/lib/javax.faces.jar new file mode 100644 index 00000000..51f63500 Binary files /dev/null and b/simple-blog/build/web/WEB-INF/lib/javax.faces.jar differ diff --git a/simple-blog/build/web/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar b/simple-blog/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/simple-blog/build/web/WEB-INF/lib/mysql-connector-java-5.1.23-bin.jar differ diff --git a/simple-blog/build/web/WEB-INF/web.xml b/simple-blog/build/web/WEB-INF/web.xml new file mode 100644 index 00000000..c215fbcf --- /dev/null +++ b/simple-blog/build/web/WEB-INF/web.xml @@ -0,0 +1,30 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/redirectIndex.xhtml + + + MySQL Datasource example + jdbc/simpleBlogDb + javax.sql.DataSource + Container + + diff --git a/simple-blog/build/web/index.xhtml b/simple-blog/build/web/index.xhtml new file mode 100644 index 00000000..f81e7a52 --- /dev/null +++ b/simple-blog/build/web/index.xhtml @@ -0,0 +1,55 @@ + + + + + + Simple Blog + + + + +
+ +
+
+ + + +
+
+ + diff --git a/simple-blog/build/web/mainTemplate.xhtml b/simple-blog/build/web/mainTemplate.xhtml new file mode 100644 index 00000000..29ad73da --- /dev/null +++ b/simple-blog/build/web/mainTemplate.xhtml @@ -0,0 +1,56 @@ + + + + + + + + + Simple Blog + + + + +
+ + + +
+
+ + + +
+
+ + + +
+ +
+ + diff --git a/simple-blog/build/web/resources/css/cssLayout.css b/simple-blog/build/web/resources/css/cssLayout.css new file mode 100644 index 00000000..fd40910d --- /dev/null +++ b/simple-blog/build/web/resources/css/cssLayout.css @@ -0,0 +1,4 @@ + + + + diff --git a/simple-blog/build/web/resources/css/default.css b/simple-blog/build/web/resources/css/default.css new file mode 100644 index 00000000..9c70ad56 --- /dev/null +++ b/simple-blog/build/web/resources/css/default.css @@ -0,0 +1,861 @@ +@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: 25px; +} + +h3 { + font-size: 40px; + padding-bottom: 20px; +} + +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: 600px; + /* 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: 200px; + 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: 100px; + 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 { + + 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 0 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/simple-blog/build/web/resources/data/simple_blog.sql b/simple-blog/build/web/resources/data/simple_blog.sql new file mode 100644 index 00000000..dbf28f93 --- /dev/null +++ b/simple-blog/build/web/resources/data/simple_blog.sql @@ -0,0 +1,115 @@ +-- phpMyAdmin SQL Dump +-- version 4.1.12 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Nov 24, 2014 at 03:53 PM +-- Server version: 5.6.16 +-- PHP Version: 5.5.11 + +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: `simple_blog` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `comment` +-- + +CREATE TABLE IF NOT EXISTS `comment` ( + `id` int(11) NOT NULL DEFAULT '0', + `post_id` int(11) NOT NULL, + `name` varchar(100) NOT NULL, + `email` varchar(100) NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `content` text NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `comment` +-- + +INSERT INTO `comment` (`id`, `post_id`, `name`, `email`, `date`, `content`) VALUES +(1, 1, 'sasuke uchiha', 'sasuke@gmail.com', '2014-11-24 14:53:00', 'f*ck you too!'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `post` +-- + +CREATE TABLE IF NOT EXISTS `post` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `title` varchar(100) NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `content` text NOT NULL, + `status` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; + +-- +-- Dumping data for table `post` +-- + +INSERT INTO `post` (`id`, `user_id`, `title`, `date`, `content`, `status`) VALUES +(1, 1, 'F*ck you!', '2014-11-24 14:44:19', 'tai kuda keinjek', 1), +(2, 1, 'kagebunshin no jutsu!', '2014-11-24 14:51:33', 'jadi jurus ini adalah...', 1); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `email` varchar(100) NOT NULL, + `username` varchar(16) NOT NULL, + `name` varchar(100) NOT NULL, + `password` varchar(16) NOT NULL, + `role` enum('admin','owner','editor') NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`id`, `email`, `username`, `name`, `password`, `role`) VALUES +(1, 'naruto@gmail.com', 'naruto69', 'naruto uzumaki', 'uzumakinaruto', 'admin'); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `comment` +-- +ALTER TABLE `comment` + ADD CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- +-- Constraints for table `post` +-- +ALTER TABLE `post` + ADD CONSTRAINT `post_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +/*!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/simple-blog/nbproject/ant-deploy.xml b/simple-blog/nbproject/ant-deploy.xml new file mode 100644 index 00000000..9bc5adf7 --- /dev/null +++ b/simple-blog/nbproject/ant-deploy.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/simple-blog/nbproject/build-impl.xml b/simple-blog/nbproject/build-impl.xml new file mode 100644 index 00000000..a9d2d60b --- /dev/null +++ b/simple-blog/nbproject/build-impl.xml @@ -0,0 +1,1446 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/simple-blog/nbproject/genfiles.properties b/simple-blog/nbproject/genfiles.properties new file mode 100644 index 00000000..32fa2553 --- /dev/null +++ b/simple-blog/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f04b4eed +build.xml.script.CRC32=3ae87e29 +build.xml.stylesheet.CRC32=651128d4@1.67.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=f04b4eed +nbproject/build-impl.xml.script.CRC32=767e0769 +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.67.1.1 diff --git a/simple-blog/nbproject/private/private.properties b/simple-blog/nbproject/private/private.properties new file mode 100644 index 00000000..c5f426b3 --- /dev/null +++ b/simple-blog/nbproject/private/private.properties @@ -0,0 +1,12 @@ +deploy.ant.properties.file=C:\\Users\\Luqman\\AppData\\Roaming\\NetBeans\\8.0\\tomcat70.properties +j2ee.server.domain=C:/Users/Ichwan Haryo Sembodo/AppData/Roaming/NetBeans/8.0/apache-tomcat-8.0.3.0_base +j2ee.server.home=D:/Dev/xampp/tomcat +j2ee.server.instance=tomcat70:home=D:\\Dev\\xampp\\tomcat +javac.debug=true +javadoc.preview=true +selected.browser=SL[/Browsers/FirefoxBrowser +<<<<<<< HEAD +user.properties.file=C:\\Users\\Luqman\\AppData\\Roaming\\NetBeans\\8.0\\build.properties +======= +user.properties.file=C:\\Users\\Luqman\\AppData\\Roaming\\NetBeans\\8.0\\build.properties +>>>>>>> 1ad5524ee457665f8af94fad951907782b8234f2 diff --git a/simple-blog/nbproject/private/private.xml b/simple-blog/nbproject/private/private.xml new file mode 100644 index 00000000..851db0b7 --- /dev/null +++ b/simple-blog/nbproject/private/private.xml @@ -0,0 +1,25 @@ + + + + + + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/model/ViewPost.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/viewPost.xhtml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/navigationBar.xhtml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/DatabaseController.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/WEB-INF/web.xml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/META-INF/context.xml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/model/CookieHelper.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/resources/css/cssLayout.css + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/nbproject/build-impl.xml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/resources/data/simple_blog.sql + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/model/Post.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/mainTemplate.xhtml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/ViewPostController.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/model/Comment.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/index.xhtml + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/src/java/simpleblog/PostController.java + file:/D:/Project/Web/SimpleBlog2/IF3110-02-Simple-Blog-Java/simple-blog/web/resources/css/default.css + + + diff --git a/simple-blog/nbproject/project.properties b/simple-blog/nbproject/project.properties new file mode 100644 index 00000000..3a5a1dee --- /dev/null +++ b/simple-blog/nbproject/project.properties @@ -0,0 +1,86 @@ +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=Facelets +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.6-web +j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.2.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar +j2ee.server.type=Tomcat +jar.compress=false +javac.classpath=\ + ${libs.jsf20.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.6 +javac.target=1.6 +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 +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=simple-blog.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/simple-blog/nbproject/project.xml b/simple-blog/nbproject/project.xml new file mode 100644 index 00000000..a711411d --- /dev/null +++ b/simple-blog/nbproject/project.xml @@ -0,0 +1,27 @@ + + + org.netbeans.modules.web.project + + + simple-blog + 1.6.5 + + + ${libs.jsf20.classpath} + WEB-INF/lib + + + ${libs.MySQLDriver.classpath} + WEB-INF/lib + + + + + + + + + + + + diff --git a/simple-blog/src/conf/MANIFEST.MF b/simple-blog/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/simple-blog/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/simple-blog/src/java/simpleblog/DatabaseController.java b/simple-blog/src/java/simpleblog/DatabaseController.java new file mode 100644 index 00000000..afcf6a28 --- /dev/null +++ b/simple-blog/src/java/simpleblog/DatabaseController.java @@ -0,0 +1,248 @@ +package simpleblog; + +/* + * 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. + */ + +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; +import static org.apache.tomcat.jni.User.username; +import simpleblog.model.User; +/** + * + * @author Luqman + */ +@ManagedBean(name="databaseController") +@SessionScoped +public class DatabaseController implements Serializable { + + private User user; + private DataSource ds; + private Context initCtx; + private Context envCtx; + private Connection conn; + private PreparedStatement ps; + private User selectedUser; + private List lusers; + /** + * Creates a new instance of dbTest + */ + public DatabaseController() { + System.out.println("db ctrl dibuat"); + selectedUser = new User(); + } + public User getSelectedUser() { + if(selectedUser == null) + selectedUser = new User(); + return selectedUser; + } + + public void setSelectedUser(User selectedUser) { + this.selectedUser = selectedUser; + } + + public User loginValidator(String username, String password){ + setUser(new User()); + try{ + //get database connection + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection conn = ds.getConnection(); + ps = conn.prepareStatement("SELECT * FROM user WHERE user.username = '" + username + "' AND user.password = '" + password + "'"); + ResultSet result = ps.executeQuery(); + result.next(); + getUser().setId(result.getInt("id")); + getUser().setEmail(result.getString("email")); + getUser().setUsername(result.getString("username")); + getUser().setName(result.getString("name")); + getUser().setPassword(result.getString("password")); + getUser().setRole(result.getString("role")); + + conn.close(); + + System.out.println("masuk database"); + return getUser(); + } catch (Exception e) { + System.out.println("masuk exception database"); + getUser().setRole("guest"); + return getUser(); + } + } + public User getUser() { + if(user == null) + user = new User(); + return user; + } + public User intialUser(){ + user = new User(); + return user; + } + /** + * @param user the user to set + */ + public void setUser(User user) { + this.user = user; + } + public List getUserList() throws SQLException{ + try { + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + } catch (NamingException e) { + } + if(ds==null) + throw new SQLException("Can't get data source"); + + //get database connection + conn = ds.getConnection(); + + if(conn==null) + throw new SQLException("Can't get database connection"); + + ps + = conn.prepareStatement( + "SELECT id,username,name,email,password,role FROM user"); + + //get customer data from database + ResultSet result = ps.executeQuery(); + List list = new ArrayList(); + + while(result.next()){ + setUser(new User()); + + getUser().setId(result.getInt("id")); + getUser().setEmail(result.getString("email")); + getUser().setName(result.getString("name")); + getUser().setUsername(result.getString("username")); + getUser().setPassword(result.getString("password")); + getUser().setRole(result.getString("role")); + //store all data into a List + list.add(getUser()); + } + + return list; + } + public void add() throws SQLException{ + try { + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + } catch (NamingException e) { + } + if(ds==null) + throw new SQLException("Can't get data source"); + + //get database connection + conn = ds.getConnection(); + if(conn==null) + throw new SQLException("Can't get database connection"); + else{ + ps = conn.prepareStatement("INSERT INTO user (username,name,email,password,role) VALUES('"+user.getUsername()+"','"+user.getName()+"','"+user.getEmail()+"','"+user.getPassword()+"','"+user.getRole()+"')"); + ps.executeUpdate(); + conn.close(); + ps.close();} + System.out.println("Berhasil"); + user = null; + } + + + public void delete() throws SQLException{ + try { + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + } catch (NamingException e) { + } + if(ds==null) + throw new SQLException("Can't get data source"); + + //get database connection + conn = ds.getConnection(); + if(conn==null) + throw new SQLException("Can't get database connection"); + else{ + ps = conn.prepareStatement("DELETE FROM user WHERE id = "+selectedUser.getId()+""); + ps.executeUpdate(); + conn.close(); + ps.close();} + System.out.println("Berhasil"); + } + public void update() throws SQLException{ + try { + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + } catch (NamingException e) { + } + if(ds==null) + throw new SQLException("Can't get data source"); + + //get database connection + conn = ds.getConnection(); + if(conn==null) + throw new SQLException("Can't get database connection"); + else{ + ps = conn.prepareStatement("UPDATE user SET email='"+selectedUser.getEmail()+"',username='"+selectedUser.getUsername()+"',name='"+selectedUser.getName()+"',password='"+selectedUser.getPassword()+"',role='"+selectedUser.getRole()+"' WHERE id = '"+selectedUser.getId()+"'"); + ps.executeUpdate(); + System.out.println(selectedUser.getName()); + conn.close(); + ps.close();} + System.out.println("Berhasil"); + } + public void settingSelectedUser(){ + try { + initCtx = new InitialContext(); + envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + //get database connection + conn = ds.getConnection(); + + System.out.println("SELECT * FROM user WHERE user.id ='"+selectedUser.getId()+"'"); + + ps = conn.prepareStatement("SELECT * FROM user WHERE user.id ='"+selectedUser.getId()+"'"); + ResultSet result = ps.executeQuery(); + result.next(); + selectedUser.setEmail(result.getString("email")); + selectedUser.setName(result.getString("name")); + selectedUser.setUsername(result.getString("username")); + selectedUser.setPassword(result.getString("password")); + selectedUser.setRole(result.getString("role")); + conn.close(); + ps.close(); + System.out.println("Berhasil"); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + public void nullUser(){ + user = new User(); + user.setRole(null); + } + + public void redirectTable() throws Exception{ + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + externalContext.redirect("faces/ShowTable.xhtml"); + } +} diff --git a/simple-blog/src/java/simpleblog/PostController.java b/simple-blog/src/java/simpleblog/PostController.java new file mode 100644 index 00000000..fc5a39bc --- /dev/null +++ b/simple-blog/src/java/simpleblog/PostController.java @@ -0,0 +1,419 @@ +/* + * 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 simpleblog; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.bean.ViewScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletContext; +import javax.servlet.http.Part; +import javax.sql.DataSource; +import simpleblog.model.Post; +import simpleblog.model.User; + +/** + * + * @author Luqman + */ +@ManagedBean +@ViewScoped +public class PostController implements Serializable { + private DataSource ds; + private String title; + private String date; + private String content; + private String post_id; + private Part image; + private Post post; + + /** + * Creates a new instance of PostController + */ + + public PostController(){ + title = new String(); + date = new String(); + content = new String(); + post = new Post(); + } + + public void setNull(){ + title = null; + date = null; + content = null; + } + + public void getDatabasePost(){ + try{ + //get database connection + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + System.out.println("SELECT * FROM post WHERE post.id = '"+ getPost_id() + "'"); + + Connection conn = ds.getConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT * FROM post WHERE post.id = '"+ getPost_id() + "'"); + ResultSet result = ps.executeQuery(); + result.next(); + post.setId(result.getInt("id")); + post.setUserId(result.getInt("user_id")); + post.setTitle(result.getString("title")); + + String[] date = result.getString("date").split(" "); + + post.setDate(date[0]); + post.setContent(result.getString("content")); + post.setStatus(result.getInt("status")); + + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public List getPostList() throws SQLException, NamingException + { + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps + = con.prepareStatement( + "SELECT * FROM post WHERE status=1"); + ResultSet result = ps.executeQuery(); + + List list = new ArrayList(); + + while(result.next()) + { + Post post = new Post(); + + post.setId(result.getInt("id")); + post.setTitle(result.getString("title")); + post.setContent(result.getString("content")); + post.setDate(result.getTimestamp("date").toString()); + post.setUserId(result.getInt("user_id")); + + list.add(post); + } + return list; + } + + public boolean insertPost(User user) throws NamingException, SQLException{ + try { + Date dates = new Date(); + date = date + " " + dates.getHours() + ":" + dates.getMinutes() + ":" + dates.getSeconds(); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement( + "INSERT INTO post (user_id, title, date, content, status) VALUES ('"+ user.getId() +"','"+ title +"','"+ date +"','"+ content +"','0')"); + ps.executeUpdate(); + ps = con.prepareStatement("SELECT LAST_INSERT_ID();"); + ResultSet result = ps.executeQuery(); + result.first(); + uploadImage(result.getInt(1)); + + con.close(); + + ps.close(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + public void uploadImage(int imageId) throws IOException + { + String fileExtension = getFileExtension(getImage()); + String basePath = "D:" + File.separator; + + File outputFilePath = new File(getImagePath()+ File.separator + "resources"+File.separator+"images" + File.separator + imageId + "." + fileExtension); + InputStream inputStream = null; + OutputStream outputStream = null; + System.out.println("Nama file " + outputFilePath.getAbsolutePath()); + + try { + inputStream = image.getInputStream(); + outputStream = new FileOutputStream(outputFilePath); + + int read = 0; + final byte[] bytes = new byte[1024*1024*5]; + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + + } catch (IOException e) { + } finally { + if (outputStream != null) { + outputStream.close(); + } + if (inputStream != null) { + inputStream.close(); + } + } + } + + public String getImagePath() + { + ExternalContext ctx; + ctx = FacesContext.getCurrentInstance().getExternalContext(); + String absoluteWebPath = ctx.getRealPath("/"); + return absoluteWebPath; + } + + private String getFileExtension(Part part) { + final String partHeader = part.getHeader("content-disposition"); + System.out.println("***** partHeader: " + partHeader); + for (String content : part.getHeader("content-disposition").split(";")) { + if (content.trim().startsWith("filename")) { + String fileName = content.substring(content.indexOf('=') + 1).trim().replace("\"", ""); + String[] subFileName = fileName.split("\\."); + return subFileName[subFileName.length-1]; + } + } + return null; + } + + + public boolean editPost() throws NamingException, SQLException{ + try { + Date dates = new Date(); + post.setDate(post.getDate() + " " + dates.getHours() + ":" + dates.getMinutes() + ":" + dates.getSeconds()); + System.out.println("UPDATE post SET title= '"+ post.getTitle() +"', date= '"+ post.getDate() +"', content= '"+ post.getContent() +"' WHERE id = '"+ post_id +"'"); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement( + "UPDATE post SET title= '"+ post.getTitle() +"', date= '"+ post.getDate() +"', content= '"+ post.getContent() +"' WHERE id = '"+ post_id +"'"); + ps.executeUpdate(); + con.close(); + ps.close(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public String actionInsertPost(User user) throws NamingException, SQLException{ + if(insertPost(user)){ + return "index"; + } + else return ""; + } + + public String actionEditPost() throws NamingException, SQLException{ + if(editPost()){ + return "index"; + } + else return ""; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the date + */ + public String getDate() { + return date; + } + + /** + * @param date the date to set + */ + public void setDate(String date) { + this.date = date; + } + + /** + * @return the content + */ + public String getContent() { + return content; + } + + /** + * @param content the content to set + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return the post + */ + public Post getPost() { + return post; + } + + /** + * @param post the post to set + */ + public void setPost(Post post) { + this.post = post; + } + + /** + * @return the post_id + */ + public String getPost_id() { + return post_id; + } + + /** + * @param post_id the post_id to set + */ + public void setPost_id(String post_id) { + this.post_id = post_id; + } + + public Part getImage() { + return image; + } + + public void setImage(Part image) { + this.image = image; + } + + + public void softDelete(){ + try { + System.out.println("UPDATE post SET status = 2 WHERE id =" + post_id); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement( + "UPDATE post SET status = 2 WHERE id =" + post_id); + ps.executeUpdate(); + con.close(); + ps.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void hardDelete(int id){ + try { + System.out.println("DELETE FROM post WHERE id = "+post_id); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement( + "DELETE FROM post WHERE id = "+id); + ps.executeUpdate(); + con.close(); + ps.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void redirectIndex() throws Exception{ + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + externalContext.redirect("index.xhtml"); + } + + public List getSoftDeletedPost() throws SQLException, NamingException + { + DataSource ds; + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps + = con.prepareStatement( + "SELECT * FROM post WHERE status=2"); + ResultSet result = ps.executeQuery(); + + List list = new ArrayList(); + + while(result.next()) + { + Post post = new Post(); + + post.setId(result.getInt("id")); + post.setTitle(result.getString("title")); + post.setContent(result.getString("content")); + post.setDate(result.getTimestamp("date").toString()); + post.setUserId(result.getInt("user_id")); + list.add(post); + } + return list; + } + + public String restorePost(int post_id) + { + DataSource ds; + try { + Date dates = new Date(); + System.out.println("UPDATE post SET status=1 WHERE id = '"+ post_id +"'"); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement("UPDATE post SET status=1 WHERE id = '"+ post_id +"'"); + ps.executeUpdate(); + con.close(); + ps.close(); + return ""; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + +} diff --git a/simple-blog/src/java/simpleblog/PublishPostController.java b/simple-blog/src/java/simpleblog/PublishPostController.java new file mode 100644 index 00000000..bc768903 --- /dev/null +++ b/simple-blog/src/java/simpleblog/PublishPostController.java @@ -0,0 +1,82 @@ +/* + * 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 simpleblog; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ViewScoped; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; +import simpleblog.model.Post; + +/** + * + * @author Luqman + */ +@ManagedBean +@ViewScoped +public class PublishPostController { + + public List getPostList() throws SQLException, NamingException + { + System.out.println("SELECT * FROM post WHERE status=0"); + DataSource ds; + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps + = con.prepareStatement( + "SELECT * FROM post WHERE status=0"); + ResultSet result = ps.executeQuery(); + + List list = new ArrayList(); + + while(result.next()) + { + Post post = new Post(); + + post.setId(result.getInt("id")); + post.setTitle(result.getString("title")); + post.setContent(result.getString("content")); + post.setDate(result.getTimestamp("date").toString()); + post.setUserId(result.getInt("user_id")); + list.add(post); + } + return list; + } + public String publishPost(int post_id) + { + DataSource ds; + try { + Date dates = new Date(); + System.out.println("UPDATE post SET status=1 WHERE id = '"+ post_id +"'"); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps = con.prepareStatement("UPDATE post SET status=1 WHERE id = '"+ post_id +"'"); + ps.executeUpdate(); + con.close(); + ps.close(); + return ""; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } +} diff --git a/simple-blog/src/java/simpleblog/UserController.java b/simple-blog/src/java/simpleblog/UserController.java new file mode 100644 index 00000000..5fb7d1aa --- /dev/null +++ b/simple-blog/src/java/simpleblog/UserController.java @@ -0,0 +1,271 @@ +package simpleblog; + +/* + * 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. + */ + +import java.io.IOException; +import java.io.Serializable; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import simpleblog.model.CookieHelper; +import simpleblog.model.User; +import simpleblog.model.User; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Resource; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; +import simpleblog.model.Post; + +/** + * + * @author Ichwan Haryo Sembodo + */ +@ManagedBean +@SessionScoped +public class UserController implements Serializable{ + + private CookieHelper cookie; + private User user; + private String username; + private String password; + + /** + * Creates a new instance of UserController + */ + public UserController() { + System.out.println("user ctrl dibuat"); + user = new User(); + cookie = new CookieHelper(); + } + + public User loginValidator(String username, String password){ + user = new User(); + try{ + //get database connection + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + DataSource ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection conn = ds.getConnection(); + PreparedStatement ps = conn.prepareStatement("SELECT * FROM user WHERE user.username = '" + username + "' AND user.password = '" + password + "'"); + ResultSet result = ps.executeQuery(); + result.next(); + user.setId(result.getInt("id")); + user.setEmail(result.getString("email")); + user.setUsername(result.getString("username")); + user.setName(result.getString("name")); + user.setPassword(result.getString("password")); + user.setRole(result.getString("role")); + + conn.close(); + + return user; + } catch (Exception e) { + user.setRole("guest"); + return user; + } + } + + /** + * @return the user + */ + public User getUser() { + return loginValidator(username, password); + } + + /** + * @param user the user to set + */ + public void setUser(User user) { + System.out.println("set user"); + this.user = user; + } + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(String username) { + System.out.println("set username"); + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(String password) { + System.out.println("set password"); + this.password = password; + } + + public boolean showEditHapus(int id){ + System.out.println("=========show edit hapus method========="); + System.out.println("role diset = " + user.getRole()); + System.out.println("user id = " + user.getId()); + System.out.println("post user id = " + id); + if(user.getRole().equals("admin")) + { + return true; + } + else if(user.getRole().equals("owner") && user.getId() == id) + { + return true; + } + else if(user.getRole().equals("editor")) + { + return true; + } + return false; + } + + public String actionLogin(){ + System.out.println("=========action login method========="); + getUser(); + if(showEditHapus(user.getId())){ + cookie.setCookie("username", username, 86400); + cookie.setCookie("password", password, 86400); + return ""; + } + else return ""; + } + + /** + * @return the cookie + */ + public CookieHelper getCookie() { + return cookie; + } + + /** + * @param cookie the cookie to set + */ + public void setCookie(CookieHelper cookie) { + this.cookie = cookie; + } + + public boolean isUsernamePasswordExist(){ + System.out.println("=========is Username Password exist method========="); + if(cookie.getCookie("username") != null && cookie.getCookie("password") != null){ + System.out.println("username cookie = " + cookie.getCookie("username").getValue()); + System.out.println("password cookie = " + cookie.getCookie("password").getValue()); + if(user.getRole().equals("guest")){ + if(username == null && password == null){ + setUsername(cookie.getCookie("username").getValue()); + setPassword(cookie.getCookie("password").getValue()); + getUser(); + if(showEditHapus(user.getId())){ + System.out.println("cookie != null dan guest dan username & password == null dan valid"); + return true; + } + else{ + System.out.println("cookie != null dan guest dan username & password == null dan tidak valid"); + return false; + } + } + else { + if(username.equals("") && password.equals("")){ + System.out.println("cookie != null dan guest dan username & password = ''"); + return false; + } + else{ + System.out.println("cookie != null dan guest dan username & password = " + username + " & " + password); + return true; + } + } + } + else { + System.out.println("cookie != null dan !guest dan username & password != null"); + return true; + } + } + else{ + if(username != null && password != null){ + if(showEditHapus(user.getId())){ + System.out.println("cookie = null dan username & password != null dan valid"); + return true; + } + else { + System.out.println("cookie = null dan username & password != null dan tidak valid"); + return false; + } + } + else { + System.out.println("cookie = null dan username & password = null"); + return false; + } + } + } + + public String actionLogout(){ + System.out.println("=========action logout method========="); + cookie.setCookie("username", null, 0); + cookie.setCookie("password", null, 0); + User tmp = new User(); + user = tmp; + setUsername(""); + System.out.println("set username to null"); + setPassword(""); + System.out.println("set password to null"); + System.out.println("cookie dihapus"); + System.out.println("username time left = "+cookie.getCookie("username").getMaxAge()); + System.out.println("password time left = "+cookie.getCookie("password").getMaxAge()); + System.out.println("username cookie = " + cookie.getCookie("username").getValue()); + System.out.println("password cookie = " + cookie.getCookie("password").getValue()); + return ""; + } + + public void redirect() throws IOException{ + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + externalContext.redirect("faces/index.xhtml"); + } + + public void test(){ + System.out.println("=======================selesai iterasi=========================="); + } + + public boolean isAdmin(){ + return user.getRole().equals("admin"); + } + + public boolean isOwner(){ + return user.getRole().equals("owner"); + } + + public boolean isEditor(){ + return user.getRole().equals("editor"); + } + + public boolean isGuest(){ + return user.getRole().equals("guest"); + } + +} diff --git a/simple-blog/src/java/simpleblog/ViewPostController.java b/simple-blog/src/java/simpleblog/ViewPostController.java new file mode 100644 index 00000000..4767b6ff --- /dev/null +++ b/simple-blog/src/java/simpleblog/ViewPostController.java @@ -0,0 +1,176 @@ +/* + * 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 simpleblog; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import javax.faces.bean.SessionScoped; +import javax.faces.bean.ViewScoped; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; +import simpleblog.model.Comment; +import simpleblog.model.Post; +import simpleblog.model.ViewPost; + +/** + * + * @author Luqman + */ +@ManagedBean(eager=true) +@ViewScoped +public class ViewPostController { + private int postId; + private ViewPost viewPost; + + public void getPost() + { + try { + DataSource ds; + viewPost = new ViewPost(); + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + PreparedStatement ps + = con.prepareStatement( + "SELECT * FROM post WHERE id="+postId); + ResultSet result = ps.executeQuery(); + if(result.first()) + { + viewPost.setId(result.getInt("id")); + viewPost.setTitle(result.getString("title")); + viewPost.setContent(result.getString("content")); + viewPost.setDate(result.getTimestamp("date").toString()); + } + + + } catch (NamingException ex) { + Logger.getLogger(ViewPostController.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(ViewPostController.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private String inputName; + private String inputEmail; + private String inputComment; + + public List getComment() + { + List list = new ArrayList(); + try { + System.out.println("Bakemono "+inputName); + System.out.println("Bakemono "+inputEmail); + System.out.println("Bakemono "+inputComment); + DataSource ds; + Context initCtx = new InitialContext(); + Context envCtx = (Context) initCtx.lookup("java:comp/env"); + ds = (DataSource) envCtx.lookup("jdbc/simpleBlogDb"); + + Connection con = ds.getConnection(); + + PreparedStatement ps; + ResultSet result; + if(getInputName() != null && getInputName() != "") + { + System.out.println("Bakemono : "+"INSERT INTO comment (post_id,name,email,content) VALUES ('"+postId+"','"+getInputName()+"','"+getInputEmail()+"','"+getInputComment()+"')"); + ps = con.prepareStatement("INSERT INTO comment (post_id,name,email,content) VALUES ('"+postId+"','"+getInputName()+"','"+getInputEmail()+"','"+getInputComment()+"')"); + ps.executeUpdate(); + setInputName(null); + setInputEmail(null); + setInputComment(null); + } + ps = con.prepareStatement("SELECT * FROM comment WHERE post_id="+postId); + result = ps.executeQuery(); + while(result.next()) + { + Comment comment = new Comment(); + + comment.setId(result.getInt("id")); + comment.setPostId(result.getInt("post_id")); + comment.setName(result.getString("name")); + comment.setEmail(result.getString("email")); + comment.setDate(result.getTimestamp("date").toString()); + comment.setContent(result.getString("content")); + + list.add(comment); + } + + + } catch (NamingException ex) { + Logger.getLogger(ViewPostController.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(ViewPostController.class.getName()).log(Level.SEVERE, null, ex); + } + return list; + } + + /** + * @return the postId + */ + public int getPostId() { + return postId; + } + + /** + * @param postId the postId to set + */ + public void setPostId(int postId) { + this.postId = postId; + } + + /** + * @return the viewPost + */ + public ViewPost getViewPost() { + return viewPost; + } + + /** + * @param viewPost the viewPost to set + */ + public void setViewPost(ViewPost viewPost) { + this.viewPost = viewPost; + } + + public String getInputName() { + return inputName; + } + + public void setInputName(String inputName) { + this.inputName = inputName; + } + + public String getInputEmail() { + return inputEmail; + } + + public void setInputEmail(String inputEmail) { + this.inputEmail = inputEmail; + } + + public String getInputComment() { + return inputComment; + } + + public void setInputComment(String inputComment) { + this.inputComment = inputComment; + } + +} diff --git a/simple-blog/src/java/simpleblog/model/Comment.java b/simple-blog/src/java/simpleblog/model/Comment.java new file mode 100644 index 00000000..f906a3ea --- /dev/null +++ b/simple-blog/src/java/simpleblog/model/Comment.java @@ -0,0 +1,68 @@ +/* + * 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 simpleblog.model; + +/** + * + * @author Luqman + */ +public class Comment { + private int id; + private int postId; + private String name; + private String email; + private String date; + private String content; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getPostId() { + return postId; + } + + public void setPostId(int postId) { + this.postId = postId; + } + + 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 String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/simple-blog/src/java/simpleblog/model/CookieHelper.java b/simple-blog/src/java/simpleblog/model/CookieHelper.java new file mode 100644 index 00000000..ef68c5e0 --- /dev/null +++ b/simple-blog/src/java/simpleblog/model/CookieHelper.java @@ -0,0 +1,70 @@ +package simpleblog.model; + + +import javax.faces.context.FacesContext; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/* + * 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. + */ + +/** + * + * @author Ichwan Haryo Sembodo + */ +public class CookieHelper { + + public void setCookie(String name, String value,int expiry) { + + FacesContext facesContext = FacesContext.getCurrentInstance(); + + HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); + Cookie cookie = null; + + Cookie[] userCookies = request.getCookies(); + if (userCookies != null && userCookies.length > 0 ) { + for (int i = 0; i < userCookies.length; i++) { + if (userCookies[i].getName().equals(name)) { + cookie = userCookies[i]; + break; + } + } + } + + if (cookie != null) { + cookie.setValue(value); + } else { + cookie = new Cookie(name, value); + //cookie.setPath(request.getContextPath()); + } + + cookie.setMaxAge(expiry); + + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); + response.setContentType("text/html"); + response.addCookie(cookie); + } + + public Cookie getCookie(String name) { + + FacesContext facesContext = FacesContext.getCurrentInstance(); + + HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); + Cookie cookie = null; + + Cookie[] userCookies = request.getCookies(); + if (userCookies != null && userCookies.length > 0 ) { + for (int i = 0; i < userCookies.length; i++) { + if (userCookies[i].getName().equals(name)) { + cookie = userCookies[i]; + return cookie; + } + } + } + return null; + } +} \ No newline at end of file diff --git a/simple-blog/src/java/simpleblog/model/Post.java b/simple-blog/src/java/simpleblog/model/Post.java new file mode 100644 index 00000000..e9aefa8c --- /dev/null +++ b/simple-blog/src/java/simpleblog/model/Post.java @@ -0,0 +1,104 @@ +/* + * 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 simpleblog.model; + +/** + * + * @author Luqman + */ +public class Post { + private int id; + private String title; + private String content; + private String date; + private int userId; + private int status; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the content + */ + public String getContent() { + return content; + } + + /** + * @param content the content to set + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return the date + */ + public String getDate() { + return date; + } + + /** + * @param date the date to set + */ + public void setDate(String date) { + this.date = date; + } + + /** + * @return the userId + */ + public int getUserId() { + return userId; + } + + /** + * @param userId the userId to set + */ + public void setUserId(int userId) { + this.userId = userId; + } + + /** + * @return the status + */ + public int getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(int status) { + this.status = status; + } +} diff --git a/simple-blog/src/java/simpleblog/model/User.java b/simple-blog/src/java/simpleblog/model/User.java new file mode 100644 index 00000000..0bd78c4c --- /dev/null +++ b/simple-blog/src/java/simpleblog/model/User.java @@ -0,0 +1,110 @@ +package simpleblog.model; + +/* + * 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. + */ + +/** + * + * @author Ichwan Haryo Sembodo + */ +public class User { + private int id; + private String email; + private String username; + private String name; + private String password; + private String role; + + public User(){ + role = "guest"; + } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * @param email the email to set + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * @return the role + */ + public String getRole() { + return role; + } + + /** + * @param role the role to set + */ + public void setRole(String role) { + this.role = role; + } + + +} diff --git a/simple-blog/src/java/simpleblog/model/ViewPost.java b/simple-blog/src/java/simpleblog/model/ViewPost.java new file mode 100644 index 00000000..cf21f3be --- /dev/null +++ b/simple-blog/src/java/simpleblog/model/ViewPost.java @@ -0,0 +1,75 @@ +/* + * 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 simpleblog.model; + +/** + * + * @author Luqman + */ +public class ViewPost { + private int id; + private String title; + private String content; + private String date; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the content + */ + public String getContent() { + return content; + } + + /** + * @param content the content to set + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return the date + */ + public String getDate() { + return date; + } + + /** + * @param date the date to set + */ + public void setDate(String date) { + this.date = date; + } + +} diff --git a/simple-blog/web/DeleteTable.xhtml b/simple-blog/web/DeleteTable.xhtml new file mode 100644 index 00000000..c6ac7011 --- /dev/null +++ b/simple-blog/web/DeleteTable.xhtml @@ -0,0 +1,18 @@ + + + + + + + + + Simple Blog + + + + + \ No newline at end of file diff --git a/simple-blog/web/EditTable.xhtml b/simple-blog/web/EditTable.xhtml new file mode 100644 index 00000000..324acd17 --- /dev/null +++ b/simple-blog/web/EditTable.xhtml @@ -0,0 +1,61 @@ + + + + + + + + + Insert Data + + + + +
+ +
+
+
+
+ \ No newline at end of file diff --git a/simple-blog/web/InsertTabel.xhtml b/simple-blog/web/InsertTabel.xhtml new file mode 100644 index 00000000..ba81bd5c --- /dev/null +++ b/simple-blog/web/InsertTabel.xhtml @@ -0,0 +1,60 @@ + + + + + + + + Insert Data + + + + +
+ +
+
+
+
+ \ No newline at end of file diff --git a/simple-blog/web/META-INF/context.xml b/simple-blog/web/META-INF/context.xml new file mode 100644 index 00000000..dd73d3e1 --- /dev/null +++ b/simple-blog/web/META-INF/context.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/simple-blog/web/ShowTable.xhtml b/simple-blog/web/ShowTable.xhtml new file mode 100644 index 00000000..216888b2 --- /dev/null +++ b/simple-blog/web/ShowTable.xhtml @@ -0,0 +1,80 @@ + + + + + + + + + + +
+ +
+
+ + + +
+
+ + \ No newline at end of file diff --git a/simple-blog/web/WEB-INF/web.xml b/simple-blog/web/WEB-INF/web.xml new file mode 100644 index 00000000..c215fbcf --- /dev/null +++ b/simple-blog/web/WEB-INF/web.xml @@ -0,0 +1,30 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/redirectIndex.xhtml + + + MySQL Datasource example + jdbc/simpleBlogDb + javax.sql.DataSource + Container + + diff --git a/simple-blog/web/addPost.xhtml b/simple-blog/web/addPost.xhtml new file mode 100644 index 00000000..acb8cf93 --- /dev/null +++ b/simple-blog/web/addPost.xhtml @@ -0,0 +1,44 @@ + + + + + + +

+
+
+ +
+ + + + + + + + + + +

+ + + + + +
+
+
+
+
+ + + +
+
+ + diff --git a/simple-blog/web/deletedPost.xhtml b/simple-blog/web/deletedPost.xhtml new file mode 100644 index 00000000..9cc1853a --- /dev/null +++ b/simple-blog/web/deletedPost.xhtml @@ -0,0 +1,52 @@ + + + + + Restore Post + + + + +
+ +
+
+ + + +
+
+ + diff --git a/simple-blog/web/editPost.xhtml b/simple-blog/web/editPost.xhtml new file mode 100644 index 00000000..33802c5a --- /dev/null +++ b/simple-blog/web/editPost.xhtml @@ -0,0 +1,43 @@ + + + + + + + + + + +

+
+
+ +
+ + + + + + + +

+ + + +
+
+
+
+
+ + + +
+
+ + diff --git a/simple-blog/web/index.xhtml b/simple-blog/web/index.xhtml new file mode 100644 index 00000000..f81e7a52 --- /dev/null +++ b/simple-blog/web/index.xhtml @@ -0,0 +1,55 @@ + + + + + + Simple Blog + + + + +
+ +
+
+ + + +
+
+ + diff --git a/simple-blog/web/mainTemplate.xhtml b/simple-blog/web/mainTemplate.xhtml new file mode 100644 index 00000000..29ad73da --- /dev/null +++ b/simple-blog/web/mainTemplate.xhtml @@ -0,0 +1,56 @@ + + + + + + + + + Simple Blog + + + + +
+ + + +
+
+ + + +
+
+ + + +
+ +
+ + diff --git a/simple-blog/web/navigationBar.xhtml b/simple-blog/web/navigationBar.xhtml new file mode 100644 index 00000000..8a4dd2d5 --- /dev/null +++ b/simple-blog/web/navigationBar.xhtml @@ -0,0 +1,38 @@ + + + + + + + + + + + + +

+ + + + | + + | + + | + + + + | + + + | + + +

+
+ diff --git a/simple-blog/web/publishPost.xhtml b/simple-blog/web/publishPost.xhtml new file mode 100644 index 00000000..11497b4d --- /dev/null +++ b/simple-blog/web/publishPost.xhtml @@ -0,0 +1,51 @@ + + + + + Facelet Title + + + + +
+ +
+
+
+
+ + diff --git a/simple-blog/web/redirectDeletePost.xhtml b/simple-blog/web/redirectDeletePost.xhtml new file mode 100644 index 00000000..04daafba --- /dev/null +++ b/simple-blog/web/redirectDeletePost.xhtml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/simple-blog/web/redirectDeleteUser.xhtml b/simple-blog/web/redirectDeleteUser.xhtml new file mode 100644 index 00000000..cdeb6df9 --- /dev/null +++ b/simple-blog/web/redirectDeleteUser.xhtml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/simple-blog/web/redirectIndex.xhtml b/simple-blog/web/redirectIndex.xhtml new file mode 100644 index 00000000..10c4d7a3 --- /dev/null +++ b/simple-blog/web/redirectIndex.xhtml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/simple-blog/web/resources/css/cssLayout.css b/simple-blog/web/resources/css/cssLayout.css new file mode 100644 index 00000000..fd40910d --- /dev/null +++ b/simple-blog/web/resources/css/cssLayout.css @@ -0,0 +1,4 @@ + + + + diff --git a/simple-blog/web/resources/css/default.css b/simple-blog/web/resources/css/default.css new file mode 100644 index 00000000..9c70ad56 --- /dev/null +++ b/simple-blog/web/resources/css/default.css @@ -0,0 +1,861 @@ +@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: 25px; +} + +h3 { + font-size: 40px; + padding-bottom: 20px; +} + +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: 600px; + /* 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: 200px; + 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: 100px; + 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 { + + 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 0 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/simple-blog/web/resources/data/simple_blog.sql b/simple-blog/web/resources/data/simple_blog.sql new file mode 100644 index 00000000..dbf28f93 --- /dev/null +++ b/simple-blog/web/resources/data/simple_blog.sql @@ -0,0 +1,115 @@ +-- phpMyAdmin SQL Dump +-- version 4.1.12 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Nov 24, 2014 at 03:53 PM +-- Server version: 5.6.16 +-- PHP Version: 5.5.11 + +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: `simple_blog` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `comment` +-- + +CREATE TABLE IF NOT EXISTS `comment` ( + `id` int(11) NOT NULL DEFAULT '0', + `post_id` int(11) NOT NULL, + `name` varchar(100) NOT NULL, + `email` varchar(100) NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `content` text NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `comment` +-- + +INSERT INTO `comment` (`id`, `post_id`, `name`, `email`, `date`, `content`) VALUES +(1, 1, 'sasuke uchiha', 'sasuke@gmail.com', '2014-11-24 14:53:00', 'f*ck you too!'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `post` +-- + +CREATE TABLE IF NOT EXISTS `post` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `title` varchar(100) NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `content` text NOT NULL, + `status` tinyint(1) NOT NULL, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; + +-- +-- Dumping data for table `post` +-- + +INSERT INTO `post` (`id`, `user_id`, `title`, `date`, `content`, `status`) VALUES +(1, 1, 'F*ck you!', '2014-11-24 14:44:19', 'tai kuda keinjek', 1), +(2, 1, 'kagebunshin no jutsu!', '2014-11-24 14:51:33', 'jadi jurus ini adalah...', 1); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `email` varchar(100) NOT NULL, + `username` varchar(16) NOT NULL, + `name` varchar(100) NOT NULL, + `password` varchar(16) NOT NULL, + `role` enum('admin','owner','editor') NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`id`, `email`, `username`, `name`, `password`, `role`) VALUES +(1, 'naruto@gmail.com', 'naruto69', 'naruto uzumaki', 'uzumakinaruto', 'admin'); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `comment` +-- +ALTER TABLE `comment` + ADD CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- +-- Constraints for table `post` +-- +ALTER TABLE `post` + ADD CONSTRAINT `post_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +/*!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/simple-blog/web/resources/js/commentValidation.js b/simple-blog/web/resources/js/commentValidation.js new file mode 100644 index 00000000..cf37e430 --- /dev/null +++ b/simple-blog/web/resources/js/commentValidation.js @@ -0,0 +1,8 @@ +/* + * 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. + */ + + + diff --git a/simple-blog/web/resources/js/delete.js b/simple-blog/web/resources/js/delete.js new file mode 100644 index 00000000..a61dc471 --- /dev/null +++ b/simple-blog/web/resources/js/delete.js @@ -0,0 +1,20 @@ +function ConfirmDeletePost() +{ + if (confirm("Delete Post?")) + return true; + else return false; +} + +function ConfirmDeleteUser(ID) +{ + if (confirm("Delete User?")) + return true; + else return false; +} + +function ConfirmActionOnDeletedPost() +{ + if (confirm("Are you sure?")) + return true; + else return false; +} diff --git a/simple-blog/web/resources/js/emailValidation.js b/simple-blog/web/resources/js/emailValidation.js new file mode 100644 index 00000000..1228c949 --- /dev/null +++ b/simple-blog/web/resources/js/emailValidation.js @@ -0,0 +1,19 @@ +/* + * 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. + */ + +function validateEmail() { + var email = document.getElementById("Form:Email").value; + var re = /^(([^<>()[\]\\.,;:\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,}))$/; + if(re.test(email)){ + return true; + } + else{ + alert('Email tidak valid!'); + return false; + } +} + + diff --git a/simple-blog/web/resources/js/postValidation.js b/simple-blog/web/resources/js/postValidation.js new file mode 100644 index 00000000..b2ba0f8f --- /dev/null +++ b/simple-blog/web/resources/js/postValidation.js @@ -0,0 +1,59 @@ +function postValidation() { + var Judul = document.getElementById("Form:Judul"); + var Tanggal = document.getElementById("Form:Tanggal"); + var Konten = document.getElementById("Form:Konten"); + + if (Judul.value =="") + { + alert('Judul harus di isi!'); + return false; + } + + if (Tanggal.value =="") + { + alert('Tanggal harus di isi!'); + return false; + } + + if (Konten.value =="") + { + alert('Konten harus di isi!'); + return false; + } + + if (Tanggal.value!="") + { + var arrTanggal = Tanggal.value.split("-"); + + var tanggal = new Date(); + tanggal.setFullYear(arrTanggal[0], parseInt(arrTanggal[1])-1, arrTanggal[2]); + var date = new Date(); + + if (tanggal < date) + { + alert('Tanggal harus sama atau lebih besar dari tanggal sekarang!'); + return false; + } + } + + return true; +} + +function resetForm(FormId){ + document.forms[FormId].reset(); +} + +function makeYear(Tanggal){ + var tahun = Tanggal.charAt(0) + Tanggal.charAt(1) + Tanggal.charAt(2) + Tanggal.charAt(3); + return parseInt(tahun); +} + +function makeMonth(Tanggal){ + var bulan = Tanggal.charAt(5) + Tanggal.charAt(6); + return parseInt(bulan); +} + +function makeDay(Tanggal){ + var hari = Tanggal.charAt(8) + Tanggal.charAt(9); + return parseInt(hari); +} \ No newline at end of file diff --git a/simple-blog/web/viewPost.xhtml b/simple-blog/web/viewPost.xhtml new file mode 100644 index 00000000..52975fd4 --- /dev/null +++ b/simple-blog/web/viewPost.xhtml @@ -0,0 +1,81 @@ + + + + + + + + + + Facelet Title + + + + +
+ +
+
+ +

#{viewPostController.viewPost.title}

+

+
+
+ +
+ +
+
+ +

#{viewPostController.viewPost.content}

+ +
+ +

Komentar

+ +
+ + + + + +

+ + + + +
+
+ +
    + + +
  • +
    +

    #{comment.name}

    +
    #{comment.date}
    +
    +

    #{comment.content} …

    +
  • +
    +
    +
+
+
+ +
+
+ + + +
+
+ \ No newline at end of file