flexpaper流读取

原贴地址

http://jackyrong.iteye.com/blog/1768553

 flexpaper是个不错的将pdf,word之类的文件转化为swf的开源工具,关于这个其实网上说了不少了,它做出来的效果有点象百度文库的效果了,但最近发现一个问题,就是在 
    SwfFile : escape("xxxx.swf"); 
这里,可能会造成很容易通过绝对路径下载到swf的地址,于是可以下载到swf,那么有什么好的方法保护之呢?当然,要搞到很复杂是不大可能的,除非有百度的能力,但简单的保护还是有办法的. 
办法就是,其实flexpaper的SwfFile是支持以文件流的方式读文件的,所以, 
可以简单写一个action或者servlet来读取,代码如下: 

Java代码   收藏代码
  1. try  
  2.         {  
  3.         ServletOutputStream out =   
  4.             this.getResponse().getOutputStream ();   
  5.           
  6.         this.ismsdocversion = this.docversionsService  
  7.         .getswfnamebydocumentId(documentId);  
  8.           
  9.         String realPath =ServletActionContext.getServletContext().getRealPath("swffiles")+"/"+this.ismsdocversion.getAttachmentflashname();  
  10.         logger.info("swrealpath is"+realPath);  
  11.         InputStream ips = null;  
  12.         OutputStream ops = null;  
  13.           
  14.           this.getResponse().reset();  
  15.          this.getResponse().setContentType("application/swf");  
  16.         File file = new File(realPath);  
  17.         ops =  this.getResponse().getOutputStream();  
  18.         ips = new FileInputStream(file);  
  19.          this.getResponse().addHeader("Content-Length"new Long(file.length()).toString());  
  20.            
  21.         int i = 0;  
  22.         byte[] buffer = new byte[1024];  
  23.         i = ips.read(buffer);  
  24.         while (i != -1) {  
  25.             ops.write(buffer, 0, i);  
  26.             i = ips.read(buffer);  
  27.         }  
  28.            
  29.         ips.close();  
  30.         ops.flush();  
  31.         ops.close();  
  32.         }  
  33.         catch (Exception e)  
  34.         {  
  35.             e.printStackTrace();  
  36.         }  
  37.           


  然后在flexpaper中,指定为: 
  SwfFile : escape('<%=basePath%>docview/docview!getSwffile.action?documentId=${ismsdocversion.documentId}'), 

   其实就是指定为这个servlet输出,这样就可以达到不能直接下载SWF的目的了. 

flexpaper是不可以用绝对路径的调用本地或项目外的swf文件的,这个我们就有两种方法,一种是把swf和项目放在同一个目录下面,通过相对路径来获取

另一种是在运行项目的tomcat的server.xml配置里面host下添加一段内容 

<Context crossContext="true" docBase="E:/SVPE/" path="/SVPE" reloadable="false"/>

function showFlash(url){
    $('#documentViewer').empty().FlexPaperViewer(
            { config : {
                SWFFile : escape(url),
                //SWFFile : file,
                jsDirectory : $basePath+'/FlexPaper/js/',
                Scale : 0.6,
                ZoomTransition : 'easeOut',
                ZoomTime : 0.5,
                ZoomInterval : 0.2,
                FitPageOnLoad : true,
                FitWidthOnLoad : true,
                FullScreenAsMaxWindow : false,
                ProgressiveLoading : false,
                MinZoomSize : 0.2,
                MaxZoomSize : 5,
                SearchMatchAll : false,
                InitViewMode : 'Portrait',
                RenderingOrder : 'flash,html',
                StartAtPage : '',
    
                ViewModeToolsVisible : true,
                ZoomToolsVisible : true,
                NavToolsVisible : true,
                CursorToolsVisible : true,
                SearchToolsVisible : true,
                WMode : 'window',
                localeChain: 'zh_CN'
            }}
    );
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值