Renamed catcher to hook. Improved hooking.

This commit is contained in:
Christian P. MOMON 2016-12-06 14:36:45 +01:00
parent ad97832f48
commit 99bf85794b
19 changed files with 611 additions and 298 deletions

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View file

@ -16,11 +16,13 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View file

@ -16,22 +16,41 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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();
}

View file

@ -16,23 +16,35 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.catchers;
import java.util.ArrayList;
package fr.devinsy.kiss4web.hooks;
/**
*
*/
public class Catchers extends ArrayList<Catcher>
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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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<Hook> hooks;
/**
*
*/
public HookRegister()
{
super();
this.hooks = new ArrayList<Hook>();
}
/**
*
* @return
*/
public List<Hook> 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<Hook> 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;
}
}

View file

@ -16,11 +16,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.catchers;
package fr.devinsy.kiss4web.hooks;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View file

@ -16,11 +16,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;

View file

@ -16,11 +16,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;

View file

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.catchers;
package fr.devinsy.kiss4web.hooks;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View file

@ -16,11 +16,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;

View file

@ -16,11 +16,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
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;
}

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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;
}
}

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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<Part> 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
}
}