jdaugherty commented on code in PR #14875: URL: https://github.com/apache/grails-core/pull/14875#discussion_r2183908644
########## grails-gsp/grails-layout/src/main/groovy/org/grails/plugins/web/taglib/RenderGrailsLayoutTagLib.groovy: ########## @@ -0,0 +1,337 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.plugins.web.taglib + +import com.opensymphony.module.sitemesh.* +import grails.artefact.TagLibrary +import grails.core.GrailsApplication +import grails.core.support.GrailsApplicationAware +import grails.gsp.TagLib +import grails.util.TypeConvertingMap +import groovy.text.Template +import groovy.transform.CompileStatic +import org.apache.grails.web.layout.FactoryHolder +import org.apache.grails.web.layout.GSPGrailsLayoutPage +import org.apache.grails.web.layout.GrailsHTMLPageParser +import org.apache.grails.web.layout.EmbeddedGrailsLayoutView +import org.apache.grails.web.layout.GroovyPageLayoutFinder +import org.apache.grails.web.layout.SpringMVCViewDecorator +import org.grails.buffer.FastStringWriter +import org.grails.buffer.StreamCharBuffer +import org.grails.gsp.GroovyPageTemplate +import org.grails.gsp.GroovyPagesTemplateEngine +import org.grails.gsp.compiler.GroovyPageParser +import org.grails.taglib.TagLibraryLookup +import org.grails.taglib.TagOutput +import org.grails.taglib.encoder.OutputContextLookupHelper +import jakarta.servlet.http.HttpServletRequest + +/** + * Tags to help rendering of views and layouts. + * + * @author Graeme Rocher + */ +@CompileStatic +@TagLib +class RenderGrailsLayoutTagLib implements RequestConstants, TagLibrary, GrailsApplicationAware { + GroovyPagesTemplateEngine groovyPagesTemplateEngine + TagLibraryLookup gspTagLibraryLookup + GroovyPageLayoutFinder groovyPageLayoutFinder + protected boolean grailsLayoutPreprocessMode = true + + protected HTMLPage getPage() { + return (HTMLPage) getRequest().getAttribute(PAGE) + } + + @Override + void setGrailsApplication(GrailsApplication grailsApplication) { + grailsLayoutPreprocessMode = grailsApplication.config.getProperty(GroovyPageParser.CONFIG_PROPERTY_GSP_GRAILS_LAYOUT_PREPROCESS, Boolean, true) + } + + protected boolean isGrailsLayoutPreprocessMode() { + return grailsLayoutPreprocessMode + } + + + /** + * Apply a layout to a particular block of text or to the given view or template.<br/> + * + * <g:applyLayout name="myLayout">some text</g:applyLayout><br/> + * <g:applyLayout name="myLayout" template="mytemplate" /><br/> + * <g:applyLayout name="myLayout" url="http://www.google.com" /><br/> + * <g:applyLayout name="myLayout" action="myAction" controller="myController"><br/> + * + * @attr name The name of the layout + * @attr template Optional. The template to apply the layout to + * @attr url Optional. The URL to retrieve the content from and apply a layout to + * @attr action Optional. The action to be called to generate the content to apply the layout to + * @attr controller Optional. The controller that contains the action that will generate the content to apply the layout to + * @attr contentType Optional. The content type to use, default is "text/html" + * @attr encoding Optional. The encoding to use + * @attr params Optional. The params to pass onto the page object + * @attr parse Optional. If true, Grails Layout parser will always be used to parse the content. + */ + Closure applyLayout = { Map attrs, body -> + if (!groovyPagesTemplateEngine) throw new IllegalStateException("Property [groovyPagesTemplateEngine] must be set!") + def oldPage = getPage() + String contentType = attrs.contentType ? attrs.contentType as String : "text/html" + + Map pageParams = attrs.params instanceof Map ? (Map) attrs.params : [:] + Map viewModel = attrs.model instanceof Map ? (Map) attrs.model : [:] + Object content = null + GSPGrailsLayoutPage gspGrailsLayoutPage = null + if (attrs.url) { + content = new URL(attrs.url as String).getText("UTF-8") Review Comment: I've gone ahead and replaced every instance in the code base with StandardCharsets.UTF_8 where possible, and StandardCharsets.UTF_8.name() where not. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@grails.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org