freemarker.template.SimpleScalar Java Examples

The following examples show how to use freemarker.template.SimpleScalar. 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: RouteMethod.java    From mangooio with Apache License 2.0 6 votes vote down vote up
@Override
public TemplateModel exec(List arguments) throws TemplateModelException {
    String url;
    if (arguments.size() >= MIN_ARGUMENTS) {
        String controller = ((SimpleScalar) arguments.get(0)).getAsString();
        RequestRoute requestRoute = Router.getReverseRoute(controller);
        
        if (requestRoute != null) {
            url = requestRoute.getUrl();
            Matcher matcher = PARAMETER_PATTERN.matcher(url);
            int i = 1;
            while (matcher.find()) {
                String argument = ((SimpleScalar) arguments.get(i)).getAsString();
                url = StringUtils.replace(url, "{" + matcher.group(1) + "}", argument);
                i++;
            }
        } else {
            throw new TemplateModelException("Reverse route for " + controller + " could not be found!");
        }
    } else {
        throw new TemplateModelException("Missing at least one argument (ControllerClass:ControllerMethod) for reverse routing!");
    }

    return new SimpleScalar(url);
}
 
Example #2
Source File: ConfigFileTemplate.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
@Override
public Object exec(List list) throws TemplateModelException {
    if (list.size() == 0) {
        return registry.getAgents();
    } else if (list.size() == 1) {
        Object arg = list.get(0);
        if (!(arg instanceof SimpleScalar)) {
            throw new TemplateModelException("Wrong type of the first parameter."
                    + " It should be SimpleScalar . Found: " + arg.getClass());
        }

        Map<String, String> tags = TagUtils.parseTags(((SimpleScalar) arg).getAsString());
        List<AgentData> result = new ArrayList<>();
        for (AgentData agent : registry.getAgents()) {
            if (TagUtils.matches(tags, agent.getTags())) {
                result.add(agent);
            }
        }
        return result;
    } else {
        throw new TemplateModelException("Wrong number of arguments for method agents()."
                + " Method has zero a 1 String argument, found " + list.size());
    }
}
 
Example #3
Source File: ReactWhileOfStep.java    From requirementsascode with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
   @Override
   public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 1) {
    throw new TemplateModelException("Wrong number of arguments. Must be 1.");
}

Step step = getStep(arguments.get(0));

String reactWhile = "";
if (step instanceof FlowStep) {
    Condition reactWhileCondition = ((FlowStep) step).getReactWhile();
    if (reactWhileCondition != null) {
	reactWhile = REACT_WHILE_PREFIX + getLowerCaseWordsOfClassName(reactWhileCondition.getClass())
		+ REACT_WHILE_POSTFIX;
    }
}

return new SimpleScalar(reactWhile);
   }
 
Example #4
Source File: UserPartOfStep.java    From requirementsascode with Apache License 2.0 6 votes vote down vote up
@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.getMessageClass());
    userPartOfStep = userActorName + " " + wordsOfUserEventClassName + USER_POSTFIX;
  }
  
  return new SimpleScalar(userPartOfStep);
}
 
Example #5
Source File: AssetPathHelper.java    From blog-spring with MIT License 6 votes vote down vote up
@Override
public Object exec(List list) throws TemplateModelException {
  if (!(list.get(0) instanceof SimpleScalar)) {
    throw new TemplateModelException("Wrong parameter for assetPath: Only string permitted!");
  }

  String originalPath = ((SimpleScalar) list.get(0)).getAsString();
  if (assetConfig.isDevelopment()) {
    return "/assets/" + originalPath;
  }

  String digestedPath = manifest.assets.get(originalPath);
  if (digestedPath == null || digestedPath.isEmpty()) {
    throw new TemplateModelException("Asset " + originalPath + " not found!");
  } else {
    return "/assets/" + digestedPath;
  }
}
 
