lordgamez commented on code in PR #1995: URL: https://github.com/apache/nifi-minifi-cpp/pull/1995#discussion_r2329761010
########## extensions/standard-processors/controllers/XMLReader.cpp: ########## @@ -0,0 +1,200 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "XMLReader.h" + +#include <algorithm> + +#include "core/Resource.h" +#include "utils/TimeUtil.h" +#include "utils/gsl.h" + +namespace org::apache::nifi::minifi::standard { + +namespace { +bool hasChildNodes(const pugi::xml_node& node) { + return std::any_of(node.begin(), node.end(), [] (const pugi::xml_node& child) { + return child.type() == pugi::node_element; + }); +} + +void addRecordFieldToObject(core::RecordObject& record_object, const std::string& name, const core::RecordField& field) { + auto it = record_object.find(name); + if (it == record_object.end()) { + record_object.emplace(name, field); + return; + } + + if (std::holds_alternative<core::RecordArray>(it->second.value_)) { + std::get<core::RecordArray>(it->second.value_).emplace_back(field); + return; + } + + core::RecordArray array; + array.emplace_back(it->second); + array.emplace_back(field); + it->second = core::RecordField(std::move(array)); +} +} // namespace + +void XMLReader::writeRecordField(core::RecordObject& record_object, const std::string& name, const std::string& value, bool write_pcdata_node) const { + // If the name is the value set in the Field Name for Content property, we should only add this value to the RecordObject if we are writing a plain character data node. + if (!write_pcdata_node && name == field_name_for_content_) { + return; + } + + if (value == "true" || value == "false") { + addRecordFieldToObject(record_object, name, core::RecordField(value == "true")); + return; + } else if (auto date = utils::timeutils::parseDateTimeStr(value)) { + addRecordFieldToObject(record_object, name, core::RecordField(*date)); + return; + } else if (auto date = utils::timeutils::parseRfc3339(value)) { + addRecordFieldToObject(record_object, name, core::RecordField(*date)); + return; + } + + if (std::all_of(value.begin(), value.end(), ::isdigit)) { Review Comment: I checked in NiFi and it is not allowed there either, it throws an exception when NiFi tries to parse a number with whitespaces around it: `java.lang.NumberFormatException: For input string: " 1"` I think we should not allow it either in this case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
