posts - 61,  comments - 2033,  trackbacks - 0
   由于web中的文件不能直接通过url方式读取opencms的sites下的文件,所以必须绕个弯子解决。查阅了一下opencms的源代码,我的解决思路如下:
 
第一 拷贝方式:
 
   1.第一次访问时,根据opencms提供的接口,把文件从数据库读到java对象obj
   2.将obj对象拷贝到web中的对应目录
   3.将web中的对应目录的url确定,即可直接调用。
   4.第二次及其以后访问时,根据对象obj的最后修改时间属性,确定是否需要重复1-3步骤。

参考源代码:
 

 
<% @ page pageencoding = " utf-8 "   %>
<% @ page buffer = " none "   import = " org.opencms.util.*, org.teema.eeonline.exhibition.exhibitionconstants,com.tblink.common.util.stringutil,org.opencms.frontend.templateone.modules.*,javax.servlet.servletoutputstream, org.opencms.file.*,java.util.*, java.io.*, org.opencms.frontend.templateone.* "   %>
<% @ taglib uri = " http://jakarta.apache.org/struts/tags-bean "  prefix = " bean " %>
<% @ taglib prefix = " cms "  uri = " http://www.opencms.org/taglib/cms "   %>
<% @ taglib prefix = " fmt "  uri = " http://java.sun.com/jstl/fmt "   %>
<% @ taglib prefix = " c "  uri = " http://java.sun.com/jstl/core "   %>
<% @ include file = " ../elements/common/common.jsp "   %>

<%!
private  string copyfile(cmsfile cmsfile){
    
try {
        
byte [] bytefile  =  cmsfile.getcontents();
        string path 
=  stringutil.getrealpath(stringutil. class , " web-inf " ,exhibitionconstants.exhibition_flash_directionary);
        randomaccessfile rf
= new  randomaccessfile(path   exhibitionconstants.exhibition_flash_name, " rw " ); 
        rf.write(bytefile); 
        rf.close();
        
return  path.substring( 0 ,path.length() - 1 );
    }
    
catch (exception e)
    {
        
return   "" ;
    }
}
%>

<%
string direct 
=  exhibitionconstants.exhibition_flash_directionary   exhibitionconstants.exhibition_flash_name;
string flashurl 
=   "" ;
try {
cmsfile cmsfile 
=  __cmsjsp.getcmsobject().readfile(direct);
long  l  =  cmsfile.getdatelastmodified();
string lstr 
=  (string)application.getattribute(exhibitionconstants.application_flash_date_index);
flashurl 
=  (string)application.getattribute(exhibitionconstants.application_flash_url_index);

if (lstr == null   ||   ! stringutil.isnums(lstr)){
    direct 
=  copyfile(cmsfile);
}
else   if (long.parselong(lstr) == l){
    
if (flashurl == null ){
        direct 
=  copyfile(cmsfile);
    }
}
else {
      direct 
=  copyfile(cmsfile);
}
flashurl 
=   request.getcontextpath()   exhibitionconstants.exhibition_flash_directionary   exhibitionconstants.exhibition_flash_name;
application.setattribute(exhibitionconstants.application_flash_date_index,lstr);
application.setattribute(exhibitionconstants.application_flash_url_index,flashurl);

}
catch (exception e)
{
    out.println(e); 
}
%>

< object classid = " clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 "  codebase = " http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 "  width = " 760 "  height = " 266 " >
       
< param name = " movie "  value = " <%=flashurl%> " >
       
< param name = " quality "  value = " high " >
       
< embed src = " <%=flashurl%> "  quality = " high "  pluginspage = " http://www.macromedia.com/go/getflashplayer "  type = " application/x-shockwave-flash "  width = " 760 "  height = " 266 " > embed >
object >



第二、新增resource type方式

  1.新建resource type,详细请见前一篇文章
  2.在opencms控制台,新增该类别的文件
  3.调用相关api显示出来,代码如下

 
<%
    
if (getresourcecount(__cms, "teema_ad/home/wide_block_1/|teemaad"false> 0) { 
%>  

            
<cms:contentload collector="allinfolderdatereleaseddesc" param="teema_ad/home/wide_block_1/|teemaad" editable="true">
                    
<% 
                 
if(bannertextcount<1) {
                bannertextcount
;
            
%>

                            
<a href='' target="_blank">
                              
<img src="/eeonline/cms"image/image"/>" width="440" height="75">
                            
a>

            
<%   } %>
                  
cms:contentload>
        
tr>
<%
    } 
%>  

 

欢迎提出新的意见!
posted on 2006-08-11 12:59 鱼上游 阅读(3761) 评论(1)  编辑  收藏 所属分类: 爪哇世界探险


feedback:
# re: 关于opencms把sites目录中的文件根据url显示到网页的解决方法
2006-09-01 12:44 |
不错,opencms文章太少,多一篇都是好的  回复  
  

只有注册用户后才能发表评论。


网站导航:
              
 
2006年8月
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(82)

关于opencms把sites目录中的文件根据url显示到网页的解决方法 -凯发k8网页登录

  • management it
  • open source host
  • java's opensource
  • open source,java
  • quick update
  • opensymphony
  • sourceforge
  • software's authority

搜索

  •  

积分与排名

  • 积分 - 1261225
  • 排名 - 22

最新评论

阅读排行榜

网站地图