Example #6
Source File: FreeMarkerWorker.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
* Gets BeanModel from FreeMarker context and returns the object that it wraps.
* @param varName the name of the variable in the FreeMarker context.
* @param env the FreeMarker Environment
*/
public static <T> T getWrappedObject(String varName, Environment env) {
    Object obj = null;
    try {
        obj = env.getVariable(varName);
        if (obj != null) {
            if (obj == TemplateModel.NOTHING) {
                obj = null;
            } else if (obj instanceof BeanModel) {
                BeanModel bean = (BeanModel) obj;
                obj = bean.getWrappedObject();
            } else if (obj instanceof SimpleScalar) {
                obj = obj.toString();
            }
        }
    } catch (TemplateModelException e) {
        Debug.logInfo(e.getMessage(), module);
    }
    return UtilGenerics.<T>cast(obj);
}
 
Example #7
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 #8
Source File: FormatDescriptionMethod.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public Object exec(List args) throws TemplateModelException {
    if (args.size() != 1) {
        throw new TemplateModelException("There should be a single argument of type string " +
                "passed to format description method");
    }

    SimpleScalar arg1 = (SimpleScalar) args.get(0);
    String inputString = arg1.getAsString();

    // Replacing spaces that should not be considered in text wrapping with non breaking spaces
    inputString = replaceLeadingSpaces(inputString);

    inputString = inputString.replaceAll("<", "&lt;");
    inputString = inputString.replaceAll(">", "&gt;");

    // Replacing new line characters
    inputString = replaceNewLines(inputString);

    inputString = inputString.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
    inputString = inputString.replaceAll("```([^```]*)```",
            "</p><pre>$1</pre><p style=\"word-wrap: break-word;margin: 0;\">");
    inputString = inputString.replaceAll("`([^`]*)`", "<code>$1</code>");

    return "<p style=\"word-wrap: break-word;margin: 0;\">" + inputString + "</p>";
}
 
Example #9
Source File: SyslogUtil.java    From freeacs with MIT License 6 votes vote down vote up
public TemplateModel exec(List args) throws TemplateModelException {
  if (args.isEmpty()) {
    throw new TemplateModelException("Wrong number of arguments");
  }
  String uts = (String) args.get(0);
  String es = (String) args.get(1);
  String text = texts.get(uts + ":" + es);
  if (text != null) {
    return new SimpleScalar(text);
  }
  Integer unittypeId = !"".equals(uts) ? Integer.parseInt(uts) : null;
  Integer eventId = Integer.parseInt(es);
  Unittype ut = unittypeId != null ? acs.getUnittype(unittypeId) : null;
  SyslogEvent event =
      ut != null && eventId != null ? ut.getSyslogEvents().getByEventId(eventId) : null;
  if (ut != null && event != null) {
    texts.put(uts + ":" + es, event.toString());
    return new SimpleScalar(event.toString());
  }
  if (eventId != null && eventId == 0) {
    return new SimpleScalar(SyslogEvents.getById(eventId).getName());
  }
  return new SimpleScalar("n/a");
}
 
Example #10
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 number of arguments");
  }
  String id = (String) args.get(0);
  String name = (String) args.get(1);
  Unit unit = units.get(id);
  if (unit == null) {
    try {
      unit = acsUnit.getUnitById(id);
      units.put(id, unit);
    } catch (SQLException e) {
      throw new TemplateModelException("Error: " + e.getLocalizedMessage());
    }
  }
  String up = unit.getParameters().get(name);
  if (up != null && up.trim().isEmpty() && unit.getUnitParameters().get(name) != null) {
    return new SimpleScalar(
        "<span class=\"requiresTitlePopup\" title=\"The unit has overridden the profile value with a blank string\">[blank&nbsp;unit&nbsp;parameter]</span>");
  }
  return new SimpleScalar(up);
}
 
Example #11
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 #12
Source File: GroupsPage.java    From freeacs with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public TemplateModel exec(List arg0) throws TemplateModelException {
  String groupName = (String) arg0.get(0);

  Group group = unittype.getGroups().getByName(groupName);

  Group lastgroup = null;
  Group current = group;
  while ((current = current.getParent()) != null) {
    lastgroup = current;
  }

  Profile profile = null;
  if (lastgroup != null && lastgroup.getProfile() != null) {
    profile = unittype.getProfiles().getById(lastgroup.getProfile().getId());
  } else if (group.getProfile() != null) {
    profile = unittype.getProfiles().getById(group.getProfile().getId());
  }

  if (profile != null) {
    return new SimpleScalar(profile.getName());
  }
  return new SimpleScalar("All profiles");
}
 
Example #13
Source File: RenderLinkDirective.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
private LayoutType resolveLayoutType(Map params) throws TemplateException
{
    LayoutType layoutType = LayoutType.HORIZONTAL;
    SimpleScalar layoutModel = (SimpleScalar) params.get("layout");
    if (layoutModel != null)
    {
        String lt = layoutModel.getAsString();
        try
        {
            layoutType = LayoutType.valueOf(lt.toUpperCase());
        }
        catch (IllegalArgumentException e)
        {
            throw new TemplateException("Layout: " + lt + " is not supported.", e, null);
        }
    }
    return layoutType;
}
 
Example #14
Source File: FindSourceFilesByClassNameMethod.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (String)");
    }
    SimpleScalar arg = (SimpleScalar) arguments.get(0);
    String qualifedClassName = arg.getAsString();
    JavaClassModel classModel = javaClassService.getByName(qualifedClassName);
    List<AbstractJavaSourceModel> results = new ArrayList<>();
    if (classModel instanceof AmbiguousJavaClassModel)
    {
        AmbiguousJavaClassModel ambiguousJavaClassModel = (AmbiguousJavaClassModel) classModel;
        for (JavaClassModel referencedClass : ambiguousJavaClassModel.getReferences())
        {
            addSourceFilesToResult(results, referencedClass);
        }
    }
    else
    {
        addSourceFilesToResult(results, classModel);
    }
    return results;
}
 
Example #15
Source File: RenderRuleLinkDirective.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException
{
    final Writer writer = env.getOut();
    SimpleScalar ruleIDStringModel = (SimpleScalar) params.get("ruleID");
    if (ruleIDStringModel == null || ruleIDStringModel.getAsString() == null)
        return;

    SimpleScalar renderTypeScalar = (SimpleScalar) params.get("renderType");
    final String renderType;
    if (renderTypeScalar == null)
        renderType = RENDER_TYPE_TAG;
    else
        renderType = renderTypeScalar.getAsString();

    SimpleScalar cssClassScalar = (SimpleScalar) params.get("class");
    String cssClass;
    if (cssClassScalar == null || StringUtils.isBlank(cssClassScalar.getAsString())) {
        cssClass = "";
    }
    else {
        cssClass = cssClassScalar.getAsString();
    }

    String ruleID = ruleIDStringModel.getAsString();

    writer.append("<a title='View Rule: " + ruleID + "' href='" + RenderRuleProviderReportRuleProvider.OUTPUT_FILENAME + "#" + ruleID + "'>");
    if (RENDER_TYPE_GLYPH.equals(renderType))
        writer.append("<span class='glyphicon glyphicon-link "+cssClass+"'></span>");
    else if (RENDER_TYPE_TAG.equals(renderType))
        writer.append("<span class='tag "+cssClass+"'>&lt;rule/></span>");
    else
        writer.append("<span class='plain "+cssClass+"'>"+ ruleID +"</span>");
    writer.append("</a>");
}
 
Example #16
Source File: WriteToDiskDirective.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException
{
    SimpleScalar filename = (SimpleScalar) params.get(FILENAME);
    if (filename == null || StringUtils.isBlank(filename.getAsString()))
        throw new WindupException(NAME + " - Validation error, " + FILENAME + " parameter must not be blank!");

    Path dataDirectory = new ReportService(context).getReportDataDirectory();
    Path outputPath = dataDirectory.resolve(filename.getAsString());

    try (FileWriter writer = new FileWriter(outputPath.toFile()))
    {
        body.render(writer);
    }
}
 
Example #17
Source File: GetProjectTraversalMethod.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() < 1)
    {
        throw new TemplateModelException("Error, method expects at least one argument (" + ProjectModel.class.getSimpleName() + ")");
    }
    StringModel stringModelArg = (StringModel) arguments.get(0);
    ProjectModel projectModel = (ProjectModel) stringModelArg.getWrappedObject();

    String traversalStrategyString = ALL;
    if (arguments.size() > 1)
        traversalStrategyString = ((SimpleScalar)arguments.get(1)).getAsString();

    TraversalStrategy traversalStrategy;
    if (traversalStrategyString == null)
        traversalStrategyString = ALL;
    switch (traversalStrategyString)
    {
        case ONLY_ONCE: traversalStrategy = new OnlyOnceTraversalStrategy(); break;
        case SHARED:    traversalStrategy = new SharedLibsTraversalStrategy(); break;
        default:
            Logger.getLogger(GetProjectTraversalMethod.class.getName()).warning("Unknown strategy name: " + traversalStrategyString);
        case ALL: traversalStrategy = new AllTraversalStrategy(); break;
    }

    ProjectModelTraversal traversal = new ProjectModelTraversal(projectModel, traversalStrategy);
    ExecutionStatistics.get().end(NAME);
    return traversal;
}
 
