1 48 49 package org.jpublish.view.freemarker; 50 51 import freemarker.template.*; 52 import org.jpublish.RequestContext; 53 54 59 60 public class FreeMarkerViewContext implements TemplateHashModelEx { 61 62 private RequestContext context; 63 64 69 70 public FreeMarkerViewContext(RequestContext context) { 71 this.context = context; 72 } 73 74 79 80 public int size() { 81 return context.getKeys().length; 82 } 83 84 89 90 public boolean isEmpty() { 91 return size() == 0; 92 } 93 94 101 102 public TemplateModel get(String key) throws TemplateModelException { 103 return wrapAsTemplateModel(context.get(key)); 104 } 105 106 112 113 public TemplateCollectionModel keys() throws TemplateModelException { 114 return (TemplateCollectionModel) wrapAsTemplateModel(context.getKeys()); 115 } 116 117 123 124 public TemplateCollectionModel values() throws TemplateModelException { 125 Object [] arr = context.getKeys(); 126 arr = (Object []) arr.clone(); 127 for (int i = 0; i < arr.length; i++) { 128 arr[i] = context.get(arr[i].toString()); 129 } 130 return (TemplateCollectionModel) wrapAsTemplateModel(arr); 131 } 132 133 140 141 private TemplateModel wrapAsTemplateModel(Object obj) throws TemplateModelException { 142 return ObjectWrapper.BEANS_WRAPPER.wrap(obj); 143 } 144 145 } 146 | Popular Tags |