
com.github.dennisit.vplus.mvc.plugin.VPlusMvcBornApiImpl Maven / Gradle / Ivy
The newest version!
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.mvc.plugin;
import com.alibaba.fastjson.JSON;
import com.github.dennisit.vplus.core.apis.TemplateLoadApi;
import com.github.dennisit.vplus.core.apis.impl.VPlusBornCoreApiImpl;
import com.github.dennisit.vplus.core.bean.HTable;
import com.github.dennisit.vplus.core.config.Vsetting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Elon.su on 17/3/7.
*/
public class VPlusMvcBornApiImpl extends VPlusBornCoreApiImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(VPlusMvcBornApiImpl.class);
// override born method for extend plugin
public void vBorn(List beans, TemplateLoadApi templateLoadApi, Vsetting vsetting) {
List templates = templateLoadApi.scanResourceUrls(vsetting.getLocationPattern(), vsetting.getTemplateAccepts());
if(CollectionUtils.isEmpty(beans) || CollectionUtils.isEmpty(templates)){
LOGGER.warn("empty bean found or empty template found");
return;
}
System.out.println("[生成文件]\t 生成路径:" + vsetting.getBornPath());
for(HTable bean: beans){
if(null == bean || null == bean.getPrimaryField()){
LOGGER.error("error bean found! no primary key: {}", JSON.toJSONString(bean));
System.err.println("error bean found! no primary key: " + JSON.toJSONString(bean));
continue;
}
Map context = new HashMap();
context.put("bean", bean);
context.put("beans", beans);
Map extendData = vsetting.getExtendData();
if(!CollectionUtils.isEmpty(extendData)){
context.putAll(extendData);
}
Map templatePathReplaces = vsetting.getTemplatePathReplaces();
if(CollectionUtils.isEmpty(templatePathReplaces)){
templatePathReplaces = new HashMap();
}
templatePathReplaces.put("#V#", bean.getBeanName());
templatePathReplaces.put("#P#", vsetting.getBornPackage().replaceAll("\\.", "/"));
templatePathReplaces.put("vplus-mvc", "");
render(templates, context, templatePathReplaces, vsetting.getNeverRenders(), vsetting.getBornPath(), vsetting.getCharset());
}
return;
}
@Override
public String convertStreamToString(URL url) {
return super.convertStreamToString(url);
}
@Override
public void render(List templates, Map data, Map templatePathReplaces, List naverRenders, String bornPath, String charset) {
super.render(templates, data, templatePathReplaces, naverRenders, bornPath, charset);
}
@Override
public void render(String template, Map data, File destFile, String charset) {
super.render(template, data, destFile, charset);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy