3.对较大文本内容的发布
在Bea Repository中,一般的文字内容都被存为String类型,不过String类型是有长度限制的,所以不能存储较长的内容。当然,我们可以把较长的内容先编辑成文件,再以Binary类型存入BEA Repository中进行发布。但是,如果用BEA提供的ShowBinaryServlet来显示这种Binary类型的数据,只能是在一个新打开的页面中显示,而不能在自定义页面中进行显示,这就造成了不能按自己的需要定制内容显示的界面。为解决这个问题,我们在在认真研究ShowBinarySeverlet的基础上,开发了自己的Java代码以读取这种Binary内容并在JSP中予以显示。
//"bContent"为存放文本文件的字段
Property property=node.getProperty("bContent"

;
// 将要用到Property的getPropertyBytes()方法,它必须以transaction的方式来执行
UserTransaction tx;
Context initCtx = new InitialContext();
tx = (UserTransaction)initCtx.lookup("java:comp/UserTransaction"

;
//通过getPropertyBytes()方法把二进制数据变成流文件
tx.begin();
RepositoryManager repositoryManager = RepositoryManagerFactory.connect();
NodeOps nodeOps = repositoryManager.getNodeOps();
InputStream is = null;
is = nodeOps.getPropertyBytes(node.getId(), property.getId());
tx.commit();
//把输入流中的数据读入缓冲区
InputStreamReader isr = new InputStreamReader(is);
StringBuffer buffer = new StringBuffer();
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
is.close();
//把缓冲区的内容转换为字符串,为了支持中文还需作编码方式的转换
String str = buffer.toString();
String newStr = new String(str.getBytes(),"gb2312"

;