View Javadoc

1   package net.sourceforge.pmd.lang.vm.directive;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  
23  /**
24   * BlockMacro directive is used to invoke Velocity macros with normal parameters and a macro body.
25   * <p>
26   * The macro can then refer to the passed body AST. This directive can be used as a 
27   * "decorator". Body AST can contain any valid Velocity syntax.
28   *
29   * An example:
30   * <pre>
31   * #set($foobar = "yeah!")
32   * 
33   * #macro(strong $txt)
34   * &lt;strong&gt;$bodyContent&lt;/strong&gt; $txt
35   * #end
36   *
37   * #@strong($foobar)
38   * &lt;u&gt;This text is underlined and bold&lt;/u&gt;
39   * #end
40   * </pre>
41   * Will print:
42   * <pre>
43   * &lt;strong&gt;&lt;u&gt;This text is underlined and bold&lt;u&gt;&lt;/strong&gt; yeah!
44   * </pre>
45   * 
46   * bodyContent reference name is configurable (see velocity.properties).
47   *
48   * @author <a href="mailto:wyla@removethis.sci.fi">Jarkko Viinamaki</a>
49   * @since 1.7
50   * @version $Id$
51   */
52  public class BlockMacro extends Block
53  {
54      private String name;
55  
56      public BlockMacro(String name)
57      {
58          this.name = name;
59      }
60      
61      public String getName()
62      {
63          return key;
64      }
65  
66      /**
67       * Override to use the macro name, since it is within an
68       * #@myMacro() ... #end block that the scope in question
69       * would be used.
70       */
71      public String getScopeName()
72      {
73          return name;
74      }
75  
76  
77  }