View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.servlet.jsp.JspException;
26  import javax.servlet.jsp.tagext.BodyContent;
27  import javax.servlet.jsp.tagext.BodyTag;
28  
29  public abstract class TobagoBodyTag extends TobagoTag implements BodyTag {
30  
31    private static final Logger LOG = LoggerFactory.getLogger(TobagoBodyTag.class);
32  
33    private BodyContent bodyContent;
34  
35    public int doAfterBody() throws JspException {
36      return getDoAfterBodyValue();
37    }
38  
39    public void doInitBody() throws JspException {
40    }
41  
42    protected String getBodyContentStr() {
43      final String content = bodyContent.getString();
44      bodyContent.clearBody();
45      return content;
46    }
47  
48    protected boolean isBodyContentEmpty() {
49      if (bodyContent != null) {
50        final String content = bodyContent.getString();
51        final String tmp = content.replace('\n', ' ');
52        if (tmp.trim().length() > 0) { // if there are only whitespaces: drop bodyContent
53          return false;
54        }
55      }
56      return true;
57    }
58  
59    protected int getDoStartValue() throws JspException {
60      return BodyTag.EVAL_BODY_BUFFERED;
61    }
62  
63    protected int getDoAfterBodyValue() throws JspException {
64      return BodyTag.SKIP_BODY;
65    }
66  
67    public void release() {
68      super.release();
69      bodyContent = null;
70    }
71  
72    public void setBodyContent(final BodyContent bodyContent) {
73      this.bodyContent = bodyContent;
74    }
75  }
76