// opensearchdescriptionReader.java // (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany // first published 11.03.2008 on http://yacy.net // // This is a part of YaCy, a peer-to-peer based web search engine // // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ // $LastChangedRevision: 1986 $ // $LastChangedBy: orbiter $ // // LICENSE // // 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 package de.anomic.xml; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import de.anomic.server.serverByteBuffer; import de.anomic.server.logging.serverLog; public class opensearchdescriptionReader extends DefaultHandler { // statics for item generation and automatic categorization static int guidcount = 0; //private static final String recordTag = "OpenSearchDescription"; private static final String[] tagsDef = new String[]{ "ShortName", "LongName", "Image", "Language", "OutputEncoding", "InputEncoding", "AdultContent", "Description", "Url", "Developer", "Query", "Tags", "Contact", "Attribution", "SyndicationRight" }; /* YaCy/#[clientname]# YaCy.net - #[SearchPageGreeting]# http://#[thisaddress]#/env/grafics/yacy.gif en-us UTF-8 UTF-8 true YaCy is an open-source GPL-licensed software that can be used for stand-alone search engine installations or as a client for a multi-user P2P-based web indexing cluster. This is the access to peer '#[clientname]#'. See http://developer.berlios.de/projects/yacy/ YaCy P2P Web Search See http://#[thisaddress]#/ViewProfile.html?hash=localhash YaCy Software &copy; 2004-2007 by Michael Christen et al., YaCy.net; Content: ask peer owner open */ private static final HashSet tags = new HashSet(); static { for (int i = 0; i < tagsDef.length; i++) { tags.add(tagsDef[i]); } } // class variables private Item channel; private final StringBuilder buffer; private boolean parsingChannel; private final String imageURL = null; private final ArrayList itemsGUID; // a list of GUIDs, so the items can be retrieved by a specific order private final HashMap items; // a guid:Item map public opensearchdescriptionReader() { itemsGUID = new ArrayList(); items = new HashMap(); buffer = new StringBuilder(); channel = null; parsingChannel = false; } public opensearchdescriptionReader(final String path) { this(); try { final SAXParserFactory factory = SAXParserFactory.newInstance(); final SAXParser saxParser = factory.newSAXParser(); saxParser.parse(path, this); } catch (final Exception e) { e.printStackTrace(); } } public opensearchdescriptionReader(final InputStream stream) { this(); try { final SAXParserFactory factory = SAXParserFactory.newInstance(); final SAXParser saxParser = factory.newSAXParser(); saxParser.parse(stream, this); } catch (final Exception e) { e.printStackTrace(); } } public static opensearchdescriptionReader parse(final byte[] a) { // check integrity of array if ((a == null) || (a.length == 0)) { serverLog.logWarning("opensearchdescriptionReader", "response=null"); return null; } if (a.length < 100) { serverLog.logWarning("opensearchdescriptionReader", "response=" + new String(a)); return null; } if (!serverByteBuffer.equals(a, " map; public Item() { this.map = new HashMap(); this.map.put("guid", Long.toHexString(System.currentTimeMillis()) + ":" + guidcount++); } public void setValue(final String name, final String value) { map.put(name, value); } } }