001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-impl/impl/src/java/org/sakaiproject/search/component/adapter/util/SimpleDigester.java $
003: * $Id: SimpleDigester.java 9109 2006-05-08 14:44:04Z ian@caret.cam.ac.uk $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.search.component.adapter.util;
021:
022: import java.util.HashMap;
023: import java.util.Stack;
024:
025: import org.xml.sax.Attributes;
026: import org.xml.sax.ContentHandler;
027: import org.xml.sax.Locator;
028: import org.xml.sax.SAXException;
029:
030: /**
031: * @author ieb
032: */
033: public class SimpleDigester implements ContentHandler {
034:
035: private Stack stack = new Stack();
036:
037: private StringBuffer buffer = new StringBuffer();
038:
039: private HashMap tags = new HashMap();
040:
041: public static final String[] tagList = { "p", "\n", "div", "\n",
042: "a", "\n", "span", " ", "td", "\n", "th", "\n", "li", "\n",
043: "content", ""
044:
045: };
046:
047: public SimpleDigester() {
048: for (int i = 0; i < tagList.length; i += 2) {
049: tags.put(tagList[i], tagList[i + 1]);
050: }
051: }
052:
053: public String toString() {
054: return buffer.toString();
055: }
056:
057: public void setDocumentLocator(Locator arg0) {
058: }
059:
060: public void startDocument() throws SAXException {
061: }
062:
063: public void endDocument() throws SAXException {
064: }
065:
066: public void startPrefixMapping(String arg0, String arg1)
067: throws SAXException {
068: }
069:
070: public void endPrefixMapping(String arg0) throws SAXException {
071: }
072:
073: public void startElement(String namespaceURI, String localName,
074: String qName, Attributes atts) throws SAXException {
075: stack.push(tags.get(localName.toLowerCase()));
076: }
077:
078: public void endElement(String arg0, String arg1, String arg2)
079: throws SAXException {
080: String marker = (String) stack.pop();
081: if (marker != null) {
082: buffer.append(marker);
083: }
084: }
085:
086: public void characters(char[] arg0, int arg1, int arg2)
087: throws SAXException {
088: if (stack.peek() != null) {
089: String s = new String(arg0, arg1, arg2);
090: buffer.append(s.trim()).append(" ");
091: }
092:
093: }
094:
095: public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
096: throws SAXException {
097:
098: }
099:
100: public void processingInstruction(String arg0, String arg1)
101: throws SAXException {
102:
103: }
104:
105: public void skippedEntity(String arg0) throws SAXException {
106:
107: }
108: }
|