自定义翻译创建挂接
使用翻译创建挂接自定义为翻译包创建的翻译对象的常规属性。翻译创建挂接受 wt.properties 文件中的 xconf 属性 com.ptc.tml.preparation.CustomTranslationCreationHook 控制。
自定义翻译创建挂接的步骤如下:
1. 开发 java 代码 - 创建延伸抽象类的 java 类 com.ptc.tml.preparation.CustomTranslationCreationHook 并实现每个业务需求的预期行为。
2. 注册自定义 - 在包含特性相应值的 <自定义根目录>/configurations/xconf/ custom.site.xconf 位置处创建自定义 xconf 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration
SYSTEM "xconf.dtd">
<Configuration xmlns:xlink="http://www.w3.org/1999/xlink">
<Property name="com.ptc.tml.preparation.CustomTranslationCreationHook"
overridable="true"
targetFile="codebase/wt.properties"
value=<"className>"/>
</Configuration>
属性值应为在步骤 1 中所实现类的名称。
以下为示例代码,该代码将前缀 "PTC" 添加到翻译文档的“翻译编号”属性中。
package com.ptc.tml.preparation.sample;
import java.util.List;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import com.ptc.tml.preparation.CustomTranslationCreationHook;
/** Example implementation of CustomTranslationCreationHook that customizes translation objects by prepending "PTC"
* to each translation object's Number. This is enabled by adding
* 'com.ptc.tml.preparation.CustomTranslationCreationHook=com.ptc.tml.preparation.sample.PrefixCustomTranslationObjectCreationHook'
* to wt.properties. */
public class PrefixCustomTranslationObjectCreationHook extends CustomTranslationCreationHook {
@Override
protected void customize(List<EPMDocumentCopyInfo> documentCopies) throws WTException, WTPropertyVetoException {
for (EPMDocumentCopyInfo info : documentCopies) {
final String initialNumber = info.getTarget().getNumber();
info.getTarget().setNumber("PTC" + initialNumber);
}
}
}