arnied, libi2ncommon, arnielizer, ui: (tomj) moved common xml code to own lib2ncommon...
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 2 Sep 2008 11:24:46 +0000 (11:24 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 2 Sep 2008 11:24:46 +0000 (11:24 +0000)
Makefile.am
configure.in
libi2ncommon.spec
libi2ncommon_xml.pc.in [new file with mode: 0644]
xmllib/Makefile.am [new file with mode: 0644]
xmllib/xmlcommon.cpp [new file with mode: 0644]
xmllib/xmlcommon.hpp [new file with mode: 0644]

index b4a6b0a..92a4416 100644 (file)
@@ -2,11 +2,11 @@
 # have all needed files, that a GNU package needs
 AUTOMAKE_OPTIONS = foreign 1.4
 
-SUBDIRS = src configlib test
+SUBDIRS = src configlib xmllib test
 
 # Install the pkg-config file:
 pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libi2ncommon.pc libi2ncommon_config.pc
+pkgconfig_DATA = libi2ncommon.pc libi2ncommon_config.pc libi2ncommon_xml.pc
 
 if AUTOCHECK
 all: config.h
index 0dfdac1..4e6b320 100644 (file)
@@ -25,6 +25,10 @@ AC_ARG_WITH(optimize,[  --with-optimize      compile with optimizing],
 
 AM_CONDITIONAL(AUTOCHECK, test "$enable_autocheck" = yes)
 
+PKG_CHECK_MODULES(LIBXMLPP, libxml++-2.6 >= 0.2.1)
+AC_SUBST(LIBXMLPP_CFLAGS)
+AC_SUBST(LIBXMLPP_LIBS)
+
 PKG_CHECK_MODULES(LIBGETTEXT, libgettext >= 0.0.0)
 AC_SUBST(LIBGETTEXT_CFLAGS)
 AC_SUBST(LIBGETTEXT_LIBS)
@@ -35,5 +39,5 @@ AC_SUBST(LIBICONV_LIBS)
 
 AM_PATH_CPPUNIT(1.8.0)
 
-AC_OUTPUT(Doxyfile Makefile configlib/Makefile libi2ncommon.pc src/Makefile \
-       test/Makefile libi2ncommon_config.pc)
+AC_OUTPUT(Doxyfile Makefile configlib/Makefile xmllib/Makefile libi2ncommon.pc src/Makefile \
+       test/Makefile libi2ncommon_config.pc libi2ncommon_xml.pc)
index 9235b41..4fcde73 100644 (file)
@@ -37,6 +37,13 @@ library with a config module.
 The config module provides a global configuration system with decentralized
 declaration of the config variables.
 
+%package xml
+Summary:    library with a xml module
+Group:      Intranator
+Requires:   libi2ncommon = %{version}
+
+%description xml
+The xml module provides common xml functions.
 
 %prep
 %setup -q
@@ -75,3 +82,7 @@ rm -fr $RPM_BUILD_ROOT
 %doc LICENSE
 %{prefix}/lib/libi2ncommon_config.so*
 
+%files xml
+%defattr(-,root,root)
+%doc LICENSE
+%{prefix}/lib/libi2ncommon_xml.so*
diff --git a/libi2ncommon_xml.pc.in b/libi2ncommon_xml.pc.in
new file mode 100644 (file)
index 0000000..fa7f5ac
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libi2ncommon_xml
+Description: library with xml module common in some Intra2net programs
+Requires: libxml++-2.6 libi2ncommon
+Version: @VERSION@
+Libs: -L${libdir} -li2ncommon_xml
+Cflags: -I${includedir}
diff --git a/xmllib/Makefile.am b/xmllib/Makefile.am
new file mode 100644 (file)
index 0000000..4c22119
--- /dev/null
@@ -0,0 +1,16 @@
+# set the include path found by configure
+INCLUDES = -I$(top_srcdir)/src $(all_includes) @LIBXMLPP_CFLAGS@ @LIBGETTEXT_CFLAGS@
+METASOURCES = AUTO
+
+lib_LTLIBRARIES = libi2ncommon_xml.la
+
+include_HEADERS = xmlcommon.hpp
+
+# Note:  If you specify a:b:c as the version in the next line,
+#  the library that is made has version (a-c).c.b.  In this
+#  example, the version is 2.1.2. (3:2:1)
+
+libi2ncommon_xml_la_LDFLAGS = -version-info @LIBI2NCOMMON_LIB_VERSION@
+
+libi2ncommon_xml_la_LIBADD = @LIBXMLPP_LIBS@
+libi2ncommon_xml_la_SOURCES = xmlcommon.cpp
diff --git a/xmllib/xmlcommon.cpp b/xmllib/xmlcommon.cpp
new file mode 100644 (file)
index 0000000..6f53be1
--- /dev/null
@@ -0,0 +1,81 @@
+/***************************************************************************
+                   xmlcommon.cpp - Common XML functions
+                             -------------------
+    begin                : Tue Apr 27 2004
+    copyright            : (C) 2004 by Intra2net AG
+    email                : info@intra2net.com
+ ***************************************************************************/
+
+#include <xmlcommon.hpp>
+#include <exception.hxx>
+#include <sstream>
+#include <vector>
+
+using namespace xmlpp;
+using namespace std;
+
+namespace I2n {
+
+void xml_validate_dtd(Node *root, const std::string &subsetname, const std::string &dtdname)
+{
+    // Create empty document, set DTD
+    Document doc;
+    doc.set_internal_subset(subsetname, "", dtdname);
+    Element *newRoot = doc.create_root_node(root->get_name(), "", "");
+    
+    // Import nodes
+    Node::NodeList list = root->get_children();
+    Node::NodeList::iterator list_end = list.end();
+    for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list_end; ++iter)
+        newRoot->import_node(*iter);
+
+    // Parse XML again to validate it
+    DomParser parser;
+    parser.set_validate();
+    parser.parse_memory(doc.write_to_string_formatted());
+}
+
+std::string xml_get_child_content(xmlpp::Node *base, const std::string &elementname)
+{
+    vector<xmlpp::Node*> nodes;
+
+    // Read in value
+    nodes = base->find(elementname);
+
+    if (nodes.size() != 1)
+    {
+        ostringstream os;
+        os << "xml parse error at line " << base->get_line() << ": element ambiguous or not found: " << elementname;
+        throw EXCEPTION(runtime_error_src,os.str());
+    }
+
+    return xml_get_text_content(nodes[0], elementname);
+}
+
+std::string xml_get_text_content(xmlpp::Node *node, const std::string &elementname)
+{
+    if (node->get_children().size() <= 0)
+    {
+        ostringstream os;
+        os << "xml parse error at line " << node->get_line() << ": element content not found in " << elementname;
+        throw EXCEPTION(runtime_error_src,os.str());
+    }
+
+    xmlpp::Node::NodeList childs = node->get_children();
+    xmlpp::Node::NodeList::iterator text = childs.begin();
+    const xmlpp::ContentNode *nodeText=dynamic_cast<const xmlpp::ContentNode*>(*text);
+
+    if (nodeText)
+        return nodeText->get_content();
+    else
+    {
+        ostringstream os;
+        os << "xml parse error at line " << (*text)->get_line() << ": element " << elementname << " does not contain content";
+        throw EXCEPTION(runtime_error_src,os.str());
+    }
+
+    // not reached
+    return "";
+}
+
+}
diff --git a/xmllib/xmlcommon.hpp b/xmllib/xmlcommon.hpp
new file mode 100644 (file)
index 0000000..b345ff4
--- /dev/null
@@ -0,0 +1,24 @@
+/***************************************************************************
+                   xmlcommon.hxx - Common XML functions
+                             -------------------
+    begin                : Tue Apr 27 2004
+    copyright            : (C) 2004 by Intra2net AG
+    email                : info@intra2net.com
+ ***************************************************************************/
+
+#ifndef __XMLCOMMON
+#define __XMLCOMMON
+
+#include <libxml++/libxml++.h>
+#include <string>
+
+namespace I2n {
+
+void xml_validate_dtd(xmlpp::Node *root, const std::string &subsetname, const std::string &dtdname);
+
+std::string xml_get_child_content(xmlpp::Node *base, const std::string &elementname);
+std::string xml_get_text_content(xmlpp::Node *node, const std::string &elementname);
+
+}
+
+#endif