當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。