Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for GRAILS-4842

  • Loading branch information...
commit de32bafe76b2d7b6f9919efe861222ee61ad58f1 1 parent 98ebbcb
@graemerocher graemerocher authored
View
3  grails/src/java/org/codehaus/groovy/grails/web/mapping/RegexUrlMapping.java
@@ -71,6 +71,7 @@
private static final String CAPTURED_DOUBLE_WILDCARD = "(**)";
private static final Log LOG = LogFactory.getLog(RegexUrlMapping.class);
+ private static final Pattern DOUBLE_WILDCARD_PATTERN = Pattern.compile("\\(\\*\\*?\\)");
/**
@@ -197,7 +198,7 @@ private String createURLInternal(Map parameterValues, String encoding, boolean i
StringBuilder uri = new StringBuilder(contextPath);
Set usedParams = new HashSet();
- Pattern p = Pattern.compile("\\(\\*\\*?\\)");
+ Pattern p = DOUBLE_WILDCARD_PATTERN;
String[] tokens = urlData.getTokens();
int paramIndex = 0;
View
36 grails/src/java/org/codehaus/groovy/grails/web/pages/GroovyPageWritable.java
@@ -20,7 +20,9 @@
import groovy.lang.Writable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codehaus.groovy.grails.commons.DomainClassArtefactHandler;
import org.codehaus.groovy.grails.commons.GrailsApplication;
+import org.codehaus.groovy.grails.commons.GrailsClass;
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes;
import org.codehaus.groovy.grails.web.servlet.WrappedResponseHolder;
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
@@ -32,9 +34,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
/**
* An instance of groovy.lang.Writable that writes itself to the specified
@@ -265,11 +265,12 @@ protected void formulateBinding(HttpServletRequest request, HttpServletResponse
protected void populateViewModel(HttpServletRequest request, Binding binding) {
// Go through request attributes and add them to the binding as the model
+ final Map variables = binding.getVariables();
for (Enumeration attributeEnum = request.getAttributeNames(); attributeEnum.hasMoreElements();) {
String key = (String) attributeEnum.nextElement();
if(!GroovyPage.isReservedName(key)) {
- if(!binding.getVariables().containsKey(key)) {
+ if(!variables.containsKey(key)) {
binding.setVariable( key, request.getAttribute(key) );
}
}
@@ -291,7 +292,7 @@ protected void populateViewModel(HttpServletRequest request, Binding binding) {
private void formulateBindingFromWebRequest(Binding binding, HttpServletRequest request, HttpServletResponse response, Writer out, GroovyObject controller) {
// if there is no controller in the request configure using existing attributes, creating objects where necessary
- GrailsWebRequest webRequest = (GrailsWebRequest)request.getAttribute(GrailsApplicationAttributes.WEB_REQUEST);
+ GrailsWebRequest webRequest = GrailsWebRequest.lookup(request);
binding.setVariable(GroovyPage.WEB_REQUEST, webRequest);
binding.setVariable(GroovyPage.REQUEST, request);
binding.setVariable(GroovyPage.RESPONSE, response);
@@ -300,8 +301,13 @@ private void formulateBindingFromWebRequest(Binding binding, HttpServletRequest
ApplicationContext appCtx = webRequest.getAttributes().getApplicationContext();
binding.setVariable(GroovyPage.APPLICATION_CONTEXT, appCtx);
- if(appCtx!=null)
- binding.setVariable(GrailsApplication.APPLICATION_ID, webRequest.getAttributes().getGrailsApplication());
+ if(appCtx!=null) {
+ GrailsApplication app = appCtx.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
+ binding.setVariable(GrailsApplication.APPLICATION_ID, app);
+ Map<String,Class> domainClassesWithoutPackage = getDomainClassMap(app);
+ final Map variables = binding.getVariables();
+ variables.putAll(domainClassesWithoutPackage);
+ }
binding.setVariable(GroovyPage.SESSION, webRequest.getSession());
binding.setVariable(GroovyPage.PARAMS, webRequest.getParams());
binding.setVariable(GroovyPage.ACTION_NAME, webRequest.getActionName());
@@ -309,9 +315,25 @@ private void formulateBindingFromWebRequest(Binding binding, HttpServletRequest
if(controller!= null) {
binding.setVariable(GrailsApplicationAttributes.CONTROLLER, controller);
binding.setVariable(GroovyPage.PLUGIN_CONTEXT_PATH, controller.getProperty(GroovyPage.PLUGIN_CONTEXT_PATH));
+
}
binding.setVariable(GroovyPage.OUT, out);
}
+ private static Map<String,Class> domainsWithoutPackage = new HashMap<String,Class>();
+ private static Map<String,Class> getDomainClassMap(GrailsApplication application) {
+ GrailsClass[] domainClasses = application.getArtefacts(DomainClassArtefactHandler.TYPE);
+ if(domainClasses.length==domainsWithoutPackage.size()) return domainsWithoutPackage;
+ else {
+ domainsWithoutPackage.clear();
+ for (GrailsClass domainClass : domainClasses) {
+ final Class theClass = domainClass.getClazz();
+ domainsWithoutPackage.put(theClass.getName(),theClass);
+ }
+ return domainsWithoutPackage;
+ }
+
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.