1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.servlet.taglib;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.servlet.BodyContentWrapper;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.kernel.util.StringPool;
22  
23  import java.io.IOException;
24  import java.io.Writer;
25  
26  import javax.servlet.jsp.tagext.BodyContent;
27  import javax.servlet.jsp.tagext.BodyTagSupport;
28  
29  /**
30   * <a href="BaseBodyTagSupport.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Shuyang Zhou
33   */
34  public class BaseBodyTagSupport extends BodyTagSupport {
35  
36      public StringBundler getBodyContentAsStringBundler() {
37          BodyContent bodyContent = getBodyContent();
38  
39          if (bodyContent instanceof BodyContentWrapper) {
40              BodyContentWrapper bodyContentWrapper =
41                  (BodyContentWrapper)bodyContent;
42  
43              return bodyContentWrapper.getStringBundler();
44          }
45          else {
46              if (_log.isWarnEnabled()) {
47                  _log.warn(
48                      "BodyContent is not BodyContentWrapper. Check " +
49                          "JspFactorySwapper.");
50              }
51  
52              String bodyContentString = bodyContent.getString();
53  
54              if (bodyContentString == null) {
55                  bodyContentString = StringPool.BLANK;
56              }
57  
58              return new StringBundler(bodyContentString);
59          }
60      }
61  
62      public void writeBodyContent(Writer writer) throws IOException {
63          StringBundler sb = getBodyContentAsStringBundler();
64  
65          sb.writeTo(writer);
66      }
67  
68      private static Log _log = LogFactoryUtil.getLog(BaseBodyTagSupport.class);
69  
70  }