|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsRDFXMLSerializer_h__ |
|
8 #define nsRDFXMLSerializer_h__ |
|
9 |
|
10 #include "nsIRDFLiteral.h" |
|
11 #include "nsIRDFXMLSerializer.h" |
|
12 #include "nsIRDFXMLSource.h" |
|
13 #include "nsNameSpaceMap.h" |
|
14 #include "nsXPIDLString.h" |
|
15 |
|
16 #include "nsDataHashtable.h" |
|
17 #include "rdfITripleVisitor.h" |
|
18 |
|
19 class nsString; |
|
20 class nsIOutputStream; |
|
21 class nsIRDFContainerUtils; |
|
22 |
|
23 /** |
|
24 * A helper class that can serialize RDF/XML from a |
|
25 * datasource. Implements both nsIRDFXMLSerializer and |
|
26 * nsIRDFXMLSource. |
|
27 */ |
|
28 class nsRDFXMLSerializer : public nsIRDFXMLSerializer, |
|
29 public nsIRDFXMLSource |
|
30 { |
|
31 public: |
|
32 static nsresult |
|
33 Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); |
|
34 |
|
35 NS_DECL_ISUPPORTS |
|
36 NS_DECL_NSIRDFXMLSERIALIZER |
|
37 NS_DECL_NSIRDFXMLSOURCE |
|
38 |
|
39 protected: |
|
40 nsRDFXMLSerializer(); |
|
41 virtual ~nsRDFXMLSerializer(); |
|
42 |
|
43 // Implementation methods |
|
44 nsresult |
|
45 RegisterQName(nsIRDFResource* aResource); |
|
46 nsresult |
|
47 GetQName(nsIRDFResource* aResource, nsCString& aQName); |
|
48 already_AddRefed<nsIAtom> |
|
49 EnsureNewPrefix(); |
|
50 |
|
51 nsresult |
|
52 SerializeInlineAssertion(nsIOutputStream* aStream, |
|
53 nsIRDFResource* aResource, |
|
54 nsIRDFResource* aProperty, |
|
55 nsIRDFLiteral* aValue); |
|
56 |
|
57 nsresult |
|
58 SerializeChildAssertion(nsIOutputStream* aStream, |
|
59 nsIRDFResource* aResource, |
|
60 nsIRDFResource* aProperty, |
|
61 nsIRDFNode* aValue); |
|
62 |
|
63 nsresult |
|
64 SerializeProperty(nsIOutputStream* aStream, |
|
65 nsIRDFResource* aResource, |
|
66 nsIRDFResource* aProperty, |
|
67 bool aInline, |
|
68 int32_t* aSkipped); |
|
69 |
|
70 bool |
|
71 IsContainerProperty(nsIRDFResource* aProperty); |
|
72 |
|
73 nsresult |
|
74 SerializeDescription(nsIOutputStream* aStream, |
|
75 nsIRDFResource* aResource); |
|
76 |
|
77 nsresult |
|
78 SerializeMember(nsIOutputStream* aStream, |
|
79 nsIRDFResource* aContainer, |
|
80 nsIRDFNode* aMember); |
|
81 |
|
82 nsresult |
|
83 SerializeContainer(nsIOutputStream* aStream, |
|
84 nsIRDFResource* aContainer); |
|
85 |
|
86 nsresult |
|
87 SerializePrologue(nsIOutputStream* aStream); |
|
88 |
|
89 nsresult |
|
90 SerializeEpilogue(nsIOutputStream* aStream); |
|
91 |
|
92 nsresult |
|
93 CollectNamespaces(); |
|
94 |
|
95 bool |
|
96 IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType); |
|
97 |
|
98 nsCOMPtr<nsIRDFDataSource> mDataSource; |
|
99 nsNameSpaceMap mNameSpaces; |
|
100 nsXPIDLCString mBaseURLSpec; |
|
101 |
|
102 // hash mapping resources to utf8-encoded QNames |
|
103 nsDataHashtable<nsISupportsHashKey, nsCString> mQNames; |
|
104 friend class QNameCollector; |
|
105 |
|
106 uint32_t mPrefixID; |
|
107 |
|
108 static int32_t gRefCnt; |
|
109 static nsIRDFResource* kRDF_instanceOf; |
|
110 static nsIRDFResource* kRDF_type; |
|
111 static nsIRDFResource* kRDF_nextVal; |
|
112 static nsIRDFResource* kRDF_Bag; |
|
113 static nsIRDFResource* kRDF_Seq; |
|
114 static nsIRDFResource* kRDF_Alt; |
|
115 static nsIRDFContainerUtils* gRDFC; |
|
116 }; |
|
117 |
|
118 #endif // nsRDFXMLSerializer_h__ |