1 18 23 24 package org.apache.roller.webservices.adminapi.sdk; 25 26 import java.io.InputStream ; 27 import java.io.IOException ; 28 import org.jdom.Document; 29 import org.jdom.Element; 30 import org.jdom.Text; 31 import org.jdom.input.SAXBuilder; 32 import org.jdom.JDOMException; 33 import org.apache.roller.webservices.adminapi.sdk.Entry.Attributes; 34 import org.apache.roller.webservices.adminapi.sdk.Entry.Types; 35 36 41 public class MemberEntry extends Entry { 42 43 public interface Permissions { 44 public static final String ADMIN = "ADMIN"; 45 public static final String AUTHOR = "AUTHOR"; 46 public static final String LIMITED = "LIMITED"; 47 } 48 49 static interface Tags { 50 public static final String MEMBER = "member"; 51 public static final String NAME = "name"; 52 public static final String HANDLE = "handle"; 53 public static final String PERMISSION = "permission"; 54 } 55 56 private String name; 57 private String handle; 58 private String permission; 59 60 public MemberEntry(Element e, String urlPrefix) throws MissingElementException { 61 populate(e, urlPrefix); 62 } 63 64 public MemberEntry(String handle, String userName, String urlPrefix) { 65 String href = urlPrefix + "/" + EntrySet.Types.MEMBERS + "/" + handle + "/" + userName; 66 setHref(href); 67 setHandle(handle); 68 setName(userName); 69 } 70 71 public MemberEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException , MissingElementException { 72 SAXBuilder sb = new SAXBuilder(); 73 Document d = sb.build(stream); 74 Element e = d.detachRootElement(); 75 76 populate(e, urlPrefix); 77 } 78 79 private void populate(Element e, String urlPrefix) throws MissingElementException { 80 Element nameElement = e.getChild(Tags.NAME, NAMESPACE); 82 if (nameElement == null) { 83 throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.NAME); 84 } 85 setName(nameElement.getText()); 86 87 Element handleElement = e.getChild(Tags.HANDLE, NAMESPACE); 89 if (handleElement == null) { 90 throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.HANDLE); 91 } 92 setHandle(handleElement.getText()); 93 94 setHref(urlPrefix + "/" + EntrySet.Types.MEMBERS + "/" + getHandle() + "/" + getName()); 96 97 Element permissionElement = e.getChild(Tags.PERMISSION, NAMESPACE); 99 if (permissionElement == null) { 100 throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.PERMISSION); 101 } 102 setPermission(permissionElement.getText()); 103 } 104 105 106 public String getType() { 107 return Types.MEMBER; 108 } 109 110 public Document toDocument() { 111 Element member = new Element(Tags.MEMBER, NAMESPACE); 112 Document doc = new Document(member); 113 114 member.setAttribute(Attributes.HREF, getHref()); 116 117 Element name = new Element(Tags.NAME, Service.NAMESPACE); 119 Text nameText = new Text(getName()); 120 name.addContent(nameText); 121 member.addContent(name); 122 123 Element handle = new Element(Tags.HANDLE, NAMESPACE); 125 Text handleText = new Text(getHandle()); 126 handle.addContent(handleText); 127 member.addContent(handle); 128 129 Element permission = new Element(Tags.PERMISSION, NAMESPACE); 131 Text permissionText = new Text(getPermission()); 132 permission.addContent(permissionText); 133 member.addContent(permission); 134 135 return doc; 136 } 137 138 public boolean equals(Object o) { 139 if ( o == null || o.getClass() != this.getClass()) { 140 return false; 141 } 142 143 MemberEntry other = (MemberEntry)o; 144 145 if (!areEqual(getHandle(), other.getHandle())) { 146 return false; 147 } 148 if (!areEqual(getName(), other.getName())) { 149 return false; 150 } 151 if (!areEqual(getPermission(), other.getPermission())) { 152 return false; 153 } 154 155 return super.equals(o); 156 } 157 158 159 public String getName() { 160 return name; 161 } 162 163 public void setName(String name) { 164 this.name = name; 165 } 166 167 public String getHandle() { 168 return handle; 169 } 170 171 public void setHandle(String handle) { 172 this.handle = handle; 173 } 174 175 public String getPermission() { 176 return permission; 177 } 178 179 public void setPermission(String permission) { 180 this.permission = permission; 181 } 182 } 183 | Popular Tags |