1 18 package org.apache.roller.webservices.adminapi.sdk; 19 20 import java.io.IOException ; 21 import java.io.StringWriter ; 22 import java.io.Writer ; 23 import java.util.Arrays ; 24 import org.jdom.Document; 25 import org.jdom.Namespace; 26 import org.jdom.output.Format; 27 import org.jdom.output.XMLOutputter; 28 29 33 public abstract class Entry { 34 protected static final Namespace NAMESPACE = Namespace.getNamespace("http://purl.org/apache/roller/aapp#"); 35 36 37 public static interface Types { 38 42 public static final String USER = "user"; 43 47 public static final String WEBLOG = "weblog"; 48 52 public static final String MEMBER = "member"; 53 58 public static final String COLLECTION = "collection"; 59 } 60 61 62 protected static interface Attributes { 63 public static final String HREF = "href"; 64 } 65 66 private String href = null; 67 68 69 public String getHref() { 70 return href; 71 } 72 73 74 public void setHref(String href) { 75 this.href = href; 76 } 77 78 79 public abstract Document toDocument(); 80 81 84 public String toString() { 85 Writer writer = new StringWriter (); 86 XMLOutputter outputter = new XMLOutputter(); 87 outputter.setFormat(Format.getPrettyFormat()); 88 try { 89 outputter.output(toDocument(), writer); 90 writer.close(); 91 } catch (IOException ioe) { 92 throw new IllegalStateException (ioe.getMessage()); 93 } 94 95 return writer.toString(); 96 } 97 98 public abstract String getType(); 99 100 public boolean equals(Object o) { 101 if ( o == null || o.getClass() != this.getClass()) { 102 return false; 103 } 104 105 Entry other = (Entry)o; 106 107 if (!areEqual(getHref(), other.getHref())) { 108 return false; 109 } 110 if (!areEqual(getType(), other.getType())) { 111 return false; 112 } 113 114 return true; 115 } 116 117 protected static boolean areEqual(Object o1, Object o2) { 118 return o1 == null ? o2 == null : o1.equals(o2); 119 } 120 121 protected static boolean areEqual(Object [] oa1, Object [] oa2) { 122 return oa1 == null ? oa2 == null : Arrays.equals(oa1, oa2); 123 } 124 } 125 | Popular Tags |