com.xnx3.file.FileUtil Java Examples

The following examples show how to use com.xnx3.file.FileUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UI.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
   * 读取文件内容,通过用户自己打开文件选择框的方式
   * @param encode 以什么编码读取文件,如:{@link FileUtil#UTF8}
   * @return 文件的内容,若用户没有打开或者打开失败,返回null
   */
  public static String readFileByJFileChooser(String encode){
  	String xnx3_content = null;
  	JFileChooser jfc=new JFileChooser(".");
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result=jfc.showOpenDialog(jfc);
if(result==0){	//用户选择了打开
	try{
		File file=jfc.getSelectedFile();
		FileUtil f = new FileUtil();
		xnx3_content = f.read(file, encode);
		file=null;
	}catch (Exception e) {
		e.printStackTrace();
	}
}
jfc=null;
return xnx3_content;
  }
 
Example #2
Source File: Tts.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 输入文字以及发音速度,女声读出
 * 已废弃,建议使用 {@link TTSUtil#speak(String, int)}
 * <li>需联网。
 * <li>会阻塞当前线程
 * <li>组合函数,首先通过 {@link FileUtil#downFile(String, String)} 将服务器声音文件下载到本地 {@link #ttsPath} ,然后使用 {@link File#play(String)} 进行声音播放
 * @param text 要读的文字,建议80个汉字以内,
 * 				<li><i>标点符号注意:</i>逗号、句号、分号等常用符号没问题,其他特殊符号自行测试。有的会终止阅读甚至报错!
 * @param mode 阅读的快慢,越小发音越慢,参数范围1-5
 * @return 成功|失败
 * @deprecated
 */
public boolean speak(String text,int mode){
	boolean xnx3_result=false;
	
	try {
		//URL编码,防止乱码导致不发音
		text=URLEncoder.encode(text, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	//先下载文件
	String down=FileUtil.downFile("http://tts.baidu.com/text2audio?lan=zh&pid=101&ie=UTF-8&text="+text+"&spd="+mode, ttsPath);
	if(down==null){
		int play=file.play(ttsPath);
		if(play!=0){
			xnx3_result=true;
			this.playId=play;
		}
	}else{
		log.debug(this, "speak", down);
	}
	
	return xnx3_result;
}
 
Example #3
Source File: NewsServiceImpl.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
public void generateListHtml(Site site, SiteColumn siteColumn,List<News> newsList, HttpServletRequest request){
	int count = newsList.size();	//总条数
	Page page = new Page(count, G.PAGE_WAP_NUM);
	page.setUrlByStringUrl("");
	
	//如果是之前的通用模版,装载通用模版的配套方案
	String listHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list.html");
	String listItem = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/module/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list_item.html");
	GenerateHTML gh = new GenerateHTML(site);
	listHtml = gh.assemblyCommon(listHtml);	//装载通用组件
	listHtml = gh.replacePublicTag(listHtml);		//替换通用标签
	
	
	//循环生成每个页面
	for (int i = 1; i <= page.getLastPageNumber() && count >= 0; i++) {
		page.setCurrentPageNumber(i);
		
		String currentListHtml = generateListHtml(listHtml, listItem, page, siteColumn, count, newsList, site, false);
		gh.generateListHtml(currentListHtml, siteColumn, i);
	}
}
 
Example #4
Source File: NewsServiceImpl.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
public void generateListHtml(Site site, SiteColumn siteColumn) {
	List<News> list = sqlDAO.findBySqlQuery("SELECT * FROM news WHERE cid = "+siteColumn.getId() + " AND status = "+News.STATUS_NORMAL, News.class);
	int count = list.size();	//总条数
	Page page = new Page(count, G.PAGE_WAP_NUM);
	page.setUrlByStringUrl("");
	
	String listHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list.html");
	String listItem = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/module/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list_item.html");
	GenerateHTML gh = new GenerateHTML(site);
	listHtml = gh.assemblyCommon(listHtml);	//装载通用组件
	listHtml = gh.replacePublicTag(listHtml);		//替换通用标签
	
	//循环生成每个页面
	for (int i = 1; i <= page.getLastPageNumber() && count >= 0; i++) {
		page.setCurrentPageNumber(i);
		
		String currentListHtml = generateListHtml(listHtml, listItem, page, siteColumn, count, list, site, false);
		gh.generateListHtml(currentListHtml, siteColumn, i);
	}
	
}
 
Example #5
Source File: WeUI.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 生成js缓存文件保存
 */
public void generateCacheFile(){
	String fileName = getClass().getSimpleName()+"_"+objName;
	String filePath = Global.getProjectPath()+Global.CACHE_FILE+fileName+".js"; 
	String data = "";
	for (int i = 0; i < dataList.size(); i++) {
		Map<String, String> map = dataList.get(i);
		if(data.length() > 0){
			data = data + ",";
		}
		data = data + "{title: \""+map.get("title")+"\",value: \""+map.get("value")+"\"}";
	}
	String content = "var "+fileName+" = ["+data+"];";
	try {
		Log.info("create cache js file success ! file path : "+filePath);
		FileUtil.write(filePath, content,FileUtil.UTF8);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: GenerateHTML.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 生成内容详情页面,News的页面,包含独立页面、新闻详情、图文详情
 * @param site
 * @param news
 * @param siteColumn
 * @param text 内容,NewsData.text
 */
public void generateViewHtml(Site site, News news, SiteColumn siteColumn, String text) {
	String pageHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/page.html");
	pageHtml = assemblyCommon(pageHtml);	//装载通用组件
	pageHtml = replaceSiteColumnTag(pageHtml, siteColumn);	//替换栏目相关标签
	pageHtml = replacePublicTag(pageHtml);		//替换通用标签
	pageHtml = replaceNewsListItem(pageHtml, news);	//替换news相关标签
	
	//替换 SEO 相关
	pageHtml = pageHtml.replaceAll(regex("title"), news.getTitle()+"_"+site.getName());
	pageHtml = pageHtml.replaceAll(regex("keywords"), news.getTitle()+","+site.getKeywords());
	pageHtml = Template.replaceAll(pageHtml, regex("description"), news.getIntro()+"");
	
	
	pageHtml = Template.replaceAll(pageHtml, regex("text"), replaceNewsText(text));	//替换新闻内容的详情
	
	String generateUrl = "";
	if(news.getType() - News.TYPE_PAGE == 0){
		generateUrl = "site/"+site.getId()+"/c"+news.getCid()+".html";
	}else{
		generateUrl = "site/"+site.getId()+"/"+news.getId()+".html";
	}
	AttachmentFile.putStringFile(generateUrl, pageHtml);
}
 
Example #7
Source File: GenerateHTML.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
	 * 装载common文件夹下的通用组件,WAP、PC通用
	 * @param text 页面模版的内容,会将这里面所存在的调用common的模版装载组合
	 * @param 返回装载了通用模版组件的模版内容
	 */
	public String assemblyCommon(String text){
		Pattern p = Pattern.compile(regex("include=(.*?)"));
        Matcher m = p.matcher(text);
        while (m.find()) {
        	String templateVarName = m.group(1);	//模版变量的id
            
        	//查看再内存中是否有此项内容了,若没有,先将模版装载入内存,以后直接从内存取
        	String key = templateId+templateVarName;
        	String templateVarText = commonMap.get(key);
//            if(templateVarText == null){
            if(true){
            	templateVarText = FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/common/"+templateVarName+".html");
            	commonMap.put(key,templateVarText);
            }
            
            String reg = regex("include="+templateVarName);
            text = text.replaceAll(reg, templateVarText);
        }
		
        return text;
	}
 
Example #8
Source File: GenerateHTML.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
	 * 生成网站首页
	 * @param htmlText 如果是PC首页,则需要传入要声称页面的内容。毕竟PC首页会牵扯到替换模版某个模块,不能全局替换,替换处理再 pc/下
	 * 				如果是WAP首页,则不需要传此参数
	 * @param siteData {@link SiteData},单个模块刷新时可传null
	 */
	public void generateIndexHtml(String htmlText,SiteData siteData){
		if(htmlText == null){
			//加入htmledit时,刷新首页报空指针,加此
			return;
		}
		
		if(site.getClient() - Site.CLIENT_PC == 0){
			//电脑页面
//			html = gh.pcIndex();
			//刷新pc首页的时候,需要刷新pc首页中间的那些数据,还需要到数据库里将其查询出来
			
			htmlText = htmlText.replaceAll("<!--templateStyleCss-->", "<link href=\""+AttachmentFile.netUrl()+"template/"+site.getTemplateId()+"/style.css\" rel=\"stylesheet\" type=\"text/css\">");
		}else{
			htmlText = FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/index.html");
			htmlText = assemblyCommon(htmlText);	//装载通用组件
			htmlText = replacePublicTag(htmlText);		//替换通用标签
		}
		
		//替换 SEO 相关
		htmlText = htmlText.replaceAll(regex("title"), site.getName());
		htmlText = htmlText.replaceAll(regex("keywords"), site.getKeywords());
		htmlText = htmlText.replaceAll(regex("description"), siteData == null? site.getName():siteData.getIndexDescription());
		
		generateIndexHtml(htmlText);
	}
 
Example #9
Source File: Test.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	
	try {
		FileUtil.downFiles("http://res.weiunity.com/template/qiye1/images/icon-sns-zh.gif", "/Users/apple/Desktop/icon-sns-zh.gif");
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
 
Example #10
Source File: Cache.java    From templatespider with Apache License 2.0 5 votes vote down vote up
/**
 * 将 {@link #cacheMap} 缓存到本地磁盘,文件下载
 */
public static synchronized void downFile(Resource resource){
	try {
		FileUtil.downFiles(resource.getNetUrl(), resource.getLocalUrl());
	}catch(java.io.FileNotFoundException notFind){
		Global.log("404 File Not Found !  "+resource.getNetUrl());
	}catch(java.lang.NullPointerException nullE){
		Global.log("downFile NULL----- "+resource.getNetUrl());
	}catch (Exception e) {
		Global.log(e.getMessage()+" --- "+resource.getNetUrl());
		e.printStackTrace();
	}
}
 
Example #11
Source File: MP3Play.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * @param filePath	MP3文件的绝对路径,如 E:/xnx3/test.mp3
 * @throws JavaLayerException 
 * @throws FileNotFoundException 
 */
public MP3Play(String filePath) throws JavaLayerException, FileNotFoundException {
	if(FileUtil.exists(filePath)){
		BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(filePath));
        player = new Player(buffer);
	}else{
		throw new FileNotFoundException(filePath+" is not exists");
	}
}
 
Example #12
Source File: BaseGenerate.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化缓存文件夹,若根目录下没有缓存文件夹,自动创建
 */
private void initCacheFolder(){
	if(!FileUtil.exists(Global.getProjectPath()+Global.CACHE_FILE)){
		com.xnx3.j2ee.func.Log.info("create cache folder : "+ Global.getProjectPath()+Global.CACHE_FILE);
		String[] folders = Global.CACHE_FILE.split("/");
		String path = Global.getProjectPath();
		for (int i = 0; i < folders.length; i++) {
			if(folders[i].length()>0&&!FileUtil.exists(path+folders[i])){
				File file = new File(path+folders[i]);
				file.mkdir();
			}
			path = path+folders[i]+"/";
		}
	}
}
 
Example #13
Source File: BaseGenerate.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 生成js缓存文件保存
 */
public void generateCacheFile(){
	addCommonJsFunction();
	initCacheFolder();
	String filePath = Global.getProjectPath()+Global.CACHE_FILE+getClass().getSimpleName()+"_"+objName+".js"; 
	try {
		content = content + " var xnx3_r"+DateUtil.timeForUnix10()+" = '"+getRandomValue()+"';";
		FileUtil.write(filePath, content,FileUtil.UTF8);
		com.xnx3.j2ee.func.Log.info("create cache js file success ! file path : "+filePath);
	} catch (IOException e) {
		e.printStackTrace();
	}
	this.content=null;
}
 
Example #14
Source File: InstallController_.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 自删除,将此installController.class删除掉
 */
@RequestMapping("/delete${url.suffix}")
public String delete(HttpServletRequest request, Model model){
	String thisClassPath = this.getClass().getResource("/com/xnx3/j2ee/controller/InstallController_.class").getPath();
	boolean d = FileUtil.deleteFile(thisClassPath);
	if(d){
		return success(model, "安装文件已删除!登录后台 /login.do 使用吧", "/login.do");
	}else{
		return error(model, "删除失败,可能文件已删除了");
	}
}
 
Example #15
Source File: AutoCreateDataFolder.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public AutoCreateDataFolder() {
	//初始化缓存文件夹,若根目录下没有缓存文件夹,自动创建
	if(!FileUtil.exists(Global.getProjectPath()+G.CACHE_FILE)){
		String path = Global.getProjectPath();
		System.out.println("create -- data --"+new File(path+G.CACHE_FILE).mkdir());
	}
}
 
Example #16
Source File: GenerateHTML.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取编辑模式下,pc首页的html
 * @return
 */
public String pcIndex(){
	String pageHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/index.html");
	pageHtml = assemblyCommon(pageHtml);	//装载通用组件
	pageHtml = replacePublicTag(pageHtml);		//替换通用标签
	
	pageHtml = pageHtml.replaceAll(regex("title"), site.getName());
	
	return pageHtml;
}
 
Example #17
Source File: GenerateHTML.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取编辑模式下,wap首页的html
 * @return
 */
public String wapIndex(){
	String pageHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/index.html");
	pageHtml = assemblyCommon(pageHtml);	//装载通用组件
	pageHtml = replacePublicTag(pageHtml);		//替换通用标签
	
	pageHtml = pageHtml.replaceAll(regex("title"), site.getName());
	
	return pageHtml;
}
 
Example #18
Source File: SiteServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public TemplateCommon getTemplateCommonHtml(Site site, String title, Model model) {
	if(site == null){
		site = new Site();
		site.setId(0);
		site.setName("");
		site.setTemplateId(1);
	}
	
	TemplateCommon tc = new TemplateCommon();
	
	GenerateHTML gh = new GenerateHTML(site);
	Template temp = new Template(site);
	gh.setEditMode(true);
	
	String headHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+gh.templateId+"/common/head.html");
	headHtml = gh.replacePublicTag(headHtml);
	headHtml = headHtml.replaceAll(GenerateHTML.regex("title"), title);
	headHtml = temp.replaceForEditModeTag(headHtml);
	
	String topHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+gh.templateId+"/common/top.html");
	topHtml = gh.replacePublicTag(topHtml);
	topHtml = topHtml.replaceAll(GenerateHTML.regex("title"), title);
	topHtml = temp.replaceForEditModeTag(topHtml);
	
	String footHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+gh.templateId+"/common/foot.html");
	footHtml = gh.replacePublicTag(footHtml);
	footHtml = temp.replaceForEditModeTag(footHtml);
	
	model.addAttribute("headHtml", headHtml);
	model.addAttribute("topHtml", topHtml);
	model.addAttribute("footHtml", footHtml);
	
	return tc;
}
 
Example #19
Source File: NewsServiceImpl.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 编辑模式下的列表页面html生成
 */
public String generateListHtml(Page page, SiteColumn siteColumn, int count, List<News> list, Site site){
	String listHtml = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list.html");
	String listItem = FileUtil.read(Global.getProjectPath()+"/static/template/"+site.getTemplateId()+"/module/"+(siteColumn.getType()==SiteColumn.TYPE_NEWS? "news":"newsimage")+"_list_item.html");
	GenerateHTML gh = new GenerateHTML(site);
	gh.setEditMode(true);
	listHtml = gh.assemblyCommon(listHtml);	//装载通用组件
	listHtml = gh.replacePublicTag(listHtml);		//替换通用标签
	
	return generateListHtml(listHtml, listItem, page, siteColumn, count, list, site, true);
}
 
Example #20
Source File: StringDiff.java    From templatespider with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	String a = FileUtil.read(Global.getAppPath()+"template/about2.html");
	String b = FileUtil.read(Global.getAppPath()+"template/about1.html");
	StringDiff d = new StringDiff(a, b);
	
	try {
		FileUtil.write(StringDiff.class.getResource("/").getPath()+"preview.html", d.previewDiffHtml(), "UTF-8");
		SystemUtil.openUrl("file://"+StringDiff.class.getResource("/").getPath()+"preview.html");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #21
Source File: doc.java    From templatespider with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
		
		Document doc = Jsoup.parse(FileUtil.read("G:/MyEclipseWorkSpace/templaete/template/about.html", FileUtil.UTF8));
		Element body = doc.getElementsByTag("body").first();
//		System.out.println(body);
		
		Elements e = body.children();
		for (int i = 0; i < e.size(); i++) {
			System.out.println("---------------"+e.get(i).tagName());
			System.out.println(e.get(i));
		}
		
	}
 
Example #22
Source File: Action.java    From templatespider with Apache License 2.0 5 votes vote down vote up
/**
 * 在app跟目录写出模版文件
 * @param fileName 文件名字
 * @param text 文件内容
 */
public static void writeTemplateFile(String fileName, String text){
	File file = new File(Global.getAppPath()+getTemplatePathName()+"/");
	if(!file.exists()){
		file.mkdir();
	}
	
	FileUtil.write(Global.getAppPath()+getTemplatePathName()+"/"+fileName+".html", text);
}
 
Example #23
Source File: Cache.java    From templatespider with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
	FileUtil.downFiles("http://www.xingyucjb.com/Public/Wap/images/b4.png", "/images/js/b4.png");
}
 
Example #24
Source File: InputModelServiceImpl.java    From wangmarket with Apache License 2.0 4 votes vote down vote up
public String getDefaultInputModelText() {
	if(defaultInputModelText == null){	
		defaultInputModelText = FileUtil.read(Global.getProjectPath()+"static/inputModel/default.html");
	}
	return defaultInputModelText;
}
 
Example #25
Source File: Com.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 创建dm.dmsoft对象
 * <li>检测dm.dll是否已注册,若是没有注册,则自动注册
 * <li>若是已注册,则创建dm.dmsoft对象
 */
private void initRegisterDll(){
	if(Com.initDll){
		return;
	}
	
	Com.initDll=true;
	activeBean=new ActiveBean();
	String currentDir=Lang.getCurrentJrePath();	//当前项目Jre路径
	
	try {
		ActiveXComponent activeDm=new ActiveXComponent("dm.dmsoft");
		activeBean.setDm(activeDm);		//创建大漠对象
		activeBean.setPlugin365(new ActiveXComponent("Plugin365ID"));	//创建365对象
		this.createSuccess=true;
	} catch (Exception e) {
		e.printStackTrace();
		//检测dm.dll是否放到了C:下
		String dm="C:\\dm.dll";
		if(!FileUtil.exists(dm)){
			this.createSuccess=false;
			FileUtil.inputStreamToFile(this.getClass().getResourceAsStream("dll/dm.dll"), dm);
			SystemUtil.registerDll(dm);
			log.debug(this, "initRegisterDll()", "注册dm.dll完毕");
		}
		
		//检测Plug365New.dll是否放到了C:下
		String plug365="C:\\Plug365New.dll";
		if(!FileUtil.exists(plug365)){
			this.createSuccess=false;
			FileUtil.inputStreamToFile(this.getClass().getResourceAsStream("dll/Plug365New.dll"), plug365);
			SystemUtil.registerDll(plug365);
			log.debug(this, "initRegisterDll()", "注册Plug365New.dll完毕");
		}
		
		try {
			activeBean.setDm(new ActiveXComponent("dm.dmsoft"));		//创建大漠对象
			activeBean.setPlugin365(new ActiveXComponent("Plugin365ID"));	//创建365对象
			log.debug(this, "initDll", "检测到dll未注册,已自动注册完毕");
			this.createSuccess=true;
		} catch (Exception e2) {
			this.createSuccess=false;
			
			e2.printStackTrace();
			if(e2.getMessage().equals("Can't co-create object")){
				System.out.println("检测到dll插件未注册,进行自动注册时出错!报此异常,极大可能是运行的Jar导致的,请下载我们测试好的Jar1.7安装包进行开发调试");
				System.out.println("http://www.xnx3.com/doc/jre1.7.html");
				System.out.println("(如果弹出提示注册...dll文件失败,则你的操作系统注册不了,有极少数的xp、win7的用户电脑注册不了的,可以换台电脑测试)");
			}
			
		}
	}
	
}
 
Example #26
Source File: Resource.java    From templatespider with Apache License 2.0 4 votes vote down vote up
/**
	 * 根据this.netUrl 网上的绝对路径,来计算存到本地的路径
	 */
	public void jisuanLocalFile(){
		
//		String originalUrl = null;
		if(this.netUrl.lastIndexOf("/") < 5){
			Global.log("debug netUrl.lastIndexOf < 5, netUrl:"+this.netUrl);
			return;
		}else{
			//保存到本地的文件
			this.localFile = UrlUtil.getFileName(this.netUrl);
//					StringUtil.getFileNameByUrl(this.netUrl);
		}

		//判断资源类型,是html、css、js、image
		//获取资源的后缀名+后面?的一堆
		String suffix = Lang.subString(this.localFile, ".", null, 4);
		//图片文件后缀
		String[] imgs = {"jpg","jpeg","gif","png","bmp","ico","svg"};
		String type = null;
		for (int i = 0; i < imgs.length; i++) {
			if(suffix.equalsIgnoreCase(imgs[i])){
				type = "image";
				break;
			}
		}
		if(type == null){
			//判断是否是js后缀
			if(suffix.equalsIgnoreCase("js")){
				type = "js";
			}
		}
		if(type == null){
			//判断是否是css后缀
			String[] csss = {"css","woff2","woff","eot","ttf","otf"};
			for (int i = 0; i < csss.length; i++) {
				if(suffix.equalsIgnoreCase(csss[i])){
					type = "css";
					break;
				}
			}
		}
		if(type == null){
			//判断是否是html文件
			String[] htmls = {"htm","html","shtml","jsp","action","do","asp","aspx","php"};
			for (int i = 0; i < htmls.length; i++) {
				if(suffix.equalsIgnoreCase(htmls[i])){
					type = "html";
					suffix = "html";	//后缀名变为html
					this.localFile.replace("."+htmls[i], "html");	//将缓存的后缀改为html
					break;
				}
			}
		}
		if(type == null){
			System.out.println("未发现什么类型。type:"+type+",--"+originalUrl);
			this.localUrl = Global.getLocalTemplatePath();
			this.localRelativePath = "/";
		}else{
			switch (type) {
			case "image":
				this.localUrl = Global.getLocalTemplatePath()+"images/";
				this.localRelativePath = "images/";
				break;
			case "js":
				this.localUrl = Global.getLocalTemplatePath()+"js/";
				this.localRelativePath = "js/";
				break;
			case "css":
				this.localUrl = Global.getLocalTemplatePath()+"css/";
				this.localRelativePath = "css/";
				break;
			case "html":
				this.localUrl = Global.getLocalTemplatePath();
				this.localRelativePath = "/";
				break;
			default:
				this.localUrl = Global.getLocalTemplatePath();
				this.localRelativePath = "/";
				break;
			}
		}

		
		//判断磁盘上这个文件是否存在
		if(FileUtil.exists(this.localUrl + localFile)){
			//已经存在了,那么要重新命名,不能覆盖
			this.localFile = Lang.subString(this.localFile, null, ".")+"_"+Lang.uuid()+"."+suffix;
		}
		
		//赋值,当前存储再磁盘的绝对路径
		this.localUrl = this.localUrl + this.localFile;
	}
 
Example #27
Source File: Template.java    From wangmarket with Apache License 2.0 2 votes vote down vote up
/**
 * 获取当前首页模版的html代码。仅仅当前首页的模版,不包含引入的common文件
 * @param templateId 模版编号
 * @return 模版的HTML代码
 */
public String getIndexTemplateHtml_Only(){
	return FileUtil.read(Global.getProjectPath()+"/static/template/"+templateId+"/index.html");
}