情况是这样的,我这样定义一个工件类型:
<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>
同时我还定义了一个handler,mediaType为“application/vnd.wso2-tets+xml”,handler代码如下:
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 添加一个 Artifact 时,例如:
在上面的代码中,我可以获得名称、版本和描述的属性值。但我无法获得 Zcos 的属性值。在 Artifact 的定义中,字段类型的 Zos 是 options ,字段类型的其他属性是 text 或 text-area。为什么我无法获取 Zcos 属性值?提前致谢!