diff --git a/src/fr/devinsy/kiss4web/catchers/FolderCatcher.java b/src/fr/devinsy/kiss4web/catchers/FolderCatcher.java deleted file mode 100644 index 3705889..0000000 --- a/src/fr/devinsy/kiss4web/catchers/FolderCatcher.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2006-2010, 2013-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.catchers; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fr.devinsy.kiss4web.KissDispatcherUtils; -import fr.devinsy.util.strings.StringList; - -/** - * - */ -public class FolderCatcher -{ - private static Logger logger = LoggerFactory.getLogger(FolderCatcher.class); - - /** - * @throws IOException - * @throws ServletException - * - */ - public static void doCatch(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException - { - logger.debug("Doing catch."); - - String urlPath = request.getPathInfo(); - - String className; - String[] tokens = urlPath.split("/"); - if (tokens.length == 1) - { - className = "Index_xhtml"; - } - else - { - StringList buffer = new StringList(); - - // Note: as pathInfo starts always with a '/', the first - // good token index is 1. - for (int tokenCounter = 1; tokenCounter <= tokens.length - 1; tokenCounter++) - { - buffer.append(tokens[tokenCounter]); - buffer.append('.'); - } - - // String lastToken = tokens[tokens.length - 1]; - // buffer.append(StringUtils.capitalize(lastToken)).append("_xhtml"); - buffer.append("Index_xhtml"); - - className = buffer.toString(); - } - - className = KissDispatcherUtils.concatenatePackage(webClassesRootPackage, className); - logger.info("className=[" + className + "]"); - - KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className); - } - - /** - * - * @param urlPath - * @return - */ - public static boolean matches(final HttpServletRequest request) - { - boolean result; - - String urlPath = request.getPathInfo(); - - if ((urlPath != null) && (urlPath.endsWith("/"))) - { - result = true; - } - else - { - result = false; - } - - // - return result; - } - -} diff --git a/src/fr/devinsy/kiss4web/catchers/XHTMLCatcher.java b/src/fr/devinsy/kiss4web/catchers/XHTMLCatcher.java deleted file mode 100644 index 4222a40..0000000 --- a/src/fr/devinsy/kiss4web/catchers/XHTMLCatcher.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (C) 2006-2010, 2013-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.catchers; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fr.devinsy.kiss4web.KissDispatcherUtils; -import fr.devinsy.util.strings.StringList; - -/** - * - */ -public class XHTMLCatcher -{ - private static Logger logger = LoggerFactory.getLogger(XHTMLCatcher.class); - - /** - * @throws IOException - * @throws ServletException - */ - public static void doCatch(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException - { - logger.debug("Doing catch."); - - String urlPath = request.getPathInfo(); - - String className = translateToClassName(urlPath); - className = KissDispatcherUtils.concatenatePackage(webClassesRootPackage, className); - logger.info("className=[" + className + "]"); - - KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className); - } - - /** - * - * @param urlPath - * @return - */ - public static boolean matches(final HttpServletRequest request) - { - boolean result; - - String urlPath = request.getPathInfo(); - - if ((urlPath != null) && (urlPath.endsWith(".xhtml"))) - { - result = true; - } - else - { - result = false; - } - - // - return result; - } - - /** - * - * @param urlPath - * @return - */ - public static String translateToClassName(final String urlPath) - { - String result; - - String[] tokens = urlPath.split("/"); - if (tokens.length == 1) - { - result = "Index_xhtml"; - } - else - { - StringList buffer = new StringList(); - - // Note: as pathInfo starts always with a '/', the first - // good token index is 1. - for (int tokenCounter = 1; tokenCounter < tokens.length - 1; tokenCounter++) - { - buffer.append(tokens[tokenCounter]); - buffer.append('.'); - } - - String lastToken = tokens[tokens.length - 1]; - buffer.append(StringUtils.capitalize(lastToken).replace('.', '_')); - - result = buffer.toString(); - } - - // - return result; - } -} diff --git a/src/fr/devinsy/kiss4web/catchers/BlankCatcher.java b/src/fr/devinsy/kiss4web/hooks/BlankHook.java similarity index 72% rename from src/fr/devinsy/kiss4web/catchers/BlankCatcher.java rename to src/fr/devinsy/kiss4web/hooks/BlankHook.java index d88d628..9ddd20a 100644 --- a/src/fr/devinsy/kiss4web/catchers/BlankCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/BlankHook.java @@ -16,11 +16,13 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.IOException; import java.io.PrintWriter; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,15 +32,25 @@ import org.slf4j.LoggerFactory; /** * */ -public class BlankCatcher +public class BlankHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(BlankCatcher.class); + private static Logger logger = LoggerFactory.getLogger(BlankHook.class); + + /** + * + */ + public BlankHook() + { + super(); + } /** * @throws IOException * */ - public static void doCatch(final HttpServletResponse response) throws IOException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException { logger.debug("Doing catch."); @@ -57,7 +69,8 @@ public class BlankCatcher * @param urlPath * @return */ - public static boolean matches(final HttpServletRequest request) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; diff --git a/src/fr/devinsy/kiss4web/hooks/FolderHook.java b/src/fr/devinsy/kiss4web/hooks/FolderHook.java new file mode 100644 index 0000000..9d9fb53 --- /dev/null +++ b/src/fr/devinsy/kiss4web/hooks/FolderHook.java @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2006-2010, 2013-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.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.kiss4web.KissDispatcherUtils; + +/** + * + */ +public class FolderHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(FolderHook.class); + + /** + * + */ + public FolderHook() + { + super(); + } + + /** + * @throws IOException + * @throws ServletException + * + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("Doing catch."); + + String urlPath = request.getPathInfo(); + KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, urlPath); + } + + /** + * + * @param urlPath + * @return + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + String urlPath = request.getPathInfo(); + + if ((urlPath != null) && (urlPath.endsWith("/"))) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + +} diff --git a/src/fr/devinsy/kiss4web/catchers/Catcher.java b/src/fr/devinsy/kiss4web/hooks/Hook.java similarity index 55% rename from src/fr/devinsy/kiss4web/catchers/Catcher.java rename to src/fr/devinsy/kiss4web/hooks/Hook.java index ff590a3..6cce1a4 100644 --- a/src/fr/devinsy/kiss4web/catchers/Catcher.java +++ b/src/fr/devinsy/kiss4web/hooks/Hook.java @@ -16,22 +16,41 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * */ -public interface Catcher +public interface Hook { - void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws Exception; + /** + * + * @param request + * @param response + * @throws Exception + */ + void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException; /** * * @param source * @return */ - boolean matches(final String urlPath); + boolean matches(final ServletContext servletContext, final HttpServletRequest request); + + /** + * + * + * @return true if it is a final hook, false otherwise. + */ + boolean isTerminal(); } diff --git a/src/fr/devinsy/kiss4web/catchers/Catchers.java b/src/fr/devinsy/kiss4web/hooks/HookCore.java similarity index 67% rename from src/fr/devinsy/kiss4web/catchers/Catchers.java rename to src/fr/devinsy/kiss4web/hooks/HookCore.java index 1cfaac3..f8e5885 100644 --- a/src/fr/devinsy/kiss4web/catchers/Catchers.java +++ b/src/fr/devinsy/kiss4web/hooks/HookCore.java @@ -16,23 +16,35 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; - -import java.util.ArrayList; +package fr.devinsy.kiss4web.hooks; /** * */ -public class Catchers extends ArrayList +public abstract class HookCore implements Hook { - private static final long serialVersionUID = -5400120588573116300L; + private boolean terminal; + + public void setTerminal(boolean terminal) + { + this.terminal = terminal; + } /** * */ - public Catchers() + public HookCore() { super(); + + this.terminal = true; } + /** + * + */ + public boolean isTerminal() + { + return this.terminal; + } } diff --git a/src/fr/devinsy/kiss4web/hooks/HookRegister.java b/src/fr/devinsy/kiss4web/hooks/HookRegister.java new file mode 100644 index 0000000..fa444c6 --- /dev/null +++ b/src/fr/devinsy/kiss4web/hooks/HookRegister.java @@ -0,0 +1,98 @@ +/** + * Copyright (C) 2006-2010, 2013-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.hooks; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +/** + * + */ +public class HookRegister +{ + List hooks; + + /** + * + */ + public HookRegister() + { + super(); + + this.hooks = new ArrayList(); + } + + /** + * + * @return + */ + public List hooks() + { + return hooks; + } + + /** + * + * @param hook + */ + public void register(Hook hook) + { + hooks.add(hook); + } + + /** + * + * @param servletContext + * @param request + * @return + */ + public Hook getMatching(final ServletContext servletContext, final HttpServletRequest request) + { + Hook result; + + boolean ended = false; + Iterator iterator = this.hooks.iterator(); + result = null; + while (!ended) + { + if (iterator.hasNext()) + { + Hook currentHook = iterator.next(); + + if (currentHook.matches(servletContext, request)) + { + ended = true; + result = currentHook; + } + } + else + { + ended = true; + result = null; + } + } + + // + return result; + } +} diff --git a/src/fr/devinsy/kiss4web/catchers/LongURLCatcher.java b/src/fr/devinsy/kiss4web/hooks/LongURLHook.java similarity index 70% rename from src/fr/devinsy/kiss4web/catchers/LongURLCatcher.java rename to src/fr/devinsy/kiss4web/hooks/LongURLHook.java index 012700b..98766d1 100644 --- a/src/fr/devinsy/kiss4web/catchers/LongURLCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/LongURLHook.java @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.IOException; import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,28 +34,34 @@ import fr.devinsy.kiss4web.KissDispatcherUtils; /** * */ -public class LongURLCatcher +public class LongURLHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(LongURLCatcher.class); + private static Logger logger = LoggerFactory.getLogger(LongURLHook.class); + + /** + * + */ + public LongURLHook() + { + super(); + } /** * @throws IOException * @throws ServletException * */ - public static void doCatch(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException { logger.debug("Doing catch."); String urlPath = request.getPathInfo(); String rewritedURLPath = LongURLRewriter.unrewrite(urlPath); - String className = XHTMLCatcher.translateToClassName(rewritedURLPath); - className = KissDispatcherUtils.concatenatePackage(webClassesRootPackage, className); - logger.info("className=[" + className + "]"); - KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className); + KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, rewritedURLPath); } /** @@ -62,7 +69,8 @@ public class LongURLCatcher * @param urlPath * @return */ - public static boolean matches(final HttpServletRequest request) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; diff --git a/src/fr/devinsy/kiss4web/catchers/LongURLRewriter.java b/src/fr/devinsy/kiss4web/hooks/LongURLRewriter.java similarity index 95% rename from src/fr/devinsy/kiss4web/catchers/LongURLRewriter.java rename to src/fr/devinsy/kiss4web/hooks/LongURLRewriter.java index c0c0c23..d7780af 100644 --- a/src/fr/devinsy/kiss4web/catchers/LongURLRewriter.java +++ b/src/fr/devinsy/kiss4web/hooks/LongURLRewriter.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.catchers; +package fr.devinsy.kiss4web.hooks; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/fr/devinsy/kiss4web/catchers/RootCatcher.java b/src/fr/devinsy/kiss4web/hooks/RootHook.java similarity index 69% rename from src/fr/devinsy/kiss4web/catchers/RootCatcher.java rename to src/fr/devinsy/kiss4web/hooks/RootHook.java index 87f3201..23d9870 100644 --- a/src/fr/devinsy/kiss4web/catchers/RootCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/RootHook.java @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.IOException; import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,23 +34,31 @@ import fr.devinsy.kiss4web.KissDispatcherUtils; /** * */ -public class RootCatcher +public class RootHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(RootCatcher.class); + private static Logger logger = LoggerFactory.getLogger(RootHook.class); + + /** + * + */ + public RootHook() + { + super(); + } /** * @throws IOException * @throws ServletException * */ - public static void doCatch(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException { logger.debug("Doing catch."); - String className = KissDispatcherUtils.concatenatePackage(webClassesRootPackage, "Index_xhtml"); + String className = "index.xhtml"; - logger.info("classPathname=[" + className + "]"); KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className); } @@ -58,7 +67,8 @@ public class RootCatcher * @param urlPath * @return */ - public static boolean matches(final HttpServletRequest request) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; diff --git a/src/fr/devinsy/kiss4web/catchers/ShortURLCatcher.java b/src/fr/devinsy/kiss4web/hooks/ShortURLHook.java similarity index 70% rename from src/fr/devinsy/kiss4web/catchers/ShortURLCatcher.java rename to src/fr/devinsy/kiss4web/hooks/ShortURLHook.java index 4f7c3f3..fb5df13 100644 --- a/src/fr/devinsy/kiss4web/catchers/ShortURLCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/ShortURLHook.java @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.IOException; import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,17 +34,26 @@ import fr.devinsy.kiss4web.KissDispatcherUtils; /** * */ -public class ShortURLCatcher +public class ShortURLHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(ShortURLCatcher.class); + private static Logger logger = LoggerFactory.getLogger(ShortURLHook.class); + + /** + * + */ + public ShortURLHook() + { + super(); + } /** * @throws IOException * @throws ServletException * */ - public static void doCatch(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException { logger.debug("Doing catch."); @@ -51,12 +61,7 @@ public class ShortURLCatcher String rewritedURLPath = ShortURLRewriter.unrewrite(urlPath); - String className = XHTMLCatcher.translateToClassName(rewritedURLPath); - className = KissDispatcherUtils.concatenatePackage(webClassesRootPackage, className); - - logger.info("className=[" + className + "]"); - - KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, className); + KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, rewritedURLPath); } /** @@ -64,7 +69,8 @@ public class ShortURLCatcher * @param urlPath * @return */ - public static boolean matches(final HttpServletRequest request) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; diff --git a/src/fr/devinsy/kiss4web/catchers/ShortURLRewriter.java b/src/fr/devinsy/kiss4web/hooks/ShortURLRewriter.java similarity index 96% rename from src/fr/devinsy/kiss4web/catchers/ShortURLRewriter.java rename to src/fr/devinsy/kiss4web/hooks/ShortURLRewriter.java index 770242d..79af076 100644 --- a/src/fr/devinsy/kiss4web/catchers/ShortURLRewriter.java +++ b/src/fr/devinsy/kiss4web/hooks/ShortURLRewriter.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.catchers; +package fr.devinsy.kiss4web.hooks; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/fr/devinsy/kiss4web/hooks/StatisticsHook.java b/src/fr/devinsy/kiss4web/hooks/StatisticsHook.java new file mode 100644 index 0000000..a51b8e4 --- /dev/null +++ b/src/fr/devinsy/kiss4web/hooks/StatisticsHook.java @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2006-2010, 2013-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.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class StatisticsHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(StatisticsHook.class); + + /** + * + */ + public StatisticsHook() + { + super(); + + setTerminal(false); + } + + /** + * @throws IOException + * + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException + { + logger.debug("Doing catch."); + + // TODO store statistics. + } + + /** + * + * @param urlPath + * @return + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + result = true; + + // + return result; + } +} diff --git a/src/fr/devinsy/kiss4web/catchers/WebContentCatcher.java b/src/fr/devinsy/kiss4web/hooks/WebContentHook.java similarity index 75% rename from src/fr/devinsy/kiss4web/catchers/WebContentCatcher.java rename to src/fr/devinsy/kiss4web/hooks/WebContentHook.java index 3d63230..ae31e83 100644 --- a/src/fr/devinsy/kiss4web/catchers/WebContentCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/WebContentHook.java @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.File; import java.io.IOException; +import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -34,16 +35,26 @@ import fr.devinsy.kiss4web.KissDispatcherUtils; /** * */ -public class WebContentCatcher +public class WebContentHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(WebContentCatcher.class); + private static Logger logger = LoggerFactory.getLogger(WebContentHook.class); + + /** + * + */ + public WebContentHook() + { + super(); + } /** * @throws IOException * @throws ServletException * */ - public static void doCatch(final ServletContext servletContext, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException { logger.debug("Doing catch."); @@ -61,7 +72,8 @@ public class WebContentCatcher * @param urlPath * @return */ - public static boolean matches(final ServletContext servletContext, final HttpServletRequest request) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; diff --git a/src/fr/devinsy/kiss4web/catchers/WebInfCatcher.java b/src/fr/devinsy/kiss4web/hooks/WebInfHook.java similarity index 73% rename from src/fr/devinsy/kiss4web/catchers/WebInfCatcher.java rename to src/fr/devinsy/kiss4web/hooks/WebInfHook.java index 2a397f1..40b0bc7 100644 --- a/src/fr/devinsy/kiss4web/catchers/WebInfCatcher.java +++ b/src/fr/devinsy/kiss4web/hooks/WebInfHook.java @@ -16,11 +16,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Kiss4web. If not, see */ -package fr.devinsy.kiss4web.catchers; +package fr.devinsy.kiss4web.hooks; import java.io.File; import java.io.IOException; +import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -34,21 +35,30 @@ import fr.devinsy.kiss4web.KissDispatcherUtils; /** * */ -public class WebInfCatcher +public class WebInfHook extends HookCore { - private static Logger logger = LoggerFactory.getLogger(WebInfCatcher.class); + private static Logger logger = LoggerFactory.getLogger(WebInfHook.class); + + /** + * + */ + public WebInfHook() + { + super(); + } /** * @throws IOException * @throws ServletException * */ - public static void doCatch(final ServletContext servletContext, final HttpServletRequest request, final HttpServletResponse response, final String webClassesRootPackage) throws IOException, - ServletException + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException { logger.debug("Doing catch."); - String path = servletContext.getRealPath("/") + "WEB-INF/classes/" + webClassesRootPackage.replaceAll("\\.", "/") + request.getPathInfo(); + String path = servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo(); logger.info("path=[{}]", path); @@ -63,11 +73,12 @@ public class WebInfCatcher * @param urlPath * @return */ - public static boolean matches(final ServletContext servletContext, final HttpServletRequest request, final String webClassesRootPackage) + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) { boolean result; - if (new File(servletContext.getRealPath("/") + "WEB-INF/classes/" + webClassesRootPackage.replaceAll("\\.", "/") + request.getPathInfo()).exists()) + if (new File(servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo()).exists()) { result = true; } diff --git a/src/fr/devinsy/kiss4web/hooks/XHTMLHook.java b/src/fr/devinsy/kiss4web/hooks/XHTMLHook.java new file mode 100644 index 0000000..7a206ec --- /dev/null +++ b/src/fr/devinsy/kiss4web/hooks/XHTMLHook.java @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2006-2010, 2013-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.hooks; + +import java.io.IOException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.kiss4web.KissDispatcherUtils; + +/** + * + */ +public class XHTMLHook extends HookCore +{ + private static Logger logger = LoggerFactory.getLogger(XHTMLHook.class); + + /** + * + */ + public XHTMLHook() + { + super(); + } + + /** + * @throws IOException + * @throws ServletException + */ + @Override + public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request, + final HttpServletResponse response) throws IOException, ServletException + { + logger.debug("Doing catch."); + + String urlPath = request.getPathInfo(); + + KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, urlPath); + } + + /** + * + * @param urlPath + * @return + */ + @Override + public boolean matches(final ServletContext servletContext, final HttpServletRequest request) + { + boolean result; + + String urlPath = request.getPathInfo(); + + if ((urlPath != null) && (urlPath.endsWith(".xhtml"))) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + +} diff --git a/test/fr/devinsy/kiss4web/catchers/BlankCatcherTest.java b/test/fr/devinsy/kiss4web/catchers/BlankCatcherTest.java index 1f4b2f1..c7ae845 100644 --- a/test/fr/devinsy/kiss4web/catchers/BlankCatcherTest.java +++ b/test/fr/devinsy/kiss4web/catchers/BlankCatcherTest.java @@ -23,6 +23,8 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.kiss4web.hooks.BlankHook; +import fr.devinsy.kiss4web.hooks.ShortURLHook; import fr.devinsy.kiss4web.mocks.HttpServletRequestMock; /** @@ -31,7 +33,7 @@ import fr.devinsy.kiss4web.mocks.HttpServletRequestMock; */ public class BlankCatcherTest { - private static Logger logger = LoggerFactory.getLogger(ShortURLCatcher.class); + private static Logger logger = LoggerFactory.getLogger(ShortURLHook.class); /** * @@ -42,7 +44,7 @@ public class BlankCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo(null); - Assert.assertTrue(BlankCatcher.matches(source)); + Assert.assertTrue(BlankHook.matches(source)); } /** @@ -54,7 +56,7 @@ public class BlankCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo(""); - Assert.assertTrue(BlankCatcher.matches(source)); + Assert.assertTrue(BlankHook.matches(source)); } /** @@ -66,6 +68,6 @@ public class BlankCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo("/"); - Assert.assertFalse(BlankCatcher.matches(source)); + Assert.assertFalse(BlankHook.matches(source)); } } diff --git a/test/fr/devinsy/kiss4web/catchers/RootCatcherTest.java b/test/fr/devinsy/kiss4web/catchers/RootCatcherTest.java index fdc8fe7..051c0fd 100644 --- a/test/fr/devinsy/kiss4web/catchers/RootCatcherTest.java +++ b/test/fr/devinsy/kiss4web/catchers/RootCatcherTest.java @@ -23,6 +23,8 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.kiss4web.hooks.RootHook; +import fr.devinsy.kiss4web.hooks.ShortURLHook; import fr.devinsy.kiss4web.mocks.HttpServletRequestMock; /** @@ -31,7 +33,7 @@ import fr.devinsy.kiss4web.mocks.HttpServletRequestMock; */ public class RootCatcherTest { - private static Logger logger = LoggerFactory.getLogger(ShortURLCatcher.class); + private static Logger logger = LoggerFactory.getLogger(ShortURLHook.class); /** * @@ -42,7 +44,7 @@ public class RootCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo(null); - Assert.assertFalse(RootCatcher.matches(source)); + Assert.assertFalse(RootHook.matches(source)); } /** @@ -54,7 +56,7 @@ public class RootCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo(""); - Assert.assertFalse(RootCatcher.matches(source)); + Assert.assertFalse(RootHook.matches(source)); } /** @@ -66,7 +68,7 @@ public class RootCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo("/"); - Assert.assertTrue(RootCatcher.matches(source)); + Assert.assertTrue(RootHook.matches(source)); } /** @@ -78,6 +80,6 @@ public class RootCatcherTest HttpServletRequestMock source = new HttpServletRequestMock(); source.setPathInfo("/toto"); - Assert.assertFalse(RootCatcher.matches(source)); + Assert.assertFalse(RootHook.matches(source)); } } diff --git a/test/fr/devinsy/kiss4web/mocks/HttpServletRequestMock.java b/test/fr/devinsy/kiss4web/mocks/HttpServletRequestMock.java index e6aa94f..9446efc 100644 --- a/test/fr/devinsy/kiss4web/mocks/HttpServletRequestMock.java +++ b/test/fr/devinsy/kiss4web/mocks/HttpServletRequestMock.java @@ -22,20 +22,29 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.Principal; +import java.util.Collection; import java.util.Enumeration; import java.util.Locale; import java.util.Map; +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javax.servlet.http.Part; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fr.devinsy.kiss4web.catchers.ShortURLCatcher; +import fr.devinsy.kiss4web.hooks.ShortURLHook; /** * @@ -43,7 +52,7 @@ import fr.devinsy.kiss4web.catchers.ShortURLCatcher; */ public class HttpServletRequestMock implements HttpServletRequest { - private static Logger logger = LoggerFactory.getLogger(ShortURLCatcher.class); + private static Logger logger = LoggerFactory.getLogger(ShortURLHook.class); private String pathInfo; @@ -429,4 +438,88 @@ public class HttpServletRequestMock implements HttpServletRequest this.pathInfo = pathInfo; } + @Override + public AsyncContext getAsyncContext() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public DispatcherType getDispatcherType() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServletContext getServletContext() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isAsyncStarted() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isAsyncSupported() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public AsyncContext startAsync() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean authenticate(HttpServletResponse arg0) throws IOException, ServletException + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Part getPart(String arg0) throws IOException, IllegalStateException, ServletException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Collection getParts() throws IOException, IllegalStateException, ServletException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void login(String arg0, String arg1) throws ServletException + { + // TODO Auto-generated method stub + + } + + @Override + public void logout() throws ServletException + { + // TODO Auto-generated method stub + + } + }