本文整理匯總了Java中freemarker.template.SimpleHash類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleHash類的具體用法?Java SimpleHash怎麽用?Java SimpleHash使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleHash類屬於freemarker.template包,在下文中一共展示了SimpleHash類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeSimpleMapAdapter
import freemarker.template.SimpleHash; //導入依賴的package包/類
/**
* Adapts a map to a TemplateHashModelEx using an appropriate simple adapter, normally
* DefaultMapAdapter (or SimpleMapModel for BeansWrapper compatibility).
* <p>
* The ObjectWrapper is expected to implement at least ObjectWrapperWithAPISupport.
* <p>
* WARN: If impossible, it will duplicate the map using SimpleHash; but because this may result
* in loss of ordering, a log warning will be printed.
*/
public static TemplateHashModelEx makeSimpleMapAdapter(Map<?, ?> map, ObjectWrapper objectWrapper, boolean permissive) throws TemplateModelException {
// COMPATIBILITY MODE: check if exactly BeansWrapper, or a class that we know extends it WITHOUT extending DefaultObjectWrapper
if (objectWrapper instanceof ScipioBeansWrapper || BeansWrapper.class.equals(objectWrapper.getClass())) {
return new SimpleMapModel(map, (BeansWrapper) objectWrapper);
} else if (objectWrapper instanceof ObjectWrapperWithAPISupport) {
return DefaultMapAdapter.adapt(map, (ObjectWrapperWithAPISupport) objectWrapper);
} else {
if (permissive) {
Debug.logWarning("Scipio: adaptSimpleMap: Unsupported Freemarker object wrapper (expected to implement ObjectWrapperWithAPISupport or BeansWrapper); forced to adapt map"
+ " using SimpleHash; this could cause loss of map insertion ordering; please switch renderer setup to a different ObjectWrapper", module);
return new SimpleHash(map, objectWrapper);
} else {
throw new TemplateModelException("Tried to wrap a Map using an adapter class,"
+ " but our ObjectWrapper does not implement ObjectWrapperWithAPISupport or BeansWrapper"
+ "; please switch renderer setup to a different ObjectWrapper");
}
}
}
示例2: combineMaps
import freemarker.template.SimpleHash; //導入依賴的package包/類
/**
* Combines two maps with the given operator into a new hash.
*/
public static TemplateHashModelEx combineMaps(TemplateHashModelEx first, TemplateHashModelEx second, SetOperations ops,
ObjectWrapper objectWrapper) throws TemplateModelException {
SimpleHash res = new SimpleHash(objectWrapper);
if (ops == null || ops == SetOperations.UNION) {
// this is less efficient than freemarker + operator, but provides the "alternative" implementation, so have choice
addToSimpleMap(res, first);
addToSimpleMap(res, second);
}
else if (ops == SetOperations.INTERSECT) {
Set<String> intersectKeys = toStringSet(second.keys());
intersectKeys.retainAll(toStringSet(first.keys()));
addToSimpleMap(res, second, intersectKeys);
}
else if (ops == SetOperations.DIFFERENCE) {
Set<String> diffKeys = toStringSet(first.keys());
diffKeys.removeAll(toStringSet(second.keys()));
addToSimpleMap(res, first, diffKeys);
}
else {
throw new TemplateModelException("Unsupported combineMaps operation");
}
return res;
}
示例3: merge
import freemarker.template.SimpleHash; //導入依賴的package包/類
private void merge() {
try (PrintWriter writer = new PrintWriter(fileCreator.getReportFile("html", getReportStartingDate()),
StandardCharsets.UTF_8.name())) {
SimpleHash root = new SimpleHash();
root.put("collector", testEventCollector);
root.put("date", new SimpleDateFormat("yyyy-MM-dd HH.mm.ss").format(new Date()));
root.put("total", getTestCount());
root.put("passed", getPassedTestCount());
root.put("failed", getFailedCount());
root.put("passedPercent", getPassedTestPercent());
root.put("failedPercent", getFailedPercent());
temp.process(root, writer);
writer.flush();
} catch (TemplateException | IOException e) {
LOG.error("Exception when merging model with template", e);
}
}
示例4: getSubSubField
import freemarker.template.SimpleHash; //導入依賴的package包/類
public List getSubSubField(Subfield subfield,SimpleHash subField){
List ssf=new ArrayList();;
for (int j=0; j<subfield.getSubsubfieldCount(); j++){
Subsubfield subsubfield=subfield.getSubsubfield(j);
if(subsubfield!=null){
SimpleHash subSubField=new SimpleHash();
subSubField.put("name",subsubfield.getName()+"");
String cont=subsubfield.getContent();
cont=cont.replaceAll("<","<");
cont=cont.replaceAll(">",">");
subSubField.put("content",cont);
if(!subsubfield.getContent().equals("")&& !subsubfield.getContent().equals(" ")){
ssf.add(subSubField);
}
}
}
return ssf;
}
示例5: render
import freemarker.template.SimpleHash; //導入依賴的package包/類
@Override
public void render(JAGeneratorContext context) throws Exception {
util = new JavaClassGeneratorUtil(getId().getClassName());
ByteArrayOutputStream bodyStream = renderBody(context);
// Now render header in case there are injections
ByteArrayOutputStream headerStream = renderHeader(context);
// Now add the header
SimpleHash freemarkerContext = context.createSimpleHash();
freemarkerContext.put("model", this);
freemarkerContext.put("util", util);
freemarkerContext.put("context", context);
Template template = context.getTemplate("JavaHeader.ftl");
File file = getPath(context).toFile();
// create file structure
file.getParentFile().mkdirs();
// before writing to it
FileOutputStream outputStream = new FileOutputStream(file);
template.process(freemarkerContext, new OutputStreamWriter(outputStream));
// And append the header & body
if (headerStream != null) {
headerStream.writeTo(outputStream);
}
bodyStream.writeTo(outputStream);
}
示例6: renderHeader
import freemarker.template.SimpleHash; //導入依賴的package包/類
private ByteArrayOutputStream renderHeader(JAGeneratorContext context) throws IOException, TemplateException {
String headerTemplate = getFreemarkerHeaderTemplateName();
if (headerTemplate != null) {
SimpleHash freemarkerContext = context.createSimpleHash();
freemarkerContext.put("model", getFreemarkerModel());
freemarkerContext.put("util", util);
freemarkerContext.put("context", context);
// First process body
Template template = context.getTemplate(headerTemplate);
ByteArrayOutputStream headerStream = new ByteArrayOutputStream();
template.process(freemarkerContext, new OutputStreamWriter(headerStream));
return headerStream;
} else {
return null;
}
}
示例7: render
import freemarker.template.SimpleHash; //導入依賴的package包/類
/**
* 渲染
*
*/
public void render(RenderClass target, String template, String outpath) {
try {
StringWriter writer = new StringWriter();
Template tl = templateconfig.getTemplate(template,
templateconfig.getLocale());
SimpleHash root= new SimpleHash();
root.put("entity", target);
tl.process(root, writer);
// Assistant.createNewFile(outpath);
FileOutputStream fos = new FileOutputStream(outpath);
PrintWriter pwriter = new PrintWriter(fos);
pwriter.write(writer.toString());
pwriter.close();
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例8: render
import freemarker.template.SimpleHash; //導入依賴的package包/類
/**
* 渲染
*
*/
public void render(RenderClass target,String template,String outpath)
{
try
{
StringWriter writer = new StringWriter();
Template tl = templateconfig.getTemplate(
template,
templateconfig.getLocale());
SimpleHash root = new SimpleHash();
root.put("entity", target);
tl.process(root, writer);
Assistant.createNewFile(outpath);
FileOutputStream fos = new FileOutputStream(outpath);
PrintWriter pwriter = new PrintWriter(fos);
pwriter.write(writer.toString());
pwriter.close();
fos.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
示例9: generate
import freemarker.template.SimpleHash; //導入依賴的package包/類
@Override
public Set<FileInfo> generate(CGModel cgModel, CGConfig config) throws ModuleException {
Set<FileInfo> targetFileSet = new HashSet<>();
SimpleHash fmModel = this.getFreemarkerModel();
fmModel.put("config", config);
Map<String, String> enumConstants = new HashMap<>();
for (EnumInfo enums : cgModel.getEnums()) {
enumConstants.put(enums.getName(), joinEnumConstants(enums.getEnumConstants()));
}
fmModel.put("enumConstants", enumConstants);
for (ClassInfo classInfo : cgModel.getClasses()) {
fmModel.put("clazz", classInfo);
}
fmModel.put("classes", cgModel.getClasses());
String relativePath = ClassNameUtil.packageNameToPath("com.vsc_technologies");
FileInfo classFile = this.generateFile(classTemplate, fmModel, "schemas", "coffee", relativePath, SOURCE_FOLDER);
targetFileSet.add(classFile);
return targetFileSet;
}
示例10: generate
import freemarker.template.SimpleHash; //導入依賴的package包/類
@Override
public Set<FileInfo> generate(CGModel cgModel, CGConfig config) throws ModuleException {
Set<FileInfo> targetFileSet = new HashSet<>();
SimpleHash fmModel = this.getFreemarkerModel();
fmModel.put("config", config);
Map<String, String> enumConstants = new HashMap<>();
for (EnumInfo enums : cgModel.getEnums()) {
enumConstants.put(enums.getName(), joinEnumConstants(enums.getEnumConstants()));
}
fmModel.put("enumConstants", enumConstants);
for (ClassInfo classInfo : cgModel.getClasses()) {
fmModel.put("clazz", classInfo);
}
fmModel.put("classes", cgModel.getClasses());
String relativePath = ClassNameUtil.packageNameToPath("com.vsc_technologies");
FileInfo classFile = this.generateFile(classTemplate, fmModel, "schemas", "js", relativePath, SOURCE_FOLDER);
targetFileSet.add(classFile);
return targetFileSet;
}
示例11: getModel
import freemarker.template.SimpleHash; //導入依賴的package包/類
private static TemplateModel getModel (String screen_name, long interval) {
List<Follower> followers = ui.getRecentFollowers(screen_name, interval);
List<Unfollower> unfollowers = ui.getRecentUnfollowers(screen_name, interval);
int unfollowers_deleted = 0;
for (Iterator<Unfollower> i = unfollowers.iterator(); i.hasNext();) {
Unfollower u = i.next();
if (u.getFollowerScreenName().startsWith("*")) {
i.remove();
unfollowers_deleted++;
}
}
SimpleHash root = new SimpleHash();
root.put("screen_name", screen_name);
root.put("interval", interval);
root.put("followers", followers);
root.put("unfollowers", unfollowers);
root.put("unfollowers_deleted", unfollowers_deleted);
return root;
}
示例12: initReportRoute
import freemarker.template.SimpleHash; //導入依賴的package包/類
protected void initReportRoute() throws IOException {
get(new FreemarkerBasedRoute("/item/report", "report.ftl") {
@Override
protected void doHandle(Request request, Response response, Writer writer) throws IOException, TemplateException {
String itemId = request.queryParams("id");
CityItem cityItem = CityItemDAO.getCityItem(itemId);
SimpleHash data = new SimpleHash();
data.put("id", itemId);
data.put("type", cityItem.getTypeAsString());
data.put("description", cityItem.getDescription());
data.put("lat", cityItem.getLatitude());
data.put("lng", cityItem.getLongitude());
template.process(data, writer);
}
});
post(new Route("/item/report") {
@Override
public Object handle(Request rqst, Response rspns) {
Report.Builder b = new Report.Builder();
b.cityItemId(rqst.queryParams("id"))
.comment(rqst.queryParams("comment"))
.priority(Integer.parseInt(rqst.queryParams("priority")))
.reportDate(new Date())
.resolved(false);
ReportDAO.insertReport(b.build());
JSONObject jsonResult = new JSONObject();
jsonResult.put("success", true);
return jsonResult.toString();
}
});
}
示例13: initIndexRoute
import freemarker.template.SimpleHash; //導入依賴的package包/類
protected void initIndexRoute() throws IOException {
get(new FreemarkerBasedRoute("/", "index.ftl") {
@Override
public void doHandle(
Request request, Response response, Writer writer)
throws IOException, TemplateException {
SimpleHash data = new SimpleHash();
data.put("Username", "dummy");
template.process(data, writer);
}
});
}
示例14: toMapModel
import freemarker.template.SimpleHash; //導入依賴的package包/類
public TemplateHashModelEx toMapModel(Environment env) {
SimpleHash map = new SimpleHash(env.getObjectWrapper());
map.put("ctxVars", ctxVars);
map.put("globalCtxVars", globalCtxVars);
map.put("reqAttribs", reqAttribs);
return map;
}
示例15: execMergeArgMapsToLocals
import freemarker.template.SimpleHash; //導入依賴的package包/類
@SuppressWarnings("unchecked")
protected Object execMergeArgMapsToLocals(List methodArgs, boolean recordArgNames) throws TemplateModelException {
Environment env = CommonFtlUtil.getCurrentEnvironment();
SimpleHash resArgs = (SimpleHash) execMergeArgMaps(methodArgs, recordArgNames, env);
LangFtlUtil.localsPutAll(resArgs, env);
env.setLocalVariable("args", resArgs);
return new SimpleScalar("");
}