1 18 23 24 package org.apache.roller.webservices.adminapi.sdk; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import org.jdom.Document; 32 import org.jdom.Element; 33 import org.jdom.JDOMException; 34 import org.jdom.input.SAXBuilder; 35 import org.apache.roller.webservices.adminapi.sdk.EntrySet.Types; 36 37 41 public class UserEntrySet extends EntrySet { 42 43 private static interface Tags { 44 public static final String USERS = "users"; 45 } 46 47 48 public UserEntrySet(String urlPrefix) { 49 setHref(urlPrefix + "/" + Types.USERS); 50 } 51 52 53 public UserEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 54 populate(d, urlPrefix); 55 } 56 57 public UserEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException , MissingElementException, UnexpectedRootElementException { 58 SAXBuilder sb = new SAXBuilder(); 59 Document d = sb.build(stream); 60 61 populate(d, urlPrefix); 62 } 63 64 private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 65 Element root = d.getRootElement(); 66 String rootName = root.getName(); 67 if (!rootName.equals(Tags.USERS)) { 68 throw new UnexpectedRootElementException("ERROR: Unexpected root element", Tags.USERS, rootName); 69 } 70 List users = root.getChildren(UserEntry.Tags.USER, NAMESPACE); 71 if (users != null) { 72 List entries = new ArrayList (); 73 for (Iterator i = users.iterator(); i.hasNext(); ) { 74 Element user = (Element)i.next(); 75 UserEntry entry = new UserEntry(user, urlPrefix); 76 entries.add(entry); 77 } 78 setEntries((Entry[])entries.toArray(new Entry[0])); 79 } 80 setHref(urlPrefix + "/" + Types.USERS); 81 } 82 83 public String getType() { 84 return Types.USERS; 85 } 86 } 87 | Popular Tags |