下载aActiviti中的流程文件和流程图
2015-04-21 16:26
344 查看
现在的Activiti流程中没有提供给我们下载流程文件(.bpmn)和流程图(.png)的方法,所以研究了一下,用传统的struts2下载结合jdbc的知识可以实现我们想要的效果。
1.首先,在action的头文件中加入(PreparedStatement
和ResultSet 都是java.sql的,而sessionFaction来自于hibernate):
private File file; //上传的文件
private String fileFileName; //文件名称
private SessionFactory sessionFactory;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
2.然后在action中加入如下代码:
//下载流程定义图片
@SuppressWarnings("null")
public String download() {
FileOutputStream fos = null;
String realpath = getServletContext().getRealPath("/Uplaod");
//String savePath = UploadUtil.generateSavePath(realpath, fileName);
String filePath = realpath+File.separator+fileFileName;
try{
Session session = sessionFactory.getCurrentSession();
rs=session.doReturningWork(
new ReturningWork<ResultSet>() {
@Override
public ResultSet execute(Connection connection) throws SQLException {
String sql="select agb.BYTES_ from act_ge_bytearray agb where agb.NAME_=? and agb.DEPLOYMENT_ID_=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, fileFileName);
pstmt.setString(2, deployId);
rs=pstmt.executeQuery();
return rs;
}
}
);
while (rs.next()){
System.out.println("Read text document...");
BufferedReader br=new BufferedReader(rs.getCharacterStream("BYTES_"));
String str=null;
while((str=br.readLine())!=null){
System.out.println(str);
}
System.out.println("Read text document OK!");
System.out.println("Read image file...");
file = new File(filePath);
if(!file.exists())
{
file.createNewFile(); //如果文件不存在,则创建
}
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));
byte[] buf=new byte[1024];
BufferedInputStream bis=new BufferedInputStream(rs.getBinaryStream("BYTES_"));
int count=-1;
while((count=bis.read(buf, 0, 1024))!=-1){
bos.write(buf, 0, count);
}
bos.flush();
System.out.println("Read image file OK!");
bos.close();
}
}catch(Exception e){
System.out.println("[OutPutFile error : ]" + e.getMessage());
}
return "download";
}
public InputStream getDownloadFile() throws UnsupportedEncodingException{
try {
String realpath = getServletContext().getRealPath("/Uplaod");
//String savePath = UploadUtil.generateSavePath(realpath, fileName);
String filePath = realpath+File.separator+fileFileName;
File file = new File(filePath);
FileInputStream in = new FileInputStream(file);
return in;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
3.最后在对应的struts文件中加上传统的下载配置:
<result type="stream" name="download">
<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
<param name="inputName">downloadFile</param>
<param name="contentDisposition">attachment;filename=${fileFileName}</param>
<param name="bufferSize">4096</param>
</result>
1.首先,在action的头文件中加入(PreparedStatement
和ResultSet 都是java.sql的,而sessionFaction来自于hibernate):
private File file; //上传的文件
private String fileFileName; //文件名称
private SessionFactory sessionFactory;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
2.然后在action中加入如下代码:
//下载流程定义图片
@SuppressWarnings("null")
public String download() {
FileOutputStream fos = null;
String realpath = getServletContext().getRealPath("/Uplaod");
//String savePath = UploadUtil.generateSavePath(realpath, fileName);
String filePath = realpath+File.separator+fileFileName;
try{
Session session = sessionFactory.getCurrentSession();
rs=session.doReturningWork(
new ReturningWork<ResultSet>() {
@Override
public ResultSet execute(Connection connection) throws SQLException {
String sql="select agb.BYTES_ from act_ge_bytearray agb where agb.NAME_=? and agb.DEPLOYMENT_ID_=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, fileFileName);
pstmt.setString(2, deployId);
rs=pstmt.executeQuery();
return rs;
}
}
);
while (rs.next()){
System.out.println("Read text document...");
BufferedReader br=new BufferedReader(rs.getCharacterStream("BYTES_"));
String str=null;
while((str=br.readLine())!=null){
System.out.println(str);
}
System.out.println("Read text document OK!");
System.out.println("Read image file...");
file = new File(filePath);
if(!file.exists())
{
file.createNewFile(); //如果文件不存在,则创建
}
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));
byte[] buf=new byte[1024];
BufferedInputStream bis=new BufferedInputStream(rs.getBinaryStream("BYTES_"));
int count=-1;
while((count=bis.read(buf, 0, 1024))!=-1){
bos.write(buf, 0, count);
}
bos.flush();
System.out.println("Read image file OK!");
bos.close();
}
}catch(Exception e){
System.out.println("[OutPutFile error : ]" + e.getMessage());
}
return "download";
}
public InputStream getDownloadFile() throws UnsupportedEncodingException{
try {
String realpath = getServletContext().getRealPath("/Uplaod");
//String savePath = UploadUtil.generateSavePath(realpath, fileName);
String filePath = realpath+File.separator+fileFileName;
File file = new File(filePath);
FileInputStream in = new FileInputStream(file);
return in;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
3.最后在对应的struts文件中加上传统的下载配置:
<result type="stream" name="download">
<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
<param name="inputName">downloadFile</param>
<param name="contentDisposition">attachment;filename=${fileFileName}</param>
<param name="bufferSize">4096</param>
</result>
相关文章推荐
- 【入门篇】Activiti流程资源文件下载保存到本地
- 客户端从服务端下载文件的流程分析
- Php中文件下载功能实现超详细流程分析
- Activiti支持直接部署扩展名为bpmn的流程文件
- Activiti学习笔记三-开发部署bpmn流程文件
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程
- 清除病毒的完整步骤流程图解(附删除病毒文件流程图)
- Activiti的流程定义文件解析(后续)
- Activiti学习笔记四-开发部署zip格式的流程文件
- PHP 文件下载流程
- strtus2 批量下载 中文问题、压缩文件等 ------ 讨论struts2工作流程 (摘自:http://www.blogjava.net/xcp/archive/2009/10/30/downloadlist.html)
- 文件上传下载流程设计
- Activiti6.0.0 跟踪流程执行情况用红色框在流程图上标识路线跟节点
- jbpm4.4根据.jpdl.xml流程定义文件,得到流程图.png
- activiti5.20简单介绍(二) -- 流程文件
- 扩展Activiti流程定义文件,实现自定义节点属性
- activiti根据流程实例id查询资源文件(xml、image)
- 扩展Activiti流程定义文件,实现自定义节点属性