Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/miamm/soapmmil/test/simple/SimpleContentHandler.java


1   /* -*- Mode: java; indent-tabs-mode:nil; c-basic-offset: 2 -*-
2    * ex: set sw=2 expandtab:
3    * $Id: SimpleContentHandler.java,v 1.5 2003/03/01 23:46:19 kowey Exp $
4    *
5    * This software is released under a BSD-style license.
6    * Please see the LICENSE file in this distribution.
7    */
8   
9   package org.miamm.soapmmil.test.simple;
10  
11  import org.xml.sax.Attributes;
12  import org.xml.sax.helpers.DefaultHandler;
13  import org.apache.log4j.Logger;
14  
15  /**
16   * A simple SAX <code>ContentHandler</code> for the XML data handled 
17   * <code>SimpleMIAMMService</code>.  Note, this is very poorly
18   * implemented, and anybody who writes code like this for his service
19   * deserves to be slapped upside the head.
20   *
21   * <p>
22   * Note: normally, you wouldn't write a class like this... you'd take
23   * advantage, for example, of Dirk's fancy MMIL parser
24   * </p>
25   *
26   * @version
27   * $Revision: 1.5 $<br>
28   * $Date: 2003/03/01 23:46:19 $<br>
29   * @author Eric Kow (kow at loria point fr)
30   */
31  public class SimpleContentHandler extends DefaultHandler 
32    implements SimpleMIAMMServiceConstants
33  {
34    static Logger _logger = Logger.getLogger(SimpleContentHandler.class);  boolean _inReality;
35    boolean _inDream;
36    String _reality;
37    String _dream;
38  
39    public SimpleContentHandler() {
40      _inReality = false;
41      _inDream = false;
42      _reality = "";
43      _dream = "";
44    }
45  
46    public void startElement(java.lang.String uri, 
47                             java.lang.String localName, 
48                             java.lang.String qName,
49                             Attributes attributes) {
50      _logger.debug("start element " + qName);
51      if (localName.equals(ELEMENT_TAG_REALITY)) _inReality = true;
52      if (localName.equals(ELEMENT_TAG_DREAM)) _inDream = true;
53    }
54  
55    public void endElement(java.lang.String uri, 
56                           java.lang.String localName, 
57                           java.lang.String qName) {
58      _logger.debug("end element " + qName);
59      if (localName.equals(ELEMENT_TAG_REALITY)) _inReality = false;
60      if (localName.equals(ELEMENT_TAG_DREAM)) _inDream = false;
61    }
62  
63    public void characters(char[] ch, int start, int length) {
64      _logger.debug("characters" + new String(ch, start, length));
65  
66      if (_inReality) { 
67        _reality = new String(ch, start, length);
68      }
69      if (_inDream)   {
70        _dream  = new String(ch, start, length);
71      }
72    }
73  
74    public String getReality() {
75      return _reality;
76    }
77  
78    public String getDream() {
79      return _dream;
80    }
81  } 
82