blob: 53e7c86cdc97f4deae2f158a9d973e045837a2bc [file] [log] [blame]
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001/*
2 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
22 * CREATED: 2012-08-10
23 */
24
25#include "XmlFileDocSource.h"
26#include <libxml/parser.h>
Guillaume Denneulin3ba083e2014-01-31 15:09:42 +010027#include <libxml/xinclude.h>
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020028
29#define base CXmlDocSource
30
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020031CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
32 const string& strXmlSchemaFile,
33 const string& strRootElementType,
34 const string& strRootElementName,
35 const string& strNameAttrituteName) :
Guillaume Denneulin3ba083e2014-01-31 15:09:42 +010036 base(readFile(strXmlInstanceFile),
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020037 strXmlSchemaFile,
38 strRootElementType,
39 strRootElementName,
40 strNameAttrituteName),
41 _strXmlInstanceFile(strXmlInstanceFile)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020042{
43}
44
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020045CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile,
46 const string& strXmlSchemaFile,
47 const string& strRootElementType) :
Guillaume Denneulin3ba083e2014-01-31 15:09:42 +010048 base(readFile(strXmlInstanceFile),
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020049 strXmlSchemaFile,
50 strRootElementType),
51 _strXmlInstanceFile(strXmlInstanceFile)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020052{
53}
54
Frédéric Boisnarda409daa2012-10-18 18:20:03 +020055bool CXmlFileDocSource::isParsable(CXmlSerializingContext& serializingContext) const
56{
57 // Check that the doc has been created
58 if (!_pDoc) {
59
60 serializingContext.setError("Could not parse file " + _strXmlInstanceFile);
61
62 return false;
63 }
64
65 return true;
66}
67
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020068bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020069{
Guillaume Denneulin3ba083e2014-01-31 15:09:42 +010070 if (!validate(serializingContext)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020071
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020072 // Add the file's name in the error message
73 serializingContext.appendLineToError("File : " + _strXmlInstanceFile);
74
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075 return false;
76 }
77
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020078 return true;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020079}
Guillaume Denneulin3ba083e2014-01-31 15:09:42 +010080
81_xmlDoc* CXmlFileDocSource::readFile(const string& strFileName)
82{
83 // Read xml file
84 xmlDocPtr pDoc = xmlReadFile(strFileName.c_str(), NULL, 0);
85
86 if (!pDoc) {
87
88 return NULL;
89 }
90 // Process file inclusion
91 // WARNING: this symbol is available if libxml2 has been compiled with LIBXML_XINCLUDE_ENABLED
92 if (xmlXIncludeProcess(pDoc) < 0) {
93
94 xmlFreeDoc(pDoc);
95 return NULL;
96 }
97
98 return pDoc;
99}