KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > webservices > adminapi > sdk > MemberEntry


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * MemberEntry.java
20  *
21  * Created on January 17, 2006, 12:44 PM
22  */

23
24 package org.apache.roller.webservices.adminapi.sdk;
25
26 import java.io.InputStream JavaDoc;
27 import java.io.IOException JavaDoc;
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 /**
37  * This class describes a member entry.
38  * A member entry is a triple consisting of a user name, a weblog handle,
39  * and a permission.
40  */

41 public class MemberEntry extends Entry {
42     /** Member permissions */
43     public interface Permissions {
44         public static final String JavaDoc ADMIN = "ADMIN";
45         public static final String JavaDoc AUTHOR = "AUTHOR";
46         public static final String JavaDoc LIMITED = "LIMITED";
47     }
48     
49     static interface Tags {
50         public static final String JavaDoc MEMBER = "member";
51         public static final String JavaDoc NAME = "name";
52         public static final String JavaDoc HANDLE = "handle";
53         public static final String JavaDoc PERMISSION = "permission";
54     }
55     
56     private String JavaDoc name;
57     private String JavaDoc handle;
58     private String JavaDoc permission;
59     
60     public MemberEntry(Element e, String JavaDoc urlPrefix) throws MissingElementException {
61         populate(e, urlPrefix);
62     }
63     
64     public MemberEntry(String JavaDoc handle, String JavaDoc userName, String JavaDoc urlPrefix) {
65         String JavaDoc href = urlPrefix + "/" + EntrySet.Types.MEMBERS + "/" + handle + "/" + userName;
66     setHref(href);
67         setHandle(handle);
68         setName(userName);
69     }
70
71     public MemberEntry(InputStream JavaDoc stream, String JavaDoc urlPrefix) throws JDOMException, IOException JavaDoc, 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 JavaDoc urlPrefix) throws MissingElementException {
80         // name
81
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         // handle
88
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         // href
95
setHref(urlPrefix + "/" + EntrySet.Types.MEMBERS + "/" + getHandle() + "/" + getName());
96         
97         // password
98
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 JavaDoc 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         // href
115
member.setAttribute(Attributes.HREF, getHref());
116                
117         // name
118
Element name = new Element(Tags.NAME, Service.NAMESPACE);
119         Text nameText = new Text(getName());
120         name.addContent(nameText);
121         member.addContent(name);
122        
123         // handle
124
Element handle = new Element(Tags.HANDLE, NAMESPACE);
125         Text handleText = new Text(getHandle());
126         handle.addContent(handleText);
127         member.addContent(handle);
128         
129         // permission
130
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 JavaDoc 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 JavaDoc getName() {
160         return name;
161     }
162
163     public void setName(String JavaDoc name) {
164         this.name = name;
165     }
166
167     public String JavaDoc getHandle() {
168         return handle;
169     }
170
171     public void setHandle(String JavaDoc handle) {
172         this.handle = handle;
173     }
174
175     public String JavaDoc getPermission() {
176         return permission;
177     }
178     
179     public void setPermission(String JavaDoc permission) {
180         this.permission = permission;
181     }
182 }
183
Popular Tags