View Javadoc
1   package org.codehaus.mojo.taglist.tags;
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  import java.util.Locale;
23  
24  /** The generic tag class.
25   * 
26   *  This class defines a generic "case sensitive" exact match tag.  This tag
27   *  will only match if the exact string listed is found within
28   *  the scanned lines.
29   *  
30   *  Example POM:
31   *  <pre>
32   *   &lt;project &gt;
33   *       ...
34   *       &lt;matchString&gt;fixme&lt;/matchString&gt;
35   *       ...
36   *   &lt;/project&gt;
37   *  </pre>
38   *  
39   *  Example Java code with match:
40   *  <pre>
41   *     * fixme this will NOT match.
42   *  </pre>
43   *  
44   *  Example Java code without match:
45   *  <pre>
46   *     * Fixme this will NOT match.
47   *  </pre>
48   *       
49   */
50  public class GenericTag extends AbsTag
51  {
52      /** Check to see if the string contains this tag.  
53       *  If there is a match, return the index within the string; otherwise,
54       *  return NO_MATCH.
55       *  
56       *  @param currentLine the string for the current line being scanned.
57       *  @param locale the Locale of the currentLine.
58       *  @return the index within the string of the matched tag, or TagClass.NO_MATCH
59       *  if not match was found.
60       */
61      public int contains( final String currentLine, final Locale locale )
62      {
63          int result = AbsTag.NO_MATCH;
64          
65          if ( currentLine != null )
66          {
67              // Get index match or -1 if no match
68              result = currentLine.indexOf( tagString );
69          }
70          
71          return ( result );
72      }
73      
74      /** Check to see if the string starts with this tag.  
75       *  
76       *  @param currentLine the string for the current line being scanned.
77       *  @param locale the Locale of the currentLine.
78       *  @return true if the string starts with this tag.
79       */
80      public boolean startsWith( final String currentLine, final Locale locale )
81      {
82          boolean result = false;
83          
84          if ( currentLine != null )
85          {
86              result = currentLine.startsWith( tagString );
87          }
88          
89          return ( result );
90      }
91      
92      /** Return the length of the last matched tag.
93       * 
94       * In the case of a generic tag, this is always the length of the tag.
95       *  
96       * @return the length of the last matched tag.
97       */
98      public int getLastTagMatchLength()
99      {
100         return ( tagString.length() );
101     }
102 
103     /** Constructor.
104      * 
105      * @param exactTagString the string to match against for this tag.
106      */
107     public GenericTag ( final String exactTagString )
108     {
109         super( exactTagString );
110     }
111 
112 }