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


Java TemplateModelException类代码示例

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


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

示例1: getSharedVariable

import freemarker.template.TemplateModelException; //导入依赖的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: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    Object result = null;
    
    if (args.size() == 1)
    {
        Object arg0 = args.get(0);
        if (arg0 instanceof TemplateDateModel)
        {
            result = ISO8601DateFormat.format(((TemplateDateModel)arg0).getAsDate());
        }
        else if (arg0 instanceof TemplateScalarModel)
        {
            result = ISO8601DateFormat.parse(((TemplateScalarModel)arg0).getAsString());
        }
    }
    
    return result != null ? result : "";
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:ISO8601DateFormatMethod.java

示例3: initialValue

import freemarker.template.TemplateModelException; //导入依赖的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

示例4: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException
{
    String result = "";
    
    if (args.size() != 0)
    {
        String s = "";
        Object arg0 = args.get(0);
        if (arg0 instanceof TemplateScalarModel)
        {
            s = ((TemplateScalarModel)arg0).getAsString();
        }
        
        if (s != null)
        {
            result = URLDecoder.decode(s);
        }
    }
    
    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:URLDecodeMethod.java

示例5: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
/**
 * 执行方法
 * 
 * @param argList
 *            参加列表
 * @return 格式化后的字符串
 * @throws TemplateModelException
 *             模版异常
 */
@Override
public Object exec(@SuppressWarnings("rawtypes") List argList) throws TemplateModelException {
    // 限定方法中必须且只能传递一个参数
    if (argList.size() != 1) {
        throw new TemplateModelException("Wrong arguments!");
    }
    // String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
    String[] u = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
    char[] str = String.valueOf(argList.get(0)).toCharArray();
    String rstr = "";
    for (int i = 0; i < str.length; i++) {
        rstr = rstr + u[Integer.parseInt(str[i] + "")];
    }
    return rstr;
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:25,代码来源:UpperNumMethod.java

示例6: createTagRenderer

import freemarker.template.TemplateModelException; //导入依赖的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

示例7: getAsString

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@Override
public String getAsString() throws TemplateModelException
{
	DateRenderer d = dateRendererFactory.createDateRenderer(date);

	SectionWriter context = getSectionWriter();
	d.preRender(context);

	try
	{
		StringWriter s = new StringWriter();
		SectionWriter n = new SectionWriter(s, context);
		d.realRender(n);
		return s.toString();
	}
	catch( IOException e )
	{
		throw new TemplateModelException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:DateTemplateModelProvider.java

示例8: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@Override
public Object exec(List arguments) throws TemplateModelException
{
	// You can use it as a function to prevent the time-ago ness
	return new TemplateDateModel()
	{
		@Override
		public Date getAsDate() throws TemplateModelException
		{
			return date;
		}

		@Override
		public int getDateType()
		{
			return TemplateDateModel.DATETIME;
		}
	};
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:DateTemplateModelProvider.java

示例9: getSectionWriter

import freemarker.template.TemplateModelException; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
	try
	{
		AdapterTemplateModel model = (AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
			"_info");
		if( model != null )
		{
			return (SectionWriter) model.getAdaptedObject(SectionWriter.class);
		}
		return null;
	}
	catch( TemplateModelException e )
	{
		throw new SectionsRuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:SectionsTemplateModel.java

示例10: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException
{
	JSCallable function = (JSCallable) jsObject;
	RenderContext context = getSectionWriter();
	context.preRender(function);
	Object[] exprArgs = new Object[args.size()];
	int i = 0;
	for( Object obj : args )
	{
		if( obj instanceof AdapterTemplateModel )
		{
			Object adapted = ((AdapterTemplateModel) obj).getAdaptedObject(Object.class);
			exprArgs[i] = adapted;
		}
		else
		{
			exprArgs[i] = new ScriptExpression(obj.toString());
		}
		i++;
	}
	return function.getExpressionForCall(context, JSUtils.convertExpressions(exprArgs));
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:SectionsBeansWrapper.java

示例11: getSectionWriter

import freemarker.template.TemplateModelException; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
	try
	{
		return (SectionWriter) ((AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
			"_info")) //$NON-NLS-1$
			.getAdaptedObject(SectionWriter.class);
	}
	catch( TemplateModelException e )
	{
		throw new SectionsRuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:14,代码来源:SectionsBeansWrapper.java

示例12: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public Object exec(List arguments) throws TemplateModelException {
	
	String str = String.valueOf(arguments.get(0));
	String type = String.valueOf(arguments.get(1));
	
	try {
		if (type == null || "0".equals(type)) {
			return URLEncoder.encode(str, "utf-8");
		} else {
			return URLDecoder.decode(str, "utf-8");
		}
	} catch (Exception e) {
		e.printStackTrace();
		return e.getMessage();
	}
}
 
开发者ID:gooking,项目名称:yijava,代码行数:19,代码来源:UrlEncodeMethod.java

示例13: exec

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public Object exec(List arguments) throws TemplateModelException {
  if (arguments.size() != 1) {
    throw new TemplateModelException("Wrong number of arguments. Must be 1.");
  }

  String userPartOfStep = "";
  Step step = getStepFromFreemarker(arguments.get(0));
  if (hasUser(step)) {
    String userActorName = getUserActor(step).getName();
    String wordsOfUserEventClassName = getLowerCaseWordsOfClassName(step.getUserEventClass());
    userPartOfStep = userActorName + " " + wordsOfUserEventClassName + USER_POSTFIX;
  }
  
  return new SimpleScalar(userPartOfStep);
}
 
开发者ID:bertilmuth,项目名称:requirementsascode,代码行数:18,代码来源:UserPartOfStep.java

示例14: configuration

import freemarker.template.TemplateModelException; //导入依赖的package包/类
@Singleton
@Provides
public static Configuration configuration(LinkHelper linkHelper, MultiTemplateLoader templateLoader) {
    try {
        freemarker.log.Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
        Configuration cfg = new freemarker.template.Configuration(Configuration.VERSION_2_3_25);
        cfg.setTagSyntax(freemarker.template.Configuration.SQUARE_BRACKET_TAG_SYNTAX);
        cfg.setLazyAutoImports(true);
        cfg.setLocale(Locale.GERMANY); // todo make configurable
        cfg.addAutoImport("saito", "saito.ftl");
        cfg.setSharedVariable("saitoLinkHelper", linkHelper);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLogTemplateExceptions(false);
        cfg.setTemplateLoader(templateLoader);
        return cfg;
    } catch (TemplateModelException | ClassNotFoundException e) {
        log.error("Error creating config", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:21,代码来源:FreemarkerModule.java

示例15: toSimpleMapRewrapAdapters

import freemarker.template.TemplateModelException; //导入依赖的package包/类
/**
 * Converts map to a simple wrapper, if applicable, by rewrapping
 * known complex map wrappers that implement <code>WrapperTemplateModel</code>.
 * <p>
 * If the specified ObjectWrapper is a BeansWrapper, this forces rewrapping as a SimpleMapModel.
 * If it isn't we assume caller specified an objectWrapper that will rewrap the map with
 * a simple model (we have no way of knowing).
 * <p>
 * WARN: Bypasses auto-escaping for complex maps; caller must decide how to handle
 * (e.g. the object wrapper used to rewrap the result).
 * Other types of maps are not altered.
 * 
 * @deprecated don't use
 */
@Deprecated
private static TemplateHashModel toSimpleMapRewrapAdapters(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof SimpleMapModel || object instanceof BeanModel || object instanceof DefaultMapAdapter) {
        // Permissive
        Map<?, ?> wrappedObject = (Map<?, ?>) ((WrapperTemplateModel) object).getWrappedObject();
        if (objectWrapper instanceof BeansWrapper) {
            // Bypass the beanswrapper wrap method and always make simple wrapper
            return new SimpleMapModel(wrappedObject, (BeansWrapper) objectWrapper);
        } else {
            // If anything other than BeansWrapper, assume caller is aware and his wrapper will create a simple map
            return (TemplateHashModel) objectWrapper.wrap(wrappedObject);
        }
    }
    else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    }
    else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:35,代码来源:LangFtlUtil.java


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