Skip to content

Commit d613234

Browse files
author
Dan Smith
committed
option to disable XML validation for SICD too
1 parent bc2c97e commit d613234

8 files changed

Lines changed: 59 additions & 45 deletions

File tree

six/modules/c++/six.sicd/include/six/sicd/NITFReadComplexXMLControl.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ namespace six
6464
const six::NITFReadControl& NITFReadControl() const { return reader; }
6565
six::NITFReadControl& NITFReadControl() { return reader; }
6666

67-
void load(const std::string& fromFile,
68-
const std::vector<std::string>& schemaPaths);
69-
void load(const std::filesystem::path& fromFile,
70-
const std::vector<std::filesystem::path>& schemaPaths);
67+
void load(const std::string& fromFile, const std::vector<std::string>* pSchemaPaths);
68+
void load(const std::filesystem::path& fromFile, const std::vector<std::filesystem::path>* pSchemaPaths);
69+
void load(const std::filesystem::path& fromFile, const std::vector<std::filesystem::path>& schemaPaths)
70+
{
71+
load(fromFile, &schemaPaths);
72+
}
7173
void load(const std::filesystem::path& fromFile)
7274
{
73-
static const std::vector<std::filesystem::path> schemaPaths;
74-
load(fromFile, schemaPaths);
75+
load(fromFile, nullptr /*schemaPaths*/);
7576
}
7677
void load(io::FileInputStream&, const std::vector<std::string>& schemaPaths);
7778

six/modules/c++/six.sicd/include/six/sicd/Utilities.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,16 @@ class Utilities
657657

658658

659659
// c.f. six_sicd.i
660-
extern std::vector<std::byte> readFromNITF(const std::filesystem::path&, const std::vector<std::filesystem::path>& schemaPaths,
661-
std::unique_ptr<ComplexData>& pComplexData);
660+
extern std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, const std::vector<std::filesystem::path>*,
661+
std::unique_ptr<ComplexData>& pComplexData);
662+
inline std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, const std::vector<std::filesystem::path>& schemaPaths,
663+
std::unique_ptr<ComplexData>& pComplexData)
664+
{
665+
return readFromNITF(pathname, &schemaPaths, pComplexData);
666+
}
662667
inline std::vector<std::byte> readFromNITF(const std::filesystem::path& pathname, std::unique_ptr<ComplexData>& pComplexData)
663668
{
664-
static const std::vector<std::filesystem::path> schemaPaths;
665-
return readFromNITF(pathname, schemaPaths, pComplexData);
669+
return readFromNITF(pathname, nullptr /*pSchemaPaths*/, pComplexData);
666670
}
667671

668672
// c.f. six_sicd.i

six/modules/c++/six.sicd/source/NITFReadComplexXMLControl.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ six::sicd::NITFReadComplexXMLControl::NITFReadComplexXMLControl()
3939
}
4040

4141
void six::sicd::NITFReadComplexXMLControl::load(const std::string& fromFile,
42-
const std::vector<std::string>& schemaPaths)
42+
const std::vector<std::string>* pSchemaPaths)
4343
{
44-
reader.load(fromFile, schemaPaths);
44+
reader.load(fromFile, pSchemaPaths);
4545
}
4646
void six::sicd::NITFReadComplexXMLControl::load(const std::filesystem::path& fromFile,
47-
const std::vector<std::filesystem::path>& schemaPaths)
47+
const std::vector<std::filesystem::path>* pSchemaPaths)
4848
{
49+
const std::vector<std::string>* pSchemaPaths_ = nullptr;
4950
std::vector<std::string> schemaPaths_;
50-
std::transform(schemaPaths.begin(), schemaPaths.end(), std::back_inserter(schemaPaths_), [](const fs::path& p) { return p.string(); });
51-
load(fromFile.string(), schemaPaths_);
52-
}
53-
void six::sicd::NITFReadComplexXMLControl::load(io::FileInputStream& stream, const std::vector<std::string>& schemaPaths)
54-
{
55-
reader.load(stream, schemaPaths);
51+
if (pSchemaPaths != nullptr)
52+
{
53+
std::transform(pSchemaPaths->begin(), pSchemaPaths->end(), std::back_inserter(schemaPaths_), [](const fs::path& p) { return p.string(); });
54+
pSchemaPaths_ = &schemaPaths_;
55+
}
56+
load(fromFile.string(), pSchemaPaths_);
5657
}
5758

