i just experienced the same HTML extension problem in Dojo setup.

no doubt, I do agree that .html is a pretty good abstraction to underly
implementation.

however, can we add a filter by default to bypass all static html pages ?
that is pretty essential, I believe.

~thinkboy.



Rene Lavoie wrote:
> 
> About the DOJO problem,
> 
> I had this issue when I tried using DOJO in my JSF/Appfuse app and the
> work 
> around I used was  to write a filter that intercepted request for 
> /script/dojo/* path and serve the files with the filter if the extension
> was 
> *.html.
> 
> I prefered this approach to changing the file extension, since *.html is a 
> customer requirement.
> 
> I was using DOJO mainly for the HTML editor and ended up using TinyMCE, so
> I 
> aint using the filter anymore, but here is the code I had written.
> Note, that this code was not properly tested and use at your own risk.
> ----------------------------------------------------------------------------------------------
> public class HtmlFilter implements Filter {
>  private static Log log = LogFactory.getLog(HtmlFilter.class);
> 
>  private final static String SUFFIX = ".html";
> 
>  private FilterConfig filterConfig = null;
> 
>  public void destroy() {
>   //
> 
>  }
> 
>  public void doFilter(ServletRequest request, ServletResponse response,
>    FilterChain chain) throws IOException, ServletException {
> 
>   final HttpServletRequest req = (HttpServletRequest) request;
>   final HttpServletResponse res = (HttpServletResponse) response;
> 
>   String partialPath = getPartialPath(req);
> 
>   if (log.isDebugEnabled()) {
>    log.debug("HtmlFilter doFilter");
>   }
>   // If the file file does not end with html, use regular fitler flow.
>   if (!partialPath.endsWith(SUFFIX)) {
>    if (log.isDebugEnabled()) {
>     log.debug("HtmlFilter doFilter: file is not html, chaining");
>    }
>    chain.doFilter(request, response);
>    return;
>   } else if (filterConfig != null) {
>    String fullPath = filterConfig.getServletContext().getRealPath(
>      partialPath);
>    if (log.isDebugEnabled()) {
>     log.debug("HtmlFilter doFilter: filePath: " + fullPath);
>    }
> 
>    File file = new File(fullPath);
>    if (!file.exists()) {
>     if (log.isDebugEnabled()) {
>      log.debug("HtmlFilter doFilter: file not found ");
>     }
>     res.sendError(404);
>     return;
>    }
>    URLConnection urlc = file.toURL().openConnection();
> 
>    setContentType(res, urlc);
> 
>    serveFile(res, file);
> 
>    return;
>   }
>   throw new ServletException(
>     "something went wrong: filterConfig is null?"
>       + (filterConfig == null) + " filename.toString():");
>   //
> 
>  }
> 
>  /**
>   * @param res
>   * @param file
>   * @throws IOException
>   * @throws MalformedURLException
>   */
>  private void serveFile(final HttpServletResponse res, File file) throws 
> IOException, MalformedURLException {
>   InputStream is = file.toURL().openConnection().getInputStream();
>   OutputStream o = res.getOutputStream();
>   byte[] buf = new byte[32 * 1024]; // 32k buffer
>   int nRead = 0;
>   while ((nRead = is.read(buf)) != -1) {
>    o.write(buf, 0, nRead);
>   }
>   o.flush();
>   o.close();
>  }
> 
>  /**
>   * @param res
>   * @param urlc
>   */
>  private void setContentType(final HttpServletResponse res, URLConnection 
> urlc) {
>   String contentType = urlc.getContentType();
> 
>   if (contentType == null) {
>    // aassume html, since this is what we are serving
>    contentType = "text/html";
>   }
>   res.setContentType(contentType);
>  }
> 
>  /**
>   * @param req
>   */
>  private String getPartialPath(final HttpServletRequest req) {
>   StringBuffer url = req.getRequestURL();
>   String contextPath = req.getContextPath();
>   String partialPath = "";
>   String[] requestFile = url.toString().split(contextPath);
>   if (requestFile.length > 0) {
>    partialPath = requestFile[1];
>   }
>   return partialPath;
>  }
> 
>  /**
>   */
>  public void init(FilterConfig filterConfig) {
>   this.filterConfig = filterConfig;
>  }
> 
> }
> ----------------------------------------------------------------
> 
> web.xml
> <filter>
> 
> <filter-name>htmlFilter</filter-name>
> 
> <filter-class>com.myapp.webapp.filter.HtmlFilter</filter-class>
> 
> </filter>
> 
> <filter-mapping>
> 
> <filter-name>htmlFilter</filter-name>
> 
> <url-pattern>/scripts/dojo/*</url-pattern>
> 
> </filter-mapping>
> 
> 
> 
> 
> ----- Original Message ----- 
> From: "Matt Raible" <[EMAIL PROTECTED]>
> To: "AppFuse" <[email protected]>
> Sent: Wednesday, September 20, 2006 4:10 PM
> Subject: [appfuse-user] Changing default extension from *.html to *.??
> 
> 
>> Dear AppFuse users,
>>
>> As many of you likely know, there are a couple of issues with using
>> the *.html extension with some frameworks in AppFuse.  For example,
>> with WebWork - it loads Dojo template files from a *.html extension.
>> If you want to use Dojo with WebWork, you have to modify your default
>> extension.
>>
>> http://issues.appfuse.org/browse/APF-431
>>
>> Because of this, we're starting to look at other extensions.  I'd
>> rather use one for all frameworks, rather than the recommended ones
>> for each framework b/c it allows us to have one security.xml files,
>> rather than one for each framework.  Another option is to use
>> path-based mapping, for example:
>>
>> http://localhost:8080/yourapp/go/users
>>
>> Where "/go/*" is the path that front-controller servlet/filters are
>> mapped to.  The only problem with this is stat trackers typically like
>> to track extensions, and so we'd be unfriendly to those companies who
>> like to watch their stats.
>>
>> Here's a couple thoughts - feel free to add your own suggestions and 
>> thoughts:
>>
>> 1. *.htm
>> 2. *.aspx
>> 3. *.php
>> 4. *.app
>> 5. *.a
>> 6. *.o
>> 7. *.apf (would help us track AppFuse-based applications, but it's a
>> pretty ugly extension)
>> 8. *.em
>> 9. *.fun
>> 10. *.page
>>
>> I still like *.html the best b/c it doesn't give away the underlying
>> technology, so *.htm seems like the best option after that.  But of
>> course, I'm open to suggestions. ;-)
>>
>> Matt
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Changing-default-extension-from-*.html-to-*.---tf2307780s2369.html#a8384015
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to