Java Code Examples for freemarker.template.SimpleHash#put()

The following examples show how to use freemarker.template.SimpleHash#put() . 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: WrapTag.java    From javalite with Apache License 2.0 6 votes vote down vote up
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    if(!params.containsKey("with")) {
        throw new RuntimeException("\"with\" param was not provided");
    }

    String withArgument = params.get("with").toString();

    StringWriter innerContent = new StringWriter();
    body.render(innerContent);        

    SimpleHash envValues = getHash(env);
    envValues.putAll(params);
    envValues.put("page_content", innerContent.toString());
    for(Object key : params.keySet()) {
        if(key.toString().equals("with")) {
            continue;
        } else {
            envValues.put(key.toString(), params.get(key));
        }
    }

    String path = getTemplatePath(env.getTemplate().getName(), withArgument);
    Template template = env.getConfiguration().getTemplate(path + ".ftl");
    template.process(envValues, env.getOut());
}
 
Example 2
Source File: MultiVarMethod.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Adds to simple hash from source map.
 * <p>
 * <em>WARN</em>: This is not BeanModel-aware (complex map).
 */
public static void addToSimpleMap(SimpleHash dest, TemplateHashModelEx source) throws TemplateModelException {
    TemplateCollectionModel keysModel = source.keys();
    TemplateModelIterator modelIt = keysModel.iterator();
    while(modelIt.hasNext()) {
        String key = getAsStringNonEscaping((TemplateScalarModel) modelIt.next());
        dest.put(key, source.get(key));
    }
}
 
Example 4
Source File: NanoWSClientModule.java    From mwsc with MIT License 5 votes vote down vote up
@Override
public Set<FileInfo> generate(WSCodeGenModel cgModel, CGConfig config)
		throws WscModuleException {
	// freemarker datamodel
	SimpleHash fmModel = this.getFreemarkerModel();
	
	// container for target codes
	Set<FileInfo> targetFileSet = new HashSet<FileInfo>();
	
	info("Generating the Nano web serivce client classes...");
	
	fmModel.put("group", config.picoServiceGroup);
	fmModel.put("config", config);
	
	// generate endpoint interface
	for (SEIInfo interfaceInfo : cgModel.getServiceEndpointInterfaces()) {
		fmModel.put("imports", this.getInterfaceImports(interfaceInfo));
		fmModel.put("endpointInterface", interfaceInfo);

		String relativePath = ClassNameUtil.packageNameToPath(interfaceInfo.getPackageName());
		relativePath += File.separator + "client";
		FileInfo eiSoapClient = this.generateFile(soapClientTemplate, fmModel, interfaceInfo.getName() + "_SOAPClient", "java", relativePath);
		targetFileSet.add(eiSoapClient);
		FileInfo eiXmlClient = this.generateFile(xmlClientTemplate, fmModel, interfaceInfo.getName() + "_XMLClient", "java", relativePath);
		targetFileSet.add(eiXmlClient);
	}
	
	return targetFileSet;
}
 
Example 5
Source File: RenderComponentDirective.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
protected SimpleHash getFullModel(SiteItem component, Map<String, Object> templateModel,
                                  Map<String, Object> additionalModel) throws TemplateException {
    SimpleHash model = modelFactory.getObject();
    model.put(KEY_MODEL, component);
    model.put(KEY_CONTENT_MODEL, component);

    if (MapUtils.isNotEmpty(templateModel)) {
        model.putAll(templateModel);
    }
    if (MapUtils.isNotEmpty(additionalModel)) {
        model.putAll(additionalModel);
    }

    return model;
}
 
Example 6
Source File: WrapTag.java    From javalite with Apache License 2.0 5 votes vote down vote up
private SimpleHash getHash(Environment env) throws TemplateModelException {
    Set names = env.getKnownVariableNames();
    SimpleHash simpleHash = new SimpleHash();
    for(Object name: names){
        simpleHash.put(name.toString(),env.getVariable(name.toString()));
    }
    return simpleHash;
}
 
Example 7
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
public static void addToSimpleMap(SimpleHash dest, TemplateHashModel source, Set<String> keys) throws TemplateModelException {
    for(String key : keys) {
        dest.put(key, source.get(key));
    }
}
 
