001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.lib.collab.xmpp.jso.impl.x.pubsub;
043:
044: import java.util.*;
045:
046: import org.jabberstudio.jso.NSI;
047: import org.jabberstudio.jso.JID;
048: import org.jabberstudio.jso.StreamElement;
049: import org.jabberstudio.jso.StreamObject;
050: import org.jabberstudio.jso.StreamDataFactory;
051:
052: import net.outer_planes.jso.ElementNode;
053:
054: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.PubSubItems;
055: import org.netbeans.lib.collab.xmpp.jso.iface.x.pubsub.PubSubEvent;
056:
057: /**
058: *
059: */
060: public class PubSubItemsNode extends ElementNode implements PubSubItems {
061:
062: private static final String ATTR_ID = "id";
063: private static final NSI NSI_ID = new NSI(ATTR_ID,
064: PubSubEvent.NAMESPACE);
065: private static final NSI NSI_ITEM = new NSI("item",
066: PubSubEvent.NAMESPACE);
067: private static final NSI NSI_RETRACT = new NSI("retract",
068: PubSubEvent.NAMESPACE);
069:
070: public PubSubItemsNode(StreamDataFactory sdf) {
071: super (sdf, NAME);
072: }
073:
074: public PubSubItemsNode(StreamElement parent, PubSubItemsNode base) {
075: super (parent, base);
076: }
077:
078: public void setNodeIdentifier(String nodeValue)
079: throws IllegalArgumentException {
080: setAttributeValue("node", nodeValue);
081: }
082:
083: public String getNodeIdentifier() {
084: return getAttributeValue("node");
085: }
086:
087: public StreamElement addPubSubItem(String id) {
088: StreamElement elem = createPubSubItem(id);
089: add(elem);
090: return elem;
091: }
092:
093: public StreamElement addPubSubItem(String id, String content) {
094: StreamElement elem = createPubSubItem(id);
095: elem.addText(content);
096: add(elem);
097: return elem;
098: }
099:
100: public StreamElement addPubSubItem(String id, StreamElement el) {
101: StreamElement elem = createPubSubItem(id);
102: elem.add(el);
103: add(elem);
104: return elem;
105: }
106:
107: public void removePubSubItem(String id) {
108: StreamElement item = getPubSubItem(id);
109: if (item != null) {
110: remove(item);
111: }
112: }
113:
114: public List listPubSubItems() {
115: List l = new ArrayList();
116: for (Iterator i = listElements("item").iterator(); i.hasNext();) {
117: StreamElement item = (StreamElement) i.next();
118: l.add(item);
119: }
120: return l;
121: }
122:
123: public void addPubSubRetractItem(String id) {
124: StreamElement elem = createPubSubRetractItem(id);
125: add(elem);
126: }
127:
128: public StreamElement createPubSubItem(String itemId) {
129: StreamElement item = getDataFactory().createElementNode(
130: NSI_ITEM);
131: item.setAttributeValue(ATTR_ID, itemId);
132: return item;
133: }
134:
135: public StreamElement createPubSubRetractItem(String itemId) {
136: StreamElement item = getDataFactory().createElementNode(
137: NSI_RETRACT);
138: item.setAttributeValue(ATTR_ID, itemId);
139: return item;
140: }
141:
142: public StreamElement getPubSubItem(String id) {
143: for (Iterator i = listElements("item").iterator(); i.hasNext();) {
144: StreamElement item = (StreamElement) i.next();
145: if (item.getAttributeValue(ATTR_ID).equals(id)) {
146: return item;
147: }
148: }
149: return null;
150: }
151:
152: public StreamElement getPubSubRetractItem() {
153: return getFirstElement(NSI_RETRACT);
154: }
155:
156: public boolean hasPubSubRetractItem() {
157: return getFirstElement(NSI_RETRACT) != null;
158: }
159:
160: public void clearPubSubItems() {
161: for (Iterator i = listElements("item").iterator(); i.hasNext();) {
162: StreamElement item = (StreamElement) i.next();
163: remove(item);
164: }
165: }
166:
167: public StreamObject copy(StreamElement parent) {
168: return new PubSubItemsNode(parent, this);
169: }
170:
171: }
|