Skip to content
Snippets Groups Projects
XMLDOMDocument.cpp 35.5 KiB
Newer Older
PeiYong Zhang's avatar
PeiYong Zhang committed
/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * $Id$
 */

#include "stdafx.h"

#include <xercesc/dom/deprecated/DOMParser.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed
#include <xercesc/sax/SAXParseException.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>

#include "xml4com.h"
#include "XMLDOMDocument.h"
#include "XMLDOMUtil.h"
#include "XMLDOMNodeList.h"
#include "XMLDOMNamedNodeMap.h"
#include "XMLDOMDocumentType.h"
#include "XMLDOMImplementation.h"
#include "XMLDOMElement.h"
#include "XMLDOMDocumentFragment.h"
#include "XMLDOMText.h"
#include "XMLDOMComment.h"
#include "XMLDOMCDATASection.h"
#include "XMLDOMProcessingInstruction.h"
#include "XMLDOMAttribute.h"
#include "XMLDOMEntityReference.h"
#include "BindStatusCallback.h"
#include <xercesc/dom/deprecated/DocumentImpl.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed

// I need to make sure the file is registered with long filenames
HRESULT WINAPI CXMLDOMDocument::UpdateRegistry(BOOL bRegister)
{
	USES_CONVERSION;

	TCHAR file[MAX_PATH];
	if (::GetModuleFileName(_Module.m_hInst, file, MAX_PATH)) {
		WIN32_FIND_DATA d;
		memset(&d,0,sizeof(WIN32_FIND_DATA));
		HANDLE h = FindFirstFile(file,&d);
		if (h != INVALID_HANDLE_VALUE) {
			TCHAR  *name = _tcsrchr(file,_T('\\'));
			TCHAR newFile[MAX_PATH] = _T("");
			_tcsncpy(newFile,file,name-file);
			_tcscat(newFile,_T("\\"));
			_tcscat(newFile,d.cFileName);
			FindClose(h);
			
			_ATL_REGMAP_ENTRY regmap[2] = {{NULL,NULL},{NULL,NULL}};
			regmap[0].szKey  = OLESTR("XMLMODULE");
			regmap[0].szData = T2OLE(newFile);
			return _Module.UpdateRegistryFromResource((UINT) IDR_XMLDOCUMENT, bRegister,regmap);
		}
	}
	return E_FAIL;
}

CXMLDOMDocument::CXMLDOMDocument()
	:m_Document					()
	,m_bValidate				(false)
	,m_lReadyState				(0)
	,m_url						(_T(""))
	,m_pParseError				(NULL)
	,m_bAsync					(false)
	,m_bAbort					(false)
	,m_hParseThread				(NULL)
	,m_pOnReadyStateChange		(NULL)
	,m_pOnDataAvailable			(NULL)
	,m_pOnTransformNode			(NULL)
	,m_FileName					(_T(""))
	,m_xml						(_T(""))
	,m_bParseError				(false)
	,m_bThreadValidate			(false)
	,m_bPreserveWhiteSpace      (false)
{
}

HRESULT CXMLDOMDocument::FinalConstruct()
{
	// create monitor window
	RECT rc;
    memset(&rc,0,sizeof(RECT));
	if (NULL == Create(NULL, rc, _T("XML Parse Monitor Window"), 0))
		return E_FAIL;

	HRESULT hr = CXMLDOMParseErrorObj::CreateInstance(&m_pParseError);
	if (S_OK != hr)
		return hr;
	
	m_pParseError->AddRef();
	m_pIXMLDOMDocument = this;

	m_Document = DOM_Document::createDocument();

	return hr;
}

void CXMLDOMDocument::FinalRelease()
{
	if (NULL != m_hParseThread) {
		m_bAbort = true;
		::WaitForSingleObject(m_hParseThread, INFINITE);
		::CloseHandle(m_hParseThread);
		m_hParseThread = NULL;
	}

	if (m_pParseError != NULL) {
		m_pParseError->Release();
		m_pParseError = NULL;
	}
	if (m_pOnReadyStateChange != NULL) {
		m_pOnReadyStateChange->Release();
		m_pOnReadyStateChange = NULL;
	}
	if (m_pOnDataAvailable != NULL) {
		m_pOnDataAvailable->Release();
		m_pOnDataAvailable = NULL;
	}
	if (m_pOnTransformNode != NULL) {
		m_pOnTransformNode->Release();
		m_pOnTransformNode = NULL;
	}

	DestroyWindow();
}

void CXMLDOMDocument::warning(const SAXParseException& exception)
{
	// ignore warnings
}

void CXMLDOMDocument::error(const SAXParseException& exception)
{
	m_pParseError->SetData(1,
						   exception.getSystemId(),
						   exception.getMessage(),
						   _T(""),
						   exception.getLineNumber(),
						   exception.getColumnNumber(),
						   0);
	m_bParseError = true;
}

void CXMLDOMDocument::fatalError(const SAXParseException& exception)
{
	m_pParseError->SetData(1,
Loading
Loading full blame...