|
| 1 | +package com.hmkcode.vo; |
| 2 | + |
| 3 | +import java.util.LinkedList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import com.thoughtworks.xstream.annotations.XStreamAlias; |
| 7 | +import com.thoughtworks.xstream.annotations.XStreamAsAttribute; |
| 8 | +import com.thoughtworks.xstream.annotations.XStreamConverter; |
| 9 | +import com.thoughtworks.xstream.annotations.XStreamImplicit; |
| 10 | +import com.thoughtworks.xstream.annotations.XStreamOmitField; |
| 11 | +import com.thoughtworks.xstream.converters.basic.BooleanConverter; |
| 12 | + |
| 13 | +@XStreamAlias("article") |
| 14 | +public class Article { |
| 15 | + |
| 16 | + @XStreamAsAttribute |
| 17 | + private String title; |
| 18 | + |
| 19 | + @XStreamAlias("address") |
| 20 | + private String url; |
| 21 | + |
| 22 | + @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"}) |
| 23 | + private boolean published; |
| 24 | + |
| 25 | + @XStreamOmitField |
| 26 | + private List<String> categories; |
| 27 | + |
| 28 | + @XStreamImplicit(itemFieldName="tag") |
| 29 | + private List<String> tags; |
| 30 | + |
| 31 | + public String getTitle() { |
| 32 | + return title; |
| 33 | + } |
| 34 | + public void setTitle(String title) { |
| 35 | + this.title = title; |
| 36 | + } |
| 37 | + public String getUrl() { |
| 38 | + return url; |
| 39 | + } |
| 40 | + public void setUrl(String url) { |
| 41 | + this.url = url; |
| 42 | + } |
| 43 | + |
| 44 | + public boolean isPublished() { |
| 45 | + return published; |
| 46 | + } |
| 47 | + public void setPublished(boolean published) { |
| 48 | + this.published = published; |
| 49 | + } |
| 50 | + public List<String> getCategories() { |
| 51 | + return categories; |
| 52 | + } |
| 53 | + public void setCategories(List<String> categories) { |
| 54 | + this.categories = categories; |
| 55 | + } |
| 56 | + public List<String> getTags() { |
| 57 | + return tags; |
| 58 | + } |
| 59 | + public void setTags(List<String> tags) { |
| 60 | + this.tags = tags; |
| 61 | + } |
| 62 | + |
| 63 | + public void addCategory(String category){ |
| 64 | + if(this.categories == null) |
| 65 | + this.categories = new LinkedList<String>(); |
| 66 | + this.categories.add(category); |
| 67 | + } |
| 68 | + public void addTag(String tag){ |
| 69 | + if(this.tags == null) |
| 70 | + this.tags = new LinkedList<String>(); |
| 71 | + |
| 72 | + this.tags.add(tag); |
| 73 | + } |
| 74 | + @Override |
| 75 | + public String toString() { |
| 76 | + return "Article [title=" + title + ",\nurl=" + url + ",\npublished=" |
| 77 | + + published + ",\ncategories=" + categories + ",\ntags=" + tags |
| 78 | + + "]"; |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +} |
0 commit comments