GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / src / web / org / codehaus / groovy / grails / web / taglib / GroovyDefTag.java
blob4fe93587a9a9e734b3523b289a8e6a8d0ceab2d5
1 /* Copyright 2004-2005 the original author or authors.
2 *
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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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;
21 /**
22 * Allows defining of variables within the page context
24 * @author Graeme Rocher
25 * @since 23-Feb-2006
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.");
40 out.print("def ");
41 out.print(var.substring(1,var.length() -1));
42 out.print('=');
43 out.println(expr);
46 public void doEndTag() {
47 // do nothing
50 public String getName() {
51 return TAG_NAME;
54 public boolean isBufferWhiteSpace() {
55 return false;
58 public boolean hasPrecedingContent() {
59 return true;