Skip to content

Commit 5524e20

Browse files
committed
Improved caching of the current UrlMapping in the PrettyContext - thanks to fcaputo for the patch
1 parent b0c5edd commit 5524e20

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎core/src/main/java/com/ocpsoft/pretty/PrettyContext.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ public UrlMapping getCurrentMapping()
257257
return currentMapping;
258258
}
259259

260+
/**
261+
* Called once from PrettyFilter to initialize the currentMapping property.
262+
* This leads to better performance because the filter already knows the mapping
263+
* and we won't have to do the mapping identification again in the getter for
264+
* the property.
265+
*/
266+
void setCurrentMapping(UrlMapping mapping)
267+
{
268+
currentMapping = mapping;
269+
}
270+
260271
/**
261272
* Return the current viewId to which the current request will be forwarded
262273
* to JSF.

‎core/src/main/java/com/ocpsoft/pretty/PrettyFilter.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.servlet.http.HttpServletRequest;
3131
import javax.servlet.http.HttpServletResponse;
3232

33+
import com.ocpsoft.pretty.faces.config.mapping.UrlMapping;
3334
import org.apache.commons.logging.Log;
3435
import org.apache.commons.logging.LogFactory;
3536

@@ -90,8 +91,10 @@ public void doFilter(final ServletRequest req, final ServletResponse resp, final
9091
else
9192
{
9293
URL url = context.getRequestURL();
93-
if (getConfig().isURLMapped(url))
94+
UrlMapping mapping = getConfig().getMappingForUrl(url);
95+
if (mapping != null)
9496
{
97+
context.setCurrentMapping(mapping);
9598
PrettyContext.setCurrentContext(request, context); // set
9699

97100
String viewId = context.getCurrentViewId();

‎core/src/main/java/com/ocpsoft/pretty/faces/beans/ParameterInjector.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void injectParameters(final FacesContext context)
4747
log.trace("Injecting parameters");
4848
PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
4949
URL url = prettyContext.getRequestURL();
50-
UrlMapping mapping = prettyContext.getConfig().getMappingForUrl(url);
50+
UrlMapping mapping = prettyContext.getCurrentMapping();
5151

5252
if (mapping != null)
5353
{

‎core/src/main/java/com/ocpsoft/pretty/faces/beans/ParameterValidator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void validateParameters(final FacesContext context)
5353
log.trace("Validating parameters.");
5454
PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
5555
URL url = prettyContext.getRequestURL();
56-
UrlMapping mapping = prettyContext.getConfig().getMappingForUrl(url);
56+
UrlMapping mapping = prettyContext.getCurrentMapping();
5757

5858
if (mapping != null)
5959
{

0 commit comments

Comments
 (0)