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-By" value="${user.name} using ant" />
<attribute name="Built-Date" value="${dist.time}" /> <attribute name="Built-Date" value="${dist.time}" />
</manifest> </manifest>
<service type="javax.annotation.processing.Processor" provider="fr.devinsy.kiss4web.dispatcher.annotation.KissServletProcessor" />
<fileset dir="${build.classes}" /> <fileset dir="${build.classes}" />
</jar> </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. * This file is part of Kiss4web.
* *
@ -32,14 +32,14 @@ import jakarta.servlet.http.HttpServletResponse;
*/ */
public class CookieHelper public class CookieHelper
{ {
private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class);
public enum Scope public enum Scope
{ {
HTTP_AND_HTTPS, HTTP_AND_HTTPS,
HTTPS_ONLY HTTPS_ONLY
} }
private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class);
/** /**
* Builds the cookie. * Builds the cookie.
* *

View file

@ -23,6 +23,9 @@ import java.util.HashMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class HtmlCache. * The Class HtmlCache.
*/ */
@ -39,11 +42,107 @@ public class HtmlCache extends HashMap<String, String>
super(); 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. * Gets the.
* *
* @param get * @param key
* the get * the key
* @return the string * @return the string
*/ */
public String get(final String key) public String get(final String key)
@ -67,4 +166,35 @@ public class HtmlCache extends HashMap<String, String>
// //
return result; 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 public class Kiss4web
{ {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Kiss4web.class);
/** /**
* The Enum Mode. * The Enum Mode.
*/ */
@ -63,8 +65,6 @@ public class Kiss4web
private static final Kiss4web instance = new 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 BuildInformation buildInformation;
private Mode mode; private Mode mode;
@ -238,6 +238,8 @@ public class Kiss4web
this.mode = mode; this.mode = mode;
} }
break; 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. * This file is part of Kiss4web.
* *
@ -28,6 +28,8 @@ import jakarta.servlet.http.HttpServletResponse;
*/ */
public class Redirector public class Redirector
{ {
private static final Logger logger = LoggerFactory.getLogger(Redirector.class);
public enum Type public enum Type
{ {
MOVED_PERMANENTLY(HttpServletResponse.SC_MOVED_PERMANENTLY), MOVED_PERMANENTLY(HttpServletResponse.SC_MOVED_PERMANENTLY),
@ -56,8 +58,6 @@ public class Redirector
} }
} }
private static final Logger logger = LoggerFactory.getLogger(Redirector.class);
/** /**
* Redirect. * Redirect.
* *

View file

@ -36,8 +36,10 @@ import jakarta.servlet.http.HttpServletRequest;
* The Class KissDispatcher. * The Class KissDispatcher.
* *
* According that URL is under UTF-8 format. Set Tomcat connector if needs * 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 public class KissDispatcher
{ {

View file

@ -31,13 +31,13 @@ import jakarta.servlet.http.HttpServlet;
*/ */
public class KissDispatcherFactory public class KissDispatcherFactory
{ {
static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
private static class SingletonHolder private static class SingletonHolder
{ {
private static final KissDispatcherFactory instance = new KissDispatcherFactory(); 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. * Need to avoid servlet duplication when more than pathinfo is matching a servlet.
* ClassPath -> Servlet. * ClassPath -> Servlet.
@ -66,10 +66,11 @@ public class KissDispatcherFactory
* *
* @param config * @param config
* the config * the config
* @param request * @param servletClass
* the request * the servlet class
* @return the http servlet * @return the http servlet
* @throws ServletException * @throws ServletException
* the servlet exception
*/ */
public HttpServlet provideServlet(final ServletConfig config, final Class<HttpServlet> servletClass) throws ServletException 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 public class KissDispatcherUtils
{ {
static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
public enum ContentDispositionType public enum ContentDispositionType
{ {
ATTACHMENT, ATTACHMENT,
INLINE INLINE
} }
static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
/** /**
* Builds the class name. * Builds the class name.
* *
@ -259,8 +259,8 @@ public class KissDispatcherUtils
/** /**
* Checks if is available path. * Checks if is available path.
* *
* @param urlPath * @param path
* the url path * the path
* @return true, if is available path * @return true, if is available path
*/ */
public static boolean isAvailablePath(final String path) public static boolean isAvailablePath(final String path)
@ -586,6 +586,10 @@ public class KissDispatcherUtils
} }
catch (IOException exception) 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); response.sendError(HttpServletResponse.SC_PARTIAL_CONTENT);
} }
finally finally

View file

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

View file

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

View file

@ -27,6 +27,9 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
/**
* The Class KissServletProcessor.
*/
@javax.annotation.processing.SupportedAnnotationTypes("fr.devinsy.kiss4web.dispatcher.annotation.KissServlet") @javax.annotation.processing.SupportedAnnotationTypes("fr.devinsy.kiss4web.dispatcher.annotation.KissServlet")
@javax.annotation.processing.SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_17) @javax.annotation.processing.SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_17)
public class KissServletProcessor extends AbstractProcessor public class KissServletProcessor extends AbstractProcessor
@ -39,7 +42,7 @@ public class KissServletProcessor extends AbstractProcessor
{ {
super.init(processingEnv); super.init(processingEnv);
// Initialization code, if needed // 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. * Instantiates a new direct hook.
* *
* @param regex
* the regex
* @param targetClassName * @param targetClassName
* the target class path * the target class name
*/ */
public DirectHook(final String targetClassName) public DirectHook(final String targetClassName)
{ {

View file

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

View file

@ -46,6 +46,9 @@ public class ErrorServlet extends HttpServlet
/** /**
* Instantiates a new error servlet. * Instantiates a new error servlet.
*
* @param message
* the message
*/ */
public ErrorServlet(final String message) public ErrorServlet(final String message)
{ {
@ -54,6 +57,11 @@ public class ErrorServlet extends HttpServlet
/** /**
* Instantiates a new error servlet. * Instantiates a new error servlet.
*
* @param message
* the message
* @param exception
* the exception
*/ */
public ErrorServlet(final String message, final Exception 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 public abstract class HookCore implements Hook
{ {
private boolean terminal;
/** /**
* Instantiates a new hook core. * Instantiates a new hook core.
*/ */

View file

@ -123,8 +123,8 @@ public class HookRegister
/** /**
* Register. * Register.
* *
* @param hook * @param hooks
* the hook * the hooks
* @return the hook register * @return the hook register
*/ */
public HookRegister register(final Collection<? extends Hook> hooks) 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. * 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 * /catalog/article-/123/2016/12/14/resume.xhtml -> /catalog/article.xhtml
* *
* @param source * @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. * This file is part of Kiss4web.
* *
@ -183,6 +183,8 @@ public class ShortURLRewriter
} }
/** /**
* This method unrewrite a pathInfo.
*
* article.xhtm?id=123 -> article.xhtml * article.xhtm?id=123 -> article.xhtml
* *
* @param source * @param source

View file

@ -23,7 +23,6 @@ import java.io.File;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.Kiss4webException;
import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -45,8 +44,6 @@ public class WebContentHook extends HookCore
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @throws Kiss4webException
*/ */
@Override @Override
public String getServletClassName(final ServletConfig servletConfig, final HttpServletRequest request) 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. * This file is part of Kiss4web.
* *
@ -22,22 +22,26 @@ import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
/** /**
* * The Class Groups.
*/ */
public class Groups extends Vector<Group> public class Groups extends Vector<Group>
{ {
private static final long serialVersionUID = 6238581648850758903L; private static final long serialVersionUID = 6238581648850758903L;
/** /**
* * Instantiates a new groups.
*/ */
public Groups() public Groups()
{ {
super(); super();
} }
/* /**
* Contains.
* *
* @param name
* the name
* @return true, if successful
*/ */
public boolean contains(final String name) 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) public Group get(final String name)
{ {
Group result; 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) public Vector<String> getLoginGroups(final String login)
{ {
Vector<String> result; 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) public String getLoginGroupsString(final String login)
{ {
String result; String result;
@ -150,8 +166,8 @@ public class Groups extends Vector<Group>
} }
/** /**
* * {@inheritDoc}
*/ */
@Override @Override
public String toString() public String toString()
{ {
@ -173,5 +189,3 @@ public class Groups extends Vector<Group>
return (result); return (result);
} }
} }
// ////////////////////////////////////////////////////////////////////////