From be027229ff7f43150e723324bc7e08afe94b497d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=9D=B0?= Date: Mon, 9 Oct 2017 12:33:22 +0000 Subject: [PATCH] Updates docs/storage-datasource-config.md Auto commit by GitBook Editor --- docs/images/datasource-tools.png | Bin 0 -> 6657 bytes docs/storage-datasource-config.md | 258 +++++++++++++++++++++++++++++- 2 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 docs/images/datasource-tools.png diff --git a/docs/images/datasource-tools.png b/docs/images/datasource-tools.png new file mode 100644 index 0000000000000000000000000000000000000000..b3b21dd7acf3a8cf5dec4243a84ee50f2e2b7e6b GIT binary patch literal 6657 zcmb_>_gfQD*DWD2M2Zxp_Y#o^N-t6rh;$;-M0!U$0hA6QND=8$L=ccBO+Y}T7wI5f zdItl9F1;AIKb# z1_iEnP&qTBh_SUgJkMVNm&+NVwn+-2sk zKiPB?GuR-wl9!aAEP!@`I|U*q~xHrZ2NZBNhPKE11KZ*Nzz zw9Gy|J5xQ|$L+pnE3|H#x$KN)reS8j%f`mGyt`{Q8IDAvfK72eD>WX@B4QwmN-HjQ ztS*n+?R=~ul!a}JEJ%}@x24~mcz?7)x`YjefR{zWZ%ft$IJx(`HMW(~5lvw7~_ zLoKhYz&SbP@4i(sD5oSnV-p+7jbMWy@P z5<nwQ)5Gda^WyaTN9W6bP!Gy5l8DV^7bj zC>AMUqYoWnEH&izCp&X_juWNV5N|$8d!fe5%6yx8xnHV zA0E&{O{cXw(-ctOaIsTQLr1q7SEh{g$Rx+>E32PBqe;lS z3K08!w6o;C(@T+Bu~ASm6(p~I31c~(9o;Tce=ac*RT#~&>pt?;G%o527iawDNqjkm zRCtz7YkK^8_xq6+wK#$J6zi=KMJCQ$uOdXxUjyV(m`E)>c7`YB8F2! zBG;Q06%-Cj*udh5Yj%SfV-(U@EH?L9ndyEDm~uVMc5Cu$h2zA%09Nvi5E9B{Hd)^n z8yOO=8Cz48%4No3zoU-Y?lox>)}Pv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Muq`HwWO6#R zek}+X-8HDI`{aMN@5>sNViqWsqbeu?5S}FTN+-UdKFRHN3_`);3F|C{lTxUI{J3BT znGEnLa}1hNX$HJAgD!oX>)O(#^l7r{Fnq9<@jgk9-I2VvH{4=OwG9$1^tyR7{kg2V zVsO_ofM&LoUa`VuUdVm?s3n>OJO + + /WEB-INF/config.properties + + +``` + +**Note: **The above Bean configuraton is practically a standard configuration of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class. We know that we can load external properties of Spring by configuring PropertyPlaceholderConfigurer. If the project has been configured with PropertyPlaceholderConfigurer class, the corresponding UReport2 properties can be directly added to the properties file corresponding to the class of the configuration, and it is no need to configure the config.properties file. + +Open the file config.properties and add the attribute named “ureport.fileStoreDir”, while the value of the attribute is applied to define the default file system-based report storage directory provided by UReport2. For example, the attribute can be defined as follows: + +``` +ureport.fileStoreDir=D:/ureportfiles +``` + +It means to save the report files in the directory ureportfiles under the Drive D. It shall be noted that when the specific directory is assigned, we shall save the directory and assure its existence, otherwise it will not be adopted. For an instance, the directory named ureportfiles in Drive D must exist and needs to be created in advance. + +The report storage mechanism known as the “server file system” provided by UReport2 by fault actually realizes the interface of com.bstek.ureport.provider.report.Report Provider provided by UReport2. The source code of the interface is as follows: + +``` +package com.bstek.ureport.provider.report; import java.io.InputStream; +import java.util.List; +/** +* @author Jacky.gao +* @since 2016年12月4日 +* @since Dec. 4 2016 +*/ +public interface ReportProvider { +/** +* 根据报表名加载报表文件 +* Load the report file according to the report name +*@param file 报表名称 +* @param file report name +*@return 返回的InputStream +* @return returned InputStream +*/ +InputStream loadReport(String file); +/** +* 根据报表名,删除指定的报表文件 +* Delete the specific report file according to the report name +* @param file 报表名称 +* @param file report name +*/ +void deleteReport(String file); +/** +* 获取所有的报表文件 +* Acquire all report files +* @return 返回报表文件列表 +* @return return the list of report file +*/ +List getReportFiles(); +/** +* 保存报表文件 +* Save report files +*@param file 报表名称 +* @param file report name +*@param content 报表的XML内容 +* @param content XML content of report +*/ +void saveReport(String file,String content); +/** +* @return 返回存储器名称 +* @return return storage name +*/ +String getName(); +/** +* @return 返回是否禁用 +* @return return if deactivation +*/ +boolean disabled(); +/** +* @return 返回报表文件名前缀 +* @return return prefix of report name +*/ +String getPrefix(); +} +``` + +After realizing the ReportProvider interface, configure the implementation class to Spring and make it a standard Spring Bean. Then UReport2 will detect, find and load it. The source code of the report storage known as the “server file system” provided by UReport2 by default is listed below: + +``` +package com.bstek.ureport.provider.report.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import javax.servlet.ServletContext; + +import org.apache.commons.io.IOUtils; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.web.context.WebApplicationContext; + +import com.bstek.ureport.exception.ReportException; +import com.bstek.ureport.provider.report.ReportFile; +import com.bstek.ureport.provider.report.ReportProvider; + +/** + * @author Jacky.gao + * @since 2017年2月11日 + */ +public class FileReportProvider implements ReportProvider,ApplicationContextAware{ + private String prefix="file:"; + private String fileStoreDir; + private boolean disabled; + @Override + public InputStream loadReport(String file) { + if(file.startsWith(prefix)){ + file=file.substring(prefix.length(),file.length()); + } + String fullPath=fileStoreDir+"/"+file; + try { + return new FileInputStream(fullPath); + } catch (FileNotFoundException e) { + throw new ReportException(e); + } + } + + @Override + public void deleteReport(String file) { + if(file.startsWith(prefix)){ + file=file.substring(prefix.length(),file.length()); + } + String fullPath=fileStoreDir+"/"+file; + File f=new File(fullPath); + if(f.exists()){ + f.delete(); + } + } + + @Override + public List getReportFiles() { + File file=new File(fileStoreDir); + List list=new ArrayList(); + for(File f:file.listFiles()){ + Calendar calendar=Calendar.getInstance(); + calendar.setTimeInMillis(f.lastModified()); + list.add(new ReportFile(f.getName(),calendar.getTime())); + } + Collections.sort(list, new Comparator(){ + @Override + public int compare(ReportFile f1, ReportFile f2) { + return f2.getUpdateDate().compareTo(f1.getUpdateDate()); + } + }); + return list; + } + + @Override + public String getName() { + return "服务器文件系统"; + } + + @Override + public void saveReport(String file,String content) { + if(file.startsWith(prefix)){ + file=file.substring(prefix.length(),file.length()); + } + String fullPath=fileStoreDir+"/"+file; + FileOutputStream outStream=null; + try{ + outStream=new FileOutputStream(new File(fullPath)); + IOUtils.write(content, outStream,"utf-8"); + }catch(Exception ex){ + throw new ReportException(ex); + }finally{ + if(outStream!=null){ + try { + outStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + + @Override + public boolean disabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public void setFileStoreDir(String fileStoreDir) { + this.fileStoreDir = fileStoreDir; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + File file=new File(fileStoreDir); + if(file.exists()){ + return; + } + if(applicationContext instanceof WebApplicationContext){ + WebApplicationContext context=(WebApplicationContext)applicationContext; + ServletContext servletContext=context.getServletContext(); + String basePath=servletContext.getRealPath("/"); + fileStoreDir=basePath+fileStoreDir; + file=new File(fileStoreDir); + if(!file.exists()){ + file.mkdirs(); + } + } + } + + @Override + public String getPrefix() { + return prefix; + } +} +``` + +Disable the default report storage provided by the system. If we customize the report storage and do not want to use the default report storage of “server file system” provided by the system, we only needs to add an attribute named ureport.disableFileProvider in the config.properties file mentioned above and set its value as true. + +In view of the introduction above, we can easily develop other types of report storages by realizing the ReportProvider interface, such as developing a new report storage to save reports in database and FTP etc. + +# The data source Configuration + +Open the report designer in UReport2. We can see three types of data sources of reports provided by UReport2, as shown in the figure below: + +![](docs/images/datasource-tools.png)![](docs/images/datasource-tools.png)![](docs/images/datasource-tools.png) + + + + + + + + + + + + + + + +![](docs/images/datasource-tools.png)