用于返回数据以填充 Microsoft Word 通信的样本代码

以下样本代码片段说明如何编写代码来将值构建到 BLOB 对象中并返回该对象,以便将这些值插入 Microsoft Word 文档。请注意,使用 org.jdom.Element 以名称/值对的格式来插入值。

名称/值对中的 NAME 属性是模板中插入的 DocProperty 的名称。VALUE 属性是将替换所创建 Microsoft Word 通信中字段的特定于通信方的数据。

图 1. 用于返回数据以填充 Microsoft Word 通信的样本代码
    org.jdom.Element rootElement = new org.jdom.Element("ROOT");
    org.jdom.Element fieldsElement = new org.jdom.Element ("FIELDS");
    
    org.jdom.Element fieldElement = new org.jdom.Element ("FIELD");
    fieldElement.setAttribute ("NAME", "personName");
    fieldElement.setAttribute ("VALUE", "James Smith");
    fieldsElement.addContent (fieldElement);
    
    org.jdom.Element fieldElement1 = new org.jdom.Element ("FIELD");
    fieldElement1.setAttribute ("NAME", "AddressLine1");
    fieldElement1.setAttribute ("VALUE", "1074, Park Terrace");
    fieldsElement.addContent (fieldElement1);
    
    org.jdom.Element fieldElement2 = new org.jdom.Element ("FIELD");
    fieldElement2.setAttribute ("NAME", "AddressLine2");
    fieldElement2.setAttribute ("VALUE", "Fairfield, Midway");
    fieldsElement.addContent(fieldElement2);
    
    org.jdom.Element fieldElement3 = new org.jdom.Element ("FIELD");
    fieldElement3.setAttribute ("NAME", "AddressLine3");
    fieldElement3.setAttribute ("VALUE", "UTAH");
    fieldsElement.addContent (fieldElement3);
    
    org.jdom.Element fieldElement4 = new org.jdom.Element ("FIELD");
    fieldElement4.setAttribute ("NAME", "userName");
    fieldElement4.setAttribute ("VALUE", "Caseworker");
    fieldsElement.addContent (fieldElement4);
    
    rootElement.addContent (fieldsElement);
    
    return new curam.util.type.Blob (
    new org.jdom.output.XMLOutputter
    .outputString(rootElement).getBytes());

有关如何编写服务器代码的更多信息,请参阅《Cúram 服务器开发者指南》。