Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » views » jsp » [javadoc | source]
    1   /*
    2    * $Id: StrutsBodyTagSupport.java 726715 2008-12-15 15:39:15Z musachy $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.views.jsp;
   23   
   24   import java.io.PrintWriter;
   25   
   26   import javax.servlet.jsp.tagext.BodyTagSupport;
   27   
   28   import org.apache.struts2.components.Component;
   29   import org.apache.struts2.util.FastByteArrayOutputStream;
   30   
   31   import com.opensymphony.xwork2.util.TextParseUtil;
   32   import com.opensymphony.xwork2.util.ValueStack;
   33   
   34   
   35   /**
   36    * Contains common functonalities for Struts JSP Tags.
   37    *
   38    */
   39   public class StrutsBodyTagSupport extends BodyTagSupport {
   40   
   41       private static final long serialVersionUID = -1201668454354226175L;
   42   
   43       protected ValueStack getStack() {
   44           return TagUtils.getStack(pageContext);
   45       }
   46   
   47       protected String findString(String expr) {
   48           return (String) findValue(expr, String.class);
   49       }
   50   
   51       protected Object findValue(String expr) {
   52       	expr = Component.stripExpressionIfAltSyntax(getStack(), expr);
   53   
   54           return getStack().findValue(expr);
   55       }
   56   
   57       protected Object findValue(String expr, Class toType) {
   58           if (Component.altSyntax(getStack()) && toType == String.class) {
   59           	return TextParseUtil.translateVariables('%', expr, getStack());
   60               //return translateVariables(expr, getStack());
   61           } else {
   62           	expr = Component.stripExpressionIfAltSyntax(getStack(), expr);
   63   
   64               return getStack().findValue(expr, toType);
   65           }
   66       }
   67   
   68       protected String toString(Throwable t) {
   69           FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
   70           PrintWriter wrt = new PrintWriter(bout);
   71           t.printStackTrace(wrt);
   72           wrt.close();
   73   
   74           return bout.toString();
   75       }
   76   
   77       protected String getBody() {
   78           if (bodyContent == null) {
   79               return "";
   80           } else {
   81               return bodyContent.getString().trim();
   82           }
   83       }
   84   }

Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » views » jsp » [javadoc | source]