1 /*
2 * Copyright (c) 2001 - 2005 ivata limited.
3 * All rights reserved.
4 * ---------------------------------------------------------
5 * ivata masks may be redistributed under the GNU General Public
6 * License as published by the Free Software Foundation;
7 * version 2 of the License.
8 *
9 * These programs are free software; you can redistribute them and/or
10 * modify them under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2 of the License.
12 *
13 * These programs are distributed in the hope that they will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * See the GNU General Public License in the file LICENSE.txt for more
18 * details.
19 *
20 * If you would like a copy of the GNU General Public License write to
21 *
22 * Free Software Foundation, Inc.
23 * 59 Temple Place - Suite 330
24 * Boston, MA 02111-1307, USA.
25 *
26 *
27 * To arrange commercial support and licensing, contact ivata at
28 * http://www.ivata.com/contact.jsp
29 * ---------------------------------------------------------
30 * $Log: CaseFormat.java,v $
31 * Revision 1.1 2005/04/11 14:44:46 colinmacleod
32 * First version.
33 *
34 * ---------------------------------------------------------
35 */
36 package com.ivata.mask.web.format;
37
38 import org.apache.log4j.Logger;
39
40 /***
41 * Convert a string to upper or lower case.
42 *
43 * @since ivata masks 0.6 (2005-03-15)
44 * @author Colin MacLeod
45 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
46 * @version $Revision: 1.1 $
47 */
48
49 public class CaseFormat implements HTMLFormat {
50 /***
51 * Logger for this class.
52 */
53 private static final Logger logger = Logger.getLogger(CaseFormat.class);
54
55 /***
56 * Refer to {@link #isLower}.
57 */
58 private boolean lower = true;
59 /***
60 * Converts the given text to either upper or lower (default) case,
61 * depending on the setting of {@link #isLower lower}.
62 *
63 * @param textParam text to be converted.
64 * @return text with all characters converted to either upper or lower case.
65 */
66 public String format(String textParam) {
67 if (lower) {
68 return textParam.toLowerCase();
69 } else {
70 return textParam.toUpperCase();
71 }
72 }
73 /***
74 * If <code>true</code>, then <code>format</code> will convert to lower
75 * case.
76 * @return Returns <code>true</code>, if <code>format</code> should convert
77 * to lower case, otherwise <code>false</code>.
78 */
79 public boolean isLower() {
80 return lower;
81 }
82 /***
83 * Refer to {@link #isLower}.
84 * @param lowerParam Refer to {@link #isLower}.
85 */
86 public void setLower(boolean lowerParam) {
87 if (logger.isDebugEnabled()) {
88 logger.debug("Setting lower. Before '" + lower + "', after '"
89 + lowerParam + "'");
90 }
91 lower = lowerParam;
92 }
93 }