Compare commits

..

4 commits

20 changed files with 222 additions and 51 deletions

View file

@ -110,6 +110,7 @@
<attribute name="Built-By" value="${user.name} using ant" />
<attribute name="Built-Date" value="${dist.time}" />
</manifest>
<service type="javax.annotation.processing.Processor" provider="fr.devinsy.kiss4web.dispatcher.annotation.KissServletProcessor" />
<fileset dir="${build.classes}" />
</jar>

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2006-2023 Christian Pierre MOMON
* Copyright (C) 2006-2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
@ -32,14 +32,14 @@ import jakarta.servlet.http.HttpServletResponse;
*/
public class CookieHelper
{
private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class);
public enum Scope
{
HTTP_AND_HTTPS,
HTTPS_ONLY
}
private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class);
/**
* Builds the cookie.
*

View file

@ -23,6 +23,9 @@ import java.util.HashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
/**
* The Class HtmlCache.
*/
@ -39,11 +42,107 @@ public class HtmlCache extends HashMap<String, String>
super();
}
/**
* Builds the key.
*
* @param object
* the object
* @param strings
* the strings
* @return the string
*/
public String buildKey(final Object object, final String... strings)
{
String result;
if (object == null)
{
result = null;
}
else
{
result = buildKey(object.getClass().getCanonicalName(), strings);
}
//
return result;
}
/**
* Builds the key.
*
* @param main
* the main
* @param strings
* the strings
* @return the string
*/
public String buildKey(final String main, final String... strings)
{
String result;
if (main == null)
{
result = null;
}
else
{
int capacity = strings.length * 2 + 1;
StringList buffer = new StringList(capacity);
buffer.add(main);
for (int index = 0; index < strings.length; index++)
{
buffer.append('#');
buffer.append(index);
buffer.append(strings[index]);
}
result = buffer.toString();
}
//
return result;
}
/**
* Gets the HTML code using a GET request.
*
* @param request
* the request
* @return the string
*/
public String get(final HttpServletRequest request)
{
String result;
if (request == null)
{
result = null;
}
else
{
String key = request.getPathInfo();
if (request.getQueryString() != null)
{
key = key + "?" + request.getQueryString();
}
result = super.get(key);
if (result != null)
{
logger.info("HTML CACHE MATCHED: [{}]", key);
}
}
//
return result;
}
/**
* Gets the.
*
* @param get
* the get
* @param key
* the key
* @return the string
*/
public String get(final String key)
@ -67,4 +166,35 @@ public class HtmlCache extends HashMap<String, String>
//
return result;
}
/**
* Put HTML code using a GET request.
*
* @param html
* the html
* @param request
* the request
* @return the string
*/
public String put(final HttpServletRequest request, final String html)
{
String result;
if ((request == null) || (html == null))
{
result = null;
}
else
{
String key = request.getPathInfo();
if (request.getQueryString() != null)
{
key = key + "?" + request.getQueryString();
}
result = super.put(key, html);
}
//
return result;
}
}

View file

