From 9cfba09e2f19ae987032108baeaf72428378a727 Mon Sep 17 00:00:00 2001 From: Can Bican Date: Sun, 28 Jun 2015 21:10:06 +0300 Subject: [PATCH] term for taxonomies added & options implemented --- src/net/bican/wordpress/Option.java | 79 +++++ src/net/bican/wordpress/Term.java | 159 +++++++++ src/net/bican/wordpress/TermFilter.java | 105 ++++++ src/net/bican/wordpress/Wordpress.java | 319 +++++++++++------- src/net/bican/wordpress/XmlRpcMapped.java | 7 +- .../bican/wordpress/test/CategoryTest.java | 3 +- .../net/bican/wordpress/test/OptionsTest.java | 81 +++++ .../bican/wordpress/test/TaxonomyTest.java | 76 +++++ 8 files changed, 699 insertions(+), 130 deletions(-) create mode 100644 src/net/bican/wordpress/Option.java create mode 100644 src/net/bican/wordpress/Term.java create mode 100644 src/net/bican/wordpress/TermFilter.java create mode 100644 test/net/bican/wordpress/test/OptionsTest.java diff --git a/src/net/bican/wordpress/Option.java b/src/net/bican/wordpress/Option.java new file mode 100644 index 0000000..a5e3f0e --- /dev/null +++ b/src/net/bican/wordpress/Option.java @@ -0,0 +1,79 @@ +package net.bican.wordpress; + +/** + * Option object for a blog. + * + * @author Can Bican <can@bican.net> + */ +public class Option extends XmlRpcMapped implements StringHeader { + String name; + String desc; + String value; + Boolean readonly; + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @param name + * name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the description + */ + public String getDesc() { + return this.desc; + } + + /** + * @return the value + */ + public String getValue() { + return this.value; + } + + /** + * @return read-only status + */ + public Boolean isReadonly() { + return this.readonly; + } + + /** + * @param desc + * description to set + */ + public void setDesc(String desc) { + this.desc = desc; + } + + /** + * @param readonly + * read-only status to set + */ + public void setReadonly(Boolean readonly) { + this.readonly = readonly; + } + + /** + * @param value + * value to set + */ + public void setValue(String value) { + this.value = value; + } + + @Override + public String getStringHeader() { + return ""; //$NON-NLS-1$ + } + +} diff --git a/src/net/bican/wordpress/Term.java b/src/net/bican/wordpress/Term.java new file mode 100644 index 0000000..f1b3952 --- /dev/null +++ b/src/net/bican/wordpress/Term.java @@ -0,0 +1,159 @@ +package net.bican.wordpress; + +/** + * Term object for a blog. + * + * @author Can Bican <can@bican.net> + */ +public class Term extends XmlRpcMapped implements StringHeader { + Integer term_id; + String name; + String slug; + String term_group; + String term_taxonomy_id; + String taxonomy; + String description; + Integer parent; + Integer count; + + /** + * @return the term id + */ + public Integer getTerm_id() { + return this.term_id; + } + + /** + * @param term_id + * term id to set + */ + public void setTerm_id(Integer term_id) { + this.term_id = term_id; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * @param name + * name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the slug + */ + public String getSlug() { + return this.slug; + } + + /** + * @param slug + * slug to set + */ + public void setSlug(String slug) { + this.slug = slug; + } + + /** + * @return the term group + */ + public String getTerm_group() { + return this.term_group; + } + + /** + * @param term_group + * term group to set + */ + public void setTerm_group(String term_group) { + this.term_group = term_group; + } + + /** + * @return the taxonomy id + */ + public String getTerm_taxonomy_id() { + return this.term_taxonomy_id; + } + + /** + * @param term_taxonomy_id + * taxonomy id to set + */ + public void setTerm_taxonomy_id(String term_taxonomy_id) { + this.term_taxonomy_id = term_taxonomy_id; + } + + /** + * @return the taxonomy + */ + public String getTaxonomy() { + return this.taxonomy; + } + + /** + * @param taxonomy + * taxonomy to set + */ + public void setTaxonomy(String taxonomy) { + this.taxonomy = taxonomy; + } + + /** + * @return the description + */ + public String getDescription() { + return this.description; + } + + /** + * @param description + * description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the parent + */ + public Integer getParent() { + return this.parent; + } + + /** + * @param parent + * parent to set + */ + public void setParent(Integer parent) { + this.parent = parent; + } + + /** + * @return the count + */ + public Integer getCount() { + return this.count; + } + + /** + * @param count + * count to set + */ + public void setCount(Integer count) { + this.count = count; + } + + @Override + public String getStringHeader() { + return ""; //$NON-NLS-1$ + } + +} diff --git a/src/net/bican/wordpress/TermFilter.java b/src/net/bican/wordpress/TermFilter.java new file mode 100644 index 0000000..0c1167a --- /dev/null +++ b/src/net/bican/wordpress/TermFilter.java @@ -0,0 +1,105 @@ +package net.bican.wordpress; + +/** + * Object for filtering terms during search + * + * @author Can Bican <can@bican.net> + */ +public class TermFilter extends XmlRpcMapped { + Integer number; + Integer offset; + String orderby; + String order; + boolean hide_empty; + String search; + + /** + * @return the number + */ + public Integer getNumber() { + return this.number; + } + + /** + * @param number + * number to set + */ + public void setNumber(Integer number) { + this.number = number; + } + + /** + * @return the offset + */ + public Integer getOffset() { + return this.offset; + } + + /** + * @param offset + * offset to set + */ + public void setOffset(Integer offset) { + this.offset = offset; + } + + /** + * @return the order-by + */ + public String getOrderby() { + return this.orderby; + } + + /** + * @param orderby + * order-by to set + */ + public void setOrderby(String orderby) { + this.orderby = orderby; + } + + /** + * @return the order + */ + public String getOrder() { + return this.order; + } + + /** + * @param order + * order to set + */ + public void setOrder(String order) { + this.order = order; + } + + /** + * @return the hide-empty status + */ + public boolean isHide_empty() { + return this.hide_empty; + } + + /** + * @param hide_empty + * hide-empty status to set + */ + public void setHide_empty(boolean hide_empty) { + this.hide_empty = hide_empty; + } + + /** + * @return the search terms + */ + public String getSearch() { + return this.search; + } + + /** + * @param search + * search terms to set + */ + public void setSearch(String search) { + this.search = search; + } +} diff --git a/src/net/bican/wordpress/Wordpress.java b/src/net/bican/wordpress/Wordpress.java index c0b67d8..6f65f7d 100644 --- a/src/net/bican/wordpress/Wordpress.java +++ b/src/net/bican/wordpress/Wordpress.java @@ -1014,10 +1014,193 @@ public List getTaxonomies() { XmlRpcArray r = this.wp.getTaxonomies(0, this.username, this.password); return fillFromXmlRpcArray(r, Taxonomy.class, new Taxonomy()); } + + /** + * @param taxonomy + * taxonomy to get + * @return the taxonomy + */ + @SuppressWarnings("boxing") + public Taxonomy getTaxonomy(String taxonomy) { + XmlRpcStruct r = this.wp.getTaxonomy(0, this.username, this.password, + taxonomy); + Taxonomy t = new Taxonomy(); + t.fromXmlRpcStruct(r); + return t; + } + + /** + * @param taxonomy + * taxonomy name + * @return the list of terms + */ + public List getTerms(String taxonomy) { + return this.getTerms(taxonomy, null); + } + + /** + * @param taxonomy + * taxonomy name + * @param filter + * term filter + * @return the list of terms + */ + @SuppressWarnings("boxing") + public List getTerms(String taxonomy, TermFilter filter) { + XmlRpcArray r = (filter != null) ? this.wp.getTerms(0, this.username, + this.password, taxonomy, filter.toXmlRpcStruct()) : this.wp.getTerms(0, + this.username, this.password, taxonomy); + return fillFromXmlRpcArray(r, Term.class, new Term()); + } + + /** + * @param taxonomy + * taxonomy name + * @param termId + * term id + * @return the term + */ + @SuppressWarnings("boxing") + public Term getTerm(String taxonomy, Integer termId) { + XmlRpcStruct r = this.wp.getTerm(0, this.username, this.password, taxonomy, + termId); + Term t = new Term(); + t.fromXmlRpcStruct(r); + return t; + } + + /** + * @param term + * new term + * @return the term id + */ + @SuppressWarnings("boxing") + public Integer newTerm(Term term) { + String r = this.wp.newTerm(0, this.username, this.password, + term.toXmlRpcStruct()); + return Integer.valueOf(r); + } + + /** + * @param taxonomy + * taxonomy name + * @param termId + * term id + * @return result of the operation + */ + @SuppressWarnings("boxing") + public boolean deleteTerm(String taxonomy, Integer termId) { + Boolean r = this.wp.deleteTerm(0, this.username, this.password, taxonomy, + termId); + return r.booleanValue(); + } + + /** + * @param termId + * term id + * @param content + * new contents + * @return the result of the operation + */ + @SuppressWarnings({ "unchecked", "boxing" }) + public boolean editTerm(Integer termId, Term content) { + XmlRpcStruct datar = new XmlRpcStruct(); + datar.put("taxonomy", content.getTaxonomy()); //$NON-NLS-1$ + if (content.getName() != null) + datar.put("name", content.getName()); //$NON-NLS-1$ + if (content.getSlug() != null) + datar.put("slug", content.getSlug()); //$NON-NLS-1$ + if (content.getDescription() != null) + datar.put("description", content.getDescription()); //$NON-NLS-1$ + if (content.getParent() != null) + datar.put("parent", content.getParent()); //$NON-NLS-1$ + Boolean r = this.wp + .editTerm(0, this.username, this.password, termId, datar); + return r.booleanValue(); + } + + /** + * @return the list of options + */ + public List