1 /* Copyright 2004-2005 the original author or authors.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 package org
.codehaus
.groovy
.grails
.web
.taglib
;
17 import org
.apache
.commons
.lang
.StringUtils
;
18 import org
.codehaus
.groovy
.grails
.web
.taglib
.exceptions
.GrailsTagException
;
19 import grails
.util
.GrailsUtil
;
22 * Allows defining of variables within the page context
24 * @author Graeme Rocher
27 public class GroovyDefTag
extends GroovySyntaxTag
{
28 public static final String TAG_NAME
= "def";
29 private static final String ATTRIBUTE_VALUE
= "value";
30 public void doStartTag() {
31 String expr
= (String
) attributes
.get(ATTRIBUTE_VALUE
);
32 String var
= (String
) attributes
.get(ATTRIBUTE_VAR
);
34 if(StringUtils
.isBlank(var
))
35 throw new GrailsTagException("Tag ["+TAG_NAME
+"] missing required attribute ["+ATTRIBUTE_VAR
+"]");
36 if(StringUtils
.isBlank(expr
))
37 throw new GrailsTagException("Tag ["+TAG_NAME
+"] missing required attribute ["+ATTRIBUTE_VALUE
+"]");
39 GrailsUtil
.deprecated("The tag <g:def> is deprecated and will be removed in a future release. Use <g:set> instead.");
41 out
.print(var
.substring(1,var
.length() -1));
46 public void doEndTag() {
50 public String
getName() {
54 public boolean isBufferWhiteSpace() {
58 public boolean hasPrecedingContent() {