@ -43,6 +43,8 @@ import fr.devinsy.kiss4web.dispatcher.hooks.XHTMLHook;
*/
public class Kiss4web
{
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Kiss4web.class);
/**
* The Enum Mode.
*/
@ -63,8 +65,6 @@ public class Kiss4web
private static final Kiss4web instance = new Kiss4web();
}
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Kiss4web.class);
private BuildInformation buildInformation;
private Mode mode;
@ -238,6 +238,8 @@ public class Kiss4web
this.mode = mode;
}
break;
default:
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2006-2023 Christian Pierre MOMON
* Copyright (C) 2006-2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
@ -28,6 +28,8 @@ import jakarta.servlet.http.HttpServletResponse;
*/
public class Redirector
{
private static final Logger logger = LoggerFactory.getLogger(Redirector.class);
public enum Type
{
MOVED_PERMANENTLY(HttpServletResponse.SC_MOVED_PERMANENTLY),
@ -56,8 +58,6 @@ public class Redirector
}
}
private static final Logger logger = LoggerFactory.getLogger(Redirector.class);
/**
* Redirect.
*

View file

@ -36,8 +36,10 @@ import jakarta.servlet.http.HttpServletRequest;
* The Class KissDispatcher.
*
* According that URL is under UTF-8 format. Set Tomcat connector if needs
* (<connector URIEncoding="UTF-8" />).
*
* <pre>
* <connector URIEncoding="UTF-8" />.
* </pre>
*/
public class KissDispatcher
{

View file

@ -31,13 +31,13 @@ import jakarta.servlet.http.HttpServlet;
*/
public class KissDispatcherFactory
{
static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
private static class SingletonHolder
{
private static final KissDispatcherFactory instance = new KissDispatcherFactory();
}
static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
/*
* Need to avoid servlet duplication when more than pathinfo is matching a servlet.
* ClassPath -> Servlet.
@ -66,10 +66,11 @@ public class KissDispatcherFactory
*
* @param config
* the config
* @param request
* the request
* @param servletClass
* the servlet class
* @return the http servlet
* @throws ServletException
* the servlet exception
*/
public HttpServlet provideServlet(final ServletConfig config, final Class<HttpServlet> servletClass) throws ServletException
{

View file

@ -44,14 +44,14 @@ import jakarta.servlet.http.HttpServletResponse;
*/
public class KissDispatcherUtils
{
static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
public enum ContentDispositionType
{
ATTACHMENT,
INLINE
}
static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
/**
* Builds the class name.
*
@ -259,8 +259,8 @@ public class KissDispatcherUtils
/**
* Checks if is available path.
*
* @param urlPath
* the url path
* @param path
* the path
* @return true, if is available path
*/
public static boolean isAvailablePath(final String path)
@ -586,6 +586,10 @@ public class KissDispatcherUtils
}
catch (IOException exception)
{
System.out.println("/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\");
exception.printStackTrace();
// TODO As sendError cannot be send because partial content has
// been send, we have to replace this with a better way.
response.sendError(HttpServletResponse.SC_PARTIAL_CONTENT);
}
finally

View file

@ -28,7 +28,6 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.Kiss4webException;
import jakarta.servlet.http.HttpServlet;
/**
@ -79,7 +78,6 @@ public class AnnotationUtils
* Gets the annotation hooks.
*
* @return the annotation hooks
* @throws Kiss4webException
*/
public static AnnotationHooks getAnnotationHooks()
{

View file

@ -23,9 +23,17 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The Interface KissServlet.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface KissServlet
{
/**
* Value of the pathInfo regex to map on the annoted class..
*
* @return the string
*/
String value();
}

View file

@ -27,6 +27,9 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
/**
* The Class KissServletProcessor.
*/
@javax.annotation.processing.SupportedAnnotationTypes("fr.devinsy.kiss4web.dispatcher.annotation.KissServlet")
@javax.annotation.processing.SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_17)
public class KissServletProcessor extends AbstractProcessor
@ -39,7 +42,7 @@ public class KissServletProcessor extends AbstractProcessor
{
super.init(processingEnv);
// Initialization code, if needed
System.out.println("=============== @INIT");
// System.out.println("=============== @INIT");
}
/**

View file

@ -37,10 +37,8 @@ public class DirectHook extends HookCore
/**
* Instantiates a new direct hook.
*
* @param regex
* the regex
* @param targetClassName
* the target class path
* the target class name
*/
public DirectHook(final String targetClassName)
{

View file

@ -32,7 +32,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class StaticPageServlet.
* The Class DirectServlet.
*/
public class DirectServlet extends HttpServlet
{
@ -42,7 +42,10 @@ public class DirectServlet extends HttpServlet
private String path;
/**
* Instantiates a new static page servlet.
* Instantiates a new direct servlet.
*
* @param path
* the path
*/
public DirectServlet(final String path)
{

View file

@ -46,6 +46,9 @@ public class ErrorServlet extends HttpServlet
/**
* Instantiates a new error servlet.
*
* @param message
* the message
*/
public ErrorServlet(final String message)
{
@ -54,6 +57,11 @@ public class ErrorServlet extends HttpServlet
/**
* Instantiates a new error servlet.
*
* @param message
* the message
* @param exception
* the exception
*/
public ErrorServlet(final String message, final Exception exception)
{

View file

@ -23,8 +23,6 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
*/
public abstract class HookCore implements Hook
{
private boolean terminal;
/**
* Instantiates a new hook core.
*/

View file

@ -123,8 +123,8 @@ public class HookRegister
/**
* Register.
*
* @param hook
* the hook
* @param hooks
* the hooks
* @return the hook register
*/
public HookRegister register(final Collection<? extends Hook> hooks)

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2006-2023 Christian Pierre MOMON
* Copyright (C) 2006-2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
@ -106,6 +106,8 @@ public class LongURLRewriter
}
/**
* This methods unrewrite a pathinfo.
*
* /catalog/article-/123/2016/12/14/resume.xhtml -> /catalog/article.xhtml
*
* @param source

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2006-2023 Christian Pierre MOMON
* Copyright (C) 2006-2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
@ -183,6 +183,8 @@ public class ShortURLRewriter
}
/**
* This method unrewrite a pathInfo.
*
* article.xhtm?id=123 -> article.xhtml
*
* @param source

View file

@ -23,7 +23,6 @@ import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.Kiss4webException;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
@ -45,8 +44,6 @@ public class WebContentHook extends HookCore
/**
* {@inheritDoc}
*
* @throws Kiss4webException
*/
@Override
public String getServletClassName(final ServletConfig servletConfig, final HttpServletRequest request)

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
* Copyright (C) 2006-2010, 2013-2014, 2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
@ -22,22 +22,26 @@ import java.util.Iterator;
import java.util.Vector;
/**
*
* The Class Groups.
*/
public class Groups extends Vector<Group>
{
private static final long serialVersionUID = 6238581648850758903L;
/**
*
*/
* Instantiates a new groups.
*/
public Groups()
{
super();
}
/*
/**
* Contains.
*
* @param name
* the name
* @return true, if successful
*/
public boolean contains(final String name)
{
@ -57,8 +61,12 @@ public class Groups extends Vector<Group>
}
/**
*
*/
* Gets the.
*
* @param name
* the name
* @return the group
*/
public Group get(final String name)
{
Group result;
@ -96,8 +104,12 @@ public class Groups extends Vector<Group>
}
/**
*
*/
* Gets the login groups.
*
* @param login
* the login
* @return the login groups
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
@ -120,8 +132,12 @@ public class Groups extends Vector<Group>
}
/**
*
*/
* Gets the login groups string.
*
* @param login
* the login
* @return the login groups string
*/
public String getLoginGroupsString(final String login)
{
String result;
@ -150,8 +166,8 @@ public class Groups extends Vector<Group>
}
/**
*
*/
* {@inheritDoc}
*/
@Override
public String toString()
{
@ -173,5 +189,3 @@ public class Groups extends Vector<Group>
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////