Skip to content

Commit 44596d4

Browse files
committed
Changed the default package to com.samaxes.filter.
Updated the distribution repositories to Sonatype Nexus.
1 parent 2dd0cd0 commit 44596d4

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
lines changed

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
= J2EE Cache Filter =
33
=====================
44

5+
== 1.2 ==
6+
* Changed the default package to com.samaxes.filter.
7+
* Updated the distribution repositories to Sonatype Nexus.
8+
59
== 1.1.0 ==
610
* Use response.setDateHeader() instead of response.setHeader() to set "Expires" HTTP cache header.
711
* Compiled against JDK 1.5 instead of JDK 1.6.

pom.xml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
36
<modelVersion>4.0.0</modelVersion>
47

5-
<groupId>com.samaxes.cachefilter</groupId>
8+
<groupId>com.samaxes.filter</groupId>
69
<artifactId>cachefilter</artifactId>
710
<version>1.2-SNAPSHOT</version>
811
<packaging>jar</packaging>
@@ -11,6 +14,10 @@
1114
<description>J2EE Cache Filter is a Servlet Filter that allows you to set HTTP headers in order to enable browser caching.</description>
1215
<url>http://code.google.com/p/cache-filter/</url>
1316
<inceptionYear>2010</inceptionYear>
17+
<organization>
18+
<name>samaxes</name>
19+
<url>http://www.samaxes.com/</url>
20+
</organization>
1421
<licenses>
1522
<license>
1623
<name>The Apache Software License, Version 2.0</name>
@@ -42,12 +49,16 @@
4249
<url>http://cache-filter.googlecode.com/svn/trunk</url>
4350
</scm>
4451

52+
<prerequisites>
53+
<maven>[2.1.0,)</maven>
54+
</prerequisites>
55+
4556
<build>
4657
<plugins>
4758
<plugin>
4859
<groupId>org.apache.maven.plugins</groupId>
4960
<artifactId>maven-compiler-plugin</artifactId>
50-
<version>2.1</version>
61+
<version>2.3</version>
5162
<configuration>
5263
<source>1.5</source>
5364
<target>1.5</target>
@@ -79,8 +90,8 @@
7990
</plugin>
8091
<plugin>
8192
<groupId>org.apache.maven.plugins</groupId>
82-
<artifactId>maven-release-plugin</artifactId>
83-
<version>2.0-beta-9</version>
93+
<artifactId>maven-gpg-plugin</artifactId>
94+
<version>1.0</version>
8495
</plugin>
8596
</plugins>
8697
</build>

src/main/java/com/samaxes/cachefilter/presentation/CacheFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*
3333
* @author : Samuel Santos
3434
* @version : $Revision: 25 $
35+
* @deprecated Please update to the new {@link com.samaxes.filter.CacheFilter CacheFilter} instead.
3536
*/
3637
public class CacheFilter implements Filter {
3738

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* $Id$
3+
*
4+
* Copyright 2008 samaxes.com
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.samaxes.filter;
19+
20+
import java.io.IOException;
21+
22+
import javax.servlet.Filter;
23+
import javax.servlet.FilterChain;
24+
import javax.servlet.FilterConfig;
25+
import javax.servlet.ServletException;
26+
import javax.servlet.ServletRequest;
27+
import javax.servlet.ServletResponse;
28+
import javax.servlet.http.HttpServletResponse;
29+
30+
/**
31+
* Filter responsible for browser caching.
32+
*
33+
* @author : Samuel Santos
34+
* @version : $Revision: 25 $
35+
*/
36+
public class CacheFilter implements Filter {
37+
38+
private FilterConfig filterConfig;
39+
40+
/**
41+
* Place this filter into service.
42+
*
43+
* @param filterConfig {@link FilterConfig}
44+
*/
45+
public void init(FilterConfig filterConfig) throws ServletException {
46+
this.filterConfig = filterConfig;
47+
}
48+
49+
/**
50+
* Take this filter out of service.
51+
*/
52+
public void destroy() {
53+
this.filterConfig = null;
54+
}
55+
56+
/**
57+
* Sets cache headers directives.
58+
*
59+
* @param servletRequest {@link ServletRequest}
60+
* @param servletResponse {@link ServletResponse}
61+
* @param filterChain {@link FilterChain}
62+
* @throws IOException {@link FilterChain}
63+
* @throws ServletException {@link ServletException}
64+
*/
65+
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
66+
throws IOException, ServletException {
67+
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
68+
String privacy = filterConfig.getInitParameter("privacy");
69+
String expirationTime = filterConfig.getInitParameter("expirationTime");
70+
71+
if (httpServletResponse != null && privacy != null && !"".equals(privacy) && expirationTime != null
72+
&& !"".equals(expirationTime)) {
73+
long seconds = Long.valueOf(expirationTime);
74+
75+
// set the provided HTTP response parameters
76+
httpServletResponse.setHeader("Cache-Control", privacy + ", max-age=" + seconds + ", must-revalidate");
77+
httpServletResponse.setDateHeader("Expires", System.currentTimeMillis() + seconds * 1000L);
78+
}
79+
80+
// pass the request/response on
81+
filterChain.doFilter(servletRequest, servletResponse);
82+
}
83+
}

0 commit comments

Comments
 (0)