Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*--------------------------------------------------------------------------
* 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.html.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 com.github.dennisit.vplus.core.parser.AbstraClassNameParser;
import com.github.dennisit.vplus.core.parser.AbstraTableLoadingParser;
import com.google.common.collect.Lists;
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 VPlusHtmlBornApiImpl extends VPlusBornCoreApiImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(VPlusHtmlBornApiImpl.class);
@Override
public void vBorn(AbstraTableLoadingParser abstraTableLoadingParser, Vsetting vsetting) {
super.vBorn(abstraTableLoadingParser, vsetting);
}
@Override
public void vBorn(AbstraTableLoadingParser abstraTableLoadingParser, TemplateLoadApi templateLoadApi, Vsetting vsetting) {
super.vBorn(abstraTableLoadingParser, templateLoadApi, vsetting);
}
@Override
public void vBorn(AbstraClassNameParser abstraClassNameParser, Vsetting vsetting) {
super.vBorn(abstraClassNameParser, vsetting);
}
@Override
public void vBorn(AbstraClassNameParser abstraClassNameParser, TemplateLoadApi templateLoadApi, Vsetting vsetting) {
super.vBorn(abstraClassNameParser, templateLoadApi, vsetting);
}
// override born method for extend plugin
@Override
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;
}
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("#T#", bean.getTableName());
templatePathReplaces.put("vplus-html", "");
List neverRenders = Lists.newArrayList();
if(CollectionUtils.isEmpty(neverRenders)){
neverRenders = Lists.newArrayList();
}
neverRenders.addAll(vsetting.getNeverRenders());
neverRenders.add("assets/js/plugins");
neverRenders.add("assets.js.plugins");
neverRenders.add("resources/log4j2.xml");
neverRenders.add("resources.log4j2.xml");
vsetting.setNeverRenders(neverRenders);
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);
}
}