Skip to content

Commit 37d3e5b

Browse files
committed
Support for relative URIs on JBoss. Fixes #9821
1 parent 82b711d commit 37d3e5b

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/GroovyPagesGrailsPlugin.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class GroovyPagesGrailsPlugin extends Plugin {
267267
if (enableReload) {
268268
cacheTimeout = gspCacheTimeout
269269
}
270+
else {
271+
cache = true
272+
}
270273
}
271274
// Configure a Spring MVC view resolver
272275
jspViewResolver(GroovyPageViewResolver) { bean ->

grails-web-common/src/main/groovy/org/grails/web/pages/GroovyPagesUriSupport.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class GroovyPagesUriSupport implements GroovyPagesUriService, org.codehau
3838
private static final String BLANK = "";
3939
private static final String UNDERSCORE = "_";
4040
protected static final String EXTENSION = ".gsp";
41-
protected static final String SUFFIX = ".gsp";
41+
protected static final String SUFFIX = ".gsp";
42+
public static final String RELATIVE_STRING = "../";
4243

4344
/**
4445
* Obtains a template URI for the given controller instance and template name
@@ -117,6 +118,9 @@ public String getTemplateURI(String controllerName, String templateName, boolean
117118
if (templateName.startsWith(SLASH_STR)) {
118119
return getAbsoluteTemplateURI(templateName, includeExtension);
119120
}
121+
else if(templateName.startsWith(RELATIVE_STRING)) {
122+
return getRelativeTemplateURIInternal(templateName, includeExtension);
123+
}
120124

121125
FastStringWriter buf = new FastStringWriter();
122126
String pathToTemplate = BLANK;
@@ -143,7 +147,6 @@ public String getTemplateURI(String controllerName, String templateName, boolean
143147
}
144148
}
145149

146-
147150
/**
148151
* Used to resolve template names that are not relative to a controller.
149152
*
@@ -173,6 +176,7 @@ public String getAbsoluteTemplateURI(String templateName, boolean includeExtensi
173176
return uri;
174177
}
175178

179+
176180
/**
177181
* Obtains a view URI of the given controller name and view name
178182
* @param controllerName The name of the controller
@@ -230,9 +234,12 @@ public String getDeployedAbsoluteViewURI(String viewName) {
230234
}
231235

232236
private String getViewURIInternal(String viewPathPrefix, String viewName, FastStringWriter buf, boolean includeSuffix) {
233-
if (viewName != null && viewName.startsWith(SLASH_STR)) {
237+
if (viewName != null && (viewName.startsWith(SLASH_STR) )) {
234238
return getAbsoluteViewURIInternal(viewName, buf, includeSuffix);
235239
}
240+
else if(viewName.startsWith(RELATIVE_STRING)) {
241+
return getRelativeViewURIInternal(viewName, buf, includeSuffix);
242+
}
236243

237244
if (viewPathPrefix != null) {
238245
buf.append(SLASH).append(viewPathPrefix);
@@ -244,6 +251,15 @@ private String getViewURIInternal(String viewPathPrefix, String viewName, FastSt
244251
return includeSuffix ? buf.append(SUFFIX).toString() : buf.toString();
245252
}
246253

254+
private String getRelativeViewURIInternal(String viewName, FastStringWriter buf, boolean includeSuffix) {
255+
String tmp = viewName.substring(RELATIVE_STRING.length() - 1, viewName.length());
256+
buf.append(tmp);
257+
if(includeSuffix) {
258+
buf.append(SUFFIX);
259+
}
260+
return buf.toString();
261+
}
262+
247263
private String getAbsoluteViewURIInternal(String viewName, FastStringWriter buf, boolean includeSuffix) {
248264
String tmp = viewName.substring(1,viewName.length());
249265
if (tmp.indexOf(SLASH) > -1) {
@@ -257,7 +273,18 @@ private String getAbsoluteViewURIInternal(String viewName, FastStringWriter buf,
257273
buf.append(viewName.substring(1,viewName.length()));
258274
}
259275
if (includeSuffix) {
260-
buf.append(SUFFIX).toString();
276+
buf.append(SUFFIX);
277+
}
278+
return buf.toString();
279+
}
280+
281+
private String getRelativeTemplateURIInternal(String templateName, boolean includeSuffix) {
282+
String tmp = templateName.substring(RELATIVE_STRING.length() , templateName.length());
283+
FastStringWriter buf = new FastStringWriter();
284+
buf.append("/_");
285+
buf.append(tmp);
286+
if(includeSuffix) {
287+
buf.append(SUFFIX);
261288
}
262289
return buf.toString();
263290
}

grails-web-common/src/test/groovy/org/grails/web/pages/GroovyPagesUriSupportTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public void testNoSuffxGetViewURI() {
4848
public void testGetTemplateURI() {
4949
GroovyPagesUriSupport uriSupport = new GroovyPagesUriSupport();
5050
assertEquals("/foo/_bar.gsp", uriSupport.getTemplateURI("foo", "bar"));
51+
assertEquals("/_bar.gsp", uriSupport.getTemplateURI("foo", "../bar"));
5152
assertEquals("/bar/_foo.gsp", uriSupport.getTemplateURI("foo", "/bar/foo"));
5253
assertEquals("/foo/bar/_foo.gsp", uriSupport.getTemplateURI("foo", "bar/foo"));
5354
}
@@ -64,6 +65,7 @@ public void testGetViewURIForController() throws IllegalAccessException, Instant
6465
GroovyObject controller = (GroovyObject) new GroovyClassLoader().parseClass("class FooController { }").newInstance();
6566
GroovyPagesUriSupport uriSupport = new GroovyPagesUriSupport();
6667
assertEquals("/foo/bar.gsp", uriSupport.getViewURI(controller, "bar"));
68+
assertEquals("/bar.gsp", uriSupport.getViewURI(controller, "../bar"));
6769
assertEquals("/bar/foo.gsp", uriSupport.getViewURI(controller, "/bar/foo"));
6870
assertEquals("/foo/bar/foo.gsp", uriSupport.getViewURI(controller, "bar/foo"));
6971
}

0 commit comments

Comments
 (0)