|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |