2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
30 package mircoders.localizer.basic;
\r
33 import mir.config.MirPropertiesConfiguration;
\r
35 import java.util.Collections;
\r
36 import java.util.List;
\r
38 public class MirBasicUtilityFunctions {
\r
39 public String encodeXML(Object anObject) throws Exception {
\r
40 return HTMLRoutines.encodeXML(StringRoutines.interpretAsString(anObject));
\r
43 public String encodeHTML(Object aString) throws Exception {
\r
44 return HTMLRoutines.encodeHTML(StringRoutines.interpretAsString(aString));
\r
47 public String prettyEncodeHTML(Object aString) throws Exception {
\r
48 return HTMLRoutines.prettyEncodeHTML(StringRoutines.interpretAsString(aString));
\r
51 public String encodeURI(Object aString) throws Exception {
\r
52 return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aString));
\r
55 public String encodeURI(Object aString, Object anEncoding) throws Exception {
\r
56 return HTMLRoutines.encodeURL(
\r
57 StringRoutines.interpretAsString(aString),
\r
58 StringRoutines.interpretAsString(anEncoding));
\r
61 public String subString(Object aString, Object aFrom) throws Exception {
\r
62 return StringRoutines.interpretAsString(aString).substring(StringRoutines.interpretAsInteger(aFrom));
\r
65 public String subString(Object aString, Object aFrom, Object aLength) throws Exception {
\r
66 int length = StringRoutines.interpretAsInteger(aLength);
\r
67 String target = StringRoutines.interpretAsString(aString);
\r
68 if (length<0 || length>target.length()) {
\r
69 length=target.length();
\r
72 return target.substring(StringRoutines.interpretAsInteger(aFrom), length);
\r
75 public String escapeJDBCString(Object aString) throws Exception {
\r
76 return JDBCStringRoutines.escapeStringLiteral(StringRoutines.interpretAsString(aString));
\r
79 public String constructString(Object aString) throws Exception {
\r
81 return StructuredContentParser.constructStringLiteral("");
\r
83 return StructuredContentParser.constructStringLiteral(StringRoutines.interpretAsString(aString));
\r
86 public Object parseStructuredString(Object aString) throws Exception {
\r
90 return StructuredContentParser.parse(StringRoutines.interpretAsString(aString));
\r
93 public boolean isOdd(Object anInteger) throws Exception {
\r
94 return (StringRoutines.interpretAsInteger(anInteger) & 1) == 1;
\r
97 public int increment(Object anInteger) throws Exception {
\r
98 final Integer ONE = new Integer(1);
\r
100 return increment(anInteger, ONE);
\r
103 public int increment(Object anInteger, Object anIncrement) throws Exception {
\r
104 return StringRoutines.interpretAsInteger(anInteger) +
\r
105 StringRoutines.interpretAsInteger(anIncrement);
\r
108 public Object subList(Object aList, Object aSkip) throws Exception {
\r
109 return subList(aList, aSkip, new Integer(-1));
\r
112 public Object subList(Object aList, Object aSkip, Object aMaxSize) throws Exception {
\r
113 int skip = StringRoutines.interpretAsInteger(aSkip);
\r
114 int maxSize = StringRoutines.interpretAsInteger(aMaxSize);
\r
116 if (aList instanceof RewindableIterator)
\r
117 return new SubsetIterator((RewindableIterator) aList, skip, maxSize);
\r
119 List list = (List) aList;
\r
121 if (skip>=list.size())
\r
122 return Collections.EMPTY_LIST;
\r
123 if (maxSize<0 || (skip+maxSize)>=list.size())
\r
124 return list.subList(skip, list.size());
\r
126 return list.subList(skip, skip+maxSize);
\r
130 public int listSize(RewindableIterator anIterator) {
\r
131 anIterator.rewind();
\r
134 while (anIterator.hasNext()) {
\r
139 anIterator.rewind();
\r
144 public int listSize(List aList) {
\r
145 return aList.size();
\r
148 public Object evaluate(Object aTarget, String anExpression) throws Exception {
\r
149 return ParameterExpander.expandExpression(aTarget, anExpression);
\r
152 public String regexpreplace(String aString, String anExpression, String aReplacement) {
\r
153 return StringRoutines.performRegularExpressionReplacement(aString, anExpression, aReplacement);
\r
156 public boolean regexpmatch(String aString, String anExpression) {
\r
157 return StringRoutines.performRegularExpressionSearch(aString, anExpression);
\r