freemarker.template.TemplateModel Java Examples

The following examples show how to use freemarker.template.TemplateModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClasspathResourceMethod.java    From pippo with Apache License 2.0 6 votes vote down vote up
@Override
public TemplateModel exec(List args) {
    if (urlPattern.get() == null) {
        String pattern = router.uriPatternFor(resourceHandlerClass);
        if (pattern == null) {
            throw new PippoRuntimeException("You must register a route for {}",
                    resourceHandlerClass.getSimpleName());
        }

        urlPattern.set(pattern);
    }

    String path = args.get(0).toString();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(ClasspathResourceHandler.PATH_PARAMETER, path);
    String url = router.uriFor(urlPattern.get(), parameters);

    return new SimpleScalar(url);
}
 
Example #2
Source File: DirectiveUtils.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public static Integer[] getIntArray(String name,
		Map<String, TemplateModel> params) throws TemplateException {
	String str = DirectiveUtils.getString(name, params);
	if (StringUtils.isBlank(str)) {
		return null;
	}
	String[] arr = StringUtils.split(str, ',');
	Integer[] ids = new Integer[arr.length];
	int i = 0;
	try {
		for (String s : arr) {
			ids[i++] = Integer.valueOf(s);
		}
		return ids;
	} catch (NumberFormatException e) {
		throw new MustSplitNumberException(name, e);
	}
}
 
Example #3
Source File: CDOMObjectModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private <T> TemplateModel proc(Class<T> cl, String key) throws TemplateModelException
{
	/*
	 * What if it didn't previously exist (e.g. cl==SubClass.class)...
	 * shouldn't be able to get here really (in that case)
	 */
	OutputActor<? super T> actor = WRAPPER_FACET.getActor(id.getDatasetID(), cl, key);
	if (actor == null)
	{
		throw new TemplateModelException(
			"object of type " + cdo.getClass().getSimpleName() + " did not have output of type " + key);
	}
	@SuppressWarnings("unchecked")
	T obj = (T) cdo;
	return actor.process(id, obj);
}
 
Example #4
Source File: SimpleWrapperLibrary.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Wraps the given object into a TemplateModel, using the ObjectWrapper
 * objects previously added to this SimpleWrapperLibrary.
 * 
 * Each ObjectWrapper which has been added to the SimpleWrapperLibrary is
 * given the chance, in the order they were added to the
 * SimpleWrapperLibrary, to wrap the object into a TemplateModel. The
 * results of the first successful ObjectWrapper are returned.
 * 
 * @param toWrap
 *            The Object to be wrapped
 * @return The TemplateModel produced by an ObjectWrapper contained in this
 *         SimpleWrapperLibrary
 * @throws TemplateModelException
 *             if no ObjectWrapper in this SimpleWrapperLibrary can wrap the
 *             given object into a TemplateModel
 */
public static TemplateModel wrap(Object toWrap) throws TemplateModelException
{
	if (toWrap == null)
	{
		return null;
	}
	for (SimpleObjectWrapper ow : WRAPPER_LIST)
	{
		try
		{
			return ow.wrap(toWrap);
		}
		catch (TemplateModelException ignored)
		{
			//No worries, Try the next one
		}
	}
	String info = toWrap.getClass().getCanonicalName();
	throw new TemplateModelException("Unable to find wrapping for " + info);
}
 
Example #5
Source File: DirectiveUtils.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public static Integer getInt(String name, Map<String, TemplateModel> params)
		throws TemplateException {
	TemplateModel model = params.get(name);
	if (model == null) {
		return null;
	}
	if (model instanceof TemplateScalarModel) {
		String s = ((TemplateScalarModel) model).getAsString();
		if (StringUtils.isBlank(s)) {
			return null;
		}
		try {
			return Integer.parseInt(s);
		} catch (NumberFormatException e) {
			throw new MustNumberException(name);
		}
	} else if (model instanceof TemplateNumberModel) {
		return ((TemplateNumberModel) model).getAsNumber().intValue();
	} else {
		throw new MustNumberException(name);
	}
}
 
Example #6
Source File: OutputDB.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Builds the PlayerCharacter data model for the given CharID.
 * 
 * @param id
 *            The CharID for which the data model should be built
 * @return A Map of the data model for the PlayerCharacter identified by the
 *         given CharID
 */
