00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012 #ifndef _WX_DTD_H_
00013 #define _WX_DTD_H_
00014
00015
00016 #include "wx/xml2.h"
00017
00018
00019
00020 class WXDLLIMPEXP_WXXML2 wxXml2DTD;
00021 class WXDLLIMPEXP_WXXML2 wxXml2ElemDecl;
00022 class WXDLLIMPEXP_WXXML2 wxXml2AttrDecl;
00023 class WXDLLIMPEXP_WXXML2 wxXml2EntityDecl;
00024 class WXDLLIMPEXP_WXXML2 wxXml2ElemContent;
00025 class WXDLLIMPEXP_WXXML2 wxXml2Enumeration;
00026
00027
00028
00029 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2DTD) wxXml2EmptyDTD;
00030 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2ElemDecl) wxXml2EmptyElemDecl;
00031 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2AttrDecl) wxXml2EmptyAttrDecl;
00032 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2EntityDecl) wxXml2EmptyEntityDecl;
00033 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2Enumeration) wxXml2EmptyEnumeration;
00034 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2ElemContent) wxXml2EmptyElemContent;
00035
00036
00037
00040 enum wxXml2ElementTypeVal {
00041 wxXML2_ELEMENT_TYPE_UNDEFINED = 0,
00042 wxXML2_ELEMENT_TYPE_EMPTY = 1,
00043 wxXML2_ELEMENT_TYPE_ANY,
00044 wxXML2_ELEMENT_TYPE_MIXED,
00045 wxXML2_ELEMENT_TYPE_ELEMENT
00046 };
00047
00048
00051 enum wxXml2ElementContentType {
00052 wxXML2_ELEMENT_CONTENT_PCDATA = 1,
00053 wxXML2_ELEMENT_CONTENT_ELEMENT,
00054 wxXML2_ELEMENT_CONTENT_SEQ,
00055 wxXML2_ELEMENT_CONTENT_OR,
00056 };
00057
00058
00061 enum wxXml2ElementContentOccur {
00062 wxXML2_ELEMENT_CONTENT_ONCE = 1,
00063 wxXML2_ELEMENT_CONTENT_OPT,
00064 wxXML2_ELEMENT_CONTENT_MULT,
00065 wxXML2_ELEMENT_CONTENT_PLUS,
00066 };
00067
00068
00070 enum wxXml2AttributeType {
00071 wxXML2_ATTRIBUTE_CDATA = 1,
00072 wxXML2_ATTRIBUTE_ID,
00073 wxXML2_ATTRIBUTE_IDREF,
00074 wxXML2_ATTRIBUTE_IDREFS,
00075 wxXML2_ATTRIBUTE_ENTITY,
00076 wxXML2_ATTRIBUTE_ENTITIES,
00077 wxXML2_ATTRIBUTE_NMTOKEN,
00078 wxXML2_ATTRIBUTE_NMTOKENS,
00079 wxXML2_ATTRIBUTE_ENUMERATION,
00080 wxXML2_ATTRIBUTE_NOTATION
00081 };
00082
00083
00085 enum wxXml2AttributeDefault {
00086 wxXML2_ATTRIBUTE_NONE = 1,
00087 wxXML2_ATTRIBUTE_REQUIRED,
00088 wxXML2_ATTRIBUTE_IMPLIED,
00089 wxXML2_ATTRIBUTE_FIXED
00090 };
00091
00092
00094 enum wxXml2EntityType {
00095 wxXML2_INTERNAL_GENERAL_ENTITY = 1,
00096 wxXML2_EXTERNAL_GENERAL_PARSED_ENTITY,
00097 wxXML2_EXTERNAL_GENERAL_UNPARSED_ENTITY,
00098 wxXML2_INTERNAL_PARAMETER_ENTITY,
00099 wxXML2_EXTERNAL_PARAMETER_ENTITY,
00100 wxXML2_INTERNAL_PREDEFINED_ENTITY,
00101 };
00102
00103
00110 class WXDLLIMPEXP_WXXML2 wxXml2HelpWrapper : public wxObject
00111 {
00112 DECLARE_ABSTRACT_CLASS(wxXml2HelpWrapper)
00113
00114
00115 bool m_bLinked;
00116
00117 protected:
00118
00120 virtual void Destroy() = 0;
00121
00123 virtual void DestroyIfUnlinked();
00124
00127 void Link(bool linking = TRUE)
00128 { wxASSERT_MSG(m_bLinked != linking || linking == FALSE,
00129 wxT("Cannot link this node another time; already linked !!"));
00130 m_bLinked = linking; }
00131
00132 public:
00133 wxXml2HelpWrapper() { m_bLinked=FALSE; }
00134 virtual ~wxXml2HelpWrapper() {}
00135 };
00136
00137
00138
00157 class WXDLLIMPEXP_WXXML2 wxXml2ElemContent : public wxXml2HelpWrapper
00158 {
00159 friend class wxXml2ElemDecl;
00160 DECLARE_DYNAMIC_CLASS(wxXml2ElemContent)
00161
00162
00163 xmlElementContent *m_cont;
00164
00165 protected:
00166
00167 void Destroy() {
00168 if (m_cont) xmlFreeElementContent(m_cont);
00169 SetAsEmpty();
00170 }
00171
00172 void SetAsEmpty()
00173 { m_cont = NULL; }
00174
00175 void Copy(const wxXml2ElemContent &n)
00176 { m_cont = xmlCopyElementContent(n.m_cont); }
00177
00178
00179 public:
00180
00181 wxXml2ElemContent(xmlElementContent *cont = NULL)
00182 : m_cont(cont) {}
00183
00184 wxXml2ElemContent(const wxString &name,
00185 wxXml2ElementContentType val = wxXML2_ELEMENT_CONTENT_PCDATA,
00186 wxXml2ElementContentOccur occ = wxXML2_ELEMENT_CONTENT_ONCE)
00187 { m_cont=NULL; Create(name, val, occ); }
00188
00189 virtual ~wxXml2ElemContent() { DestroyIfUnlinked(); }
00190
00191
00192 public:
00193
00194 bool operator==(const wxXml2ElemContent &decl) const;
00195 bool operator!=(const wxXml2ElemContent &decl) const { return !(*this == decl); }
00196
00197 wxXml2ElemContent &operator=(const wxXml2ElemContent &decl)
00198 { Copy(decl); return *this; }
00199
00200
00201 public:
00202
00203 void Create(const wxString &name,
00204 wxXml2ElementContentType val,
00205 wxXml2ElementContentOccur occ);
00206
00207 bool IsNonEmpty() const
00208 { return m_cont != NULL; }
00209
00210 xmlElementContent *GetObj() const
00211 { return m_cont; }
00212
00213 wxXml2ElementContentType GetType() const
00214 { return (wxXml2ElementContentType)GetObj()->type; }
00215 wxXml2ElementContentOccur GetOccurrence() const
00216 { return (wxXml2ElementContentOccur)GetObj()->ocur; }
00217
00218 wxString GetName() const
00219 { if (GetObj()) return XML2WX(GetObj()->name); return wxEmptyString; }
00220 wxXml2Namespace GetNamespace() const
00221 { if (GetObj()) return wxXml2Namespace(XML2WX(GetObj()->prefix), wxEmptyString); return wxXml2EmptyNamespace; }
00222
00223 wxXml2ElemContent GetFirstChild() const
00224 { if (GetObj()) return wxXml2ElemContent(GetObj()->c1); return wxXml2EmptyElemContent; }
00225 wxXml2ElemContent GetSecondChild() const
00226 { if (GetObj()) return wxXml2ElemContent(GetObj()->c2); return wxXml2EmptyElemContent; }
00227 wxXml2ElemContent GetParent() const
00228 { if (GetObj()) return wxXml2ElemContent(GetObj()->parent); return wxXml2EmptyElemContent; }
00229 };
00230
00231
00232
00240 class WXDLLIMPEXP_WXXML2 wxXml2Enumeration : public wxXml2HelpWrapper
00241 {
00242 friend class wxXml2AttrDecl;
00243 DECLARE_DYNAMIC_CLASS(wxXml2Enumeration)
00244
00245
00246 xmlEnumeration *m_enum;
00247
00248 protected:
00249
00250 void Destroy() {
00251 if (m_enum) xmlFreeEnumeration(m_enum);
00252 SetAsEmpty();
00253 }
00254
00255 void SetAsEmpty()
00256 { m_enum = NULL; }
00257
00258 void Copy(const wxXml2Enumeration &n)
00259 { m_enum = xmlCopyEnumeration(n.m_enum); }
00260
00261 public:
00262
00263 wxXml2Enumeration(xmlEnumeration *towrap = NULL) : m_enum(towrap) {}
00264 wxXml2Enumeration(const wxXml2Enumeration &tocopy) : wxXml2HelpWrapper()
00265 { Copy(tocopy); }
00266
00267 wxXml2Enumeration(const wxString &name, const wxXml2Enumeration &next)
00268 { m_enum=NULL; Create(name, next); }
00269 wxXml2Enumeration(const wxString &list)
00270 { m_enum=NULL; Create(list); }
00271
00272 virtual ~wxXml2Enumeration()
00273 { DestroyIfUnlinked(); }
00274
00275
00276 public:
00277
00278 bool operator==(const wxXml2Enumeration &decl) const;
00279 bool operator!=(const wxXml2Enumeration &decl) const { return !(*this == decl); }
00280
00281 wxXml2Enumeration &operator=(const wxXml2Enumeration &decl)
00282 { Copy(decl); return *this; }
00283
00284
00285 public:
00286
00287 void Create(const wxString &name, const wxXml2Enumeration &next);
00288 void Create(const wxString &list);
00289
00291 void Append(const wxXml2Enumeration &e)
00292 { Append(e.GetObj()); }
00293
00294 void Append(xmlEnumeration *e);
00295
00296 bool IsNonEmpty() const
00297 { return m_enum != NULL; }
00298
00299 xmlEnumeration *GetObj() const
00300 { return m_enum; }
00301
00302 wxXml2Enumeration GetNext() const
00303 { if (GetObj()) return wxXml2Enumeration(GetObj()->next); return wxXml2EmptyEnumeration; }
00304 wxString GetName() const
00305 { if (GetObj()) return XML2WX(GetObj()->name); return wxEmptyString; }
00306 };
00307
00308
00309
00310
00324 class WXDLLIMPEXP_WXXML2 wxXml2ElemDecl : public wxXml2BaseNode
00325 {
00326 DECLARE_DYNAMIC_CLASS(wxXml2ElemDecl)
00327
00328 public:
00329
00330 wxXml2ElemDecl() {}
00331
00333 wxXml2ElemDecl(xmlElement *n)
00334 { m_obj = (wxXml2BaseNodeObj*)n; JustWrappedNew(); }
00335
00337 wxXml2ElemDecl(const wxXml2ElemDecl &n) : wxXml2BaseNode()
00338 { Copy(n); }
00339
00342 wxXml2ElemDecl(const wxXml2DTD &parent, const wxString &name,
00343 wxXml2ElementTypeVal val = wxXML2_ELEMENT_TYPE_ELEMENT,
00344 wxXml2ElemContent &content = wxXml2EmptyElemContent)
00345 { Create(parent, name, val, content); }
00346
00347 virtual ~wxXml2ElemDecl() { DestroyIfUnlinked(); }
00348
00349
00350 public:
00351
00352 bool operator==(const wxXml2ElemDecl &decl) const;
00353 bool operator!=(const wxXml2ElemDecl &decl) const { return !(*this == decl); }
00354
00355 wxXml2ElemDecl &operator=(const wxXml2ElemDecl &decl)
00356 { Copy(decl); return *this; }
00357
00358
00359 public:
00360
00361 void Create(const wxXml2DTD &parent, const wxString &name,
00362 wxXml2ElementTypeVal val, wxXml2ElemContent &content);
00363 xmlElement *GetObj() const
00364 { return (xmlElement *)m_obj; }
00365
00366
00367 wxXml2DTD GetParent() const;
00368 wxXml2AttrDecl GetAttributes() const;
00369
00370 wxXml2ElementTypeVal GetType() const
00371 { return (wxXml2ElementTypeVal)GetObj()->etype; }
00372 wxXml2ElemContent GetContent() const
00373 { if (GetObj()) return wxXml2ElemContent(GetObj()->content); return wxXml2EmptyElemContent; }
00374 wxXml2Namespace GetNamespace() const
00375 { if (GetObj()) return wxXml2Namespace(XML2WX(GetObj()->prefix), wxEmptyString); return wxXml2EmptyNamespace; }
00376 };
00377
00378
00379
00392 class WXDLLIMPEXP_WXXML2 wxXml2AttrDecl : public wxXml2BaseNode
00393 {
00394 DECLARE_DYNAMIC_CLASS(wxXml2AttrDecl)
00395
00396
00397
00398
00399 public:
00400
00401 wxXml2AttrDecl() {}
00402
00404 wxXml2AttrDecl(xmlAttribute *n)
00405 { m_obj = (wxXml2BaseNodeObj*)n; JustWrappedNew(); }
00406
00408 wxXml2AttrDecl(const wxXml2AttrDecl &n) : wxXml2BaseNode()
00409 { Copy(n); }
00410
00413 wxXml2AttrDecl(const wxXml2DTD &parent, const wxString &element,
00414 const wxString &name,
00415 const wxXml2Namespace &ns = wxXml2EmptyNamespace,
00416 wxXml2AttributeType type = wxXML2_ATTRIBUTE_CDATA,
00417 wxXml2AttributeDefault def = wxXML2_ATTRIBUTE_NONE,
00418 const wxString &defaultval = wxEmptyString,
00419 wxXml2Enumeration &e = wxXml2EmptyEnumeration)
00420 { Create(parent, element, name, ns, type, def, defaultval, e); }
00421
00422 virtual ~wxXml2AttrDecl() { DestroyIfUnlinked(); }
00423
00424
00425 public:
00426
00427 bool operator==(const wxXml2AttrDecl &decl) const;
00428 bool operator!=(const wxXml2AttrDecl &decl) const { return !(*this == decl); }
00429
00430 wxXml2AttrDecl &operator=(const wxXml2AttrDecl &decl)
00431 { Copy(decl); return *this; }
00432
00433
00434 public:
00435
00436 void Create(const wxXml2DTD &parent, const wxString &element,
00437 const wxString &name, const wxXml2Namespace &ns,
00438 wxXml2AttributeType type, wxXml2AttributeDefault def,
00439 const wxString &defaultval, wxXml2Enumeration &e);
00440
00441 xmlAttribute *GetObj() const
00442 { return (xmlAttribute*)m_obj; }
00443
00444
00445 wxXml2DTD GetParent() const;
00446
00447 wxXml2AttributeType GetType() const
00448 { return (wxXml2AttributeType)GetObj()->atype; }
00449 wxXml2AttributeDefault GetDefault() const
00450 { return (wxXml2AttributeDefault)GetObj()->def; }
00451 wxXml2Enumeration GetEnum() const
00452 { if (GetObj()) return wxXml2Enumeration(GetObj()->tree); return wxXml2EmptyEnumeration; }
00453 wxXml2Namespace GetNamespace() const
00454 { if (GetObj()) return wxXml2Namespace(XML2WX(GetObj()->prefix), wxEmptyString); return wxXml2EmptyNamespace; }
00455 wxString GetDefaultVal() const
00456 { if (GetObj()) return XML2WX(GetObj()->defaultValue); return wxEmptyString; }
00457 wxString GetElementName() const
00458 { if (GetObj()) return XML2WX(GetObj()->elem); return wxEmptyString; }
00459 wxString GetName() const
00460 { if (GetObj()) return XML2WX(GetObj()->name); return wxEmptyString; }
00461 };
00462
00463
00464
00465
00474 class WXDLLIMPEXP_WXXML2 wxXml2EntityDecl : public wxXml2BaseNode
00475 {
00476 DECLARE_DYNAMIC_CLASS(wxXml2EntityDecl)
00477
00478
00479
00480
00481 public:
00482
00483 wxXml2EntityDecl() {}
00484
00486 wxXml2EntityDecl(xmlEntity *n)
00487 { m_obj = (wxXml2BaseNodeObj*)n; JustWrappedNew(); }
00488
00490 wxXml2EntityDecl(const wxXml2EntityDecl &n) : wxXml2BaseNode()
00491 { Copy(n); }
00492
00493
00494 wxXml2EntityDecl(const wxXml2DTD &parent, const wxString &name,
00495 wxXml2EntityType type = wxXML2_INTERNAL_GENERAL_ENTITY,
00496 const wxString &externalID = wxEmptyString,
00497 const wxString &systemID = wxEmptyString,
00498 const wxString &content = wxEmptyString)
00499 { Create(parent, name, type, externalID, systemID, content); }
00500
00501 virtual ~wxXml2EntityDecl() { DestroyIfUnlinked(); }
00502
00503
00504 public:
00505
00506 bool operator==(const wxXml2EntityDecl &decl) const;
00507 bool operator!=(const wxXml2EntityDecl &decl) const { return !(*this == decl); }
00508
00509 wxXml2EntityDecl &operator=(const wxXml2EntityDecl &decl)
00510 { Copy(decl); return *this; }
00511
00512
00513 public:
00514
00515 void Create(const wxXml2DTD &parent, const wxString &name,
00516 wxXml2EntityType type, const wxString &externalID,
00517 const wxString &systemID, const wxString &content);
00518
00519 xmlEntity *GetObj() const
00520 { return (xmlEntity *)m_obj; }
00521
00522
00523 wxXml2DTD GetParent() const;
00524
00525 wxXml2EntityType GetType() const
00526 { return (wxXml2EntityType)GetObj()->etype; }
00527 wxString GetName() const
00528 { if (GetObj()) return XML2WX(GetObj()->name); return wxEmptyString; }
00529 wxString GetContent() const
00530 { if (GetObj()) return XML2WX(GetObj()->content); return wxEmptyString; }
00531 wxString GetExternalID() const
00532 { if (GetObj()) return XML2WX(GetObj()->ExternalID); return wxEmptyString; }
00533 wxString GetSystemID() const
00534 { if (GetObj()) return XML2WX(GetObj()->SystemID); return wxEmptyString; }
00535 };
00536
00537
00538
00539
00574 class WXDLLIMPEXP_WXXML2 wxXml2DTD : public wxXml2Wrapper
00575 {
00576 DECLARE_DYNAMIC_CLASS(wxXml2DTD)
00577
00578
00579 xmlDtd *m_dtd;
00580
00581 protected:
00582
00583 void Destroy() {
00584 if (m_dtd) xmlFreeDtd(m_dtd);
00585 SetAsEmpty();
00586 }
00587
00588 void SetAsEmpty()
00589 { m_dtd = NULL; }
00590
00591 void Copy(const wxXml2DTD &dtd) {
00592 UnwrappingOld();
00593 m_dtd = dtd.m_dtd;
00594 JustWrappedNew();
00595 }
00596
00597 int &GetPrivate() const
00598 { return (int &)(m_dtd->_private); }
00599
00605 void SetRoot(wxXml2BaseNode &node);
00606
00607 public:
00608
00610 wxXml2DTD() : m_dtd(NULL) {}
00611
00614 wxXml2DTD(const wxString &file) : m_dtd(NULL)
00615 { Load(file); }
00616
00618 wxXml2DTD(const wxXml2Document &doc,
00619 const wxString &name, const wxString &externalid,
00620 const wxString &systemid) : m_dtd(NULL)
00621 { Create(doc, name, externalid, systemid); }
00622
00624 wxXml2DTD(xmlDtd *dtd) : m_dtd(dtd)
00625 { JustWrappedNew(); }
00626
00628 wxXml2DTD(const wxXml2DTD &dtd) : wxXml2Wrapper(), m_dtd(NULL)
00629 { Copy(dtd); }
00630
00633 virtual ~wxXml2DTD() { DestroyIfUnlinked(); }
00634
00635
00636 public:
00637
00638 bool operator==(const wxXml2DTD &ns) const;
00639 bool operator!=(const wxXml2DTD &p) const { return !(*this == p); }
00640
00641 wxXml2DTD &operator=(const wxXml2DTD &dtd)
00642 { Copy(dtd); return *this; }
00643
00644 public:
00645
00647 void Create(const wxXml2Document &doc,
00648 const wxString &name, const wxString &externalid,
00649 const wxString &systemid);
00650
00651
00655 bool Load(wxInputStream &, wxString *pErr = NULL);
00656
00658 bool Load(const wxString &filename, wxString *pErr = NULL);
00659
00662 int Save(wxOutputStream &, long flags = wxXML2DOC_USE_NATIVE_NEWLINES) const;
00663
00665 bool Save(const wxString &filename, long flags = wxXML2DOC_USE_NATIVE_NEWLINES) const;
00666
00670 bool LoadFullDTD(wxString *pErr = NULL);
00671
00672
00673 public:
00674
00676 bool IsOk() const;
00677
00679 bool IsNonEmpty() const
00680 { return m_dtd != NULL; }
00681
00684 bool IsUnlinked() const
00685 { if (!m_dtd) return TRUE; return (m_dtd->parent == NULL); }
00686
00691 bool IsExternalReference() const;
00692
00700 bool IsSystemSubset() const;
00701
00710 bool IsPublicSubset() const;
00711
00720 bool IsFullDTD() const
00721 { return !IsExternalReference(); }
00722
00723 public:
00724
00728 wxString GetExternalID() const
00729 { if (IsPublicSubset()) return XML2WX(m_dtd->ExternalID); return wxEmptyString; }
00730
00736 wxString GetExternalURI() const
00737 { if (IsPublicSubset()) return XML2WX(m_dtd->SystemID); return wxEmptyString; }
00738
00742 wxString GetSystemID() const
00743 { if (IsSystemSubset()) return XML2WX(m_dtd->SystemID); return wxEmptyString; }
00744
00748 wxString GetName() const { return XML2WX(m_dtd->name); }
00749
00751 xmlDtd *GetObj() const { return m_dtd; }
00752
00756 wxXml2BaseNode GetRoot() const;
00757
00758 public:
00759
00760 void SetName(const wxString &p);
00761 void SetSystemID(const wxString &u);
00762 void SetExternalID(const wxString &u);
00763
00766 void SetExternalURI(const wxString &u)
00767 { SetSystemID(u); }
00768
00770 void SetRoot(wxXml2ElemDecl &node)
00771 { SetRoot((wxXml2BaseNode &)node); }
00772 void SetRoot(wxXml2AttrDecl &node)
00773 { SetRoot((wxXml2BaseNode &)node); }
00774 void SetRoot(wxXml2EntityDecl &node)
00775 { SetRoot((wxXml2BaseNode &)node); }
00776
00777
00778 public:
00779
00784 void AddElemDecl(const wxString &name,
00785 wxXml2ElementTypeVal val = wxXML2_ELEMENT_TYPE_ELEMENT,
00786 wxXml2ElemContent &content = wxXml2EmptyElemContent);
00787
00792 void AddAttrDecl(const wxString &element,
00793 const wxString &name,
00794 const wxXml2Namespace &ns = wxXml2EmptyNamespace,
00795 wxXml2AttributeType type = wxXML2_ATTRIBUTE_CDATA,
00796 wxXml2AttributeDefault def = wxXML2_ATTRIBUTE_NONE,
00797 const wxString &defaultval = wxEmptyString,
00798 wxXml2Enumeration &e = wxXml2EmptyEnumeration);
00799
00801 void AddEntityDecl(const wxString &name,
00802 wxXml2EntityType type = wxXML2_INTERNAL_GENERAL_ENTITY,
00803 const wxString &externalID = wxEmptyString,
00804 const wxString &systemID = wxEmptyString,
00805 const wxString &content = wxEmptyString);
00806 };
00807
00808
00809 #endif // _WX_DTD_H_