http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/OverloadedMethods2.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/OverloadedMethods2.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/OverloadedMethods2.java deleted file mode 100644 index 4e80e71..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/OverloadedMethods2.java +++ /dev/null @@ -1,1110 +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.test.templatesuite.models; - -import java.io.File; -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.model.AdapterTemplateModel; -import org.apache.freemarker.core.model.ObjectWrapper; -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.model.TemplateNumberModel; -import org.apache.freemarker.core.model.WrapperTemplateModel; -import org.apache.freemarker.core.model.impl.RationalNumber; -import org.apache.freemarker.core.util._StringUtil; -import org.apache.freemarker.test.TestUtil; - -public class OverloadedMethods2 { - - public String mVarargs(String... a1) { - StringBuilder sb = new StringBuilder(); - for (String s : a1) { - sb.append(s); - } - return "mVarargs(String... a1 = " + sb + ")"; - } - - public BigInteger bigInteger(BigDecimal n) { - return n.toBigInteger(); - } - - public RationalNumber rational(int a, int b) { - return new RationalNumber(a, b); - } - - public String mVarargs(File a1, String... a2) { - return "mVarargs(File a1, String... a2)"; - } - - public NumberAndStringModel getNnS(String s) { - return new NumberAndStringModel(s); - } - - public String mNull1(String a1) { - return "mNull1(String a1 = " + a1 + ")"; - } - - public String mNull1(int a1) { - return "mNull1(int a1 = " + a1 + ")"; - } - - public String mNull2(String a1) { - return "mNull2(String a1 = " + a1 + ")"; - } - - public String mNull2(Object a1) { - return "mNull2(Object a1 = " + a1 + ")"; - } - - public String mSpecificity(Object a1, String a2) { - return "mSpecificity(Object a1, String a2)"; - } - - public String mSpecificity(String a1, Object a2) { - return "mSpecificity(String a1, Object a2)"; - } - - public String mChar(char a1) { - return "mChar(char a1 = " + a1 + ")"; - } - - public String mChar(Character a1) { - return "mChar(Character a1 = " + a1 + ")"; - } - - public String mBoolean(boolean a1) { - return "mBoolean(boolean a1 = " + a1 + ")"; - } - - public String mBoolean(Boolean a1) { - return "mBoolean(Boolean a1 = " + a1 + ")"; - } - - public int mIntNonOverloaded(int a1) { - return a1; - } - - public String mIntPrimVSBoxed(int a1) { - return "mIntPrimVSBoxed(int a1 = " + a1 + ")"; - } - - public String mIntPrimVSBoxed(Integer a1) { - return "mIntPrimVSBoxed(Integer a1 = " + a1 + ")"; - } - - public String mNumPrimVSPrim(short a1) { - return "mNumPrimVSPrim(short a1 = " + a1 + ")"; - } - - public String mNumPrimVSPrim(long a1) { - return "mNumPrimVSPrim(long a1 = " + a1 + ")"; - } - - public String mNumBoxedVSBoxed(Short a1) { - return "mNumBoxedVSBoxed(Short a1 = " + a1 + ")"; - } - - public String mNumBoxedVSBoxed(Long a1) { - return "mNumBoxedVSBoxed(Long a1 = " + a1 + ")"; - } - - public String mNumUnambigous(Short a1, boolean otherOverload) { - return "mmNumUnambigous won't be called"; - } - - public String mNumUnambigous(Integer a1) { - return "mNumUnambigous(Integer a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Byte a1) { - return "mNumBoxedAll(Byte a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Short a1) { - return "mNumBoxedAll(Short a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Integer a1) { - return "mNumBoxedAll(Integer a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Long a1) { - return "mNumBoxedAll(Long a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Float a1) { - return "mNumBoxedAll(Float a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(Double a1) { - return "mNumBoxedAll(Double a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(BigInteger a1) { - return "mNumBoxedAll(BigInteger a1 = " + a1 + ")"; - } - - public String mNumBoxedAll(BigDecimal a1) { - return "mNumBoxedAll(BigDecimal a1 = " + a1 + ")"; - } - - public String mNumPrimAll(byte a1) { - return "mNumPrimAll(byte a1 = " + a1 + ")"; - } - - public String mNumPrimAll(short a1) { - return "mNumPrimAll(short a1 = " + a1 + ")"; - } - - public String mNumPrimAll(int a1) { - return "mNumPrimAll(int a1 = " + a1 + ")"; - } - - public String mNumPrimAll(long a1) { - return "mNumPrimAll(long a1 = " + a1 + ")"; - } - - public String mNumPrimAll(float a1) { - return "mNumPrimAll(float a1 = " + a1 + ")"; - } - - public String mNumPrimAll(double a1) { - return "mNumPrimAll(double a1 = " + a1 + ")"; - } - - public String mNumPrimAll(BigInteger a1) { - return "mNumPrimAll(BigInteger a1 = " + a1 + ")"; - } - - public String mNumPrimAll(BigDecimal a1) { - return "mNumPrimAll(BigDecimal a1 = " + a1 + ")"; - } - - - public String mNumBoxedAll2nd(Short a1) { - return "mNumBoxedAll2nd(Short a1 = " + a1 + ")"; - } - - public String mNumBoxedAll2nd(Long a1) { - return "mNumBoxedAll2nd(Long a1 = " + a1 + ")"; - } - - public String mNumBoxedAll2nd(Double a1) { - return "mNumBoxedAll2nd(Double a1 = " + a1 + ")"; - } - - public String mNumPrimAll2nd(short a1) { - return "mNumPrimAll2nd(short a1 = " + a1 + ")"; - } - - public String mNumPrimAll2nd(long a1) { - return "mNumPrimAll2nd(long a1 = " + a1 + ")"; - } - - public String mNumPrimAll2nd(double a1) { - return "mNumPrimAll2nd(double a1 = " + a1 + ")"; - } - - public String mNumPrimFallbackToNumber(long a1) { - return "mNumPrimFallbackToNumber(long a1 = " + a1 + ")"; - } - - public String mNumPrimFallbackToNumber(Number a1) { - return "mNumPrimFallbackToNumber(Number a1 = " + a1 + ")"; - } - - public String mNumPrimFallbackToNumber(Object a1) { - return "mNumPrimFallbackToNumber(Object a1 = " + a1 + ")"; - } - - public String mNumBoxedFallbackToNumber(Long a1) { - return "mNumBoxedFallbackToNumber(Long a1 = " + a1 + ")"; - } - - public String mNumBoxedFallbackToNumber(Number a1) { - return "mNumBoxedFallbackToNumber(Number a1 = " + a1 + ")"; - } - - public String mNumBoxedFallbackToNumber(Object a1) { - return "mNumBoxedFallbackToNumber(Object a1 = " + a1 + ")"; - } - - public String mDecimalLoss(int a1) { - return "mDecimalLoss(int a1 = " + a1 + ")"; - } - - public String mDecimalLoss(double a1) { - return "mDecimalLoss(double a1 = " + a1 + ")"; - } - - public String mNumConversionLoses1(byte i, Object o1, Object o2) { - return "byte " + i; - } - - public String mNumConversionLoses1(double i, Object o1, Object o2) { - return "double " + i; - } - - public String mNumConversionLoses1(Number i, String o1, String o2) { - return "Number " + i + " " + i.getClass().getName(); - } - - public String mNumConversionLoses2(int i, Object o1, Object o2) { - return "int " + i; - } - - public String mNumConversionLoses2(long i, Object o1, Object o2) { - return "long " + i; - } - - public String mNumConversionLoses2(Number i, String o1, String o2) { - return "Number " + i + " " + i.getClass().getName(); - } - - public String mNumConversionLoses3(int i, Object o1, Object o2) { - return "int " + i; - } - - public String mNumConversionLoses3(Serializable i, String o1, String o2) { - return "Serializable " + i + " " + i.getClass().getName(); - } - - public String nIntAndLong(int i) { - return "nIntAndLong(int " + i + ")"; - } - - public String nIntAndLong(long i) { - return "nIntAndLong(long " + i + ")"; - } - - public String nIntAndShort(int i) { - return "nIntAndShort(int " + i + ")"; - } - - public String nIntAndShort(short i) { - return "nIntAndShort(short " + i + ")"; - } - - public String nLongAndShort(long i) { - return "nLongAndShort(long " + i + ")"; - } - - public String nLongAndShort(short i) { - return "nLongAndShort(short " + i + ")"; - } - - public String varargs1(String s, int... xs) { - return "varargs1(String s = " + _StringUtil.jQuote(s) + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs1(String s, double... xs) { - return "varargs1(String s = " + _StringUtil.jQuote(s) + ", double... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs1(String s, Object... xs) { - return "varargs1(String s = " + _StringUtil.jQuote(s) + ", Object... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs1(Object s, Object... xs) { - return "varargs1(Object s = " + s + ", Object... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs2(int... xs) { - return "varargs2(int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs2(double... xs) { - return "varargs2(double... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs3(String... xs) { - return "varargs3(String... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs3(Comparable... xs) { - return "varargs3(Comparable... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs3(Object... xs) { - return "varargs3(Object... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs4(Integer... xs) { - return "varargs4(Integer... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs4(int... xs) { - return "varargs4(int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs5(int... xs) { - return "varargs5(int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs5(int a1, int... xs) { - return "varargs5(int a1 = " + a1 + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs5(int a1, int a2, int... xs) { - return "varargs5(int a1 = " + a1 + ", int a2 = " + a2 + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs5(int a1, int a2, int a3, int... xs) { - return "varargs5(int a1 = " + a1 + ", int a2 = " + a2 + ", int a3 = " + a3 - + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs6(String a1, int... xs) { - return "varargs6(String a1 = " + a1 + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs6(Object a1, int a2, int... xs) { - return "varargs6(Object a1 = " + a1 + ", int a2 = " + a2 + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs7(int... xs) { - return "varargs7(int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String varargs7(short a1, int... xs) { - return "varargs7(short a1 = " + a1 + ", int... xs = " + TestUtil.arrayToString(xs) + ")"; - } - - public String mNullAmbiguous(String s) { - return "mNullAmbiguous(String s = " + s + ")"; - } - - public String mNullAmbiguous(int i) { - return "mNullAmbiguous(int i = " + i + ")"; - } - - public String mNullAmbiguous(File f) { - return "mNullAmbiguous(File f = " + f + ")"; - } - - public String mNullAmbiguous2(String s) { - return "mNullNonAmbiguous(String s = " + s + ")"; - } - - public String mNullAmbiguous2(File f) { - return "mNullAmbiguous(File f = " + f + ")"; - } - - public String mNullAmbiguous2(Object o) { - return "mNullAmbiguous(Object o = " + o + ")"; - } - - public String mNullNonAmbiguous(String s) { - return "mNullNonAmbiguous(String s = " + s + ")"; - } - - public String mNullNonAmbiguous(int i) { - return "mNullNonAmbiguous(int i = " + i + ")"; - } - - public String mVarargsIgnoredTail(int i, double... ds) { - return "mVarargsIgnoredTail(int i = " + i + ", double... ds = " + TestUtil.arrayToString(ds) + ")"; - } - - public String mVarargsIgnoredTail(int... is) { - return "mVarargsIgnoredTail(int... is = " + TestUtil.arrayToString(is) + ")"; - } - - public String mLowRankWins(int x, int y, Object o) { - return "mLowRankWins(int x = " + x + ", int y = " + y + ", Object o = " + o + ")"; - } - - public String mLowRankWins(Integer x, Integer y, String s) { - return "mLowRankWins(Integer x = " + x + ", Integer y = " + y + ", String s = " + s + ")"; - } - - public String mRareWrappings(File f, double d1, Double d2, double d3, boolean b) { - return "mRareWrappings(File f = " + f + ", double d1 = " + d1 + ", Double d2 = " + d2 - + ", double d3 = " + d3 + ", b = " + b + ")"; - } - - public String mRareWrappings(Object o, double d1, Double d2, Double d3, boolean b) { - return "mRareWrappings(Object o = " + o + ", double d1 = " + d1 + ", Double d2 = " + d2 - + ", double d3 = " + d3 + ", b = " + b + ")"; - } - - public String mRareWrappings(String s, double d1, Double d2, Double d3, boolean b) { - return "mRareWrappings(String s = " + s + ", double d1 = " + d1 + ", Double d2 = " + d2 - + ", double d3 = " + d3 + ", b = " + b + ")"; - } - - public String mRareWrappings2(String s) { - return "mRareWrappings2(String s = " + s + ")"; - } - - public String mRareWrappings2(byte b) { - return "mRareWrappings2(byte b = " + b + ")"; - } - - public File getFile() { - return new File("file"); - } - - public String mSeqToArrayNonOverloaded(String[] items, String s) { - return "mSeqToArrayNonOverloaded(String[] " + TestUtil.arrayToString(items) + ", String " + s + ")"; - } - - public String mSeqToArrayGoodHint(String[] items, String s) { - return "mSeqToArrayGoodHint(String[] " + TestUtil.arrayToString(items) + ", String " + s + ")"; - } - - public String mSeqToArrayGoodHint(String[] items, int i) { - return "mSeqToArrayGoodHint(String[] " + TestUtil.arrayToString(items) + ", int " + i + ")"; - } - - public String mSeqToArrayGoodHint2(String[] items, String s) { - return "mSeqToArrayGoodHint2(String[] " + TestUtil.arrayToString(items) + ", String " + s + ")"; - } - - public String mSeqToArrayGoodHint2(String item) { - return "mSeqToArrayGoodHint2(String " + item + ")"; - } - - public String mSeqToArrayPoorHint(String[] items, String s) { - return "mSeqToArrayPoorHint(String[] " + TestUtil.arrayToString(items) + ", String " + s + ")"; - } - - public String mSeqToArrayPoorHint(String item, int i) { - return "mSeqToArrayPoorHint(String " + item + ", int " + i + ")"; - } - - public String mSeqToArrayPoorHint2(String[] items) { - return "mSeqToArrayPoorHint2(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mSeqToArrayPoorHint2(String item) { - return "mSeqToArrayPoorHint2(String " + item + ")"; - } - - public String mSeqToArrayPoorHint3(String[] items) { - return "mSeqToArrayPoorHint3(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mSeqToArrayPoorHint3(int[] items) { - return "mSeqToArrayPoorHint3(int[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVsListPreference(String[] items) { - return "mStringArrayVsListPreference(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVsListPreference(List items) { - return "mStringArrayVsListPreference(List " + TestUtil.listToString(items) + ")"; - } - - public String mStringArrayVsObjectArrayPreference(String[] items) { - return "mStringArrayVsObjectArrayPreference(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVsObjectArrayPreference(Object[] items) { - return "mStringArrayVsObjectArrayPreference(Object[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntArrayVsIntegerArrayPreference(int[] items) { - return "mIntArrayVsIntegerArrayPreference(int[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntArrayVsIntegerArrayPreference(Integer[] items) { - return "mIntArrayVsIntegerArrayPreference(Integer[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntArrayNonOverloaded(int[] items) { - return "mIntArrayNonOverloaded(int[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntegerArrayNonOverloaded(Integer[] items) { - return "mIntegerArrayNonOverloaded(Integer[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntegerListNonOverloaded(List<Integer> items) { - return "mIntegerListNonOverloaded(List<Integer> " + items + ")"; - } - - public String mStringListNonOverloaded(List<String> items) { - return "mStringListNonOverloaded(List<String> " + items + ")"; - } - - public String mStringArrayNonOverloaded(String[] items) { - return "mStringArrayNonOverloaded(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mObjectListNonOverloaded(List<Object> items) { - return "mObjectListNonOverloaded(List<Object> " + items + ")"; - } - - public String mObjectArrayNonOverloaded(Object[] items) { - return "mObjectArrayNonOverloaded(Object[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mIntegerArrayOverloaded(Integer[] items, int i) { - return "mIntegerArrayOverloaded(Integer[] " + TestUtil.arrayToString(items) + ", int " + i + ")"; - } - - public String mIntegerArrayOverloaded(Object obj, boolean b) { - return "mIntegerArrayOverloaded(Object " + obj + ", boolean " + b + ")"; - } - - public String mStringArrayOverloaded(String[] items, int i) { - return "mStringArrayOverloaded(String[] " + TestUtil.arrayToString(items) + ", int " + i + ")"; - } - - public String mStringArrayOverloaded(Object obj, boolean b) { - return "mStringArrayOverloaded(Object " + obj + ", boolean " + b + ")"; - } - - public String mCharArrayOverloaded(char[] items, int i) { - return "mCharArrayOverloaded(char[] " + TestUtil.arrayToString(items) + ", int " + i + ")"; - } - - public String mCharArrayOverloaded(Character[] items, String s) { - return "mCharArrayOverloaded(Character[] " + TestUtil.arrayToString(items) + ", String " + s + ")"; - } - - public String mCharArrayOverloaded(Object obj, boolean b) { - return "mCharArrayOverloaded(Object " + obj + ", boolean " + b + ")"; - } - - public String mStringArrayArrayOverloaded(String[][] arrayArray, int i) { - return "mStringArrayArrayOverloaded(String[][] " + TestUtil.arrayToString(arrayArray) + ", int " + i + ")"; - } - - public String mStringArrayArrayOverloaded(Object obj, boolean b) { - return "mStringArrayArrayOverloaded(Object " + obj + ", boolean " + b + ")"; - } - - public String mIntArrayArrayOverloaded(int[][] xss) { - return "mIntArrayArrayOverloaded(" + TestUtil.arrayToString(xss) + ")"; - } - - public String mIntArrayArrayOverloaded(String s) { - return "mIntArrayArrayOverloaded(" + s + ")"; - } - - public String mArrayOfListsOverloaded(List[] xss) { - return "mArrayOfListsOverloaded(" + TestUtil.arrayToString(xss) + ")"; - } - - public String mArrayOfListsOverloaded(String x) { - return "mArrayOfListsOverloaded(" + x + ")"; - } - - public String mIntArrayArrayNonOverloaded(int[][] xss) { - return "mIntArrayArrayNonOverloaded(" + TestUtil.arrayToString(xss) + ")"; - } - - public String mArrayOfListsNonOverloaded(List[] xss) { - return "mArrayOfListsNonOverloaded(" + TestUtil.arrayToString(xss) + ")"; - } - - public String mStringArrayVarargsNonOverloaded(String... items) { - return "mStringArrayVarargsNonOverloaded(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded(String... items) { - return "mStringArrayVarargsNonOverloaded(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded1(String... items) { - return "mStringArrayVarargsOverloaded1(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded1(List<String> items) { - return "mStringArrayVarargsOverloaded1(List " + TestUtil.listToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded2(String... items) { - return "mStringArrayVarargsOverloaded2(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded2(String item) { - return "mStringArrayVarargsOverloaded2(String " + item + ")"; - } - - public String mStringArrayVarargsOverloaded3(String... items) { - return "mStringArrayVarargsOverloaded3(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded3(String item1, String item2) { - return "mStringArrayVarargsOverloaded3(String " + item1 + ", String " + item2 + ")"; - } - - public String mStringArrayVarargsOverloaded4(String... items) { - return "mStringArrayVarargsOverloaded4(String[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mStringArrayVarargsOverloaded4(List... items) { - return "mStringArrayVarargsOverloaded4(List[] " + TestUtil.arrayToString(items) + ")"; - } - - public String mListOrString(List<String> items) { - return "mListOrString(List " + TestUtil.listToString(items) + ")"; - } - - public String mListOrString(String item) { - return "mListOrString(String " + item + ")"; - } - - public String mListListOrString(List<List<Object>> items) { - return "mListListOrString(List " + TestUtil.listToString(items) + ")"; - } - - public String mListListOrString(String item) { - return "mListListOrString(String " + item + ")"; - } - - public String mMapOrBoolean(Map v) { - return "mMapOrBoolean(Map " + v + ")"; - } - - public String mMapOrBoolean(boolean v) { - return "mMapOrBoolean(boolean " + v + ")"; - } - - public String mMapOrBooleanVarargs(Map... v) { - return "mMapOrBooleanVarargs(Map... " + TestUtil.arrayToString(v) + ")"; - } - - public String mMapOrBooleanVarargs(boolean... v) { - return "mMapOrBooleanVarargs(boolean... " + TestUtil.arrayToString(v) + ")"; - } - - public String mMapOrBooleanFixedAndVarargs(Map v) { - return "mMapOrBooleanFixedAndVarargs(Map " + v + ")"; - } - - public String mMapOrBooleanFixedAndVarargs(boolean v) { - return "mMapOrBooleanFixedAndVarargs(boolean " + v + ")"; - } - - public String mMapOrBooleanFixedAndVarargs(Map... v) { - return "mMapOrBooleanFixedAndVarargs(Map... " + TestUtil.arrayToString(v) + ")"; - } - - public String mMapOrBooleanFixedAndVarargs(boolean... v) { - return "mMapOrBooleanFixedAndVarargs(boolean... " + TestUtil.arrayToString(v) + ")"; - } - - public String mNumberOrArray(Number v) { - return "mNumberOrArray(Number " + v + ")"; - } - - public String mNumberOrArray(Object[] v) { - return "mNumberOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mIntOrArray(int v) { - return "mIntOrArray(int " + v + ")"; - } - - public String mIntOrArray(Object[] v) { - return "mIntOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mDateOrArray(Date v) { - return "mDateOrArray(Date " + v.getTime() + ")"; - } - - public String mDateOrArray(Object[] v) { - return "mDateOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mStringOrArray(String v) { - return "mStringOrArray(String " + v + ")"; - } - - public String mStringOrArray(Object[] v) { - return "mStringOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mBooleanOrArray(boolean v) { - return "mBooleanOrArray(boolean " + v + ")"; - } - - public String mBooleanOrArray(Object[] v) { - return "mBooleanOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mMapOrArray(Map v) { - return "mMapOrArray(Map " + v + ")"; - } - - public String mMapOrArray(Object[] v) { - return "mMapOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mListOrArray(List v) { - return "mListOrArray(List " + v + ")"; - } - - public String mListOrArray(Object[] v) { - return "mListOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mSetOrArray(Set v) { - return "mSetOrArray(Set " + v + ")"; - } - - public String mSetOrArray(Object[] v) { - return "mSetOrArray(Object[] " + TestUtil.arrayToString(v) + ")"; - } - - public String mCharNonOverloaded(char c) { - return "mCharNonOverloaded(char " + c + ")"; - } - - public String mCharacterNonOverloaded(Character c) { - return "mCharacterNonOverloaded(Character " + c + ")"; - } - - public String mCharOrCharacterOverloaded(char c) { - return "mCharOrCharacterOverloaded(char " + c + ")"; - } - - public String mCharOrCharacterOverloaded(Character c) { - return "mCharOrCharacterOverloaded(Character " + c + ")"; - } - - public String mCharOrBooleanOverloaded(char c) { - return "mCharOrBooleanOverloaded(char " + c + ")"; - } - - public String mCharOrBooleanOverloaded(boolean b) { - return "mCharOrBooleanOverloaded(boolean " + b + ")"; - } - - public String mCharOrStringOverloaded(char c, boolean b) { - return "mCharOrStringOverloaded(char " + c + ", boolean " + b + ")"; - } - - public String mCharOrStringOverloaded(String s, int i) { - return "mCharOrStringOverloaded(String " + s + ", int " + i + ")"; - } - - public String mCharacterOrStringOverloaded(Character c, boolean b) { - return "mCharacterOrStringOverloaded(Character " + c + ", boolean " + b + ")"; - } - - public String mCharacterOrStringOverloaded(String s, int i) { - return "mCharacterOrStringOverloaded(String " + s + ", int " + i + ")"; - } - - public String mCharOrStringOverloaded2(String s) { - return "mCharOrStringOverloaded2(String " + s + ")"; - } - - public String mCharOrStringOverloaded2(char c) { - return "mCharOrStringOverloaded2(char " + c + ")"; - } - - public String mCharacterOrStringOverloaded2(String s) { - return "mCharacterOrStringOverloaded2(String " + s + ")"; - } - - public String mCharacterOrStringOverloaded2(Character c) { - return "mCharacterOrStringOverloaded2(Character " + c + ")"; - } - - - public String getJavaString() { - return "s"; - } - - public List getJavaStringList() { - List list = new ArrayList(); - list.add("a"); - list.add("b"); - return list; - } - - public List getJavaString2List() { - List list = new ArrayList(); - list.add("aa"); - list.add("bb"); - return list; - } - - public List getJavaStringListList() { - List listList = new ArrayList(); - { - List list = new ArrayList(); - list.add("a"); - list.add("b"); - - listList.add(list); - } - { - List list = new ArrayList(); - list.add("c"); - - listList.add(list); - } - return listList; - } - - public List getJavaStringSequenceList() throws TemplateModelException { - ObjectWrapper ow = Environment.getCurrentEnvironment().getObjectWrapper(); - - List listList = new ArrayList(); - { - List list = new ArrayList(); - list.add("a"); - list.add("b"); - - listList.add(ow.wrap(list)); - } - { - List list = new ArrayList(); - list.add("c"); - - listList.add(ow.wrap(list)); - } - return listList; - } - - public List<int[]> getJavaListOfIntArrays() { - List list = new ArrayList(); - list.add(new int[] {1, 2, 3}); - list.add(new int[] {}); - list.add(new int[] {4}); - return list; - } - - @SuppressWarnings("boxing") - public List getJavaIntegerListList() { - List listList = new ArrayList(); - { - List list = new ArrayList(); - list.add(1); - list.add(2); - - listList.add(list); - } - { - List list = new ArrayList(); - list.add(3); - - listList.add(list); - } - return listList; - } - - @SuppressWarnings("boxing") - public List<Integer> getJavaIntegerList() { - List<Integer> list = new ArrayList<>(); - list.add(1); - list.add(2); - return list; - } - - @SuppressWarnings("boxing") - public List<Byte> getJavaByteList() { - List<Byte> list = new ArrayList<>(); - list.add((byte) 1); - list.add((byte) 2); - return list; - } - - @SuppressWarnings("boxing") - public List<Character> getJavaCharacterList() { - List<Character> list = new ArrayList<>(); - list.add('c'); - list.add('C'); - return list; - } - - public String[] getJavaStringArray() { - return new String[] { "a", "b" }; - } - - public int[] getJavaIntArray() { - return new int[] { 11, 22 }; - } - - public Integer[] getJavaIntegerArray() { - return new Integer[] { Integer.valueOf(11), Integer.valueOf(22) }; - } - - public String[] getJavaEmptyStringArray() { - return new String[] { }; - } - - public String[][] getJavaStringArrayArray() { - return new String[][] { new String[] { "a", "b" }, new String[] { }, new String[] { "c" } }; - } - - public Object[] getJavaObjectArray() { - return new Object[] { "a", "b" }; - } - - public TemplateModel getHashAndScalarModel() { - return HashAndScalarModel.INSTANCE; - } - - public TemplateModel getBooleanAndScalarModel() { - return BooleanAndScalarModel.INSTANCE; - } - - public TemplateModel getAllModels() { - return AllTemplateModels.INSTANCE; - } - - public TemplateNumberModel getAdaptedNumber() { - return new MyAdapterNumberModel(); - } - - public TemplateNumberModel getWrapperNumber() { - return new MyWrapperNumberModel(); - } - - public TemplateBooleanModel getStringAdaptedToBoolean() { - return new MyStringAdaptedToBooleanModel(); - } - - public TemplateBooleanModel getStringAdaptedToBoolean2() { - return new MyStringAdaptedToBooleanModel2(); - } - - public TemplateBooleanModel getStringWrappedAsBoolean() { - return new MyStringWrapperAsBooleanModel(); - } - - public TemplateBooleanModel getBooleanWrappedAsAnotherBoolean() { - return new MyBooleanWrapperAsAnotherBooleanModel(); - } - - public String bugReport363(Map<String, ?> fields, List<?> listField) { - return "Executed: testMethod(Map fields, List listField) on input: fields=" + fields - + " and listField=" + listField; - } - - public String bugReport363(Object... fields) { - return "Executed: testMethod(Object... fields) on input: fields=" + TestUtil.arrayToString(fields); - } - - private static class MyAdapterNumberModel implements TemplateNumberModel, AdapterTemplateModel { - - @Override - public Object getAdaptedObject(Class hint) { - if (hint == double.class) { - return Double.valueOf(123.0001); - } else if (hint == Double.class) { - return Double.valueOf(123.0002); - } else { - return Long.valueOf(124L); - } - } - - @Override - public Number getAsNumber() throws TemplateModelException { - return Integer.valueOf(122); - } - - } - - private static class MyWrapperNumberModel implements TemplateNumberModel, WrapperTemplateModel { - - @Override - public Number getAsNumber() throws TemplateModelException { - return Integer.valueOf(122); - } - - @Override - public Object getWrappedObject() { - return Double.valueOf(123.0001); - } - - } - - private static class MyStringWrapperAsBooleanModel implements TemplateBooleanModel, WrapperTemplateModel { - - @Override - public Object getWrappedObject() { - return "yes"; - } - - @Override - public boolean getAsBoolean() throws TemplateModelException { - return true; - } - - } - - private static class MyBooleanWrapperAsAnotherBooleanModel implements TemplateBooleanModel, WrapperTemplateModel { - - @Override - public Object getWrappedObject() { - return Boolean.TRUE; - } - - @Override - public boolean getAsBoolean() throws TemplateModelException { - return false; - } - - } - - private static class MyStringAdaptedToBooleanModel implements TemplateBooleanModel, AdapterTemplateModel { - - @Override - public Object getAdaptedObject(Class hint) { - if (hint != Boolean.class && hint != boolean.class) { - return "yes"; - } else { - return Boolean.TRUE; - } - } - - @Override - public boolean getAsBoolean() throws TemplateModelException { - return false; - } - - } - - private static class MyStringAdaptedToBooleanModel2 implements TemplateBooleanModel, AdapterTemplateModel { - - @Override - public Object getAdaptedObject(Class hint) { - return "yes"; - } - - @Override - public boolean getAsBoolean() throws TemplateModelException { - return true; - } - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/SimpleTestMethod.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/SimpleTestMethod.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/SimpleTestMethod.java deleted file mode 100644 index 85e27d7..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/SimpleTestMethod.java +++ /dev/null @@ -1,49 +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.test.templatesuite.models; - -import java.util.List; - -import org.apache.freemarker.core.model.TemplateMethodModel; -import org.apache.freemarker.core.model.impl.SimpleScalar; - -/** - * A simple method model used as a test bed. - */ -public class SimpleTestMethod implements TemplateMethodModel { - - /** - * Executes a method call. - * - * @param arguments a <tt>List</tt> of <tt>String</tt> objects containing - * the values of the arguments passed to the method. - * @return the <tt>TemplateModel</tt> produced by the method, or null. - */ - @Override - public Object exec(List arguments) { - if ( arguments.size() == 0 ) { - return new SimpleScalar( "Empty list provided" ); - } else if ( arguments.size() > 1 ) { - return new SimpleScalar( "Argument size is: " + arguments.size() ); - } else { - return new SimpleScalar( "Single argument value is: " + arguments.get(0) ); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformHashWrapper.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformHashWrapper.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformHashWrapper.java deleted file mode 100644 index 4602b67..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformHashWrapper.java +++ /dev/null @@ -1,79 +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.test.templatesuite.models; - -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.model.ObjectWrapper; -import org.apache.freemarker.core.model.TemplateHashModel; -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.DefaultObjectWrapper; -import org.apache.freemarker.core.model.impl.SimpleHash; -import org.apache.freemarker.core.util.HtmlEscape; -import org.apache.freemarker.core.util.StandardCompress; - -/** - * Part of the TestTransform testcase suite. - */ -public class TransformHashWrapper implements TemplateHashModel, - TemplateScalarModel { - - private ObjectWrapper ow = new DefaultObjectWrapper.Builder(Configuration.VERSION_3_0_0).build(); - private SimpleHash m_cHashModel = new SimpleHash(ow); - - /** Creates new TransformHashWrapper */ - public TransformHashWrapper() { - m_cHashModel.put( "htmlEscape", new HtmlEscape() ); - m_cHashModel.put( "compress", new StandardCompress() ); - m_cHashModel.put( "escape", new TransformMethodWrapper1() ); - m_cHashModel.put( "special", new TransformMethodWrapper2() ); - } - - /** - * Gets a <tt>TemplateModel</tt> from the hash. - * - * @param key the name by which the <tt>TemplateModel</tt> - * is identified in the template. - * @return the <tt>TemplateModel</tt> referred to by the key, - * or null if not found. - */ - @Override - public TemplateModel get(String key) throws TemplateModelException { - return m_cHashModel.get( key ); - } - - /** - * @return true if this object is empty. - */ - @Override - public boolean isEmpty() { - return false; - } - - /** - * Returns the scalar's value as a String. - * @return the String value of this scalar. - */ - @Override - public String getAsString() { - return "Utility transformations"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper1.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper1.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper1.java deleted file mode 100644 index 8311134..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper1.java +++ /dev/null @@ -1,49 +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.test.templatesuite.models; - -import java.util.List; - -import org.apache.freemarker.core.model.TemplateMethodModel; -import org.apache.freemarker.core.util.HtmlEscape; -import org.apache.freemarker.core.util.XmlEscape; - -/** - * Simple test of the interaction between MethodModels and TransformModels. - */ -public class TransformMethodWrapper1 implements TemplateMethodModel { - - /** - * Executes a method call. - * - * @param arguments a <tt>List</tt> of <tt>String</tt> objects containing - * the values of the arguments passed to the method. - * @return the <tt>TemplateModel</tt> produced by the method, or null. - */ - @Override - public Object exec(List arguments) { - - if (( arguments.size() > 0 ) && ( arguments.get( 0 ).toString().equals( "xml" ))) { - return new XmlEscape(); - } else { - return new HtmlEscape(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper2.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper2.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper2.java deleted file mode 100644 index 96eb1a5..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformMethodWrapper2.java +++ /dev/null @@ -1,64 +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.test.templatesuite.models; - -import java.util.Iterator; -import java.util.List; - -import org.apache.freemarker.core.model.TemplateMethodModel; - -/** - * Another test of the interaction between MethodModels and TransformModels. - */ -public class TransformMethodWrapper2 implements TemplateMethodModel { - - /** - * Executes a method call. - * - * @param arguments a <tt>List</tt> of <tt>String</tt> objects containing - * the values of the arguments passed to the method. - * @return the <tt>TemplateModel</tt> produced by the method, or null. - */ - @Override - public Object exec(List arguments) { - TransformModel1 cTransformer = new TransformModel1(); - Iterator iArgument = arguments.iterator(); - - // Sets up properties of the Transform model based on the arguments - // passed into this method - - while ( iArgument.hasNext() ) { - String aArgument = (String) iArgument.next(); - - if ( aArgument.equals( "quote" )) { - cTransformer.setQuotes( true ); - } else if ( aArgument.equals( "tag" )) { - cTransformer.setTags( true ); - } else if ( aArgument.equals( "ampersand" )) { - cTransformer.setAmpersands( true ); - } else { - cTransformer.setComment( aArgument ); - } - } - - // Now return the transform class. - return cTransformer; - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformModel1.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformModel1.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformModel1.java deleted file mode 100644 index 0875679..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/TransformModel1.java +++ /dev/null @@ -1,175 +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.test.templatesuite.models; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Map; - -import org.apache.freemarker.core.model.TemplateTransformModel; - -/** - * A TemplateTransformModel that includes properties. These properties can be - * set at model construction time, or, for the purposes of this demonstration, - * can be passed in from a wrapper TemplateMethodModel. - */ -public class TransformModel1 implements TemplateTransformModel { - - private boolean m_bAmpersands = false; - private boolean m_bQuotes = false; - private boolean m_bTags = false; - private String m_aComment = ""; - - private static final int READER_BUFFER_SIZE = 4096; - - @Override - public Writer getWriter(final Writer out, - final Map args) { - final StringBuilder buf = new StringBuilder(); - return new Writer(out) { - @Override - public void write(char cbuf[], int off, int len) { - buf.append(cbuf, off, len); - } - - @Override - public void flush() { - } - - @Override - public void close() throws IOException { - StringReader sr = new StringReader(buf.toString()); - StringWriter sw = new StringWriter(); - transform(sr, sw); - out.write(sw.toString()); - } - }; - } - - - /** - * Indicates whether we escape ampersands. This property can be set either - * while the model is being constructed, or via a property passed in through - * a <code>TemplateMethodModel</code>. - */ - public void setAmpersands( boolean bAmpersands ) { - m_bAmpersands = bAmpersands; - } - - /** - * Indicates whether we escape quotes. This property can be set either - * while the model is being constructed, or via a property passed in through - * a <code>TemplateMethodModel</code>. - */ - public void setQuotes( boolean bQuotes ) { - m_bQuotes = bQuotes; - } - - /** - * Indicates whether we escape tags. This property can be set either - * while the model is being constructed, or via a property passed in through - * a <code>TemplateMethodModel</code>. - */ - public void setTags( boolean bTags ) { - m_bTags = bTags; - } - - /** - * Sets a comment for this transformation. This property can be set either - * while the model is being constructed, or via a property passed in through - * a <code>TemplateMethodModel</code>. - */ - public void setComment( String aComment ) { - m_aComment = aComment; - } - - /** - * Performs a transformation/filter on FreeMarker output. - * - * @param source the input to be transformed - * @param output the destination of the transformation - */ - public void transform(Reader source, Writer output) - throws IOException { - // Output the source, converting unsafe certain characters to their - // equivalent entities. - int n = 0; - boolean bCommentSent = false; - char[] aBuffer = new char[ READER_BUFFER_SIZE ]; - int i = source.read( aBuffer ); - while (i >= 0) { - for ( int j = 0; j < i; j++ ) { - char c = aBuffer[j]; - switch (c) { - case '&': - if ( m_bAmpersands ) { - output.write("&"); - } else { - output.write( c ); - } - break; - case '<': - if ( m_bTags ) { - output.write("<"); - } else { - output.write( c ); - } - break; - case '>': - if ( m_bTags ) { - output.write(">"); - } else { - output.write( c ); - } - break; - case '"': - if ( m_bQuotes ) { - output.write("""); - } else { - output.write( c ); - } - break; - case '\'': - if ( m_bQuotes ) { - output.write("'"); - } else { - output.write( c ); - } - break; - case '*': - if ( ! bCommentSent ) { - output.write( m_aComment ); - bCommentSent = true; - } else { - output.write( c ); - } - break; - default: - output.write(c); - } - n++; - } - i = source.read( aBuffer ); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/VarArgTestModel.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/VarArgTestModel.java b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/VarArgTestModel.java deleted file mode 100644 index 940cb17..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/models/VarArgTestModel.java +++ /dev/null @@ -1,63 +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.test.templatesuite.models; - -import java.util.Date; - -public class VarArgTestModel { - - public int bar(Integer... xs) { - int sum = 0; - for (Integer x : xs) { - if (x != null) { - sum *= 100; - sum += x; - } - } - return sum; - } - - public int bar2(int first, int... xs) { - int sum = 0; - for (int x : xs) { - sum *= 100; - sum += x; - } - return -(sum * 100 + first); - } - - public int overloaded(int x, int y) { - return x * 100 + y; - } - - public int overloaded(int... xs) { - int sum = 0; - for (int x : xs) { - sum *= 100; - sum += x; - } - return -sum; - } - - public String noVarArgs(String s, boolean b, int i, Date d) { - return s + ", " + b + ", " + i + ", " + d.getTime(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/package.html ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/package.html b/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/package.html deleted file mode 100644 index cabffb0..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/templatesuite/package.html +++ /dev/null @@ -1,42 +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. ---> -<html> -<head> -</head> -<body> - -<p>JUnit test-suite that processes FreeMarker templates and compare their -output to reference files.</p> - -<p>To add a test-case, go to -<tt>src/test/resources/freemarker/test/templatesuite/</tt> and inside that -directory:</p> -<ol> - <li>Add a template to under <tt>templates/</tt> with whatever meaningful - file name</li> - <li>Add the expected output to <tt>references/</tt> with exactly the same - file name</li> - <li>Add a new <tt>testcase</tt> elemen to <tt>testcases.xml</tt></li> - <li>If you want to add items to the data-model or do something else special, - modify the <tt>setUp()</tt> method in - <tt>src/test/java/freemarker/test/templatesuite/TemplateTestCase.java</tt> - </li> -</ol> -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertDirective.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertDirective.java deleted file mode 100644 index 8f31680..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertDirective.java +++ /dev/null @@ -1,73 +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.test.util; - -import java.io.IOException; -import java.util.Map; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.NestedContentNotSupportedException; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateDirectiveBody; -import org.apache.freemarker.core.model.TemplateDirectiveModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.util.FTLUtil; - -public class AssertDirective implements TemplateDirectiveModel { - - public static AssertDirective INSTANCE = new AssertDirective(); - - private static final String TEST_PARAM = "test"; - - private AssertDirective() { } - - @Override - public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) - throws TemplateException, IOException { - TemplateModel test = null; - for (Object paramEnt : params.entrySet()) { - Map.Entry<String, TemplateModel> param = (Map.Entry) paramEnt; - String paramName = param.getKey(); - if (paramName.equals(TEST_PARAM)) { - test = param.getValue(); - } else { - throw new UnsupportedParameterException(paramName, env); - } - } - if (test == null) { - throw new MissingRequiredParameterException(TEST_PARAM, env); - } - NestedContentNotSupportedException.check(body); - - if (!(test instanceof TemplateBooleanModel)) { - throw new AssertationFailedInTemplateException("Assertion failed:\n" - + "The value had to be boolean, but it was of type" + FTLUtil.getTypeDescription(test), - env); - } - if (!((TemplateBooleanModel) test).getAsBoolean()) { - throw new AssertationFailedInTemplateException("Assertion failed:\n" - + "the value was false.", - env); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertEqualsDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertEqualsDirective.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertEqualsDirective.java deleted file mode 100644 index 63a9ebc..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertEqualsDirective.java +++ /dev/null @@ -1,91 +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.test.util; - -import java.io.IOException; -import java.util.Map; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.NestedContentNotSupportedException; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateDateModel; -import org.apache.freemarker.core.model.TemplateDirectiveBody; -import org.apache.freemarker.core.model.TemplateDirectiveModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.model.TemplateNumberModel; -import org.apache.freemarker.core.model.TemplateScalarModel; -import org.apache.freemarker.core.util._StringUtil; - -public class AssertEqualsDirective implements TemplateDirectiveModel { - - public static AssertEqualsDirective INSTANCE = new AssertEqualsDirective(); - - private static final String ACTUAL_PARAM = "actual"; - private static final String EXPECTED_PARAM = "expected"; - - private AssertEqualsDirective() { } - - @Override - public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) - throws TemplateException, IOException { - TemplateModel actual = null; - TemplateModel expected = null; - for (Object paramEnt : params.entrySet()) { - Map.Entry<String, TemplateModel> param = (Map.Entry) paramEnt; - String paramName = param.getKey(); - if (paramName.equals(ACTUAL_PARAM)) { - actual = param.getValue(); - } else if (paramName.equals(EXPECTED_PARAM)) { - expected = param.getValue(); - } else { - throw new UnsupportedParameterException(paramName, env); - } - } - if (actual == null) { - throw new MissingRequiredParameterException(ACTUAL_PARAM, env); - } - if (expected == null) { - throw new MissingRequiredParameterException(EXPECTED_PARAM, env); - } - NestedContentNotSupportedException.check(body); - - if (!env.applyEqualsOperatorLenient(actual, expected)) { - throw new AssertationFailedInTemplateException("Assertion failed:\n" - + "Expected: " + tryUnwrapp(expected) + "\n" - + "Actual: " + tryUnwrapp(actual), - env); - } - - } - - private String tryUnwrapp(TemplateModel value) throws TemplateModelException { - if (value == null) return "null"; - // This is the same order as comparison goes: - else if (value instanceof TemplateNumberModel) return ((TemplateNumberModel) value).getAsNumber().toString(); - else if (value instanceof TemplateDateModel) return ((TemplateDateModel) value).getAsDate().toString(); - else if (value instanceof TemplateScalarModel) return _StringUtil.jQuote(((TemplateScalarModel) value).getAsString()); - else if (value instanceof TemplateBooleanModel) return String.valueOf(((TemplateBooleanModel) value).getAsBoolean()); - // This shouldn't be reached, as the comparison should have failed earlier: - else return value.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertFailsDirective.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertFailsDirective.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertFailsDirective.java deleted file mode 100644 index bd18d8d..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertFailsDirective.java +++ /dev/null @@ -1,152 +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.test.util; - -import java.io.IOException; -import java.util.Map; -import java.util.regex.Pattern; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.TemplateException; -import org.apache.freemarker.core.model.TemplateDirectiveBody; -import org.apache.freemarker.core.model.TemplateDirectiveModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.model.TemplateNumberModel; -import org.apache.freemarker.core.model.TemplateScalarModel; -import org.apache.freemarker.core.util._NullWriter; -import org.apache.freemarker.core.util._StringUtil; - -public class AssertFailsDirective implements TemplateDirectiveModel { - - public static AssertFailsDirective INSTANCE = new AssertFailsDirective(); - - private static final String MESSAGE_PARAM = "message"; - private static final String MESSAGE_REGEXP_PARAM = "messageRegexp"; - private static final String EXCEPTION_PARAM = "exception"; - private static final String CAUSE_NESTING_LEVEL_PARAM = "causeNestingLevel"; - - private AssertFailsDirective() { } - - @Override - public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) - throws TemplateException, IOException { - String message = null; - Pattern messageRegexp = null; - String exception = null; - int causeNestingLevel = 0; - for (Object paramEnt : params.entrySet()) { - Map.Entry<String, TemplateModel> param = (Map.Entry) paramEnt; - String paramName = param.getKey(); - if (paramName.equals(MESSAGE_PARAM)) { - message = getAsString(param.getValue(), MESSAGE_PARAM, env); - } else if (paramName.equals(MESSAGE_REGEXP_PARAM)) { - messageRegexp = Pattern.compile( - getAsString(param.getValue(), MESSAGE_REGEXP_PARAM, env), - Pattern.CASE_INSENSITIVE); - } else if (paramName.equals(EXCEPTION_PARAM)) { - exception = getAsString(param.getValue(), EXCEPTION_PARAM, env); - } else if (paramName.equals(CAUSE_NESTING_LEVEL_PARAM)) { - causeNestingLevel = getAsInt(param.getValue(), CAUSE_NESTING_LEVEL_PARAM, env); - } else { - throw new UnsupportedParameterException(paramName, env); - } - } - - if (body != null) { - boolean blockFailed; - try { - body.render(_NullWriter.INSTANCE); - blockFailed = false; - } catch (Throwable e) { - blockFailed = true; - - int causeNestingLevelCountDown = causeNestingLevel; - while (causeNestingLevelCountDown != 0) { - e = e.getCause(); - if (e == null) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected: The cause exception nesting dept was lower than " - + causeNestingLevel + ".", - env); - } - causeNestingLevelCountDown--; - } - - if (message != null || messageRegexp != null) { - if (e.getMessage() == null) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception message was null, " - + "and thus it doesn't contain:\n" + _StringUtil.jQuote(message) + ".", - env); - } - if (message != null) { - String actualMessage = e instanceof TemplateException - ? ((TemplateException) e).getMessageWithoutStackTop() : e.getMessage(); - if (actualMessage.toLowerCase().indexOf(message.toLowerCase()) == -1) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception message:\n" + _StringUtil.jQuote(actualMessage) - + "\ndoesn't contain:\n" + _StringUtil.jQuote(message) + ".", - env); - } - } - if (messageRegexp != null) { - if (!messageRegexp.matcher(e.getMessage()).find()) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception message:\n" + _StringUtil.jQuote(e.getMessage()) - + "\ndoesn't match this regexp:\n" + _StringUtil.jQuote(messageRegexp.toString()) - + ".", - env); - } - } - } - if (exception != null && e.getClass().getName().indexOf(exception) == -1) { - throw new AssertationFailedInTemplateException( - "Failure is not like expected. The exception class name " + _StringUtil.jQuote(e.getClass().getName()) - + " doesn't contain " + _StringUtil.jQuote(message) + ".", - env); - } - } - if (!blockFailed) { - throw new AssertationFailedInTemplateException( - "Block was expected to fail, but it didn't.", - env); - } - } - } - - private String getAsString(TemplateModel value, String paramName, Environment env) - throws BadParameterTypeException, TemplateModelException { - if (value instanceof TemplateScalarModel) { - return ((TemplateScalarModel) value).getAsString(); - } else { - throw new BadParameterTypeException(paramName, "string", value, env); - } - } - - private int getAsInt(TemplateModel value, String paramName, Environment env) throws BadParameterTypeException, TemplateModelException { - if (value instanceof TemplateNumberModel) { - return ((TemplateNumberModel) value).getAsNumber().intValue(); - } else { - throw new BadParameterTypeException(paramName, "number", value, env); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertationFailedInTemplateException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertationFailedInTemplateException.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertationFailedInTemplateException.java deleted file mode 100644 index 7a65c42..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/AssertationFailedInTemplateException.java +++ /dev/null @@ -1,46 +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.test.util; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.TemplateException; - -/** - * Fills the role of {@link junit.framework.AssertionFailedError}, but carries the template location information. - */ -public class AssertationFailedInTemplateException extends TemplateException { - - public AssertationFailedInTemplateException(Environment env) { - super(env); - } - - public AssertationFailedInTemplateException(String description, Environment env) { - super(description, env); - } - - public AssertationFailedInTemplateException(Exception cause, Environment env) { - super(cause, env); - } - - public AssertationFailedInTemplateException(String description, Exception cause, Environment env) { - super(description, cause, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/BadParameterTypeException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/BadParameterTypeException.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/BadParameterTypeException.java deleted file mode 100644 index f1230be..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/BadParameterTypeException.java +++ /dev/null @@ -1,60 +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.test.util; - -import org.apache.freemarker.core.Environment; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.util._StringUtil; - -/** - * Indicates that a named directive/function parameter is not of the expected type. - * This is will be public and go into the org.apache.freemarker.core.ast when the directive/method stuff was reworked. - */ -public class BadParameterTypeException extends ParameterException { - - public BadParameterTypeException(String parameterName, String expectedType, TemplateModel value, Environment env) { - this(parameterName, expectedType, value, null, null, env); - } - - public BadParameterTypeException(String parameterName, String expectedType, TemplateModel value, - Exception cause, Environment env) { - this(parameterName, expectedType, value, null, cause, env); - } - - public BadParameterTypeException(String parameterName, String expectedType, TemplateModel value, - String description, Environment env) { - this(parameterName, expectedType, value, description, null, env); - } - - public BadParameterTypeException( - String parameterName, String expectedType, TemplateModel value, String description, Exception cause, Environment env) { - super(parameterName, - "The type of the parameter " + _StringUtil.jQuote(parameterName) + " should be " + expectedType - + ", but the actual value was " + getTypeDescription(value) + "." - + (description != null ? " " + _StringUtil.jQuote(description) : ""), - cause, env); - } - - private static String getTypeDescription(TemplateModel value) { - //FIXME: This should call EvaluationUtil.getTypeDescriptionForDebugging, but that's not visible from here yet. - return value == null ? "Null" : value.getClass().getName(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/CoreTestUtil.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/CoreTestUtil.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/CoreTestUtil.java deleted file mode 100644 index d9770fc..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/CoreTestUtil.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apache.freemarker.test.util; - -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.Version; - -public final class CoreTestUtil { - - private CoreTestUtil() { - // Not meant to be instantiated - } - - /** - * Returns the closes FreeMarker version number that doesn't exit yet (so it's illegal). - */ - public static Version getClosestFutureVersion() { - Version v = Configuration.getVersion(); - return new Version(v.getMajor(), v.getMinor(), v.getMicro() + 1); - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/test/util/EntirelyCustomObjectWrapper.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/test/util/EntirelyCustomObjectWrapper.java b/freemarker-core/src/test/java/org/apache/freemarker/test/util/EntirelyCustomObjectWrapper.java deleted file mode 100644 index cdcde1f..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/test/util/EntirelyCustomObjectWrapper.java +++ /dev/null @@ -1,91 +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.test.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -import org.apache.freemarker.core.model.ObjectWrapper; -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateDateModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateModelAdapter; -import org.apache.freemarker.core.model.TemplateModelException; -import org.apache.freemarker.core.model.impl.DefaultObjectWrapper; -import org.apache.freemarker.core.model.impl.SimpleDate; -import org.apache.freemarker.core.model.impl.SimpleHash; -import org.apache.freemarker.core.model.impl.SimpleNumber; -import org.apache.freemarker.core.model.impl.SimpleScalar; -import org.apache.freemarker.core.model.impl.SimpleSequence; - -/** - * An object wrapper that doesn't extend {@link DefaultObjectWrapper}. - */ -public class EntirelyCustomObjectWrapper implements ObjectWrapper { - - @Override - public TemplateModel wrap(Object obj) throws TemplateModelException { - if (obj == null) { - return null; - } - - if (obj instanceof TemplateModel) { - return (TemplateModel) obj; - } - if (obj instanceof TemplateModelAdapter) { - return ((TemplateModelAdapter) obj).getTemplateModel(); - } - - if (obj instanceof String) { - return new SimpleScalar((String) obj); - } - if (obj instanceof Number) { - return new SimpleNumber((Number) obj); - } - if (obj instanceof Boolean) { - return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; - } - if (obj instanceof java.util.Date) { - if (obj instanceof java.sql.Date) { - return new SimpleDate((java.sql.Date) obj); - } - if (obj instanceof java.sql.Time) { - return new SimpleDate((java.sql.Time) obj); - } - if (obj instanceof java.sql.Timestamp) { - return new SimpleDate((java.sql.Timestamp) obj); - } - return new SimpleDate((java.util.Date) obj, TemplateDateModel.UNKNOWN); - } - - if (obj.getClass().isArray()) { - obj = Arrays.asList((Object[]) obj); - } - if (obj instanceof Collection) { - return new SimpleSequence((Collection<?>) obj, this); - } - if (obj instanceof Map) { - return new SimpleHash((Map<?, ?>) obj, this); - } - - return null; - } -}
