本文整理汇总了Java中freemarker.template.SimpleSequence类的典型用法代码示例。如果您正苦于以下问题:Java SimpleSequence类的具体用法?Java SimpleSequence怎么用?Java SimpleSequence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleSequence类属于freemarker.template包,在下文中一共展示了SimpleSequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
if (args == null || args.size() != 2) {
throw new TemplateModelException("Invalid number of arguments (expected: 2)");
}
String styleString = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
styleString = TemplateFtlUtil.getPlainClassArgNames(styleString);
String prefix = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(1)));
String[] names = StringUtils.split(styleString, ' ');
// NOTE: For emergency/safety reasons, use the current wrapper, which MAY be escaping.
// style strings contain only simple characters anyway.
ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper();
SimpleSequence res = new SimpleSequence(names.length, objectWrapper);
for(String name : names) {
if (name.startsWith(prefix)) {
res.add(name);
}
}
// redundant
//return LangFtlUtil.wrap(res, objectWrapper);
return res;
}
示例2: getComplexParams
import freemarker.template.SimpleSequence; //导入依赖的package包/类
protected Map getComplexParams(Map params) {
HashMap map = new HashMap(params.size());
for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
Object value = entry.getValue();
if (value != null && complexType(value)) {
if (value instanceof freemarker.ext.beans.BeanModel) {
map.put(entry.getKey(), ((freemarker.ext.beans.BeanModel) value).getWrappedObject());
} else if (value instanceof SimpleNumber) {
map.put(entry.getKey(), ((SimpleNumber) value).getAsNumber());
} else if (value instanceof SimpleSequence) {
try {
map.put(entry.getKey(), ((SimpleSequence) value).toList());
} catch (TemplateModelException e) {
if (LOG.isErrorEnabled()) {
LOG.error("There was a problem converting a SimpleSequence to a list", e);
}
}
}
}
}
return map;
}
示例3: parseSequenceParameter
import freemarker.template.SimpleSequence; //导入依赖的package包/类
/**
* Parse sequence parameter.
*
* @param params the params
* @param paramName the param name
* @return the string [ ]
* @throws TemplateModelException the template model exception
*/
@SuppressWarnings("rawtypes")
protected String[] parseSequenceParameter(Map params, String paramName) throws TemplateModelException {
Object paramModel = params.get(paramName);
if (paramModel == null) {
return null;
}
if (!(paramModel instanceof SimpleSequence)) {
throw new IllegalArgumentException(paramName + " must be sequence");
}
List<String> list = transformSimpleSequenceAsStringList((SimpleSequence)paramModel, paramName);
return list.toArray(new String[list.size()]);
}
示例4: transformSimpleSequenceAsStringList
import freemarker.template.SimpleSequence; //导入依赖的package包/类
/**
* Transform simple sequence as string list.
*
* @param sequence the sequence
* @param paramName the param name
* @return the list
* @throws TemplateModelException the template model exception
*/
private List<String> transformSimpleSequenceAsStringList(SimpleSequence sequence, String paramName)
throws TemplateModelException {
List<String> list = new ArrayList<>();
int size = sequence.size();
for (int i = 0; i < size; i++) {
TemplateModel model = sequence.get(i);
if (!(model instanceof SimpleScalar)) {
throw new IllegalArgumentException(paramName + "'s item must be string");
}
list.add(((SimpleScalar)model).getAsString());
}
return list;
}
示例5: loadDataModel
import freemarker.template.SimpleSequence; //导入依赖的package包/类
private SimpleSequence loadDataModel(Engine engine, List<?> args) throws Exception {
final List<TemplateModel> templateModels = new ArrayList<TemplateModel>();
for (int i = 0; i < args.size(); i++) {
final String resourceName = args.get(i).toString();
final URL resource = loadResource(engine, resourceName);
if (resource != null) {
final TemplateModel templateModel = templateLoader.load(resource);
if (templateModel != null) {
templateModels.add(templateModel);
}
} else {
throw new IllegalArgumentException("resource[" + i + "] not found: " + resourceName);
}
}
return new SimpleSequence(templateModels);
}
示例6: exec
import freemarker.template.SimpleSequence; //导入依赖的package包/类
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() < 1) {
throw new TemplateModelException("Wrong arguments");
}
//所有参数都要先转成SimpleSequence
SimpleSequence arg0 = (SimpleSequence)arguments.get(0);
//把参数转换为list
List<String> list = arg0.toList();
TemplateScalarModel value = (TemplateScalarModel)arguments.get(1);
return list.contains(value.getAsString());
}
示例7: addToSimpleList
import freemarker.template.SimpleSequence; //导入依赖的package包/类
public static void addToSimpleList(SimpleSequence dest, TemplateModel source) throws TemplateModelException {
if (source instanceof TemplateCollectionModel) {
addToSimpleList(dest, (TemplateCollectionModel) source);
}
else if (source instanceof TemplateSequenceModel) {
addToSimpleList(dest, (TemplateSequenceModel) source);
}
else {
throw new TemplateModelException("Can't add to simple list from source type (non-list type): " + source.getClass());
}
}
示例8: getSequence
import freemarker.template.SimpleSequence; //导入依赖的package包/类
public static List<Object> getSequence(SimpleSequence ss){
List<Object> res=new ArrayList<Object>();
for(int i=0;i<ss.size();i++){
try {
Object obj=ss.get(i);
res.add(unwrapObject(obj));
} catch (TemplateModelException e) {
e.printStackTrace();
}
}
return res;
}
示例9: loadDataModel
import freemarker.template.SimpleSequence; //导入依赖的package包/类
private SimpleSequence loadDataModel(Engine engine, List<?> args) throws Exception {
final List<Class<?>> classes = loadClasses(engine, args);
final List<TemplateModel> templateModels = new ArrayList<TemplateModel>();
for (final Class<?> clazz : classes) {
final TemplateModel templateModel = templateLoader.load(clazz);
if (templateModel != null) {
templateModels.add(templateModel);
}
}
return new SimpleSequence(templateModels);
}
示例10: load
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public SimpleSequence load(Engine engine, List args) throws Exception {
System.out.println("loading option set definitions...");
System.out.println("...args: " + args);
final SimpleSequence result = super.load(engine, args);
System.out.println("loaded " + result.size() + " option set definitions.");
return result;
}
示例11: load
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public SimpleSequence load(Engine engine, List args) throws Exception {
System.out.println("loading command definitions...");
System.out.println("...args: " + args);
final SimpleSequence result = super.load(engine, args);
System.out.println("loaded " + result.size() + " command definitions.");
return result;
}
示例12: simpleSequenceToSet
import freemarker.template.SimpleSequence; //导入依赖的package包/类
/**
* Converts a FreeMarker {@link SimpleSequence} to a {@link Set}.
*
*/
public static Set<String> simpleSequenceToSet(SimpleSequence simpleSequence)
{
if (simpleSequence == null)
return Collections.emptySet();
Set<String> result = new HashSet<>();
for (int i = 0; i < simpleSequence.size(); i++)
{
try
{
Object sequenceEntry = simpleSequence.get(i);
if (sequenceEntry instanceof SimpleScalar)
{
result.add(((SimpleScalar) sequenceEntry).getAsString());
}
else
{
result.add(simpleSequence.get(i).toString());
}
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
return result;
}
示例13: exec
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@Override
public Object exec(List arguments) throws TemplateModelException
{
if (arguments.isEmpty())
throw new TemplateModelException("Method " + getMethodName() + " requires the following parameters (GraphRewrite event, ProjectModel project, Set<String> includeTags, Set<String> excludeTags)");
// Gets the graph rewrite event
final GraphRewrite event = (GraphRewrite)((StringModel)arguments.get(0)).getWrappedObject();
// Get the project if one was passed in
final ProjectModel projectModel;
StringModel projectModelArg = (StringModel) arguments.get(1);
if (projectModelArg == null)
projectModel = null;
else
projectModel = (ProjectModel) projectModelArg.getWrappedObject();
Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));
Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(3));
Set<ProjectModel> projectModels = getProjects(projectModel);
Map<IssueCategoryModel, List<ProblemSummary>> problemSummariesOriginal
= ProblemSummaryService.getProblemSummaries(event.getGraphContext(), projectModels, includeTags, excludeTags);
// Convert the keys to String to make Freemarker happy
Comparator<IssueCategoryModel> severityComparator = new IssueCategoryModel.IssueSummaryPriorityComparator();
Map<IssueCategoryModel, List<ProblemSummary>> problemSummaries = new TreeMap<>(severityComparator);
problemSummaries.putAll(problemSummariesOriginal);
Map<String, List<ProblemSummary>> primarySummariesByString = new LinkedHashMap<>(problemSummariesOriginal.size());
for (Map.Entry<IssueCategoryModel, List<ProblemSummary>> entry : problemSummaries.entrySet())
{
String severityString = entry.getKey() == null ? null : entry.getKey().getName();
primarySummariesByString.put(severityString, entry.getValue());
}
return primarySummariesByString;
}
示例14: exec
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
ExecutionStatistics.get().begin(NAME);
try
{
if (arguments.size() != 3)
{
throw new TemplateModelException("Error, method expects one argument (FileModel, includeTags:Set<String>, excludeTags:Set<String>)");
}
StringModel stringModelArg = (StringModel) arguments.get(0);
FileModel fileModel = (FileModel) stringModelArg.getWrappedObject();
Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(1));
Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2));
SourceReportModel result = sourceReportService.getSourceReportForFileModel(fileModel);
if (result == null)
return false;
return TagUtil.hasHintsOrClassificationsWithRelevantTags(result.getSourceFileModel(), includeTags, excludeTags);
}
finally
{
ExecutionStatistics.get().end(NAME);
}
}
示例15: getIterable
import freemarker.template.SimpleSequence; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Iterable<Object> getIterable(Object arg) throws TemplateModelException
{
if (arg instanceof BeanModel)
{
BeanModel beanModel = (BeanModel) arg;
return (Iterable<Object>) beanModel.getWrappedObject();
}
else if (arg instanceof SimpleSequence)
{
SimpleSequence simpleSequence = (SimpleSequence) arg;
return (Iterable<Object>) simpleSequence.toList();
}
else if (arg instanceof DefaultIterableAdapter)
{
DefaultIterableAdapter adapter = (DefaultIterableAdapter) arg;
return (Iterable<Object>) adapter.getAdaptedObject(Iterable.class);
}
else if (arg instanceof DefaultListAdapter)
{
DefaultListAdapter defaultListAdapter = (DefaultListAdapter) arg;
return (Iterable<Object>) defaultListAdapter.getWrappedObject();
}
else
{
throw new WindupException("Unrecognized type passed to: " + getMethodName() + ": "
+ arg.getClass().getCanonicalName());
}
}