View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.jelly.tags.log;
17  
18  import org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.TagSupport;
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /***
24   * An abstract base class for any logging tag..
25   *
26   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
27   * @version $Revision: 155420 $
28   */
29  public abstract class LogTagSupport extends TagSupport {
30  
31      private Log log;
32      private boolean encode;
33  
34      public LogTagSupport() {
35      }
36  
37      // Properties
38      //-------------------------------------------------------------------------
39  
40      /***
41       * @return the Log being used by this tag. If none is returned then a new one will be created.
42       */
43      public Log getLog() {
44          if ( log == null ) {
45              // use a default Log
46              // ### we could inherit from a parent tag?
47              log = LogFactory.getLog( getClass() );
48          }
49          return log;
50      }
51  
52      /***
53       * Sets the name of the logger to use
54       */
55      public void setName(String name) {
56          setLog( LogFactory.getLog(name) );
57      }
58  
59      /*** Sets the Log instance to use for logging. */
60      public void setLog(Log log) {
61          this.log = log;
62      }
63  
64      /***
65       * Returns whether the body of this tag will be XML encoded or not.
66       */
67      public boolean isEncode() {
68          return encode;
69      }
70  
71      /***
72       * Sets whether the body of the tag should be encoded as text (so that &lt; and &gt; are
73       * encoded as &amp;lt; and &amp;gt;) or leave the text as XML which is the default.
74       */
75      public void setEncode(boolean encode) {
76          this.encode = encode;
77      }
78  
79  }