2012-04-10 131 views
2

我需要添加鏈接到我的resteasy api xml和json輸出。 所以我寫了一個JAXB AtomLink類如下HATEOAS鏈接可點擊

package samples; 
import javax.xml.bind.annotation.XmlAttribute; 
import javax.xml.bind.annotation.XmlRootElement; 

@XmlRootElement(name="link", namespace="http://www.w3.org/2005/Atom") 

public class AtomLink { 
    private String rel; 
    private String href; 
    private String type; 

    public AtomLink() {} 

    public AtomLink(String rel, String href, String type) { 
     this.rel = rel; 
     this.href = href; 
     this.type = type; 
    } 

    public AtomLink(String rel, String href) { 
     this(rel,href,"application/xml"); 
    } 

    @XmlAttribute 
    public String getRel() { 
     return rel; 
    } 
    public void setRel(String rel) { 
     this.rel = rel; 
    } 

    @XmlAttribute 
    public String getHref() { 
     return href; 
    } 
    public void setHref(String href) { 
     this.href = href; 
    } 

    @XmlAttribute 
    public String getType() { 
     return type; 
    } 
    public void setType(String type) { 
     this.type = type; 
    } 

} 

,並在我的JAXB XML或JSON對象設置鏈接值。 我得到了如下輸出。但鏈接不可點擊。

輸出:

<data xmlns:ns2="http://www.w3.org/2005/Atom"> 
<bucket id="2" name="2012-APR-09 12:05 AM"> 
<av_data unit="percent" value="100"/> 
<data_count unit="#" value="10"/> 
<pf_data unit="seconds" value="4.618"/> 
</bucket> 
<ns2:link href="http://localhost:8080/webapp/api/getrawdata?start=3&size=2" rel="next" type="application/xml"/> 
</data> 

我應該做的,以使鏈接點擊。

在此先感謝。 Anitha

回答

2

XML和JSON只是基於文本的數據表示。點擊鏈接的能力取決於您使用的瀏覽器來查看數據能力,以將該文本的一部分識別爲鏈接並將其呈現爲超鏈接。

+0

感謝您的回答,我的疑問得到了澄清。 – Anitha 2012-04-11 06:26:13