You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
3 years ago
|
package com.fr.plugin.xxx.report.link;
|
||
|
|
||
|
import com.fr.base.extension.FileExtension;
|
||
|
import com.fr.data.NetworkHelper;
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.stable.ActorConstants;
|
||
|
import com.fr.stable.ActorFactory;
|
||
|
import com.fr.stable.web.*;
|
||
|
import com.fr.web.reportlet.EmbeddedTplReportlet;
|
||
|
import com.fr.web.reportlet.OldWeblet;
|
||
|
import com.fr.web.reportlet.TemplateReportlet;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @author 秃破天际
|
||
|
* @version 10.0
|
||
|
* Created by 秃破天际 on 2020-04-01
|
||
|
**/
|
||
|
public class ReportletCreator extends AbstractWebletCreator {
|
||
|
|
||
|
public static final ReportletCreator KEY = new ReportletCreator();
|
||
|
/**
|
||
|
* hugh:直接把10.0的report-engine的ReportletCreator的代码复制过来,把构造改成public即可
|
||
|
* 以后如果产品的ReportletCreator发生了变更,同样要copy过来
|
||
|
*/
|
||
|
public ReportletCreator() {
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public TemplatePathMarker[] queryPathMarker() {
|
||
|
return new TemplatePathMarker[]{PathMarkerImpl.VIEWLET, PathMarkerImpl.REPORTLET};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public FileExtension suffix() {
|
||
|
return FileExtension.CPT;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 通过http请求构造Weblet
|
||
|
*
|
||
|
* @param req http请求
|
||
|
* @param res http应答
|
||
|
* @return 构造的Weblet
|
||
|
* @throws Exception
|
||
|
*/
|
||
|
@Override
|
||
|
public Weblet createWebletByRequest(HttpServletRequest req, HttpServletResponse res) {
|
||
|
TemplatePathNode pathNode = queryPath(req);
|
||
|
String reportlet = pathNode.getPath();
|
||
|
if (oldWebletOrServletCheck(req, pathNode)) {
|
||
|
return OldWeblet.asOldReportlet(reportlet);
|
||
|
}
|
||
|
// 暂时兼容cptx从cpt格式中读取
|
||
|
if (ComparatorUtils.equals(NetworkHelper.getHTTPRequestParameter(req, FORMAT), X)) {
|
||
|
return new TemplateReportlet(reportlet + X);
|
||
|
}
|
||
|
return new TemplateReportlet(reportlet);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据模板路径生成合适的Weblet
|
||
|
*
|
||
|
* @param tplPath 模板路径模板名
|
||
|
* @param parameterMap 参数
|
||
|
* @return 构造的Weblet
|
||
|
* @throws Exception
|
||
|
*/
|
||
|
@Override
|
||
|
public Weblet createEmbeddedWeblet(String tplPath, Map<String, Object> parameterMap) {
|
||
|
if (tplPath == null || !matchReportTpl(tplPath)) {
|
||
|
return null;
|
||
|
}
|
||
|
return new EmbeddedTplReportlet(tplPath, ActorFactory.getActor(ActorConstants.TYPE_PAGE), parameterMap);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 是否是报表模板
|
||
|
*
|
||
|
* @param tplPath 模板路径
|
||
|
* @return 如果是报表模板返回true,否则false
|
||
|
*/
|
||
|
private boolean matchReportTpl(String tplPath) {
|
||
|
return FileExtension.CPT.matchExtension(tplPath);
|
||
|
}
|
||
|
}
|