00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _udom_hpp_
00021 #define _udom_hpp_
00022
00023 #include <map>
00024 #include <ubit/udoc.hpp>
00025 #include <ubit/uclassImpl.hpp>
00026 #include <ubit/ustr.hpp>
00027 #include <fstream>
00028 namespace ubit {
00029
00030 class UXmlGrammar;
00031 class UXmlGrammars;
00032
00033
00036 class UComment : public UBrick {
00037 public:
00038 UBIT_CLASS(UComment, UBrick)
00039
00040 UComment(const UStr& = "");
00041 virtual unsigned short getNodeType() const {return COMMENT_NODE;}
00042 virtual const UStr* getNodeName() const;
00043 virtual const UStr* getNodeValue() const {return data;}
00044 virtual const UStr* getData() const {return data;}
00045
00046 private:
00047 uptr<UStr> data;
00048 };
00049
00050
00053 class UCDATASection : public UBrick {
00054 public:
00055 UBIT_CLASS(UCDATASection, UBrick)
00056
00057 UCDATASection(const UStr& = "");
00058 virtual unsigned short getNodeType() const {return CDATA_SECTION_NODE;}
00059 virtual const UStr* getNodeName() const;
00060 virtual const UStr* getNodeValue() const {return data;}
00061 virtual const UStr* getData() const {return data;}
00062
00063 private:
00064 uptr<UStr> data;
00065 };
00066
00067
00070 class UProcessingInstruction : public UBrick {
00071 public:
00072 UBIT_CLASS(UProcessingInstruction, UBrick)
00073
00074 UProcessingInstruction(const UStr& target, const UStr& data);
00075 virtual unsigned short getNodeType() const {return PROCESSING_INSTRUCTION_NODE;}
00076 virtual const UStr* getNodeName() const {return target;}
00077 virtual const UStr* getNodeValue() const {return data;}
00078 virtual const UStr* getTarget() const {return target;}
00079 virtual const UStr* getData() const {return data;}
00080
00081 private:
00082 friend class Class;
00083 uptr<UStr> target, data;
00084 UProcessingInstruction();
00085 };
00086
00087
00090 class UXmlDocType : public UBrick {
00091 public:
00092 UBIT_CLASS(UXmlDocType, UBrick)
00093
00094 UXmlDocType(const UStr& name, const UStr& public_id, const UStr& system_id);
00095 virtual ~UXmlDocType();
00096 virtual unsigned short getNodeType() const {return DOCUMENT_TYPE_NODE;}
00097 virtual const UStr* getNodeName() const {return name;}
00098 virtual const UStr* getName() const {return name;}
00099 virtual const UStr* getPublicId() const {return public_id;}
00100 virtual const UStr* getSystemId() const {return system_id;}
00101
00102 private:
00103 friend class UXmlDoc;
00104 friend class Class;
00105 uptr<UStr> name, public_id, system_id;
00106 UXmlDocType();
00107 };
00108
00109
00110
00113 class UXmlDoc : public UDoc {
00114 public:
00115 UBIT_ELEMENT_CLASS(UXmlDoc, UDoc)
00116
00117 UXmlDoc();
00118 UXmlDoc(const UStr& pathname);
00119 virtual ~UXmlDoc();
00120
00121 virtual unsigned short getNodeType() const {return DOCUMENT_NODE;}
00122 virtual const UStr* getNodeName() const;
00123 virtual const UStr* getNodeValue() const {return null;}
00124
00125 virtual UGroup* getDocumentElement() {return doc_elem;}
00126 virtual const UGroup* getDocumentElement() const {return doc_elem;}
00127 virtual const UXmlDocType* getDoctype() const {return doc_type;}
00128 virtual const UStr* getXmlVersion() const {return xml_version;}
00129 virtual const UStr* getXmlEncoding() const {return xml_encoding;}
00130 virtual bool isXmlStandalone() const {return xml_standalone;}
00131
00132 virtual UProp* createAttribute(const UStr& name);
00133 virtual UGroup* createElement(const UStr& name);
00134 virtual UStr* createTextNode(const UStr& data);
00135 virtual UComment* createComment(const UStr& data);
00136 virtual UCDATASection* createCDATASection(const UStr& data);
00137 virtual UProcessingInstruction* createProcessingInstruction(const UStr& target, const UStr& data);
00138
00139 virtual void initElement(UGroup*);
00140 virtual void setClassStyle(UGroup*, const UStr* name, const UStr* value);
00141 virtual void setIdStyle(UGroup*, const UStr* name, const UStr* value);
00142
00143 virtual void addGrammar(const UXmlGrammar&);
00145
00146 virtual void print(std::ostream& fout);
00148
00149 virtual void print(UStr& buffer);
00151
00152 virtual const UDocAttachments* getAttachments() const;
00154
00155 virtual int loadAttachments(bool reload = false);
00156 virtual bool loadAttachment(UDocAttachment*, bool reload = false);
00157 virtual void addAttachment(UDocAttachment*);
00159
00160 const UStyleSheet& getStyleSheet() const {return doc_stylesheet;}
00161 UStyleSheet& getStyleSheet() {return doc_stylesheet;}
00163
00164
00165 protected:
00166 friend class UXmlParser;
00167 static const UStr NodeName;
00168 uptr<UStr> xml_version, xml_encoding;
00169 bool xml_standalone;
00170 UXmlDocType* doc_type;
00171 UXmlGrammars* grammars;
00172 UStyleSheet doc_stylesheet;
00173 UGroup* doc_elem;
00174 UDocAttachments attachments;
00175 void constructs();
00176 virtual void setClassIdStyle(UGroup*, const UStr* name, const UStr* value);
00177 };
00178
00179
00182 struct UXmlCreator : public UDocCreator {
00183 UXmlCreator();
00184 virtual UDoc* create(UDocSource& doc);
00185
00186 bool load_objects;
00187 bool keep_comments;
00188 bool permissive;
00189 bool collapse_spaces;
00190 };
00191
00194 struct UHtmlCreator : public UXmlCreator {
00195 UHtmlCreator();
00196 };
00197
00198
00199
00200 struct UImgAttachment : public UDocAttachment {
00201 const UStr url, *type;
00202 UIma* ima;
00203
00204 UImgAttachment(const UStr* _url, const UStr* _type, UIma* _ima)
00205 : url(_url ? *_url : ""), type(_type), ima(_ima) {}
00206
00207 virtual const UStr* getUrl() const {return &url;}
00208 virtual const UStr* getType() const {return type;}
00209 virtual bool isLoaded() const;
00210 virtual int load(UDoc*);
00211 };
00212
00213
00214
00215 struct UCssAttachment : public UDocAttachment {
00216 const UStr *url, *type;
00217 UXmlDoc* doc;
00218 int stat;
00219
00220 UCssAttachment(const UStr* _url, const UStr* _type, UXmlDoc* _doc)
00221 : url(_url), type(_type), doc(_doc), stat(0) {}
00222
00223 virtual const UStr* getUrl() const {return url;}
00224 virtual const UStr* getType() const {return type;}
00225 virtual bool isLoaded() const {return stat > 0;}
00226 virtual int load(UDoc*);
00227 };
00228
00229 }
00230 #endif
00231
00232
00233