XHTMLDocument.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:3k
- /* CVS ID: $Id: XHTMLDocument.java,v 1.3 2000/04/18 13:13:38 wastl Exp $ */
- package net.wastl.webmail.ui.xml;
- import net.wastl.webmail.server.*;
- 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) {
- StringWriter writer = new StringWriter();
- long start_t=System.currentTimeMillis();
- try {
- XSLTInputSource msg_xml=new XSLTInputSource((Node)xml);
- XSLTInputSource msg_xsl=new XSLTInputSource(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.");
- }
- 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) {
- 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();
- }
- 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