sax/source/fastparser/fastparser.cxx      |   59 ++++++++++++------------------
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx |    1 
 2 files changed, 25 insertions(+), 35 deletions(-)

New commits:
commit 1307c65d74fc9a1241f0a50142921cadac1e882b
Author: LuboÅ¡ Luňák <[email protected]>
Date:   Thu Nov 20 13:57:46 2014 +0100

    proper error reporting from libxml2
    
    Change-Id: Ia173f7f4c88c90b6d54c9a47d6ae18b933502678

diff --git a/sax/source/fastparser/fastparser.cxx 
b/sax/source/fastparser/fastparser.cxx
index e1d22d2..bf3aa01 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -532,46 +532,20 @@ Event& Entity::getEvent( CallbackType aType )
     return rEvent;
 }
 
-OUString lclGetErrorMessage( xmlParserCtxtPtr, const OUString& sSystemId, 
sal_Int32 nLine )
+OUString lclGetErrorMessage( xmlParserCtxtPtr ctxt, const OUString& sSystemId, 
sal_Int32 nLine )
 {
-    const sal_Char* pMessage = "";
-#if 0
-    pMessage = "Error";
-    switch( xmlE )
-    {
-        case XML_ERROR_NONE:                            pMessage = "No";       
                             break;
-        case XML_ERROR_NO_MEMORY:                       pMessage = "no 
memory";                             break;
-        case XML_ERROR_SYNTAX:                          pMessage = "syntax";   
                             break;
-        case XML_ERROR_NO_ELEMENTS:                     pMessage = "no 
elements";                           break;
-        case XML_ERROR_INVALID_TOKEN:                   pMessage = "invalid 
token";                         break;
-        case XML_ERROR_UNCLOSED_TOKEN:                  pMessage = "unclosed 
token";                        break;
-        case XML_ERROR_PARTIAL_CHAR:                    pMessage = "partial 
char";                          break;
-        case XML_ERROR_TAG_MISMATCH:                    pMessage = "tag 
mismatch";                          break;
-        case XML_ERROR_DUPLICATE_ATTRIBUTE:             pMessage = "duplicate 
attribute";                   break;
-        case XML_ERROR_JUNK_AFTER_DOC_ELEMENT:          pMessage = "junk after 
doc element";                break;
-        case XML_ERROR_PARAM_ENTITY_REF:                pMessage = "parameter 
entity reference";            break;
-        case XML_ERROR_UNDEFINED_ENTITY:                pMessage = "undefined 
entity";                      break;
-        case XML_ERROR_RECURSIVE_ENTITY_REF:            pMessage = "recursive 
entity reference";            break;
-        case XML_ERROR_ASYNC_ENTITY:                    pMessage = "async 
entity";                          break;
-        case XML_ERROR_BAD_CHAR_REF:                    pMessage = "bad char 
reference";                    break;
-        case XML_ERROR_BINARY_ENTITY_REF:               pMessage = "binary 
entity reference";               break;
-        case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF:   pMessage = "attribute 
external entity reference";   break;
-        case XML_ERROR_MISPLACED_XML_PI:                pMessage = "misplaced 
xml processing instruction";  break;
-        case XML_ERROR_UNKNOWN_ENCODING:                pMessage = "unknown 
encoding";                      break;
-        case XML_ERROR_INCORRECT_ENCODING:              pMessage = "incorrect 
encoding";                    break;
-        case XML_ERROR_UNCLOSED_CDATA_SECTION:          pMessage = "unclosed 
cdata section";                break;
-        case XML_ERROR_EXTERNAL_ENTITY_HANDLING:        pMessage = "external 
entity reference";             break;
-        case XML_ERROR_NOT_STANDALONE:                  pMessage = "not 
standalone";                        break;
-        default:;
-    }
-#endif
+    const sal_Char* pMessage;
+    xmlErrorPtr error = xmlCtxtGetLastError( ctxt );
+    if( error && error->message )
+        pMessage = error->message;
+    else
+        pMessage = "unknown error";
     OUStringBuffer aBuffer( '[' );
     aBuffer.append( sSystemId );
     aBuffer.append( " line " );
     aBuffer.append( nLine );
     aBuffer.append( "]: " );
     aBuffer.appendAscii( pMessage );
-    aBuffer.append( " error" );
     return aBuffer.makeStringAndClear();
 }
 
