Coverage Report - org.seasar.cubby.tags.ParamTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ParamTag
100%
16/16
100%
4/4
2
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.tags;
 17  
 
 18  
 import static org.seasar.cubby.internal.util.LogMessages.format;
 19  
 
 20  
 import java.io.IOException;
 21  
 import java.io.StringWriter;
 22  
 
 23  
 import javax.servlet.jsp.JspException;
 24  
 import javax.servlet.jsp.tagext.SimpleTagSupport;
 25  
 
 26  
 /**
 27  
  * パラメータを指定するためのカスタムタグです。
 28  
  * 
 29  
  * @author baba
 30  
  */
 31  12
 public class ParamTag extends SimpleTagSupport {
 32  
 
 33  
         /** パラメータ名。 */
 34  
         private String name;
 35  
 
 36  
         /** 値。 */
 37  
         private String value;
 38  
 
 39  
         /**
 40  
          * パラメータ名を設定します。
 41  
          * 
 42  
          * @param name
 43  
          *            パラメータ名
 44  
          */
 45  
         public void setName(final String name) {
 46  12
                 this.name = name;
 47  12
         }
 48  
 
 49  
         /**
 50  
          * 値を設定します。
 51  
          * 
 52  
          * @param value
 53  
          *            値
 54  
          */
 55  
         public void setValue(final String value) {
 56  11
                 this.value = value;
 57  11
         }
 58  
 
 59  
         /**
 60  
          * {@inheritDoc}
 61  
          */
 62  
         @Override
 63  
         public void doTag() throws JspException, IOException {
 64  12
                 final ParamParent parent = (ParamParent) findAncestorWithClass(this,
 65  
                                 ParamParent.class);
 66  12
                 if (parent == null) {
 67  2
                         throw new JspException(format("ECUB1004"));
 68  
                 }
 69  
                 final String value;
 70  10
                 if (this.value == null) {
 71  1
                         final StringWriter writer = new StringWriter();
 72  1
                         getJspBody().invoke(writer);
 73  1
                         value = writer.toString().trim();
 74  1
                 } else {
 75  9
                         value = this.value;
 76  
                 }
 77  10
                 parent.addParameter(name, value);
 78  10
         }
 79  
 
 80  
 }