summaryrefslogtreecommitdiff
path: root/xmloff/source/forms/propertyimport.cxx
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2006-07-26 06:34:21 +0000
committerRüdiger Timm <rt@openoffice.org>2006-07-26 06:34:21 +0000
commit30cc8f1bcc0b75787b755c6557f5f0efe8ded2ef (patch)
treedf9239cafc3f729d9bf41913577987dddf0685eb /xmloff/source/forms/propertyimport.cxx
parent93f19be786fe5724df59d25ab603ab0cdeec2fbd (diff)
INTEGRATION: CWS dba204b (1.23.16); FILE MERGED
2006/07/14 11:05:05 fs 1.23.16.1: #i67019# support for list-property / list-value
Diffstat (limited to 'xmloff/source/forms/propertyimport.cxx')
-rw-r--r--xmloff/source/forms/propertyimport.cxx451
1 files changed, 293 insertions, 158 deletions
diff --git a/xmloff/source/forms/propertyimport.cxx b/xmloff/source/forms/propertyimport.cxx
index 44ca136b51fc..453c5958cc08 100644
--- a/xmloff/source/forms/propertyimport.cxx
+++ b/xmloff/source/forms/propertyimport.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: propertyimport.cxx,v $
*
- * $Revision: 1.23 $
+ * $Revision: 1.24 $
*
- * last change: $Author: hr $ $Date: 2006-06-19 18:21:00 $
+ * last change: $Author: rt $ $Date: 2006-07-26 07:34:21 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -102,108 +102,41 @@ namespace xmloff
#define TYPE_DATETIME 3
//=====================================================================
- //= OPropertyImport
+ //= PropertyConversion
//=====================================================================
- //---------------------------------------------------------------------
- OPropertyImport::OPropertyImport(IFormsImportContext& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName)
- :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
- ,m_rContext(_rImport)
- ,m_bTrackAttributes(sal_False)
+ namespace
{
- }
-
- //---------------------------------------------------------------------
- SvXMLImportContext* OPropertyImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
- const Reference< sax::XAttributeList >& _rxAttrList)
- {
- if( token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
+ //---------------------------------------------------------------------
+ ::com::sun::star::util::Time lcl_getTime(double _nValue)
{
- return new OPropertyElementsContext( m_rContext.getGlobalContext(),
- _nPrefix, _rLocalName, this);
+ ::com::sun::star::util::Time aTime;
+ sal_uInt32 nIntValue = sal_Int32(_nValue * 8640000);
+ nIntValue *= 8640000;
+ aTime.HundredthSeconds = (sal_uInt16)( nIntValue % 100 );
+ nIntValue /= 100;
+ aTime.Seconds = (sal_uInt16)( nIntValue % 60 );
+ nIntValue /= 60;
+ aTime.Minutes = (sal_uInt16)( nIntValue % 60 );
+ nIntValue /= 60;
+ OSL_ENSURE(nIntValue < 24, "lcl_getTime: more than a day?");
+ aTime.Hours = static_cast< sal_uInt16 >( nIntValue );
+
+ return aTime;
}
- else
- {
- OSL_ENSURE(sal_False,
- ::rtl::OString("OPropertyImport::CreateChildContext: unknown sub element (only \"properties\" is recognized, but it is ")
- += ::rtl::OString(_rLocalName.getStr(), _rLocalName.getLength(), RTL_TEXTENCODING_ASCII_US)
- += ::rtl::OString(")!"));
- return SvXMLImportContext::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
- }
- }
-
- //---------------------------------------------------------------------
- void OPropertyImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
- {
- OSL_ENSURE(_rxAttrList.is(), "OPropertyImport::StartElement: invalid attribute list!");
- sal_Int32 nAttributeCount = _rxAttrList->getLength();
-
- // assume the 'worst' case: all attributes describe properties. This should save our property array
- // some reallocs
- m_aValues.reserve(nAttributeCount);
- sal_uInt16 nNamespace;
- ::rtl::OUString sLocalName;
- for (sal_Int16 i=0; i<nAttributeCount; ++i)
+ //---------------------------------------------------------------------
+ static ::com::sun::star::util::Date lcl_getDate( double _nValue )
{
- nNamespace = m_rContext.getGlobalContext().GetNamespaceMap().GetKeyByAttrName(_rxAttrList->getNameByIndex(i), &sLocalName);
- handleAttribute(nNamespace, sLocalName, _rxAttrList->getValueByIndex(i));
-
- if (m_bTrackAttributes)
- m_aEncounteredAttributes.insert(sLocalName);
+ Date aToolsDate((sal_uInt32)_nValue);
+ ::com::sun::star::util::Date aDate;
+ ::utl::typeConvert(aToolsDate, aDate);
+ return aDate;
}
-
- // TODO: create PropertyValues for all the attributes which were not present, because they were implied
- // this is necessary as soon as we have properties where the XML default is different from the property
- // default
}
//---------------------------------------------------------------------
- sal_Bool OPropertyImport::encounteredAttribute(const ::rtl::OUString& _rAttributeName) const
- {
- OSL_ENSURE(m_bTrackAttributes, "OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
- return m_aEncounteredAttributes.end() != m_aEncounteredAttributes.find(_rAttributeName);
- }
-
- //---------------------------------------------------------------------
- void OPropertyImport::Characters(const ::rtl::OUString&
- #if OSL_DEBUG_LEVEL > 0
- _rChars
- #endif
- )
- {
- // ignore them (should be whitespaces only)
- OSL_ENSURE(0 == _rChars.trim().getLength(), "OPropertyImport::Characters: non-whitespace characters!");
- }
-
- //---------------------------------------------------------------------
- void OPropertyImport::handleAttribute(sal_uInt16 /*_nNamespaceKey*/, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
- {
- const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
- if (pProperty)
- {
- // create and store a new PropertyValue
- PropertyValue aNewValue;
- aNewValue.Name = pProperty->sPropertyName;
-
- // convert the value string into the target type
- aNewValue.Value = convertString(m_rContext.getGlobalContext(), pProperty->aPropertyType, _rValue, pProperty->pEnumMap, pProperty->bInverseSemantics);
- implPushBackPropertyValue( aNewValue );
- }
-#if OSL_DEBUG_LEVEL > 0
- else
- {
- ::rtl::OString sMessage( "OPropertyImport::handleAttribute: Can't handle the following:\n" );
- sMessage += ::rtl::OString( " Attribute name: " );
- sMessage += ::rtl::OString( _rLocalName.getStr(), _rLocalName.getLength(), osl_getThreadTextEncoding() );
- sMessage += ::rtl::OString( "\n value: " );
- sMessage += ::rtl::OString( _rValue.getStr(), _rValue.getLength(), osl_getThreadTextEncoding() );
- OSL_ENSURE( sal_False, sMessage.getStr() );
- }
-#endif
- }
-
- //---------------------------------------------------------------------
- Any OPropertyImport::convertString(SvXMLImport& _rImporter, const ::com::sun::star::uno::Type& _rExpectedType, const ::rtl::OUString& _rReadCharacters, const SvXMLEnumMapEntry* _pEnumMap, const sal_Bool _bInvertBoolean)
+ Any PropertyConversion::convertString( SvXMLImport& _rImporter, const ::com::sun::star::uno::Type& _rExpectedType,
+ const ::rtl::OUString& _rReadCharacters, const SvXMLEnumMapEntry* _pEnumMap, const sal_Bool _bInvertBoolean )
{
Any aReturn;
sal_Bool bEnumAsInt = sal_False;
@@ -217,7 +150,7 @@ namespace xmloff
#endif
_rImporter.GetMM100UnitConverter().convertBool(bValue, _rReadCharacters);
OSL_ENSURE(bSuccess,
- ::rtl::OString("OPropertyImport::convertString: could not convert \"")
+ ::rtl::OString("PropertyConversion::convertString: could not convert \"")
+= ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US)
+= ::rtl::OString("\" into a boolean!"));
aReturn = ::cppu::bool2any(_bInvertBoolean ? !bValue : bValue);
@@ -233,7 +166,7 @@ namespace xmloff
#endif
_rImporter.GetMM100UnitConverter().convertNumber(nValue, _rReadCharacters);
OSL_ENSURE(bSuccess,
- ::rtl::OString("OPropertyImport::convertString: could not convert \"")
+ ::rtl::OString("PropertyConversion::convertString: could not convert \"")
+= ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US)
+= ::rtl::OString("\" into an integer!"));
if (TypeClass_SHORT == _rExpectedType.getTypeClass())
@@ -246,12 +179,12 @@ namespace xmloff
// NO BREAK! handle it as enum
case TypeClass_ENUM:
{
- sal_uInt16 nEnumValue;
+ sal_uInt16 nEnumValue(0);
#if OSL_DEBUG_LEVEL > 0
sal_Bool bSuccess =
#endif
_rImporter.GetMM100UnitConverter().convertEnum(nEnumValue, _rReadCharacters, _pEnumMap);
- OSL_ENSURE(bSuccess, "OPropertyImport::convertString: could not convert to an enum value!");
+ OSL_ENSURE(bSuccess, "PropertyConversion::convertString: could not convert to an enum value!");
if (bEnumAsInt)
if (TypeClass_SHORT == _rExpectedType.getTypeClass())
aReturn <<= (sal_Int16)nEnumValue;
@@ -263,7 +196,7 @@ namespace xmloff
break;
case TypeClass_HYPER:
{
- OSL_ENSURE(sal_False, "OPropertyImport::convertString: 64-bit integers not implemented yet!");
+ OSL_ENSURE(sal_False, "PropertyConversion::convertString: 64-bit integers not implemented yet!");
}
break;
case TypeClass_DOUBLE:
@@ -274,7 +207,7 @@ namespace xmloff
#endif
_rImporter.GetMM100UnitConverter().convertDouble(nValue, _rReadCharacters);
OSL_ENSURE(bSuccess,
- ::rtl::OString("OPropertyImport::convertString: could not convert \"")
+ ::rtl::OString("PropertyConversion::convertString: could not convert \"")
+= ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US)
+= ::rtl::OString("\" into a double!"));
aReturn <<= (double)nValue;
@@ -285,15 +218,15 @@ namespace xmloff
break;
case TypeClass_STRUCT:
{
- // recognized structs:
- static ::com::sun::star::uno::Type s_aDateType = ::getCppuType(static_cast< ::com::sun::star::util::Date* >(NULL));
- static ::com::sun::star::uno::Type s_aTimeType = ::getCppuType(static_cast< ::com::sun::star::util::Time* >(NULL));
- static ::com::sun::star::uno::Type s_aDateTimeType = ::getCppuType(static_cast< ::com::sun::star::util::DateTime* >(NULL));
sal_Int32 nType = 0;
- if ( (_rExpectedType.equals(s_aDateType) && (nType = TYPE_DATE))
- || (_rExpectedType.equals(s_aTimeType) && (nType = TYPE_TIME))
- || (_rExpectedType.equals(s_aDateTimeType) && (nType = TYPE_DATETIME))
- )
+ if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Date >::get() ) )
+ nType = TYPE_DATE;
+ else if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Time >::get() ) )
+ nType = TYPE_TIME;
+ else if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::DateTime >::get() ) )
+ nType = TYPE_DATETIME;
+
+ if ( nType )
{
// first extract the double
double nValue = 0;
@@ -302,7 +235,7 @@ namespace xmloff
#endif
_rImporter.GetMM100UnitConverter().convertDouble(nValue, _rReadCharacters);
OSL_ENSURE(bSuccess,
- ::rtl::OString("OPropertyImport::convertString: could not convert \"")
+ ::rtl::OString("PropertyConversion::convertString: could not convert \"")
+= ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US)
+= ::rtl::OString("\" into a double!"));
@@ -312,21 +245,21 @@ namespace xmloff
case TYPE_DATE:
{
OSL_ENSURE(((sal_uInt32)nValue) - nValue == 0,
- "OPropertyImport::convertString: a Date value with a fractional part?");
- aReturn <<= implGetDate(nValue);
+ "PropertyConversion::convertString: a Date value with a fractional part?");
+ aReturn <<= lcl_getDate(nValue);
}
break;
case TYPE_TIME:
{
OSL_ENSURE(((sal_uInt32)nValue) == 0,
- "OPropertyImport::convertString: a Time value with more than a fractional part?");
- aReturn <<= implGetTime(nValue);
+ "PropertyConversion::convertString: a Time value with more than a fractional part?");
+ aReturn <<= lcl_getTime(nValue);
}
break;
case TYPE_DATETIME:
{
- ::com::sun::star::util::Time aTime = implGetTime(nValue);
- ::com::sun::star::util::Date aDate = implGetDate(nValue);
+ ::com::sun::star::util::Time aTime = lcl_getTime(nValue);
+ ::com::sun::star::util::Date aDate = lcl_getDate(nValue);
::com::sun::star::util::DateTime aDateTime;
aDateTime.HundredthSeconds = aTime.HundredthSeconds;
@@ -342,41 +275,138 @@ namespace xmloff
}
}
else
- OSL_ENSURE(sal_False, "OPropertyImport::convertString: unsupported property type!");
+ OSL_ENSURE(sal_False, "PropertyConversion::convertString: unsupported property type!");
}
break;
default:
- OSL_ENSURE(sal_False, "OPropertyImport::convertString: invalid type class!");
+ OSL_ENSURE(sal_False, "PropertyConversion::convertString: invalid type class!");
}
return aReturn;
}
//---------------------------------------------------------------------
- ::com::sun::star::util::Time OPropertyImport::implGetTime(double _nValue)
+ Type PropertyConversion::xmlTypeToUnoType( const ::rtl::OUString& _rType )
+ {
+ Type aUnoType( ::getVoidCppuType() );
+
+ DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Type, MapString2Type );
+ static MapString2Type s_aTypeNameMap;
+ if ( s_aTypeNameMap.empty() )
+ {
+ s_aTypeNameMap[ token::GetXMLToken( token::XML_BOOLEAN ) ] = ::getBooleanCppuType();
+ s_aTypeNameMap[ token::GetXMLToken( token::XML_FLOAT ) ] = ::getCppuType( static_cast< double* >(NULL) );
+ s_aTypeNameMap[ token::GetXMLToken( token::XML_STRING ) ] = ::getCppuType( static_cast< ::rtl::OUString* >(NULL) );
+ s_aTypeNameMap[ token::GetXMLToken( token::XML_VOID ) ] = ::getVoidCppuType();
+ }
+
+ const ConstMapString2TypeIterator aTypePos = s_aTypeNameMap.find( _rType );
+ OSL_ENSURE( s_aTypeNameMap.end() != aTypePos, "PropertyConversion::xmlTypeToUnoType: invalid property name!" );
+ if ( s_aTypeNameMap.end() != aTypePos )
+ aUnoType = aTypePos->second;
+
+ return aUnoType;
+ }
+
+ //=====================================================================
+ //= OPropertyImport
+ //=====================================================================
+ //---------------------------------------------------------------------
+ OPropertyImport::OPropertyImport(IFormsImportContext& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName)
+ :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
+ ,m_rContext(_rImport)
+ ,m_bTrackAttributes(sal_False)
+ {
+ }
+
+ //---------------------------------------------------------------------
+ SvXMLImportContext* OPropertyImport::CreateChildContext(sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
+ const Reference< sax::XAttributeList >& _rxAttrList)
+ {
+ if( token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
+ {
+ return new OPropertyElementsContext( m_rContext.getGlobalContext(),
+ _nPrefix, _rLocalName, this);
+ }
+ else
+ {
+ OSL_ENSURE(sal_False,
+ ::rtl::OString("OPropertyImport::CreateChildContext: unknown sub element (only \"properties\" is recognized, but it is ")
+ += ::rtl::OString(_rLocalName.getStr(), _rLocalName.getLength(), RTL_TEXTENCODING_ASCII_US)
+ += ::rtl::OString(")!"));
+ return SvXMLImportContext::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
+ }
+ }
+
+ //---------------------------------------------------------------------
+ void OPropertyImport::StartElement(const Reference< sax::XAttributeList >& _rxAttrList)
+ {
+ OSL_ENSURE(_rxAttrList.is(), "OPropertyImport::StartElement: invalid attribute list!");
+ sal_Int32 nAttributeCount = _rxAttrList->getLength();
+
+ // assume the 'worst' case: all attributes describe properties. This should save our property array
+ // some reallocs
+ m_aValues.reserve(nAttributeCount);
+
+ sal_uInt16 nNamespace;
+ ::rtl::OUString sLocalName;
+ for (sal_Int16 i=0; i<nAttributeCount; ++i)
+ {
+ nNamespace = m_rContext.getGlobalContext().GetNamespaceMap().GetKeyByAttrName(_rxAttrList->getNameByIndex(i), &sLocalName);
+ handleAttribute(nNamespace, sLocalName, _rxAttrList->getValueByIndex(i));
+
+ if (m_bTrackAttributes)
+ m_aEncounteredAttributes.insert(sLocalName);
+ }
+
+ // TODO: create PropertyValues for all the attributes which were not present, because they were implied
+ // this is necessary as soon as we have properties where the XML default is different from the property
+ // default
+ }
+
+ //---------------------------------------------------------------------
+ sal_Bool OPropertyImport::encounteredAttribute(const ::rtl::OUString& _rAttributeName) const
+ {
+ OSL_ENSURE(m_bTrackAttributes, "OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
+ return m_aEncounteredAttributes.end() != m_aEncounteredAttributes.find(_rAttributeName);
+ }
+
+ //---------------------------------------------------------------------
+ void OPropertyImport::Characters(const ::rtl::OUString&
+ #if OSL_DEBUG_LEVEL > 0
+ _rChars
+ #endif
+ )
{
- ::com::sun::star::util::Time aTime;
- sal_uInt32 nIntValue = sal_Int32(_nValue * 8640000);
- nIntValue *= 8640000;
- aTime.HundredthSeconds = (sal_uInt16)( nIntValue % 100 );
- nIntValue /= 100;
- aTime.Seconds = (sal_uInt16)( nIntValue % 60 );
- nIntValue /= 60;
- aTime.Minutes = (sal_uInt16)( nIntValue % 60 );
- nIntValue /= 60;
- OSL_ENSURE(nIntValue < 24, "OPropertyImport::implGetTime: more than a day?");
- aTime.Hours = static_cast< sal_uInt16 >( nIntValue );
-
- return aTime;
+ // ignore them (should be whitespaces only)
+ OSL_ENSURE(0 == _rChars.trim().getLength(), "OPropertyImport::Characters: non-whitespace characters!");
}
//---------------------------------------------------------------------
- ::com::sun::star::util::Date OPropertyImport::implGetDate(double _nValue)
+ void OPropertyImport::handleAttribute(sal_uInt16 /*_nNamespaceKey*/, const ::rtl::OUString& _rLocalName, const ::rtl::OUString& _rValue)
{
- Date aToolsDate((sal_uInt32)_nValue);
- ::com::sun::star::util::Date aDate;
- ::utl::typeConvert(aToolsDate, aDate);
- return aDate;
+ const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
+ if (pProperty)
+ {
+ // create and store a new PropertyValue
+ PropertyValue aNewValue;
+ aNewValue.Name = pProperty->sPropertyName;
+
+ // convert the value string into the target type
+ aNewValue.Value = PropertyConversion::convertString(m_rContext.getGlobalContext(), pProperty->aPropertyType, _rValue, pProperty->pEnumMap, pProperty->bInverseSemantics);
+ implPushBackPropertyValue( aNewValue );
+ }
+#if OSL_DEBUG_LEVEL > 0
+ else
+ {
+ ::rtl::OString sMessage( "OPropertyImport::handleAttribute: Can't handle the following:\n" );
+ sMessage += ::rtl::OString( " Attribute name: " );
+ sMessage += ::rtl::OString( _rLocalName.getStr(), _rLocalName.getLength(), osl_getThreadTextEncoding() );
+ sMessage += ::rtl::OString( "\n value: " );
+ sMessage += ::rtl::OString( _rValue.getStr(), _rValue.getLength(), osl_getThreadTextEncoding() );
+ OSL_ENSURE( sal_False, sMessage.getStr() );
+ }
+#endif
}
//=====================================================================
@@ -400,8 +430,7 @@ namespace xmloff
}
else if( token::IsXMLToken( _rLocalName, token::XML_LIST_PROPERTY ) )
{
- OSL_ENSURE(sal_False, "list properties aren't supported" );
- return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName);
+ return new OListPropertyContext( GetImport(), _nPrefix, _rLocalName, m_xPropertyImporter );
}
else
{
@@ -493,20 +522,7 @@ namespace xmloff
OSL_ENSURE(aPropValue.Name.getLength(), "OSinglePropertyContext::StartElement: invalid property name!");
// needs to be translated into a ::com::sun::star::uno::Type
- DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Type, MapString2Type );
- static MapString2Type s_aTypeNameMap;
- if (!s_aTypeNameMap.size())
- {
- s_aTypeNameMap[token::GetXMLToken( token::XML_BOOLEAN)] = ::getBooleanCppuType();
- s_aTypeNameMap[token::GetXMLToken( token::XML_FLOAT)] = ::getCppuType( static_cast< double* >(NULL) );
- s_aTypeNameMap[token::GetXMLToken( token::XML_STRING)] = ::getCppuType( static_cast< ::rtl::OUString* >(NULL) );
- s_aTypeNameMap[token::GetXMLToken( token::XML_VOID)] = ::getVoidCppuType();
- }
-
- const ConstMapString2TypeIterator aTypePos = s_aTypeNameMap.find(sType);
- OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OSinglePropertyContext::StartElement: invalid property name!");
- if (s_aTypeNameMap.end() != aTypePos)
- aPropType = aTypePos->second;
+ aPropType = PropertyConversion::xmlTypeToUnoType( sType );
if( TypeClass_VOID == aPropType.getTypeClass() )
{
aPropValue.Value = Any();
@@ -514,7 +530,7 @@ namespace xmloff
else
{
aPropValue.Value =
- OPropertyImport::convertString(GetImport(), aPropType,
+ PropertyConversion::convertString(GetImport(), aPropType,
sValue);
}
@@ -523,14 +539,133 @@ namespace xmloff
m_xPropertyImporter->implPushBackGenericPropertyValue(aPropValue);
}
-#if OSL_DEBUG_LEVEL > 0
+ //=====================================================================
+ //= OListPropertyContext
+ //=====================================================================
//---------------------------------------------------------------------
- void OSinglePropertyContext::Characters(const ::rtl::OUString& _rChars)
+ OListPropertyContext::OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
+ const OPropertyImportRef& _rPropertyImporter )
+ :SvXMLImportContext( _rImport, _nPrefix, _rName )
+ ,m_xPropertyImporter( _rPropertyImporter )
{
- OSL_ENSURE(0 == _rChars.trim(), "OSinglePropertyContext::Characters: non-whitespace characters detected!");
- SvXMLImportContext::Characters(_rChars);
}
-#endif
+
+ //---------------------------------------------------------------------
+ void OListPropertyContext::StartElement( const Reference< sax::XAttributeList >& _rxAttrList )
+ {
+ sal_Int32 nAttributeCount = _rxAttrList->getLength();
+
+ sal_uInt16 nNamespace;
+ ::rtl::OUString sAttributeName;
+ for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
+ {
+ nNamespace = GetImport().GetNamespaceMap().GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
+ if ( ( XML_NAMESPACE_FORM == nNamespace )
+ && ( token::IsXMLToken( sAttributeName, token::XML_PROPERTY_NAME ) )
+ )
+ {
+ m_sPropertyName = _rxAttrList->getValueByIndex( i );
+ }
+ else if ( ( XML_NAMESPACE_OFFICE == nNamespace )
+ && ( token::IsXMLToken( sAttributeName, token::XML_VALUE_TYPE ) )
+ )
+ {
+ m_sPropertyType = _rxAttrList->getValueByIndex( i );
+ }
+ else
+ {
+ OSL_ENSURE( false,
+ ::rtl::OString( "OListPropertyContext::StartElement: unknown child element (\"")
+ += ::rtl::OString( sAttributeName.getStr(), sAttributeName.getLength(), RTL_TEXTENCODING_ASCII_US )
+ += ::rtl::OString( "\")!" ) );
+ }
+ }
+ }
+
+ //---------------------------------------------------------------------
+ void OListPropertyContext::EndElement()
+ {
+ OSL_ENSURE( m_sPropertyName.getLength() && m_sPropertyType.getLength(),
+ "OListPropertyContext::EndElement: no property name or type!" );
+
+ if ( !m_sPropertyName.getLength() || !m_sPropertyType.getLength() )
+ return;
+
+ Sequence< Any > aListElements( m_aListValues.size() );
+ Any* pListElement = aListElements.getArray();
+ com::sun::star::uno::Type aType = PropertyConversion::xmlTypeToUnoType( m_sPropertyType );
+ for ( ::std::vector< ::rtl::OUString >::const_iterator values = m_aListValues.begin();
+ values != m_aListValues.end();
+ ++values, ++pListElement
+ )
+ {
+ *pListElement = PropertyConversion::convertString( GetImport(), aType, *values );
+ }
+
+ PropertyValue aSequenceValue;
+ aSequenceValue.Name = m_sPropertyName;
+ aSequenceValue.Value <<= aListElements;
+
+ m_xPropertyImporter->implPushBackGenericPropertyValue( aSequenceValue );
+ }
+
+ //---------------------------------------------------------------------
+ SvXMLImportContext* OListPropertyContext::CreateChildContext( sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, const Reference< sax::XAttributeList >& /*_rxAttrList*/ )
+ {
+ if ( token::IsXMLToken( _rLocalName, token::XML_LIST_VALUE ) )
+ {
+ m_aListValues.resize( m_aListValues.size() + 1 );
+ return new OListValueContext( GetImport(), _nPrefix, _rLocalName, *m_aListValues.rbegin() );
+ }
+ else
+ {
+ OSL_ENSURE( sal_False,
+ ::rtl::OString("OListPropertyContext::CreateChildContext: unknown child element (\"")
+ += ::rtl::OString(_rLocalName.getStr(), _rLocalName.getLength(), RTL_TEXTENCODING_ASCII_US)
+ += ::rtl::OString("\")!"));
+ return new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
+ }
+ }
+
+ //=====================================================================
+ //= OListValueContext
+ //=====================================================================
+ //---------------------------------------------------------------------
+ OListValueContext::OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, ::rtl::OUString& _rListValueHolder )
+ :SvXMLImportContext( _rImport, _nPrefix, _rName )
+ ,m_rListValueHolder( _rListValueHolder )
+ {
+ }
+
+ //---------------------------------------------------------------------
+ void OListValueContext::StartElement( const Reference< sax::XAttributeList >& _rxAttrList )
+ {
+ sal_Int32 nAttributeCount = _rxAttrList->getLength();
+
+ sal_uInt16 nNamespace;
+ ::rtl::OUString sAttributeName;
+ for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
+ {
+ nNamespace = GetImport().GetNamespaceMap().GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
+ if ( XML_NAMESPACE_OFFICE == nNamespace )
+ {
+ if ( token::IsXMLToken( sAttributeName, token::XML_VALUE )
+ || token::IsXMLToken( sAttributeName, token::XML_STRING_VALUE )
+ || token::IsXMLToken( sAttributeName, token::XML_BOOLEAN_VALUE )
+ )
+ {
+ m_rListValueHolder = _rxAttrList->getValueByIndex( i );
+ continue;
+ }
+ }
+
+ OSL_ENSURE( false,
+ ::rtl::OString( "OListValueContext::StartElement: unknown child element (\"")
+ += ::rtl::OString( sAttributeName.getStr(), sAttributeName.getLength(), RTL_TEXTENCODING_ASCII_US )
+ += ::rtl::OString( "\")!" ) );
+ }
+ }
+
//.........................................................................
} // namespace xmloff
//.........................................................................