[3952] | 1 | |
---|
| 2 | package nu.fw.jeti.plugins; |
---|
| 3 | |
---|
| 4 | import org.xml.sax.helpers.*; |
---|
| 5 | import java.util.*; |
---|
| 6 | |
---|
| 7 | /* |
---|
| 8 | * Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer |
---|
| 9 | * |
---|
| 10 | * This program is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | * (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * This program is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | * GNU General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with this program; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 23 | * |
---|
| 24 | * For questions, comments etc, |
---|
| 25 | * use the website at http://jeti.jabberstudio.org |
---|
| 26 | * or mail/IM me at jeti@jabber.org |
---|
| 27 | * |
---|
| 28 | * Created in 2002 |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | public class PluginsHandler extends DefaultHandler |
---|
| 32 | { |
---|
| 33 | private List plugins; |
---|
| 34 | private StringBuffer text= new StringBuffer(); |
---|
| 35 | private Object[] current; |
---|
| 36 | private boolean found = false; |
---|
| 37 | |
---|
| 38 | public PluginsHandler(List plugins) |
---|
| 39 | { |
---|
| 40 | this.plugins = plugins; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | //public void startDocument() |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | //public void endDocument() |
---|
| 47 | |
---|
| 48 | // public void startElement(String namespaceURI, |
---|
| 49 | // String sName, // simple name |
---|
| 50 | // String qName, // qualified name |
---|
| 51 | // Attributes attrs) |
---|
| 52 | // throws SAXException |
---|
| 53 | // { |
---|
| 54 | // // if(qName.equals("icon")) texts = new LinkedList(); |
---|
| 55 | // /* |
---|
| 56 | // if(qName.equals("plugin")) |
---|
| 57 | // { |
---|
| 58 | // current = new Object[6]; |
---|
| 59 | // current[1] = new Boolean(false); |
---|
| 60 | // } |
---|
| 61 | // */ |
---|
| 62 | // } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | public void endElement(String namespaceURI,String sName,String qName) |
---|
| 66 | { |
---|
| 67 | |
---|
| 68 | if(qName.equals("name")) |
---|
| 69 | {//search name |
---|
| 70 | String name = text.toString().trim(); |
---|
| 71 | for(Iterator i = plugins.iterator();i.hasNext();) |
---|
| 72 | { |
---|
| 73 | Object[] temp = (Object[])i.next(); |
---|
| 74 | if(name.equals(temp[0])) |
---|
| 75 | { |
---|
| 76 | current = temp; |
---|
| 77 | found = true; |
---|
| 78 | break; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | if(!found) |
---|
| 82 | { |
---|
| 83 | current = new Object[6]; |
---|
| 84 | current[0] = name; |
---|
| 85 | current[1] = Boolean.FALSE; |
---|
| 86 | current[3] = ""; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | else if(qName.equals("description")) current[2] = text.toString().trim(); |
---|
| 90 | else if(qName.equals("version")) |
---|
| 91 | { |
---|
| 92 | String t = text.toString().trim(); |
---|
| 93 | if(t.equals("")) current[3] = text; |
---|
| 94 | // else if (current[3]==null) current[3] |
---|
| 95 | } |
---|
| 96 | else if(qName.equals("min_jeti_version")) current[4] = text.toString().trim(); |
---|
| 97 | else if(qName.equals("parent")) current[5] = text.toString().trim(); |
---|
| 98 | else if(qName.equals("plugin")) |
---|
| 99 | { |
---|
| 100 | if(!found) plugins.add(current); |
---|
| 101 | else found = false; |
---|
| 102 | } |
---|
| 103 | text = new StringBuffer(); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | public void characters(char buf[], int offset, int Len) |
---|
| 107 | { |
---|
| 108 | text.append(buf, offset, Len); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | /* |
---|
| 112 | * Overrides for emacs |
---|
| 113 | * Local variables: |
---|
| 114 | * tab-width: 4 |
---|
| 115 | * End: |
---|
| 116 | */ |
---|