ubit
udom.hpp
1 /* ==================================================== ======== ======= *
2  *
3  * udom.hpp
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _udom_hpp_
18 #define _udom_hpp_ 1
19 #include <map>
20 #include <ubit/udoc.hpp>
21 #include <ubit/uclassImpl.hpp> //UStyleSheet
22 #include <ubit/ustr.hpp>
23 #include <fstream>
24 namespace ubit {
25 
26  class UXmlGrammar;
27  class UXmlGrammars;
28 
29  /* ==================================================== ======== ======= */
32  class UComment : public UNode {
33  public:
34  UCLASSDEF("comment", UComment, new UComment)
35 
36  UComment(const UStr& = "");
37  virtual int getNodeType() const {return COMMENT_NODE;}
38  virtual const UStr& getNodeName() const;
39  virtual UStr getNodeValue() const {return *data;}
40  virtual const UStr& getData() const {return *data;}
41 
42  private:
43  uptr<UStr> data;
44  };
45 
46  /* ==================================================== ======== ======= */
49  class UCDATASection : public UNode { // pas bon: va afficher cdata
50  public:
51  UCLASSDEF("CDATASection", UCDATASection, new UCDATASection)
52 
53  UCDATASection(const UStr& = "");
54  virtual int getNodeType() const {return CDATA_SECTION_NODE;}
55  virtual const UStr& getNodeName() const;
56  virtual UStr getNodeValue() const {return *data;}
57  virtual const UStr& getData() const {return *data;}
58 
59  private:
60  uptr<UStr> data;
61  };
62 
63  /* ==================================================== ======== ======= */
66  class UProcessingInstruction : public UNode {
67  public:
68  UCLASSDEF("processinginstruction", UProcessingInstruction, new UProcessingInstruction("",""))
69 
70  UProcessingInstruction(const UStr& target, const UStr& data);
71  virtual int getNodeType() const {return PROCESSING_INSTRUCTION_NODE;}
72  virtual const UStr& getNodeName() const {return getTarget();}
73  virtual UStr getNodeValue() const {return getData();}
74  virtual const UStr& getTarget() const {return *target;}
75  virtual const UStr& getData() const {return *data;}
76 
77  private:
78  uptr<UStr> target, data;
79  };
80 
81  /* ==================================================== ======== ======= */
84  class UXmlDocType : public UNode {
85  public:
86  UCLASSDEF("doctype", UXmlDocType, new UXmlDocType("","",""))
87 
88  UXmlDocType(const UStr& name, const UStr& public_id, const UStr& system_id);
89  virtual ~UXmlDocType();
90  virtual int getNodeType() const {return DOCUMENT_TYPE_NODE;}
91  virtual const UStr& getNodeName() const {return *name;}
92  virtual const UStr& getName() const {return *name;}
93  virtual const UStr& getPublicId() const {return *public_id;}
94  virtual const UStr& getSystemId() const {return *system_id;}
95 
96  private:
97  friend class UXmlDocument;
98  uptr<UStr> name, public_id, system_id;
99  //UXmlDocType();
100  };
101 
102 
103  /* ==================================================== ======== ======= */
106  class UXmlDocument : public UDoc {
107  public:
108  UCLASSDEF("document", UXmlDocument, new UXmlDocument)
109 
110  UXmlDocument();
111  UXmlDocument(const UStr& pathname);
112  virtual ~UXmlDocument();
113 
114  virtual int getNodeType() const {return DOCUMENT_NODE;}
115  virtual const UStr& getNodeName() const;
116  virtual UStr getNodeValue() const {return "";}
117 
118  virtual UElem* getDocumentElement() {return doc_elem;}
119  virtual const UElem* getDocumentElement() const {return doc_elem;}
120  virtual const UXmlDocType* getDoctype() const {return doc_type;}
121  virtual const UStr& getXmlVersion() const {return *xml_version;}
122  virtual const UStr& getXmlEncoding() const {return *xml_encoding;}
123  virtual bool isXmlStandalone() const {return xml_standalone;}
124 
125  virtual UAttr* createAttribute(const UStr& name);
126  virtual UElem* createElement(const UStr& name);
127  virtual UStr* createTextNode(const UStr& data);
128  virtual UComment* createComment(const UStr& data);
129  virtual UCDATASection* createCDATASection(const UStr& data);
130  virtual UProcessingInstruction* createProcessingInstruction(const UStr& target, const UStr& data);
131 
132  virtual void initElement(UElem*);
133  virtual void setClassStyle(UElem*, const UStr& name, const UStr& value);
134  virtual void setIdStyle(UElem*, const UStr& name, const UStr& value);
135 
136  virtual void addGrammar(const UXmlGrammar&);
138 
139  virtual void print(std::ostream& fout);
141 
142  virtual void print(UStr& buffer);
144 
145  virtual const UDocAttachments* getAttachments() const;
147 
148  virtual int loadAttachments(bool reload = false);
149  virtual bool loadAttachment(UDocAttachment*, bool reload = false);
150  virtual void addAttachment(UDocAttachment*);
152 
153  const UStyleSheet& getStyleSheet() const {return doc_stylesheet;}
154  UStyleSheet& getStyleSheet() {return doc_stylesheet;}
156 
157  protected:
158  friend class UXmlParser;
159  static const UStr NodeName;
160  uptr<UStr> xml_version, xml_encoding;
161  bool xml_standalone;
162  UXmlDocType* doc_type;
163  UXmlGrammars* grammars;
164  UStyleSheet doc_stylesheet;
165  UElem* doc_elem;
166  UDocAttachments attachments;
167  void constructs();
168  virtual void setClassIdStyle(UElem*, const UStr& name, const UStr& value);
169  };
170 
171  /* ==================================================== ======== ======= */
174  struct UXmlCreator : public UDocCreator {
175  UXmlCreator();
176  virtual UDoc* create(UDocSource& doc);
177 
180  bool permissive;
181  bool collapse_spaces;
182  };
183 
186  struct UHtmlCreator : public UXmlCreator {
187  UHtmlCreator();
188  };
189 
190  /* ==================================================== ======== ======= */
191 
192  struct UImgAttachment : public UDocAttachment {
193  const UStr url, type;
194  UIma* ima;
195 
196  UImgAttachment(const UStr& _url, const UStr& _type, UIma* _ima)
197  : url(_url), type(_type), ima(_ima) {}
198 
199  virtual const UStr& getUrl() const {return url;}
200  virtual const UStr& getType() const {return type;}
201  virtual bool isLoaded() const;
202  virtual int load(UDoc*);
203  };
204 
205  /* ==================================================== ======== ======= */
206 
207  struct UCssAttachment : public UDocAttachment {
208  const UStr url, type;
209  UXmlDocument* doc;
210  int stat;
211 
212  UCssAttachment(const UStr& _url, const UStr& _type, UXmlDocument* _doc)
213  : url(_url), type(_type), doc(_doc), stat(0) {}
214 
215  virtual const UStr& getUrl() const {return url;}
216  virtual const UStr& getType() const {return type;}
217  virtual bool isLoaded() const {return stat > 0;}
218  virtual int load(UDoc*);
219  };
220 
221 }
222 #endif
223 
bool keep_comments
keep comments [default=false].
Definition: udom.hpp:179
Base class for attributes.
Definition: uattr.hpp:97
virtual int getNodeType() const
returns the XML node type.
Definition: udom.hpp:37
Image.
Definition: uima.hpp:50
virtual UStr getNodeValue() const
return the XML node value.
Definition: udom.hpp:73
virtual int getNodeType() const
returns the XML node type.
Definition: udom.hpp:54
XML parser.
Definition: uxmlparser.hpp:30
Base class of objects that can be added to the UBIT scene graph (SEE DETAILS!).
Definition: unode.hpp:38
virtual const UStr & getNodeName() const
return the XML node name.
Definition: udom.hpp:72
Definition: udom.hpp:207
XML ProcessingInstruction.
Definition: udom.hpp:66
Definition: udom.hpp:192
[impl] XML Creator.
Definition: udom.hpp:174
virtual UStr getNodeValue() const
return the XML node value.
Definition: udom.hpp:39
virtual const UStr & getNodeName() const
return the XML node name.
Definition: udom.cpp:31
Document source (file, buffer, etc.).
Definition: udoc.hpp:199
virtual UStr getNodeValue() const
return the XML node value.
Definition: udom.hpp:116
Generic Document.
Definition: udoc.hpp:122
XML DocType.
Definition: udom.hpp:84
lightweight general purpose container.
Definition: uelem.hpp:44
Document attachment (image, stylesheet, etc.)
Definition: udoc.hpp:187
virtual int getNodeType() const
returns the XML node type.
Definition: udom.hpp:114
XML Grammar.
Definition: uxmlgrammar.hpp:27
XML Comment.
Definition: udom.hpp:32
Definition: uclassImpl.hpp:155
virtual int getNodeType() const
returns the XML node type.
Definition: udom.hpp:90
Definition: uhardfont.hpp:31
[impl] HTML Creator.
Definition: udom.hpp:186
virtual const UStr & getNodeName() const
return the XML node name.
Definition: udom.hpp:91
XML Doc.
Definition: udom.hpp:106
List of XML Grammars.
Definition: uxmlgrammar.hpp:59
virtual UStr getNodeValue() const
return the XML node value.
Definition: udom.hpp:56
Document creator interface (intended to be subclassed).
Definition: udoc.hpp:216
bool permissive
parse documents in permissive mode [default=false].
Definition: udom.hpp:180
XML CDATASection.
Definition: udom.hpp:49
virtual int getNodeType() const
returns the XML node type.
Definition: udom.hpp:71
Ubit String.
Definition: ustr.hpp:72
bool load_objects
load HTML objects (eg. images) [default=true].
Definition: udom.hpp:178
UStyleSheet & getStyleSheet()
impl.
Definition: udom.hpp:154