我怎样才能在治理工件中获得属性值与治理?

时间:2016-04-02 15:35:43

标签: wso2 artifact wso2greg

情况是这样的我定义了这样的工件类型:

<artifactType type="application/vnd.wso2-tets+xml" shortName="test" singularLabel="tests" pluralLabel="tests" hasNamespace="false" iconSet="9">
    <storagePath>/applications/@{name}/@{overview_version}</storagePath>
    <nameAttribute>overview_name</nameAttribute>
    <ui>
        <list>
            <column name="Name">
                <data type="path" value="overview_name" href="/applications/@{name}"/>
            </column>
            <column name="Version">
                <data type="path" value="overview_version" href="@{storagePath}"/>
            </column>
        </list>
    </ui>
    <content>
        <table name="Overview">
            <field type="text" required="true">
                <name>Name</name>
            </field>
            <field type="text" required="true">
                <name>Version</name>
            </field>
            <field type="text-area">
                <name>Description</name>
            </field>
            <field type="options">
         <name label="Zcos">Zcos</name>
         <values class="cn.oge.wso2.populator.AlgPopulator"/>
       </field>
        </table>
    </content>
</artifactType>

同时我还定义了一个处理程序,mediaType是&#34; application / vnd.wso2-tets + xml&#34;处理程序代码如下:

public class XcosMediaTypeHandler extends Handler {

    public Resource get(RequestContext requestContext) throws RegistryException {
        return null;
    }

    public void put(RequestContext requestContext) throws RegistryException {
        Resource resource = requestContext.getResource();
        String name = "";
        String version = "";
        String description = "";
        String zcos = "";

        byte[] content = (byte[]) resource.getContent();
        ByteArrayInputStream in = new ByteArrayInputStream(content);
        OMElement docElement = null;
        try {
            StAXOMBuilder builder = new StAXOMBuilder(in);
            docElement = builder.getDocumentElement();
        } catch (Exception ae) {
            throw new RegistryException(
                    "Failed to parse the propject proposal. "
                            + "All project proposals should be in XML format.");
        }
        System.out.println("==========================================");
        OMElement firstElement = docElement.getFirstElement();
        System.out.println(firstElement);
        Iterator<OMElement> ite = firstElement.getChildElements();
        for (OMElement e = ite.next(); ite.hasNext(); e = ite.next()) {
            if (e.getLocalName().equals("name")) {
                name = e.getText();
            } else if (e.getLocalName().equals("version")) {
                version = e.getText();
            } else if (e.getLocalName().equals("description")) {
                description = e.getText();
            } else if (e.getLocalName().equals("zcos")) {
                zcos = e.getText();
            }
        }

        System.out.println("Name:" + name);
        System.out.println("Version:" + version);
        System.out.println("Description:" + description);
        System.out.println("zcos:" + zcos);         
    }

    public void importResource(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importResource");
    }

    public void delete(RequestContext requestContext) throws RegistryException {

    }

    public void putChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("putChild");
    }

    public void importChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importChild");
    }

}

问题来了,当我使用UI添加工件时,例如:   enter image description here

在上面的代码中,我可以获取Name,Version和Description的属性值。但我无法获得Zcos的属性值。在工件的定义中,字段类型的Zos是选项,字段类型的其他属性是文本或文本区域。 为什么我无法获得Zcos的财产价值?提前感谢!

1 个答案:

答案 0 :(得分:0)

为了减少混淆,将文件引用小写如下,

<field type="options">
  <name label="Zcos">zcos</name>
  <values class="cn.oge.wso2.populator.AlgPopulator"/>
</field>

找到下面的代码来获取zcos值,

// Get the first OMElement child with name 'overview'
OMElement elementOverview = getFirstChild(docElement, "overview");
// Get the first OMElement child with name 'zcos' and appending absolute path prefix.
String zcos = getFirstChild(elementOverview, "zcos").getText();

要查找示例代码,请查看this blog post