资源下载

来源:互联网 发布:md文件编辑器 mac版本 编辑:程序博客网 时间:2024/05/01 21:30

下载:
<script type="text/javascript">
    function getPortalVersionSource(version) {
        var url ="<%=path%>/PortalVersion/downLoadPortalVersion.action?portalVersion.version="+version;
        window.location = url;
    }
</script>
下载门户原始zip包
<span> <a  href="javascript:getPortalVersionSource('<s:property value='#portalVersion.version'/>')" ><s:text name="msg.portalMS.publishmgr.version.download.zip" /></a> </span>

strut.xml
        <!--source-->  
        <action name="downLoadPortalVersion" class="portalVersionAction" method="downLoadPortalVersion">
            <!-- 设置文件名参数,由页面上传入 -->
            <result name="success" type="stream">
                <!-- 下载文件类型定义 -->
                <param name="bufferSize">1024</param>
                <!-- 下载文件输出流定义 -->
                <param name="inputName">portalInputStream</param>
            </result>
            <result name="error">/common/error.jsp</result>
        </action>

portalVersionAction.java :
    private transient FileInputStream portalInputStream;
    
    private PortalVersion portalVersion;
/**
     * 下载导入模板文件
     *
     * @return
     * @throws IOException
     */
    public void downLoadPortalVersion() throws IOException
    {
        logger.enterFuncDebugLog();
        OutputStream toClient = null;
        
        String filePath = Constants.PORTAL_PACKAGE.getStringValue()
                + File.separator + "source";// filePath=portalPackage\source
        String filePathversion = jbossbin + File.separator + filePath
                + File.separator + this.portalVersion.getVersion() + ".zip";
                //filePathversion= D:\tomcat_portal\bin\portalMS\portalPackage\source\TWGD.zip
        logger.atFuncDebugLog("filePathversion:",filePathversion);
        File file = new File(filePathversion);
        if (!file.exists())
        {
            logger.excepFuncDebugLog("file is not find" + file.getPath());
            logger.exitFuncDebugLog();
            return;
        }
        try
        {
            portalInputStream = new FileInputStream(filePathversion);
            HttpServletResponse response = this.getHttpServletResponse();
            response.setHeader("Content-Disposition",
                    "attachment;filename="
                            + new String(
                                    (this.portalVersion.getVersion() + ".zip").getBytes("GBK"),
                                    "iso8859-1"));
            int i = portalInputStream.available(); // 得到文件大小
            byte data[] = new byte[i];
            portalInputStream.read(data); // 读数据
            
            toClient = response.getOutputStream(); // 得到向客户端输出二进制数据的对象
            toClient.write(data); // 输出数据
            
        }
        catch (Exception e)
        {
            logger.excepFuncDebugLog("download the file is failed:"
                    + e.getMessage());
            logger.exitFuncDebugLog();
            return;
        }
        finally
        {
            portalInputStream.close();
            toClient.close();
        }
        logger.exitFuncDebugLog();
        return;
    }


PortalVersion.java
package com.xxxxxx.dhm.portalMS.publishMs.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import com.xxxxxx.ChineseCharacter;
import com.xxxxxx.dhm.common.config.impl.PropertiesFactory;
import com.xxxxxx.dhm.portalMS.common.util.DateUtil;

public class PortalVersion implements Serializable
{
    private static final long serialVersionUID = 1L;
    private Long versionId;
    private Long siteID;
    private Integer status;

    private String statusStr;

    // 门户版本别名,如幻灯版
    private String versionName;

    // 版本号
    private String version;

    // 局点简称,如南京广电
    private String customer;

    // 模板页面,需要通过PortalMS生成静态页面
    private String templatepages;

    // 门户版本包发布日期
    private Date deploydate;

    private String deploydateStr;

    // 门户导入日期
    private Date importdate;

    private String importdateStr;

    // 最后修改日期
    private Date lastmodifydate;
    private String lastmodifydateStr;
    private String remark;

    public String getImportdateStr()
    {
        return importdateStr;
    }

    public void setImportdateStr(String importdateStr)
    {
        this.importdateStr = importdateStr;
    }

    public String getLastmodifydateStr()
    {
        return lastmodifydateStr;
    }

