[Xmlstorage-commits] SF.net SVN: xmlstorage: [90] trunk/java/src/de/mfuchs/xmlstorage/XMLReader. ja
Brought to you by:
martinfuchs
From: <mar...@us...> - 2008-03-31 11:16:03
|
Revision: 90 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=90&view=rev Author: martinfuchs Date: 2008-03-31 04:16:06 -0700 (Mon, 31 Mar 2008) Log Message: ----------- parsing of multiline content Modified Paths: -------------- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java Modified: trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java =================================================================== --- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-02-07 22:27:25 UTC (rev 89) +++ trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-03-31 11:16:06 UTC (rev 90) @@ -62,8 +62,8 @@ SAXParserFactory factory = SAXParserFactory.newInstance(); _parser = factory.newSAXParser(); - // Aktivierung der CDATA-Benachrichtigungen - _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); + // Aktivierung der CDATA-Benachrichtigungen + _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); _last_tag = TAG_NONE; } @@ -71,7 +71,7 @@ /// read XML stream into XML tree below _pos void read(InputSource source) throws SAXException, IOException { - _parser.parse(source, this); + _parser.parse(source, this); if (_pos.cur()._children.isEmpty()) _pos.cur()._trailing += _content; @@ -79,11 +79,11 @@ _pos.cur()._children.back()._trailing += _content; _content = ""; - _isContentCDATA = false; + _isContentCDATA = false; } protected XMLPos _pos; - protected SAXParser _parser; + protected SAXParser _parser; protected String _xml_version; protected String _encoding; @@ -93,7 +93,7 @@ protected static final int TAG_NONE = 0; protected static final int TAG_START = 1; protected static final int TAG_END = 2; - int _last_tag; // enum + int _last_tag; // enum /* information about XML version and encoding not available using SAX parser @@ -102,16 +102,16 @@ protected static void XMLCALL XML_XmlDeclHandler(void* userData, const XML_Char* version, const XML_Char* encoding, int standalone); */ - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - // search for end of first line - int i = _content.indexOf('\n'); + // 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 != -1) - ++i; - else - i = _content.length(); - if (i > 0) if (_pos.cur()._children.isEmpty()) { // no children in last node? if (_last_tag == TAG_START) @@ -133,7 +133,7 @@ _pos.addDown(node); for(int n=0; n<attributes.getLength(); ++n) { - final String attrName = attributes.getQName(n); + final String attrName = attributes.getQName(n); final String attr_value = attributes.getValue(n); node.put(attrName, attr_value); @@ -142,27 +142,21 @@ _last_tag = TAG_START; _content = ""; - _isContentCDATA = false; + _isContentCDATA = false; } - public void endElement(String uri, String localName, String qName) throws SAXException - { - // search for end of first line - int i; + public void endElement(String uri, String localName, String qName) throws SAXException + { + // search for content end leaving only whitespaces for leading + int i = _content.length(); + for (; i>0; i--) { + char ch = _content.charAt(i-1); + if (!Character.isWhitespace(ch)) + break; + } - if (_isContentCDATA) - i = _content.length(); - else { - i = _content.indexOf('\n'); - - if (i != -1) - ++i; - else - i = _content.length(); - } - if (i > 0) - if (_pos.cur()._children.isEmpty()) // no children in current node? + if (_pos.cur()._children.isEmpty()) // no children in current node? _pos.cur()._content += _content.substring(0, i); else if (_last_tag == TAG_START) @@ -177,44 +171,44 @@ _last_tag = TAG_END; _content = ""; - _isContentCDATA = false; - } + _isContentCDATA = false; + } - public void characters(char ch[], int start, int length) throws SAXException - { - // encode _content compatible to XMLNode.setContent() - _content += XMLHelper.encodeXMLString(new String(ch, start, length)); + public void characters(char ch[], int start, int length) throws SAXException + { + // encode _content compatible to XMLNode.setContent() + _content += XMLHelper.encodeXMLString(new String(ch, start, length)); - if (_inCDATASection) - _isContentCDATA = true; - } + if (_inCDATASection) + _isContentCDATA = true; + } - // CDATA-Handling + // CDATA-Handling - protected boolean _inCDATASection = false; - protected boolean _isContentCDATA = false; + protected boolean _inCDATASection = false; + protected boolean _isContentCDATA = false; - public void startCDATA() throws SAXException - { - _inCDATASection = true; - } + public void startCDATA() throws SAXException + { + _inCDATASection = true; + } - public void endCDATA() throws SAXException - { - _inCDATASection = false; - } + public void endCDATA() throws SAXException + { + _inCDATASection = false; + } - public void processingInstruction (String target, String data) + public void processingInstruction (String target, String data) throws SAXException - { + { _instructions.append("<?").append(target) .append(" ").append(data).append("?>"); - } + } - public String getInstructions() - { - return _instructions.toString(); - } + public String getInstructions() + { + return _instructions.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |