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