1 52 53 package freemarker.core; 54 55 import freemarker.template.SimpleScalar; 56 import freemarker.template.TemplateModel; 57 import freemarker.template.TemplateScalarModel; 58 import freemarker.template.TemplateSequenceModel; 59 60 68 public class StringArraySequence implements TemplateSequenceModel { 69 private String [] stringArray; 70 private TemplateScalarModel[] array; 71 72 75 public StringArraySequence(String [] stringArray) { 76 this.stringArray = stringArray; 77 } 78 79 public TemplateModel get(int index) { 80 if (array == null) { 81 array = new TemplateScalarModel[stringArray.length]; 82 } 83 TemplateScalarModel result = array[index]; 84 if (result == null) { 85 result = new SimpleScalar(stringArray[index]); 86 array[index] = result; 87 } 88 return result; 89 } 90 91 public int size() { 92 return stringArray.length; 93 } 94 } 95 | Popular Tags |