| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkXMLFileOutputWindow.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:49 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
DEF |
=========================================================================*/ |
| 17 |
|
#ifdef _WIN32 |
| 18 |
|
#pragma warning ( disable : 4786 ) |
| 19 |
|
#endif |
| 20 |
|
|
| 21 |
|
#include "itkXMLFileOutputWindow.h" |
| 22 |
|
#include <fstream> |
| 23 |
|
|
| 24 |
|
namespace itk |
| 25 |
|
{ |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* Prompting off by default |
| 29 |
|
*/ |
| 30 |
|
XMLFileOutputWindow |
| 31 |
|
::XMLFileOutputWindow() |
| 32 |
|
{ |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
XMLFileOutputWindow |
| 36 |
|
::~XMLFileOutputWindow() |
| 37 |
|
{ |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
void |
| 41 |
|
XMLFileOutputWindow |
| 42 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 43 |
|
{ |
| 44 |
|
Superclass::PrintSelf(os, indent); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
void |
| 49 |
|
XMLFileOutputWindow |
| 50 |
|
::Initialize() |
| 51 |
|
{ |
| 52 |
|
if (!m_Stream) |
| 53 |
|
{ |
| 54 |
|
if (m_FileName == "") |
| 55 |
|
{ |
| 56 |
|
m_FileName = "itkMessageLog.xml"; |
| 57 |
|
} |
| 58 |
|
if (m_Append) |
| 59 |
|
{ |
| 60 |
|
m_Stream = new std::ofstream(m_FileName.c_str(), std::ios::app); |
| 61 |
|
} |
| 62 |
|
else |
| 63 |
|
{ |
| 64 |
|
m_Stream = new std::ofstream(m_FileName.c_str()); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
void |
| 70 |
|
XMLFileOutputWindow |
| 71 |
|
::DisplayTag(const char* text) |
| 72 |
|
{ |
| 73 |
|
Superclass::DisplayText(text); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
void |
| 78 |
|
XMLFileOutputWindow |
| 79 |
|
::DisplayXML(const char* tag, const char* text) |
| 80 |
|
{ |
| 81 |
|
char *xmlText; |
| 82 |
|
|
| 83 |
|
if(!text) |
| 84 |
|
{ |
| 85 |
|
return; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
// allocate enough room for the worst case |
| 89 |
|
xmlText = new char[strlen(text) * 6 + 1]; |
| 90 |
|
|
| 91 |
|
const char *s = text; |
| 92 |
|
char *x = xmlText; |
| 93 |
|
*x = '\0'; |
| 94 |
|
|
| 95 |
|
// replace all special characters |
| 96 |
|
while (*s) |
| 97 |
|
{ |
| 98 |
|
switch (*s) |
| 99 |
|
{ |
| 100 |
|
case '&': |
| 101 |
IND |
********strcat(x, "&"); x += 5; |
| 102 |
IND |
********break; |
| 103 |
|
case '"': |
| 104 |
IND |
********strcat(x, """); x += 6; |
| 105 |
IND |
********break; |
| 106 |
|
case '\'': |
| 107 |
IND |
********strcat(x, "'"); x += 6; |
| 108 |
IND |
********break; |
| 109 |
|
case '<': |
| 110 |
|
strcat(x, "<"); x += 4; |
| 111 |
|
break; |
| 112 |
|
case '>': |
| 113 |
IND |
********strcat(x, ">"); x += 4; |
| 114 |
IND |
********break; |
| 115 |
|
default: |
| 116 |
IND |
*********x = *s; x++; |
| 117 |
IND |
*********x = '\0'; // explicitly terminate the new string |
| 118 |
|
} |
| 119 |
|
s++; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
if (!m_Stream) |
| 123 |
|
{ |
| 124 |
|
this->Initialize(); |
| 125 |
|
} |
| 126 |
|
*m_Stream << "<" << tag << ">" << xmlText << "</" << tag << ">" << std::endl; |
| 127 |
|
|
| 128 |
|
if (m_Flush) |
| 129 |
|
{ |
| 130 |
|
m_Stream->flush(); |
| 131 |
|
} |
| 132 |
|
delete [] xmlText; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
void |
| 136 |
|
XMLFileOutputWindow |
| 137 |
|
::DisplayText(const char* text) |
| 138 |
|
{ |
| 139 |
|
this->DisplayXML("Text", text); |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
void |
| 143 |
|
XMLFileOutputWindow |
| 144 |
|
::DisplayErrorText(const char* text) |
| 145 |
|
{ |
| 146 |
|
this->DisplayXML("Error", text); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
void |
| 150 |
|
XMLFileOutputWindow |
| 151 |
|
::DisplayWarningText(const char* text) |
| 152 |
|
{ |
| 153 |
|
this->DisplayXML("Warning", text); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
void |
| 157 |
|
XMLFileOutputWindow |
| 158 |
|
::DisplayGenericOutputText(const char* text) |
| 159 |
|
{ |
| 160 |
|
this->DisplayXML("GenericOutput", text); |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
void |
| 164 |
|
XMLFileOutputWindow |
| 165 |
|
::DisplayDebugText(const char* text) |
| 166 |
|
{ |
| 167 |
|
this->DisplayXML("Debug", text); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
} // end namespace itk |
| 171 |
|
|