new pattern: Issue#1264: Implemented Composite-View Pattern (#1923)

* initial commit, created package, README, pom, and directory structure.

* Issue#1264, continue working on JavaBeans, added getters, setters, and private fields. Created test file for JavaBeans.

* set up junit for tests folder.

* Issue#1264, set up local server and added web-application framework to composite-view to allow the JSP to run on a local Tomcat container. Wrote unit tests for Java-bean class, working on JSP pages.

* Issue#1264, Added forwarding functionality to servlet and main composite view page.

* Issue#1264, Finished composite view template in newsDisplay.jsp and created atomic sub-view components in businessNews.jsp, header.jsp, localNews.jsp, scienceNews.jsp, sportsNews.jsp, worldNews.jsp. Composite view page renders correctly, atomic views are inserted in and substituted in the template page depending on request parameters.

* Issue#1264, Added all views, updated README.md with documentation.

* Issue#1264, updated README.md, moved images folder into etc folder.

* Issue#1264, removed build artifacts from tracked files.

* Issue#1264, updated README.md

* Issue#1264, updated README.md

* Issue#1264, removed unused import, made AppServlet class final, changed to .equals() for string comparison.

* Issue#1264, in AppServlet, put the output writing into try blocks to ensure writers are closed.

* Issue#1264, added tests for Servlet, coverage up to 100%, used lombok to reduce boilerplate setters and getter, updated README.md with better grammar, appropriate tags and links to related patterns. Updated pom.xml to get rid of superfluous lines.

* Issue#1264, made changes as requested in README.md.

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
Kevin
2022-01-18 13:51:53 -06:00
committed by GitHub
parent 07ee94d671
commit 7652b11bca
20 changed files with 978 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>com.iluwatar.compositeview.AppServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/news</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,33 @@
<%--
Created by IntelliJ IDEA.
User: Kevin
Date: 11/29/2021
Time: 2:51 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<style>
h2 { text-align: center;}
table {border: 1px solid black;}
tr {text-align: center;}
td {text-align: center;}
</style>
</head>
<body>
<h2>
Generic Business News
</h2>
<table style="margin-right: auto; margin-left: auto">
<tr>
<td>Stock prices up across the world</td>
<td>New tech companies to invest in</td>
</tr>
<tr>
<td>Industry leaders unveil new project</td>
<td>Price fluctuations and what they mean</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,23 @@
<%--
Created by IntelliJ IDEA.
User: Kevin
Date: 11/29/2021
Time: 1:28 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.Date"%>
<html>
<head>
<style>
h1 { text-align: center;}
h2 { text-align: center;}
h3 { text-align: center;}
</style>
</head>
<body>
<% String todayDateStr = (new Date().toString()); %>
<h1>Today's Personalized Frontpage</h1>
<h2><%=todayDateStr%></h2>
</body>
</html>

View File

@ -0,0 +1,20 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<style>
h1 { text-align: center;}
h2 { text-align: center;}
h3 { text-align: center;}
</style>
</head>
<body>
<h1>Welcome To The Composite Patterns Mock News Site</h1>
<h2>Send a GET request to the "/news" path to see the composite view with mock news</h2>
<h2>Use the following parameters:</h2>
<h3>name: string name to be dynamically displayed</h3>
<h3>bus: boolean for whether you want to see the mock business news</h3>
<h3>world: boolean for whether you want to see the mock world news</h3>
<h3>sci: boolean for whether you want to see the mock world news</h3>
<h3>sport: boolean for whether you want to see the mock world news</h3>
</body>
</html>

View File

@ -0,0 +1,25 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<div style="text-align: center">
<h3>
Generic Local News
</h3>
<ul style="list-style-type: none">
<li>
Mayoral elections coming up in 2 weeks
</li>
<li>
New parking meter rates downtown coming tomorrow
</li>
<li>
Park renovations to finish by the next year
</li>
<li>
Annual marathon sign ups available online
</li>
</ul>
</div>
</body>
</html>

View File

@ -0,0 +1,57 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.iluwatar.compositeview.ClientPropertiesBean"%>
<html>
<head>
<style>
h1 { text-align: center;}
h2 { text-align: center;}
h3 { text-align: center;}
.centerTable {
margin-left: auto;
margin-right: auto;
}
table {border: 1px solid black;}
tr {text-align: center;}
td {text-align: center;}
</style>
</head>
<body>
<%ClientPropertiesBean propertiesBean = (ClientPropertiesBean) request.getAttribute("properties");%>
<h1>Welcome <%= propertiesBean.getName()%></h1>
<jsp:include page="header.jsp"></jsp:include>
<table class="centerTable">
<tr>
<td></td>
<% if(propertiesBean.isWorldNewsInterest()) { %>
<td><%@include file="worldNews.jsp"%></td>
<% } else { %>
<td><%@include file="localNews.jsp"%></td>
<% } %>
<td></td>
</tr>
<tr>
<% if(propertiesBean.isBusinessInterest()) { %>
<td><%@include file="businessNews.jsp"%></td>
<% } else { %>
<td><%@include file="localNews.jsp"%></td>
<% } %>
<td></td>
<% if(propertiesBean.isSportsInterest()) { %>
<td><%@include file="sportsNews.jsp"%></td>
<% } else { %>
<td><%@include file="localNews.jsp"%></td>
<% } %>
</tr>
<tr>
<td></td>
<% if(propertiesBean.isScienceNewsInterest()) { %>
<td><%@include file="scienceNews.jsp"%></td>
<% } else { %>
<td><%@include file="localNews.jsp"%></td>
<% } %>
<td></td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,34 @@
<%--
Created by IntelliJ IDEA.
User: Kevin
Date: 11/29/2021
Time: 4:18 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<div style="text-align: center">
<h3>
Generic Science News
</h3>
<ul>
<li>
New model of gravity proposed for dark matter
</li>
<li>
Genetic modifying technique proved on bacteria
</li>
<li>
Neurology study maps brain with new precision
</li>
<li>
Survey of rainforest discovers 15 new species
</li>
<li>
New signalling pathway for immune system discovered
</li>
</ul>
</div>
</body>
</html>

View File

@ -0,0 +1,32 @@
<%--
Created by IntelliJ IDEA.
User: Kevin
Date: 11/29/2021
Time: 3:53 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<style>
h2 { text-align: center;}
table {border: 1px solid black;}
tr {text-align: center;}
td {text-align: center;}
</style>
</head>
<body>
<h2>
Generic Sports News
</h2>
<div style="margin-left: auto; margin-right: auto; padding: 20px">
International football match delayed due to weather, will be held next week
</div>
<div style="margin-left: auto; margin-right: auto; padding: 20px">
New rising stars in winter sports, ten new athletes that will shake up the scene
</div>
<div style="margin-left: auto; margin-right: auto; padding: 20px">
Biggest upset in basketball history, upstart team sweeps competition
</div>
</body>
</html>

View File

@ -0,0 +1,34 @@
<%--
Created by IntelliJ IDEA.
User: Kevin
Date: 11/29/2021
Time: 2:51 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<style>
h2 { text-align: center;}
table {border: 1px solid black;}
tr {text-align: center;}
td {text-align: center;}
</style>
</head>
<body>
<h2>
Generic World News
</h2>
<table style="margin-right: auto; margin-left: auto">
<tr>
<td>New trade talks happening at UN on Thursday</td>
</tr>
<tr>
<td>European Union to announce new resolution next week</td>
</tr>
<tr>
<td>UN delivers report on world economic status</td>
</tr>
</table>
</body>
</html>