public static Map<String, Object> buildDataModel(CharID id)
{
	Map<String, Object> input = new HashMap<>();
	for (Object k1 : outModels.getKeySet())
	{
		for (Object k2 : outModels.getSecondaryKeySet(k1))
		{
			ModelFactory modelFactory = outModels.get(k1, k2);
			TemplateModel model = modelFactory.generate(id);
			String k1String = k1.toString();
			if ("".equals(k2.toString()))
			{
				input.put(k1String, model);
			}
			else
			{
				ensureMap(input, k1String);
				@SuppressWarnings("unchecked")
				Map<Object, Object> m = (Map<Object, Object>) input.get(k1String);
				m.put(k2.toString(), model);
			}
		}
	}
	return input;
}
 
Example #7
Source File: OutputDB.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Builds the PlayerCharacter data model for the given CharID.
 * 
 * @param id
 *            The CharID for which the data model should be built
 * @return A Map of the data model for the PlayerCharacter identified by the
 *         given CharID
 */
public static Map<String, Object> buildDataModel(CharID id)
{
	Map<String, Object> input = new HashMap<>();
	for (Object k1 : outModels.getKeySet())
	{
		for (Object k2 : outModels.getSecondaryKeySet(k1))
		{
			ModelFactory modelFactory = outModels.get(k1, k2);
			TemplateModel model = modelFactory.generate(id);
			String k1String = k1.toString();
			if ("".equals(k2.toString()))
			{
				input.put(k1String, model);
			}
			else
			{
				ensureMap(input, k1String);
				@SuppressWarnings("unchecked")
				Map<Object, Object> m = (Map<Object, Object>) input.get(k1String);
				m.put(k2.toString(), model);
			}
		}
	}
	return input;
}
 
Example #8
Source File: ContentDirective.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	Integer id = getId(params);
	Boolean next = DirectiveUtils.getBool(PRAMA_NEXT, params);
	Content content;
	if (next == null) {
		content = contentMng.findById(id);
	} else {
		CmsSite site = FrontUtils.getSite(env);
		Integer channelId = DirectiveUtils.getInt(PARAM_CHANNEL_ID, params);
		content = contentMng.getSide(id, site.getId(), channelId, next);
	}

	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
			params);
	paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(content));
	Map<String, TemplateModel> origMap = DirectiveUtils
			.addParamsToVariable(env, paramWrap);
	body.render(env.getOut());
	DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
 
Example #9
Source File: WrapTag.java    From javalite with Apache License 2.0 6 votes vote down vote up
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    if(!params.containsKey("with")) {
        throw new RuntimeException("\"with\" param was not provided");
    }

    String withArgument = params.get("with").toString();

    StringWriter innerContent = new StringWriter();
    body.render(innerContent);        

    SimpleHash envValues = getHash(env);
    envValues.putAll(params);
    envValues.put("page_content", innerContent.toString());
    for(Object key : params.keySet()) {
        if(key.toString().equals("with")) {
            continue;
        } else {
            envValues.put(key.toString(), params.get(key));
        }
    }

    String path = getTemplatePath(env.getTemplate().getName(), withArgument);
    Template template = env.getConfiguration().getTemplate(path + ".ftl");
    template.process(envValues, env.getOut());
}
 
Example #10
Source File: DateTagDirective.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
		throws TemplateException, IOException {
	String dateValue = params.get("value").toString();
	String format = params.get("format").toString();
	String dateString="";
	if(dateValue==null) {
		if(format==null) {
			dateString=DateUtils.getCurrentDateAsString(DateUtils.FORMAT_DATE_YYYY_MM_DD);
		}else {
			dateString=DateUtils.getCurrentDateAsString(format);
		}
	}else {
		if(format==null) {
			dateString=DateUtils.format(DateUtils.tryParse(dateValue),DateUtils.FORMAT_DATE_YYYY_MM_DD);
		}else {
			dateString=DateUtils.format(DateUtils.tryParse(dateValue),format);
		}
	}
	
	env.getOut().append(dateString);
	
}
 
Example #11
Source File: FreeMarkerServiceTest.java    From freemarker-online-tester with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #12
Source File: AbstractWebPage.java    From freeacs with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public TemplateModel exec(List args) throws TemplateModelException {
  if (args.size() != 2) {
    throw new TemplateModelException("Wrong arguments");
  }

  String text = (String) args.get(0);
  String toFind = (String) args.get(1);

  if (".".equals(toFind)) {
    toFind = "\\.";
  }

  String[] arr = text.split(toFind);

  String result = arr.length > 1 ? arr[arr.length - 1] : arr[0];

  return new SimpleScalar(result);
}
 
