在載入文件規格之後,您可以反覆使用範本,以及每一個範本的資料來源。範本的資料來源可在 RPETemplate.getDataSources() 集合中找到。在識別資料來源之後,您可以視需要修改資料來源的內容。
範例顯示如何修改名稱為 "DS1" 之資料來源的 URI。會在文件規格中的所有範本內搜尋資料來源。如果您想限制搜尋,您必須驗證範本的路徑內容。
for (RPETemplate template : docspec.getRuntime().getTemplates())
{
String templatePath = PropertyUtils.getPropertyRawValue( template.getProperty(RPEConfigConstants.PROPERTY_PATH), "");
for ( RPEDataSource ds : template.getDataSources())
{
String dsName = PropertyUtils.getPropertyRawValue( ds.getProperty(RPEConfigConstants.PROPERTY_NAME), "");
if ( dsName.equals("DS1"))
{
Property dsURI = ds.getProperty(RPEConfigConstants.PROPERTY_URI);
assert( dsURI != null);
dsURI.setValue( new Value( null, "c:\\test\\sample.xml"));
}
}
註: 當您將範本新增至文件規格時,您也可以配置該範本中的資料來源。