From df8c8d8eaa3fd74b2f6a76341611555ee6d8834d Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Sun, 22 Nov 2015 15:07:27 +0100 Subject: Add initial files --- .classpath | 8 + .gitignore | 1 + .project | 36 ++++ .settings/org.eclipse.jdt.core.prefs | 8 + .settings/org.eclipse.jdt.ui.prefs | 3 + ...org.eclipse.jst.common.project.facet.core.prefs | 4 + .settings/org.eclipse.wst.common.component | 9 + .../org.eclipse.wst.common.project.facet.core.xml | 8 + .settings/org.eclipse.wst.validation.prefs | 6 + WEB-INF/web.xml | 1 + WebContent/META-INF/MANIFEST.MF | 3 + WebContent/WEB-INF/faces-config.xml | 211 +++++++++++++++++++++ WebContent/WEB-INF/web.xml | 47 +++++ WebContent/index.jsp | 10 + WebContent/pages/categories.xhtml | 54 ++++++ WebContent/pages/category.xhtml | 23 +++ WebContent/pages/contact.xhtml | 23 +++ WebContent/pages/greeting.xhtml | 22 +++ WebContent/pages/home.xhtml | 28 +++ WebContent/pages/login.xhtml | 41 ++++ WebContent/pages/product.xhtml | 44 +++++ WebContent/pages/products.xhtml | 62 ++++++ WebContent/stylesheets/form.css | 16 ++ WebContent/stylesheets/navigation.css | 25 +++ WebContent/stylesheets/twocolumn.css | 53 ++++++ WebContent/templates/common.xhtml | 60 ++++++ WebContent/templates/loggedin.xhtml | 60 ++++++ jcatalog.sql | 127 +++++++++++++ quellen.txt | 10 + src/META-INF/persistence.xml | 15 ++ src/beans/CategoryManager.java | 83 ++++++++ src/beans/ContactManager.java | 15 ++ src/beans/ProductManager.java | 70 +++++++ src/beans/UserManager.java | 100 ++++++++++ src/jpa/Category.java | 103 ++++++++++ src/jpa/JPATest.java | 62 ++++++ src/jpa/Product.java | 113 +++++++++++ src/jpa/User.java | 36 ++++ src/resources.properties | 2 + src/util/DigestUtils.java | 58 ++++++ 40 files changed, 1660 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.jdt.ui.prefs create mode 100644 .settings/org.eclipse.jst.common.project.facet.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.validation.prefs create mode 100644 WEB-INF/web.xml create mode 100644 WebContent/META-INF/MANIFEST.MF create mode 100644 WebContent/WEB-INF/faces-config.xml create mode 100644 WebContent/WEB-INF/web.xml create mode 100644 WebContent/index.jsp create mode 100644 WebContent/pages/categories.xhtml create mode 100644 WebContent/pages/category.xhtml create mode 100644 WebContent/pages/contact.xhtml create mode 100644 WebContent/pages/greeting.xhtml create mode 100644 WebContent/pages/home.xhtml create mode 100644 WebContent/pages/login.xhtml create mode 100644 WebContent/pages/product.xhtml create mode 100644 WebContent/pages/products.xhtml create mode 100644 WebContent/stylesheets/form.css create mode 100644 WebContent/stylesheets/navigation.css create mode 100644 WebContent/stylesheets/twocolumn.css create mode 100644 WebContent/templates/common.xhtml create mode 100644 WebContent/templates/loggedin.xhtml create mode 100644 jcatalog.sql create mode 100644 quellen.txt create mode 100644 src/META-INF/persistence.xml create mode 100644 src/beans/CategoryManager.java create mode 100644 src/beans/ContactManager.java create mode 100644 src/beans/ProductManager.java create mode 100644 src/beans/UserManager.java create mode 100644 src/jpa/Category.java create mode 100644 src/jpa/JPATest.java create mode 100644 src/jpa/Product.java create mode 100644 src/jpa/User.java create mode 100644 src/resources.properties create mode 100644 src/util/DigestUtils.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fa0a137 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9b4f01 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/* diff --git a/.project b/.project new file mode 100644 index 0000000..e5f3bc1 --- /dev/null +++ b/.project @@ -0,0 +1,36 @@ + + + JCatalog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dali.core.persistenceBuilder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.dali.core.persistenceNature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d04de3a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Jun 25 14:38:55 CEST 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..be0c06f --- /dev/null +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +#Mon Jun 25 14:38:55 CEST 2007 +eclipse.preferences.version=1 +internal.default.compliance=default diff --git a/.settings/org.eclipse.jst.common.project.facet.core.prefs b/.settings/org.eclipse.jst.common.project.facet.core.prefs new file mode 100644 index 0000000..faee126 --- /dev/null +++ b/.settings/org.eclipse.jst.common.project.facet.core.prefs @@ -0,0 +1,4 @@ +#Tue Dec 05 14:34:55 CET 2006 +classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER/owners=jst.java\:5.0 +classpath.helper/org.eclipse.jst.server.core.container\:\:org.eclipse.jst.server.tomcat.runtimeTarget\:\:Apache\ Tomcat\ v5.5/owners=jst.web\:2.4 +eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..320180b --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..2a3c4eb --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..01f00ff --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,6 @@ +#Mon Jun 25 14:38:55 CEST 2007 +DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator; +USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.dali.packaging.internal.validator.PackagingValidator;org.eclipse.jst.j2ee.internal.web.validation.UIWarValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator; +USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.dali.packaging.internal.validator.PackagingValidator;org.eclipse.jst.j2ee.internal.web.validation.UIWarValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator; +USER_PREFERENCE=overrideGlobalPreferencesfalse +eclipse.preferences.version=1 diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml new file mode 100644 index 0000000..12bbf74 --- /dev/null +++ b/WEB-INF/web.xml @@ -0,0 +1 @@ + diff --git a/WebContent/META-INF/MANIFEST.MF b/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/WebContent/WEB-INF/faces-config.xml b/WebContent/WEB-INF/faces-config.xml new file mode 100644 index 0000000..06265ca --- /dev/null +++ b/WebContent/WEB-INF/faces-config.xml @@ -0,0 +1,211 @@ + + + + + + + UserManager + beans.UserManager + session + + + + CategoryManager + beans.CategoryManager + session + + + + ContactManager + beans.ContactManager + session + + + + ProductManager + beans.ProductManager + session + + + + + /pages/home.xhtml + + + contact + /pages/contact.xhtml + + + + login + /pages/login.xhtml + + + + categories + /pages/categories.xhtml + + + + + + + /pages/login.xhtml + + + contact + /pages/contact.xhtml + + + + login + /pages/login.xhtml + + + + categories + /pages/categories.xhtml + + + + failure + /pages/login.xhtml + + + + success + /pages/greeting.xhtml + + + + + + + + /pages/categories.xhtml + + + contact + /pages/contact.xhtml + + + + login + /pages/login.xhtml + + + + categories + /pages/categories.xhtml + + + + select + /pages/products.xhtml + + + + + + + /pages/greeting.xhtml + + + contact + /pages/contact.xhtml + + + + categories + /pages/categories.xhtml + + + + home + /pages/home.xhtml + + + + + + + /pages/contact.xhtml + + + contact + /pages/contact.xhtml + + + + categories + /pages/categories.xhtml + + + + login + /pages/login.xhtml + + + + + + + /pages/products.xhtml + + + contact + /pages/contact.xhtml + + + + categories + /pages/categories.xhtml + + + + login + /pages/login.xhtml + + + + + + + /pages/product.xhtml + + + products + /pages/products.xhtml + + + + contact + /pages/contact.xhtml + + + + categories + /pages/categories.xhtml + + + + login + /pages/login.xhtml + + + + + + + com.sun.facelets.FaceletViewHandler + + + de_DE + + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..ee62240 --- /dev/null +++ b/WebContent/WEB-INF/web.xml @@ -0,0 +1,47 @@ + + + Facelets JCatalog Application + + javax.faces.DEFAULT_SUFFIX + .xhtml + + + facelets.REFRESH_PERIOD + 2 + + + facelets.DEVELOPMENT + true + + + javax.faces.STATE_SAVING_METHOD + client + + + com.sun.faces.validateXml + true + + + com.sun.faces.verifyObjects + true + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.jsf + + + JCatalog + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + diff --git a/WebContent/index.jsp b/WebContent/index.jsp new file mode 100644 index 0000000..fa6ee7d --- /dev/null +++ b/WebContent/index.jsp @@ -0,0 +1,10 @@ + + + + + <% response.sendRedirect("pages/home.jsf"); %> + + + \ No newline at end of file diff --git a/WebContent/pages/categories.xhtml b/WebContent/pages/categories.xhtml new file mode 100644 index 0000000..4a7532e --- /dev/null +++ b/WebContent/pages/categories.xhtml @@ -0,0 +1,54 @@ + + + + + + + JCatalog Application + + JCatalog Categories + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JCatalog Footer + + + + diff --git a/WebContent/pages/category.xhtml b/WebContent/pages/category.xhtml new file mode 100644 index 0000000..b5313a3 --- /dev/null +++ b/WebContent/pages/category.xhtml @@ -0,0 +1,23 @@ + + + + + + + JCatalog Application + + JCatalog Application + + +

Welcome to the JCatalog Demo Application

+
+ + JCatalog Footer + +
+ + diff --git a/WebContent/pages/contact.xhtml b/WebContent/pages/contact.xhtml new file mode 100644 index 0000000..b51f1dd --- /dev/null +++ b/WebContent/pages/contact.xhtml @@ -0,0 +1,23 @@ + + + + + + + JCatalog Application + + JCatalog Application + + +

Contact Page

+
+ + JCatalog Footer + +
+ + diff --git a/WebContent/pages/greeting.xhtml b/WebContent/pages/greeting.xhtml new file mode 100644 index 0000000..73e1d62 --- /dev/null +++ b/WebContent/pages/greeting.xhtml @@ -0,0 +1,22 @@ + + + + + + + JCatalog Welcome + + JCatalog Application + + +

Welcome to the JCatalog Demo Application

+
+ + JCatalog Footer + +
+ + diff --git a/WebContent/pages/home.xhtml b/WebContent/pages/home.xhtml new file mode 100644 index 0000000..735c734 --- /dev/null +++ b/WebContent/pages/home.xhtml @@ -0,0 +1,28 @@ + + + + + + + + + + + JCatalog Application + + JCatalog Application + + +

Welcome to the JCatalog Demo Application

+

Please make your choice.

+

Bitte eine Option auswählen.

+
+ + JCatalog Footer + +
+ + diff --git a/WebContent/pages/login.xhtml b/WebContent/pages/login.xhtml new file mode 100644 index 0000000..2e94421 --- /dev/null +++ b/WebContent/pages/login.xhtml @@ -0,0 +1,41 @@ + + + + + + + JCatalog Login + + Login + + +
+ + +
+ + +
+
+ + +
+
+ + + +
+
+ +
+ + + JCatalog Footer + + + + diff --git a/WebContent/pages/product.xhtml b/WebContent/pages/product.xhtml new file mode 100644 index 0000000..06c4a8d --- /dev/null +++ b/WebContent/pages/product.xhtml @@ -0,0 +1,44 @@ + + + + + + + JCatalog Application + + Login + + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + + +
+
+ +
+ + + JCatalog Footer + + + + diff --git a/WebContent/pages/products.xhtml b/WebContent/pages/products.xhtml new file mode 100644 index 0000000..f833c1d --- /dev/null +++ b/WebContent/pages/products.xhtml @@ -0,0 +1,62 @@ + + + + + + + JCatalog Application + + List of Products + + + + + +

+ List of Products in Category + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + JCatalog Footer + +
+ + diff --git a/WebContent/stylesheets/form.css b/WebContent/stylesheets/form.css new file mode 100644 index 0000000..8667f07 --- /dev/null +++ b/WebContent/stylesheets/form.css @@ -0,0 +1,16 @@ +div.row { + clear: both; + padding-top: 10px; +} + +div.row label { + float: left; + width: 100px; + text-align: right; +} + +div.row span.formw { + float: right; + width: 335px; + text-align: left; +} diff --git a/WebContent/stylesheets/navigation.css b/WebContent/stylesheets/navigation.css new file mode 100644 index 0000000..1ec153b --- /dev/null +++ b/WebContent/stylesheets/navigation.css @@ -0,0 +1,25 @@ +#navcontainer ul +{ +margin: 0; +padding: 0; +list-style-type: none; +} + +#navcontainer li { margin: 0 0 .2em 0; } + +#navcontainer a +{ +display: block; +color: black; +background-color: #ddd; +width: 6em; +padding: .2em .8em; +text-decoration: none; +} + +#navcontainer a:hover +{ +background-color: #bbb; +color: #FFF; +} + diff --git a/WebContent/stylesheets/twocolumn.css b/WebContent/stylesheets/twocolumn.css new file mode 100644 index 0000000..e5b8e84 --- /dev/null +++ b/WebContent/stylesheets/twocolumn.css @@ -0,0 +1,53 @@ +@CHARSET "ISO-8859-1"; + +#container +{ +width: 90%; +margin: 10px auto; +background-color: #fff; +color: #333; +border: 1px solid gray; +line-height: 130%; +} + +#top +{ +padding: .5em; +background-color: #ddd; +border-bottom: 1px solid gray; +} + +#top h1 +{ +padding: 0; +margin: 0; +} + +#leftnav +{ +float: left; +width: 160px; +margin: 0; +padding: 1em; +} + +#content +{ +margin-left: 200px; +border-left: 1px solid gray; +padding: 1em; +max-width: 36em; +} + +#footer +{ +clear: both; +margin: 0; +padding: .5em; +color: #333; +background-color: #ddd; +border-top: 1px solid gray; +} + +#leftnav p { margin: 0 0 1em 0; } +#content h2 { margin: 0 0 .5em 0; } diff --git a/WebContent/templates/common.xhtml b/WebContent/templates/common.xhtml new file mode 100644 index 0000000..151411f --- /dev/null +++ b/WebContent/templates/common.xhtml @@ -0,0 +1,60 @@ + + + + + + <ui:insert name="pageTitle">Page Title</ui:insert> + + + + + + + + +
+ +
+ Page Header +
+ +
+ + +
    +
  • + + + +
  • +
  • + + + +
  • +
  • + + + +
  • +
+
+
+
+ +
+ Page Body +
+ + + +
+ + + + diff --git a/WebContent/templates/loggedin.xhtml b/WebContent/templates/loggedin.xhtml new file mode 100644 index 0000000..3ac57ca --- /dev/null +++ b/WebContent/templates/loggedin.xhtml @@ -0,0 +1,60 @@ + + + + + + <ui:insert name="pageTitle">Page Title</ui:insert> + + + + + + + + +
+ +
+ Page Header +
+ +
+ + +
    +
  • + + + +
  • +
  • + + + +
  • +
  • + + + +
  • +
+
+
+
+ +
+ Page Body +
+ + + +
+ + + + diff --git a/jcatalog.sql b/jcatalog.sql new file mode 100644 index 0000000..dafd669 --- /dev/null +++ b/jcatalog.sql @@ -0,0 +1,127 @@ +-- phpMyAdmin SQL Dump +-- version 2.9.0.1 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generation Time: Jan 17, 2007 at 02:57 PM +-- Server version: 5.0.24 +-- PHP Version: 5.1.6 +-- +-- Database: `catalog` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `category` +-- + +CREATE TABLE `category` ( + `id` int(10) NOT NULL auto_increment, + `name` varchar(50) collate latin1_general_ci NOT NULL, + `description` varchar(255) collate latin1_general_ci default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; + +-- +-- Dumping data for table `category` +-- + +INSERT INTO `category` (`id`, `name`, `description`) VALUES (1, 'Category One', 'Category one description'); +INSERT INTO `category` (`id`, `name`, `description`) VALUES (2, 'Category Two', 'Category two description'); +INSERT INTO `category` (`id`, `name`, `description`) VALUES (3, 'Category Three', 'Category three description'); +INSERT INTO `category` (`id`, `name`, `description`) VALUES (4, 'Category Four', 'Category four description'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `product` +-- + +CREATE TABLE `product` ( + `id` int(10) NOT NULL auto_increment, + `name` varchar(50) collate latin1_general_ci NOT NULL, + `price` decimal(8,2) default NULL, + `width` decimal(8,2) default NULL, + `height` decimal(8,2) default NULL, + `description` longtext collate latin1_general_ci, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; + +-- +-- Dumping data for table `product` +-- + +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (1, 'Product1', 20.00, 12.00, 16.00, 'JavaServer Faces (JSF) technology is a new user interface framework for J2EE applications. It is particularly suited, by design, for use with applications based on the MVC architecture. Numerous articles have been published to introduce JSF. However, most of them take a highly theoretical approach that does not meet the challenges of real-world enterprise development. There are still a lot of issues that need to be solved. For example, how JSF fits INTO the overall MVC architecture? How JSF integrates with other Java frameworks? Should business logic exist in the JSF backing beans? How to handle security in JSF? And most importantly, how to build a real-world web application using JSF? This article addresses all these issues. It shows you how to integrate JSF with other Java frameworks – specifically, Spring Framework and Hibernate.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (2, 'Product2', 40.00, 18.00, 16.00, 'The sample application used in this article is an online product catalog system. By showing you how to build a real-world web application, this article covers each phase of the web application design, including business requirement gathering, analysis, technology selection, high-level architecture and implementation level design. It discusses the advantages and disadvantages of the technologies used in the sample application. It also demonstrates the approach to designing some key aspects of the sample application.This article is aimed at Java architects, developers already working with J2EE based web application. It is not an introduction to JSF, Spring Framework and Hibernate.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (3, 'Product3', 38.88, 20.00, 18.00, 'The sample application is a real-world web application, which is realistic enough to provide the basis for a meaningful discussion of web application architectural decisions. It is important to begin by presenting the requirements of the sample application. I will refer back to this section throughout the rest of the article to address the technical decisions and architecture design. The first phase in designing a web application is to gather functional requirements for the system. The sample application is a typical e-business application system.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (4, 'Product4', 22.99, 18.00, 14.00, 'There are two groups of pages in the sample application – public internet and administration intranet. The intranet is only accessible to the users who log in the system successfully. ProductSummary is not presented to the users as a separate page. It is shown inside a HTML frame within the Catalog page. ProductList is a special catalog viewable only by the administrators. It contains links to create product, edit product and delete product.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (5, 'Product5', 18.68, 17.00, 21.00, 'A multi-tier architecture partitions the whole system INTO distinct functional units - client, presentation, business logic, integration and enterprise information system (EIS). This ensures a clean division of responsibility and makes the system more maintainable and extensible. Systems with three or more tiers have proven more scalable and flexible than a client-server system, in which there is no business logic middle tier.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (6, 'Product6', 28.99, 19.00, 20.00, 'The business logic tier contains the business objects and the business services of an application. It receives requests from the presentation tier, processes the business logic based on the requests and mediates access to EIS tier resources. Business logic tier components benefit most from system level services such as security management, transaction management and resource management.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (7, 'Product7', 36.66, 16.00, 18.00, 'A multi-tier non-distributed architecture is used for the sample application. The diagram shows us the partitioning of the application tiers, and the technologies chosen for each tier. It also serves as a deployment diagram of the sample application. For a collocated architecture, the presentation tier, business logic tier and integration tier are located in the same web container physically. Well-defined interfaces are used to isolate the responsibility for each tier. The collocated architecture makes the application simple and scalable.'); +INSERT INTO `product` (`id`, `name`, `price`, `width`, `height`, `description`) VALUES (8, 'Product8', 32.99, 26.00, 18.00, 'Model-View-Controller (MVC) is the Java BluePrints recommended architectural design pattern for interactive application. MVC separates design concerns, decreasing code duplication, centralizing control, and making the application more extensible. MVC also helps developers with different skill sets to focus on their core skills and collaborate through clearly defined interfaces. MVC is the architectural design pattern for the presentation tier.'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `product_category` +-- + +CREATE TABLE `product_category` ( + `product_id` int(10) NOT NULL, + `category_id` int(10) NOT NULL, + PRIMARY KEY (`product_id`,`category_id`), + KEY `category_id` (`category_id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; + +-- +-- Dumping data for table `product_category` +-- + +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (1, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (2, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (3, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (4, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (5, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (6, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (7, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (8, 1); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (1, 2); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (4, 2); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (6, 2); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (8, 2); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (1, 3); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (2, 3); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (7, 3); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (1, 4); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (3, 4); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (5, 4); +INSERT INTO `product_category` (`product_id`, `category_id`) VALUES (8, 4); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE `user` ( + `username` varchar(20) collate latin1_general_ci NOT NULL, + `password` varchar(32) collate latin1_general_ci NOT NULL, + PRIMARY KEY (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`username`, `password`) VALUES ('admin', 'abe6db4c9f5484fae8d79f2e868a673c'); + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `product_category` +-- +ALTER TABLE `product_category` + ADD CONSTRAINT `product_category_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`), ADD CONSTRAINT `product_category_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`); diff --git a/quellen.txt b/quellen.txt new file mode 100644 index 0000000..82e584f --- /dev/null +++ b/quellen.txt @@ -0,0 +1,10 @@ +Downloads: + +http://myfaces.apache.org/ +https://facelets.dev.java.net/ +http://www.oracle.com/technology/products/ias/toplink/jpa/download.html +http://dev.mysql.com/downloads/connector/j/3.0.html + +Online-Artikel: + +http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html (Die Vorlage für die Kataloganwendung) \ No newline at end of file diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml new file mode 100644 index 0000000..039a45e --- /dev/null +++ b/src/META-INF/persistence.xml @@ -0,0 +1,15 @@ + + + +jpa.User +jpa.Category +jpa.Product + + + + + + + + + diff --git a/src/beans/CategoryManager.java b/src/beans/CategoryManager.java new file mode 100644 index 0000000..7b96d2f --- /dev/null +++ b/src/beans/CategoryManager.java @@ -0,0 +1,83 @@ +/* + * $RCSFile$ + * + * Created on 08.03.2007 + * for Project: + * by steins + * + * (C) 2005-2006 by + */ +package beans; + +import java.io.IOException; +import java.util.Collection; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; + +import jpa.Category; + +public class CategoryManager +{ + private Category current; + + public Category getCurrent() + { + return current; + } + + public void setCurrent(Category current) + { + this.current = current; + } + + public Collection getCategories() + { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + return manager.createQuery("SELECT c FROM Category c ").getResultList(); + } + + public void select(javax.faces.event.ActionEvent actionEvent) + { + FacesContext facesContext = FacesContext.getCurrentInstance(); + Map params = facesContext.getExternalContext().getRequestParameterMap(); + Integer selectedId = Integer.valueOf((String) params.get("selectedId")); +// System.out.println(selectedId); + + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + + EntityTransaction tx = manager.getTransaction(); + tx.begin(); + try + { + current = manager.find(Category.class, selectedId); +// System.out.println(current.getName()); + tx.commit(); + } + catch (Exception ex) + { + ex.printStackTrace(System.err); + tx.rollback(); + } + + FacesContext context = FacesContext.getCurrentInstance(); + try + { + context.getExternalContext().redirect("products.jsf"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + context.responseComplete(); + } +} diff --git a/src/beans/ContactManager.java b/src/beans/ContactManager.java new file mode 100644 index 0000000..43c96e0 --- /dev/null +++ b/src/beans/ContactManager.java @@ -0,0 +1,15 @@ +/* + * $RCSFile$ + * + * Created on 12.03.2007 + * for Project: + * by steins + * + * (C) 2005-2006 by + */ +package beans; + +public class ContactManager +{ + // nothing implemented yet +} diff --git a/src/beans/ProductManager.java b/src/beans/ProductManager.java new file mode 100644 index 0000000..cc0dcaa --- /dev/null +++ b/src/beans/ProductManager.java @@ -0,0 +1,70 @@ +/* + * $RCSFile$ + * + * Created on 11.06.2007 + * for Project: + * by steins + * + * (C) 2005-2006 by + */ +package beans; + +import java.io.IOException; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; + +import jpa.Product; + +public class ProductManager +{ + private Product current; + + public Product getCurrent() + { + return current; + } + + public void select(javax.faces.event.ActionEvent actionEvent) + { + FacesContext facesContext = FacesContext.getCurrentInstance(); + Map params = facesContext.getExternalContext().getRequestParameterMap(); + String selectedId = (String) params.get("selectedId"); +// System.out.println(selectedId); + + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + + EntityTransaction tx = manager.getTransaction(); + tx.begin(); + try + { + current = manager.find(Product.class, selectedId); + + tx.commit(); + } + catch (Exception ex) + { + ex.printStackTrace(System.err); + tx.rollback(); + } + + FacesContext context = FacesContext.getCurrentInstance(); + try + { + context.getExternalContext().redirect("product.jsf"); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + context.responseComplete(); + } + +} diff --git a/src/beans/UserManager.java b/src/beans/UserManager.java new file mode 100644 index 0000000..9e08543 --- /dev/null +++ b/src/beans/UserManager.java @@ -0,0 +1,100 @@ +/* + * $RCSFile$ + * + * Created on 06.12.2006 + * for Project: + * by steins + * + * (C) 2005-2006 by + */ +package beans; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import jpa.User; +import static util.DigestUtils.md5; + +public class UserManager { + private User current; + + private boolean loggedIn; + + public UserManager() { + current = new User(); + } + + public String login() { + String outcome = "failure"; + if (current.getUsername() != null && current.getUsername().length() > 0 + && current.getPassword() != null + && current.getPassword().length() > 0) { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + Query query = manager + .createQuery("SELECT u FROM User u where u.username = :username and u.password = :password"); + query.setParameter("username", current.getUsername()); + query.setParameter("password", md5(current.getPassword())); + List results = query.getResultList(); + + if (!results.isEmpty()) { + loggedIn = true; + current = (User) results.get(0); + outcome = "success"; + } + } + // System.out.println(outcome); + return outcome; + } + + public String logout() { + loggedIn = false; + current = new User(); + return "home"; + } + + public void setUsername(String username) { + current.setUsername(username); + } + + public String getUsername() { + return current.getUsername(); + } + + public void setPassword(String password) { + current.setPassword(password); + } + + public String getPassword() { + return current.getPassword(); + } + + public boolean isLoggedIn() { + return loggedIn; + } + + public User getCurrent() { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + + EntityTransaction tx = manager.getTransaction(); + tx.begin(); + try { + current = manager.find(User.class, getUsername()); + + tx.commit(); + } catch (Exception ex) { + ex.printStackTrace(System.err); + tx.rollback(); + } + + return current; + } +} diff --git a/src/jpa/Category.java b/src/jpa/Category.java new file mode 100644 index 0000000..c29c1f7 --- /dev/null +++ b/src/jpa/Category.java @@ -0,0 +1,103 @@ +package jpa; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToMany; + +@Entity +public class Category implements Serializable +{ + @Id + private int id; + + private String name; + + private String description; + + @ManyToMany(mappedBy = "categoryCollection") + private Set productCollection; + + private static final long serialVersionUID = 1L; + + public Category() + { + super(); + } + + public int getId() + { + return this.id; + } + + public void setId(int id) + { + this.id = id; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return this.description; + } + + public void setDescription(String description) + { + this.description = description; + } + + /** + * The method getProductCollection() returns a + * Collection object that is incompatible with JSF. + * + * @return collection of product objects. + */ + public Collection getProducts() + { + Collection c = new ArrayList(); + + for (Iterator iter = getProductCollection().iterator(); iter.hasNext();) + { + Product product = (Product) iter.next(); + c.add(product); +// System.out.println(product.getName()); + } + + return c; + } + + public Set getProductCollection() + { + return this.productCollection; + } + + public void setProductCollection(Set productCollection) + { + this.productCollection = productCollection; + } + + public void addProduct(Product product) + { + Set products = getProductCollection(); + if (!products.contains(product)) + { + products.add(product); + product.addCategory(this); + } + } + +} diff --git a/src/jpa/JPATest.java b/src/jpa/JPATest.java new file mode 100644 index 0000000..5a4749e --- /dev/null +++ b/src/jpa/JPATest.java @@ -0,0 +1,62 @@ +package jpa; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; + +public class JPATest +{ + /** + * @param args + */ + public static void main(String[] args) + { + EntityManagerFactory factory = Persistence + .createEntityManagerFactory("catalog"); + EntityManager manager = factory.createEntityManager(); + EntityTransaction tx = manager.getTransaction(); + tx.begin(); + try + { +// Product product = manager.find(Product.class, "7"); +// Category newCategory = manager.find(Category.class, 4); +// product.addCategory(newCategory); +// manager.persist(product); +// Collection categories = product.getCategoryCollection(); +// for (Category category : categories) +// { +// System.out.println(category.getName()); +// } + Product product = new Product(); + product.setDescription("Noch ein Testprodukt"); + product.setName("Produkt"); + manager.persist(product); +// User user = new User(); +// user.setUsername("bestertester2"); +// System.out.println(DigestUtils.md5("masterkey")); +// user.setPassword(DigestUtils.md5("masterkey")); +// manager.persist(user); + + tx.commit(); + } + catch (Exception ex) + { + ex.printStackTrace(System.err); + tx.rollback(); + } + +// CategoryManager cm = new CategoryManager(); +// Collection categories = cm.getCategories(); +// for (Category category : categories) +// { +// System.out.println(category.getName()); +// Set products = category.getProductCollection(); +// for (Product product : products) +// { +// System.out.println("\t" + product.getName()); +// } +// +// } + } +} diff --git a/src/jpa/Product.java b/src/jpa/Product.java new file mode 100644 index 0000000..dc0b3f8 --- /dev/null +++ b/src/jpa/Product.java @@ -0,0 +1,113 @@ +package jpa; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Set; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; + +@Entity +public class Product implements Serializable { + @Id + @GeneratedValue(strategy=GenerationType.SEQUENCE) + private String id; + + private String description; + + private BigDecimal price; + + private String name; + + private BigDecimal width; + + private BigDecimal height; + + @ManyToMany + @JoinTable( + joinColumns=@JoinColumn(name="product_id"), + inverseJoinColumns=@JoinColumn(name="category_id")) + private Set categoryCollection; + + private static final long serialVersionUID = 1L; + + public Product() { + super(); + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public BigDecimal getPrice() { + return this.price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public BigDecimal getWidth() { + return this.width; + } + + public void setWidth(BigDecimal width) { + this.width = width; + } + + public BigDecimal getHeight() { + return this.height; + } + + public void setHeight(BigDecimal height) { + this.height = height; + } + + public Collection getCategories() { + return this.getCategoryCollection(); + } + + public Set getCategoryCollection() { + return this.categoryCollection; + } + + public void setCategoryCollection(Set categoryCollection) { + this.categoryCollection = categoryCollection; + } + + public void addCategory(Category category) + { + Set categories = getCategoryCollection(); + if (!categories.contains(category)) + { + categories.add(category); + category.addProduct(this); + } + } +} diff --git a/src/jpa/User.java b/src/jpa/User.java new file mode 100644 index 0000000..32d2af8 --- /dev/null +++ b/src/jpa/User.java @@ -0,0 +1,36 @@ +package jpa; + +import java.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class User implements Serializable { + @Id + private String username; + + private String password; + + private static final long serialVersionUID = 1L; + + public User() { + super(); + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/src/resources.properties b/src/resources.properties new file mode 100644 index 0000000..8e1cc07 --- /dev/null +++ b/src/resources.properties @@ -0,0 +1,2 @@ +prompt=Your Name\: +greeting=Hello diff --git a/src/util/DigestUtils.java b/src/util/DigestUtils.java new file mode 100644 index 0000000..4633715 --- /dev/null +++ b/src/util/DigestUtils.java @@ -0,0 +1,58 @@ +/* + * $RCSFile$ + * + * Created on 06.12.2006 + * for Project: + * by steins + * + * (C) 2005-2006 by + */ +package util; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class DigestUtils +{ + private static final String HEX_DIGITS = "0123456789abcdef"; + + private DigestUtils() + { + } + + public static String bin2hex(byte[] bin) + { + StringBuilder sb = new StringBuilder(32); + for (int i = 0; i < bin.length; ++i) + { + byte b = bin[i]; + int h = (b & 0xf0) >> 4; + sb.append(HEX_DIGITS.charAt(h)); + h = b & 0x0f; + sb.append(HEX_DIGITS.charAt(h)); + } + + return sb.substring(0); + } + + public static String md5(String s) + { + MessageDigest md = null; + try + { + md = MessageDigest.getInstance("MD5"); + md.update(s.getBytes("ISO-8859-1")); + } + catch (NoSuchAlgorithmException e) + { + e.printStackTrace(); + } + catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + } + + return bin2hex(md.digest()); + } +} -- cgit v1.2.3-70-g09d2