Example #13
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * Converts map to a simple wrapper, if applicable. Currently only applies to complex maps.
 * <p>
 * 2017-01-26: This has been changed so that it will by default try to wrap everything
 * with DefaultMapAdapter (or SimpleMapModel for BeansWrapper compatibility), which will always work as long as
 * the ObjectWrapper implements ObjectWrapperWithAPISupport.
 * <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.
 */
public static TemplateHashModel toSimpleMap(TemplateModel object, Boolean copy, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (OfbizFtlObjectType.COMPLEXMAP.isObjectType(object)) {
        // WARN: bypasses auto-escaping
        Map<?, ?> wrappedObject = UtilGenerics.cast(((WrapperTemplateModel) object).getWrappedObject());
        if (Boolean.TRUE.equals(copy)) {
            return makeSimpleMapCopy(wrappedObject, objectWrapper);
        } else {
            return makeSimpleMapAdapter(wrappedObject, objectWrapper, true);
        }
    } else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    } else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
Example #14
Source File: RenderComponentDirective.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
protected SiteItem getComponentFromNode(TemplateModel parentParam, TemplateModel componentParam, Environment env)
    throws TemplateException {
    SiteItem parentItem = unwrap(COMPONENT_PARENT_PARAM_NAME, parentParam, SiteItem.class, env);
    Element includeElementParent = unwrap(COMPONENT_PARAM_NAME, componentParam, Element.class, env);
    Element includeElement = includeElementParent.element(includeElementName);
    Element componentElement = includeElementParent.element(componentElementName);

    if (includeElement != null) {
        logger.debug("Using the include element to load the site item");
        String componentPath = includeElement.getTextTrim();

        return getComponent(componentPath, env);
    } else if (componentElement != null) {
        logger.debug("Using an embedded site item");
        if (parentItem == null) {
            logger.debug("Using default parent component");
            parentItem =
                unwrap(KEY_CONTENT_MODEL, env.getVariable(CrafterPageView.KEY_CONTENT_MODEL), SiteItem.class, env);
        }
        return siteItemService.getSiteItem(parentItem, componentElement);
    } else {
        throw new IllegalStateException("No '" + includeElementName + "' or '" + componentElementName + "' element "
            + "found under component "+ includeElementParent.getUniquePath());
    }
}
 
Example #15
Source File: AbstractContentDirective.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
protected Integer[] getChannelIds(Map<String, TemplateModel> params)
		throws TemplateException {
	Integer[] ids = DirectiveUtils.getIntArray(PARAM_CHANNEL_ID, params);
	if (ids != null && ids.length > 0) {
		return ids;
	} else {
		return null;
	}
}
 
Example #16
Source File: NavsTags.java    From cms with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    if (params.get("id") == null)
        return;
    String id = params.get("id").toString();

    List<Navs> navs = SystemCacheManager.get(ConstantsUtils.TE_NAVS_KEY + id, List.class);

    if (navs == null) {
        Category model = new Category();
        model.setShowModes("1");
        model.setSiteId(Long.parseLong(id));
        List<Category> categorys = categoryService.getList(model);
        navs = getRootNodes(categorys);

        for (Navs nav : navs) {
            childNodes(categorys, nav);
        }
        SystemCacheManager.put(ConstantsUtils.TE_NAVS_KEY + id, navs);
    }

    env.setVariable("navs", wrap(navs));
    if (body != null) {
        body.render(env.getOut());
    }
}
 
Example #17
Source File: ItemFacetModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TemplateModel get(String arg0) throws TemplateModelException
{
	TemplateHashModel model = getInternalHashModel();
	if (model == null)
	{
		return null;
	}
	return model.get(arg0);
}
 
