summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parameter/ParameterMgr.cpp195
-rw-r--r--parameter/ParameterMgr.h83
-rw-r--r--remote-processor/RequestMessage.cpp6
-rw-r--r--remote-processor/RequestMessage.h8
-rw-r--r--xmlserializer/Android.mk3
-rw-r--r--xmlserializer/XmlDocSink.cpp4
-rw-r--r--xmlserializer/XmlDocSink.h32
-rw-r--r--xmlserializer/XmlDocSource.cpp181
-rw-r--r--xmlserializer/XmlDocSource.h151
-rw-r--r--xmlserializer/XmlFileDocSink.cpp10
-rw-r--r--xmlserializer/XmlFileDocSink.h29
-rw-r--r--xmlserializer/XmlFileDocSource.cpp128
-rw-r--r--xmlserializer/XmlFileDocSource.h73
-rw-r--r--xmlserializer/XmlMemoryDocSink.cpp7
-rw-r--r--xmlserializer/XmlMemoryDocSink.h24
-rw-r--r--xmlserializer/XmlMemoryDocSource.cpp24
-rw-r--r--xmlserializer/XmlMemoryDocSource.h55
-rw-r--r--xmlserializer/XmlStringDocSink.cpp3
-rw-r--r--xmlserializer/XmlStringDocSink.h29
-rw-r--r--xmlserializer/XmlStringDocSource.cpp44
-rw-r--r--xmlserializer/XmlStringDocSource.h60
21 files changed, 856 insertions, 293 deletions
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index 4003753..0bef3df 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -1,4 +1,4 @@
-/*
+ /*
* INTEL CONFIDENTIAL
* Copyright © 2011 Intel
* Corporation All Rights Reserved.
@@ -74,6 +74,7 @@
#include "XmlFileDocSink.h"
#include "XmlFileDocSource.h"
#include "XmlStringDocSink.h"
+#include "XmlStringDocSource.h"
#include "XmlMemoryDocSink.h"
#include "XmlMemoryDocSource.h"
#include "Utility.h"
@@ -244,12 +245,16 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa
"<file path>", "Export settings to binary file" },
{ "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
"<file path>", "Import settings from binary file" },
- { "getDomainsXML", &CParameterMgr::getDomainsXMLCommmandProcess, 0 ,
+ { "getDomainsWithSettingsXML",
+ &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
"", "Print domains including settings as XML" },
-
+ { "setDomainsWithSettingsXML",
+ &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
+ "<xml configurable domains>", "Import domains including settings from XML string" },
/// Structure Export
{ "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
"", "Print parameter structure as XML" }
+
};
// Remote command parsers array Size
@@ -1362,24 +1367,35 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationPar
}
/// Settings Import/Export
-CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
{
- return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
+ string strFileName = remoteCommand.getArgument(0);
+ return exportDomainsXml(strFileName, false, true, strResult) ?
+ CCommandHandler::EDone : CCommandHandler::EFailed;
}
-CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
{
- return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
+ return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
+ CCommandHandler::EDone : CCommandHandler::EFailed;
}
-CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
{
- return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
+ string strFileName = remoteCommand.getArgument(0);
+ return exportDomainsXml(strFileName, true, true, strResult) ?
+ CCommandHandler::EDone : CCommandHandler::EFailed;
}
CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
{
- return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
+ return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
}
CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
@@ -1392,13 +1408,13 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommm
return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
}
-/// GUI commands
-
-CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
{
(void)remoteCommand;
- if (!getDomainsXMLString(strResult, true)) {
+ if (!exportDomainsXml(strResult, true, false, strResult)) {
return CCommandHandler::EFailed;
}
@@ -1406,7 +1422,17 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommma
return CCommandHandler::ESucceeded;
}
-CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
+{
+ return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
+ CCommandHandler::EDone : CCommandHandler::EFailed;
+}
+
+CParameterMgr::CCommandHandler::CommandStatus
+ CParameterMgr::getSystemClassXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult)
{
(void)remoteCommand;
@@ -1801,8 +1827,8 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable
return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
}
-// XML Import/Export
-bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
+bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
+ bool bFromFile, string& strError)
{
// Check tuning mode
if (!checkTuningModeOn(strError)) {
@@ -1811,7 +1837,7 @@ bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettin
}
// check path is absolute
- if (strFileName[0] != '/') {
+ if (bFromFile && strXmlSource[0] != '/') {
strError = "Please provide absolute path";
@@ -1823,25 +1849,67 @@ bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettin
// Context
CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
- // Secltion criteria definition for rule creation
- xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
+ // Selection criteria definition for rule creation
+ xmlDomainSerializingContext.setSelectionCriteriaDefinition(
+ getConstSelectionCriteria()->getSelectionCriteriaDefinition());
- // Parse
- if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
+ // Init serializing context
+ xmlDomainSerializingContext.set(
+ _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
+ "", _strSchemaFolderLocation);
+
+ // Get Schema file associated to root element
+ string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
+ pConfigurableDomains->getKind() + ".xsd";
+
+ // Xml Source
+ CXmlDocSource* pSource;
+
+ if (bFromFile) {
+
+ // when importing from a file strXmlSource is the file name
+ pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
+ pConfigurableDomains->getKind(),
+ pConfigurableDomains->getName(), "SystemClassName");
+
+ } else {
+
+ // when importing from an xml string, strXmlSource contains the string
+ pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
+ pConfigurableDomains->getKind(),
+ pConfigurableDomains->getName(), "SystemClassName");
- return false;
}
+ // Start clean
+ pConfigurableDomains->clean();
- // Validate domains after XML import
- pConfigurableDomains->validate(_pMainParameterBlackboard);
+ // Use a doc sink that instantiate Configurable Domains from the given doc source
+ CXmlMemoryDocSink memorySink(pConfigurableDomains);
- return true;
+ bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
+
+ if (!bProcessSuccess) {
+
+ //Cleanup
+ pConfigurableDomains->clean();
+
+ } else {
+
+ // Validate domains after XML import
+ pConfigurableDomains->validate(_pMainParameterBlackboard);
+
+ }
+
+ delete pSource;
+
+ return bProcessSuccess;
}
-bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
+bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
+ string& strError) const
{
// check path is absolute
- if (strFileName[0] != '/') {
+ if (bToFile && strXmlDest[0] != '/') {
strError = "Please provide absolute path";
@@ -1852,7 +1920,8 @@ bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettin
const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
// Get Schema file associated to root element
- string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
+ string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
+ pConfigurableDomains->getKind() + ".xsd";
// Context
CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
@@ -1864,16 +1933,27 @@ bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettin
xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
// Use a doc source by loading data from instantiated Configurable Domains
- CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
+ CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
+ strXmlSchemaFilePath, "parameter-framework", getVersion());
- // Use a doc sink to write the doc data in a file
- CXmlFileDocSink fileSink(strFileName);
+ // Xml Sink
+ CXmlDocSink* pSink;
- if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
- return false;
+ if (bToFile) {
+
+ // Use a doc sink to write the doc data in a file
+ pSink = new CXmlFileDocSink(strXmlDest);
+
+ } else {
+
+ // Use a doc sink to write the doc data in a string
+ pSink = new CXmlStringDocSink(strXmlDest);
}
- return true;
+ bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
+
+ delete pSink;
+ return bProcessSuccess;
}
// Binary Import/Export
@@ -2116,42 +2196,6 @@ void CParameterMgr::doApplyConfigurations(bool bForce)
getSelectionCriteria()->resetModifiedStatus();
}
-/// GUI commands functions
-bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
-{
-
- // Root element
- const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
-
- // Get Schema file associated to root element
- string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
-
- string strError;
-
- // Context
- CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
-
- // Value space
- xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
-
- // Output raw format
- xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
-
- // Use a doc source by loading data from instantiated Configurable Domains
- CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
-
- // Use a doc sink the write the doc data in a string
- CXmlStringDocSink stringSink(strResult);
-
- if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
- strResult = strError;
-
- return false;
- }
-
- return true;
-}
-
bool CParameterMgr::getSystemClassXMLString(string& strResult)
{
// Root element
@@ -2167,10 +2211,13 @@ bool CParameterMgr::getSystemClassXMLString(string& strResult)
// Use a doc sink that write the doc data in a string
CXmlStringDocSink stringSink(strResult);
- if (!stringSink.process(memorySource, xmlSerializingContext)) {
+ bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
+
+ if (!bProcessSuccess) {
+
strResult = strError;
- return false;
+
}
- return true;
+ return bProcessSuccess;
}
diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h
index 0d7119d..47ba21f 100644
--- a/parameter/ParameterMgr.h
+++ b/parameter/ParameterMgr.h
@@ -159,16 +159,50 @@ public:
bool removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError);
bool split(const string& strDomain, const string& strConfigurableElementPath, string& strError);
- // XML Import/Export
- bool importDomainsXml(const string& strFileName, bool bWithSettings, string& strError);
- bool exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const;
+ /**
+ * Method that imports Configurable Domains from an Xml source.
+ *
+ * @param[in] strXmlSource a string containing an xml description or a path to an xml file
+ * @param[in] bWithSettings a boolean that determines if the settings should be used in the
+ * xml description
+ * @param[in] bFromFile a boolean that determines if the source is an xml description in
+ * strXmlSource or contained in a file. In that case strXmlSource is just the file path.
+ * @param[out] strError is used as the error output
+ *
+ * @return false if any error occures
+ */
+ bool importDomainsXml(const string& strXmlSource, bool bWithSettings, bool bFromFile,
+ string& strError);
+
+ /**
+ * Method that exports Configurable Domains to an Xml destination.
+ * If bToFile is false, the xml description from the xml document will be written
+ * in strXmlDest. Otherwise it will be written in a file located at the path in strXmlDest
+ *
+ * @param[in:out] strXmlDest a string containing an xml description or a path to an xml file
+ * @param[in] bWithSettings a boolean that determines if the settings should be used in the
+ * xml description
+ * @param[in] bToFile a boolean that determines if the destination is an xml description in
+ * strXmlDest or contained in a file. In that case strXmlDest is just the file path.
+ * @param[out] strError is used as the error output
+ *
+ * @return false if any error occures
+ */
+ bool exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
+ string& strError) const;
// Binary Import/Export
bool importDomainsBinary(const string& strFileName, string& strError);
bool exportDomainsBinary(const string& strFileName, string& strError);
- // GUI command XML send
- bool getDomainsXMLString(string& strResult, bool bWithSettings);
+ /**
+ * Method that creates an Xml description of the instanciated parameter structure contained
+ * in SystemClass.
+ *
+ * @param[out] strResult contains the xml description of SystemClass or the errors if any
+ *
+ * @return false if any error occures during the creation of the xml description
+ */
bool getSystemClassXMLString(string& strResult);
// Introspect
@@ -257,9 +291,42 @@ private:
CCommandHandler::CommandStatus importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult);
CCommandHandler::CommandStatus exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult);
CCommandHandler::CommandStatus importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult);
- /// GUI commands
- CCommandHandler::CommandStatus getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult);
- CCommandHandler::CommandStatus getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult);
+
+ /**
+ * Command handler method for getConfigurableDomainWithSettings command.
+ *
+ * @param[in] remoteCommand contains the arguments of the received command.
+ * @param[out] strResult a string containing the result of the command
+ *
+ * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed
+ * in the other case
+ */
+ CCommandHandler::CommandStatus getConfigurableDomainsWithSettingsXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult);
+
+ /**
+ * Command handler method for setConfigurableDomainWithSettings command.
+ *
+ * @param[in] remoteCommand contains the arguments of the received command.
+ * @param[out] strResult a string containing the result of the command
+ *
+ * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed
+ * in the other case
+ */
+ CCommandHandler::CommandStatus setConfigurableDomainsWithSettingsXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult);
+
+ /**
+ * Command handler method for getSystemClass command.
+ *
+ * @param[in] remoteCommand contains the arguments of the received command.
+ * @param[out] strResult a string containing the result of the command
+ *
+ * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed
+ * in the other case
+ */
+ CCommandHandler::CommandStatus getSystemClassXMLCommmandProcess(
+ const IRemoteCommand& remoteCommand, string& strResult);
// Max command usage length, use for formatting
void setMaxCommandUsageLength();
diff --git a/remote-processor/RequestMessage.cpp b/remote-processor/RequestMessage.cpp
index 5dfecd0..ced2064 100644
--- a/remote-processor/RequestMessage.cpp
+++ b/remote-processor/RequestMessage.cpp
@@ -30,6 +30,8 @@
#define base CMessage
+const char* const CRequestMessage::gacDelimiters = " \t\n\v\f\r";
+
CRequestMessage::CRequestMessage(const string& strCommand) : base(ECommandRequest), _strCommand(strCommand)
{
}
@@ -152,7 +154,9 @@ string CRequestMessage::trim(const string& strToTrim)
// Trim string
string strTrimmed = strToTrim;
- strTrimmed.erase(remove_if(strTrimmed.begin(), strTrimmed.end(), ::isspace), strTrimmed.end());
+ strTrimmed.erase(strTrimmed.find_last_not_of(gacDelimiters) + 1 );
+
+ strTrimmed.erase(0, strTrimmed.find_first_not_of(gacDelimiters));
return strTrimmed;
}
diff --git a/remote-processor/RequestMessage.h b/remote-processor/RequestMessage.h
index 2b2edb7..a9567e5 100644
--- a/remote-processor/RequestMessage.h
+++ b/remote-processor/RequestMessage.h
@@ -44,6 +44,14 @@ public:
virtual const string packArguments(uint32_t uiStartArgument, uint32_t uiNbArguments) const;
private:
+
+ /**
+ * Constant character array.
+ * This value defines the delimiters used to separate the arguments
+ * in the request command.
+ */
+ static const char* const gacDelimiters;
+
// Fill data to send
virtual void fillDataToSend();
// Collect received data
diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk
index 8ddb700..630cc34 100644
--- a/xmlserializer/Android.mk
+++ b/xmlserializer/Android.mk
@@ -12,7 +12,8 @@ COMMON_SRC_FILES := \
XmlMemoryDocSource.cpp \
XmlStringDocSink.cpp \
XmlFileDocSink.cpp \
- XmlFileDocSource.cpp
+ XmlFileDocSource.cpp \
+ XmlStringDocSource.cpp
COMMON_MODULE := libxmlserializer
diff --git a/xmlserializer/XmlDocSink.cpp b/xmlserializer/XmlDocSink.cpp
index dedfcf8..2a07d74 100644
--- a/xmlserializer/XmlDocSink.cpp
+++ b/xmlserializer/XmlDocSink.cpp
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -19,7 +19,6 @@
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
*
- * CREATED: 2012-08-10
*/
#include "XmlDocSink.h"
@@ -28,7 +27,6 @@ CXmlDocSink::CXmlDocSink()
{
}
-// Source Processing
bool CXmlDocSink::process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext)
{
if (!xmlDocSource.populate(serializingContext)) {
diff --git a/xmlserializer/XmlDocSink.h b/xmlserializer/XmlDocSink.h
index d341ecf..56a806f 100644
--- a/xmlserializer/XmlDocSink.h
+++ b/xmlserializer/XmlDocSink.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -19,24 +19,46 @@
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
*
- * CREATED: 2012-08-10
*/
#pragma once
-
#include "XmlDocSource.h"
#include "XmlSerializingContext.h"
+/**
+ * The CXmlDocSink class defines how to use a CXmlDocSource.
+ * The interaction between the xml source and xml sink is defined
+ * in the process method of CXmlDocSink. One can subclass CXmlDocSink
+ * for different purpose by implementing the doProcess method and then
+ * use it with any existing implementation of CXmlDocSource.
+ */
class CXmlDocSink
{
public:
CXmlDocSink();
- // Source processing
+ /**
+ * Method to be called to use an xmlDocSource.
+ * Any subclass of XmlDocSink must implement the doProcess
+ * method that will define how to use the xmlDocSource.
+ *
+ * @param[in] xmlDocSource a CXmlDocSource reference
+ * @param[in] serializingContext a CXmlSerializing Context reference
+ *
+ * @return true is there was no error during the processing of xmlDocSource
+ */
bool process(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext);
virtual ~CXmlDocSink() {}
private:
- // Handle for subclasses to process the source
+ /**
+ * Handle for subclasses to process the source.
+ * This method will define what to do with the xmlDocSource.
+ *
+ * @param[in] xmlDocSource a CXmlDocSource reference
+ * @param[in] serializingContext a CXmlSerializing Context reference
+ *
+ * @return true is there was no error during the processing of xmlDocSource
+ */
virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext) = 0;
};
diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp
index e876f16..144b636 100644
--- a/xmlserializer/XmlDocSource.cpp
+++ b/xmlserializer/XmlDocSource.cpp
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,31 +18,55 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
+
#include "XmlDocSource.h"
#include <libxml/tree.h>
+#include <libxml/xmlschemas.h>
#include <stdlib.h>
// Schedule for libxml2 library
bool CXmlDocSource::_bLibXml2CleanupScheduled;
CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, _xmlNode *pRootNode):
- _pDoc(pDoc), _pRootNode(pRootNode)
+ _pDoc(pDoc),
+ _pRootNode(pRootNode),
+ _strXmlSchemaFile(""),
+ _strRootElementType(""),
+ _strRootElementName(""),
+ _strNameAttrituteName(""),
+ _bNameCheck(false)
{
- if (!_bLibXml2CleanupScheduled) {
-
- // Schedule cleanup
- atexit(xmlCleanupParser);
-
- _bLibXml2CleanupScheduled = true;
- }
+ init();
+}
- if (!_pRootNode) {
+CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName) :
+ _pDoc(pDoc),
+ _pRootNode(NULL),
+ _strXmlSchemaFile(strXmlSchemaFile),
+ _strRootElementType(strRootElementType),
+ _strRootElementName(strRootElementName),
+ _strNameAttrituteName(strNameAttrituteName),
+ _bNameCheck(true)
+{
+ init();
+}
- _pRootNode = xmlDocGetRootElement(_pDoc);
- }
+CXmlDocSource::CXmlDocSource(_xmlDoc* pDoc,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType) :
+ _pDoc(pDoc), _pRootNode(NULL),
+ _strXmlSchemaFile(strXmlSchemaFile),
+ _strRootElementType(strRootElementType),
+ _strRootElementName(""),
+ _strNameAttrituteName(""),
+ _bNameCheck(false)
+{
+ init();
}
CXmlDocSource::~CXmlDocSource()
@@ -54,7 +78,6 @@ CXmlDocSource::~CXmlDocSource()
}
}
-// Root element
void CXmlDocSource::getRootElement(CXmlElement& xmlRootElement) const
{
xmlRootElement.setXmlElement(_pRootNode);
@@ -77,3 +100,131 @@ _xmlDoc* CXmlDocSource::getDoc() const
return _pDoc;
}
+bool CXmlDocSource::validate(CXmlSerializingContext& serializingContext)
+{
+ // Check that the doc has been created
+ if (!_pDoc) {
+
+ serializingContext.setError("Could not parse document ");
+
+ return false;
+ }
+
+ // Validate
+ if (!isInstanceDocumentValid()) {
+
+ serializingContext.setError("Document is not valid");
+
+ return false;
+ }
+
+ // Check Root element type
+ if (getRootElementName() != _strRootElementType) {
+
+ serializingContext.setError("Error: Wrong XML structure document ");
+ serializingContext.appendLineToError("Root Element " + getRootElementName()
+ + " mismatches expected type " + _strRootElementType);
+
+ return false;
+ }
+
+ if (_bNameCheck) {
+
+ string strRootElementNameCheck = getRootElementAttributeString(_strNameAttrituteName);
+
+ // Check Root element name attribute (if any)
+ if (!_strRootElementName.empty() && strRootElementNameCheck != _strRootElementName) {
+
+ serializingContext.setError("Error: Wrong XML structure document ");
+ serializingContext.appendLineToError(_strRootElementType + " element "
+ + _strRootElementName + " mismatches expected "
+ + _strRootElementType + " type "
+ + strRootElementNameCheck);
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void CXmlDocSource::init()
+{
+ if (!_bLibXml2CleanupScheduled) {
+
+ // Schedule cleanup
+ atexit(xmlCleanupParser);
+
+ _bLibXml2CleanupScheduled = true;
+ }
+
+ if (!_pRootNode) {
+
+ _pRootNode = xmlDocGetRootElement(_pDoc);
+ }
+}
+
+bool CXmlDocSource::isInstanceDocumentValid()
+{
+#ifdef LIBXML_SCHEMAS_ENABLED
+ xmlDocPtr pSchemaDoc = xmlReadFile(_strXmlSchemaFile.c_str(), NULL, XML_PARSE_NONET);
+
+ if (!pSchemaDoc) {
+ // Unable to load Schema
+ return false;
+ }
+
+ xmlSchemaParserCtxtPtr pParserCtxt = xmlSchemaNewDocParserCtxt(pSchemaDoc);
+
+ if (!pParserCtxt) {
+
+ // Unable to create schema context
+ xmlFreeDoc(pSchemaDoc);
+ return false;
+ }
+
+ // Get Schema
+ xmlSchemaPtr pSchema = xmlSchemaParse(pParserCtxt);
+
+ if (!pSchema) {
+
+ // Invalid Schema
+ xmlSchemaFreeParserCtxt(pParserCtxt);
+ xmlFreeDoc(pSchemaDoc);
+ return false;
+ }
+ xmlSchemaValidCtxtPtr pValidationCtxt = xmlSchemaNewValidCtxt(pSchema);
+
+ if (!pValidationCtxt) {
+
+ // Unable to create validation context
+ xmlSchemaFree(pSchema);
+ xmlSchemaFreeParserCtxt(pParserCtxt);
+ xmlFreeDoc(pSchemaDoc);
+ return false;
+ }
+
+ xmlSetStructuredErrorFunc(this, schemaValidityStructuredErrorFunc);
+
+ bool isDocValid = xmlSchemaValidateDoc(pValidationCtxt, _pDoc) == 0;
+
+ xmlSchemaFreeValidCtxt(pValidationCtxt);
+ xmlSchemaFree(pSchema);
+ xmlSchemaFreeParserCtxt(pParserCtxt);
+ xmlFreeDoc(pSchemaDoc);
+
+ return isDocValid;
+#else
+ return true;
+#endif
+}
+
+void CXmlDocSource::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError)
+{
+ (void)pUserData;
+
+#ifdef LIBXML_SCHEMAS_ENABLED
+ // Display message
+ puts(pError->message);
+#endif
+}
diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h
index a59919e..1953425 100644
--- a/xmlserializer/XmlDocSource.h
+++ b/xmlserializer/XmlDocSource.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,44 +18,175 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#pragma once
-
#include "XmlElement.h"
#include "XmlSerializingContext.h"
+#include <string>
struct _xmlDoc;
struct _xmlNode;
+struct _xmlError;
+/**
+ * The CXmlDocSource is used by CXmlDocSink.
+ * The interaction between the xml source and xml sink is defined
+ * in the process method of CXmlDocSink. One can subclass CXmlDocSource
+ * for different purposes by implementing the populate method and then
+ * use it with any existing implementation of CXmlDocSink.
+ */
class CXmlDocSource
{
public:
+ /**
+ * Constructor
+ *
+ * @param[out] pDoc a pointer to the xml document that will be filled by the class
+ * @param[in] pRootNode a pointer to the root element of the document.
+ */
CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL);
+
+ /**
+ * Constructor
+ *
+ * @param[out] pDoc a pointer to the xml document that will be filled by the class
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strRootElementType a string containing the root element type
+ * @param[in] strRootElementName a string containing the root element name
+ * @param[in] strNameAttributeName a string containing the name of the root name attribute
+ */
+ CXmlDocSource(_xmlDoc* pDoc,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName);
+
+ /**
+ * Constructor
+ *
+ * @param[out] pDoc a pointer to the xml document that will be filled by the class
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strRootElementType a string containing the root element type
+ */
+ CXmlDocSource(_xmlDoc* pDoc, const string& strXmlSchemaFile, const string& strRootElementType);
+
+ /**
+ * Destructor
+ */
virtual ~CXmlDocSource();
- // Method Called by the CXmlDocSink::process method
+ /**
+ * Method called by the CXmlDocSink::process method.
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if there are any error
+ */
virtual bool populate(CXmlSerializingContext& serializingContext) = 0;
- // Root element
+ /**
+ * Method that returns the root element of the Xml tree.
+ *
+ * @param[out] xmlRootElement a reference to the CXmleElement destination
+ */
void getRootElement(CXmlElement& xmlRootElement) const;
+
+ /**
+ * Getter method.
+ *
+ * @return the root element's name
+ */
string getRootElementName() const;
+
+ /**
+ * Getter method.
+ * Method that returns the root element's attribute with name matching strAttributeName.
+ *
+ * @param[in] strAttributeName is a string used to find the corresponding attribute
+ *
+ * @return the value of the root's attribute named as strAttributeName
+ */
string getRootElementAttributeString(const string& strAttributeName) const;
- // Method that returns the xmlDoc contained in the Source. (Can be used in a Doc Sink)
+ /**
+ * Getter method.
+ * Method that returns the xmlDoc contained in the Source.
+ * (Can be used in a Doc Sink)
+ *
+ * @return the document _pDoc
+ */
_xmlDoc* getDoc() const;
+ /**
+ * Method that validates the Xml doc contained in pDoc
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
+ virtual bool validate(CXmlSerializingContext& serializingContext);
+
protected:
- // Doc
+ /**
+ * Doc
+ */
_xmlDoc* _pDoc;
- // Root node
+ /**
+ * Root node
+ */
_xmlNode* _pRootNode;
- // libxml2 library cleanup
+ /**
+ * libxml2 library cleanup
+ */
static bool _bLibXml2CleanupScheduled;
+
+private:
+
+ /**
+ * Method that initializes class internal attributes in constructor
+ */
+ void init();
+
+ /** Method that check the validity of the document with the xsd file.
+ *
+ * @return true if document is valid, false if any error occures
+ */
+ bool isInstanceDocumentValid();
+
+ /** Validity error display method
+ *
+ * @param[in] pUserData pointer to the data to validate
+ * @param[out] pError is the xml error output
+ */
+ static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError);
+
+ /**
+ * Schema file
+ */
+ string _strXmlSchemaFile;
+
+ /**
+ * Element type info
+ */
+ string _strRootElementType;
+
+ /**
+ * Element name info
+ */
+ string _strRootElementName;
+
+ /**
+ * Element name attribute info
+ */
+ string _strNameAttrituteName;
+
+ /**
+ * Boolean that enables the root element name attribute check
+ */
+ bool _bNameCheck;
};
diff --git a/xmlserializer/XmlFileDocSink.cpp b/xmlserializer/XmlFileDocSink.cpp
index 4a2b13f..d59ead4 100644
--- a/xmlserializer/XmlFileDocSink.cpp
+++ b/xmlserializer/XmlFileDocSink.cpp
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,8 +18,6 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#include "XmlFileDocSink.h"
@@ -32,10 +30,12 @@ CXmlFileDocSink::CXmlFileDocSink(const string& strXmlInstanceFile):
{
}
-bool CXmlFileDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext)
+bool CXmlFileDocSink::doProcess(CXmlDocSource& xmlDocSource,
+ CXmlSerializingContext& serializingContext)
{
// Write file (formatted)
- if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(), xmlDocSource.getDoc(), "UTF-8", 1) == -1) {
+ if (xmlSaveFormatFileEnc(_strXmlInstanceFile.c_str(),
+ xmlDocSource.getDoc(), "UTF-8", 1) == -1) {
serializingContext.setError("Could not write file " + _strXmlInstanceFile);
diff --git a/xmlserializer/XmlFileDocSink.h b/xmlserializer/XmlFileDocSink.h
index d06365a..370d175 100644
--- a/xmlserializer/XmlFileDocSink.h
+++ b/xmlserializer/XmlFileDocSink.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -19,22 +19,41 @@
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
*
- * CREATED: 2012-08-10
*/
#pragma once
-
#include "XmlDocSink.h"
+#include <string>
+/**
+ * Sink class that save the content of any CXmlDocSource into a file.
+ * The file path is defined in the constructor.
+ */
class CXmlFileDocSink : public CXmlDocSink
{
public:
+ /**
+ * Constructor
+ *
+ * @param[in] strXmlInstanceFile defines the path used to save the file.
+ */
CXmlFileDocSink(const string& strXmlInstanceFile);
private:
- // Source processing
+ /**
+ * Implementation of CXmlDocSink::doProcess()
+ * Write the content of the xmlDocSource to the file opened in strXmlInstanceFile using
+ * UTF-8 encoding
+ *
+ * @param[in] xmlDocSource is the source containing the Xml document
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext);
- // Instance file
+ /**
+ * Name of the instance file
+ */
string _strXmlInstanceFile;
};
diff --git a/xmlserializer/XmlFileDocSource.cpp b/xmlserializer/XmlFileDocSource.cpp
index f1094f1..4df2ad1 100644
--- a/xmlserializer/XmlFileDocSource.cpp
+++ b/xmlserializer/XmlFileDocSource.cpp
@@ -24,64 +24,33 @@
#include "XmlFileDocSource.h"
#include <libxml/parser.h>
-#include <libxml/xmlschemas.h>
#define base CXmlDocSource
-
-
-CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, const string& strRootElementName, const string& strNameAttrituteName) :
- base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0)), _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _strRootElementName(strRootElementName), _strNameAttrituteName(strNameAttrituteName), _bNameCheck(true)
+CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName) :
+ base(xmlReadFile(strXmlInstanceFile.c_str(),NULL, 0),
+ strXmlSchemaFile,
+ strRootElementType,
+ strRootElementName,
+ strNameAttrituteName),
+ _strXmlInstanceFile(strXmlInstanceFile)
{
}
-CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType) :
- base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0)), _strXmlInstanceFile(strXmlInstanceFile), _strXmlSchemaFile(strXmlSchemaFile), _strRootElementType(strRootElementType), _strRootElementName(""), _strNameAttrituteName(""), _bNameCheck(false)
+CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType) :
+ base(xmlReadFile(strXmlInstanceFile.c_str(), NULL, 0),
+ strXmlSchemaFile,
+ strRootElementType),
+ _strXmlInstanceFile(strXmlInstanceFile)
{
}
-bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext)
-{
- // Check that the doc has been created
- if (!isParsable(serializingContext)) {
-
- return false;
- }
-
- // Validate
- if (!isInstanceDocumentValid()) {
-
- serializingContext.setError("Document " + _strXmlInstanceFile + " is not valid");
-
- return false;
- }
-
- // Check Root element type
- if (getRootElementName() != _strRootElementType) {
-
- serializingContext.setError("Error: Wrong XML structure file " + _strXmlInstanceFile);
- serializingContext.appendLineToError("Root Element " + getRootElementName() + " mismatches expected type " + _strRootElementType);
-
- return false;
- }
-
- // Check Root element name attribute (if any)
- if (_bNameCheck) {
-
- string strRootElementNameCheck = getRootElementAttributeString(_strNameAttrituteName);
-
- if (!_strRootElementName.empty() && strRootElementNameCheck != _strRootElementName) {
-
- serializingContext.setError("Error: Wrong XML structure file " + _strXmlInstanceFile);
- serializingContext.appendLineToError(_strRootElementType + " element " + _strRootElementName + " mismatches expected " + _strRootElementType + " type " + strRootElementNameCheck);
-
- return false;
- }
- }
-
- return true;
-}
-
bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) const
{
// Check that the doc has been created
@@ -95,68 +64,15 @@ bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) c
return true;
}
-bool CXmlFileDocSource::isInstanceDocumentValid()
+bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext)
{
-#ifdef LIBXML_SCHEMAS_ENABLED
- xmlDocPtr pSchemaDoc = xmlReadFile(_strXmlSchemaFile.c_str(), NULL, XML_PARSE_NONET);
-
- if (!pSchemaDoc) {
- // Unable to load Schema
- return false;
- }
-
- xmlSchemaParserCtxtPtr pParserCtxt = xmlSchemaNewDocParserCtxt(pSchemaDoc);
-
- if (!pParserCtxt) {
-
- // Unable to create schema context
- xmlFreeDoc(pSchemaDoc);
- return false;
- }
+ if (!base::validate(serializingContext)) {
- // Get Schema
- xmlSchemaPtr pSchema = xmlSchemaParse(pParserCtxt);
+ // Add the file's name in the error message
+ serializingContext.appendLineToError("File : " + _strXmlInstanceFile);
- if (!pSchema) {
-
- // Invalid Schema
- xmlSchemaFreeParserCtxt(pParserCtxt);
- xmlFreeDoc(pSchemaDoc);
- return false;
- }
- xmlSchemaValidCtxtPtr pValidationCtxt = xmlSchemaNewValidCtxt(pSchema);
-
- if (!pValidationCtxt) {
-
- // Unable to create validation context
- xmlSchemaFree(pSchema);
- xmlSchemaFreeParserCtxt(pParserCtxt);
- xmlFreeDoc(pSchemaDoc);
return false;
}
- xmlSetStructuredErrorFunc(this, schemaValidityStructuredErrorFunc);
- //xmlSchemaSetValidErrors(pValidationCtxt, schemaValidityErrorFunc, schemaValidityWarningFunc, NULL);
-
- bool isDocValid = xmlSchemaValidateDoc(pValidationCtxt, _pDoc) == 0;
-
- xmlSchemaFreeValidCtxt(pValidationCtxt);
- xmlSchemaFree(pSchema);
- xmlSchemaFreeParserCtxt(pParserCtxt);
- xmlFreeDoc(pSchemaDoc);
-
- return isDocValid;
-#else
return true;
-#endif
-}
-
-void CXmlFileDocSource::schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError)
-{
- (void)pUserData;
-
-#ifdef LIBXML_SCHEMAS_ENABLED
- // Display message
- puts(pError->message);
-#endif
}
diff --git a/xmlserializer/XmlFileDocSource.h b/xmlserializer/XmlFileDocSource.h
index 46c5230..98ba6e3 100644
--- a/xmlserializer/XmlFileDocSource.h
+++ b/xmlserializer/XmlFileDocSource.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,49 +18,64 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#pragma once
-
#include "XmlDocSource.h"
-#include "XmlSource.h"
-
-struct _xmlError;
+#include <string>
+/**
+ * Source class that read a file to get an xml document.
+ * Its base class will validate the document.
+ */
class CXmlFileDocSource : public CXmlDocSource
{
public:
- CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType, const string& strRootElementName, const string& strNameAttrituteName);
-
+ /**
+ * Constructor
+ *
+ * @param[in] strXmlInstanceFile a string containing the path to the xml file
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strRootElementType a string containing the root element type
+ * @param[in] strRootElementName a string containing the root element name
+ * @param[in] strNameAttributeName a string containing the name of the root name attribute
+ */
+ CXmlFileDocSource(const string& strXmlInstanceFile,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName);
+ /**
+ * Constructor
+ *
+ * @param[in] strXmlInstanceFile a string containing the path to the xml file
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strRootElementType a string containing the root element type
+ */
CXmlFileDocSource(const string& strXmlInstanceFile, const string& strXmlSchemaFile, const string& strRootElementType);
-
- // CXmlDocSource method implemented
+ /**
+ * CXmlDocSource method implementation.
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
virtual bool populate(CXmlSerializingContext& serializingContext);
- // Check that the file exists and is readable
+ /**
+ * Method that checks that the file exists and is readable.
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs during the parsing
+ */
virtual bool isParsable(CXmlSerializingContext& serializingContext) const;
private:
- // Validation of the document with the xsd file
- bool isInstanceDocumentValid();
-
- static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError);
-
- // Instance file
+ /**
+ * Instance file
+ */
string _strXmlInstanceFile;
- // Schema file
- string _strXmlSchemaFile;
- // Element type info
- string _strRootElementType;
- // Element name info
- string _strRootElementName;
- // Element name attribute info
- string _strNameAttrituteName;
-
- bool _bNameCheck;
-
};
diff --git a/xmlserializer/XmlMemoryDocSink.cpp b/xmlserializer/XmlMemoryDocSink.cpp
index 6318496..85dd691 100644
--- a/xmlserializer/XmlMemoryDocSink.cpp
+++ b/xmlserializer/XmlMemoryDocSink.cpp
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,8 +18,6 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#include "XmlMemoryDocSink.h"
@@ -31,7 +29,8 @@ CXmlMemoryDocSink::CXmlMemoryDocSink(IXmlSink* pXmlSink):
{
}
-bool CXmlMemoryDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext)
+bool CXmlMemoryDocSink::doProcess(CXmlDocSource& xmlDocSource,
+ CXmlSerializingContext& serializingContext)
{
CXmlElement docElement;
diff --git a/xmlserializer/XmlMemoryDocSink.h b/xmlserializer/XmlMemoryDocSink.h
index 9bc2acf..e2e261c 100644
--- a/xmlserializer/XmlMemoryDocSink.h
+++ b/xmlserializer/XmlMemoryDocSink.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -19,21 +19,37 @@
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
*
- * CREATED: 2012-08-10
*/
#pragma once
-
#include "XmlDocSink.h"
#include "XmlSink.h"
+/**
+ * Sink class used to parse an xml document and instanciate parameter-framework structures.
+ */
class CXmlMemoryDocSink : public CXmlDocSink
{
public:
+ /**
+ * Constructor
+ *
+ * @param[out] pXmlSink a pointer to a parameter-framework structure that can parse an xml
+ * description to instanciate itself
+ */
CXmlMemoryDocSink(IXmlSink* pXmlSink);
private:
- // Source processing
+ /**
+ * Implementation of CXmlDocSink::doProcess()
+ * Parse the Xml document contained in xmlDocSource to instanciate the parameter-framework
+ * structures.
+ *
+ * @param[in] xmlDocSource is the source containing the Xml document
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext);
// Xml Sink
diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp
index ffa86e3..c323e44 100644
--- a/xmlserializer/XmlMemoryDocSource.cpp
+++ b/xmlserializer/XmlMemoryDocSource.cpp
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,8 +18,6 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#include "XmlMemoryDocSource.h"
@@ -28,14 +26,22 @@
#define base CXmlDocSource
-CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, const string& strXmlSchemaFile, const string& strProduct, const string& strVersion):
- base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true), _strProduct(strProduct), _strVersion(strVersion)
+CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource,
+ const string& strRootElementType,
+ const string& strXmlSchemaFile,
+ const string& strProduct,
+ const string& strVersion):
+ base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
+ _pXmlSource(pXmlSource), _strXmlSchemaFile(strXmlSchemaFile), _bWithHeader(true),
+ _strProduct(strProduct), _strVersion(strVersion)
{
init();
}
-CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType):
- base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _bWithHeader(false)
+CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource,
+ const string& strRootElementType):
+ base(xmlNewDoc(BAD_CAST "1.0"), xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())),
+ _pXmlSource(pXmlSource), _bWithHeader(false)
{
init();
}
@@ -52,7 +58,9 @@ void CXmlMemoryDocSource::init()
bool CXmlMemoryDocSource::populate(CXmlSerializingContext& serializingContext)
{
#ifndef LIBXML_TREE_ENABLED
- serializingContext.setError("XML file exporting feature unsupported on this image. This easiest way to activate it is to do a global recompilation with LIBXML_TREE_ENABLED compiler switch set");
+ serializingContext.setError("XML file exporting feature unsupported on this image. " +
+ "This easiest way to activate it is to do a global " +
+ "recompilation with LIBXML_TREE_ENABLED compiler switch set");
return false;
#endif
diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h
index 4a1de63..ffa6513 100644
--- a/xmlserializer/XmlMemoryDocSource.h
+++ b/xmlserializer/XmlMemoryDocSource.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -19,34 +19,73 @@
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
*
- * CREATED: 2012-08-10
*/
#pragma once
-
+#include <string>
#include "XmlDocSource.h"
#include "XmlSource.h"
+using std::string;
+
+/**
+ * Source class that uses parameter-framework's structures to create an xml document
+ */
class CXmlMemoryDocSource : public CXmlDocSource
{
public:
- CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType, const string& strXmlSchemaFile, const string& strProduct, const string& strVersion);
+ /**
+ * Constructor
+ *
+ * @param[in] pXmlSource a pointer to a parameter-framework structure that can generate
+ * an xml description of itself
+ * @param[in] strRootElementType a string containing the root element type
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strProduct a string containing the product name
+ * @param[in] strVersion a string containing the version number
+ */
+ CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType,
+ const string& strXmlSchemaFile, const string& strProduct,
+ const string& strVersion);
+ /**
+ * Constructor
+ *
+ * @param[in] pXmlSource a pointer to a parameter-framework structure that can generate
+ * an xml description of itself
+ * @param[in] strRootElementType a string containing the root element type
+ */
CXmlMemoryDocSource(const IXmlSource* pXmlSource, const string& strRootElementType);
+ /**
+ * Implementation of CXmlDocSource::populate() method.
+ * Method that popuplates the Xml document using the IXmlSource given in the constructor.
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
virtual bool populate(CXmlSerializingContext& serializingContext);
private:
- // initialize root element
+ /**
+ * Initialize root element
+ */
void init();
- // Xml Source
+ /**
+ * Xml Source
+ */
const IXmlSource* _pXmlSource;
- // Schema file
+ /**
+ * Schema file
+ */
string _strXmlSchemaFile;
- // Boolean used to specify if a header should be added in the Xml Doc
+ /**
+ * Boolean used to specify if a header should be added in the Xml Doc
+ */
bool _bWithHeader;
// Product and version info
diff --git a/xmlserializer/XmlStringDocSink.cpp b/xmlserializer/XmlStringDocSink.cpp
index c38036d..e635fdc 100644
--- a/xmlserializer/XmlStringDocSink.cpp
+++ b/xmlserializer/XmlStringDocSink.cpp
@@ -32,7 +32,8 @@ CXmlStringDocSink::CXmlStringDocSink(string& strResult):
{
}
-bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext)
+bool CXmlStringDocSink::doProcess(CXmlDocSource& xmlDocSource,
+ CXmlSerializingContext& serializingContext)
{
(void)serializingContext;
diff --git a/xmlserializer/XmlStringDocSink.h b/xmlserializer/XmlStringDocSink.h
index 2d777fa..576b244 100644
--- a/xmlserializer/XmlStringDocSink.h
+++ b/xmlserializer/XmlStringDocSink.h
@@ -1,6 +1,6 @@
/*
* INTEL CONFIDENTIAL
- * Copyright © 2011 Intel
+ * Copyright © 2013 Intel
* Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related to
@@ -18,25 +18,42 @@
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Intel in writing.
- *
- * CREATED: 2012-08-10
*/
#pragma once
-
+#include <string>
#include "XmlDocSink.h"
#include "XmlSource.h"
+using std::string;
+
+/**
+ * Sink class that writes the content of any CXmlDocSource into a string.
+ * A reference to an empty string is given in the constructor.
+ */
class CXmlStringDocSink : public CXmlDocSink
{
public:
+ /** Constructor
+ *
+ * @param[out] strResult a reference to a string that will be filled by the doProcess method
+ */
CXmlStringDocSink(string& strResult);
private:
- // Source processing
+ /** Implementation of CXmlDocSink::doProcess()
+ * Writes the content of the xmlDocSource in strResult
+ *
+ * @param[in] xmlDocSource is the source containing the Xml document
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
virtual bool doProcess(CXmlDocSource& xmlDocSource, CXmlSerializingContext& serializingContext);
- // Result string containing the XML informations
+ /**
+ * Result string containing the XML informations
+ */
string& _strResult;
};
diff --git a/xmlserializer/XmlStringDocSource.cpp b/xmlserializer/XmlStringDocSource.cpp
new file mode 100644
index 0000000..f9aa65d
--- /dev/null
+++ b/xmlserializer/XmlStringDocSource.cpp
@@ -0,0 +1,44 @@
+/*
+ * INTEL CONFIDENTIAL
+ * Copyright © 2013 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ */
+
+#include "XmlStringDocSource.h"
+#include <libxml/parser.h>
+
+#define base CXmlDocSource
+
+CXmlStringDocSource::CXmlStringDocSource(const string& strXmlInput,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName) :
+ base(xmlReadMemory(strXmlInput.c_str(), strXmlInput.size(), "", NULL, 0),
+ strXmlSchemaFile,
+ strRootElementType,
+ strRootElementName,
+ strNameAttrituteName)
+{
+}
+
+bool CXmlStringDocSource::populate(CXmlSerializingContext &serializingContext)
+{
+ return validate(serializingContext);
+}
diff --git a/xmlserializer/XmlStringDocSource.h b/xmlserializer/XmlStringDocSource.h
new file mode 100644
index 0000000..b2edcf4
--- /dev/null
+++ b/xmlserializer/XmlStringDocSource.h
@@ -0,0 +1,60 @@
+/*
+ * INTEL CONFIDENTIAL
+ * Copyright © 2013 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ */
+
+#pragma once
+#include "XmlDocSource.h"
+#include <string>
+
+/**
+ * Source class that get an xml document from a string.
+ * Its base class will check the validity of the document.
+ */
+class CXmlStringDocSource : public CXmlDocSource
+{
+public:
+ /**
+ * Constructor
+ *
+ * @param[in] strXmlInput a string containing an xml description
+ * @param[in] strXmlSchemaFile a string containing the path to the schema file
+ * @param[in] strRootElementType a string containing the root element type
+ * @param[in] strRootElementName a string containing the root element name
+ * @param[in] strNameAttributeName a string containing the name of the root name attribute
+ */
+ CXmlStringDocSource(const string& strXmlInput,
+ const string& strXmlSchemaFile,
+ const string& strRootElementType,
+ const string& strRootElementName,
+ const string& strNameAttrituteName);
+
+ /**
+ * CXmlDocSource method implementation.
+ *
+ * @param[out] serializingContext is used as error output
+ *
+ * @return false if any error occurs
+ */
+ virtual bool populate(CXmlSerializingContext& serializingContext);
+};
+
+