1 52 53 package freemarker.testcase.models; 54 55 import freemarker.template.*; 56 57 62 public class MultiModel1 implements TemplateHashModel, 63 TemplateSequenceModel, TemplateScalarModel { 64 65 private TemplateModel m_cSubModel = new MultiModel2(); 66 private TemplateModel m_cListHashModel1 = new MultiModel4(); 67 private TemplateModel m_cListHashModel2 = new MultiModel5(); 68 private TemplateSequenceModel m_cListModel = new SimpleSequence(); 69 private TemplateHashModel m_cHashModel = new SimpleHash(); 70 71 72 public MultiModel1() { 73 for( int i = 0; i < 10; i++ ) { 74 ((SimpleSequence)m_cListModel).add( "Model1 value: " + Integer.toString( i )); 75 } 76 ((SimpleSequence)m_cListModel).add( new MultiModel3() ); 77 ((SimpleHash)m_cHashModel).put( "nested", new MultiModel3() ); 78 } 79 80 88 public TemplateModel get(String key) { 89 if( key.equals( "model2" )) { 90 return m_cSubModel; 91 } else if( key.equals( "modellist" )) { 92 return m_cListModel; 93 } else if( key.equals( "selftest" )) { 94 return new SimpleScalar( "Selftest of a hash from MultiModel1" ); 95 } else if( key.equals( "one" )) { 96 return m_cListHashModel1; 97 } else if( key.equals( "two" )) { 98 return m_cListHashModel2; 99 } else if( key.equals( "size" )) { 100 return new SimpleScalar( "Nasty!" ); 101 } else if( key.equals( "nesting1" )) { 102 return m_cHashModel; 103 } else { 104 return null; 105 } 106 } 107 108 111 public boolean isEmpty() { 112 return false; 113 } 114 115 118 public TemplateModel get(int i) throws TemplateModelException { 119 return m_cListModel.get( i ); 120 } 121 122 127 public String getAsString() { 128 return "MultiModel1 as a string!"; 129 } 130 131 public int size() throws TemplateModelException { 132 return m_cListModel.size(); 133 } 134 } 135 | Popular Tags |