我下面的代码在 Tridion 2009 中运行良好,最近我们迁移到 Tridion 2011,下面是用 java 编写的代码。
获取文件: ExtensionsConfiguration.java
package com.tridion.custom.extensions;
import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.configuration.XMLConfigurationReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExtensionsConfiguration
{
private static Logger logger = LoggerFactory.getLogger(ExtensionsConfiguration.class);
private static Configuration configuration;
public static Configuration getInstance()
{
if (configuration == null)
try
{
XMLConfigurationReader localXMLConfigurationReader = new XMLConfigurationReader();
configuration = localXMLConfigurationReader.readConfiguration("cd_deployer_ext.xml");
logger.info("ExtensionsConfiguration.getInstance:File Read",configuration.getContent());
}
catch (ConfigurationException localConfigurationException)
{
logger.error("ExtensionsConfiguration.ConfigurationException: Unable to read configuration.", localConfigurationException);
}
catch (Exception ex)
{
logger.error("ExtensionsConfiguration.Exception: Unable to read configuration.", ex.getStackTrace());
}
return configuration;
}
}
在上面的代码中,我试图读取放置在 %TRIDION_HOME%/config 中的“cd_deployer_ext.xml”,上面的代码在 2009 年运行良好。
cd_deployer_ext.xml 的样本格式
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<DeployerCustomization Enable="true" Extension=".aspx" FilePath="F:\WWW\GoogleDataFiles\"></DeployerCustomization>
</Configuration>
这是我尝试从该文件中读取值的方式
读取值: PageDeployer.java 下面是我用来从 ExtensionsConfiguration.java 读取值的示例代码
Configuration configData = ExtensionsConfiguration.getInstance();
String extensionFromFile = ConfigurationHelper.getStringValue(configData,"Configuration/DeployerCustomization/Extension", null);
现在 extensionFromFile 应该给我“.aspx”。
请推荐!!
谢谢。