txt轉(zhuǎn)pdf、eqpu、xml.doc_第1頁
txt轉(zhuǎn)pdf、eqpu、xml.doc_第2頁
txt轉(zhuǎn)pdf、eqpu、xml.doc_第3頁
txt轉(zhuǎn)pdf、eqpu、xml.doc_第4頁
txt轉(zhuǎn)pdf、eqpu、xml.doc_第5頁
已閱讀5頁,還剩56頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

chapter.html模板(每一章的內(nèi)容)html view plaincopyprint?$chapter.ttitle!$section.htmlContent!$chapter.ttitle!$section.htmlContent!content.html(目錄信息) html view plaincopyprint?目錄目錄$chapter.ttitle!目錄目錄$chapter.ttitle!converpage.html(封面) html view plaincopyprint?$ebook.ttitle!$ebook.ttitle!ncx文件html view plaincopyprint?$ebook.ttitle!$ebook.tauthor!封面$chapter.ttitle! $ebook.ttitle!$ebook.tauthor!封面$chapter.ttitle!opf文件 html view plaincopyprint?$ebook.ttitle!en$ebook.tauthor!Freesourcelcsh:Novel$ebook.ttitle!en$ebook.tauthor!Freesourcelcsh: Novel以上這些文件必須放在模板處理的類所在的子目錄resources里面,當(dāng)然自己可以調(diào)整下面貼出模板處理的兩個(gè)類TemplateException.javajava view plaincopyprint?packagecom.dangdang.template;/*模板異常類.*/publicclassTemplateExceptionextendsExceptionprivatestaticfinallongserialVersionUID=-1532247619099231683L;publicTemplateException()publicTemplateException(finalStringmessage)super(message);publicTemplateException(finalThrowablecause)super(cause);publicTemplateException(finalStringmessage,finalThrowablecause)super(message,cause);package com.dangdang.template;/*模板異常類.* */public class TemplateException extends Exception private static final long serialVersionUID = -1532247619099231683L;public TemplateException() public TemplateException(final String message) super(message);public TemplateException(final Throwable cause) super(cause);public TemplateException(final String message, final Throwable cause) super(message, cause);TemplateProcess.java java view plaincopyprint?packagecom.dangdang.template;importjava.io.BufferedOutputStream;importjava.io.File;importjava.io.IOException;importjava.io.OutputStream;importjava.io.OutputStreamWriter;importjava.io.StringWriter;importjava.io.Writer;importjava.util.Map;mons.io.IOUtils;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importcom.dangdang.util.FileUtils;importfreemarker.cache.ClassTemplateLoader;importfreemarker.cache.TemplateLoader;importfreemarker.template.Configuration;importfreemarker.template.DefaultObjectWrapper;importfreemarker.template.Template;/*基于freemarker的模板處理程序.*/publicabstractclassTemplateProcessprivateTemplateProcess()privatestaticLoggerlog=LoggerFactory.getLogger(TemplateProcess.class);privatestaticfinalConfigurationCFG=newConfiguration()TemplateLoadertemplateLoader=newClassTemplateLoader(TemplateProcess.class,resources);setTemplateLoader(templateLoader);setDefaultEncoding(UTF-8);setObjectWrapper(newDefaultObjectWrapper();/*處理模板,返回結(jié)果.*paramtpl相對(duì)于classpath:/tpl的模板文件路徑*parammodel模板數(shù)據(jù)*return合成結(jié)果*throwsTemplateException*/publicstaticStringprocess(finalStringtpl,finalMapmodel)throwsTemplateExceptionfinalWriterout=newStringWriter();process(tpl,model,out);returnout.toString();/*處理模板,輸出結(jié)果到文件.如果文件不存在,將創(chuàng)建文件及路徑上的所有目錄.*paramtpl相對(duì)于classpath:/tpl的模板文件路徑*parammodel模板數(shù)據(jù)*paramfile目標(biāo)文件,不存在是將新建*paramoverwrite目標(biāo)文件存在時(shí)是否覆蓋*throwsTemplateException*/publicstaticvoidprocess(finalStringtpl,finalMapmodel,finalFilefile,finalbooleanoverwrite)throwsExceptionif(file.exists()if(overwrite)FileUtils.deleteQuietly(file);elselog.warn(目標(biāo)文件已存在);return;OutputStreamout;tryout=FileUtils.openOutputStream(file);catch(finalIOExceptione)finalStringmsg=處理模板失敗-打開目標(biāo)文件失敗;log.error(msg,e);thrownewTemplateException(msg,e);finalWriterwriter=newOutputStreamWriter(newBufferedOutputStream(out,8192),UTF-8);process(tpl,model,writer);IOUtils.closeQuietly(writer);IOUtils.closeQuietly(out);/*處理模板,輸出結(jié)果到writer參數(shù).*paramtpl相對(duì)于classpath:/tpl的模板文件路徑*parammodel模板數(shù)據(jù)*paramwriter輸出目標(biāo)*throwsTemplateException*/publicstaticvoidprocess(finalStringtpl,finalMapmodel,finalWriterwriter)throwsTemplateExceptiontryfinalTemplatetemplate=CFG.getTemplate(tpl);template.setEncoding(UTF-8);cess(model,writer);catch(finalExceptione)finalStringmsg=處理模板失敗;log.error(msg,e);thrownewTemplateException(msg,e);package com.dangdang.template;import java.io.BufferedOutputStream;import java.io.File;import java.io.IOException;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.StringWriter;import java.io.Writer;import java.util.Map;import mons.io.IOUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.dangdang.util.FileUtils;import freemarker.cache.ClassTemplateLoader;import freemarker.cache.TemplateLoader;import freemarker.template.Configuration;import freemarker.template.DefaultObjectWrapper;import freemarker.template.Template;/* * 基于freemarker的模板處理程序. * * */public abstract class TemplateProcess private TemplateProcess() private static Logger log = LoggerFactory.getLogger(TemplateProcess.class);private static final Configuration CFG = new Configuration() TemplateLoader templateLoader=new ClassTemplateLoader(TemplateProcess.class,resources);setTemplateLoader(templateLoader);setDefaultEncoding(UTF-8);setObjectWrapper(new DefaultObjectWrapper(); ;/* * 處理模板,返回結(jié)果. * * param tpl 相對(duì)于classpath:/tpl的模板文件路徑 * param model 模板數(shù)據(jù) * return 合成結(jié)果 * throws TemplateException */public static String process(final String tpl, final Map model) throws TemplateException final Writer out = new StringWriter();process(tpl, model, out);return out.toString();/* * 處理模板,輸出結(jié)果到文件. 如果文件不存在,將創(chuàng)建文件及路徑上的所有目錄. * * param tpl 相對(duì)于classpath:/tpl的模板文件路徑 * param model 模板數(shù)據(jù) * param file 目標(biāo)文件,不存在是將新建 * param overwrite 目標(biāo)文件存在時(shí)是否覆蓋 * throws TemplateException */public static void process(final String tpl, final Map model, final File file, final boolean overwrite) throws Exception if (file.exists() if (overwrite) FileUtils.deleteQuietly(file); else log.warn(目標(biāo)文件已存在);return;OutputStream out;try out = FileUtils.openOutputStream(file); catch (final IOException e) final String msg = 處理模板失敗-打開目標(biāo)文件失敗;log.error(msg, e);throw new TemplateException(msg, e);final Writer writer = new OutputStreamWriter(new BufferedOutputStream(out, 8192), UTF-8);process(tpl, model, writer);IOUtils.closeQuietly(writer);IOUtils.closeQuietly(out);/* * 處理模板,輸出結(jié)果到writer參數(shù). * * param tpl 相對(duì)于classpath:/tpl的模板文件路徑 * param model 模板數(shù)據(jù) * param writer 輸出目標(biāo) * throws TemplateException */public static void process(final String tpl, final Map model, final Writer writer) throws TemplateException try final Template template = CFG.getTemplate(tpl);template.setEncoding(UTF-8);cess(model, writer); catch (final Exception e) final String msg = 處理模板失敗;log.error(msg, e);throw new TemplateException(msg, e);例如這兩個(gè)文件放在com.zimo.template包下 那么為了方便起見,可以將上面的五個(gè)文件放在com.zimo.template.resources下面,當(dāng)然這里面涉及到模板處理的時(shí)候的,類加載器的問題也可以自己定義存放文件的位置,下面再給出mimetype文件和css文件,contain.xml文件這些可以放在項(xiàng)目根目錄下的resource下面mimetype文件里面的內(nèi)容application/epub+zipcss文件css view plaincopyprint?bodyfont-size:100%;font-family:HiFontSongGB;.coverheight:100%;.smy-smfont-size:2.7500em;font-family:HiFontHeiGB;margin-top:1.5em;margin-bottom:1.5em;text-align:center;font-weight:normal;.smy-sm1font-size:2.7500em;font-family:HiFontHeiGB;margin-top:1em;margin-bottom:0em;text-align:center;font-weight:normal;.smy-fsmfont-size:2.0000em;font-family:HiFontHeiGB;margin-bottom:2em;margin-top:0em;text-align:center;font-weight:normal;.smy-fsm1font-size:2.0000em;font-family:HiFontHeiGB;margin-bottom:0.5em;margin-top:0.5em;text-align:center;font-weight:normal;.smy-zzfont-size:1.8750em;font-family:HiFontHeiGB;margin-top:1em;margin-bottom:0em;text-align:center;font-weight:normal;.smy-zz1font-size:1.8750em;font-family:HiFontHeiGB;margin-top:0em;margin-bottom:0em;text-align:center;font-weight:normal;.smy-cbsfont-size:1.7500em;font-family:HiFontHeiGB;margin-top:4em;text-align:center;font-weight:normal;.smy-cbs1font-size:1.7500em;font-family:HiFontHeiGB;margin-top:3em;text-align:center;font-weight:normal;.smy-qtfont-size:1.7500em;font-family:HiFontHeiGB;text-align:center;font-weight:normal;.bq-smfont-size:1.3750em;line-height:1.6000em;font-family:HiFontHeiGB;margin-top:2em;font-weight:normal;.bqfont-size:1.2500em;line-height:1.6000em;font-family:HiFontSongGB;.ml-btfont-size:2.1875em;font-family:HiFontHeiGB;margin-bottom:1em;margin-top:1em;text-align:center;font-weight:normal;.ml-1font-size:1.5000em;margin-left:0em;font-family:HiFontSongGB;line-height:1.6000em;text-align:justify;.ml-2font-size:1.3750em;margin-left:2em;font-family:HiFontSongGB;line-height:1.6000em;text-align:justify;.ml-3font-size:1.2500em;margin-left:4em;font-family:HiFontSongGB;line-height:1.6000em;text-align:justify;.ml-4font-size:1.2500em;margin-left:6em;font-family:HiFontSongGB;line-height:1.6000em;text-align:justify;h1font-size:1.5000em;font-family:HiFontHeiGB;margin-bottom:1em;margin-top:1em;text-align:center;font-weight:normal;h2font-size:1.3750em;font-family:HiFontHeiGB;font-weight:normal;margin-bottom:1em;margin-top:1em;h3font-size:1.2500em;font-family:HiFontHeiGB;font-weight:normal;margin-top:1em;margin-bottom:1em;h4font-size:1.2500em;font-family:HiFontHeiGB;font-weight:normal;margin-top:1em;margin-bottom:0em;h5font-size:1.2500em;font-family:HiFontHeiGB;font-weight:normal;ma

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論