/* * Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/IM me at jeti@jabber.org * * Created on 27-jul-2003 */ package nu.fw.jeti.jabber.handlers; import java.util.LinkedList; import java.util.List; import org.xml.sax.Attributes; import nu.fw.jeti.jabber.elements.Extension; import nu.fw.jeti.jabber.elements.XDataBuilder; import nu.fw.jeti.jabber.elements.XDataFieldBuilder; /** * @author E.S. de Boer * */ public class XDataHandler extends ExtensionHandler {//add item and reported private XDataBuilder builder; private XDataFieldBuilder fieldBuilder; private String label; private String value; private boolean inOption; private boolean multiple; private boolean reported; private List items; public XDataHandler() { builder = new XDataBuilder(); fieldBuilder = new XDataFieldBuilder(); } public void startHandling(Attributes attr) { inOption=false; label=null; value=null; multiple = false; reported=false; builder.reset(); builder.type = attr.getValue("type"); } public void startElement(String name,Attributes attr) { if(name.equals("reported")) { multiple = true; reported=true; } if(name.equals("item"))items = new LinkedList(); if(name.equals("field")) { fieldBuilder.reset(); fieldBuilder.label =attr.getValue("label"); fieldBuilder.var = attr.getValue("var"); fieldBuilder.type = attr.getValue("type"); } else if(name.equals("option")) { inOption = true; label = attr.getValue("label"); } //else if(!name.equals("title") || !name.equals("instructions") ) nu.fw.jeti.util.Log.notParsedXML("roster " + name); } public void endElement(String name) { if(name.equals("field")) { if(reported)builder.addReportedField(fieldBuilder.build()); else if(multiple && items != null) items.add(fieldBuilder.build()); else builder.addField(fieldBuilder.build()); } else if(name.equals("title")) { builder.title = getText(); } else if(name.equals("instructions")) { builder.addInstructions(getText()); } else if(name.equals("desc")) { fieldBuilder.addDescription(getText()); } else if(name.equals("required")) { fieldBuilder.required = true; } else if(name.equals("option")) { fieldBuilder.addOption(label,value); inOption=false; label=null; value=null; } else if(name.equals("value")) { if(inOption == true) value = getText(); else fieldBuilder.addValue(getText()); } else if (name.equals("reported")) { reported = false; } else if (name.equals("item")) { builder.addItem(items); } else nu.fw.jeti.util.Log.notParsedXML("XData " + name + getText()); clearCurrentChars(); } public Extension build() throws InstantiationException { Extension e = builder.build(); builder.reset(); return e; } } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */