Coverage Report - org.seasar.cubby.tags.ParamTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ParamTag
100%
16/16
100%
4/4
0
 
 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  
  * @since 1.1.0
 31  
  */
 32  36
 public class ParamTag extends SimpleTagSupport {
 33  
 
 34  
         /** パラメータ名。 */
 35  
         private String name;
 36  
 
 37  
         /** 値。 */
 38  
         private String value;
 39  
 
 40  
         /**
 41  
          * パラメータ名を設定します。
 42  
          * 
 43  
          * @param name
 44  
          *            パラメータ名
 45  
          */
 46  
         public void setName(final String name) {
 47  36
                 this.name = name;
 48  36
         }
 49  
 
 50  
         /**
 51  
          * 値を設定します。
 52  
          * 
 53  
          * @param value
 54  
          *            値
 55  
          */
 56  
         public void setValue(final String value) {
 57  33
                 this.value = value;
 58  33
         }
 59  
 
 60  
         /**
 61  
          * {@inheritDoc}
 62  
          */
 63  
         @Override
 64  
         public void doTag() throws JspException, IOException {
 65  36
                 final ParamParent parent = (ParamParent) findAncestorWithClass(this,
 66  
                                 ParamParent.class);
 67  36
                 if (parent == null) {
 68  6
                         throw new JspException(format("ECUB1004"));
 69  
                 }
 70  
                 final String value;
 71  30
                 if (this.value == null) {
 72  3
                         final StringWriter writer = new StringWriter();
 73  3
                         getJspBody().invoke(writer);
 74  3
                         value = writer.toString().trim();
 75  3
                 } else {
 76  27
                         value = this.value;
 77  
                 }
 78  30
                 parent.addParameter(name, value);
 79  30
         }
 80  
 
 81  
 }