Skip to content

Commit

Permalink
implemented issue #115 - configurable support extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
phaneesh authored and chanwit committed Apr 20, 2010
1 parent a5f1036 commit 2adffe7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
18 changes: 16 additions & 2 deletions ZkGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,21 @@ this plugin adds ZK Ajax framework (www.zkoss.org) support to Grails application
"org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter"

def doWithWebDescriptor = { xml ->
def urls = ["*.zul", "*.zhtml", "*.svg", "*.xml2html"]
//
// e.g. ["zul"]
//
def supportExts = ZkConfigHelper.supportExtensions

//
// e.g. ["*.zul", "/zkau/*"]
//
def filterUrls = supportExts.collect{ "*." + it } + ["/zkau/*"]

//
// e.g. ["*.zul", "*.dsp", "*.zhtml", "*.svg", "*.xml2html"]
//
def urls = supportExts.collect{ "*." + it } +
["*.dsp", "*.zhtml", "*.svg", "*.xml2html"]

// adding GrailsOpenSessionInView
if(manager?.hasGrailsPlugin("hibernate")) {
Expand All @@ -104,7 +118,7 @@ this plugin adds ZK Ajax framework (www.zkoss.org) support to Grails application
}
// filter for each ZK urls
def filterMappingElements = xml.'filter-mapping'[0]
["*.zul", "/zkau/*"].each {p ->
filterUrls.each {p ->
filterMappingElements + {
'filter-mapping' {
'filter-name'("GOSIVFilter")
Expand Down
22 changes: 22 additions & 0 deletions src/groovy/org/zkoss/zkgrails/ZkConfigHelper.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.zkoss.zkgrails

import org.codehaus.groovy.grails.commons.ConfigurationHolder

//
// Helper class to get the Url Mapping in the ZKPageFilter and ZkGrailsPlugin
//
class ZkConfigHelper {

//
// Get the extensions configuration using the ConfigurationHolder
// Return String[]{"zul"} if not configured
//
static ArrayList<String> getSupportExtensions() {
def exts = ConfigurationHolder.config?.grails.zk.extensions
if(exts) {
return exts
} else {
return ["zul"] as String[]
}
}
}
17 changes: 14 additions & 3 deletions src/java/org/zkoss/zkgrails/ZKGrailsPageFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ private String extractRequestPath(HttpServletRequest request) {
}

private boolean isZK(HttpServletRequest request) {
if(path.indexOf("/zkau") != -1) return true;

//
// Extend checking in custom url mapping in custom url mapping
// By default, ["zul"] will be checked here
//
ArrayList<String> arrExtensions = ZkConfigHelper.getSupportExtensions();
for(String sExt : arrExtensions) {
if(path.lastIndexOf("." + sExt) != -1) return true;
}

String path = extractRequestPath(request);
final String[] ext = new String[]{".zul",".dsp","*.zhtml", "*.svg", "*.xml2html"};
final String[] ext = new String[]{".dsp",".zhtml", ".svg", ".xml2html"};
for(int i=0;i < ext.length; i++) {
if(path.lastIndexOf(ext[i])!=-1) return true;
if(path.lastIndexOf(ext[i]) != -1) return true;
}
if(path.indexOf("/zkau")!=-1) return true;

return false;
}

Expand Down

0 comments on commit 2adffe7

Please sign in to comment.