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 
18 using namespace std;
19 namespace Isis {
23  OriginalXmlLabel::OriginalXmlLabel() {
24  }
25 
26 
32  OriginalXmlLabel::OriginalXmlLabel(const QString &file) {
33  Blob blob = Blob("IsisCube", "OriginalXmlLabel");
34  blob.Read(file);
35  fromBlob(blob);
36  }
37 
43  OriginalXmlLabel::OriginalXmlLabel(Isis::Blob &blob) {
44  fromBlob(blob);
45  }
46 
47 
51  OriginalXmlLabel::~OriginalXmlLabel() {
52  }
53 
54 
55  /*
56  * Load blob data into m_originalLabel
57  */
58  void OriginalXmlLabel::fromBlob(Isis::Blob blob) {
59  QString errorMessage;
60  int errorLine;
61  int errorColumn;
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 
78  Blob OriginalXmlLabel::toBlob() const {
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 
103  void OriginalXmlLabel::readFromXmlFile(const FileName &xmlFileName) {
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 }
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::Blob::setData
void setData(const char *buffer, int nbytes)
Set the data stored in the BLOB.
Definition: Blob.cpp:382
Isis::IsLsb
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition: Endian.h:67
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Blob::Read
void Read(const QString &file, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >())
This method reads Pvl values from a specified file.
Definition: Blob.cpp:255
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::Blob::getBuffer
char * getBuffer()
Get the internal data buff of the Blob.
Definition: Blob.cpp:546
Isis::Blob::Label
PvlObject & Label()
Accessor method that returns a PvlObject containing the Blob label.
Definition: Blob.cpp:151
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Blob::Size
int Size() const
Accessor method that returns the number of bytes in the blob data.
Definition: Blob.cpp:142
std
Namespace for the standard library.
Isis::Blob
Definition: Blob.h:51
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16