Example #18
Source File: MakeSectionsRendererMethod.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public Object execTyped(List<TemplateModel> args) throws TemplateModelException {
    if (args.size() != 2) {
        throw new TemplateModelException("Invalid number of arguments (expected: 2)");
    }

    Environment env = FreeMarkerWorker.getCurrentEnvironment();

    TemplateModel arg1 = args.get(0);
    if (!(arg1 instanceof TemplateScalarModel)) {
        throw new TemplateModelException("First argument (type) was not a string");
    }
    String type = LangFtlUtil.getAsStringNonEscaping((TemplateScalarModel) arg1);

    TemplateModel arg2 = args.get(1);
    if (!(arg2 instanceof TemplateHashModel)) {
        throw new TemplateModelException("Second argument (sectionsMap) was not a map");
    }
    TemplateHashModelEx sectionsMapModel = (TemplateHashModelEx) LangFtlUtil.toSimpleMap(arg2, false, env.getObjectWrapper());

    if ("ftl".equals(type)) {
        FtlSectionsRenderer sections = FtlSectionsRenderer.create(sectionsMapModel);
        return sections;
    } else if ("screen".equals(type)) {
        // TODO: "screen": WARN: due to build dependencies we won't be able to invoke widget renderer from here
        // may be forced to use reflection (dirty)...
        throw new TemplateModelException("First argument (type) currently only supports: ftl (screen type not yet implemented)");
    } else {
        throw new TemplateModelException("First argument (type) currently only supports: ftl");
    }
}
 
Example #19
Source File: ExecuteControllerDirective.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
protected SiteItem getContentModel(Environment env) throws TemplateException {
    TemplateModel contentModel = env.getVariable(CrafterPageView.KEY_CONTENT_MODEL);
    if (contentModel != null) {
        Object unwrappedContentModel = DeepUnwrap.unwrap(contentModel);
        if (unwrappedContentModel instanceof SiteItem) {
            return (SiteItem)unwrappedContentModel;
        } else {
            throw new TemplateException("Variable '" + CrafterPageView.KEY_CONTENT_MODEL + " of unexpected type: expected: " +
                                        SiteItem.class.getName() + ", actual: " + unwrappedContentModel.getClass().getName(),
                                        env);
        }
    } else {
        return null;
    }
}
 
Example #20
Source File: LocaleTagDirective.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, 
        Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    WebApplicationContext webApplicationContext = 
            RequestContextUtils.findWebApplicationContext(request);
    String message = "";
    if (params.get("code") == null) {
        message = RequestContextUtils.getLocale(request).getLanguage();
    } else if (params.get("code").toString().equals("global.application.version")
            || params.get("code").toString().equals("application.version")) {
        message = WebContext.properties.getProperty("application.formatted-version");
    } else {
        _logger.trace("message code " + params.get("code"));
        try {
            message = webApplicationContext.getMessage(
                            params.get("code").toString(), 
                            null,
                            RequestContextUtils.getLocale(request));

        } catch (Exception e) {
            _logger.error("message code " + params.get("code"), e);
        }
    }
    env.getOut().append(message);
}
 
Example #21
Source File: TemporalDialerAdapter.java    From freemarker-java-8 with Apache License 2.0 5 votes vote down vote up
@Override
protected TemplateModel getForType(String methodName) throws TemplateModelException {
    TemporalUnit temporalUnit = new MethodNameToTemporalUnitMapper().map(methodName);
    if (temporalUnit == null) {
        return delegate.get(methodName);
    } else {
        return new TemporalDialer(this.getObject(), temporalUnit);
    }
}
 
Example #22
Source File: SimpleObjectWrapperWithXmlSupport.java    From freemarker-online-tester with Apache License 2.0 5 votes vote down vote up
@Override
protected TemplateModel handleUnknownType(Object obj) throws TemplateModelException {
    if (obj instanceof Node) {
        return wrapDomNode(obj);
    }
    return super.handleUnknownType(obj);
}
 
Example #23
Source File: SourceReportGenerator.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Object exec(List arguments) throws TemplateModelException {
  TemplateModel model = (TemplateModel) arguments.get(0);
  if (model instanceof SimpleNumber) {
    SimpleNumber number = (SimpleNumber) model;
    return "" + number;
  } else if (model instanceof BeanModel) {
    BeanModel arg0 = (BeanModel) model;
    Cost cost = (Cost) arg0.getAdaptedObject(Cost.class);
    return "Cost: " + costModel.computeOverall(cost) + " [" + cost + "]";
  } else {
    throw new IllegalStateException();
  }
}
 
Example #24
Source File: FreeMarkerRenderer.java    From opoopress with Apache License 2.0 5 votes vote down vote up
private void initializeTemplateModels() {
    templateModels = site.getFactory().getPluginManager().getObjectMap(TemplateModel.class);
    Map<String, String> map = site.get(TemplateModel.class.getName());
    if (map != null) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String name = entry.getKey();
            String className = entry.getValue();
            TemplateModel t = ClassUtils.newInstance(className, site.getClassLoader(), site, site.getConfig());
            log.debug("Create instance: {}", className);
            templateModels.put(name, t);
        }
    }
}
 
