/* ================================================================== * Created [2009-4-27 下午11:32:55] by Jon.King * ================================================================== * TSS * ================================================================== * mailTo:jinpujun@hotmail.com * Copyright (c) Jon.King, 2009-2012 * ================================================================== */ package com.jinhe.tss.cms.helper; import java.io.File; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import com.jinhe.tss.cms.dao.IChannelDao; import com.jinhe.tss.cms.entity.Channel; import com.jinhe.tss.component.support.web.upload.AbstractFilePathCreator; /** * 设置上传文件存放位置和文件名。 * 需要实现接口com.jinhe.tss.component.support.web.upload.IFilePathCreator 或扩展超类com.jinhe.tss.component.support.web.upload.naming.AbstractFilePathCreator */ public class ArticleAttachPathCreator extends AbstractFilePathCreator { @Autowired IChannelDao channelDao; public String getPath(File file, Map<String, String> params) { Channel channel = channelDao.getEntity(Long.valueOf(params.get("channelId"))); Channel site = channelDao.getEntity(channel.getSiteId()); return ArticleHelper.getAttachmentPath(site, Integer.valueOf(params.get("type"))); } public String getFileName(File file, Map<String, String> params) { String name = file.getName(); params.put("name", name); int i = name.lastIndexOf("."); String fileExt = (i != -1) ? name.substring(i, name.length()) : ""; return System.currentTimeMillis() + fileExt; } }