transport: simulate convertion dbxml to xml
[abstract.git] / transport / sqlite / src / aaDBXMLtoXMLConverter.cpp
blob4c7a2a588e05516b5ca666d333b7519a7125b1e1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2010 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "aaDBXMLtoXMLConverter.h"
24 #include "nsIChannel.h"
25 #include "nsILoadGroup.h"
27 #include "nsStringAPI.h"
28 #include "nsMimeTypes.h"
30 NS_IMPL_ISUPPORTS3(aaDBXMLtoXMLConverter,
31 nsIStreamConverter,
32 nsIStreamListener,
33 nsIRequestObserver)
35 aaDBXMLtoXMLConverter::aaDBXMLtoXMLConverter()
36 : mListener(nsnull)
40 aaDBXMLtoXMLConverter::~aaDBXMLtoXMLConverter()
44 NS_IMETHODIMP
45 aaDBXMLtoXMLConverter::Convert(nsIInputStream *aFromStream,
46 const char *aFromType, const char *aToType, nsISupports *aCtxt,
47 nsIInputStream **_retval)
49 return NS_ERROR_NOT_IMPLEMENTED;
52 NS_IMETHODIMP
53 aaDBXMLtoXMLConverter::AsyncConvertData(const char *aFromType,
54 const char *aToType, nsIStreamListener *aListener, nsISupports *ctxt)
56 NS_ENSURE_ARG_POINTER(aListener);
57 mListener = aListener;
58 return NS_OK;
61 // nsIStreamListener method
62 /* This method handles asyncronous conversion of data. */
63 NS_IMETHODIMP
64 aaDBXMLtoXMLConverter::OnDataAvailable(nsIRequest* request, nsISupports *aContext,
65 nsIInputStream *aInStream, PRUint32 aSourceOffset, PRUint32 aCount)
67 NS_ENSURE_STATE(mListener);
68 return mListener->OnDataAvailable(request, aContext, aInStream,
69 aSourceOffset, aCount);
72 // nsIRequestObserver methods
73 /* These methods just pass through directly to the mListener */
74 NS_IMETHODIMP
75 aaDBXMLtoXMLConverter::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
77 nsresult rv = NS_OK;
78 NS_ENSURE_STATE(mListener);
80 nsCOMPtr<nsIChannel> channel =
81 do_QueryInterface(request, &rv);
82 NS_ENSURE_SUCCESS(rv, rv);
84 rv = channel->SetContentType(NS_LITERAL_CSTRING(TEXT_XML));
85 NS_ENSURE_SUCCESS(rv, rv);
87 return mListener->OnStartRequest(request, ctxt);
90 NS_IMETHODIMP
91 aaDBXMLtoXMLConverter::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
92 nsresult aStatus)
94 NS_ENSURE_STATE(mListener);
95 return mListener->OnStopRequest(request, ctxt, aStatus);