freemarker.template.SimpleSequence Java Examples
The following examples show how to use
freemarker.template.SimpleSequence.
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: GetStyleNamesByPrefixMethod.java From scipio-erp with Apache License 2.0 | 6 votes |
@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)"); } 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; }
Example #2
Source File: PagerTag.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public int doStartTag() throws JspException { ServletRequest request = this.pageContext.getRequest(); try { Object object = this.pageContext.getAttribute(this.getListName()); Collection collection = (null != object && object instanceof SimpleSequence) ? ((SimpleSequence) object).toList() : (Collection) object; if (collection == null) { _logger.error("There is no list in the request"); } else { PagerTagHelper helper = new PagerTagHelper(); IPagerVO pagerVo = helper.getPagerVO(collection, this.getPagerId(), this.isPagerIdFromFrame(), this.getMax(), this.isAdvanced(), this.getOffset(), request); this.pageContext.setAttribute(this.getObjectName(), pagerVo); } } catch (Throwable t) { _logger.error("Error detected during tag initialization", t); //ApsSystemUtils.logThrowable(e, this, "doStartTag"); throw new JspException("Error detected during tag initialization", t); } return EVAL_BODY_INCLUDE; }
Example #3
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "unused" }) @Deprecated private static TemplateSequenceModel toSimpleSequence(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException { if (object instanceof TemplateSequenceModel) { return (TemplateSequenceModel) object; } else if (object instanceof WrapperTemplateModel) { WrapperTemplateModel wrapperModel = (WrapperTemplateModel) object; // WARN: bypasses auto-escaping Object wrappedObject = wrapperModel.getWrappedObject(); if (wrappedObject instanceof List) { return DefaultListAdapter.adapt((List<Object>) wrappedObject, (RichObjectWrapper) objectWrapper); } else if (wrappedObject instanceof Object[]) { return DefaultArrayAdapter.adapt((Object[]) wrappedObject, (ObjectWrapperAndUnwrapper) objectWrapper); } else if (wrappedObject instanceof Set) { throw new UnsupportedOperationException("Not yet implemented"); } else if (wrappedObject instanceof Collection) { throw new UnsupportedOperationException("Not yet implemented"); } else if (wrappedObject instanceof Iterable) { throw new UnsupportedOperationException("Not yet implemented"); } else { throw new TemplateModelException("Cannot convert bean-wrapped object of type " + (object != null ? object.getClass() : "null") + " to simple sequence"); } } else if (object instanceof TemplateCollectionModel) { TemplateCollectionModel collModel = (TemplateCollectionModel) object; SimpleSequence res = new SimpleSequence(objectWrapper); TemplateModelIterator it = collModel.iterator(); while(it.hasNext()) { res.add(it.next()); } return res; } else { throw new TemplateModelException("Cannot convert object of type " + (object != null ? object.getClass() : "null") + " to simple sequence"); } }
Example #4
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
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()); } }
Example #5
Source File: Dom4jNodeModel.java From engine with GNU General Public License v3.0 | 5 votes |
@Override public TemplateSequenceModel getChildNodes() throws TemplateModelException { if (node instanceof Branch) { List childNodes = ((Branch) node).content(); if (childNodes != null) { return new SimpleSequence(childNodes, wrapper); } else { return null; } } else { return new SimpleSequence(Collections.emptyList(), wrapper); } }
Example #6
Source File: FreeMarkerUtil.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example #7
Source File: GetProblemSummariesMethod.java From windup with Eclipse Public License 1.0 | 5 votes |
@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; }
Example #8
Source File: IsReportableFile.java From windup with Eclipse Public License 1.0 | 5 votes |
@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); } }
Example #9
Source File: SortFilesByPathMethod.java From windup with Eclipse Public License 1.0 | 5 votes |
@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()); } }
Example #10
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 4 votes |
public static void addToSimpleList(SimpleSequence dest, TemplateCollectionModel source) throws TemplateModelException { TemplateModelIterator it = source.iterator(); while(it.hasNext()) { dest.add(it.next()); } }
Example #11
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 4 votes |
public static void addToSimpleList(SimpleSequence dest, TemplateSequenceModel source) throws TemplateModelException { for(int i=0; i < source.size(); i++) { dest.add(source.get(0)); } }
Example #12
Source File: SelectTag.java From javalite with Apache License 2.0 | 4 votes |
@Override protected void render(Map params, String body, Writer writer) throws Exception { validateParamsPresence(params, "list"); Object listObj = params.get("list"); if (!(listObj instanceof SimpleSequence)) { throw new ViewException("Mandatory parameter 'list' must be java.util.List"); } SimpleSequence sequence = (SimpleSequence) listObj; List options = sequence.toList(); //doing verification in this loop before writing to writer so that not to have a partial write. for(Object item: options){ if(!(item instanceof SelectOption)){ throw new ViewException("Must place " + SelectOption.class.getName() + " instances into select tag"); } } StringBuffer optionsBuffer = new StringBuffer(); for(Object o: options){ SelectOption option = (SelectOption) o; TagFactory tf = new TagFactory("option", option.getLabel()); tf.attribute("value", option.getValue()); if(!option.isEnabled()){ tf.attribute("disabled", "true"); } if(option.isSelected()){ tf.attribute("selected", "true"); } optionsBuffer.append(tf.toString()); } TagFactory selectTf = new TagFactory("select", body + optionsBuffer); selectTf.addAttributesExcept(params, "list", "data"); if(params.containsKey("data")){ selectTf.textAttributes(params.get("data").toString()); } selectTf.write(writer); }
Example #13
Source File: GetEffortDetailsForProjectTraversalMethod.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { // Process arguments ExecutionStatistics.get().begin(NAME); if (arguments.size() < 2) { throw new TemplateModelException( "Error, method expects at least three arguments" + " (projectModel: ProjectModel, recursive: Boolean, [includeTags: Set<String>], [excludeTags: Set<String>])"); } StringModel projectModelTraversalArg = (StringModel) arguments.get(0); ProjectModelTraversal projectModelTraversal = (ProjectModelTraversal) projectModelTraversalArg.getWrappedObject(); TemplateBooleanModel recursiveBooleanModel = (TemplateBooleanModel) arguments.get(1); boolean recursive = recursiveBooleanModel.getAsBoolean(); Set<String> includeTags = Collections.emptySet(); if (arguments.size() >= 3) { includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(2)); } Set<String> excludeTags = Collections.emptySet(); if (arguments.size() >= 4) { excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(3)); } Set<String> issueCategories = Collections.emptySet(); if (arguments.size() >= 5) { issueCategories = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(4)); } // Get values for classification and hints. Map<Integer, Integer> classificationEffortDetails = classificationService.getMigrationEffortByPoints(projectModelTraversal, includeTags, excludeTags, issueCategories, recursive, false); Map<Integer, Integer> hintEffortDetails = inlineHintService.getMigrationEffortByPoints(projectModelTraversal, includeTags, excludeTags, issueCategories, recursive, false); Map<Integer, Integer> results = sumMaps(classificationEffortDetails, hintEffortDetails); ExecutionStatistics.get().end(NAME); int points = sumPoints(results); LOG.fine(String.format("%s() FM function called:\n\t\t\tEFFORT: %3d = %s = C%s + H%s; %s, %srecur, tags: %s, excl: %s", NAME, points, results, classificationEffortDetails, hintEffortDetails, projectModelTraversal, recursive ? "" : "!", includeTags, excludeTags)); return results; }
Example #14
Source File: GetEffortCountForProjectByIssueCategoryMethod.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { ExecutionStatistics.get().begin(NAME); if (arguments.size() < 3) { throw new TemplateModelException( "Error, method expects at least three arguments (event:GraphRewrite, projectModelTraversal:ProjectModelTraversal, recursive:Boolean, [includeTags:Set<String>]. [excludeTags:Set<String>])"); } GraphRewrite event = (GraphRewrite)((StringModel)arguments.get(0)).getWrappedObject(); StringModel projectModelTraversalArg = (StringModel) arguments.get(1); ProjectModelTraversal traversal = (ProjectModelTraversal) projectModelTraversalArg.getWrappedObject(); TemplateBooleanModel recursiveBooleanModel = (TemplateBooleanModel) arguments.get(2); boolean recursive = recursiveBooleanModel.getAsBoolean(); Set<String> includeTags = Collections.emptySet(); if (arguments.size() >= 4) { includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(3)); } Set<String> excludeTags = Collections.emptySet(); if (arguments.size() >= 5) { excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) arguments.get(4)); } Map<IssueCategoryModel, Integer> classificationEffortDetails = classificationService.getMigrationEffortBySeverity(event, traversal, includeTags, excludeTags, Collections.emptySet(), recursive); Map<IssueCategoryModel, Integer> hintEffortDetails = inlineHintService.getMigrationEffortBySeverity(event, traversal, includeTags, excludeTags, Collections.emptySet(), recursive); Map<IssueCategoryModel, Integer> results = new TreeMap<>(new IssueCategoryModel.IssueSummaryPriorityComparator()); addAllIncidents(results, classificationEffortDetails); addAllIncidents(results, hintEffortDetails); ExecutionStatistics.get().end(NAME); return results; }
Example #15
Source File: RenderApplicationPieChartDirective.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { StringModel projectStringModel = (StringModel) params.get("project"); ProjectModel projectModel = null; if (projectStringModel != null) projectModel = (ProjectModel) projectStringModel.getWrappedObject(); StringModel projectTraversalStringModel = (StringModel) params.get("projectTraversal"); ProjectModelTraversal projectTraversal = null; if (projectTraversalStringModel != null) projectTraversal = (ProjectModelTraversal) projectTraversalStringModel.getWrappedObject(); if (projectModel != null && projectTraversal != null) throw new WindupException(NAME + " both 'project' and 'projectTraversal' were specified. Only one of these values should be specified."); else if (projectModel == null && projectTraversal == null) throw new WindupException(NAME + " neither 'project' nor 'projectTraversal' were specified. At least one of these must be specified."); TemplateBooleanModel recursiveBooleanModel = (TemplateBooleanModel) params.get("recursive"); boolean recursive = recursiveBooleanModel.getAsBoolean(); SimpleScalar elementIDStringModel = (SimpleScalar) params.get("elementID"); String elementID = elementIDStringModel.getAsString(); Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) params.get("includeTags")); Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) params.get("excludeTags")); TypeReferenceService typeReferenceService = new TypeReferenceService(context); Map<String, Integer> data; if (projectModel != null) data = typeReferenceService.getPackageUseFrequencies(projectModel, includeTags, excludeTags, 2, recursive); else data = typeReferenceService.getPackageUseFrequencies(projectTraversal, includeTags, excludeTags, 2, recursive); if (data.keySet().size() > 0) { drawPie(env.getOut(), data, elementID); } else { // if we aren't drawing a pie, remove the element that would have held it Writer writer = env.getOut(); writer.append("<script type='text/javascript'>"); writer.append("$('#" + elementID + "').parent().remove()"); writer.append("</script>"); } }