Public Member Functions | Package Functions | Private Attributes | Static Private Attributes

de.mfuchs.xmlstorage.XMLDocReader Class Reference

XMLDocReader is the XML file reader of XMLStorage. More...

Inheritance diagram for de.mfuchs.xmlstorage.XMLDocReader:
Inheritance graph
[legend]
Collaboration diagram for de.mfuchs.xmlstorage.XMLDocReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException
void endElement (String uri, String localName, String qName) throws SAXException
void characters (char[] ch, int start, int length) throws SAXException
void startCDATA () throws SAXException
void endCDATA () throws SAXException
void processingInstruction (String target, String data) throws SAXException
String getInstructions ()

Package Functions

 XMLDocReader (XMLNode node) throws ParserConfigurationException, SAXException
void read (InputSource source) throws SAXException, IOException
 read XML stream into XML tree below _pos

Private Attributes

XMLPos _pos
SAXParser _parser
String _content = ""
StringBuffer _instructions = new StringBuffer()
int _lastTag
boolean _inCDATASection = false
boolean _isContentCDATA = false

Static Private Attributes

static final int TAG_NONE = 0
static final int TAG_START = 1
static final int TAG_END = 2

Detailed Description

XMLDocReader is the XML file reader of XMLStorage.

Definition at line 56 of file XMLDocReader.java.


Constructor & Destructor Documentation

de.mfuchs.xmlstorage.XMLDocReader.XMLDocReader ( XMLNode  node ) throws ParserConfigurationException, SAXException [package]

Definition at line 58 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._lastTag, de.mfuchs.xmlstorage.XMLDocReader._parser, de.mfuchs.xmlstorage.XMLDocReader._pos, and de.mfuchs.xmlstorage.XMLDocReader.TAG_NONE.

    {
        _pos = new XMLPos(node);
        _lastTag = TAG_NONE;

        SAXParserFactory factory = SAXParserFactory.newInstance();
        _parser = factory.newSAXParser();

         // activate CDATA notifications
        _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
    }

Member Function Documentation

void de.mfuchs.xmlstorage.XMLDocReader.characters ( char[]  ch,
int  start,
int  length 
) throws SAXException

