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 WeblogEntrySet extends EntrySet { 42 static interface Tags { 43 public static final String WEBLOGS = "weblogs"; 44 } 45 46 public WeblogEntrySet(String urlPrefix) { 47 setHref(urlPrefix + "/" + Types.WEBLOGS); 48 } 49 50 public WeblogEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 51 populate(d, urlPrefix); 52 } 53 54 public WeblogEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException , MissingElementException, UnexpectedRootElementException { 55 SAXBuilder sb = new SAXBuilder(); 56 Document d = sb.build(stream); 57 58 populate(d, urlPrefix); 59 } 60 61 private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException { 62 Element root = d.getRootElement(); 63 String rootName = root.getName(); 64 if (!rootName.equals(Tags.WEBLOGS)) { 65 throw new UnexpectedRootElementException("ERROR: Unexpected root element", Tags.WEBLOGS, rootName); 66 } 67 List weblogs = root.getChildren(WeblogEntry.Tags.WEBLOG, Service.NAMESPACE); 68 if (weblogs != null) { 69 List entries = new ArrayList (); 70 for (Iterator i = weblogs.iterator(); i.hasNext(); ) { 71 Element weblog = (Element)i.next(); 72 WeblogEntry entry = new WeblogEntry(weblog, urlPrefix); 73 entries.add(entry); 74 } 75 setEntries((Entry[])entries.toArray(new Entry[0])); 76 } 77 setHref(urlPrefix + "/" + Types.WEBLOGS); 78 } 79 80 public String getType() { 81 return Types.WEBLOGS; 82 } 83 } 84 | Popular Tags |