Browse Source

依赖FineKit改写

master 4.0
richie 5 years ago
parent
commit
a44a4b26a7
  1. 2
      build.xml
  2. BIN
      lib/finekit-10.0.jar
  3. 5
      plugin.xml
  4. 9
      pom.xml
  5. 2
      src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java
  6. 10
      src/main/java/com/fr/plugin/export/xml/core/IconLoader.java
  7. 10
      src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java
  8. 10
      src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java
  9. 62
      src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java
  10. 4
      src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java

2
build.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home"/>
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>

BIN
lib/finekit-10.0.jar

Binary file not shown.

5
plugin.xml

@ -4,12 +4,13 @@
<main-package>com.fr.plugin.export</main-package>
<name><![CDATA[导出XML]]></name>
<active>yes</active>
<version>3.0</version>
<version>4.0</version>
<env-version>10.0</env-version>
<jartime>2018-10-21</jartime>
<jartime>2019-09-25</jartime>
<vendor>author</vendor>
<description><![CDATA[将报表导出为XML文件]]></description>
<change-notes><![CDATA[
[2019-09-26]插件适配10.0且只依赖FineKit。<br/>
[2017-12-21]修复功能点记录重复的问题。<br/>
[2017-12-21]适配9.0同时修复导出时可能出现空指针错误。<br/>
[2016-01-25]修复xml导出无法正确导出带有格式信息的单元格内容。<br/>

9
pom.xml

@ -12,6 +12,15 @@
<packaging>jar</packaging>
<artifactId>demo-export-xml</artifactId>
<dependencies>
<dependency>
<groupId>com.fanruan.api</groupId>
<artifactId>finekit</artifactId>
<version>10.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/finekit-10.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.export.xml-1.0/classes</outputDirectory>

2
src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java

@ -1,6 +1,6 @@
package com.fr.plugin.export.xml;
import com.fr.stable.EncodeConstants;
import com.fanruan.api.macro.EncodeConstants;
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler;
/**

10
src/main/java/com/fr/plugin/export/xml/core/IconLoader.java

@ -1,8 +1,6 @@
package com.fr.plugin.export.xml.core;
import com.fr.base.Icon;
import com.fr.base.IconManager;
import com.fr.general.IOUtils;
import com.fanruan.api.report.SundryKit;
/**
@ -11,8 +9,8 @@ import com.fr.general.IOUtils;
public class IconLoader {
public static String loadIcon() {
Icon icon = new Icon("xml", IOUtils.readImage("/com/fr/plugin/export/xml/images/xml16.png"));
IconManager.getIconManager().addIcon(icon, true);
return icon.getName();
String name = "xml";
SundryKit.loadToolbarIcon(name, "/com/fr/plugin/export/xml/images/xml16.png");
return name;
}
}

10
src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java

@ -1,12 +1,10 @@
package com.fr.plugin.export.xml.core;
import com.fanruan.api.report.export.BaseOperate;
import com.fr.general.DeclareRecordType;
import com.fr.io.collection.ExportCollection;
import com.fr.io.exporter.CSVExporter;
import com.fr.plugin.export.xml.exporter.XmlExporter;
import com.fr.web.core.ReportSessionIDInfor;
import com.fr.web.core.reserve.DefaultOperate;
import com.fr.web.core.utils.ExportUtils;
import com.fr.stable.web.SessionProvider;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -14,7 +12,7 @@ import javax.servlet.http.HttpServletResponse;
/**
* Created by richie on 16/1/19.
*/
public class XmlExportOperate extends DefaultOperate {
public class XmlExportOperate extends BaseOperate {
@Override
public void setContent(HttpServletRequest req, HttpServletResponse res, String fileName, boolean isEmbed) {
@ -24,7 +22,7 @@ public class XmlExportOperate extends DefaultOperate {
}
@Override
public ExportCollection createCollection(HttpServletRequest req, HttpServletResponse res, ReportSessionIDInfor sessionIDInfor, String fileName) {
public ExportCollection newExportCollection(HttpServletRequest req, HttpServletResponse res, SessionProvider sessionIDInfor, String fileName) {
ExportCollection collection = ExportCollection.create();
collection.setExporter(new XmlExporter());
collection.setRecordType(DeclareRecordType.EXPORT_TYPE_CSV);

10
src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java

@ -1,8 +1,8 @@
package com.fr.plugin.export.xml.core;
import com.fr.form.ui.WebContentUtils;
import com.fanruan.api.i18n.I18nKit;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.js.JavaScript;
import com.fr.js.JavaScriptImpl;
import com.fr.report.fun.impl.AbstractExtensionButton;
import com.fr.stable.web.Repository;
@ -13,7 +13,7 @@ import com.fr.stable.web.Repository;
public class XmlExtensionButton extends AbstractExtensionButton {
public XmlExtensionButton() {
super(Inter.getLocText("Plugin-Xml_Export"), IconLoader.loadIcon());
super(I18nKit.getLocText("Plugin-Xml_Export"), IconLoader.loadIcon());
}
public XmlExtensionButton(String text) {
@ -55,7 +55,7 @@ public class XmlExtensionButton extends AbstractExtensionButton{
}
@Override
protected JavaScriptImpl clickAction(Repository repo) {
return new JavaScriptImpl(WebContentUtils.getContentPanel(repo) + ".exportReportToXML()");
protected JavaScript clickAction(Repository repo) {
return new JavaScriptImpl("_g().exportReportToXML()");
}
}

62
src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java

@ -1,27 +1,22 @@
package com.fr.plugin.export.xml.exporter;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.report.PrintKit;
import com.fanruan.api.report.export.BaseAppExporter;
import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.Style;
import com.fr.general.FRLogger;
import com.fr.general.GeneralUtils;
import com.fr.io.core.ExporterUtils;
import com.fr.io.exporter.AbstractAppExporter;
import com.fr.log.FineLoggerFactory;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.page.ClippedPageProvider;
import com.fr.page.PageSetProvider;
import com.fr.page.PaperSettingProvider;
import com.fr.page.ReportPageProvider;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.export.xml.core.XmlConstants;
import com.fr.plugin.context.PluginContexts;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.cellattr.CellGUIAttr;
import com.fr.report.core.ReportUtils;
import com.fr.report.elementcase.ElementGetter;
import com.fr.report.report.ECReport;
import com.fr.report.report.ResultReport;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@ -33,11 +28,11 @@ import java.util.List;
/**
* Created by richie on 16/1/21.
*/
public class XmlExporter extends AbstractAppExporter {
public class XmlExporter extends BaseAppExporter {
@Override
public void export(OutputStream out, ResultWorkBook book) throws Exception {
List paperSettingList = ReportUtils.getPaperSettingListFromWorkBook(book);
List paperSettingList = PrintKit.getPaperSettings(book);
for (int i = 0, len = book.getReportCount(); i < len; i++) {
this.export(out, book.getResultReport(i), (PaperSettingProvider) paperSettingList.get(i));
}
@ -47,7 +42,7 @@ public class XmlExporter extends AbstractAppExporter {
public void export(java.io.OutputStream out, PageSetProvider pageSet) throws Exception {
for (int i = 0; i < pageSet.size(); i++) {
ReportPageProvider reportPage = pageSet.getPage(i);
ClippedPageProvider page = ExporterUtils.support(reportPage);
ClippedPageProvider page = PrintKit.pick(reportPage);
if (page == null) {
break;
}
@ -58,14 +53,13 @@ public class XmlExporter extends AbstractAppExporter {
private void export(OutputStream out, ResultReport report, PaperSettingProvider paperSetting)
throws Exception {
if (report != null) {
FineLoggerFactory.getLogger().info("UnLayerReport start export");
LogKit.info("UnLayerReport start export");
exportReport(out, (ECReport) report, 0, (report).getRowCount());
}
}
public void exportReport(OutputStream out, ElementGetter reportCase, int start, int end) throws Exception {
PluginLicense license = PluginLicenseManager.getInstance().getPluginLicenseByID(XmlConstants.PLUGIN_ID);
if (license != null && license.isAvailable()) {
if (PluginContexts.currentContext().isAvailable()) {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, EncodeConstants.ENCODING_UTF_8));
StringBuilder xmlBuffer = new StringBuilder();
xmlBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
@ -76,17 +70,26 @@ public class XmlExporter extends AbstractAppExporter {
while (it.hasNext()) {
xmlBuffer.append("<col>");
String exportText;
CellElement cell = (CellElement) it.next();
Object value = getCellValue(cell);
if (cell == null) {
exportText = StringKit.EMPTY;
} else {
boolean export = PrintKit.isCellPrintable(cell);
if (export) {
Object value = cell.getValue();
Style style = cell.getStyle();
String str;
if (style != null) {
Format format = style.getFormat();
str = Style.valueToText(value, format);
exportText = Style.valueToText(value, format);
} else {
exportText = GeneralKit.objectToString(value);
}
} else {
str = GeneralUtils.objectToString(value);
exportText = StringKit.EMPTY;
}
}
xmlBuffer.append(str);
xmlBuffer.append(exportText);
xmlBuffer.append("</col>");
}
@ -99,19 +102,4 @@ public class XmlExporter extends AbstractAppExporter {
throw new RuntimeException("XML Export Plugin License Expired!");
}
}
private Object getCellValue(CellElement cell) {
if (cell == null) {
return null;
}
Object value = cell.getValue();
CellGUIAttr gui = cell.getCellGUIAttr();
if (gui != null && !gui.isPrintContent()) {
value = StringUtils.EMPTY;
}
return value == null ? StringUtils.EMPTY : value;
}
}

4
src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java

@ -1,8 +1,8 @@
package com.fr.plugin.export.xml.ui;
import com.fanruan.api.i18n.I18nKit;
import com.fr.design.fun.impl.AbstractToolbarItem;
import com.fr.form.ui.Widget;
import com.fr.locale.InterProviderFactory;
import com.fr.plugin.export.xml.core.XmlExtensionButton;
/**
@ -21,6 +21,6 @@ public class XmlExportToolbarUI extends AbstractToolbarItem {
@Override
public String nameForWidget() {
return InterProviderFactory.getProvider().getLocText("Plugin-Xml_Export");
return I18nKit.getLocText("Plugin-Xml_Export");
}
}
Loading…
Cancel
Save