commit 0315da87fac35f45b47fc5df0aaa3c9535ea42fe Author: richie Date: Fri Nov 16 09:25:24 2018 +0800 xml导出示例 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c03e859 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.iml +lib/report/*.jar +.DS_Store +.idea/ \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..8e951e5 --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/report/.gitkeep b/lib/report/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..c71f871 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,31 @@ + + + com.fr.plugin.export.xml + com.fr.plugin.export + + yes + 3.0 + 10.0 + 2018-10-21 + author + + + [2017-12-21]适配9.0同时修复导出时可能出现空指针错误。
+ [2016-01-25]修复xml导出无法正确导出带有格式信息的单元格内容。
+ [2016-02-28]增加功能点使用统计信息。
+ [2016-01-19]完善xml导出的基本框架。
+ ]]>
+ + + + + + + + + + + + +
\ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c606d7d --- /dev/null +++ b/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + + jar + demo-export-xml + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.export.xml-1.0/classes + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java b/src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java new file mode 100644 index 0000000..ad4aa1f --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java @@ -0,0 +1,21 @@ +package com.fr.plugin.export.xml; + +import com.fr.stable.EncodeConstants; +import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; + +/** + * Created by richie on 16/1/21. + */ +public class XmlFileHandler extends AbstractJavaScriptFileHandler { + @Override + public String[] pathsForFiles() { + return new String[]{ + "/com/fr/plugin/export/xml/web/pane.extra.js" + }; + } + + @Override + public String encode() { + return EncodeConstants.ENCODING_UTF_8; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/XmlLocaleFinder.java b/src/main/java/com/fr/plugin/export/xml/XmlLocaleFinder.java new file mode 100644 index 0000000..75370b7 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/XmlLocaleFinder.java @@ -0,0 +1,14 @@ +package com.fr.plugin.export.xml; + +import com.fr.stable.fun.impl.AbstractLocaleFinder; + +/** + * Created by richie on 15/12/15. + */ +public class XmlLocaleFinder extends AbstractLocaleFinder { + + @Override + public String find() { + return "com/fr/plugin/export/xml/locale/xml"; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/core/IconLoader.java b/src/main/java/com/fr/plugin/export/xml/core/IconLoader.java new file mode 100644 index 0000000..66dde4e --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/core/IconLoader.java @@ -0,0 +1,18 @@ +package com.fr.plugin.export.xml.core; + +import com.fr.base.Icon; +import com.fr.base.IconManager; +import com.fr.general.IOUtils; + + +/** + * Created by richie on 15/12/15. + */ +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(); + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/core/XmlConstants.java b/src/main/java/com/fr/plugin/export/xml/core/XmlConstants.java new file mode 100644 index 0000000..047d230 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/core/XmlConstants.java @@ -0,0 +1,9 @@ +package com.fr.plugin.export.xml.core; + +/** + * Created by richie on 16/3/28. + */ +public class XmlConstants { + + public static final String PLUGIN_ID = "com.fr.plugin.export.xml"; +} diff --git a/src/main/java/com/fr/plugin/export/xml/core/XmlExport.java b/src/main/java/com/fr/plugin/export/xml/core/XmlExport.java new file mode 100644 index 0000000..bd11ebe --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/core/XmlExport.java @@ -0,0 +1,27 @@ +package com.fr.plugin.export.xml.core; + +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.report.fun.impl.AbstractExportOperateProvider; +import com.fr.stable.fun.Authorize; +import com.fr.web.core.reserve.Operate; + +/** + * Created by richie on 16/1/19. + */ +@Authorize(callSignKey = XmlConstants.PLUGIN_ID) +@EnableMetrics +public class XmlExport extends AbstractExportOperateProvider { + + @Override + @Focus(id = XmlConstants.PLUGIN_ID, text = "Plugin-Xml_Export", source = Original.PLUGIN) + public Operate operate() { + return new XmlExportOperate(); + } + + @Override + public String markType() { + return "xml"; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java b/src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java new file mode 100644 index 0000000..3c3a112 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java @@ -0,0 +1,34 @@ +package com.fr.plugin.export.xml.core; + +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Created by richie on 16/1/19. + */ +public class XmlExportOperate extends DefaultOperate { + + @Override + public void setContent(HttpServletRequest req, HttpServletResponse res, String fileName, boolean isEmbed) { + res.setContentType("application/octet-stream"); + res.setHeader("extension", "xml"); + res.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xml"); + } + + @Override + public ExportCollection createCollection(HttpServletRequest req, HttpServletResponse res, ReportSessionIDInfor sessionIDInfor, String fileName) { + ExportCollection collection = ExportCollection.create(); + collection.setExporter(new XmlExporter()); + collection.setRecordType(DeclareRecordType.EXPORT_TYPE_CSV); + + return collection; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java b/src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java new file mode 100644 index 0000000..1f6a112 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java @@ -0,0 +1,61 @@ +package com.fr.plugin.export.xml.core; + +import com.fr.form.ui.WebContentUtils; +import com.fr.form.ui.Widget; +import com.fr.general.Inter; +import com.fr.js.JavaScriptImpl; +import com.fr.report.fun.impl.AbstractExtensionButton; +import com.fr.stable.web.Repository; + +/** + * Created by richie on 15/12/15. + */ +public class XmlExtensionButton extends AbstractExtensionButton{ + + public XmlExtensionButton() { + super(Inter.getLocText("Plugin-Xml_Export"), IconLoader.loadIcon()); + } + + public XmlExtensionButton(String text) { + super(text); + } + + public XmlExtensionButton(String text, String iconName) { + super(text, iconName); + } + + @Override + public Class classForDirectoryButton() { + return this.getClass(); + } + + @Override + public String getParentDirectory() { + return null; + } + + @Override + public String getType() { + return "XmlExport.class"; + } + + @Override + public String getRelatedCheckBoxTitle() { + return null; + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public void setSelected(boolean isSelected) { + + } + + @Override + protected JavaScriptImpl clickAction(Repository repo) { + return new JavaScriptImpl(WebContentUtils.getContentPanel(repo) + ".exportReportToXML()"); + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java b/src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java new file mode 100644 index 0000000..f74e6c0 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java @@ -0,0 +1,117 @@ +package com.fr.plugin.export.xml.exporter; + +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.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; +import java.io.PrintWriter; +import java.text.Format; +import java.util.Iterator; +import java.util.List; + +/** + * Created by richie on 16/1/21. + */ +public class XmlExporter extends AbstractAppExporter { + + @Override + public void export(OutputStream out, ResultWorkBook book) throws Exception { + List paperSettingList = ReportUtils.getPaperSettingListFromWorkBook(book); + for (int i = 0, len = book.getReportCount(); i < len; i++) { + this.export(out, book.getResultReport(i), (PaperSettingProvider) paperSettingList.get(i)); + } + } + + @Override + 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); + if (page == null) { + break; + } + this.exportReport(out, (ElementGetter) page, 0, (page).getRowCount()); + } + } + + private void export(OutputStream out, ResultReport report, PaperSettingProvider paperSetting) + throws Exception { + if (report != null) { + FineLoggerFactory.getLogger().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()) { + PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, EncodeConstants.ENCODING_UTF_8)); + StringBuilder xmlBuffer = new StringBuilder(); + xmlBuffer.append(""); + xmlBuffer.append(""); + for (int row = start; row < end; row++) { + xmlBuffer.append(""); + Iterator it = reportCase.getRow(row); + + while (it.hasNext()) { + xmlBuffer.append(""); + CellElement cell = (CellElement) it.next(); + Object value = getCellValue(cell); + Style style = cell.getStyle(); + String str; + if (style != null) { + Format format = style.getFormat(); + str = Style.valueToText(value, format); + } else { + str = GeneralUtils.objectToString(value); + } + xmlBuffer.append(str); + xmlBuffer.append(""); + + } + xmlBuffer.append(""); + } + xmlBuffer.append(""); + writer.println(xmlBuffer.toString()); + writer.flush(); + } else { + 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; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java b/src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java new file mode 100644 index 0000000..c647414 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java @@ -0,0 +1,26 @@ +package com.fr.plugin.export.xml.ui; + +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; + +/** + * Created by richie on 15/12/15. + */ +public class XmlExportToolbarUI extends AbstractToolbarItem { + @Override + public Class classForWidget() { + return XmlExtensionButton.class; + } + + @Override + public String iconPathForWidget() { + return "/com/fr/plugin/export/xml/images/xml16.png"; + } + + @Override + public String nameForWidget() { + return InterProviderFactory.getProvider().getLocText("Plugin-Xml_Export"); + } +} \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/xml/images/xml16.png b/src/main/resources/com/fr/plugin/export/xml/images/xml16.png new file mode 100644 index 0000000..287ffa7 Binary files /dev/null and b/src/main/resources/com/fr/plugin/export/xml/images/xml16.png differ diff --git a/src/main/resources/com/fr/plugin/export/xml/locale/xml.properties b/src/main/resources/com/fr/plugin/export/xml/locale/xml.properties new file mode 100644 index 0000000..e15291c --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/xml/locale/xml.properties @@ -0,0 +1 @@ +Plugin-Xml_Export=XML \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/xml/locale/xml_zh_CN.properties b/src/main/resources/com/fr/plugin/export/xml/locale/xml_zh_CN.properties new file mode 100644 index 0000000..632f35f --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/xml/locale/xml_zh_CN.properties @@ -0,0 +1 @@ +Plugin-Xml_Export=Xml\u5BFC\u51FA \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/xml/web/pane.extra.js b/src/main/resources/com/fr/plugin/export/xml/web/pane.extra.js new file mode 100644 index 0000000..30fcda0 --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/xml/web/pane.extra.js @@ -0,0 +1,29 @@ +/** + * Created by richie on 16/1/21. + */ +(function($){ + // 你好啊,导出 + $.extend(FR.WritePane.prototype, { + exportReportToXML : function() { + if (this.fireEvent("beforexml") === false) { + return; + } + var self = this; + this.saveReport(function () { + window.location = FR.servletURL + "?op=export&sessionID=" + self.currentSessionID + "&format=xml"; + FR.progressBar(self.currentSessionID,"xml"); + self.fireEvent("afterxml"); + }); + } + }); + $.extend(FR.PagePane.prototype, { + exportReportToXML : function() { + if (this.fireEvent("beforexml") === false) { + return; + } + window.location = FR.servletURL + "?op=export&sessionID=" + this.currentSessionID + "&format=xml"; + FR.progressBar(this.currentSessionID, "xml"); + this.fireEvent("afterxml"); + } + }); +})(jQuery); \ No newline at end of file