001: /* ====================================================================
002: * Tea - Copyright (c) 1997-2000 Walt Disney Internet Group
003: * ====================================================================
004: * The Tea Software License, Version 1.1
005: *
006: * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Walt Disney Internet Group (http://opensource.go.com/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact opensource@dig.com.
031: *
032: * 5. Products derived from this software may not be called "Tea",
033: * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
034: * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
035: * written permission of the Walt Disney Internet Group.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
041: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
042: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
043: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
044: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
045: * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
046: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
047: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
048: * ====================================================================
049: *
050: * For more information about Tea, please see http://opensource.go.com/.
051: */
052:
053: package com.go.tea.runtime;
054:
055: /******************************************************************************
056: * Extends the basic context to provide generic utility functions that most
057: * templates will need to use for formatting.
058: *
059: * @author Brian S O'Neill
060: * @version
061: * <!--$$Revision:--> 12 <!-- $-->, <!--$$JustDate:--> 9/07/00 <!-- $-->
062: */
063: public interface UtilityContext extends Context {
064:
065: /**
066: * Returns a Date object with the current date and time.
067: */
068: public java.util.Date currentDate();
069:
070: /**
071: * Tests if the given string starts with the given prefix.
072: * Returns true if the given string starts with the given prefix.
073: *
074: * @param str the source string
075: * @param prefix the prefix to test for
076: *
077: * @return true if the given string starts with the given prefix
078: */
079: public boolean startsWith(String str, String prefix);
080:
081: /**
082: * Tests if the given string ends with the given suffix.
083: * Returns true if the given string ends with the given suffix.
084: *
085: * @param str the source string
086: * @param suffix the suffix to test for
087: *
088: * @return true if the given string ends with the given suffix
089: */
090: public boolean endsWith(String str, String suffix);
091:
092: /**
093: * Finds the indices for each occurrence of the given search string in the
094: * source string. Returns an array of indices, which is empty if the
095: * search string wasn't found
096: *
097: * @param str the source string
098: * @param search the string to search for
099: *
100: * @return an array of indices, which is empty if the search string
101: * wasn't found
102: */
103: public int[] find(String str, String search);
104:
105: /**
106: * Finds the indices for each occurrence of the given search string in the
107: * source string, starting from the given index.
108: *
109: * @param str the source string
110: * @param search the string to search for
111: * @param fromIndex index to start the find
112: *
113: * @return an array of indices, which is empty if the search string
114: * wasn't found
115: */
116: public int[] find(String str, String search, int fromIndex);
117:
118: /**
119: * Finds the index of the first occurrence of the given search string in
120: * the source string, or -1 if not found.
121: *
122: * @param str the source string
123: * @param search the string to search for
124: *
125: * @return the start index of the found string or -1 if not found
126: */
127: public int findFirst(String str, String search);
128:
129: /**
130: * Finds the index of the first occurrence of the given search string in
131: * the source string, starting from the given index, or -1 if not found.
132: *
133: * @param str the source string
134: * @param search the string to search for
135: * @param fromIndex index to start the find
136: *
137: * @return the start index of the found string or -1 if not found
138: */
139: public int findFirst(String str, String search, int fromIndex);
140:
141: /**
142: * Finds the index of the last occurrence of the given search string in the
143: * source string, or -1 if not found.
144: *
145: * @param str the source string
146: * @param search the string to search for
147: *
148: * @return the start index of the found string or -1 if not found
149: */
150: public int findLast(String str, String search);
151:
152: /**
153: * Finds the index of the last occurrence of the given search string in the
154: * source string, starting from the given index, or -1 if not found.
155: *
156: * @param str the source string
157: * @param search the string to search for
158: * @param fromIndex optional index to start the find
159: *
160: * @return the start index of the found string or -1 if not found
161: */
162: public int findLast(String str, String search, int fromIndex);
163:
164: /**
165: * Returns the trailing end of the given string, starting from the given
166: * index.
167: *
168: * @param str the source string
169: * @param startIndex the start index, inclusive
170: *
171: * @return the specified substring.
172: */
173: public String substring(String str, int startIndex);
174:
175: /**
176: * Returns a sub-portion of the given string for the characters that are at
177: * or after the starting index, and are before the end index.
178: *
179: * @param str the source string
180: * @param startIndex the start index, inclusive
181: * @param endIndex the ending index, exclusive
182: *
183: * @return the specified substring.
184: */
185: public String substring(String str, int startIndex, int endIndex);
186:
187: /**
188: * Converts all the characters in the given string to lowercase.
189: *
190: * @param str the string to convert
191: *
192: * @return the string converted to lowercase
193: */
194: public String toLowerCase(String str);
195:
196: /**
197: * Converts all the characters in the given string to uppercase.
198: *
199: * @param str the string to convert
200: *
201: * @return the string converted to uppercase
202: */
203: public String toUpperCase(String str);
204:
205: /**
206: * Trims all leading and trailing whitespace characters from the given
207: * string.
208: *
209: * @param str the string to trim
210: *
211: * @return the trimmed string
212: */
213: public String trim(String str);
214:
215: /**
216: * Trims all leading whitespace characters from the given string.
217: *
218: * @param str the string to trim
219: *
220: * @return the trimmed string
221: */
222: public String trimLeading(String str);
223:
224: /**
225: * Trims all trailing whitespace characters from the given string.
226: *
227: * @param str the string to trim
228: *
229: * @return the trimmed string
230: */
231: public String trimTrailing(String str);
232:
233: /**
234: * Replaces all exact matches of the given pattern in the source string
235: * with the provided replacement.
236: *
237: * @param source the source string
238: * @param pattern the simple string pattern to search for
239: * @param replacement the string to use for replacing matched patterns.
240: *
241: * @return the string with any replacements applied.
242: */
243: public String replace(String source, String pattern,
244: String replacement);
245:
246: /**
247: * Replaces all exact matches of the given pattern in the source string
248: * with the provided replacement, starting from the given index.
249: *
250: * @param source the source string
251: * @param pattern the simple string pattern to search for
252: * @param replacement the string to use for replacing matched patterns.
253: * @param fromIndex index to start the replace
254: *
255: * @return the string with any replacements applied.
256: */
257: public String replace(String source, String pattern,
258: String replacement, int fromIndex);
259:
260: /**
261: * Applies string replacements using the pattern-replacement pairs provided
262: * by the given map (associative array). The longest matching pattern is
263: * used for selecting an appropriate replacement.
264: *
265: * @param source the source string
266: * @param patternReplacements pattern-replacement pairs
267: */
268: public String replace(String source,
269: java.util.Map patternReplacements);
270:
271: /**
272: * Replaces the first exact match of the given pattern in the source
273: * string with the provided replacement.
274: *
275: * @param source the source string
276: * @param pattern the simple string pattern to search for
277: * @param replacement the string to use for replacing matched patterns
278: *
279: * @return the string with any replacements applied
280: */
281: public String replaceFirst(String source, String pattern,
282: String replacement);
283:
284: /**
285: * Replaces the first exact match of the given pattern in the source
286: * string with the provided replacement, starting from the given index.
287: *
288: * @param source the source string
289: * @param pattern the simple string pattern to search for
290: * @param replacement the string to use for replacing matched patterns
291: * @param fromIndex index to start the replace
292: *
293: * @return the string with any replacements applied
294: */
295: public String replaceFirst(String source, String pattern,
296: String replacement, int fromIndex);
297:
298: /**
299: * Replaces the last exact match of the given pattern in the source
300: * string with the provided replacement.
301: *
302: * @param source the source string
303: * @param pattern the simple string pattern to search for
304: * @param replacement the string to use for replacing matched patterns
305: *
306: * @return the string with any replacements applied
307: */
308: public String replaceLast(String source, String pattern,
309: String replacement);
310:
311: /**
312: * Replaces the last exact match of the given pattern in the source
313: * string with the provided replacement, starting from the given index.
314: *
315: * @param source the source string
316: * @param pattern the simple string pattern to search for
317: * @param replacement the string to use for replacing matched patterns
318: * @param fromIndex index to start the replace
319: *
320: * @return the string with any replacements applied
321: */
322: public String replaceLast(String source, String pattern,
323: String replacement, int fromIndex);
324:
325: /**
326: * A function that converts an integer to a short ordinal value.
327: * i.e. 1st, 2nd, 3rd etc.
328: *
329: * @param n the number to convert
330: *
331: * @return a String containing the short ordinal value of the specified
332: * number
333: */
334: public String shortOrdinal(Long n);
335:
336: /**
337: * A function that converts an integer to a short ordinal value.
338: * i.e. 1st, 2nd, 3rd etc.
339: *
340: * @param n the number to convert
341: *
342: * @return a String containing the short ordinal value of the specified
343: * number
344: *
345: * @hidden
346: */
347: public String shortOrdinal(long n);
348:
349: /**
350: * A function that converts an integer to an ordinal value. i.e. first,
351: * second, third etc.
352: *
353: * @param n the number to convert
354: *
355: * @return a String containing the ordinal value of the specified number
356: */
357: public String ordinal(Long n);
358:
359: /**
360: * A function that converts an integer to an ordinal value. i.e. first,
361: * second, third etc.
362: *
363: * @param n the number to convert
364: *
365: * @return a String containing the ordinal value of the specified number
366: *
367: * @hidden
368: */
369: public String ordinal(long n);
370:
371: /**
372: * A function that converts an integer to a cardinal value. i.e. one,
373: * two, three etc.
374: *
375: * @param n the number to convert
376: *
377: * @return a String containing the cardinal value of the specified number
378: */
379: public String cardinal(Long n);
380:
381: /**
382: * A function that converts an integer to a cardinal value. i.e. one,
383: * two, three etc.
384: *
385: * @param n the number to convert
386: *
387: * @return a String containing the cardinal value of the specified number
388: *
389: * @hidden
390: */
391: public String cardinal(long n);
392: }
|