sbiTunesXMLParser.h
Go to the documentation of this file.
1 /*
2  //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 #ifndef SBITUNESXMLPARSER_H_
27 #define SBITUNESXMLPARSER_H_
28 
29 #include <nsTArray.h>
30 #include <nsCOMPtr.h>
31 #include <nsISAXContentHandler.h>
32 #include <nsISAXErrorHandler.h>
33 #include <nsISAXXMLReader.h>
34 #include <nsStringAPI.h>
35 #include <sbIStringMap.h>
36 
37 #include <sbIiTunesXMLParser.h>
38 
39 class nsIInputStream;
40 class nsIInputStreamPump;
41 
42 typedef nsCOMPtr<nsISAXXMLReader> nsISAXXMLReaderPtr;
43 
44 #define SBITUNESXMLPARSER_CONTRACTID \
45  "@songbirdnest.com/Songbird/sbiTunesXMLParser;1"
46 #define SBITUNESXMLPARSER_CLASSNAME \
47  "Songbird iTunes XML Parser Interface"
48 // {F0EBF580-C5FB-4efc-960A-50BEF0BCEDCC}
49 #define SBITUNESXMLPARSER_CID \
50 { 0xf0ebf580, 0xc5fb, 0x4efc, { 0x96, 0xa, 0x50, 0xbe, 0xf0, 0xbc, 0xed, 0xcc } }
51 
59  public nsISAXContentHandler,
60  public nsISAXErrorHandler
61 {
62 public:
64  NS_DECL_SBIITUNESXMLPARSER
65  NS_DECL_NSISAXCONTENTHANDLER
66  NS_DECL_NSISAXERRORHANDLER
67 
68  // For use when directly allocating a parser
69  static sbiTunesXMLParser * New();
74 
75 protected:
80 private:
87  enum State
88  {
89  START, // Initial state
90  TOP_LEVEL_PROPERTIES, // Base top level properties state <dict>
91 
92  TRACKS, // Found the Tracks section
93  TRACKS_COLLECTION, // In the tracks collection <dict>
94  TRACK, // Base track state <dict>
95 
96  PLAYLISTS, // Playlists section
97  PLAYLISTS_COLLECTION, // Playlists collection <array>
98  PLAYLIST, // Base playlist state <dict>
99  PLAYLIST_ITEMS, // Playlist items collection <array>
100  PLAYLIST_ITEM, // Base playlist item state <dict>
101  DONE // We're done, ignore the rest
102  };
103 
104  // Typedefs
105  typedef nsCOMPtr<sbIMutableStringMap> sbIMutableStringMapPtr;
106  typedef nsCOMPtr<sbIiTunesXMLParserListener> sbIiTunesXMLParserListenerPtr;
107  typedef nsTArray<PRInt32> Tracks;
108  typedef nsCOMPtr<nsIInputStream> nsIInputStreamPtr;
109 
113  nsISAXXMLReaderPtr const & GetSAXReader();
117  nsresult InitializeProperties();
118 
122  nsresult ClearProperties();
123 
124  PRInt32 mState;
125  sbIMutableStringMapPtr mProperties;
126  nsCOMPtr<nsIInputStreamPump> mPump;
127  nsISAXXMLReaderPtr mSAXReader;
128  nsString mPropertyName;
129  nsString mCharacters;
130  sbIiTunesXMLParserListenerPtr mListener;
131  Tracks mTracks;
132  PRInt64 mBytesRead;
133 };
134 
135 #endif /* SBITUNESXMLPARSER_H_ */
nsCOMPtr< nsISAXXMLReader > nsISAXXMLReaderPtr
NS_DECL_ISUPPORTS NS_DECL_SBIITUNESXMLPARSER NS_DECL_NSISAXCONTENTHANDLER static NS_DECL_NSISAXERRORHANDLER sbiTunesXMLParser * New()