From a51396ecbe1666804a793547770be97f3563d72b Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 19 Sep 2016 03:55:20 +0200 Subject: [PATCH] Integrated Xidyn demo. --- .../demo/website/dispatcher/index.html | 4 +- .../demo/website/xidyn/Index_xhtml.java | 389 ++++++++++++++++++ .../Raw_hello_xhtml.java | 2 +- .../kiss4web/demo/website/xidyn/index.html | 89 ++++ 4 files changed, 481 insertions(+), 3 deletions(-) create mode 100644 src/fr/devinsy/kiss4web/demo/website/xidyn/Index_xhtml.java rename src/fr/devinsy/kiss4web/demo/website/{dispatcher => xidyn}/Raw_hello_xhtml.java (97%) create mode 100644 src/fr/devinsy/kiss4web/demo/website/xidyn/index.html diff --git a/src/fr/devinsy/kiss4web/demo/website/dispatcher/index.html b/src/fr/devinsy/kiss4web/demo/website/dispatcher/index.html index 76160dc..69c17b7 100644 --- a/src/fr/devinsy/kiss4web/demo/website/dispatcher/index.html +++ b/src/fr/devinsy/kiss4web/demo/website/dispatcher/index.html @@ -60,12 +60,12 @@ WebContent URL /path/hello.png - return direct file + KissDispatcher returns direct file Classes URL /path/hello.png - return direct file + KissDispatcher returns direct file