Example #18
Source File: MailComposer.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Override
public Object exec(List arguments) throws TemplateModelException {
  if (arguments.size() == 0) {
    throw new TemplateModelException("Wrong number of arguments");
  }
  SimpleScalar simpleScalar = (SimpleScalar) arguments.get(0);
  if (simpleScalar == null || Strings.isNullOrEmpty(simpleScalar.getAsString())) {
    throw new TemplateModelException("Invalid code value '" + simpleScalar + "'");
  }
  @SuppressWarnings("unchecked")
  Object[] args = arguments.stream().skip(1).map(Objects::toString).toArray(String[]::new);
  return messageSource.getMessage(simpleScalar.getAsString(), args, locale);
}
 
Example #19
Source File: UtilCodecMethod.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() != 2) {
        throw new TemplateModelException("Invalid number of arguments (expected: 2)");
    }
    Environment env = FreeMarkerWorker.getCurrentEnvironment();

    String value = LangFtlUtil.toRawJavaString((TemplateModel) args.get(0), env);
    String lang = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(1)));

    return new SimpleScalar(langExec(value, lang));
}
 
Example #20
Source File: FtlUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static void setObjectVariable(Environment env, String name, Object val){
	if(TemplateModel.class.isInstance(val)){
		env.setVariable(name, (TemplateModel)val);
	}else if(String.class.isInstance(val)){
		env.setVariable(name, new SimpleScalar(val.toString()));
	}else{
		env.setVariable(name, wrapAsBeanModel(val));
	}
}
 
Example #21
Source File: VisibleToModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
	if (arguments.size() != 1)
	{
		throw new TemplateModelException("Expected 1 argument but found: " + arguments.size());
	}
	View v = View.getViewFromName(((SimpleScalar) arguments.get(0)).getAsString());
	return visibility.isVisibleTo(v);
}
 
Example #22
Source File: DateTimeTools.java    From freemarker-java-8 with Apache License 2.0 5 votes vote down vote up
/**
 * Look up a ZoneId based on a String in a list on a given index.
 *
 * @param list  A list of Strings containing the String representation of the ZoneId.
 * @param index The index on where in the list the ZoneId string is located.
 * @return A ZoneId instance for the given ZoneId string. If index is lower than the list size, then an empty {@link Optional} will be returned.
 * @throws TemplateModelException If Illegal ZoneId string was found in the list.
 */
public static Optional<ZoneId> zoneIdLookup(final List list, final int index) throws TemplateModelException {
    if (list.size() > index) {
        final String zoneIdString = ((SimpleScalar) list.get(index)).getAsString();
        try {
            return Optional.of(ZoneId.of(zoneIdString));
        } catch (final ZoneRulesException e) {
            throw new TemplateModelException(DateTimeTools.ILLEGAL_ZONE_ID_MSG, e);
        }
    }
    return Optional.empty();
}
 
Example #23
Source File: DateTimeTools.java    From freemarker-java-8 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a DateTimeFormatter from a pattern found in a List on a given index.
 *
 * @param list           A list of Strings containing the pattern
 * @param index          The index on where in the list the pattern is located.
 * @param defaultPattern The pattern to be used for the formatter if the list size is lower than the given index.
 * @return A DateTimeFormatter for the given pattern, or the default pattern.
 */
public static DateTimeFormatter createDateTimeFormatter(List list,
                                                        int index,
                                                        final String defaultPattern) {
    return DateTimeFormatter.ofPattern(
            list.size() > index
                    ? ((SimpleScalar) list.get(index)).getAsString()
                    : defaultPattern, getLocale());
}
 
