Back to index

lightning-sunbird  0.9+nobinonly
TransactionFactory.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Daniel Glazman <glazman@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "TransactionFactory.h"
00040 // transactions this factory knows how to build
00041 #include "EditAggregateTxn.h"
00042 #include "PlaceholderTxn.h"
00043 #include "InsertTextTxn.h"
00044 #include "DeleteTextTxn.h"
00045 #include "CreateElementTxn.h"
00046 #include "InsertElementTxn.h"
00047 #include "DeleteElementTxn.h"
00048 #include "DeleteRangeTxn.h"
00049 #include "ChangeAttributeTxn.h"
00050 #include "SplitElementTxn.h"
00051 #include "JoinElementTxn.h"
00052 #include "nsStyleSheetTxns.h"
00053 #include "IMETextTxn.h"
00054 
00055 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
00056 #include "SetDocTitleTxn.h"
00057 #include "ChangeCSSInlineStyleTxn.h"
00058 #endif // MOZILLA_PLAINTEXT_EDITOR_ONLY
00059 
00060 TransactionFactory::TransactionFactory()
00061 {
00062 }
00063 
00064 TransactionFactory::~TransactionFactory()
00065 {
00066 }
00067 
00068 nsresult
00069 TransactionFactory::GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult)
00070 {
00071   nsresult result = NS_OK;
00072   *aResult = nsnull;
00073   if (aTxnType.Equals(InsertTextTxn::GetCID()))
00074     *aResult = new InsertTextTxn();
00075   else if (aTxnType.Equals(DeleteTextTxn::GetCID()))
00076     *aResult = new DeleteTextTxn();
00077   else if (aTxnType.Equals(CreateElementTxn::GetCID()))
00078     *aResult = new CreateElementTxn();
00079   else if (aTxnType.Equals(InsertElementTxn::GetCID()))
00080     *aResult = new InsertElementTxn();
00081   else if (aTxnType.Equals(DeleteElementTxn::GetCID()))
00082     *aResult = new DeleteElementTxn();
00083   else if (aTxnType.Equals(DeleteRangeTxn::GetCID()))
00084     *aResult = new DeleteRangeTxn();
00085   else if (aTxnType.Equals(ChangeAttributeTxn::GetCID()))
00086     *aResult = new ChangeAttributeTxn();
00087 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
00088   else if (aTxnType.Equals(ChangeCSSInlineStyleTxn::GetCID()))
00089     *aResult = new ChangeCSSInlineStyleTxn();
00090 #endif // MOZILLA_PLAINTEXT_EDITOR_ONLY
00091   else if (aTxnType.Equals(SplitElementTxn::GetCID()))
00092     *aResult = new SplitElementTxn();
00093   else if (aTxnType.Equals(JoinElementTxn::GetCID()))
00094     *aResult = new JoinElementTxn();
00095   else if (aTxnType.Equals(EditAggregateTxn::GetCID()))
00096     *aResult = new EditAggregateTxn();
00097   else if (aTxnType.Equals(IMETextTxn::GetCID()))
00098     *aResult = new IMETextTxn();
00099   else if (aTxnType.Equals(AddStyleSheetTxn::GetCID()))
00100     *aResult = new AddStyleSheetTxn();
00101   else if (aTxnType.Equals(RemoveStyleSheetTxn::GetCID()))
00102     *aResult = new RemoveStyleSheetTxn();
00103 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
00104   else if (aTxnType.Equals(SetDocTitleTxn::GetCID()))
00105     *aResult = new SetDocTitleTxn();
00106 #endif // MOZILLA_PLAINTEXT_EDITOR_ONLY
00107   else if (aTxnType.Equals(PlaceholderTxn::GetCID()))
00108     *aResult = new PlaceholderTxn();
00109   else
00110     result = NS_ERROR_NO_INTERFACE;
00111   
00112   if (NS_SUCCEEDED(result) && !*aResult)
00113     result = NS_ERROR_OUT_OF_MEMORY;
00114 
00115   if (NS_SUCCEEDED(result))
00116     NS_ADDREF(*aResult);
00117 
00118   return result;
00119 }
00120