Package meganetpo.picturehandler

Source Code of meganetpo.picturehandler.saxParser

package meganetpo.picturehandler;

import java.util.Map;
import org.apache.commons.collections.map.HashedMap;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
*
* @author Burtovoy Semen
*/
public class saxParser extends DefaultHandler {

    private Map<String, Integer> letterMap = null;
    private String currentLetter = null;
    private int currentHash = 0;
    private String currentElement;

    public saxParser() {
  letterMap = new HashedMap();
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
  for (int i = start; i < start + length; i++) {
      switch (ch[i]) {
    case '\\':
        break;
    case '"':
        break;
    case '\n':
        break;
    case '\r':
        break;
    case '\t':
        break;
    default:
        if (currentElement.equalsIgnoreCase("letter")) {
      currentLetter = Character.toString(ch[i]);
        }
        break;
      }
  }
    }

    @Override
    public void endDocument() throws SAXException {
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
  if (currentElement.equalsIgnoreCase("letter")) {
      letterMap.put(currentLetter, currentHash);
  }
    }

    @Override
    public void startDocument() throws SAXException {
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  currentElement = qName;
  if (qName.equalsIgnoreCase("letter")) {
      String attValue = attributes.getValue(0);
      String attName = attributes.getLocalName(0);
      if (attName.equalsIgnoreCase("hash")) {
    Integer attribut = new Integer(attValue);
    currentHash = attribut;
      }
  }
    }

    public Map<String, Integer> getLetterMap() {
  return letterMap;
    }

    public void setLetterMap(Map<String, Integer> letterMap) {
  this.letterMap = letterMap;
    }
}
TOP

Related Classes of meganetpo.picturehandler.saxParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.