您的位置:首页 > 运维架构 > Linux

Linux下使用mail命令发送邮件

2013-09-18 16:28 519 查看
在做使用XSL+XML生成HTML时遇到一个问题,网上搜索到的代码大多以读一个文件路径的方式读取xsl文件(来源:http://www.blogjava.net/yangxiang/archive/2009/08/11/290688.html),
Source xslSource = new StreamSource(xslFileName);

但是我最终是要把方法wrap成一个custom component,xsl是通过一个Document变量传进来,于是尝试采用如下方法读xsl文件:
Source xslSource = new DOMSource(xslDoc);

执行没有出错,但是生成的html没有包含xml里面数据,总之结果不正确。于是想办法把Document转换成一个stream后按Source xslSource = new StreamSource(xslFileName);同样方法读取Source。

以下是将Document转换成ByteArrayInputStream的方法:

public static ByteArrayInputStream ConvertDoc2Stream(org.w3c.dom.Document myDoc){
ByteArrayInputStream byteStream = null;
try{
TransformerFactory transFactory=TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty("indent", "yes");

DOMSource source = new DOMSource();
source.setNode(myDoc);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamResult result = new StreamResult();
result.setOutputStream(outputStream);
transformer.transform(source, result);
byteStream = new ByteArrayInputStream(outputStream.toByteArray());
}catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return byteStream;
}

本文出自 “有用技术整理” 博客,请务必保留此出处http://positiverock.blog.51cto.com/8640784/1638220
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: