Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: edu/ou/kmi/buddyspace/xml/XDataItem.java


1   /*
2    *   License
3    *
4    * The contents of this file are subject to the Jabber Open Source License
5    * Version 1.0 (the "License").  You may not copy or use this file, in either
6    * source code or executable form, except in compliance with the License.  You
7    * may obtain a copy of the License at http://www.jabber.com/license/ or at
8    * http://www.opensource.org/.  
9    *
10   * Software distributed under the License is distributed on an "AS IS" basis,
11   * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
12   * for the specific language governing rights and limitations under the
13   * License.
14   *
15   *   Copyrights
16   *
17   * Portions created by or assigned to Jabber.com, Inc. are 
18   * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
19   * information for Jabber.com, Inc. is available at http://www.jabber.com/.
20   *
21   * Portions Copyright (c) 1999-2000 David Waite 
22   *
23   *   Acknowledgements
24   * 
25   * Special thanks to the Jabber Open Source Contributors for their
26   * suggestions and support of Jabber.
27   * 
28   *   Changes
29   *
30   * @author  David Waite <a href="mailto:dwaite@jabber.com">
31   *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
32   *
33   * @author  $Author: brouk $
34   * @version $Revision: 1.1 $
35   *
36   * j.komzak
37   * Changed into XDataItem
38   */
39  
40  package edu.ou.kmi.buddyspace.xml;
41  
42  /*
43   * XDataItem.java
44   *
45   * Project: BuddySpace
46   * (C) Copyright Knowledge Media Institute 2003
47   *
48   *
49   * Created on 26 March 2003, 11:29
50   */
51  
52  import java.util.Vector;
53  import java.util.Enumeration;
54  import org.jabber.jabberbeans.*;
55  import org.jabber.jabberbeans.Extension.*;
56  
57  /**
58   * <code>XDataItem</code> contains item tag from &lt;x xmlns='jabber:x:data'&gt form.
59   *
60   * @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
61   */
62  public class XDataItem
63      extends XMLData
64      implements MessageExtension, QueryExtension, PresenceExtension
65  {
66      /** Vector of 'Field' objects contained */
67      private Vector fields;
68      
69      private boolean reported = false;
70      
71      /**
72       * Creates a new <code>XDataItem</code> instance, based on the builder
73       * state.
74       *
75       * @param builder an <code>XDataItemBuilder</code> value
76       * @exception InstantiationException if malformed or insufficient data is
77       * in the builder.
78       */
79      public XDataItem(XDataItemBuilder builder)
80          throws InstantiationException
81      {
82          fields = (Vector) builder.getFields().clone();
83          reported = builder.isReported();
84      }
85      
86      public boolean isReported() {
87          return reported;
88      }
89  
90      /**
91       * returns an enumeration of <code>fields</code> contained within this
92       * object.
93       *
94       * @return an <code>Enumeration</code> value
95       */
96      public Enumeration fields()
97      {
98          return fields.elements();
99      }
100     
101     
102     /**
103      * <code>appendItem</code> converts this packet to XML. 
104      * It then appends it to a StringBuffer.
105      *
106      * @param retval The <code>StringBuffer</code> to append to
107      */
108     public void appendItem(StringBuffer retval)
109     {
110         if (reported) retval.append("<reported");
111         else retval.append("<item");
112         
113         boolean emptyTag = true;
114         
115         Enumeration fieldEnum = fields();
116         if (fieldEnum.hasMoreElements()) {
117             retval.append(">\n");
118             emptyTag = false;
119         }
120         while (fieldEnum.hasMoreElements())
121             ((XDataField)fieldEnum.nextElement()).appendItem(retval);
122         
123         if (emptyTag)
124             retval.append("/>\n");
125         else {
126             if (reported) retval.append("</reported>\n");
127             else retval.append("</item>\n");
128         }
129     }
130 }