@Override public TemplateModel get(String key) throws TemplateModelException { synchronized (SimpleHash.this) { return SimpleHash.this.get(key); } }
@Override public TemplateModel get(String key) throws TemplateModelException { TemplateModel model = super.get(key); if (model != null) { return model;
@Override public TemplateModel get(final String key) throws TemplateModelException { try { // GIT Issue#357: Accessing db in freemarker template throws exception // When content store is accessed with key "db" then wrap the ContentStore with BeansWrapper and return to template. // All methods on db are then accessible in template. Eg: ${db.getPublishedPostsByTag(tagName).size()} if(key.equals(Crawler.Attributes.DB)) { BeansWrapperBuilder bwb = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); BeansWrapper bw = bwb.build(); return bw.wrap(db); } return extractors.extractAndTransform(db, key, eagerModel.toMap(), new TemplateEngineAdapter<TemplateModel>() { @Override public TemplateModel adapt(String key, Object extractedValue) { if(key.equals(Crawler.Attributes.ALLTAGS)) { return new SimpleCollection((Collection) extractedValue, wrapper); } else if(key.equals(Crawler.Attributes.PUBLISHED_DATE)) { return new SimpleDate((Date) extractedValue, TemplateDateModel.UNKNOWN); } else { // All other cases, as far as I know, are document collections return new SimpleSequence((Collection) extractedValue, wrapper); } } }); } catch(NoModelExtractorException e) { return eagerModel.get(key); } }
public TemplateModel get(String key) throws TemplateModelException { synchronized (SimpleHash.this) { return SimpleHash.this.get(key); } }
@Override public TemplateModel get(String key) throws TemplateModelException { synchronized (SimpleHash.this) { return SimpleHash.this.get(key); } }
@Override public TemplateModel get(String key) throws TemplateModelException { synchronized (SimpleHash.this) { return SimpleHash.this.get(key); } }
/** * Fall back on the parameters' hash model if no bean property has been found. */ @Override public TemplateModel get(String key) throws TemplateModelException { TemplateModel templateModel = super.get(key); if (templateModel == null) { templateModel = paramHash.get(key); } return templateModel; } }
/** * Fall back on the parameters' hash model if no bean property has been found. */ public TemplateModel get(String key) throws TemplateModelException { TemplateModel templateModel = super.get(key); if (templateModel == null) { templateModel = paramHash.get(key); } return templateModel; } }
@Override public TemplateModel get(String key) throws TemplateModelException { TemplateModel result = super.get(key); if(result != null && result instanceof FreeMarkerProperty && !((FreeMarkerProperty) result).hasValue()){ return null; } return result; } }
/** * Add {@link RequestInfo} to the freemarker model * * @param model * @throws TemplateModelException */ protected void setRequestInfo(SimpleHash model) throws TemplateModelException { final RequestInfo requestInfo = RequestInfo.get(); if (model.get("page") == null) { if (requestInfo != null) { model.put("page", requestInfo); } } }
protected Object internalPutInContext(String key, Object value) { TemplateModel model = null; try { model = getContext().get(key); } catch (TemplateModelException e) { throw new RuntimeException("Could not get key " + key, e); } getContext().put(key, value); return model; }
protected Object internalRemoveFromContext(String key) { TemplateModel model = null; try { model = getContext().get(key); } catch (TemplateModelException e) { throw new RuntimeException("Could not get key " + key, e); } getContext().remove(key); return model; }
public TemplateModel wrap(Object obj) throws TemplateModelException { TemplateModel model = wrapper.wrap(obj); if ( model instanceof SimpleHash ) { SimpleHash hash = (SimpleHash) model; if ( hash.get( "page" ) == null ) { PageInfo pageInfo = (PageInfo) request.getAttributes().get( PageInfo.KEY ); if ( pageInfo != null ) { hash.put( "page", pageInfo ); } } } return model; } });
public void render(String template, ValueStack stack, Writer writer, Component component) throws Exception { SimpleHash model = buildModel(stack, component); Object prevTag = model.get("tag"); model.put("tag", component); getTemplate(template).process(model, writer); if (null != prevTag) model.put("tag", prevTag); }
public TemplateModel get(String key) throws TemplateModelException { TemplateModel result; try { result = facadeModel.get(key); } catch (InvalidPropertyException e1) { result = getContentModel().get(key); if (result == null) { result = delegateModel.get(key); } } return result; }
protected Object internalRemoveFromContext(String key) { TemplateModel model = null; try { model = getContext().get(key); } catch (TemplateModelException e) { throw new ExporterException("Could not get key " + key, e); } getContext().remove(key); return model; }
protected Object internalPutInContext(String key, Object value) { TemplateModel model = null; try { model = getContext().get(key); } catch (TemplateModelException e) { throw new ExporterException("Could not get key " + key, e); } getContext().put(key, value); return model; }
public static Object get(SimpleHash args, String key) { Object o = null; try { o = args.get(key); } catch (TemplateModelException e) { Debug.logVerbose(e.getMessage(), module); return null; } Object returnObj = unwrap(o); if (returnObj == null) { Object ctxObj = null; try { ctxObj = args.get("context"); } catch (TemplateModelException e) { Debug.logInfo(e.getMessage(), module); return returnObj; } Map<String, ?> ctx = null; if (ctxObj instanceof BeanModel) { ctx = UtilGenerics.cast(((BeanModel) ctxObj).getWrappedObject()); returnObj = ctx.get(key); } } return returnObj; }
@Override public TemplateModel get(final String key) throws TemplateModelException { try { // GIT Issue#357: Accessing db in freemarker template throws exception // When content store is accessed with key "db" then wrap the ContentStore with BeansWrapper and return to template. // All methods on db are then accessible in template. Eg: ${db.getPublishedPostsByTag(tagName).size()} if(key.equals(Crawler.Attributes.DB)) { BeansWrapperBuilder bwb = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); BeansWrapper bw = bwb.build(); return bw.wrap(db); } return extractors.extractAndTransform(db, key, eagerModel.toMap(), new TemplateEngineAdapter<TemplateModel>() { @Override public TemplateModel adapt(String key, Object extractedValue) { if(key.equals(Crawler.Attributes.ALLTAGS)) { return new SimpleCollection((Collection) extractedValue, wrapper); } else if(key.equals(Crawler.Attributes.PUBLISHED_DATE)) { return new SimpleDate((Date) extractedValue, TemplateDateModel.UNKNOWN); } else { // All other cases, as far as I know, are document collections return new SimpleSequence((Collection) extractedValue, wrapper); } } }); } catch(NoModelExtractorException e) { return eagerModel.get(key); } }
/** * FIXME ama -> what is the actual structure of the map, does it need property types? */ @Test public void testTransformedProperties() throws TemplateModelException { AMWTemplateExceptionHandler templateExceptionHandler = new AMWTemplateExceptionHandler(); AmwAppServerNodeModel model = new AmwAppServerNodeModel(); resolver.transform(templateExceptionHandler, model); assertEquals("app2", ((SimpleHash)model.get("app")).get("label").toString()); assertEquals("as2", ((SimpleHash)model.get("appServer")).get("label").toString()); assertTrue(templateExceptionHandler.isSuccess()); } }