原贴地址
http://jackyrong.iteye.com/blog/1768553
flexpaper是个不错的将pdf,word之类的文件转化为swf的开源工具,关于这个其实网上说了不少了,它做出来的效果有点象百度文库的效果了,但最近发现一个问题,就是在
SwfFile : escape("xxxx.swf");
这里,可能会造成很容易通过绝对路径下载到swf的地址,于是可以下载到swf,那么有什么好的方法保护之呢?当然,要搞到很复杂是不大可能的,除非有百度的能力,但简单的保护还是有办法的.
办法就是,其实flexpaper的SwfFile是支持以文件流的方式读文件的,所以,
可以简单写一个action或者servlet来读取,代码如下:
- try
- {
- ServletOutputStream out =
- this.getResponse().getOutputStream ();
- this.ismsdocversion = this.docversionsService
- .getswfnamebydocumentId(documentId);
- String realPath =ServletActionContext.getServletContext().getRealPath("swffiles")+"/"+this.ismsdocversion.getAttachmentflashname();
- logger.info("swrealpath is"+realPath);
- InputStream ips = null;
- OutputStream ops = null;
- this.getResponse().reset();
- this.getResponse().setContentType("application/swf");
- File file = new File(realPath);
- ops = this.getResponse().getOutputStream();
- ips = new FileInputStream(file);
- this.getResponse().addHeader("Content-Length", new Long(file.length()).toString());
- int i = 0;
- byte[] buffer = new byte[1024];
- i = ips.read(buffer);
- while (i != -1) {
- ops.write(buffer, 0, i);
- i = ips.read(buffer);
- }
- ips.close();
- ops.flush();
- ops.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
然后在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'
}}
);
}