2016-04-02 7 views
2

状況は私はこのような案件タイプ定義のようである:私はまた、ハンドラを定義同時にガバナンスのガバナンスでgetAttributeValueをどのように取得できますか?

<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は「+ XMLアプリケーション/ vnd.wso2-TETS」このようなハンドラコードであります:私はたとえば、アーティファクトを追加するためにUIを使用する場合

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"); 
    } 

} 

質問は、来ている: enter image description here

を上記のコードでは、私は名前、バージョン、および説明のための属性値を取得することができます。 Zcosの属性値は取得できません。 Artifactの定義では、ファイル型のZosはオプションです。ファイル型のその他の属性はtextまたはtext-areaです。 Zcosのプロパティ値を取得できない理由はありますか?それほど混乱のため

+0

ハンドラをデバッグできますか? – harsha89

+0

お返事ありがとうございます、私はそれを試してみます – Pourquoi

+0

@pourquoiは以下の回答はあなたを助けましたか?私に何が起こったのか教えてください。 – tkr

答えて

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を見つけてください。

関連する問題