Definition at line 176 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._content, de.mfuchs.xmlstorage.XMLDocReader._inCDATASection, de.mfuchs.xmlstorage.XMLDocReader._isContentCDATA, and de.mfuchs.xmlstorage.XMLHelper.encodeXMLString().

    {
         // encode _content compatible to XMLNode.setContent()
        _content += XMLHelper.encodeXMLString(new String(ch, start, length));

        if (_inCDATASection)
            _isContentCDATA = true;
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.XMLDocReader.endCDATA (  ) throws SAXException

Definition at line 196 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._inCDATASection.

    {
        _inCDATASection = false;
    }
void de.mfuchs.xmlstorage.XMLDocReader.endElement ( String  uri,
String  localName,
String  qName 
) throws SAXException

Definition at line 141 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLNode._children, de.mfuchs.xmlstorage.XMLNode._content, de.mfuchs.xmlstorage.XMLDocReader._content, de.mfuchs.xmlstorage.XMLNode._endLeading, de.mfuchs.xmlstorage.XMLDocReader._isContentCDATA, de.mfuchs.xmlstorage.XMLDocReader._lastTag, de.mfuchs.xmlstorage.XMLDocReader._pos, de.mfuchs.xmlstorage.XMLPos.back(), de.mfuchs.xmlstorage.XMLPos.cur(), de.mfuchs.xmlstorage.XMLDocReader.TAG_END, and de.mfuchs.xmlstorage.XMLDocReader.TAG_START.

    {
        int i;

        if (_isContentCDATA)
            i = _content.length();
        else {
             // search for content end leaving only whitespaces for leading
            i = _content.length();
            for (; i>0; i--) {
                char ch = _content.charAt(i-1);
                if (!Character.isWhitespace(ch))
                    break;
            }
        }

        if (i > 0)
            if (_pos.cur()._children.isEmpty()) // no children in current node?
                _pos.cur()._content += _content.substring(0, i);
            else
                if (_lastTag == TAG_START)
                    _pos.cur()._content += _content.substring(0, i);
                else
                    _pos.cur()._children.getLast()._trailing += _content.substring(0, i);

        if (i < _content.length())
            _pos.cur()._endLeading = _content.substring(i);

        _pos.back();

        _lastTag = TAG_END;
        _content = "";
        _isContentCDATA = false;
    }

Here is the call graph for this function:

String de.mfuchs.xmlstorage.XMLDocReader.getInstructions (  )

Definition at line 209 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._instructions.

Referenced by de.mfuchs.xmlstorage.XMLDoc.read().

    {
        return _instructions.toString();
    }
void de.mfuchs.xmlstorage.XMLDocReader.processingInstruction ( String  target,
String  data 
) throws SAXException

Definition at line 202 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._instructions.

    {
        _instructions.append("<?").append(target)
            .append(" ").append(data).append("?>");
    }
void de.mfuchs.xmlstorage.XMLDocReader.read ( InputSource  source ) throws SAXException, IOException [package]

read XML stream into XML tree below _pos

Definition at line 71 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLNode._children, de.mfuchs.xmlstorage.XMLDocReader._content, de.mfuchs.xmlstorage.XMLDocReader._isContentCDATA, de.mfuchs.xmlstorage.XMLDocReader._parser, de.mfuchs.xmlstorage.XMLDocReader._pos, de.mfuchs.xmlstorage.XMLNode._trailing, and de.mfuchs.xmlstorage.XMLPos.cur().

Referenced by de.mfuchs.xmlstorage.XMLDoc.read().

    {
         // read XML data
        _parser.parse(source, this);

         // process last data pieces
        if (_pos.cur()._children.isEmpty())
            _pos.cur()._trailing += _content;
        else
            _pos.cur()._children.getLast()._trailing += _content;

        _content = "";
        _isContentCDATA = false;
    }

Here is the call graph for this function:

void de.mfuchs.xmlstorage.XMLDocReader.startCDATA (  ) throws SAXException

Definition at line 191 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLDocReader._inCDATASection.

    {
        _inCDATASection = true;
    }
void de.mfuchs.xmlstorage.XMLDocReader.startElement ( String  uri,
String  localName,
String  qName,
Attributes  attributes 
) throws SAXException

Definition at line 98 of file XMLDocReader.java.

References de.mfuchs.xmlstorage.XMLNode._attributes, de.mfuchs.xmlstorage.XMLNode._children, de.mfuchs.xmlstorage.XMLNode._content, de.mfuchs.xmlstorage.XMLDocReader._content, de.mfuchs.xmlstorage.XMLDocReader._isContentCDATA, de.mfuchs.xmlstorage.XMLDocReader._lastTag, de.mfuchs.xmlstorage.XMLDocReader._pos, de.mfuchs.xmlstorage.XMLNode._trailing, de.mfuchs.xmlstorage.XMLPos.addDown(), de.mfuchs.xmlstorage.XMLPos.cur(), de.mfuchs.xmlstorage.XMLDocReader.TAG_END, and de.mfuchs.xmlstorage.XMLDocReader.TAG_START.

    {
         // search for content end leaving only whitespaces for _end_leading
        int i = _content.length();
        for (; i>0; i--) {
            char ch = _content.charAt(i-1);
            if (!Character.isWhitespace(ch))
                break;
        }

        if (i > 0)
            if (_pos.cur()._children.isEmpty()) {   // no children in last node?
                if (_lastTag == TAG_START)
                    _pos.cur()._content += _content.substring(0, i);
                else if (_lastTag == TAG_END)
                    _pos.cur()._trailing += _content.substring(0, i);
                // else TAG_NONE -> don't store white space in root node
            } else
                _pos.cur()._children.getLast()._trailing += _content.substring(0, i);

        String leading = "";

        if (i < _content.length())
            leading = _content.substring(i);

        XMLNode node = new XMLNode(qName, leading);
        //XMLNode node = new XMLNode(XMLHelper.String_from_XML_Char(qName), leading);

        _pos.addDown(node);

        for(int n=0; n<attributes.getLength(); ++n) {
            final String attrName = attributes.getQName(n);
            final String attrValue = attributes.getValue(n);

            node._attributes.put(attrName, attrValue);
            //node.put(XMLHelper.String_from_XML_Char(attrName), XMLHelper.String_from_XML_Char(attr_value));
        }

        _lastTag = TAG_START;
        _content = "";
        _isContentCDATA = false;
    }

Here is the call graph for this function:


Member Data Documentation

StringBuffer de.mfuchs.xmlstorage.XMLDocReader._instructions = new StringBuffer() [private]
final int de.mfuchs.xmlstorage.XMLDocReader.TAG_END = 2 [static, private]
final int de.mfuchs.xmlstorage.XMLDocReader.TAG_NONE = 0 [static, private]

Definition at line 92 of file XMLDocReader.java.

Referenced by de.mfuchs.xmlstorage.XMLDocReader.XMLDocReader().

final int de.mfuchs.xmlstorage.XMLDocReader.TAG_START = 1 [static, private]

The documentation for this class was generated from the following file: