From 0315da87fac35f45b47fc5df0aaa3c9535ea42fe Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 16 Nov 2018 09:25:24 +0800 Subject: [PATCH] =?UTF-8?q?xml=E5=AF=BC=E5=87=BA=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + build.xml | 130 ++++++++++++++++++ lib/report/.gitkeep | 0 plugin.xml | 31 +++++ pom.xml | 29 ++++ .../fr/plugin/export/xml/XmlFileHandler.java | 21 +++ .../fr/plugin/export/xml/XmlLocaleFinder.java | 14 ++ .../fr/plugin/export/xml/core/IconLoader.java | 18 +++ .../plugin/export/xml/core/XmlConstants.java | 9 ++ .../fr/plugin/export/xml/core/XmlExport.java | 27 ++++ .../export/xml/core/XmlExportOperate.java | 34 +++++ .../export/xml/core/XmlExtensionButton.java | 61 ++++++++ .../export/xml/exporter/XmlExporter.java | 117 ++++++++++++++++ .../export/xml/ui/XmlExportToolbarUI.java | 26 ++++ .../com/fr/plugin/export/xml/images/xml16.png | Bin 0 -> 1128 bytes .../plugin/export/xml/locale/xml.properties | 1 + .../export/xml/locale/xml_zh_CN.properties | 1 + .../fr/plugin/export/xml/web/pane.extra.js | 29 ++++ 18 files changed, 552 insertions(+) create mode 100644 .gitignore create mode 100644 build.xml create mode 100644 lib/report/.gitkeep create mode 100644 plugin.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/fr/plugin/export/xml/XmlFileHandler.java create mode 100644 src/main/java/com/fr/plugin/export/xml/XmlLocaleFinder.java create mode 100644 src/main/java/com/fr/plugin/export/xml/core/IconLoader.java create mode 100644 src/main/java/com/fr/plugin/export/xml/core/XmlConstants.java create mode 100644 src/main/java/com/fr/plugin/export/xml/core/XmlExport.java create mode 100644 src/main/java/com/fr/plugin/export/xml/core/XmlExportOperate.java create mode 100644 src/main/java/com/fr/plugin/export/xml/core/XmlExtensionButton.java create mode 100644 src/main/java/com/fr/plugin/export/xml/exporter/XmlExporter.java create mode 100644 src/main/java/com/fr/plugin/export/xml/ui/XmlExportToolbarUI.java create mode 100644 src/main/resources/com/fr/plugin/export/xml/images/xml16.png create mode 100644 src/main/resources/com/fr/plugin/export/xml/locale/xml.properties create mode 100644 src/main/resources/com/fr/plugin/export/xml/locale/xml_zh_CN.properties create mode 100644 src/main/resources/com/fr/plugin/export/xml/web/pane.extra.js 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 0000000000000000000000000000000000000000..287ffa73a90c37ea40dfb845954a1a7e65133f90 GIT binary patch literal 1128 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|I14-?iy0WW zg+Z8+Vb&Z8pn}txArU1JzCKpT`MG+DDfvmMdKI|^K-CNkHWgMtW^QUpqC!P(PF}H9 zg{=};g%ywu64qBz04piUwpEJo4N!2-FG^J~)icpEP_pAvP*AWbN=dT{a&d!d2l8x{ zGD=Dctn~HE%ggo3jrH=2()A53EiLs8jP#9+bb%^#i!1X=5-W7`ij^UTz|3(;Elw`V zEGWs$&r<-Io0ybeT4JlD1hNPYpzh2qfLoMT4D}VzfBF@P1^R}12Kv}Em1L$NoQI+d zBm>a~_7%i38(`2_ITxiSmgEEak-AvibK zH#^u-#5Vullf5d-6myduJUN=CI0!7c(8|5>kz2v*WAh*K7c7>pZ~6U?LtIJX<)R0R zT4%K`Q4JM{`y?cE|NHEZ_c$xhu39kNrzriMZTh=A#mPqt?=XMpnzrbxzM95QjzE#Q zFaMhy^ICev%u=E6h*I=)hu?>u8*{zvow01Mv*qnc`#uG&Y_afEnId*w#s%R^f0`DsM!el=5qBwQS!7S*niD5BE_~Q7CH{|VFB@0V zlhoU0pKRP`sqL7f?ZcdF&@;6!;6sy)KfB<)a?@F=yr;_qj!$GXl(a8=b>86bUt!PR z4CnorV{A8Wd@a=I|Db%iW!!zgk4gF5@qPXu{{E5qTPJ_`;e{!0E%>B*+48PtS-iRN zE`6@BH z|6L!{Cv6bhXa4Wu>Tieri@$zcp!9Ahx5xIbn`hkj#+jdgU^l^QMQBV+o2ZSP&Xtpi z&R@!oPUR75{q4(sygx?g5s&p*v6U-1_pr{I=p+=zaOF+Kwj<%E-fopyrO;^7zVcAq zY15N6mwmV0U$^EHhx1d%Nj9@myM!i9cy=VFgxUE-Wy(6|OOsq|Jj{GW8cW?$#U6V< zZ#~bzH8aqRf1yHR#gtsnzWXmr-sw&EZlAq%8?Rom%gNUhUi$W`$o3!KH^)a!zga=! n-?`Z;tVxG&W~@