Back to index

lightning-sunbird  0.9+nobinonly
nsRDFXMLSerializer.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Chris Waterson <waterson@netscape.com>
00025  *   Axel Hecht <axel@pike.org>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef nsRDFXMLSerializer_h__
00042 #define nsRDFXMLSerializer_h__
00043 
00044 #include "nsIRDFLiteral.h"
00045 #include "nsIRDFXMLSerializer.h"
00046 #include "nsIRDFXMLSource.h"
00047 #include "nsNameSpaceMap.h"
00048 #include "nsXPIDLString.h"
00049 
00050 #include "nsDataHashtable.h"
00051 #include "rdfITripleVisitor.h"
00052 
00053 class nsString;
00054 class nsIOutputStream;
00055 class nsIRDFContainerUtils;
00056 
00062 class nsRDFXMLSerializer : public nsIRDFXMLSerializer,
00063                            public nsIRDFXMLSource
00064 {
00065 public:
00066     static NS_IMETHODIMP
00067     Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
00068 
00069     NS_DECL_ISUPPORTS
00070     NS_DECL_NSIRDFXMLSERIALIZER
00071     NS_DECL_NSIRDFXMLSOURCE
00072 
00073 protected:
00074     nsRDFXMLSerializer();
00075     virtual ~nsRDFXMLSerializer();
00076 
00077     // Implementation methods
00078     nsresult
00079     RegisterQName(nsIRDFResource* aResource);
00080     nsresult
00081     GetQName(nsIRDFResource* aResource, nsCString& aQName);
00082     already_AddRefed<nsIAtom>
00083     EnsureNewPrefix();
00084 
00085     nsresult
00086     SerializeInlineAssertion(nsIOutputStream* aStream,
00087                              nsIRDFResource* aResource,
00088                              nsIRDFResource* aProperty,
00089                              nsIRDFLiteral* aValue);
00090 
00091     nsresult
00092     SerializeChildAssertion(nsIOutputStream* aStream,
00093                             nsIRDFResource* aResource,
00094                             nsIRDFResource* aProperty,
00095                             nsIRDFNode* aValue);
00096 
00097     nsresult
00098     SerializeProperty(nsIOutputStream* aStream,
00099                       nsIRDFResource* aResource,
00100                       nsIRDFResource* aProperty,
00101                       PRBool aInline,
00102                       PRInt32* aSkipped);
00103 
00104     PRBool
00105     IsContainerProperty(nsIRDFResource* aProperty);
00106 
00107     nsresult
00108     SerializeDescription(nsIOutputStream* aStream,
00109                          nsIRDFResource* aResource);
00110 
00111     nsresult
00112     SerializeMember(nsIOutputStream* aStream,
00113                     nsIRDFResource* aContainer,
00114                     nsIRDFNode* aMember);
00115 
00116     nsresult
00117     SerializeContainer(nsIOutputStream* aStream,
00118                        nsIRDFResource* aContainer);
00119 
00120     nsresult
00121     SerializePrologue(nsIOutputStream* aStream);
00122 
00123     nsresult
00124     SerializeEpilogue(nsIOutputStream* aStream);
00125 
00126     nsresult
00127     CollectNamespaces();
00128 
00129     PRBool
00130     IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType);
00131 
00132     nsCOMPtr<nsIRDFDataSource> mDataSource;
00133     nsNameSpaceMap mNameSpaces;
00134     nsXPIDLCString mBaseURLSpec;
00135 
00136     // hash mapping resources to utf8-encoded QNames
00137     nsDataHashtable<nsISupportsHashKey, nsCString> mQNames;
00138     friend class QNameCollector;
00139 
00140     PRUint32 mPrefixID;
00141 
00142     static PRInt32 gRefCnt;
00143     static nsIRDFResource* kRDF_instanceOf;
00144     static nsIRDFResource* kRDF_type;
00145     static nsIRDFResource* kRDF_nextVal;
00146     static nsIRDFResource* kRDF_Bag;
00147     static nsIRDFResource* kRDF_Seq;
00148     static nsIRDFResource* kRDF_Alt;
00149     static nsIRDFContainerUtils* gRDFC;
00150 };
00151 
00152 #endif // nsRDFXMLSerializer_h__