5859
std::shared_ptr<const six::Container> six::sicd::NITFReadComplexXMLControl::getContainer() const

six/modules/c++/six.sicd/source/Utilities.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static void readSicd_(const std::string& sicdPathname,
579579
std::vector<std::complex<float>>& widebandData)
580580
{
581581
six::sicd::NITFReadComplexXMLControl reader;
582-
reader.load(sicdPathname, schemaPaths);
582+
reader.load(sicdPathname, &schemaPaths);
583583

584584
// For SICD, there's only one image (container->size() == 1)
585585
if (reader.getContainer()->size() != 1)
@@ -640,7 +640,7 @@ static void readSicd_(const std::string& sicdPathname,
640640
TScalarMeshPtr& scalarMesh)
641641
{
642642
six::sicd::NITFReadComplexXMLControl reader;
643-
reader.load(sicdPathname, schemaPaths);
643+
reader.load(sicdPathname, &schemaPaths);
644644

645645
auto complexData_ = reader.getComplexData();
646646
complexData.reset(complexData_.release());
@@ -728,7 +728,7 @@ mem::auto_ptr<ComplexData> Utilities::getComplexData(
728728
else
729729
{
730730
six::sicd::NITFReadComplexXMLControl reader;
731-
reader.load(pathname, schemaPaths);
731+
reader.load(pathname, &schemaPaths);
732732

733733
auto pComplexData = reader.getComplexData();
734734
return mem::auto_ptr<ComplexData>(pComplexData.release());
@@ -1553,12 +1553,12 @@ void Utilities::projectPixelsToSlantPlane(
15531553
}
15541554
}
15551555

1556-
std::vector<std::byte> six::sicd::readFromNITF(const fs::path& pathname, const std::vector<fs::path>& schemaPaths,
1556+
std::vector<std::byte> six::sicd::readFromNITF(const fs::path& pathname, const std::vector<fs::path>* pSchemaPaths,
15571557
std::unique_ptr<ComplexData>& pComplexData)
15581558
{
15591559
six::sicd::NITFReadComplexXMLControl reader;
15601560
reader.setLogger();
1561-
reader.load(pathname, schemaPaths);
1561+
reader.load(pathname, pSchemaPaths);
15621562

15631563
// For SICD, there's only one image (container->size() == 1)
15641564
if (reader.getContainer()->size() != 1)

six/modules/c++/six.sicd/unittests/test_valid_six.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,15 @@ TEST_CASE(valid_six_50x50)
164164
{
165165
setNitfPluginPath();
166166

167+
static const std::vector<std::filesystem::path> schemaPaths;
167168
const auto inputPathname = getNitfPath("sicd_50x50.nitf");
168169
std::unique_ptr<six::sicd::ComplexData> pComplexData;
169-
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData);
170+
const auto image = six::sicd::readFromNITF(inputPathname, schemaPaths, pComplexData); // validate XML
170171
const six::Data* pData = pComplexData.get();
171172

172173
TEST_ASSERT_EQ(six::PixelType::RE32F_IM32F, pData->getPixelType());
173174
TEST_ASSERT_EQ(static_cast<size_t>(8), pData->getNumBytesPerPixel());
174175

175-
/*
176-
// UTF-8 characters in 50x50.nitf
177-
#ifdef _WIN32
178-
const std::string classificationText("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFIÉ / UNCLASSIFIED"
179-
#else
180-
const std::string classificationText("NON CLASSIFI\xc3\x89 / UNCLASSIFIED"); // UTF-8 "NON CLASSIFIÉ / UNCLASSIFIED"
181-
#endif
182-
const auto& classification = pData->getClassification();
183-
const auto actual = classification.getLevel();
184-
//TEST_ASSERT_EQ(actual, classificationText);
185-
*/
186176
const std::string classificationText("NON CLASSIFIE' / UNCLASSIFIED");
187177
const auto& classification = pData->getClassification();
188178
const auto actual = classification.getLevel();
@@ -197,12 +187,9 @@ TEST_CASE(sicd_French_xml)
197187

198188
const auto inputPathname = getNitfPath("sicd_French_xml.nitf");
199189
std::unique_ptr<six::sicd::ComplexData> pComplexData;
200-
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData);
190+
const auto image = six::sicd::readFromNITF(inputPathname, pComplexData); // no validation
201191
const six::Data* pData = pComplexData.get();
202192

203-
TEST_ASSERT_EQ(six::PixelType::RE32F_IM32F, pData->getPixelType());
204-
TEST_ASSERT_EQ(static_cast<size_t>(8), pData->getNumBytesPerPixel());
205-
206193
// UTF-8 characters in 50x50.nitf
207194
#ifdef _WIN32
208195
const std::string classificationText("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFIÉ / UNCLASSIFIED"

six/modules/c++/six/include/six/NITFReadControl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ struct NITFReadControl : public ReadControl
125125
*/
126126
void load(const std::string& fromFile,
127127
const std::vector<std::string>& schemaPaths) override;
128+
void load(const std::string& fromFile,
129+
const std::vector<std::string>* pSchemaPaths);
128130

129131
/*
130132
* \func load
@@ -139,7 +141,8 @@ struct NITFReadControl : public ReadControl
139141
void load(std::shared_ptr<nitf::IOInterface> ioInterface);
140142
void load(std::shared_ptr<nitf::IOInterface> ioInterface,
141143
const std::vector<std::string>& schemaPaths);
142-
144+
void load(std::shared_ptr<nitf::IOInterface> ioInterface,
145+
const std::vector<std::string>* pSchemaPaths);
143146

144147
using ReadControl::interleaved;
145148
/*!

six/modules/c++/six/include/six/Utilities.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ mem::auto_ptr<Data> parseData(const XMLControlRegistry& xmlReg,
222222
::io::InputStream& xmlStream,
223223
const std::vector<std::string>& schemaPaths,
224224
logging::Logger& log);
225-
std::unique_ptr<Data> parseData(const XMLControlRegistry& xmlReg,
226-
::io::InputStream& xmlStream,
225+
std::unique_ptr<Data> parseData(const XMLControlRegistry&, ::io::InputStream&,
227226
const std::vector<std::filesystem::path>*, logging::Logger&);
228227

229228
/*

six/modules/c++/six/source/NITFReadControl.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ void NITFReadControl::load(const std::string& fromFile,
256256
auto handle(std::make_shared<nitf::IOHandle>(fromFile));
257257
load(handle, schemaPaths);
258258
}
259+
void NITFReadControl::load(const std::string& fromFile,
260+
const std::vector<std::string>* pSchemaPaths)
261+
{
262+
auto handle(std::make_shared<nitf::IOHandle>(fromFile));
263+
load(handle, pSchemaPaths);
264+
}
259265

260266
void NITFReadControl::load(io::SeekableInputStream& stream,
261267
const std::vector<std::string>& schemaPaths)
@@ -302,8 +308,21 @@ static std::vector<six::NITFImageInfo*> getImageInfos(six::Container& container)
302308
}
303309

304310
void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
305-
const std::vector<std::string>& schemaPaths)
311+
const std::vector<std::string>& schemaPaths)
306312
{
313+
load(ioInterface, &schemaPaths);
314+
}
315+
void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
316+
const std::vector<std::string>* pSchemaPaths_)
317+
{
318+
const std::vector<std::filesystem::path>* pSchemaPaths = nullptr;
319+
std::vector<std::filesystem::path> schemaPaths;
320+
if (pSchemaPaths_ != nullptr)
321+
{
322+
std::transform(pSchemaPaths_->begin(), pSchemaPaths_->end(), std::back_inserter(schemaPaths), [](const std::string& s) { return s; });
323+
pSchemaPaths = &schemaPaths;
324+
}
325+
307326
reset();
308327
mInterface = ioInterface;
309328

@@ -331,7 +350,7 @@ void NITFReadControl::load(std::shared_ptr<nitf::IOInterface> ioInterface,
331350
std::unique_ptr<Data> data(parseData(*mXMLRegistry,
332351
ioAdapter,
333352
dataType,
334-
schemaPaths,
353+
pSchemaPaths,
335354
*mLog));
336355
if (data.get() == nullptr)
337356
{

0 commit comments

Comments
 (0)