richie
6 years ago
commit
0315da87fa
18 changed files with 552 additions and 0 deletions
@ -0,0 +1,130 @@
|
||||
<?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="libs" value="${basedir}/lib"/> |
||||
<property name="publicLibs" value=""/> |
||||
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/> |
||||
<property name="destLoc" value="."/> |
||||
<property name="classes" value="classes"/> |
||||
<xmlproperty file="${basedir}/plugin.xml"/> |
||||
<property name="current-version" value="${plugin.version}"/> |
||||
|
||||
<!-- 插件版本--> |
||||
<property name="plugin-version" value="${current-version}"/> |
||||
<!-- 插件名字--> |
||||
<property name="plugin-name" value="export-xml"/> |
||||
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/> |
||||
|
||||
<target name="prepare"> |
||||
<delete dir="${classes}"/> |
||||
<delete dir="fr-plugin-${plugin-name}-${plugin-version}"/> |
||||
<xmlproperty file="${basedir}/plugin.xml"/> |
||||
<delete dir="${destLoc}/${plugin.name}"/> |
||||
</target> |
||||
<path id="compile.classpath"> |
||||
<fileset dir="${libs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
<fileset dir="${publicLibs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
<fileset dir="${reportLibs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
</path> |
||||
<patternset id="resources4Jar"> |
||||
<exclude name="**/.settings/**"/> |
||||
<exclude name=".classpath"/> |
||||
<exclude name=".project"/> |
||||
|
||||
<exclude name="**/*.java"/> |
||||
<exclude name="**/*.db"/> |
||||
<exclude name="**/*.g"/> |
||||
<exclude name="**/package.html"/> |
||||
</patternset> |
||||
<target name="copy_resources"> |
||||
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/> |
||||
<delete dir="tmp"/> |
||||
<copy todir="tmp"> |
||||
<fileset dir="${resources_from}/src/main/resources"> |
||||
<patternset refid="resources4Jar"/> |
||||
</fileset> |
||||
</copy> |
||||
<copy todir="${classes}"> |
||||
<fileset dir="tmp"/> |
||||
</copy> |
||||
<delete dir="tmp"/> |
||||
</target> |
||||
<target name="compile_javas"> |
||||
<echo message="编译${compile_files}下的Java文件"/> |
||||
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}" |
||||
target="${target_jdk_version}" |
||||
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}" |
||||
executable="${compile_jdk_version}/bin/javac"> |
||||
<src path="${basedir}/src/main/java"/> |
||||
<exclude name="**/.svn/**"/> |
||||
<compilerarg line="-encoding UTF8 "/> |
||||
<classpath refid="compile.classpath"/> |
||||
</javac> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${basedir}"/> |
||||
</target> |
||||
|
||||
<target name="jar_classes"> |
||||
<echo message="打Jar包:${jar_name}"/> |
||||
<delete file="${basedir}/${jar_name}"/> |
||||
<jar jarfile="${basedir}/${jar_name}"> |
||||
<fileset dir="${classes}"> |
||||
</fileset> |
||||
</jar> |
||||
</target> |
||||
|
||||
<target name="super_jar" depends="prepare"> |
||||
<antcall target="copy_resources"> |
||||
<param name="resources_from" value="${basedir}"/> |
||||
</antcall> |
||||
<antcall target="compile_javas"> |
||||
<param name="source_jdk_version" value="1.6"/> |
||||
<param name="target_jdk_version" value="1.6"/> |
||||
<param name="compile_jdk_version" value="${jdk.home}"/> |
||||
<param name="compile_files" value="${basedir}/src"/> |
||||
</antcall> |
||||
<echo message="compile plugin success!"/> |
||||
|
||||
<antcall target="jar_classes"> |
||||
<param name="jar_name" value="${plugin-jar}"/> |
||||
</antcall> |
||||
<delete dir="${classes}"/> |
||||
|
||||
</target> |
||||
|
||||
<target name="jar" depends="super_jar"> |
||||
<antcall target="zip"/> |
||||
</target> |
||||
|
||||
<target name="zip"> |
||||
<property name="plugin-folder" value="fr-plugin-${plugin-name}-${plugin-version}"/> |
||||
<echo message="----------zip files----------"/> |
||||
<mkdir dir="${plugin-folder}"/> |
||||
<copy todir="${plugin-folder}"> |
||||
<fileset dir="."> |
||||
<include name="${plugin-jar}"/> |
||||
<include name="plugin.xml"/> |
||||
</fileset> |
||||
<fileset dir="${libs}"> |
||||
<include name="*.jar"/> |
||||
<include name="*.dll"/> |
||||
</fileset> |
||||
</copy> |
||||
<zip destfile="${basedir}/${plugin-folder}.zip" basedir="."> |
||||
<include name="${plugin-folder}/*.jar"/> |
||||
<include name="${plugin-folder}/*.dll"/> |
||||
<include name="${plugin-folder}/plugin.xml"/> |
||||
</zip> |
||||
<move file="${plugin-folder}.zip" todir="${destLoc}/install"/> |
||||
</target> |
||||
</project> |
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.export.xml</id> |
||||
<main-package>com.fr.plugin.export</main-package> |
||||
<name><![CDATA[导出XML]]></name> |
||||
<active>yes</active> |
||||
<version>3.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-10-21</jartime> |
||||
<vendor>author</vendor> |
||||
<description><![CDATA[将报表导出为XML文件]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2017-12-21]修复功能点记录重复的问题。<br/> |
||||
[2017-12-21]适配9.0同时修复导出时可能出现空指针错误。<br/> |
||||
[2016-01-25]修复xml导出无法正确导出带有格式信息的单元格内容。<br/> |
||||
[2016-02-28]增加功能点使用统计信息。<br/> |
||||
[2016-01-19]完善xml导出的基本框架。<br/> |
||||
]]></change-notes> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.export.xml.XmlLocaleFinder"/> |
||||
</extra-core> |
||||
<extra-report> |
||||
<ExtensionButtonProvider class="com.fr.plugin.export.xml.core.XmlExtensionButton"/> |
||||
<ExportOperateProvider class="com.fr.plugin.export.xml.core.XmlExport"/> |
||||
<JavaScriptFileHandler class="com.fr.plugin.export.xml.XmlFileHandler"/> |
||||
</extra-report> |
||||
<extra-designer> |
||||
<ToolbarItemProvider class="com.fr.plugin.export.xml.ui.XmlExportToolbarUI"/> |
||||
</extra-designer> |
||||
<function-recorder class="com.fr.plugin.export.xml.core.XmlExport"/> |
||||
</plugin> |
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<parent> |
||||
<groupId>com.fr.plugin</groupId> |
||||
<artifactId>starter</artifactId> |
||||
<version>10.0</version> |
||||
</parent> |
||||
|
||||
<packaging>jar</packaging> |
||||
<artifactId>demo-export-xml</artifactId> |
||||
<build> |
||||
<!---如果要更改调试插件,改这里的配置就可以了--> |
||||
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.export.xml-1.0/classes</outputDirectory> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<configuration> |
||||
<source>6</source> |
||||
<target>6</target> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
@ -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; |
||||
} |
||||
} |
@ -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"; |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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"; |
||||
} |
@ -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"; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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<? extends Widget> 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()"); |
||||
} |
||||
} |
@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); |
||||
xmlBuffer.append("<report>"); |
||||
for (int row = start; row < end; row++) { |
||||
xmlBuffer.append("<row>"); |
||||
Iterator it = reportCase.getRow(row); |
||||
|
||||
while (it.hasNext()) { |
||||
xmlBuffer.append("<col>"); |
||||
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("</col>"); |
||||
|
||||
} |
||||
xmlBuffer.append("</row>"); |
||||
} |
||||
xmlBuffer.append("</report>"); |
||||
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; |
||||
} |
||||
|
||||
|
||||
} |
@ -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<? extends Widget> 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"); |
||||
} |
||||
} |
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1 @@
|
||||
Plugin-Xml_Export=XML |
@ -0,0 +1 @@
|
||||
Plugin-Xml_Export=Xml\u5BFC\u51FA |
@ -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); |
Loading…
Reference in new issue