OpenASIP  2.0
XMLSerializer.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file XMLSerializer.cc
26  *
27  * Implementation of XMLSerializer class.
28  *
29  * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30  * @note reviewed 8 Jun 2004 by tr, jm, am, ll
31  * @note rating: red
32  */
33 
34 #include <fstream>
35 
36 #include <xercesc/util/XercesVersion.hpp>
37 
38 #if XERCES_VERSION_MAJOR >= 3
39 #include <xercesc/dom/DOMLSParser.hpp>
40 #include <xercesc/dom/DOMLSSerializer.hpp>
41 #include <xercesc/dom/DOMDocument.hpp>
42 #include <xercesc/dom/DOMLSOutput.hpp>
43 #else
44 #include <xercesc/dom/DOMWriter.hpp>
45 #include <xercesc/dom/DOMBuilder.hpp>
46 #endif
47 
48 #include <xercesc/dom/DOMImplementation.hpp>
49 #include <xercesc/dom/DOMElement.hpp>
50 #include <xercesc/dom/DOMText.hpp>
51 #include <xercesc/dom/DOMNamedNodeMap.hpp>
52 #include <xercesc/dom/DOMException.hpp>
53 #include <xercesc/framework/LocalFileFormatTarget.hpp>
54 #include <xercesc/util/PlatformUtils.hpp>
55 #include <xercesc/validators/common/Grammar.hpp>
56 #include <xercesc/sax/SAXException.hpp>
57 #include <xercesc/dom/DOMException.hpp>
58 #include <xercesc/util/XMLException.hpp>
59 #include <xercesc/util/PlatformUtils.hpp>
60 #include <xercesc/dom/DOMImplementationRegistry.hpp>
61 #include <xercesc/framework/MemBufInputSource.hpp>
62 #include <xercesc/framework/Wrapper4InputSource.hpp>
63 #include <xercesc/framework/MemBufFormatTarget.hpp>
64 
65 #include "XMLSerializer.hh"
67 #include "Conversion.hh"
68 #include "FileSystem.hh"
69 #include "Application.hh"
70 #include "ObjectState.hh"
71 
72 using std::string;
73 using std::ifstream;
74 
75 /**
76  * Constructor.
77  */
79  Serializer(), sourceFile_(""), destinationFile_(""), schemaFile_(""),
80  useSchema_(false), parser_(NULL), domImplementation_(NULL),
81  sourceString_(NULL), destinationString_(NULL), nsUri_("") {
82 
83  XMLPlatformUtils::Initialize();
84 
85  const XMLCh gLS[] = {chLatin_L, chLatin_S, chNull};
87  DOMImplementationRegistry::getDOMImplementation(gLS);
88 
89 #if XERCES_VERSION_MAJOR >= 3
90  parser_ = domImplementation_->createLSParser(
91  DOMImplementationLS::MODE_SYNCHRONOUS, 0);
92 #else
93  parser_ = domImplementation_->createDOMBuilder(
94  DOMImplementationLS::MODE_SYNCHRONOUS, 0);
95 #endif
96 }
97 
98 /**
99  * Destructor.
100  */
102  delete parser_;
103  XMLPlatformUtils::Terminate();
104 }
105 
106 /**
107  * Sets the source file used when readState is called.
108  *
109  * Previously set source file or string is unset.
110  *
111  * @param fileName Relative or absolute path of the source file, e.g.
112  * /home/openasip/file.xml or ./file.xml.
113  */
114 void
115 XMLSerializer::setSourceFile(const std::string& fileName) {
116  sourceFile_ = fileName;
117  sourceString_ = NULL;
118 }
119 
120 /**
121  * Sets the source string used when readState is called.
122  *
123  * Previously set source file or string is unset.
124  *
125  * @param source Source string to read.
126  */
127 void
128 XMLSerializer::setSourceString(const std::string& source) {
129  sourceString_ = &source;
130  sourceFile_ = "";
131 }
132 
133 /**
134  * Sets the destination file used when writeState is called.
135  *
136  * Previously set destination file or string is unset.
137  *
138  * @param fileName Relative or absolute path of the destination file,
139  * e.g. /home/openasip/file.xml or ./file.xml.
140  */
141 void
142 XMLSerializer::setDestinationFile(const std::string& fileName) {
143  destinationFile_ = fileName;
144  destinationString_ = NULL;
145 }
146 
147 
148 /**
149  * Sets the destination string used when writeState is called.
150  *
151  * Previously set destination file or string is unset.
152  *
153  * @param target Target string to write.
154  */
155 void
157  destinationString_ = &target;
158  destinationFile_ = "";
159 }
160 
161 /**
162  * Sets the schema file used to validate xml files.
163  *
164  * @param fileName Relative or absolute path of the schema file, e.g.
165  * /home/openasip/schema.xsd or ./schema.xsd.
166  */
167 void
168 XMLSerializer::setSchemaFile(const std::string& fileName) {
169  schemaFile_ = fileName;
170 }
171 
172 /**
173  * Sets/unsets validation of xml files using xml schema.
174  *
175  * @param useSchema True sets and false unsets validation. Default value is
176  * false.
177  */
178 void
180  useSchema_ = useSchema;
181 }
182 
183 /**
184  * Sets the XML namespace URI to be used when creating a DOM document
185  *
186  */
187 void
188 XMLSerializer::setXMLNamespace(std::string nsUri) {
189  nsUri_ = nsUri;
190 }
191 
192 /**
193  * Reads object state from a file or string.
194  *
195  * File is read if a source file is set with setSourceFile().
196  * String is read if a source string is set with setSourceString().
197  * Only the last file/string set will be read.
198  */
201  if (sourceFile_ != "") {
202  return readFile(sourceFile_);
203  } else if (sourceString_ != NULL) {
204  return readString(*sourceString_);
205  } else {
206  string errorMsg = "No Source file or string set.";
207  throw SerializerException(__FILE__, __LINE__, __func__, errorMsg);
208  }
209 }
210 
211 /**
212  * Writes the given object state to a file or string.
213  *
214  * File is written if a destiantion file is set with setDestinationFile().
215  * String is written if a destination string is set with
216  * setDestinationString(). Only the last file/string set will be written.
217  */
218 void
220  if (destinationFile_ != "") {
221  writeFile(destinationFile_, state);
222  } else if (destinationString_ != NULL) {
224  } else {
225  string errorMsg = "No destination file or string set.";
226  throw SerializerException(__FILE__, __LINE__, __func__, errorMsg);
227  }
228 }
229 
230 /**
231  * Initializes the XML parser.
232  */
233 void
235 
236  if (useSchema_ && schemaFile_ == "") {
237  string errorMsg = "No schema file set.";
238  throw SerializerException(__FILE__, __LINE__, __func__, errorMsg);
239  }
240 
241  if (useSchema_) {
242 
243  try {
245  } catch (UnreachableStream& exception) {
246  SerializerException error(__FILE__, __LINE__, __func__,
247  exception.errorMessage());
248 
249  error.setCause(exception);
250  throw error;
251  }
252 
253  string absoluteSchemaFile = schemaFile_;
254 
255  // convert the given schemaFile path to absolute path if it isn't
257  absoluteSchemaFile = FileSystem::currentWorkingDir() +
259  }
260 
261  XMLCh* filePath = Conversion::toXMLCh(absoluteSchemaFile);
262 #if XERCES_VERSION_MAJOR >= 3
263  parser_->getDomConfig()->setParameter(XMLUni::fgXercesSchema, true);
264  parser_->getDomConfig()->setParameter(XMLUni::fgDOMValidate, true);
265  parser_->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, true);
266  parser_->getDomConfig()->setParameter(
267  XMLUni::fgXercesSchemaFullChecking, true);
268  parser_->getDomConfig()->setParameter(
269  XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
270  filePath);
271 #else
272  parser_->setFeature(XMLUni::fgXercesSchema, true);
273  parser_->setFeature(XMLUni::fgDOMValidation, true);
274  parser_->setFeature(XMLUni::fgDOMNamespaces, true);
275  parser_->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
276  parser_->setProperty(
277  XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
278  filePath);
279 #endif
280 
281  XMLString::release(&filePath);
282  }
283 #if XERCES_VERSION_MAJOR >= 3
284  parser_->getDomConfig()->setParameter(
285  XMLUni::fgDOMElementContentWhitespace, false);
286  parser_->getDomConfig()->setParameter(XMLUni::fgDOMComments, false);
287 #else
288  parser_->setFeature(XMLUni::fgDOMWhitespaceInElementContent, false);
289  parser_->setFeature(XMLUni::fgDOMComments, false);
290 #endif
291 }
292 
293 /**
294  * Reads object state from an xml string.
295  *
296  * @param XML to read as an string containing the entire xml document.
297  * @return Root node of the created ObjectState tree.
298  * @exception SerializerException If an error occurs while reading.
299  */
301 XMLSerializer::readString(const std::string& source) {
303  DOMDocument* dom = NULL;
305 #if XERCES_VERSION_MAJOR >= 3
306  parser_->getDomConfig()->setParameter(
307  XMLUni::fgDOMErrorHandler, errHandler);
308 #else
309  parser_->setErrorHandler(errHandler);
310 #endif
311 
312  // build the DOM object
313  try {
314  parser_->resetDocumentPool();
315 
316  MemBufInputSource* buf = new MemBufInputSource(
317  (const XMLByte*)source.c_str(),
318  source.length(),
319  "sourceXML",
320  false);
321 
322  Wrapper4InputSource* domBuf = new Wrapper4InputSource(buf);
323 #if XERCES_VERSION_MAJOR >= 3
324  dom = parser_->parse(domBuf);
325 #else
326  dom = parser_->parse(*domBuf);
327 #endif
328  delete domBuf;
329  } catch(...) {
330  string errorLog = errHandler->errorLog();
331  delete errHandler;
332  throw SerializerException(__FILE__, __LINE__, __func__, errorLog);
333  }
334 
335  int errors(errHandler->errorCount());
336 
337  if (errors > 0) {
338  // if there were such errors in xml file or schema file that
339  // exception was not thrown when parseURI was called
340  string errorLog = errHandler->errorLog();
341  delete errHandler;
342  throw SerializerException(__FILE__, __LINE__, __func__, errorLog);
343  }
344 
345  if (dom == NULL || dom->getDocumentElement() == NULL) {
346  delete errHandler;
347  throw SerializerException(
348  __FILE__, __LINE__, __func__, "Illegal file: " + source);
349  }
350  ObjectState* rootState = createState(dom->getDocumentElement());
351  delete errHandler;
352  errHandler = NULL;
353 
354  return rootState;
355 }
356 
357 /**
358  * Reads current XML file set and creates an ObjectState tree according to
359  * it.
360  *
361  * The XML file is validated with the current schema file if the setting
362  * is on.
363  *
364  * @return Root node of the created ObjectState tree.
365  * @exception SerializerException If an error occurs while reading.
366  */
368 XMLSerializer::readFile(const std::string& sourceFile) {
370  DOMDocument* dom = NULL;
371 
372  if (sourceFile == "") {
373  string errorMsg = "No source file set.";
374  throw SerializerException(__FILE__, __LINE__, __func__, errorMsg);
375  }
376 
377  // check validity of file stream
378  try {
380  } catch (UnreachableStream& exception) {
381  throw SerializerException(__FILE__, __LINE__, __func__,
382  exception.errorMessage());
383  }
384 
386 #if XERCES_VERSION_MAJOR >= 3
387  parser_->getDomConfig()->setParameter(
388  XMLUni::fgDOMErrorHandler, errHandler);
389 #else
390  parser_->setErrorHandler(errHandler);
391 #endif
392 
393  try {
394  parser_->resetDocumentPool();
395  dom = parser_->parseURI(sourceFile.c_str());
396  } catch (const ErrorInExternalFile& exception) {
397 
398  string errorLog = errHandler->errorLog();
399  delete errHandler;
400 
401  throw SerializerException(__FILE__, __LINE__, __func__, errorLog);
402  }
403 
404  if (dom == NULL || dom->getDocumentElement() == NULL) {
405  delete errHandler;
406  throw SerializerException(
407  __FILE__, __LINE__, __func__, "Illegal file: " + sourceFile);
408 
409  }
410 
411 
412  int errors(errHandler->errorCount());
413 
414  if (errors > 0) {
415  // if there were such errors in xml file or schema file that
416  // exception was not thrown when parseURI was called
417  string errorLog = errHandler->errorLog();
418  delete errHandler;
419  throw SerializerException(__FILE__, __LINE__, __func__, errorLog);
420  }
421 
422  ObjectState* rootState = createState(dom->getDocumentElement());
423 
424  delete errHandler;
425  return rootState;
426 }
427 
428 /**
429  * Writes the given ObjectState tree into the current XML file set.
430  *
431  * @param rootState The root object of the ObjectState tree.
432  * @exception SerializerException If the destination file cannot be written.
433  */
434 void
436  const std::string& destinationFile, const ObjectState* rootState) {
437 #if XERCES_VERSION_MAJOR >= 3
438  DOMLSSerializer* domWriter = domImplementation_->createLSSerializer();
439  domWriter->getDomConfig()->setParameter(
440  XMLUni::fgDOMWRTFormatPrettyPrint, true);
441  DOMLSOutput* lsOutput = domImplementation_->createLSOutput();
442 #else
443  DOMWriter* domWriter = domImplementation_->createDOMWriter();
444  domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
445 #endif
446  DOMDocument* document = createDOMDocument(rootState);
447 
448  try {
449  if (!FileSystem::fileIsCreatable(destinationFile) &&
450  !FileSystem::fileIsWritable(destinationFile)) {
451  throw "";
452  }
453 #if XERCES_VERSION_MAJOR >= 3
454  LocalFileFormatTarget targetFile(destinationFile.c_str());
455  lsOutput->setByteStream(&targetFile);
456  domWriter->write(document, lsOutput);
457  domWriter->release();
458  delete lsOutput;
459 #else
460  LocalFileFormatTarget targetFile(destinationFile.c_str());
461  domWriter->writeNode(&targetFile, *document);
462  domWriter->release();
463  delete document;
464 #endif
465  } catch (...) {
466 #if XERCES_VERSION_MAJOR >= 3
467  domWriter->release();
468  delete lsOutput;
469 #else
470  delete document;
471 #endif
472  string errorMessage = "Cannot write to " + destinationFile;
473  throw SerializerException(__FILE__, __LINE__, __func__,
474  errorMessage);
475  }
476 }
477 
478 /**
479  * Writes the given ObjectState tree to a target string.
480  *
481  * @param rootState The root object of the ObjectState tree.
482  * @exception SerializerException If the destination file cannot be written.
483  */
484 void
485 XMLSerializer::writeString(std::string& target, const ObjectState* rootState) {
486 #if XERCES_VERSION_MAJOR >= 3
487  DOMLSSerializer* domWriter = domImplementation_->createLSSerializer();
488  domWriter->getDomConfig()->setParameter(
489  XMLUni::fgDOMWRTFormatPrettyPrint, true);
490  DOMLSOutput* lsOutput = domImplementation_->createLSOutput();
491 #else
492  DOMWriter* domWriter = domImplementation_->createDOMWriter();
493  domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
494 #endif
495  DOMDocument* document = createDOMDocument(rootState);
496 
497  try {
498  target.clear();
499 #if XERCES_VERSION_MAJOR >= 3
500  MemBufFormatTarget* buf = new MemBufFormatTarget();
501  lsOutput->setByteStream(buf);
502  domWriter->write(document, lsOutput);
503 #else
504  MemBufFormatTarget* buf = new MemBufFormatTarget();
505  domWriter->writeNode(buf, *document);
506 #endif
507  target.append((char*)(buf->getRawBuffer()));
508  domWriter->release();
509  delete buf;
510  delete document;
511  } catch (...) {
512  domWriter->release();
513  delete document;
514  string errorMessage = "Error writing xml to a string.";
515  throw SerializerException(__FILE__, __LINE__, __func__,
516  errorMessage);
517  }
518 }
519 
520 /**
521  * Returns the source file that is set.
522  *
523  * @return The source file.
524  */
525 std::string
527  return sourceFile_;
528 }
529 
530 /**
531  * Creates a DOM tree according to the given ObjectState tree.
532  *
533  * @param state Root node of the ObjectState tree.
534  * @return The created DOM tree.
535  */
536 DOMDocument*
538 
539  XMLCh* nsUri = NULL;
540  if (!nsUri_.empty()) {
541  nsUri = Conversion::toXMLCh(nsUri_);
542  }
543  XMLCh* docName = Conversion::toXMLCh(state->name());
544  DOMDocument* doc = domImplementation_->createDocument(nsUri, docName, 0);
545  XMLString::release(&docName);
546  if (nsUri != NULL) {
547  XMLString::release(&nsUri);
548  nsUri = NULL;
549  }
550  DOMElement* rootElem = doc->getDocumentElement();
551 
552  for (int i = 0; i < state->attributeCount(); i++) {
553  ObjectState::Attribute* attribute = state->attribute(i);
554  XMLCh* attribName = Conversion::toXMLCh(attribute->name);
555  XMLCh* attribValue = Conversion::toXMLCh(attribute->value);
556  rootElem->setAttribute(attribName, attribValue);
557  XMLString::release(&attribName);
558  XMLString::release(&attribValue);
559  }
560 
561  string value = state->stringValue();
562  if (value != "") {
563  XMLCh* nodeValue = Conversion::toXMLCh(value);
564  DOMText* valueNode = doc->createTextNode(nodeValue);
565  rootElem->appendChild(valueNode);
566  XMLString::release(&nodeValue);
567  }
568 
569  for (int i = 0; i < state->childCount(); i++) {
570  ObjectState* childState = state->child(i);
571  DOMElement* childElement = createDOM(childState, doc);
572  rootElem->appendChild(childElement);
573  }
574 
575  return doc;
576 }
577 
578 
579 
580 /**
581  * Checks that the file is OK for reading.
582  *
583  * @param fileName Name of the XML file.
584  * @exception UnreachableStream If the given file cannot be read.
585  */
586 void
587 XMLSerializer::ensureValidStream(const std::string& fileName) const {
588  ifstream filestream;
589  filestream.open(fileName.c_str());
590  if(!filestream.is_open() || !filestream.good()) {
591  filestream.close();
592  string procName = "XMLSerializer::ensureValidStream";
593  string errorMessage = "Cannot open file \'";
594  errorMessage += fileName;
595  errorMessage += "\'.";
596  throw UnreachableStream(__FILE__, __LINE__, procName, errorMessage);
597  }
598  filestream.close();
599 }
600 
601 /**
602  * Creates DOM tree from the given ObjectState tree.
603  *
604  * @param state Root node of the ObjectState tree.
605  * @param doc The DOMDocument to which the created DOM tree
606  * belongs.
607  */
608 DOMElement*
610  ObjectState* state,
611  DOMDocument* doc) const {
612 
613  XMLCh* elemName = Conversion::toXMLCh(state->name());
614  DOMElement* rootElem =
615  doc->createElement(elemName);
616  XMLString::release(&elemName);
617 
618  for (int i = 0; i < state->attributeCount(); i++) {
619  ObjectState::Attribute* attribute = state->attribute(i);
620  XMLCh* attribName = Conversion::toXMLCh(attribute->name);
621  XMLCh* attribValue = Conversion::toXMLCh(attribute->value);
622  rootElem->setAttribute(attribName, attribValue);
623  XMLString::release(&attribName);
624  XMLString::release(&attribValue);
625  }
626 
627  if (state->childCount() == 0) {
628  if (state->stringValue() != "") {
629  XMLCh* text = Conversion::toXMLCh(state->stringValue());
630  DOMText* value = doc->createTextNode(text);
631  rootElem->appendChild(value);
632  XMLString::release(&text);
633  }
634  }
635 
636  for (int i = 0; i < state->childCount(); i++) {
637  ObjectState* childState = state->child(i);
638  rootElem->appendChild(createDOM(childState, doc));
639  }
640 
641  return rootElem;
642 }
643 
644 
645 /**
646  * Creates a one-to-one ObjectState object (tree) according to the given
647  * DOMNode.
648  *
649  * @param node DOMNode from which the ObjectState is created.
650  * @return The created ObjectState instance (tree).
651  */
653 XMLSerializer::createState(const DOMNode* node) const {
654  ObjectState* state =
655  new ObjectState(Conversion::XMLChToString(node->getNodeName()));
656  DOMNamedNodeMap* attributes = node->getAttributes();
657 
658  // set the attributes
659  if (attributes != NULL) {
660  for (unsigned int i = 0; i < attributes->getLength(); i++) {
661  DOMNode* attribute = attributes->item(i);
662  state->setAttribute(
663  Conversion::XMLChToString(attribute->getNodeName()),
664  Conversion::XMLChToString(attribute->getNodeValue()));
665  }
666  }
667 
668  DOMNode* child = node->getFirstChild();
669  while (child != NULL) {
670  if (child->getNodeType() == DOMNode::ELEMENT_NODE) {
671  state->addChild(createState(child));
672  }
673  child = child->getNextSibling();
674  }
675 
676  // if node has no child elements, read its value
677  if (!hasChildElementNodes(node)) {
678  if (node->getFirstChild() != NULL) {
679  state->setValue(Conversion::XMLChToString(node->getFirstChild()->
680  getNodeValue()));
681  }
682  }
683 
684  return state;
685 }
686 
687 
688 /**
689  * Returns true if the given node has child elements.
690  *
691  * @param node Node.
692  * @return True if the node has child elements, otherwise false.
693  */
694 bool
695 XMLSerializer::hasChildElementNodes(const DOMNode* node) const {
696  DOMNode* child = node->getFirstChild();
697  while (child != NULL) {
698  if (child->getNodeType() == DOMNode::ELEMENT_NODE) {
699  return true;
700  }
701  child = child->getNextSibling();
702  }
703  return false;
704 }
XMLSerializer::readString
virtual ObjectState * readString(const std::string &source)
Definition: XMLSerializer.cc:301
XMLSerializer::XMLSerializer
XMLSerializer()
Definition: XMLSerializer.cc:78
ObjectState::attribute
Attribute * attribute(int index) const
Definition: ObjectState.cc:228
FileSystem.hh
ObjectState::Attribute
Struct for describing an attribute of the XML element.
Definition: ObjectState.hh:62
XMLSerializer::writeString
virtual void writeString(std::string &target, const ObjectState *rootState)
Definition: XMLSerializer.cc:485
XMLSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition: XMLSerializer.cc:115
UnreachableStream
Definition: Exception.hh:171
ObjectState::Attribute::name
std::string name
Name of the attribute.
Definition: ObjectState.hh:63
ObjectState::Attribute::value
std::string value
Value of the attribute.
Definition: ObjectState.hh:64
FileSystem::isRelativePath
static bool isRelativePath(const std::string &pathName)
Definition: FileSystem.cc:252
XMLSerializer::schemaFile_
std::string schemaFile_
Schema file path.
Definition: XMLSerializer.hh:116
Exception::setCause
void setCause(const Exception &cause)
Definition: Exception.cc:75
XMLSerializer::sourceFile
std::string sourceFile() const
Definition: XMLSerializer.cc:526
XMLSerializer::sourceFile_
std::string sourceFile_
Source file path.
Definition: XMLSerializer.hh:112
ObjectState
Definition: ObjectState.hh:59
XMLSerializer::ensureValidStream
void ensureValidStream(const std::string &fileName) const
Definition: XMLSerializer.cc:587
XMLSerializer::hasChildElementNodes
bool hasChildElementNodes(const DOMNode *node) const
Definition: XMLSerializer.cc:695
XMLSerializer::writeFile
virtual void writeFile(const std::string &fileName, const ObjectState *rootState)
Definition: XMLSerializer.cc:435
FileSystem::fileIsCreatable
static bool fileIsCreatable(const std::string fileName)
Definition: FileSystem.cc:123
DOMBuilderErrorHandler
Definition: DOMBuilderErrorHandler.hh:47
XMLSerializer::readFile
virtual ObjectState * readFile(const std::string &fileName)
Definition: XMLSerializer.cc:368
XMLSerializer::initializeParser
void initializeParser()
Definition: XMLSerializer.cc:234
XMLSerializer.hh
XMLSerializer::setSchemaFile
void setSchemaFile(const std::string &fileName)
Definition: XMLSerializer.cc:168
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
Conversion.hh
XMLSerializer::domImplementation_
DOMImplementation * domImplementation_
Implementation of the DOM.
Definition: XMLSerializer.hh:126
XMLSerializer::readState
virtual ObjectState * readState()
Definition: XMLSerializer.cc:200
XMLSerializer::nsUri_
std::string nsUri_
XML namespace URI.
Definition: XMLSerializer.hh:134
Application.hh
Conversion::toXMLCh
static XMLCh * toXMLCh(const std::string &string)
XMLSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: XMLSerializer.cc:142
__func__
#define __func__
Definition: Application.hh:67
ObjectState.hh
DOMBuilderErrorHandler::errorLog
std::string errorLog() const
Definition: DOMBuilderErrorHandler.cc:102
TCETools::Serializer
Definition: Serializer.hh:45
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
ObjectState::childCount
int childCount() const
SerializerException
Definition: Exception.hh:675
ObjectState::name
std::string name() const
XMLSerializer::setUseSchema
void setUseSchema(bool useSchema)
Definition: XMLSerializer.cc:179
XMLSerializer::createDOMDocument
DOMDocument * createDOMDocument(const ObjectState *state) const
Definition: XMLSerializer.cc:537
DOMBuilderErrorHandler.hh
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
XMLSerializer::createDOM
DOMElement * createDOM(ObjectState *state, DOMDocument *doc) const
Definition: XMLSerializer.cc:609
XMLSerializer::setXMLNamespace
void setXMLNamespace(std::string nsUri)
Definition: XMLSerializer.cc:188
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
XMLSerializer::parser_
DOMBuilder * parser_
The parser that checks the XML file for errors with the Schema.
Definition: XMLSerializer.hh:123
Conversion::XMLChToString
static std::string XMLChToString(const XMLCh *source)
XMLSerializer::setDestinationString
void setDestinationString(std::string &destination)
Definition: XMLSerializer.cc:156
XMLSerializer::useSchema_
bool useSchema_
Indicates if xml file is validated using schema.
Definition: XMLSerializer.hh:118
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
XMLSerializer::sourceString_
const std::string * sourceString_
Source string to read.
Definition: XMLSerializer.hh:129
XMLSerializer::destinationFile_
std::string destinationFile_
Destination file path.
Definition: XMLSerializer.hh:114
XMLSerializer::~XMLSerializer
virtual ~XMLSerializer()
Definition: XMLSerializer.cc:101
ObjectState::stringValue
std::string stringValue() const
XMLSerializer::createState
ObjectState * createState(const DOMNode *node) const
Definition: XMLSerializer.cc:653
FileSystem::currentWorkingDir
static std::string currentWorkingDir()
Definition: FileSystem.cc:142
DOMBuilderErrorHandler::errorCount
int errorCount() const
Definition: DOMBuilderErrorHandler.cc:91
XMLSerializer::setSourceString
void setSourceString(const std::string &source)
Definition: XMLSerializer.cc:128
XMLSerializer::destinationString_
std::string * destinationString_
Destination string to write.
Definition: XMLSerializer.hh:131
ObjectState::setValue
void setValue(const std::string &value)
ErrorInExternalFile
Definition: Exception.hh:387
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
ObjectState::attributeCount
int attributeCount() const
XMLSerializer::writeState
virtual void writeState(const ObjectState *rootState)
Definition: XMLSerializer.cc:219