当前位置: 首页>>代码示例>>Java>>正文


Java TemplateModel类代码示例

本文整理汇总了Java中freemarker.template.TemplateModel的典型用法代码示例。如果您正苦于以下问题:Java TemplateModel类的具体用法?Java TemplateModel怎么用?Java TemplateModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TemplateModel类属于freemarker.template包,在下文中一共展示了TemplateModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSharedVariable

import freemarker.template.TemplateModel; //导入依赖的package包/类
@Override
public TemplateModel getSharedVariable(String string) {
    Object value = map.getAttribute(string);
    if (value == null) {
        value = engineScope.get(string);
    }
    if (value == null && fo != null) {
        value = fo.getAttribute(string);
    }
    try {
        return getObjectWrapper().wrap(value);
    } catch (TemplateModelException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:RsrcLoader.java

示例2: initialValue

import freemarker.template.TemplateModel; //导入依赖的package包/类
@Override
protected ObjectWrapper initialValue()
{
    return new DefaultObjectWrapper()
    {
        /* (non-Javadoc)
         * @see freemarker.template.DefaultObjectWrapper#wrap(java.lang.Object)
         */
        @Override
        public TemplateModel wrap(Object obj) throws TemplateModelException
        {
            if (obj instanceof QNameMap)
            {
                return new QNameHash((QNameMap)obj, this);
            }
            else
            {
                return super.wrap(obj);
            }
        }
    };
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:QNameAwareObjectWrapper.java

示例3: createTagRenderer

import freemarker.template.TemplateModel; //导入依赖的package包/类
@Override
@SuppressWarnings("nls")
protected TagRenderer createTagRenderer(HtmlMutableListState state, Environment env, Map<?, ?> params,
	TemplateDirectiveBody body, TemplateModel[] loopVars) throws TemplateModelException
{
	String tag = "div";
	if( params.containsKey("tag") )
	{
		tag = ((SimpleScalar) params.get("tag")).getAsString();
	}

	boolean hideDisabledOptions = false;
	if( params.containsKey("hideDisabledOptions") )
	{
		hideDisabledOptions = ((TemplateBooleanModel) params.get("hideDisabledOptions")).getAsBoolean();
	}

	return new ButtonListTagRenderer(tag, (HtmlListState) state, env, body, loopVars, hideDisabledOptions);
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:ButtonListDirective.java

示例4: ButtonListTagRenderer

import freemarker.template.TemplateModel; //导入依赖的package包/类
@SuppressWarnings("nls")
public ButtonListTagRenderer(String tag, HtmlListState state, Environment env, TemplateDirectiveBody body,
	TemplateModel[] loopVars, boolean hideDisabledOptions)
{
	super(tag, state); //$NON-NLS-1$
	this.wrapper = (BeansWrapper) env.getObjectWrapper();
	this.listState = state;
	this.body = body;
	this.loopVars = loopVars;
	this.hideDisabledOptions = hideDisabledOptions;

	this.hiddenId = new AppendedElementId(state, "_hid");
	ScriptVariable valVar = new ScriptVariable("val");
	JSStatements changeBody = new AssignStatement(new ElementValueExpression(hiddenId), valVar);

	JSHandler lsChangeHandler = state.getHandler(JSHandler.EVENT_CHANGE);
	if( lsChangeHandler != null )
	{
		changeBody = StatementBlock.get(changeBody, lsChangeHandler);
	}
	clickFunc = new SimpleFunction(JSHandler.EVENT_CHANGE, state, changeBody, valVar);
}
 
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:ButtonListDirective.java

示例5: execute

import freemarker.template.TemplateModel; //导入依赖的package包/类
@Override
public synchronized void execute(Environment env, @SuppressWarnings("rawtypes") Map params,
        TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    entered++;
    notifyAll();
    final long startTime = System.currentTimeMillis();
    while (!released) {
        // To avoid blocking the CI server forever is something goes wrong:
        if (System.currentTimeMillis() - startTime > BLOCKING_TEST_TIMEOUT) {
            LOG.error("JUnit test timed out");
        }
        try {
            wait(1000);
        } catch (InterruptedException e) {
            LOG.error("JUnit test was interrupted");
        }
    }
    LOG.debug("Blocker released");
}
 
开发者ID:apache,项目名称:incubator-freemarker-online-tester,代码行数:20,代码来源:FreeMarkerServiceTest.java

示例6: get

import freemarker.template.TemplateModel; //导入依赖的package包/类
@Override
public TemplateModel get(String s) throws TemplateModelException {
  Object value = null;

  if ("topic".equals(s)) {
    value = this.connectRecord.topic();
  } else if ("partition".equals(s)) {
    value = this.connectRecord.kafkaPartition();
  } else if (null != (this.struct.schema().field(s))) {
    value = this.struct.get(s);
  }

  if (null == value) {
    return TemplateModel.NOTHING;
  }

  return wrap(value);
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:19,代码来源:ConnectTemplateHashModel.java

示例7: execute

import freemarker.template.TemplateModel; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
	AdPosition adPosition;
	Long id = getId(params);
	boolean useCache = useCache(env, params);
	String cacheRegion = getCacheRegion(env, params);
	if (useCache) {
		adPosition = adPositionService.find(id, cacheRegion);
	} else {
		adPosition = adPositionService.find(id);
	}
	if (body != null) {
		setLocalVariable(VARIABLE_NAME, adPosition, env, body);
	} else {
		if (adPosition != null && adPosition.getTemplate() != null) {
			try {
				Map<String, Object> model = new HashMap<String, Object>();
				model.put(VARIABLE_NAME, adPosition);
				Writer out = env.getOut();
				new Template("adTemplate", new StringReader(adPosition.getTemplate()), freeMarkerConfigurer.getConfiguration()).process(model, out);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:27,代码来源:AdPositionDirective.java

示例8: getBoolParam

import freemarker.template.TemplateModel; //导入依赖的package包/类
public static boolean getBoolParam(final Environment env,Map params,String key,boolean def) throws TemplateException
{
	final TemplateModel tv = (TemplateModel)params.get(key);
	if(tv == null) 
	{
		return def;
	}
	
	if(tv instanceof TemplateBooleanModel)
	{
		return ((TemplateBooleanModel)tv).getAsBoolean();
           //throw new TemplateException(
           //		String.format("Expected a boolean model. '%s' is instead %s", key,tv.getClass().getName()) 
           //        , env);
       }
	
	return Convert.parseBool(tv.toString());
}
 
开发者ID:fancimage,项目名称:tern,代码行数:19,代码来源:Directives.java

示例9: overrideWithArgs

import freemarker.template.TemplateModel; //导入依赖的package包/类
public static void overrideWithArgs(Map<String, Object> ctx, Map<String, Object> args) {
    for (Map.Entry<String, Object> entry: args.entrySet()) {
        String key = entry.getKey();
        Object obj = entry.getValue();
        //if (Debug.infoOn()) Debug.logInfo("in overrideWithArgs, key(3):" + key + " obj:" + obj + " class:" + obj.getClass().getName() , module);
        if (obj != null) {
            if (obj == TemplateModel.NOTHING) {
                ctx.put(key, null);
            } else {
                Object unwrappedObj = unwrap(obj);
                if (unwrappedObj == null) {
                    unwrappedObj = obj;
                }
                ctx.put(key, unwrappedObj.toString());
            }
        } else {
            ctx.put(key, null);
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:21,代码来源:FreeMarkerWorker.java

示例10: getBooleanArg

import freemarker.template.TemplateModel; //导入依赖的package包/类
/**
 * Gets boolean arg.
 * <p>
 * Will automatically interpret string true/false as boolean.
 */
public static Boolean getBooleanArg(TemplateModel obj, Boolean defaultValue) throws TemplateModelException {
    if (obj instanceof TemplateBooleanModel) {
        return ((TemplateBooleanModel) obj).getAsBoolean();
    }
    else if (obj instanceof TemplateScalarModel) {
        TemplateScalarModel s = (TemplateScalarModel) obj;
        String val = s.getAsString();
        // SCIPIO: empty check is desirable and makes it so caller can request default by specifying ""
        if (!val.isEmpty()) {
            return "true".equalsIgnoreCase(s.getAsString());
        }
    } else if (obj != null) {
        throw new TemplateModelException("Expected boolean model or string model representation of boolean, but got a " +
                obj.getClass() + " instead");
    }
    return defaultValue;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:23,代码来源:TransformUtil.java

示例11: execute

import freemarker.template.TemplateModel; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    try {
        SimpleNumber pFor = (SimpleNumber) params.get("for");

        Number forMillis = null;

        if (pFor != null) {
            forMillis = pFor.getAsNumber();

            try {
                Thread.sleep(forMillis.longValue());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:23,代码来源:WaitDirective.java

示例12: getParam

import freemarker.template.TemplateModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getParam(String name, Class<?> type, Object defaultValue) {
    try {
        Object o = params.get(name);

        if (o != null) {
            if (o instanceof TemplateModel) {
                return (T) eval(BeansWrapper.getDefaultInstance().unwrap((TemplateModel) o), type, defaultValue);
            } else {
                return (T) eval(o, type, defaultValue);
            }
        } else {
            TemplateModel tm = hash().get(name);

            if (tm != null) {
                return (T) eval(BeansWrapper.getDefaultInstance().unwrap(tm), type, defaultValue);
            }
        }
    } catch (TemplateModelException e) {
        throw new RuntimeException(e);
    }

    return null;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:26,代码来源:FreemarkerWidgetContext.java

示例13: getIntegerArg

import freemarker.template.TemplateModel; //导入依赖的package包/类
/**
 * Gets integer arg.
 * <p>
 * If string passed, will be parsed as integer. Other types such as maps or lists
 * will throw TemplateModelException.
 */
public static Integer getIntegerArg(TemplateModel obj, Integer defaultValue) throws TemplateModelException, NumberFormatException {
    if (obj instanceof TemplateNumberModel) {
        return ((TemplateNumberModel) obj).getAsNumber().intValue();
    } else if (obj instanceof TemplateScalarModel) {
        TemplateScalarModel s = (TemplateScalarModel) obj;
        String strResult = LangFtlUtil.getAsString(s, true);
        if (strResult.isEmpty()) {
            return defaultValue;
        } else {
            return Integer.parseInt(strResult);
        }
    } else if (obj == null) {
        return defaultValue;
    } else {
        throw new TemplateModelException("Expected integer model or string representing of integer, but got a " +
                obj.getClass() + " instead");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:25,代码来源:TransformUtil.java

示例14: execute

import freemarker.template.TemplateModel; //导入依赖的package包/类
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException 
{
	String name = Directives.getStringParam(env, params, "name");
	
	name = BLOCK_NAME_PRE+name;
	Namespace ns = env.getCurrentNamespace();
	if(ns.get(name) == null)  /*block���ܶ�α���д�����ж�����ģ���е�����Ϊ����*/
	{
		//java.io.Writer out = new java.io.StringWriter();
		//body.render(out);
		
		env.getCurrentNamespace().put(name, body);
		//env.getCurrentNamespace().put(name, out.toString());
		//env.setLocalVariable(name, out.toString());			
	}			
}
 
开发者ID:fancimage,项目名称:tern,代码行数:18,代码来源:Overrides.java

示例15: execute

import freemarker.template.TemplateModel; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
	Long productCategoryId = FreemarkerUtils.getParameter(PRODUCT_CATEGORY_ID_PARAMETER_NAME, Long.class, params);

	ProductCategory productCategory = productCategoryService.find(productCategoryId);

	List<ProductCategory> productCategories;
	if (productCategoryId != null && productCategory == null) {
		productCategories = new ArrayList<ProductCategory>();
	} else {
		boolean useCache = useCache(env, params);
		String cacheRegion = getCacheRegion(env, params);
		Integer count = getCount(params);
		if (useCache) {
			productCategories = productCategoryService.findParents(productCategory, count, cacheRegion);
		} else {
			productCategories = productCategoryService.findParents(productCategory, count);
		}
	}
	setLocalVariable(VARIABLE_NAME, productCategories, env, body);
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:22,代码来源:ProductCategoryParentListDirective.java


注:本文中的freemarker.template.TemplateModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。