Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 1 | /* |
| 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 Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 27 | #include <libxml/xinclude.h> |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 28 | |
| 29 | #define base CXmlDocSource |
| 30 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 31 | CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, |
| 32 | const string& strXmlSchemaFile, |
| 33 | const string& strRootElementType, |
| 34 | const string& strRootElementName, |
| 35 | const string& strNameAttrituteName) : |
Guillaume Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 36 | base(readFile(strXmlInstanceFile), |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 37 | strXmlSchemaFile, |
| 38 | strRootElementType, |
| 39 | strRootElementName, |
| 40 | strNameAttrituteName), |
| 41 | _strXmlInstanceFile(strXmlInstanceFile) |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 45 | CXmlFileDocSource::CXmlFileDocSource(const string& strXmlInstanceFile, |
| 46 | const string& strXmlSchemaFile, |
| 47 | const string& strRootElementType) : |
Guillaume Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 48 | base(readFile(strXmlInstanceFile), |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 49 | strXmlSchemaFile, |
| 50 | strRootElementType), |
| 51 | _strXmlInstanceFile(strXmlInstanceFile) |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
Frédéric Boisnard | a409daa | 2012-10-18 18:20:03 +0200 | [diff] [blame] | 55 | bool 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 Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 68 | bool CXmlFileDocSource::populate(CXmlSerializingContext& serializingContext) |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 69 | { |
Guillaume Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 70 | if (!validate(serializingContext)) { |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 71 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame] | 72 | // Add the file's name in the error message |
| 73 | serializingContext.appendLineToError("File : " + _strXmlInstanceFile); |
| 74 | |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 75 | return false; |
| 76 | } |
| 77 | |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 78 | return true; |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 79 | } |
Guillaume Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 80 | |
| 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 | } |