00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _PACKAGE_WXP_H_
00013 #define _PACKAGE_WXP_H_
00014
00015
00016 #include <wx/xml/xml.h>
00017 #include <wx/wfstream.h>
00018 #include <wx/dynarray.h>
00019
00020 #include "wxp/wxp.h"
00021
00022 class wxArray;
00023 class wxPackageXMLDescriptor;
00024 extern wxPackageXMLDescriptor wxEmptyPackageXMLDescriptor;
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define WXP_VERSION_NUMBER 1.1
00034 #define WXP_VERSION_STRING wxT("1.1")
00035
00038 class wxPackageXMLDescriptor : public wxPackageXML
00039 {
00040 DECLARE_DYNAMIC_CLASS(wxPackageXMLDescriptor)
00041
00042 public:
00043 wxPackageXMLDescriptor() { Reset(); }
00044 virtual ~wxPackageXMLDescriptor() {}
00045
00046
00047 void Reset()
00048 {
00049 m_pBasics = m_pLicensing = m_pDetails = m_pDep = m_pBuildSystem = m_pPackaging = NULL;
00050 m_pId = m_pDescription = m_pCategory = m_pKeywords = NULL;
00051 m_pWebsite = m_pCreationDate = NULL;
00052 m_pLicense = m_pOrganization = m_pCost = m_pCredits = NULL;
00053 m_pCopyright = m_pAuthors = m_pMaintainers = NULL;
00054 m_pStatus = m_pProgLanguage = m_pSamples = NULL;
00055 m_pDownloads = m_pLogo = m_pRSS = m_pScreenshots = m_pDocs = NULL;
00056 m_pSupportedPorts = m_pTestedPorts = NULL;
00057 m_pFormats = m_pOptions = m_pStages = NULL;
00058 m_pRoot = m_pContents = m_pFileName = m_pUpload = m_pCompress = NULL;
00059
00060 for (size_t i=0; i<wxPDT_MAX; i++)
00061 m_pDependencies[i] = NULL;
00062
00063 m_nIndentationStep = 4;
00064 }
00065
00066 public:
00067
00069 const wxPackageInfo &GetPackageInfo() const
00070 { return m_info; }
00071
00072 public:
00073
00076 void SetPackageInfo(const wxPackageInfo &);
00077
00078 public:
00079
00080
00081
00082
00083
00084 bool Load(const wxString &filename)
00085 {
00086 wxFileInputStream stream(filename);
00087 if (!stream.Ok())
00088 return false;
00089 return Load(stream);
00090 }
00091
00092 bool Load(wxInputStream &stream)
00093 {
00094 SetRoot(NULL);
00095 Reset();
00096
00097 if (!wxPackageXML::Load(stream, wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES))
00098 return false;
00099 return Parse();
00100 }
00101
00102
00103 bool Parse();
00104
00105 bool Save(const wxString &filename) const
00106 { return wxPackageXML::Save(filename, -1); }
00107 bool Save(wxOutputStream &stream) const
00108 { return wxPackageXML::Save(stream, -1); }
00109
00110 wxPackageXMLDescriptor& operator=(const wxPackageXMLDescriptor& doc)
00111 {
00112 Reset();
00113
00114
00115 ((wxXmlDocument&)(*this)) = (wxXmlDocument&)doc;
00116
00117
00118 m_pBasics = FindNode(wxT("basics"));
00119 m_pLicensing = FindNode(wxT("licensing"));
00120 m_pDetails = FindNode(wxT("details"));
00121 m_pDep = FindNode(wxT("dependencies"));
00122 m_pBuildSystem = FindNode(wxT("build-system"));
00123 m_pPackaging = FindNode(wxT("packaging"));
00124
00125
00126 m_pId = FindNode(m_pBasics, wxT("id"));
00127 m_pDescription = FindNode(m_pBasics, wxT("description"));
00128 m_pCategory = FindNode(m_pBasics, wxT("category"));
00129 m_pKeywords = FindNode(m_pBasics, wxT("keywords"));
00130 m_pWebsite = FindNode(m_pBasics, wxT("website"));
00131 m_pCreationDate = FindNode(m_pBasics, wxT("creation-date"));
00132
00133
00134 m_pLicense = FindNode(m_pLicensing, wxT("license"));
00135 m_pOrganization = FindNode(m_pLicensing, wxT("organization"));
00136 m_pCost = FindNode(m_pLicensing, wxT("cost"));
00137 m_pCredits = FindNode(m_pLicensing, wxT("credits"));
00138 m_pCopyright = FindNode(m_pLicensing, wxT("copyright"));
00139 m_pAuthors = FindNode(m_pLicensing, wxT("authors"));
00140 m_pMaintainers = FindNode(m_pLicensing, wxT("maintainers"));
00141
00142
00143 m_pRoot = FindNode(m_pPackaging, wxT("root"));
00144 m_pFileName = FindNode(m_pPackaging, wxT("filename"));
00145 m_pContents = FindNode(m_pPackaging, wxT("contents"));
00146 m_pUpload = FindNode(m_pPackaging, wxT("upload"));
00147 m_pCompress = FindNode(m_pPackaging, wxT("compress"));
00148
00149
00150 m_pStatus = FindNode(m_pDetails, wxT("status"));
00151 m_pProgLanguage = FindNode(m_pDetails, wxT("proglanguage"));
00152 m_pSamples = FindNode(m_pDetails, wxT("samples"));
00153 m_pDownloads = FindNode(m_pDetails, wxT("download"));
00154 m_pLogo = FindNode(m_pDetails, wxT("logo"));
00155 m_pRSS = FindNode(m_pDetails, wxT("rss"));
00156 m_pScreenshots = FindNode(m_pDetails, wxT("screenshots"));
00157 m_pDocs = FindNode(m_pDetails, wxT("documentation"));
00158
00159
00160 m_pSupportedPorts = FindNode(m_pDep, wxT("supported-ports"));
00161 m_pTestedPorts = FindNode(m_pDep, wxT("tested-ports"));
00162 m_pDependencies[wxPDT_REQUIRED] =
00163 FindNode(m_pDep, wxT("dependency"), wxT("type"), wxT("required"));
00164 m_pDependencies[wxPDT_SUGGESTED] =
00165 FindNode(m_pDep, wxT("dependency"), wxT("type"), wxT("suggested"));
00166
00167
00168 m_pFormats = FindNode(m_pBuildSystem, wxT("formats"));
00169 m_pOptions = FindNode(m_pBuildSystem, wxT("options"));
00170 m_pStages = FindNode(m_pBuildSystem, wxT("stages"));
00171
00172 return *this;
00173 }
00174
00175 wxXmlNode *FindNode(const wxString &name,
00176 const wxString &propname = wxEmptyString,
00177 const wxString &propval = wxEmptyString) const
00178 {
00179 if (!GetRoot())
00180 return NULL;
00181
00182 return DoFindNode(GetRoot(), name, propname, propval);
00183 }
00184
00185 wxXmlNode *FindNode(wxXmlNode *node,
00186 const wxString &name,
00187 const wxString &propname = wxEmptyString,
00188 const wxString &propval = wxEmptyString) const
00189 {
00190 if (!node)
00191 return NULL;
00192
00193 return DoFindNode(node, name, propname, propval);
00194 }
00195
00196 protected:
00197
00198 wxString GetHrefProp(const wxXmlNode *p) const;
00199 wxString GetLocalRefProp(const wxXmlNode *p) const;
00200
00201 bool LoadBasics(const wxXmlNode *n, wxPackageInfo &);
00202 bool LoadPackaging(const wxXmlNode *n, wxPackageInfo &);
00203 bool LoadDetails(const wxXmlNode *n, wxPackageInfo &);
00204 bool LoadLicensing(const wxXmlNode *n, wxPackageInfo &);
00205 bool LoadDependencies(const wxXmlNode *n, wxPackageInfo &);
00206 bool LoadBuildSystem(const wxXmlNode *n, wxPackageInfo &);
00207
00208
00209 bool LoadStages(const wxXmlNode *n, wxPackageInfo &p);
00210
00211
00212 bool LoadWxportTags(const wxXmlNode *port, const wxVersionRange &str,
00213 wxArrayInt *ports, wxVersionRangeArray *ver);
00214
00215
00216
00217 bool LoadContentsTag(const wxXmlNode *tag,
00218 wxArrayString *dirs,
00219 wxArrayString *files,
00220 wxArrayString *patterns);
00221
00222
00223
00224
00225 wxXmlNode *DoFindNode(wxXmlNode *node, const wxString &name,
00226 const wxString &propname, const wxString &propval) const
00227 {
00228 if (node->GetName() == name)
00229 {
00230
00231 if (propname.IsEmpty() ||
00232 node->GetPropVal(propname, wxEmptyString) == propval)
00233 {
00234
00235 return node;
00236 }
00237 }
00238
00239 wxXmlNode *child = node->GetChildren();
00240 while (child)
00241 {
00242 wxXmlNode *ret = DoFindNode(child, name, propname, propval);
00243 if (ret)
00244 return ret;
00245
00246 child = child->GetNext();
00247 }
00248
00249
00250 return NULL;
00251 }
00252
00253 protected:
00254
00255
00256 typedef void (*FormatNodeFnc)(wxXmlNode *n, size_t i,
00257 const wxPackageInfo &userdata);
00258
00259 void ResetEnumeration(wxXmlNode *parent, int parentIndentLevel,
00260 const wxString &nodename, size_t max,
00261 FormatNodeFnc f, const wxPackageInfo &pkg,
00262 bool eraseChildren = true);
00263
00264 void CreateSiblingIfMissing(wxXmlNode *prev, wxXmlNode **node,
00265 const wxString &name);
00266
00267 void CreateChildIfMissing(wxXmlNode *parent, wxXmlNode *prev,
00268 wxXmlNode **node, const wxString &name,
00269 int level);
00270
00271 void CreateMissingNodes();
00272
00273
00274 void SetNodeContent(wxXmlNode *node, const wxString &text);
00275
00276
00277
00278 void SetRefProp(wxXmlNode *node, const wxPackageDataWithRef &ref);
00279
00280
00281
00282 void RemoveAllPropertiesFrom(wxXmlNode *node,
00283 const wxString &name = wxEmptyString);
00284
00285
00286
00287 void RemoveAllChildrenFrom(wxXmlNode *node,
00288 const wxString &name = wxEmptyString);
00289
00290 protected:
00291
00292
00293
00294
00295 wxXmlNode *m_pBasics, *m_pLicensing, *m_pDetails, *m_pDep, *m_pBuildSystem,
00296 *m_pPackaging;
00297
00298
00299 wxXmlNode *m_pId, *m_pDescription, *m_pCategory, *m_pKeywords, *m_pWebsite,
00300 *m_pCreationDate;
00301
00302
00303 wxXmlNode *m_pRoot, *m_pFileName, *m_pContents, *m_pUpload, *m_pCompress;
00304
00305
00306 wxXmlNode *m_pLicense, *m_pOrganization, *m_pCost, *m_pCredits, *m_pCopyright,
00307 *m_pAuthors, *m_pMaintainers;
00308
00309
00310 wxXmlNode *m_pStatus, *m_pProgLanguage, *m_pSamples, *m_pDownloads,
00311 *m_pLogo, *m_pRSS, *m_pScreenshots, *m_pDocs;
00312
00313
00314 wxXmlNode *m_pSupportedPorts, *m_pTestedPorts, *m_pDependencies[wxPDT_MAX];
00315
00316
00317 wxXmlNode *m_pFormats, *m_pOptions, *m_pStages;
00318
00319 private:
00320
00321
00322 wxPackageInfo m_info;
00323 };
00324
00325
00326
00327 #endif // _PACKAGE_WXP_H_
00328