Example #24
Source File: DateTimeTools.java    From freemarker-java-8 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a DateTimeFormatter from a pattern found in a List on a given index.
 *
 * @param list             A list of Strings containing the pattern
 * @param index            The index on where in the list the pattern is located.
 * @param defaultFormatter A default formatter to be returned if the given list size is lower than the given index.
 * @return A DateTimeFormatter for the given pattern, or the default formatter.
 */
public static DateTimeFormatter createDateTimeFormatter(final List list, final int index,
                                                        final DateTimeFormatter defaultFormatter) {
    if (list.size() > 0) {
        final String format = ((SimpleScalar) list.get(index)).getAsString();
        final ExtFormatStyle style = DateTimeTools.getFormatStyle(format);

        if (style != null) {
            return style.getFormatter().withLocale(DateTimeTools.getLocale());
        }
        final Optional<DateTimeFormatter> builtin = DateTimeTools.getJreBuiltinFormatter(format);
        return builtin.orElseGet(() -> DateTimeFormatter.ofPattern(format, DateTimeTools.getLocale()));
    }
    return defaultFormatter.withLocale(DateTimeTools.getLocale());
}
 
Example #25
Source File: NavigationTags.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 {
    String alias = ((SimpleScalar) params.getOrDefault("alias", new SimpleScalar("navigations"))).getAsString();

    List<Navigation> navigations = navigationService.getNavigation();

    env.setVariable(alias, wrap(navigations));
    if (body != null) {
        body.render(env.getOut());
    }
}
 
Example #26
Source File: AdTags.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 {
    SimpleScalar positionCode = (SimpleScalar) params.getOrDefault("positionCode", "");
    List<Ad> ads = adService.getAdByPositionCode(positionCode.getAsString());

    env.setVariable("ads", wrap(ads));
    if (body != null) {
        body.render(env.getOut());
    }
}
 
Example #27
Source File: RequestTag.java    From cms with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Environment env, Map params, TemplateModel[] templateModels, TemplateDirectiveBody body) throws TemplateException, IOException {
    String alias = ((SimpleScalar) params.getOrDefault("alias", new SimpleScalar("currentURI"))).getAsString();
    String currentURI = request.getRequestURI();
    env.setVariable(alias, wrap(currentURI));
    if (body != null) {
        body.render(env.getOut());
    }
}
 
Example #28
Source File: ArticleTags.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 {
    SimpleScalar id = (SimpleScalar) params.get("id");
    SimpleScalar categoryId = (SimpleScalar) params.get("categoryId");
    SimpleScalar type = (SimpleScalar) params.get("type");
    SimpleScalar showCountParms = (SimpleScalar) params.get("showCount");
    Integer showCount = showCountParms == null ? 10 : Integer.parseInt(showCountParms.toString());
    SimpleScalar nameParms = (SimpleScalar) params.get("alias");
    String name = nameParms == null ? "article" : nameParms.toString();

    List<Article> list = null;
    try {
        Long catId = null;
        Integer _type = null;
        if (categoryId != null) {
            catId = Long.parseLong(categoryId.toString());
        }
        if (type != null) {
            _type = Integer.parseInt(type.toString());
        }
        list = articleService.getArticleList(Long.parseLong(id.toString()), catId, _type, showCount);

    } catch (Exception e) {
    } finally {
        env.setVariable(name, wrap(list));
        if (body != null) {
            body.render(env.getOut());
        }
    }

}
 
Example #29
Source File: AdTags.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 {
    SimpleScalar id = (SimpleScalar) params.get("id");
    List<Ad> ads = adService.getAdByPositionId(Long.parseLong(id.toString()));

    env.setVariable("ads", wrap(ads));
    if (body != null) {
        body.render(env.getOut());
    }
}
 
Example #30
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the logical raw string operation on a single value.
 */
public static TemplateScalarModel toRawString(TemplateModel value, Environment env) throws TemplateModelException {
    if (value instanceof TemplateScalarModel) {
        TemplateScalarModel strModel = (TemplateScalarModel) value;
        String str = getAsStringNonEscaping(strModel);
        return new SimpleScalar(str); // Emulates Freemarker ?string built-in
    } else {
        return execStringBuiltIn(value, env);
    }
}