2013-12-17 01:30:11 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2013 Kitware, Inc.
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmWIXPatchParser.h"
|
|
|
|
|
|
|
|
#include <CPack/cmCPackGenerator.h>
|
|
|
|
|
|
|
|
#include <cm_expat.h>
|
|
|
|
|
|
|
|
cmWIXPatchElement::~cmWIXPatchElement()
|
|
|
|
{
|
|
|
|
for(child_list_t::iterator i = children.begin(); i != children.end(); ++i)
|
|
|
|
{
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmWIXPatchParser::cmWIXPatchParser(
|
|
|
|
fragment_map_t& fragments, cmCPackLog* logger):
|
|
|
|
Logger(logger),
|
2013-12-20 21:12:01 +04:00
|
|
|
State(BEGIN_DOCUMENT),
|
|
|
|
Valid(true),
|
|
|
|
Fragments(fragments)
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmWIXPatchParser::StartElement(const char *name, const char **atts)
|
|
|
|
{
|
|
|
|
std::string name_str = name;
|
2013-12-20 21:12:01 +04:00
|
|
|
if(State == BEGIN_DOCUMENT)
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
|
|
|
if(name_str == "CPackWiXPatch")
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
State = BEGIN_FRAGMENTS;
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReportValidationError("Expected root element 'CPackWiXPatch'");
|
|
|
|
}
|
|
|
|
}
|
2013-12-20 21:12:01 +04:00
|
|
|
else if(State == BEGIN_FRAGMENTS)
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
|
|
|
if(name_str == "CPackWiXFragment")
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
State = INSIDE_FRAGMENT;
|
2013-12-17 01:30:11 +04:00
|
|
|
StartFragment(atts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReportValidationError("Expected 'CPackWixFragment' element");
|
|
|
|
}
|
|
|
|
}
|
2013-12-20 21:12:01 +04:00
|
|
|
else if(State == INSIDE_FRAGMENT)
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
cmWIXPatchElement &parent = *ElementStack.back();
|
2013-12-17 01:30:11 +04:00
|
|
|
|
|
|
|
parent.children.resize(parent.children.size() + 1);
|
|
|
|
cmWIXPatchElement*& currentElement = parent.children.back();
|
|
|
|
currentElement = new cmWIXPatchElement;
|
|
|
|
currentElement->name = name;
|
|
|
|
|
|
|
|
for(size_t i = 0; atts[i]; i += 2)
|
|
|
|
{
|
|
|
|
std::string key = atts[i];
|
|
|
|
std::string value = atts[i+1];
|
|
|
|
|
|
|
|
currentElement->attributes[key] = value;
|
|
|
|
}
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
ElementStack.push_back(currentElement);
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmWIXPatchParser::StartFragment(const char **attributes)
|
|
|
|
{
|
|
|
|
for(size_t i = 0; attributes[i]; i += 2)
|
|
|
|
{
|
|
|
|
std::string key = attributes[i];
|
|
|
|
std::string value = attributes[i+1];
|
|
|
|
|
|
|
|
if(key == "Id")
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
if(Fragments.find(value) != Fragments.end())
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << "Invalid reuse of 'CPackWixFragment' 'Id': " << value;
|
|
|
|
ReportValidationError(tmp.str());
|
|
|
|
}
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
ElementStack.push_back(&Fragments[value]);
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReportValidationError(
|
|
|
|
"The only allowed 'CPackWixFragment' attribute is 'Id'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmWIXPatchParser::EndElement(const char *name)
|
|
|
|
{
|
|
|
|
std::string name_str = name;
|
2013-12-20 21:12:01 +04:00
|
|
|
if(State == INSIDE_FRAGMENT)
|
2013-12-17 01:30:11 +04:00
|
|
|
{
|
|
|
|
if(name_str == "CPackWiXFragment")
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
State = BEGIN_FRAGMENTS;
|
|
|
|
ElementStack.clear();
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
ElementStack.pop_back();
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmWIXPatchParser::ReportError(int line, int column, const char* msg)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while processing XML patch file at " << line << ":" << column <<
|
|
|
|
": "<< msg << std::endl);
|
2013-12-20 21:12:01 +04:00
|
|
|
Valid = false;
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmWIXPatchParser::ReportValidationError(const std::string& message)
|
|
|
|
{
|
|
|
|
ReportError(XML_GetCurrentLineNumber(Parser),
|
|
|
|
XML_GetCurrentColumnNumber(Parser),
|
|
|
|
message.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmWIXPatchParser::IsValid() const
|
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
return Valid;
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|