    public void setLastmodifydateStr(String lastmodifydateStr)
    {
        this.lastmodifydateStr = lastmodifydateStr;
    }

    public Long getVersionId()
    {
        return versionId;
    }

    public void setVersionId(Long versionId)
    {
        this.versionId = versionId;
    }

    public Long getSiteID()
    {
        return siteID;
    }

    public void setSiteID(Long siteID)
    {
        this.siteID = siteID;
    }

    public Integer getStatus()
    {
        return status;
    }

    public void setStatus(Integer status)
    {
        this.status = status;
        if (this.status == 0)
        {
            this.statusStr = PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_NEW);
        }
        else if (this.status == 1)
        {
            this.statusStr =  PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_WAIT);
        }
        else if (this.status == 2)
        {
            this.statusStr = PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_REJECT);
        }
        else if (this.status == 3)
        {
            this.statusStr =  PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_PASS);
        }
        else if (this.status == 4)
        {
            this.statusStr =  PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_PUBLISHING);
        }
        else if (this.status == 5)
        {
            this.statusStr =  PropertiesFactory.getValueString(ChineseCharacter.PORTALVERSION_STATUS_PUBLISHED);
        }

    }

    public String getVersionName()
    {
        return versionName;
    }

    public void setVersionName(String versionName)
    {
        this.versionName = versionName;
    }

    public String getVersion()
    {
        return version;
    }

    public void setVersion(String version)
    {
        this.version = version;
    }

    public String getCustomer()
    {
        return customer;
    }

    public void setCustomer(String customer)
    {
        this.customer = customer;
    }

    public String getTemplatepages()
    {
        return templatepages;
    }

    public void setTemplatepages(String templatepages)
    {
        this.templatepages = templatepages;
    }

    public Date getDeploydate()
    {
        Date temp = deploydate;
        return temp;
    }

    public void setDeploydate(Date deploydate)
    {
        if (null != deploydate)
        {
            Calendar date = Calendar.getInstance();
            date.setTime(deploydate);
            this.deploydate = date.getTime();
        }
    }

    public Date getImportdate()
    {
        Date temp = importdate;
        return temp;
    }

    public void setImportdate(Date importdate)
    {
        if (null != importdate)
        {
            Calendar date = Calendar.getInstance();
            date.setTime(importdate);
            this.importdate = date.getTime();
        }
        this.importdateStr = DateUtil.fmtDateTime(this.importdate);
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public String getStatusStr()
    {
        return statusStr;
    }

    public void setStatusStr(String statusStr)
    {
        this.statusStr = statusStr;
    }

    public String getDeploydateStr()
    {
        return deploydateStr;
    }

    public void setDeploydateStr(String deploydateStr)
    {
        this.deploydateStr = deploydateStr;
    }

    public Date getLastmodifydate()
    {
        Date tmp = lastmodifydate;
        return tmp;
    }

    public void setLastmodifydate(Date lastmodifydate)
    {
        if (null != lastmodifydate)
        {
            Calendar date = Calendar.getInstance();
            date.setTime(lastmodifydate);
            this.lastmodifydate = date.getTime();
        }
         
        this.lastmodifydateStr = DateUtil.fmtDateTime(this.lastmodifydate);
    }

    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("PortalVersion [versionId=");
        builder.append(versionId);
        builder.append(", siteID=");
        builder.append(siteID);
        builder.append(", status=");
        builder.append(status);
        builder.append(", versionName=");
        builder.append(versionName);
        builder.append(", version=");
        builder.append(version);
        builder.append(", customer=");
        builder.append(customer);
        builder.append(", importdate=");
        builder.append(importdate);
        builder.append(", lastmodifydate=");
        builder.append(lastmodifydate);
        builder.append("]");
        return builder.toString();
    }
}

   



  /* 读取根路径 */
  private static String jbossbin = getConfigFullPath("portalMS");
    
  public static String getAppRootPath()
  {
    return System.getProperty("user.dir");
  }

  public static String getConfigFullPath(String configFileName)
  {
    String configFile = configFileName.replace('/', FS.charAt(0));
    if (!configFile.startsWith(FS))
    {
      configFile = FS + configFile;
    }
    return getAppRootPath() + configFile;
  }

0 0
原创粉丝点击