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 abstract base class for tags.
25   * 
26   *  This class defines the required functions that each type of 
27   *  tag must implement.  The goal here is to allow different types
28   *  of tags to be created by the user, but the call processing 
29   *  for each tag can be generic. 
30   *  
31   *  For example, a generic tag might search files for an exact string
32   *  match of the tag, but a regex tag will use regular expressions in
33   *  its searching.  Either way, the processing classes call each tag
34   *  with the same function and get the same results. 
35   * 
36   */
37  public abstract class AbsTag
38  {
39      /** The int value for no tag match found.
40       *  This value matches what is returned from Java String class 
41       *  indexOf(..string..) function. */
42      static final int NO_MATCH = -1;
43      
44      /** The tag string for this tag. The string here is generic, and its
45       *  use is defined by the derived tag objects.
46       */
47      protected String tagString = null;
48      
49      
50      /** Check to see if the string contains this tag.  
51       *  If there is a match, return the index within the string; otherwise,
52       *  return NO_MATCH.
53       *  
54       *  @param currentLine the string for the current line being scanned.
55       *  @param locale the Locale of the currentLine.
56       *  @return the index within the string of the matched tag, or TagClass.NO_MATCH
57       *  if not match was found.
58       */
59      public abstract int contains( final String currentLine, final Locale locale );
60      
61      /** Check to see if the string starts with this tag.  
62       *  If there is a match, return true.
63       *  
64       *  @param currentLine the string for the current line being scanned.
65       *  @param locale the Locale of the currentLine.
66       *  @return true if the string starts with this tag.
67       */
68      public abstract boolean startsWith( final String currentLine, final Locale locale );
69      
70      /** Return the length of the last matched tag.
71       * 
72       * Normally this is the length of the tag; however, some tags
73       * are dynamic.  For example a regular expression tag might be
74       * 10 characters; however, the matched string may only be 5.
75       * 
76       * Calling this function allows the tag object to return the
77       * correct length for the last matched tag.
78       *  
79       * @return the length of the last matched tag.
80       */
81      public abstract int getLastTagMatchLength();
82  
83      /** Constructor.
84       * 
85       * @param tag the tag string to be used for this tag.
86       */
87      protected AbsTag ( final String tag )
88      {
89          tagString = tag;
90      }
91  
92  }