Skip to content

Commit

Permalink
Clarify that gbxmlValidator is 7.03, with reservation for adding new …
Browse files Browse the repository at this point in the history
…schemas
  • Loading branch information
jmarrec committed Dec 18, 2024
1 parent 46344c9 commit ccffa37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/gbxml/ReverseTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "../model/AdditionalProperties.hpp"

#include "../utilities/core/Assert.hpp"
#include "../utilities/core/Compare.hpp"
#include "../utilities/core/FilesystemHelpers.hpp"
#include "../utilities/units/Quantity.hpp"
#include "../utilities/units/UnitFactory.hpp"
Expand Down Expand Up @@ -97,13 +98,19 @@ namespace gbxml {
}
// Scan version of gbxml schema
std::string version = root.attribute("version").value();
VersionString schemaVersion(7, 3);
if (version.empty()) {
LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03.");
version = "7.03";
} else {
try {
schemaVersion = VersionString(version);
} catch (...) {
LOG(Warn, "gbXML has `version` '" << version << "' which was not understood, assuming 7.03.");
}
}
if (version == "7.03") {
if (schemaVersion == VersionString(7, 3)) {
// validate the gbxml prior to reverse translation
auto gbxmlValidator = XMLValidator::gbxmlValidator();
auto gbxmlValidator = XMLValidator::gbxmlValidator(VersionString(7, 3));
gbxmlValidator.validate(path);
} else {
LOG(Error,
Expand Down
10 changes: 7 additions & 3 deletions src/utilities/xml/XMLValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,18 @@ std::vector<LogMessage> XMLValidator::logMessages() const {
return m_logMessages;
}

XMLValidator XMLValidator::gbxmlValidator() {
XMLValidator XMLValidator::gbxmlValidator(const VersionString& schemaVersion) {
const auto tmpDir = openstudio::filesystem::create_temporary_directory("xmlvalidation");
if (tmpDir.empty()) {
LOG_AND_THROW("Failed to create a temporary directory for extracting the embedded path");
}
if (schemaVersion != VersionString(7, 3)) {
LOG_AND_THROW("Unexpected gbXML Schema Version: accepted = [7.03]");
}
const bool quiet = true;
::openstudio::embedded_files::extractFile(":/xml/resources/GreenBuildingXML_Ver7.03.xsd", openstudio::toString(tmpDir), quiet);
auto validator = XMLValidator(tmpDir / "GreenBuildingXML_Ver7.03.xsd");
std::string schemaName = fmt::format("GreenBuildingXML_Ver{}.{:02}.xsd", schemaVersion.major(), schemaVersion.minor());
::openstudio::embedded_files::extractFile(fmt::format(":/xml/resources/{}", schemaName), openstudio::toString(tmpDir), quiet);
auto validator = XMLValidator(tmpDir / schemaName);
validator.m_tempDir = tmpDir;
return validator;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/xml/XMLValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UTILITIES_API XMLValidator
XMLValidator& operator=(const XMLValidator& other) = default;
XMLValidator& operator=(XMLValidator&& other) noexcept = default;

static XMLValidator gbxmlValidator();
static XMLValidator gbxmlValidator(const VersionString& schemaVersion = VersionString(7, 3));

static XMLValidator bclXMLValidator(openstudio::BCLXMLType bclXMLType = openstudio::BCLXMLType::MeasureXML,
const VersionString& schemaVersion = VersionString(3, 1));
Expand Down

0 comments on commit ccffa37

Please sign in to comment.