http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java index b1bd1dd..6632654 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java @@ -60,7 +60,7 @@ class BuiltInsForMultipleTypes { return formatNumber(env, model); } else if (model instanceof TemplateBooleanModel) { return new SimpleScalar(((TemplateBooleanModel) model).getAsBoolean() - ? MiscUtil.C_TRUE : MiscUtil.C_FALSE); + ? TemplateBooleanFormat.C_TRUE : TemplateBooleanFormat.C_FALSE); } else { throw new UnexpectedTypeException( target, model, @@ -71,7 +71,7 @@ class BuiltInsForMultipleTypes { @Override protected TemplateModel formatNumber(Environment env, TemplateModel model) throws TemplateModelException { - Number num = _EvalUtil.modelToNumber((TemplateNumberModel) model, target); + Number num = _EvalUtils.modelToNumber((TemplateNumberModel) model, target); if (num instanceof Integer || num instanceof Long) { // Accelerate these fairly common cases return new SimpleScalar(num.toString()); @@ -514,7 +514,7 @@ class BuiltInsForMultipleTypes { defaultFormat = dateType == TemplateDateModel.UNKNOWN ? null // Lazy unknown type error in getAsString() : env.getTemplateDateFormat( - dateType, _EvalUtil.modelToDate(dateModel, target).getClass(), target, true); + dateType, _EvalUtils.modelToDate(dateModel, target).getClass(), target, true); } @Override @@ -550,16 +550,16 @@ class BuiltInsForMultipleTypes { if (cachedValue == null) { if (defaultFormat == null) { if (dateModel.getDateType() == TemplateDateModel.UNKNOWN) { - throw MessageUtil.newCantFormatUnknownTypeDateException(target, null); + throw MessageUtils.newCantFormatUnknownTypeDateException(target, null); } else { throw new BugException(); } } try { - cachedValue = _EvalUtil.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel)); + cachedValue = _EvalUtils.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel)); } catch (TemplateValueFormatException e) { try { - throw MessageUtil.newCantFormatDateException(defaultFormat, target, e, true); + throw MessageUtils.newCantFormatDateException(defaultFormat, target, e, true); } catch (TemplateException e2) { // `e` should always be a TemplateModelException here, but to be sure: throw _CoreAPI.ensureIsTemplateModelException("Failed to format date/time/dateTime", e2); @@ -587,7 +587,7 @@ class BuiltInsForMultipleTypes { // As we format lazily, we need a snapshot of the format inputs: this.numberModel = numberModel; - number = _EvalUtil.modelToNumber(numberModel, target); // for BackwardCompatibleTemplateNumberFormat-s + number = _EvalUtils.modelToNumber(numberModel, target); // for BackwardCompatibleTemplateNumberFormat-s try { defaultFormat = env.getTemplateNumberFormat(stringBI.this, true); } catch (TemplateException e) { @@ -652,7 +652,7 @@ class BuiltInsForMultipleTypes { TemplateModel model = target.eval(env); if (model instanceof TemplateNumberModel) { TemplateNumberModel numberModel = (TemplateNumberModel) model; - Number num = _EvalUtil.modelToNumber(numberModel, target); + Number num = _EvalUtils.modelToNumber(numberModel, target); return new NumberFormatter(numberModel, env); } else if (model instanceof TemplateDateModel) { TemplateDateModel dm = (TemplateDateModel) model; @@ -688,7 +688,7 @@ class BuiltInsForMultipleTypes { return formatNumber(env, model); } else if (model instanceof TemplateBooleanModel) { return new SimpleScalar(((TemplateBooleanModel) model).getAsBoolean() - ? MiscUtil.C_TRUE : MiscUtil.C_FALSE); + ? TemplateBooleanFormat.C_TRUE : TemplateBooleanFormat.C_FALSE); } else { throw new UnexpectedTypeException( target, model,
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNodes.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNodes.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNodes.java index 5390dc4..bd01e06 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNodes.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNodes.java @@ -26,7 +26,7 @@ import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.model.TemplateNodeModel; import org.apache.freemarker.core.model.TemplateNodeModelEx; import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * A holder for builtins that operate exclusively on (XML-)node left-hand value. @@ -145,7 +145,7 @@ class BuiltInsForNodes { } } else { for (int argIdx = 0; argIdx < args.length; argIdx++) { - if (_StringUtil.matchesQName( + if (_StringUtils.matchesQName( _CallableUtils.castArgToString(args, argIdx), nodeName, nsURI, env)) { result.add(tnm); break; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNumbers.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNumbers.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNumbers.java index 58a2aa6..c197756 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNumbers.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForNumbers.java @@ -31,8 +31,8 @@ import org.apache.freemarker.core.model.TemplateNumberModel; import org.apache.freemarker.core.model.impl.SimpleDate; import org.apache.freemarker.core.model.impl.SimpleNumber; import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.util._NumberUtil; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._NumberUtils; +import org.apache.freemarker.core.util._StringUtils; /** * A holder for builtins that operate exclusively on number left-hand value. @@ -45,7 +45,7 @@ class BuiltInsForNumbers { TemplateModel calculateResult(Number num, TemplateModel model) throws TemplateModelException { final int n; try { - n = _NumberUtil.toIntExact(num); + n = _NumberUtils.toIntExact(num); } catch (ArithmeticException e) { throw new _TemplateModelException(target, "The left side operand value isn't compatible with ?", key, ": ", e.getMessage()); @@ -66,7 +66,7 @@ class BuiltInsForNumbers { @Override protected String toABC(int n) { - return _StringUtil.toLowerABC(n); + return _StringUtils.toLowerABC(n); } } @@ -75,7 +75,7 @@ class BuiltInsForNumbers { @Override protected String toABC(int n) { - return _StringUtil.toUpperABC(n); + return _StringUtils.toUpperABC(n); } } @@ -202,7 +202,7 @@ class BuiltInsForNumbers { static class is_infiniteBI extends BuiltInForNumber { @Override TemplateModel calculateResult(Number num, TemplateModel model) throws TemplateModelException { - return _NumberUtil.isInfinite(num) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; + return _NumberUtils.isInfinite(num) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } } @@ -210,7 +210,7 @@ class BuiltInsForNumbers { static class is_nanBI extends BuiltInForNumber { @Override TemplateModel calculateResult(Number num, TemplateModel model) throws TemplateModelException { - return _NumberUtil.isNaN(num) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; + return _NumberUtils.isNaN(num) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } } @@ -222,7 +222,7 @@ class BuiltInsForNumbers { TemplateModel model = target.eval(env); if (!(model instanceof TemplateNumberModel) && model instanceof TemplateDateModel) { - Date date = _EvalUtil.modelToDate((TemplateDateModel) model, target); + Date date = _EvalUtils.modelToDate((TemplateDateModel) model, target); return new SimpleNumber(date.getTime()); } else { Number num = target.modelToNumber(model, env); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForOutputFormatRelated.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForOutputFormatRelated.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForOutputFormatRelated.java index 2ae2fe7..5ab518c 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForOutputFormatRelated.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForOutputFormatRelated.java @@ -49,7 +49,7 @@ class BuiltInsForOutputFormatRelated { @Override protected TemplateModel calculateResult(Environment env) throws TemplateException { TemplateModel lhoTM = target.eval(env); - Object lhoMOOrStr = _EvalUtil.coerceModelToStringOrMarkup(lhoTM, target, null, env); + Object lhoMOOrStr = _EvalUtils.coerceModelToStringOrMarkup(lhoTM, target, null, env); MarkupOutputFormat contextOF = outputFormat; if (lhoMOOrStr instanceof String) { // TemplateMarkupOutputModel return calculateResult((String) lhoMOOrStr, contextOF, env); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForSequences.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForSequences.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForSequences.java index 6757998..f5e3253 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForSequences.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForSequences.java @@ -44,7 +44,7 @@ import org.apache.freemarker.core.model.impl.SimpleNumber; import org.apache.freemarker.core.model.impl.SimpleScalar; import org.apache.freemarker.core.model.impl.TemplateModelListSequence; import org.apache.freemarker.core.util.BugException; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * A holder for builtins that operate exclusively on sequence or collection left-hand value. @@ -215,13 +215,13 @@ class BuiltInsForSequences { hadItem = true; } try { - sb.append(_EvalUtil.coerceModelToStringOrUnsupportedMarkup(item, null, null, env)); + sb.append(_EvalUtils.coerceModelToStringOrUnsupportedMarkup(item, null, null, env)); } catch (TemplateException e) { throw new _TemplateModelException(e, "\"?", key, "\" failed at index ", idx, " with this error:\n\n", - MessageUtil.EMBEDDED_MESSAGE_BEGIN, + MessageUtils.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessageWithoutStackTop(e), - MessageUtil.EMBEDDED_MESSAGE_END); + MessageUtils.EMBEDDED_MESSAGE_END); } } idx++; @@ -716,7 +716,7 @@ class BuiltInsForSequences { startErrorMessage(keyNamesLn, i), (keyNameI == 0 ? "Sequence items must be hashes when using ?sortBy. " - : "The " + _StringUtil.jQuote(keyNames[keyNameI - 1])), + : "The " + _StringUtils.jQuote(keyNames[keyNameI - 1])), " subvariable is not a hash, so ?sortBy ", "can't proceed with getting the ", new _DelayedJQuote(keyNames[keyNameI]), @@ -728,7 +728,7 @@ class BuiltInsForSequences { if (key == null) { throw new _TemplateModelException( startErrorMessage(keyNamesLn, i), - "The " + _StringUtil.jQuote(keyNames[keyNameI]), " subvariable was null or missing."); + "The " + _StringUtils.jQuote(keyNames[keyNameI]), " subvariable was null or missing."); } } // for each key @@ -864,9 +864,9 @@ class BuiltInsForSequences { Environment env) throws TemplateModelException { try { - return _EvalUtil.compare( + return _EvalUtils.compare( seqItem, null, - _EvalUtil.CMP_OP_EQUALS, null, + _EvalUtils.CMP_OP_EQUALS, null, searchedItem, null, null, false, true, true, true, // The last one is true to emulate an old bug for BC http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java index 9311626..b7a0e93 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java @@ -32,7 +32,7 @@ import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.model.TemplateScalarModel; import org.apache.freemarker.core.model.impl.SimpleNumber; import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; class BuiltInsForStringsBasic { @@ -56,14 +56,14 @@ class BuiltInsForStringsBasic { static class capitalizeBI extends BuiltInForString { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.capitalize(s)); + return new SimpleScalar(_StringUtils.capitalize(s)); } } static class chop_linebreakBI extends BuiltInForString { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.chomp(s)); + return new SimpleScalar(_StringUtils.chomp(s)); } } @@ -504,8 +504,8 @@ class BuiltInsForStringsBasic { try { return new SimpleScalar( leftPadder - ? _StringUtil.leftPad(s, width, filling) - : _StringUtil.rightPad(s, width, filling)); + ? _StringUtils.leftPad(s, width, filling) + : _StringUtils.rightPad(s, width, filling)); } catch (IllegalArgumentException e) { if (filling.length() == 0) { throw new _TemplateModelException( @@ -516,7 +516,7 @@ class BuiltInsForStringsBasic { } } } else { - return new SimpleScalar(leftPadder ? _StringUtil.leftPad(s, width) : _StringUtil.rightPad(s, width)); + return new SimpleScalar(leftPadder ? _StringUtils.leftPad(s, width) : _StringUtils.rightPad(s, width)); } } @@ -614,7 +614,7 @@ class BuiltInsForStringsBasic { String[] result; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { RegexpHelper.checkNonRegexpFlags("split", flags); - result = _StringUtil.split(s, splitString, + result = _StringUtils.split(s, splitString, (flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) != 0); } else { Pattern pattern = RegexpHelper.getPattern(splitString, (int) flags); @@ -692,7 +692,7 @@ class BuiltInsForStringsBasic { throw newIndexGreaterThanLengthException(1, endIdx, len); } if (beginIdx > endIdx) { - throw MessageUtil.newMethodArgsInvalidValueException("?" + key, + throw MessageUtils.newMethodArgsInvalidValueException("?" + key, "The begin index argument, ", beginIdx, ", shouldn't be greater than the end index argument, ", endIdx, "."); @@ -710,7 +710,7 @@ class BuiltInsForStringsBasic { private TemplateModelException newIndexGreaterThanLengthException( int argIdx, int idx, final int len) throws TemplateModelException { - return MessageUtil.newMethodArgInvalidValueException( + return MessageUtils.newMethodArgInvalidValueException( "?" + key, argIdx, "The index mustn't be greater than the length of the string, ", len, ", but it was ", idx, "."); @@ -718,7 +718,7 @@ class BuiltInsForStringsBasic { private TemplateModelException newIndexLessThan0Exception( int argIdx, int idx) throws TemplateModelException { - return MessageUtil.newMethodArgInvalidValueException( + return MessageUtils.newMethodArgInvalidValueException( "?" + key, argIdx, "The index must be at least 0, but was ", idx, "."); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java index 794fe94..6d67d4f 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java @@ -29,7 +29,7 @@ import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.model.TemplateScalarModel; import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; class BuiltInsForStringsEncoding { @@ -37,7 +37,7 @@ class BuiltInsForStringsEncoding { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.XHTMLEnc(s)); + return new SimpleScalar(_StringUtils.XHTMLEnc(s)); } } @@ -45,28 +45,28 @@ class BuiltInsForStringsEncoding { static class j_stringBI extends BuiltInForString { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.javaStringEnc(s)); + return new SimpleScalar(_StringUtils.javaStringEnc(s)); } } static class js_stringBI extends BuiltInForString { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.javaScriptStringEnc(s)); + return new SimpleScalar(_StringUtils.javaScriptStringEnc(s)); } } static class json_stringBI extends BuiltInForString { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.jsonStringEnc(s)); + return new SimpleScalar(_StringUtils.jsonStringEnc(s)); } } static class rtfBI extends BuiltInForLegacyEscaping { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.RTFEnc(s)); + return new SimpleScalar(_StringUtils.RTFEnc(s)); } } @@ -80,7 +80,7 @@ class BuiltInsForStringsEncoding { @Override protected String encodeWithCharset(Charset charset) throws UnsupportedEncodingException { - return _StringUtil.URLEnc(targetAsString, charset); + return _StringUtils.URLEnc(targetAsString, charset); } } @@ -102,7 +102,7 @@ class BuiltInsForStringsEncoding { @Override protected String encodeWithCharset(Charset charset) throws UnsupportedEncodingException { - return _StringUtil.URLPathEnc(targetAsString, charset); + return _StringUtils.URLPathEnc(targetAsString, charset); } } @@ -117,14 +117,14 @@ class BuiltInsForStringsEncoding { static class xhtmlBI extends BuiltInForLegacyEscaping { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.XHTMLEnc(s)); + return new SimpleScalar(_StringUtils.XHTMLEnc(s)); } } static class xmlBI extends BuiltInForLegacyEscaping { @Override TemplateModel calculateResult(String s, Environment env) { - return new SimpleScalar(_StringUtil.XMLEnc(s)); + return new SimpleScalar(_StringUtils.XMLEnc(s)); } } @@ -157,7 +157,7 @@ class BuiltInsForStringsEncoding { charset = Charset.forName(charsetName); } catch (UnsupportedCharsetException e) { throw new _TemplateModelException(e, "Wrong charset name, or charset is unsupported by the runtime " - + "environment: " + _StringUtil.jQuote(charsetName)); + + "environment: " + _StringUtils.jQuote(charsetName)); } return new SimpleScalar(encodeWithCharset(charset)); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java index 1bcd592..c90f15d 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java @@ -45,9 +45,9 @@ class BuiltInsForStringsMisc { @Override TemplateModel calculateResult(String s, Environment env) throws TemplateException { final boolean b; - if (s.equals(MiscUtil.C_TRUE)) { + if (s.equals(TemplateBooleanFormat.C_TRUE)) { b = true; - } else if (s.equals(MiscUtil.C_FALSE)) { + } else if (s.equals(TemplateBooleanFormat.C_FALSE)) { b = false; } else if (s.equals(env.getTemplateBooleanFormat().getTrueStringValue())) { b = true; @@ -98,9 +98,9 @@ class BuiltInsForStringsMisc { } catch (ParseException e) { throw new _MiscTemplateException(this, env, "Failed to \"?", key, "\" string with this error:\n\n", - MessageUtil.EMBEDDED_MESSAGE_BEGIN, + MessageUtils.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessage(e), - MessageUtil.EMBEDDED_MESSAGE_END, + MessageUtils.EMBEDDED_MESSAGE_END, "\n\nThe failing expression:"); } try { @@ -108,9 +108,9 @@ class BuiltInsForStringsMisc { } catch (TemplateException e) { throw new _MiscTemplateException(this, env, "Failed to \"?", key, "\" string with this error:\n\n", - MessageUtil.EMBEDDED_MESSAGE_BEGIN, + MessageUtils.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessageWithoutStackTop(e), - MessageUtil.EMBEDDED_MESSAGE_END, + MessageUtils.EMBEDDED_MESSAGE_END, "\n\nThe failing expression:"); } } @@ -181,9 +181,9 @@ class BuiltInsForStringsMisc { } catch (IOException e) { throw new _MiscTemplateException(this, e, env, "Template parsing with \"?", key, "\" has failed with this error:\n\n", - MessageUtil.EMBEDDED_MESSAGE_BEGIN, + MessageUtils.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessage(e), - MessageUtil.EMBEDDED_MESSAGE_END, + MessageUtils.EMBEDDED_MESSAGE_END, "\n\nThe failed expression:"); } @@ -210,9 +210,9 @@ class BuiltInsForStringsMisc { } catch (Exception e) { throw new _TemplateModelException(e, "Template created with \"?", key, "\" has stopped with this error:\n\n", - MessageUtil.EMBEDDED_MESSAGE_BEGIN, + MessageUtils.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessage(e), - MessageUtil.EMBEDDED_MESSAGE_END); + MessageUtils.EMBEDDED_MESSAGE_END); } callPlace.executeNestedContent(null, out, env); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java index ef73e5f..8c75de1 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java @@ -33,7 +33,7 @@ import org.apache.freemarker.core.model.TemplateModelIterator; import org.apache.freemarker.core.model.TemplateScalarModel; import org.apache.freemarker.core.model.TemplateSequenceModel; import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** @@ -120,7 +120,7 @@ class BuiltInsForStringsRegexp { String result; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { RegexpHelper.checkNonRegexpFlags("replace", flags); - result = _StringUtil.replace(s, arg1, arg2, + result = _StringUtils.replace(s, arg1, arg2, (flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) != 0, (flags & RegexpHelper.RE_FLAG_FIRST_ONLY) != 0); } else { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsWithParseTimeParameters.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsWithParseTimeParameters.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsWithParseTimeParameters.java index 1126410..d88c2d9 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsWithParseTimeParameters.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsWithParseTimeParameters.java @@ -132,9 +132,9 @@ final class BuiltInsWithParseTimeParameters { for (int i = 0; i + 1 < paramCnt; i += 2) { ASTExpression caseExp = (ASTExpression) parameters.get(i); TemplateModel caseValue = caseExp.evalToNonMissing(env); - if (_EvalUtil.compare( + if (_EvalUtils.compare( targetValue, target, - _EvalUtil.CMP_OP_EQUALS, "==", + _EvalUtils.CMP_OP_EQUALS, "==", caseValue, caseExp, this, true, false, false, false, http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java b/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java index 3eea7b9..e817c1c 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java @@ -80,11 +80,11 @@ import org.apache.freemarker.core.templateresolver.impl.DefaultTemplateNameForma import org.apache.freemarker.core.templateresolver.impl.DefaultTemplateResolver; import org.apache.freemarker.core.templateresolver.impl.MruCacheStorage; import org.apache.freemarker.core.templateresolver.impl.SoftCacheStorage; -import org.apache.freemarker.core.util._ClassUtil; -import org.apache.freemarker.core.util._CollectionUtil; +import org.apache.freemarker.core.util._ClassUtils; +import org.apache.freemarker.core.util._CollectionUtils; import org.apache.freemarker.core.util._NullArgumentException; import org.apache.freemarker.core.util._SortedArraySet; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; import org.apache.freemarker.core.util._UnmodifiableCompositeSet; import org.apache.freemarker.core.valueformat.TemplateDateFormatFactory; import org.apache.freemarker.core.valueformat.TemplateNumberFormatFactory; @@ -340,7 +340,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc this.objectWrapper = builder.getObjectWrapper(); { - Map<String, Object> sharedVariables = _CollectionUtil.mergeImmutableMaps(builder + Map<String, Object> sharedVariables = _CollectionUtils.mergeImmutableMaps(builder .getImpliedSharedVariables(), builder.getSharedVariables(), false); HashMap<String, TemplateModel> wrappedSharedVariables = new HashMap<>( @@ -351,7 +351,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc } catch (TemplateModelException e) { throw new InvalidSettingValueException( ExtendableBuilder.SHARED_VARIABLES_KEY, null, false, - "Failed to wrap shared variable " + _StringUtil.jQuote(ent.getKey()), + "Failed to wrap shared variable " + _StringUtils.jQuote(ent.getKey()), e); } } @@ -390,13 +390,13 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc newBuiltinClassResolver = builder.getNewBuiltinClassResolver(); showErrorTips = builder.getShowErrorTips(); apiBuiltinEnabled = builder.getAPIBuiltinEnabled(); - customDateFormats = _CollectionUtil.mergeImmutableMaps( + customDateFormats = _CollectionUtils.mergeImmutableMaps( builder.getImpliedCustomDateFormats(), builder.getCustomDateFormats(), false); - customNumberFormats = _CollectionUtil.mergeImmutableMaps( + customNumberFormats = _CollectionUtils.mergeImmutableMaps( builder.getImpliedCustomNumberFormats(), builder.getCustomNumberFormats(), false); - autoImports = _CollectionUtil.mergeImmutableMaps( + autoImports = _CollectionUtils.mergeImmutableMaps( builder.getImpliedAutoImports(), builder.getAutoImports(), true); - autoIncludes = _CollectionUtil.mergeImmutableLists( + autoIncludes = _CollectionUtils.mergeImmutableLists( builder.getImpliedAutoIncludes(), builder.getAutoIncludes(), true); lazyImports = builder.getLazyImports(); lazyAutoImports = builder.getLazyAutoImports(); @@ -744,7 +744,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc if (stdOF == null) { StringBuilder sb = new StringBuilder(); sb.append("Unregistered output format name, "); - sb.append(_StringUtil.jQuote(name)); + sb.append(_StringUtils.jQuote(name)); sb.append(". The output formats registered in the Configuration are: "); Set<String> registeredNames = new TreeSet<>(); @@ -758,7 +758,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc } else { sb.append(", "); } - sb.append(_StringUtil.jQuote(registeredName)); + sb.append(_StringUtils.jQuote(registeredName)); } throw new UnregisteredOutputFormatException(sb.toString()); @@ -1358,29 +1358,29 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc TemplateLoader tl = getTemplateLoader(); String msg; if (tl == null) { - msg = "Don't know where to load template " + _StringUtil.jQuote(name) + msg = "Don't know where to load template " + _StringUtils.jQuote(name) + " from because the \"templateLoader\" FreeMarker " + "setting wasn't set (Configuration.setTemplateLoader), so it's null."; } else { final String missingTempNormName = maybeTemp.getMissingTemplateNormalizedName(); final String missingTempReason = maybeTemp.getMissingTemplateReason(); final TemplateLookupStrategy templateLookupStrategy = getTemplateLookupStrategy(); - msg = "Template not found for name " + _StringUtil.jQuote(name) + msg = "Template not found for name " + _StringUtils.jQuote(name) + (missingTempNormName != null && name != null && !removeInitialSlash(name).equals(missingTempNormName) - ? " (normalized: " + _StringUtil.jQuote(missingTempNormName) + ")" + ? " (normalized: " + _StringUtils.jQuote(missingTempNormName) + ")" : "") + (customLookupCondition != null ? " and custom lookup condition " - + _StringUtil.jQuote(customLookupCondition) : "") + + _StringUtils.jQuote(customLookupCondition) : "") + "." + (missingTempReason != null ? "\nReason given: " + ensureSentenceIsClosed(missingTempReason) : "") + "\nThe name was interpreted by this TemplateLoader: " - + _StringUtil.tryToString(tl) + "." + + _StringUtils.tryToString(tl) + "." + (!isKnownNonConfusingLookupStrategy(templateLookupStrategy) ? "\n(Before that, the name was possibly changed by this lookup strategy: " - + _StringUtil.tryToString(templateLookupStrategy) + ".)" + + _StringUtils.tryToString(templateLookupStrategy) + ".)" : "") + (missingTempReason == null && name.indexOf('\\') != -1 ? "\nWarning: The name contains backslash (\"\\\") instead of slash (\"/\"); " @@ -1613,7 +1613,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc boolean nameUnhandled = false; try { if (LOCALIZED_TEMPLATE_LOOKUP_KEY.equals(name)) { - setLocalizedTemplateLookup(_StringUtil.getYesNo(value)); + setLocalizedTemplateLookup(_StringUtils.getYesNo(value)); } else if (REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY.equals(name)) { List list = (List) _ObjectBuilderSettingEvaluator.eval( value, List.class, true, _SettingEvaluationEnvironment.getCurrent()); @@ -1630,7 +1630,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc } if (value.indexOf('.') == -1) { int strongSize = 0; int softSize = 0; - Map map = _StringUtil.parseNameValuePairList( + Map map = _StringUtils.parseNameValuePairList( value, String.valueOf(Integer.MAX_VALUE)); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { @@ -1641,7 +1641,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc pValue = Integer.parseInt((String) ent.getValue()); } catch (NumberFormatException e) { throw new InvalidSettingValueException(name, value, - "Malformed integer number (shown quoted): " + _StringUtil.jQuote(ent.getValue())); + "Malformed integer number (shown quoted): " + _StringUtils.jQuote(ent.getValue())); } if ("soft".equalsIgnoreCase(pName)) { softSize = pValue; @@ -1650,7 +1650,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc } else { throw new InvalidSettingValueException(name, value, "Unsupported cache parameter name (shown quoted): " - + _StringUtil.jQuote(ent.getValue())); + + _StringUtils.jQuote(ent.getValue())); } } if (softSize == 0 && strongSize == 0) { @@ -1683,7 +1683,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc multipier = 1000 * 60 * 60; } else if (!unit.isEmpty()) { throw new InvalidSettingValueException(name, value, - "Unrecognized time unit " + _StringUtil.jQuote(unit) + ". Valid units are: ms, s, m, h"); + "Unrecognized time unit " + _StringUtils.jQuote(unit) + ". Valid units are: ms, s, m, h"); } else { multipier = 0; } @@ -1702,7 +1702,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc if (!(key instanceof String)) { throw new InvalidSettingValueException(name, null, false, "All keys in this Map must be strings, but one of them is an instance of " - + "this class: " + _ClassUtil.getShortClassNameOfObject(key), null); + + "this class: " + _ClassUtils.getShortClassNameOfObject(key), null); } } setSharedVariables((Map) sharedVariables); @@ -2319,7 +2319,7 @@ public final class Configuration implements TopLevelConfiguration, CustomStateSc */ public void setSharedVariables(Map<String, ?> sharedVariables) { _NullArgumentException.check("sharedVariables", sharedVariables); - _CollectionUtil.safeCastMap( + _CollectionUtils.safeCastMap( "sharedVariables", sharedVariables, String.class, false, Object.class,true); this.sharedVariables = Collections.unmodifiableMap(new HashMap<>(sharedVariables)); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/CoreSettingValueNotSetException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/CoreSettingValueNotSetException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/CoreSettingValueNotSetException.java index ee7a3bc..5c5b26a 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/CoreSettingValueNotSetException.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/CoreSettingValueNotSetException.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * Thrown when you try to read a core (that is, non-custom) configuration setting which wasn't set and isn't inherited @@ -39,7 +39,7 @@ public class CoreSettingValueNotSetException extends SettingValueNotSetException } public CoreSettingValueNotSetException(String settingName, Throwable cause) { - super("The " + _StringUtil.jQuote(settingName) + " setting is not set in this layer and has no default here " + super("The " + _StringUtils.jQuote(settingName) + " setting is not set in this layer and has no default here " + "either.", cause); this.settingName = settingName; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/CustomSettingValueNotSetException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/CustomSettingValueNotSetException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/CustomSettingValueNotSetException.java index 7f427f6..4ad997e 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/CustomSettingValueNotSetException.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/CustomSettingValueNotSetException.java @@ -21,7 +21,7 @@ package org.apache.freemarker.core; import java.io.Serializable; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * Thrown by {@link ProcessingConfiguration#getCustomSetting(Serializable)} if the custom setting is not set. @@ -41,7 +41,7 @@ public class CustomSettingValueNotSetException extends SettingValueNotSetExcepti * @param key {@link ProcessingConfiguration#getCustomSetting(Serializable)} */ public CustomSettingValueNotSetException(Serializable key, Throwable cause) { - super("The " + _StringUtil.jQuote(key) + super("The " + _StringUtils.jQuote(key) + (key instanceof String ? "" : " (key class " + key.getClass().getName() + ")") + " setting is not set in this layer and has no default here either.", cause); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java b/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java index f697309..a035da5 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java @@ -64,10 +64,10 @@ import org.apache.freemarker.core.templateresolver.MalformedTemplateNameExceptio import org.apache.freemarker.core.templateresolver.TemplateResolver; import org.apache.freemarker.core.templateresolver.impl.DefaultTemplateNameFormat; import org.apache.freemarker.core.util.StringToIndexMap; -import org.apache.freemarker.core.util._DateUtil; -import org.apache.freemarker.core.util._DateUtil.DateToISO8601CalendarFactory; +import org.apache.freemarker.core.util._DateUtils; +import org.apache.freemarker.core.util._DateUtils.DateToISO8601CalendarFactory; import org.apache.freemarker.core.util._NullWriter; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; import org.apache.freemarker.core.valueformat.TemplateDateFormat; import org.apache.freemarker.core.valueformat.TemplateDateFormatFactory; import org.apache.freemarker.core.valueformat.TemplateNumberFormat; @@ -941,7 +941,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compare(leftValue, _EvalUtil.CMP_OP_EQUALS, rightValue, this); + return _EvalUtils.compare(leftValue, _EvalUtils.CMP_OP_EQUALS, rightValue, this); } /** @@ -951,7 +951,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyEqualsOperatorLenient(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compareLenient(leftValue, _EvalUtil.CMP_OP_EQUALS, rightValue, this); + return _EvalUtils.compareLenient(leftValue, _EvalUtils.CMP_OP_EQUALS, rightValue, this); } /** @@ -959,7 +959,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyLessThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compare(leftValue, _EvalUtil.CMP_OP_LESS_THAN, rightValue, this); + return _EvalUtils.compare(leftValue, _EvalUtils.CMP_OP_LESS_THAN, rightValue, this); } /** @@ -967,7 +967,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyLessThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compare(leftValue, _EvalUtil.CMP_OP_LESS_THAN_EQUALS, rightValue, this); + return _EvalUtils.compare(leftValue, _EvalUtils.CMP_OP_LESS_THAN_EQUALS, rightValue, this); } /** @@ -975,7 +975,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyGreaterThanOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compare(leftValue, _EvalUtil.CMP_OP_GREATER_THAN, rightValue, this); + return _EvalUtils.compare(leftValue, _EvalUtils.CMP_OP_GREATER_THAN, rightValue, this); } /** @@ -983,7 +983,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen */ public boolean applyWithGreaterThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) throws TemplateException { - return _EvalUtil.compare(leftValue, _EvalUtil.CMP_OP_GREATER_THAN_EQUALS, rightValue, this); + return _EvalUtils.compare(leftValue, _EvalUtils.CMP_OP_GREATER_THAN_EQUALS, rightValue, this); } public void setOut(Writer out) { @@ -1026,7 +1026,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen String s = templateBooleanFormat.getTrueStringValue(); if (s == null) { if (fallbackToTrueFalse) { - return MiscUtil.C_TRUE; + return TemplateBooleanFormat.C_TRUE; } else { throw new _MiscTemplateException(getNullBooleanFormatErrorDescription()); } @@ -1037,7 +1037,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen String s = templateBooleanFormat.getFalseStringValue(); if (s == null) { if (fallbackToTrueFalse) { - return MiscUtil.C_FALSE; + return TemplateBooleanFormat.C_FALSE; } else { throw new _MiscTemplateException(getNullBooleanFormatErrorDescription()); } @@ -1104,9 +1104,9 @@ public final class Environment extends MutableProcessingConfiguration<Environmen boolean useTempModelExc) throws TemplateException { try { - return _EvalUtil.assertFormatResultNotNull(format.formatToPlainText(number)); + return _EvalUtils.assertFormatResultNotNull(format.formatToPlainText(number)); } catch (TemplateValueFormatException e) { - throw MessageUtil.newCantFormatNumberException(format, exp, e, useTempModelExc); + throw MessageUtils.newCantFormatNumberException(format, exp, e, useTempModelExc); } } @@ -1269,7 +1269,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen TemplateNumberFormatFactory formatFactory = getCustomNumberFormat(name); if (formatFactory == null) { throw new UndefinedCustomFormatException( - "No custom number format was defined with name " + _StringUtil.jQuote(name)); + "No custom number format was defined with name " + _StringUtils.jQuote(name)); } return formatFactory.get(params, locale, this); @@ -1380,9 +1380,9 @@ public final class Environment extends MutableProcessingConfiguration<Environmen TemplateDateFormat format = getTemplateDateFormat(tdm, tdmSourceExpr, useTempModelExc); try { - return _EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); + return _EvalUtils.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { - throw MessageUtil.newCantFormatDateException(format, tdmSourceExpr, e, useTempModelExc); + throw MessageUtils.newCantFormatDateException(format, tdmSourceExpr, e, useTempModelExc); } } @@ -1395,7 +1395,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen String formatDateToPlainText(TemplateDateModel tdm, String formatString, ASTExpression blamedDateSourceExp, ASTExpression blamedFormatterExp, boolean useTempModelExc) throws TemplateException { - Date date = _EvalUtil.modelToDate(tdm, blamedDateSourceExp); + Date date = _EvalUtils.modelToDate(tdm, blamedDateSourceExp); TemplateDateFormat format = getTemplateDateFormat( formatString, tdm.getDateType(), date.getClass(), @@ -1403,9 +1403,9 @@ public final class Environment extends MutableProcessingConfiguration<Environmen useTempModelExc); try { - return _EvalUtil.assertFormatResultNotNull(format.formatToPlainText(tdm)); + return _EvalUtils.assertFormatResultNotNull(format.formatToPlainText(tdm)); } catch (TemplateValueFormatException e) { - throw MessageUtil.newCantFormatDateException(format, blamedDateSourceExp, e, useTempModelExc); + throw MessageUtils.newCantFormatDateException(format, blamedDateSourceExp, e, useTempModelExc); } } @@ -1567,7 +1567,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen TemplateDateFormat getTemplateDateFormat(TemplateDateModel tdm, ASTExpression tdmSourceExpr, boolean useTempModelExc) throws TemplateException { - Date date = _EvalUtil.modelToDate(tdm, tdmSourceExpr); + Date date = _EvalUtils.modelToDate(tdm, tdmSourceExpr); return getTemplateDateFormat( tdm.getDateType(), date.getClass(), tdmSourceExpr, @@ -1583,7 +1583,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen try { return getTemplateDateFormat(dateType, dateClass); } catch (UnknownDateTypeFormattingUnsupportedException e) { - throw MessageUtil.newCantFormatUnknownTypeDateException(blamedDateSourceExp, e); + throw MessageUtils.newCantFormatUnknownTypeDateException(blamedDateSourceExp, e); } catch (TemplateValueFormatException e) { String settingName; String settingValue; @@ -1626,7 +1626,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen try { return getTemplateDateFormat(formatString, dateType, dateClass); } catch (UnknownDateTypeFormattingUnsupportedException e) { - throw MessageUtil.newCantFormatUnknownTypeDateException(blamedDateSourceExp, e); + throw MessageUtils.newCantFormatUnknownTypeDateException(blamedDateSourceExp, e); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Can't invoke date/time/dateTime format based on format string ", @@ -1789,7 +1789,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen formatFactory = getCustomDateFormat(name); if (formatFactory == null) { throw new UndefinedCustomFormatException( - "No custom date format was defined with name " + _StringUtil.jQuote(name)); + "No custom date format was defined with name " + _StringUtils.jQuote(name)); } } else { formatParams = formatString; @@ -1833,13 +1833,13 @@ public final class Environment extends MutableProcessingConfiguration<Environmen /** * Returns the {@link DateToISO8601CalendarFactory} used by the the "iso_" built-ins. Be careful when using this; it * should only by used with - * {@link _DateUtil#dateToISO8601String(Date, boolean, boolean, boolean, int, TimeZone, DateToISO8601CalendarFactory)} - * and {@link _DateUtil#dateToXSString(Date, boolean, boolean, boolean, int, TimeZone, DateToISO8601CalendarFactory)} + * {@link _DateUtils#dateToISO8601String(Date, boolean, boolean, boolean, int, TimeZone, DateToISO8601CalendarFactory)} + * and {@link _DateUtils#dateToXSString(Date, boolean, boolean, boolean, int, TimeZone, DateToISO8601CalendarFactory)} * . */ DateToISO8601CalendarFactory getISOBuiltInCalendarFactory() { if (isoBuiltInCalendarFactory == null) { - isoBuiltInCalendarFactory = new _DateUtil.TrivialDateToISO8601CalendarFactory(); + isoBuiltInCalendarFactory = new _DateUtils.TrivialDateToISO8601CalendarFactory(); } return isoBuiltInCalendarFactory; } @@ -2114,15 +2114,15 @@ public final class Environment extends MutableProcessingConfiguration<Environmen } static void appendInstructionStackItem(ASTElement stackEl, StringBuilder sb) { - sb.append(MessageUtil.shorten(stackEl.getDescription(), 40)); + sb.append(MessageUtils.shorten(stackEl.getDescription(), 40)); sb.append(" ["); ASTDirMacroOrFunction enclosingMacro = getEnclosingMacro(stackEl); if (enclosingMacro != null) { - sb.append(MessageUtil.formatLocationForEvaluationError( + sb.append(MessageUtils.formatLocationForEvaluationError( enclosingMacro, stackEl.beginLine, stackEl.beginColumn)); } else { - sb.append(MessageUtil.formatLocationForEvaluationError( + sb.append(MessageUtils.formatLocationForEvaluationError( stackEl.getTemplate(), stackEl.beginLine, stackEl.beginColumn)); } sb.append("]"); @@ -2761,7 +2761,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen if (status == InitializationStatus.FAILED) { throw new TemplateModelException( "Lazy initialization of the imported namespace for " - + _StringUtil.jQuote(templateName) + + _StringUtils.jQuote(templateName) + " has already failed earlier; won't retry it."); } try { @@ -2772,7 +2772,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen // [FM3] Rethrow TemplateException-s as is throw new TemplateModelException( "Lazy initialization of the imported namespace for " - + _StringUtil.jQuote(templateName) + + _StringUtils.jQuote(templateName) + " has failed; see cause exception", e); } finally { if (status != InitializationStatus.INITIALIZED) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingNameException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingNameException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingNameException.java index 912619c..dd70ebb 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingNameException.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingNameException.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core; import org.apache.freemarker.core.Configuration.ExtendableBuilder; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * Thrown by {@link ExtendableBuilder#setSetting(String, String)} if the setting name was not recognized. @@ -28,12 +28,12 @@ import org.apache.freemarker.core.util._StringUtil; public class InvalidSettingNameException extends ConfigurationException { InvalidSettingNameException(String name, String correctedName) { - super("Unknown FreeMarker configuration setting: " + _StringUtil.jQuote(name) - + (correctedName == null ? "" : ". You may meant: " + _StringUtil.jQuote(correctedName))); + super("Unknown FreeMarker configuration setting: " + _StringUtils.jQuote(name) + + (correctedName == null ? "" : ". You may meant: " + _StringUtils.jQuote(correctedName))); } InvalidSettingNameException(String name, Version removedInVersion) { - super("Unknown FreeMarker configuration setting: " + _StringUtil.jQuote(name) + super("Unknown FreeMarker configuration setting: " + _StringUtils.jQuote(name) + (removedInVersion == null ? "" : ". This setting was removed in version " + removedInVersion)); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingValueException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingValueException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingValueException.java index 1acbefa..69d88c3 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingValueException.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/InvalidSettingValueException.java @@ -21,7 +21,7 @@ package org.apache.freemarker.core; import java.util.Date; import org.apache.freemarker.core.Configuration.ExtendableBuilder; -import org.apache.freemarker.core.util._StringUtil; +import org.apache.freemarker.core.util._StringUtils; /** * Thrown by {@link ExtendableBuilder#setSetting(String, String)}; The setting name was recognized, but its value @@ -65,12 +65,12 @@ public class InvalidSettingValueException extends ConfigurationException { private static String createMessage(String name, Object value, boolean showValue, String detail1, String detail2) { StringBuilder sb = new StringBuilder(64); - sb.append("Failed to set FreeMarker configuration setting ").append(_StringUtil.jQuote(name)); + sb.append("Failed to set FreeMarker configuration setting ").append(_StringUtils.jQuote(name)); if (showValue) { sb.append(" to value ") .append( value instanceof Number || value instanceof Boolean || value instanceof Date ? value - : _StringUtil.jQuote(value)); + : _StringUtils.jQuote(value)); } else { sb.append(" to the specified value"); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtil.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtil.java b/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtil.java deleted file mode 100644 index 8749fd4..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtil.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import java.util.ArrayList; - -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.util._StringUtil; -import org.apache.freemarker.core.valueformat.TemplateDateFormat; -import org.apache.freemarker.core.valueformat.TemplateNumberFormat; -import org.apache.freemarker.core.valueformat.TemplateValueFormatException; -import org.apache.freemarker.core.valueformat.UnknownDateTypeFormattingUnsupportedException; - -/** - * Utilities for creating error messages (and other messages). - */ -class MessageUtil { - - static final String UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE - = "Can't convert the date-like value to string because it isn't " - + "known if it's a date (no time part), time or date-time value."; - - static final String UNKNOWN_DATE_TYPE_ERROR_TIP = - "Use ?date, ?time, or ?dateTime to tell FreeMarker the exact type."; - - static final Object[] UNKNOWN_DATE_TO_STRING_TIPS = { - UNKNOWN_DATE_TYPE_ERROR_TIP, - "If you need a particular format only once, use ?string(pattern), like ?string('dd.MM.yyyy HH:mm:ss'), " - + "to specify which fields to display. " - }; - - static final String FM3_SNAKE_CASE = "\nThe name contains '_' character, but since FreeMarker 3 names defined " - + "by the template language use camel case (e.g. someExampleName)."; - - static final String EMBEDDED_MESSAGE_BEGIN = "---begin-message---\n"; - - static final String EMBEDDED_MESSAGE_END = "\n---end-message---"; - - static final String ERROR_MESSAGE_HR = "----"; - - // Can't be instantiated - private MessageUtil() { } - - static String formatLocationForSimpleParsingError(Template template, int line, int column) { - return formatLocation("in", template, line, column); - } - - static String formatLocationForSimpleParsingError(String templateSourceOrLookupName, int line, int column) { - return formatLocation("in", templateSourceOrLookupName, line, column); - } - - static String formatLocationForEvaluationError(Template template, int line, int column) { - return formatLocation("at", template, line, column); - } - - static String formatLocationForEvaluationError(ASTDirMacroOrFunction macro, int line, int column) { - Template t = macro.getTemplate(); - return formatLocation("at", t != null ? t.getSourceOrLookupName() : null, macro.getName(), macro.isFunction(), - line, column); - } - - private static String formatLocation(String preposition, Template template, int line, int column) { - return formatLocation(preposition, template != null ? template.getSourceOrLookupName() : null, line, column); - } - - private static String formatLocation(String preposition, String templateSourceName, int line, int column) { - return formatLocation( - preposition, templateSourceName, - null, false, - line, column); - } - - private static String formatLocation( - String preposition, String templateSourceName, - String macroOrFuncName, boolean isFunction, - int line, int column) { - String templateDesc; - if (line < 0) { - templateDesc = "?eval-ed string"; - macroOrFuncName = null; - } else { - templateDesc = templateSourceName != null - ? "template " + _StringUtil.jQuoteNoXSS(templateSourceName) - : "nameless template"; - } - return "in " + templateDesc - + (macroOrFuncName != null - ? " in " + (isFunction ? "function " : "macro ") + _StringUtil.jQuote(macroOrFuncName) - : "") - + " " - + preposition + " " + formatPosition(line, column); - } - - static String formatPosition(int line, int column) { - return "line " + (line >= 0 ? line : line - (ASTNode.RUNTIME_EVAL_LINE_DISPLACEMENT - 1)) - + ", column " + column; - } - - /** - * Returns a single line string that is no longer than {@code maxLength}. - * If will truncate the string at line-breaks too. - * The truncation is always signaled with a a {@code "..."} at the end of the result string. - */ - static String shorten(String s, int maxLength) { - if (maxLength < 5) maxLength = 5; - - boolean isTruncated = false; - - int brIdx = s.indexOf('\n'); - if (brIdx != -1) { - s = s.substring(0, brIdx); - isTruncated = true; - } - brIdx = s.indexOf('\r'); - if (brIdx != -1) { - s = s.substring(0, brIdx); - isTruncated = true; - } - - if (s.length() > maxLength) { - s = s.substring(0, maxLength - 3); - isTruncated = true; - } - - if (!isTruncated) { - return s; - } else { - if (s.endsWith(".")) { - if (s.endsWith("..")) { - if (s.endsWith("...")) { - return s; - } else { - return s + "."; - } - } else { - return s + ".."; - } - } else { - return s + "..."; - } - } - } - - static StringBuilder appendExpressionAsUntearable(StringBuilder sb, ASTExpression argExp) { - boolean needParen = - !(argExp instanceof ASTExpNumberLiteral) - && !(argExp instanceof ASTExpStringLiteral) - && !(argExp instanceof ASTExpBooleanLiteral) - && !(argExp instanceof ASTExpListLiteral) - && !(argExp instanceof ASTExpHashLiteral) - && !(argExp instanceof ASTExpVariable) - && !(argExp instanceof ASTExpDot) - && !(argExp instanceof ASTExpDynamicKeyName) - && !(argExp instanceof ASTExpFunctionCall) - && !(argExp instanceof ASTExpBuiltIn); - if (needParen) sb.append('('); - sb.append(argExp.getCanonicalForm()); - if (needParen) sb.append(')'); - return sb; - } - - static TemplateModelException newArgCntError(String methodName, int argCnt, int expectedCnt) { - return newArgCntError(methodName, argCnt, expectedCnt, expectedCnt); - } - - static TemplateModelException newArgCntError(String methodName, int argCnt, int minCnt, int maxCnt) { - ArrayList/*<Object>*/ desc = new ArrayList(20); - - desc.add(methodName); - - desc.add("("); - if (maxCnt != 0) desc.add("..."); - desc.add(") expects "); - - if (minCnt == maxCnt) { - if (maxCnt == 0) { - desc.add("no"); - } else { - desc.add(Integer.valueOf(maxCnt)); - } - } else if (maxCnt - minCnt == 1) { - desc.add(Integer.valueOf(minCnt)); - desc.add(" or "); - desc.add(Integer.valueOf(maxCnt)); - } else { - desc.add(Integer.valueOf(minCnt)); - if (maxCnt != Integer.MAX_VALUE) { - desc.add(" to "); - desc.add(Integer.valueOf(maxCnt)); - } else { - desc.add(" or more (unlimited)"); - } - } - desc.add(" argument"); - if (maxCnt > 1) desc.add("s"); - - desc.add(" but has received "); - if (argCnt == 0) { - desc.add("none"); - } else { - desc.add(Integer.valueOf(argCnt)); - } - desc.add("."); - - return new _TemplateModelException(desc.toArray()); - } - - static TemplateModelException newMethodArgMustBeStringException(String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "string", arg); - } - - static TemplateModelException newMethodArgMustBeNumberException(String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "number", arg); - } - - static TemplateModelException newMethodArgMustBeBooleanException(String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "boolean", arg); - } - - static TemplateModelException newMethodArgMustBeExtendedHashException( - String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "extended hash", arg); - } - - static TemplateModelException newMethodArgMustBeSequenceException( - String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "sequence", arg); - } - - static TemplateModelException newMethodArgMustBeSequenceOrCollectionException( - String methodName, int argIdx, TemplateModel arg) { - return newMethodArgUnexpectedTypeException(methodName, argIdx, "sequence or collection", arg); - } - - static TemplateModelException newMethodArgUnexpectedTypeException( - String methodName, int argIdx, String expectedType, TemplateModel arg) { - return new _TemplateModelException( - methodName, "(...) expects ", new _DelayedAOrAn(expectedType), " as argument #", Integer.valueOf(argIdx + 1), - ", but received ", new _DelayedAOrAn(new _DelayedFTLTypeDescription(arg)), "."); - } - - /** - * The type of the argument was good, but it's value wasn't. - */ - static TemplateModelException newMethodArgInvalidValueException( - String methodName, int argIdx, Object... details) { - return new _TemplateModelException( - methodName, "(...) argument #", Integer.valueOf(argIdx + 1), - " had invalid value: ", details); - } - - /** - * The type of the argument was good, but the values of two or more arguments are inconsistent with each other. - */ - static TemplateModelException newMethodArgsInvalidValueException( - String methodName, Object... details) { - return new _TemplateModelException(methodName, "(...) arguments have invalid value: ", details); - } - - static TemplateException newInstantiatingClassNotAllowedException(String className, Environment env) { - return new _MiscTemplateException(env, - "Instantiating ", className, " is not allowed in the template for security reasons."); - } - - static TemplateModelException newCantFormatUnknownTypeDateException( - ASTExpression dateSourceExpr, UnknownDateTypeFormattingUnsupportedException cause) { - return new _TemplateModelException(cause, null, new _ErrorDescriptionBuilder( - MessageUtil.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) - .blame(dateSourceExpr) - .tips(MessageUtil.UNKNOWN_DATE_TO_STRING_TIPS)); - } - - static TemplateException newCantFormatDateException(TemplateDateFormat format, ASTExpression dataSrcExp, - TemplateValueFormatException e, boolean useTempModelExc) { - _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( - "Failed to format date/time/dateTime with format ", new _DelayedJQuote(format.getDescription()), ": ", - e.getMessage()) - .blame(dataSrcExp); - return useTempModelExc - ? new _TemplateModelException(e, null, desc) - : new _MiscTemplateException(e, null, desc); - } - - static TemplateException newCantFormatNumberException(TemplateNumberFormat format, ASTExpression dataSrcExp, - TemplateValueFormatException e, boolean useTempModelExc) { - _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( - "Failed to format number with format ", new _DelayedJQuote(format.getDescription()), ": ", - e.getMessage()) - .blame(dataSrcExp); - return useTempModelExc - ? new _TemplateModelException(e, null, desc) - : new _MiscTemplateException(e, null, desc); - } - - /** - * @return "a" or "an" or "a(n)" (or "" for empty string) for an FTL type name - */ - static String getAOrAn(String s) { - if (s == null) return null; - if (s.length() == 0) return ""; - - char fc = Character.toLowerCase(s.charAt(0)); - if (fc == 'a' || fc == 'e' || fc == 'i') { - return "an"; - } else if (fc == 'h') { - String ls = s.toLowerCase(); - if (ls.startsWith("has") || ls.startsWith("hi")) { - return "a"; - } else if (ls.startsWith("ht")) { - return "an"; - } else { - return "a(n)"; - } - } else if (fc == 'u' || fc == 'o') { - return "a(n)"; - } else { - char sc = (s.length() > 1) ? s.charAt(1) : '\0'; - if (fc == 'x' && !(sc == 'a' || sc == 'e' || sc == 'i' || sc == 'a' || sc == 'o' || sc == 'u')) { - return "an"; - } else { - return "a"; - } - } - } - -}