diff --git a/grailszk-common/src/main/java/org/zkoss/web/util/resource/GrailsContentLoader.java b/grailszk-common/src/main/java/org/zkoss/web/util/resource/GrailsContentLoader.java index 2f6d977..679d343 100644 --- a/grailszk-common/src/main/java/org/zkoss/web/util/resource/GrailsContentLoader.java +++ b/grailszk-common/src/main/java/org/zkoss/web/util/resource/GrailsContentLoader.java @@ -1,6 +1,8 @@ package org.zkoss.web.util.resource; +import grails.config.Config; import grails.core.GrailsApplication; +import grails.util.Holders; import groovy.lang.Writable; import groovy.text.Template; import org.apache.commons.logging.Log; @@ -20,6 +22,7 @@ import java.io.*; import java.net.URL; +import java.nio.file.Files; import java.util.Map; @SuppressWarnings("deprecation") @@ -112,8 +115,8 @@ private StringReader preprocessGSP(final Map config, final long length, fi private PageDefinition parse(final String path, final org.springframework.core.io.Resource resource, final Object extra) throws Throwable { - final Map config = grailsApplication.getConfig().flatten(); - final Boolean disable = (Boolean)config.get(CONFIG_ZKGRAILS_TAGLIB_DISABLE); + final Config config = grailsApplication.getConfig(); + final Boolean disable = config.getProperty(CONFIG_ZKGRAILS_TAGLIB_DISABLE, Boolean.class); final Locator locator = (Locator)((extra != null) ? extra : PageDefinitions.getLocator(webApp, path)); if (disable != null && disable) { return new Parser(webApp, locator).parse(new InputStreamReader(resource.getInputStream()), path); @@ -133,13 +136,14 @@ protected PageDefinition parse(final String path, final URL url, final Object ex @Override protected PageDefinition parse(final String path, final File file, final Object extra) throws Exception { final GrailsApplication grailsApplication = (GrailsApplication) appCtx.getBean("grailsApplication"); - final Map config = grailsApplication.getConfig().flatten(); - final Boolean disable = (Boolean) config.get(CONFIG_ZKGRAILS_TAGLIB_DISABLE); + final Config config = grailsApplication.getConfig(); + final Boolean disable = config.getProperty(CONFIG_ZKGRAILS_TAGLIB_DISABLE, Boolean.class); + final Locator locator = (Locator)((extra != null) ? extra : PageDefinitions.getLocator(webApp, path)); if (disable != null && disable) { return new Parser(webApp, locator).parse(file, path); } - final StringReader reader = preprocessGSP(config, file.length(), new FileInputStream(file)); + final StringReader reader = preprocessGSP(config, file.length(), Files.newInputStream(file.toPath())); final PageDefinition pgdef = new Parser(webApp, locator).parse(reader, Servlets.getExtension(path)); pgdef.setRequestPath(path); return pgdef; diff --git a/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZKGrailsPageFilter.java b/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZKGrailsPageFilter.java index 8c4f548..dc26441 100644 --- a/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZKGrailsPageFilter.java +++ b/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZKGrailsPageFilter.java @@ -94,12 +94,7 @@ public void init(FilterConfig fc) { layoutViewResolver = WebUtils.lookupViewResolver(applicationContext); final GrailsApplication grailsApplication = GrailsWebUtil.lookupApplication(fc.getServletContext()); - - // TODO: Verify the line below. In war files it returns NavigableMapConfig - Object encoding = Holders.getFlatConfig().get(CONFIG_OPTION_GSP_ENCODING); - if (encoding instanceof String) { - defaultEncoding = (String) encoding; - } + defaultEncoding = grailsApplication.getConfig().getProperty(CONFIG_OPTION_GSP_ENCODING, defaultEncoding); Map interceptors = applicationContext.getBeansOfType(PersistenceContextInterceptor.class); if (!interceptors.isEmpty()) { @@ -190,8 +185,7 @@ public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain) if (content == null || response.isCommitted()) { return; } - Content content2 = applyLive(request, content); - new GrailsNoDecorator().render(content2, webAppContext); + new GrailsNoDecorator().render(content, webAppContext); return; } @@ -220,7 +214,6 @@ public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain) if (content == null || response.isCommitted()) { return; } - // applyLive(request, content); detectContentTypeFromPage(content, response); new GrailsNoDecorator().render(content, webAppContext); dispatched = true; @@ -244,69 +237,6 @@ public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain) } } - private Content applyLive(HttpServletRequest request, Content content) throws IOException { - if(Environment.getCurrent() == Environment.DEVELOPMENT) { - // if ZK Grails in the Dev mode - // insert z-it-live.js - if(content instanceof GSPSitemeshPage) { - GSPSitemeshPage page = (GSPSitemeshPage)content; - String pageContent = page.getPage(); - if(pageContent == null) { - return content; - } - String contextPath = request.getContextPath(); - // - // src="/zello/zkau/ - if(pageContent.indexOf("src=\""+ contextPath + "/zkau/") > 0) { - StreamCharBuffer buffer = new StreamCharBuffer(); - LinkGenerator grailsLinkGenerator = (LinkGenerator) applicationContext.getBean("grailsLinkGenerator"); - String link = grailsLinkGenerator.resource(new HashMap(){{ - put("dir","ext/js"); - put("file","z-it-live.js"); - }}); - buffer.getWriter().write( - pageContent.replace("", - "\n") - ); - page.setPageBuffer(buffer); - } - return content; - } else if(content instanceof HTMLPage2Content) { - HTMLPage2Content page2Content = (HTMLPage2Content)content; - try { - Field fPage = HTMLPage2Content.class.getDeclaredField("page"); - fPage.setAccessible(true); - GrailsTokenizedHTMLPage htmlPage = (GrailsTokenizedHTMLPage)fPage.get(page2Content); - String pageContent = htmlPage.getPage(); - String head = htmlPage.getHead(); - String body = htmlPage.getBody(); - - String contextPath = request.getContextPath(); - // - // src="/zello/zkau/ - if(pageContent.indexOf("src=\""+ contextPath + "/zkau/") > 0) { - LinkGenerator grailsLinkGenerator = (LinkGenerator) applicationContext.getBean("grailsLinkGenerator"); - String link = grailsLinkGenerator.resource(new HashMap(){{ - put("dir","ext/js"); - put("file","z-it-live.js"); - }}); - pageContent = pageContent.replace("", "\n"); - head = head + "\n\n"; - CharArray newBody = new CharArray(body.length()); - newBody.append(body); - CharArray newHead = new CharArray(head.length()); - newHead.append(head); - GrailsTokenizedHTMLPage newHtmlPage = new GrailsTokenizedHTMLPage(pageContent.toCharArray(), newBody, newHead); - return new HTMLPage2Content(newHtmlPage); - } - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - } - } - return content; - } - private String detectZULFile(String pageContent, String contextPath) { // detect uu:'/zello/zkau' int i = pageContent.indexOf("uu:'"+ contextPath + "/zkau'"); diff --git a/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZULUrlMappingsFilter.java b/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZULUrlMappingsFilter.java index 41ce7ce..6c80ab4 100644 --- a/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZULUrlMappingsFilter.java +++ b/grailszk/src/main/groovy/org/zkoss/zk/grails/web/ZULUrlMappingsFilter.java @@ -28,6 +28,7 @@ import grails.web.mapping.UrlMappingsHolder; import grails.web.mapping.exceptions.UrlMappingException; import grails.web.mime.MimeType; +import groovy.util.ConfigObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codehaus.groovy.control.MultipleCompilationErrorsException; @@ -43,6 +44,7 @@ import org.grails.web.util.GrailsApplicationAttributes; import org.grails.web.util.WebUtils; import org.springframework.context.ApplicationContext; +import org.springframework.util.ClassUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.WebRequest; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -423,11 +425,12 @@ private void processFilterChain(HttpServletRequest request, HttpServletResponse } } - protected void createStackTraceFilterer() { + protected void createStackTraceFilterer() throws LinkageError { try { - filterer = (StackTraceFilterer) GrailsClassUtils.instantiateFromFlatConfig( - grailsConfig.flatten(), "grails.logging.stackTraceFiltererClass", DefaultStackTraceFilterer.class.getName()); - // TODO: verify + String className = application.getConfig().getProperty( + "grails.logging.stackTraceFiltererClass", DefaultStackTraceFilterer.class.getName()); + filterer = (StackTraceFilterer) ClassUtils.forName(className, ClassUtils.getDefaultClassLoader()).newInstance(); + } catch (Throwable t) { logger.error("Problem instantiating StackTracePrinter class, using default: " + t.getMessage());