[gnote] Remove libxml++ TextReader. Should fix both bug #579292 and bug #579316.
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] Remove libxml++ TextReader. Should fix both bug #579292 and bug #579316.
- Date: Wed, 27 May 2009 18:34:59 -0400 (EDT)
commit d23236275936e6f0f44dddae639528e4f0f7b935
Author: Hubert Figuiere <hub figuiere net>
Date: Mon May 25 23:04:38 2009 -0400
Remove libxml++ TextReader. Should fix both bug #579292 and bug #579316.
---
.gitignore | 1 +
NEWS | 4 +-
configure.ac | 6 +-
src/Makefile.am | 11 ++-
src/note.cpp | 20 +++--
src/notebuffer.cpp | 17 ++--
src/notebuffer.hpp | 8 ++-
src/notetag.cpp | 7 +-
src/notetag.hpp | 5 +-
src/sharp/datetime.cpp | 7 +-
src/sharp/xmlreader.cpp | 195 ++++++++++++++++++++++++++++++++++++++++++++
src/sharp/xmlreader.hpp | 86 +++++++++++++++++++
src/test/xmlreadertest.cpp | 81 ++++++++++++++++++
src/utils.cpp | 9 +-
14 files changed, 416 insertions(+), 41 deletions(-)
diff --git a/.gitignore b/.gitignore
index 4975ac4..f1e42d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,6 +41,7 @@ src/notetest
src/stringtest
src/trietest
src/uritest
+src/xmlreadertest
src/addins/addins.mk
src/addins/fixedwidth/fixedwidth.so
m4/intltool.m4
diff --git a/NEWS b/NEWS
index ba48609..ba243b9 100644
--- a/NEWS
+++ b/NEWS
@@ -8,9 +8,7 @@ New features:
Fixes:
- * Hard require on libxml++ 2.26. Should prevent some bugs (Bug #583807,
- Bug #583808, Bug #579292, Bug #579316)
- See: http://git.gnome.org/cgit/libxml++/commit/?id=24b3ec06f5c5ebd0529100a5506a8038f14bac5b
+ * Remove libxml++ TextReader. (Closes #579292) Possibly closes bug #579316.
* Note is now trackable. Should avoid a crash related to signals.
(Closes #581618)
* Remove obsolete UTF-8 keyword in .desktop (Closes #581623)
diff --git a/configure.ac b/configure.ac
index 8039c67..2086a58 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,10 +28,6 @@ LIBGLIBMM_VERSION=2.0
LIBGTKMM_VERSION=2.12.0
dnl LIBGLADEMM_VERSION=2.6.0
dnl LIBGCONFMM_VERSION=2.6.0
-dnl libxml++ 2.24 has too many bugs, mostly in TextReader
-dnl see http://git.gnome.org/cgit/libxml++/commit/?id=4ff42fba42e3f89986d30231a4e8e604592c8fff
-dnl and https://bugzilla.gnome.org/show_bug.cgi?id=583825
-LIBXMLPP_VERSION=2.26.0
LIBGCONF_VERSION=2.0.0
LIBGNOMEUI_VERSION=2.0.0
LIBPANELAPPLETMM_VERSION=2.22.0
@@ -74,7 +70,7 @@ PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= $GTK_VERSION])
PKG_CHECK_MODULES(LIBGTKMM, [gtkmm-2.4 >= $LIBGTKMM_VERSION])
PKG_CHECK_MODULES(LIBXML, [libxml-2.0])
PKG_CHECK_MODULES(LIBXSLT, [libxslt])
-PKG_CHECK_MODULES(LIBXMLPP, [libxml++-2.6 >= $LIBXMLPP_VERSION])
+PKG_CHECK_MODULES(LIBXMLPP, [libxml++-2.6])
PKG_CHECK_MODULES(GCONF, [gconf-2.0])
dnl PKG_CHECK_MODULES(LIBGLADEMM, [libglademm-2.4 >= $LIBGLADEMM_VERSION])
dnl PKG_CHECK_MODULES(LIBGNOMEUI, [libgnomeui-2.0 >= $LIBGNOMEUI_VERSION])
diff --git a/src/Makefile.am b/src/Makefile.am
index 10d64c0..7de83b3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,8 +20,10 @@ GNOTE_LIBS = libgnote.a @LIBGLIBMM_LIBS@ @LIBGTKMM_LIBS@ @LIBXMLPP_LIBS@ \
noinst_LIBRARIES = libgnote.a
bin_PROGRAMS = gnote
-check_PROGRAMS = trietest stringtest notetest dttest uritest filestest
-TESTS = trietest stringtest notetest dttest uritest filestest
+check_PROGRAMS = trietest stringtest notetest dttest uritest filestest \
+ xmlreadertest
+TESTS = trietest stringtest notetest dttest uritest filestest \
+ xmlreadertest
trietest_SOURCES = test/trietest.cpp \
@@ -44,6 +46,10 @@ uritest_SOURCES = test/uritest.cpp \
sharp/string.cpp sharp/uri.cpp debug.cpp
uritest_LDADD = @BOOST_REGEX_LIBS@ @LIBGLIBMM_LIBS@
+xmlreadertest_SOURCES = test/xmlreadertest.cpp \
+ sharp/xmlreader.cpp debug.cpp
+xmlreadertest_LDADD = @LIBXML_LIBS@
+
notetest_SOURCES = test/notetest.cpp
notetest_LDADD = $(GNOTE_LIBS)
@@ -81,6 +87,7 @@ libgnote_a_SOURCES = \
sharp/uri.hpp sharp/uri.cpp \
sharp/uuid.hpp \
sharp/xmlconvert.hpp sharp/xmlconvert.cpp \
+ sharp/xmlreader.hpp sharp/xmlreader.cpp \
sharp/xmlresolver.hpp \
sharp/xmlwriter.hpp sharp/xmlwriter.cpp \
sharp/xsltargumentlist.hpp sharp/xsltargumentlist.cpp \
diff --git a/src/note.cpp b/src/note.cpp
index 061111a..75af4a1 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -32,7 +32,6 @@
#include <boost/filesystem/path.hpp>
#include <boost/algorithm/string/find.hpp>
-#include <libxml++/parsers/textreader.h>
#include <libxml++/parsers/domparser.h>
#include <libxml++/nodes/textnode.h>
@@ -52,6 +51,7 @@
#include "sharp/map.hpp"
#include "sharp/string.hpp"
#include "sharp/xmlconvert.hpp"
+#include "sharp/xmlreader.hpp"
#include "sharp/xmlwriter.hpp"
@@ -817,8 +817,8 @@ namespace gnote {
}
}
- xmlpp::TextReader xml((const unsigned char*)foreignNoteXml.c_str(),
- foreignNoteXml.size());
+ sharp::XmlReader xml;
+ xml.load_buffer(foreignNoteXml);
// Remove tags now, since a note with no tags has
// no "tags" element in the XML
@@ -831,7 +831,7 @@ namespace gnote {
while (xml.read()) {
switch (xml.get_node_type()) {
- case xmlpp::TextReader::Element:
+ case XML_READER_TYPE_ELEMENT:
name = xml.get_name();
if (name == "title") {
set_title(xml.read_string());
@@ -1088,13 +1088,13 @@ namespace gnote {
NoteData *note = new NoteData(uri);
std::string version;
- xmlpp::TextReader xml(read_file);
+ sharp::XmlReader xml(read_file);
Glib::ustring name;
while (xml.read ()) {
switch (xml.get_node_type()) {
- case xmlpp::TextReader::Element:
+ case XML_READER_TYPE_ELEMENT:
name = xml.get_name();
if(name == "note") {
@@ -1166,7 +1166,7 @@ namespace gnote {
if (version != NoteArchiver::CURRENT_VERSION) {
// Note has old format, so rewrite it. No need
// to reread, since we are not adding anything.
- DBG_OUT("Updating note XML to newest format...");
+ DBG_OUT("Updating note XML from %s to newest format...", version.c_str());
NoteArchiver::write (read_file, *note);
}
return note;
@@ -1333,11 +1333,13 @@ namespace gnote {
std::string NoteArchiver::get_title_from_note_xml(const std::string & noteXml) const
{
if (!noteXml.empty()) {
- xmlpp::TextReader xml((const unsigned char*)noteXml.c_str(), noteXml.size());
+ sharp::XmlReader xml;
+
+ xml.load_buffer(noteXml);
while (xml.read ()) {
switch (xml.get_node_type()) {
- case xmlpp::TextReader::Element:
+ case XML_READER_TYPE_ELEMENT:
if (xml.get_name() == "title") {
return xml.read_string ();
}
diff --git a/src/notebuffer.cpp b/src/notebuffer.cpp
index 4e249a5..e145d2e 100644
--- a/src/notebuffer.cpp
+++ b/src/notebuffer.cpp
@@ -22,7 +22,6 @@
#include <algorithm>
#include <tr1/array>
-#include <libxml++/parsers/textreader.h>
#include "debug.hpp"
#include "notebuffer.hpp"
@@ -31,6 +30,7 @@
#include "preferences.hpp"
#include "undo.hpp"
+#include "sharp/xmlreader.hpp"
#include "sharp/xmlwriter.hpp"
namespace gnote {
@@ -1382,7 +1382,8 @@ namespace gnote {
{
if(!content.empty()) {
// it looks like an empty string does not really make the cut
- xmlpp::TextReader xml((const unsigned char *)content.c_str(), content.size());
+ sharp::XmlReader xml;
+ xml.load_buffer(content);
deserialize(buffer, iter, xml);
}
}
@@ -1399,7 +1400,7 @@ namespace gnote {
void NoteBufferArchiver::deserialize(const Glib::RefPtr<Gtk::TextBuffer> & buffer,
const Gtk::TextIter & start,
- xmlpp::TextReader & xml)
+ sharp::XmlReader & xml)
{
int offset = start.get_offset();
std::stack<TagStart> tag_stack;
@@ -1418,7 +1419,7 @@ namespace gnote {
while (xml.read ()) {
Gtk::TextIter insert_at;
switch (xml.get_node_type()) {
- case xmlpp::TextReader::Element:
+ case XML_READER_TYPE_ELEMENT:
if (xml.get_name() == "note-content")
break;
@@ -1460,9 +1461,9 @@ namespace gnote {
tag_stack.push (tag_start);
break;
- case xmlpp::TextReader::Text:
- case xmlpp::TextReader::Whitespace:
- case xmlpp::TextReader::SignificantWhitespace:
+ case XML_READER_TYPE_TEXT:
+ case XML_READER_TYPE_WHITESPACE:
+ case XML_READER_TYPE_SIGNIFICANT_WHITESPACE:
insert_at = buffer->get_iter_at_offset (offset);
buffer->insert (insert_at, xml.get_value());
@@ -1476,7 +1477,7 @@ namespace gnote {
}
break;
- case xmlpp::TextReader::EndElement:
+ case XML_READER_TYPE_END_ELEMENT:
if (xml.get_name() == "note-content")
break;
diff --git a/src/notebuffer.hpp b/src/notebuffer.hpp
index bd02f9f..f4282f2 100644
--- a/src/notebuffer.hpp
+++ b/src/notebuffer.hpp
@@ -33,7 +33,11 @@
#include <gtkmm/widget.h>
#include "notetag.hpp"
-#include "sharp/xmlwriter.hpp"
+
+namespace sharp {
+ class XmlReader;
+ class XmlWriter;
+}
namespace gnote {
@@ -156,7 +160,7 @@ public:
static void deserialize(const Glib::RefPtr<Gtk::TextBuffer> &, const Gtk::TextIter & ,
const std::string & );
static void deserialize(const Glib::RefPtr<Gtk::TextBuffer> & buffer,
- const Gtk::TextIter & iter, xmlpp::TextReader & xml);
+ const Gtk::TextIter & iter, sharp::XmlReader & xml);
private:
static void write_tag(const Glib::RefPtr<const Gtk::TextTag> & tag, sharp::XmlWriter & xml,
diff --git a/src/notetag.cpp b/src/notetag.cpp
index 9f4115a..3db4007 100644
--- a/src/notetag.cpp
+++ b/src/notetag.cpp
@@ -21,12 +21,11 @@
#include <boost/lexical_cast.hpp>
-#include <libxml++/parsers/textreader.h>
-
#include <gtk/gtk.h>
#include <gtkmm/image.h>
#include <gtkmm/rc.h>
+#include "sharp/xmlreader.hpp"
#include "sharp/xmlwriter.hpp"
#include "debug.hpp"
#include "notetag.hpp"
@@ -149,7 +148,7 @@ namespace gnote {
}
}
- void NoteTag::read(xmlpp::TextReader & xml, bool start)
+ void NoteTag::read(sharp::XmlReader & xml, bool start)
{
if (can_serialize()) {
if (start) {
@@ -308,7 +307,7 @@ namespace gnote {
}
}
- void DynamicNoteTag::read(xmlpp::TextReader & xml, bool start)
+ void DynamicNoteTag::read(sharp::XmlReader & xml, bool start)
{
if (can_serialize()) {
NoteTag::read (xml, start);
diff --git a/src/notetag.hpp b/src/notetag.hpp
index b8d1ffb..1eb6a27 100644
--- a/src/notetag.hpp
+++ b/src/notetag.hpp
@@ -35,6 +35,7 @@
namespace sharp {
class XmlWriter;
+ class XmlReader;
}
namespace xmlpp {
@@ -108,7 +109,7 @@ public:
void get_extents(const Gtk::TextIter & iter, Gtk::TextIter & start,
Gtk::TextIter & end);
virtual void write(sharp::XmlWriter &, bool) const;
- virtual void read(xmlpp::TextReader &, bool);
+ virtual void read(sharp::XmlReader &, bool);
virtual Glib::RefPtr<Gdk::Pixbuf> get_image() const;
virtual void set_image(const Glib::RefPtr<Gdk::Pixbuf> &);
virtual Gtk::Widget * get_widget() const
@@ -183,7 +184,7 @@ public:
return m_attributes;
}
virtual void write(sharp::XmlWriter &, bool) const;
- virtual void read(xmlpp::TextReader &, bool);
+ virtual void read(sharp::XmlReader &, bool);
/// <summary>
/// Derived classes should override this if they desire
/// to be notified when a tag attribute is read in.
diff --git a/src/sharp/datetime.cpp b/src/sharp/datetime.cpp
index ab5e893..994a7f6 100644
--- a/src/sharp/datetime.cpp
+++ b/src/sharp/datetime.cpp
@@ -107,9 +107,12 @@ namespace sharp {
std::string DateTime::to_iso8601() const
{
+ std::string retval;
char * iso8601 = g_time_val_to_iso8601(const_cast<GTimeVal*>(&m_date));
- std::string retval(iso8601);
- g_free(iso8601);
+ if(iso8601) {
+ retval = iso8601;
+ g_free(iso8601);
+ }
return retval;
}
diff --git a/src/sharp/xmlreader.cpp b/src/sharp/xmlreader.cpp
new file mode 100644
index 0000000..a036ef0
--- /dev/null
+++ b/src/sharp/xmlreader.cpp
@@ -0,0 +1,195 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#include "debug.hpp"
+
+#include "sharp/xmlreader.hpp"
+
+namespace sharp {
+
+ std::string xmlchar_to_string(const xmlChar * s)
+ {
+ return (s ? (const char*)s : "");
+ }
+
+ std::string xmlchar_to_string(xmlChar * s, bool freemem)
+ {
+ if(s == NULL) {
+ return "";
+ }
+ std::string value = (const char*)s;
+ if(freemem) {
+ xmlFree(s);
+ }
+ return value;
+ }
+
+ XmlReader::XmlReader()
+ : m_reader(NULL)
+ , m_error(false)
+ {
+ m_error = true;
+ }
+
+ XmlReader::XmlReader(const std::string & filename)
+ : m_reader(NULL)
+ , m_error(false)
+ {
+ m_reader = xmlNewTextReaderFilename(filename.c_str());
+ m_error = (m_reader == NULL);
+ if(m_reader) {
+ setup_error_handling();
+ }
+ }
+
+
+ XmlReader::~XmlReader()
+ {
+ close();
+ }
+
+
+ /** load the buffer from the s
+ * The parser is reset.
+ */
+ void XmlReader::load_buffer(const std::string &s)
+ {
+ close();
+ /** we copy the string. It shouldn't be a big deal as the strings
+ * are copy on write.
+ */
+ m_buffer = s;
+ m_reader = xmlReaderForMemory(m_buffer.c_str(), m_buffer.size(), "",
+ "UTF-8", 0);//XML_PARSE_RECOVER);
+ m_error = (m_reader == NULL);
+ if(m_reader) {
+ setup_error_handling();
+ }
+ }
+
+
+ /** read the next node */
+ bool XmlReader::read()
+ {
+ if(m_error) {
+ return false;
+ }
+ int res = xmlTextReaderRead(m_reader);
+ return (res > 0);
+ }
+
+ xmlReaderTypes XmlReader::get_node_type()
+ {
+ int type = xmlTextReaderNodeType(m_reader);
+ if(type == -1) {
+ m_error = true;
+ }
+ return (xmlReaderTypes)type;
+ }
+
+ std::string XmlReader::get_name()
+ {
+ return xmlchar_to_string(xmlTextReaderConstName(m_reader));
+ }
+
+ std::string XmlReader::get_attribute(const char * name)
+ {
+ return xmlchar_to_string(xmlTextReaderGetAttribute(m_reader, (const xmlChar*)name), true);
+ }
+
+ std::string XmlReader::get_value()
+ {
+ return xmlchar_to_string(xmlTextReaderConstValue(m_reader));
+ }
+
+ std::string XmlReader::read_string()
+ {
+ return xmlchar_to_string(xmlTextReaderReadString(m_reader), true);
+ }
+
+ std::string XmlReader::read_inner_xml()
+ {
+ return xmlchar_to_string(xmlTextReaderReadInnerXml(m_reader), true);
+ }
+
+ std::string XmlReader::read_outer_xml()
+ {
+ return xmlchar_to_string(xmlTextReaderReadOuterXml(m_reader), true);
+ }
+
+ bool XmlReader::move_to_next_attribute()
+ {
+ if(m_error) {
+ return false;
+ }
+ int res = xmlTextReaderMoveToNextAttribute(m_reader);
+ return (res > 0);
+ }
+
+ bool XmlReader::read_attribute_value()
+ {
+ if(m_error) {
+ return false;
+ }
+ int res = xmlTextReaderReadAttributeValue(m_reader);
+ return (res > 0);
+ }
+
+
+ void XmlReader::close()
+ {
+ if(m_reader) {
+ xmlFreeTextReader(m_reader);
+ m_reader = NULL;
+ }
+ m_error = true;
+ }
+
+
+ void XmlReader::setup_error_handling()
+ {
+ xmlTextReaderErrorFunc func = NULL;
+ void* arg = NULL;
+
+ // We respect any other error handlers already setup:
+ xmlTextReaderGetErrorHandler(m_reader, &func, &arg);
+ if(!func)
+ {
+ func = (xmlTextReaderErrorFunc)&XmlReader::error_handler;
+ xmlTextReaderSetErrorHandler(m_reader, func, this);
+ }
+ }
+
+
+ void XmlReader::error_handler(void* arg, const char* msg,
+ int severity, void* locator)
+ {
+ XmlReader* self = (XmlReader*)arg;
+ self->m_error = true;
+ ERR_OUT("XML error %s", msg ? msg : "unknown parse error");
+ }
+
+}
diff --git a/src/sharp/xmlreader.hpp b/src/sharp/xmlreader.hpp
new file mode 100644
index 0000000..ada71a3
--- /dev/null
+++ b/src/sharp/xmlreader.hpp
@@ -0,0 +1,86 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+
+#ifndef __SHARP_XMLREADER_HPP_
+#define __SHARP_XMLREADER_HPP_
+
+#include <string>
+
+#include <boost/noncopyable.hpp>
+#include <libxml/xmlreader.h>
+
+namespace sharp {
+
+class XmlReader
+ : public boost::noncopyable
+{
+public:
+ /** Create a XmlReader to read from a buffer */
+ XmlReader();
+ /** Create a XmlReader to read from a file */
+ XmlReader(const std::string & filename);
+ ~XmlReader();
+
+ /** load the buffer from the s
+ * The parser is reset.
+ */
+ void load_buffer(const std::string &s);
+
+
+ /** read the next node
+ * return false if it couldn't be read. (either end or error)
+ */
+ bool read();
+
+ xmlReaderTypes get_node_type();
+
+ std::string get_name();
+ std::string get_attribute(const char *);
+ std::string get_value();
+ std::string read_string();
+ std::string read_inner_xml();
+ std::string read_outer_xml();
+ bool move_to_next_attribute();
+ bool read_attribute_value();
+
+ void close();
+private:
+
+ void setup_error_handling();
+ static void error_handler(void* arg, const char* msg, int severity, void* locator);
+
+ std::string m_buffer;
+ xmlTextReaderPtr m_reader;
+ // error signaling
+ bool m_error;
+};
+
+
+}
+
+
+#endif
diff --git a/src/test/xmlreadertest.cpp b/src/test/xmlreadertest.cpp
new file mode 100644
index 0000000..6a440c8
--- /dev/null
+++ b/src/test/xmlreadertest.cpp
@@ -0,0 +1,81 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+
+#include <boost/test/minimal.hpp>
+
+
+#include "sharp/xmlreader.hpp"
+
+using namespace sharp;
+
+int test_main(int /*argc*/, char ** /*argv*/)
+{
+ XmlReader xml;
+
+ std::string content = "<note-content xmlns:link=\"http://beatniksoftware.com/tomboy/link\">"
+ "Start Here\n\n"
+ "<bold>Welcome to Gnote!</bold>\n\n"
+ "Use this \"Start Here\" note to begin organizing "
+ "your ideas and thoughts.\n\n"
+ "You can create new notes to hold your ideas by "
+ "selecting the \"Create New Note\" item from the "
+ "Gnote Notes menu in your GNOME Panel. "
+ "Your note will be saved automatically.\n\n"
+ "Then organize the notes you create by linking "
+ "related notes and ideas together!\n\n"
+ "We've created a note called "
+ "<link:internal>Using Links in Gnote</link:internal>. "
+ "Notice how each time we type <link:internal>Using "
+ "Links in Gnote</link:internal> it automatically "
+ "gets underlined? Click on the link to open the note."
+ "</note-content>";
+
+ xml.load_buffer(content);
+
+ BOOST_CHECK(xml.read());
+ BOOST_CHECK(xml.get_node_type() == XML_READER_TYPE_ELEMENT);
+ BOOST_CHECK(xml.get_name() == "note-content");
+ BOOST_CHECK(xml.get_attribute("xmlns:link") == "http://beatniksoftware.com/tomboy/link");
+
+#if 0
+ BOOST_CHECK(xml.read_inner_xml() == "Start Here\n\n"
+ "<bold>Welcome to Gnote!</bold>\n\n"
+ "Use this \"Start Here\" note to begin organizing "
+ "your ideas and thoughts.\n\n"
+ "You can create new notes to hold your ideas by "
+ "selecting the \"Create New Note\" item from the "
+ "Gnote Notes menu in your GNOME Panel. "
+ "Your note will be saved automatically.\n\n"
+ "Then organize the notes you create by linking "
+ "related notes and ideas together!\n\n"
+ "We've created a note called "
+ "<link:internal>Using Links in Gnote</link:internal>. "
+ "Notice how each time we type <link:internal>Using "
+ "Links in Gnote</link:internal> it automatically "
+ "gets underlined? Click on the link to open the note.");
+#endif
+ BOOST_CHECK(xml.read());
+ BOOST_CHECK(xml.get_node_type() == XML_READER_TYPE_TEXT);
+
+ return 0;
+}
+
diff --git a/src/utils.cpp b/src/utils.cpp
index 6dd96d1..80f22fa 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -36,8 +36,8 @@
#include <gtkmm/image.h>
#include <gtkmm/stock.h>
#include <gtkmm/textbuffer.h>
-#include <libxml++/parsers/textreader.h>
+#include "sharp/xmlreader.hpp"
#include "sharp/xmlwriter.hpp"
#include "sharp/string.hpp"
#include "sharp/uri.hpp"
@@ -528,12 +528,13 @@ namespace gnote {
// this will do for now.
std::string builder;
- xmlpp::TextReader xml((const xmlChar *)source.c_str(), source.size());
+ sharp::XmlReader xml;
+ xml.load_buffer(source);
while (xml.read ()) {
switch (xml.get_node_type()) {
- case xmlpp::TextReader::Text:
- case xmlpp::TextReader::Whitespace:
+ case XML_READER_TYPE_TEXT:
+ case XML_READER_TYPE_WHITESPACE:
builder += xml.get_value();
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]