Java Code Examples for com.xnx3.file.FileUtil#read()

The following examples show how to use com.xnx3.file.FileUtil#read() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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");
}