diff --git a/src/fr/devinsy/kiss4web/demo/website/xidyn/Index_xhtml.java b/src/fr/devinsy/kiss4web/demo/website/xidyn/Index_xhtml.java new file mode 100644 index 0000000..0ddb6f2 --- /dev/null +++ b/src/fr/devinsy/kiss4web/demo/website/xidyn/Index_xhtml.java @@ -0,0 +1,389 @@ +/** + * Copyright (C) 2016 Christian Pierre MOMON + * + * This file is part of Kiss4web. + * + * Kiss4web is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Kiss4web is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Kiss4web. If not, see + */ +package fr.devinsy.kiss4web.demo.website.xidyn; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringEscapeUtils; + +import fr.devinsy.kiss4web.demo.website.FatalView; +import fr.devinsy.util.strings.StringList; +import fr.devinsy.xidyn.data.SimpleTagData; +import fr.devinsy.xidyn.pages.Page; +import fr.devinsy.xidyn.pages.PageFactory; + +/** + * + */ +public class Index_xhtml extends HttpServlet +{ + private static final long serialVersionUID = 1513508164890999104L; + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Index_xhtml.class); + + /** + * + */ + @Override + public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("doGet starting…"); + + try + { + // + logger.debug("doGet starting…"); + + // Get parameters. + // =============== + // Locale locale = kiwa.getUserLocale(request); + // Long accountId = kiwa.getAuthentifiedAccountId(request, + // response); + + // Use parameters. + // =============== + + // Send response. + // ============== + Page demoPage = PageFactory.instance().create("/fr/devinsy/kiss4web/demo/website/xidyn/index.html"); + + // Step #01. + { + try + { + System.out.println("----------------------------"); + + String htmlSource = "
a pseudo
"; + + Page page = new Page(htmlSource); + page.setContent("pseudo", "Superman"); + + String htmlTarget = page.dynamizeToString(); + + StringList display = new StringList(); + display.append(StringEscapeUtils.escapeXml(htmlSource)).appendln("
"); + display.append("+").appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.set(\"pseudo\", \"superman\");")).appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget)).appendln("
"); + + demoPage.setContent("demo1", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo1", exception.getMessage()); + } + } + + // Step #02. + { + try + { + System.out.println("----------------------------"); + + String htmlSource = "
a pseudo
"; + + Page page = new Page(htmlSource); + page.setContent("pseudo", "Spiderman"); + page.appendAttribute("pseudo", "style", "background: blue;"); + page.appendAttribute("pseudo", "style", "foreground: red;"); + page.setAttribute("pseudo", "class", "superhero"); + + String htmlTarget = page.dynamizeToString(); + + StringList display = new StringList(); + display.append(StringEscapeUtils.escapeXml(htmlSource)).appendln("
"); + display.append("+").appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.set(\"pseudo\", \"spiderman\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.appendAttribute(\"pseudo\", \"style\", \"foreground: red\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.appendAttribute(\"pseudo\", \"style\", \"background: blue\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setAttribute(\"pseudo\", \"class\", \"superhero\");")).appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget)).appendln("
"); + + demoPage.setContent("demo2", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo2", exception.getMessage()); + } + } + + // Step #03a. + { + try + { + System.out.println("----------------------------"); + + StringList source = new StringList(); + source.appendln(""); + String htmlSource = source.toString(); + + Page page = new Page(htmlSource); + page.addContent("words", "alpha"); + page.addContent("words", "bravo"); + page.addContent("words", "charlie"); + page.addContent("words", "delta"); + page.addContent("words", "echo"); + page.addContent("words", "fox"); + + String htmlTarget = page.dynamizeToString(); + + StringList display = new StringList(); + display.appendln(StringEscapeUtils.escapeXml(htmlSource).replace("\n", "
\n").replace(" ", " \n")); + display.append("+").appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"alpha\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"bravo\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"charlie\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"delta\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"echo\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.addContent (\"words\", \"fox\");")).appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo3.1", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo3.1", exception.getMessage()); + } + } + + // Step #03b. + { + try + { + System.out.println("----------------------------"); + + StringList source = new StringList(); + source.appendln(""); + String htmlSource = source.toString(); + + // Populate. + Page page = new Page(htmlSource); + page.setContent("words", 0, "alpha"); + page.setContent("words", 1, "bravo"); + page.setContent("words", 2, "charlie"); + page.setContent("words", 3, "delta"); + page.setContent("words", 4, "echo"); + page.setContent("words", 5, "fox"); + + String htmlTarget = page.dynamizeToString(); + + StringList display = new StringList(); + display.appendln(StringEscapeUtils.escapeXml(htmlSource).replace("\n", "
\n").replace(" ", " \n")); + display.append("+").appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 0, \"alpha\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 1, \"bravo\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 2, \"charlie\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 3, \"delta\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 4, \"echo\");")).appendln("
"); + display.append(StringEscapeUtils.escapeXml("page.setContent (\"words\", 5, \"fox\");")).appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo3.2", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo3.2", exception.getMessage()); + } + } + + // Step #04. + { + try + { + System.out.println("----------------------------"); + + StringList source = new StringList(); + source.append("\n"); + source.append(" \n"); + source.append("
noidJeanReve
"); + String htmlSource = source.toString(); + + // Populate. + Page page = new Page(htmlSource); + page.setContent("identity", 0, "last_name", "Jemba"); + page.setContent("identity", 0, "first_name", "Epo"); + page.setContent("identity", 1, "last_name", "Momon"); + page.setContent("identity", 1, "first_name", "Christian"); + page.setContent("identity", 2, "last_name", "Tronche"); + page.setContent("identity", 2, "first_name", "Christophe"); + + String htmlTarget = page.dynamizeToString(); + + StringList display = new StringList(); + display.appendln(StringEscapeUtils.escapeXml(htmlSource).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + display.append("+").appendln("
"); + System.out.println("datas = new Data ();"); + display.append("page.setContent (\"identity\", 0, \"last_name\", \"Jemba\");").appendln("
"); + display.append("page.setContent (\"identity\", 0, \"first_name\", \"Epo\");").appendln("
"); + display.append("page.setContent (\"identity\", 1, \"last_name\", \"Momon\");").appendln("
"); + display.append("page.setContent (\"identity\", 1, \"first_name\", \"Christian\");").appendln("
"); + display.append("page.setContent (\"identity\", 2, \"last_name\", \"Tronche\");").appendln("
"); + display.append("page.setContent (\"identity\", 2, \"first_name\", \"Christophe\");").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo4", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo4", exception.getMessage()); + } + } + + // Step #05. + { + try + { + System.out.println("----------------------------"); + + StringList source = new StringList(); + source.appendln(""); + String htmlSource = source.toString(); + + // Populate. + Page page = new Page(htmlSource); + + StringList display = new StringList(); + display.appendln(StringEscapeUtils.escapeXml(htmlSource).replace("\n", "
\n").replace(" ", " \n")); + demoPage.setContent("demo5", display.toString()); + + // + page.setIterationStrategy("words", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW); + String htmlTarget = page.dynamizeToString(); + + display = new StringList(); + display.append("

Strategy ONLY_FIRST_ROW

"); + display.append("+").appendln("
"); + display.append("page.setIterationStrategy(\"words\", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW);").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo5.1", display.toString()); + + // + page.setIterationStrategy("words", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS); + htmlTarget = page.dynamizeToString(); + + display = new StringList(); + display.append("

Strategy ONLY_FIRST_TWO_ROWS

"); + display.append("+").appendln("
"); + display.append("page.setIterationStrategy(\"words\", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS);").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo5.2", display.toString()); + + // + page.setIterationStrategy("words", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID); + htmlTarget = page.dynamizeToString(); + + display = new StringList(); + display.append("

Strategy ONLY_ROWS_WITH_ID

"); + display.append("+").appendln("
"); + display.append("page.setIterationStrategy(\"words\", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID);").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo5.3", display.toString()); + + // + page.setIterationStrategy("words", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + htmlTarget = page.dynamizeToString(); + + display = new StringList(); + display.append("

Strategy ONLY_ROWS_WITHOUT_ID

"); + display.append("+").appendln("
"); + display.append("page.setIterationStrategy(\"words\", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo5.4", display.toString()); + + // + page.setIterationStrategy("words", SimpleTagData.IterationStrategy.ALL_ROWS); + htmlTarget = page.dynamizeToString(); + + display = new StringList(); + display.append("

Strategy ALL_ROWS

"); + display.append("+").appendln("
"); + display.append("page.setIterationStrategy(\"v\", SimpleTagData.IterationStrategy.ALL_ROWS);").appendln("
"); + display.append("=>").appendln("
"); + display.append(StringEscapeUtils.escapeXml(htmlTarget).replace("\n", "
\n").replace(" ", " \n")).appendln("
"); + + demoPage.setContent("demo5.5", display.toString()); + } + catch (Exception exception) + { + demoPage.setContent("demo5.1", exception.getMessage()); + } + } + + // + Page charter = PageFactory.instance().create("/fr/devinsy/kiss4web/demo/website/charter/charter.html"); + charter.include("content_container", demoPage); + String html = charter.dynamize().toString(); + + // Display page. + response.setContentType("application/xhtml+xml; charset=UTF-8"); + response.getWriter().println(html); + } + catch (Exception exception) + { + FatalView.show(request, response, exception); + } + + logger.debug("doGet done."); + } + + /** + * + */ + @Override + public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException + { + doGet(request, response); + } + + /** + * + */ + @Override + public void init() throws ServletException + { + } +} + +// //////////////////////////////////////////////////////////////////////// diff --git a/src/fr/devinsy/kiss4web/demo/website/dispatcher/Raw_hello_xhtml.java b/src/fr/devinsy/kiss4web/demo/website/xidyn/Raw_hello_xhtml.java similarity index 97% rename from src/fr/devinsy/kiss4web/demo/website/dispatcher/Raw_hello_xhtml.java rename to src/fr/devinsy/kiss4web/demo/website/xidyn/Raw_hello_xhtml.java index 7a7e8e8..a7a5b1f 100644 --- a/src/fr/devinsy/kiss4web/demo/website/dispatcher/Raw_hello_xhtml.java +++ b/src/fr/devinsy/kiss4web/demo/website/xidyn/Raw_hello_xhtml.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.demo.website.dispatcher; +package fr.devinsy.kiss4web.demo.website.xidyn; import java.io.IOException; import java.io.PrintWriter; diff --git a/src/fr/devinsy/kiss4web/demo/website/xidyn/index.html b/src/fr/devinsy/kiss4web/demo/website/xidyn/index.html new file mode 100644 index 0000000..f6cb2fc --- /dev/null +++ b/src/fr/devinsy/kiss4web/demo/website/xidyn/index.html @@ -0,0 +1,89 @@ + + + + + Kiss4web + + + + + + + +

Dispatcher Xidyn

+

+ Template is another step of the web application requirements. How dynamize a static HTML file with data? +

+

+ There is many frameworks about template activity. + Almost every time, the solution is to add one more layer above the HTML grammar, and sometimes into. + Do you imagine how to manage dozens pages containing corrupt HTML? It is weird. +

+ +

+ Kiss4web offers a simple solution: use the id of HTML tag to modify them. +

+ +

Instanciate page

+

+ A page is defined by: +

    +
  • a presenter: the entity which dynamize template
  • +
  • dynamic data: data to put in the template
  • +
+

+

+ Many HTML sources are available to instanciate a page: + + + + + + + + + + + + + + + + + + + + + + + + + +
SourceExample
Stringnew Page("<div name='pseudo'>a pseudo</div>")
Filenew Page("/home/foo/files/index.html")
URL from networknew Page("http://www.devinsy.fr/foo/index.html")
URL from Java packagenew Page("/fr/devinsy/kiss4web/demo/website/xidyn/index.html")
DOMnew Page(document)
+

+ +

Set content tag

+

n/a

+ +

Set attribute tag

+

n/a

+ +

Repeat tag (without line index)

+

n/a

+ +

Repeat tag (with line index)

+

n/a

+ +

Fill table

+

n/a

+ +

Iteration strategies

+

n/a

+

n/a

+

n/a

+

n/a

+

n/a

+

n/a

+ + + \ No newline at end of file