Back to index

lightning-sunbird  0.9+nobinonly
XMLDocument.cpp
Go to the documentation of this file.
00001 // XMLDocument.cpp : Implementation of CXMLDocument
00002 #include "stdafx.h"
00003 //#include "Activexml.h"
00004 #include "XMLDocument.h"
00005 
00006 
00007 CXMLDocument::CXMLDocument()
00008 {
00009        ATLTRACE(_T("CXMLDocument::CXMLDocument()\n"));
00010        m_nReadyState = READYSTATE_COMPLETE;
00011 }
00012 
00013 
00014 CXMLDocument::~CXMLDocument()
00015 {
00016 }
00017 
00018 
00020 // CXMLDocument
00021 
00022 
00023 STDMETHODIMP CXMLDocument::InterfaceSupportsErrorInfo(REFIID riid)
00024 {
00025        static const IID* arr[] = 
00026        {
00027               &IID_IXMLDocument
00028        };
00029        for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
00030        {
00031               if (InlineIsEqualGUID(*arr[i],riid))
00032                      return S_OK;
00033        }
00034        return S_FALSE;
00035 }
00036 
00037 
00039 // IPersistStreamInit implementation
00040 
00041 
00042 HRESULT STDMETHODCALLTYPE CXMLDocument::Load(/* [in] */ LPSTREAM pStm)
00043 {
00044        if (pStm == NULL)
00045        {
00046               return E_INVALIDARG;
00047        }
00048 
00049        // Load the XML from the stream
00050        STATSTG statstg;
00051        pStm->Stat(&statstg, STATFLAG_NONAME);
00052 
00053        ULONG cbBufSize = statstg.cbSize.LowPart;
00054 
00055        char *pBuffer = new char[cbBufSize];
00056        if (pBuffer == NULL)
00057        {
00058               return E_OUTOFMEMORY;
00059        }
00060 
00061        memset(pBuffer, 0, cbBufSize);
00062        pStm->Read(pBuffer, cbBufSize, NULL);
00063 
00064        m_spRoot.Release();
00065        ParseExpat(pBuffer, cbBufSize, (IXMLDocument *) this, &m_spRoot);
00066 
00067        delete []pBuffer;
00068 
00069        m_nReadyState = READYSTATE_LOADED;
00070 
00071        return S_OK;
00072 }
00073 
00074 
00075 HRESULT STDMETHODCALLTYPE CXMLDocument::Save(/* [in] */ LPSTREAM pStm, /* [in] */ BOOL fClearDirty)
00076 {
00077        return E_NOTIMPL;
00078 }
00079 
00080 
00081 HRESULT STDMETHODCALLTYPE CXMLDocument::GetSizeMax(/* [out] */ ULARGE_INTEGER __RPC_FAR *pCbSize)
00082 {
00083        return E_NOTIMPL;
00084 }
00085 
00086 
00087 HRESULT STDMETHODCALLTYPE CXMLDocument::InitNew(void)
00088 {
00089        return S_OK;
00090 }
00091 
00092 
00094 // IPersistMoniker implementation
00095 
00096 
00097 HRESULT STDMETHODCALLTYPE CXMLDocument::GetClassID(/* [out] */ CLSID __RPC_FAR *pClassID)
00098 {
00099        if (pClassID == NULL)
00100        {
00101               return E_INVALIDARG;
00102        }
00103        *pClassID = CLSID_MozXMLDocument;
00104        return S_OK;
00105 }
00106 
00107 
00108 HRESULT STDMETHODCALLTYPE CXMLDocument::IsDirty(void)
00109 {
00110        return E_NOTIMPL;
00111 }
00112 
00113 
00114 HRESULT STDMETHODCALLTYPE CXMLDocument::Load(/* [in] */ BOOL fFullyAvailable, /* [in] */ IMoniker __RPC_FAR *pimkName, /* [in] */ LPBC pibc, /* [in] */ DWORD grfMode)
00115 {
00116        if (pimkName == NULL)
00117        {
00118               return E_INVALIDARG;
00119        }
00120 
00121        m_nReadyState = READYSTATE_LOADING;
00122 
00123        // Bind to the stream specified by the moniker
00124        CComQIPtr<IStream, &IID_IStream> spIStream;
00125        if (FAILED(pimkName->BindToStorage(pibc, NULL, IID_IStream, (void **) &spIStream)))
00126        {
00127               return E_FAIL;
00128        }
00129 
00130        return Load(spIStream);
00131 }
00132 
00133 
00134 HRESULT STDMETHODCALLTYPE CXMLDocument::Save(/* [in] */ IMoniker __RPC_FAR *pimkName, /* [in] */ LPBC pbc, /* [in] */ BOOL fRemember)
00135 {
00136        return E_NOTIMPL;
00137 }
00138 
00139 
00140 HRESULT STDMETHODCALLTYPE CXMLDocument::SaveCompleted(/* [in] */ IMoniker __RPC_FAR *pimkName, /* [in] */ LPBC pibc)
00141 {
00142        return E_NOTIMPL;
00143 }
00144 
00145 
00146 HRESULT STDMETHODCALLTYPE CXMLDocument::GetCurMoniker(/* [out] */ IMoniker __RPC_FAR *__RPC_FAR *ppimkName)
00147 {
00148        return E_NOTIMPL;
00149 }
00150 
00151 
00153 // IXMLError implementation
00154 
00155 HRESULT STDMETHODCALLTYPE CXMLDocument::GetErrorInfo(XML_ERROR __RPC_FAR *pErrorReturn)
00156 {
00157        return E_NOTIMPL;
00158 }
00159 
00161 // IXMLDocument implementation
00162 
00163 
00164 HRESULT STDMETHODCALLTYPE CXMLDocument::get_root(/* [out][retval] */ IXMLElement __RPC_FAR *__RPC_FAR *p)
00165 {
00166        if (p == NULL)
00167        {
00168               return E_INVALIDARG;
00169        }
00170        *p = NULL;
00171        if (m_spRoot)
00172        {
00173               m_spRoot->QueryInterface(IID_IXMLElement, (void **) p);
00174        }
00175        return S_OK;
00176 }
00177 
00178 
00179 HRESULT STDMETHODCALLTYPE CXMLDocument::get_fileSize(/* [out][retval] */ BSTR __RPC_FAR *p)
00180 {
00181        return E_NOTIMPL;
00182 }
00183 
00184 
00185 HRESULT STDMETHODCALLTYPE CXMLDocument::get_fileModifiedDate(/* [out][retval] */ BSTR __RPC_FAR *p)
00186 {
00187        return E_NOTIMPL;
00188 }
00189 
00190 
00191 HRESULT STDMETHODCALLTYPE CXMLDocument::get_fileUpdatedDate(/* [out][retval] */ BSTR __RPC_FAR *p)
00192 {
00193        return E_NOTIMPL;
00194 }
00195 
00196 
00197 HRESULT STDMETHODCALLTYPE CXMLDocument::get_URL(/* [out][retval] */ BSTR __RPC_FAR *p)
00198 {
00199        if (p == NULL)
00200        {
00201               return E_INVALIDARG;
00202        }
00203 
00204        USES_CONVERSION;
00205        *p = SysAllocString(A2OLE(m_szURL.c_str()));
00206        return S_OK;
00207 }
00208 
00209 
00210 HRESULT STDMETHODCALLTYPE CXMLDocument::put_URL(/* [in] */ BSTR p)
00211 {
00212        if (p == NULL)
00213        {
00214               return E_INVALIDARG;
00215        }
00216 
00217        USES_CONVERSION;
00218        m_szURL = OLE2A(p);
00219 
00220        // Destroy old document
00221        CComQIPtr<IMoniker, &IID_IMoniker> spIMoniker;
00222        if (FAILED(CreateURLMoniker(NULL, A2W(m_szURL.c_str()), &spIMoniker)))
00223        {
00224               return E_FAIL;
00225        }
00226 
00227        CComQIPtr<IBindCtx, &IID_IBindCtx> spIBindCtx;
00228        if (FAILED(CreateBindCtx(0, &spIBindCtx)))
00229        {
00230               return E_FAIL;
00231        }
00232 
00233        if (FAILED(Load(TRUE, spIMoniker, spIBindCtx, 0)))
00234        {
00235               return E_FAIL;
00236        }
00237 
00238        return S_OK;
00239 }
00240 
00241 
00242 HRESULT STDMETHODCALLTYPE CXMLDocument::get_mimeType(/* [out][retval] */ BSTR __RPC_FAR *p)
00243 {
00244        return E_NOTIMPL;
00245 }
00246 
00247 
00248 HRESULT STDMETHODCALLTYPE CXMLDocument::get_readyState(/* [out][retval] */ long __RPC_FAR *pl)
00249 {
00250        if (pl == NULL)
00251        {
00252               return E_INVALIDARG;
00253        }
00254        *pl = m_nReadyState;
00255        return S_OK;
00256 }
00257 
00258 
00259 HRESULT STDMETHODCALLTYPE CXMLDocument::get_charset(/* [out][retval] */ BSTR __RPC_FAR *p)
00260 {
00261        return E_NOTIMPL;
00262 }
00263 
00264 
00265 HRESULT STDMETHODCALLTYPE CXMLDocument::put_charset(/* [in] */ BSTR p)
00266 {
00267        return E_NOTIMPL;
00268 }
00269 
00270 
00271 HRESULT STDMETHODCALLTYPE CXMLDocument::get_version(/* [out][retval] */ BSTR __RPC_FAR *p)
00272 {
00273        return E_NOTIMPL;
00274 }
00275 
00276 
00277 HRESULT STDMETHODCALLTYPE CXMLDocument::get_doctype(/* [out][retval] */ BSTR __RPC_FAR *p)
00278 {
00279        return E_NOTIMPL;
00280 }
00281 
00282 
00283 HRESULT STDMETHODCALLTYPE CXMLDocument::get_dtdURL(/* [out][retval] */ BSTR __RPC_FAR *p)
00284 {
00285        return E_NOTIMPL;
00286 }
00287 
00288 
00289 HRESULT STDMETHODCALLTYPE CXMLDocument::createElement(/* [in] */ VARIANT vType, /* [in][optional] */ VARIANT var1, /* [out][retval] */ IXMLElement __RPC_FAR *__RPC_FAR *ppElem)
00290 {
00291        if (vType.vt != VT_I4)
00292        {
00293               return E_INVALIDARG;
00294        }
00295        if (ppElem == NULL)
00296        {
00297               return E_INVALIDARG;
00298        }
00299 
00300        CXMLElementInstance *pInstance = NULL;
00301        CXMLElementInstance::CreateInstance(&pInstance);
00302        if (pInstance == NULL)
00303        {
00304               return E_OUTOFMEMORY;
00305        }
00306 
00307        IXMLElement *pElement = NULL;
00308        if (FAILED(pInstance->QueryInterface(IID_IXMLElement, (void **) &pElement)))
00309        {
00310               pInstance->Release();
00311               return E_NOINTERFACE;
00312        }
00313 
00314        // Set the element type
00315        long nType = vType.intVal;
00316        pInstance->PutType(nType);
00317 
00318        // Set the tag name
00319        if (var1.vt == VT_BSTR)
00320        {
00321               pInstance->put_tagName(var1.bstrVal);
00322        }
00323        
00324        *ppElem = pElement;
00325        return S_OK;
00326 }
00327 
00328