2021SC@SDUSC
**内容非常主观,可能出现错漏,慎重参考
此部分是_DelayedConversionToString以及其子类,对各类string进行处理。
_DelayedConversionToString.java
package freemarker.core; public abstract class _DelayedConversionToString { private static final String NOT_SET = new String(); private Object object; private volatile String stringValue = NOT_SET; public _DelayedConversionToString(Object object) { this.object = object; } @Override public String toString() { String stringValue = this.stringValue; if (stringValue == NOT_SET) { synchronized (this) { stringValue = this.stringValue; if (stringValue == NOT_SET) { stringValue = doConversion(object); this.stringValue = stringValue; this.object = null; } } } return stringValue; } protected abstract String doConversion(Object obj); }
_DelayedConversionToString重写了toString方法,当stringValue未设定值时,使全局变量stringValue = this.stringValue。
_DelayedAOrAn.java
package freemarker.core; public class _DelayedAOrAn extends _DelayedConversionToString { public _DelayedAOrAn(Object object) { super(object); } @Override protected String doConversion(Object obj) { String s = obj.toString(); return _MessageUtil.getAOrAn(s) + " " + s; } }
_DelayedAOrAn是_DelayedConversionToString的子类
_DelayedFTLTypeDescription.java
package freemarker.core; import freemarker.template.TemplateModel; import freemarker.template.utility.ClassUtil; public class _DelayedFTLTypeDescription extends _DelayedConversionToString { public _DelayedFTLTypeDescription(TemplateModel tm) { super(tm); } @Override protected String doConversion(Object obj) { return ClassUtil.getFTLTypeDescription((TemplateModel) obj); } }
_DelayedFTLTypeDescription是_DelayedConversionToString的子类,对TemplateModel进行处理
_DelayedGetCanonicalForm.java
package freemarker.core; public class _DelayedGetCanonicalForm extends _DelayedConversionToString { public _DelayedGetCanonicalForm(TemplateObject obj) { super(obj); } @Override protected String doConversion(Object obj) { try { return ((TemplateObject) obj).getCanonicalForm(); } catch (Exception e) { return "{Error getting canonical form}"; } } }
_DelayedGetCanonicalForm是_DelayedConversionToString的子类,
_DelayedGetMessage.java
package freemarker.core; public class _DelayedGetMessage extends _DelayedConversionToString { public _DelayedGetMessage(Throwable exception) { super(exception); } @Override protected String doConversion(Object obj) { final String message = ((Throwable) obj).getMessage(); return message == null || message.length() == 0 ? "[No exception message]" : message; } }
_DelayedGetMessageWithoutStackTop.java
package freemarker.core; import freemarker.template.TemplateException; public class _DelayedGetMessageWithoutStackTop extends _DelayedConversionToString { public _DelayedGetMessageWithoutStackTop(TemplateException exception) { super(exception); } @Override protected String doConversion(Object obj) { return ((TemplateException) obj).getMessageWithoutStackTop(); } }
_DelayedJoinWithComma.java
package freemarker.core; public class _DelayedJoinWithComma extends _DelayedConversionToString { public _DelayedJoinWithComma(String[] items) { super(items); } @Override protected String doConversion(Object obj) { String[] items = (String[]) obj; int totalLength = 0; for (int i = 0; i < items.length; i++) { if (i != 0) totalLength += 2; totalLength += items[i].length(); } StringBuilder sb = new StringBuilder(totalLength); for (int i = 0; i < items.length; i++) { if (i != 0) sb.append(", "); sb.append(items[i]); } return sb.toString(); } }
_DelayedJQuote.java
package freemarker.core; import freemarker.template.utility.StringUtil; public class _DelayedJQuote extends _DelayedConversionToString { public _DelayedJQuote(Object object) { super(object); } @Override protected String doConversion(Object obj) { return StringUtil.jQuote(_ErrorDescriptionBuilder.toString(obj)); } }
_DelayedOrdinal.java
package freemarker.core; public class _DelayedOrdinal extends _DelayedConversionToString { public _DelayedOrdinal(Object object) { super(object); } @Override protected String doConversion(Object obj) { if (obj instanceof Number) { long n = ((Number) obj).longValue(); if (n % 10 == 1 && n % 100 != 11) { return n + "st"; } else if (n % 10 == 2 && n % 100 != 12) { return n + "nd"; } else if (n % 10 == 3 && n % 100 != 13) { return n + "rd"; } else { return n + "th"; } } else { return "" + obj; } } }
_DelayedShortClassName.java
package freemarker.core; import freemarker.template.utility.ClassUtil; public class _DelayedShortClassName extends _DelayedConversionToString { public _DelayedShortClassName(Class pClass) { super(pClass); } @Override protected String doConversion(Object obj) { return ClassUtil.getShortClassName((Class) obj, true); } }
_DelayedToString.java
package freemarker.core; public class _DelayedToString extends _DelayedConversionToString { public _DelayedToString(Object object) { super(object); } public _DelayedToString(int object) { super(Integer.valueOf(object)); } @Override protected String doConversion(Object obj) { return String.valueOf(obj); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)