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 
22 
23 #include <stdio.h>
24 
25 #include "Identifier.h"
26 
27 #include "XMLWriter.h"
28 class AUDACITY_DLL_API XMLValueChecker
29 {
30 public:
31  // "Good" means well-formed and for the file-related functions, names an existing file or folder.
32  // These are used in HandleXMLTag and BuildFomXML methods to check the input for
33  // security vulnerabilities, per the NGS report for UmixIt.
34  static bool IsGoodString(const wxString & str);
35  // Labels are allowed to be very long. At some future date we will format long labels nicely.
36  static bool IsGoodLongString(const wxString & str);
37 
38  static bool IsGoodFileName(const FilePath & strFileName, const FilePath & strDirName = {});
39  static bool IsGoodFileString(const FilePath &str);
40  static bool IsGoodSubdirName(const FilePath & strSubdirName, const FilePath & strDirName = {});
41  static bool IsGoodPathName(const FilePath & strPathName);
42  static bool IsGoodPathString(const FilePath &str);
43 
53  static bool IsGoodInt(const wxString & strInt);
63  static bool IsGoodInt64(const wxString & strInt);
64  static bool IsGoodIntForRange(const wxString & strInt, const wxString & strMAXABS);
65 
67  {
68  LeftChannel = 0,
69  RightChannel = 1,
70  MonoChannel = 2
71  };
72  static bool IsValidChannel(const int nValue);
73 #ifdef USE_MIDI
74  static bool IsValidVisibleChannels(const int nValue);
75 #endif
76  static bool IsValidSampleFormat(const int nValue); // true if nValue is one sampleFormat enum values
77 };
78 
79 
80 class AUDACITY_DLL_API XMLTagHandler /* not final */ {
81  public:
83  virtual ~XMLTagHandler(){};
84  //
85  // Methods to override
86  //
87 
88  // This method will be called on your class if your class has
89  // been registered to handle this particular tag. Parse the
90  // tag and the attribute-value pairs (null-terminated), and
91  // return true on success, and false on failure. If you return
92  // false, you will not get any calls about children.
93  virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) = 0;
94 
95  // This method will be called when a closing tag is encountered.
96  // It is optional to override this method.
97  virtual void HandleXMLEndTag(const wxChar * WXUNUSED(tag)) {}
98 
99  // This method will be called when element content has been
100  // encountered.
101  // It is optional to override this method.
102  virtual void HandleXMLContent(const wxString & WXUNUSED(content)) {}
103 
104  // If the XML document has children of your tag, this method
105  // should be called. Typically you should construct a NEW
106  // object for the child, insert it into your own local data
107  // structures, and then return it. If you do not wish to
108  // handle this child, return NULL and it will be ignored.
109  virtual XMLTagHandler *HandleXMLChild(const wxChar *tag) = 0;
110 
111  // These functions receive data from expat. They do charset
112  // conversion and then pass the data to the handlers above.
113  bool ReadXMLTag(const char *tag, const char **attrs);
114  void ReadXMLEndTag(const char *tag);
115  void ReadXMLContent(const char *s, int len);
116  XMLTagHandler *ReadXMLChild(const char *tag);
117 };
118 
119 #endif // define __AUDACITY_XML_TAG_HANDLER__
120 
FilePath
wxString FilePath
Definition: Identifier.h:227
XMLWriter.h
XMLTagHandler::HandleXMLEndTag
virtual void HandleXMLEndTag(const wxChar *WXUNUSED(tag))
Definition: XMLTagHandler.h:97
XMLTagHandler::XMLTagHandler
XMLTagHandler()
Definition: XMLTagHandler.h:82
XMLTagHandler::HandleXMLContent
virtual void HandleXMLContent(const wxString &WXUNUSED(content))
Definition: XMLTagHandler.h:102
Identifier.h
XMLTagHandler
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:80
XMLTagHandler::~XMLTagHandler
virtual ~XMLTagHandler()
Definition: XMLTagHandler.h:83
XMLValueChecker::ChannelType
ChannelType
Definition: XMLTagHandler.h:67
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:29