commit 0df9ac47dfa287249e77bb8f6a5555324a94a48d
Author: LuboÅ¡ Luňák <[email protected]>
Date:   Thu Nov 20 13:42:16 2014 +0100

    make FastSaxParser provide the whole content in one characters() call
    
    SAX interface is not required to provide the whole node content in one
    characters() call (e.g. if there's an entity that needs decoding). However
    it's easier to consumers to assume this (e.g. writerfilter's
    DomainMapper::lcl_utext() handles datecontrol that way), and expat 
apparently
    never used this. However this can happen with libxml2, so ensure such 
consumers
    still work.
    
    Change-Id: Ib564f372fbea8451f84553a6d49a07d091a950e9

diff --git a/sax/source/fastparser/fastparser.cxx 
b/sax/source/fastparser/fastparser.cxx
index 38a4bbb..e1d22d2 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -237,6 +237,7 @@ public:
 private:
     bool consume(EventList *);
     void deleteUsedEvents();
+    void sendPendingCharacters();
 
     sal_Int32 GetToken( const xmlChar* pName, sal_Int32 nameLen );
     sal_Int32 GetTokenWithPrefix( const xmlChar* pPrefix, int prefixLen, const 
xmlChar* pName, int nameLen ) throw (::com::sun::star::xml::sax::SAXException);
@@ -257,6 +258,7 @@ private:
 
     Entity *mpTop;                          /// std::stack::top() is amazingly 
slow => cache this.
     ::std::stack< Entity > maEntities;      /// Entity stack for each call of 
parseStream().
+    OUString pendingCharacters;             /// Data from characters() 
callback that needs to be sent.
 };
 
 } // namespace sax_fastparser
@@ -1048,6 +1050,8 @@ void FastSaxParserImpl::parse()
 void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const 
xmlChar* prefix, const xmlChar* URI,
     int numNamespaces, const xmlChar** namespaces, int numAttributes, int 
/*defaultedAttributes*/, const xmlChar **attributes)
 {
+    if( !pendingCharacters.isEmpty())
+        sendPendingCharacters();
     Entity& rEntity = getEntity();
     if( rEntity.maNamespaceCount.empty() )
     {
@@ -1154,6 +1158,8 @@ void FastSaxParserImpl::callbackStartElement(const 
xmlChar *localName , const xm
 
 void FastSaxParserImpl::callbackEndElement( const xmlChar*, const xmlChar*, 
const xmlChar* )
 {
+    if( !pendingCharacters.isEmpty())
+        sendPendingCharacters();
     Entity& rEntity = getEntity();
     assert( !rEntity.maNamespaceCount.empty() );
     if( !rEntity.maNamespaceCount.empty() )
@@ -1172,9 +1178,20 @@ void FastSaxParserImpl::callbackEndElement( const 
xmlChar*, const xmlChar*, cons
 
 void FastSaxParserImpl::callbackCharacters( const xmlChar* s, int nLen )
 {
+    // SAX interface allows that the characters callback splits content of one 
XML node
+    // (e.g. because there's an entity that needs decoding), however for 
consumers it's
+    // simpler FastSaxParser's character callback provides the whole string at 
once,
+    // so merge data from possible multiple calls and send them at once 
(before the element
+    // ends or another one starts).
+    pendingCharacters += OUString( XML_CAST( s ), nLen, RTL_TEXTENCODING_UTF8 
);
+}
+
+void FastSaxParserImpl::sendPendingCharacters()
+{
     Entity& rEntity = getEntity();
     Event& rEvent = rEntity.getEvent( CHARACTERS );
-    rEvent.msChars = OUString( XML_CAST( s ), nLen, RTL_TEXTENCODING_UTF8);
+    rEvent.msChars = pendingCharacters;
+    pendingCharacters.clear();
     if (rEntity.mbEnableThreads)
         produce();
     else
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index d0c6e87..e187959 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -582,7 +582,6 @@ DECLARE_OOXMLEXPORT_TEST(testTableCurruption, 
"tableCurrupt.docx")
 
 DECLARE_OOXMLEXPORT_TEST(testDateControl, "date-control.docx")
 {
-if (true) return;
     // check XML
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
     if (!pXmlDoc)
_______________________________________________
Libreoffice-commits mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to