01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * WeblogEntrySet.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.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: /**
38: * This class describes a set of weblog entries.
39: * @author jtb
40: */
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)
51: throws UnexpectedRootElementException {
52: populate(d, urlPrefix);
53: }
54:
55: public WeblogEntrySet(InputStream stream, String urlPrefix)
56: throws JDOMException, IOException,
57: 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)
65: throws UnexpectedRootElementException {
66: Element root = d.getRootElement();
67: String rootName = root.getName();
68: if (!rootName.equals(Tags.WEBLOGS)) {
69: throw new UnexpectedRootElementException(
70: "ERROR: Unexpected root element", Tags.WEBLOGS,
71: rootName);
72: }
73: List weblogs = root.getChildren(WeblogEntry.Tags.WEBLOG,
74: Service.NAMESPACE);
75: if (weblogs != null) {
76: List entries = new ArrayList();
77: for (Iterator i = weblogs.iterator(); i.hasNext();) {
78: Element weblog = (Element) i.next();
79: WeblogEntry entry = new WeblogEntry(weblog, urlPrefix);
80: entries.add(entry);
81: }
82: setEntries((Entry[]) entries.toArray(new Entry[0]));
83: }
84: setHref(urlPrefix + "/" + Types.WEBLOGS);
85: }
86:
87: public String getType() {
88: return Types.WEBLOGS;
89: }
90: }
|