So now I created a servlet filter that listens for request for the
offline manifest. Not perfect, but working.
Upon requesting the offline manifest, the filter redirects to the
version applicable for the current user-agent.

Problem is, that as soon as there is no network connection, the
offline mode does not work...

Do I have to rename the returned offline manifest to match the name
described in the HTML file? (appcache.nocache.manifest)
Because now I return appcache.nocache.manifest.gecko1_8 for example...
If it needs to be renamed how can this rename be achived with a
servlet filter?
Right now the only technique I am aware of is to send a redirect...

Thanks for your help!
Stefan


Here is the filter code....

package com.siemens.html5.whiteboard.server.filters;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class OfflineManifestFilter implements Filter {

        public static final HashMap<String, String> offlineManifestMap = new
HashMap<String, String>(6);

        static {
                offlineManifestMap.put("Chrome",
"appcache.nocache.manifest.gecko1_8");
                offlineManifestMap.put("Firefox",
"appcache.nocache.manifest.gecko1_8");
                offlineManifestMap.put("Safari",
"appcache.nocache.manifest.safari");
                offlineManifestMap.put("Opera", 
"appcache.nocache.manifest.opera");
                offlineManifestMap.put("MSIE8", 
"appcache.nocache.manifest.ie8");
                offlineManifestMap.put("MSIE7", 
"appcache.nocache.manifest.ie7");
                offlineManifestMap.put("MSIE6", 
"appcache.nocache.manifest.ie6");
        }

        public static final String OFFLINE_MANIFEST =
"appcache.nocache.manifest";

        @Override
        public void destroy() {
                // TODO Auto-generated method stub

        }

        @Override
        public void doFilter(ServletRequest req, ServletResponse res,
                        FilterChain fc) throws IOException, ServletException {

                HttpServletRequest httpRequest = (HttpServletRequest)req;

                if (httpRequest.getRequestURI().contains(OFFLINE_MANIFEST)) {

                        String userAgent = ((HttpServletRequest) 
req).getHeader("User-
Agent");
                        System.out.println("User-Agent: " +userAgent);

                        for (String browser : offlineManifestMap.keySet()) {
                                if (userAgent.contains(browser)) {
                                        System.out.println("Sending redirect 
to; "
+httpRequest.getRequestURI().replace(OFFLINE_MANIFEST,
offlineManifestMap.get(browser)));
        
((HttpServletResponse)res).sendRedirect(httpRequest.getRequestURI().replace(OFFLINE_MANIFEST,
offlineManifestMap.get(browser)));
                                }
                        }

                }

                fc.doFilter(req, res);

        }

        @Override
        public void init(FilterConfig cfg) throws ServletException {
                // TODO Auto-generated method stub

        }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to