Added possibility to toggle xml validation

BZ: 184054

It was not possible to enable/disable xml file validation.
The parameter framework only relied on the LIBXML_SCHEMAS flag.

This patchs implements a new constructor for XmlFiles
which allows enabling/disabling xml/xsd check.

Change-Id: I32d220a42bb27f4ce685f07cb194e78e76f44a5d
Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk
index fabbf84..a5ab4e1 100755
--- a/xmlserializer/Android.mk
+++ b/xmlserializer/Android.mk
@@ -60,8 +60,6 @@
 common_shared_libraries := libicuuc
 common_static_libraries := libxml2
 
-common_ldlibs := -Lexternal/libxml2/lib
-
 #############################
 # Target build
 
@@ -82,8 +80,6 @@
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries) libstlport
 LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
 
-LOCAL_LDLIBS += $(common_ldlibs)
-
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
 
 include $(BUILD_STATIC_LIBRARY)
@@ -100,13 +96,10 @@
 
 LOCAL_CFLAGS := $(common_cflags)
 
-LOCAL_C_INCLUDES += \
-    $(common_c_includes)
+LOCAL_C_INCLUDES += $(common_c_includes)
 
 LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)-host
-LOCAL_STATIC_LIBRARIES := $(common_static_libraries)
-
-LOCAL_LDLIBS += $(common_ldlibs)
+LOCAL_STATIC_LIBRARIES := libxml2-schemas
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
 
diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp
index 476e415..5e53a81 100644
--- a/xmlserializer/XmlDocSource.cpp
+++ b/xmlserializer/XmlDocSource.cpp
@@ -36,14 +36,16 @@
 // Schedule for libxml2 library
 bool CXmlDocSource::_bLibXml2CleanupScheduled;
 
-CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode):
+CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode,
+                             bool bValidateWithSchema) :
       _pDoc(pDoc),
       _pRootNode(pRootNode),
       _strXmlSchemaFile(""),
       _strRootElementType(""),
       _strRootElementName(""),
       _strNameAttrituteName(""),
-      _bNameCheck(false)
+      _bNameCheck(false),
+      _bValidateWithSchema(bValidateWithSchema)
 {
     init();
 }
@@ -59,20 +61,41 @@
     _strRootElementType(strRootElementType),
     _strRootElementName(strRootElementName),
     _strNameAttrituteName(strNameAttrituteName),
-    _bNameCheck(true)
+    _bNameCheck(true),
+    _bValidateWithSchema(false)
 {
     init();
 }
 
 CXmlDocSource::CXmlDocSource(_xmlDoc* pDoc,
                              const string& strXmlSchemaFile,
-                             const string& strRootElementType) :
+                             const string& strRootElementType,
+                             bool bValidateWithSchema) :
     _pDoc(pDoc), _pRootNode(NULL),
     _strXmlSchemaFile(strXmlSchemaFile),
     _strRootElementType(strRootElementType),
     _strRootElementName(""),
     _strNameAttrituteName(""),
-    _bNameCheck(false)
+    _bNameCheck(false),
+    _bValidateWithSchema(bValidateWithSchema)
+{
+    init();
+}
+
+CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc,
+                             const string& strXmlSchemaFile,
+                             const string& strRootElementType,
+                             const string& strRootElementName,
+                             const string& strNameAttrituteName,
+                             bool bValidateWithSchema) :
+    _pDoc(pDoc),
+    _pRootNode(NULL),
+    _strXmlSchemaFile(strXmlSchemaFile),
+    _strRootElementType(strRootElementType),
+    _strRootElementName(strRootElementName),
+    _strNameAttrituteName(strNameAttrituteName),
+    _bNameCheck(true),
+    _bValidateWithSchema(bValidateWithSchema)
 {
     init();
 }
@@ -118,12 +141,15 @@
         return false;
     }
 
