From cec86c1904a45a7027218adb3d34c8764bdfcc38 Mon Sep 17 00:00:00 2001 From: Georges-Henri Baron Date: Tue, 4 Sep 2012 17:30:28 +0200 Subject: PFW: Add setDomainsXML command to import domains from string BZ: 55694 Unable possibility to import the configurable domains from a string Create one command that can be called through the command line of the parameter-framework. The command setDomainXML allows to import configurable domains with settings from a string provided as first argument containing the xml description. Change-Id: I6db7ccb8ba61b5e4c8ba81579a68f40e887d1534 Signed-off-by: Georges-Henri Baron Reviewed-on: http://android.intel.com:8080/65408 Reviewed-by: cactus Reviewed-by: Dixon, CharlesX Reviewed-by: Rocard, KevinX Tested-by: Dixon, CharlesX Reviewed-by: buildbot Tested-by: buildbot --- xmlserializer/Android.mk | 3 +- xmlserializer/XmlDocSink.cpp | 4 +- xmlserializer/XmlDocSink.h | 32 ++++++- xmlserializer/XmlDocSource.cpp | 181 ++++++++++++++++++++++++++++++++--- xmlserializer/XmlDocSource.h | 151 +++++++++++++++++++++++++++-- xmlserializer/XmlFileDocSink.cpp | 10 +- xmlserializer/XmlFileDocSink.h | 29 +++++- xmlserializer/XmlFileDocSource.cpp | 128 +++++-------------------- xmlserializer/XmlFileDocSource.h | 73 ++++++++------ xmlserializer/XmlMemoryDocSink.cpp | 7 +- xmlserializer/XmlMemoryDocSink.h | 24 ++++- xmlserializer/XmlMemoryDocSource.cpp | 24 +++-- xmlserializer/XmlMemoryDocSource.h | 55 +++++++++-- xmlserializer/XmlStringDocSink.cpp | 3 +- xmlserializer/XmlStringDocSink.h | 29 ++++-- xmlserializer/XmlStringDocSource.cpp | 44 +++++++++ xmlserializer/XmlStringDocSource.h | 60 ++++++++++++ 17 files changed, 647 insertions(+), 210 deletions(-) create mode 100644 xmlserializer/XmlStringDocSource.cpp create mode 100644 xmlserializer/XmlStringDocSource.h (limited to 'xmlserializer') diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk index 8ddb700..630cc34 100644 --- a/xmlserializer/Android.mk +++ b/xmlserializer/Android.mk @@ -12,7 +12,8 @@ COMMON_SRC_FILES := \ XmlMemoryDocSource.cpp \ XmlStringDocSink.cpp \ XmlFileDocSink.cpp \ - XmlFileDocSource.cpp + XmlFileDocSource.cpp \ + XmlStringDocSource.cpp COMMON_MODULE := libxmlserializer diff --git a/xmlserializer/XmlDocSink.cpp b/xmlserializer/XmlDocSink.cpp index dedfcf8..2a07d74 100644 --- a/xmlserializer/XmlDocSink.cpp +++ b/xmlserializer/XmlDocSink.cpp @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -19,7 +19,6 @@ * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. * - * CREATED: 2012-08-10 */ #include "XmlDocSink.h" @@ -28,7 +27,6 @@ CXmlDocSink::CXmlDocSink() { } -// Source Processing bool CXmlDocSink::process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) { if (!xmlDocSource.populate(serializingContext)) { diff --git a/xmlserializer/XmlDocSink.h b/xmlserializer/XmlDocSink.h index d341ecf..56a806f 100644 --- a/xmlserializer/XmlDocSink.h +++ b/xmlserializer/XmlDocSink.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -19,24 +19,46 @@ * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. * - * CREATED: 2012-08-10 */ #pragma once - #include "XmlDocSource.h" #include "XmlSerializingContext.h" +/** + * The CXmlDocSink class defines how to use a CXmlDocSource. + * The interaction between the xml source and xml sink is defined + * in the process method of CXmlDocSink. One can subclass CXmlDocSink + * for different purpose by implementing the doProcess method and then + * use it with any existing implementation of CXmlDocSource. + */ class CXmlDocSink { public: CXmlDocSink(); - // Source processing + /** + * Method to be called to use an xmlDocSource. + * Any subclass of XmlDocSink must implement the doProcess + * method that will define how to use the xmlDocSource. + * + * @param[in] xmlDocSource a CXmlDocSource reference + * @param[in] serializingContext a CXmlSerializing Context reference + * + * @return true is there was no error during the processing of xmlDocSource + */ bool process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); virtual ~CXmlDocSink() {} private: - // Handle for subclasses to process the source + /** + * Handle for subclasses to process the source. + * This method will define what to do with the xmlDocSource. + * + * @param[in] xmlDocSource a CXmlDocSource reference + * @param[in] serializingContext a CXmlSerializing Context reference + * + * @return true is there was no error during the processing of xmlDocSource + */ virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) = 0; }; diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp index e876f16..144b636 100644 --- a/xmlserializer/XmlDocSource.cpp +++ b/xmlserializer/XmlDocSource.cpp @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,31 +18,55 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ + #include "XmlDocSource.h" #include +#include #include // Schedule for libxml2 library bool CXmlDocSource::_bLibXml2CleanupScheduled; CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode): - _pDoc(pDoc), _pRootNode(pRootNode) + _pDoc(pDoc), + _pRootNode(pRootNode), + _strXmlSchemaFile(""), + _strRootElementType(""), + _strRootElementName(""), + _strNameAttrituteName(""), + _bNameCheck(false) { - if (!_bLibXml2CleanupScheduled) { - - // Schedule cleanup - atexit(xmlCleanupParser); - - _bLibXml2CleanupScheduled = true; - } + init(); +} - if (!_pRootNode) { +CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName) : + _pDoc(pDoc), + _pRootNode(NULL), + _strXmlSchemaFile(strXmlSchemaFile), + _strRootElementType(strRootElementType), + _strRootElementName(strRootElementName), + _strNameAttrituteName(strNameAttrituteName), + _bNameCheck(true) +{ + init(); +} - _pRootNode = xmlDocGetRootElement(_pDoc); - } +CXmlDocSource::CXmlDocSource(_xmlDoc* pDoc, + const string& strXmlSchemaFile, + const string& strRootElementType) : + _pDoc(pDoc), _pRootNode(NULL), + _strXmlSchemaFile(strXmlSchemaFile), + _strRootElementType(strRootElementType), + _strRootElementName(""), + _strNameAttrituteName(""), + _bNameCheck(false) +{ + init(); } CXmlDocSource::~CXmlDocSource() @@ -54,7 +78,6 @@ CXmlDocSource::~CXmlDocSource() } } -// Root element void CXmlDocSource::getRootElement(CXmlElement& xmlRootElement) const { xmlRootElement.setXmlElement(_pRootNode); @@ -77,3 +100,131 @@ _xmlDoc* CXmlDocSource::getDoc() const return _pDoc; } +bool CXmlDocSource::validate(CXmlSerializingContext& serializingContext) +{ + // Check that the doc has been created + if (!_pDoc) { + + serializingContext.setError("Could not parse document "); + + return false; + } + + // Validate + if (!isInstanceDocumentValid()) { + + serializingContext.setError("Document is not valid"); + + return false; + } + + // Check Root element type + if (getRootElementName() != _strRootElementType) { + + serializingContext.setError("Error: Wrong XML structure document "); + serializingContext.appendLineToError("Root Element " + getRootElementName() + + " mismatches expected type " + _strRootElementType); + + return false; + } + + if (_bNameCheck) { + + string strRootElementNameCheck = getRootElementAttributeString(_strNameAttrituteName); + + // Check Root element name attribute (if any) + if (!_strRootElementName.empty() && strRootElementNameCheck != _strRootElementName) { + + serializingContext.setError("Error: Wrong XML structure document "); + serializingContext.appendLineToError(_strRootElementType + " element " + + _strRootElementName + " mismatches expected " + + _strRootElementType + " type " + + strRootElementNameCheck); + + return false; + } + } + + return true; +} + +void CXmlDocSource::init() +{ + if (!_bLibXml2CleanupScheduled) { + + // Schedule cleanup + atexit(xmlCleanupParser); + + _bLibXml2CleanupScheduled = true; + } + + if (!_pRootNode) { + + _pRootNode = xmlDocGetRootElement(_pDoc); + } +} + +bool CXmlDocSource::isInstanceDocumentValid() +{ +#ifdef LIBXML_SCHEMAS_ENABLED + xmlDocPtr pSchemaDoc = xmlReadFile(_strXmlSchemaFile.c_str(), NULL, XML_PARSE_NONET); + + if (!pSchemaDoc) { + // Unable to load Schema + return false; + } + + xmlSchemaParserCtxtPtr pParserCtxt = xmlSchemaNewDocParserCtxt(pSchemaDoc); + + if (!pParserCtxt) { + + // Unable to create schema context + xmlFreeDoc(pSchemaDoc); + return false; + } + + // Get Schema + xmlSchemaPtr pSchema = xmlSchemaParse(pParserCtxt); + + if (!pSchema) { + + // Invalid Schema + xmlSchemaFreeParserCtxt(pParserCtxt); + xmlFreeDoc(pSchemaDoc); + return false; + } + xmlSchemaValidCtxtPtr pValidationCtxt = xmlSchemaNewValidCtxt(pSchema); + + if (!pValidationCtxt) { + + // Unable to create validation context + xmlSchemaFree(pSchema); + xmlSchemaFreeParserCtxt(pParserCtxt); + xmlFreeDoc(pSchemaDoc); + return false; + } + + xmlSetStructuredErrorFunc(this, schemaValidityStructuredErrorFunc); + + bool isDocValid = xmlSchemaValidateDoc(pValidationCtxt, _pDoc) == 0; + + xmlSchemaFreeValidCtxt(pValidationCtxt); + xmlSchemaFree(pSchema); + xmlSchemaFreeParserCtxt(pParserCtxt); + xmlFreeDoc(pSchemaDoc); + + return isDocValid; +#else + return true; +#endif +} + +void CXmlDocSource::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError) +{ + (void)pUserData; + +#ifdef LIBXML_SCHEMAS_ENABLED + // Display message + puts(pError->message); +#endif +} diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h index a59919e..1953425 100644 --- a/xmlserializer/XmlDocSource.h +++ b/xmlserializer/XmlDocSource.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,44 +18,175 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #pragma once - #include "XmlElement.h" #include "XmlSerializingContext.h" +#include struct _xmlDoc; struct _xmlNode; +struct _xmlError; +/** + * The CXmlDocSource is used by CXmlDocSink. + * The interaction between the xml source and xml sink is defined + * in the process method of CXmlDocSink. One can subclass CXmlDocSource + * for different purposes by implementing the populate method and then + * use it with any existing implementation of CXmlDocSink. + */ class CXmlDocSource { public: + /** + * Constructor + * + * @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. + */ CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL); + + /** + * 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 + * @param[in] strRootElementName a string containing the root element name + * @param[in] strNameAttributeName a string containing the name of the root name attribute + */ + CXmlDocSource(_xmlDoc* pDoc, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName); + + /** + * 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); + + /** + * Destructor + */ virtual ~CXmlDocSource(); - // Method Called by the CXmlDocSink::process method + /** + * Method called by the CXmlDocSink::process method. + * + * @param[out] serializingContext is used as error output + * + * @return false if there are any error + */ virtual bool populate(CXmlSerializingContext& serializingContext) = 0; - // Root element + /** + * Method that returns the root element of the Xml tree. + * + * @param[out] xmlRootElement a reference to the CXmleElement destination + */ void getRootElement(CXmlElement& xmlRootElement) const; + + /** + * Getter method. + * + * @return the root element's name + */ string getRootElementName() const; + + /** + * Getter method. + * Method that returns the root element's attribute with name matching strAttributeName. + * + * @param[in] strAttributeName is a string used to find the corresponding attribute + * + * @return the value of the root's attribute named as strAttributeName + */ string getRootElementAttributeString(const string& strAttributeName) const; - // Method that returns the xmlDoc contained in the Source. (Can be used in a Doc Sink) + /** + * Getter method. + * Method that returns the xmlDoc contained in the Source. + * (Can be used in a Doc Sink) + * + * @return the document _pDoc + */ _xmlDoc* getDoc() const; + /** + * Method that validates the Xml doc contained in pDoc + * + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ + virtual bool validate(CXmlSerializingContext& serializingContext); + protected: - // Doc + /** + * Doc + */ _xmlDoc* _pDoc; - // Root node + /** + * Root node + */ _xmlNode* _pRootNode; - // libxml2 library cleanup + /** + * libxml2 library cleanup + */ static bool _bLibXml2CleanupScheduled; + +private: + + /** + * Method that initializes class internal attributes in constructor + */ + void init(); + + /** Method that check the validity of the document with the xsd file. + * + * @return true if document is valid, false if any error occures + */ + bool isInstanceDocumentValid(); + + /** Validity error display method + * + * @param[in] pUserData pointer to the data to validate + * @param[out] pError is the xml error output + */ + static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); + + /** + * Schema file + */ + string _strXmlSchemaFile; + + /** + * Element type info + */ + string _strRootElementType; + + /** + * Element name info + */ + string _strRootElementName; + + /** + * Element name attribute info + */ + string _strNameAttrituteName; + + /** + * Boolean that enables the root element name attribute check + */ + bool _bNameCheck; }; diff --git a/xmlserializer/XmlFileDocSink.cpp b/xmlserializer/XmlFileDocSink.cpp index 4a2b13f..d59ead4 100644 --- a/xmlserializer/XmlFileDocSink.cpp +++ b/xmlserializer/XmlFileDocSink.cpp @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,8 +18,6 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #include "XmlFileDocSink.h" @@ -32,10 +30,12 @@ CXmlFileDocSink::CXmlFileDocSink(const string& strXmlInstanceFile): { } -bool CXmlFileDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +bool CXmlFileDocSink::doProcess(CXmlDocSource& xmlDocSource, + CXmlSerializingContext& serializingContext) { // Write file (formatted) - if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(), xmlDocSource.getDoc(), "UTF-8", 1) == -1) { + if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(), + xmlDocSource.getDoc(), "UTF-8", 1) == -1) { serializingContext.setError("Could not write file " + _strXmlInstanceFile); diff --git a/xmlserializer/XmlFileDocSink.h b/xmlserializer/XmlFileDocSink.h index d06365a..370d175 100644 --- a/xmlserializer/XmlFileDocSink.h +++ b/xmlserializer/XmlFileDocSink.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -19,22 +19,41 @@ * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. * - * CREATED: 2012-08-10 */ #pragma once - #include "XmlDocSink.h" +#include +/** + * Sink class that save the content of any CXmlDocSource into a file. + * The file path is defined in the constructor. + */ class CXmlFileDocSink : public CXmlDocSink { public: + /** + * Constructor + * + * @param[in] strXmlInstanceFile defines the path used to save the file. + */ CXmlFileDocSink(const string& strXmlInstanceFile); private: - // Source processing + /** + * Implementation of CXmlDocSink::doProcess() + * Write the content of the xmlDocSource to the file opened in strXmlInstanceFile using + * UTF-8 encoding + * + * @param[in] xmlDocSource is the source containing the Xml document + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); - // Instance file + /** + * Name of the instance file + */ string _strXmlInstanceFile; }; diff --git a/xmlserializer/XmlFileDocSource.cpp b/xmlserializer/XmlFileDocSource.cpp index f1094f1..4df2ad1 100644 --- a/xmlserializer/XmlFileDocSource.cpp +++ b/xmlserializer/XmlFileDocSource.cpp @@ -24,64 +24,33 @@ #include "XmlFileDocSource.h" #include -#include #define base CXmlDocSource - - -CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, const string& strRootElementName, const string& strNameAttrituteName) : - base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0)), _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _strRootElementName(strRootElementName), _strNameAttrituteName(strNameAttrituteName), _bNameCheck(true) +CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName) : + base(xmlReadFile(strXmlInstanceFile.c_str(),NULL, 0), + strXmlSchemaFile, + strRootElementType, + strRootElementName, + strNameAttrituteName), + _strXmlInstanceFile(strXmlInstanceFile) { } -CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType) : - base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0)), _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _strRootElementName(""), _strNameAttrituteName(""), _bNameCheck(false) +CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, + const string& strXmlSchemaFile, + const string& strRootElementType) : + base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0), + strXmlSchemaFile, + strRootElementType), + _strXmlInstanceFile(strXmlInstanceFile) { } -bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) -{ - // Check that the doc has been created - if (!isParsable(serializingContext)) { - - return false; - } - - // Validate - if (!isInstanceDocumentValid()) { - - serializingContext.setError("Document " + _strXmlInstanceFile + " is not valid"); - - return false; - } - - // Check Root element type - if (getRootElementName() != _strRootElementType) { - - serializingContext.setError("Error: Wrong XML structure file " + _strXmlInstanceFile); - serializingContext.appendLineToError("Root Element " + getRootElementName() + " mismatches expected type " + _strRootElementType); - - return false; - } - - // Check Root element name attribute (if any) - if (_bNameCheck) { - - string strRootElementNameCheck = getRootElementAttributeString(_strNameAttrituteName); - - if (!_strRootElementName.empty() && strRootElementNameCheck != _strRootElementName) { - - serializingContext.setError("Error: Wrong XML structure file " + _strXmlInstanceFile); - serializingContext.appendLineToError(_strRootElementType + " element " + _strRootElementName + " mismatches expected " + _strRootElementType + " type " + strRootElementNameCheck); - - return false; - } - } - - return true; -} - bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) const { // Check that the doc has been created @@ -95,68 +64,15 @@ bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) c return true; } -bool CXmlFileDocSource::isInstanceDocumentValid() +bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) { -#ifdef LIBXML_SCHEMAS_ENABLED - xmlDocPtr pSchemaDoc = xmlReadFile(_strXmlSchemaFile.c_str(), NULL, XML_PARSE_NONET); - - if (!pSchemaDoc) { - // Unable to load Schema - return false; - } - - xmlSchemaParserCtxtPtr pParserCtxt = xmlSchemaNewDocParserCtxt(pSchemaDoc); - - if (!pParserCtxt) { - - // Unable to create schema context - xmlFreeDoc(pSchemaDoc); - return false; - } + if (!base::validate(serializingContext)) { - // Get Schema - xmlSchemaPtr pSchema = xmlSchemaParse(pParserCtxt); + // Add the file's name in the error message + serializingContext.appendLineToError("File : " + _strXmlInstanceFile); - if (!pSchema) { - - // Invalid Schema - xmlSchemaFreeParserCtxt(pParserCtxt); - xmlFreeDoc(pSchemaDoc); - return false; - } - xmlSchemaValidCtxtPtr pValidationCtxt = xmlSchemaNewValidCtxt(pSchema); - - if (!pValidationCtxt) { - - // Unable to create validation context - xmlSchemaFree(pSchema); - xmlSchemaFreeParserCtxt(pParserCtxt); - xmlFreeDoc(pSchemaDoc); return false; } - xmlSetStructuredErrorFunc(this, schemaValidityStructuredErrorFunc); - //xmlSchemaSetValidErrors(pValidationCtxt, schemaValidityErrorFunc, schemaValidityWarningFunc, NULL); - - bool isDocValid = xmlSchemaValidateDoc(pValidationCtxt, _pDoc) == 0; - - xmlSchemaFreeValidCtxt(pValidationCtxt); - xmlSchemaFree(pSchema); - xmlSchemaFreeParserCtxt(pParserCtxt); - xmlFreeDoc(pSchemaDoc); - - return isDocValid; -#else return true; -#endif -} - -void CXmlFileDocSource::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError) -{ - (void)pUserData; - -#ifdef LIBXML_SCHEMAS_ENABLED - // Display message - puts(pError->message); -#endif } diff --git a/xmlserializer/XmlFileDocSource.h b/xmlserializer/XmlFileDocSource.h index 46c5230..98ba6e3 100644 --- a/xmlserializer/XmlFileDocSource.h +++ b/xmlserializer/XmlFileDocSource.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,49 +18,64 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #pragma once - #include "XmlDocSource.h" -#include "XmlSource.h" - -struct _xmlError; +#include +/** + * Source class that read a file to get an xml document. + * Its base class will validate the document. + */ class CXmlFileDocSource : public CXmlDocSource { public: - CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, const string& strRootElementName, const string& strNameAttrituteName); - + /** + * 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] strRootElementName a string containing the root element name + * @param[in] strNameAttributeName a string containing the name of the root name attribute + */ + CXmlFileDocSource(const string& strXmlInstanceFile, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName); + /** + * 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 + */ CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType); - - // CXmlDocSource method implemented + /** + * CXmlDocSource method implementation. + * + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ virtual bool populate(CXmlSerializingContext& serializingContext); - // Check that the file exists and is readable + /** + * Method that checks that the file exists and is readable. + * + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs during the parsing + */ virtual bool isParsable(CXmlSerializingContext& serializingContext) const; private: - // Validation of the document with the xsd file - bool isInstanceDocumentValid(); - - static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); - - // Instance file + /** + * Instance file + */ string _strXmlInstanceFile; - // Schema file - string _strXmlSchemaFile; - // Element type info - string _strRootElementType; - // Element name info - string _strRootElementName; - // Element name attribute info - string _strNameAttrituteName; - - bool _bNameCheck; - }; diff --git a/xmlserializer/XmlMemoryDocSink.cpp b/xmlserializer/XmlMemoryDocSink.cpp index 6318496..85dd691 100644 --- a/xmlserializer/XmlMemoryDocSink.cpp +++ b/xmlserializer/XmlMemoryDocSink.cpp @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,8 +18,6 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #include "XmlMemoryDocSink.h" @@ -31,7 +29,8 @@ CXmlMemoryDocSink::CXmlMemoryDocSink(IXmlSink* pXmlSink): { } -bool CXmlMemoryDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +bool CXmlMemoryDocSink::doProcess(CXmlDocSource& xmlDocSource, + CXmlSerializingContext& serializingContext) { CXmlElement docElement; diff --git a/xmlserializer/XmlMemoryDocSink.h b/xmlserializer/XmlMemoryDocSink.h index 9bc2acf..e2e261c 100644 --- a/xmlserializer/XmlMemoryDocSink.h +++ b/xmlserializer/XmlMemoryDocSink.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -19,21 +19,37 @@ * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. * - * CREATED: 2012-08-10 */ #pragma once - #include "XmlDocSink.h" #include "XmlSink.h" +/** + * Sink class used to parse an xml document and instanciate parameter-framework structures. + */ class CXmlMemoryDocSink : public CXmlDocSink { public: + /** + * Constructor + * + * @param[out] pXmlSink a pointer to a parameter-framework structure that can parse an xml + * description to instanciate itself + */ CXmlMemoryDocSink(IXmlSink* pXmlSink); private: - // Source processing + /** + * Implementation of CXmlDocSink::doProcess() + * Parse the Xml document contained in xmlDocSource to instanciate the parameter-framework + * structures. + * + * @param[in] xmlDocSource is the source containing the Xml document + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); // Xml Sink diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp index ffa86e3..c323e44 100644 --- a/xmlserializer/XmlMemoryDocSource.cpp +++ b/xmlserializer/XmlMemoryDocSource.cpp @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,8 +18,6 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #include "XmlMemoryDocSource.h" @@ -28,14 +26,22 @@ #define base CXmlDocSource -CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, 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())), _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true), _strProduct(strProduct), _strVersion(strVersion) +CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, + 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())), + _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true), + _strProduct(strProduct), _strVersion(strVersion) { init(); } -CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType): - base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _bWithHeader(false) +CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, + const string& strRootElementType): + base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), + _pXmlSource(pXmlSource), _bWithHeader(false) { init(); } @@ -52,7 +58,9 @@ void CXmlMemoryDocSource::init() bool CXmlMemoryDocSource::populate(CXmlSerializingContext& serializingContext) { #ifndef LIBXML_TREE_ENABLED - serializingContext.setError("XML file exporting feature unsupported on this image. This easiest way to activate it is to do a global recompilation with LIBXML_TREE_ENABLED compiler switch set"); + serializingContext.setError("XML file exporting feature unsupported on this image. " + + "This easiest way to activate it is to do a global " + + "recompilation with LIBXML_TREE_ENABLED compiler switch set"); return false; #endif diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h index 4a1de63..ffa6513 100644 --- a/xmlserializer/XmlMemoryDocSource.h +++ b/xmlserializer/XmlMemoryDocSource.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -19,34 +19,73 @@ * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. * - * CREATED: 2012-08-10 */ #pragma once - +#include #include "XmlDocSource.h" #include "XmlSource.h" +using std::string; + +/** + * Source class that uses parameter-framework's structures to create an xml document + */ class CXmlMemoryDocSource : public CXmlDocSource { public: - CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, const string& strXmlSchemaFile, const string& strProduct, const string& strVersion); + /** + * Constructor + * + * @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] 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 + */ + CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, + const string& strXmlSchemaFile, const string& strProduct, + const string& strVersion); + /** + * Constructor + * + * @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 + */ CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType); + /** + * Implementation of CXmlDocSource::populate() method. + * Method that popuplates the Xml document using the IXmlSource given in the constructor. + * + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ virtual bool populate(CXmlSerializingContext& serializingContext); private: - // initialize root element + /** + * Initialize root element + */ void init(); - // Xml Source + /** + * Xml Source + */ const IXmlSource* _pXmlSource; - // Schema file + /** + * Schema file + */ string _strXmlSchemaFile; - // Boolean used to specify if a header should be added in the Xml Doc + /** + * Boolean used to specify if a header should be added in the Xml Doc + */ bool _bWithHeader; // Product and version info diff --git a/xmlserializer/XmlStringDocSink.cpp b/xmlserializer/XmlStringDocSink.cpp index c38036d..e635fdc 100644 --- a/xmlserializer/XmlStringDocSink.cpp +++ b/xmlserializer/XmlStringDocSink.cpp @@ -32,7 +32,8 @@ CXmlStringDocSink::CXmlStringDocSink(string& strResult): { } -bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource, + CXmlSerializingContext& serializingContext) { (void)serializingContext; diff --git a/xmlserializer/XmlStringDocSink.h b/xmlserializer/XmlStringDocSink.h index 2d777fa..576b244 100644 --- a/xmlserializer/XmlStringDocSink.h +++ b/xmlserializer/XmlStringDocSink.h @@ -1,6 +1,6 @@ /* * INTEL CONFIDENTIAL - * Copyright © 2011 Intel + * Copyright © 2013 Intel * Corporation All Rights Reserved. * * The source code contained or described herein and all documents related to @@ -18,25 +18,42 @@ * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * express and approved by Intel in writing. - * - * CREATED: 2012-08-10 */ #pragma once - +#include #include "XmlDocSink.h" #include "XmlSource.h" +using std::string; + +/** + * Sink class that writes the content of any CXmlDocSource into a string. + * A reference to an empty string is given in the constructor. + */ class CXmlStringDocSink : public CXmlDocSink { public: + /** Constructor + * + * @param[out] strResult a reference to a string that will be filled by the doProcess method + */ CXmlStringDocSink(string& strResult); private: - // Source processing + /** Implementation of CXmlDocSink::doProcess() + * Writes the content of the xmlDocSource in strResult + * + * @param[in] xmlDocSource is the source containing the Xml document + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); - // Result string containing the XML informations + /** + * Result string containing the XML informations + */ string& _strResult; }; diff --git a/xmlserializer/XmlStringDocSource.cpp b/xmlserializer/XmlStringDocSource.cpp new file mode 100644 index 0000000..f9aa65d --- /dev/null +++ b/xmlserializer/XmlStringDocSource.cpp @@ -0,0 +1,44 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2013 Intel + * Corporation All Rights Reserved. + * + * The source code contained or described herein and all documents related to + * the source code ("Material") are owned by Intel Corporation or its suppliers + * or licensors. Title to the Material remains with Intel Corporation or its + * suppliers and licensors. The Material contains trade secrets and proprietary + * and confidential information of Intel or its suppliers and licensors. The + * Material is protected by worldwide copyright and trade secret laws and + * treaty provisions. No part of the Material may be used, copied, reproduced, + * modified, published, uploaded, posted, transmitted, distributed, or + * disclosed in any way without Intel’s prior express written permission. + * + * No license under any patent, copyright, trade secret or other intellectual + * property right is granted to or conferred upon you by disclosure or delivery + * of the Materials, either expressly, by implication, inducement, estoppel or + * otherwise. Any license under such intellectual property rights must be + * express and approved by Intel in writing. + */ + +#include "XmlStringDocSource.h" +#include + +#define base CXmlDocSource + +CXmlStringDocSource::CXmlStringDocSource(const string& strXmlInput, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName) : + base(xmlReadMemory(strXmlInput.c_str(), strXmlInput.size(), "", NULL, 0), + strXmlSchemaFile, + strRootElementType, + strRootElementName, + strNameAttrituteName) +{ +} + +bool CXmlStringDocSource::populate(CXmlSerializingContext &serializingContext) +{ + return validate(serializingContext); +} diff --git a/xmlserializer/XmlStringDocSource.h b/xmlserializer/XmlStringDocSource.h new file mode 100644 index 0000000..b2edcf4 --- /dev/null +++ b/xmlserializer/XmlStringDocSource.h @@ -0,0 +1,60 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2013 Intel + * Corporation All Rights Reserved. + * + * The source code contained or described herein and all documents related to + * the source code ("Material") are owned by Intel Corporation or its suppliers + * or licensors. Title to the Material remains with Intel Corporation or its + * suppliers and licensors. The Material contains trade secrets and proprietary + * and confidential information of Intel or its suppliers and licensors. The + * Material is protected by worldwide copyright and trade secret laws and + * treaty provisions. No part of the Material may be used, copied, reproduced, + * modified, published, uploaded, posted, transmitted, distributed, or + * disclosed in any way without Intel’s prior express written permission. + * + * No license under any patent, copyright, trade secret or other intellectual + * property right is granted to or conferred upon you by disclosure or delivery + * of the Materials, either expressly, by implication, inducement, estoppel or + * otherwise. Any license under such intellectual property rights must be + * express and approved by Intel in writing. + * + */ + +#pragma once +#include "XmlDocSource.h" +#include + +/** + * Source class that get an xml document from a string. + * Its base class will check the validity of the document. + */ +class CXmlStringDocSource : public CXmlDocSource +{ +public: + /** + * Constructor + * + * @param[in] strXmlInput a string containing an xml description + * @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 + */ + CXmlStringDocSource(const string& strXmlInput, + const string& strXmlSchemaFile, + const string& strRootElementType, + const string& strRootElementName, + const string& strNameAttrituteName); + + /** + * CXmlDocSource method implementation. + * + * @param[out] serializingContext is used as error output + * + * @return false if any error occurs + */ + virtual bool populate(CXmlSerializingContext& serializingContext); +}; + + -- cgit v1.1