Example #25
Source File: PermissionDirective.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(
    Environment env,
    @SuppressWarnings("rawtypes") Map params,
    TemplateModel[] loopVars,
    TemplateDirectiveBody body)
    throws TemplateException, IOException {
  String entityTypeIdValue = DataConverter.toString(params.get("entityTypeId"));
  String pluginIdValue = DataConverter.toString(params.get("plugin"));
  String permissionValue = DataConverter.toString(params.get("permission"));

  if (permissionValue == null) throw new TemplateModelException("Missing 'permission' parameter");
  if ((entityTypeIdValue == null) && (pluginIdValue == null))
    throw new TemplateModelException("Missing 'entityTypeId' and/or 'plugin' parameter");

  boolean hasPermission = true;
  if (entityTypeIdValue != null) {
    hasPermission =
        permissionService.hasPermission(
            new EntityTypeIdentity(entityTypeIdValue), toEntityTypePermissions(permissionValue));
  }

  if ((pluginIdValue != null) && hasPermission) {
    hasPermission =
        permissionService.hasPermission(
            new PluginIdentity(pluginIdValue), PluginPermission.VIEW_PLUGIN);
  }

  execute(hasPermission, env, body);
}
 
Example #26
Source File: ConnectObjectWrapper.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
  if (obj instanceof Map) {
    return new MissingValueHashWrapper((Map<String, ?>) obj);
  }

  return super.wrap(obj);
}
 
Example #27
Source File: ThemeTagDirective.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, 
        Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    String theme = null;
    if (null != WebContext.getUserInfo()) {
        theme =  WebContext.getUserInfo().getTheme();
        _logger.trace("read theme form login user session , theme is " + theme);
    }
    
    if (null == theme) {
        Cookie  themeCookie = 
                WebContext.readCookieByName(request, WebConstants.THEME_COOKIE_NAME);
        if (themeCookie != null) {
            theme = themeCookie.getValue();
            _logger.trace("read theme form cookie , theme is " + theme);
        }
    }
    
    //每次登陆完成设置一次COOKIE
    if (request.getAttribute(WebConstants.THEME_COOKIE_NAME) == null 
            && null != WebContext.getUserInfo()) {
        request.setAttribute(WebConstants.THEME_COOKIE_NAME, "theme");
        WebContext.setCookie(response, 
                WebConstants.THEME_COOKIE_NAME, theme, ConstantsTimeInterval.ONE_WEEK);
    }
    
    env.getOut().append(theme == null ? "default" : theme);
}
 
Example #28
Source File: CopyObjectMethod.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException {
    if (args == null || args.size() < 1 || args.size() > 2) {
        throw new TemplateModelException("Invalid number of arguments (expected: 1-2)");
    }
    Environment env = CommonFtlUtil.getCurrentEnvironment();
    TemplateModel object = (TemplateModel) args.get(0);
    ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper(env);
    return LangFtlUtil.copyObject(object, null, objectWrapper);
}
 
Example #29
Source File: DirectiveUtils.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 是否调用模板
 * 
 * 0:不调用,使用标签的body;1:调用自定义模板;2:调用系统预定义模板;3:调用用户预定义模板。默认:0。
 * 
 * @param params
 * @return
 * @throws TemplateException
 */
public static InvokeType getInvokeType(Map<String, TemplateModel> params)
		throws TemplateException {
	String tpl = getString(PARAM_TPL, params);
	if ("3".equals(tpl)) {
		return InvokeType.userDefined;
	} else if ("2".equals(tpl)) {
		return InvokeType.sysDefined;
	} else if ("1".equals(tpl)) {
		return InvokeType.custom;
	} else {
		return InvokeType.body;
	}
}
 
Example #30
Source File: DirectiveUtils.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将variable中的params值移除
 * 
 * @param env
 * @param params
 * @param origMap
 * @throws TemplateException
 */
public static void removeParamsFromVariable(Environment env,
		Map<String, TemplateModel> params,
		Map<String, TemplateModel> origMap) throws TemplateException {
	if (params.size() <= 0) {
		return;
	}
	for (String key : params.keySet()) {
		env.setVariable(key, origMap.get(key));
	}
}