-    // Validate
-    if (!isInstanceDocumentValid()) {
+    // Validate if necessary
+    if (_bValidateWithSchema)
+    {
+        if (!isInstanceDocumentValid()) {
 
-        serializingContext.setError("Document is not valid");
+            serializingContext.setError("Document is not valid");
 
-        return false;
+            return false;
+        }
     }
 
     // Check Root element type
diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h
index 9b780e5..fd9a693 100644
--- a/xmlserializer/XmlDocSource.h
+++ b/xmlserializer/XmlDocSource.h
@@ -52,8 +52,9 @@
       *
       * @param[out] pDoc a pointer to the xml document that will be filled by the class
       * @param[in] pRootNode a pointer to the root element of the document.
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
-    CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL);
+    CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL, bool bValidateWithSchema = false);
 
     /**
       * Constructor
@@ -76,8 +77,26 @@
       * @param[out] pDoc a pointer to the xml document that will be filled by the class
       * @param[in] strXmlSchemaFile a string containing the path to the schema file
       * @param[in] strRootElementType a string containing the root element type
+      * @param[in] strRootElementName a string containing the root element name
+      * @param[in] strNameAttributeName a string containing the name of the root name attribute
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
-    CXmlDocSource(_xmlDoc* pDoc, const string& strXmlSchemaFile, const string& strRootElementType);
+    CXmlDocSource(_xmlDoc* pDoc,
+                           const string& strXmlSchemaFile,
+                           const string& strRootElementType,
+                           const string& strRootElementName,
+                           const string& strNameAttrituteName,
+                             bool bValidateWithSchema);
+
+    /**
+      * Constructor
+      *
+      * @param[out] pDoc a pointer to the xml document that will be filled by the class
+      * @param[in] strXmlSchemaFile a string containing the path to the schema file
+      * @param[in] strRootElementType a string containing the root element type
+      */
+    CXmlDocSource(_xmlDoc* pDoc, const string& strXmlSchemaFile, const string& strRootElementType,
+                             bool bValidateWithSchema);
 
     /**
       * Destructor
@@ -197,4 +216,9 @@
       * Boolean that enables the root element name attribute check
       */
     bool _bNameCheck;
+
+    /**
+      * Boolean that enables the validation via xsd files
+      */
+    bool _bValidateWithSchema;
 };
diff --git a/xmlserializer/XmlFileDocSource.cpp b/xmlserializer/XmlFileDocSource.cpp
index 0fb3962..908c13b 100644
--- a/xmlserializer/XmlFileDocSource.cpp
+++ b/xmlserializer/XmlFileDocSource.cpp
@@ -38,22 +38,26 @@
                                      const string& strXmlSchemaFile,
                                      const string& strRootElementType,
                                      const string& strRootElementName,
-                                     const string& strNameAttrituteName) :
+                                     const string& strNameAttrituteName,
+                                     bool bValidateWithSchema) :
         base(readFile(strXmlInstanceFile),
              strXmlSchemaFile,
              strRootElementType,
              strRootElementName,
-             strNameAttrituteName),
+             strNameAttrituteName,
+             bValidateWithSchema),
         _strXmlInstanceFile(strXmlInstanceFile)
 {
 }
 
 CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
                                      const string& strXmlSchemaFile,
-                                     const string& strRootElementType) :
+                                     const string& strRootElementType,
+                                     bool bValidateWithSchema) :
         base(readFile(strXmlInstanceFile),
              strXmlSchemaFile,
-             strRootElementType),
+             strRootElementType,
+             bValidateWithSchema),
         _strXmlInstanceFile(strXmlInstanceFile)
 {
 }
diff --git a/xmlserializer/XmlFileDocSource.h b/xmlserializer/XmlFileDocSource.h
index 7a8bb8d..b8b0c6b 100644
--- a/xmlserializer/XmlFileDocSource.h
+++ b/xmlserializer/XmlFileDocSource.h
@@ -47,20 +47,24 @@
       * @param[in] strRootElementType a string containing the root element type
       * @param[in] strRootElementName a string containing the root element name
       * @param[in] strNameAttributeName a string containing the name of the root name attribute
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
     CXmlFileDocSource(const string& strXmlInstanceFile,
                       const string& strXmlSchemaFile,
                       const string& strRootElementType,
                       const string& strRootElementName,
-                      const string& strNameAttrituteName);
+                      const string& strNameAttrituteName,
+                      bool bValidateWithSchema);
     /**
       * Constructor
       *
       * @param[in] strXmlInstanceFile a string containing the path to the xml file
       * @param[in] strXmlSchemaFile a string containing the path to the schema file
       * @param[in] strRootElementType a string containing the root element type
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
-    CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType);
+    CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType,
+            bool bValidateWithSchema);
 
     /**
       * CXmlDocSource method implementation.
diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp
index b60ee41..85abbfc 100644
--- a/xmlserializer/XmlMemoryDocSource.cpp
+++ b/xmlserializer/XmlMemoryDocSource.cpp
@@ -38,8 +38,10 @@
                                          const string& strRootElementType,
                                          const string& strXmlSchemaFile,
                                          const string& strProduct,
-                                         const string& strVersion):
-     base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
+                                         const string& strVersion,
+                                         bool bValidateWithSchema):
+     base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str()),
+             bValidateWithSchema),
      _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true),
      _strProduct(strProduct), _strVersion(strVersion)
 {
@@ -47,8 +49,10 @@
 }
 
 CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource,
-                                         const string& strRootElementType):
-    base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
+                                         const string& strRootElementType,
+                                         bool bValidateWithSchema):
+    base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str()),
+            bValidateWithSchema),
     _pXmlSource(pXmlSource), _bWithHeader(false)
 {
     init();
diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h
index 1e549ff..072cb06 100644
--- a/xmlserializer/XmlMemoryDocSource.h
+++ b/xmlserializer/XmlMemoryDocSource.h
@@ -50,10 +50,12 @@
       * @param[in] strXmlSchemaFile a string containing the path to the schema file
       * @param[in] strProduct a string containing the product name
       * @param[in] strVersion a string containing the version number
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
     CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType,
                         const string& strXmlSchemaFile, const string& strProduct,
-                        const string& strVersion);
+                        const string& strVersion,
+                        bool bValidateWithSchema);
 
     /**
       * Constructor
@@ -61,8 +63,9 @@
       * @param[in] pXmlSource a pointer to a parameter-framework structure that can generate
       * an xml description of itself
       * @param[in] strRootElementType a string containing the root element type
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
-    CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType);
+    CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, bool bValidateWithSchema);
 
     /**
       * Implementation of CXmlDocSource::populate() method.
diff --git a/xmlserializer/XmlStringDocSource.cpp b/xmlserializer/XmlStringDocSource.cpp
index b360322..12307f2 100644
--- a/xmlserializer/XmlStringDocSource.cpp
+++ b/xmlserializer/XmlStringDocSource.cpp
@@ -37,12 +37,14 @@
                                          const string& strXmlSchemaFile,
                                          const string& strRootElementType,
                                          const string& strRootElementName,
-                                         const string& strNameAttrituteName) :
+                                         const string& strNameAttrituteName,
+                                         bool bValidateWithSchema) :
     base(xmlReadMemory(strXmlInput.c_str(), strXmlInput.size(), "", NULL, 0),
-            strXmlSchemaFile,
-            strRootElementType,
-            strRootElementName,
-            strNameAttrituteName)
+         strXmlSchemaFile,
+         strRootElementType,
+         strRootElementName,
+         strNameAttrituteName,
+         bValidateWithSchema)
 {
 }
 
diff --git a/xmlserializer/XmlStringDocSource.h b/xmlserializer/XmlStringDocSource.h
index 312d72b..d7cde9b 100644
--- a/xmlserializer/XmlStringDocSource.h
+++ b/xmlserializer/XmlStringDocSource.h
@@ -47,12 +47,14 @@
       * @param[in] strRootElementType a string containing the root element type
       * @param[in] strRootElementName a string containing the root element name
       * @param[in] strNameAttributeName a string containing the name of the root name attribute
+      * @param[in] bValidateWithSchema a boolean that toggles schema validation
       */
     CXmlStringDocSource(const string& strXmlInput,
                         const string& strXmlSchemaFile,
                         const string& strRootElementType,
                         const string& strRootElementName,
-                        const string& strNameAttrituteName);
+                        const string& strNameAttrituteName,
+                        bool bValidateWithSchema);
 
     /**
       * CXmlDocSource method implementation.