2002-05-16 05:00:29 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* $RCSfile: basicparser.cxx,v $
|
|
|
|
* $Revision: 1.11 $
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
2008-04-11 08:00:32 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2002-05-16 05:00:29 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 09:33:21 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_configmgr.hxx"
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
#include "basicparser.hxx"
|
|
|
|
#include <com/sun/star/xml/sax/SAXException.hpp>
|
2002-05-28 09:44:53 -05:00
|
|
|
#include "valuetypeconverter.hxx"
|
2002-05-16 05:00:29 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
namespace xml
|
|
|
|
{
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
namespace uno = ::com::sun::star::uno;
|
|
|
|
namespace sax = ::com::sun::star::xml::sax;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
typedef uno::Reference< script::XTypeConverter > TypeConverter;
|
|
|
|
|
|
|
|
static inline
|
2006-06-19 17:35:23 -05:00
|
|
|
TypeConverter createTCV(BasicParser::Context const & _xContext)
|
2002-05-16 05:00:29 -05:00
|
|
|
{
|
2004-08-31 08:58:23 -05:00
|
|
|
OSL_ENSURE(_xContext.is(),"Cannot create Parser without a Context");
|
2002-05-16 05:00:29 -05:00
|
|
|
|
|
|
|
static const rtl::OUString k_sTCVService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter"));
|
|
|
|
|
2004-08-31 08:58:23 -05:00
|
|
|
uno::Reference< lang::XMultiComponentFactory > xSvcFactory = _xContext->getServiceManager();
|
|
|
|
return TypeConverter::query(xSvcFactory->createInstanceWithContext(k_sTCVService,_xContext));
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct BasicParser::ValueData : ValueConverter
|
|
|
|
{
|
|
|
|
OUString content;
|
|
|
|
OUString locale;
|
|
|
|
bool isLocalized;
|
|
|
|
|
|
|
|
ValueData(uno::Type const& _aType, TypeConverter const & _xTCV)
|
|
|
|
: ValueConverter(_aType, _xTCV)
|
|
|
|
, content()
|
|
|
|
, locale()
|
|
|
|
, isLocalized(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Any convertToAny() const
|
|
|
|
{
|
|
|
|
return ValueConverter::convertToAny(this->content);
|
|
|
|
}
|
|
|
|
|
2002-05-28 09:44:53 -05:00
|
|
|
OUString toString() const
|
|
|
|
{
|
|
|
|
return this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence<OUString> toStringList() const
|
|
|
|
{
|
|
|
|
return ValueConverter::splitStringList(this->content);
|
|
|
|
}
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
void setLocalized(OUString const & _aLocale)
|
|
|
|
{
|
|
|
|
isLocalized = true;
|
|
|
|
locale = _aLocale;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2004-08-31 08:58:23 -05:00
|
|
|
BasicParser::BasicParser(Context const & _xContext)
|
|
|
|
: m_xTypeConverter( createTCV(_xContext) )
|
2002-05-16 05:00:29 -05:00
|
|
|
, m_xLocator(NULL)
|
2004-08-31 08:58:23 -05:00
|
|
|
, m_aDataParser(Logger(_xContext))
|
2002-05-16 05:00:29 -05:00
|
|
|
, m_aNodes()
|
|
|
|
, m_aValueType()
|
|
|
|
, m_pValueData(NULL)
|
|
|
|
, m_nSkipLevels(0)
|
2002-05-28 09:44:53 -05:00
|
|
|
, m_bEmpty(true)
|
|
|
|
, m_bInProperty(false)
|
2002-05-16 05:00:29 -05:00
|
|
|
{
|
|
|
|
if (!m_xTypeConverter.is())
|
|
|
|
throw uno::RuntimeException();
|
2002-07-03 08:07:28 -05:00
|
|
|
|
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BasicParser::~BasicParser()
|
|
|
|
{
|
|
|
|
delete m_pValueData;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2003-04-15 11:19:20 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2002-07-03 08:07:28 -05:00
|
|
|
void BasicParser::dbgUpdateLocation()
|
|
|
|
{
|
|
|
|
#ifndef DBG_UTIL
|
|
|
|
OUString dbgPublicId, dbgSystemId;
|
|
|
|
sal_Int32 dbgLineNo, dbgColumnNo;
|
2003-04-15 11:19:20 -05:00
|
|
|
#endif // OSL_DEBUG_LEVEL
|
2002-07-03 08:07:28 -05:00
|
|
|
|
|
|
|
if (m_xLocator.is())
|
|
|
|
{
|
|
|
|
dbgPublicId = m_xLocator->getPublicId();
|
|
|
|
dbgSystemId = m_xLocator->getSystemId();
|
|
|
|
dbgLineNo = m_xLocator->getLineNumber();
|
|
|
|
dbgColumnNo = m_xLocator->getColumnNumber();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dbgPublicId = dbgSystemId = OUString::createFromAscii("<<<unknown>>>");
|
|
|
|
dbgLineNo = dbgColumnNo = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-05-16 05:00:29 -05:00
|
|
|
void SAL_CALL BasicParser::startDocument( )
|
|
|
|
throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
|
|
|
m_aDataParser.reset();
|
|
|
|
m_aValueType = uno::Type();
|
2002-05-28 09:44:53 -05:00
|
|
|
m_bInProperty = false;
|
2002-05-16 05:00:29 -05:00
|
|
|
m_nSkipLevels = 0;
|
|
|
|
|
|
|
|
delete m_pValueData, m_pValueData = NULL;
|
|
|
|
|
|
|
|
while (!m_aNodes.empty()) m_aNodes.pop();
|
|
|
|
|
|
|
|
m_bEmpty = true;
|
2002-07-03 08:07:28 -05:00
|
|
|
|
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL BasicParser::endDocument( ) throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (!m_aNodes.empty() || isSkipping() || isInValueData())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid XML: Unexpected end of document" );
|
|
|
|
|
|
|
|
m_xLocator.clear();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL BasicParser::characters( const OUString& aChars )
|
|
|
|
throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (isInValueData())
|
|
|
|
{
|
|
|
|
m_pValueData->content += aChars;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_XMLPARSER_VALIDATE_WHITESPACE
|
|
|
|
else
|
|
|
|
OSL_ENSURE( isSkipping() || aChars.trim().getLength() == 0, "Unexpected text content in configuration XML");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL BasicParser::ignorableWhitespace( const OUString& aWhitespaces )
|
|
|
|
throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
2002-05-16 05:00:29 -05:00
|
|
|
if (isInValueData())
|
|
|
|
{
|
|
|
|
OSL_ENSURE(false, "Configuration XML: Unexpected ignorable (!) whitespace instruction in value data");
|
|
|
|
if (!m_pValueData->isNull())
|
|
|
|
m_pValueData->content += aWhitespaces;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_XMLPARSER_VALIDATE_WHITESPACE
|
|
|
|
else
|
|
|
|
OSL_ENSURE( aChars.trim().getLength() == 0, "Unexpected non-space content in ignorable whitespace");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2006-06-19 17:35:23 -05:00
|
|
|
void SAL_CALL BasicParser::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
|
2002-05-16 05:00:29 -05:00
|
|
|
throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ENSURE(false, "Unexpected processing instruction in Configuration XML");
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL BasicParser::setDocumentLocator( const uno::Reference< sax::XLocator >& xLocator )
|
|
|
|
throw (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
|
|
|
m_xLocator = xLocator;
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2006-06-19 17:35:23 -05:00
|
|
|
void BasicParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& /*xAttribs*/ )
|
2002-05-16 05:00:29 -05:00
|
|
|
{
|
2006-06-19 17:35:23 -05:00
|
|
|
{ (void)aInfo; }
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ENSURE( !isSkipping(), "While skipping, call startSkipping() instead of startNode()");
|
|
|
|
OSL_ENSURE( aInfo.type != ElementType::property, "For properties, call startProperty() instead of startNode()");
|
|
|
|
|
|
|
|
if (isInProperty())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid Data: Cannot have a node nested in a property" );
|
|
|
|
|
|
|
|
m_aNodes.push(aInfo);
|
|
|
|
m_bEmpty = (aInfo.flags != 0) || (aInfo.op > Operation::modify);
|
|
|
|
|
|
|
|
OSL_POSTCOND( isInNode(), "Could not start a node ");
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::endNode( )
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ENSURE( !isSkipping(), "While skipping, honor wasSkipping() instead of calling endNode()");
|
|
|
|
OSL_ENSURE( !isInProperty(), "For properties, call endProperty() instead of endNode()" );
|
|
|
|
|
|
|
|
ensureInNode();
|
|
|
|
|
|
|
|
m_aNodes.pop();
|
|
|
|
m_bEmpty = false;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::ensureInNode( )
|
|
|
|
{
|
|
|
|
if (!isInNode())
|
|
|
|
raiseParseException("Unexpected endElement without matching startElement");
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isInNode( )
|
|
|
|
{
|
|
|
|
return ! m_aNodes.empty();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isEmptyNode( )
|
|
|
|
{
|
|
|
|
return m_bEmpty;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ElementInfo const & BasicParser::getActiveNodeInfo( )
|
|
|
|
{
|
|
|
|
ensureInNode();
|
|
|
|
|
|
|
|
return m_aNodes.top();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs )
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ENSURE( !isSkipping(), "While skipping, call startSkipping() instead of startProperty()");
|
|
|
|
OSL_ENSURE( aInfo.type == ElementType::property, "For non-property nodes, call startNode() instead of startProperty()");
|
|
|
|
|
|
|
|
if (isInProperty())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid Data: Properties may not nest" );
|
|
|
|
|
2004-11-15 06:38:08 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_aValueType = getDataParser().getPropertyValueType(xAttribs);
|
|
|
|
}
|
|
|
|
catch (ElementParser::BadValueType & error)
|
|
|
|
{
|
|
|
|
raiseParseException(error.message());
|
|
|
|
}
|
|
|
|
|
2002-05-28 09:44:53 -05:00
|
|
|
m_bInProperty = true;
|
2002-05-16 05:00:29 -05:00
|
|
|
|
|
|
|
m_aNodes.push(aInfo);
|
|
|
|
m_bEmpty = true;
|
|
|
|
|
|
|
|
OSL_POSTCOND( isInProperty(), "Could not get data to start a property" );
|
|
|
|
OSL_POSTCOND( isInUnhandledProperty(), "Could not mark property as unhandled");
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::endProperty( )
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ENSURE( !isSkipping(), "While skipping, honor wasSkipping() instead of calling endProperty()");
|
|
|
|
OSL_ENSURE( isInProperty(), "For non-property nodes, call endNode() instead of endProperty()" );
|
|
|
|
|
|
|
|
ensureInNode();
|
|
|
|
|
|
|
|
m_aNodes.pop();
|
|
|
|
m_bEmpty = false;
|
|
|
|
|
|
|
|
m_aValueType = uno::Type();
|
2002-05-28 09:44:53 -05:00
|
|
|
m_bInProperty = false;
|
2002-05-16 05:00:29 -05:00
|
|
|
|
|
|
|
OSL_POSTCOND( !isInProperty(), "Could not get mark end of property" );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uno::Type BasicParser::getActivePropertyType()
|
|
|
|
{
|
|
|
|
return m_aValueType;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isInProperty()
|
|
|
|
{
|
2002-05-28 09:44:53 -05:00
|
|
|
return m_bInProperty;
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isInUnhandledProperty()
|
|
|
|
{
|
2002-05-28 09:44:53 -05:00
|
|
|
return m_bEmpty && m_bInProperty;
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (!isInProperty())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid Data: A value may occur only within a property" );
|
|
|
|
|
|
|
|
if (m_aValueType.getTypeClass() == uno::TypeClass_ANY)
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid Data: Cannot have values for properties of type 'Any'" );
|
|
|
|
|
|
|
|
if (isInValueData())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid Data: Unexpected element while parsing value data" );
|
|
|
|
|
2006-06-19 17:35:23 -05:00
|
|
|
m_pValueData = new ValueData(m_aValueType, m_xTypeConverter);
|
2002-05-16 05:00:29 -05:00
|
|
|
|
|
|
|
m_pValueData->setIsNull( getDataParser().isNull(xAttribs) );
|
|
|
|
|
2002-05-28 09:44:53 -05:00
|
|
|
m_pValueData->setSeparator( getDataParser().getSeparator(xAttribs) );
|
|
|
|
|
|
|
|
OSL_ENSURE( !m_pValueData->hasSeparator() ||
|
|
|
|
!m_pValueData->isTypeSet() ||
|
|
|
|
m_pValueData->isList(),
|
|
|
|
"Warning: Spurious oor:separator on value that is not a list");
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_ENSURE( !m_pValueData->hasSeparator() ||
|
2002-05-28 09:44:53 -05:00
|
|
|
!m_pValueData->isNull(),
|
|
|
|
"Warning: Spurious oor:separator on value that is not a list");
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OUString aLocale;
|
|
|
|
if ( getDataParser().getLanguage(xAttribs,aLocale) )
|
|
|
|
m_pValueData->setLocalized( aLocale );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isInValueData()
|
|
|
|
{
|
|
|
|
return m_pValueData != NULL;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isValueDataLocalized()
|
|
|
|
{
|
|
|
|
OSL_ENSURE(isInValueData(), "There is no value data that could be localized");
|
|
|
|
|
|
|
|
return m_pValueData && m_pValueData->isLocalized;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OUString BasicParser::getValueDataLocale()
|
|
|
|
{
|
|
|
|
OSL_ENSURE(isValueDataLocalized(), "There is no value data or it is not localized");
|
|
|
|
|
|
|
|
return m_pValueData->locale;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
uno::Any BasicParser::getCurrentValue()
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ASSERT( isInValueData() );
|
|
|
|
|
2002-05-28 09:44:53 -05:00
|
|
|
uno::Any aResult;
|
|
|
|
|
|
|
|
if (m_pValueData->isTypeSet())
|
2002-10-01 10:10:50 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
aResult = m_pValueData->convertToAny();
|
|
|
|
}
|
|
|
|
catch (script::CannotConvertException & e)
|
|
|
|
{
|
|
|
|
this->raiseParseException(uno::makeAny(e),"Configuration XML Parser - Invalid Data: Cannot convert value to type of property" );
|
|
|
|
}
|
2002-05-28 09:44:53 -05:00
|
|
|
else if (m_pValueData->isNull())
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (m_pValueData->hasSeparator() || m_pValueData->isList())
|
|
|
|
{
|
|
|
|
aResult <<= m_pValueData->toStringList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aResult <<= m_pValueData->toString();
|
|
|
|
}
|
|
|
|
return aResult;
|
2002-05-16 05:00:29 -05:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/// end collecting data for a value
|
|
|
|
void BasicParser::endValueData()
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
OSL_ASSERT( isInValueData() );
|
|
|
|
|
|
|
|
delete m_pValueData, m_pValueData = NULL;
|
|
|
|
m_bEmpty = false;
|
|
|
|
|
|
|
|
OSL_POSTCOND( !isInValueData(), "Could not end value data tag" );
|
|
|
|
OSL_POSTCOND( !isInUnhandledProperty(), "Could not mark property as handled" );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2006-06-19 17:35:23 -05:00
|
|
|
void BasicParser::startSkipping( const OUString& aName, const uno::Reference< sax::XAttributeList >& /*xAttribs*/ )
|
2002-05-16 05:00:29 -05:00
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
m_aNodes.push( ElementInfo(aName) );
|
|
|
|
++m_nSkipLevels;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::wasSkipping( const OUString& aName )
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (m_nSkipLevels == 0) return false;
|
|
|
|
|
|
|
|
if (m_aNodes.empty())
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid XML: Unexpected end of element (while skipping data)" );
|
|
|
|
|
|
|
|
if (aName != m_aNodes.top().name)
|
|
|
|
raiseParseException( "Configuration XML Parser - Invalid XML: End tag does not match start tag (while skipping data)" );
|
|
|
|
|
|
|
|
--m_nSkipLevels;
|
|
|
|
m_aNodes.pop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool BasicParser::isSkipping( )
|
|
|
|
{
|
|
|
|
return m_nSkipLevels != 0;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::raiseParseException( uno::Any const & _aTargetException, sal_Char const * _pMsg )
|
|
|
|
CFG_THROW2 (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid Data: ";
|
|
|
|
|
|
|
|
OUString sMessage = OUString::createFromAscii(_pMsg);
|
|
|
|
|
|
|
|
uno::Exception aEx;
|
|
|
|
if (_aTargetException >>= aEx)
|
|
|
|
sMessage += aEx.Message;
|
|
|
|
|
2004-08-31 08:58:23 -05:00
|
|
|
getLogger().error(sMessage,"parse","configuration::xml::BasicParser");
|
2002-05-16 05:00:29 -05:00
|
|
|
throw sax::SAXException( sMessage, *this, _aTargetException );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void BasicParser::raiseParseException( sal_Char const * _pMsg )
|
|
|
|
CFG_THROW2 (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
2002-07-03 08:07:28 -05:00
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
2002-05-16 05:00:29 -05:00
|
|
|
if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid XML";
|
|
|
|
|
|
|
|
OUString const sMessage = OUString::createFromAscii(_pMsg);
|
|
|
|
|
2004-08-31 08:58:23 -05:00
|
|
|
getLogger().error(sMessage,"parse","configuration::xml::BasicParser");
|
2002-05-16 05:00:29 -05:00
|
|
|
throw sax::SAXException( sMessage, *this, uno::Any() );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2004-11-15 06:38:08 -06:00
|
|
|
|
|
|
|
void BasicParser::raiseParseException( OUString const & sMessage )
|
|
|
|
CFG_THROW2 (sax::SAXException, uno::RuntimeException)
|
|
|
|
{
|
|
|
|
OSL_DEBUG_ONLY( dbgUpdateLocation() );
|
|
|
|
|
|
|
|
if (sMessage.getLength() == 0) raiseParseException(NULL);
|
|
|
|
|
|
|
|
getLogger().error(sMessage,"parse","configuration::xml::BasicParser");
|
|
|
|
throw sax::SAXException( sMessage, *this, uno::Any() );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-05-16 05:00:29 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
} // namespace
|
|
|
|
|