Subversion Repository Public Repository

litesoft

Diff Revisions 465 vs 466 for /trunk/Java/VersionedStaticContentFilter/src/org/litesoft/servlet/versionedstaticcontentfilter/VersionedStaticContentFilter.java

Diff revisions: vs.
  @@ -6,6 +6,8 @@
6 6 import javax.servlet.*;
7 7 import javax.servlet.http.*;
8 8
9 + import org.litesoft.servlet.*;
10 +
9 11 /**
10 12 * This is a filter which enforces proper caching of a "LiteSoft Versioned" web app
11 13 * w/ "common" redirection. It requires that you serve your GWT application via a
  @@ -67,29 +69,14 @@
67 69 * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32">Pragma
68 70 * directive</a>
69 71 */
70 - @SuppressWarnings({"UnusedDeclaration"})
71 72 public class VersionedStaticContentFilter implements Filter
72 73 {
73 - private String getLocationAnchor() // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
74 - {
75 - try
76 - {
77 - Class<?> zClass = getClass().getClassLoader().loadClass( "org.litesoft.locationanchor.LocationAnchor" );
78 - return zClass.newInstance().toString();
79 - }
80 - catch ( Exception e )
81 - {
82 - e.printStackTrace();
83 - return null;
84 - }
85 - }
86 -
87 74 @Override
88 75 public void init( FilterConfig filterConfig )
89 76 throws ServletException
90 77 {
91 78 mServletContext = filterConfig.getServletContext();
92 - String zLocationAnchor = getLocationAnchor();
79 + String zLocationAnchorPath = WebInfLocator.getLocationAnchorPath( this );
93 80 String zDevMode = System.getProperty( "DevMode" );
94 81 if ( zDevMode == null )
95 82 {
  @@ -97,19 +84,20 @@
97 84 }
98 85 else
99 86 {
100 - File[] zStaticFileSearchPaths = createStaticFileSearchPaths( zDevMode, zLocationAnchor );
87 + File[] zStaticFileSearchPaths = createStaticFileSearchPaths( zDevMode, zLocationAnchorPath );
101 88 mMode = (zStaticFileSearchPaths == null) ? new DevMode() : new DevModeDirect( zStaticFileSearchPaths );
102 89 }
103 - System.out.println( "VersionedStaticContentFilter.init: " + zLocationAnchor + "\n Mode: " + mMode );
90 + System.out.println( "VersionedStaticContentFilter.init: " + zLocationAnchorPath + "\n Mode: " + mMode );
104 91 }
105 92
106 - private File[] createStaticFileSearchPaths( String pDevMode, String pLocationAnchor )
93 + private File[] createStaticFileSearchPaths( String pDevMode, String pLocationAnchorPath )
107 94 {
108 - File zWarDir = extractWarDir( pLocationAnchor );
109 - if ( zWarDir == null )
95 + File zDir = WebInfLocator.extractDir( pLocationAnchorPath );
96 + if ( zDir == null )
110 97 {
111 98 return null;
112 99 }
100 + File zWarDir = zDir.getParentFile();
113 101 List<File> zStaticFileSearchPaths = new ArrayList<File>();
114 102 zStaticFileSearchPaths.add( zWarDir );
115 103 int from = 0;
  @@ -143,40 +131,6 @@
143 131 }
144 132 }
145 133
146 - private File extractWarDir( String pLocationAnchor ) // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
147 - { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 01234
148 - if ( pLocationAnchor == null || !pLocationAnchor.startsWith( "file:/" ) )
149 - { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0123456
150 - return null;
151 - }
152 - int at = pLocationAnchor.indexOf( "/WEB-INF/" );
153 - if ( at <= 6 )
154 - {
155 - System.out.println( "VersionedStaticContentFilter.extractWarDir: Path appears to be too short!" );
156 - return null;
157 - }
158 - String zWarPath = pLocationAnchor.substring( 5, at );
159 - if ( (zWarPath.length() > 3) && Character.isLetter( zWarPath.charAt( 1 ) ) && ":/".equals( zWarPath.substring( 2, 4 ) ) )
160 - {
161 - zWarPath = zWarPath.substring( 1 );
162 - }
163 - File zWarDir = new File( zWarPath );
164 - if ( !zWarDir.isDirectory() )
165 - {
166 - System.out.println( "VersionedStaticContentFilter.extractWarDir, Not a Directory: " + zWarDir.getPath() );
167 - return null;
168 - }
169 - try
170 - {
171 - return zWarDir.getCanonicalFile();
172 - }
173 - catch ( IOException e )
174 - {
175 - System.out.println( "VersionedStaticContentFilter.extractWarDir, Could not Canonicalize: " + zWarDir.getPath() );
176 - return null;
177 - }
178 - }
179 -
180 134 private interface Mode
181 135 {
182 136 void processGetRequest( String pRequestURI, HttpServletRequest pRequest, HttpServletResponse pResponse, ServletContext pServletContext, FilterChain pChain )