summaryrefslogtreecommitdiffstats
path: root/xmlserializer
diff options
context:
space:
mode:
Diffstat (limited to 'xmlserializer')
-rw-r--r--xmlserializer/Android.mk10
-rw-r--r--xmlserializer/XmlComposer.cpp105
-rw-r--r--xmlserializer/XmlDocSink.cpp39
-rw-r--r--xmlserializer/XmlDocSink.h41
-rw-r--r--xmlserializer/XmlDocSource.cpp (renamed from xmlserializer/XmlSerializer.cpp)56
-rw-r--r--xmlserializer/XmlDocSource.h (renamed from xmlserializer/XmlSerializer.h)39
-rw-r--r--xmlserializer/XmlElement.cpp8
-rw-r--r--xmlserializer/XmlElement.h1
-rw-r--r--xmlserializer/XmlFileDocSink.cpp46
-rw-r--r--xmlserializer/XmlFileDocSink.h40
-rw-r--r--xmlserializer/XmlFileDocSource.cpp (renamed from xmlserializer/XmlParser.cpp)127
-rw-r--r--xmlserializer/XmlFileDocSource.h63
-rw-r--r--xmlserializer/XmlMemoryDocSink.cpp44
-rw-r--r--xmlserializer/XmlMemoryDocSink.h (renamed from xmlserializer/XmlParser.h)37
-rw-r--r--xmlserializer/XmlMemoryDocSource.cpp92
-rw-r--r--xmlserializer/XmlMemoryDocSource.h59
-rw-r--r--xmlserializer/XmlStringDocSink.cpp49
-rw-r--r--xmlserializer/XmlStringDocSink.h (renamed from xmlserializer/XmlComposer.h)37
18 files changed, 622 insertions, 271 deletions
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 <libxml/parser.h>
-#include <libxml/tree.h>
-#include <sys/time.h>
-
-#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/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/XmlSerializer.cpp b/xmlserializer/XmlDocSource.cpp
index d3e18f9..e876f16 100644
--- a/xmlserializer/XmlSerializer.cpp
+++ b/xmlserializer/XmlDocSource.cpp
@@ -1,8 +1,8 @@
-/*
+/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * 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
@@ -12,25 +12,24 @@
* 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
+ *
+ * CREATED: 2012-08-10
*/
-#include "XmlSerializer.h"
+#include "XmlDocSource.h"
#include <libxml/tree.h>
#include <stdlib.h>
// Schedule for libxml2 library
-bool CXmlSerializer::_bLibXml2CleanupScheduled;
+bool CXmlDocSource::_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)
+CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode):
+ _pDoc(pDoc), _pRootNode(pRootNode)
{
if (!_bLibXml2CleanupScheduled) {
@@ -39,45 +38,42 @@ CXmlSerializer::CXmlSerializer(const string& strXmlInstanceFile, const string& s
_bLibXml2CleanupScheduled = true;
}
-}
-
-CXmlSerializer::~CXmlSerializer()
-{
- // Free XML doc
- xmlFreeDoc(_pDoc);
-}
-
-bool CXmlSerializer::close()
-{
- // Free XML doc
- xmlFreeDoc(_pDoc);
- _pDoc = NULL;
+ if (!_pRootNode) {
- return true;
+ _pRootNode = xmlDocGetRootElement(_pDoc);
+ }
}
-bool CXmlSerializer::open()
+CXmlDocSource::~CXmlDocSource()
{
- return _pDoc != NULL;
+ if (_pDoc) {
+ // Free XML doc
+ xmlFreeDoc(_pDoc);
+ _pDoc = NULL;
+ }
}
// Root element
-void CXmlSerializer::getRootElement(CXmlElement& xmlRootElement) const
+void CXmlDocSource::getRootElement(CXmlElement& xmlRootElement) const
{
xmlRootElement.setXmlElement(_pRootNode);
}
-string CXmlSerializer::getRootElementName() const
+string CXmlDocSource::getRootElementName() const
{
return (const char*)_pRootNode->name;
}
-string CXmlSerializer::getRootElementAttributeString(const string& strAttributeName) const
+string CXmlDocSource::getRootElementAttributeString(const string& strAttributeName) const
{
CXmlElement topMostElement(_pRootNode);
return topMostElement.getAttributeString(strAttributeName);
}
+_xmlDoc* CXmlDocSource::getDoc() const
+{
+ return _pDoc;
+}
diff --git a/xmlserializer/XmlSerializer.h b/xmlserializer/XmlDocSource.h
index 91a95b0..a59919e 100644
--- a/xmlserializer/XmlSerializer.h
+++ b/xmlserializer/XmlDocSource.h
@@ -1,8 +1,8 @@
-/*
+/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * 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
@@ -12,16 +12,16 @@
* 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
+ *
+ * CREATED: 2012-08-10
*/
+
#pragma once
#include "XmlElement.h"
@@ -30,34 +30,27 @@
struct _xmlDoc;
struct _xmlNode;
-class CXmlSerializer
+class CXmlDocSource
{
public:
- CXmlSerializer(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext);
- virtual ~CXmlSerializer();
+ CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL);
+ virtual ~CXmlDocSource();
- // Open/Close
- virtual bool open();
- virtual bool close();
+ // 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;
-protected:
- // Instance file
- string _strXmlInstanceFile;
- // Schema file
- string _strXmlSchemaFile;
+ // Method that returns the xmlDoc contained in the Source. (Can be used in a Doc Sink)
+ _xmlDoc* getDoc() const;
- // Root element type
- string _strRootElementType;
- // Serializing context
- CXmlSerializingContext& _serializingContext;
+protected:
- // XML document
+ // Doc
_xmlDoc* _pDoc;
// Root node
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 <libxml/tree.h>
#include <stdlib.h>
+#include <sstream>
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 <libxml/parser.h>
+
+#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/XmlParser.cpp b/xmlserializer/XmlFileDocSource.cpp
index af26346..c8a0837 100644
--- a/xmlserializer/XmlParser.cpp
+++ b/xmlserializer/XmlFileDocSource.cpp
@@ -1,8 +1,8 @@
-/*
+/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * 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
@@ -12,46 +12,79 @@
* 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
+ *
+ * CREATED: 2012-08-10
*/
-#include "XmlParser.h"
-#include <stdio.h>
-#include <stdarg.h>
+
+#include "XmlFileDocSource.h"
#include <libxml/parser.h>
-#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
-#define base CXmlSerializer
+#define base CXmlDocSource
+
-CXmlParser::CXmlParser(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, CXmlSerializingContext& serializingContext) :
- base(strXmlInstanceFile, strXmlSchemaFile, strRootElementType, serializingContext)
+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)
{
}
-CXmlParser::~CXmlParser()
+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)
{
}
-void CXmlParser::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError)
+bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext)
{
- (void)pUserData;
+ // Check that the doc has been created
+ if (!_pDoc) {
-#ifdef LIBXML_SCHEMAS_ENABLED
- // Display message
- puts(pError->message);
-#endif
+ 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 CXmlParser::isInstanceDocumentValid()
+bool CXmlFileDocSource::isInstanceDocumentValid()
{
#ifdef LIBXML_SCHEMAS_ENABLED
xmlDocPtr pSchemaDoc = xmlReadFile(_strXmlSchemaFile.c_str(), NULL, XML_PARSE_NONET);
@@ -107,50 +140,12 @@ bool CXmlParser::isInstanceDocumentValid()
#endif
}
-bool CXmlParser::open()
+void CXmlFileDocSource::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError)
{
- // 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);
+ (void)pUserData;
- return pXmlSink->fromXml(topMostElement, _serializingContext);
+#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/XmlParser.h b/xmlserializer/XmlMemoryDocSink.h
index 03defd9..9bc2acf 100644
--- a/xmlserializer/XmlParser.h
+++ b/xmlserializer/XmlMemoryDocSink.h
@@ -1,8 +1,8 @@
-/*
+/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * 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
@@ -12,37 +12,30 @@
* 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
+ *
+ * CREATED: 2012-08-10
*/
+
#pragma once
-#include "XmlSerializer.h"
+#include "XmlDocSink.h"
#include "XmlSink.h"
-struct _xmlError;
-
-class CXmlParser : public CXmlSerializer
+class CXmlMemoryDocSink : public CXmlDocSink
{
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);
+ CXmlMemoryDocSink(IXmlSink* pXmlSink);
private:
- // Validity checks
- bool isInstanceDocumentValid();
- static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError);
+ // 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 <libxml/parser.h>
+#include <libxml/tree.h>
+
+#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/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 <libxml/parser.h>
+
+#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/XmlComposer.h b/xmlserializer/XmlStringDocSink.h
index 9e50de8..2d777fa 100644
--- a/xmlserializer/XmlComposer.h
+++ b/xmlserializer/XmlStringDocSink.h
@@ -1,8 +1,8 @@
-/*
+/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * 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
@@ -12,38 +12,31 @@
* 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
+ *
+ * CREATED: 2012-08-10
*/
+
#pragma once
-#include "XmlSerializer.h"
+#include "XmlDocSink.h"
#include "XmlSource.h"
-struct _xmlDoc;
-struct _xmlNode;
-
-class CXmlComposer : public CXmlSerializer
+class CXmlStringDocSink : public CXmlDocSink
{
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);
+ CXmlStringDocSink(string& strResult);
private:
- static string getTimeAsString();
+ // Source processing
+ virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext);
+
+ // Result string containing the XML informations
+ string& _strResult;
};