source: branches/2.2/jabberit_messenger/java_source/src/nu/fw/jeti/jabber/handlers/XDataHandler.java @ 3102

Revision 3102, 3.6 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer 
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *      For questions, comments etc,
19 *      use the website at http://jeti.jabberstudio.org
20 *  or mail/IM me at jeti@jabber.org
21 *
22 *      Created on 27-jul-2003
23 */
24
25package nu.fw.jeti.jabber.handlers;
26
27import java.util.LinkedList;
28import java.util.List;
29
30import org.xml.sax.Attributes;
31import nu.fw.jeti.jabber.elements.Extension;
32import nu.fw.jeti.jabber.elements.XDataBuilder;
33import nu.fw.jeti.jabber.elements.XDataFieldBuilder;
34
35/**
36 * @author E.S. de Boer
37 *
38 */
39public class XDataHandler extends ExtensionHandler
40{//add item and reported
41        private XDataBuilder builder;
42        private XDataFieldBuilder fieldBuilder;
43        private String label;
44        private String value;
45        private boolean inOption;
46        private boolean multiple;
47        private boolean reported;
48        private List items;
49       
50        public XDataHandler()
51        {
52                builder = new XDataBuilder();
53                fieldBuilder = new XDataFieldBuilder();
54        }
55
56        public void startHandling(Attributes attr)
57        {
58                inOption=false;
59                label=null;
60                value=null;
61                multiple = false;
62                reported=false;
63                builder.reset();
64                builder.type = attr.getValue("type");
65        }
66
67        public void startElement(String name,Attributes attr)
68        {
69                if(name.equals("reported"))
70                {
71                        multiple = true;
72                        reported=true;
73                }
74                if(name.equals("item"))items = new LinkedList();
75                if(name.equals("field"))
76                {
77                        fieldBuilder.reset();
78                        fieldBuilder.label =attr.getValue("label");
79                        fieldBuilder.var = attr.getValue("var");
80                        fieldBuilder.type = attr.getValue("type");
81                }
82                else if(name.equals("option"))
83                {
84                        inOption = true;
85                        label = attr.getValue("label");
86                }
87                //else if(!name.equals("title") || !name.equals("instructions")  ) nu.fw.jeti.util.Log.notParsedXML("roster " + name);
88        }
89
90        public void endElement(String name)
91        {
92                if(name.equals("field"))
93                {
94                        if(reported)builder.addReportedField(fieldBuilder.build());
95                        else if(multiple && items != null) items.add(fieldBuilder.build());
96                        else builder.addField(fieldBuilder.build());
97                }
98                else if(name.equals("title"))
99                {
100                        builder.title = getText(); 
101                }
102                else if(name.equals("instructions"))
103                {
104                        builder.addInstructions(getText());
105                }
106                else if(name.equals("desc"))
107                {
108                        fieldBuilder.addDescription(getText());
109                }
110                else if(name.equals("required"))
111                {
112                        fieldBuilder.required = true;
113                }
114                else if(name.equals("option"))
115                {
116                        fieldBuilder.addOption(label,value);
117                        inOption=false;
118                        label=null;
119                        value=null;
120                }
121                else if(name.equals("value"))
122                {
123                        if(inOption == true) value = getText();
124                        else fieldBuilder.addValue(getText());
125                }
126                else if (name.equals("reported"))
127                {
128                        reported = false;
129                }
130                else if (name.equals("item"))
131                {
132                        builder.addItem(items);
133                }
134                else nu.fw.jeti.util.Log.notParsedXML("XData " + name + getText());
135                clearCurrentChars();
136        }
137
138        public Extension build() throws InstantiationException
139        {
140                Extension e = builder.build();
141                builder.reset();
142                return e;
143        }
144}
145/*
146 * Overrides for emacs
147 * Local variables:
148 * tab-width: 4
149 * End:
150 */
Note: See TracBrowser for help on using the repository browser.