
nz.net.osnz.lmz.stencil.NamedStencil.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lmz-stencil Show documentation
Show all versions of lmz-stencil Show documentation
OSNZ LMZ Stencil dependency
package nz.net.osnz.lmz.stencil
import nz.ac.auckland.stencil.Stencil
import nz.ac.auckland.stencil.StencilService
import javax.inject.Inject
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
/**
* @author Kefeng Deng ([email protected])
*/
public abstract class NamedStencil implements Stencil {
public static final STENCIL_LOCATION = '/WEB-INF/stencils/'
public static final NAME_STENCIL = 'Stencil'
public static final NAME_PAGE = 'Page'
@Inject
StencilService pageService
String defaultView
public NamedStencil() {
StringBuilder sb = new StringBuilder()
String clazzName = this.getClass().simpleName
if (clazzName.endsWith(NAME_STENCIL)) {
clazzName = clazzName.substring(0, clazzName.length() - NAME_STENCIL.length())
} else if (clazzName.endsWith(NAME_PAGE)) {
clazzName = clazzName.substring(0, clazzName.length() - NAME_PAGE.length())
}
for (Character c : clazzName.chars) {
if (c.isUpperCase()) {
if (sb.size() > 0) {
sb.append('_')
}
sb.append(c.toLowerCase())
} else {
sb.append(c)
}
}
defaultView = getPrefixStencilLocation(sb.toString())
}
protected String getPrefixStencilLocation(String currentName) {
return STENCIL_LOCATION + currentName + ".jsp"
}
@Override
void render(HttpServletRequest request, HttpServletResponse response, Map pathParameters) {
Map model = render(request, pathParameters)
pageService.renderJsp(request, response, defaultView, model)
}
public abstract Map render(HttpServletRequest request, Map pathParameters)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy