From 326a31df0dd401283de6170ed09bcf605f61ef7d Mon Sep 17 00:00:00 2001 From: Georges-Henri Baron Date: Thu, 28 Jun 2012 12:05:09 +0200 Subject: PFW: Add two commands to print xml settings and structure BZ: 44910 Creates two commands that can be called through the command line of the parameter-framework. First command getDomainXML returns a string containing the xml structure of the domains, configurations and settings. Second command getSystemClassXML returns a string containing the xml structure of all the instantiated parameter with their attributes. Change-Id: I9a35333802049a2177b8fc416754fdb67e6efff0 Signed-off-by: Georges-Henri Baron Reviewed-on: http://android.intel.com:8080/55155 Reviewed-by: Rocard, KevinX Reviewed-by: Centelles, Sylvain Tested-by: Mendi, EduardoX Reviewed-by: buildbot Tested-by: buildbot --- xmlserializer/Android.mk | 10 ++- xmlserializer/XmlComposer.cpp | 105 ----------------------- xmlserializer/XmlComposer.h | 49 ----------- xmlserializer/XmlDocSink.cpp | 39 +++++++++ xmlserializer/XmlDocSink.h | 41 +++++++++ xmlserializer/XmlDocSource.cpp | 79 ++++++++++++++++++ xmlserializer/XmlDocSource.h | 61 ++++++++++++++ xmlserializer/XmlElement.cpp | 8 ++ xmlserializer/XmlElement.h | 1 + xmlserializer/XmlFileDocSink.cpp | 46 +++++++++++ xmlserializer/XmlFileDocSink.h | 40 +++++++++ xmlserializer/XmlFileDocSource.cpp | 151 +++++++++++++++++++++++++++++++++ xmlserializer/XmlFileDocSource.h | 63 ++++++++++++++ xmlserializer/XmlMemoryDocSink.cpp | 44 ++++++++++ xmlserializer/XmlMemoryDocSink.h | 41 +++++++++ xmlserializer/XmlMemoryDocSource.cpp | 92 +++++++++++++++++++++ xmlserializer/XmlMemoryDocSource.h | 59 +++++++++++++ xmlserializer/XmlParser.cpp | 156 ----------------------------------- xmlserializer/XmlParser.h | 48 ----------- xmlserializer/XmlSerializer.cpp | 83 ------------------- xmlserializer/XmlSerializer.h | 68 --------------- xmlserializer/XmlStringDocSink.cpp | 49 +++++++++++ xmlserializer/XmlStringDocSink.h | 42 ++++++++++ 23 files changed, 863 insertions(+), 512 deletions(-) delete mode 100644 xmlserializer/XmlComposer.cpp delete mode 100644 xmlserializer/XmlComposer.h create mode 100644 xmlserializer/XmlDocSink.cpp create mode 100644 xmlserializer/XmlDocSink.h create mode 100644 xmlserializer/XmlDocSource.cpp create mode 100644 xmlserializer/XmlDocSource.h create mode 100644 xmlserializer/XmlFileDocSink.cpp create mode 100644 xmlserializer/XmlFileDocSink.h create mode 100644 xmlserializer/XmlFileDocSource.cpp create mode 100644 xmlserializer/XmlFileDocSource.h create mode 100644 xmlserializer/XmlMemoryDocSink.cpp create mode 100644 xmlserializer/XmlMemoryDocSink.h create mode 100644 xmlserializer/XmlMemoryDocSource.cpp create mode 100644 xmlserializer/XmlMemoryDocSource.h delete mode 100644 xmlserializer/XmlParser.cpp delete mode 100644 xmlserializer/XmlParser.h delete mode 100644 xmlserializer/XmlSerializer.cpp delete mode 100644 xmlserializer/XmlSerializer.h create mode 100644 xmlserializer/XmlStringDocSink.cpp create mode 100644 xmlserializer/XmlStringDocSink.h (limited to 'xmlserializer') diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk index 7aa4e74..b1a41f6 100644 --- a/xmlserializer/Android.mk +++ b/xmlserializer/Android.mk @@ -5,11 +5,15 @@ include $(CLEAR_VARS) LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) LOCAL_SRC_FILES:= \ - XmlParser.cpp \ XmlElement.cpp \ - XmlComposer.cpp \ XmlSerializingContext.cpp \ - XmlSerializer.cpp + XmlDocSource.cpp \ + XmlDocSink.cpp \ + XmlMemoryDocSink.cpp \ + XmlMemoryDocSource.cpp \ + XmlStringDocSink.cpp \ + XmlFileDocSink.cpp \ + XmlFileDocSource.cpp LOCAL_MODULE:= libxmlserializer diff --git a/xmlserializer/XmlComposer.cpp b/xmlserializer/XmlComposer.cpp deleted file mode 100644 index d00a21e..0000000 --- a/xmlserializer/XmlComposer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#include "XmlComposer.h" -#include -#include -#include - -#define base CXmlSerializer - -#ifndef LIBXML_TREE_ENABLED -#warning "LIBXML_TREE_ENABLED undefined. XML file exporting feature won't be supported!" -#endif - -CXmlComposer::CXmlComposer(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext) : - base(strXmlInstanceFile, strXmlSchemaFile, strRootElementType, serializingContext) -{ -} - -CXmlComposer::~CXmlComposer() -{ -} - -// open / close -bool CXmlComposer::open() -{ -#ifdef LIBXML_TREE_ENABLED - // Create document from scratch - _pDoc = xmlNewDoc(BAD_CAST "1.0"); - - // Create root node - _pRootNode = xmlNewNode(NULL, BAD_CAST _strRootElementType.c_str()); - - // Assign it to document - xmlDocSetRootElement(_pDoc, _pRootNode); -#else - _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"); -#endif - return base::open(); -} - -bool CXmlComposer::close() -{ - // Write file (formatted) - if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(), _pDoc, "UTF-8", 1) == -1) { - - _serializingContext.setError("Could not write file " + _strXmlInstanceFile); - - return false; - } - - return base::close(); -} - -// Composing contents -void CXmlComposer::compose(const IXmlSource* pXmlSource, const string& strProduct, const string& strVersion) -{ - // Compose document - CXmlElement docElement(_pRootNode); - - // Schema namespace - docElement.setAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - - // Schema location - docElement.setAttributeString("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile); - - // Comment for date/time - docElement.setComment(string(" Exported on ") + getTimeAsString() + " from " + strProduct + " version " + strVersion + " "); - - pXmlSource->toXml(docElement, _serializingContext); -} - -string CXmlComposer::getTimeAsString() -{ - char acBuf[200]; - time_t t; - struct tm *tmp; - t = time(NULL); - tmp = localtime(&t); - - strftime(acBuf, sizeof(acBuf), "%F, %T", tmp); - - return acBuf; -} diff --git a/xmlserializer/XmlComposer.h b/xmlserializer/XmlComposer.h deleted file mode 100644 index 9e50de8..0000000 --- a/xmlserializer/XmlComposer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#pragma once - -#include "XmlSerializer.h" -#include "XmlSource.h" - -struct _xmlDoc; -struct _xmlNode; - -class CXmlComposer : public CXmlSerializer -{ -public: - CXmlComposer(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext); - virtual ~CXmlComposer(); - - // open / close - virtual bool open(); - virtual bool close(); - - // Composing contents - void compose(const IXmlSource* pXmlSource, const string& strProduct, const string& strVersion); - -private: - static string getTimeAsString(); -}; - diff --git a/xmlserializer/XmlDocSink.cpp b/xmlserializer/XmlDocSink.cpp new file mode 100644 index 0000000..dedfcf8 --- /dev/null +++ b/xmlserializer/XmlDocSink.cpp @@ -0,0 +1,39 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#include "XmlDocSink.h" + +CXmlDocSink::CXmlDocSink() +{ +} + +// Source Processing +bool CXmlDocSink::process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +{ + if (!xmlDocSource.populate(serializingContext)) { + return false; + } + + return doProcess(xmlDocSource, serializingContext); +} diff --git a/xmlserializer/XmlDocSink.h b/xmlserializer/XmlDocSink.h new file mode 100644 index 0000000..e1b2fc3 --- /dev/null +++ b/xmlserializer/XmlDocSink.h @@ -0,0 +1,41 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSource.h" +#include "XmlSerializingContext.h" + +class CXmlDocSink +{ +public: + CXmlDocSink(); + + // Source processing + bool process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); + +private: + // Handle for subclasses to process the source + virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) = 0; +}; diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp new file mode 100644 index 0000000..e876f16 --- /dev/null +++ b/xmlserializer/XmlDocSource.cpp @@ -0,0 +1,79 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ +#include "XmlDocSource.h" +#include +#include + +// Schedule for libxml2 library +bool CXmlDocSource::_bLibXml2CleanupScheduled; + +CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode): + _pDoc(pDoc), _pRootNode(pRootNode) +{ + if (!_bLibXml2CleanupScheduled) { + + // Schedule cleanup + atexit(xmlCleanupParser); + + _bLibXml2CleanupScheduled = true; + } + + if (!_pRootNode) { + + _pRootNode = xmlDocGetRootElement(_pDoc); + } +} + +CXmlDocSource::~CXmlDocSource() +{ + if (_pDoc) { + // Free XML doc + xmlFreeDoc(_pDoc); + _pDoc = NULL; + } +} + +// Root element +void CXmlDocSource::getRootElement(CXmlElement& xmlRootElement) const +{ + xmlRootElement.setXmlElement(_pRootNode); +} + +string CXmlDocSource::getRootElementName() const +{ + return (const char*)_pRootNode->name; +} + +string CXmlDocSource::getRootElementAttributeString(const string& strAttributeName) const +{ + CXmlElement topMostElement(_pRootNode); + + return topMostElement.getAttributeString(strAttributeName); +} + +_xmlDoc* CXmlDocSource::getDoc() const +{ + return _pDoc; +} + diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h new file mode 100644 index 0000000..a59919e --- /dev/null +++ b/xmlserializer/XmlDocSource.h @@ -0,0 +1,61 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlElement.h" +#include "XmlSerializingContext.h" + +struct _xmlDoc; +struct _xmlNode; + +class CXmlDocSource +{ +public: + CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL); + virtual ~CXmlDocSource(); + + // Method Called by the CXmlDocSink::process method + virtual bool populate(CXmlSerializingContext& serializingContext) = 0; + + // Root element + void getRootElement(CXmlElement& xmlRootElement) const; + string getRootElementName() const; + string getRootElementAttributeString(const string& strAttributeName) const; + + // Method that returns the xmlDoc contained in the Source. (Can be used in a Doc Sink) + _xmlDoc* getDoc() const; + + +protected: + + // Doc + _xmlDoc* _pDoc; + + // Root node + _xmlNode* _pRootNode; + + // libxml2 library cleanup + static bool _bLibXml2CleanupScheduled; +}; diff --git a/xmlserializer/XmlElement.cpp b/xmlserializer/XmlElement.cpp index ffd5787..9f3f84a 100644 --- a/xmlserializer/XmlElement.cpp +++ b/xmlserializer/XmlElement.cpp @@ -25,6 +25,7 @@ #include "XmlElement.h" #include #include +#include CXmlElement::CXmlElement(_xmlNode* pXmlElement) : _pXmlElement(pXmlElement) { @@ -199,6 +200,13 @@ void CXmlElement::setAttributeString(const string& strAttributeName, const strin xmlNewProp(_pXmlElement, BAD_CAST strAttributeName.c_str(), BAD_CAST strValue.c_str()); } +void CXmlElement::setAttributeInteger(const string& strAttributeName, uint32_t uiValue) +{ + ostringstream strStream; + strStream << uiValue; + setAttributeString(strAttributeName, strStream.str()); +} + void CXmlElement::setNameAttribute(const string& strValue) { setAttributeString("Name", strValue); diff --git a/xmlserializer/XmlElement.h b/xmlserializer/XmlElement.h index 62de769..a1bf42c 100644 --- a/xmlserializer/XmlElement.h +++ b/xmlserializer/XmlElement.h @@ -67,6 +67,7 @@ public: void setNameAttribute(const string& strValue); void setTextContent(const string& strContent); void setComment(const string& strComment); + void setAttributeInteger(const string& strAttributeName, uint32_t uiValue); // Child creation void createChild(CXmlElement& childElement, const string& strType); diff --git a/xmlserializer/XmlFileDocSink.cpp b/xmlserializer/XmlFileDocSink.cpp new file mode 100644 index 0000000..4a2b13f --- /dev/null +++ b/xmlserializer/XmlFileDocSink.cpp @@ -0,0 +1,46 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#include "XmlFileDocSink.h" +#include + +#define base CXmlDocSink + +CXmlFileDocSink::CXmlFileDocSink(const string& strXmlInstanceFile): + _strXmlInstanceFile(strXmlInstanceFile) +{ +} + +bool CXmlFileDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +{ + // Write file (formatted) + if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(), xmlDocSource.getDoc(), "UTF-8", 1) == -1) { + + serializingContext.setError("Could not write file " + _strXmlInstanceFile); + + return false; + } + return true; +} + diff --git a/xmlserializer/XmlFileDocSink.h b/xmlserializer/XmlFileDocSink.h new file mode 100644 index 0000000..d06365a --- /dev/null +++ b/xmlserializer/XmlFileDocSink.h @@ -0,0 +1,40 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSink.h" + +class CXmlFileDocSink : public CXmlDocSink +{ +public: + CXmlFileDocSink(const string& strXmlInstanceFile); + +private: + // Source processing + virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); + + // Instance file + string _strXmlInstanceFile; +}; diff --git a/xmlserializer/XmlFileDocSource.cpp b/xmlserializer/XmlFileDocSource.cpp new file mode 100644 index 0000000..c8a0837 --- /dev/null +++ b/xmlserializer/XmlFileDocSource.cpp @@ -0,0 +1,151 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#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) : + base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0)), _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _strRootElementName(""), _strNameAttrituteName(""), _bNameCheck(false) +{ +} + +bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) +{ + // Check that the doc has been created + if (!_pDoc) { + + serializingContext.setError("Could not parse file " + _strXmlInstanceFile); + + 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::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); + //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 new file mode 100644 index 0000000..3274b29 --- /dev/null +++ b/xmlserializer/XmlFileDocSource.h @@ -0,0 +1,63 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSource.h" +#include "XmlSource.h" + +struct _xmlError; + +class CXmlFileDocSource : public CXmlDocSource +{ +public: + CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, const string& strRootElementName, const string& strNameAttrituteName); + + CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType); + + + // CXmlDocSource method implemented + virtual bool populate(CXmlSerializingContext& serializingContext); + +private: + + // Validation of the document with the xsd file + bool isInstanceDocumentValid(); + + static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); + + // 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 new file mode 100644 index 0000000..430ae1d --- /dev/null +++ b/xmlserializer/XmlMemoryDocSink.cpp @@ -0,0 +1,44 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#include "XmlMemoryDocSink.h" + +#define base CXmlDocSink + +CXmlMemoryDocSink::CXmlMemoryDocSink(IXmlSink* pXmlSink): + _pXmlSink(pXmlSink) +{ +} + +bool CXmlMemoryDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +{ + + CXmlElement docElement; + xmlDocSource.getRootElement(docElement); + + // Load the structure from the XML Sink + _pXmlSink->fromXml(docElement, serializingContext); + + return true; +} diff --git a/xmlserializer/XmlMemoryDocSink.h b/xmlserializer/XmlMemoryDocSink.h new file mode 100644 index 0000000..9bc2acf --- /dev/null +++ b/xmlserializer/XmlMemoryDocSink.h @@ -0,0 +1,41 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSink.h" +#include "XmlSink.h" + +class CXmlMemoryDocSink : public CXmlDocSink +{ +public: + CXmlMemoryDocSink(IXmlSink* pXmlSink); + +private: + // Source processing + virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); + + // Xml Sink + IXmlSink* _pXmlSink; +}; diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp new file mode 100644 index 0000000..9f1c5ad --- /dev/null +++ b/xmlserializer/XmlMemoryDocSource.cpp @@ -0,0 +1,92 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#include "XmlMemoryDocSource.h" +#include +#include + +#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) +{ + 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) +{ + init(); +} + +void CXmlMemoryDocSource::init() +{ +#ifdef LIBXML_TREE_ENABLED + + // Assign it to document + xmlDocSetRootElement(_pDoc, _pRootNode); +#endif +} + +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"); + + return false; +#endif + + // Create Xml element with the Doc + CXmlElement docElement(_pRootNode); + + if (_bWithHeader) { + + // Schema namespace + docElement.setAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + + // Schema location + docElement.setAttributeString("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile); + + // Comment for date/time + docElement.setComment(string(" Exported on ") + getTimeAsString() + " from " + _strProduct + " version " + _strVersion + " "); + } + + // Compose the xml document + _pXmlSource->toXml(docElement, serializingContext); + + return true; +} + +string CXmlMemoryDocSource::getTimeAsString() +{ + char acBuf[200]; + time_t t; + struct tm *tmp; + t = time(NULL); + tmp = localtime(&t); + + strftime(acBuf, sizeof(acBuf), "%F, %T", tmp); + + return acBuf; +} diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h new file mode 100644 index 0000000..c507282 --- /dev/null +++ b/xmlserializer/XmlMemoryDocSource.h @@ -0,0 +1,59 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSource.h" +#include "XmlSource.h" + +class CXmlMemoryDocSource : public CXmlDocSource +{ +public: + CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, const string& strXmlSchemaFile, const string& strProduct, const string& strVersion); + + CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType); + + virtual bool populate(CXmlSerializingContext& serializingContext); +private: + + // initialize root element + void init(); + + // Xml Source + const IXmlSource* _pXmlSource; + + // Schema file + string _strXmlSchemaFile; + + // Boolean used to specify if a header should be added in the Xml Doc + bool _bWithHeader; + + // Product and version info + string _strProduct; + string _strVersion; + + // Get the current system time + static string getTimeAsString(); + +}; diff --git a/xmlserializer/XmlParser.cpp b/xmlserializer/XmlParser.cpp deleted file mode 100644 index af26346..0000000 --- a/xmlserializer/XmlParser.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#include "XmlParser.h" -#include -#include -#include -#include -#include - -#define base CXmlSerializer - - -CXmlParser::CXmlParser(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext) : - base(strXmlInstanceFile, strXmlSchemaFile, strRootElementType, serializingContext) -{ -} - -CXmlParser::~CXmlParser() -{ -} - -void CXmlParser::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError) -{ - (void)pUserData; - -#ifdef LIBXML_SCHEMAS_ENABLED - // Display message - puts(pError->message); -#endif -} - -bool CXmlParser::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); - //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 -} - -bool CXmlParser::open() -{ - // Parse the file and get the DOM - _pDoc = xmlReadFile(_strXmlInstanceFile.c_str(), NULL, 0); - - if (!_pDoc) { - - _serializingContext.setError("Could not parse file " + _strXmlInstanceFile); - - return false; - } - // Validate - if (!isInstanceDocumentValid()) { - - _serializingContext.setError("Document " + _strXmlInstanceFile + " is not valid"); - - // Free XML doc - xmlFreeDoc(_pDoc); - - _pDoc = NULL; - - return false; - } - - // Get the root element node - _pRootNode = xmlDocGetRootElement(_pDoc); - - // 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; - } - - return base::open(); -} - -bool CXmlParser::parse(IXmlSink* pXmlSink) -{ - // Parse document - CXmlElement topMostElement(_pRootNode); - - return pXmlSink->fromXml(topMostElement, _serializingContext); -} - diff --git a/xmlserializer/XmlParser.h b/xmlserializer/XmlParser.h deleted file mode 100644 index 03defd9..0000000 --- a/xmlserializer/XmlParser.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#pragma once - -#include "XmlSerializer.h" -#include "XmlSink.h" - -struct _xmlError; - -class CXmlParser : public CXmlSerializer -{ -public: - CXmlParser(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext); - virtual ~CXmlParser(); - - // Parsing file - virtual bool open(); - - // Parsing contents - bool parse(IXmlSink* pXmlSink); - -private: - // Validity checks - bool isInstanceDocumentValid(); - static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); -}; diff --git a/xmlserializer/XmlSerializer.cpp b/xmlserializer/XmlSerializer.cpp deleted file mode 100644 index d3e18f9..0000000 --- a/xmlserializer/XmlSerializer.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#include "XmlSerializer.h" -#include -#include - -// Schedule for libxml2 library -bool CXmlSerializer::_bLibXml2CleanupScheduled; - -CXmlSerializer::CXmlSerializer(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext) : - _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _serializingContext(serializingContext), _pDoc(NULL), _pRootNode(NULL) -{ - if (!_bLibXml2CleanupScheduled) { - - // Schedule cleanup - atexit(xmlCleanupParser); - - _bLibXml2CleanupScheduled = true; - } -} - -CXmlSerializer::~CXmlSerializer() -{ - // Free XML doc - xmlFreeDoc(_pDoc); -} - -bool CXmlSerializer::close() -{ - // Free XML doc - xmlFreeDoc(_pDoc); - - _pDoc = NULL; - - return true; -} - -bool CXmlSerializer::open() -{ - return _pDoc != NULL; -} - -// Root element -void CXmlSerializer::getRootElement(CXmlElement& xmlRootElement) const -{ - xmlRootElement.setXmlElement(_pRootNode); -} - -string CXmlSerializer::getRootElementName() const -{ - return (const char*)_pRootNode->name; -} - -string CXmlSerializer::getRootElementAttributeString(const string& strAttributeName) const -{ - CXmlElement topMostElement(_pRootNode); - - return topMostElement.getAttributeString(strAttributeName); -} - - diff --git a/xmlserializer/XmlSerializer.h b/xmlserializer/XmlSerializer.h deleted file mode 100644 index 91a95b0..0000000 --- a/xmlserializer/XmlSerializer.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * INTEL CONFIDENTIAL - * Copyright © 2011 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. - * - * CREATED: 2011-06-01 - * UPDATED: 2011-07-27 - */ -#pragma once - -#include "XmlElement.h" -#include "XmlSerializingContext.h" - -struct _xmlDoc; -struct _xmlNode; - -class CXmlSerializer -{ -public: - CXmlSerializer(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext); - virtual ~CXmlSerializer(); - - // Open/Close - virtual bool open(); - virtual bool close(); - - // Root element - void getRootElement(CXmlElement& xmlRootElement) const; - string getRootElementName() const; - string getRootElementAttributeString(const string& strAttributeName) const; -protected: - // Instance file - string _strXmlInstanceFile; - - // Schema file - string _strXmlSchemaFile; - - // Root element type - string _strRootElementType; - - // Serializing context - CXmlSerializingContext& _serializingContext; - - // XML document - _xmlDoc* _pDoc; - - // Root node - _xmlNode* _pRootNode; - - // libxml2 library cleanup - static bool _bLibXml2CleanupScheduled; -}; diff --git a/xmlserializer/XmlStringDocSink.cpp b/xmlserializer/XmlStringDocSink.cpp new file mode 100644 index 0000000..a96a1ed --- /dev/null +++ b/xmlserializer/XmlStringDocSink.cpp @@ -0,0 +1,49 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#include "XmlStringDocSink.h" +#include + +#define base CXmlDocSink + +CXmlStringDocSink::CXmlStringDocSink(string& strResult): + _strResult(strResult) +{ +} + +bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) +{ + (void)serializingContext; + + xmlChar* pcDumpedDoc = NULL; + + int iSize; + xmlDocDumpFormatMemoryEnc(xmlDocSource.getDoc(), &pcDumpedDoc, &iSize, "UTF-8", 1); + + _strResult.append((const char*)pcDumpedDoc); + + xmlFree(pcDumpedDoc); + + return true; +} diff --git a/xmlserializer/XmlStringDocSink.h b/xmlserializer/XmlStringDocSink.h new file mode 100644 index 0000000..2d777fa --- /dev/null +++ b/xmlserializer/XmlStringDocSink.h @@ -0,0 +1,42 @@ +/* + * INTEL CONFIDENTIAL + * Copyright © 2011 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. + * + * CREATED: 2012-08-10 + */ + +#pragma once + +#include "XmlDocSink.h" +#include "XmlSource.h" + +class CXmlStringDocSink : public CXmlDocSink +{ +public: + CXmlStringDocSink(string& strResult); + +private: + // Source processing + virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext); + + // Result string containing the XML informations + string& _strResult; +}; + -- cgit v1.1