/* * Jeti, a Java Jabber client, Copyright (C) 2001 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 me at eric@jeti.tk * * 30-12-2004 */ package nu.fw.jeti.images; import java.io.*; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.zip.ZipException; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import nu.fw.jeti.backend.Start; import nu.fw.jeti.backend.XMLDataFile; import nu.fw.jeti.plugins.PluginsHandler; import nu.fw.jeti.util.Preferences; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * @author E.S. de Boer */ public class Icons extends XMLDataFile { //TODO combine with emoticons as classloader private List iconList;//all rostericons/emoticons private SAXParser parser; private String iconType; public Icons(String type) { iconList = Preferences.getPlugable(type); iconType = type; } private void loadParser() { try{parser = SAXParserFactory.newInstance().newSAXParser();} catch (FactoryConfigurationError ex){ex.printStackTrace();} catch (SAXException ex){ex.printStackTrace();} catch (ParserConfigurationException ex){ex.printStackTrace();} } public Icons(SAXParser parser,String type) throws IOException { iconType = type; iconList =Preferences.getPlugable(iconType); this.parser = parser; InputStream data = null; data = getClass().getResourceAsStream("/" + iconType+".xml"); if(data!=null)parseData(data); try { data = (new URL(Start.dataURL + "plugins/" + iconType + "/" + iconType+ ".xml")).openStream(); parseData(data); } catch (IOException ex) { if (new File(Start.path + "plugins" + File.separator + iconType).exists()) scanIcons(); } //if( iconList.isEmpty() ) throw new IOException("no " + iconType); for(Iterator i = iconList.iterator();i.hasNext();) { //remove icons whitout description /deleted plugins still in preferences Object[] object = (Object[])i.next(); if(object[2] == null) { System.out.println(object[0] + "not found or no description"); i.remove(); } else if(object[3] == null) { object[3] = getType((String)object[0]); } } parser = null; } private void parseData(InputStream data) { if(data != null) { try { parser.parse(new InputSource(new InputStreamReader(data,"UTF-8")),new PluginsHandler(iconList)); } catch (SAXException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } public void scanIcons() { List oldrostericons = new ArrayList(iconList); iconList.clear(); searchIcons(); //System.out.println(this.toString()); try { BufferedWriter writer = new BufferedWriter(new FileWriter(Start.path + "plugins" + File.separator + iconType + File.separator + iconType +".xml")); writer.write(this.toString()); writer.close(); //new PrintWriter(new BufferedOutputStream(new FileOutputStream(Start.path +"plugins/plugins.xml"))).write(this.toString()); } catch (IOException ex2) { ex2.printStackTrace(); } for(Iterator i = oldrostericons.iterator();i.hasNext();) { Object[] oldPlugin =(Object[])i.next(); for(Iterator j = iconList.iterator();j.hasNext();) { Object[] newPlugin =(Object[])j.next(); if(oldPlugin[0].equals(newPlugin[0])) { newPlugin[1] = oldPlugin[1]; if(!oldPlugin[3].equals(""))newPlugin[3] = oldPlugin[3]; break; } } } InputStream data = getClass().getResourceAsStream("/" + iconType+".xml"); if(data!=null) { if(parser ==null) loadParser(); parseData(data); } } private void searchIcons() {//voeg samen met plugindata? String urlString = Start.path + "plugins" + File.separator + iconType; //urlString += dir + "/"; //System.out.println(urlString); File path = new File(urlString); File file[] = path.listFiles(); if(file == null) { //System.out.println("no rostericons"); return; } for (int tel=0;tel"); for(Iterator i = iconList.iterator();i.hasNext();) { appendOpenTag(xml,""); Object[] temp = (Object[]) i.next(); appendElement(xml,"name",(String)temp[0]); appendElement(xml,"description",(String)temp[2]); appendElement(xml,"version",(String)temp[3]); appendElement(xml,"min_jeti_version",(String)temp[4]);//hackje appendCloseTag(xml,""); } appendCloseTag(xml,""); } } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */