當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleHash類代碼示例

本文整理匯總了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");
        }
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:28,代碼來源:LangFtlUtil.java

示例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;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:27,代碼來源:LangFtlUtil.java

示例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);
    }
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:18,代碼來源:HtmlReporter.java

示例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("<","&lt;");
            cont=cont.replaceAll(">","&gt;");
            subSubField.put("content",cont);
            
            if(!subsubfield.getContent().equals("")&& !subsubfield.getContent().equals(" ")){
            	ssf.add(subSubField);
            }
  		}
	}
	return ssf;
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:21,代碼來源:Base.java

示例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);
}
 
開發者ID:iorga-group,項目名稱:ivif,代碼行數:25,代碼來源:JavaTargetFile.java

示例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;
    }
}
 
開發者ID:iorga-group,項目名稱:ivif,代碼行數:17,代碼來源:JavaTargetFile.java

示例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();
	}
}
 
開發者ID:RayleighChen,項目名稱:Improve,代碼行數:23,代碼來源:FreemarkerRender.java

示例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();
	}
}
 
開發者ID:RayleighChen,項目名稱:Improve,代碼行數:28,代碼來源:FreemarkerRender.java

示例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;
}
 
開發者ID:agodet,項目名稱:wadlcodegenerator,代碼行數:26,代碼來源:CoffeeScriptClientModule.java

示例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;
}
 
開發者ID:agodet,項目名稱:wadlcodegenerator,代碼行數:26,代碼來源:EcmaScript6ClientModule.java

示例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;
}
 
開發者ID:drmirror,項目名稱:followt,代碼行數:20,代碼來源:WebUI.java

示例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();
        }
    });
}
 
開發者ID:Labas-Vakaras,項目名稱:Smart_City,代碼行數:38,代碼來源:ReportRoutes.java

示例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);
        }
    });
}
 
開發者ID:Labas-Vakaras,項目名稱:Smart_City,代碼行數:14,代碼來源:CityItemRoutes.java

示例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;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:8,代碼來源:MultiVarMethod.java

示例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(""); 
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:12,代碼來源:ArgMapMethod.java


注:本文中的freemarker.template.SimpleHash類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。