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 * <p> 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 * <p> 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 /** The int value for no tag match found. 39 * This value matches what is returned from Java String class 40 * indexOf(..string..) function. */ 41 static final int NO_MATCH = -1; 42 43 /** 44 * The tag string for this tag. The string here is generic, and its use is defined by the derived tag objects. 45 */ 46 protected String tagString; 47 48 /** Check to see if the string contains this tag. 49 * If there is a match, return the index within the string; otherwise, 50 * return NO_MATCH. 51 * 52 * @param currentLine the string for the current line being scanned. 53 * @param locale the Locale of the currentLine. 54 * @return the index within the string of the matched tag, or TagClass.NO_MATCH 55 * if not match was found. 56 */ 57 public abstract int contains(final String currentLine, final Locale locale); 58 59 /** Check to see if the string starts with this tag. 60 * If there is a match, return true. 61 * 62 * @param currentLine the string for the current line being scanned. 63 * @param locale the Locale of the currentLine. 64 * @return true if the string starts with this tag. 65 */ 66 public abstract boolean startsWith(final String currentLine, final Locale locale); 67 68 /** Return the length of the last matched tag. 69 * <p> 70 * Normally this is the length of the tag; however, some tags 71 * are dynamic. For example a regular expression tag might be 72 * 10 characters; however, the matched string may only be 5. 73 * <p> 74 * Calling this function allows the tag object to return the 75 * correct length for the last matched tag. 76 * 77 * @return the length of the last matched tag. 78 */ 79 public abstract int getLastTagMatchLength(); 80 81 /** Constructor. 82 * 83 * @param tag the tag string to be used for this tag. 84 */ 85 protected AbsTag(final String tag) { 86 tagString = tag; 87 } 88 }