Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions
itk::PSMDOMNodeXMLReader Class Reference

Class to read a special PSM DOM object from an XML file or an input stream. More...

#include <itkPSMDOMNodeXMLReader.h>

+ Inheritance diagram for itk::PSMDOMNodeXMLReader:
+ Collaboration diagram for itk::PSMDOMNodeXMLReader:

Public Types

typedef PSMDOMNodeXMLReader Self
 
typedef Object Superclass
 
typedef SmartPointer< SelfPointer
 
typedef SmartPointer< const SelfConstPointer
 
typedef PSMDOMNode DOMNodeType
 
typedef DOMNodeType::Pointer DOMNodePointer
 

Public Member Functions

 itkNewMacro (Self)
 
 itkTypeMacro (PSMDOMNodeXMLReader, Object)
 
 itkSetStringMacro (FileName)
 
 itkGetStringMacro (FileName)
 
 itkSetObjectMacro (DOMNode, DOMNodeType)
 
 itkGetObjectMacro (DOMNode, DOMNodeType)
 
 itkGetConstObjectMacro (DOMNode, DOMNodeType)
 
void Update (std::istream &is)
 
virtual void Update ()
 
virtual void StartElement (const char *name, const char **atts)
 
virtual void EndElement (const char *name)
 
virtual void CharacterDataHandler (const char *text, int len)
 

Detailed Description

Class to read a special PSM DOM object from an XML file or an input stream.

This class is used by the PSMProjectReader to produce the DOM tree data structure that is passed to a PSMProject.

See also
DOMReader
PSMDOMNode
PSMProject

Definition at line 45 of file itkPSMDOMNodeXMLReader.h.

Member Typedef Documentation

Standard class typedefs.

Definition at line 49 of file itkPSMDOMNodeXMLReader.h.

Member Function Documentation

void itk::PSMDOMNodeXMLReader::CharacterDataHandler ( const char *  text,
int  len 
)
virtual

Callback function – called from XML parser with the character data for an XML element.

Definition at line 178 of file itkPSMDOMNodeXMLReader.cxx.

179 {
180  std::string s( text, len );
181 
182  StringTools::Trim( s );
183  if ( s.size() == 0 )
184  {
185  return;
186  }
187 
188  this->m_Context->AddText(s);
189 }
void AddText(const std::string &s)
Definition: itkPSMDOMNode.h:89
void itk::PSMDOMNodeXMLReader::EndElement ( const char *  name)
virtual

Callback function – called from XML parser when ending tag encountered.

Definition at line 165 of file itkPSMDOMNodeXMLReader.cxx.

166 {
167  if ( this->m_Context->GetName() != name )
168  {
169  itkExceptionMacro( "start/end tag names mismatch" );
170  }
171  this->m_Context = dynamic_cast<PSMDOMNode *>(this->m_Context->GetParent());
172 }
itk::PSMDOMNodeXMLReader::itkGetConstObjectMacro ( DOMNode  ,
DOMNodeType   
)

Get the output DOM object for read-only access.

itk::PSMDOMNodeXMLReader::itkGetObjectMacro ( DOMNode  ,
DOMNodeType   
)

Get the output DOM object for full access.

itk::PSMDOMNodeXMLReader::itkGetStringMacro ( FileName  )

Get the input XML filename.

itk::PSMDOMNodeXMLReader::itkNewMacro ( Self  )

Method for creation through the object factory.

itk::PSMDOMNodeXMLReader::itkSetObjectMacro ( DOMNode  ,
DOMNodeType   
)

The output DOM object will be created automatically, but the user can appoint a user DOM object as the output by calling this function.

itk::PSMDOMNodeXMLReader::itkSetStringMacro ( FileName  )

Set the input XML filename.

itk::PSMDOMNodeXMLReader::itkTypeMacro ( PSMDOMNodeXMLReader  ,
Object   
)

Run-time type information (and related methods).

void itk::PSMDOMNodeXMLReader::StartElement ( const char *  name,
const char **  atts 
)
virtual

Callback function – called from XML parser with start-of-element information.

Definition at line 128 of file itkPSMDOMNodeXMLReader.cxx.

129 {
130  DOMNodeType* node = NULL;
131  if ( this->m_Context )
132  {
133  DOMNodePointer node1 = DOMNodeType::New();
134  node = (DOMNodeType*)node1;
135  this->m_Context->AddChildAtEnd( node );
136  }
137  else
138  {
139  node = this->GetDOMNode();
140  }
141  node->SetName( name );
142 
143  size_t i = 0;
144  while ( atts[i] )
145  {
146  std::string key( atts[i++] );
147  std::string value( atts[i++] );
148  if ( StringTools::MatchWith(key,"id") )
149  {
150  node->SetID( value );
151  }
152  else
153  {
154  node->SetAttribute( key, value );
155  }
156  }
157 
158  this->m_Context = node;
159 }
void itk::PSMDOMNodeXMLReader::Update ( std::istream &  is)

Function called by Update() or end-users to generate the output DOM object from an input stream such as file, string, etc.

Definition at line 64 of file itkPSMDOMNodeXMLReader.cxx.

65 {
66  DOMNodeType* output = this->GetDOMNode();
67  if ( output == NULL )
68  {
69  DOMNodePointer object = DOMNodeType::New();
70  output = (DOMNodeType*)object;
71  this->SetDOMNode( output );
72  }
73 
74  output->RemoveAllAttributesAndChildren();
75  this->m_Context = NULL;
76 
77  is >> std::noskipws;
78  std::string s;
79  while ( true )
80  {
81  char c = 0;
82  is >> c;
83  if ( !is.good() )
84  {
85  break;
86  }
87  s.append( 1, c );
88  }
89 
90  XML_Parser parser = XML_ParserCreate( 0 );
91  XML_SetElementHandler( parser, &itkXMLParserStartElement, &itkXMLParserEndElement );
92  XML_SetCharacterDataHandler( parser, &itkXMLParserCharacterDataHandler );
93  XML_SetUserData( parser, this );
94 
95  bool ok = XML_Parse( parser, s.data(), s.size(), false );
96  if ( !ok )
97  {
98  ExceptionObject e( __FILE__, __LINE__ );
99  std::string message( XML_ErrorString(XML_GetErrorCode(parser)) );
100  e.SetDescription( message.c_str() );
101  throw e;
102  }
103 
104  XML_ParserFree( parser );
105 }
void itk::PSMDOMNodeXMLReader::Update ( )
virtual

Function called by end-users to generate the output DOM object from the input XML file.

Reimplemented in itk::PSMProjectReader.

Definition at line 111 of file itkPSMDOMNodeXMLReader.cxx.

112 {
113  std::ifstream is( this->m_FileName.c_str() );
114  if ( !is.is_open() )
115  {
116  itkExceptionMacro( "failed openning the input XML file" );
117  }
118 
119  this->Update( is );
120 
121  is.close();
122 }

The documentation for this class was generated from the following files: