2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-12-06 16:32:01 +00:00
/*************************************************************************
*
2008-04-10 21:00:47 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2000-12-06 16:32:01 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2000-12-06 16:32:01 +00:00
*
2008-04-10 21:00:47 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-12-06 16:32:01 +00:00
*
2008-04-10 21:00:47 +00:00
* This file is part of OpenOffice . org .
2000-12-06 16:32:01 +00:00
*
2008-04-10 21:00:47 +00: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 .
2000-12-06 16:32:01 +00:00
*
2008-04-10 21:00:47 +00: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 ) .
2000-12-06 16:32:01 +00:00
*
2008-04-10 21:00:47 +00: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 .
2000-12-06 16:32:01 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 09:34:03 +00:00
2000-12-06 16:32:01 +00:00
# include "elementimport.hxx"
2010-09-15 13:55:34 +02:00
# include "xmloff/xmlimp.hxx"
# include "xmloff/nmspmap.hxx"
2000-12-06 16:32:01 +00:00
# include "strings.hxx"
2000-12-12 11:01:05 +00:00
# include "callbacks.hxx"
# include "attriblistmerge.hxx"
2010-04-16 23:04:00 +02:00
# include "xmloff/xmlnmspe.hxx"
2001-01-02 14:58:22 +00:00
# include "eventimport.hxx"
2010-09-15 13:55:34 +02:00
# include "xmloff/txtstyli.hxx"
2003-10-21 07:38:38 +00:00
# include "formenums.hxx"
2010-09-15 13:55:34 +02:00
# include "xmloff/xmltoken.hxx"
2004-11-09 11:16:35 +00:00
# include "gridcolumnproptranslator.hxx"
2010-09-15 13:55:34 +02:00
# include "property_description.hxx"
# include "property_meta_data.hxx"
2004-05-07 14:59:30 +00:00
/** === begin UNO includes === **/
# include <com/sun/star/text/XText.hpp>
2000-12-12 11:01:05 +00:00
# include <com/sun/star/util/XCloneable.hpp>
2011-10-11 14:19:08 +02:00
# include <com/sun/star/util/Duration.hpp>
2000-12-13 09:40:15 +00:00
# include <com/sun/star/form/FormComponentType.hpp>
2004-07-05 15:07:58 +00:00
# include <com/sun/star/awt/ImagePosition.hpp>
2004-05-07 14:59:30 +00:00
# include <com/sun/star/beans/XMultiPropertySet.hpp>
2007-03-09 12:05:34 +00:00
# include <com/sun/star/beans/XPropertyContainer.hpp>
# include <com/sun/star/beans/PropertyAttribute.hpp>
2004-05-07 14:59:30 +00:00
/** === end UNO includes === **/
2010-09-15 13:55:34 +02:00
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
# include <sax/tools/converter.hxx>
2004-08-02 13:14:10 +00:00
# include <tools/urlobj.hxx>
2010-09-15 13:55:34 +02:00
# include <tools/diagnose_ex.h>
2009-04-23 10:42:05 +00:00
# include <rtl/logfile.hxx>
2011-10-05 09:27:07 +01:00
# include <rtl/strbuf.hxx>
2010-09-15 13:55:34 +02:00
# include <comphelper/extract.hxx>
# include <comphelper/types.hxx>
2000-12-06 16:32:01 +00:00
2001-11-02 11:34:13 +00:00
# include <algorithm>
2004-05-07 14:59:30 +00:00
# include <functional>
2001-11-02 11:34:13 +00:00
2000-12-06 16:32:01 +00:00
//.........................................................................
namespace xmloff
{
//.........................................................................
2004-07-05 15:07:58 +00:00
using namespace : : xmloff : : token ;
2006-07-26 06:32:42 +00:00
using namespace : : com : : sun : : star ;
2000-12-06 16:32:01 +00:00
using namespace : : com : : sun : : star : : uno ;
2004-07-05 15:07:58 +00:00
using namespace : : com : : sun : : star : : awt ;
2000-12-06 16:32:01 +00:00
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : beans ;
2001-01-02 14:58:22 +00:00
using namespace : : com : : sun : : star : : script ;
2000-12-06 16:32:01 +00:00
using namespace : : com : : sun : : star : : lang ;
2000-12-13 09:40:15 +00:00
using namespace : : com : : sun : : star : : form ;
2000-12-06 16:32:01 +00:00
using namespace : : com : : sun : : star : : xml ;
2000-12-12 11:01:05 +00:00
using namespace : : com : : sun : : star : : util ;
2004-05-07 14:59:30 +00:00
using namespace : : com : : sun : : star : : text ;
2006-07-26 06:32:42 +00:00
using namespace : : comphelper ;
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
using : : com : : sun : : star : : xml : : sax : : XAttributeList ;
2000-12-06 16:32:01 +00:00
2000-12-13 09:40:15 +00:00
# define PROPID_VALUE 1
# define PROPID_CURRENT_VALUE 2
# define PROPID_MIN_VALUE 3
# define PROPID_MAX_VALUE 4
2000-12-06 16:32:01 +00:00
//=====================================================================
struct PropertyValueLess
{
sal_Bool operator ( ) ( const PropertyValue & _rLeft , const PropertyValue & _rRight )
{
return _rLeft . Name < _rRight . Name ;
}
} ;
2004-08-02 13:14:10 +00:00
//=====================================================================
struct PropertyValueCompare : public : : std : : binary_function < PropertyValue , : : rtl : : OUString , bool >
{
bool operator ( ) ( const PropertyValue & lhs , const : : rtl : : OUString & rhs ) const
{
return lhs . Name = = rhs ;
}
bool operator ( ) ( const : : rtl : : OUString & lhs , const PropertyValue & rhs ) const
{
return lhs = = rhs . Name ;
}
} ;
2000-12-06 16:32:01 +00:00
//=====================================================================
template < class ELEMENT >
void pushBackSequenceElement ( Sequence < ELEMENT > & _rContainer , const ELEMENT & _rElement )
{
sal_Int32 nLen = _rContainer . getLength ( ) ;
_rContainer . realloc ( nLen + 1 ) ;
_rContainer [ nLen ] = _rElement ;
}
//=====================================================================
//= OElementNameMap
//=====================================================================
2000-12-12 11:01:05 +00:00
//---------------------------------------------------------------------
OElementNameMap : : MapString2Element OElementNameMap : : s_sElementTranslations ;
//---------------------------------------------------------------------
2000-12-06 16:32:01 +00:00
const OControlElement : : ElementType & operator + + ( OControlElement : : ElementType & _e )
{
2000-12-20 13:01:19 +00:00
OControlElement : : ElementType e = _e ;
sal_Int32 nAsInt = static_cast < sal_Int32 > ( e ) ;
2000-12-06 16:32:01 +00:00
_e = static_cast < OControlElement : : ElementType > ( + + nAsInt ) ;
return _e ;
}
//---------------------------------------------------------------------
OControlElement : : ElementType OElementNameMap : : getElementType ( const : : rtl : : OUString & _rName )
{
2009-04-23 10:42:05 +00:00
if ( s_sElementTranslations . empty ( ) )
2000-12-06 16:32:01 +00:00
{ // initialize
for ( ElementType eType = ( ElementType ) 0 ; eType < UNKNOWN ; + + eType )
s_sElementTranslations [ : : rtl : : OUString : : createFromAscii ( getElementName ( eType ) ) ] = eType ;
}
ConstMapString2ElementIterator aPos = s_sElementTranslations . find ( _rName ) ;
if ( s_sElementTranslations . end ( ) ! = aPos )
return aPos - > second ;
return UNKNOWN ;
}
//=====================================================================
//= OElementImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OElementImport : : OElementImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer )
2000-12-18 14:14:35 +00:00
: OPropertyImport ( _rImport , _nPrefix , _rName )
2000-12-12 11:01:05 +00:00
, m_rFormImport ( _rImport )
2001-01-02 14:58:22 +00:00
, m_rEventManager ( _rEventManager )
2002-10-25 12:19:34 +00:00
, m_pStyleElement ( NULL )
2006-06-19 17:17:05 +00:00
, m_xParentContainer ( _rxParentContainer )
2010-09-24 15:57:20 +02:00
, m_bImplicitGenericAttributeHandling ( true )
2000-12-06 16:32:01 +00:00
{
OSL_ENSURE ( m_xParentContainer . is ( ) , " OElementImport::OElementImport: invalid parent container! " ) ;
}
2006-06-19 17:17:05 +00:00
//---------------------------------------------------------------------
OElementImport : : ~ OElementImport ( )
{
}
2010-09-15 13:55:34 +02:00
//---------------------------------------------------------------------
: : rtl : : OUString OElementImport : : determineDefaultServiceName ( ) const
{
return : : rtl : : OUString ( ) ;
}
2000-12-06 16:32:01 +00:00
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OElementImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2000-12-06 16:32:01 +00:00
{
2002-10-02 13:33:52 +00:00
ENTER_LOG_CONTEXT ( " xmloff::OElementImport - importing one element " ) ;
2000-12-06 16:32:01 +00:00
2010-09-15 13:55:34 +02:00
const SvXMLNamespaceMap & rMap = m_rContext . getGlobalContext ( ) . GetNamespaceMap ( ) ;
const : : rtl : : OUString sImplNameAttribute = rMap . GetQNameByKey ( XML_NAMESPACE_FORM , GetXMLToken ( XML_CONTROL_IMPLEMENTATION ) ) ;
const : : rtl : : OUString sControlImplementation = _rxAttrList - > getValueByName ( sImplNameAttribute ) ;
// retrieve the service name
2012-01-25 21:59:48 -02:00
if ( ! sControlImplementation . isEmpty ( ) )
2010-09-15 13:55:34 +02:00
{
: : rtl : : OUString sOOoImplementationName ;
const sal_uInt16 nImplPrefix = GetImport ( ) . GetNamespaceMap ( ) . GetKeyByAttrName ( sControlImplementation , & sOOoImplementationName ) ;
m_sServiceName = ( nImplPrefix = = XML_NAMESPACE_OOO ) ? sOOoImplementationName : sControlImplementation ;
}
2012-01-25 21:59:48 -02:00
if ( m_sServiceName . isEmpty ( ) )
2010-09-15 13:55:34 +02:00
determineDefaultServiceName ( ) ;
// create the object *now*. This allows setting properties in the various handleAttribute methods.
// (Though currently not all code is migrated to this pattern, most attributes are still handled
// by remembering the value (via implPushBackPropertyValue), and setting the correct property value
// later (in OControlImport::StartElement).)
2000-12-06 16:32:01 +00:00
m_xElement = createElement ( ) ;
2010-09-15 13:55:34 +02:00
if ( m_xElement . is ( ) )
2009-04-23 10:42:05 +00:00
m_xInfo = m_xElement - > getPropertySetInfo ( ) ;
2010-09-15 13:55:34 +02:00
// call the base class
OPropertyImport : : StartElement ( _rxAttrList ) ;
2000-12-06 16:32:01 +00:00
}
2001-01-02 14:58:22 +00:00
//---------------------------------------------------------------------
SvXMLImportContext * OElementImport : : CreateChildContext ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
const Reference < XAttributeList > & _rxAttrList )
2001-01-02 14:58:22 +00:00
{
2004-07-13 07:29:16 +00:00
if ( token : : IsXMLToken ( _rLocalName , token : : XML_EVENT_LISTENERS ) & & ( XML_NAMESPACE_OFFICE = = _nPrefix ) )
2001-01-02 14:58:22 +00:00
return new OFormEventsImportContext ( m_rFormImport . getGlobalContext ( ) , _nPrefix , _rLocalName , * this ) ;
return OPropertyImport : : CreateChildContext ( _nPrefix , _rLocalName , _rxAttrList ) ;
}
2000-12-06 16:32:01 +00:00
//---------------------------------------------------------------------
void OElementImport : : EndElement ( )
{
OSL_ENSURE ( m_xElement . is ( ) , " OElementImport::EndElement: invalid element created! " ) ;
if ( ! m_xElement . is ( ) )
return ;
2010-09-24 21:27:18 +02:00
// apply the non-generic properties
implApplySpecificProperties ( ) ;
// set the generic properties
implApplyGenericProperties ( ) ;
// set the style properties
if ( m_pStyleElement & & m_xElement . is ( ) )
{
Reference < XPropertySet > xPropTranslation =
new OGridColumnPropertyTranslator ( Reference < XMultiPropertySet > ( m_xElement , UNO_QUERY ) ) ;
const_cast < XMLTextStyleContext * > ( m_pStyleElement ) - > FillPropertySet ( xPropTranslation ) ;
const : : rtl : : OUString sNumberStyleName = const_cast < XMLTextStyleContext * > ( m_pStyleElement ) - > GetDataStyleName ( ) ;
2012-01-25 21:59:48 -02:00
if ( ! sNumberStyleName . isEmpty ( ) )
2010-09-24 21:27:18 +02:00
// the style also has a number (sub) style
m_rContext . applyControlNumberStyle ( m_xElement , sNumberStyleName ) ;
}
// insert the element into the parent container
2012-01-25 21:59:48 -02:00
if ( m_sName . isEmpty ( ) )
2010-09-24 21:27:18 +02:00
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OElementImport::EndElement: did not find a name attribute! " ) ;
2010-09-24 21:27:18 +02:00
m_sName = implGetDefaultName ( ) ;
}
2011-06-09 21:39:53 -04:00
if ( m_xParentContainer . is ( ) )
m_xParentContainer - > insertByName ( m_sName , makeAny ( m_xElement ) ) ;
2010-09-24 21:27:18 +02:00
LEAVE_LOG_CONTEXT ( ) ;
}
//---------------------------------------------------------------------
void OElementImport : : implApplySpecificProperties ( )
{
if ( m_aValues . empty ( ) )
return ;
2000-12-06 16:32:01 +00:00
// set all the properties we collected
2003-04-15 15:33:07 +00:00
# if OSL_DEBUG_LEVEL > 0
2000-12-06 16:32:01 +00:00
// check if the object has all the properties
// (We do this in the non-pro version only. Doing it all the time would be much to expensive)
2009-04-23 10:42:05 +00:00
if ( m_xInfo . is ( ) )
2000-12-06 16:32:01 +00:00
{
2010-09-24 21:27:18 +02:00
PropertyValueArray : : const_iterator aEnd = m_aValues . end ( ) ;
2004-05-07 14:59:30 +00:00
for ( PropertyValueArray : : iterator aCheck = m_aValues . begin ( ) ;
2009-04-23 10:42:05 +00:00
aCheck ! = aEnd ;
2000-12-06 16:32:01 +00:00
+ + aCheck
)
{
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( m_xInfo - > hasPropertyByName ( aCheck - > Name ) ,
2011-10-05 09:27:07 +01:00
: : rtl : : OStringBuffer ( " OElementImport::implApplySpecificProperties: read a property ( " ) .
append ( rtl : : OUStringToOString ( aCheck - > Name , RTL_TEXTENCODING_ASCII_US ) ) .
append ( " ) which does not exist on the element! " ) . getStr ( ) ) ;
2000-12-06 16:32:01 +00:00
}
}
# endif
// set the properties
2009-04-23 10:42:05 +00:00
const Reference < XMultiPropertySet > xMultiProps ( m_xElement , UNO_QUERY ) ;
2000-12-06 16:32:01 +00:00
sal_Bool bSuccess = sal_False ;
if ( xMultiProps . is ( ) )
{
// translate our properties so that the XMultiPropertySet can handle them
// sort our property value array so that we can use it in a setPropertyValues
: : std : : sort ( m_aValues . begin ( ) , m_aValues . end ( ) , PropertyValueLess ( ) ) ;
// the names
Sequence < : : rtl : : OUString > aNames ( m_aValues . size ( ) ) ;
: : rtl : : OUString * pNames = aNames . getArray ( ) ;
// the values
Sequence < Any > aValues ( m_aValues . size ( ) ) ;
Any * pValues = aValues . getArray ( ) ;
// copy
2009-04-23 10:42:05 +00:00
PropertyValueArray : : iterator aEnd = m_aValues . end ( ) ;
2004-05-07 14:59:30 +00:00
for ( PropertyValueArray : : iterator aPropValues = m_aValues . begin ( ) ;
2009-04-23 10:42:05 +00:00
aPropValues ! = aEnd ;
2000-12-06 16:32:01 +00:00
+ + aPropValues , + + pNames , + + pValues
)
{
* pNames = aPropValues - > Name ;
* pValues = aPropValues - > Value ;
}
try
{
xMultiProps - > setPropertyValues ( aNames , aValues ) ;
bSuccess = sal_True ;
}
catch ( Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)! " ) ;
2000-12-06 16:32:01 +00:00
}
}
if ( ! bSuccess )
{ // no XMultiPropertySet or setting all properties at once failed
2009-04-23 10:42:05 +00:00
PropertyValueArray : : iterator aEnd = m_aValues . end ( ) ;
2004-05-07 14:59:30 +00:00
for ( PropertyValueArray : : iterator aPropValues = m_aValues . begin ( ) ;
2009-04-23 10:42:05 +00:00
aPropValues ! = aEnd ;
2000-12-06 16:32:01 +00:00
+ + aPropValues
)
{
// this try/catch here is expensive, but because this is just a fallback which should normally not be
// used it's acceptable this way ...
try
{
m_xElement - > setPropertyValue ( aPropValues - > Name , aPropValues - > Value ) ;
}
catch ( Exception & )
{
2011-10-05 09:27:07 +01:00
OSL_FAIL ( : : rtl : : OStringBuffer ( " OElementImport::implApplySpecificProperties: could not set the property \" " ) .
append ( rtl : : OUStringToOString ( aPropValues - > Name , RTL_TEXTENCODING_ASCII_US ) ) .
append ( " \" ! " ) . getStr ( ) ) ;
2000-12-06 16:32:01 +00:00
}
}
}
}
2006-07-26 06:32:42 +00:00
//---------------------------------------------------------------------
2010-09-24 21:27:18 +02:00
void OElementImport : : implApplyGenericProperties ( )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
if ( m_aGenericValues . empty ( ) )
return ;
2007-03-09 12:05:34 +00:00
Reference < XPropertyContainer > xDynamicProperties ( m_xElement , UNO_QUERY ) ;
2004-07-13 07:29:16 +00:00
2009-04-23 10:42:05 +00:00
PropertyValueArray : : iterator aEnd = m_aGenericValues . end ( ) ;
2006-07-26 06:32:42 +00:00
for ( PropertyValueArray : : iterator aPropValues =
2004-07-13 07:29:16 +00:00
m_aGenericValues . begin ( ) ;
2009-04-23 10:42:05 +00:00
aPropValues ! = aEnd ;
2004-07-13 07:29:16 +00:00
+ + aPropValues
)
{
// check property type for numeric types before setting
// the property
try
{
2007-03-09 12:05:34 +00:00
// if such a property does not yet exist at the element, create it if necessary
2009-04-23 10:42:05 +00:00
const bool bExistentProperty = m_xInfo - > hasPropertyByName ( aPropValues - > Name ) ;
2007-03-09 12:05:34 +00:00
if ( ! bExistentProperty )
{
if ( ! xDynamicProperties . is ( ) )
{
2008-12-01 12:31:27 +00:00
# if OSL_DEBUG_LEVEL > 0
2010-09-24 21:27:18 +02:00
: : rtl : : OString aMessage ( " OElementImport::implApplyGenericProperties: encountered an unknown property ( " ) ;
2008-12-01 12:31:27 +00:00
aMessage + = : : rtl : : OUStringToOString ( aPropValues - > Name , RTL_TEXTENCODING_ASCII_US ) ;
aMessage + = " ), but component is no PropertyBag! " ;
2011-03-12 14:27:45 +01:00
OSL_FAIL ( aMessage . getStr ( ) ) ;
2008-12-01 12:31:27 +00:00
# endif
2007-03-09 12:05:34 +00:00
continue ;
}
xDynamicProperties - > addProperty (
aPropValues - > Name ,
PropertyAttribute : : BOUND | PropertyAttribute : : REMOVEABLE ,
aPropValues - > Value
) ;
// re-fetch the PropertySetInfo
2009-04-23 10:42:05 +00:00
m_xInfo = m_xElement - > getPropertySetInfo ( ) ;
2007-03-09 12:05:34 +00:00
}
2010-09-15 13:55:34 +02:00
// determine the type of the value (source for the following conversion)
2006-07-26 06:32:42 +00:00
TypeClass eValueTypeClass = aPropValues - > Value . getValueTypeClass ( ) ;
2009-04-23 10:42:05 +00:00
const sal_Bool bValueIsSequence = TypeClass_SEQUENCE = = eValueTypeClass ;
2006-07-26 06:32:42 +00:00
if ( bValueIsSequence )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
uno : : Type aSimpleType ( getSequenceElementType ( aPropValues - > Value . getValueType ( ) ) ) ;
2004-07-13 07:29:16 +00:00
eValueTypeClass = aSimpleType . getTypeClass ( ) ;
}
2010-09-15 13:55:34 +02:00
// determine the type of the property (target for the following conversion)
2009-04-23 10:42:05 +00:00
const Property aProperty ( m_xInfo - > getPropertyByName ( aPropValues - > Name ) ) ;
2006-07-26 06:32:42 +00:00
TypeClass ePropTypeClass = aProperty . Type . getTypeClass ( ) ;
2009-04-23 10:42:05 +00:00
const sal_Bool bPropIsSequence = TypeClass_SEQUENCE = = ePropTypeClass ;
2006-07-26 06:32:42 +00:00
if ( bPropIsSequence )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
uno : : Type aSimpleType ( : : comphelper : : getSequenceElementType ( aProperty . Type ) ) ;
ePropTypeClass = aSimpleType . getTypeClass ( ) ;
}
if ( bPropIsSequence ! = bValueIsSequence )
{
2011-03-12 14:27:45 +01:00
OSL_FAIL ( " OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them! " ) ;
2006-07-26 06:32:42 +00:00
continue ;
}
if ( bValueIsSequence )
{
OSL_ENSURE ( eValueTypeClass = = TypeClass_ANY ,
2010-09-24 21:27:18 +02:00
" OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property! " ) ;
2006-07-26 06:32:42 +00:00
// (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
OSL_ENSURE ( ePropTypeClass = = TypeClass_SHORT ,
2010-09-24 21:27:18 +02:00
" OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet! " ) ;
2006-07-26 06:32:42 +00:00
Sequence < Any > aXMLValueList ;
aPropValues - > Value > > = aXMLValueList ;
Sequence < sal_Int16 > aPropertyValueList ( aXMLValueList . getLength ( ) ) ;
const Any * pXMLValue = aXMLValueList . getConstArray ( ) ;
sal_Int16 * pPropValue = aPropertyValueList . getArray ( ) ;
for ( sal_Int32 i = 0 ; i < aXMLValueList . getLength ( ) ; + + i , + + pXMLValue , + + pPropValue )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
// only value sequences of numeric types implemented so far.
double nVal ( 0 ) ;
OSL_VERIFY ( * pXMLValue > > = nVal ) ;
* pPropValue = static_cast < sal_Int16 > ( nVal ) ;
2004-07-13 07:29:16 +00:00
}
2006-07-26 06:32:42 +00:00
aPropValues - > Value < < = aPropertyValueList ;
2004-07-13 07:29:16 +00:00
}
2006-07-26 06:32:42 +00:00
else if ( ePropTypeClass ! = eValueTypeClass )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
switch ( eValueTypeClass )
2004-07-13 07:29:16 +00:00
{
2006-07-26 06:32:42 +00:00
case TypeClass_DOUBLE :
{
2006-11-21 16:34:29 +00:00
double nVal = 0 ;
2006-07-26 06:32:42 +00:00
aPropValues - > Value > > = nVal ;
switch ( ePropTypeClass )
{
case TypeClass_BYTE :
aPropValues - > Value < < = static_cast < sal_Int8 > ( nVal ) ;
break ;
case TypeClass_SHORT :
aPropValues - > Value < < = static_cast < sal_Int16 > ( nVal ) ;
break ;
case TypeClass_LONG :
case TypeClass_ENUM :
aPropValues - > Value < < = static_cast < sal_Int32 > ( nVal ) ;
break ;
case TypeClass_HYPER :
aPropValues - > Value < < = static_cast < sal_Int64 > ( nVal ) ;
break ;
default :
2011-03-12 14:27:45 +01:00
OSL_FAIL ( " OElementImport::implImportGenericProperties: unsupported value type! " ) ;
2006-07-26 06:32:42 +00:00
break ;
}
}
break ;
2006-06-19 17:17:05 +00:00
default :
2011-03-12 14:27:45 +01:00
OSL_FAIL ( " OElementImport::implImportGenericProperties: non-double values not supported! " ) ;
2006-06-19 17:17:05 +00:00
break ;
2004-07-13 07:29:16 +00:00
}
}
2007-03-09 12:05:34 +00:00
m_xElement - > setPropertyValue ( aPropValues - > Name , aPropValues - > Value ) ;
2004-07-13 07:29:16 +00:00
}
catch ( Exception & )
{
2011-10-05 09:27:07 +01:00
OSL_FAIL ( : : rtl : : OStringBuffer ( " OElementImport::EndElement: could not set the property \" " ) .
append ( : : rtl : : OUStringToOString ( aPropValues - > Name , RTL_TEXTENCODING_ASCII_US ) ) .
append ( " \" ! " ) . getStr ( ) ) ;
2004-07-13 07:29:16 +00:00
}
}
}
2000-12-06 16:32:01 +00:00
//---------------------------------------------------------------------
: : rtl : : OUString OElementImport : : implGetDefaultName ( ) const
{
// no optimization here. If this method gets called, the XML stream did not contain a name for the
// element, which is a heavy error. So in this case we don't care for performance
2010-11-21 15:43:10 +01:00
static const : : rtl : : OUString sUnnamedName ( RTL_CONSTASCII_USTRINGPARAM ( " unnamed " ) ) ;
2011-11-24 17:40:44 +01:00
OSL_ENSURE ( m_xParentContainer . is ( ) , " OElementImport::implGetDefaultName: no parent container! " ) ;
if ( ! m_xParentContainer . is ( ) )
return sUnnamedName ;
Sequence < : : rtl : : OUString > aNames = m_xParentContainer - > getElementNames ( ) ;
2000-12-06 16:32:01 +00:00
: : rtl : : OUString sReturn ;
const : : rtl : : OUString * pNames = NULL ;
const : : rtl : : OUString * pNamesEnd = aNames . getConstArray ( ) + aNames . getLength ( ) ;
for ( sal_Int32 i = 0 ; i < 32768 ; + + i ) // the limit is nearly arbitrary ...
{
// assemble the new name (suggestion)
sReturn = sUnnamedName ;
sReturn + = : : rtl : : OUString : : valueOf ( i ) ;
// check the existence (this is the bad performance part ....)
for ( pNames = aNames . getConstArray ( ) ; pNames < pNamesEnd ; + + pNames )
{
if ( * pNames = = sReturn )
{
break ;
}
}
if ( pNames < pNamesEnd )
// found the name
continue ;
return sReturn ;
}
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OElementImport::implGetDefaultName: did not find a free name! " ) ;
2000-12-06 16:32:01 +00:00
return sUnnamedName ;
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
PropertyGroups : : const_iterator OElementImport : : impl_matchPropertyGroup ( const PropertyGroups & i_propertyGroups ) const
2000-12-06 16:32:01 +00:00
{
2010-09-15 13:55:34 +02:00
ENSURE_OR_RETURN ( m_xInfo . is ( ) , " OElementImport::impl_matchPropertyGroup: no property set info! " , i_propertyGroups . end ( ) ) ;
for ( PropertyGroups : : const_iterator group = i_propertyGroups . begin ( ) ;
group ! = i_propertyGroups . end ( ) ;
+ + group
)
{
bool missingProp = false ;
for ( PropertyDescriptionList : : const_iterator prop = group - > begin ( ) ;
prop ! = group - > end ( ) ;
+ + prop
)
{
if ( ! m_xInfo - > hasPropertyByName ( ( * prop ) - > propertyName ) )
{
missingProp = true ;
break ;
}
}
2004-07-13 07:29:16 +00:00
2010-09-15 13:55:34 +02:00
if ( missingProp )
// try next group
continue ;
return group ;
2000-12-06 16:32:01 +00:00
}
2010-09-15 13:55:34 +02:00
return i_propertyGroups . end ( ) ;
}
//---------------------------------------------------------------------
2010-09-24 15:57:20 +02:00
bool OElementImport : : tryGenericAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2000-12-06 16:32:01 +00:00
{
2010-09-15 13:55:34 +02:00
// the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
const AttributeDescription attribute ( metadata : : getAttributeDescription ( _nNamespaceKey , _rLocalName ) ) ;
if ( attribute . attributeToken ! = XML_TOKEN_INVALID )
{
PropertyGroups propertyGroups ;
metadata : : getPropertyGroupList ( attribute , propertyGroups ) ;
const PropertyGroups : : const_iterator pos = impl_matchPropertyGroup ( propertyGroups ) ;
if ( pos = = propertyGroups . end ( ) )
2010-09-24 15:57:20 +02:00
return false ;
2004-07-13 07:29:16 +00:00
2010-09-15 13:55:34 +02:00
do
2002-10-25 12:19:34 +00:00
{
2010-09-15 13:55:34 +02:00
const PropertyDescriptionList & rProperties ( * pos ) ;
const PropertyDescription * first = * rProperties . begin ( ) ;
2012-01-15 11:30:24 +01:00
if ( ! first )
{
SAL_WARN ( " xmloff.forms " , " OElementImport::handleAttribute: invalid property description! " ) ;
break ;
}
2010-09-15 13:55:34 +02:00
const PPropertyHandler handler = ( * first - > factory ) ( first - > propertyId ) ;
2012-01-15 11:30:24 +01:00
if ( ! handler . get ( ) )
{
SAL_WARN ( " xmloff.forms " , " OElementImport::handleAttribute: invalid property handler! " ) ;
break ;
}
2010-09-15 13:55:34 +02:00
PropertyValues aValues ;
for ( PropertyDescriptionList : : const_iterator propDesc = rProperties . begin ( ) ;
propDesc ! = rProperties . end ( ) ;
+ + propDesc
)
{
aValues [ ( * propDesc ) - > propertyId ] = Any ( ) ;
}
if ( handler - > getPropertyValues ( _rValue , aValues ) )
{
for ( PropertyDescriptionList : : const_iterator propDesc = rProperties . begin ( ) ;
propDesc ! = rProperties . end ( ) ;
+ + propDesc
)
{
implPushBackPropertyValue ( ( * propDesc ) - > propertyName , aValues [ ( * propDesc ) - > propertyId ] ) ;
}
}
2002-10-25 12:19:34 +00:00
}
2010-09-15 13:55:34 +02:00
while ( false ) ;
// handled
return true ;
2000-12-06 16:32:01 +00:00
}
2010-09-24 15:57:20 +02:00
return false ;
}
//---------------------------------------------------------------------
bool OElementImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
{
if ( token : : IsXMLToken ( _rLocalName , token : : XML_CONTROL_IMPLEMENTATION ) )
// ignore this, it has already been handled in OElementImport::StartElement
return true ;
if ( token : : IsXMLToken ( _rLocalName , token : : XML_NAME ) )
2000-12-06 16:32:01 +00:00
{
2012-01-25 21:59:48 -02:00
if ( m_sName . isEmpty ( ) )
2000-12-06 16:32:01 +00:00
// remember the name for later use in EndElement
m_sName = _rValue ;
2010-09-24 15:57:20 +02:00
return true ;
}
2000-12-06 16:32:01 +00:00
2010-09-24 15:57:20 +02:00
// maybe it's the style attribute?
if ( token : : IsXMLToken ( _rLocalName , token : : XML_TEXT_STYLE_NAME ) )
{
const SvXMLStyleContext * pStyleContext = m_rContext . getStyleElement ( _rValue ) ;
OSL_ENSURE ( pStyleContext , " OElementImport::handleAttribute: do not know the style! " ) ;
// remember the element for later usage.
m_pStyleElement = PTR_CAST ( XMLTextStyleContext , pStyleContext ) ;
return true ;
2000-12-06 16:32:01 +00:00
}
2010-09-24 15:57:20 +02:00
if ( m_bImplicitGenericAttributeHandling )
if ( tryGenericAttribute ( _nNamespaceKey , _rLocalName , _rValue ) )
return true ;
2010-09-15 13:55:34 +02:00
// let the base class handle it
return OPropertyImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
Reference < XPropertySet > OElementImport : : createElement ( )
{
Reference < XPropertySet > xReturn ;
2012-01-25 21:59:48 -02:00
if ( ! m_sServiceName . isEmpty ( ) )
2000-12-06 16:32:01 +00:00
{
2009-04-23 10:42:05 +00:00
Reference < XInterface > xPure = m_rFormImport . getGlobalContext ( ) . getServiceFactory ( ) - > createInstance ( m_sServiceName ) ;
2000-12-06 16:32:01 +00:00
OSL_ENSURE ( xPure . is ( ) ,
2011-10-05 09:27:07 +01:00
: : rtl : : OStringBuffer ( " OElementImport::createElement: service factory gave me no object (service name: " ) . append ( rtl : : OUStringToOString ( m_sServiceName , RTL_TEXTENCODING_ASCII_US ) ) . append ( " )! " ) . getStr ( ) ) ;
2000-12-06 16:32:01 +00:00
xReturn = Reference < XPropertySet > ( xPure , UNO_QUERY ) ;
}
else
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OElementImport::createElement: no service name to create an element! " ) ;
2000-12-06 16:32:01 +00:00
return xReturn ;
}
2001-01-02 14:58:22 +00:00
//---------------------------------------------------------------------
void OElementImport : : registerEvents ( const Sequence < ScriptEventDescriptor > & _rEvents )
{
OSL_ENSURE ( m_xElement . is ( ) , " OElementImport::registerEvents: no element to register events for! " ) ;
m_rEventManager . registerEvents ( m_xElement , _rEvents ) ;
}
2003-03-27 17:21:03 +00:00
//---------------------------------------------------------------------
void OElementImport : : simulateDefaultedAttribute ( const sal_Char * _pAttributeName , const : : rtl : : OUString & _rPropertyName , const sal_Char * _pAttributeDefault )
{
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( m_xInfo . is ( ) , " OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties! " ) ;
2003-03-27 17:21:03 +00:00
2009-04-23 10:42:05 +00:00
if ( ! m_xInfo . is ( ) | | m_xInfo - > hasPropertyByName ( _rPropertyName ) )
2003-03-27 17:21:03 +00:00
{
: : rtl : : OUString sLocalAttrName = : : rtl : : OUString : : createFromAscii ( _pAttributeName ) ;
if ( ! encounteredAttribute ( sLocalAttrName ) )
2010-09-15 13:55:34 +02:00
OSL_VERIFY ( handleAttribute ( XML_NAMESPACE_FORM , sLocalAttrName , : : rtl : : OUString : : createFromAscii ( _pAttributeDefault ) ) ) ;
2003-03-27 17:21:03 +00:00
}
}
2000-12-06 16:32:01 +00:00
//=====================================================================
//= OControlImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OControlImport : : OControlImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer )
2001-01-02 14:58:22 +00:00
: OElementImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer )
2000-12-12 11:01:05 +00:00
, m_eElementType ( OControlElement : : UNKNOWN )
{
2010-09-24 15:57:20 +02:00
disableImplicitGenericAttributeHandling ( ) ;
2000-12-12 11:01:05 +00:00
}
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OControlImport : : OControlImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer , OControlElement : : ElementType _eType )
2001-01-02 14:58:22 +00:00
: OElementImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer )
2000-12-12 11:01:05 +00:00
, m_eElementType ( _eType )
2000-12-06 16:32:01 +00:00
{
2010-09-24 15:57:20 +02:00
disableImplicitGenericAttributeHandling ( ) ;
2000-12-06 16:32:01 +00:00
}
2010-09-15 13:55:34 +02:00
//---------------------------------------------------------------------
: : rtl : : OUString OControlImport : : determineDefaultServiceName ( ) const
{
const sal_Char * pServiceName = NULL ;
switch ( m_eElementType )
{
case OControlElement : : TEXT :
case OControlElement : : TEXT_AREA :
case OControlElement : : PASSWORD : pServiceName = " com.sun.star.form.component.TextField " ; break ;
case OControlElement : : FILE : pServiceName = " com.sun.star.form.component.FileControl " ; break ;
case OControlElement : : FORMATTED_TEXT : pServiceName = " com.sun.star.form.component.FormattedField " ; break ;
case OControlElement : : FIXED_TEXT : pServiceName = " com.sun.star.form.component.FixedText " ; break ;
case OControlElement : : COMBOBOX : pServiceName = " com.sun.star.form.component.ComboBox " ; break ;
case OControlElement : : LISTBOX : pServiceName = " com.sun.star.form.component.ListBox " ; break ;
case OControlElement : : BUTTON : pServiceName = " com.sun.star.form.component.CommandButton " ; break ;
case OControlElement : : IMAGE : pServiceName = " com.sun.star.form.component.ImageButton " ; break ;
case OControlElement : : CHECKBOX : pServiceName = " com.sun.star.form.component.CheckBox " ; break ;
case OControlElement : : RADIO : pServiceName = " com.sun.star.form.component.RadioButton " ; break ;
case OControlElement : : FRAME : pServiceName = " com.sun.star.form.component.GroupBox " ; break ;
case OControlElement : : IMAGE_FRAME : pServiceName = " com.sun.star.form.component.DatabaseImageControl " ; break ;
case OControlElement : : HIDDEN : pServiceName = " com.sun.star.form.component.HiddenControl " ; break ;
case OControlElement : : GRID : pServiceName = " com.sun.star.form.component.GridControl " ; break ;
case OControlElement : : TIME : pServiceName = " com.sun.star.form.component.DateField " ; break ;
case OControlElement : : DATE : pServiceName = " com.sun.star.form.component.TimeField " ; break ;
2010-09-16 09:02:54 +02:00
default : break ;
2010-09-15 13:55:34 +02:00
}
if ( pServiceName ! = NULL )
return : : rtl : : OUString : : createFromAscii ( pServiceName ) ;
return : : rtl : : OUString ( ) ;
2000-12-06 16:32:01 +00:00
}
2001-01-03 15:25:34 +00:00
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OControlImport : : addOuterAttributes ( const Reference < XAttributeList > & _rxOuterAttribs )
2001-01-03 15:25:34 +00:00
{
OSL_ENSURE ( ! m_xOuterAttributes . is ( ) , " OControlImport::addOuterAttributes: already have these attributes! " ) ;
m_xOuterAttributes = _rxOuterAttribs ;
}
2000-12-06 16:32:01 +00:00
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OControlImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2000-12-06 16:32:01 +00:00
{
2009-04-23 10:42:05 +00:00
static const sal_Char * pLinkedCellAttributeName = OAttributeMetaData : : getBindingAttributeName ( BA_LINKED_CELL ) ;
2010-04-19 18:27:16 +02:00
if ( IsXMLToken ( _rLocalName , XML_ID ) )
2000-12-06 16:32:01 +00:00
{ // it's the control id
2010-04-19 18:27:16 +02:00
if ( XML_NAMESPACE_XML = = _nNamespaceKey )
{
m_sControlId = _rValue ;
}
else if ( XML_NAMESPACE_FORM = = _nNamespaceKey )
{
2012-01-25 21:59:48 -02:00
if ( m_sControlId . isEmpty ( ) )
2010-04-19 18:27:16 +02:00
{
m_sControlId = _rValue ;
}
}
2010-09-15 13:55:34 +02:00
return true ;
2000-12-06 16:32:01 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _rLocalName . equalsAscii ( pLinkedCellAttributeName ) )
2004-07-05 15:07:58 +00:00
{ // it's the address of a spreadsheet cell
2003-10-21 07:38:38 +00:00
m_sBoundCellAddress = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
2003-10-21 07:38:38 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _nNamespaceKey = = XML_NAMESPACE_XFORMS & & IsXMLToken ( _rLocalName , XML_BIND ) )
2004-11-16 09:09:27 +00:00
{
m_sBindingID = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
2004-11-16 09:09:27 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _nNamespaceKey = = XML_NAMESPACE_FORM & & IsXMLToken ( _rLocalName , XML_XFORMS_LIST_SOURCE ) )
2004-11-16 09:09:27 +00:00
{
m_sListBindingID = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
2004-11-16 09:09:27 +00:00
}
2010-09-15 13:55:34 +02:00
if ( ( ( _nNamespaceKey = = XML_NAMESPACE_FORM )
& & IsXMLToken ( _rLocalName , XML_XFORMS_SUBMISSION )
)
| | ( ( _nNamespaceKey = = XML_NAMESPACE_XFORMS )
& & IsXMLToken ( _rLocalName , XML_SUBMISSION )
)
)
2004-11-16 09:09:27 +00:00
{
m_sSubmissionID = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
2004-11-16 09:09:27 +00:00
}
2010-09-15 13:55:34 +02:00
2010-09-24 15:57:20 +02:00
if ( OElementImport : : tryGenericAttribute ( _nNamespaceKey , _rLocalName , _rValue ) )
2010-09-15 13:55:34 +02:00
return true ;
static const sal_Char * pValueAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_VALUE ) ;
static const sal_Char * pCurrentValueAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_CURRENT_VALUE ) ;
static const sal_Char * pMinValueAttributeName = OAttributeMetaData : : getSpecialAttributeName ( SCA_MIN_VALUE ) ;
static const sal_Char * pMaxValueAttributeName = OAttributeMetaData : : getSpecialAttributeName ( SCA_MAX_VALUE ) ;
static const sal_Char * pRepeatDelayAttributeName = OAttributeMetaData : : getSpecialAttributeName ( SCA_REPEAT_DELAY ) ;
sal_Int32 nHandle = - 1 ;
if ( _rLocalName . equalsAscii ( pValueAttributeName ) )
nHandle = PROPID_VALUE ;
else if ( _rLocalName . equalsAscii ( pCurrentValueAttributeName ) )
nHandle = PROPID_CURRENT_VALUE ;
else if ( _rLocalName . equalsAscii ( pMinValueAttributeName ) )
nHandle = PROPID_MIN_VALUE ;
else if ( _rLocalName . equalsAscii ( pMaxValueAttributeName ) )
nHandle = PROPID_MAX_VALUE ;
if ( nHandle ! = - 1 )
2000-12-13 09:40:15 +00:00
{
2010-09-15 13:55:34 +02:00
// for the moment, simply remember the name and the value
PropertyValue aProp ;
aProp . Name = _rLocalName ;
aProp . Handle = nHandle ;
aProp . Value < < = _rValue ;
m_aValueProperties . push_back ( aProp ) ;
return true ;
}
if ( _rLocalName . equalsAscii ( pRepeatDelayAttributeName ) )
2000-12-13 09:40:15 +00:00
{
2011-10-11 14:19:08 +02:00
util : : Duration aDuration ;
if ( : : sax : : Converter : : convertDuration ( aDuration , _rValue ) )
2000-12-13 09:40:15 +00:00
{
PropertyValue aProp ;
2010-09-15 13:55:34 +02:00
aProp . Name = PROPERTY_REPEAT_DELAY ;
2011-10-11 14:19:08 +02:00
sal_Int32 const nMS =
( ( aDuration . Hours * 60 + aDuration . Minutes ) * 60
+ aDuration . Seconds ) * 1000 + aDuration . MilliSeconds ;
aProp . Value < < = nMS ;
2004-11-26 12:01:35 +00:00
2010-09-15 13:55:34 +02:00
implPushBackPropertyValue ( aProp ) ;
2004-11-26 12:01:35 +00:00
}
2010-09-15 13:55:34 +02:00
return true ;
2000-12-13 09:40:15 +00:00
}
2010-09-15 13:55:34 +02:00
2010-09-24 15:57:20 +02:00
return OElementImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-13 09:40:15 +00:00
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OControlImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2000-12-13 09:40:15 +00:00
{
2004-07-13 07:29:16 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : xml : : sax : : XAttributeList > xAttributes ;
if ( m_xOuterAttributes . is ( ) )
{
// merge the attribute lists
OAttribListMerger * pMerger = new OAttribListMerger ;
// our own one
pMerger - > addList ( _rxAttrList ) ;
// and the ones of our enclosing element
pMerger - > addList ( m_xOuterAttributes ) ;
xAttributes = pMerger ;
}
else
{
xAttributes = _rxAttrList ;
}
2001-01-03 15:25:34 +00:00
2000-12-13 09:40:15 +00:00
// let the base class handle all the attributes
2001-01-03 15:25:34 +00:00
OElementImport : : StartElement ( xAttributes ) ;
2000-12-13 09:40:15 +00:00
2009-04-23 10:42:05 +00:00
if ( ! m_aValueProperties . empty ( ) & & m_xElement . is ( ) )
2000-12-13 09:40:15 +00:00
{
// get the property set info
2009-04-23 10:42:05 +00:00
if ( ! m_xInfo . is ( ) )
2000-12-13 09:40:15 +00:00
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OControlImport::StartElement: no PropertySetInfo! " ) ;
2000-12-13 09:40:15 +00:00
return ;
}
const sal_Char * pValueProperty = NULL ;
const sal_Char * pCurrentValueProperty = NULL ;
const sal_Char * pMinValueProperty = NULL ;
const sal_Char * pMaxValueProperty = NULL ;
sal_Bool bRetrievedValues = sal_False ;
sal_Bool bRetrievedValueLimits = sal_False ;
// get the class id of our element
sal_Int16 nClassId = FormComponentType : : CONTROL ;
m_xElement - > getPropertyValue ( PROPERTY_CLASSID ) > > = nClassId ;
// translate the value properties we collected in handleAttributes
2009-04-23 10:42:05 +00:00
PropertyValueArray : : iterator aEnd = m_aValueProperties . end ( ) ;
2004-05-07 14:59:30 +00:00
for ( PropertyValueArray : : iterator aValueProps = m_aValueProperties . begin ( ) ;
2009-04-23 10:42:05 +00:00
aValueProps ! = aEnd ;
2000-12-13 09:40:15 +00:00
+ + aValueProps
)
{
2010-11-01 11:34:47 +01:00
bool bSuccess = false ;
2000-12-13 09:40:15 +00:00
switch ( aValueProps - > Handle )
{
case PROPID_VALUE :
case PROPID_CURRENT_VALUE :
{
// get the property names
if ( ! bRetrievedValues )
{
getValuePropertyNames ( m_eElementType , nClassId , pCurrentValueProperty , pValueProperty ) ;
2012-01-15 11:30:24 +01:00
if ( ! pCurrentValueProperty & & ! pValueProperty )
{
SAL_WARN ( " xmloff.forms " , " OControlImport::StartElement: illegal value property names! " ) ;
break ;
}
2000-12-13 09:40:15 +00:00
bRetrievedValues = sal_True ;
}
2012-01-15 11:30:24 +01:00
if ( PROPID_VALUE = = aValueProps - > Handle & & ! pValueProperty )
{
SAL_WARN ( " xmloff.forms " , " OControlImport::StartElement: the control does not have a value property! " ) ;
break ;
}
if ( PROPID_CURRENT_VALUE = = aValueProps - > Handle & & ! pCurrentValueProperty )
{
SAL_WARN ( " xmloff.forms " , " OControlImport::StartElement: the control does not have a current-value property! " ) ;
break ;
}
2000-12-13 09:40:15 +00:00
// transfer the name
if ( PROPID_VALUE = = aValueProps - > Handle )
aValueProps - > Name = : : rtl : : OUString : : createFromAscii ( pValueProperty ) ;
else
aValueProps - > Name = : : rtl : : OUString : : createFromAscii ( pCurrentValueProperty ) ;
2010-11-01 11:34:47 +01:00
bSuccess = true ;
2000-12-13 09:40:15 +00:00
}
break ;
case PROPID_MIN_VALUE :
case PROPID_MAX_VALUE :
{
// get the property names
if ( ! bRetrievedValueLimits )
{
getValueLimitPropertyNames ( nClassId , pMinValueProperty , pMaxValueProperty ) ;
2012-01-15 11:30:24 +01:00
if ( ! pMinValueProperty | | ! pMaxValueProperty )
{
SAL_WARN ( " xmloff.forms " , " OControlImport::StartElement: illegal value limit property names! " ) ;
break ;
}
2000-12-13 09:40:15 +00:00
bRetrievedValueLimits = sal_True ;
}
OSL_ENSURE ( ( PROPID_MIN_VALUE ! = aValueProps - > Handle ) | | pMinValueProperty ,
" OControlImport::StartElement: the control does not have a value property! " ) ;
OSL_ENSURE ( ( PROPID_MAX_VALUE ! = aValueProps - > Handle ) | | pMaxValueProperty ,
" OControlImport::StartElement: the control does not have a current-value property! " ) ;
// transfer the name
if ( PROPID_MIN_VALUE = = aValueProps - > Handle )
aValueProps - > Name = : : rtl : : OUString : : createFromAscii ( pMinValueProperty ) ;
else
aValueProps - > Name = : : rtl : : OUString : : createFromAscii ( pMaxValueProperty ) ;
2010-11-01 11:34:47 +01:00
bSuccess = true ;
2000-12-13 09:40:15 +00:00
}
break ;
}
2010-11-01 11:34:47 +01:00
if ( ! bSuccess )
continue ;
2000-12-13 09:40:15 +00:00
// translate the value
2009-04-23 10:42:05 +00:00
implTranslateValueProperty ( m_xInfo , * aValueProps ) ;
2000-12-13 09:40:15 +00:00
// add the property to the base class' array
implPushBackPropertyValue ( * aValueProps ) ;
}
}
}
//---------------------------------------------------------------------
void OControlImport : : implTranslateValueProperty ( const Reference < XPropertySetInfo > & _rxPropInfo ,
PropertyValue & _rPropValue )
{
OSL_ENSURE ( _rxPropInfo - > hasPropertyByName ( _rPropValue . Name ) ,
" OControlImport::implTranslateValueProperty: invalid property name! " ) ;
// retrieve the type of the property
Property aProp = _rxPropInfo - > getPropertyByName ( _rPropValue . Name ) ;
// the untranslated string value as read in handleAttribute
: : rtl : : OUString sValue ;
2003-04-15 15:33:07 +00:00
# if OSL_DEBUG_LEVEL > 0
2000-12-13 09:40:15 +00:00
sal_Bool bSuccess =
# endif
_rPropValue . Value > > = sValue ;
OSL_ENSURE ( bSuccess , " OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values! " ) ;
2001-05-17 11:40:01 +00:00
if ( TypeClass_ANY = = aProp . Type . getTypeClass ( ) )
{
// we have exactly 2 properties where this type class is allowed:
OSL_ENSURE (
2012-05-17 14:51:04 +01:00
( 0 = = _rPropValue . Name . equalsAsciiL ( PROPERTY_EFFECTIVE_VALUE . ascii , PROPERTY_EFFECTIVE_VALUE . length ) )
| | ( 0 = = _rPropValue . Name . equalsAsciiL ( PROPERTY_EFFECTIVE_DEFAULT . ascii , PROPERTY_EFFECTIVE_DEFAULT . length ) ) ,
2001-05-17 11:40:01 +00:00
" OControlImport::implTranslateValueProperty: invalid property type/name combination! " ) ;
// Both properties are allowed to have a double or a string value,
// so first try to convert the string into a number
double nValue ;
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
if ( : : sax : : Converter : : convertDouble ( nValue , sValue ) )
2001-05-17 11:40:01 +00:00
_rPropValue . Value < < = nValue ;
else
_rPropValue . Value < < = sValue ;
}
else
2006-07-26 06:32:42 +00:00
_rPropValue . Value = PropertyConversion : : convertString ( GetImport ( ) , aProp . Type , sValue ) ;
2000-12-06 16:32:01 +00:00
}
2000-12-12 11:01:05 +00:00
//---------------------------------------------------------------------
void OControlImport : : EndElement ( )
{
OSL_ENSURE ( m_xElement . is ( ) , " OControlImport::EndElement: invalid control! " ) ;
2002-09-09 12:55:30 +00:00
if ( ! m_xElement . is ( ) )
return ;
2000-12-12 11:01:05 +00:00
// register our control with it's id
2012-01-25 21:59:48 -02:00
if ( ! m_sControlId . isEmpty ( ) )
2009-04-23 10:42:05 +00:00
m_rFormImport . registerControlId ( m_xElement , m_sControlId ) ;
2000-12-12 11:01:05 +00:00
// it's allowed to have no control id. In this case we're importing a column
2002-09-09 12:55:30 +00:00
// one more pre-work to do:
// when we set default values, then by definition the respective value is set
// to this default value, too. This means if the sequence contains for example
// a DefaultText value, then the Text will be affected by this, too.
// In case the Text is not part of the property sequence (or occurs _before_
// the DefaultText, which can happen for other value/default-value property names),
// this means that the Text (the value property) is incorrectly imported.
sal_Bool bRestoreValuePropertyValue = sal_False ;
Any aValuePropertyValue ;
sal_Int16 nClassId = FormComponentType : : CONTROL ;
try
{
// get the class id of our element
m_xElement - > getPropertyValue ( PROPERTY_CLASSID ) > > = nClassId ;
}
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OControlImport::EndElement: caught an exception while retrieving the class id! " ) ;
2002-09-09 12:55:30 +00:00
}
const sal_Char * pValueProperty = NULL ;
const sal_Char * pDefaultValueProperty = NULL ;
getRuntimeValuePropertyNames ( m_eElementType , nClassId , pValueProperty , pDefaultValueProperty ) ;
if ( pDefaultValueProperty & & pValueProperty )
{
sal_Bool bNonDefaultValuePropertyValue = sal_False ;
// is the "value property" part of the sequence?
// look up this property in our sequence
2009-04-23 10:42:05 +00:00
PropertyValueArray : : iterator aEnd = m_aValues . end ( ) ;
2004-05-07 14:59:30 +00:00
for ( PropertyValueArray : : iterator aCheck = m_aValues . begin ( ) ;
2009-04-23 10:42:05 +00:00
( aCheck ! = aEnd ) ;
2002-09-09 12:55:30 +00:00
+ + aCheck
)
{
if ( aCheck - > Name . equalsAscii ( pDefaultValueProperty ) )
bRestoreValuePropertyValue = sal_True ;
else if ( aCheck - > Name . equalsAscii ( pValueProperty ) )
{
bNonDefaultValuePropertyValue = sal_True ;
// we need to restore the value property we found here, nothing else
aValuePropertyValue = aCheck - > Value ;
}
}
if ( bRestoreValuePropertyValue & & ! bNonDefaultValuePropertyValue )
{
// found it -> need to remember (and restore) the "value property value", which is not set explicitly
try
{
aValuePropertyValue = m_xElement - > getPropertyValue ( : : rtl : : OUString : : createFromAscii ( pValueProperty ) ) ;
}
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OControlImport::EndElement: caught an exception while retrieving the current value property! " ) ;
2002-09-09 12:55:30 +00:00
}
}
}
// let the base class set all the values
2000-12-12 11:01:05 +00:00
OElementImport : : EndElement ( ) ;
2002-09-09 12:55:30 +00:00
// restore the "value property value", if necessary
if ( bRestoreValuePropertyValue & & pValueProperty )
{
try
{
m_xElement - > setPropertyValue ( : : rtl : : OUString : : createFromAscii ( pValueProperty ) , aValuePropertyValue ) ;
}
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OControlImport::EndElement: caught an exception while restoring the value property! " ) ;
2002-09-09 12:55:30 +00:00
}
}
2003-10-21 07:38:38 +00:00
// the external cell binding, if applicable
2012-01-25 21:59:48 -02:00
if ( m_xElement . is ( ) & & ! m_sBoundCellAddress . isEmpty ( ) )
2003-10-21 07:38:38 +00:00
doRegisterCellValueBinding ( m_sBoundCellAddress ) ;
2004-11-16 09:09:27 +00:00
// XForms binding, if applicable
2012-01-25 21:59:48 -02:00
if ( m_xElement . is ( ) & & ! m_sBindingID . isEmpty ( ) )
2004-11-16 09:09:27 +00:00
doRegisterXFormsValueBinding ( m_sBindingID ) ;
// XForms list binding, if applicable
2012-01-25 21:59:48 -02:00
if ( m_xElement . is ( ) & & ! m_sListBindingID . isEmpty ( ) )
2004-11-16 09:09:27 +00:00
doRegisterXFormsListBinding ( m_sListBindingID ) ;
// XForms submission, if applicable
2012-01-25 21:59:48 -02:00
if ( m_xElement . is ( ) & & ! m_sSubmissionID . isEmpty ( ) )
2004-11-16 09:09:27 +00:00
doRegisterXFormsSubmission ( m_sSubmissionID ) ;
2003-10-21 07:38:38 +00:00
}
//---------------------------------------------------------------------
void OControlImport : : doRegisterCellValueBinding ( const : : rtl : : OUString & _rBoundCellAddress )
{
OSL_PRECOND ( m_xElement . is ( ) , " OControlImport::doRegisterCellValueBinding: invalid element! " ) ;
2012-01-25 21:59:48 -02:00
OSL_PRECOND ( ! _rBoundCellAddress . isEmpty ( ) ,
2003-10-21 07:38:38 +00:00
" OControlImport::doRegisterCellValueBinding: invalid address! " ) ;
m_rContext . registerCellValueBinding ( m_xElement , _rBoundCellAddress ) ;
2000-12-12 11:01:05 +00:00
}
2004-11-16 09:09:27 +00:00
//---------------------------------------------------------------------
void OControlImport : : doRegisterXFormsValueBinding ( const : : rtl : : OUString & _rBindingID )
{
OSL_PRECOND ( m_xElement . is ( ) , " need element " ) ;
2012-01-25 21:59:48 -02:00
OSL_PRECOND ( ! _rBindingID . isEmpty ( ) , " binding ID is not valid " ) ;
2004-11-16 09:09:27 +00:00
m_rContext . registerXFormsValueBinding ( m_xElement , _rBindingID ) ;
}
//---------------------------------------------------------------------
void OControlImport : : doRegisterXFormsListBinding ( const : : rtl : : OUString & _rBindingID )
{
OSL_PRECOND ( m_xElement . is ( ) , " need element " ) ;
2012-01-25 21:59:48 -02:00
OSL_PRECOND ( ! _rBindingID . isEmpty ( ) , " binding ID is not valid " ) ;
2004-11-16 09:09:27 +00:00
m_rContext . registerXFormsListBinding ( m_xElement , _rBindingID ) ;
}
//---------------------------------------------------------------------
void OControlImport : : doRegisterXFormsSubmission ( const : : rtl : : OUString & _rSubmissionID )
{
OSL_PRECOND ( m_xElement . is ( ) , " need element " ) ;
2012-01-25 21:59:48 -02:00
OSL_PRECOND ( ! _rSubmissionID . isEmpty ( ) , " binding ID is not valid " ) ;
2004-11-16 09:09:27 +00:00
m_rContext . registerXFormsSubmission ( m_xElement , _rSubmissionID ) ;
}
2002-11-06 09:37:04 +00:00
//---------------------------------------------------------------------
2010-10-19 23:45:24 -05:00
2002-11-06 09:37:04 +00:00
Reference < XPropertySet > OControlImport : : createElement ( )
{
2009-04-23 10:42:05 +00:00
const Reference < XPropertySet > xPropSet = OElementImport : : createElement ( ) ;
if ( xPropSet . is ( ) )
2002-11-06 09:37:04 +00:00
{
2009-04-23 10:42:05 +00:00
m_xInfo = xPropSet - > getPropertySetInfo ( ) ;
if ( m_xInfo . is ( ) & & m_xInfo - > hasPropertyByName ( PROPERTY_ALIGN ) )
2002-11-06 09:37:04 +00:00
{
Any aValue ;
xPropSet - > setPropertyValue ( PROPERTY_ALIGN , aValue ) ;
}
}
return xPropSet ;
}
2004-07-05 15:07:58 +00:00
//=====================================================================
//= OImagePositionImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OImagePositionImport : : OImagePositionImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager ,
2004-07-05 15:07:58 +00:00
sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName , const Reference < XNameContainer > & _rxParentContainer ,
OControlElement : : ElementType _eType )
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
, m_nImagePosition ( - 1 )
, m_nImageAlign ( 0 )
, m_bHaveImagePosition ( sal_False )
{
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OImagePositionImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName ,
2004-07-05 15:07:58 +00:00
const : : rtl : : OUString & _rValue )
{
if ( _rLocalName = = GetXMLToken ( XML_IMAGE_POSITION ) )
{
2006-07-26 06:32:42 +00:00
OSL_VERIFY ( PropertyConversion : : convertString (
2004-07-05 15:07:58 +00:00
m_rContext . getGlobalContext ( ) , : : getCppuType ( & m_nImagePosition ) ,
_rValue , OEnumMapper : : getEnumMap ( OEnumMapper : : epImagePosition )
) > > = m_nImagePosition ) ;
m_bHaveImagePosition = sal_True ;
2010-09-15 13:55:34 +02:00
return true ;
2004-07-05 15:07:58 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _rLocalName = = GetXMLToken ( XML_IMAGE_ALIGN ) )
2004-07-05 15:07:58 +00:00
{
2006-07-26 06:32:42 +00:00
OSL_VERIFY ( PropertyConversion : : convertString (
2004-07-05 15:07:58 +00:00
m_rContext . getGlobalContext ( ) , : : getCppuType ( & m_nImageAlign ) ,
_rValue , OEnumMapper : : getEnumMap ( OEnumMapper : : epImageAlign )
) > > = m_nImageAlign ) ;
2010-09-15 13:55:34 +02:00
return true ;
2004-07-05 15:07:58 +00:00
}
2010-09-15 13:55:34 +02:00
return OControlImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2004-07-05 15:07:58 +00:00
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OImagePositionImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2004-07-05 15:07:58 +00:00
{
OControlImport : : StartElement ( _rxAttrList ) ;
if ( m_bHaveImagePosition )
{
sal_Int16 nUnoImagePosition = ImagePosition : : Centered ;
if ( m_nImagePosition > = 0 )
{
OSL_ENSURE ( ( m_nImagePosition < = 3 ) & & ( m_nImageAlign > = 0 ) & & ( m_nImageAlign < 3 ) ,
" OImagePositionImport::StartElement: unknown image align and/or position! " ) ;
nUnoImagePosition = m_nImagePosition * 3 + m_nImageAlign ;
}
PropertyValue aImagePosition ;
aImagePosition . Name = PROPERTY_IMAGE_POSITION ;
aImagePosition . Value < < = nUnoImagePosition ;
implPushBackPropertyValue ( aImagePosition ) ;
}
}
2000-12-12 11:01:05 +00:00
//=====================================================================
//= OReferredControlImport
//=====================================================================
//---------------------------------------------------------------------
OReferredControlImport : : OReferredControlImport (
2009-04-23 10:42:05 +00:00
OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
2006-06-19 17:17:05 +00:00
OControlElement : : ElementType )
2001-01-02 14:58:22 +00:00
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer )
2000-12-12 11:01:05 +00:00
{
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OReferredControlImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2000-12-12 11:01:05 +00:00
{
OControlImport : : StartElement ( _rxAttrList ) ;
// the base class should have created the control, so we can register it
2012-01-25 21:59:48 -02:00
if ( ! m_sReferringControls . isEmpty ( ) )
2009-04-23 10:42:05 +00:00
m_rFormImport . registerControlReferences ( m_xElement , m_sReferringControls ) ;
2000-12-12 11:01:05 +00:00
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OReferredControlImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName ,
2000-12-12 11:01:05 +00:00
const : : rtl : : OUString & _rValue )
{
2004-08-02 13:14:10 +00:00
static const : : rtl : : OUString s_sReferenceAttributeName = : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_FOR ) ) ;
2000-12-12 11:01:05 +00:00
if ( _rLocalName = = s_sReferenceAttributeName )
2010-09-15 13:55:34 +02:00
{
2000-12-12 11:01:05 +00:00
m_sReferringControls = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
}
return OControlImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-12 11:01:05 +00:00
}
2000-12-18 14:14:35 +00:00
//=====================================================================
//= OPasswordImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OPasswordImport : : OPasswordImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-18 14:14:35 +00:00
const Reference < XNameContainer > & _rxParentContainer , OControlElement : : ElementType _eType )
2001-01-02 14:58:22 +00:00
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2000-12-18 14:14:35 +00:00
{
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OPasswordImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2000-12-18 14:14:35 +00:00
{
2004-08-02 13:14:10 +00:00
static const : : rtl : : OUString s_sEchoCharAttributeName = : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getSpecialAttributeName ( SCA_ECHO_CHAR ) ) ;
2000-12-18 14:14:35 +00:00
if ( _rLocalName = = s_sEchoCharAttributeName )
{
// need a special handling for the EchoChar property
PropertyValue aEchoChar ;
aEchoChar . Name = PROPERTY_ECHOCHAR ;
OSL_ENSURE ( _rValue . getLength ( ) = = 1 , " OPasswordImport::handleAttribute: invalid echo char attribute! " ) ;
// we ourself should not have written values other than of length 1
if ( _rValue . getLength ( ) > = 1 )
aEchoChar . Value < < = ( sal_Int16 ) _rValue . getStr ( ) [ 0 ] ;
else
aEchoChar . Value < < = ( sal_Int16 ) 0 ;
implPushBackPropertyValue ( aEchoChar ) ;
2010-09-15 13:55:34 +02:00
return true ;
2000-12-18 14:14:35 +00:00
}
2010-09-15 13:55:34 +02:00
return OControlImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-18 14:14:35 +00:00
}
2001-02-13 08:09:32 +00:00
//=====================================================================
//= ORadioImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
ORadioImport : : ORadioImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2001-02-13 08:09:32 +00:00
const Reference < XNameContainer > & _rxParentContainer , OControlElement : : ElementType _eType )
2004-07-05 15:07:58 +00:00
: OImagePositionImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2001-02-13 08:09:32 +00:00
{
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool ORadioImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2001-02-13 08:09:32 +00:00
{
// need special handling for the State & CurrentState properties:
// they're stored as booleans, but expected to be int16 properties
2009-04-23 10:42:05 +00:00
static const sal_Char * pCurrentSelectedAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_CURRENT_SELECTED ) ;
static const sal_Char * pSelectedAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_SELECTED ) ;
if ( _rLocalName . equalsAscii ( pCurrentSelectedAttributeName )
| | _rLocalName . equalsAscii ( pSelectedAttributeName )
2004-07-05 15:07:58 +00:00
)
2001-02-13 08:09:32 +00:00
{
const OAttribute2Property : : AttributeAssignment * pProperty = m_rContext . getAttributeMap ( ) . getAttributeTranslation ( _rLocalName ) ;
OSL_ENSURE ( pProperty , " ORadioImport::handleAttribute: invalid property map! " ) ;
if ( pProperty )
{
2009-04-23 10:42:05 +00:00
const Any aBooleanValue ( PropertyConversion : : convertString ( m_rContext . getGlobalContext ( ) , pProperty - > aPropertyType , _rValue , pProperty - > pEnumMap ) ) ;
2001-02-13 08:09:32 +00:00
// create and store a new PropertyValue
PropertyValue aNewValue ;
aNewValue . Name = pProperty - > sPropertyName ;
aNewValue . Value < < = ( sal_Int16 ) : : cppu : : any2bool ( aBooleanValue ) ;
implPushBackPropertyValue ( aNewValue ) ;
}
2010-09-15 13:55:34 +02:00
return true ;
2001-02-13 08:09:32 +00:00
}
2010-09-15 13:55:34 +02:00
return OImagePositionImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2001-02-13 08:09:32 +00:00
}
2002-11-22 13:39:17 +00:00
//=====================================================================
//= OURLReferenceImport
//=====================================================================
2009-04-23 10:42:05 +00:00
OURLReferenceImport : : OURLReferenceImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2002-11-22 13:39:17 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
OControlElement : : ElementType _eType )
2004-07-05 15:07:58 +00:00
: OImagePositionImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2002-11-22 13:39:17 +00:00
{
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OURLReferenceImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2002-11-22 13:39:17 +00:00
{
2004-08-02 13:14:10 +00:00
static const sal_Char * s_pTargetLocationAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_TARGET_LOCATION ) ;
static const sal_Char * s_pImageDataAttributeName = OAttributeMetaData : : getCommonControlAttributeName ( CCA_IMAGE_DATA ) ;
2002-11-22 13:39:17 +00:00
// need to make the URL absolute if
// * it's the image-data attribute
// * it's the target-location attribute, and we're dealign with an object which has the respective property
sal_Bool bMakeAbsolute =
( 0 = = _rLocalName . compareToAscii ( s_pImageDataAttributeName ) )
| | ( ( 0 = = _rLocalName . compareToAscii ( s_pTargetLocationAttributeName ) )
& & ( ( OControlElement : : BUTTON = = m_eElementType )
| | ( OControlElement : : IMAGE = = m_eElementType )
)
) ;
2012-01-25 21:59:48 -02:00
if ( bMakeAbsolute & & ! _rValue . isEmpty ( ) )
2002-11-22 13:39:17 +00:00
{
// make a global URL out of the local one
2010-09-15 13:55:34 +02:00
: : rtl : : OUString sAdjustedValue ;
// only resolve image related url
// we don't want say form url targets to be resolved
// using ResolveGraphicObjectURL
if ( 0 = = _rLocalName . compareToAscii ( s_pImageDataAttributeName ) )
2011-01-06 14:57:12 +01:00
sAdjustedValue = m_rContext . getGlobalContext ( ) . ResolveGraphicObjectURL ( _rValue , sal_False ) ;
2010-09-15 13:55:34 +02:00
else
sAdjustedValue = m_rContext . getGlobalContext ( ) . GetAbsoluteReference ( _rValue ) ;
return OImagePositionImport : : handleAttribute ( _nNamespaceKey , _rLocalName , sAdjustedValue ) ;
2002-11-22 13:39:17 +00:00
}
2010-09-15 13:55:34 +02:00
return OImagePositionImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2002-11-22 13:39:17 +00:00
}
2001-03-28 13:00:56 +00:00
//=====================================================================
//= OButtonImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OButtonImport : : OButtonImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2001-03-28 13:00:56 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
OControlElement : : ElementType _eType )
2002-11-22 13:39:17 +00:00
: OURLReferenceImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2001-03-28 13:00:56 +00:00
{
2001-03-29 08:45:16 +00:00
enableTrackAttributes ( ) ;
2001-03-28 13:00:56 +00:00
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OButtonImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2001-03-28 13:00:56 +00:00
{
2003-12-11 11:08:29 +00:00
OURLReferenceImport : : StartElement ( _rxAttrList ) ;
2001-03-28 13:00:56 +00:00
// handle the target-frame attribute
2004-08-02 13:14:10 +00:00
simulateDefaultedAttribute ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_TARGET_FRAME ) , PROPERTY_TARGETFRAME , " _blank " ) ;
2001-03-28 13:00:56 +00:00
}
2003-12-11 11:08:29 +00:00
//=====================================================================
//= OValueRangeImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OValueRangeImport : : OValueRangeImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2003-12-11 11:08:29 +00:00
const Reference < XNameContainer > & _rxParentContainer , OControlElement : : ElementType _eType )
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
, m_nStepSizeValue ( 1 )
{
2009-04-23 10:42:05 +00:00
2003-12-11 11:08:29 +00:00
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OValueRangeImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2003-12-11 11:08:29 +00:00
{
2004-08-02 13:14:10 +00:00
if ( _rLocalName . equalsAscii ( OAttributeMetaData : : getSpecialAttributeName ( SCA_STEP_SIZE ) ) )
2003-12-11 11:08:29 +00:00
{
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
: : sax : : Converter : : convertNumber ( m_nStepSizeValue , _rValue ) ;
2010-09-15 13:55:34 +02:00
return true ;
2003-12-11 11:08:29 +00:00
}
2010-09-15 13:55:34 +02:00
return OControlImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2003-12-11 11:08:29 +00:00
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OValueRangeImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2003-12-11 11:08:29 +00:00
{
OControlImport : : StartElement ( _rxAttrList ) ;
2009-04-23 10:42:05 +00:00
if ( m_xInfo . is ( ) )
2003-12-11 11:08:29 +00:00
{
2009-04-23 10:42:05 +00:00
if ( m_xInfo - > hasPropertyByName ( PROPERTY_SPIN_INCREMENT ) )
2003-12-11 11:08:29 +00:00
m_xElement - > setPropertyValue ( PROPERTY_SPIN_INCREMENT , makeAny ( m_nStepSizeValue ) ) ;
2009-04-23 10:42:05 +00:00
else if ( m_xInfo - > hasPropertyByName ( PROPERTY_LINE_INCREMENT ) )
2003-12-11 11:08:29 +00:00
m_xElement - > setPropertyValue ( PROPERTY_LINE_INCREMENT , makeAny ( m_nStepSizeValue ) ) ;
}
}
2001-03-29 08:45:16 +00:00
//=====================================================================
//= OTextLikeImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OTextLikeImport : : OTextLikeImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2001-03-29 08:45:16 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
OControlElement : : ElementType _eType )
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2004-05-07 14:59:30 +00:00
, m_bEncounteredTextPara ( false )
2001-03-29 08:45:16 +00:00
{
enableTrackAttributes ( ) ;
}
2004-05-07 14:59:30 +00:00
//---------------------------------------------------------------------
SvXMLImportContext * OTextLikeImport : : CreateChildContext ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
const Reference < XAttributeList > & _rxAttrList )
2004-05-07 14:59:30 +00:00
{
2012-02-21 01:06:12 +09:00
if ( ( XML_NAMESPACE_TEXT = = _nPrefix ) & & _rLocalName . equalsIgnoreAsciiCaseAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " p " ) ) )
2004-05-07 14:59:30 +00:00
{
OSL_ENSURE ( m_eElementType = = OControlElement : : TEXT_AREA ,
" OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area? " ) ;
if ( m_eElementType = = OControlElement : : TEXT_AREA )
{
Reference < XText > xTextElement ( m_xElement , UNO_QUERY ) ;
if ( xTextElement . is ( ) )
{
UniReference < XMLTextImportHelper > xTextImportHelper ( m_rContext . getGlobalContext ( ) . GetTextImport ( ) ) ;
if ( ! m_xCursor . is ( ) )
{
m_xOldCursor = xTextImportHelper - > GetCursor ( ) ;
m_xCursor = xTextElement - > createTextCursor ( ) ;
if ( m_xCursor . is ( ) )
xTextImportHelper - > SetCursor ( m_xCursor ) ;
}
if ( m_xCursor . is ( ) )
{
m_bEncounteredTextPara = true ;
return xTextImportHelper - > CreateTextChildContext ( m_rContext . getGlobalContext ( ) , _nPrefix , _rLocalName , _rxAttrList ) ;
}
}
else
{
// in theory, we could accumulate all the text portions (without formatting),
// and set it as Text property at the model ...
}
}
}
return OControlImport : : CreateChildContext ( _nPrefix , _rLocalName , _rxAttrList ) ;
}
2001-03-29 08:45:16 +00:00
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OTextLikeImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2001-03-29 08:45:16 +00:00
{
OControlImport : : StartElement ( _rxAttrList ) ;
2004-05-07 14:59:30 +00:00
// handle the convert-empty-to-null attribute, whose default is different from the property default
2001-04-27 10:33:04 +00:00
// unfortunately, different classes are imported by this class ('cause they're represented by the
// same XML element), though not all of them know this property.
// So we have to do a check ...
2009-04-23 10:42:05 +00:00
if ( m_xElement . is ( ) & & m_xInfo . is ( ) & & m_xInfo - > hasPropertyByName ( PROPERTY_EMPTY_IS_NULL ) )
2004-08-02 13:14:10 +00:00
simulateDefaultedAttribute ( OAttributeMetaData : : getDatabaseAttributeName ( DA_CONVERT_EMPTY ) , PROPERTY_EMPTY_IS_NULL , " false " ) ;
2001-03-29 08:45:16 +00:00
}
2004-05-07 14:59:30 +00:00
//---------------------------------------------------------------------
struct EqualHandle : public : : std : : unary_function < PropertyValue , bool >
{
2009-04-23 10:42:05 +00:00
const sal_Int32 m_nHandle ;
2004-05-07 14:59:30 +00:00
EqualHandle ( sal_Int32 _nHandle ) : m_nHandle ( _nHandle ) { }
inline bool operator ( ) ( const PropertyValue & _rProp )
{
2009-04-23 10:42:05 +00:00
return _rProp . Handle = = m_nHandle ;
2004-05-07 14:59:30 +00:00
}
} ;
//---------------------------------------------------------------------
void OTextLikeImport : : removeRedundantCurrentValue ( )
{
if ( m_bEncounteredTextPara )
{
// In case the text is written in the text:p elements, we need to ignore what we read as
// current-value attribute, since it's redundant.
// fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
// handle, so we do not need to determine the name of our value property here
// (normally, it should be "Text", since no other controls than the edit field should
// have the text:p elements)
PropertyValueArray : : iterator aValuePropertyPos = : : std : : find_if (
m_aValues . begin ( ) ,
m_aValues . end ( ) ,
EqualHandle ( PROPID_CURRENT_VALUE )
) ;
if ( aValuePropertyPos ! = m_aValues . end ( ) )
{
OSL_ENSURE ( aValuePropertyPos - > Name = = PROPERTY_TEXT , " OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'! " ) ;
if ( aValuePropertyPos - > Name = = PROPERTY_TEXT )
{
: : std : : copy (
aValuePropertyPos + 1 ,
m_aValues . end ( ) ,
aValuePropertyPos
) ;
m_aValues . resize ( m_aValues . size ( ) - 1 ) ;
}
}
2010-11-10 13:50:33 +08:00
// additionally, we need to set the "RichText" property of our element to sal_True
2004-05-07 14:59:30 +00:00
// (the presence of the text:p is used as indicator for the value of the RichText property)
sal_Bool bHasRichTextProperty = sal_False ;
2009-04-23 10:42:05 +00:00
if ( m_xInfo . is ( ) )
bHasRichTextProperty = m_xInfo - > hasPropertyByName ( PROPERTY_RICH_TEXT ) ;
2004-05-07 14:59:30 +00:00
OSL_ENSURE ( bHasRichTextProperty , " OTextLikeImport::EndElement: text:p, but no rich text control? " ) ;
if ( bHasRichTextProperty )
m_xElement - > setPropertyValue ( PROPERTY_RICH_TEXT , makeAny ( ( sal_Bool ) sal_True ) ) ;
}
// Note that we do *not* set the RichText property (in case our element has one) to sal_False here
// since this is the default of this property, anyway.
}
//---------------------------------------------------------------------
struct EqualName : public : : std : : unary_function < PropertyValue , bool >
{
2009-04-23 10:42:05 +00:00
const : : rtl : : OUString m_sName ;
2004-05-07 14:59:30 +00:00
EqualName ( const : : rtl : : OUString & _rName ) : m_sName ( _rName ) { }
inline bool operator ( ) ( const PropertyValue & _rProp )
{
2009-04-23 10:42:05 +00:00
return _rProp . Name = = m_sName ;
2004-05-07 14:59:30 +00:00
}
} ;
//---------------------------------------------------------------------
void OTextLikeImport : : adjustDefaultControlProperty ( )
{
// In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
// so that it now uses another default control. So if we encounter a text field where the *old* default
// control property is writting, we are not allowed to use it
PropertyValueArray : : iterator aDefaultControlPropertyPos = : : std : : find_if (
m_aValues . begin ( ) ,
m_aValues . end ( ) ,
EqualName ( : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " DefaultControl " ) ) )
) ;
if ( aDefaultControlPropertyPos ! = m_aValues . end ( ) )
{
: : rtl : : OUString sDefaultControl ;
OSL_VERIFY ( aDefaultControlPropertyPos - > Value > > = sDefaultControl ) ;
2012-04-06 14:28:18 +02:00
if ( sDefaultControl = = " stardiv.one.form.control.Edit " )
2004-05-07 14:59:30 +00:00
{
// complete remove this property value from the array. Today's "default value" of the "DefaultControl"
// property is sufficient
: : std : : copy (
aDefaultControlPropertyPos + 1 ,
m_aValues . end ( ) ,
aDefaultControlPropertyPos
) ;
m_aValues . resize ( m_aValues . size ( ) - 1 ) ;
}
}
}
//---------------------------------------------------------------------
void OTextLikeImport : : EndElement ( )
{
removeRedundantCurrentValue ( ) ;
adjustDefaultControlProperty ( ) ;
// let the base class do the stuff
OControlImport : : EndElement ( ) ;
// some cleanups
UniReference < XMLTextImportHelper > xTextImportHelper ( m_rContext . getGlobalContext ( ) . GetTextImport ( ) ) ;
if ( m_xCursor . is ( ) )
{
// delete the newline which has been imported errornously
// TODO (fs): stole this code somewhere - why don't we fix the text import??
m_xCursor - > gotoEnd ( sal_False ) ;
m_xCursor - > goLeft ( 1 , sal_True ) ;
m_xCursor - > setString ( : : rtl : : OUString ( ) ) ;
// reset cursor
xTextImportHelper - > ResetCursor ( ) ;
}
if ( m_xOldCursor . is ( ) )
xTextImportHelper - > SetCursor ( m_xOldCursor ) ;
}
2000-12-06 16:32:01 +00:00
//=====================================================================
//= OListAndComboImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OListAndComboImport : : OListAndComboImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-06 16:32:01 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
2000-12-12 11:01:05 +00:00
OControlElement : : ElementType _eType )
2001-01-02 14:58:22 +00:00
: OControlImport ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , _eType )
2001-11-02 11:34:13 +00:00
, m_nEmptyListItems ( 0 )
, m_nEmptyValueItems ( 0 )
, m_bEncounteredLSAttrib ( sal_False )
2003-10-21 07:38:38 +00:00
, m_bLinkWithIndexes ( sal_False )
2000-12-06 16:32:01 +00:00
{
2001-03-29 08:45:16 +00:00
if ( OControlElement : : COMBOBOX = = m_eElementType )
enableTrackAttributes ( ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
SvXMLImportContext * OListAndComboImport : : CreateChildContext ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
const Reference < XAttributeList > & _rxAttrList )
2000-12-06 16:32:01 +00:00
{
// is it the "option" sub tag of a listbox ?
2010-11-21 15:43:10 +01:00
static const : : rtl : : OUString s_sOptionElementName ( RTL_CONSTASCII_USTRINGPARAM ( " option " ) ) ;
2000-12-06 16:32:01 +00:00
if ( s_sOptionElementName = = _rLocalName )
return new OListOptionImport ( GetImport ( ) , _nPrefix , _rLocalName , this ) ;
// is it the "item" sub tag of a combobox ?
2010-11-21 15:43:10 +01:00
static const : : rtl : : OUString s_sItemElementName ( RTL_CONSTASCII_USTRINGPARAM ( " item " ) ) ;
2000-12-06 16:32:01 +00:00
if ( s_sItemElementName = = _rLocalName )
return new OComboItemImport ( GetImport ( ) , _nPrefix , _rLocalName , this ) ;
// everything else
return OControlImport : : CreateChildContext ( _nPrefix , _rLocalName , _rxAttrList ) ;
}
2001-03-29 08:45:16 +00:00
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OListAndComboImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2001-03-29 08:45:16 +00:00
{
2003-10-21 07:38:38 +00:00
m_bLinkWithIndexes = sal_False ;
2001-03-29 08:45:16 +00:00
OControlImport : : StartElement ( _rxAttrList ) ;
if ( OControlElement : : COMBOBOX = = m_eElementType )
{
// for the auto-completion
// the attribute default does not equal the property default, so in case we did not read this attribute,
// we have to simulate it
2004-08-02 13:14:10 +00:00
simulateDefaultedAttribute ( OAttributeMetaData : : getSpecialAttributeName ( SCA_AUTOMATIC_COMPLETION ) , PROPERTY_AUTOCOMPLETE , " false " ) ;
2001-03-29 08:45:16 +00:00
// same for the convert-empty-to-null attribute, which's default is different from the property default
2004-08-02 13:14:10 +00:00
simulateDefaultedAttribute ( OAttributeMetaData : : getDatabaseAttributeName ( DA_CONVERT_EMPTY ) , PROPERTY_EMPTY_IS_NULL , " false " ) ;
2001-03-29 08:45:16 +00:00
}
}
2000-12-06 16:32:01 +00:00
//---------------------------------------------------------------------
void OListAndComboImport : : EndElement ( )
{
// append the list source property the the properties sequence of our importer
// the string item list
PropertyValue aItemList ;
aItemList . Name = PROPERTY_STRING_ITEM_LIST ;
2001-01-02 14:58:22 +00:00
aItemList . Value < < = m_aListSource ;
2000-12-06 16:32:01 +00:00
implPushBackPropertyValue ( aItemList ) ;
if ( OControlElement : : LISTBOX = = m_eElementType )
{
2001-12-12 15:35:19 +00:00
OSL_ENSURE ( ( m_aListSource . getLength ( ) + m_nEmptyListItems ) = = ( m_aValueList . getLength ( ) + m_nEmptyValueItems ) ,
" OListAndComboImport::EndElement: inconsistence between labels and values! " ) ;
2001-11-02 11:34:13 +00:00
if ( ! m_bEncounteredLSAttrib )
{
// the value sequence
PropertyValue aValueList ;
aValueList . Name = PROPERTY_LISTSOURCE ;
aValueList . Value < < = m_aValueList ;
implPushBackPropertyValue ( aValueList ) ;
}
2000-12-06 16:32:01 +00:00
// the select sequence
PropertyValue aSelected ;
aSelected . Name = PROPERTY_SELECT_SEQ ;
aSelected . Value < < = m_aSelectedSeq ;
implPushBackPropertyValue ( aSelected ) ;
// the default select sequence
PropertyValue aDefaultSelected ;
aDefaultSelected . Name = PROPERTY_DEFAULT_SELECT_SEQ ;
aDefaultSelected . Value < < = m_aDefaultSelectedSeq ;
implPushBackPropertyValue ( aDefaultSelected ) ;
}
OControlImport : : EndElement ( ) ;
2003-10-21 07:38:38 +00:00
// the external list source, if applicable
2012-01-25 21:59:48 -02:00
if ( m_xElement . is ( ) & & ! m_sCellListSource . isEmpty ( ) )
2003-10-21 07:38:38 +00:00
m_rContext . registerCellRangeListSource ( m_xElement , m_sCellListSource ) ;
}
//---------------------------------------------------------------------
void OListAndComboImport : : doRegisterCellValueBinding ( const : : rtl : : OUString & _rBoundCellAddress )
{
: : rtl : : OUString sBoundCellAddress ( _rBoundCellAddress ) ;
if ( m_bLinkWithIndexes )
{
// This is a HACK. We register a string which is no valid address, but allows
// (somewhere else) to determine that a non-standard binding should be created.
// This hack is acceptable for OOo 1.1.1, since the file format for value
// bindings of form controls is to be changed afterwards, anyway.
sBoundCellAddress + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " :index " ) ) ;
}
OControlImport : : doRegisterCellValueBinding ( sBoundCellAddress ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OListAndComboImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2000-12-06 16:32:01 +00:00
{
2009-04-23 10:42:05 +00:00
static const sal_Char * pListSourceAttributeName = OAttributeMetaData : : getDatabaseAttributeName ( DA_LIST_SOURCE ) ;
if ( _rLocalName . equalsAscii ( pListSourceAttributeName ) )
2000-12-06 16:32:01 +00:00
{
2001-03-28 11:27:19 +00:00
PropertyValue aListSource ;
aListSource . Name = PROPERTY_LISTSOURCE ;
2001-11-02 11:34:13 +00:00
// it's the ListSource attribute
m_bEncounteredLSAttrib = sal_True ;
if ( OControlElement : : COMBOBOX = = m_eElementType )
{
aListSource . Value < < = _rValue ;
}
else
{
// a listbox which has a list-source attribute must have a list-source-type of something
// not equal to ValueList.
// In this case, the list-source value is simply the one and only element of the ListSource property.
Sequence < : : rtl : : OUString > aListSourcePropValue ( 1 ) ;
aListSourcePropValue [ 0 ] = _rValue ;
aListSource . Value < < = aListSourcePropValue ;
}
implPushBackPropertyValue ( aListSource ) ;
2010-09-15 13:55:34 +02:00
return true ;
2000-12-06 16:32:01 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _rLocalName . equalsAscii ( OAttributeMetaData : : getBindingAttributeName ( BA_LIST_CELL_RANGE ) ) )
2003-10-21 07:38:38 +00:00
{
m_sCellListSource = _rValue ;
2010-09-15 13:55:34 +02:00
return true ;
2003-10-21 07:38:38 +00:00
}
2010-09-15 13:55:34 +02:00
if ( _rLocalName . equalsAscii ( OAttributeMetaData : : getBindingAttributeName ( BA_LIST_LINKING_TYPE ) ) )
2003-10-21 07:38:38 +00:00
{
sal_Int16 nLinkageType = 0 ;
2006-07-26 06:32:42 +00:00
PropertyConversion : : convertString (
2003-10-21 07:38:38 +00:00
m_rContext . getGlobalContext ( ) ,
: : getCppuType ( static_cast < sal_Int16 * > ( NULL ) ) ,
_rValue ,
OEnumMapper : : getEnumMap ( OEnumMapper : : epListLinkageType )
) > > = nLinkageType ;
m_bLinkWithIndexes = ( nLinkageType ! = 0 ) ;
2010-09-15 13:55:34 +02:00
return true ;
2003-10-21 07:38:38 +00:00
}
2010-09-15 13:55:34 +02:00
return OControlImport : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
void OListAndComboImport : : implPushBackLabel ( const : : rtl : : OUString & _rLabel )
{
2001-05-21 12:33:04 +00:00
OSL_ENSURE ( ! m_nEmptyListItems , " OListAndComboImport::implPushBackValue: label list is already done! " ) ;
if ( ! m_nEmptyListItems )
pushBackSequenceElement ( m_aListSource , _rLabel ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
void OListAndComboImport : : implPushBackValue ( const : : rtl : : OUString & _rValue )
{
2001-05-21 12:33:04 +00:00
OSL_ENSURE ( ! m_nEmptyValueItems , " OListAndComboImport::implPushBackValue: value list is already done! " ) ;
if ( ! m_nEmptyValueItems )
2001-11-02 11:34:13 +00:00
{
OSL_ENSURE ( ! m_bEncounteredLSAttrib , " OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m? " ) ;
// We already had the list-source attribute, which means that the ListSourceType is
// not ValueList, which means that the ListSource should contain only one string in
// the first element of the sequence
// All other values in the file are invalid
pushBackSequenceElement ( m_aValueList , _rValue ) ;
}
2001-05-21 12:33:04 +00:00
}
//---------------------------------------------------------------------
void OListAndComboImport : : implEmptyLabelFound ( )
{
+ + m_nEmptyListItems ;
}
//---------------------------------------------------------------------
void OListAndComboImport : : implEmptyValueFound ( )
{
+ + m_nEmptyValueItems ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
void OListAndComboImport : : implSelectCurrentItem ( )
{
2001-05-21 12:33:04 +00:00
OSL_ENSURE ( ( m_aListSource . getLength ( ) + m_nEmptyListItems ) = = ( m_aValueList . getLength ( ) + m_nEmptyValueItems ) ,
" OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values! " ) ;
2000-12-06 16:32:01 +00:00
2001-05-21 12:33:04 +00:00
sal_Int16 nItemNumber = ( sal_Int16 ) ( m_aListSource . getLength ( ) - 1 + m_nEmptyListItems ) ;
pushBackSequenceElement ( m_aSelectedSeq , nItemNumber ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
void OListAndComboImport : : implDefaultSelectCurrentItem ( )
{
2001-05-21 12:33:04 +00:00
OSL_ENSURE ( ( m_aListSource . getLength ( ) + m_nEmptyListItems ) = = ( m_aValueList . getLength ( ) + m_nEmptyValueItems ) ,
" OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values! " ) ;
2000-12-06 16:32:01 +00:00
2001-05-21 12:33:04 +00:00
sal_Int16 nItemNumber = ( sal_Int16 ) ( m_aListSource . getLength ( ) - 1 + m_nEmptyListItems ) ;
pushBackSequenceElement ( m_aDefaultSelectedSeq , nItemNumber ) ;
2000-12-06 16:32:01 +00:00
}
//=====================================================================
//= OListOptionImport
//=====================================================================
//---------------------------------------------------------------------
OListOptionImport : : OListOptionImport ( SvXMLImport & _rImport , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
const OListAndComboImportRef & _rListBox )
: SvXMLImportContext ( _rImport , _nPrefix , _rName )
, m_xListBoxImport ( _rListBox )
{
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OListOptionImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2000-12-06 16:32:01 +00:00
{
// the label and the value
2009-04-23 10:42:05 +00:00
const SvXMLNamespaceMap & rMap = GetImport ( ) . GetNamespaceMap ( ) ;
const : : rtl : : OUString sLabelAttribute = rMap . GetQNameByKey (
2010-11-21 15:43:10 +01:00
GetPrefix ( ) , : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " label " ) ) ) ;
2009-04-23 10:42:05 +00:00
const : : rtl : : OUString sValueAttribute = rMap . GetQNameByKey (
2010-11-21 15:43:10 +01:00
GetPrefix ( ) , : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " value " ) ) ) ;
2000-12-06 16:32:01 +00:00
2001-05-21 12:33:04 +00:00
// -------------------
// the label attribute
: : rtl : : OUString sValue = _rxAttrList - > getValueByName ( sLabelAttribute ) ;
sal_Bool bNonexistentAttribute = sal_False ;
2012-01-25 21:59:48 -02:00
if ( sValue . isEmpty ( ) )
if ( _rxAttrList - > getTypeByName ( sLabelAttribute ) . isEmpty ( ) )
2001-05-21 12:33:04 +00:00
// this attribute does not really exist
bNonexistentAttribute = sal_True ;
if ( bNonexistentAttribute )
m_xListBoxImport - > implEmptyLabelFound ( ) ;
else
m_xListBoxImport - > implPushBackLabel ( sValue ) ;
// -------------------
// the value attribute
sValue = _rxAttrList - > getValueByName ( sValueAttribute ) ;
bNonexistentAttribute = sal_False ;
2012-01-25 21:59:48 -02:00
if ( sValue . isEmpty ( ) )
if ( _rxAttrList - > getTypeByName ( sValueAttribute ) . isEmpty ( ) )
2001-05-21 12:33:04 +00:00
// this attribute does not really exist
bNonexistentAttribute = sal_True ;
if ( bNonexistentAttribute )
m_xListBoxImport - > implEmptyValueFound ( ) ;
else
m_xListBoxImport - > implPushBackValue ( sValue ) ;
2000-12-06 16:32:01 +00:00
// the current-selected and selected
2009-04-23 10:42:05 +00:00
const : : rtl : : OUString sSelectedAttribute = rMap . GetQNameByKey (
2004-08-02 13:14:10 +00:00
GetPrefix ( ) , : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_CURRENT_SELECTED ) ) ) ;
2009-04-23 10:42:05 +00:00
const : : rtl : : OUString sDefaultSelectedAttribute = rMap . GetQNameByKey (
2004-08-02 13:14:10 +00:00
GetPrefix ( ) , : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_SELECTED ) ) ) ;
2000-12-06 16:32:01 +00:00
// propagate the selected flag
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
bool bSelected ( false ) ;
: : sax : : Converter : : convertBool ( bSelected ,
_rxAttrList - > getValueByName ( sSelectedAttribute ) ) ;
2000-12-06 16:32:01 +00:00
if ( bSelected )
m_xListBoxImport - > implSelectCurrentItem ( ) ;
// same for the default selected
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
bool bDefaultSelected ( false ) ;
: : sax : : Converter : : convertBool ( bDefaultSelected ,
_rxAttrList - > getValueByName ( sDefaultSelectedAttribute ) ) ;
2000-12-06 16:32:01 +00:00
if ( bDefaultSelected )
m_xListBoxImport - > implDefaultSelectCurrentItem ( ) ;
SvXMLImportContext : : StartElement ( _rxAttrList ) ;
}
//=====================================================================
//= OComboItemImport
//=====================================================================
//---------------------------------------------------------------------
OComboItemImport : : OComboItemImport ( SvXMLImport & _rImport , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
const OListAndComboImportRef & _rListBox )
2001-03-28 11:27:19 +00:00
: SvXMLImportContext ( _rImport , _nPrefix , _rName )
2000-12-06 16:32:01 +00:00
, m_xListBoxImport ( _rListBox )
{
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OComboItemImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2000-12-06 16:32:01 +00:00
{
2001-07-10 16:12:09 +00:00
const : : rtl : : OUString sLabelAttributeName = GetImport ( ) . GetNamespaceMap ( ) . GetQNameByKey (
2004-08-02 13:14:10 +00:00
GetPrefix ( ) , : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_LABEL ) ) ) ;
2001-03-28 11:27:19 +00:00
m_xListBoxImport - > implPushBackLabel ( _rxAttrList - > getValueByName ( sLabelAttributeName ) ) ;
SvXMLImportContext : : StartElement ( _rxAttrList ) ;
2000-12-06 16:32:01 +00:00
}
2004-07-13 07:29:16 +00:00
2000-12-06 16:32:01 +00:00
//=====================================================================
2004-07-13 07:29:16 +00:00
//= OColumnWrapperImport
2000-12-06 16:32:01 +00:00
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OColumnWrapperImport : : OColumnWrapperImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer )
: SvXMLImportContext ( _rImport . getGlobalContext ( ) , _nPrefix , _rName )
, m_xParentContainer ( _rxParentContainer )
2006-06-19 17:17:05 +00:00
, m_rFormImport ( _rImport )
2001-01-02 14:58:22 +00:00
, m_rEventManager ( _rEventManager )
2000-12-06 16:32:01 +00:00
{
}
//---------------------------------------------------------------------
2004-07-13 07:29:16 +00:00
SvXMLImportContext * OColumnWrapperImport : : CreateChildContext ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
const Reference < XAttributeList > & )
2000-12-06 16:32:01 +00:00
{
2001-01-03 15:25:34 +00:00
OControlImport * pReturn = implCreateChildContext ( _nPrefix , _rLocalName , OElementNameMap : : getElementType ( _rLocalName ) ) ;
if ( pReturn )
{
2004-07-13 07:29:16 +00:00
OSL_ENSURE ( m_xOwnAttributes . is ( ) , " OColumnWrapperImport::CreateChildContext: had no form:column element! " ) ;
2001-01-03 15:25:34 +00:00
pReturn - > addOuterAttributes ( m_xOwnAttributes ) ;
}
return pReturn ;
}
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OColumnWrapperImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2001-01-03 15:25:34 +00:00
{
2004-07-13 07:29:16 +00:00
OSL_ENSURE ( ! m_xOwnAttributes . is ( ) , " OColumnWrapperImport::StartElement: aready have the cloned list! " ) ;
2001-01-03 15:25:34 +00:00
// clone the attributes
Reference < XCloneable > xCloneList ( _rxAttrList , UNO_QUERY ) ;
2004-07-13 07:29:16 +00:00
OSL_ENSURE ( xCloneList . is ( ) , " OColumnWrapperImport::StartElement: AttributeList not cloneable! " ) ;
2004-11-09 11:16:35 +00:00
if ( xCloneList . is ( ) )
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
m_xOwnAttributes = Reference < XAttributeList > ( xCloneList - > createClone ( ) , UNO_QUERY ) ;
2004-07-13 07:29:16 +00:00
OSL_ENSURE ( m_xOwnAttributes . is ( ) , " OColumnWrapperImport::StartElement: no cloned list! " ) ;
2001-01-03 15:25:34 +00:00
}
2000-12-12 11:01:05 +00:00
2004-07-14 12:59:37 +00:00
//---------------------------------------------------------------------
OControlImport * OColumnWrapperImport : : implCreateChildContext (
sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
OControlElement : : ElementType _eType )
{
OSL_ENSURE ( ( OControlElement : : TEXT = = _eType )
| | ( OControlElement : : TEXT_AREA = = _eType )
| | ( OControlElement : : FORMATTED_TEXT = = _eType )
| | ( OControlElement : : CHECKBOX = = _eType )
| | ( OControlElement : : LISTBOX = = _eType )
2010-09-15 13:55:34 +02:00
| | ( OControlElement : : COMBOBOX = = _eType )
| | ( OControlElement : : TIME = = _eType )
| | ( OControlElement : : DATE = = _eType ) ,
2004-07-14 12:59:37 +00:00
" OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element! " ) ;
switch ( _eType )
{
case OControlElement : : COMBOBOX :
case OControlElement : : LISTBOX :
2004-11-09 11:16:35 +00:00
return new OColumnImport < OListAndComboImport > ( m_rFormImport , m_rEventManager , _nPrefix , _rLocalName , m_xParentContainer , _eType ) ;
2004-07-14 12:59:37 +00:00
case OControlElement : : PASSWORD :
2004-11-09 11:16:35 +00:00
return new OColumnImport < OPasswordImport > ( m_rFormImport , m_rEventManager , _nPrefix , _rLocalName , m_xParentContainer , _eType ) ;
2007-07-31 12:40:33 +00:00
case OControlElement : : TEXT :
case OControlElement : : TEXT_AREA :
case OControlElement : : FORMATTED_TEXT :
return new OColumnImport < OTextLikeImport > ( m_rFormImport , m_rEventManager , _nPrefix , _rLocalName , m_xParentContainer , _eType ) ;
2000-12-06 16:32:01 +00:00
2004-07-14 12:59:37 +00:00
default :
2004-11-09 11:16:35 +00:00
return new OColumnImport < OControlImport > ( m_rFormImport , m_rEventManager , _nPrefix , _rLocalName , m_xParentContainer , _eType ) ;
2004-07-14 12:59:37 +00:00
}
}
2000-12-12 11:01:05 +00:00
//=====================================================================
//= OGridImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OGridImport : : OGridImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer ,
OControlElement : : ElementType _eType )
2001-01-03 15:25:34 +00:00
: OGridImport_Base ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , " column " )
2000-12-12 11:01:05 +00:00
{
setElementType ( _eType ) ;
2000-12-06 16:32:01 +00:00
}
//---------------------------------------------------------------------
2001-01-03 15:25:34 +00:00
SvXMLImportContext * OGridImport : : implCreateControlWrapper ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName )
2000-12-06 16:32:01 +00:00
{
2001-01-03 15:25:34 +00:00
return new OColumnWrapperImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer ) ;
2000-12-12 11:01:05 +00:00
}
2000-12-06 16:32:01 +00:00
2000-12-12 11:01:05 +00:00
//=====================================================================
//= OFormImport
//=====================================================================
//---------------------------------------------------------------------
2009-04-23 10:42:05 +00:00
OFormImport : : OFormImport ( OFormLayerXMLImport_Impl & _rImport , IEventAttacherManager & _rEventManager , sal_uInt16 _nPrefix , const : : rtl : : OUString & _rName ,
2000-12-12 11:01:05 +00:00
const Reference < XNameContainer > & _rxParentContainer )
2001-01-03 15:25:34 +00:00
: OFormImport_Base ( _rImport , _rEventManager , _nPrefix , _rName , _rxParentContainer , " control " )
2001-01-02 14:58:22 +00:00
{
2001-03-29 08:45:16 +00:00
enableTrackAttributes ( ) ;
2001-01-02 14:58:22 +00:00
}
//---------------------------------------------------------------------
SvXMLImportContext * OFormImport : : CreateChildContext ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
const Reference < XAttributeList > & _rxAttrList )
2000-12-12 11:01:05 +00:00
{
2004-07-13 07:29:16 +00:00
if ( token : : IsXMLToken ( _rLocalName , token : : XML_FORM ) )
return new OFormImport ( m_rFormImport , * this , _nPrefix , _rLocalName ,
m_xMeAsContainer ) ;
2004-08-02 13:14:10 +00:00
else if ( token : : IsXMLToken ( _rLocalName , token : : XML_CONNECTION_RESOURCE ) )
return new OXMLDataSourceImport ( GetImport ( ) , _nPrefix , _rLocalName , _rxAttrList , m_xElement ) ;
2008-12-11 07:05:03 +00:00
else if ( ( token : : IsXMLToken ( _rLocalName , token : : XML_EVENT_LISTENERS ) & &
( XML_NAMESPACE_OFFICE = = _nPrefix ) ) | |
2004-07-13 07:29:16 +00:00
token : : IsXMLToken ( _rLocalName , token : : XML_PROPERTIES ) )
return OElementImport : : CreateChildContext ( _nPrefix , _rLocalName ,
_rxAttrList ) ;
else
return implCreateChildContext ( _nPrefix , _rLocalName ,
OElementNameMap : : getElementType ( _rLocalName ) ) ;
2000-12-12 11:01:05 +00:00
}
2000-12-06 16:32:01 +00:00
2001-01-24 08:37:58 +00:00
//---------------------------------------------------------------------
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
void OFormImport : : StartElement ( const Reference < XAttributeList > & _rxAttrList )
2001-01-24 08:37:58 +00:00
{
m_rFormImport . enterEventContext ( ) ;
OFormImport_Base : : StartElement ( _rxAttrList ) ;
2001-03-28 13:00:56 +00:00
// handle the target-frame attribute
2004-08-02 13:14:10 +00:00
simulateDefaultedAttribute ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_TARGET_FRAME ) , PROPERTY_TARGETFRAME , " _blank " ) ;
2001-01-24 08:37:58 +00:00
}
//---------------------------------------------------------------------
void OFormImport : : EndElement ( )
{
OFormImport_Base : : EndElement ( ) ;
m_rFormImport . leaveEventContext ( ) ;
}
2000-12-12 11:01:05 +00:00
//---------------------------------------------------------------------
2001-01-03 15:25:34 +00:00
SvXMLImportContext * OFormImport : : implCreateControlWrapper ( sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName )
2000-12-12 11:01:05 +00:00
{
2004-07-13 07:29:16 +00:00
OSL_ENSURE ( ! this , " illegal call to OFormImport::implCreateControlWrapper " ) ;
return new SvXMLImportContext ( GetImport ( ) , _nPrefix , _rLocalName ) ;
2000-12-12 11:01:05 +00:00
}
//---------------------------------------------------------------------
2010-09-15 13:55:34 +02:00
bool OFormImport : : handleAttribute ( sal_uInt16 _nNamespaceKey , const : : rtl : : OUString & _rLocalName , const : : rtl : : OUString & _rValue )
2000-12-12 11:01:05 +00:00
{
// handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
2004-08-02 13:14:10 +00:00
static const : : rtl : : OUString s_sMasterFieldsAttributeName = : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getFormAttributeName ( faMasterFields ) ) ;
static const : : rtl : : OUString s_sDetailFieldsAttributeName = : : rtl : : OUString : : createFromAscii ( OAttributeMetaData : : getFormAttributeName ( faDetailFiels ) ) ;
2010-09-15 13:55:34 +02:00
if ( s_sMasterFieldsAttributeName = = _rLocalName )
{
2000-12-12 11:01:05 +00:00
implTranslateStringListProperty ( PROPERTY_MASTERFIELDS , _rValue ) ;
2010-09-15 13:55:34 +02:00
return true ;
}
if ( s_sDetailFieldsAttributeName = = _rLocalName )
{
2000-12-12 11:01:05 +00:00
implTranslateStringListProperty ( PROPERTY_DETAILFIELDS , _rValue ) ;
2010-09-15 13:55:34 +02:00
return true ;
}
2004-08-02 13:14:10 +00:00
2010-09-15 13:55:34 +02:00
return OFormImport_Base : : handleAttribute ( _nNamespaceKey , _rLocalName , _rValue ) ;
2000-12-12 11:01:05 +00:00
}
//---------------------------------------------------------------------
void OFormImport : : implTranslateStringListProperty ( const : : rtl : : OUString & _rPropertyName , const : : rtl : : OUString & _rValue )
{
PropertyValue aProp ;
aProp . Name = _rPropertyName ;
Sequence < : : rtl : : OUString > aList ;
// split up the value string
2012-01-25 21:59:48 -02:00
if ( ! _rValue . isEmpty ( ) )
2000-12-12 11:01:05 +00:00
{
// For the moment, we build a vector instead of a Sequence. It's easier to handle because of it's
// push_back method
: : std : : vector < : : rtl : : OUString > aElements ;
// estimate the number of tokens
sal_Int32 nEstimate = 0 , nLength = _rValue . getLength ( ) ;
const sal_Unicode * pChars = _rValue . getStr ( ) ;
for ( sal_Int32 i = 0 ; i < nLength ; + + i , + + pChars )
if ( * pChars = = ' , ' )
+ + nEstimate ;
aElements . reserve ( nEstimate + 1 ) ;
// that's the worst case. If the string contains the separator character _quoted_, we reserved to much ...
sal_Int32 nElementStart = 0 ;
sal_Int32 nNextSep = 0 ;
sal_Int32 nElementLength ;
: : rtl : : OUString sElement ;
do
{
// extract the current element
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
nNextSep = : : sax : : Converter : : indexOfComma (
2006-10-12 13:43:19 +00:00
_rValue , nElementStart ) ;
2000-12-12 11:01:05 +00:00
if ( - 1 = = nNextSep )
nNextSep = nLength ;
sElement = _rValue . copy ( nElementStart , nNextSep - nElementStart ) ;
nElementLength = sElement . getLength ( ) ;
// when writing the sequence, we quoted the single elements with " characters
OSL_ENSURE ( ( nElementLength > = 2 )
& & ( sElement . getStr ( ) [ 0 ] = = ' " ' )
& & ( sElement . getStr ( ) [ nElementLength - 1 ] = = ' " ' ) ,
" OFormImport::implTranslateStringListProperty: invalid quoted element name. " ) ;
sElement = sElement . copy ( 1 , nElementLength - 2 ) ;
aElements . push_back ( sElement ) ;
// swith to the next element
nElementStart = 1 + nNextSep ;
}
while ( nElementStart < nLength ) ;
2004-09-08 13:58:49 +00:00
: : rtl : : OUString * pElements = aElements . empty ( ) ? 0 : & aElements [ 0 ] ;
aList = Sequence < : : rtl : : OUString > ( pElements , aElements . size ( ) ) ;
2000-12-12 11:01:05 +00:00
}
else
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormImport::implTranslateStringListProperty: invalid value (empty)! " ) ;
2000-12-12 11:01:05 +00:00
}
aProp . Value < < = aList ;
// add the property to the base class' array
implPushBackPropertyValue ( aProp ) ;
2000-12-06 16:32:01 +00:00
}
2004-08-02 13:14:10 +00:00
//=====================================================================
//= OXMLDataSourceImport
//=====================================================================
OXMLDataSourceImport : : OXMLDataSourceImport (
SvXMLImport & _rImport
, sal_uInt16 nPrfx
, const : : rtl : : OUString & _sLocalName
, const Reference < : : com : : sun : : star : : xml : : sax : : XAttributeList > & _xAttrList
, const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : beans : : XPropertySet > & _xElement ) :
SvXMLImportContext ( _rImport , nPrfx , _sLocalName )
{
OSL_ENSURE ( _xAttrList . is ( ) , " Attribute list is NULL! " ) ;
2007-01-15 12:42:45 +00:00
const SvXMLNamespaceMap & rMap = _rImport . GetNamespaceMap ( ) ;
2004-08-02 13:14:10 +00:00
sal_Int16 nLength = ( _xElement . is ( ) & & _xAttrList . is ( ) ) ? _xAttrList - > getLength ( ) : 0 ;
for ( sal_Int16 i = 0 ; i < nLength ; + + i )
{
: : rtl : : OUString sLocalName ;
: : rtl : : OUString sAttrName = _xAttrList - > getNameByIndex ( i ) ;
2007-01-15 12:42:45 +00:00
sal_uInt16 nPrefix = rMap . GetKeyByAttrName ( sAttrName , & sLocalName ) ;
2000-12-06 16:32:01 +00:00
2007-01-15 12:42:45 +00:00
if ( ( nPrefix = = OAttributeMetaData : : getCommonControlAttributeNamespace ( CCA_TARGET_LOCATION ) )
& & ( sLocalName . equalsAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCA_TARGET_LOCATION ) ) )
)
2004-08-02 13:14:10 +00:00
{
2007-01-15 12:42:45 +00:00
: : rtl : : OUString sValue = _xAttrList - > getValueByIndex ( i ) ;
2004-08-02 13:14:10 +00:00
INetURLObject aURL ( sValue ) ;
if ( aURL . GetProtocol ( ) = = INET_PROT_FILE )
_xElement - > setPropertyValue ( PROPERTY_DATASOURCENAME , makeAny ( sValue ) ) ;
else
_xElement - > setPropertyValue ( PROPERTY_URL , makeAny ( sValue ) ) ; // the url is the "sdbc:" string
break ;
}
}
}
2004-07-13 07:29:16 +00:00
//---------------------------------------------------------------------
OControlImport * OFormImport : : implCreateChildContext (
sal_uInt16 _nPrefix , const : : rtl : : OUString & _rLocalName ,
OControlElement : : ElementType _eType )
{
switch ( _eType )
{
case OControlElement : : TEXT :
case OControlElement : : TEXT_AREA :
case OControlElement : : FORMATTED_TEXT :
return new OTextLikeImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
case OControlElement : : BUTTON :
case OControlElement : : IMAGE :
case OControlElement : : IMAGE_FRAME :
2008-12-01 12:31:27 +00:00
return new OButtonImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
2004-07-13 07:29:16 +00:00
case OControlElement : : COMBOBOX :
case OControlElement : : LISTBOX :
return new OListAndComboImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
case OControlElement : : RADIO :
return new ORadioImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
2004-11-26 12:01:35 +00:00
case OControlElement : : CHECKBOX :
return new OImagePositionImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
2004-07-13 07:29:16 +00:00
case OControlElement : : PASSWORD :
return new OPasswordImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
case OControlElement : : FRAME :
case OControlElement : : FIXED_TEXT :
return new OReferredControlImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
case OControlElement : : GRID :
return new OGridImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
case OControlElement : : VALUERANGE :
return new OValueRangeImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
default :
return new OControlImport ( m_rFormImport , * this , _nPrefix , _rLocalName , m_xMeAsContainer , _eType ) ;
}
}
2000-12-06 16:32:01 +00:00
//.........................................................................
} // namespace xmloff
//.........................................................................
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */