Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Serializer.h
1 /*
2  * $Id$
3  * xom::Serializer class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2009, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_XOM_SERIALIZER_H_
23 #define ELM_XOM_SERIALIZER_H_
24 
25 #include <elm/string.h>
26 #include <elm/xom/String.h>
27 #include <elm/io/Output.h>
28 
29 namespace elm {
30 
31 namespace io { class OutStream; }
32 
33 namespace xom {
34 
35 // Predeclaration
36 class Attribute;
37 class Comment;
38 class DocType;
39 class Document;
40 class Element;
41 class Node;
42 class ProcessingInstruction;
43 class Text;
44 
45 // Serialier class
46 class Serializer {
47 public:
48  Serializer(io::OutStream& out_stream);
49  Serializer(io::OutStream& out, string encoding);
50 
51  inline const string& getEncoding(void) const { return _encoding; }
52  inline int getIndent(void) const { return _indent; }
53  inline const string& getLineSeparator(void) const { return _line_separator; }
54  inline int getMaxLength(void) const { return _max_length; }
55  inline bool getPreserveBaseURI(void) const { return _preserve; }
56  inline bool getUnicodeNormalizationFormC() const { return _normalize; }
57 
58  inline void setIndent(int indent) { _indent = indent; }
59  inline void setLineSeparator(string line_separator) { _line_separator = line_separator; }
60  inline void setMaxLength(int max_length) { _max_length = max_length; }
61  inline void setOutputStream(io::OutStream& out) { _out.setStream(out); }
62  inline void setPreserveBaseURI(bool preserve) { _preserve = preserve; }
63  inline void setUnicodeNormalizationFormC(bool normalize) { _normalize = normalize; }
64  virtual void write(Document *doc);
65 
66  void flush(void);
67 
68 protected:
69  int getColumnNumber(void);
70  virtual void breakLine(void);
71  virtual void write(Attribute *attribute);
72  virtual void write(Comment *comment);
73  virtual void write(DocType *doctype);
74  virtual void write(Element *element);
75  virtual void write(ProcessingInstruction *instruction);
76  virtual void write(Text *text);
77  virtual void writeAttributes(Element *element);
78  virtual void writeAttributeValue(String value);
79  virtual void writeChild(Node *node);
80  virtual void writeEmptyElementTag(Element *element);
81  virtual void writeEndTag(Element *element);
82  virtual void writeEscaped(String text);
83  virtual void writeNamespaceDeclaration(const string& prefix, const string& uri);
84  virtual void writeNamespaceDeclarations(Element *element);
85  virtual void writeRaw(String text, int length = -1);
86  virtual void writeStartTag(Element *element);
87  virtual void writeXMLDeclaration(void);
88 
89 private:
90  io::Output _out;
91  string _encoding;
92  string _line_separator;
93  int _indent, _max_length;
94  int _ilevel;
95  bool _preserve, _normalize;
96 };
97 
98 } } // elm::xom
99 
100 #endif /* ELM_XOM_SERIALIZER_H_ */
101 
elm::xom::Serializer::flush
void flush(void)
Definition: xom_Serializer.cpp:139
elm::t::out
typename type_info< T >::out_t out
Definition: type_info.h:284
elm::xom::Serializer::write
virtual void write(Document *doc)
Definition: xom_Serializer.cpp:233
elm::xom::String
Definition: String.h:35
elm::xom::Serializer
Definition: Serializer.h:46
elm::xom::Serializer::Serializer
Serializer(io::OutStream &out_stream)
Definition: xom_Serializer.cpp:106
elm::xom::Serializer::writeEmptyElementTag
virtual void writeEmptyElementTag(Element *element)
Definition: xom_Serializer.cpp:351
elm::xom::Serializer::setIndent
void setIndent(int indent)
Definition: Serializer.h:58
elm::xom::Serializer::getPreserveBaseURI
bool getPreserveBaseURI(void) const
Definition: Serializer.h:55
value
elm::xom::Serializer::setUnicodeNormalizationFormC
void setUnicodeNormalizationFormC(bool normalize)
Definition: Serializer.h:63
elm::xom::Serializer::writeAttributes
virtual void writeAttributes(Element *element)
Definition: xom_Serializer.cpp:209
elm::xom::Text
Definition: Text.h:15
elm::xom::Serializer::getMaxLength
int getMaxLength(void) const
Definition: Serializer.h:54
elm::xom::Serializer::getColumnNumber
int getColumnNumber(void)
Definition: xom_Serializer.cpp:153
elm::xom::Serializer::getIndent
int getIndent(void) const
Definition: Serializer.h:52
elm::xom::Serializer::writeNamespaceDeclaration
virtual void writeNamespaceDeclaration(const string &prefix, const string &uri)
Definition: xom_Serializer.cpp:388
elm::xom::Serializer::writeAttributeValue
virtual void writeAttributeValue(String value)
Definition: xom_Serializer.cpp:187
elm::xom::Serializer::setOutputStream
void setOutputStream(io::OutStream &out)
Definition: Serializer.h:61
elm::xom::Serializer::setPreserveBaseURI
void setPreserveBaseURI(bool preserve)
Definition: Serializer.h:62
elm::io::Output::setStream
void setStream(OutStream &stream)
Definition: io_Output.cpp:117
elm::xom::Serializer::writeEscaped
virtual void writeEscaped(String text)
Definition: xom_Serializer.cpp:472
elm
Definition: adapter.h:26
elm::xom::Serializer::setLineSeparator
void setLineSeparator(string line_separator)
Definition: Serializer.h:59
elm::xom::Serializer::writeChild
virtual void writeChild(Node *node)
Definition: xom_Serializer.cpp:329
elm::xom::Serializer::writeRaw
virtual void writeRaw(String text, int length=-1)
Definition: xom_Serializer.cpp:172
elm::io::OutStream
Definition: OutStream.h:30
elm::xom::Comment
Definition: Comment.h:30
elm::xom::Document
Definition: Document.h:20
elm::xom::Serializer::getEncoding
const string & getEncoding(void) const
Definition: Serializer.h:51
elm::xom::Serializer::writeEndTag
virtual void writeEndTag(Element *element)
Definition: xom_Serializer.cpp:366
elm::xom::Serializer::writeXMLDeclaration
virtual void writeXMLDeclaration(void)
Definition: xom_Serializer.cpp:456
elm::xom::Serializer::getLineSeparator
const string & getLineSeparator(void) const
Definition: Serializer.h:53
elm::xom::Serializer::writeNamespaceDeclarations
virtual void writeNamespaceDeclarations(Element *element)
Definition: xom_Serializer.cpp:400
elm::xom::Element
Definition: Element.h:21
elm::xom::Serializer::writeStartTag
virtual void writeStartTag(Element *element)
Definition: xom_Serializer.cpp:413
elm::xom::Serializer::breakLine
virtual void breakLine(void)
Definition: xom_Serializer.cpp:161
elm::xom::Serializer::getUnicodeNormalizationFormC
bool getUnicodeNormalizationFormC() const
Definition: Serializer.h:56
elm::io::Output
Definition: Output.h:179
elm::xom::Serializer::setMaxLength
void setMaxLength(int max_length)
Definition: Serializer.h:60
elm::xom::Attribute
Definition: Attribute.h:30
elm::xom::Node
Definition: Node.h:40