Isis 3 Programmer Reference
OriginalXmlLabel.cpp
Go to the documentation of this file.
1 
23 #include <fstream>
24 #include <sstream>
25 #include <string>
26 
27 #include <QByteArray>
28 #include <QFile>
29 
30 #include "OriginalXmlLabel.h"
31 #include "Application.h"
32 #include "PvlObject.h"
33 
34 using namespace std;
35 namespace Isis {
39  OriginalXmlLabel::OriginalXmlLabel() : Isis::Blob("IsisCube", "OriginalXmlLabel") {
40  p_blobPvl += Isis::PvlKeyword("ByteOrder", "NULL");
41  }
42 
43 
49  OriginalXmlLabel::OriginalXmlLabel(const QString &file) :
50  Isis::Blob("IsisCube", "OriginalXmlLabel") {
51  p_blobPvl += Isis::PvlKeyword("ByteOrder", "NULL");
52  Blob::Read(file);
53  }
54 
55 
60  }
61 
62 
71  void OriginalXmlLabel::readFromXmlFile(const FileName &xmlFileName) {
72  QFile xmlFile(xmlFileName.expanded());
73  if ( !xmlFile.open(QIODevice::ReadOnly) ) {
74  QString msg = "Could not open label file [" + xmlFileName.expanded() +
75  "].";
77  }
78 
79  QString errmsg;
80  int errline, errcol;
81  if ( !m_originalLabel.setContent(&xmlFile, false, &errmsg, &errline, &errcol) ) {
82  xmlFile.close();
83  QString msg = "XML read/parse error in file [" + xmlFileName.expanded()
84  + "] at line [" + toString(errline) + "], column [" + toString(errcol)
85  + "], message: " + errmsg;
87  }
88 
89  xmlFile.close();
90  }
91 
92 
102  void OriginalXmlLabel::ReadData(std::istream &stream) {
103  // Use Blob's ReadData to fill p_buffer
104  Blob::ReadData(stream);
105 
106  // Setup variables for error reproting in QT's xml parser
107  QString errorMessage;
108  int errorLine;
109  int errorColumn;
110 
111  // Attempt to use QT's xml parser to internalize the label
112  if ( !m_originalLabel.setContent( QByteArray(p_buffer, p_nbytes) ) ) {
113  QString msg = "XML read/parse error when parsing original label. "
114  "Error at line [" + toString(errorLine) +
115  "], column [" + toString(errorColumn) +
116  "]. Error message: " + errorMessage;
118  }
119  }
120 
121 
128  p_nbytes = m_originalLabel.toByteArray(0).size();
129 
130  if (Isis::IsLsb()) {
131  p_blobPvl["ByteOrder"] = Isis::ByteOrderName(Isis::Lsb);
132  }
133  else {
134  p_blobPvl["ByteOrder"] = Isis::ByteOrderName(Isis::Msb);
135  }
136  }
137 
138 
146  void OriginalXmlLabel::WriteData(std::fstream &os) {
147  QByteArray labelByteArray = m_originalLabel.toByteArray(0);
148  os.write( labelByteArray.data(), labelByteArray.size() );
149  }
150 
151 
157  const QDomDocument &OriginalXmlLabel::ReturnLabels() const {
158  return m_originalLabel;
159  }
160 }
void WriteInit()
Prepare to write the label out.
const QDomDocument & ReturnLabels() const
Returns the original Xml label.
File name manipulation and expansion.
Definition: FileName.h:116
void Read(const QString &file)
This method reads Pvl values from a specified file.
Definition: Blob.cpp:243
Namespace for the standard library.
int p_nbytes
Size of blob data (in bytes)
Definition: Blob.h:99
PvlObject p_blobPvl
Pvl Blob object.
Definition: Blob.h:94
OriginalXmlLabel()
Constructors a default OriginalXmlLabel with an empty label.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:171
virtual void ReadData(std::istream &is)
Read binary data from an input stream into the Blob object.
Definition: Blob.cpp:340
char * p_buffer
Buffer blob data is stored in.
Definition: Blob.h:97
QDomDocument m_originalLabel
Original Xml Label.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition: Endian.h:84
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
void WriteData(std::fstream &os)
Write the label out to a stream.
void ReadData(std::istream &stream)
Read the xml file data from an input stream.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void readFromXmlFile(const FileName &xmlFileName)
Read the original label from an Xml file.
~OriginalXmlLabel()
Destructor.