From 2d3dcaba776edd2b5969e97ee9ad4a7a512de462 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 5 Oct 2016 02:31:47 +0200 Subject: [PATCH] Renamed view packages --- .../prueba/controllers/web/PagesController.java | 2 +- .../com/prueba/services/impl/LoginServiceImpl.java | 3 +- src/main/java/com/prueba/view/LoginFormImpl.java | 48 ++++++++++++++++++++++ src/main/java/com/prueba/view/PageImpl.java | 24 +++++++++++ .../java/com/prueba/view/login/LoginFormImpl.java | 48 ---------------------- src/main/java/com/prueba/view/page/PageImpl.java | 24 ----------- 6 files changed, 74 insertions(+), 75 deletions(-) create mode 100644 src/main/java/com/prueba/view/LoginFormImpl.java create mode 100644 src/main/java/com/prueba/view/PageImpl.java delete mode 100644 src/main/java/com/prueba/view/login/LoginFormImpl.java delete mode 100644 src/main/java/com/prueba/view/page/PageImpl.java diff --git a/src/main/java/com/prueba/controllers/web/PagesController.java b/src/main/java/com/prueba/controllers/web/PagesController.java index c420a52..d17a53f 100644 --- a/src/main/java/com/prueba/controllers/web/PagesController.java +++ b/src/main/java/com/prueba/controllers/web/PagesController.java @@ -6,7 +6,7 @@ import java.io.OutputStream; import com.prueba.controllers.Controller; import com.prueba.core.http.sessions.SessionContext; import com.prueba.core.http.sessions.SessionInfo; -import com.prueba.view.page.PageImpl; +import com.prueba.view.PageImpl; import com.sun.net.httpserver.HttpExchange; public class PagesController implements Controller { diff --git a/src/main/java/com/prueba/services/impl/LoginServiceImpl.java b/src/main/java/com/prueba/services/impl/LoginServiceImpl.java index 8df3e78..dd3a6f0 100644 --- a/src/main/java/com/prueba/services/impl/LoginServiceImpl.java +++ b/src/main/java/com/prueba/services/impl/LoginServiceImpl.java @@ -11,7 +11,7 @@ import com.prueba.core.http.sessions.SessionContext; import com.prueba.core.http.sessions.SessionInfo; import com.prueba.core.http.sessions.Sessions; import com.prueba.model.dao.AccountDao; -import com.prueba.view.login.LoginFormImpl; +import com.prueba.view.LoginFormImpl; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; @@ -54,7 +54,6 @@ public class LoginServiceImpl { } httpExchange.sendResponseHeaders(200, html.length()); - try (final OutputStream os = httpExchange.getResponseBody()) { os.write(html.getBytes()); } diff --git a/src/main/java/com/prueba/view/LoginFormImpl.java b/src/main/java/com/prueba/view/LoginFormImpl.java new file mode 100644 index 0000000..41bbfda --- /dev/null +++ b/src/main/java/com/prueba/view/LoginFormImpl.java @@ -0,0 +1,48 @@ +package com.prueba.view; + +import static org.rendersnake.HtmlAttributesFactory.for_; +import static org.rendersnake.HtmlAttributesFactory.id; +import static org.rendersnake.HtmlAttributesFactory.type; + +import java.io.IOException; + +import org.rendersnake.HtmlCanvas; + +public class LoginFormImpl { + private static final String ID_USERNAME = "username"; + private static final String ID_PASSWORD = "password"; + private static final String VAR_USERNAME = "username"; + private static final String VAR_PASSWORD = "password"; + + public String doNoRequiredLogin() throws IOException { + final HtmlCanvas html = new HtmlCanvas(); + return html + .html() + .body() + .h1().content("NO REQUIRED LOGIN") + ._body() + ._html() + .toHtml(); + } + + public String doRequiredLogin(String requestedURI) throws IOException { + final HtmlCanvas html = new HtmlCanvas(); + return html + .html() + .form(id("sample").action(requestedURI).method("post")) + .label(for_(ID_USERNAME)).write("Username:")._label() + .input( + id(ID_USERNAME) + .name(VAR_USERNAME)) + .br() + .label(for_(ID_PASSWORD)).write("Password:")._label() + .input( + type("password") + .id(ID_PASSWORD) + .name(VAR_PASSWORD)) + .br() + .input(type("submit").value("Log me in")) + ._form() + .toHtml(); + } +} diff --git a/src/main/java/com/prueba/view/PageImpl.java b/src/main/java/com/prueba/view/PageImpl.java new file mode 100644 index 0000000..c9cf80e --- /dev/null +++ b/src/main/java/com/prueba/view/PageImpl.java @@ -0,0 +1,24 @@ +package com.prueba.view; + +import static org.rendersnake.HtmlAttributesFactory.href; + +import java.io.IOException; + +import org.rendersnake.HtmlCanvas; + +public class PageImpl { + + public String doPage(int number, String userName) throws IOException { + final HtmlCanvas html = new HtmlCanvas(); + return html + .html() + .body() + .h1().content("PAGE: " + number) + .h1().content("Hello " + userName) + .h1().a(href("/app/login/logout.html")).write("Logout")._a()._h1() + ._body() + ._html() + .toHtml(); + } + +} diff --git a/src/main/java/com/prueba/view/login/LoginFormImpl.java b/src/main/java/com/prueba/view/login/LoginFormImpl.java deleted file mode 100644 index e42b135..0000000 --- a/src/main/java/com/prueba/view/login/LoginFormImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.prueba.view.login; - -import static org.rendersnake.HtmlAttributesFactory.for_; -import static org.rendersnake.HtmlAttributesFactory.id; -import static org.rendersnake.HtmlAttributesFactory.type; - -import java.io.IOException; - -import org.rendersnake.HtmlCanvas; - -public class LoginFormImpl { - private static final String ID_USERNAME = "username"; - private static final String ID_PASSWORD = "password"; - private static final String VAR_USERNAME = "username"; - private static final String VAR_PASSWORD = "password"; - - public String doNoRequiredLogin() throws IOException { - final HtmlCanvas html = new HtmlCanvas(); - return html - .html() - .body() - .h1().content("NO REQUIRED LOGIN") - ._body() - ._html() - .toHtml(); - } - - public String doRequiredLogin(String requestedURI) throws IOException { - final HtmlCanvas html = new HtmlCanvas(); - return html - .html() - .form(id("sample").action(requestedURI).method("post")) - .label(for_(ID_USERNAME)).write("Username:")._label() - .input( - id(ID_USERNAME) - .name(VAR_USERNAME)) - .br() - .label(for_(ID_PASSWORD)).write("Password:")._label() - .input( - type("password") - .id(ID_PASSWORD) - .name(VAR_PASSWORD)) - .br() - .input(type("submit").value("Log me in")) - ._form() - .toHtml(); - } -} diff --git a/src/main/java/com/prueba/view/page/PageImpl.java b/src/main/java/com/prueba/view/page/PageImpl.java deleted file mode 100644 index f258825..0000000 --- a/src/main/java/com/prueba/view/page/PageImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.prueba.view.page; - -import static org.rendersnake.HtmlAttributesFactory.href; - -import java.io.IOException; - -import org.rendersnake.HtmlCanvas; - -public class PageImpl { - - public String doPage(int number, String userName) throws IOException { - final HtmlCanvas html = new HtmlCanvas(); - return html - .html() - .body() - .h1().content("PAGE: " + number) - .h1().content("Hello " + userName) - .h1().a(href("/app/login/logout.html")).write("Logout")._a()._h1() - ._body() - ._html() - .toHtml(); - } - -} -- 2.1.4