1 18 23 24 package org.apache.roller.webservices.adminapi.sdk; 25 26 import java.io.InputStream ; 27 import java.io.IOException ; 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 42 public class MemberEntrySet extends EntrySet { 43 static interface Tags { 44 public static final String MEMBERS = "members"; 45 } 46 47 public MemberEntrySet(String urlPrefix) { 48 setHref(urlPrefix + "/" + Types.MEMBERS); 49 } 50 51 public MemberEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 52 populate(d, urlPrefix); 53 } 54 55 public MemberEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException , MissingElementException, UnexpectedRootElementException { 56 SAXBuilder sb = new SAXBuilder(); 57 Document d = sb.build(stream); 58 59 populate(d, urlPrefix); 60 } 61 62 private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 63 Element root = d.getRootElement(); 64 String rootName = root.getName(); 65 if (!rootName.equals(Tags.MEMBERS)) { 66 throw new UnexpectedRootElementException("ERROR: Incorrect root element", Tags.MEMBERS, rootName); 67 } 68 List members = root.getChildren(MemberEntry.Tags.MEMBER, NAMESPACE); 69 if (members != null) { 70 List entries = new ArrayList (); 71 for (Iterator i = members.iterator(); i.hasNext(); ) { 72 Element member = (Element)i.next(); 73 MemberEntry entry = new MemberEntry(member, urlPrefix); 74 entries.add(entry); 75 } 76 setEntries((Entry[])entries.toArray(new Entry[0])); 77 } 78 setHref(urlPrefix + "/" + Types.MEMBERS); 79 } 80 81 public String getType() { 82 return Types.MEMBERS; 83 } 84 } 85 | Popular Tags |