Example 8
Source File: PicoWSClientModule.java    From mwsc with MIT License 4 votes vote down vote up
@Override
public Set<FileInfo> generate(WSCodeGenModel cgModel, CGConfig config)
		throws WscModuleException {
	// freemarker datamodel
	SimpleHash fmModel = this.getFreemarkerModel();
	
	// container for target codes
	Set<FileInfo> targetFileSet = new HashSet<FileInfo>();
	
	info("Generating the Pico web serivce client classes...");
	
	if (config.picoPrefix == null) {
		warn("No prefix is provided, it's recommended to add prefix for Pico binding to avoid possible conflict");
	}
	String prefix = config.picoPrefix == null ? "" : config.picoPrefix;
	prefixType(cgModel, prefix);
	
	fmModel.put("group", config.picoServiceGroup);
	
	// generate endpoint interface
	for (SEIInfo interfaceInfo : cgModel.getServiceEndpointInterfaces()) {
		fmModel.put("imports", this.getInterfaceImports(interfaceInfo));
		fmModel.put("endpointInterface", interfaceInfo);
		// special logic for ebay service demo, just a convenient for ebay service proxy generation
		if (config.eBaySOAService) {
			fmModel.put("eBaySOAService", config.eBaySOAService);
		} else if (config.eBayShoppingAPI) {
			fmModel.put("eBayShoppingAPI", config.eBayShoppingAPI);
		} else if (config.eBayTradingAPI) {
			fmModel.put("eBayTradingAPI", config.eBayTradingAPI);
		}
		String relativePath = ClassNameUtil.packageNameToPath(interfaceInfo.getPackageName());
		relativePath += File.separator + "client";
		FileInfo eiSoapIntf = this.generateFile(eiIntfSOAPTemplate, fmModel, interfaceInfo.getName() + "_SOAPClient", "h", relativePath);
		targetFileSet.add(eiSoapIntf);
		FileInfo eiSoapImpl = this.generateFile(eiImplSOAPTemplate, fmModel, interfaceInfo.getName() + "_SOAPClient", "m", relativePath);
		targetFileSet.add(eiSoapImpl);
		FileInfo eiXmlIntf = this.generateFile(eiIntfXMLTemplate, fmModel, interfaceInfo.getName() + "_XMLClient", "h", relativePath);
		targetFileSet.add(eiXmlIntf);
		FileInfo eiXmlImpl = this.generateFile(eiImplXMLTemplate, fmModel, interfaceInfo.getName() + "_XMLClient", "m", relativePath);
		targetFileSet.add(eiXmlImpl);
	}
	
	return targetFileSet;
}
 
Example 9
Source File: PicoClientModule.java    From mxjc with MIT License 4 votes vote down vote up
@Override
public Set<FileInfo> generate(CGModel cgModel, CGConfig config)
		throws XjcModuleException {
	// freemarker datamodel
	SimpleHash fmModel = this.getFreemarkerModel();
	
	// container for target codes
	Set<FileInfo> targetFileSet = new HashSet<FileInfo>();
	
	info("Generating the Pico client classes...");
	
	if (config.picoPrefix == null) {
		warn("No prefix is provided, it's recommended to add prefix for Pico binding to avoid possible conflict");
	}
	String prefix = config.picoPrefix == null ? "" : config.picoPrefix;
	prefixType(cgModel, prefix);
	
	fmModel.put("group", config.picoServiceGroup);
	
	
	String relativePath = null;
	// generate classes
	info("Generating classes ...");
	for(ClassInfo classInfo : cgModel.getClasses()) {
		this.convertFieldsType(classInfo);
		fmModel.put("superClassImports", this.getSuperClassImports(classInfo));
		fmModel.put("fieldClassImports", this.getFieldImports(classInfo));
		fmModel.put("clazz", classInfo);
		
		relativePath = ClassNameUtil.packageNameToPath(classInfo.getPackageName());
		FileInfo classIntf = this.generateFile(clzIntfTemplate, fmModel, classInfo.getName(), "h", relativePath);
		targetFileSet.add(classIntf);
		FileInfo classImpl = this.generateFile(clzImplTempalte, fmModel, classInfo.getName(), "m", relativePath);
		targetFileSet.add(classImpl);
	}
	
	// generate enums
	info("Generating enums ...");
	for(EnumInfo enumInfo : cgModel.getEnums()) {
		fmModel.put("enum", enumInfo);
		relativePath = ClassNameUtil.packageNameToPath(enumInfo.getPackageName());
		FileInfo enumDec = this.generateFile(enumDeclarationTemplate, fmModel, enumInfo.getName(), "h", relativePath);
		targetFileSet.add(enumDec);
		FileInfo enumDef = this.generateFile(enumDefinitionTemplate, fmModel, enumInfo.getName(), "m", relativePath);
		targetFileSet.add(enumDef);
	}
	
	// generate common header
	info("Generating common header ...");
	fmModel.put("classes", cgModel.getClasses());
	fmModel.put("enums", cgModel.getEnums());
	
	if (relativePath == null) {
		relativePath = "";
	}
	relativePath += File.separator + "common";
	String commonTypeFileName = prefix + "CommonTypes";
	FileInfo commonHeader = this.generateFile(commonHeaderTemplate, fmModel, commonTypeFileName, "h", relativePath);
	targetFileSet.add(commonHeader);
	
	return targetFileSet;
}