summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parameter/BaseParameter.cpp7
-rw-r--r--parameter/BaseParameter.h3
-rw-r--r--parameter/BitParameterBlockType.cpp9
-rw-r--r--parameter/BitParameterBlockType.h3
-rw-r--r--parameter/BitParameterType.cpp16
-rw-r--r--parameter/BitParameterType.h2
-rw-r--r--parameter/EnumParameterType.cpp8
-rw-r--r--parameter/EnumParameterType.h3
-rw-r--r--parameter/EnumValuePair.cpp12
-rw-r--r--parameter/EnumValuePair.h3
-rw-r--r--parameter/FixedPointParameterType.cpp15
-rw-r--r--parameter/FixedPointParameterType.h3
-rw-r--r--parameter/IntegerParameterType.cpp30
-rw-r--r--parameter/IntegerParameterType.h3
-rw-r--r--parameter/ParameterMgr.cpp147
-rw-r--r--parameter/ParameterMgr.h9
-rw-r--r--parameter/StringParameterType.cpp9
-rw-r--r--parameter/StringParameterType.h3
-rw-r--r--parameter/SystemClass.cpp8
-rw-r--r--parameter/SystemClass.h3
-rw-r--r--parameter/TypeElement.cpp11
-rw-r--r--parameter/TypeElement.h3
-rw-r--r--parameter/XmlFileIncluderElement.cpp18
-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
41 files changed, 898 insertions, 323 deletions
diff --git a/parameter/BaseParameter.cpp b/parameter/BaseParameter.cpp
index caa9daa..7ca96a7 100644
--- a/parameter/BaseParameter.cpp
+++ b/parameter/BaseParameter.cpp
@@ -218,3 +218,10 @@ bool CBaseParameter::accessValue(CPathNavigator& pathNavigator, string& strValue
return accessAsString(strValue, bSet, parameterAccessContext);
}
+
+void CBaseParameter::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+
+ // Delegate to type element
+ getTypeElement()->toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/BaseParameter.h b/parameter/BaseParameter.h
index a9dc0e5..80636cb 100644
--- a/parameter/BaseParameter.h
+++ b/parameter/BaseParameter.h
@@ -64,6 +64,9 @@ public:
bool accessAsString(string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
virtual bool accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const;
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
protected:
// Parameter Access
virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
diff --git a/parameter/BitParameterBlockType.cpp b/parameter/BitParameterBlockType.cpp
index f89651a..e219553 100644
--- a/parameter/BitParameterBlockType.cpp
+++ b/parameter/BitParameterBlockType.cpp
@@ -62,3 +62,12 @@ CInstanceConfigurableElement* CBitParameterBlockType::doInstantiate() const
{
return new CBitParameterBlock(getName(), this);
}
+
+// From IXmlSource
+void CBitParameterBlockType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Size
+ xmlElement.setAttributeString("Size", toString(_uiSize * 8));
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/BitParameterBlockType.h b/parameter/BitParameterBlockType.h
index c074f43..36845ff 100644
--- a/parameter/BitParameterBlockType.h
+++ b/parameter/BitParameterBlockType.h
@@ -37,6 +37,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// CElement
virtual string getKind() const;
private:
diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp
index 83865dc..6c5a90f 100644
--- a/parameter/BitParameterType.cpp
+++ b/parameter/BitParameterType.cpp
@@ -233,3 +233,19 @@ bool CBitParameterType::isEncodable(uint32_t uiData) const
return true;
}
+
+// From IXmlSource
+void CBitParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Position
+ xmlElement.setAttributeString("Pos", toString(_uiBitPos));
+
+ // Size
+ xmlElement.setAttributeString("Size", toString(_uiBitSize));
+
+ // Maximum
+ xmlElement.setAttributeString("Max", toString(_uiMax));
+
+ base::toXml(xmlElement, serializingContext);
+
+}
diff --git a/parameter/BitParameterType.h b/parameter/BitParameterType.h
index fcf96c2..08201da 100644
--- a/parameter/BitParameterType.h
+++ b/parameter/BitParameterType.h
@@ -38,6 +38,8 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
/// Conversion
// String
bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp
index c89aaf4..dcdbfaa 100644
--- a/parameter/EnumParameterType.cpp
+++ b/parameter/EnumParameterType.cpp
@@ -333,3 +333,11 @@ bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parame
return false;
}
+// From IXmlSource
+void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Size
+ xmlElement.setAttributeString("Size", toString(getSize() * 8));
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/EnumParameterType.h b/parameter/EnumParameterType.h
index 3e4c3a2..ea5f857 100644
--- a/parameter/EnumParameterType.h
+++ b/parameter/EnumParameterType.h
@@ -36,6 +36,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
/// Conversion
// String
virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
diff --git a/parameter/EnumValuePair.cpp b/parameter/EnumValuePair.cpp
index 1a03134..49ee017 100644
--- a/parameter/EnumValuePair.cpp
+++ b/parameter/EnumValuePair.cpp
@@ -67,3 +67,15 @@ void CEnumValuePair::logValue(string& strValue, CErrorContext& errorContext) con
// Convert value
strValue = getNumericalAsString();
}
+
+// From IXmlSource
+void CEnumValuePair::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Literal
+ xmlElement.setAttributeString("Literal", this->getName());
+
+ // Numerical
+ xmlElement.setAttributeString("Numerical", getNumericalAsString());
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/EnumValuePair.h b/parameter/EnumValuePair.h
index a9e8245..84c755e 100644
--- a/parameter/EnumValuePair.h
+++ b/parameter/EnumValuePair.h
@@ -38,6 +38,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// CElement
virtual string getKind() const;
protected:
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp
index aa93ac2..3c9e20f 100644
--- a/parameter/FixedPointParameterType.cpp
+++ b/parameter/FixedPointParameterType.cpp
@@ -340,3 +340,18 @@ double CFixedPointParameterType::asDouble(int32_t iValue) const
// Convert
return (double)iValue / (1UL << _uiFractional);
}
+
+// From IXmlSource
+void CFixedPointParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Size
+ xmlElement.setAttributeString("Size", toString(getSize() * 8));
+
+ // Integral
+ xmlElement.setAttributeString("Integral", toString(_uiIntegral));
+
+ // Fractional
+ xmlElement.setAttributeString("Fractional", toString(_uiFractional));
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/FixedPointParameterType.h b/parameter/FixedPointParameterType.h
index 30922a0..617f121 100644
--- a/parameter/FixedPointParameterType.h
+++ b/parameter/FixedPointParameterType.h
@@ -34,6 +34,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// XML Serialization value space handling
// Value space handling for configuration import
virtual void handleValueSpaceAttribute(CXmlElement& xmlConfigurableElementSettingsElement, CConfigurationAccessContext& configurationAccessContext) const;
diff --git a/parameter/IntegerParameterType.cpp b/parameter/IntegerParameterType.cpp
index 8fadf27..b6784d9 100644
--- a/parameter/IntegerParameterType.cpp
+++ b/parameter/IntegerParameterType.cpp
@@ -428,3 +428,33 @@ const CParameterAdaptation* CIntegerParameterType::getParameterAdaptation() cons
{
return static_cast<const CParameterAdaptation*>(findChildOfKind("Adaptation"));
}
+
+// From IXmlSource
+void CIntegerParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Sign
+ xmlElement.setAttributeBoolean("Signed", _bSigned);
+
+ if (_bSigned) {
+
+ // Mininmum
+ xmlElement.setAttributeString("Min", toString((int32_t)_uiMin));
+
+ // Maximum
+ xmlElement.setAttributeString("Max", toString((int32_t)_uiMax));
+
+ } else {
+
+ // Minimum
+ xmlElement.setAttributeString("Min", toString(_uiMin));
+
+ // Maximum
+ xmlElement.setAttributeString("Max", toString(_uiMax));
+ }
+
+ // Size
+ xmlElement.setAttributeString("Size", toString(getSize() * 8));
+
+ base::toXml(xmlElement, serializingContext);
+
+}
diff --git a/parameter/IntegerParameterType.h b/parameter/IntegerParameterType.h
index b29f0ac..9fb0dfd 100644
--- a/parameter/IntegerParameterType.h
+++ b/parameter/IntegerParameterType.h
@@ -36,6 +36,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
/// Conversion
// String
virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index ddce610..9f1d160 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -23,7 +23,6 @@
* UPDATED: 2011-07-27
*/
#include "ParameterMgr.h"
-#include "XmlParser.h"
#include "XmlParameterSerializingContext.h"
#include "XmlElementSerializingContext.h"
#include "SystemClass.h"
@@ -54,7 +53,6 @@
#include "ConfigurableDomains.h"
#include "ConfigurableDomain.h"
#include "DomainConfiguration.h"
-#include "XmlComposer.h"
#include "XmlDomainSerializingContext.h"
#include "BitParameterBlockType.h"
#include "BitParameterType.h"
@@ -74,6 +72,11 @@
#include "ParameterHandle.h"
#include "LinearParameterAdaptation.h"
#include "EnumValuePair.h"
+#include "XmlFileDocSink.h"
+#include "XmlFileDocSource.h"
+#include "XmlStringDocSink.h"
+#include "XmlMemoryDocSink.h"
+#include "XmlMemoryDocSource.h"
#define base CElement
@@ -166,7 +169,10 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa
{ "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
{ "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
{ "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
- { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
+ { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" },
+ { "getDomainsXML", &CParameterMgr::getDomainsXMLCommmandProcess, 0 ,"", "Print domains including settings as XML" },
+ /// Structure Export
+ { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,"", "Print parameter structure as XML" }
};
// Remote command parsers array Size
const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
@@ -510,43 +516,20 @@ bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingCo
// Get Schema file associated to root element
string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
- // Parse Structure XML file
- CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
-
- if (!parser.open()) {
-
- return false;
- }
-
- // Check Root element name attribute (if any)
- string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
-
- if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
-
- elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
- elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
-
- return false;
- }
+ CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
// Start clean
pRootElement->clean();
- // Parse
- if (!parser.parse(pRootElement)) {
+ CXmlMemoryDocSink memorySink(pRootElement);
- // Cleanup
+ if (!memorySink.process(fileDocSource, elementSerializingContext)) {
+ //Cleanup
pRootElement->clean();
return false;
}
- // Close parser
- if (!parser.close()) {
-
- return false;
- }
-
return true;
}
@@ -1274,6 +1257,32 @@ 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)
+{
+ (void)remoteCommand;
+
+ if (!getDomainsXMLString(strResult, true)) {
+
+ return CCommandHandler::EFailed;
+ }
+ // Succeeded
+ return CCommandHandler::ESucceeded;
+}
+
+CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
+{
+ (void)remoteCommand;
+
+ if (!getSystemClassXMLString(strResult)) {
+
+ return CCommandHandler::EFailed;
+ }
+ // Succeeded
+ return CCommandHandler::ESucceeded;
+}
+
// User set/get parameters
bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
{
@@ -1646,21 +1655,13 @@ bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettin
// Output raw format
xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
- // Instantiate composer
- CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
-
- // Open composer
- if (!xmlComposer.open()) {
+ // Use a doc source by loading data from instantiated Configurable Domains
+ CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
- return false;
- }
-
- // Compose
- xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
-
- // Close composer
- if (!xmlComposer.close()) {
+ // Use a doc sink to write the doc data in a file
+ CXmlFileDocSink fileSink(strFileName);
+ if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
return false;
}
@@ -1891,3 +1892,63 @@ const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
{
return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
}
+
+/// 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
+ const CSystemClass* pSystemClass = getSystemClass();
+
+ string strError;
+
+ CXmlSerializingContext xmlSerializingContext(strError);
+
+ // Use a doc source by loading data from instantiated Configurable Domains
+ CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
+
+ // Use a doc sink that write the doc data in a string
+ CXmlStringDocSink stringSink(strResult);
+
+ if (!stringSink.process(memorySource, xmlSerializingContext)) {
+ strResult = strError;
+ return false;
+ }
+
+ return true;
+}
diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h
index 59b4ab3..78db932 100644
--- a/parameter/ParameterMgr.h
+++ b/parameter/ParameterMgr.h
@@ -32,6 +32,8 @@
#include "Element.h"
#include <map>
#include <vector>
+#include "XmlDocSink.h"
+#include "XmlDocSource.h"
class CElementLibrarySet;
@@ -159,6 +161,10 @@ public:
bool importDomainsBinary(const string& strFileName, string& strError);
bool exportDomainsBinary(const string& strFileName, string& strError);
+ // GUI command XML send
+ bool getDomainsXMLString(string& strResult, bool bWithSettings);
+ bool getSystemClassXMLString(string& strResult);
+
// Introspect
void logStructureContent(string& strContent) const;
@@ -242,6 +248,9 @@ 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);
// Max command usage length, use for formatting
void setMaxCommandUsageLength();
diff --git a/parameter/StringParameterType.cpp b/parameter/StringParameterType.cpp
index 12d3741..840528e 100644
--- a/parameter/StringParameterType.cpp
+++ b/parameter/StringParameterType.cpp
@@ -68,3 +68,12 @@ uint32_t CStringParameterType::getMaxLength() const
{
return _uiMaxLength;
}
+
+// From IXmlSource
+void CStringParameterType::toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const
+{
+ // MaxLength
+ xmlElement.setAttributeInteger("MaxLength", _uiMaxLength);
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/StringParameterType.h b/parameter/StringParameterType.h
index 55d96c9..8ad3d70 100644
--- a/parameter/StringParameterType.h
+++ b/parameter/StringParameterType.h
@@ -39,6 +39,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// Element properties
virtual void showProperties(string& strResult) const;
diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp
index e108c05..8d6b334 100644
--- a/parameter/SystemClass.cpp
+++ b/parameter/SystemClass.cpp
@@ -237,3 +237,11 @@ bool CSystemClass::init(string& strError)
return base::init(strError);
}
+// From IXmlSource
+void CSystemClass::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Set the name of system class
+ xmlElement.setNameAttribute(getName());
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h
index 9dbbf92..5cb86e4 100644
--- a/parameter/SystemClass.h
+++ b/parameter/SystemClass.h
@@ -45,6 +45,9 @@ public:
virtual bool init(string& strError);
virtual string getKind() const;
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
private:
CSystemClass(const CSystemClass&);
CSystemClass& operator=(const CSystemClass&);
diff --git a/parameter/TypeElement.cpp b/parameter/TypeElement.cpp
index 4c32bc2..405dc7d 100644
--- a/parameter/TypeElement.cpp
+++ b/parameter/TypeElement.cpp
@@ -125,3 +125,14 @@ CMappingData* CTypeElement::getMappingData()
}
return _pMappingData;
}
+
+// From IXmlSource
+void CTypeElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ if (!isScalar()) {
+
+ xmlElement.setAttributeInteger("ArrayLength", getArrayLength());
+ }
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/TypeElement.h b/parameter/TypeElement.h
index e8855c6..bf0b306 100644
--- a/parameter/TypeElement.h
+++ b/parameter/TypeElement.h
@@ -48,6 +48,9 @@ public:
// From IXmlSink
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
+ // From IXmlSource
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// Scalar or Array?
bool isScalar() const;
diff --git a/parameter/XmlFileIncluderElement.cpp b/parameter/XmlFileIncluderElement.cpp
index 6e93721..89e5c14 100644
--- a/parameter/XmlFileIncluderElement.cpp
+++ b/parameter/XmlFileIncluderElement.cpp
@@ -23,7 +23,8 @@
* UPDATED: 2011-07-27
*/
#include "XmlFileIncluderElement.h"
-#include "XmlParser.h"
+#include "XmlFileDocSource.h"
+#include "XmlMemoryDocSink.h"
#include "XmlElementSerializingContext.h"
#include "ElementLibrary.h"
#include <assert.h>
@@ -52,17 +53,13 @@ bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSeriali
// Instantiate parser
string strIncludedElementType = getIncludedElementType();
- CXmlParser parser(strPath, elementSerializingContext.getXmlSchemaPathFolder() + "/" + strIncludedElementType + ".xsd", strIncludedElementType, elementSerializingContext);
-
- if (!parser.open()) {
-
- return false;
- }
+ // Use a doc source that load data from a file
+ CXmlFileDocSource fileDocSource(strPath, elementSerializingContext.getXmlSchemaPathFolder() + "/" + strIncludedElementType + ".xsd", strIncludedElementType);
// Get top level element
CXmlElement childElement;
- parser.getRootElement(childElement);
+ fileDocSource.getRootElement(childElement);
// Create child element
CElement* pChild = elementSerializingContext.getElementLibrary()->createElement(childElement);
@@ -78,7 +75,10 @@ bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSeriali
return false;
}
- if (!parser.parse(pChild)) {
+ // Use a doc sink that instantiate the structure from the doc source
+ CXmlMemoryDocSink memorySink(pChild);
+
+ if (!memorySink.process(fileDocSource, elementSerializingContext)) {
return false;
}
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;
};