View Javadoc

1   package org.apache.maven.jelly.tags.jeez;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.apache.commons.jelly.JellyException;
22  import org.apache.commons.jelly.Tag;
23  import org.apache.commons.jelly.TagLibrary;
24  import org.apache.commons.jelly.impl.DynamicTagLibrary;
25  import org.apache.commons.jelly.impl.TagFactory;
26  import org.apache.commons.jelly.impl.TagScript;
27  import org.apache.commons.jelly.tags.ant.AntTagLibrary;
28  import org.apache.maven.werkz.jelly.WerkzTagLibrary;
29  import org.xml.sax.Attributes;
30  
31  /** Convenience taglib that puts jelly:core, jelly:werkz and jelly:ant
32   *  into a single namespace.
33   *
34   * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
35   * @version $Revision: 517014 $
36   */
37  public class JeezTagLibrary
38      extends DynamicTagLibrary
39  {
40      /** jelly:werkz taglib. */
41      private TagLibrary werkzTagLib = new WerkzTagLibrary();
42  
43      /** jelly:ant taglib. */
44      private AntTagLibrary antTagLib = new AntTagLibrary();
45  
46      /**
47       * Create a script from the element and the attributes.
48       * This method will check for 'tagdef' and 'target' tags, and try to create
49       * an instance of these tags first.
50       *
51       * Failing that it tries to create a werkz tag script followed by an ant
52       * 'custom tag script' (i.e. one for filescanner or setProperty).
53       *
54       * If all else fails, it creates a TagScript from a factory that creates a script
55       * from either a Jeez tag, or an Ant tag
56       * @see org.apache.commons.jelly.TagLibrary#createTagScript(java.lang.String, org.xml.sax.Attributes)
57       */
58      public TagScript createTagScript( final String name, Attributes attrs )
59          throws JellyException
60      {
61  
62          if ( name.equals( "tagdef" ) )
63          {
64              return new TagScript( new TagFactory()
65              {
66                  public Tag createTag( String name, Attributes attributes )
67                  {
68                      return new TagDefTag( JeezTagLibrary.this );
69                  }
70              } );
71          }
72          if ( name.equals( "target" ) )
73          {
74              return new TagScript( new TagFactory()
75              {
76                  public Tag createTag( String name, Attributes attributes )
77                  {
78                      return new TargetTag();
79                  }
80              } );
81          }
82  
83          TagScript script = werkzTagLib.createTagScript( name, attrs );
84          if ( script == null )
85          {
86              script = antTagLib.createCustomTagScript( name, attrs );
87              if ( script == null )
88              {
89                  return new TagScript( new TagFactory()
90                  {
91                      public Tag createTag( String name, Attributes attributes )
92                          throws JellyException
93                      {
94                          // lets try create a dynamic tag first
95                          Tag tag = JeezTagLibrary.this.createTag( name, attributes );
96                          if ( tag != null )
97                          {
98                              return tag;
99                          }
100                         else
101                         {
102                             return antTagLib.createTag( name, attributes );
103                         }
104                     }
105                 } );
106             }
107         }
108         return script;
109     }
110 }