📄 xhtmldocument.java
字号:
/* CVS ID: $Id: XHTMLDocument.java,v 1.5 2000/12/30 10:39:09 wastl Exp $ */package net.wastl.webmail.ui.xml;import net.wastl.webmail.server.*;import net.wastl.webmail.exceptions.*;import org.w3c.dom.*;import org.xml.sax.SAXException;import org.apache.xalan.xslt.*;import java.io.*;/** * XHTMLDocument.java * * Created: Mon Mar 27 16:05:52 2000 * * Copyright (C) 2000 Sebastian Schaffert * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//** * Constructs HTML-Documents using a Stylesheet and a XML Document. * * @author Sebastian Schaffert * @version */public class XHTMLDocument extends net.wastl.webmail.ui.html.HTMLDocument { public XHTMLDocument(Document xml, String xsl) throws WebMailException { StringWriter writer = new StringWriter(); long start_t=System.currentTimeMillis(); try { XSLTInputSource msg_xml=new XSLTInputSource((Node)xml);// XSLTInputSource msg_xsl=new XSLTInputSource(xsl); XSLTInputSource msg_xsl=new XSLTInputSource("file://"+xsl); XSLTResultTarget msg_result=new XSLTResultTarget(writer); XSLTProcessor processor=XSLTProcessorFactory.getProcessorUsingLiaisonName("org.apache.xalan.xpath.xdom.XercesLiaison"); processor.setDiagnosticsOutput(System.err); processor.process(msg_xml,msg_xsl,msg_result); } catch(SAXException ex) { System.err.println("Error transforming XML with "+xsl+" to XHTML."); //ex.printStackTrace(); WebMailServer.getStorage().log(Storage.LOG_INFO,"Error transforming XML with "+xsl+" to XHTML."); throw new WebMailException(ex.getMessage()); } long end_t=System.currentTimeMillis(); //System.err.println("Transformation XML --> XHTML took "+(end_t-start_t)+" ms."); WebMailServer.getStorage().log(Storage.LOG_DEBUG,"Transformation XML --> XHTML took "+(end_t-start_t)+" ms."); content=writer.toString(); } public XHTMLDocument(Document xml, StylesheetRoot stylesheet) throws WebMailException { StringWriter writer = new StringWriter(); long start_t=System.currentTimeMillis(); try { XSLTInputSource msg_xml=new XSLTInputSource((Node)xml); XSLTResultTarget msg_result=new XSLTResultTarget(writer); stylesheet.process(msg_xml,msg_result); } catch(Exception ex) { System.err.println("Error transforming XML to XHTML."); ex.printStackTrace(); throw new WebMailException(ex.toString()); } long end_t=System.currentTimeMillis(); //System.err.println("Transformation (with precompiled stylesheet) XML --> XHTML took "+(end_t-start_t)+" ms."); WebMailServer.getStorage().log(Storage.LOG_DEBUG,"Transformation (with precompiled stylesheet) XML --> XHTML took "+(end_t-start_t)+" ms."); content=writer.toString(); } public String toString() { return content; } public int length() { return content.length(); } } // XHTMLDocument
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -