Isis 3 Programmer Reference
OriginalXmlLabel.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include <fstream>
8#include <sstream>
9#include <string>
10
11#include <QByteArray>
12#include <QFile>
13
14#include "OriginalXmlLabel.h"
15#include "Application.h"
16#include "PvlObject.h"
17
18using namespace std;
19namespace Isis {
25
26
33 Blob blob = Blob("IsisCube", "OriginalXmlLabel");
34 blob.Read(file);
35 fromBlob(blob);
36 }
37
44 fromBlob(blob);
45 }
46
47
53
54
55 /*
56 * Load blob data into m_originalLabel
57 */
58 void OriginalXmlLabel::fromBlob(Isis::Blob blob) {
59 QString errorMessage;
60 int errorLine = 0;
61 int errorColumn = 0;
62
63 if ( !m_originalLabel.setContent( QByteArray(blob.getBuffer(), blob.Size()) ) ) {
64 QString msg = "XML read/parse error when parsing original label. "
65 "Error at line [" + toString(errorLine) +
66 "], column [" + toString(errorColumn) +
67 "]. Error message: " + errorMessage;
68 throw IException(IException::Unknown, msg, _FILEINFO_);
69 }
70 }
71
72
79 std::stringstream sstream;
80 sstream << m_originalLabel.toString();
81 string orglblStr = sstream.str();
82 Isis::Blob blob("IsisCube", "OriginalXmlLabel");
83 blob.setData((char*)orglblStr.data(), orglblStr.length());
84 blob.Label() += Isis::PvlKeyword("ByteOrder", "NULL");
85 if (Isis::IsLsb()) {
86 blob.Label()["ByteOrder"] = Isis::ByteOrderName(Isis::Lsb);
87 }
88 else {
89 blob.Label()["ByteOrder"] = Isis::ByteOrderName(Isis::Msb);
90 }
91 return blob;
92 }
93
94
104 QFile xmlFile(xmlFileName.expanded());
105 if ( !xmlFile.open(QIODevice::ReadOnly) ) {
106 QString msg = "Could not open label file [" + xmlFileName.expanded() +
107 "].";
108 throw IException(IException::Io, msg, _FILEINFO_);
109 }
110
111 QString errmsg;
112 int errline, errcol;
113 if ( !m_originalLabel.setContent(&xmlFile, false, &errmsg, &errline, &errcol) ) {
114 xmlFile.close();
115 QString msg = "XML read/parse error in file [" + xmlFileName.expanded()
116 + "] at line [" + toString(errline) + "], column [" + toString(errcol)
117 + "], message: " + errmsg;
118 throw IException(IException::Unknown, msg, _FILEINFO_);
119 }
120
121 xmlFile.close();
122 }
123
124
130 const QDomDocument &OriginalXmlLabel::ReturnLabels() const{
131 return m_originalLabel;
132 }
133}
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
const QDomDocument & ReturnLabels() const
Returns the original Xml label.
void readFromXmlFile(const FileName &xmlFileName)
Read the original label from an Xml file.
QDomDocument m_originalLabel
Original Xml Label.
OriginalXmlLabel()
Constructors a default OriginalXmlLabel with an empty label.
Blob toBlob() const
Serialize the OriginalXmlLabel to a Blob.
A single keyword-value pair.
Definition PvlKeyword.h:87
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition Endian.h:67
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.