Audacity  3.0.3
XMLTagHandler.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  XMLTagHandler.h
6 
7  Dominic Mazzoni
8  Vaughan Johnson
9 
10  The XMLTagHandler class is an interface which should be implemented by
11  classes which wish to be able to load and save themselves
12  using XML files.
13 
14  The XMLValueChecker class implements static bool methods for checking
15  input values from XML files.
16 
17 **********************************************************************/
18 #ifndef __AUDACITY_XML_TAG_HANDLER__
19 #define __AUDACITY_XML_TAG_HANDLER__
20 
21 #include "XMLWriter.h"
22 class XML_API XMLValueChecker
23 {
24 public:
25  // "Good" means well-formed and for the file-related functions, names an existing file or folder.
26  // These are used in HandleXMLTag and BuildFomXML methods to check the input for
27  // security vulnerabilities, per the NGS report for UmixIt.
28  static bool IsGoodString(const wxString & str);
29  // Labels are allowed to be very long. At some future date we will format long labels nicely.
30  static bool IsGoodLongString(const wxString & str);
31 
32  static bool IsGoodFileName(const FilePath & strFileName, const FilePath & strDirName = {});
33  static bool IsGoodFileString(const FilePath &str);
34  static bool IsGoodSubdirName(const FilePath & strSubdirName, const FilePath & strDirName = {});
35  static bool IsGoodPathName(const FilePath & strPathName);
36  static bool IsGoodPathString(const FilePath &str);
37 
47  static bool IsGoodInt(const wxString & strInt);
57  static bool IsGoodInt64(const wxString & strInt);
58  static bool IsGoodIntForRange(const wxString & strInt, const wxString & strMAXABS);
59 };
60 
61 
62 class XML_API XMLTagHandler /* not final */ {
63  public:
65  virtual ~XMLTagHandler(){};
66  //
67  // Methods to override
68  //
69 
70  // This method will be called on your class if your class has
71  // been registered to handle this particular tag. Parse the
72  // tag and the attribute-value pairs (null-terminated), and
73  // return true on success, and false on failure. If you return
74  // false, you will not get any calls about children.
75  virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) = 0;
76 
77  // This method will be called when a closing tag is encountered.
78  // It is optional to override this method.
79  virtual void HandleXMLEndTag(const wxChar * WXUNUSED(tag)) {}
80 
81  // This method will be called when element content has been
82  // encountered.
83  // It is optional to override this method.
84  virtual void HandleXMLContent(const wxString & WXUNUSED(content)) {}
85 
86  // If the XML document has children of your tag, this method
87  // should be called. Typically you should construct a NEW
88  // object for the child, insert it into your own local data
89  // structures, and then return it. If you do not wish to
90  // handle this child, return NULL and it will be ignored.
91  virtual XMLTagHandler *HandleXMLChild(const wxChar *tag) = 0;
92 
93  // These functions receive data from expat. They do charset
94  // conversion and then pass the data to the handlers above.
95  bool ReadXMLTag(const char *tag, const char **attrs);
96  void ReadXMLEndTag(const char *tag);
97  void ReadXMLContent(const char *s, int len);
98  XMLTagHandler *ReadXMLChild(const char *tag);
99 };
100 
101 #endif // define __AUDACITY_XML_TAG_HANDLER__
102 
XMLWriter.h
XMLTagHandler::HandleXMLEndTag
virtual void HandleXMLEndTag(const wxChar *WXUNUSED(tag))
Definition: XMLTagHandler.h:79
XMLTagHandler::XMLTagHandler
XMLTagHandler()
Definition: XMLTagHandler.h:64
FilePath
wxString FilePath
Definition: Project.h:20
XMLTagHandler::HandleXMLContent
virtual void HandleXMLContent(const wxString &WXUNUSED(content))
Definition: XMLTagHandler.h:84
XMLTagHandler
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:62
XMLTagHandler::~XMLTagHandler
virtual ~XMLTagHandler()
Definition: XMLTagHandler.h:65
XMLTagHandler::HandleXMLTag
virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs)=0
XMLTagHandler::HandleXMLChild
virtual XMLTagHandler * HandleXMLChild(const wxChar *tag)=0
XMLValueChecker
XMLValueChecker implements static bool methods for checking input values from XML files.
Definition: XMLTagHandler.h:23