【发布时间】:2012-11-12 01:56:00
【问题描述】:
我在查看代理数据库中的动态内容时遇到字符编码问题。
我有一个 scriptlet,它调用代理数据库以生成 XML 字符串,然后由 XSL 解析。
在调试这个问题时我已经剥离了我的代码,脚本现在看起来像:
.....
strOutput= "<xml>";
ComponentPresentationFactory cpf = new ComponentPresentationFactory(PublicationID);
for (int i =0; i < itemURIs.length; i++)
{
ComponentPresentation cp = cpf.getComponentPresentation(itemURIs[i], strComponentTemplateURI);
if(cp != null){
String content = "";
content = cp.getContent();
strOutput += content;
}
}
strOutput+= "</xml>";
......
当我手动覆盖此代码并在代码中手动设置 xml 字符串内容时,数据会正确显示在屏幕上,即:
.....
strOutput= "<xml>";
ComponentPresentationFactory cpf = new ComponentPresentationFactory(PublicationID);
for (int i =0; i < itemURIs.length; i++)
{
ComponentPresentation cp = cpf.getComponentPresentation(itemURIs[i], strComponentTemplateURI);
if(cp != null){
String content = "<xml><dynamicContent><subtitle><![CDATA[Außenbeleuchtung]]></subtitle></dynamicContent></xml>";
strOutput += content;
}
}
strOutput+= "</xml>";
......
使用输出格式设置为“XML 格式”的 CT 将组件发布到内容代理数据库。
发布目标设置为目标语言:JSP 和默认代码页:Unicode UTF-8
当我使用此 CT 预览内容时,数据显示正确:
<dynamicContent>
<tcm_id>tcm:345-23288</tcm_id>
<title><![CDATA[LED Road R250 - Maximum LED performance for street and highway illumination]]></title>
<subtitle><![CDATA[Außenbeleuchtung ]]></summary>
</dynamicContent>
通过模板生成器进行预览时也是如此。
Broker DB 是一个 Oracle DB(Oracle 数据库 11g 企业版版本 11.2.0.2.0),我检查了字符集
SQL> select * from v$nls_parameters where parameter like '%CHARACTERSET%';
PARAMETER VALUE
NLS_CHARACTERSET UTF8
NLS_NCHAR_CHARACTERSET UTF8
以前有没有其他人遇到过这样的例子。看起来数据库存储、与数据库的连接或 cp.getContent(); 存在问题方法。
任何帮助将不胜感激,如果您有任何其他问题,请告诉我。
问候, 克里斯
【问题讨论】:
-
从 SQLPlus 中检索到的内容是什么样的?您是否尝试将日志级别设置为调试并检查 getContent 调用中的任何编码问题?您是否尝试过使用 ComponentPresentationAssembler 而不是 ComponentPresentationFactory?
-
您好 Nuno,我通过 Oracle DB 管理器查看了内容,查看时没有编码问题,但这可能是因为查看器正在处理编码。我刚刚使用 ComponentPresentationAssembler 而不是 ComponentPresentationFactory 实现了我的代码,它具有完全相同的最终结果。
标签: tridion tridion-2011 tridion-content-delivery