diff options
Diffstat (limited to 'xmloff/source/text')
136 files changed, 47322 insertions, 0 deletions
diff --git a/xmloff/source/text/XMLAnchorTypePropHdl.hxx b/xmloff/source/text/XMLAnchorTypePropHdl.hxx new file mode 100644 index 000000000000..8ea4f3a40d0d --- /dev/null +++ b/xmloff/source/text/XMLAnchorTypePropHdl.hxx @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLANCHORTYPEPROPHDL_HXX +#define _XMLOFF_XMLANCHORTYPEPROPHDL_HXX + +#ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP +#include <com/sun/star/text/TextContentAnchorType.hpp> +#endif +#include <xmloff/xmlprhdl.hxx> + + +class XMLAnchorTypePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLAnchorTypePropHdl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const; + static sal_Bool convert( const ::rtl::OUString& rStrImpValue, + ::com::sun::star::text::TextContentAnchorType& rType ); +}; + +#endif // _XMLOFF_XMLANCHORTYPEPROPHDL_HXX diff --git a/xmloff/source/text/XMLAutoMarkFileContext.cxx b/xmloff/source/text/XMLAutoMarkFileContext.cxx new file mode 100644 index 000000000000..505a7e6b0281 --- /dev/null +++ b/xmloff/source/text/XMLAutoMarkFileContext.cxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLAutoMarkFileContext.hxx" +#include <xmloff/xmlimp.hxx> +#include <rtl/ustring.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + + +using ::rtl::OUString; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::beans::XPropertySet; + +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_HREF; + + +TYPEINIT1( XMLAutoMarkFileContext, SvXMLImportContext ); + +XMLAutoMarkFileContext::XMLAutoMarkFileContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + sIndexAutoMarkFileURL( + RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL")) +{ +} + +XMLAutoMarkFileContext::~XMLAutoMarkFileContext() +{ +} + + +void XMLAutoMarkFileContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // scan for text:alphabetical-index-auto-mark-file attribute, and if + // found set value with the document + + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 i = 0; i < nLength; i++ ) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + if ( ( XML_NAMESPACE_XLINK == nPrefix ) && + IsXMLToken(sLocalName, XML_HREF) ) + { + Any aAny; + aAny <<= GetImport().GetAbsoluteReference( xAttrList->getValueByIndex(i) ); + Reference<XPropertySet> xPropertySet( + GetImport().GetModel(), UNO_QUERY ); + if (xPropertySet.is()) + { + xPropertySet->setPropertyValue( sIndexAutoMarkFileURL, aAny ); + } + } + } +} diff --git a/xmloff/source/text/XMLAutoMarkFileContext.hxx b/xmloff/source/text/XMLAutoMarkFileContext.hxx new file mode 100644 index 000000000000..78f4d85d7a05 --- /dev/null +++ b/xmloff/source/text/XMLAutoMarkFileContext.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLAUTOMARKFILECONTEXT_HXX_ +#define _XMLOFF_XMLAUTOMARKFILECONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> + + +namespace com { namespace sun { namespace star { + namespace uno { template<class X> class Reference; } + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } + + +class XMLAutoMarkFileContext : public SvXMLImportContext +{ + const ::rtl::OUString sIndexAutoMarkFileURL; + +public: + + TYPEINFO(); + + XMLAutoMarkFileContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName); + + ~XMLAutoMarkFileContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); +}; + +#endif diff --git a/xmloff/source/text/XMLAutoTextContainerEventImport.cxx b/xmloff/source/text/XMLAutoTextContainerEventImport.cxx new file mode 100644 index 000000000000..6d14bd5ddc26 --- /dev/null +++ b/xmloff/source/text/XMLAutoTextContainerEventImport.cxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLAutoTextContainerEventImport.hxx" +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/XMLEventsImportContext.hxx> + + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::container::XNameReplace; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_EVENT_LISTENERS; + + +TYPEINIT1(XMLAutoTextContainerEventImport, SvXMLImportContext); + + +XMLAutoTextContainerEventImport::XMLAutoTextContainerEventImport( + SvXMLImport& rImport, + USHORT nPrfx, + const OUString& rLName, + const Reference<XNameReplace> & rEvnts ) : + SvXMLImportContext(rImport, nPrfx, rLName), + rEvents(rEvnts) +{ +} + +XMLAutoTextContainerEventImport::~XMLAutoTextContainerEventImport() +{ +} + +SvXMLImportContext* XMLAutoTextContainerEventImport::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & ) +{ + if ( (XML_NAMESPACE_OFFICE == nPrefix) && + IsXMLToken( rLocalName, XML_EVENT_LISTENERS) ) + { + return new XMLEventsImportContext(GetImport(), nPrefix, rLocalName, + rEvents); + } + else + return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); +} diff --git a/xmloff/source/text/XMLAutoTextContainerEventImport.hxx b/xmloff/source/text/XMLAutoTextContainerEventImport.hxx new file mode 100644 index 000000000000..9d2aa2daa465 --- /dev/null +++ b/xmloff/source/text/XMLAutoTextContainerEventImport.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLAUTOTEXTCONTAINEREVENTIMPORT_HXX +#define _XMLOFF_XMLAUTOTEXTCONTAINEREVENTIMPORT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.hxx> + + +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace container { class XNameReplace; } + namespace xml { namespace sax { class XAttributeList; } } +} } } + + +/** + * Import the text:auto-text-container element. + * This only instantiates text:auto-text-group contexta. + */ +class XMLAutoTextContainerEventImport : public SvXMLImportContext +{ + /// the parent auto text container + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XNameReplace> & rEvents; + +public: + + TYPEINFO(); + + XMLAutoTextContainerEventImport( + SvXMLImport& rImport, + USHORT nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XNameReplace > & rEvents ); + + ~XMLAutoTextContainerEventImport(); + + +protected: + + virtual SvXMLImportContext *CreateChildContext( + USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLAutoTextEventExport.cxx b/xmloff/source/text/XMLAutoTextEventExport.cxx new file mode 100644 index 000000000000..dcef23ba5734 --- /dev/null +++ b/xmloff/source/text/XMLAutoTextEventExport.cxx @@ -0,0 +1,297 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLAutoTextEventExport.hxx" +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP +#include <com/sun/star/uno/Exception.hpp> +#endif + +// #110680# +//#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +//#include <comphelper/processfactory.hxx> +//#endif +#include <rtl/ustrbuf.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/XMLEventExport.hxx> +#include <tools/debug.hxx> + + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +// #110680# +// using ::comphelper::getProcessServiceFactory; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::std::set; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::container::XNameAccess; +using ::com::sun::star::container::XNameReplace; +using ::com::sun::star::document::XEventsSupplier; +using ::com::sun::star::frame::XModel; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::xml::sax::XDocumentHandler; + + +const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; + + +// #110680# +XMLAutoTextEventExport::XMLAutoTextEventExport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, + sal_uInt16 nFlags + ) +: SvXMLExport( xServiceFactory, MAP_INCH, XML_AUTO_TEXT, nFlags ), + sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), + sNone(RTL_CONSTASCII_USTRINGPARAM("None")) +{ +} + +// #110680# +XMLAutoTextEventExport::XMLAutoTextEventExport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, + const OUString& rFileName, + const Reference<XDocumentHandler> & rHandler, + const Reference<XModel> & rModel, + const Reference<XNameAccess> & rEvents, + sal_uInt16 /*nFlags*/ ) +: SvXMLExport( xServiceFactory, rFileName, rHandler, rModel, MAP_INCH ), + xEvents(rEvents), + sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), + sNone(RTL_CONSTASCII_USTRINGPARAM("None")) +{ +} + +XMLAutoTextEventExport::~XMLAutoTextEventExport() +{ +} + + +void XMLAutoTextEventExport::initialize( + const Sequence<Any> & rArguments ) + throw(uno::Exception, uno::RuntimeException) +{ + if (rArguments.getLength() > 1) + { + Reference<XEventsSupplier> xSupplier; + rArguments[1] >>= xSupplier; + if (xSupplier.is()) + { + Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY); + xEvents = xAccess; + } + else + { + Reference<XNameReplace> xReplace; + rArguments[1] >>= xReplace; + if (xReplace.is()) + { + Reference<XNameAccess> xAccess(xReplace, UNO_QUERY); + xEvents = xAccess; + } + else + { + rArguments[1] >>= xEvents; + } + } + } + + // call super class (for XHandler) + SvXMLExport::initialize(rArguments); +} + + +sal_uInt32 XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum ) +{ + if( (getExportFlags() & EXPORT_OASIS) == 0 ) + { + Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory(); + if( xFactory.is() ) + { + try + { + + Sequence<Any> aArgs( 1 ); + aArgs[0] <<= GetDocHandler(); + + // get filter component + Reference< xml::sax::XDocumentHandler > xTmpDocHandler( + xFactory->createInstanceWithArguments( + OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"), + aArgs), UNO_QUERY); + OSL_ENSURE( xTmpDocHandler.is(), + "can't instantiate OASIS transformer component" ); + if( xTmpDocHandler.is() ) + { + SetDocHandler( xTmpDocHandler ); + } + } + catch( com::sun::star::uno::Exception& ) + { + } + } + } + if (hasEvents()) + { + GetDocHandler()->startDocument(); + + addNamespaces(); + + { + // container element + SvXMLElementExport aContainerElement( + *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS, + sal_True, sal_True); + + exportEvents(); + } + + // and close document again + GetDocHandler()->endDocument(); + } + + return 0; +} + +sal_Bool XMLAutoTextEventExport::hasEvents() +{ + // TODO: provide full implementation that check for presence of events + return xEvents.is(); +} + +void XMLAutoTextEventExport::addNamespaces() +{ + // namespaces for office:, text: and script: + GetAttrList().AddAttribute( + GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ), + GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) ); + GetAttrList().AddAttribute( + GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ), + GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) ); + GetAttrList().AddAttribute( + GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ), + GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) ); + GetAttrList().AddAttribute( + GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ), + GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) ); + GetAttrList().AddAttribute( + GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ), + GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) ); +} + +void XMLAutoTextEventExport::exportEvents() +{ + DBG_ASSERT(hasEvents(), "no events to export!"); + + GetEventExport().Export(xEvents, sal_True); +} + + + +// methods without content: + +void XMLAutoTextEventExport::_ExportMeta() {} +void XMLAutoTextEventExport::_ExportScripts() {} +void XMLAutoTextEventExport::_ExportFontDecls() {} +void XMLAutoTextEventExport::_ExportStyles( sal_Bool ) {} +void XMLAutoTextEventExport::_ExportAutoStyles() {} +void XMLAutoTextEventExport::_ExportMasterStyles() {} +void XMLAutoTextEventExport::_ExportChangeTracking() {} +void XMLAutoTextEventExport::_ExportContent() {} + + + +// methods to support the component registration + +Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames() + throw() +{ + Sequence< OUString > aSeq( 1 ); + aSeq[0] = XMLAutoTextEventExport_getImplementationName(); + return aSeq; +} + +OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" ) ); +} + +Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance( + const Reference< XMultiServiceFactory > & rSMgr) + throw( Exception ) +{ + // #110680# + // return (cppu::OWeakObject*)new XMLAutoTextEventExport; + return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr, EXPORT_ALL|EXPORT_OASIS); +} + +// methods to support the component registration + +Sequence< OUString > SAL_CALL XMLAutoTextEventExportOOO_getSupportedServiceNames() + throw() +{ + Sequence< OUString > aSeq( 1 ); + aSeq[0] = XMLAutoTextEventExportOOO_getImplementationName(); + return aSeq; +} + +OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() throw() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.comp.Writer.XMLAutotextEventsExporter" ) ); +} + +Reference< XInterface > SAL_CALL XMLAutoTextEventExportOOO_createInstance( + const Reference< XMultiServiceFactory > & rSMgr) + throw( Exception ) +{ + // #110680# + // return (cppu::OWeakObject*)new XMLAutoTextEventExport; + return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr,EXPORT_ALL); +} + diff --git a/xmloff/source/text/XMLAutoTextEventExport.hxx b/xmloff/source/text/XMLAutoTextEventExport.hxx new file mode 100644 index 000000000000..b32787e9980b --- /dev/null +++ b/xmloff/source/text/XMLAutoTextEventExport.hxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLAUTOTEXTEVENTEXPORT_HXX +#define _XMLOFF_XMLAUTOTEXTEVENTEXPORT_HXX + +#include <xmloff/xmlexp.hxx> + +#include <set> + + +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace container { class XNameAccess; } + namespace frame { class XModel; } + namespace lang { class XMultiServiceFactory; } + namespace uno { template<class X> class Reference; } + namespace uno { template<class X> class Sequence; } + namespace uno { class XInterface; } + namespace uno { class Exception; } + namespace xml { namespace sax { class XDocumentHandler; } } +} } } + + +/** + * Component for the export of events attached to autotext blocks. + * Via the XInitialization interface it expects up to two strings, the + * first giving the file name (URL) of the autotext group, and the second + * identifying the autotext. If one of the strings is not given, it + * will export the whole group / all groups. + */ +class XMLAutoTextEventExport : public SvXMLExport +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XNameAccess> xEvents; + + const ::rtl::OUString sEventType; + const ::rtl::OUString sNone; + + +public: + + // #110680# + //XMLAutoTextEventExport(); + XMLAutoTextEventExport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, sal_uInt16 nFlags + ); + + // #110680# + //XMLAutoTextEventExport( + // const ::rtl::OUString& rFileName, + // const ::com::sun::star::uno::Reference< + // ::com::sun::star::xml::sax::XDocumentHandler > & rHandler, + // const ::com::sun::star::uno::Reference< + // ::com::sun::star::frame::XModel > & rModel, + // const ::com::sun::star::uno::Reference< + // ::com::sun::star::container::XNameAccess > & rEvents); + XMLAutoTextEventExport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, + const ::rtl::OUString& rFileName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & rHandler, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & rModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > & rEvents, sal_uInt16 nFlags); + + ~XMLAutoTextEventExport(); + + // XInitialization + virtual void SAL_CALL initialize( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any> & rArguments ) + throw( + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + +protected: + + /// export the events off all autotexts + virtual sal_uInt32 exportDoc( + enum ::xmloff::token::XMLTokenEnum eClass = xmloff::token::XML_TOKEN_INVALID ); + + /// does the document have any events ? + sal_Bool hasEvents(); + + /// export the events element + void exportEvents(); + + + /// add the namespaces used by events + /// (to be called for the document element) + void addNamespaces(); + + + // methods without content: + virtual void _ExportMeta(); + virtual void _ExportScripts(); + virtual void _ExportFontDecls(); + virtual void _ExportStyles( sal_Bool bUsed ) ; + virtual void _ExportAutoStyles(); + virtual void _ExportMasterStyles(); + virtual void _ExportChangeTracking(); + virtual void _ExportContent(); +}; + + + +// global functions to support the component + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + XMLAutoTextEventExport_getSupportedServiceNames() + throw(); + +::rtl::OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() + throw(); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + XMLAutoTextEventExportOOO_createInstance( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & ) + throw( ::com::sun::star::uno::Exception ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + XMLAutoTextEventExportOOO_getSupportedServiceNames() + throw(); + +::rtl::OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() + throw(); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + XMLAutoTextEventExportOOO_createInstance( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & ) + throw( ::com::sun::star::uno::Exception ); + +#endif + diff --git a/xmloff/source/text/XMLAutoTextEventImport.cxx b/xmloff/source/text/XMLAutoTextEventImport.cxx new file mode 100644 index 000000000000..ffd7f2985070 --- /dev/null +++ b/xmloff/source/text/XMLAutoTextEventImport.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLAutoTextEventImport.hxx" +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include "XMLAutoTextContainerEventImport.hxx" +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <tools/debug.hxx> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Type; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::document::XEventsSupplier; +using ::com::sun::star::container::XNameReplace; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_AUTO_TEXT_EVENTS; + +const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; + + +// #110680# +XMLAutoTextEventImport::XMLAutoTextEventImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory) throw() +: SvXMLImport(xServiceFactory) +{ +} + +XMLAutoTextEventImport::~XMLAutoTextEventImport() throw() +{ +} + +void XMLAutoTextEventImport::initialize( + const Sequence<Any> & rArguments ) + throw(Exception, RuntimeException) +{ + // The events may come as either an XNameReplace or XEventsSupplier. + + const sal_Int32 nLength = rArguments.getLength(); + for( sal_Int32 i = 0; i < nLength; i++ ) + { + const Type& rType = rArguments[i].getValueType(); + if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) ) + { + Reference<XEventsSupplier> xSupplier; + rArguments[i] >>= xSupplier; + DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace"); + + xEvents = xSupplier->getEvents(); + } + else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) ) + { + rArguments[i] >>= xEvents; + DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace"); + } + } + + // call parent + SvXMLImport::initialize(rArguments); +} + + + +SvXMLImportContext* XMLAutoTextEventImport::CreateContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList > & xAttrList ) +{ + if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) && + IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) ) + { + return new XMLAutoTextContainerEventImport( + *this, nPrefix, rLocalName, xEvents); + } + else + { + return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList); + } +} + + +Sequence< OUString > SAL_CALL + XMLAutoTextEventImport_getSupportedServiceNames() + throw() +{ + Sequence< OUString > aSeq( 1 ); + aSeq[0] = XMLAutoTextEventImport_getImplementationName(); + return aSeq; +} + +OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" ) ); +} + +Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance( + const Reference< XMultiServiceFactory > & rSMgr) + throw( Exception ) +{ + // #110680# + // return (cppu::OWeakObject*)new XMLAutoTextEventImport; + return (cppu::OWeakObject*)new XMLAutoTextEventImport(rSMgr); +} + diff --git a/xmloff/source/text/XMLAutoTextEventImport.hxx b/xmloff/source/text/XMLAutoTextEventImport.hxx new file mode 100644 index 000000000000..c9ecb29e138e --- /dev/null +++ b/xmloff/source/text/XMLAutoTextEventImport.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLAUTOTEXTEVENTIMPORT_HXX +#define _XMLOFF_XMLAUTOTEXTEVENTIMPORT_HXX + +#include <xmloff/xmlimp.hxx> +#include <com/sun/star/uno/Reference.hxx> + + +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace frame { class XModel; } + namespace lang { class XMultiServiceFactory; } + namespace text { class XAutoTextContainer; } + namespace text { class XAutoTextGroup; } + namespace text { class XAutoTextEntry; } + namespace uno { template<class X> class Reference; } + namespace uno { template<class X> class Sequence; } + namespace uno { class XInterface; } + namespace uno { class Exception; } + namespace xml { namespace sax { class XDocumentHandler; } } +} } } + + +class XMLAutoTextEventImport : public SvXMLImport +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XNameReplace> xEvents; + +public: + // #110680# + // XMLAutoTextEventImport() throw(); + XMLAutoTextEventImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory + ) throw(); + + ~XMLAutoTextEventImport() throw(); + + // XInitialization + virtual void SAL_CALL initialize( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any> & rArguments ) + throw( + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + +protected: + + virtual SvXMLImportContext* CreateContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + +}; + + +// global functions to support the component + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + XMLAutoTextEventImport_getSupportedServiceNames() + throw(); + +::rtl::OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() + throw(); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + XMLAutoTextEventImport_createInstance( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & ) + throw( ::com::sun::star::uno::Exception ); + +#endif + diff --git a/xmloff/source/text/XMLCalculationSettingsContext.cxx b/xmloff/source/text/XMLCalculationSettingsContext.cxx new file mode 100644 index 000000000000..af1b2b0cf7c4 --- /dev/null +++ b/xmloff/source/text/XMLCalculationSettingsContext.cxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <XMLCalculationSettingsContext.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +XMLCalculationSettingsContext::XMLCalculationSettingsContext( SvXMLImport& rImport, + sal_uInt16 p_nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) +: SvXMLImportContext ( rImport, p_nPrefix, rLocalName ) +, nYear( 1930 ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); + rtl::OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( + sAttrName, &aLocalName ); + rtl::OUString sValue = xAttrList->getValueByIndex( i ); + + if (nPrefix == XML_NAMESPACE_TABLE) + { + if ( IsXMLToken( aLocalName, XML_NULL_YEAR ) ) + { + sal_Int32 nTemp; + GetImport().GetMM100UnitConverter().convertNumber(nTemp, sValue); + nYear= static_cast <sal_Int16> (nTemp); + } + } + } +} + +XMLCalculationSettingsContext::~XMLCalculationSettingsContext() +{ +} +void XMLCalculationSettingsContext::EndElement() +{ + if (nYear != 1930 ) + { + Reference < XTextDocument > xTextDoc ( GetImport().GetModel(), UNO_QUERY); + if (xTextDoc.is()) + { + Reference < XPropertySet > xPropSet ( xTextDoc, UNO_QUERY ); + OUString sTwoDigitYear ( RTL_CONSTASCII_USTRINGPARAM ( "TwoDigitYear" ) ); + Any aAny; + aAny <<= nYear; + xPropSet->setPropertyValue ( sTwoDigitYear, aAny ); + } + } +} diff --git a/xmloff/source/text/XMLCalculationSettingsContext.hxx b/xmloff/source/text/XMLCalculationSettingsContext.hxx new file mode 100644 index 000000000000..632fbaeaab8e --- /dev/null +++ b/xmloff/source/text/XMLCalculationSettingsContext.hxx @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLCALCULATIONSETTINGSCONTEXT_HXX +#define _XMLOFF_XMLCALCULATIONSETTINGSCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> + +class XMLCalculationSettingsContext : public SvXMLImportContext +{ + sal_Int16 nYear; +public: + XMLCalculationSettingsContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + virtual ~XMLCalculationSettingsContext(); + virtual void EndElement(); + +}; + + +#endif diff --git a/xmloff/source/text/XMLChangeElementImportContext.cxx b/xmloff/source/text/XMLChangeElementImportContext.cxx new file mode 100644 index 000000000000..061a9a1f9172 --- /dev/null +++ b/xmloff/source/text/XMLChangeElementImportContext.cxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLChangeElementImportContext.hxx" +#include "XMLChangedRegionImportContext.hxx" +#include "XMLChangeInfoContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + + + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_P; +using ::xmloff::token::XML_CHANGE_INFO; + +TYPEINIT1( XMLChangeElementImportContext, SvXMLImportContext ); + +XMLChangeElementImportContext::XMLChangeElementImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + sal_Bool bAccContent, + XMLChangedRegionImportContext& rParent) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + bAcceptContent(bAccContent), + rChangedRegion(rParent) +{ +} + +SvXMLImportContext* XMLChangeElementImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +{ + SvXMLImportContext* pContext = NULL; + + if ( (XML_NAMESPACE_OFFICE == nPrefix) && + IsXMLToken( rLocalName, XML_CHANGE_INFO) ) + { + pContext = new XMLChangeInfoContext(GetImport(), nPrefix, rLocalName, + rChangedRegion, GetLocalName()); + } + else + { + // import into redline -> create XText + rChangedRegion.UseRedlineText(); + + pContext = GetImport().GetTextImport()->CreateTextChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + XML_TEXT_TYPE_CHANGED_REGION); + + if (NULL == pContext) + { + // no text element -> use default + pContext = SvXMLImportContext::CreateChildContext( + nPrefix, rLocalName, xAttrList); + + // illegal element content! TODO: discard this redline! + } + } + + + return pContext; +} + +// #107848# +void XMLChangeElementImportContext::StartElement( const Reference< XAttributeList >& ) +{ + if(bAcceptContent) + { + GetImport().GetTextImport()->SetInsideDeleteContext(sal_True); + } +} + +// #107848# +void XMLChangeElementImportContext::EndElement() +{ + if(bAcceptContent) + { + GetImport().GetTextImport()->SetInsideDeleteContext(sal_False); + } +} diff --git a/xmloff/source/text/XMLChangeElementImportContext.hxx b/xmloff/source/text/XMLChangeElementImportContext.hxx new file mode 100644 index 000000000000..12d43904bc27 --- /dev/null +++ b/xmloff/source/text/XMLChangeElementImportContext.hxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLCHANGEELEMENTIMPORTCONTEXT_HXX +#define _XMLOFF_XMLCHANGEELEMENTIMPORTCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} +class XMLChangedRegionImportContext; + + + +/** + * Import <text:deletion> and <text:insertion> elements contained in a + * <text:changed-region> element. + */ +class XMLChangeElementImportContext : public SvXMLImportContext +{ + sal_Bool bAcceptContent; + XMLChangedRegionImportContext& rChangedRegion; + +public: + + TYPEINFO(); + + XMLChangeElementImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + /// accept text content (paragraphs) in element as redline content? + sal_Bool bAcceptContent, + /// context of enclosing <text:changed-region> element + XMLChangedRegionImportContext& rParent); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + // #107848# + // Start- and EndElement are needed here to set the inside_deleted_section + // flag at the corresponding TextImportHelper + virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + // #107848# + virtual void EndElement(); +}; + +#endif diff --git a/xmloff/source/text/XMLChangeImportContext.cxx b/xmloff/source/text/XMLChangeImportContext.cxx new file mode 100644 index 000000000000..9aee1c843369 --- /dev/null +++ b/xmloff/source/text/XMLChangeImportContext.cxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLChangeImportContext.hxx" +#include <com/sun/star/text/XTextRange.hpp> +#include <tools/debug.hxx> +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::text::XTextRange; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_CHANGE_ID; + +TYPEINIT1( XMLChangeImportContext, SvXMLImportContext ); + +XMLChangeImportContext::XMLChangeImportContext( + SvXMLImport& rImport, + sal_Int16 nPrefix, + const OUString& rLocalName, + sal_Bool bStart, + sal_Bool bEnd, + sal_Bool bOutsideOfParagraph) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + bIsStart(bStart), + bIsEnd(bEnd), + bIsOutsideOfParagraph(bOutsideOfParagraph) +{ + DBG_ASSERT(bStart || bEnd, "Must be either start, end, or both!"); +} + +XMLChangeImportContext::~XMLChangeImportContext() +{ +} + +void XMLChangeImportContext::StartElement( + const Reference<XAttributeList>& xAttrList) +{ + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken( sLocalName, XML_CHANGE_ID ) ) + { + // Id found! Now call RedlineImportHelper + + // prepare parameters + UniReference<XMLTextImportHelper> rHelper = + GetImport().GetTextImport(); + OUString sID = xAttrList->getValueByIndex(nAttr); + + // call for bStart and bEnd (may both be true) + if (bIsStart) + rHelper->RedlineSetCursor(sID,sal_True,bIsOutsideOfParagraph); + if (bIsEnd) + rHelper->RedlineSetCursor(sID,sal_False,bIsOutsideOfParagraph); + + // outside of paragraph and still open? set open redline ID + if (bIsOutsideOfParagraph) + { + rHelper->SetOpenRedlineId(sID); + } + } + // else: ignore + } +} diff --git a/xmloff/source/text/XMLChangeImportContext.hxx b/xmloff/source/text/XMLChangeImportContext.hxx new file mode 100644 index 000000000000..9f8c43c64d87 --- /dev/null +++ b/xmloff/source/text/XMLChangeImportContext.hxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLCHANGEIMPORTCONTEXT_HXX +#define _XMLOFF_XMLCHANGEIMPORTCONTEXT_HXX + + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} + + + +/** + * import change tracking/redlining markers + * <text:change>, <text:change-start>, <text:change-end> + */ +class XMLChangeImportContext : public SvXMLImportContext +{ + sal_Bool bIsStart; + sal_Bool bIsEnd; + sal_Bool bIsOutsideOfParagraph; + +public: + + TYPEINFO(); + + /** + * import a change mark + * (<text:change>, <text:change-start>, <text:change-end>) + * Note: a <text:change> mark denotes start and end of a change + * simultaniously, so both bIsStart and bIsEnd parameters would + * be set true. + */ + XMLChangeImportContext( + SvXMLImport& rImport, + sal_Int16 nPrefix, + const ::rtl::OUString& rLocalName, + sal_Bool bIsStart, /// mark start of a change + sal_Bool bIsEnd, /// mark end of a change + /// true if change mark is encountered outside of a paragraph + /// (usually before a section or table) + sal_Bool bIsOutsideOfParagraph = sal_False); + + ~XMLChangeImportContext(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); +}; + +#endif diff --git a/xmloff/source/text/XMLChangeInfoContext.cxx b/xmloff/source/text/XMLChangeInfoContext.cxx new file mode 100644 index 000000000000..506ead5789a4 --- /dev/null +++ b/xmloff/source/text/XMLChangeInfoContext.cxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLChangeInfoContext.hxx" +#include "XMLChangedRegionImportContext.hxx" +#include "XMLStringBufferImportContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlimp.hxx> + + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1(XMLChangeInfoContext, SvXMLImportContext); + +XMLChangeInfoContext::XMLChangeInfoContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + XMLChangedRegionImportContext& rPParent, + const OUString& rChangeType) +: SvXMLImportContext(rImport, nPrefix, rLocalName) +, rType(rChangeType) +, rChangedRegion(rPParent) +{ +} + +XMLChangeInfoContext::~XMLChangeInfoContext() +{ +} + +void XMLChangeInfoContext::StartElement(const Reference<XAttributeList> &) +{ + // no attributes +} + +SvXMLImportContext* XMLChangeInfoContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList >& xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if( XML_NAMESPACE_DC == nPrefix ) + { + if( IsXMLToken( rLocalName, XML_CREATOR ) ) + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, sAuthorBuffer); + else if( IsXMLToken( rLocalName, XML_DATE ) ) + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, sDateTimeBuffer); + } + else if ( ( XML_NAMESPACE_TEXT == nPrefix ) && + IsXMLToken( rLocalName, XML_P ) ) + { + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, sCommentBuffer); + } + + if( !pContext ) + { + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } + + return pContext; +} + +void XMLChangeInfoContext::EndElement() +{ + // set values at changed region context + rChangedRegion.SetChangeInfo(rType, sAuthorBuffer.makeStringAndClear(), + sCommentBuffer.makeStringAndClear(), + sDateTimeBuffer.makeStringAndClear()); +} diff --git a/xmloff/source/text/XMLChangeInfoContext.hxx b/xmloff/source/text/XMLChangeInfoContext.hxx new file mode 100644 index 000000000000..a2aeed545a48 --- /dev/null +++ b/xmloff/source/text/XMLChangeInfoContext.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLCHANGEINFOCONTEXT_HXX +#define _XMLOFF_XMLCHANGEINFOCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +class XMLChangedRegionImportContext; + + + +/** + * Import <office:change-info> elements as children of <text:changed-region> + * elements. The attribute values will be passed to the enclosing + * XMLChangedRegionImportContext (which has to be passed down in the + * constructor). + */ +class XMLChangeInfoContext : public SvXMLImportContext +{ + const ::rtl::OUString& rType; + + ::rtl::OUStringBuffer sAuthorBuffer; + ::rtl::OUStringBuffer sDateTimeBuffer; + ::rtl::OUStringBuffer sCommentBuffer; + + XMLChangedRegionImportContext& rChangedRegion; + +public: + + TYPEINFO(); + + XMLChangeInfoContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + XMLChangedRegionImportContext& rChangedRegion, + const ::rtl::OUString& rChangeType); + + ~XMLChangeInfoContext(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual SvXMLImportContext *CreateChildContext( + USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + virtual void EndElement(); + +}; + +#endif diff --git a/xmloff/source/text/XMLChangedRegionImportContext.cxx b/xmloff/source/text/XMLChangedRegionImportContext.cxx new file mode 100644 index 000000000000..9560a8159a0e --- /dev/null +++ b/xmloff/source/text/XMLChangedRegionImportContext.cxx @@ -0,0 +1,196 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLChangedRegionImportContext.hxx" +#include "XMLChangeElementImportContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::text::XTextCursor; +using ::com::sun::star::util::DateTime; +using ::com::sun::star::xml::sax::XAttributeList; + + + +TYPEINIT1(XMLChangedRegionImportContext, SvXMLImportContext); + +XMLChangedRegionImportContext::XMLChangedRegionImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + bMergeLastPara(sal_True) +{ +} + +XMLChangedRegionImportContext::~XMLChangedRegionImportContext() +{ +} + +void XMLChangedRegionImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // process attributes: id + bool bHaveXmlId( false ); + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + const OUString sValue = xAttrList->getValueByIndex(nAttr); + if (XML_NAMESPACE_XML == nPrefix) + { + if (IsXMLToken(sLocalName, XML_ID)) + { + sID = sValue; + bHaveXmlId = true; + } + } + else if (XML_NAMESPACE_TEXT == nPrefix) + { + if (IsXMLToken(sLocalName, XML_ID)) + { + if (!bHaveXmlId) { sID = sValue; } + } + else if( IsXMLToken( sLocalName, XML_MERGE_LAST_PARAGRAPH ) ) + { + sal_Bool bTmp; + if( SvXMLUnitConverter::convertBool(bTmp, sValue) ) + { + bMergeLastPara = bTmp; + } + } + } + } +} + +SvXMLImportContext* XMLChangedRegionImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +{ + SvXMLImportContext* pContext = NULL; + + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( rLocalName, XML_INSERTION ) || + IsXMLToken( rLocalName, XML_DELETION ) || + IsXMLToken( rLocalName, XML_FORMAT_CHANGE ) ) + { + // create XMLChangeElementImportContext for all kinds of changes + pContext = new XMLChangeElementImportContext( + GetImport(), nPrefix, rLocalName, + IsXMLToken( rLocalName, XML_DELETION ), + *this); + } + // else: it may be a text element, see below + } + + if (NULL == pContext) + { + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + + // was it a text element? If not, use default! + if (NULL == pContext) + { + pContext = SvXMLImportContext::CreateChildContext( + nPrefix, rLocalName, xAttrList); + } + } + + return pContext; +} + +void XMLChangedRegionImportContext::EndElement() +{ + // restore old XCursor (if necessary) + if (xOldCursor.is()) + { + // delete last paragraph + // (one extra paragraph was inserted in the beginning) + UniReference<XMLTextImportHelper> rHelper = + GetImport().GetTextImport(); + rHelper->DeleteParagraph(); + + GetImport().GetTextImport()->SetCursor(xOldCursor); + xOldCursor = NULL; + } +} + +void XMLChangedRegionImportContext::SetChangeInfo( + const OUString& rType, + const OUString& rAuthor, + const OUString& rComment, + const OUString& rDate) +{ + DateTime aDateTime; + if (SvXMLUnitConverter::convertDateTime(aDateTime, rDate)) + { + GetImport().GetTextImport()->RedlineAdd( + rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara); + } +} + +void XMLChangedRegionImportContext::UseRedlineText() +{ + // if we haven't already installed the redline cursor, do it now + if (! xOldCursor.is()) + { + // get TextImportHelper and old Cursor + UniReference<XMLTextImportHelper> rHelper(GetImport().GetTextImport()); + Reference<XTextCursor> xCursor( rHelper->GetCursor() ); + + // create Redline and new Cursor + Reference<XTextCursor> xNewCursor = + rHelper->RedlineCreateText(xCursor, sID); + + if (xNewCursor.is()) + { + // save old cursor and install new one + xOldCursor = xCursor; + rHelper->SetCursor( xNewCursor ); + } + // else: leave as is + } +} diff --git a/xmloff/source/text/XMLChangedRegionImportContext.hxx b/xmloff/source/text/XMLChangedRegionImportContext.hxx new file mode 100644 index 000000000000..ec87abcecdeb --- /dev/null +++ b/xmloff/source/text/XMLChangedRegionImportContext.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLCHANGEDREGIONIMPORTCONTEXT_HXX +#define _XMLOFF_XMLCHANGEDREGIONIMPORTCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace text { + class XTextCursor; + } + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} + + +class XMLChangedRegionImportContext : public SvXMLImportContext +{ + const ::rtl::OUString sEmpty; + + /// if we replace the current XTextCursor/XText by the ones for + /// the redline, we remeber the old cursor here. + ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextCursor> xOldCursor; + + ::rtl::OUString sID; /// redline-ID + + sal_Bool bMergeLastPara; /// merge-last-paragraph flag + +public: + + TYPEINFO(); + + XMLChangedRegionImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName); + + ~XMLChangedRegionImportContext(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + + /// change info: To be called from change-info context + void SetChangeInfo(const ::rtl::OUString& rType, + const ::rtl::OUString& rAuthor, + const ::rtl::OUString& rComment, + const ::rtl::OUString& rDate); + + /// create redline XText/XTextCursor on demand and register with + /// XMLTextImportHelper + void UseRedlineText(); +}; + + +#endif diff --git a/xmloff/source/text/XMLFootnoteBodyImportContext.cxx b/xmloff/source/text/XMLFootnoteBodyImportContext.cxx new file mode 100644 index 000000000000..5f48619c3946 --- /dev/null +++ b/xmloff/source/text/XMLFootnoteBodyImportContext.cxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLFootnoteBodyImportContext.hxx" + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <tools/debug.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <com/sun/star/xml/sax/XAttributeList.hpp> + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1( XMLFootnoteBodyImportContext, SvXMLImportContext ); + +XMLFootnoteBodyImportContext::XMLFootnoteBodyImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName ) : + SvXMLImportContext(rImport, nPrfx, rLocalName) +{ +} + +SvXMLImportContext* XMLFootnoteBodyImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + // return text context + SvXMLImportContext *pContext = + GetImport().GetTextImport()->CreateTextChildContext(GetImport(), + nPrefix, + rLocalName, + xAttrList, + XML_TEXT_TYPE_FOOTNOTE); + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} diff --git a/xmloff/source/text/XMLFootnoteBodyImportContext.hxx b/xmloff/source/text/XMLFootnoteBodyImportContext.hxx new file mode 100644 index 000000000000..5484853cedb9 --- /dev/null +++ b/xmloff/source/text/XMLFootnoteBodyImportContext.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLFOOTNOTEBODYIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLFOOTNOTEBODYIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} + + +/// import foot- and endnote body elements (<text:footnote-body>) +class XMLFootnoteBodyImportContext : public SvXMLImportContext +{ + +public: + + TYPEINFO(); + + XMLFootnoteBodyImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + +protected: + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); + +}; + +#endif diff --git a/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx b/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx new file mode 100644 index 000000000000..9f0658dc84da --- /dev/null +++ b/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx @@ -0,0 +1,457 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLFootnoteConfigurationImportContext.hxx" + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + +#ifndef _XMLOFF_FAMILIES_HXX +#include <xmloff/families.hxx> +#endif +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnumi.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XFootnote.hpp> +#include <com/sun/star/text/XFootnotesSupplier.hpp> +#include <com/sun/star/text/XEndnotesSupplier.hpp> +#include <com/sun/star/text/FootnoteNumbering.hpp> +#include <com/sun/star/style/NumberingType.hpp> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::xml::sax; +using namespace ::xmloff::token; + +// +// XMLFootnoteConfigHelper +// + +/// local helper class for import of quo-vadis and ergo-sum elements +class XMLFootnoteConfigHelper : public SvXMLImportContext +{ + OUStringBuffer sBuffer; + XMLFootnoteConfigurationImportContext& rConfig; + sal_Bool bIsBegin; + +public: + TYPEINFO(); + + XMLFootnoteConfigHelper( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + XMLFootnoteConfigurationImportContext& rConfigImport, + sal_Bool bBegin); + + virtual void EndElement(); + + virtual void Characters( const OUString& rChars ); +}; + +TYPEINIT1( XMLFootnoteConfigHelper, SvXMLImportContext ); + +XMLFootnoteConfigHelper::XMLFootnoteConfigHelper( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + XMLFootnoteConfigurationImportContext& rConfigImport, + sal_Bool bBegin) +: SvXMLImportContext(rImport, nPrfx, rLName) +, sBuffer() +, rConfig(rConfigImport) +, bIsBegin(bBegin) +{ +} + +void XMLFootnoteConfigHelper::EndElement() +{ + if (bIsBegin) + { + rConfig.SetBeginNotice(sBuffer.makeStringAndClear()); + } + else + { + rConfig.SetEndNotice(sBuffer.makeStringAndClear()); + } +// rConfig = NULL; // import contexts are ref-counted +} + +void XMLFootnoteConfigHelper::Characters( const OUString& rChars ) +{ + sBuffer.append(rChars); +} + + +// +// XMLFootnoteConfigurationImportContext +// + + +TYPEINIT1( XMLFootnoteConfigurationImportContext, SvXMLStyleContext ); + +XMLFootnoteConfigurationImportContext::XMLFootnoteConfigurationImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG) +, sPropertyAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName")) +, sPropertyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")) +, sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")) +, sPropertyPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName")) +, sPropertyParagraphStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")) +, sPropertyPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix")) +, sPropertyStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt")) +, sPropertySuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix")) +, sPropertyPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc")) +, sPropertyFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")) +, sPropertyEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice")) +, sPropertyBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice")) +, sNumFormat(RTL_CONSTASCII_USTRINGPARAM("1")) +, sNumSync(RTL_CONSTASCII_USTRINGPARAM("false")) +, pAttrTokenMap(NULL) +, nOffset(0) +, nNumbering(FootnoteNumbering::PER_PAGE) +, bPosition(sal_False) +, bIsEndnote(sal_False) +{ + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && IsXMLToken( sLocalName, + XML_NOTE_CLASS ) ) + { + const OUString& rValue = xAttrList->getValueByIndex( nAttr ); + if( IsXMLToken( rValue, XML_ENDNOTE ) ) + { + bIsEndnote = sal_True; + SetFamily( XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG ); + } + break; + } + } + +} +XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext() +{ + delete pAttrTokenMap; +} + +enum XMLFtnConfigToken +{ + XML_TOK_FTNCONFIG_CITATION_STYLENAME, + XML_TOK_FTNCONFIG_ANCHOR_STYLENAME, + XML_TOK_FTNCONFIG_DEFAULT_STYLENAME, + XML_TOK_FTNCONFIG_PAGE_STYLENAME, + XML_TOK_FTNCONFIG_OFFSET, + XML_TOK_FTNCONFIG_NUM_PREFIX, + XML_TOK_FTNCONFIG_NUM_SUFFIX, + XML_TOK_FTNCONFIG_NUM_FORMAT, + XML_TOK_FTNCONFIG_NUM_SYNC, + XML_TOK_FTNCONFIG_START_AT, + XML_TOK_FTNCONFIG_POSITION +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextFieldAttrTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME, XML_TOK_FTNCONFIG_CITATION_STYLENAME }, + { XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME, XML_TOK_FTNCONFIG_ANCHOR_STYLENAME }, + { XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME, XML_TOK_FTNCONFIG_DEFAULT_STYLENAME }, + { XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME, XML_TOK_FTNCONFIG_PAGE_STYLENAME }, + { XML_NAMESPACE_TEXT, XML_START_VALUE, XML_TOK_FTNCONFIG_OFFSET }, + { XML_NAMESPACE_STYLE, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX }, + { XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX }, + { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_FTNCONFIG_NUM_FORMAT }, + { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_TOK_FTNCONFIG_NUM_SYNC }, + { XML_NAMESPACE_TEXT, XML_START_NUMBERING_AT, XML_TOK_FTNCONFIG_START_AT}, + { XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION, XML_TOK_FTNCONFIG_POSITION}, + + // for backwards compatibility with SRC630 & earlier + { XML_NAMESPACE_TEXT, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX }, + { XML_NAMESPACE_TEXT, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX }, + { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_FTNCONFIG_OFFSET }, + XML_TOKEN_MAP_END +}; + +const SvXMLTokenMap& + XMLFootnoteConfigurationImportContext::GetFtnConfigAttrTokenMap() +{ + if (NULL == pAttrTokenMap) + { + pAttrTokenMap = new SvXMLTokenMap(aTextFieldAttrTokenMap); + } + + return *pAttrTokenMap; +} + +static SvXMLEnumMapEntry __READONLY_DATA aFootnoteNumberingMap[] = +{ + { XML_PAGE, FootnoteNumbering::PER_PAGE }, + { XML_CHAPTER, FootnoteNumbering::PER_CHAPTER }, + { XML_DOCUMENT, FootnoteNumbering::PER_DOCUMENT }, + { XML_TOKEN_INVALID, 0 }, +}; + +void XMLFootnoteConfigurationImportContext::StartElement( + const Reference<XAttributeList> & xAttrList ) +{ + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + OUString sValue = xAttrList->getValueByIndex(nAttr); + switch (GetFtnConfigAttrTokenMap().Get(nPrefix, sLocalName)) + { + case XML_TOK_FTNCONFIG_CITATION_STYLENAME: + sCitationStyle = sValue; + break; + case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME: + sAnchorStyle = sValue; + break; + case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME: + sDefaultStyle = sValue; + break; + case XML_TOK_FTNCONFIG_PAGE_STYLENAME: + sPageStyle = sValue; + break; + case XML_TOK_FTNCONFIG_OFFSET: + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber(nTmp, sValue)) + { + nOffset = (sal_uInt16)nTmp; + } + break; + } + case XML_TOK_FTNCONFIG_NUM_PREFIX: + sPrefix = sValue; + break; + case XML_TOK_FTNCONFIG_NUM_SUFFIX: + sSuffix = sValue; + break; + case XML_TOK_FTNCONFIG_NUM_FORMAT: + sNumFormat = sValue; + break; + case XML_TOK_FTNCONFIG_NUM_SYNC: + sNumSync = sValue; + break; + case XML_TOK_FTNCONFIG_START_AT: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sValue, + aFootnoteNumberingMap)) + { + nNumbering = nTmp; + } + break; + } + case XML_TOK_FTNCONFIG_POSITION: + bPosition = IsXMLToken( sValue, XML_DOCUMENT ); + break; + default: + ; // ignore + } + } +} + +SvXMLImportContext *XMLFootnoteConfigurationImportContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if (!bIsEndnote) + { + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( rLocalName, + XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD ) ) + { + pContext = new XMLFootnoteConfigHelper(GetImport(), + nPrefix, rLocalName, + *this, sal_False); + } + else if ( IsXMLToken( rLocalName, + XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD ) ) + { + pContext = new XMLFootnoteConfigHelper(GetImport(), + nPrefix, rLocalName, + *this, sal_True); + } + // else: default context + } + // else: unknown namespace -> default context + } + // else: endnote -> default context + + if (pContext == NULL) + { + // default: delegate to super class + pContext = SvXMLStyleContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + + return pContext; +} + + +// --> OD 2005-01-31 #i40597# - rename method <CreateAndInsertLate(..)> to +// <Finish(..)> +void XMLFootnoteConfigurationImportContext::Finish( sal_Bool bOverwrite ) +// <-- +{ + + if (bOverwrite) + { + if (bIsEndnote) + { + Reference<XEndnotesSupplier> xSupplier( + GetImport().GetModel(), UNO_QUERY); + if (xSupplier.is()) + { + ProcessSettings(xSupplier->getEndnoteSettings()); + } + } + else + { + Reference<XFootnotesSupplier> xSupplier( + GetImport().GetModel(), UNO_QUERY); + if (xSupplier.is()) + { + ProcessSettings(xSupplier->getFootnoteSettings()); + } + } + } + // else: ignore (there's only one configuration, so we can only overwrite) +} + +void XMLFootnoteConfigurationImportContext::ProcessSettings( + const Reference<XPropertySet> & rConfig) +{ + Any aAny; + + if (sCitationStyle.getLength() > 0) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sCitationStyle ); + rConfig->setPropertyValue(sPropertyCharStyleName, aAny); + } + + if (sAnchorStyle.getLength() > 0) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sAnchorStyle ); + rConfig->setPropertyValue(sPropertyAnchorCharStyleName, aAny); + } + + if (sPageStyle.getLength() > 0) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_MASTER_PAGE, sPageStyle ); + rConfig->setPropertyValue(sPropertyPageStyleName, aAny); + } + + if (sDefaultStyle.getLength() > 0) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, sDefaultStyle ); + rConfig->setPropertyValue(sPropertyParagraphStyleName, aAny); + } + + aAny <<= sPrefix; + rConfig->setPropertyValue(sPropertyPrefix, aAny); + + aAny <<= sSuffix; + rConfig->setPropertyValue(sPropertySuffix, aAny); + + sal_Int16 nNumType = NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, + sNumSync ); + // #i61399: Corrupt file? It contains "Bullet" as numbering style for footnotes. + // Okay, even it seems to be corrupt, we will oversee this and set the style to ARABIC + if( NumberingType::CHAR_SPECIAL == nNumType ) + nNumType = NumberingType::ARABIC; + + aAny <<= nNumType; + rConfig->setPropertyValue(sPropertyNumberingType, aAny); + + aAny <<= nOffset; + rConfig->setPropertyValue(sPropertyStartAt, aAny); + + if (!bIsEndnote) + { + aAny.setValue(&bPosition, ::getBooleanCppuType()); + rConfig->setPropertyValue(sPropertyPositionEndOfDoc, aAny); + + aAny <<= nNumbering; + rConfig->setPropertyValue(sPropertyFootnoteCounting, aAny); + + aAny <<= sEndNotice; + rConfig->setPropertyValue(sPropertyEndNotice, aAny); + + aAny <<= sBeginNotice; + rConfig->setPropertyValue(sPropertyBeginNotice, aAny); + } +} + +void XMLFootnoteConfigurationImportContext::SetBeginNotice( + OUString sText) +{ + sBeginNotice = sText; +} + +void XMLFootnoteConfigurationImportContext::SetEndNotice( + OUString sText) +{ + sEndNotice = sText; +} diff --git a/xmloff/source/text/XMLFootnoteImportContext.cxx b/xmloff/source/text/XMLFootnoteImportContext.cxx new file mode 100644 index 000000000000..5f7389a7b799 --- /dev/null +++ b/xmloff/source/text/XMLFootnoteImportContext.cxx @@ -0,0 +1,243 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLFootnoteImportContext.hxx" + +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + +#include "XMLFootnoteBodyImportContext.hxx" +#include "XMLTextListBlockContext.hxx" +#include "XMLTextListItemContext.hxx" + +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/XFootnote.hpp> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::xml::sax; +using namespace ::xmloff::token; + +TYPEINIT1(XMLFootnoteImportContext, SvXMLImportContext); + +const sal_Char sAPI_service_footnote[] = "com.sun.star.text.Footnote"; +const sal_Char sAPI_service_endnote[] = "com.sun.star.text.Endnote"; + +enum XMLFootnoteChildToken { + XML_TOK_FTN_NOTE_CITATION, + XML_TOK_FTN_NOTE_BODY +}; + +static __FAR_DATA SvXMLTokenMapEntry aFootnoteChildTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_NOTE_CITATION, + XML_TOK_FTN_NOTE_CITATION }, + { XML_NAMESPACE_TEXT, XML_NOTE_BODY, XML_TOK_FTN_NOTE_BODY }, + XML_TOKEN_MAP_END +}; + + +XMLFootnoteImportContext::XMLFootnoteImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& rLocalName ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sPropertyReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId")) +, mbListContextPushed(false) +, rHelper(rHlp) +{ +} + +void XMLFootnoteImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // create footnote + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(), + UNO_QUERY); + if( xFactory.is() ) + { + // create endnote or footnote + sal_Bool bIsEndnote = sal_False; + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr1 = 0; nAttr1 < nLength; nAttr1++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr1), + &sLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && IsXMLToken( sLocalName, + XML_NOTE_CLASS ) ) + { + const OUString& rValue = xAttrList->getValueByIndex( nAttr1 ); + if( IsXMLToken( rValue, XML_ENDNOTE ) ) + bIsEndnote = sal_True; + break; + } + } + + Reference<XInterface> xIfc = xFactory->createInstance( + bIsEndnote ? + OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_endnote)) : + OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_footnote)) ); + + // attach footnote to document + Reference<XTextContent> xTextContent(xIfc, UNO_QUERY); + rHelper.InsertTextContent(xTextContent); + + // process id attribute + for(sal_Int16 nAttr2 = 0; nAttr2 < nLength; nAttr2++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr2), + &sLocalName ); + + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken( sLocalName, XML_ID ) ) + { + // get ID ... + Reference<XPropertySet> xPropertySet(xTextContent, UNO_QUERY); + Any aAny =xPropertySet->getPropertyValue(sPropertyReferenceId); + sal_Int16 nID = 0; + aAny >>= nID; + + // ... and insert into map + rHelper.InsertFootnoteID( + xAttrList->getValueByIndex(nAttr2), + nID); + } + } + + // save old cursor and install new one + xOldCursor = rHelper.GetCursor(); + Reference<XText> xText(xTextContent, UNO_QUERY); + rHelper.SetCursor(xText->createTextCursor()); + + // remember old list item and block (#89891#) and reset them + // for the footnote + rHelper.PushListContext(); + mbListContextPushed = true; + + // remember footnote (for CreateChildContext) + Reference<XFootnote> xNote(xTextContent, UNO_QUERY); + xFootnote = xNote; + } + // else: ignore footnote! Content will be merged into document. +} + +void XMLFootnoteImportContext::Characters(const OUString&) +{ + // ignore characters! Text must be contained in paragraphs! + // rHelper.InsertString(rString); +} + +void XMLFootnoteImportContext::EndElement() +{ + // get rid of last dummy paragraph + rHelper.DeleteParagraph(); + + // reinstall old cursor + rHelper.SetCursor(xOldCursor); + + // reinstall old list item + if (mbListContextPushed) { + rHelper.PopListContext(); + } +} + + +SvXMLImportContext *XMLFootnoteImportContext::CreateChildContext( + sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + SvXMLTokenMap aTokenMap(aFootnoteChildTokenMap); + + switch(aTokenMap.Get(p_nPrefix, rLocalName)) + { + case XML_TOK_FTN_NOTE_CITATION: + { + // little hack: we only care for one attribute of the citation + // element. We handle that here, and then return a + // default context. + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if ( (nPrefix == XML_NAMESPACE_TEXT) && + IsXMLToken( sLocalName, XML_LABEL ) ) + { + xFootnote->setLabel(xAttrList->getValueByIndex(nAttr)); + } + } + + // ignore content: return default context + pContext = new SvXMLImportContext(GetImport(), + p_nPrefix, rLocalName); + break; + } + + case XML_TOK_FTN_NOTE_BODY: + // return footnote body + pContext = new XMLFootnoteBodyImportContext(GetImport(), + p_nPrefix, rLocalName); + break; + default: + // default: + pContext = SvXMLImportContext::CreateChildContext(p_nPrefix, + rLocalName, + xAttrList); + break; + } + + return pContext; +} diff --git a/xmloff/source/text/XMLFootnoteImportContext.hxx b/xmloff/source/text/XMLFootnoteImportContext.hxx new file mode 100644 index 000000000000..d48f7afa4057 --- /dev/null +++ b/xmloff/source/text/XMLFootnoteImportContext.hxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLFOOTNOTEIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLFOOTNOTEIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace text { + class XTextCursor; + class XFootnote; + } + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} +class XMLTextImportHelper; + +/// import footnote elements (<text:footnote>) +class XMLFootnoteImportContext : public SvXMLImportContext +{ + const ::rtl::OUString sPropertyReferenceId; + + /// old document cursor + ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextCursor> xOldCursor; + + /// old list item and block (#89891#) + bool mbListContextPushed; + + /// text import helper; holds current XTextCursor (and XText) + XMLTextImportHelper& rHelper; + + /// the footnote + ::com::sun::star::uno::Reference< + ::com::sun::star::text::XFootnote> xFootnote; + +public: + + TYPEINFO(); + + XMLFootnoteImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void Characters( + const ::rtl::OUString& rChars); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); + +}; + +#endif diff --git a/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx new file mode 100644 index 000000000000..52147bc8caf2 --- /dev/null +++ b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx @@ -0,0 +1,271 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexAlphabeticalSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + + + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE; +using ::xmloff::token::XML_OUTLINE_LEVEL; + +const sal_Char sAPI_MainEntryCharacterStyleName[] = "MainEntryCharacterStyleName"; +const sal_Char sAPI_UseAlphabeticalSeparators[] = "UseAlphabeticalSeparators"; +const sal_Char sAPI_UseCombinedEntries[] = "UseCombinedEntries"; +const sal_Char sAPI_IsCaseSensitive[] = "IsCaseSensitive"; +const sal_Char sAPI_UseKeyAsEntry[] = "UseKeyAsEntry"; +const sal_Char sAPI_UseUpperCase[] = "UseUpperCase"; +const sal_Char sAPI_UseDash[] = "UseDash"; +const sal_Char sAPI_UsePP[] = "UsePP"; +const sal_Char sAPI_SortAlgorithm[] = "SortAlgorithm"; +const sal_Char sAPI_Locale[] = "Locale"; + + +TYPEINIT1( XMLIndexAlphabeticalSourceContext, XMLIndexSourceBaseContext ); + +XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) +: XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_False) +, sMainEntryCharacterStyleName(RTL_CONSTASCII_USTRINGPARAM(sAPI_MainEntryCharacterStyleName)) +, sUseAlphabeticalSeparators(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseAlphabeticalSeparators)) +, sUseCombinedEntries(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseCombinedEntries)) +, sIsCaseSensitive(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsCaseSensitive)) +, sUseKeyAsEntry(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseKeyAsEntry)) +, sUseUpperCase(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseUpperCase)) +, sUseDash(RTL_CONSTASCII_USTRINGPARAM(sAPI_UseDash)) +, sUsePP(RTL_CONSTASCII_USTRINGPARAM(sAPI_UsePP)) +, sIsCommaSeparated(RTL_CONSTASCII_USTRINGPARAM("IsCommaSeparated")) +, sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM(sAPI_SortAlgorithm)) +, sLocale(RTL_CONSTASCII_USTRINGPARAM(sAPI_Locale)) +, bMainEntryStyleNameOK(sal_False) +, bSeparators(sal_False) +, bCombineEntries(sal_True) +, bCaseSensitive(sal_True) +, bEntry(sal_False) +, bUpperCase(sal_False) +, bCombineDash(sal_False) +, bCombinePP(sal_True) +, bCommaSeparated(sal_False) +{ +} + +XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext() +{ +} + +void XMLIndexAlphabeticalSourceContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + sal_Bool bTmp; + + switch (eParam) + { + case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE: + { + sMainEntryStyleName = rValue; + OUString sDisplayStyleName = GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName ); + const Reference < ::com::sun::star::container::XNameContainer >& + rStyles = GetImport().GetTextImport()->GetTextStyles(); + bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName ); + } + break; + + case XML_TOK_INDEXSOURCE_IGNORE_CASE: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bCaseSensitive = !bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_SEPARATORS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bSeparators = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bCombineEntries = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bCombineDash = bTmp; + } + break; + case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bEntry = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bCombinePP = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_CAPITALIZE: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUpperCase = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_COMMA_SEPARATED: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bCommaSeparated = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_SORT_ALGORITHM: + sAlgorithm = rValue; + break; + case XML_TOK_INDEXSOURCE_LANGUAGE: + aLocale.Language = rValue; + break; + case XML_TOK_INDEXSOURCE_COUNTRY: + aLocale.Country = rValue; + break; + + default: + XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); + break; + } +} + +void XMLIndexAlphabeticalSourceContext::EndElement() +{ + + Any aAny; + + if (bMainEntryStyleNameOK) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName ); + rIndexPropertySet->setPropertyValue(sMainEntryCharacterStyleName,aAny); + } + + aAny.setValue(&bSeparators, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseAlphabeticalSeparators, aAny); + + aAny.setValue(&bCombineEntries, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseCombinedEntries, aAny); + + aAny.setValue(&bCaseSensitive, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sIsCaseSensitive, aAny); + + aAny.setValue(&bEntry, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseKeyAsEntry, aAny); + + aAny.setValue(&bUpperCase, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseUpperCase, aAny); + + aAny.setValue(&bCombineDash, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseDash, aAny); + + aAny.setValue(&bCombinePP, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUsePP, aAny); + + aAny.setValue(&bCommaSeparated, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sIsCommaSeparated, aAny); + + + if (sAlgorithm.getLength() > 0) + { + aAny <<= sAlgorithm; + rIndexPropertySet->setPropertyValue(sSortAlgorithm, aAny); + } + + if ( (aLocale.Language.getLength() > 0) && + (aLocale.Country.getLength() > 0) ) + { + aAny <<= aLocale; + rIndexPropertySet->setPropertyValue(sLocale, aAny); + } + + XMLIndexSourceBaseContext::EndElement(); +} + +SvXMLImportContext* XMLIndexAlphabeticalSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken( rLocalName, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE ) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameAlphaMap, + XML_OUTLINE_LEVEL, + aLevelStylePropNameAlphaMap, + aAllowedTokenTypesAlpha); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } +} diff --git a/xmloff/source/text/XMLIndexAlphabeticalSourceContext.hxx b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.hxx new file mode 100644 index 000000000000..caf04f5fbef3 --- /dev/null +++ b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXALPHABETICALSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXALPHABETICALSOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/lang/Locale.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import alphabetical (keyword) index source element + */ +class XMLIndexAlphabeticalSourceContext : public XMLIndexSourceBaseContext +{ + const ::rtl::OUString sMainEntryCharacterStyleName; + const ::rtl::OUString sUseAlphabeticalSeparators; + const ::rtl::OUString sUseCombinedEntries; + const ::rtl::OUString sIsCaseSensitive; + const ::rtl::OUString sUseKeyAsEntry; + const ::rtl::OUString sUseUpperCase; + const ::rtl::OUString sUseDash; + const ::rtl::OUString sUsePP; + const ::rtl::OUString sIsCommaSeparated; + const ::rtl::OUString sSortAlgorithm; + const ::rtl::OUString sLocale; + + ::com::sun::star::lang::Locale aLocale; + ::rtl::OUString sAlgorithm; + + ::rtl::OUString sMainEntryStyleName; + sal_Bool bMainEntryStyleNameOK; + + sal_Bool bSeparators; + sal_Bool bCombineEntries; + sal_Bool bCaseSensitive; + sal_Bool bEntry; + sal_Bool bUpperCase; + sal_Bool bCombineDash; + sal_Bool bCombinePP; + sal_Bool bCommaSeparated; + +public: + + TYPEINFO(); + + XMLIndexAlphabeticalSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexAlphabeticalSourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexBibliographyConfigurationContext.cxx b/xmloff/source/text/XMLIndexBibliographyConfigurationContext.cxx new file mode 100644 index 000000000000..23e11530d73f --- /dev/null +++ b/xmloff/source/text/XMLIndexBibliographyConfigurationContext.cxx @@ -0,0 +1,297 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexBibliographyConfigurationContext.hxx" +#include "XMLIndexBibliographyEntryContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::lang::XMultiServiceFactory; + +const sal_Char sAPI_FieldMaster_Bibliography[] = + "com.sun.star.text.FieldMaster.Bibliography"; + + +TYPEINIT1( XMLIndexBibliographyConfigurationContext, SvXMLStyleContext ); + +XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) : + SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG), + sFieldMaster_Bibliography( + RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography)), + sBracketBefore(RTL_CONSTASCII_USTRINGPARAM("BracketBefore")), + sBracketAfter(RTL_CONSTASCII_USTRINGPARAM("BracketAfter")), + sIsNumberEntries(RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries")), + sIsSortByPosition(RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition")), + sSortKeys(RTL_CONSTASCII_USTRINGPARAM("SortKeys")), + sSortKey(RTL_CONSTASCII_USTRINGPARAM("SortKey")), + sIsSortAscending(RTL_CONSTASCII_USTRINGPARAM("IsSortAscending")), + sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")), + sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale")), + sSuffix(), + sPrefix(), + sAlgorithm(), + aLocale(), + bNumberedEntries(sal_False), + bSortByPosition(sal_True) +{ +} + +XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext() +{ +} + +void XMLIndexBibliographyConfigurationContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + ProcessAttribute(nPrefix, sLocalName, + xAttrList->getValueByIndex(nAttr)); + // else: ignore + } +} + +void XMLIndexBibliographyConfigurationContext::ProcessAttribute( + sal_uInt16 nPrefix, + OUString sLocalName, + OUString sValue) +{ + if( XML_NAMESPACE_TEXT == nPrefix ) + { + if( IsXMLToken(sLocalName, XML_PREFIX) ) + { + sPrefix = sValue; + } + else if( IsXMLToken(sLocalName, XML_SUFFIX) ) + { + sSuffix = sValue; + } + else if( IsXMLToken(sLocalName, XML_NUMBERED_ENTRIES) ) + { + sal_Bool bTmp; + if( SvXMLUnitConverter::convertBool(bTmp, sValue) ) + { + bNumberedEntries = bTmp; + } + } + else if( IsXMLToken(sLocalName, XML_SORT_BY_POSITION) ) + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + { + bSortByPosition = bTmp; + } + } + else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) ) + { + sAlgorithm = sValue; + } + } + else if( XML_NAMESPACE_FO == nPrefix ) + { + if( IsXMLToken(sLocalName, XML_LANGUAGE) ) + { + aLocale.Language = sValue; + } + else if( IsXMLToken(sLocalName, XML_COUNTRY) ) + { + aLocale.Country = sValue; + } + } +} + + +SvXMLImportContext *XMLIndexBibliographyConfigurationContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + OUString sKey; + sal_Bool bSort(sal_True); + + // process children here and use default context! + if ( ( nPrefix == XML_NAMESPACE_TEXT ) && + IsXMLToken( rLocalName, XML_SORT_KEY ) ) + { + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrfx = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if (nPrfx == XML_NAMESPACE_TEXT) + { + if ( IsXMLToken( sLocalName, XML_KEY ) ) + { + sKey = xAttrList->getValueByIndex(nAttr); + } + else if ( IsXMLToken( sLocalName, XML_SORT_ASCENDING ) ) + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool( + bTmp, xAttrList->getValueByIndex(nAttr))) + { + bSort = bTmp; + } + } + } + } + + // valid data? + sal_uInt16 nKey; + if (SvXMLUnitConverter::convertEnum(nKey, sKey, + aBibliographyDataFieldMap)) + { + + Any aAny; + Sequence<PropertyValue> aKey(2); + + PropertyValue aNameValue; + aNameValue.Name = sSortKey; + aAny <<= (sal_Int16)nKey; + aNameValue.Value = aAny; + aKey[0] = aNameValue; + + PropertyValue aSortValue; + aSortValue.Name = sIsSortAscending; + aAny.setValue(&bSort, ::getBooleanCppuType()); + aSortValue.Value = aAny; + aKey[1] = aSortValue; + + aSortKeys.push_back(aKey); + } + } + + return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); +} + +void XMLIndexBibliographyConfigurationContext::CreateAndInsert(sal_Bool) +{ + // (code almost the same as export...) + + // insert and block mode is handled in insertStyleFamily + + // first: get field master + // (we'll create one, and get the only master for this type) + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY); + if( xFactory.is() ) + { + Sequence<rtl::OUString> aServices = xFactory->getAvailableServiceNames(); + sal_Bool bFound(sal_False); + sal_Int32 i(0); + sal_Int32 nServiceCount(aServices.getLength()); + while (i < nServiceCount && !bFound) + { + if (aServices[i].equals(sFieldMaster_Bibliography)) + // here we should use a methode which compares in reverse order if available + // #85282# + bFound = sal_True; + else + i++; + } + if (bFound) + { + Reference<XInterface> xIfc = + xFactory->createInstance(sFieldMaster_Bibliography); + if( xIfc.is() ) + { + Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY ); + Any aAny; + + aAny <<= sSuffix; + xPropSet->setPropertyValue(sBracketAfter, aAny); + + aAny <<= sPrefix; + xPropSet->setPropertyValue(sBracketBefore, aAny); + + aAny.setValue(&bNumberedEntries, ::getBooleanCppuType()); + xPropSet->setPropertyValue(sIsNumberEntries, aAny); + + aAny.setValue(&bSortByPosition, ::getBooleanCppuType()); + xPropSet->setPropertyValue(sIsSortByPosition, aAny); + + if( (aLocale.Language.getLength() > 0) && + (aLocale.Country.getLength() > 0) ) + { + aAny <<= aLocale; + xPropSet->setPropertyValue(sLocale, aAny); + } + + if( sAlgorithm.getLength() > 0 ) + { + aAny <<= sAlgorithm; + xPropSet->setPropertyValue(sSortAlgorithm, aAny); + } + + sal_Int32 nCount = aSortKeys.size(); + Sequence<Sequence<PropertyValue> > aKeysSeq(nCount); + for(i = 0; i < nCount; i++) + { + aKeysSeq[i] = aSortKeys[i]; + } + aAny <<= aKeysSeq; + xPropSet->setPropertyValue(sSortKeys, aAny); + } + // else: can't get FieldMaster -> ignore + } + } + // else: can't even get Factory -> ignore +} diff --git a/xmloff/source/text/XMLIndexBibliographyEntryContext.cxx b/xmloff/source/text/XMLIndexBibliographyEntryContext.cxx new file mode 100644 index 000000000000..2fafdf44c10f --- /dev/null +++ b/xmloff/source/text/XMLIndexBibliographyEntryContext.cxx @@ -0,0 +1,181 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexBibliographyEntryContext.hxx" +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/text/BibliographyDataField.hpp> + + +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + + +const sal_Char sAPI_TokenType[] = "TokenType"; +const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName"; + +TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext); + +XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const OUString& rLocalName ) : + XMLIndexSimpleEntryContext(rImport, + rTemplate.sTokenBibliographyDataField, + rTemplate, + nPrfx, rLocalName), + nBibliographyInfo(BibliographyDataField::IDENTIFIER), + bBibliographyInfoOK(sal_False) +{ +} + +XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext() +{ +} + +const SvXMLEnumMapEntry aBibliographyDataFieldMap[] = +{ + { XML_ADDRESS, BibliographyDataField::ADDRESS }, + { XML_ANNOTE, BibliographyDataField::ANNOTE }, + { XML_AUTHOR, BibliographyDataField::AUTHOR }, + { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE }, + // #96658#: also read old documents (bib*i*liographic...) + { XML_BIBILIOGRAPHIC_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE }, + { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE }, + { XML_CHAPTER, BibliographyDataField::CHAPTER }, + { XML_CUSTOM1, BibliographyDataField::CUSTOM1 }, + { XML_CUSTOM2, BibliographyDataField::CUSTOM2 }, + { XML_CUSTOM3, BibliographyDataField::CUSTOM3 }, + { XML_CUSTOM4, BibliographyDataField::CUSTOM4 }, + { XML_CUSTOM5, BibliographyDataField::CUSTOM5 }, + { XML_EDITION, BibliographyDataField::EDITION }, + { XML_EDITOR, BibliographyDataField::EDITOR }, + { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED }, + { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER }, + { XML_INSTITUTION, BibliographyDataField::INSTITUTION }, + { XML_ISBN, BibliographyDataField::ISBN }, + { XML_JOURNAL, BibliographyDataField::JOURNAL }, + { XML_MONTH, BibliographyDataField::MONTH }, + { XML_NOTE, BibliographyDataField::NOTE }, + { XML_NUMBER, BibliographyDataField::NUMBER }, + { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS }, + { XML_PAGES, BibliographyDataField::PAGES }, + { XML_PUBLISHER, BibliographyDataField::PUBLISHER }, + { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE }, + { XML_SCHOOL, BibliographyDataField::SCHOOL }, + { XML_SERIES, BibliographyDataField::SERIES }, + { XML_TITLE, BibliographyDataField::TITLE }, + { XML_URL, BibliographyDataField::URL }, + { XML_VOLUME, BibliographyDataField::VOLUME }, + { XML_YEAR, BibliographyDataField::YEAR }, + { XML_TOKEN_INVALID, 0 } +}; + +void XMLIndexBibliographyEntryContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // handle both, style name and bibliography info + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) ) + { + sCharStyleName = xAttrList->getValueByIndex(nAttr); + bCharStyleNameOK = sal_True; + } + else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) ) + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum( + nTmp, xAttrList->getValueByIndex(nAttr), + aBibliographyDataFieldMap)) + { + nBibliographyInfo = nTmp; + bBibliographyInfoOK = sal_True; + } + } + } + } + + // if we have a style name, set it! + if (bCharStyleNameOK) + { + nValues++; + } + + // always bibliography; else element is not valid + nValues++; +} + +void XMLIndexBibliographyEntryContext::EndElement() +{ + // only valid, if we have bibliography info + if (bBibliographyInfoOK) + { + XMLIndexSimpleEntryContext::EndElement(); + } +} + +void XMLIndexBibliographyEntryContext::FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues) +{ + // entry name and (optionally) style name in parent class + XMLIndexSimpleEntryContext::FillPropertyValues(rValues); + + // bibliography data field + sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1; + rValues[nIndex].Name = rTemplateContext.sBibliographyDataField; + Any aAny; + aAny <<= nBibliographyInfo; + rValues[nIndex].Value = aAny; +} diff --git a/xmloff/source/text/XMLIndexBibliographyEntryContext.hxx b/xmloff/source/text/XMLIndexBibliographyEntryContext.hxx new file mode 100644 index 000000000000..cc7036f1185b --- /dev/null +++ b/xmloff/source/text/XMLIndexBibliographyEntryContext.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXBIBLIOGRAPHYENTRYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXBIBLIOGRAPHYENTRYCONTEXT_HXX_ + +#include "XMLIndexSimpleEntryContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } +class XMLIndexTemplateContext; +struct SvXMLEnumMapEntry; + +extern const SvXMLEnumMapEntry aBibliographyDataFieldMap[]; + +/** + * Import bibliography index entry templates + */ +class XMLIndexBibliographyEntryContext : public XMLIndexSimpleEntryContext +{ + // bibliography info + sal_Int16 nBibliographyInfo; + sal_Bool bBibliographyInfoOK; + +public: + + TYPEINFO(); + + XMLIndexBibliographyEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexBibliographyEntryContext(); + +protected: + + /** process parameters */ + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + /** call FillPropertyValues and insert into template */ + virtual void EndElement(); + + /** fill property values for this template entry */ + virtual void FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); + +}; + +#endif diff --git a/xmloff/source/text/XMLIndexBibliographySourceContext.cxx b/xmloff/source/text/XMLIndexBibliographySourceContext.cxx new file mode 100644 index 000000000000..a617c150fd4e --- /dev/null +++ b/xmloff/source/text/XMLIndexBibliographySourceContext.cxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexBibliographySourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1(XMLIndexBibliographySourceContext, XMLIndexSourceBaseContext); + + +XMLIndexBibliographySourceContext::XMLIndexBibliographySourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) : + XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, + rPropSet, sal_False) +{ +} + +XMLIndexBibliographySourceContext::~XMLIndexBibliographySourceContext() +{ +} + +void XMLIndexBibliographySourceContext::ProcessAttribute( + enum IndexSourceParamEnum, + const OUString&) +{ + // We have no attributes. Who wants attributes, anyway? +} + + +void XMLIndexBibliographySourceContext::EndElement() +{ + // No attributes, no properties. +} + + +SvXMLImportContext* XMLIndexBibliographySourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( ( XML_NAMESPACE_TEXT == nPrefix ) && + ( IsXMLToken( rLocalName, XML_BIBLIOGRAPHY_ENTRY_TEMPLATE ) ) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameBibliographyMap, + XML_BIBLIOGRAPHY_TYPE, + aLevelStylePropNameBibliographyMap, + aAllowedTokenTypesBibliography); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + +} diff --git a/xmloff/source/text/XMLIndexBibliographySourceContext.hxx b/xmloff/source/text/XMLIndexBibliographySourceContext.hxx new file mode 100644 index 000000000000..fb5fd492dc69 --- /dev/null +++ b/xmloff/source/text/XMLIndexBibliographySourceContext.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXBIBLIOGRAPHYSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXBIBLIOGRAPHYSOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import bibliography source element + */ +class XMLIndexBibliographySourceContext : public XMLIndexSourceBaseContext +{ + +public: + + TYPEINFO(); + + XMLIndexBibliographySourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexBibliographySourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexBodyContext.cxx b/xmloff/source/text/XMLIndexBodyContext.cxx new file mode 100644 index 000000000000..0776760c1de1 --- /dev/null +++ b/xmloff/source/text/XMLIndexBodyContext.cxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexBodyContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1( XMLIndexBodyContext, SvXMLImportContext); + +XMLIndexBodyContext::XMLIndexBodyContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + bHasContent(sal_False) +{ +} + +XMLIndexBodyContext::~XMLIndexBodyContext() +{ +} + +SvXMLImportContext* XMLIndexBodyContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +{ + SvXMLImportContext* pContext = NULL; + + // return text content (if possible) + pContext = GetImport().GetTextImport()->CreateTextChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, XML_TEXT_TYPE_SECTION ); + if (NULL == pContext) + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + else + bHasContent = sal_True; + + return pContext; +} diff --git a/xmloff/source/text/XMLIndexBodyContext.hxx b/xmloff/source/text/XMLIndexBodyContext.hxx new file mode 100644 index 000000000000..948a10eb3881 --- /dev/null +++ b/xmloff/source/text/XMLIndexBodyContext.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXBODYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXBODYCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + +/** + * Import index body. + * + * This class basically delegates all CreateChildContext() calls to + * the text import and doesn't do much else. + */ +class XMLIndexBodyContext : public SvXMLImportContext +{ + sal_Bool bHasContent; + +public: + + TYPEINFO(); + + XMLIndexBodyContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexBodyContext(); + + /// return whether any content elements were encountered + inline sal_Bool HasContent(); + +protected: + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +inline sal_Bool XMLIndexBodyContext::HasContent() +{ + return bHasContent; +} + +#endif diff --git a/xmloff/source/text/XMLIndexChapterInfoEntryContext.cxx b/xmloff/source/text/XMLIndexChapterInfoEntryContext.cxx new file mode 100644 index 000000000000..bc5cb36ecb81 --- /dev/null +++ b/xmloff/source/text/XMLIndexChapterInfoEntryContext.cxx @@ -0,0 +1,205 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexChapterInfoEntryContext.hxx" +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/text/ChapterFormat.hpp> + + +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + + + +TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext); + +XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const OUString& rLocalName, + sal_Bool bT ) : + XMLIndexSimpleEntryContext(rImport, + (bT ? rTemplate.sTokenEntryNumber + : rTemplate.sTokenChapterInfo), + rTemplate, nPrfx, rLocalName), + nChapterInfo(ChapterFormat::NAME_NUMBER), + bChapterInfoOK(sal_False), + bTOC( bT ), + nOutlineLevel( 0 ), + bOutlineLevelOK(sal_False) +{ +} + +XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext() +{ +} + +static const SvXMLEnumMapEntry aChapterDisplayMap[] = +{ + { XML_NAME, ChapterFormat::NAME }, + { XML_NUMBER, ChapterFormat::NUMBER }, + { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER }, + //---> i89791 + // enabled for ODF 1.2, full index support in 3.0 + { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX }, + //<--- + { XML_PLAIN_NUMBER, ChapterFormat::DIGIT }, + { XML_TOKEN_INVALID, 0 } +}; + +void XMLIndexChapterInfoEntryContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // handle both, style name and bibliography info + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) ) + { + sCharStyleName = xAttrList->getValueByIndex(nAttr); + bCharStyleNameOK = sal_True; + } + else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum( + nTmp, xAttrList->getValueByIndex(nAttr), + aChapterDisplayMap)) + { + nChapterInfo = nTmp; + bChapterInfoOK = sal_True; + } + } + else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) ) + { + sal_Int32 nTmp; + + if (SvXMLUnitConverter::convertNumber(nTmp, xAttrList->getValueByIndex(nAttr))) + { +//control on range is carried out in the UNO level + nOutlineLevel = static_cast<sal_uInt16>(nTmp); + bOutlineLevelOK = sal_True; + } + } + } + } + + // if we have a style name, set it! + if (bCharStyleNameOK) + { + nValues++; + } + + // if we have chaper info, set it! + if (bChapterInfoOK) + { + nValues++; + // --> OD 2008-06-26 #i89791# + if ( !bTOC ) + { + bool bConvert( false ); + { + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild ); + if ( GetImport().IsTextDocInOOoFileFormat() || + ( bBuildIdFound && + ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) ) + { + bConvert = true; + } + } + if ( bConvert ) + { + if ( nChapterInfo == ChapterFormat::NUMBER ) + { + nChapterInfo = ChapterFormat::DIGIT; + } + else if ( nChapterInfo == ChapterFormat::NAME_NUMBER ) + { + nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX; + } + } + } + // <-- + } + if (bOutlineLevelOK) + nValues++; +} + +void XMLIndexChapterInfoEntryContext::FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues) +{ + // entry name and (optionally) style name in parent class + XMLIndexSimpleEntryContext::FillPropertyValues(rValues); + + sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1; + + if( bChapterInfoOK ) + { + // chapter info field + rValues[nIndex].Name = rTemplateContext.sChapterFormat; + Any aAny; + aAny <<= nChapterInfo; + rValues[nIndex].Value = aAny; + nIndex++; + } + if( bOutlineLevelOK ) + { + rValues[nIndex].Name = rTemplateContext.sChapterLevel; + Any aAny; + aAny <<= nOutlineLevel; + rValues[nIndex].Value = aAny; + } +} diff --git a/xmloff/source/text/XMLIndexChapterInfoEntryContext.hxx b/xmloff/source/text/XMLIndexChapterInfoEntryContext.hxx new file mode 100644 index 000000000000..247b4f73cea5 --- /dev/null +++ b/xmloff/source/text/XMLIndexChapterInfoEntryContext.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXCHAPTERINFOENTRYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXCHAPTERINFOENTRYCONTEXT_HXX_ + +#include "XMLIndexSimpleEntryContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } +class XMLIndexTemplateContext; + +/** + * Import chapter info index entry templates + */ +class XMLIndexChapterInfoEntryContext : public XMLIndexSimpleEntryContext +{ + // chapter format + sal_Int16 nChapterInfo; + sal_Bool bChapterInfoOK; + sal_Bool bTOC; + sal_Int16 nOutlineLevel; + sal_Bool bOutlineLevelOK; + +public: + + TYPEINFO(); + + XMLIndexChapterInfoEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + sal_Bool bTOC ); + + ~XMLIndexChapterInfoEntryContext(); + +protected: + + /** process parameters */ + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + /** fill property values for this template entry */ + virtual void FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx new file mode 100644 index 000000000000..40c32701d50a --- /dev/null +++ b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexIllustrationSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE; +using ::xmloff::token::XML_TOKEN_INVALID; + +TYPEINIT1(XMLIndexIllustrationSourceContext, XMLIndexTableSourceContext); + + +XMLIndexIllustrationSourceContext::XMLIndexIllustrationSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) : + XMLIndexTableSourceContext(rImport, nPrfx, rLocalName, rPropSet) +{ +} + +XMLIndexIllustrationSourceContext::~XMLIndexIllustrationSourceContext() +{ +} + +SvXMLImportContext* XMLIndexIllustrationSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( ( XML_NAMESPACE_TEXT == nPrefix ) && + ( IsXMLToken( rLocalName, XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE ) ) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameTableMap, + XML_TOKEN_INVALID, // no outline-level attr + aLevelStylePropNameTableMap, + aAllowedTokenTypesTable); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + +} diff --git a/xmloff/source/text/XMLIndexIllustrationSourceContext.hxx b/xmloff/source/text/XMLIndexIllustrationSourceContext.hxx new file mode 100644 index 000000000000..0a56bc15a744 --- /dev/null +++ b/xmloff/source/text/XMLIndexIllustrationSourceContext.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXILLUSTRATIONSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXILLUSTRATIONSOURCECONTEXT_HXX_ + +#include "XMLIndexTableSourceContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import illustration index source element; + * + * All logic is inherited from table source context. The only difference is + * the different child context (illustration entry template). + */ +class XMLIndexIllustrationSourceContext : public XMLIndexTableSourceContext +{ +public: + + TYPEINFO(); + + XMLIndexIllustrationSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexIllustrationSourceContext(); + +protected: + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexMarkExport.cxx b/xmloff/source/text/XMLIndexMarkExport.cxx new file mode 100644 index 000000000000..325e7a66f83f --- /dev/null +++ b/xmloff/source/text/XMLIndexMarkExport.cxx @@ -0,0 +1,267 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLIndexMarkExport.hxx" +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmluconv.hxx> + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::XPropertySetInfo; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; + + + +XMLIndexMarkExport::XMLIndexMarkExport( + SvXMLExport& rExp, + XMLTextParagraphExport& rParaExp) +: sLevel(RTL_CONSTASCII_USTRINGPARAM("Level")) +, sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")) +, sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")) +, sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")) +, sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark")) +, sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")) +, sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")) +, sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")) +, sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")) +, sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")) +, sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")) +, sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry")) +, rExport(rExp) +, rParaExport(rParaExp) +{ +} + +const enum XMLTokenEnum lcl_pTocMarkNames[] = + { XML_TOC_MARK, XML_TOC_MARK_START, XML_TOC_MARK_END }; +const enum XMLTokenEnum lcl_pUserIndexMarkName[] = + { XML_USER_INDEX_MARK, + XML_USER_INDEX_MARK_START, XML_USER_INDEX_MARK_END }; +const enum XMLTokenEnum lcl_pAlphaIndexMarkName[] = + { XML_ALPHABETICAL_INDEX_MARK, + XML_ALPHABETICAL_INDEX_MARK_START, + XML_ALPHABETICAL_INDEX_MARK_END }; + + +XMLIndexMarkExport::~XMLIndexMarkExport() +{ +} + +void XMLIndexMarkExport::ExportIndexMark( + const Reference<XPropertySet> & rPropSet, + sal_Bool bAutoStyles) +{ + /// index marks have no styles! + if (!bAutoStyles) + { + const enum XMLTokenEnum * pElements = NULL; + sal_Int8 nElementNo = -1; + + // get index mark + Any aAny; + aAny = rPropSet->getPropertyValue(sDocumentIndexMark); + Reference<XPropertySet> xIndexMarkPropSet; + aAny >>= xIndexMarkPropSet; + + // common: handling of start, end, collapsed entries and + // alternative text + + // collapsed/alternative text entry? + aAny = rPropSet->getPropertyValue(sIsCollapsed); + if (*(sal_Bool *)aAny.getValue()) + { + // collapsed entry: needs alternative text + nElementNo = 0; + + aAny = xIndexMarkPropSet->getPropertyValue(sAlternativeText); + OUString sTmp; + aAny >>= sTmp; + DBG_ASSERT(sTmp.getLength() > 0, + "collapsed index mark without alternative text"); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STRING_VALUE, sTmp); + } + else + { + // start and end entries: has ID + aAny = rPropSet->getPropertyValue(sIsStart); + nElementNo = *(sal_Bool *)aAny.getValue() ? 1 : 2; + + // generate ID + OUStringBuffer sBuf; + GetID(sBuf, xIndexMarkPropSet); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_ID, + sBuf.makeStringAndClear()); + } + + // distinguish between TOC, user, alphab. index marks by + // asking for specific properties + // Export attributes for -mark-start and -mark elements, + // but not for -mark-end + Reference<XPropertySetInfo> xPropertySetInfo = + xIndexMarkPropSet->getPropertySetInfo(); + if (xPropertySetInfo->hasPropertyByName(sUserIndexName)) + { + // user index mark + pElements = lcl_pUserIndexMarkName; + if (nElementNo != 2) + { + ExportUserIndexMarkAttributes(xIndexMarkPropSet); + } + } + else if (xPropertySetInfo->hasPropertyByName(sPrimaryKey)) + { + // alphabetical index mark + pElements = lcl_pAlphaIndexMarkName; + if (nElementNo != 2) + { + ExportAlphabeticalIndexMarkAttributes(xIndexMarkPropSet); + } + } + else + { + // table of content: + pElements = lcl_pTocMarkNames; + if (nElementNo != 2) + { + ExportTOCMarkAttributes(xIndexMarkPropSet); + } + } + + // export element + DBG_ASSERT(pElements != NULL, "illegal element array"); + DBG_ASSERT(nElementNo >= 0, "illegal name array index"); + DBG_ASSERT(nElementNo <= 2, "illegal name array index"); + + if ((pElements != NULL) && (nElementNo != -1)) + { + SvXMLElementExport aElem(rExport, + XML_NAMESPACE_TEXT, + pElements[nElementNo], + sal_False, sal_False); + } + } +} + +void XMLIndexMarkExport::ExportTOCMarkAttributes( + const Reference<XPropertySet> & rPropSet) +{ + // outline level + sal_Int16 nLevel = 0; + Any aAny = rPropSet->getPropertyValue(sLevel); + aAny >>= nLevel; + OUStringBuffer sBuf; + SvXMLUnitConverter::convertNumber(sBuf, (sal_Int32)nLevel + 1); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL, + sBuf.makeStringAndClear()); +} + +void lcl_ExportPropertyString( SvXMLExport& rExport, + const Reference<XPropertySet> & rPropSet, + const OUString sProperty, + XMLTokenEnum eToken, + Any& rAny ) +{ + rAny = rPropSet->getPropertyValue( sProperty ); + + OUString sValue; + if( rAny >>= sValue ) + { + if( sValue.getLength() > 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, sValue ); + } + } +} + +void lcl_ExportPropertyBool( SvXMLExport& rExport, + const Reference<XPropertySet> & rPropSet, + const OUString sProperty, + XMLTokenEnum eToken, + Any& rAny ) +{ + rAny = rPropSet->getPropertyValue( sProperty ); + + sal_Bool bValue = sal_Bool(); + if( rAny >>= bValue ) + { + if( bValue ) + { + rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, XML_TRUE ); + } + } +} + +void XMLIndexMarkExport::ExportUserIndexMarkAttributes( + const Reference<XPropertySet> & rPropSet) +{ + // name of user index + // (unless it's the default index; then it has no name) + Any aAny; + lcl_ExportPropertyString( rExport, rPropSet, sUserIndexName, XML_INDEX_NAME, aAny ); + + // additionally export outline level; just reuse ExportTOCMarkAttributes + ExportTOCMarkAttributes( rPropSet ); +} + +void XMLIndexMarkExport::ExportAlphabeticalIndexMarkAttributes( + const Reference<XPropertySet> & rPropSet) +{ + // primary and secondary keys (if available) + Any aAny; + lcl_ExportPropertyString( rExport, rPropSet, sTextReading, XML_STRING_VALUE_PHONETIC, aAny ); + lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKey, XML_KEY1, aAny ); + lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKeyReading, XML_KEY1_PHONETIC, aAny ); + lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKey, XML_KEY2, aAny ); + lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKeyReading, XML_KEY2_PHONETIC, aAny ); + lcl_ExportPropertyBool( rExport, rPropSet, sMainEntry, XML_MAIN_ENTRY, aAny ); +} + +void XMLIndexMarkExport::GetID( + OUStringBuffer& sBuf, + const Reference<XPropertySet> & rPropSet) +{ + static const sal_Char sPrefix[] = "IMark"; + + // HACK: use address of object to form identifier + sal_Int64 nId = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(rPropSet.get())); + sBuf.appendAscii(sPrefix, sizeof(sPrefix)-1); + sBuf.append(nId); +} diff --git a/xmloff/source/text/XMLIndexMarkExport.hxx b/xmloff/source/text/XMLIndexMarkExport.hxx new file mode 100644 index 000000000000..3595c58a5f53 --- /dev/null +++ b/xmloff/source/text/XMLIndexMarkExport.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXMARKEXPORT_HXX_ +#define _XMLOFF_XMLINDEXMARKEXPORT_HXX_ + +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> + +class SvXMLExport; +class XMLTextParagraphExport; +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + } } } +namespace rtl { + class OUString; + class OUStringBuffer; +} + + +/** + * This class handles the export of index marks for table of content, + * alphabetical and user index. + * + * Marks for bibliography indices are internally modelled as text + * fields and thus handled in txtparae.cxx + */ +class XMLIndexMarkExport +{ + ::rtl::OUString sLevel; + ::rtl::OUString sUserIndexName; + ::rtl::OUString sPrimaryKey; + ::rtl::OUString sSecondaryKey; + ::rtl::OUString sDocumentIndexMark; + ::rtl::OUString sIsStart; + ::rtl::OUString sIsCollapsed; + ::rtl::OUString sAlternativeText; + ::rtl::OUString sTextReading; + ::rtl::OUString sPrimaryKeyReading; + ::rtl::OUString sSecondaryKeyReading; + ::rtl::OUString sMainEntry; + + + SvXMLExport& rExport; + XMLTextParagraphExport& rParaExport; + +public: + XMLIndexMarkExport(SvXMLExport& rExp, + XMLTextParagraphExport& rParaExp); + + ~XMLIndexMarkExport(); + + /** + * export by the property set of its *text* *portion*. + * + * The text portion supplies us with the properties of the index + * mark itself, as well as the information whether we are at the + * start or end of an index mark, or whether the index mark is + * collapsed. + */ + void ExportIndexMark( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_Bool bAutoStyles); + +protected: + + /// export attributes of table-of-content index marks + void ExportTOCMarkAttributes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export attributes of user index marks + void ExportUserIndexMarkAttributes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export attributes of alphabetical index marks + void ExportAlphabeticalIndexMarkAttributes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// create a numerical ID for this index mark + /// (represented by its properties) + void GetID( + ::rtl::OUStringBuffer& sBuffer, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + +}; + +#endif diff --git a/xmloff/source/text/XMLIndexObjectSourceContext.cxx b/xmloff/source/text/XMLIndexObjectSourceContext.cxx new file mode 100644 index 000000000000..15301ffb2fe6 --- /dev/null +++ b/xmloff/source/text/XMLIndexObjectSourceContext.cxx @@ -0,0 +1,190 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexObjectSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_OBJECT_INDEX_ENTRY_TEMPLATE; +using ::xmloff::token::XML_TOKEN_INVALID; + +const sal_Char sAPI_CreateFromStarCalc[] = "CreateFromStarCalc"; +const sal_Char sAPI_CreateFromStarChart[] = "CreateFromStarChart"; +const sal_Char sAPI_CreateFromStarDraw[] = "CreateFromStarDraw"; +const sal_Char sAPI_CreateFromStarImage[] = "CreateFromStarImage"; +const sal_Char sAPI_CreateFromStarMath[] = "CreateFromStarMath"; +const sal_Char sAPI_CreateFromOtherEmbeddedObjects[] = "CreateFromOtherEmbeddedObjects"; + + +TYPEINIT1( XMLIndexObjectSourceContext, XMLIndexSourceBaseContext ); + +XMLIndexObjectSourceContext::XMLIndexObjectSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) : + XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, + rPropSet, sal_False), + sCreateFromStarCalc(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromStarCalc)), + sCreateFromStarChart(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromStarChart)), + sCreateFromStarDraw(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromStarDraw)), + sCreateFromStarMath(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromStarMath)), + sCreateFromOtherEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromOtherEmbeddedObjects)), + bUseCalc(sal_False), + bUseChart(sal_False), + bUseDraw(sal_False), + bUseMath(sal_False), + bUseOtherObjects(sal_False) +{ +} + +XMLIndexObjectSourceContext::~XMLIndexObjectSourceContext() +{ +} + +void XMLIndexObjectSourceContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + switch (eParam) + { + sal_Bool bTmp; + + case XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseOtherObjects = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_SHEET: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseCalc = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_CHART: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseChart = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_DRAW: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseDraw = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_MATH: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseMath = bTmp; + } + break; + + default: + XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); + break; + } +} + +void XMLIndexObjectSourceContext::EndElement() +{ + Any aAny; + + aAny.setValue(&bUseCalc, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromStarCalc, aAny); + + aAny.setValue(&bUseChart, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromStarChart, aAny); + + aAny.setValue(&bUseDraw, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromStarDraw, aAny); + + aAny.setValue(&bUseMath, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromStarMath, aAny); + + aAny.setValue(&bUseOtherObjects, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromOtherEmbeddedObjects, aAny); + + XMLIndexSourceBaseContext::EndElement(); +} + +SvXMLImportContext* XMLIndexObjectSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_TEXT == nPrefix) && + (IsXMLToken(rLocalName, XML_OBJECT_INDEX_ENTRY_TEMPLATE)) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameTableMap, + XML_TOKEN_INVALID, // no outline-level attr + aLevelStylePropNameTableMap, + aAllowedTokenTypesTable); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + +} diff --git a/xmloff/source/text/XMLIndexObjectSourceContext.hxx b/xmloff/source/text/XMLIndexObjectSourceContext.hxx new file mode 100644 index 000000000000..62e0bd06c1b5 --- /dev/null +++ b/xmloff/source/text/XMLIndexObjectSourceContext.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXOBJECTSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXOBJECTSOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import object index source element + */ +class XMLIndexObjectSourceContext : public XMLIndexSourceBaseContext +{ + const ::rtl::OUString sCreateFromStarCalc; + const ::rtl::OUString sCreateFromStarChart; + const ::rtl::OUString sCreateFromStarDraw; + const ::rtl::OUString sCreateFromStarMath; + const ::rtl::OUString sCreateFromOtherEmbeddedObjects; + + sal_Bool bUseCalc; + sal_Bool bUseChart; + sal_Bool bUseDraw; + sal_Bool bUseMath; + sal_Bool bUseOtherObjects; + +public: + + TYPEINFO(); + + XMLIndexObjectSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexObjectSourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexSimpleEntryContext.cxx b/xmloff/source/text/XMLIndexSimpleEntryContext.cxx new file mode 100644 index 000000000000..4284eabe3571 --- /dev/null +++ b/xmloff/source/text/XMLIndexSimpleEntryContext.cxx @@ -0,0 +1,146 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexSimpleEntryContext.hxx" +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + + +//using namespace ::com::sun::star::text; + +using ::rtl::OUString; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_STYLE_NAME; + +const sal_Char sAPI_TokenType[] = "TokenType"; +const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName"; + +TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext); + +XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext( + SvXMLImport& rImport, + const OUString& rEntry, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const OUString& rLocalName ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, rEntryType(rEntry) +, bCharStyleNameOK(sal_False) +, rTemplateContext(rTemplate) +, nValues(1) +{ +} + +XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext() +{ +} + +void XMLIndexSimpleEntryContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // we know only one attribute: style-name + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken(sLocalName, XML_STYLE_NAME) ) + { + sCharStyleName = xAttrList->getValueByIndex(nAttr); + OUString sDisplayStyleName = GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName ); + // #142494#: Check if style exists + const Reference < ::com::sun::star::container::XNameContainer > & rStyles = + GetImport().GetTextImport()->GetTextStyles(); + if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) ) + bCharStyleNameOK = sal_True; + else + bCharStyleNameOK = sal_False; + } + } + + // if we have a style name, set it! + if (bCharStyleNameOK) + { + nValues++; + } + +} + +void XMLIndexSimpleEntryContext::EndElement() +{ + Sequence<PropertyValue> aValues(nValues); + + FillPropertyValues(aValues); + rTemplateContext.addTemplateEntry(aValues); +} + +void XMLIndexSimpleEntryContext::FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues) +{ + // due to the limited number of subclasses, we fill the values + // directly into the slots. Subclasses will have to know they can + // only use slot so-and-so. + + Any aAny; + + // token type + rValues[0].Name = rTemplateContext.sTokenType; + aAny <<= rEntryType; + rValues[0].Value = aAny; + + // char style + if (bCharStyleNameOK) + { + rValues[1].Name = rTemplateContext.sCharacterStyleName; + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, + sCharStyleName ); + rValues[1].Value = aAny; + } + +} diff --git a/xmloff/source/text/XMLIndexSimpleEntryContext.hxx b/xmloff/source/text/XMLIndexSimpleEntryContext.hxx new file mode 100644 index 000000000000..3088c2b81139 --- /dev/null +++ b/xmloff/source/text/XMLIndexSimpleEntryContext.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXSIMPLEENTRYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXSIMPLEENTRYCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } +class XMLIndexTemplateContext; + +/** + * Import index entry templates + */ +class XMLIndexSimpleEntryContext : public SvXMLImportContext +{ + + // entry type + const ::rtl::OUString& rEntryType; + +protected: + // character style + ::rtl::OUString sCharStyleName; + sal_Bool bCharStyleNameOK; + + // surrounding template + XMLIndexTemplateContext& rTemplateContext; + + // number of values for PropertyValues + sal_Int32 nValues; + +public: + + TYPEINFO(); + + XMLIndexSimpleEntryContext( + SvXMLImport& rImport, + const ::rtl::OUString& rEntry, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexSimpleEntryContext(); + +protected: + + /** process parameters */ + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + /** call FillPropertyValues and insert into template */ + virtual void EndElement(); + + /** fill property values for this template entry */ + virtual void FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); + +}; + +#endif diff --git a/xmloff/source/text/XMLIndexSourceBaseContext.cxx b/xmloff/source/text/XMLIndexSourceBaseContext.cxx new file mode 100644 index 000000000000..f9e04bd0a488 --- /dev/null +++ b/xmloff/source/text/XMLIndexSourceBaseContext.cxx @@ -0,0 +1,277 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + +const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter"; +const sal_Char sAPI_IsRelativeTabstops[] = "IsRelativeTabstops"; + +static __FAR_DATA SvXMLTokenMapEntry aIndexSourceTokenMap[] = +{ + { XML_NAMESPACE_TEXT, + XML_OUTLINE_LEVEL, + XML_TOK_INDEXSOURCE_OUTLINE_LEVEL}, + { XML_NAMESPACE_TEXT, + XML_USE_INDEX_MARKS, + XML_TOK_INDEXSOURCE_USE_INDEX_MARKS }, + { XML_NAMESPACE_TEXT, + XML_INDEX_SCOPE, + XML_TOK_INDEXSOURCE_INDEX_SCOPE }, + { XML_NAMESPACE_TEXT, + XML_RELATIVE_TAB_STOP_POSITION, + XML_TOK_INDEXSOURCE_RELATIVE_TABS } , + { XML_NAMESPACE_TEXT, + XML_USE_OTHER_OBJECTS, + XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS }, + { XML_NAMESPACE_TEXT, + XML_USE_SPREADSHEET_OBJECTS, + XML_TOK_INDEXSOURCE_USE_SHEET }, + { XML_NAMESPACE_TEXT, + XML_USE_CHART_OBJECTS, + XML_TOK_INDEXSOURCE_USE_CHART }, + { XML_NAMESPACE_TEXT, + XML_USE_DRAW_OBJECTS, + XML_TOK_INDEXSOURCE_USE_DRAW }, + { XML_NAMESPACE_TEXT, + XML_USE_IMAGE_OBJECTS, + XML_TOK_INDEXSOURCE_USE_IMAGE }, + { XML_NAMESPACE_TEXT, + XML_USE_MATH_OBJECTS, + XML_TOK_INDEXSOURCE_USE_MATH }, + { XML_NAMESPACE_TEXT, + XML_MAIN_ENTRY_STYLE_NAME, + XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE }, + { XML_NAMESPACE_TEXT, + XML_IGNORE_CASE, + XML_TOK_INDEXSOURCE_IGNORE_CASE }, + { XML_NAMESPACE_TEXT, + XML_ALPHABETICAL_SEPARATORS, + XML_TOK_INDEXSOURCE_SEPARATORS }, + { XML_NAMESPACE_TEXT, + XML_COMBINE_ENTRIES, + XML_TOK_INDEXSOURCE_COMBINE_ENTRIES }, + { XML_NAMESPACE_TEXT, + XML_COMBINE_ENTRIES_WITH_DASH, + XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH }, + { XML_NAMESPACE_TEXT, + XML_USE_KEYS_AS_ENTRIES, + XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES }, + { XML_NAMESPACE_TEXT, + XML_COMBINE_ENTRIES_WITH_PP, + XML_TOK_INDEXSOURCE_COMBINE_WITH_PP }, + { XML_NAMESPACE_TEXT, + XML_CAPITALIZE_ENTRIES, + XML_TOK_INDEXSOURCE_CAPITALIZE }, + { XML_NAMESPACE_TEXT, + XML_USE_OBJECTS, + XML_TOK_INDEXSOURCE_USE_OBJECTS }, + { XML_NAMESPACE_TEXT, + XML_USE_GRAPHICS, + XML_TOK_INDEXSOURCE_USE_GRAPHICS }, + { XML_NAMESPACE_TEXT, + XML_USE_TABLES, + XML_TOK_INDEXSOURCE_USE_TABLES }, + { XML_NAMESPACE_TEXT, + XML_USE_FLOATING_FRAMES, + XML_TOK_INDEXSOURCE_USE_FRAMES }, + { XML_NAMESPACE_TEXT, + XML_COPY_OUTLINE_LEVELS, + XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS }, + { XML_NAMESPACE_TEXT, + XML_USE_CAPTION, + XML_TOK_INDEXSOURCE_USE_CAPTION }, + { XML_NAMESPACE_TEXT, + XML_CAPTION_SEQUENCE_NAME, + XML_TOK_INDEXSOURCE_SEQUENCE_NAME }, + { XML_NAMESPACE_TEXT, + XML_CAPTION_SEQUENCE_FORMAT, + XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT }, + { XML_NAMESPACE_TEXT, + XML_COMMA_SEPARATED, + XML_TOK_INDEXSOURCE_COMMA_SEPARATED }, + { XML_NAMESPACE_TEXT, + XML_USE_INDEX_SOURCE_STYLES, + XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES }, + { XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM, + XML_TOK_INDEXSOURCE_SORT_ALGORITHM }, + { XML_NAMESPACE_FO, XML_LANGUAGE, XML_TOK_INDEXSOURCE_LANGUAGE }, + { XML_NAMESPACE_FO, XML_COUNTRY, XML_TOK_INDEXSOURCE_COUNTRY }, + { XML_NAMESPACE_TEXT, XML_INDEX_NAME, XML_TOK_INDEXSOURCE_USER_INDEX_NAME }, + { XML_NAMESPACE_TEXT, + XML_USE_OUTLINE_LEVEL, + XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL}, + + XML_TOKEN_MAP_END +}; + + +TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext ); + +XMLIndexSourceBaseContext::XMLIndexSourceBaseContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet, + sal_Bool bLevelFormats) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromChapter)) +, sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsRelativeTabstops)) +, bUseLevelFormats(bLevelFormats) +, bChapterIndex(sal_False) +, bRelativeTabs(sal_True) +, rIndexPropertySet(rPropSet) +{ +} + +XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext() +{ +} + +void XMLIndexSourceBaseContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + SvXMLTokenMap aTokenMap(aIndexSourceTokenMap); + + // process attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) + { + // map to IndexSourceParamEnum + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName); + + // process attribute + ProcessAttribute((enum IndexSourceParamEnum)nToken, + xAttrList->getValueByIndex(i)); + } +} + +void XMLIndexSourceBaseContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + switch (eParam) + { + case XML_TOK_INDEXSOURCE_INDEX_SCOPE: + if ( IsXMLToken( rValue, XML_CHAPTER ) ) + { + bChapterIndex = sal_True; + } + break; + + case XML_TOK_INDEXSOURCE_RELATIVE_TABS: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bRelativeTabs = bTmp; + } + break; + } + + default: + // unknown attribute -> ignore + break; + } +} + +void XMLIndexSourceBaseContext::EndElement() +{ + Any aAny; + + aAny.setValue(&bRelativeTabs, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny); + + aAny.setValue(&bChapterIndex, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny); +} + +SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) ) + { + pContext = new XMLIndexTitleTemplateContext(GetImport(), + rIndexPropertySet, + nPrefix, rLocalName); + } + else if ( bUseLevelFormats && + IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) ) + { + pContext = new XMLIndexTOCStylesContext(GetImport(), + rIndexPropertySet, + nPrefix, rLocalName); + } + // else: unknown element in text namespace -> ignore + } + // else: unknown namespace -> ignore + + // use default context + if (pContext == NULL) + { + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } + + return pContext; +} diff --git a/xmloff/source/text/XMLIndexSourceBaseContext.hxx b/xmloff/source/text/XMLIndexSourceBaseContext.hxx new file mode 100644 index 000000000000..8d84504df317 --- /dev/null +++ b/xmloff/source/text/XMLIndexSourceBaseContext.hxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXSOURCEBASECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXSOURCEBASECONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> +#include <rtl/ustring.hxx> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } + +enum IndexSourceParamEnum +{ + XML_TOK_INDEXSOURCE_OUTLINE_LEVEL, + XML_TOK_INDEXSOURCE_USE_INDEX_MARKS, + XML_TOK_INDEXSOURCE_INDEX_SCOPE, + XML_TOK_INDEXSOURCE_RELATIVE_TABS, + XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS, + XML_TOK_INDEXSOURCE_USE_SHEET, + XML_TOK_INDEXSOURCE_USE_CHART, + XML_TOK_INDEXSOURCE_USE_DRAW, + XML_TOK_INDEXSOURCE_USE_IMAGE, + XML_TOK_INDEXSOURCE_USE_MATH, + XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE, + XML_TOK_INDEXSOURCE_IGNORE_CASE, + XML_TOK_INDEXSOURCE_SEPARATORS, + XML_TOK_INDEXSOURCE_COMBINE_ENTRIES, + XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH, + XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES, + XML_TOK_INDEXSOURCE_COMBINE_WITH_PP, + XML_TOK_INDEXSOURCE_CAPITALIZE, + XML_TOK_INDEXSOURCE_USE_OBJECTS, + XML_TOK_INDEXSOURCE_USE_GRAPHICS, + XML_TOK_INDEXSOURCE_USE_TABLES, + XML_TOK_INDEXSOURCE_USE_FRAMES, + XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS, + XML_TOK_INDEXSOURCE_USE_CAPTION, + XML_TOK_INDEXSOURCE_SEQUENCE_NAME, + XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT, + XML_TOK_INDEXSOURCE_COMMA_SEPARATED, + XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES, + XML_TOK_INDEXSOURCE_SORT_ALGORITHM, + XML_TOK_INDEXSOURCE_LANGUAGE, + XML_TOK_INDEXSOURCE_COUNTRY, + XML_TOK_INDEXSOURCE_USER_INDEX_NAME, + XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL +}; + + +/** + * Superclass for index source elements + */ +class XMLIndexSourceBaseContext : public SvXMLImportContext +{ + const ::rtl::OUString sCreateFromChapter; + const ::rtl::OUString sIsRelativeTabstops; + + sal_Bool bUseLevelFormats; + + sal_Bool bChapterIndex; /// chapter-wise or document index? + sal_Bool bRelativeTabs; /// tab stops relative to margin or indent? + +protected: + + /// property set of index; must be accessible to subclasses + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rIndexPropertySet; + +public: + + TYPEINFO(); + + XMLIndexSourceBaseContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_Bool bLevelFormats); + + ~XMLIndexSourceBaseContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexSpanEntryContext.cxx b/xmloff/source/text/XMLIndexSpanEntryContext.cxx new file mode 100644 index 000000000000..d760a3e15be8 --- /dev/null +++ b/xmloff/source/text/XMLIndexSpanEntryContext.cxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLIndexSpanEntryContext.hxx" +#include <rtl/ustring.hxx> +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> + + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::beans::PropertyValue; + + +TYPEINIT1( XMLIndexSpanEntryContext, XMLIndexSimpleEntryContext); + +XMLIndexSpanEntryContext::XMLIndexSpanEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const OUString& rLocalName ) : + XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenText, + rTemplate, nPrfx, rLocalName) +{ + nValues++; // one more for the text string +} + +XMLIndexSpanEntryContext::~XMLIndexSpanEntryContext() +{ +} + +void XMLIndexSpanEntryContext::Characters(const OUString& sString) +{ + sContent.append(sString); +} + +void XMLIndexSpanEntryContext::FillPropertyValues( + Sequence<PropertyValue> & rValues) +{ + // call superclass for token type, stylename, + XMLIndexSimpleEntryContext::FillPropertyValues(rValues); + + // content + Any aAny; + aAny <<= sContent.makeStringAndClear(); + rValues[nValues-1].Name = rTemplateContext.sText; + rValues[nValues-1].Value = aAny; +} + diff --git a/xmloff/source/text/XMLIndexSpanEntryContext.hxx b/xmloff/source/text/XMLIndexSpanEntryContext.hxx new file mode 100644 index 000000000000..8880a7665f6e --- /dev/null +++ b/xmloff/source/text/XMLIndexSpanEntryContext.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXSPANENTRYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXSPANENTRYCONTEXT_HXX_ + +#include "XMLIndexSimpleEntryContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <rtl/ustrbuf.hxx> + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } + +/** + * Import index entry templates + */ +class XMLIndexSpanEntryContext : public XMLIndexSimpleEntryContext +{ + ::rtl::OUStringBuffer sContent; + +public: + + TYPEINFO(); + + XMLIndexSpanEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexSpanEntryContext(); + +protected: + + /// Collect element contents + virtual void Characters(const ::rtl::OUString& sString); + + /// add Text PropertyValue + virtual void FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTOCContext.cxx b/xmloff/source/text/XMLIndexTOCContext.cxx new file mode 100644 index 000000000000..2699111ab47a --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCContext.cxx @@ -0,0 +1,382 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTOCContext.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/text/XRelativeTextContentInsert.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include "XMLIndexTOCSourceContext.hxx" +#include "XMLIndexObjectSourceContext.hxx" +#include "XMLIndexAlphabeticalSourceContext.hxx" +#include "XMLIndexUserSourceContext.hxx" +#include "XMLIndexBibliographySourceContext.hxx" +#include "XMLIndexTableSourceContext.hxx" +#include "XMLIndexIllustrationSourceContext.hxx" +#include "XMLIndexBodyContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/prstylei.hxx> +#include "xmloff/xmlerror.hxx" +#include <xmloff/xmluconv.hxx> +#include <rtl/ustring.hxx> + + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::lang::IllegalArgumentException; + + +TYPEINIT1(XMLIndexTOCContext, SvXMLImportContext); + +static const sal_Char* aIndexServiceMap[] = +{ + "com.sun.star.text.ContentIndex", + "com.sun.star.text.DocumentIndex", + "com.sun.star.text.TableIndex", + "com.sun.star.text.ObjectIndex", + "com.sun.star.text.Bibliography", + "com.sun.star.text.UserIndex", + "com.sun.star.text.IllustrationsIndex" +}; + +static const XMLTokenEnum aIndexSourceElementMap[] = +{ + XML_TABLE_OF_CONTENT_SOURCE, + XML_ALPHABETICAL_INDEX_SOURCE, + XML_TABLE_INDEX_SOURCE, + XML_OBJECT_INDEX_SOURCE, + XML_BIBLIOGRAPHY_SOURCE, + XML_USER_INDEX_SOURCE, + XML_ILLUSTRATION_INDEX_SOURCE +}; + +SvXMLEnumMapEntry __READONLY_DATA aIndexTypeMap[] = +{ + { XML_TABLE_OF_CONTENT, TEXT_INDEX_TOC }, + { XML_ALPHABETICAL_INDEX, TEXT_INDEX_ALPHABETICAL }, + { XML_TABLE_INDEX, TEXT_INDEX_TABLE }, + { XML_OBJECT_INDEX, TEXT_INDEX_OBJECT }, + { XML_BIBLIOGRAPHY, TEXT_INDEX_BIBLIOGRAPHY }, + { XML_USER_INDEX, TEXT_INDEX_USER }, + { XML_ILLUSTRATION_INDEX, TEXT_INDEX_ILLUSTRATION }, + { XML_TOKEN_INVALID, 0 } +}; + + +XMLIndexTOCContext::XMLIndexTOCContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")) +, sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")) +, sName(RTL_CONSTASCII_USTRINGPARAM("Name")) +, bValid(sal_False) +{ + if (XML_NAMESPACE_TEXT == nPrfx) + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, rLocalName, aIndexTypeMap)) + { + // check for array index: + OSL_ENSURE(nTmp < (sizeof(aIndexServiceMap)/sizeof(sal_Char*)), "index out of range"); + OSL_ENSURE(sizeof(aIndexServiceMap) == + sizeof(aIndexSourceElementMap), + "service and source element maps must be same size"); + + eIndexType = static_cast<IndexTypeEnum>(nTmp); + bValid = sal_True; + } + } +} + +XMLIndexTOCContext::~XMLIndexTOCContext() +{ +} + +void XMLIndexTOCContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + if (bValid) + { + // find text:style-name attribute and set section style + // find text:protected and set value + // find text:name and set value (if not empty) + sal_Int16 nCount = xAttrList->getLength(); + sal_Bool bProtected = sal_False; + OUString sIndexName; + OUString sXmlId; + XMLPropStyleContext* pStyle(NULL); + for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) ) + { + pStyle = GetImport().GetTextImport()->FindSectionStyle( + xAttrList->getValueByIndex(nAttr)); + } + else if ( IsXMLToken( sLocalName, XML_PROTECTED ) ) + { + sal_Bool bTmp; + if ( SvXMLUnitConverter::convertBool( + bTmp, xAttrList->getValueByIndex(nAttr) ) ) + { + bProtected = bTmp; + } + } + else if ( IsXMLToken( sLocalName, XML_NAME ) ) + { + sIndexName = xAttrList->getValueByIndex(nAttr); + } + } + else if ( XML_NAMESPACE_XML == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_ID ) ) + { + sXmlId = xAttrList->getValueByIndex(nAttr); + } + } + } + + // create table of content (via MultiServiceFactory) + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(), + UNO_QUERY); + if( xFactory.is() ) + { + Reference<XInterface> xIfc = + xFactory->createInstance( + OUString::createFromAscii(aIndexServiceMap[eIndexType])); + if( xIfc.is() ) + { + // get Property set + Reference<XPropertySet> xPropSet(xIfc, UNO_QUERY); + xTOCPropertySet = xPropSet; + + // insert section + // a) insert section + // The inserted index consists of an empty paragraph + // only, as well as an empty paragraph *after* the index + // b) insert marker after index, and put Cursor inside of the + // index + + // preliminaries +#ifndef DBG_UTIL + OUString sMarker(RTL_CONSTASCII_USTRINGPARAM(" ")); +#else + OUString sMarker(RTL_CONSTASCII_USTRINGPARAM("Y")); +#endif + UniReference<XMLTextImportHelper> rImport = + GetImport().GetTextImport(); + + // a) insert index + Reference<XTextContent> xTextContent(xIfc, UNO_QUERY); + try + { + GetImport().GetTextImport()->InsertTextContent( + xTextContent); + } + catch( IllegalArgumentException e ) + { + // illegal argument? Then we can't accept indices here! + Sequence<OUString> aSeq(1); + aSeq[0] = GetLocalName(); + GetImport().SetError( + XMLERROR_FLAG_ERROR | XMLERROR_NO_INDEX_ALLOWED_HERE, + aSeq, e.Message, NULL ); + + // set bValid to false, and return prematurely + bValid = false; + return; + } + + // xml:id for RDF metadata + GetImport().SetXmlId(xIfc, sXmlId); + + // b) insert marker and move cursor + rImport->InsertString(sMarker); + rImport->GetCursor()->goLeft(2, sal_False); + } + } + + // finally, check for redlines that should start at + // the section start node + if( bValid ) + GetImport().GetTextImport()-> + RedlineAdjustStartNodeCursor(sal_True); + + if (pStyle != NULL) + { + pStyle->FillPropertySet( xTOCPropertySet ); + } + + Any aAny; + aAny.setValue( &bProtected, ::getBooleanCppuType() ); + xTOCPropertySet->setPropertyValue( sIsProtected, aAny ); + + if (sIndexName.getLength() > 0) + { + aAny <<= sIndexName; + xTOCPropertySet->setPropertyValue( sName, aAny ); + } + } +} + +void XMLIndexTOCContext::EndElement() +{ + // complete import of index by removing the markers (if the index + // was actually inserted, that is) + if( bValid ) + { + // preliminaries + OUString sEmpty; + UniReference<XMLTextImportHelper> rHelper= GetImport().GetTextImport(); + + // get rid of last paragraph (unless it's the only paragraph) + rHelper->GetCursor()->goRight(1, sal_False); + if( xBodyContextRef.Is() && + ((XMLIndexBodyContext*)&xBodyContextRef)->HasContent() ) + { + rHelper->GetCursor()->goLeft(1, sal_True); + rHelper->GetText()->insertString(rHelper->GetCursorAsRange(), + sEmpty, sal_True); + } + + // and delete second marker + rHelper->GetCursor()->goRight(1, sal_True); + rHelper->GetText()->insertString(rHelper->GetCursorAsRange(), + sEmpty, sal_True); + + // check for Redlines on our end node + GetImport().GetTextImport()->RedlineAdjustStartNodeCursor(sal_False); + } +} + +SvXMLImportContext* XMLIndexTOCContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if (bValid) + { + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( rLocalName, XML_INDEX_BODY ) ) + { + pContext = new XMLIndexBodyContext(GetImport(), nPrefix, + rLocalName); + if ( !xBodyContextRef.Is() || + !((XMLIndexBodyContext*)&xBodyContextRef)->HasContent() ) + { + xBodyContextRef = pContext; + } + } + else if (IsXMLToken(rLocalName, aIndexSourceElementMap[eIndexType])) + { + // instantiate source context for the appropriate index type + switch (eIndexType) + { + case TEXT_INDEX_TOC: + pContext = new XMLIndexTOCSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_OBJECT: + pContext = new XMLIndexObjectSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_ALPHABETICAL: + pContext = new XMLIndexAlphabeticalSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_USER: + pContext = new XMLIndexUserSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_BIBLIOGRAPHY: + pContext = new XMLIndexBibliographySourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_TABLE: + pContext = new XMLIndexTableSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + case TEXT_INDEX_ILLUSTRATION: + pContext = new XMLIndexIllustrationSourceContext( + GetImport(), nPrefix, rLocalName, xTOCPropertySet); + break; + + default: + OSL_ENSURE(false, "index type not implemented"); + break; + } + } + // else: ignore + } + // else: no text: namespace -> ignore + } + // else: not valid -> ignore + + // default: ignore + if (pContext == NULL) + { + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } + + return pContext; +} diff --git a/xmloff/source/text/XMLIndexTOCContext.hxx b/xmloff/source/text/XMLIndexTOCContext.hxx new file mode 100644 index 000000000000..66f045a5467d --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCContext.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTOCCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTOCCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +enum IndexTypeEnum +{ + TEXT_INDEX_TOC, + TEXT_INDEX_ALPHABETICAL, + TEXT_INDEX_TABLE, + TEXT_INDEX_OBJECT, + TEXT_INDEX_BIBLIOGRAPHY, + TEXT_INDEX_USER, + TEXT_INDEX_ILLUSTRATION, + + TEXT_INDEX_UNKNOWN +}; + + +/** + * Import all indices. + * + * Originally, this class would import only the TOC (table of + * content), but now it's role has been expanded to handle all + * indices, and hence is named inappropriately. Depending on the + * element name it decides which index source element context to create. + */ +class XMLIndexTOCContext : public SvXMLImportContext +{ + const ::rtl::OUString sTitle; + const ::rtl::OUString sIsProtected; + const ::rtl::OUString sName; + + /** XPropertySet of the index */ + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> xTOCPropertySet; + + enum IndexTypeEnum eIndexType; + + sal_Bool bValid; + + SvXMLImportContextRef xBodyContextRef; + +public: + + TYPEINFO(); + + XMLIndexTOCContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexTOCContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTOCSourceContext.cxx b/xmloff/source/text/XMLIndexTOCSourceContext.cxx new file mode 100644 index 000000000000..84296ff24241 --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCSourceContext.cxx @@ -0,0 +1,196 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTOCSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + +const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter"; +const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline"; +const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks"; +const sal_Char sAPI_Level[] = "Level"; +const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles"; + + +TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext ); + +XMLIndexTOCSourceContext::XMLIndexTOCSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) +: XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True) +, sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)) +, sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level)) +, sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline)) +, sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles)) + // use all chapters by default +, nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount()) +, bUseOutline(sal_True) +, bUseMarks(sal_True) +, bUseParagraphStyles(sal_False) +{ +} + +XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext() +{ +} + +void XMLIndexTOCSourceContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + switch (eParam) + { + case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL: + if ( IsXMLToken( rValue, XML_NONE ) ) + { + // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of + // OUTLINE_LEVEL with values none|1..10. For backwards + // compatibility, 'none' must still be read. + bUseOutline = sal_False; + } + else + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( + nTmp, rValue, 1, GetImport().GetTextImport()-> + GetChapterNumbering()->getCount())) + { + bUseOutline = sal_True; + nOutlineLevel = nTmp; + } + } + break; + + case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseOutline = bTmp; + } + break; + } + + + case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseMarks = bTmp; + } + break; + } + + case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseParagraphStyles = bTmp; + } + break; + } + + default: + // default: ask superclass + XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); + break; + } +} + +void XMLIndexTOCSourceContext::EndElement() +{ + Any aAny; + + aAny.setValue(&bUseMarks, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny); + + aAny.setValue(&bUseOutline, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny); + + aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny); + + aAny <<= (sal_Int16)nOutlineLevel; + rIndexPropertySet->setPropertyValue(sLevel, aAny); + + // process common attributes + XMLIndexSourceBaseContext::EndElement(); +} + + +SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameTOCMap, + XML_OUTLINE_LEVEL, + aLevelStylePropNameTOCMap, + aAllowedTokenTypesTOC, sal_True ); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } +} diff --git a/xmloff/source/text/XMLIndexTOCSourceContext.hxx b/xmloff/source/text/XMLIndexTOCSourceContext.hxx new file mode 100644 index 000000000000..c26139fd9280 --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCSourceContext.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTOCSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTOCSOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import table of context source element + */ +class XMLIndexTOCSourceContext : public XMLIndexSourceBaseContext +{ + const ::rtl::OUString sCreateFromMarks; + const ::rtl::OUString sLevel; + const ::rtl::OUString sCreateFromChapter; + const ::rtl::OUString sCreateFromOutline; + const ::rtl::OUString sCreateFromLevelParagraphStyles; + + sal_Int32 nOutlineLevel; + sal_Bool bUseOutline; + sal_Bool bUseMarks; + sal_Bool bUseParagraphStyles; + +public: + + TYPEINFO(); + + XMLIndexTOCSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexTOCSourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTOCStylesContext.cxx b/xmloff/source/text/XMLIndexTOCStylesContext.cxx new file mode 100644 index 000000000000..755bd280a539 --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCStylesContext.cxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTOCStylesContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::container::XIndexReplace; +using ::com::sun::star::xml::sax::XAttributeList; + + +const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles"; + +TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext ); + + +XMLIndexTOCStylesContext::XMLIndexTOCStylesContext( + SvXMLImport& rImport, + Reference<XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const OUString& rLocalName ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_LevelParagraphStyles)) +, rTOCPropertySet(rPropSet) +{ +} + +XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext() +{ +} + +void XMLIndexTOCStylesContext::StartElement( + const Reference<XAttributeList> & xAttrList ) +{ + // find text:outline-level attribute + sal_Int16 nCount = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( (XML_NAMESPACE_TEXT == nPrefix) && + (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) ) + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( + nTmp, xAttrList->getValueByIndex(nAttr), 1, + GetImport().GetTextImport()->GetChapterNumbering()-> + getCount())) + { + // API numbers 0..9, we number 1..10 + nOutlineLevel = nTmp-1; + } + } + } +} + +void XMLIndexTOCStylesContext::EndElement() +{ + // if valid... + if (nOutlineLevel >= 0) + { + // copy vector into sequence + const sal_Int32 nCount = aStyleNames.size(); + Sequence<OUString> aStyleNamesSequence(nCount); + for(sal_Int32 i = 0; i < nCount; i++) + { + aStyleNamesSequence[i] = GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, + aStyleNames[i] ); + } + + // get index replace + Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles); + Reference<XIndexReplace> xIndexReplace; + aAny >>= xIndexReplace; + + // set style names + aAny <<= aStyleNamesSequence; + xIndexReplace->replaceByIndex(nOutlineLevel, aAny); + } +} + +SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext( + sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + // check for index-source-style + if ( (XML_NAMESPACE_TEXT == p_nPrefix) && + IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) ) + { + // find text:style-name attribute and record in aStyleNames + sal_Int16 nCount = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken( sLocalName, XML_STYLE_NAME ) ) + { + aStyleNames.push_back(xAttrList->getValueByIndex(nAttr)); + } + } + } + + // always return default context; we already got the interesting info + return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName, + xAttrList); +} diff --git a/xmloff/source/text/XMLIndexTOCStylesContext.hxx b/xmloff/source/text/XMLIndexTOCStylesContext.hxx new file mode 100644 index 000000000000..835b8c3a341b --- /dev/null +++ b/xmloff/source/text/XMLIndexTOCStylesContext.hxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTOCSTYLESCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTOCSTYLESCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + +#ifndef __SGI_STL_VECTOR +#include <vector> +#endif + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import <test:index-source-styles> elements and their children + * + * (Small hackery here: Because there's only one type of child + * elements with only one interesting attribute, we completely handle + * them inside the CreateChildContext method, rather than creating a + * new import class for them. This must be changed if children become + * more complex in future versions.) + */ +class XMLIndexTOCStylesContext : public SvXMLImportContext +{ + const ::rtl::OUString sLevelParagraphStyles; + + /// XPropertySet of the index + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rTOCPropertySet; + + /// style names for this level + ::std::vector< ::rtl::OUString > aStyleNames; + + /// outline level + sal_Int32 nOutlineLevel; + +public: + + TYPEINFO(); + + XMLIndexTOCStylesContext( + SvXMLImport& rImport, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexTOCStylesContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTabStopEntryContext.cxx b/xmloff/source/text/XMLIndexTabStopEntryContext.cxx new file mode 100644 index 000000000000..301e7af3f96d --- /dev/null +++ b/xmloff/source/text/XMLIndexTabStopEntryContext.cxx @@ -0,0 +1,174 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTabStopEntryContext.hxx" +#include "XMLIndexTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> + +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext ); + +XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const OUString& rLocalName ) : + XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop, + rTemplate, nPrfx, rLocalName), + sLeaderChar(), + nTabPosition(0), + bTabPositionOK(sal_False), + bTabRightAligned(sal_False), + bLeaderCharOK(sal_False), + bWithTab(sal_True) // #i21237# +{ +} + +XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext() +{ +} + +void XMLIndexTabStopEntryContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // process three attributes: type, position, leader char + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + OUString sAttr = xAttrList->getValueByIndex(nAttr); + if (XML_NAMESPACE_STYLE == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_TYPE ) ) + { + // if it's neither left nor right, value is + // ignored. Since left is default, we only need to + // check for right + bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT ); + } + else if ( IsXMLToken( sLocalName, XML_POSITION ) ) + { + sal_Int32 nTmp; + if (GetImport().GetMM100UnitConverter(). + convertMeasure(nTmp, sAttr)) + { + nTabPosition = nTmp; + bTabPositionOK = sal_True; + } + } + else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) ) + { + sLeaderChar = sAttr; + // valid only, if we have a char! + bLeaderCharOK = (sAttr.getLength() > 0); + } + // #i21237# + else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) ) + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttr)) + bWithTab = bTmp; + } + // else: unknown style: attribute -> ignore + } + // else: no style attribute -> ignore + } + + // how many entries? #i21237# + nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0); + + // now try parent class (for character style) + XMLIndexSimpleEntryContext::StartElement( xAttrList ); +} + +void XMLIndexTabStopEntryContext::FillPropertyValues( + Sequence<PropertyValue> & rValues) +{ + // fill vlues from parent class (type + style name) + XMLIndexSimpleEntryContext::FillPropertyValues(rValues); + + // get values array and next entry to be written; + sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1; + PropertyValue* pValues = rValues.getArray(); + + // right aligned? + pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned; + pValues[nNextEntry].Value.setValue( &bTabRightAligned, + ::getBooleanCppuType()); + nNextEntry++; + + // position + if (bTabPositionOK) + { + pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition; + pValues[nNextEntry].Value <<= nTabPosition; + nNextEntry++; + } + + // leader char + if (bLeaderCharOK) + { + pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter; + pValues[nNextEntry].Value <<= sLeaderChar; + nNextEntry++; + } + + // tab character #i21237# + pValues[nNextEntry].Name = + OUString( RTL_CONSTASCII_USTRINGPARAM("WithTab") ); + pValues[nNextEntry].Value.setValue( &bWithTab, + ::getBooleanCppuType()); + nNextEntry++; + + // check whether we really filled all elements of the sequence + DBG_ASSERT( nNextEntry == rValues.getLength(), + "length incorrectly precumputed!" ); +} diff --git a/xmloff/source/text/XMLIndexTabStopEntryContext.hxx b/xmloff/source/text/XMLIndexTabStopEntryContext.hxx new file mode 100644 index 000000000000..dbacb2708344 --- /dev/null +++ b/xmloff/source/text/XMLIndexTabStopEntryContext.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTABSTOPENTRYCONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTABSTOPENTRYCONTEXT_HXX_ + +#include "XMLIndexSimpleEntryContext.hxx" +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +class XMLIndexTemplateContext; + +/** + * Import index entry templates + */ +class XMLIndexTabStopEntryContext : public XMLIndexSimpleEntryContext +{ + ::rtl::OUString sLeaderChar; /// fill ("leader") character + sal_Int32 nTabPosition; /// tab position + sal_Bool bTabPositionOK; /// is tab right aligned? + sal_Bool bTabRightAligned; /// is nTabPosition valid? + sal_Bool bLeaderCharOK; /// is sLeaderChar valid? + sal_Bool bWithTab; /// is tab char present? #i21237# + +public: + + TYPEINFO(); + + XMLIndexTabStopEntryContext( + SvXMLImport& rImport, + XMLIndexTemplateContext& rTemplate, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLIndexTabStopEntryContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + /** fill property values for this template entry */ + virtual void FillPropertyValues( + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTableSourceContext.cxx b/xmloff/source/text/XMLIndexTableSourceContext.cxx new file mode 100644 index 000000000000..b87514c79eda --- /dev/null +++ b/xmloff/source/text/XMLIndexTableSourceContext.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTableSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> + +#ifndef _COM_SUN_STAR_TEXT_REFERENCEFIELD_PART_HPP +#include <com/sun/star/text/ReferenceFieldPart.hpp> +#endif +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; + +const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels"; +const sal_Char sAPI_LabelCategory[] = "LabelCategory"; +const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType"; + + +TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext); + + +XMLIndexTableSourceContext::XMLIndexTableSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) : + XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, + rPropSet, sal_False), + sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLabels)), + sLabelCategory(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelCategory)), + sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelDisplayType)), + bSequenceOK(sal_False), + bDisplayFormatOK(sal_False), + bUseCaption(sal_True) +{ +} + +XMLIndexTableSourceContext::~XMLIndexTableSourceContext() +{ +} + +static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] = +{ + + { XML_TEXT, ReferenceFieldPart::TEXT }, + { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER }, + { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION }, + + // wrong values that previous versions wrote: + { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER }, + { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION }, + + { XML_TOKEN_INVALID, 0 } +}; + +void XMLIndexTableSourceContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + sal_Bool bTmp; + + switch (eParam) + { + case XML_TOK_INDEXSOURCE_USE_CAPTION: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseCaption = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_SEQUENCE_NAME: + sSequence = rValue; + bSequenceOK = sal_True; + break; + + case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, rValue, + lcl_aReferenceTypeTokenMap)) + { + nDisplayFormat = nTmp; + bDisplayFormatOK = sal_True; + } + break; + } + + default: + XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); + break; + } +} + + +void XMLIndexTableSourceContext::EndElement() +{ + Any aAny; + + aAny.setValue(&bUseCaption, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny); + + if (bSequenceOK) + { + aAny <<= sSequence; + rIndexPropertySet->setPropertyValue(sLabelCategory, aAny); + } + + if (bDisplayFormatOK) + { + aAny <<= nDisplayFormat; + rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny); + } + + XMLIndexSourceBaseContext::EndElement(); +} + + +SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( ( XML_NAMESPACE_TEXT == nPrefix ) && + ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameTableMap, + XML_TOKEN_INVALID, // no outline-level attr + aLevelStylePropNameTableMap, + aAllowedTokenTypesTable); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + +} diff --git a/xmloff/source/text/XMLIndexTableSourceContext.hxx b/xmloff/source/text/XMLIndexTableSourceContext.hxx new file mode 100644 index 000000000000..e18b38bce9f3 --- /dev/null +++ b/xmloff/source/text/XMLIndexTableSourceContext.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTABLESOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTABLESOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import table index source element + */ +class XMLIndexTableSourceContext : public XMLIndexSourceBaseContext +{ + const ::rtl::OUString sCreateFromLabels; + const ::rtl::OUString sLabelCategory; + const ::rtl::OUString sLabelDisplayType; + + ::rtl::OUString sSequence; + sal_Int16 nDisplayFormat; + + sal_Bool bSequenceOK; + sal_Bool bDisplayFormatOK; + sal_Bool bUseCaption; + +public: + + TYPEINFO(); + + XMLIndexTableSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexTableSourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTemplateContext.cxx b/xmloff/source/text/XMLIndexTemplateContext.cxx new file mode 100644 index 000000000000..05bf7f5495da --- /dev/null +++ b/xmloff/source/text/XMLIndexTemplateContext.cxx @@ -0,0 +1,504 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexSimpleEntryContext.hxx" +#include "XMLIndexSpanEntryContext.hxx" +#include "XMLIndexTabStopEntryContext.hxx" +#include "XMLIndexBibliographyEntryContext.hxx" +#include "XMLIndexChapterInfoEntryContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/container/XIndexReplace.hpp> + + +using namespace ::std; +//using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::container::XIndexReplace; + +const sal_Char sAPI_TokenEntryNumber[] = "TokenEntryNumber"; +const sal_Char sAPI_TokenEntryText[] = "TokenEntryText"; +const sal_Char sAPI_TokenTabStop[] = "TokenTabStop"; +const sal_Char sAPI_TokenText[] = "TokenText"; +const sal_Char sAPI_TokenPageNumber[] = "TokenPageNumber"; +const sal_Char sAPI_TokenChapterInfo[] = "TokenChapterInfo"; +const sal_Char sAPI_TokenHyperlinkStart[] = "TokenHyperlinkStart"; +const sal_Char sAPI_TokenHyperlinkEnd[] = "TokenHyperlinkEnd"; +const sal_Char sAPI_TokenBibliographyDataField[] = + "TokenBibliographyDataField"; + + +TYPEINIT1( XMLIndexTemplateContext, SvXMLImportContext); + +XMLIndexTemplateContext::XMLIndexTemplateContext( + SvXMLImport& rImport, + Reference<XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const OUString& rLocalName, + const SvXMLEnumMapEntry* pLevelNameMap, + enum XMLTokenEnum eLevelAttrName, + const sal_Char** pLevelStylePropMap, + const sal_Bool* pAllowedTokenTypes, + sal_Bool bT ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, pOutlineLevelNameMap(pLevelNameMap) +, eOutlineLevelAttrName(eLevelAttrName) +, pOutlineLevelStylePropMap(pLevelStylePropMap) +, pAllowedTokenTypesMap(pAllowedTokenTypes) +, nOutlineLevel(1) // all indices have level 1 (0 is for header) +, bStyleNameOK(sal_False) +, bOutlineLevelOK(sal_False) +, bTOC( bT ) +, rPropertySet(rPropSet) +, sTokenEntryNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenEntryNumber)) +, sTokenEntryText(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenEntryText)) +, sTokenTabStop(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenTabStop)) +, sTokenText(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenText)) +, sTokenPageNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenPageNumber)) +, sTokenChapterInfo(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenChapterInfo)) +, sTokenHyperlinkStart(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenHyperlinkStart)) +, sTokenHyperlinkEnd(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenHyperlinkEnd)) +, sTokenBibliographyDataField(RTL_CONSTASCII_USTRINGPARAM(sAPI_TokenBibliographyDataField)) + +, sCharacterStyleName(RTL_CONSTASCII_USTRINGPARAM("CharacterStyleName")) +, sTokenType(RTL_CONSTASCII_USTRINGPARAM("TokenType")) +, sText(RTL_CONSTASCII_USTRINGPARAM("Text")) +, sTabStopRightAligned(RTL_CONSTASCII_USTRINGPARAM("TabStopRightAligned")) +, sTabStopPosition(RTL_CONSTASCII_USTRINGPARAM("TabStopPosition")) +, sTabStopFillCharacter(RTL_CONSTASCII_USTRINGPARAM("TabStopFillCharacter")) +, sBibliographyDataField(RTL_CONSTASCII_USTRINGPARAM("BibliographyDataField")) +, sChapterFormat(RTL_CONSTASCII_USTRINGPARAM("ChapterFormat")) +, sChapterLevel(RTL_CONSTASCII_USTRINGPARAM("ChapterLevel")) //#i53420 + +, sLevelFormat(RTL_CONSTASCII_USTRINGPARAM("LevelFormat")) +, sParaStyleLevel(RTL_CONSTASCII_USTRINGPARAM("ParaStyleLevel")) +{ + DBG_ASSERT( ((XML_TOKEN_INVALID != eLevelAttrName) && (NULL != pLevelNameMap)) + || ((XML_TOKEN_INVALID == eLevelAttrName) && (NULL == pLevelNameMap)), + "need both, attribute name and value map, or neither" ); + DBG_ASSERT( NULL != pOutlineLevelStylePropMap, "need property name map" ); + DBG_ASSERT( NULL != pAllowedTokenTypes, "need allowed tokens map" ); + + // no map for outline-level? then use 1 + if (NULL == pLevelNameMap) + { + nOutlineLevel = 1; + bOutlineLevelOK = sal_True; + } +} + +XMLIndexTemplateContext::~XMLIndexTemplateContext() +{ +} + + +void XMLIndexTemplateContext::addTemplateEntry( + const PropertyValues& aValues) +{ + aValueVector.push_back(aValues); +} + + +void XMLIndexTemplateContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // process two attributes: style-name, outline-level + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if (XML_NAMESPACE_TEXT == nPrefix) + { + if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) ) + { + // style name + sStyleName = xAttrList->getValueByIndex(nAttr); + bStyleNameOK = sal_True; + } + else if (eOutlineLevelAttrName != XML_TOKEN_INVALID) + { + // we have an attr name! Then see if we have the attr, too. + if (IsXMLToken(sLocalName, eOutlineLevelAttrName)) + { + // outline level + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum( + nTmp, xAttrList->getValueByIndex(nAttr), + pOutlineLevelNameMap)) + { + nOutlineLevel = nTmp; + bOutlineLevelOK = sal_True; + } + // else: illegal value -> ignore + } + // else: unknown attribute -> ignore + } + // else: we don't care about outline-level -> ignore + } + // else: attribute not in text namespace -> ignore + } +} + +void XMLIndexTemplateContext::EndElement() +{ + if (bOutlineLevelOK) + { + const sal_Int32 nCount = aValueVector.size(); + Sequence<PropertyValues> aValueSequence(nCount); + for(sal_Int32 i = 0; i<nCount; i++) + { + aValueSequence[i] = aValueVector[i]; + } + + // get LevelFormat IndexReplace ... + Any aAny = rPropertySet->getPropertyValue(sLevelFormat); + Reference<XIndexReplace> xIndexReplace; + aAny >>= xIndexReplace; + + // ... and insert + aAny <<= aValueSequence; + xIndexReplace->replaceByIndex(nOutlineLevel, aAny); + + if (bStyleNameOK) + { + const sal_Char* pStyleProperty = + pOutlineLevelStylePropMap[nOutlineLevel]; + + DBG_ASSERT(NULL != pStyleProperty, "need property name"); + if (NULL != pStyleProperty) + { + OUString sDisplayStyleName = + GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, + sStyleName ); + // #i50288#: Check if style exists + const Reference < ::com::sun::star::container::XNameContainer > & rStyles = + GetImport().GetTextImport()->GetParaStyles(); + if( rStyles.is() && + rStyles->hasByName( sDisplayStyleName ) ) + { + aAny <<= sDisplayStyleName; + rPropertySet->setPropertyValue( + OUString::createFromAscii(pStyleProperty), aAny); + } + } + } + } +} + + + +/// template token types; used for aTokenTypeMap parameter +enum TemplateTokenType +{ + XML_TOK_INDEX_TYPE_ENTRY_TEXT = 0, + XML_TOK_INDEX_TYPE_TAB_STOP, + XML_TOK_INDEX_TYPE_TEXT, + XML_TOK_INDEX_TYPE_PAGE_NUMBER, + XML_TOK_INDEX_TYPE_CHAPTER, + XML_TOK_INDEX_TYPE_LINK_START, + XML_TOK_INDEX_TYPE_LINK_END, + XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + + +SvXMLEnumMapEntry aTemplateTokenTypeMap[] = +{ + { XML_INDEX_ENTRY_TEXT, XML_TOK_INDEX_TYPE_ENTRY_TEXT }, + { XML_INDEX_ENTRY_TAB_STOP, XML_TOK_INDEX_TYPE_TAB_STOP }, + { XML_INDEX_ENTRY_SPAN, XML_TOK_INDEX_TYPE_TEXT }, + { XML_INDEX_ENTRY_PAGE_NUMBER, XML_TOK_INDEX_TYPE_PAGE_NUMBER }, + { XML_INDEX_ENTRY_CHAPTER, XML_TOK_INDEX_TYPE_CHAPTER }, + { XML_INDEX_ENTRY_LINK_START, XML_TOK_INDEX_TYPE_LINK_START }, + { XML_INDEX_ENTRY_LINK_END, XML_TOK_INDEX_TYPE_LINK_END }, + { XML_INDEX_ENTRY_BIBLIOGRAPHY, XML_TOK_INDEX_TYPE_BIBLIOGRAPHY }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLImportContext *XMLIndexTemplateContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if (XML_NAMESPACE_TEXT == nPrefix) + { + sal_uInt16 nToken; + if (SvXMLUnitConverter::convertEnum(nToken, rLocalName, + aTemplateTokenTypeMap)) + { + // can this index accept this kind of token? + if (pAllowedTokenTypesMap[nToken]) + { + switch ((TemplateTokenType)nToken) + { + case XML_TOK_INDEX_TYPE_ENTRY_TEXT: + pContext = new XMLIndexSimpleEntryContext( + GetImport(), sTokenEntryText, *this, + nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_PAGE_NUMBER: + pContext = new XMLIndexSimpleEntryContext( + GetImport(), sTokenPageNumber, *this, + nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_LINK_START: + pContext = new XMLIndexSimpleEntryContext( + GetImport(), sTokenHyperlinkStart, *this, + nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_LINK_END: + pContext = new XMLIndexSimpleEntryContext( + GetImport(), sTokenHyperlinkEnd, *this, + nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_TEXT: + pContext = new XMLIndexSpanEntryContext( + GetImport(), *this, nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_TAB_STOP: + pContext = new XMLIndexTabStopEntryContext( + GetImport(), *this, nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_BIBLIOGRAPHY: + pContext = new XMLIndexBibliographyEntryContext( + GetImport(), *this, nPrefix, rLocalName); + break; + + case XML_TOK_INDEX_TYPE_CHAPTER: + pContext = new XMLIndexChapterInfoEntryContext( + GetImport(), *this, nPrefix, rLocalName, bTOC ); + break; + + default: + // ignore! + break; + } + } + } + } + + // ignore unknown + if (NULL == pContext) + { + return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } + + return pContext; +} + + + +// +// maps for the XMLIndexTemplateContext constructor +// + + +// table of content and user defined index: + +const SvXMLEnumMapEntry aLevelNameTOCMap[] = +{ + { XML_1, 1 }, + { XML_2, 2 }, + { XML_3, 3 }, + { XML_4, 4 }, + { XML_5, 5 }, + { XML_6, 6 }, + { XML_7, 7 }, + { XML_8, 8 }, + { XML_9, 9 }, + { XML_10, 10 }, + { XML_TOKEN_INVALID, 0 } +}; + +const sal_Char* aLevelStylePropNameTOCMap[] = + { NULL, "ParaStyleLevel1", "ParaStyleLevel2", "ParaStyleLevel3", + "ParaStyleLevel4", "ParaStyleLevel5", "ParaStyleLevel6", + "ParaStyleLevel7", "ParaStyleLevel8", "ParaStyleLevel9", + "ParaStyleLevel10", NULL }; + +const sal_Bool aAllowedTokenTypesTOC[] = +{ + sal_True, // XML_TOK_INDEX_TYPE_ENTRY_TEXT = + sal_True, // XML_TOK_INDEX_TYPE_TAB_STOP, + sal_True, // XML_TOK_INDEX_TYPE_TEXT, + sal_True, // XML_TOK_INDEX_TYPE_PAGE_NUMBER, + sal_True, // XML_TOK_INDEX_TYPE_CHAPTER, + sal_True, // XML_TOK_INDEX_TYPE_LINK_START, + sal_True, // XML_TOK_INDEX_TYPE_LINK_END, + sal_False // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + +const sal_Bool aAllowedTokenTypesUser[] = +{ + sal_True, // XML_TOK_INDEX_TYPE_ENTRY_TEXT = + sal_True, // XML_TOK_INDEX_TYPE_TAB_STOP, + sal_True, // XML_TOK_INDEX_TYPE_TEXT, + sal_True, // XML_TOK_INDEX_TYPE_PAGE_NUMBER, + sal_True, // XML_TOK_INDEX_TYPE_CHAPTER, + sal_False, // XML_TOK_INDEX_TYPE_LINK_START, + sal_False, // XML_TOK_INDEX_TYPE_LINK_END, + sal_False // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + + +// alphabetical index + +const SvXMLEnumMapEntry aLevelNameAlphaMap[] = +{ + { XML_SEPARATOR, 1 }, + { XML_1, 2 }, + { XML_2, 3 }, + { XML_3, 4 }, + { XML_TOKEN_INVALID, 0 } +}; + +const sal_Char* aLevelStylePropNameAlphaMap[] = + { NULL, "ParaStyleSeparator", "ParaStyleLevel1", "ParaStyleLevel2", + "ParaStyleLevel3", NULL }; + +const sal_Bool aAllowedTokenTypesAlpha[] = +{ + sal_True, // XML_TOK_INDEX_TYPE_ENTRY_TEXT = + sal_True, // XML_TOK_INDEX_TYPE_TAB_STOP, + sal_True, // XML_TOK_INDEX_TYPE_TEXT, + sal_True, // XML_TOK_INDEX_TYPE_PAGE_NUMBER, + sal_True, // XML_TOK_INDEX_TYPE_CHAPTER, + sal_False, // XML_TOK_INDEX_TYPE_LINK_START, + sal_False, // XML_TOK_INDEX_TYPE_LINK_END, + sal_False // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + + +// bibliography index: + +const SvXMLEnumMapEntry aLevelNameBibliographyMap[] = +{ + { XML_ARTICLE, 1 }, + { XML_BOOK, 2 }, + { XML_BOOKLET, 3 }, + { XML_CONFERENCE, 4 }, + { XML_CUSTOM1, 5 }, + { XML_CUSTOM2, 6 }, + { XML_CUSTOM3, 7 }, + { XML_CUSTOM4, 8 }, + { XML_CUSTOM5, 9 }, + { XML_EMAIL, 10 }, + { XML_INBOOK, 11 }, + { XML_INCOLLECTION, 12 }, + { XML_INPROCEEDINGS, 13 }, + { XML_JOURNAL, 14 }, + { XML_MANUAL, 15 }, + { XML_MASTERSTHESIS, 16 }, + { XML_MISC, 17 }, + { XML_PHDTHESIS, 18 }, + { XML_PROCEEDINGS, 19 }, + { XML_TECHREPORT, 20 }, + { XML_UNPUBLISHED, 21 }, + { XML_WWW, 22 }, + { XML_TOKEN_INVALID, 0 } +}; + +// TODO: replace with real property names, when available +const sal_Char* aLevelStylePropNameBibliographyMap[] = +{ + NULL, "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", NULL }; + +const sal_Bool aAllowedTokenTypesBibliography[] = +{ + sal_True, // XML_TOK_INDEX_TYPE_ENTRY_TEXT = + sal_True, // XML_TOK_INDEX_TYPE_TAB_STOP, + sal_True, // XML_TOK_INDEX_TYPE_TEXT, + sal_True, // XML_TOK_INDEX_TYPE_PAGE_NUMBER, + sal_False, // XML_TOK_INDEX_TYPE_CHAPTER, + sal_False, // XML_TOK_INDEX_TYPE_LINK_START, + sal_False, // XML_TOK_INDEX_TYPE_LINK_END, + sal_True // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + + +// table, illustration and object index + +// no name map +const SvXMLEnumMapEntry* aLevelNameTableMap = NULL; + +const sal_Char* aLevelStylePropNameTableMap[] = + { NULL, "ParaStyleLevel1", NULL }; + +const sal_Bool aAllowedTokenTypesTable[] = +{ + sal_True, // XML_TOK_INDEX_TYPE_ENTRY_TEXT = + sal_True, // XML_TOK_INDEX_TYPE_TAB_STOP, + sal_True, // XML_TOK_INDEX_TYPE_TEXT, + sal_True, // XML_TOK_INDEX_TYPE_PAGE_NUMBER, + sal_True, // XML_TOK_INDEX_TYPE_CHAPTER, + sal_False, // XML_TOK_INDEX_TYPE_LINK_START, + sal_False, // XML_TOK_INDEX_TYPE_LINK_END, + sal_False // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY +}; + diff --git a/xmloff/source/text/XMLIndexTemplateContext.hxx b/xmloff/source/text/XMLIndexTemplateContext.hxx new file mode 100644 index 000000000000..d63cb485826b --- /dev/null +++ b/xmloff/source/text/XMLIndexTemplateContext.hxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTEMPLATECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTEMPLATECONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmltoken.hxx> + +#include <vector> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValues.hpp> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } +struct SvXMLEnumMapEntry; + + +// constants for the XMLIndexTemplateContext constructor + +// TOC and user defined index: +extern const SvXMLEnumMapEntry aLevelNameTOCMap[]; +extern const sal_Char* aLevelStylePropNameTOCMap[]; +extern const sal_Bool aAllowedTokenTypesTOC[]; +extern const sal_Bool aAllowedTokenTypesUser[]; + +// alphabetical index: +extern const SvXMLEnumMapEntry aLevelNameAlphaMap[]; +extern const sal_Char* aLevelStylePropNameAlphaMap[]; +extern const sal_Bool aAllowedTokenTypesAlpha[]; + +// bibliography: +extern const SvXMLEnumMapEntry aLevelNameBibliographyMap[]; +extern const sal_Char* aLevelStylePropNameBibliographyMap[]; +extern const sal_Bool aAllowedTokenTypesBibliography[]; + +// table, illustration and object tables: +extern const SvXMLEnumMapEntry* aLevelNameTableMap; // NULL: no outline-level +extern const sal_Char* aLevelStylePropNameTableMap[]; +extern const sal_Bool aAllowedTokenTypesTable[]; + + +/** + * Import index entry templates + */ +class XMLIndexTemplateContext : public SvXMLImportContext +{ + // pick up PropertyValues to be turned into a sequence. + ::std::vector< ::com::sun::star::beans::PropertyValues > aValueVector; + + ::rtl::OUString sStyleName; + + const SvXMLEnumMapEntry* pOutlineLevelNameMap; + enum ::xmloff::token::XMLTokenEnum eOutlineLevelAttrName; + const sal_Char** pOutlineLevelStylePropMap; + const sal_Bool* pAllowedTokenTypesMap; + + sal_Int32 nOutlineLevel; + sal_Bool bStyleNameOK; + sal_Bool bOutlineLevelOK; + sal_Bool bTOC; + + // PropertySet of current index + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet; + +public: + + // constants made available to other contexts (template entry + // contexts, in particular) + const ::rtl::OUString sTokenEntryNumber; + const ::rtl::OUString sTokenEntryText; + const ::rtl::OUString sTokenTabStop; + const ::rtl::OUString sTokenText; + const ::rtl::OUString sTokenPageNumber; + const ::rtl::OUString sTokenChapterInfo; + const ::rtl::OUString sTokenHyperlinkStart; + const ::rtl::OUString sTokenHyperlinkEnd; + const ::rtl::OUString sTokenBibliographyDataField; + + const ::rtl::OUString sCharacterStyleName; + const ::rtl::OUString sTokenType; + const ::rtl::OUString sText; + const ::rtl::OUString sTabStopRightAligned; + const ::rtl::OUString sTabStopPosition; + const ::rtl::OUString sTabStopFillCharacter; + const ::rtl::OUString sBibliographyDataField; + const ::rtl::OUString sChapterFormat; + const ::rtl::OUString sChapterLevel;//i53420 + + const ::rtl::OUString sLevelFormat; + const ::rtl::OUString sParaStyleLevel; + + + TYPEINFO(); + + XMLIndexTemplateContext( + SvXMLImport& rImport, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + const SvXMLEnumMapEntry* aLevelNameMap, + enum ::xmloff::token::XMLTokenEnum eLevelAttrName, + const sal_Char** aLevelStylePropNameMap, + const sal_Bool* aAllowedTokenTypes, + sal_Bool bTOC=sal_False); + + ~XMLIndexTemplateContext(); + + /** add template; to be called by child template entry contexts */ + void addTemplateEntry( + const ::com::sun::star::beans::PropertyValues& aValues); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexTitleTemplateContext.cxx b/xmloff/source/text/XMLIndexTitleTemplateContext.cxx new file mode 100644 index 000000000000..333c141f8843 --- /dev/null +++ b/xmloff/source/text/XMLIndexTitleTemplateContext.cxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_STYLE_NAME; + + +const sal_Char sAPI_Title[] = "Title"; +const sal_Char sAPI_ParaStyleHeading[] = "ParaStyleHeading"; + + +TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext ); + +XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext( + SvXMLImport& rImport, + Reference<XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const OUString& rLocalName) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sTitle(RTL_CONSTASCII_USTRINGPARAM(sAPI_Title)) +, sParaStyleHeading(RTL_CONSTASCII_USTRINGPARAM(sAPI_ParaStyleHeading)) +, bStyleNameOK(sal_False) +, rTOCPropertySet(rPropSet) +{ +} + + +XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext() +{ +} + +void XMLIndexTitleTemplateContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // there's only one attribute: style-name + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + if ( (XML_NAMESPACE_TEXT == nPrefix) && + (IsXMLToken(sLocalName, XML_STYLE_NAME)) ) + { + sStyleName = xAttrList->getValueByIndex(nAttr); + OUString sDisplayStyleName = GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName ); + const Reference < ::com::sun::star::container::XNameContainer >& + rStyles = GetImport().GetTextImport()->GetParaStyles(); + bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName ); + } + } +} + +void XMLIndexTitleTemplateContext::EndElement() +{ + Any aAny; + + aAny <<= sContent.makeStringAndClear(); + rTOCPropertySet->setPropertyValue(sTitle, aAny); + + if (bStyleNameOK) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, + sStyleName ); + rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny); + } +} + +void XMLIndexTitleTemplateContext::Characters( + const OUString& sString) +{ + sContent.append(sString); +} diff --git a/xmloff/source/text/XMLIndexTitleTemplateContext.hxx b/xmloff/source/text/XMLIndexTitleTemplateContext.hxx new file mode 100644 index 000000000000..fb9e1190ec3e --- /dev/null +++ b/xmloff/source/text/XMLIndexTitleTemplateContext.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXTITLETEMPLATECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXTITLETEMPLATECONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + + +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } + + +/** + * Import index title templates + */ +class XMLIndexTitleTemplateContext : public SvXMLImportContext +{ + + const ::rtl::OUString sTitle; + const ::rtl::OUString sParaStyleHeading; + + // paragraph style + ::rtl::OUString sStyleName; + sal_Bool bStyleNameOK; + + // content + ::rtl::OUStringBuffer sContent; + + // TOC property set + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rTOCPropertySet; + +public: + + TYPEINFO(); + + XMLIndexTitleTemplateContext( + SvXMLImport& rImport, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName); + + ~XMLIndexTitleTemplateContext(); + +protected: + + /** process parameters */ + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + /** set values */ + virtual void EndElement(); + + /** pick up title characters */ + virtual void Characters(const ::rtl::OUString& sString); +}; + +#endif diff --git a/xmloff/source/text/XMLIndexUserSourceContext.cxx b/xmloff/source/text/XMLIndexUserSourceContext.cxx new file mode 100644 index 000000000000..b87551307d73 --- /dev/null +++ b/xmloff/source/text/XMLIndexUserSourceContext.cxx @@ -0,0 +1,231 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLIndexUserSourceContext.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include "XMLIndexTemplateContext.hxx" +#include "XMLIndexTitleTemplateContext.hxx" +#include "XMLIndexTOCStylesContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> + + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_USER_INDEX_ENTRY_TEMPLATE; +using ::xmloff::token::XML_OUTLINE_LEVEL; + + +const sal_Char sAPI_CreateFromEmbeddedObjects[] = "CreateFromEmbeddedObjects"; +const sal_Char sAPI_CreateFromGraphicObjects[] = "CreateFromGraphicObjects"; +const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks"; +const sal_Char sAPI_CreateFromTables[] = "CreateFromTables"; +const sal_Char sAPI_CreateFromTextFrames[] = "CreateFromTextFrames"; +const sal_Char sAPI_UseLevelFromSource[] = "UseLevelFromSource"; +const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles"; +const sal_Char sAPI_UserIndexName[] = "UserIndexName"; + + +TYPEINIT1(XMLIndexUserSourceContext, XMLIndexSourceBaseContext); + + +XMLIndexUserSourceContext::XMLIndexUserSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rPropSet) : + XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, + rPropSet, sal_True), + sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromEmbeddedObjects)), + sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromGraphicObjects)), + sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)), + sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromTables)), + sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromTextFrames)), + sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM( + sAPI_UseLevelFromSource)), + sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM( + sAPI_CreateFromLevelParagraphStyles)), + sUserIndexName(RTL_CONSTASCII_USTRINGPARAM(sAPI_UserIndexName)), + bUseObjects(sal_False), + bUseGraphic(sal_False), + bUseMarks(sal_False), + bUseTables(sal_False), + bUseFrames(sal_False), + bUseLevelFromSource(sal_False), + bUseLevelParagraphStyles(sal_False) +{ +} + +XMLIndexUserSourceContext::~XMLIndexUserSourceContext() +{ +} + +void XMLIndexUserSourceContext::ProcessAttribute( + enum IndexSourceParamEnum eParam, + const OUString& rValue) +{ + sal_Bool bTmp; + + switch (eParam) + { + case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseMarks = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_OBJECTS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseObjects = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_GRAPHICS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseGraphic = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_TABLES: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseTables = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_FRAMES: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseFrames = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseLevelFromSource = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES: + if (SvXMLUnitConverter::convertBool(bTmp, rValue)) + { + bUseLevelParagraphStyles = bTmp; + } + break; + + case XML_TOK_INDEXSOURCE_USER_INDEX_NAME: + sIndexName = rValue; + break; + + default: + XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); + break; + } +} + + +void XMLIndexUserSourceContext::EndElement() +{ + Any aAny; + + aAny.setValue(&bUseObjects, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromEmbeddedObjects, aAny); + + aAny.setValue(&bUseGraphic, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromGraphicObjects, aAny); + + aAny.setValue(&bUseLevelFromSource, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sUseLevelFromSource, aAny); + + aAny.setValue(&bUseMarks, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny); + + aAny.setValue(&bUseTables, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromTables, aAny); + + aAny.setValue(&bUseFrames, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromTextFrames, aAny); + + aAny.setValue(&bUseLevelParagraphStyles, ::getBooleanCppuType()); + rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny); + + if( sIndexName.getLength() > 0 ) + { + aAny <<= sIndexName; + rIndexPropertySet->setPropertyValue(sUserIndexName, aAny); + } + + XMLIndexSourceBaseContext::EndElement(); +} + + +SvXMLImportContext* XMLIndexUserSourceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_TEXT == nPrefix) && + (IsXMLToken(rLocalName, XML_USER_INDEX_ENTRY_TEMPLATE)) ) + { + return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, + nPrefix, rLocalName, + aLevelNameTOCMap, + XML_OUTLINE_LEVEL, + aLevelStylePropNameTOCMap, + aAllowedTokenTypesUser); + } + else + { + return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + +} diff --git a/xmloff/source/text/XMLIndexUserSourceContext.hxx b/xmloff/source/text/XMLIndexUserSourceContext.hxx new file mode 100644 index 000000000000..0b7684ec7dae --- /dev/null +++ b/xmloff/source/text/XMLIndexUserSourceContext.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLINDEXUSERSOURCECONTEXT_HXX_ +#define _XMLOFF_XMLINDEXUSERSOURCECONTEXT_HXX_ + +#include "XMLIndexSourceBaseContext.hxx" +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } + namespace beans { class XPropertySet; } +} } } +namespace rtl { class OUString; } + + +/** + * Import user defined index source element + */ +class XMLIndexUserSourceContext : public XMLIndexSourceBaseContext +{ + const ::rtl::OUString sCreateFromEmbeddedObjects; + const ::rtl::OUString sCreateFromGraphicObjects; + const ::rtl::OUString sCreateFromMarks; + const ::rtl::OUString sCreateFromTables; + const ::rtl::OUString sCreateFromTextFrames; + const ::rtl::OUString sUseLevelFromSource; + const ::rtl::OUString sCreateFromLevelParagraphStyles; + const ::rtl::OUString sUserIndexName; + + sal_Bool bUseObjects; + sal_Bool bUseGraphic; + sal_Bool bUseMarks; + sal_Bool bUseTables; + sal_Bool bUseFrames; + sal_Bool bUseLevelFromSource; + sal_Bool bUseLevelParagraphStyles; + ::rtl::OUString sIndexName; + +public: + + TYPEINFO(); + + XMLIndexUserSourceContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + ~XMLIndexUserSourceContext(); + +protected: + + virtual void ProcessAttribute( + enum IndexSourceParamEnum eParam, + const ::rtl::OUString& rValue); + + virtual void EndElement(); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLLineNumberingExport.cxx b/xmloff/source/text/XMLLineNumberingExport.cxx new file mode 100644 index 000000000000..dd0386d48aab --- /dev/null +++ b/xmloff/source/text/XMLLineNumberingExport.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLLineNumberingExport.hxx" +#include "com/sun/star/beans/XPropertySet.hpp" +#include "com/sun/star/text/XLineNumberingProperties.hpp" +#include <com/sun/star/style/LineNumberPosition.hpp> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnume.hxx> + + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::text::XLineNumberingProperties; + + +XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp) +: sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")) +, sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines")) +, sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames")) +, sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance")) +, sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval")) +, sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText")) +, sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition")) +, sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")) +, sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn")) +, sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage")) +, sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval")) +, rExport(rExp) +{ +} + +SvXMLEnumMapEntry __READONLY_DATA aLineNumberPositionMap[] = +{ + { XML_LEFT, style::LineNumberPosition::LEFT }, + { XML_RIGHT, style::LineNumberPosition::RIGHT }, + { XML_INSIDE, style::LineNumberPosition::INSIDE }, + { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE }, + { XML_TOKEN_INVALID, 0 } +}; + + + +void XMLLineNumberingExport::Export() +{ + // export element if we have line numbering info + Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(), + UNO_QUERY); + if (xSupplier.is()) + { + Reference<XPropertySet> xLineNumbering = + xSupplier->getLineNumberingProperties(); + + if (xLineNumbering.is()) + { + Any aAny; + + // char style + aAny = xLineNumbering->getPropertyValue(sCharStyleName); + OUString sTmp; + aAny >>= sTmp; + if (sTmp.getLength() > 0) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, + rExport.EncodeStyleName( sTmp )); + } + + // enable + aAny = xLineNumbering->getPropertyValue(sIsOn); + if (! *(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_NUMBER_LINES, XML_FALSE); + } + + // count empty lines + aAny = xLineNumbering->getPropertyValue(sCountEmptyLines); + if (! *(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_COUNT_EMPTY_LINES, XML_FALSE); + } + + // count in frames + aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames); + if (*(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_COUNT_IN_TEXT_BOXES, XML_TRUE); + } + + // restart numbering + aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage); + if (*(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_RESTART_ON_PAGE, XML_TRUE); + } + + // Distance + aAny = xLineNumbering->getPropertyValue(sDistance); + sal_Int32 nLength = 0; + aAny >>= nLength; + if (nLength != 0) + { + OUStringBuffer sBuf; + rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLength); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET, + sBuf.makeStringAndClear()); + } + + // NumeringType + OUStringBuffer sNumPosBuf; + aAny = xLineNumbering->getPropertyValue(sNumberingType); + sal_Int16 nFormat = 0; + aAny >>= nFormat; + rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat ); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT, + sNumPosBuf.makeStringAndClear()); + rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat ); + if( sNumPosBuf.getLength() ) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, + XML_NUM_LETTER_SYNC, + sNumPosBuf.makeStringAndClear() ); + } + + // number position + aAny = xLineNumbering->getPropertyValue(sNumberPosition); + sal_Int16 nPosition = 0; + aAny >>= nPosition; + if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition, + aLineNumberPositionMap)) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION, + sNumPosBuf.makeStringAndClear()); + } + + // sInterval + aAny = xLineNumbering->getPropertyValue(sInterval); + sal_Int16 nLineInterval = 0; + aAny >>= nLineInterval; + OUStringBuffer sBuf; + SvXMLUnitConverter::convertNumber(sBuf, + (sal_Int32)nLineInterval); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT, + sBuf.makeStringAndClear()); + + SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT, + XML_LINENUMBERING_CONFIGURATION, + sal_True, sal_True); + + // line separator + aAny = xLineNumbering->getPropertyValue(sSeparatorText); + OUString sSeparator; + aAny >>= sSeparator; + if (sSeparator.getLength() > 0) + { + + // SeparatorInterval + aAny = xLineNumbering->getPropertyValue(sSeparatorInterval); + sal_Int16 nLineDistance = 0; + aAny >>= nLineDistance; + SvXMLUnitConverter::convertNumber(sBuf, + (sal_Int32)nLineDistance); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT, + sBuf.makeStringAndClear()); + + SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT, + XML_LINENUMBERING_SEPARATOR, + sal_True, sal_False); + rExport.Characters(sSeparator); + } + } + // else: no configuration: don't save -> default + } + // can't even get supplier: don't save -> default +} diff --git a/xmloff/source/text/XMLLineNumberingExport.hxx b/xmloff/source/text/XMLLineNumberingExport.hxx new file mode 100644 index 000000000000..aaa1995a4e06 --- /dev/null +++ b/xmloff/source/text/XMLLineNumberingExport.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLLINENUMBERINGEXPORT_HXX_ +#define _XMLOFF_XMLLINENUMBERINGEXPORT_HXX_ + + +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.h> + +class SvXMLExport; + +/** export <text:linenumbering-configuration> and it's child elements */ +class XMLLineNumberingExport +{ + const ::rtl::OUString sCharStyleName; + const ::rtl::OUString sCountEmptyLines; + const ::rtl::OUString sCountLinesInFrames; + const ::rtl::OUString sDistance; + const ::rtl::OUString sInterval; + const ::rtl::OUString sSeparatorText; + const ::rtl::OUString sNumberPosition; + const ::rtl::OUString sNumberingType; + const ::rtl::OUString sIsOn; + const ::rtl::OUString sRestartAtEachPage; + const ::rtl::OUString sSeparatorInterval; + + SvXMLExport& rExport; + +public: + XMLLineNumberingExport(SvXMLExport& rExp); + + void Export(); +}; + +#endif diff --git a/xmloff/source/text/XMLLineNumberingImportContext.cxx b/xmloff/source/text/XMLLineNumberingImportContext.cxx new file mode 100644 index 000000000000..cc1e11389750 --- /dev/null +++ b/xmloff/source/text/XMLLineNumberingImportContext.cxx @@ -0,0 +1,322 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLLineNumberingImportContext.hxx" +#include "XMLLineNumberingSeparatorImportContext.hxx" +#include "com/sun/star/beans/XPropertySet.hpp" +#include "com/sun/star/text/XLineNumberingProperties.hpp" +#include <com/sun/star/style/LineNumberPosition.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnumi.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::xmloff::token; + +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::text::XLineNumberingProperties; +using ::rtl::OUString; + +TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext ); + + +XMLLineNumberingImportContext::XMLLineNumberingImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG) +, sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")) +, sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines")) +, sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames")) +, sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance")) +, sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval")) +, sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText")) +, sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition")) +, sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")) +, sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn")) +, sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage")) +, sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval")) +, sNumFormat(GetXMLToken(XML_1)) +, sNumLetterSync(GetXMLToken(XML_FALSE)) +, nOffset(-1) +, nNumberPosition(style::LineNumberPosition::LEFT) +, nIncrement(-1) +, nSeparatorIncrement(-1) +, bNumberLines(sal_True) +, bCountEmptyLines(sal_True) +, bCountInFloatingFrames(sal_False) +, bRestartNumbering(sal_False) +{ +} + +XMLLineNumberingImportContext::~XMLLineNumberingImportContext() +{ +} + +void XMLLineNumberingImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + static SvXMLTokenMapEntry aLineNumberingTokenMap[] = + { + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_NUMBER_LINES, + XML_TOK_LINENUMBERING_NUMBER_LINES }, + { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES, + XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES }, + { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES, + XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES }, + { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE, + XML_TOK_LINENUMBERING_RESTART_NUMBERING }, + { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET }, + { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT }, + { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, + XML_TOK_LINENUMBERING_NUM_LETTER_SYNC }, + { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION, + XML_TOK_LINENUMBERING_NUMBER_POSITION }, + { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT }, + // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION, + // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION }, + // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT }, + // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR, + // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR }, + + XML_TOKEN_MAP_END + }; + + SvXMLTokenMap aTokenMap(aLineNumberingTokenMap); + + // process attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + ProcessAttribute( + (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName), + xAttrList->getValueByIndex(i)); + } +} + +void XMLLineNumberingImportContext::ProcessAttribute( + enum LineNumberingToken eToken, + OUString sValue) +{ + sal_Bool bTmp; + sal_Int32 nTmp; + + switch (eToken) + { + case XML_TOK_LINENUMBERING_STYLE_NAME: + sStyleName = sValue; + break; + + case XML_TOK_LINENUMBERING_NUMBER_LINES: + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + { + bNumberLines = bTmp; + } + break; + + case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES: + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + { + bCountEmptyLines = bTmp; + } + break; + + case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES: + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + { + bCountInFloatingFrames = bTmp; + } + break; + + case XML_TOK_LINENUMBERING_RESTART_NUMBERING: + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + { + bRestartNumbering = bTmp; + } + break; + + case XML_TOK_LINENUMBERING_OFFSET: + if (GetImport().GetMM100UnitConverter(). + convertMeasure(nTmp, sValue)) + { + nOffset = nTmp; + } + break; + + case XML_TOK_LINENUMBERING_NUM_FORMAT: + sNumFormat = sValue; + break; + + case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC: + sNumLetterSync = sValue; + break; + + case XML_TOK_LINENUMBERING_NUMBER_POSITION: + { + static const SvXMLEnumMapEntry aLineNumberPositionMap[] = + { + { XML_LEFT, style::LineNumberPosition::LEFT }, + { XML_RIGHT, style::LineNumberPosition::RIGHT }, + { XML_INSIDE, style::LineNumberPosition::INSIDE }, + { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE }, + { XML_TOKEN_INVALID, 0 } + }; + + sal_uInt16 nTmp16; + if (SvXMLUnitConverter::convertEnum(nTmp16, sValue, + aLineNumberPositionMap)) + { + nNumberPosition = nTmp16; + } + break; + } + + case XML_TOK_LINENUMBERING_INCREMENT: + if (SvXMLUnitConverter::convertNumber(nTmp, sValue, 0)) + { + nIncrement = (sal_Int16)nTmp; + } + break; + } +} + +void XMLLineNumberingImportContext::CreateAndInsert(sal_Bool) +{ + // insert and block mode is handled in insertStyleFamily + + // we'll try to get the LineNumberingProperties + Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(), + UNO_QUERY); + if (xSupplier.is()) + { + Reference<XPropertySet> xLineNumbering = + xSupplier->getLineNumberingProperties(); + + if (xLineNumbering.is()) + { + Any aAny; + + // set style name (if it exists) + if ( GetImport().GetStyles()->FindStyleChildContext( + XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL ) + { + aAny <<= GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ); + xLineNumbering->setPropertyValue(sCharStyleName, aAny); + } + + aAny <<= sSeparator; + xLineNumbering->setPropertyValue(sSeparatorText, aAny); + + aAny <<= nOffset; + xLineNumbering->setPropertyValue(sDistance, aAny); + + aAny <<= nNumberPosition; + xLineNumbering->setPropertyValue(sNumberPosition, aAny); + + if (nIncrement >= 0) + { + aAny <<= nIncrement; + xLineNumbering->setPropertyValue(sInterval, aAny); + } + + if (nSeparatorIncrement >= 0) + { + aAny <<= nSeparatorIncrement; + xLineNumbering->setPropertyValue(sSeparatorInterval, aAny); + } + + aAny.setValue(&bNumberLines, ::getBooleanCppuType()); + xLineNumbering->setPropertyValue(sIsOn, aAny); + + aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType()); + xLineNumbering->setPropertyValue(sCountEmptyLines, aAny); + + aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType()); + xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny); + + aAny.setValue(&bRestartNumbering, ::getBooleanCppuType()); + xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny); + + sal_Int16 nNumType = NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumFormat, + sNumLetterSync ); + aAny <<= nNumType; + xLineNumbering->setPropertyValue(sNumberingType, aAny); + } + } +} + +SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (nPrefix == XML_NAMESPACE_TEXT) && + IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) ) + { + return new XMLLineNumberingSeparatorImportContext(GetImport(), + nPrefix, rLocalName, + *this); + } + else + { + // unknown element: default context + return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } +} + +void XMLLineNumberingImportContext::SetSeparatorText( + const OUString& sText) +{ + sSeparator = sText; +} + +void XMLLineNumberingImportContext::SetSeparatorIncrement( + sal_Int16 nIncr) +{ + nSeparatorIncrement = nIncr; +} + diff --git a/xmloff/source/text/XMLLineNumberingSeparatorImportContext.cxx b/xmloff/source/text/XMLLineNumberingSeparatorImportContext.cxx new file mode 100644 index 000000000000..4c2b62c5ec35 --- /dev/null +++ b/xmloff/source/text/XMLLineNumberingSeparatorImportContext.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLLineNumberingSeparatorImportContext.hxx" +#include "XMLLineNumberingImportContext.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + + +using namespace ::com::sun::star::uno; + +using ::com::sun::star::xml::sax::XAttributeList; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_INCREMENT; + +TYPEINIT1( XMLLineNumberingSeparatorImportContext, SvXMLImportContext ); + +XMLLineNumberingSeparatorImportContext::XMLLineNumberingSeparatorImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + XMLLineNumberingImportContext& rLineNumbering) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + rLineNumberingContext(rLineNumbering) +{ +} + +XMLLineNumberingSeparatorImportContext::~XMLLineNumberingSeparatorImportContext() +{ +} + +void XMLLineNumberingSeparatorImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + if ( (nPrefix == XML_NAMESPACE_TEXT) && + IsXMLToken(sLocalName, XML_INCREMENT) ) + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( + nTmp, xAttrList->getValueByIndex(i), 0)) + { + rLineNumberingContext.SetSeparatorIncrement((sal_Int16)nTmp); + } + // else: invalid number -> ignore + } + // else: unknown attribute -> ignore + } +} + +void XMLLineNumberingSeparatorImportContext::Characters( + const OUString& rChars ) +{ + sSeparatorBuf.append(rChars); +} + +void XMLLineNumberingSeparatorImportContext::EndElement() +{ + rLineNumberingContext.SetSeparatorText(sSeparatorBuf.makeStringAndClear()); +} diff --git a/xmloff/source/text/XMLLineNumberingSeparatorImportContext.hxx b/xmloff/source/text/XMLLineNumberingSeparatorImportContext.hxx new file mode 100644 index 000000000000..84661343adba --- /dev/null +++ b/xmloff/source/text/XMLLineNumberingSeparatorImportContext.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLLINENUMBERINGSEPARATORIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLLINENUMBERINGSEPARATORIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace xml { namespace sax { class XAttributeList; } } +} } } +class XMLLineNumberingImportContext; + + +/** import <text:linenumbering-separator> elements */ +class XMLLineNumberingSeparatorImportContext : public SvXMLImportContext +{ + ::rtl::OUStringBuffer sSeparatorBuf; + XMLLineNumberingImportContext& rLineNumberingContext; + +public: + + TYPEINFO(); + + XMLLineNumberingSeparatorImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + XMLLineNumberingImportContext& rLineNumbering); + + ~XMLLineNumberingSeparatorImportContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void Characters( const ::rtl::OUString& rChars ); + + virtual void EndElement(); +}; + +#endif diff --git a/xmloff/source/text/XMLPropertyBackpatcher.cxx b/xmloff/source/text/XMLPropertyBackpatcher.cxx new file mode 100644 index 000000000000..364096ad8185 --- /dev/null +++ b/xmloff/source/text/XMLPropertyBackpatcher.cxx @@ -0,0 +1,312 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Reference.h> + +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include "XMLPropertyBackpatcher.hxx" +#include <xmloff/txtimp.hxx> // XMLTextImportHelper partially implemented here + + +using ::rtl::OUString; +using ::std::vector; +using ::std::map; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::beans::XPropertySet; + + +template<class A> +XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher( + const ::rtl::OUString& sPropName) +: sPropertyName(sPropName) +, bDefaultHandling(sal_False) +, bPreserveProperty(sal_False) +, sPreservePropertyName() +{ +} + +template<class A> +XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher( + const OUString& sPropName, + const OUString& sPreserveName, + sal_Bool bDefault, + A aDef) +: sPropertyName(sPropName) +, bDefaultHandling(bDefault) +, bPreserveProperty(sPreserveName.getLength()>0) +, sPreservePropertyName(sPreserveName) +, aDefault(aDef) +{ +} + +template<class A> +XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher( + const sal_Char* pPropName) +: bDefaultHandling(sal_False) +, bPreserveProperty(sal_False) +{ + DBG_ASSERT(pPropName != NULL, "need property name"); + sPropertyName = OUString::createFromAscii(pPropName); +} + +template<class A> +XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher( + const sal_Char* pPropName, + const sal_Char* pPreservePropName, + sal_Bool bDefault, + A aDef) +: bDefaultHandling(bDefault) +, bPreserveProperty(pPreservePropName != NULL) +, aDefault(aDef) +{ + DBG_ASSERT(pPropName != NULL, "need property name"); + sPropertyName = OUString::createFromAscii(pPropName); + if (pPreservePropName != NULL) + { + sPreservePropertyName = OUString::createFromAscii(pPreservePropName); + } +} + +template<class A> +XMLPropertyBackpatcher<A>::~XMLPropertyBackpatcher() +{ + SetDefault(); +} + + +template<class A> +void XMLPropertyBackpatcher<A>::ResolveId( + const OUString& sName, + A aValue) +{ + // insert ID into ID map + aIDMap[sName] = aValue; + + // backpatch old references, if backpatch list exists + if (aBackpatchListMap.count(sName)) + { + // aah, we have a backpatch list! + BackpatchListType* pList = + (BackpatchListType*)aBackpatchListMap[sName]; + + // a) remove list from list map + aBackpatchListMap.erase(sName); + + // b) for every item, set SequenceNumber + // (and preserve Property, if appropriate) + Any aAny; + aAny <<= aValue; + if (bPreserveProperty) + { + // preserve version + for(BackpatchListType::iterator aIter = pList->begin(); + aIter != pList->end(); + aIter++) + { + Reference<XPropertySet> xProp = (*aIter); + Any aPres = xProp->getPropertyValue(sPreservePropertyName); + xProp->setPropertyValue(sPropertyName, aAny); + xProp->setPropertyValue(sPreservePropertyName, aPres); + } + } + else + { + // without preserve + for(BackpatchListType::iterator aIter = pList->begin(); + aIter != pList->end(); + aIter++) + { + (*aIter)->setPropertyValue(sPropertyName, aAny); + } + } + + // c) delete list + delete pList; + } + // else: no backpatch list -> then we're finished +} + +template<class A> +void XMLPropertyBackpatcher<A>::SetProperty( + const Reference<XPropertySet> & xPropSet, + const OUString& sName) +{ + Reference<XPropertySet> xNonConstPropSet(xPropSet); + SetProperty(xNonConstPropSet, sName); +} + +template<class A> +void XMLPropertyBackpatcher<A>::SetProperty( + Reference<XPropertySet> & xPropSet, + const OUString& sName) +{ + if (aIDMap.count(sName)) + { + // we know this ID -> set property + Any aAny; + aAny <<= aIDMap[sName]; + xPropSet->setPropertyValue(sPropertyName, aAny); + } + else + { + // ID unknown -> into backpatch list for later fixup + if (! aBackpatchListMap.count(sName)) + { + // create backpatch list for this name + BackpatchListType* pTmp = new BackpatchListType() ; + aBackpatchListMap[sName] = (void*)pTmp; + } + + // insert footnote + ((BackpatchListType*)aBackpatchListMap[sName])->push_back(xPropSet); + } +} + +template<class A> +void XMLPropertyBackpatcher<A>::SetDefault() +{ + if (bDefaultHandling) + { + // not implemented yet + } +} + +// force instantiation of templates +template class XMLPropertyBackpatcher<sal_Int16>; +template class XMLPropertyBackpatcher<OUString>; + +struct SAL_DLLPRIVATE XMLTextImportHelper::BackpatcherImpl +{ + /// backpatcher for references to footnotes and endnotes + ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> > + m_pFootnoteBackpatcher; + + /// backpatchers for references to sequences + ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> > + m_pSequenceIdBackpatcher; + + ::std::auto_ptr< XMLPropertyBackpatcher< ::rtl::OUString> > + m_pSequenceNameBackpatcher; + +}; + +::boost::shared_ptr<XMLTextImportHelper::BackpatcherImpl> +XMLTextImportHelper::MakeBackpatcherImpl() +{ + // n.b.: the shared_ptr stores the dtor! + return ::boost::shared_ptr<BackpatcherImpl>(new BackpatcherImpl); +} + +static ::rtl::OUString const& GetSequenceNumber() +{ + static ::rtl::OUString s_SequenceNumber( + RTL_CONSTASCII_USTRINGPARAM("SequenceNumber")); + return s_SequenceNumber; +} + +// +// XMLTextImportHelper +// +// Code from XMLTextImportHelper using the XMLPropertyBackpatcher is +// implemented here. The reason is that in the unxsols2 environment, +// all templates are instatiated as file local (switch +// -instances=static), and thus are not accessible from the outside. +// +// The previous solution was to force additional instantiation of +// XMLPropertyBackpatcher in txtimp.cxx. This solution combines all +// usage of the XMLPropertyBackpatcher in XMLPropertyBackpatcher.cxx +// instead. +// + +XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetFootnoteBP() +{ + if (!m_pBackpatcherImpl->m_pFootnoteBackpatcher.get()) + { + m_pBackpatcherImpl->m_pFootnoteBackpatcher.reset( + new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber())); + } + return *m_pBackpatcherImpl->m_pFootnoteBackpatcher; +} + +XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetSequenceIdBP() +{ + if (!m_pBackpatcherImpl->m_pSequenceIdBackpatcher.get()) + { + m_pBackpatcherImpl->m_pSequenceIdBackpatcher.reset( + new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber())); + } + return *m_pBackpatcherImpl->m_pSequenceIdBackpatcher; +} + +XMLPropertyBackpatcher<OUString>& XMLTextImportHelper::GetSequenceNameBP() +{ + static ::rtl::OUString s_SourceName( + RTL_CONSTASCII_USTRINGPARAM("SourceName")); + if (!m_pBackpatcherImpl->m_pSequenceNameBackpatcher.get()) + { + m_pBackpatcherImpl->m_pSequenceNameBackpatcher.reset( + new XMLPropertyBackpatcher<OUString>(s_SourceName)); + } + return *m_pBackpatcherImpl->m_pSequenceNameBackpatcher; +} + +void XMLTextImportHelper::InsertFootnoteID( + const OUString& sXMLId, + sal_Int16 nAPIId) +{ + GetFootnoteBP().ResolveId(sXMLId, nAPIId); +} + +void XMLTextImportHelper::ProcessFootnoteReference( + const OUString& sXMLId, + const Reference<XPropertySet> & xPropSet) +{ + GetFootnoteBP().SetProperty(xPropSet, sXMLId); +} + +void XMLTextImportHelper::InsertSequenceID( + const OUString& sXMLId, + const OUString& sName, + sal_Int16 nAPIId) +{ + GetSequenceIdBP().ResolveId(sXMLId, nAPIId); + GetSequenceNameBP().ResolveId(sXMLId, sName); +} + +void XMLTextImportHelper::ProcessSequenceReference( + const OUString& sXMLId, + const Reference<XPropertySet> & xPropSet) +{ + GetSequenceIdBP().SetProperty(xPropSet, sXMLId); + GetSequenceNameBP().SetProperty(xPropSet, sXMLId); +} + diff --git a/xmloff/source/text/XMLPropertyBackpatcher.hxx b/xmloff/source/text/XMLPropertyBackpatcher.hxx new file mode 100644 index 000000000000..73b4efd0bdee --- /dev/null +++ b/xmloff/source/text/XMLPropertyBackpatcher.hxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLPROPERTYBACKPATCHER_HXX +#define _XMLOFF_XMLPROPERTYBACKPATCHER_HXX + +#ifndef __SGI_STL_MAP +#include <map> +#endif + +#ifndef __SGI_STL_VECTOR +#include <vector> +#endif +#include <comphelper/stl_types.hxx> + +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + namespace uno { template<class A> class Reference; } +} } } + + +/** This class maintains an OUString->sal_Int16 mapping for cases in + * which an XPropertySet needs to be filled with values that are not + * yet known. + * + * A good example for appropriate use are footnotes and references to + * footnoes. Internally, the StarOffice API numbers footnotes, and + * references to footnotes refer to that internal numbering. In the + * XML file format, these numbers are replaced with name strings. Now + * if during import of a document a reference to a footnote is + * encountered, two things can happen: 1) The footnote already + * appeared in the document. In this case the name is already known + * and the proper ID can be requested from the footnote. 2) The + * footnote will appear later in the document. In this case the ID is + * not yet known, and the reference-ID property of the reference + * cannot be determined. Hence, the reference has to be stored and the + * ID needs to bet set later, when the footnote is eventually found in + * the document. + * + * This class simplifies this process: If the footnote is found, + * ResolveId with the XML name and the ID is called. When a reference + * is encountered, SetProperty gets called with the reference's + * XPropertySet and the XML name. All remaining tasks are handled by + * the class. + */ +template <class A> +class XMLPropertyBackpatcher +{ + + /// name of property that gets set or backpatched + ::rtl::OUString sPropertyName; + + /// should a default value be set for unresolved properties + sal_Bool bDefaultHandling; + + /// should the sPreservePropertyName be preserved + sal_Bool bPreserveProperty; + + /// name of the property to preserve + ::rtl::OUString sPreservePropertyName; + + /// default value for unresolved properties (if bDefaultHandling) + A aDefault; + + /// backpatch list type + typedef ::std::vector< + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> > BackpatchListType; + + /* use void* instead of BackpatchListType to avoid linker problems + with long typenames. The real typename (commented out) contains + >1200 chars. */ + + /// backpatch list for unresolved IDs + //::std::map<const ::rtl::OUString, BackpatchListType*> aBackpatchListMap; + ::std::map<const ::rtl::OUString, void*, ::comphelper::UStringLess> aBackpatchListMap; + + /// mapping of names -> IDs + ::std::map<const ::rtl::OUString, A, ::comphelper::UStringLess> aIDMap; + +public: + + XMLPropertyBackpatcher( + const ::rtl::OUString& sPropertyName); + + XMLPropertyBackpatcher( + const ::rtl::OUString& sPropertyName, + const ::rtl::OUString& sPreservePropertyName, + sal_Bool bDefault, + A aDef); + + XMLPropertyBackpatcher( + const sal_Char* pPropertyName); + + XMLPropertyBackpatcher( + const sal_Char* pPropertyName, + const sal_Char* pPreservePropertyName, + sal_Bool bDefault, + A aDef); + + ~XMLPropertyBackpatcher(); + + /// resolve a known ID. + /// Call this as soon as the value for a particular name is known. + void ResolveId( + const ::rtl::OUString& sName, + A aValue); + + /// Set property with the proper value for this name. If the value + /// is not yet known, store the XPropertySet in the backpatch list. + /// Use this whenever the value should be set, even if it is not yet known. + /// const version + void SetProperty( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & xPropSet, + const ::rtl::OUString& sName); + + /// non-const version of SetProperty + void SetProperty( + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & xPropSet, + const ::rtl::OUString& sName); + + /// set default (if bDefaultHandling) for unresolved names + /// called by destructor + void SetDefault(); + +}; + +#endif diff --git a/xmloff/source/text/XMLRedlineExport.cxx b/xmloff/source/text/XMLRedlineExport.cxx new file mode 100644 index 000000000000..7dee1ba94069 --- /dev/null +++ b/xmloff/source/text/XMLRedlineExport.cxx @@ -0,0 +1,672 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLRedlineExport.hxx" +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> + +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/document/XRedlinesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmluconv.hxx> + + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::UnknownPropertyException; +using ::com::sun::star::document::XRedlinesSupplier; +using ::com::sun::star::container::XEnumerationAccess; +using ::com::sun::star::container::XEnumeration; +using ::com::sun::star::text::XText; +using ::com::sun::star::text::XTextContent; +using ::com::sun::star::text::XTextSection; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::util::DateTime; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::std::list; + + +XMLRedlineExport::XMLRedlineExport(SvXMLExport& rExp) +: sDelete(RTL_CONSTASCII_USTRINGPARAM("Delete")) +, sDeletion(GetXMLToken(XML_DELETION)) +, sFormat(RTL_CONSTASCII_USTRINGPARAM("Format")) +, sFormatChange(GetXMLToken(XML_FORMAT_CHANGE)) +, sInsert(RTL_CONSTASCII_USTRINGPARAM("Insert")) +, sInsertion(GetXMLToken(XML_INSERTION)) +, sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")) +, sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")) +, sRedlineAuthor(RTL_CONSTASCII_USTRINGPARAM("RedlineAuthor")) +, sRedlineComment(RTL_CONSTASCII_USTRINGPARAM("RedlineComment")) +, sRedlineDateTime(RTL_CONSTASCII_USTRINGPARAM("RedlineDateTime")) +, sRedlineSuccessorData(RTL_CONSTASCII_USTRINGPARAM("RedlineSuccessorData")) +, sRedlineText(RTL_CONSTASCII_USTRINGPARAM("RedlineText")) +, sRedlineType(RTL_CONSTASCII_USTRINGPARAM("RedlineType")) +, sStyle(RTL_CONSTASCII_USTRINGPARAM("Style")) +, sTextTable(RTL_CONSTASCII_USTRINGPARAM("TextTable")) +, sUnknownChange(RTL_CONSTASCII_USTRINGPARAM("UnknownChange")) +, sStartRedline(RTL_CONSTASCII_USTRINGPARAM("StartRedline")) +, sEndRedline(RTL_CONSTASCII_USTRINGPARAM("EndRedline")) +, sRedlineIdentifier(RTL_CONSTASCII_USTRINGPARAM("RedlineIdentifier")) +, sIsInHeaderFooter(RTL_CONSTASCII_USTRINGPARAM("IsInHeaderFooter")) +, sRedlineProtectionKey(RTL_CONSTASCII_USTRINGPARAM("RedlineProtectionKey")) +, sRecordChanges(RTL_CONSTASCII_USTRINGPARAM("RecordChanges")) +, sMergeLastPara(RTL_CONSTASCII_USTRINGPARAM("MergeLastPara")) +, sChangePrefix(RTL_CONSTASCII_USTRINGPARAM("ct")) +, rExport(rExp) +, pCurrentChangesList(NULL) +{ +} + + +XMLRedlineExport::~XMLRedlineExport() +{ + // delete changes lists + for( ChangesMapType::iterator aIter = aChangeMap.begin(); + aIter != aChangeMap.end(); + aIter++ ) + { + delete aIter->second; + } + aChangeMap.clear(); +} + + +void XMLRedlineExport::ExportChange( + const Reference<XPropertySet> & rPropSet, + sal_Bool bAutoStyle) +{ + if (bAutoStyle) + { + // For the headers/footers, we have to collect the autostyles + // here. For the general case, however, it's better to collet + // the autostyles by iterating over the global redline + // list. So that's what we do: Here, we collect autostyles + // only if we have no current list of changes. For the + // main-document case, the autostyles are collected in + // ExportChangesListAutoStyles(). + if (pCurrentChangesList != NULL) + ExportChangeAutoStyle(rPropSet); + } + else + { + ExportChangeInline(rPropSet); + } +} + + +void XMLRedlineExport::ExportChangesList(sal_Bool bAutoStyles) +{ + if (bAutoStyles) + { + ExportChangesListAutoStyles(); + } + else + { + ExportChangesListElements(); + } +} + + +void XMLRedlineExport::ExportChangesList( + const Reference<XText> & rText, + sal_Bool bAutoStyles) +{ + // in the header/footer case, auto styles are collected from the + // inline change elements. + if (bAutoStyles) + return; + + // look for changes list for this XText + ChangesMapType::iterator aFind = aChangeMap.find(rText); + if (aFind != aChangeMap.end()) + { + ChangesListType* pChangesList = aFind->second; + + // export only if changes are found + if (pChangesList->size() > 0) + { + // changes container element + SvXMLElementExport aChanges(rExport, XML_NAMESPACE_TEXT, + XML_TRACKED_CHANGES, + sal_True, sal_True); + + // iterate over changes list + for( ChangesListType::iterator aIter = pChangesList->begin(); + aIter != pChangesList->end(); + aIter++ ) + { + ExportChangedRegion( *aIter ); + } + } + // else: changes list empty -> ignore + } + // else: no changes list found -> empty +} + +void XMLRedlineExport::SetCurrentXText( + const Reference<XText> & rText) +{ + if (rText.is()) + { + // look for appropriate list in map; use the found one, or create new + ChangesMapType::iterator aIter = aChangeMap.find(rText); + if (aIter == aChangeMap.end()) + { + ChangesListType* pList = new ChangesListType; + aChangeMap[rText] = pList; + pCurrentChangesList = pList; + } + else + pCurrentChangesList = aIter->second; + } + else + { + // don't record changes + SetCurrentXText(); + } +} + +void XMLRedlineExport::SetCurrentXText() +{ + pCurrentChangesList = NULL; +} + + +void XMLRedlineExport::ExportChangesListElements() +{ + // get redlines (aka tracked changes) from the model + Reference<XRedlinesSupplier> xSupplier(rExport.GetModel(), uno::UNO_QUERY); + if (xSupplier.is()) + { + Reference<XEnumerationAccess> aEnumAccess = xSupplier->getRedlines(); + + // redline protection key + Reference<XPropertySet> aDocPropertySet( rExport.GetModel(), + uno::UNO_QUERY ); + // redlining enabled? + sal_Bool bEnabled = *(sal_Bool*)aDocPropertySet->getPropertyValue( + sRecordChanges ).getValue(); + + // only export if we have redlines or attributes + if ( aEnumAccess->hasElements() || bEnabled ) + { + + // export only if we have changes, but tracking is not enabled + if ( !bEnabled != !aEnumAccess->hasElements() ) + { + rExport.AddAttribute( + XML_NAMESPACE_TEXT, XML_TRACK_CHANGES, + bEnabled ? XML_TRUE : XML_FALSE ); + } + + // changes container element + SvXMLElementExport aChanges(rExport, XML_NAMESPACE_TEXT, + XML_TRACKED_CHANGES, + sal_True, sal_True); + + // get enumeration and iterate over elements + Reference<XEnumeration> aEnum = aEnumAccess->createEnumeration(); + while (aEnum->hasMoreElements()) + { + Any aAny = aEnum->nextElement(); + Reference<XPropertySet> xPropSet; + aAny >>= xPropSet; + + DBG_ASSERT(xPropSet.is(), + "can't get XPropertySet; skipping Redline"); + if (xPropSet.is()) + { + // export only if not in header or footer + // (those must be exported with their XText) + aAny = xPropSet->getPropertyValue(sIsInHeaderFooter); + if (! *(sal_Bool*)aAny.getValue()) + { + // and finally, export change + ExportChangedRegion(xPropSet); + } + } + // else: no XPropertySet -> no export + } + } + // else: no redlines -> no export + } + // else: no XRedlineSupplier -> no export +} + +void XMLRedlineExport::ExportChangeAutoStyle( + const Reference<XPropertySet> & rPropSet) +{ + // record change (if changes should be recorded) + if (NULL != pCurrentChangesList) + { + // put redline in list if it's collapsed or the redline start + Any aIsStart = rPropSet->getPropertyValue(sIsStart); + Any aIsCollapsed = rPropSet->getPropertyValue(sIsCollapsed); + + if ( *(sal_Bool*)aIsStart.getValue() || + *(sal_Bool*)aIsCollapsed.getValue() ) + pCurrentChangesList->push_back(rPropSet); + } + + // get XText for export of redline auto styles + Any aAny = rPropSet->getPropertyValue(sRedlineText); + Reference<XText> xText; + aAny >>= xText; + if (xText.is()) + { + // export the auto styles + rExport.GetTextParagraphExport()->collectTextAutoStyles(xText); + } +} + +void XMLRedlineExport::ExportChangesListAutoStyles() +{ + // get redlines (aka tracked changes) from the model + Reference<XRedlinesSupplier> xSupplier(rExport.GetModel(), uno::UNO_QUERY); + if (xSupplier.is()) + { + Reference<XEnumerationAccess> aEnumAccess = xSupplier->getRedlines(); + + // only export if we actually have redlines + if (aEnumAccess->hasElements()) + { + // get enumeration and iterate over elements + Reference<XEnumeration> aEnum = aEnumAccess->createEnumeration(); + while (aEnum->hasMoreElements()) + { + Any aAny = aEnum->nextElement(); + Reference<XPropertySet> xPropSet; + aAny >>= xPropSet; + + DBG_ASSERT(xPropSet.is(), + "can't get XPropertySet; skipping Redline"); + if (xPropSet.is()) + { + + // export only if not in header or footer + // (those must be exported with their XText) + aAny = xPropSet->getPropertyValue(sIsInHeaderFooter); + if (! *(sal_Bool*)aAny.getValue()) + { + ExportChangeAutoStyle(xPropSet); + } + } + } + } + } +} + +void XMLRedlineExport::ExportChangeInline( + const Reference<XPropertySet> & rPropSet) +{ + // determine element name (depending on collapsed, start/end) + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + Any aAny = rPropSet->getPropertyValue(sIsCollapsed); + sal_Bool bCollapsed = *(sal_Bool *)aAny.getValue(); + sal_Bool bStart = sal_True; // ignored if bCollapsed = sal_True + if (bCollapsed) + { + eElement = XML_CHANGE; + } + else + { + aAny = rPropSet->getPropertyValue(sIsStart); + bStart = *(sal_Bool *)aAny.getValue(); + eElement = bStart ? XML_CHANGE_START : XML_CHANGE_END; + } + + if (XML_TOKEN_INVALID != eElement) + { + // we always need the ID + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_CHANGE_ID, + GetRedlineID(rPropSet)); + + // export the element (no whitespace because we're in the text body) + SvXMLElementExport aChangeElem(rExport, XML_NAMESPACE_TEXT, + eElement, sal_False, sal_False); + } +} + + +void XMLRedlineExport::ExportChangedRegion( + const Reference<XPropertySet> & rPropSet) +{ + // Redline-ID + rExport.AddAttributeIdLegacy(XML_NAMESPACE_TEXT, GetRedlineID(rPropSet)); + + // merge-last-paragraph + Any aAny = rPropSet->getPropertyValue(sMergeLastPara); + if( ! *(sal_Bool*)aAny.getValue() ) + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_MERGE_LAST_PARAGRAPH, + XML_FALSE); + + // export change region element + SvXMLElementExport aChangedRegion(rExport, XML_NAMESPACE_TEXT, + XML_CHANGED_REGION, sal_True, sal_True); + + + // scope for (first) change element + { + aAny = rPropSet->getPropertyValue(sRedlineType); + OUString sType; + aAny >>= sType; + SvXMLElementExport aChange(rExport, XML_NAMESPACE_TEXT, + ConvertTypeName(sType), sal_True, sal_True); + + ExportChangeInfo(rPropSet); + + // get XText from the redline and export (if the XText exists) + aAny = rPropSet->getPropertyValue(sRedlineText); + Reference<XText> xText; + aAny >>= xText; + if (xText.is()) + { + rExport.GetTextParagraphExport()->exportText(xText); + // default parameters: bProgress, bExportParagraph ??? + } + // else: no text interface -> content is inline and will + // be exported there + } + + // changed change? Hierarchical changes can onl be two levels + // deep. Here we check for the second level. + aAny = rPropSet->getPropertyValue(sRedlineSuccessorData); + Sequence<PropertyValue> aSuccessorData; + aAny >>= aSuccessorData; + + // if we actually got a hierarchical change, make element and + // process change info + if (aSuccessorData.getLength() > 0) + { + // The only change that can be "undone" is an insertion - + // after all, you can't re-insert an deletion, but you can + // delete an insertion. This assumption is asserted in + // ExportChangeInfo(Sequence<PropertyValue>&). + SvXMLElementExport aSecondChangeElem( + rExport, XML_NAMESPACE_TEXT, XML_INSERTION, + sal_True, sal_True); + + ExportChangeInfo(aSuccessorData); + } + // else: no hierarchical change +} + + +const OUString XMLRedlineExport::ConvertTypeName( + const OUString& sApiName) +{ + if (sApiName == sDelete) + { + return sDeletion; + } + else if (sApiName == sInsert) + { + return sInsertion; + } + else if (sApiName == sFormat) + { + return sFormatChange; + } + else + { + DBG_ERROR("unknown redline type"); + return sUnknownChange; + } +} + + +/** Create a Redline-ID */ +const OUString XMLRedlineExport::GetRedlineID( + const Reference<XPropertySet> & rPropSet) +{ + Any aAny = rPropSet->getPropertyValue(sRedlineIdentifier); + OUString sTmp; + aAny >>= sTmp; + + OUStringBuffer sBuf(sChangePrefix); + sBuf.append(sTmp); + return sBuf.makeStringAndClear(); +} + + +void XMLRedlineExport::ExportChangeInfo( + const Reference<XPropertySet> & rPropSet) +{ + + SvXMLElementExport aChangeInfo(rExport, XML_NAMESPACE_OFFICE, + XML_CHANGE_INFO, sal_True, sal_True); + + Any aAny = rPropSet->getPropertyValue(sRedlineAuthor); + OUString sTmp; + aAny >>= sTmp; + if (sTmp.getLength() > 0) + { + SvXMLElementExport aCreatorElem( rExport, XML_NAMESPACE_DC, + XML_CREATOR, sal_True, + sal_False ); + rExport.Characters(sTmp); + } + + aAny = rPropSet->getPropertyValue(sRedlineDateTime); + util::DateTime aDateTime; + aAny >>= aDateTime; + { + OUStringBuffer sBuf; + rExport.GetMM100UnitConverter().convertDateTime(sBuf, aDateTime); + SvXMLElementExport aDateElem( rExport, XML_NAMESPACE_DC, + XML_DATE, sal_True, + sal_False ); + rExport.Characters(sBuf.makeStringAndClear()); + } + + // comment as <text:p> sequence + aAny = rPropSet->getPropertyValue(sRedlineComment); + aAny >>= sTmp; + WriteComment( sTmp ); +} + +void XMLRedlineExport::ExportChangeInfo( + const Sequence<PropertyValue> & rPropertyValues) +{ + OUString sComment; + + sal_Int32 nCount = rPropertyValues.getLength(); + for(sal_Int32 i = 0; i < nCount; i++) + { + const PropertyValue& rVal = rPropertyValues[i]; + + if( rVal.Name.equals(sRedlineAuthor) ) + { + OUString sTmp; + rVal.Value >>= sTmp; + if (sTmp.getLength() > 0) + { + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CHG_AUTHOR, sTmp); + } + } + else if( rVal.Name.equals(sRedlineComment) ) + { + rVal.Value >>= sComment; + } + else if( rVal.Name.equals(sRedlineDateTime) ) + { + util::DateTime aDateTime; + rVal.Value >>= aDateTime; + OUStringBuffer sBuf; + rExport.GetMM100UnitConverter().convertDateTime(sBuf, aDateTime); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CHG_DATE_TIME, + sBuf.makeStringAndClear()); + } + else if( rVal.Name.equals(sRedlineType) ) + { + // check if this is an insertion; cf. comment at calling location + OUString sTmp; + rVal.Value >>= sTmp; + DBG_ASSERT(sTmp.equals(sInsert), + "hierarchical change must be insertion"); + } + // else: unknown value -> ignore + } + + // finally write element + SvXMLElementExport aChangeInfo(rExport, XML_NAMESPACE_OFFICE, + XML_CHANGE_INFO, sal_True, sal_True); + + WriteComment( sComment ); +} + +void XMLRedlineExport::ExportStartOrEndRedline( + const Reference<XPropertySet> & rPropSet, + sal_Bool bStart) +{ + if( ! rPropSet.is() ) + return; + + // get appropriate (start or end) property + Any aAny; + try + { + aAny = rPropSet->getPropertyValue(bStart ? sStartRedline : sEndRedline); + } + catch( UnknownPropertyException e ) + { + // If we don't have the property, there's nothing to do. + return; + } + + Sequence<PropertyValue> aValues; + aAny >>= aValues; + const PropertyValue* pValues = aValues.getConstArray(); + + // seek for redline properties + sal_Bool bIsCollapsed = sal_False; + sal_Bool bIsStart = sal_True; + OUString sId; + sal_Bool bIdOK = sal_False; // have we seen an ID? + sal_Int32 nLength = aValues.getLength(); + for(sal_Int32 i = 0; i < nLength; i++) + { + if (sRedlineIdentifier.equals(pValues[i].Name)) + { + pValues[i].Value >>= sId; + bIdOK = sal_True; + } + else if (sIsCollapsed.equals(pValues[i].Name)) + { + bIsCollapsed = *(sal_Bool*)pValues[i].Value.getValue(); + } + else if (sIsStart.equals(pValues[i].Name)) + { + bIsStart = *(sal_Bool*)pValues[i].Value.getValue(); + } + } + + if( bIdOK ) + { + DBG_ASSERT( sId.getLength() > 0, "Redlines must have IDs" ); + + // TODO: use GetRedlineID or elimiate that function + OUStringBuffer sBuffer(sChangePrefix); + sBuffer.append(sId); + + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_CHANGE_ID, + sBuffer.makeStringAndClear()); + + // export the element + // (whitespace because we're not inside paragraphs) + SvXMLElementExport aChangeElem( + rExport, XML_NAMESPACE_TEXT, + bIsCollapsed ? XML_CHANGE : + ( bIsStart ? XML_CHANGE_START : XML_CHANGE_END ), + sal_True, sal_True); + } +} + +void XMLRedlineExport::ExportStartOrEndRedline( + const Reference<XTextContent> & rContent, + sal_Bool bStart) +{ + Reference<XPropertySet> xPropSet(rContent, uno::UNO_QUERY); + if (xPropSet.is()) + { + ExportStartOrEndRedline(xPropSet, bStart); + } + else + { + DBG_ERROR("XPropertySet expected"); + } +} + +void XMLRedlineExport::ExportStartOrEndRedline( + const Reference<XTextSection> & rSection, + sal_Bool bStart) +{ + Reference<XPropertySet> xPropSet(rSection, uno::UNO_QUERY); + if (xPropSet.is()) + { + ExportStartOrEndRedline(xPropSet, bStart); + } + else + { + DBG_ERROR("XPropertySet expected"); + } +} + +void XMLRedlineExport::WriteComment(const OUString& rComment) +{ + if (rComment.getLength() > 0) + { + // iterate over all string-pieces separated by return (0x0a) and + // put each inside a paragraph element. + SvXMLTokenEnumerator aEnumerator(rComment, sal_Char(0x0a)); + OUString aSubString; + while (aEnumerator.getNextToken(aSubString)) + { + SvXMLElementExport aParagraph( + rExport, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False); + rExport.Characters(aSubString); + } + } +} diff --git a/xmloff/source/text/XMLRedlineExport.hxx b/xmloff/source/text/XMLRedlineExport.hxx new file mode 100644 index 000000000000..a89683e785b3 --- /dev/null +++ b/xmloff/source/text/XMLRedlineExport.hxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLREDLINEEXPORT_HXX +#define _XMLOFF_XMLREDLINEEXPORT_HXX + +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> + +#include <list> +#include <map> +#include <set> + +class SvXMLExport; +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + namespace beans { struct PropertyValue; } + namespace text { class XText; } + namespace text { class XTextContent; } + namespace text { class XTextSection; } + } } } +namespace rtl { + class OUString; + class OUStringBuffer; +} + +// store a list of redline properties +typedef ::std::list< + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> > ChangesListType; + +// store a list of redline properties for each XText +typedef ::std::map< + ::com::sun::star::uno::Reference< ::com::sun::star::text::XText>, + ChangesListType* > ChangesMapType; + + +/** + * This class handles the export of redline portions. + * It is to be called from XMLTextParagraphExport. + */ +class XMLRedlineExport +{ + const ::rtl::OUString sDelete; + const ::rtl::OUString sDeletion; + const ::rtl::OUString sFormat; + const ::rtl::OUString sFormatChange; + const ::rtl::OUString sInsert; + const ::rtl::OUString sInsertion; + const ::rtl::OUString sIsCollapsed; + const ::rtl::OUString sIsStart; + const ::rtl::OUString sRedlineAuthor; + const ::rtl::OUString sRedlineComment; + const ::rtl::OUString sRedlineDateTime; + const ::rtl::OUString sRedlineSuccessorData; + const ::rtl::OUString sRedlineText; + const ::rtl::OUString sRedlineType; + const ::rtl::OUString sStyle; + const ::rtl::OUString sTextTable; + const ::rtl::OUString sUnknownChange; + const ::rtl::OUString sStartRedline; + const ::rtl::OUString sEndRedline; + const ::rtl::OUString sRedlineIdentifier; + const ::rtl::OUString sIsInHeaderFooter; + const ::rtl::OUString sRedlineProtectionKey; + const ::rtl::OUString sRecordChanges; + const ::rtl::OUString sMergeLastPara; + + const ::rtl::OUString sChangePrefix; + + SvXMLExport& rExport; + + + // handling of change recording: + + // To support change tracking in headers and footers we need to + // write these changes separately. To do this, we record the + // changes for headers and footers. For the main document body, we + // get the complete list of changes from the document, which + // should be much more efficient than recording all of those. + + ChangesMapType aChangeMap; /// map of recorded changes + + /// list of current changes; is NULL or points to member of aChangeMap + ChangesListType* pCurrentChangesList; + + +public: + XMLRedlineExport(SvXMLExport& rExp); + + ~XMLRedlineExport(); + + /// export a change + void ExportChange( + /// PropertySet of RedlinePortion + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_Bool bAutoStyle); + + /// export the list of changes (complete list minus recorded changed) + void ExportChangesList(sal_Bool bAutoStyles); + + /// export the list of changes (recorded changes for this XText only) + void ExportChangesList( + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XText> & rText, + sal_Bool bAutoStyles); + + /// set the current XText for which changes should be recorded. + /// An empty XText means: don't record changes + void SetCurrentXText( + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XText> & rText); + + /// Do not record changes. + /// Same as SetCurrentXText(Reference<XText>) with empty argument. + void SetCurrentXText(); + + /// export redline marks which start or end at start nodes, + /// i.e. that include the complete paragraph/table/section + void ExportStartOrEndRedline( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + sal_Bool bStart); /// start or end of text entity (e.g. paragraph)? + + /// convenience method, calls XPropertySet-version of this method + void ExportStartOrEndRedline( + /// XTextContent; must also be an XPropertySet + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextContent> & rContent, + sal_Bool bStart); + + /// convenience method, calls XPropertySet-version of this method + void ExportStartOrEndRedline( + /// XTextSection; must also be an XPropertySet + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextSection> & rSection, + sal_Bool bStart); + +private: + + /// export the change mark contained in the text body + void ExportChangeInline( + /// PropertySet of RedlinePortion + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export the auto styles used in this change + void ExportChangeAutoStyle( + /// PropertySet of RedlinePortion + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export the changes list (<text:tracked-changes>) + void ExportChangesListElements(); + + /// export the auto styles needed by the changes list + void ExportChangesListAutoStyles(); + + /// export the changed-region element + void ExportChangedRegion( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export an change-info element (from a PropertySet) + void ExportChangeInfo( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// export an change-info element (from PropertyValues) + void ExportChangeInfo( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); + + /// convert the change type from API to XML names + const ::rtl::OUString ConvertTypeName(const ::rtl::OUString& sApiName); + + /// Get ID string! + const ::rtl::OUString GetRedlineID( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet); + + /// write a comment string as sequence of <text:p> elements + void WriteComment(const ::rtl::OUString& rComment); +}; + +#endif diff --git a/xmloff/source/text/XMLSectionExport.cxx b/xmloff/source/text/XMLSectionExport.cxx new file mode 100644 index 000000000000..aee5f991b48e --- /dev/null +++ b/xmloff/source/text/XMLSectionExport.cxx @@ -0,0 +1,1930 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionExport.hxx" +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +#include <vector> + + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/PropertyValues.hpp> +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/text/SectionFileLink.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/text/BibliographyDataField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include <com/sun/star/text/ChapterFormat.hpp> //i90246 +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/families.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmltkmap.hxx> +#include "txtflde.hxx" + + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::std; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::beans::PropertyState; +using ::com::sun::star::container::XIndexReplace; +using ::com::sun::star::container::XNameAccess; +using ::com::sun::star::container::XNamed; +using ::com::sun::star::lang::XServiceInfo; +using ::com::sun::star::lang::Locale; +using ::com::sun::star::uno::XInterface; + + +XMLSectionExport::XMLSectionExport( + SvXMLExport& rExp, + XMLTextParagraphExport& rParaExp) +: sCondition(RTL_CONSTASCII_USTRINGPARAM("Condition")) +, sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM("CreateFromChapter")) +, sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromEmbeddedObjects")) +, sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromGraphicObjects")) +, sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM("CreateFromLabels")) +, sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM("CreateFromMarks")) +, sCreateFromOtherEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromOtherEmbeddedObjects")) +, sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM("CreateFromOutline")) +, sCreateFromStarCalc(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarCalc")) +, sCreateFromStarChart(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarChart")) +, sCreateFromStarDraw(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarDraw")) +, sCreateFromStarImage(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarImage")) +, sCreateFromStarMath(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarMath")) +, sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM("CreateFromTables")) +, sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM("CreateFromTextFrames")) +, sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM("DDECommandElement")) +, sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM("DDECommandFile")) +, sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM("DDECommandType")) +, sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink")) +, sIsCaseSensitive(RTL_CONSTASCII_USTRINGPARAM("IsCaseSensitive")) +, sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")) +, sIsVisible(RTL_CONSTASCII_USTRINGPARAM("IsVisible")) +, sLabelCategory(RTL_CONSTASCII_USTRINGPARAM("LabelCategory")) +, sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM("LabelDisplayType")) +, sLevel(RTL_CONSTASCII_USTRINGPARAM("Level")) +, sLevelFormat(RTL_CONSTASCII_USTRINGPARAM("LevelFormat")) +, sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM("LevelParagraphStyles")) +, sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion")) +, sMainEntryCharacterStyleName(RTL_CONSTASCII_USTRINGPARAM("MainEntryCharacterStyleName")) +, sParaStyleHeading(RTL_CONSTASCII_USTRINGPARAM("ParaStyleHeading")) +, sParaStyleLevel(RTL_CONSTASCII_USTRINGPARAM("ParaStyleLevel")) +, sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")) +, sName(RTL_CONSTASCII_USTRINGPARAM("Name")) +, sUseAlphabeticalSeparators(RTL_CONSTASCII_USTRINGPARAM("UseAlphabeticalSeparators")) +, sUseCombinedEntries(RTL_CONSTASCII_USTRINGPARAM("UseCombinedEntries")) +, sUseDash(RTL_CONSTASCII_USTRINGPARAM("UseDash")) +, sUseKeyAsEntry(RTL_CONSTASCII_USTRINGPARAM("UseKeyAsEntry")) +, sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM("UseLevelFromSource")) +, sUsePP(RTL_CONSTASCII_USTRINGPARAM("UsePP")) +, sUseUpperCase(RTL_CONSTASCII_USTRINGPARAM("UseUpperCase")) +, sIsCommaSeparated(RTL_CONSTASCII_USTRINGPARAM("IsCommaSeparated")) +, sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticUpdate")) +, sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM("IsRelativeTabstops")) +, sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM("CreateFromLevelParagraphStyles")) +, sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex")) +, sContentSection(RTL_CONSTASCII_USTRINGPARAM("ContentSection")) +, sHeaderSection(RTL_CONSTASCII_USTRINGPARAM("HeaderSection")) + +, sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection")) +, sIsGlobalDocumentSection(RTL_CONSTASCII_USTRINGPARAM("IsGlobalDocumentSection")) +, sProtectionKey(RTL_CONSTASCII_USTRINGPARAM("ProtectionKey")) +, sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")) +, sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale")) +, sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")) + +, sIsCurrentlyVisible(RTL_CONSTASCII_USTRINGPARAM("IsCurrentlyVisible")) +, sHeadingStyleName(RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName")) + +, rExport(rExp) +, rParaExport(rParaExp) +, bHeadingDummiesExported( sal_False ) +{ +} + + +void XMLSectionExport::ExportSectionStart( + const Reference<XTextSection> & rSection, + sal_Bool bAutoStyles) +{ + Reference<XPropertySet> xPropertySet(rSection, UNO_QUERY); + + // always export section (auto) style + if (bAutoStyles) + { + // get PropertySet and add section style + GetParaExport().Add( XML_STYLE_FAMILY_TEXT_SECTION, xPropertySet ); + } + else + { + // always export section style + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetParaExport().Find( + XML_STYLE_FAMILY_TEXT_SECTION, + xPropertySet, sEmpty ) ); + + // xml:id for RDF metadata + GetExport().AddAttributeXmlId(rSection); + + // export index or regular section + Reference<XDocumentIndex> xIndex; + if (GetIndex(rSection, xIndex)) + { + if (xIndex.is()) + { + // we are an index + ExportIndexStart(xIndex); + } + else + { + // we are an index header + ExportIndexHeaderStart(rSection); + } + } + else + { + // we are not an index + ExportRegularSectionStart(rSection); + } + } +} + +sal_Bool XMLSectionExport::GetIndex( + const Reference<XTextSection> & rSection, + Reference<XDocumentIndex> & rIndex) const +{ + // first, reset result + sal_Bool bRet = sal_False; + rIndex = NULL; + + // get section Properties + Reference<XPropertySet> xSectionPropSet(rSection, UNO_QUERY); + + // then check if this section happens to be inside an index + if (xSectionPropSet->getPropertySetInfo()-> + hasPropertyByName(sDocumentIndex)) + { + Any aAny = xSectionPropSet->getPropertyValue(sDocumentIndex); + Reference<XDocumentIndex> xDocumentIndex; + aAny >>= xDocumentIndex; + + // OK, are we inside of an index + if (xDocumentIndex.is()) + { + // is the enclosing index identical with "our" section? + Reference<XPropertySet> xIndexPropSet(xDocumentIndex, UNO_QUERY); + aAny = xIndexPropSet->getPropertyValue(sContentSection); + Reference<XTextSection> xEnclosingSection; + aAny >>= xEnclosingSection; + + // if the enclosing section is "our" section, then we are an index! + if (rSection == xEnclosingSection) + { + rIndex = xDocumentIndex; + bRet = sal_True; + } + // else: index header or regular section + + // is the enclosing index identical with the header section? + aAny = xIndexPropSet->getPropertyValue(sHeaderSection); + // now mis-named: contains header section + aAny >>= xEnclosingSection; + + // if the enclosing section is "our" section, then we are an index! + if (rSection == xEnclosingSection) + { + bRet = sal_True; + } + // else: regular section + } + // else: we aren't even inside of an index + } + // else: we don't even know what an index is. + + return bRet; +} + + +void XMLSectionExport::ExportSectionEnd( + const Reference<XTextSection> & rSection, + sal_Bool bAutoStyles) +{ + // no end section for styles + if (!bAutoStyles) + { + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + + // export index or regular section end + Reference<XDocumentIndex> xIndex; + if (GetIndex(rSection, xIndex)) + { + if (xIndex.is()) + { + // index end: close index body element + GetExport().EndElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY, + sal_True ); + GetExport().IgnorableWhitespace(); + + switch (MapSectionType(xIndex->getServiceName())) + { + case TEXT_SECTION_TYPE_TOC: + eElement = XML_TABLE_OF_CONTENT; + break; + + case TEXT_SECTION_TYPE_ILLUSTRATION: + eElement = XML_ILLUSTRATION_INDEX; + break; + + case TEXT_SECTION_TYPE_ALPHABETICAL: + eElement = XML_ALPHABETICAL_INDEX; + break; + + case TEXT_SECTION_TYPE_TABLE: + eElement = XML_TABLE_INDEX; + break; + + case TEXT_SECTION_TYPE_OBJECT: + eElement = XML_OBJECT_INDEX; + break; + + case TEXT_SECTION_TYPE_USER: + eElement = XML_USER_INDEX; + break; + + case TEXT_SECTION_TYPE_BIBLIOGRAPHY: + eElement = XML_BIBLIOGRAPHY; + break; + + default: + OSL_ENSURE(false, "unknown index type"); + // default: skip index! + break; + } + } + else + { + eElement = XML_INDEX_TITLE; + } + } + else + { + eElement = XML_SECTION; + } + + if (XML_TOKEN_INVALID != eElement) + { + // any old attributes? + GetExport().CheckAttrList(); + + // element surrounded by whitespace + GetExport().EndElement( XML_NAMESPACE_TEXT, eElement, sal_True); + GetExport().IgnorableWhitespace(); + } + else + { + OSL_ENSURE(false, "Need element name!"); + } + } + // else: autostyles -> ignore +} + +void XMLSectionExport::ExportIndexStart( + const Reference<XDocumentIndex> & rIndex) +{ + // get PropertySet + Reference<XPropertySet> xPropertySet(rIndex, UNO_QUERY); + + switch (MapSectionType(rIndex->getServiceName())) + { + case TEXT_SECTION_TYPE_TOC: + ExportTableOfContentStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_ILLUSTRATION: + ExportIllustrationIndexStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_ALPHABETICAL: + ExportAlphabeticalIndexStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_TABLE: + ExportTableIndexStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_OBJECT: + ExportObjectIndexStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_USER: + ExportUserIndexStart(xPropertySet); + break; + + case TEXT_SECTION_TYPE_BIBLIOGRAPHY: + ExportBibliographyStart(xPropertySet); + break; + + default: + // skip index + OSL_ENSURE(false, "unknown index type"); + break; + } +} + +void XMLSectionExport::ExportIndexHeaderStart( + const Reference<XTextSection> & rSection) +{ + // export name, dammit! + Reference<XNamed> xName(rSection, UNO_QUERY); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName()); + + // format already handled -> export only start element + GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_TITLE, sal_True ); + GetExport().IgnorableWhitespace(); +} + + +SvXMLEnumStringMapEntry __READONLY_DATA aIndexTypeMap[] = +{ + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ContentIndex", TEXT_SECTION_TYPE_TOC ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.DocumentIndex", TEXT_SECTION_TYPE_ALPHABETICAL ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.TableIndex", TEXT_SECTION_TYPE_TABLE ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ObjectIndex", TEXT_SECTION_TYPE_OBJECT ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.Bibliography", TEXT_SECTION_TYPE_BIBLIOGRAPHY ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.UserIndex", TEXT_SECTION_TYPE_USER ), + ENUM_STRING_MAP_ENTRY( "com.sun.star.text.IllustrationsIndex", TEXT_SECTION_TYPE_ILLUSTRATION ), + ENUM_STRING_MAP_END() +}; + +enum SectionTypeEnum XMLSectionExport::MapSectionType( + const OUString& rServiceName) +{ + enum SectionTypeEnum eType = TEXT_SECTION_TYPE_UNKNOWN; + + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, rServiceName, aIndexTypeMap)) + { + eType = (enum SectionTypeEnum)nTmp; + } + + // TODO: index header section types, etc. + + return eType; +} + +void XMLSectionExport::ExportRegularSectionStart( + const Reference<XTextSection> & rSection) +{ + // style name already handled in ExportSectionStart(...) + + Reference<XNamed> xName(rSection, UNO_QUERY); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName()); + + // get XPropertySet for other values + Reference<XPropertySet> xPropSet(rSection, UNO_QUERY); + Any aAny; + + // condition and display + aAny = xPropSet->getPropertyValue(sCondition); + OUString sCond; + aAny >>= sCond; + enum XMLTokenEnum eDisplay = XML_TOKEN_INVALID; + if (sCond.getLength() > 0) + { + OUString sQValue = + GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW, + sCond, sal_False ); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_CONDITION, sQValue); + eDisplay = XML_CONDITION; + + // #97450# store hidden-status (of conditional sections only) + aAny = xPropSet->getPropertyValue(sIsCurrentlyVisible); + if (! *(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_IS_HIDDEN, + XML_TRUE); + } + } + else + { + eDisplay = XML_NONE; + } + aAny = xPropSet->getPropertyValue(sIsVisible); + if (! *(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eDisplay); + } + + // protect + protection key + aAny = xPropSet->getPropertyValue(sIsProtected); + if (*(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE); + } + Sequence<sal_Int8> aPassword; + xPropSet->getPropertyValue(sProtectionKey) >>= aPassword; + if (aPassword.getLength() > 0) + { + OUStringBuffer aBuffer; + SvXMLUnitConverter::encodeBase64(aBuffer, aPassword); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY, + aBuffer.makeStringAndClear()); + } + + // export element + GetExport().IgnorableWhitespace(); + GetExport().StartElement( XML_NAMESPACE_TEXT, XML_SECTION, sal_True ); + + // data source + // unfortunately, we have to test all relevant strings for non-zero length + aAny = xPropSet->getPropertyValue(sFileLink); + SectionFileLink aFileLink; + aAny >>= aFileLink; + + aAny = xPropSet->getPropertyValue(sLinkRegion); + OUString sRegionName; + aAny >>= sRegionName; + + if ( (aFileLink.FileURL.getLength() > 0) || + (aFileLink.FilterName.getLength() > 0) || + (sRegionName.getLength() > 0) ) + { + if (aFileLink.FileURL.getLength() > 0) + { + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, + GetExport().GetRelativeReference( aFileLink.FileURL) ); + } + + if (aFileLink.FilterName.getLength() > 0) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FILTER_NAME, + aFileLink.FilterName); + } + + if (sRegionName.getLength() > 0) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_SECTION_NAME, + sRegionName); + } + + SvXMLElementExport aElem(GetExport(), + XML_NAMESPACE_TEXT, XML_SECTION_SOURCE, + sal_True, sal_True); + } + else + { + // check for DDE first + if (xPropSet->getPropertySetInfo()->hasPropertyByName(sDdeCommandFile)) + { + // data source DDE + // unfortunately, we have to test all relevant strings for + // non-zero length + aAny = xPropSet->getPropertyValue(sDdeCommandFile); + OUString sApplication; + aAny >>= sApplication; + aAny = xPropSet->getPropertyValue(sDdeCommandType); + OUString sTopic; + aAny >>= sTopic; + aAny = xPropSet->getPropertyValue(sDdeCommandElement); + OUString sItem; + aAny >>= sItem; + + if ( (sApplication.getLength() > 0) || + (sTopic.getLength() > 0) || + (sItem.getLength() > 0 ) ) + { + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, + XML_DDE_APPLICATION, sApplication); + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, + sTopic); + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM, + sItem); + + aAny = xPropSet->getPropertyValue(sIsAutomaticUpdate); + if (*(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, + XML_AUTOMATIC_UPDATE, XML_TRUE); + } + + SvXMLElementExport aElem(GetExport(), + XML_NAMESPACE_OFFICE, + XML_DDE_SOURCE, sal_True, sal_True); + } + // else: no DDE data source + } + // else: no DDE on this system + } +} + +void XMLSectionExport::ExportTableOfContentStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export TOC element start + ExportBaseIndexStart(XML_TABLE_OF_CONTENT, rPropertySet); + + // scope for table-of-content-source element + { + + Any aAny; + + // TOC specific index source attributes: + + // outline-level: 1..10 + sal_Int16 nLevel = sal_Int16(); + if( rPropertySet->getPropertyValue(sLevel) >>= nLevel ) + { + OUStringBuffer sBuffer; + SvXMLUnitConverter::convertNumber(sBuffer, (sal_Int32)nLevel); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_OUTLINE_LEVEL, + sBuffer.makeStringAndClear()); + } + + // use outline level + ExportBoolean(rPropertySet, sCreateFromOutline, + XML_USE_OUTLINE_LEVEL, sal_True); + + // use index marks + ExportBoolean(rPropertySet, sCreateFromMarks, + XML_USE_INDEX_MARKS, sal_True); + + // use level styles + ExportBoolean(rPropertySet, sCreateFromLevelParagraphStyles, + XML_USE_INDEX_SOURCE_STYLES, sal_False); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_TOC, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_TOC, rPropertySet); +} + +void XMLSectionExport::ExportObjectIndexStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export index start + ExportBaseIndexStart(XML_OBJECT_INDEX, rPropertySet); + + // scope for index source element + { + ExportBoolean(rPropertySet, sCreateFromOtherEmbeddedObjects, + XML_USE_OTHER_OBJECTS, sal_False); + ExportBoolean(rPropertySet, sCreateFromStarCalc, + XML_USE_SPREADSHEET_OBJECTS, sal_False); + ExportBoolean(rPropertySet, sCreateFromStarChart, + XML_USE_CHART_OBJECTS, sal_False); + ExportBoolean(rPropertySet, sCreateFromStarDraw, + XML_USE_DRAW_OBJECTS, sal_False); + ExportBoolean(rPropertySet, sCreateFromStarMath, + XML_USE_MATH_OBJECTS, sal_False); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_OBJECT, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_OBJECT, rPropertySet); +} + +void XMLSectionExport::ExportIllustrationIndexStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export index start + ExportBaseIndexStart(XML_ILLUSTRATION_INDEX, rPropertySet); + + // scope for index source element + { + // export common attributes for illustration and table indices + ExportTableAndIllustrationIndexSourceAttributes(rPropertySet); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet); +} + +void XMLSectionExport::ExportTableIndexStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export index start + ExportBaseIndexStart(XML_TABLE_INDEX, rPropertySet); + + // scope for index source element + { + // export common attributes for illustration and table indices + ExportTableAndIllustrationIndexSourceAttributes(rPropertySet); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_TABLE, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_TABLE, rPropertySet); +} + +void XMLSectionExport::ExportAlphabeticalIndexStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export TOC element start + ExportBaseIndexStart(XML_ALPHABETICAL_INDEX, rPropertySet); + + // scope for table-of-content-source element + { + + // style name (if present) + Any aAny; + aAny = rPropertySet->getPropertyValue(sMainEntryCharacterStyleName); + OUString sStyleName; + aAny >>= sStyleName; + if (sStyleName.getLength()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_MAIN_ENTRY_STYLE_NAME, + GetExport().EncodeStyleName( sStyleName )); + } + + // other (boolean) attributes + ExportBoolean(rPropertySet, sIsCaseSensitive, XML_IGNORE_CASE, + sal_False, sal_True); + ExportBoolean(rPropertySet, sUseAlphabeticalSeparators, + XML_ALPHABETICAL_SEPARATORS, sal_False); + ExportBoolean(rPropertySet, sUseCombinedEntries, XML_COMBINE_ENTRIES, + sal_True); + ExportBoolean(rPropertySet, sUseDash, XML_COMBINE_ENTRIES_WITH_DASH, + sal_False); + ExportBoolean(rPropertySet, sUseKeyAsEntry, XML_USE_KEYS_AS_ENTRIES, + sal_False); + ExportBoolean(rPropertySet, sUsePP, XML_COMBINE_ENTRIES_WITH_PP, + sal_True); + ExportBoolean(rPropertySet, sUseUpperCase, XML_CAPITALIZE_ENTRIES, + sal_False); + ExportBoolean(rPropertySet, sIsCommaSeparated, XML_COMMA_SEPARATED, + sal_False); + + // sort algorithm + aAny = rPropertySet->getPropertyValue(sSortAlgorithm); + OUString sAlgorithm; + aAny >>= sAlgorithm; + if (sAlgorithm.getLength() > 0) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM, + sAlgorithm ); + } + + // locale + aAny = rPropertySet->getPropertyValue(sLocale); + Locale aLocale; + aAny >>= aLocale; + GetExport().AddAttribute(XML_NAMESPACE_FO, XML_LANGUAGE, + aLocale.Language); + GetExport().AddAttribute(XML_NAMESPACE_FO, XML_COUNTRY, + aLocale.Country); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet); +} + +void XMLSectionExport::ExportUserIndexStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export TOC element start + ExportBaseIndexStart(XML_USER_INDEX, rPropertySet); + + // scope for table-of-content-source element + { + // bool attributes + ExportBoolean(rPropertySet, sCreateFromEmbeddedObjects, + XML_USE_OBJECTS, sal_False); + ExportBoolean(rPropertySet, sCreateFromGraphicObjects, + XML_USE_GRAPHICS, sal_False); + ExportBoolean(rPropertySet, sCreateFromMarks, + XML_USE_INDEX_MARKS, sal_False); + ExportBoolean(rPropertySet, sCreateFromTables, + XML_USE_TABLES, sal_False); + ExportBoolean(rPropertySet, sCreateFromTextFrames, + XML_USE_FLOATING_FRAMES, sal_False); + ExportBoolean(rPropertySet, sUseLevelFromSource, + XML_COPY_OUTLINE_LEVELS, sal_False); + ExportBoolean(rPropertySet, sCreateFromLevelParagraphStyles, + XML_USE_INDEX_SOURCE_STYLES, sal_False); + + Any aAny = rPropertySet->getPropertyValue( sUserIndexName ); + OUString sIndexName; + aAny >>= sIndexName; + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_INDEX_NAME, + sIndexName); + + ExportBaseIndexSource(TEXT_SECTION_TYPE_USER, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_USER, rPropertySet); +} + +void XMLSectionExport::ExportBibliographyStart( + const Reference<XPropertySet> & rPropertySet) +{ + // export TOC element start + ExportBaseIndexStart(XML_BIBLIOGRAPHY, rPropertySet); + + // scope for table-of-content-source element + { + // No attributes. Fine. + + ExportBaseIndexSource(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet); + } + + ExportBaseIndexBody(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet); +} + + +void XMLSectionExport::ExportBaseIndexStart( + XMLTokenEnum eElement, + const Reference<XPropertySet> & rPropertySet) +{ + // protect + protection key + Any aAny = rPropertySet->getPropertyValue(sIsProtected); + if (*(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE); + } + + // index name + OUString sIndexName; + rPropertySet->getPropertyValue(sName) >>= sIndexName; + if ( sIndexName.getLength() > 0 ) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sIndexName); + } + + // index Element start + GetExport().IgnorableWhitespace(); + GetExport().StartElement( XML_NAMESPACE_TEXT, eElement, sal_False ); +} + +static const XMLTokenEnum aTypeSourceElementNameMap[] = +{ + XML_TABLE_OF_CONTENT_SOURCE, // TOC + XML_TABLE_INDEX_SOURCE, // table index + XML_ILLUSTRATION_INDEX_SOURCE, // illustration index + XML_OBJECT_INDEX_SOURCE, // object index + XML_USER_INDEX_SOURCE, // user index + XML_ALPHABETICAL_INDEX_SOURCE, // alphabetical index + XML_BIBLIOGRAPHY_SOURCE // bibliography +}; + +void XMLSectionExport::ExportBaseIndexSource( + SectionTypeEnum eType, + const Reference<XPropertySet> & rPropertySet) +{ + // check type + OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type"); + OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type"); + + Any aAny; + + // common attributes; not supported by bibliography + if (eType != TEXT_SECTION_TYPE_BIBLIOGRAPHY) + { + // document or chapter index? + aAny = rPropertySet->getPropertyValue(sCreateFromChapter); + if (*(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_INDEX_SCOPE, XML_CHAPTER); + } + + // tab-stops relative to margin? + aAny = rPropertySet->getPropertyValue(sIsRelativeTabstops); + if (! *(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_RELATIVE_TAB_STOP_POSITION, + XML_FALSE); + } + } + + // the index source element (all indices) + SvXMLElementExport aElem(GetExport(), + XML_NAMESPACE_TEXT, + GetXMLToken( + aTypeSourceElementNameMap[ + eType - TEXT_SECTION_TYPE_TOC]), + sal_True, sal_True); + + // scope for title template (all indices) + { + // header style name + aAny = rPropertySet->getPropertyValue(sParaStyleHeading); + OUString sStyleName; + aAny >>= sStyleName; + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyleName )); + + // title template + SvXMLElementExport aHeaderTemplate(GetExport(), + XML_NAMESPACE_TEXT, + XML_INDEX_TITLE_TEMPLATE, + sal_True, sal_False); + + // title as element content + aAny = rPropertySet->getPropertyValue(sTitle); + OUString sTitleString; + aAny >>= sTitleString; + GetExport().Characters(sTitleString); + } + + // export level templates (all indices) + aAny = rPropertySet->getPropertyValue(sLevelFormat); + Reference<XIndexReplace> xLevelTemplates; + aAny >>= xLevelTemplates; + + // iterate over level formats; + // skip element 0 (empty template for title) + sal_Int32 nLevelCount = xLevelTemplates->getCount(); + for(sal_Int32 i = 1; i<nLevelCount; i++) + { + // get sequence + Sequence<PropertyValues> aTemplateSequence; + aAny = xLevelTemplates->getByIndex(i); + aAny >>= aTemplateSequence; + + // export the sequence (abort export if an error occured; #91214#) + sal_Bool bResult = + ExportIndexTemplate(eType, i, rPropertySet, aTemplateSequence); + if ( !bResult ) + break; + } + + // only TOC and user index: + // styles from which to build the index (LevelParagraphStyles) + if ( (TEXT_SECTION_TYPE_TOC == eType) || + (TEXT_SECTION_TYPE_USER == eType) ) + { + aAny = rPropertySet->getPropertyValue(sLevelParagraphStyles); + Reference<XIndexReplace> xLevelParagraphStyles; + aAny >>= xLevelParagraphStyles; + ExportLevelParagraphStyles(xLevelParagraphStyles); + } +} + + +void XMLSectionExport::ExportBaseIndexBody( + SectionTypeEnum + #if OSL_DEBUG_LEVEL > 0 + eType + #endif + , + const Reference<XPropertySet> &) +{ + // type not used; checked anyway. + OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type"); + OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type"); + + // export start only + + // any old attributes? + GetExport().CheckAttrList(); + + // start surrounded by whitespace + GetExport().IgnorableWhitespace(); + GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY, sal_True ); +} + +void XMLSectionExport::ExportTableAndIllustrationIndexSourceAttributes( + const Reference<XPropertySet> & rPropertySet) +{ + // use caption + Any aAny = rPropertySet->getPropertyValue(sCreateFromLabels); + if (! *(sal_Bool*)aAny.getValue()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_USE_CAPTION, XML_FALSE); + } + + // sequence name + aAny = rPropertySet->getPropertyValue(sLabelCategory); + OUString sSequenceName; + aAny >>= sSequenceName; + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_CAPTION_SEQUENCE_NAME, + sSequenceName); + + // caption format + aAny = rPropertySet->getPropertyValue(sLabelDisplayType); + sal_Int16 nType = 0; + aAny >>= nType; + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_CAPTION_SEQUENCE_FORMAT, + XMLTextFieldExport::MapReferenceType(nType)); +} + + +// map index of LevelFormats to attribute value; +// level 0 is always the header +static const XMLTokenEnum aLevelNameTOCMap[] = + { XML_TOKEN_INVALID, XML_1, XML_2, XML_3, XML_4, XML_5, XML_6, XML_7, + XML_8, XML_9, XML_10, XML_TOKEN_INVALID }; +static const XMLTokenEnum aLevelNameTableMap[] = + { XML_TOKEN_INVALID, XML__EMPTY, XML_TOKEN_INVALID }; +static const XMLTokenEnum aLevelNameAlphaMap[] = + { XML_TOKEN_INVALID, XML_SEPARATOR, XML_1, XML_2, XML_3, XML_TOKEN_INVALID }; +static const XMLTokenEnum aLevelNameBibliographyMap[] = + { XML_TOKEN_INVALID, XML_ARTICLE, XML_BOOK, XML_BOOKLET, XML_CONFERENCE, + XML_CUSTOM1, XML_CUSTOM2, XML_CUSTOM3, XML_CUSTOM4, + XML_CUSTOM5, XML_EMAIL, XML_INBOOK, XML_INCOLLECTION, + XML_INPROCEEDINGS, XML_JOURNAL, + XML_MANUAL, XML_MASTERSTHESIS, XML_MISC, XML_PHDTHESIS, + XML_PROCEEDINGS, XML_TECHREPORT, XML_UNPUBLISHED, XML_WWW, + XML_TOKEN_INVALID }; + +static const XMLTokenEnum* aTypeLevelNameMap[] = +{ + aLevelNameTOCMap, // TOC + aLevelNameTableMap, // table index + aLevelNameTableMap, // illustration index + aLevelNameTableMap, // object index + aLevelNameTOCMap, // user index + aLevelNameAlphaMap, // alphabetical index + aLevelNameBibliographyMap // bibliography +}; + +static const sal_Char* aLevelStylePropNameTOCMap[] = + { NULL, "ParaStyleLevel1", "ParaStyleLevel2", "ParaStyleLevel3", + "ParaStyleLevel4", "ParaStyleLevel5", "ParaStyleLevel6", + "ParaStyleLevel7", "ParaStyleLevel8", "ParaStyleLevel9", + "ParaStyleLevel10", NULL }; +static const sal_Char* aLevelStylePropNameTableMap[] = + { NULL, "ParaStyleLevel1", NULL }; +static const sal_Char* aLevelStylePropNameAlphaMap[] = + { NULL, "ParaStyleSeparator", "ParaStyleLevel1", "ParaStyleLevel2", + "ParaStyleLevel3", NULL }; +static const sal_Char* aLevelStylePropNameBibliographyMap[] = + // TODO: replace with real property names, when available + { NULL, "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1", + "ParaStyleLevel1", + NULL }; + +static const sal_Char** aTypeLevelStylePropNameMap[] = +{ + aLevelStylePropNameTOCMap, // TOC + aLevelStylePropNameTableMap, // table index + aLevelStylePropNameTableMap, // illustration index + aLevelStylePropNameTableMap, // object index + aLevelStylePropNameTOCMap, // user index + aLevelStylePropNameAlphaMap, // alphabetical index + aLevelStylePropNameBibliographyMap // bibliography +}; + +static const XMLTokenEnum aTypeLevelAttrMap[] = +{ + XML_OUTLINE_LEVEL, // TOC + XML_TOKEN_INVALID, // table index + XML_TOKEN_INVALID, // illustration index + XML_TOKEN_INVALID, // object index + XML_OUTLINE_LEVEL, // user index + XML_OUTLINE_LEVEL, // alphabetical index + XML_BIBLIOGRAPHY_TYPE // bibliography +}; + +static const XMLTokenEnum aTypeElementNameMap[] = +{ + XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE, // TOC + XML_TABLE_INDEX_ENTRY_TEMPLATE, // table index + XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE, // illustration index + XML_OBJECT_INDEX_ENTRY_TEMPLATE, // object index + XML_USER_INDEX_ENTRY_TEMPLATE, // user index + XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE, // alphabetical index + XML_BIBLIOGRAPHY_ENTRY_TEMPLATE // bibliography +}; + + +sal_Bool XMLSectionExport::ExportIndexTemplate( + SectionTypeEnum eType, + sal_Int32 nOutlineLevel, + const Reference<XPropertySet> & rPropertySet, + Sequence<Sequence<PropertyValue> > & rValues) +{ + OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type"); + OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type"); + OSL_ENSURE(nOutlineLevel >= 0, "illegal outline level"); + + if ( (eType >= TEXT_SECTION_TYPE_TOC) && + (eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY) && + (nOutlineLevel >= 0) ) + { + // get level name and level attribute name from aLevelNameMap; + const XMLTokenEnum eLevelAttrName( + aTypeLevelAttrMap[eType-TEXT_SECTION_TYPE_TOC]); + const XMLTokenEnum eLevelName( + aTypeLevelNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]); + + // #92124#: some old documents may be broken, then they have + // too many template levels; we need to recognize this and + // export only as many as is legal for the respective index + // type. To do this, we simply return an error flag, which + // will then abort further template level exports. + OSL_ENSURE(XML_TOKEN_INVALID != eLevelName, "can't find level name"); + if ( XML_TOKEN_INVALID == eLevelName ) + { + // output level not found? Then end of templates! #91214# + return sal_False; + } + + // output level name + if ((XML_TOKEN_INVALID != eLevelName) && (XML_TOKEN_INVALID != eLevelAttrName)) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + GetXMLToken(eLevelAttrName), + GetXMLToken(eLevelName)); + } + + // paragraph level style name + const sal_Char* pPropName( + aTypeLevelStylePropNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]); + OSL_ENSURE(NULL != pPropName, "can't find property name"); + if (NULL != pPropName) + { + Any aAny = rPropertySet->getPropertyValue( + OUString::createFromAscii(pPropName)); + OUString sParaStyleName; + aAny >>= sParaStyleName; + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_STYLE_NAME, + GetExport().EncodeStyleName( sParaStyleName )); + } + + // template element + const XMLTokenEnum eElementName( + aTypeElementNameMap[eType - TEXT_SECTION_TYPE_TOC]); + SvXMLElementExport aLevelTemplate(GetExport(), + XML_NAMESPACE_TEXT, + GetXMLToken(eElementName), + sal_True, sal_True); + + // export sequence + sal_Int32 nTemplateCount = rValues.getLength(); + for(sal_Int32 nTemplateNo = 0; + nTemplateNo < nTemplateCount; + nTemplateNo++) + { + ExportIndexTemplateElement( + eType, //i90246 + rValues[nTemplateNo]); + } + } + + return sal_True; +} + + +enum TemplateTypeEnum +{ + TOK_TTYPE_ENTRY_NUMBER, + TOK_TTYPE_ENTRY_TEXT, + TOK_TTYPE_TAB_STOP, + TOK_TTYPE_TEXT, + TOK_TTYPE_PAGE_NUMBER, + TOK_TTYPE_CHAPTER_INFO, + TOK_TTYPE_HYPERLINK_START, + TOK_TTYPE_HYPERLINK_END, + TOK_TTYPE_BIBLIOGRAPHY, + TOK_TTYPE_INVALID +}; + +enum TemplateParamEnum +{ + TOK_TPARAM_TOKEN_TYPE, + TOK_TPARAM_CHAR_STYLE, + TOK_TPARAM_TAB_RIGHT_ALIGNED, + TOK_TPARAM_TAB_POSITION, + TOK_TPARAM_TAB_WITH_TAB, // #i21237# + TOK_TPARAM_TAB_FILL_CHAR, + TOK_TPARAM_TEXT, + TOK_TPARAM_CHAPTER_FORMAT, + TOK_TPARAM_CHAPTER_LEVEL,//i53420 + TOK_TPARAM_BIBLIOGRAPHY_DATA +}; + +SvXMLEnumStringMapEntry __READONLY_DATA aTemplateTypeMap[] = +{ + ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER ), + ENUM_STRING_MAP_ENTRY( "TokenEntryText", TOK_TTYPE_ENTRY_TEXT ), + ENUM_STRING_MAP_ENTRY( "TokenTabStop", TOK_TTYPE_TAB_STOP ), + ENUM_STRING_MAP_ENTRY( "TokenText", TOK_TTYPE_TEXT ), + ENUM_STRING_MAP_ENTRY( "TokenPageNumber", TOK_TTYPE_PAGE_NUMBER ), + ENUM_STRING_MAP_ENTRY( "TokenChapterInfo", TOK_TTYPE_CHAPTER_INFO ), + ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START ), + ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END ), + ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY ), + ENUM_STRING_MAP_END() +}; + +SvXMLEnumStringMapEntry __READONLY_DATA aTemplateParamMap[] = +{ + ENUM_STRING_MAP_ENTRY( "TokenType", TOK_TPARAM_TOKEN_TYPE ), + ENUM_STRING_MAP_ENTRY( "CharacterStyleName", TOK_TPARAM_CHAR_STYLE ), + ENUM_STRING_MAP_ENTRY( "TabStopRightAligned", TOK_TPARAM_TAB_RIGHT_ALIGNED ), + ENUM_STRING_MAP_ENTRY( "TabStopPosition", TOK_TPARAM_TAB_POSITION ), + ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter", TOK_TPARAM_TAB_FILL_CHAR ), + // #i21237# + ENUM_STRING_MAP_ENTRY( "WithTab", TOK_TPARAM_TAB_WITH_TAB ), + ENUM_STRING_MAP_ENTRY( "Text", TOK_TPARAM_TEXT ), + ENUM_STRING_MAP_ENTRY( "ChapterFormat", TOK_TPARAM_CHAPTER_FORMAT ), + ENUM_STRING_MAP_ENTRY( "ChapterLevel", TOK_TPARAM_CHAPTER_LEVEL ),//i53420 + ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA ), + ENUM_STRING_MAP_END() +}; + +SvXMLEnumMapEntry __READONLY_DATA aBibliographyDataFieldMap[] = +{ + { XML_ADDRESS, BibliographyDataField::ADDRESS }, + { XML_ANNOTE, BibliographyDataField::ANNOTE }, + { XML_AUTHOR, BibliographyDataField::AUTHOR }, + { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE }, + { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE }, + { XML_CHAPTER, BibliographyDataField::CHAPTER }, + { XML_CUSTOM1, BibliographyDataField::CUSTOM1 }, + { XML_CUSTOM2, BibliographyDataField::CUSTOM2 }, + { XML_CUSTOM3, BibliographyDataField::CUSTOM3 }, + { XML_CUSTOM4, BibliographyDataField::CUSTOM4 }, + { XML_CUSTOM5, BibliographyDataField::CUSTOM5 }, + { XML_EDITION, BibliographyDataField::EDITION }, + { XML_EDITOR, BibliographyDataField::EDITOR }, + { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED }, + { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER }, + { XML_INSTITUTION, BibliographyDataField::INSTITUTION }, + { XML_ISBN, BibliographyDataField::ISBN }, + { XML_JOURNAL, BibliographyDataField::JOURNAL }, + { XML_MONTH, BibliographyDataField::MONTH }, + { XML_NOTE, BibliographyDataField::NOTE }, + { XML_NUMBER, BibliographyDataField::NUMBER }, + { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS }, + { XML_PAGES, BibliographyDataField::PAGES }, + { XML_PUBLISHER, BibliographyDataField::PUBLISHER }, + { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE }, + { XML_SCHOOL, BibliographyDataField::SCHOOL }, + { XML_SERIES, BibliographyDataField::SERIES }, + { XML_TITLE, BibliographyDataField::TITLE }, + { XML_URL, BibliographyDataField::URL }, + { XML_VOLUME, BibliographyDataField::VOLUME }, + { XML_YEAR, BibliographyDataField::YEAR }, + { XML_TOKEN_INVALID, 0 } +}; + +void XMLSectionExport::ExportIndexTemplateElement( + SectionTypeEnum eType, //i90246 + Sequence<PropertyValue> & rValues) +{ + // variables for template values + + // char style + OUString sCharStyle; + sal_Bool bCharStyleOK = sal_False; + + // text + OUString sText; + sal_Bool bTextOK = sal_False; + + // tab position + sal_Bool bRightAligned = sal_False; + sal_Bool bRightAlignedOK = sal_False; + + // tab position + sal_Int32 nTabPosition = 0; + sal_Bool bTabPositionOK = sal_False; + + // fill character + OUString sFillChar; + sal_Bool bFillCharOK = sal_False; + + // chapter format + sal_Int16 nChapterFormat = 0; + sal_Bool bChapterFormatOK = sal_False; + + // outline max level + sal_Int16 nLevel = 0; + sal_Bool bLevelOK = sal_False; + + // Bibliography Data + sal_Int16 nBibliographyData = 0; + sal_Bool bBibliographyDataOK = sal_False; + + // With Tab Stop #i21237# + sal_Bool bWithTabStop = sal_False; + sal_Bool bWithTabStopOK = sal_False; + + //i90246, the ODF version being written to is: + const SvtSaveOptions::ODFDefaultVersion aODFVersion = rExport.getDefaultVersion(); + //the above version cannot be used for old OOo (OOo 1.0) formats! + + // token type + enum TemplateTypeEnum nTokenType = TOK_TTYPE_INVALID; + + sal_Int32 nCount = rValues.getLength(); + for(sal_Int32 i = 0; i<nCount; i++) + { + sal_uInt16 nToken; + if ( SvXMLUnitConverter::convertEnum( nToken, rValues[i].Name, + aTemplateParamMap ) ) + { + // Only use direct and default values. + // Wrong. no property states, so ignore. + // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) || + // (beans::PropertyState_DEFAULT_VALUE == rValues[i].State) ) + + switch (nToken) + { + case TOK_TPARAM_TOKEN_TYPE: + { + sal_uInt16 nTmp; + OUString sVal; + rValues[i].Value >>= sVal; + if (SvXMLUnitConverter::convertEnum( nTmp, sVal, + aTemplateTypeMap)) + { + nTokenType = (enum TemplateTypeEnum)nTmp; + } + break; + } + + case TOK_TPARAM_CHAR_STYLE: + // only valid, if not empty + rValues[i].Value >>= sCharStyle; + bCharStyleOK = sCharStyle.getLength() > 0; + break; + + case TOK_TPARAM_TEXT: + rValues[i].Value >>= sText; + bTextOK = sal_True; + break; + + case TOK_TPARAM_TAB_RIGHT_ALIGNED: + bRightAligned = + *(sal_Bool *)rValues[i].Value.getValue(); + bRightAlignedOK = sal_True; + break; + + case TOK_TPARAM_TAB_POSITION: + rValues[i].Value >>= nTabPosition; + bTabPositionOK = sal_True; + break; + + // #i21237# + case TOK_TPARAM_TAB_WITH_TAB: + bWithTabStop = *(sal_Bool *)rValues[i].Value.getValue(); + bWithTabStopOK = sal_True; + break; + + case TOK_TPARAM_TAB_FILL_CHAR: + rValues[i].Value >>= sFillChar; + bFillCharOK = sal_True; + break; + + case TOK_TPARAM_CHAPTER_FORMAT: + rValues[i].Value >>= nChapterFormat; + bChapterFormatOK = sal_True; + break; +//---> i53420 + case TOK_TPARAM_CHAPTER_LEVEL: + rValues[i].Value >>= nLevel; + bLevelOK = sal_True; + break; +//<--- + case TOK_TPARAM_BIBLIOGRAPHY_DATA: + rValues[i].Value >>= nBibliographyData; + bBibliographyDataOK = sal_True; + break; + } + } + } + + // convert type to token (and check validity) ... + XMLTokenEnum eElement(XML_TOKEN_INVALID); + switch(nTokenType) + { + case TOK_TTYPE_ENTRY_TEXT: + eElement = XML_INDEX_ENTRY_TEXT; + break; + case TOK_TTYPE_TAB_STOP: + // test validity + if ( bRightAligned || bTabPositionOK || bFillCharOK ) + { + eElement = XML_INDEX_ENTRY_TAB_STOP; + } + break; + case TOK_TTYPE_TEXT: + // test validity + if (bTextOK) + { + eElement = XML_INDEX_ENTRY_SPAN; + } + break; + case TOK_TTYPE_PAGE_NUMBER: + eElement = XML_INDEX_ENTRY_PAGE_NUMBER; + break; + case TOK_TTYPE_CHAPTER_INFO: // keyword index + eElement = XML_INDEX_ENTRY_CHAPTER; + break; + case TOK_TTYPE_ENTRY_NUMBER: // table of content + eElement = XML_INDEX_ENTRY_CHAPTER; + break; + case TOK_TTYPE_HYPERLINK_START: + eElement = XML_INDEX_ENTRY_LINK_START; + break; + case TOK_TTYPE_HYPERLINK_END: + eElement = XML_INDEX_ENTRY_LINK_END; + break; + case TOK_TTYPE_BIBLIOGRAPHY: + if (bBibliographyDataOK) + { + eElement = XML_INDEX_ENTRY_BIBLIOGRAPHY; + } + break; + default: + ; // unknown/unimplemented template + break; + } + + //--->i90246 + //check the ODF version being exported + if( aODFVersion == SvtSaveOptions::ODFVER_011 + || aODFVersion == SvtSaveOptions::ODFVER_010) + { + bLevelOK = sal_False; + if (TOK_TTYPE_CHAPTER_INFO == nTokenType) + { + //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only + //it's not permitted in other indexes + if (eType != TEXT_SECTION_TYPE_ALPHABETICAL) + { + eElement = XML_TOKEN_INVALID; //not permitted, invalidate the element + } + else //maps format for 1.1 & 1.0 + { + // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index + // in a way different from the ODF 1.1/1.0 specification: + // + // ODF1.1/1.0 OOo display in chapter info ODF1.2 + // (used in alphabetical index only + // + // number chapter number without pre/postfix plain-number + // number-and-name chapter number without pre/postfix plus title plain-number-and-name + // + // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected + // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0 + // unfortunately if there is another application which interprets correctly ODF1.1/1.0, + // the resulting alphabetical index will be rendered wrong by OOo 2.4 version + // + switch( nChapterFormat ) + { + case ChapterFormat::DIGIT: + nChapterFormat = ChapterFormat::NUMBER; + break; + case ChapterFormat::NO_PREFIX_SUFFIX: + nChapterFormat = ChapterFormat::NAME_NUMBER; + break; + } + } + } + else if (TOK_TTYPE_ENTRY_NUMBER == nTokenType) + { + //in case of ODF 1.1 or 1.0 the only allowed number format is "number" + //so, force it... + // The only expected 'foreign' nChapterFormat is + // ' ChapterFormat::DIGIT', forced to 'none, since the + // 'value allowed in ODF 1.1 and 1.0 is 'number' the default + // this can be obtained by simply disabling the chapter format + bChapterFormatOK = sal_False; + } + } +//<--- + + // ... and write Element + if (eElement != XML_TOKEN_INVALID) + { + // character style (for most templates) + if (bCharStyleOK) + { + switch (nTokenType) + { + case TOK_TTYPE_ENTRY_TEXT: + case TOK_TTYPE_TEXT: + case TOK_TTYPE_PAGE_NUMBER: + case TOK_TTYPE_ENTRY_NUMBER: + case TOK_TTYPE_HYPERLINK_START: + case TOK_TTYPE_HYPERLINK_END: + case TOK_TTYPE_BIBLIOGRAPHY: + case TOK_TTYPE_CHAPTER_INFO: + case TOK_TTYPE_TAB_STOP: + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_STYLE_NAME, + GetExport().EncodeStyleName( sCharStyle) ); + break; + default: + ; // nothing: no character style + break; + } + } + + // tab properties + if (TOK_TTYPE_TAB_STOP == nTokenType) + { + // tab type + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_TYPE, + bRightAligned ? XML_RIGHT : XML_LEFT); + + if (bTabPositionOK && (! bRightAligned)) + { + // position for left tabs (convert to measure) + OUStringBuffer sBuf; + GetExport().GetMM100UnitConverter().convertMeasure(sBuf, + nTabPosition); + GetExport().AddAttribute(XML_NAMESPACE_STYLE, + XML_POSITION, + sBuf.makeStringAndClear()); + } + + // fill char ("leader char") + if (bFillCharOK && (sFillChar.getLength() > 0)) + { + GetExport().AddAttribute(XML_NAMESPACE_STYLE, + XML_LEADER_CHAR, sFillChar); + } + + // #i21237# + if (bWithTabStopOK && ! bWithTabStop) + { + GetExport().AddAttribute(XML_NAMESPACE_STYLE, + XML_WITH_TAB, + XML_FALSE); + } + } + + // bibliography data + if (TOK_TTYPE_BIBLIOGRAPHY == nTokenType) + { + OSL_ENSURE(bBibliographyDataOK, "need bibl data"); + OUStringBuffer sBuf; + if (SvXMLUnitConverter::convertEnum( sBuf, nBibliographyData, + aBibliographyDataFieldMap ) ) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_BIBLIOGRAPHY_DATA_FIELD, + sBuf.makeStringAndClear()); + } + } + + // chapter info + if (TOK_TTYPE_CHAPTER_INFO == nTokenType) + { + OSL_ENSURE(bChapterFormatOK, "need chapter info"); + GetExport().AddAttribute( + XML_NAMESPACE_TEXT, XML_DISPLAY, + XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat)); +//---> i53420 + if (bLevelOK) + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL, + OUString::valueOf((sal_Int32)nLevel)); +//<--- + } + +//--->i53420 + if (TOK_TTYPE_ENTRY_NUMBER == nTokenType) + { + if (bChapterFormatOK) + GetExport().AddAttribute( + XML_NAMESPACE_TEXT, XML_DISPLAY, + XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat)); + + if (bLevelOK) + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL, + OUString::valueOf((sal_Int32)nLevel)); + } +//<--- + // export template + SvXMLElementExport aTemplateElement(GetExport(), XML_NAMESPACE_TEXT, + GetXMLToken(eElement), + sal_True, sal_False) + ; + + // entry text or span element: write text + if (TOK_TTYPE_TEXT == nTokenType) + { + GetExport().Characters(sText); + } + } +} + +void XMLSectionExport::ExportLevelParagraphStyles( + Reference<XIndexReplace> & xLevelParagraphStyles) +{ + // iterate over levels + sal_Int32 nPLevelCount = xLevelParagraphStyles->getCount(); + for(sal_Int32 nLevel = 0; nLevel < nPLevelCount; nLevel++) + { + Any aAny = xLevelParagraphStyles->getByIndex(nLevel); + Sequence<OUString> aStyleNames; + aAny >>= aStyleNames; + + // export only if at least one style is contained + sal_Int32 nNamesCount = aStyleNames.getLength(); + if (nNamesCount > 0) + { + // level attribute; we count 1..10; API 0..9 + OUStringBuffer sBuf; + sal_Int32 nLevelPlusOne = nLevel + 1; + SvXMLUnitConverter::convertNumber(sBuf, nLevelPlusOne); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_OUTLINE_LEVEL, + sBuf.makeStringAndClear()); + + // source styles element + SvXMLElementExport aParaStyles(GetExport(), + XML_NAMESPACE_TEXT, + XML_INDEX_SOURCE_STYLES, + sal_True, sal_True); + + // iterate over styles in this level + for(sal_Int32 nName = 0; nName < nNamesCount; nName++) + { + // stylename attribute + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_STYLE_NAME, + GetExport().EncodeStyleName( aStyleNames[nName]) ); + + // element + SvXMLElementExport aParaStyle(GetExport(), + XML_NAMESPACE_TEXT, + XML_INDEX_SOURCE_STYLE, + sal_True, sal_False); + } + } + } +} + +void XMLSectionExport::ExportBoolean( + const Reference<XPropertySet> & rPropSet, + const OUString& sPropertyName, + enum XMLTokenEnum eAttributeName, + sal_Bool bDefault, + sal_Bool bInvert) +{ + OSL_ENSURE(eAttributeName != XML_TOKEN_INVALID, "Need attribute name"); + + Any aAny = rPropSet->getPropertyValue(sPropertyName); + sal_Bool bTmp = *(sal_Bool*)aAny.getValue(); + + // value = value ^ bInvert + // omit if value == default + // negate forces sal_Bool to 0/1, making them comparable + if ((!(bTmp ^ bInvert)) != (!bDefault)) + { + // export non-default value (since default is omitted) + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + eAttributeName, + bDefault ? XML_FALSE : XML_TRUE); + } +} + +const sal_Char sAPI_FieldMaster_Bibliography[] = + "com.sun.star.text.FieldMaster.Bibliography"; +const sal_Char sAPI_SortKey[] = "SortKey"; +const sal_Char sAPI_IsSortAscending[] = "IsSortAscending"; + +void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport& rExport) +{ + // first: get field master (via text field supplier) + Reference<XTextFieldsSupplier> xTextFieldsSupp( rExport.GetModel(), + UNO_QUERY ); + if ( xTextFieldsSupp.is() ) + { + const OUString sFieldMaster_Bibliography( + RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography)); + + // get bibliography field master + Reference<XNameAccess> xMasters = + xTextFieldsSupp->getTextFieldMasters(); + if ( xMasters->hasByName(sFieldMaster_Bibliography) ) + { + Any aAny = + xMasters->getByName(sFieldMaster_Bibliography); + Reference<XPropertySet> xPropSet; + aAny >>= xPropSet; + + OSL_ENSURE( xPropSet.is(), "field master must have XPropSet" ); + + const OUString sBracketBefore( + RTL_CONSTASCII_USTRINGPARAM("BracketBefore")); + const OUString sBracketAfter( + RTL_CONSTASCII_USTRINGPARAM("BracketAfter")); + const OUString sIsNumberEntries( + RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries")); + const OUString sIsSortByPosition( + RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition")); + const OUString sSortKeys( + RTL_CONSTASCII_USTRINGPARAM("SortKeys")); + const OUString sSortAlgorithm( + RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm")); + const OUString sLocale( + RTL_CONSTASCII_USTRINGPARAM("Locale")); + + OUString sTmp; + + aAny = xPropSet->getPropertyValue(sBracketBefore); + aAny >>= sTmp; + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_PREFIX, sTmp); + + aAny = xPropSet->getPropertyValue(sBracketAfter); + aAny >>= sTmp; + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_SUFFIX, sTmp); + + aAny = xPropSet->getPropertyValue(sIsNumberEntries); + if (*(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_NUMBERED_ENTRIES, XML_TRUE); + } + + aAny = xPropSet->getPropertyValue(sIsSortByPosition); + if (! *(sal_Bool*)aAny.getValue()) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_SORT_BY_POSITION, XML_FALSE); + } + + // sort algorithm + aAny = xPropSet->getPropertyValue(sSortAlgorithm); + OUString sAlgorithm; + aAny >>= sAlgorithm; + if( sAlgorithm.getLength() > 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_TEXT, + XML_SORT_ALGORITHM, sAlgorithm ); + } + + // locale + aAny = xPropSet->getPropertyValue(sLocale); + Locale aLocale; + aAny >>= aLocale; + rExport.AddAttribute(XML_NAMESPACE_FO, XML_LANGUAGE, + aLocale.Language); + rExport.AddAttribute(XML_NAMESPACE_FO, XML_COUNTRY, + aLocale.Country); + + // configuration element + SvXMLElementExport aElement(rExport, XML_NAMESPACE_TEXT, + XML_BIBLIOGRAPHY_CONFIGURATION, + sal_True, sal_True); + + // sort keys + aAny = xPropSet->getPropertyValue(sSortKeys); + Sequence<Sequence<PropertyValue> > aKeys; + aAny >>= aKeys; + sal_Int32 nKeysCount = aKeys.getLength(); + for(sal_Int32 nKeys = 0; nKeys < nKeysCount; nKeys++) + { + Sequence<PropertyValue> & rKey = aKeys[nKeys]; + + sal_Int32 nKeyCount = rKey.getLength(); + for(sal_Int32 nPropertyKey = 0; nPropertyKey < nKeyCount; nPropertyKey++) + { + PropertyValue& rValue = rKey[nPropertyKey]; + + if (rValue.Name.equalsAsciiL(sAPI_SortKey, + sizeof(sAPI_SortKey)-1)) + { + sal_Int16 nKey = 0; + rValue.Value >>= nKey; + OUStringBuffer sBuf; + if (SvXMLUnitConverter::convertEnum( sBuf, nKey, + aBibliographyDataFieldMap ) ) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_KEY, + sBuf.makeStringAndClear()); + } + } + else if (rValue.Name.equalsAsciiL(sAPI_IsSortAscending, + sizeof(sAPI_IsSortAscending)-1)) + { + sal_Bool bTmp = *(sal_Bool*)rValue.Value.getValue(); + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_SORT_ASCENDING, + bTmp ? XML_TRUE : XML_FALSE); + } + } + + SvXMLElementExport aKeyElem(rExport, + XML_NAMESPACE_TEXT, XML_SORT_KEY, + sal_True, sal_True); + } + } + } +} + + +sal_Bool XMLSectionExport::IsMuteSection( + const Reference<XTextSection> & rSection) const +{ + sal_Bool bRet = sal_False; + + // a section is mute if + // 1) it exists + // 2) the SaveLinkedSections flag (at the export) is false + // 3) the IsGlobalDocumentSection property is true + // 4) it is not an Index + + if ( (!rExport.IsSaveLinkedSections()) && rSection.is() ) + { + // walk the section chain and set bRet if any is linked + for(Reference<XTextSection> aSection(rSection); + aSection.is(); + aSection = aSection->getParentSection()) + { + // check if it is a global document section (linked or index) + Reference<XPropertySet> xPropSet(aSection, UNO_QUERY); + if (xPropSet.is()) + { + Any aAny = xPropSet->getPropertyValue(sIsGlobalDocumentSection); + + if ( *(sal_Bool*)aAny.getValue() ) + { + Reference<XDocumentIndex> xIndex; + if (! GetIndex(rSection, xIndex)) + { + bRet = sal_True; + + // early out if result is known + break; + } + } + } + // section has no properties: ignore + } + } + // else: no section, or always save sections: default (false) + + return bRet; +} + +sal_Bool XMLSectionExport::IsMuteSection( + const Reference<XTextContent> & rSection, + sal_Bool bDefault) const +{ + // default: like default argument + sal_Bool bRet = bDefault; + + Reference<XPropertySet> xPropSet(rSection->getAnchor(), UNO_QUERY); + if (xPropSet.is()) + { + if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection)) + { + Any aAny = xPropSet->getPropertyValue(sTextSection); + Reference<XTextSection> xSection; + aAny >>= xSection; + + bRet = IsMuteSection(xSection); + } + // else: return default + } + // else: return default + + return bRet; +} + +sal_Bool XMLSectionExport::IsInSection( + const Reference<XTextSection> & rEnclosingSection, + const Reference<XTextContent> & rContent, + sal_Bool bDefault) +{ + // default: like default argument + sal_Bool bRet = bDefault; + OSL_ENSURE(rEnclosingSection.is(), "enclosing section expected"); + + Reference<XPropertySet> xPropSet(rContent, UNO_QUERY); + if (xPropSet.is()) + { + if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection)) + { + Any aAny = xPropSet->getPropertyValue(sTextSection); + Reference<XTextSection> xSection; + aAny >>= xSection; + + // now walk chain of text sections (if we have one) + if (xSection.is()) + { + do + { + bRet = (rEnclosingSection == xSection); + xSection = xSection->getParentSection(); + } + while (!bRet && xSection.is()); + } + else + bRet = sal_False; // no section -> can't be inside + } + // else: no TextSection property -> return default + } + // else: no XPropertySet -> return default + + return bRet; +} + + +void XMLSectionExport::ExportMasterDocHeadingDummies() +{ + if( bHeadingDummiesExported ) + return; + + Reference< XChapterNumberingSupplier > xCNSupplier( rExport.GetModel(), + UNO_QUERY ); + + Reference< XIndexReplace > xChapterNumbering; + if( xCNSupplier.is() ) + xChapterNumbering = xCNSupplier->getChapterNumberingRules(); + + if( !xChapterNumbering.is() ) + return; + + sal_Int32 nCount = xChapterNumbering->getCount(); + for( sal_Int32 nLevel = 0; nLevel < nCount; nLevel++ ) + { + OUString sStyle; + Sequence<PropertyValue> aProperties; + xChapterNumbering->getByIndex( nLevel ) >>= aProperties; + for( sal_Int32 i = 0; i < aProperties.getLength(); i++ ) + { + if( aProperties[i].Name == sHeadingStyleName ) + { + aProperties[i].Value >>= sStyle; + break; + } + } + if( sStyle.getLength() > 0 ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyle ) ); + + OUStringBuffer sTmp; + sTmp.append( nLevel + 1 ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, + sTmp.makeStringAndClear() ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_H, + sal_True, sal_False ); + } + } + + bHeadingDummiesExported = sal_True; +} diff --git a/xmloff/source/text/XMLSectionExport.hxx b/xmloff/source/text/XMLSectionExport.hxx new file mode 100644 index 000000000000..0187f023e9ea --- /dev/null +++ b/xmloff/source/text/XMLSectionExport.hxx @@ -0,0 +1,366 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLSECTIONEXPORT_HXX_ +#define _XMLOFF_XMLSECTIONEXPORT_HXX_ + +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <xmloff/xmltoken.hxx> + +class SvXMLExport; +class XMLTextParagraphExport; +namespace com { namespace sun { namespace star { + namespace text + { + class XTextSection; + class XDocumentIndex; + class XTextContent; + } + namespace beans + { + class XPropertySet; + } + namespace container + { + class XIndexReplace; + } +} } } + + +enum SectionTypeEnum +{ + TEXT_SECTION_TYPE_SECTION, + + // indices: keep index valued together and do not change order, + // because they are used to index into array + TEXT_SECTION_TYPE_TOC, + TEXT_SECTION_TYPE_TABLE, + TEXT_SECTION_TYPE_ILLUSTRATION, + TEXT_SECTION_TYPE_OBJECT, + TEXT_SECTION_TYPE_USER, + TEXT_SECTION_TYPE_ALPHABETICAL, + TEXT_SECTION_TYPE_BIBLIOGRAPHY, + + // index header sections: + TEXT_SECTION_TYPE_HEADER, + + TEXT_SECTION_TYPE_UNKNOWN +}; + + +/** + * This class handles the export of sections and indices (which are, + * internally, just sections). It is intended to be used only from + * within the XMLTextParagraphExport class. + */ +class XMLSectionExport +{ + const ::rtl::OUString sCondition; + const ::rtl::OUString sCreateFromChapter; + const ::rtl::OUString sCreateFromEmbeddedObjects; + const ::rtl::OUString sCreateFromGraphicObjects; + const ::rtl::OUString sCreateFromLabels; + const ::rtl::OUString sCreateFromMarks; + const ::rtl::OUString sCreateFromOtherEmbeddedObjects; + const ::rtl::OUString sCreateFromOutline; + const ::rtl::OUString sCreateFromStarCalc; + const ::rtl::OUString sCreateFromStarChart; + const ::rtl::OUString sCreateFromStarDraw; + const ::rtl::OUString sCreateFromStarImage; + const ::rtl::OUString sCreateFromStarMath; + const ::rtl::OUString sCreateFromTables; + const ::rtl::OUString sCreateFromTextFrames; + const ::rtl::OUString sDdeCommandElement; + const ::rtl::OUString sDdeCommandFile; + const ::rtl::OUString sDdeCommandType; + const ::rtl::OUString sFileLink; + const ::rtl::OUString sIsCaseSensitive; + const ::rtl::OUString sIsProtected; + const ::rtl::OUString sIsVisible; + const ::rtl::OUString sLabelCategory; + const ::rtl::OUString sLabelDisplayType; + const ::rtl::OUString sLevel; + const ::rtl::OUString sLevelFormat; + const ::rtl::OUString sLevelParagraphStyles; + const ::rtl::OUString sLinkRegion; + const ::rtl::OUString sMainEntryCharacterStyleName; + const ::rtl::OUString sParaStyleHeading; + const ::rtl::OUString sParaStyleLevel; + const ::rtl::OUString sTitle; + const ::rtl::OUString sName; + const ::rtl::OUString sUseAlphabeticalSeparators; + const ::rtl::OUString sUseCombinedEntries; + const ::rtl::OUString sUseDash; + const ::rtl::OUString sUseKeyAsEntry; + const ::rtl::OUString sUseLevelFromSource; + const ::rtl::OUString sUsePP; + const ::rtl::OUString sUseUpperCase; + const ::rtl::OUString sIsCommaSeparated; + const ::rtl::OUString sIsAutomaticUpdate; + const ::rtl::OUString sIsRelativeTabstops; + const ::rtl::OUString sCreateFromLevelParagraphStyles; + const ::rtl::OUString sDocumentIndex; + const ::rtl::OUString sContentSection; + const ::rtl::OUString sHeaderSection; + + const ::rtl::OUString sTextSection; + const ::rtl::OUString sIsGlobalDocumentSection; + const ::rtl::OUString sProtectionKey; + const ::rtl::OUString sSortAlgorithm; + const ::rtl::OUString sLocale; + const ::rtl::OUString sUserIndexName; + + const ::rtl::OUString sIsCurrentlyVisible; + const ::rtl::OUString sHeadingStyleName; + + const ::rtl::OUString sEmpty; + + SvXMLExport& rExport; + XMLTextParagraphExport& rParaExport; + + sal_Bool bHeadingDummiesExported; + +public: + XMLSectionExport(SvXMLExport& rExp, + XMLTextParagraphExport& rParaExp); + + /** + * export section or index start and source elements. This + * method handles the section styles, and delegates to the + * appropriate section or index method. + */ + void ExportSectionStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection, + sal_Bool bAutoStyles); + + /** + * export section or index end elements + */ + void ExportSectionEnd( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection, + sal_Bool bAutoStyles); + + /** + * Should the content of this section be exported? + * (E.g. linked sections in global documents are not always exported) + */ + sal_Bool IsMuteSection( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection) const; + + /** + * XTextContent-version of IsMuteSection(Reference<XTextSection>&) + * returns *true* for all non-section elements + */ + sal_Bool IsMuteSection( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > & rSection, + /// return value if this content doesn't support the section property + sal_Bool bDefault) const; + + /** + * Determine whether rContent is contained in rEnclosingSection. If the + * current section of rContent can not be determined, return bDefault. + */ + sal_Bool IsInSection( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rEnclosingSection, + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > & rContent, + /// return value if this content doesn't support the section property + sal_Bool bDefault); + + /** + * Export the configuration element for bibliography indices. + * + * (This is part of XMLSectionExport because all section- and + * index-related items are handled here.) + */ + static void ExportBibliographyConfiguration(SvXMLExport& rExport); + + /** export a heading for every level. This is used by master documents + * to not loose the heading information if master documents are exported + * without section contents + */ + void ExportMasterDocHeadingDummies(); + + + +protected: + + inline SvXMLExport& GetExport() { return rExport; } + inline XMLTextParagraphExport& GetParaExport() { return rParaExport; } + + // export methods for section and index start: + + /// export an index start element. + void ExportIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XDocumentIndex > & rSection); + + /// export an index header start element. + void ExportIndexHeaderStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection); + + /// export a proper section (and source elements) + void ExportRegularSectionStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection); + + /// export a table of content (and source element) + void ExportTableOfContentStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export a table index (and source element) + void ExportTableIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export an object index (and source element) + void ExportObjectIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export an illustration index (and source element) + void ExportIllustrationIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export an alphabetical/keyword index (and source element) + void ExportAlphabeticalIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export a user index (and source element) + void ExportUserIndexStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export the bibliography (and source element) + void ExportBibliographyStart( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rIndex); + + // helper methods: + + /** + * If this section is an index, the index is written in the + * rIndex parameter. The return value is sal_True for all "special" + * sections. + * + * Thus we have: + * return sal_False: regular section + * return sal_True, xIndex is empty: index header section + * return sal_True, xIndex is set: index section */ + sal_Bool GetIndex( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextSection > & rSection, + ::com::sun::star::uno::Reference < + ::com::sun::star::text::XDocumentIndex > & rIndex) const; + + /// map service name to section type + enum SectionTypeEnum MapSectionType(const ::rtl::OUString& rSectionName); + + /** + * Export the index element start (for all index types). + * + * All additional attributes (usually none) for the index element + * should have been set at GetExport() before calling this method. + */ + void ExportBaseIndexStart( + ::xmloff::token::XMLTokenEnum eElement, + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /** + * Export the index source element (common for all index types). + * + * All additional attributes for the source element should have + * been set at the GetExport() before calling this method. + */ + void ExportBaseIndexSource( + SectionTypeEnum eType, /// index type + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /** + * Export the index body (common for all index types). + */ + void ExportBaseIndexBody( + SectionTypeEnum eType, /// index type + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + + /** + * Helper method to export common attributes for table and + * illustration indices + */ + void ExportTableAndIllustrationIndexSourceAttributes( + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rSection); + + /// export one template for the specific index type + sal_Bool ExportIndexTemplate( + SectionTypeEnum eType, /// index type + sal_Int32 nLevel, /// outline level (if applicable) + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> > & rValues); + + /// export a single template element (e.g. span or tab-stop) + void ExportIndexTemplateElement( + SectionTypeEnum eType, //i90246, needed for ODF 1.0, 1.0 and 1.2 management + ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue> & rValues); + + /// export level paragraph styles + void ExportLevelParagraphStyles( + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexReplace> & xStyles); + + + /// helper to export boolean properties + void ExportBoolean( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropSet, + const ::rtl::OUString& sPropertyName, + enum ::xmloff::token::XMLTokenEnum eAttributeName, + sal_Bool bDefault, + sal_Bool bInvert = sal_False); +}; + +#endif diff --git a/xmloff/source/text/XMLSectionFootnoteConfigExport.cxx b/xmloff/source/text/XMLSectionFootnoteConfigExport.cxx new file mode 100644 index 000000000000..ce702d714857 --- /dev/null +++ b/xmloff/source/text/XMLSectionFootnoteConfigExport.cxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionFootnoteConfigExport.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlprmap.hxx> +#include <com/sun/star/style/NumberingType.hpp> +#include <xmloff/maptype.hxx> + +#ifndef _XMLOFF_TXTPRMAP_HXX +#include <xmloff/txtprmap.hxx> +#endif +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnume.hxx> +#include <tools/debug.hxx> + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <rtl/ustrbuf.hxx> + +#include <vector> + + +using namespace ::xmloff::token; + +using ::std::vector; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::style::NumberingType::ARABIC; + + +void XMLSectionFootnoteConfigExport::exportXML( + SvXMLExport& rExport, + sal_Bool bEndnote, + const vector<XMLPropertyState> *pProperties, + sal_uInt32 + #ifdef DBG_UTIL + nIdx + #endif + , + const UniReference<XMLPropertySetMapper> & rMapper) +{ + // store and initialize the values + sal_Bool bNumOwn = sal_False; + sal_Bool bNumRestart = sal_False; + sal_Int16 nNumRestartAt = 0; + sal_Int16 nNumberingType = ARABIC; + OUString sNumPrefix; + OUString sNumSuffix; + sal_Bool bEnd = sal_False; + + // find entries in property states vector + sal_uInt32 nCount = pProperties->size(); + for(sal_uInt32 i = 0; i < nCount; i++) + { + const XMLPropertyState& rState = (*pProperties)[i]; + + sal_Int16 nContextId = rMapper->GetEntryContextId(rState.mnIndex); + if (!bEndnote) + { + switch (nContextId) + { + case CTF_SECTION_FOOTNOTE_NUM_OWN: + rState.maValue >>= bNumOwn; + break; + case CTF_SECTION_FOOTNOTE_NUM_RESTART: + rState.maValue >>= bNumRestart; + break; + case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT: + rState.maValue >>= nNumRestartAt; + break; + case CTF_SECTION_FOOTNOTE_NUM_TYPE: + rState.maValue >>= nNumberingType; + break; + case CTF_SECTION_FOOTNOTE_NUM_PREFIX: + rState.maValue >>= sNumPrefix; + break; + case CTF_SECTION_FOOTNOTE_NUM_SUFFIX: + rState.maValue >>= sNumSuffix; + break; + case CTF_SECTION_FOOTNOTE_END: + DBG_ASSERT( i == nIdx, + "received wrong property state index" ); + rState.maValue >>= bEnd; + break; + } + } + else + { + switch (nContextId) + { + case CTF_SECTION_ENDNOTE_NUM_OWN: + rState.maValue >>= bNumOwn; + break; + case CTF_SECTION_ENDNOTE_NUM_RESTART: + rState.maValue >>= bNumRestart; + break; + case CTF_SECTION_ENDNOTE_NUM_RESTART_AT: + rState.maValue >>= nNumRestartAt; + break; + case CTF_SECTION_ENDNOTE_NUM_TYPE: + rState.maValue >>= nNumberingType; + break; + case CTF_SECTION_ENDNOTE_NUM_PREFIX: + rState.maValue >>= sNumPrefix; + break; + case CTF_SECTION_ENDNOTE_NUM_SUFFIX: + rState.maValue >>= sNumSuffix; + break; + case CTF_SECTION_ENDNOTE_END: + DBG_ASSERT( i == nIdx, + "received wrong property state index" ); + rState.maValue >>= bEnd; + break; + } + } + } + + // we only make an element if we have an own footnote/endnote numbering + if (bEnd) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS, + GetXMLToken( bEndnote ? XML_ENDNOTE + : XML_FOOTNOTE ) ); + // start numbering + OUStringBuffer sBuf; + if (bNumRestart) + { + // restart number is stored as 0.., but interpreted as 1.. + SvXMLUnitConverter::convertNumber(sBuf, + (sal_Int32)(nNumRestartAt+1)); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE, + sBuf.makeStringAndClear()); + } + + if (bNumOwn) + { + // prefix and suffix + if (sNumPrefix.getLength() > 0) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_PREFIX, + sNumPrefix); + } + if (sNumSuffix.getLength() > 0) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, + sNumSuffix); + } + + // number type: num format + rExport.GetMM100UnitConverter().convertNumFormat( sBuf, + nNumberingType ); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT, + sBuf.makeStringAndClear()); + + // and letter sync, if applicable + rExport.GetMM100UnitConverter().convertNumLetterSync( + sBuf, nNumberingType ); + if (sBuf.getLength()) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, + XML_NUM_LETTER_SYNC, + sBuf.makeStringAndClear()); + } + } + + // and finally, the element + SvXMLElementExport rElem(rExport, XML_NAMESPACE_TEXT, + XML_NOTES_CONFIGURATION, + sal_True, sal_True); + } +} diff --git a/xmloff/source/text/XMLSectionFootnoteConfigExport.hxx b/xmloff/source/text/XMLSectionFootnoteConfigExport.hxx new file mode 100644 index 000000000000..bd0a1fcf6ea8 --- /dev/null +++ b/xmloff/source/text/XMLSectionFootnoteConfigExport.hxx @@ -0,0 +1,59 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLSECTIONFOOTNOTECONFIGEXPORT_HXX +#define _XMLOFF_XMLSECTIONFOOTNOTECONFIGEXPORT_HXX + +#include <sal/types.h> + +#include <vector> + +class SvXMLExport; +class XMLPropertySetMapper; +struct XMLPropertyState; +template<class X> class UniReference; + +/** + * Export the footnote-/endnote-configuration element in section styles. + * + * Because this class contains only one method, and all information is + * available during that method call, we simply make it static. + */ +class XMLSectionFootnoteConfigExport +{ + +public: + static void exportXML( + SvXMLExport& rExport, + sal_Bool bEndnote, + const ::std::vector<XMLPropertyState> * pProperties, + sal_uInt32 nIdx, + const UniReference<XMLPropertySetMapper> & rMapper); /// used only for debugging +}; + +#endif diff --git a/xmloff/source/text/XMLSectionFootnoteConfigImport.cxx b/xmloff/source/text/XMLSectionFootnoteConfigImport.cxx new file mode 100644 index 000000000000..24e87dfde17a --- /dev/null +++ b/xmloff/source/text/XMLSectionFootnoteConfigImport.cxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionFootnoteConfigImport.hxx" + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlprmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/maptype.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/txtprmap.hxx> +#include <tools/debug.hxx> + +#include <vector> + + +using namespace ::xmloff::token; +using namespace ::com::sun::star::style; + +using ::rtl::OUString; +using ::std::vector; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1(XMLSectionFootnoteConfigImport, SvXMLImportContext); + + +XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + vector<XMLPropertyState> & rProps, + const UniReference<XMLPropertySetMapper> & rMapperRef) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + rProperties(rProps), + rMapper(rMapperRef) +{ +} + +XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport() +{ +} + +void XMLSectionFootnoteConfigImport::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + sal_Bool bEnd = sal_True; // we're inside the element, so this is true + sal_Bool bNumOwn = sal_False; + sal_Bool bNumRestart = sal_False; + sal_Bool bEndnote = sal_False; + sal_Int16 nNumRestartAt = 0; + OUString sNumPrefix; + OUString sNumSuffix; + OUString sNumFormat; + OUString sNumLetterSync; + + // iterate over xattribute list and fill values + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + OUString sAttrValue = xAttrList->getValueByIndex(nAttr); + + if (XML_NAMESPACE_TEXT == nPrefix) + { + if (IsXMLToken(sLocalName, XML_START_VALUE)) + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue)) + { + nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1; + bNumRestart = sal_True; + } + } + else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) ) + { + if( IsXMLToken( sAttrValue, XML_ENDNOTE ) ) + bEndnote = sal_True; + } + } + else if (XML_NAMESPACE_STYLE == nPrefix) + { + if (IsXMLToken(sLocalName, XML_NUM_PREFIX)) + { + sNumPrefix = sAttrValue; + bNumOwn = sal_True; + } + else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX)) + { + sNumSuffix = sAttrValue; + bNumOwn = sal_True; + } + else if (IsXMLToken(sLocalName, XML_NUM_FORMAT)) + { + sNumFormat = sAttrValue; + bNumOwn = sal_True; + } + else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC)) + { + sNumLetterSync = sAttrValue; + bNumOwn = sal_True; + } + } + } + + // OK, now we have all values and can fill the XMLPropertyState vector + Any aAny; + + aAny.setValue( &bNumOwn, ::getBooleanCppuType() ); + sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN ); + XMLPropertyState aNumOwn( nIndex, aAny ); + rProperties.push_back( aNumOwn ); + + aAny.setValue( &bNumRestart, ::getBooleanCppuType() ); + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART ); + XMLPropertyState aNumRestart( nIndex, aAny ); + rProperties.push_back( aNumRestart ); + + aAny <<= nNumRestartAt; + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_RESTART_AT : + CTF_SECTION_FOOTNOTE_NUM_RESTART_AT ); + XMLPropertyState aNumRestartAtState( nIndex, aAny ); + rProperties.push_back( aNumRestartAtState ); + + sal_Int16 nNumType = NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumFormat, + sNumLetterSync ); + aAny <<= nNumType; + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE ); + XMLPropertyState aNumFormatState( nIndex, aAny ); + rProperties.push_back( aNumFormatState ); + + aAny <<= sNumPrefix; + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX ); + XMLPropertyState aPrefixState( nIndex, aAny ); + rProperties.push_back( aPrefixState ); + + aAny <<= sNumSuffix; + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX ); + XMLPropertyState aSuffixState( nIndex, aAny ); + rProperties.push_back( aSuffixState ); + + aAny.setValue( &bEnd, ::getBooleanCppuType() ); + nIndex = rMapper->FindEntryIndex( bEndnote ? + CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END ); + XMLPropertyState aEndState( nIndex, aAny ); + rProperties.push_back( aEndState ); +} diff --git a/xmloff/source/text/XMLSectionFootnoteConfigImport.hxx b/xmloff/source/text/XMLSectionFootnoteConfigImport.hxx new file mode 100644 index 000000000000..984414ccb845 --- /dev/null +++ b/xmloff/source/text/XMLSectionFootnoteConfigImport.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLSECTIONFOOTNOTECONFIGIMPORT_HXX +#define _XMLOFF_XMLSECTIONFOOTNOTECONFIGIMPORT_HXX + + +#include <xmloff/xmlictxt.hxx> +#include <xmloff/uniref.hxx> + +#include <vector> + + +class SvXMLImport; +struct XMLPropertyState; +class XMLPropertySetMapper; +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace uno { template<class X> class Reference; } + namespace xml { namespace sax { class XAttributeList; } } +} } } + + +/** + * Import the footnote-/endnote-configuration element in section styles. + */ +class XMLSectionFootnoteConfigImport : public SvXMLImportContext +{ + ::std::vector<XMLPropertyState> & rProperties; + UniReference<XMLPropertySetMapper> rMapper; + +public: + + TYPEINFO(); + + XMLSectionFootnoteConfigImport( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::std::vector<XMLPropertyState> & rProperties, + const UniReference<XMLPropertySetMapper> & rMapperRef); + + ~XMLSectionFootnoteConfigImport(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); + +}; + +#endif diff --git a/xmloff/source/text/XMLSectionImportContext.cxx b/xmloff/source/text/XMLSectionImportContext.cxx new file mode 100644 index 000000000000..890c55140ee4 --- /dev/null +++ b/xmloff/source/text/XMLSectionImportContext.cxx @@ -0,0 +1,406 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionImportContext.hxx" +#include "XMLSectionSourceImportContext.hxx" +#include "XMLSectionSourceDDEImportContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/prstylei.hxx> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> + + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::container::XNamed; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + + +TYPEINIT1( XMLSectionImportContext, SvXMLImportContext ); + +const sal_Char sAPI_TextSection[] = "com.sun.star.text.TextSection"; +const sal_Char sAPI_IndexHeaderSection[] = "com.sun.star.text.IndexHeaderSection"; +const sal_Char sAPI_IsProtected[] = "IsProtected"; +const sal_Char sAPI_Condition[] = "Condition"; +const sal_Char sAPI_IsVisible[] = "IsVisible"; +const sal_Char sAPI_IsCurrentlyVisible[] = "IsCurrentlyVisible"; +const sal_Char sAPI_ProtectionKey[] = "ProtectionKey"; + +enum XMLSectionToken +{ + XML_TOK_SECTION_XMLID, + XML_TOK_SECTION_STYLE_NAME, + XML_TOK_SECTION_NAME, + XML_TOK_SECTION_CONDITION, + XML_TOK_SECTION_DISPLAY, + XML_TOK_SECTION_PROTECT, + XML_TOK_SECTION_PROTECTION_KEY, + XML_TOK_SECTION_IS_HIDDEN +}; + +static __FAR_DATA SvXMLTokenMapEntry aSectionTokenMap[] = +{ + { XML_NAMESPACE_XML , XML_ID, XML_TOK_SECTION_XMLID }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_SECTION_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_NAME, XML_TOK_SECTION_NAME }, + { XML_NAMESPACE_TEXT, XML_CONDITION, XML_TOK_SECTION_CONDITION }, + { XML_NAMESPACE_TEXT, XML_DISPLAY, XML_TOK_SECTION_DISPLAY }, + { XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TOK_SECTION_PROTECT }, + { XML_NAMESPACE_TEXT, XML_PROTECTION_KEY, XML_TOK_SECTION_PROTECTION_KEY}, + { XML_NAMESPACE_TEXT, XML_IS_HIDDEN, XML_TOK_SECTION_IS_HIDDEN }, + // compatibility with SRC629 (or earlier) versions + { XML_NAMESPACE_TEXT, XML_PROTECT, XML_TOK_SECTION_PROTECT }, + XML_TOKEN_MAP_END +}; + + +// section import: This one is fairly tricky due to a variety of +// limits of the core or the API. The main problem is that if you +// insert a section within another section, you can't move the cursor +// between the ends of the inner and the enclosing section. To avoid +// these problems, additional markers are first inserted and later deleted. +XMLSectionImportContext::XMLSectionImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName ) +: SvXMLImportContext(rImport, nPrfx, rLocalName) +, sTextSection(RTL_CONSTASCII_USTRINGPARAM(sAPI_TextSection)) +, sIndexHeaderSection(RTL_CONSTASCII_USTRINGPARAM(sAPI_IndexHeaderSection)) +, sCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_Condition)) +, sIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsVisible)) +, sProtectionKey(RTL_CONSTASCII_USTRINGPARAM(sAPI_ProtectionKey)) +, sIsProtected(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsProtected)) +, sIsCurrentlyVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsCurrentlyVisible)) +, bProtect(sal_False) +, bCondOK(sal_False) +, bIsVisible(sal_True) +, bValid(sal_False) +, bSequenceOK(sal_False) +, bIsCurrentlyVisible(sal_True) +, bIsCurrentlyVisibleOK(sal_False) +, bHasContent(sal_False) +{ +} + +XMLSectionImportContext::~XMLSectionImportContext() +{ +} + +void XMLSectionImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // process attributes + ProcessAttributes(xAttrList); + + // process index headers: + sal_Bool bIsIndexHeader = IsXMLToken( GetLocalName(), XML_INDEX_TITLE ); + if (bIsIndexHeader) + { + bValid = sal_True; + } + + UniReference<XMLTextImportHelper> rHelper = GetImport().GetTextImport(); + + // valid? + if (bValid) + { + // create text section (as XPropertySet) + Reference<XMultiServiceFactory> xFactory( + GetImport().GetModel(),UNO_QUERY); + if (xFactory.is()) + { + Reference<XInterface> xIfc = + xFactory->createInstance( bIsIndexHeader ? sIndexHeaderSection + : sTextSection ); + if (xIfc.is()) + { + Reference<XPropertySet> xPropSet(xIfc, UNO_QUERY); + + // save PropertySet (for CreateChildContext) + xSectionPropertySet = xPropSet; + + // name + Reference<XNamed> xNamed(xPropSet, UNO_QUERY); + xNamed->setName(sName); + + // stylename? + if (sStyleName.getLength() > 0) + { + XMLPropStyleContext* pStyle = rHelper-> + FindSectionStyle(sStyleName); + + if (pStyle != NULL) + { + pStyle->FillPropertySet( xPropSet ); + } + } + + // IsVisible and condition (not for index headers) + if (! bIsIndexHeader) + { + Any aAny; + aAny.setValue( &bIsVisible, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsVisible, aAny ); + + // #97450# hidden sections must be hidden on reload + // For backwards compatibilty, set flag only if it is + // present + if( bIsCurrentlyVisibleOK ) + { + aAny.setValue( &bIsCurrentlyVisible, + ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsCurrentlyVisible, aAny); + } + + if (bCondOK) + { + aAny <<= sCond; + xPropSet->setPropertyValue( sCondition, aAny ); + } + } + + // password (only for regular sections) + if ( bSequenceOK && + IsXMLToken(GetLocalName(), XML_SECTION) ) + { + Any aAny; + aAny <<= aSequence; + xPropSet->setPropertyValue(sProtectionKey, aAny); + } + + // protection + Any aAny; + aAny.setValue( &bProtect, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsProtected, aAny ); + + // insert marker, <paragraph>, marker; then insert + // section over the first marker character, and delete the + // last paragraph (and marker) when closing a section. + Reference<XTextRange> xStart = + rHelper->GetCursor()->getStart(); +#ifndef DBG_UTIL + static const sal_Char sMarker[] = " "; +#else + static const sal_Char sMarker[] = "X"; +#endif + OUString sMarkerString(RTL_CONSTASCII_USTRINGPARAM(sMarker)); + rHelper->InsertString(sMarkerString); + rHelper->InsertControlCharacter( + ControlCharacter::APPEND_PARAGRAPH ); + rHelper->InsertString(sMarkerString); + + // select first marker + rHelper->GetCursor()->gotoRange(xStart, sal_False); + rHelper->GetCursor()->goRight(1, sal_True); + + // convert section to XTextContent + Reference<XTextContent> xTextContent(xSectionPropertySet, + UNO_QUERY); + + // and insert (over marker) + rHelper->GetText()->insertTextContent( + rHelper->GetCursorAsRange(), xTextContent, sal_True ); + + // and delete first marker (in section) + rHelper->GetText()->insertString( + rHelper->GetCursorAsRange(), sEmpty, sal_True); + + // finally, check for redlines that should start at + // the section start node + rHelper->RedlineAdjustStartNodeCursor(sal_True); // start ??? + + // xml:id for RDF metadata + GetImport().SetXmlId(xIfc, sXmlId); + } + } + } +} + +void XMLSectionImportContext::ProcessAttributes( + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLTokenMap aTokenMap(aSectionTokenMap); + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nNamePrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + OUString sAttr = xAttrList->getValueByIndex(nAttr); + + switch (aTokenMap.Get(nNamePrefix, sLocalName)) + { + case XML_TOK_SECTION_XMLID: + sXmlId = sAttr; + break; + case XML_TOK_SECTION_STYLE_NAME: + sStyleName = sAttr; + break; + case XML_TOK_SECTION_NAME: + sName = sAttr; + bValid = sal_True; + break; + case XML_TOK_SECTION_CONDITION: + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + _GetKeyByAttrName( sAttr, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sCond = sTmp; + bCondOK = sal_True; + } + else + sCond = sAttr; + } + break; + case XML_TOK_SECTION_DISPLAY: + if (IsXMLToken(sAttr, XML_TRUE)) + { + bIsVisible = sal_True; + } + else if ( IsXMLToken(sAttr, XML_NONE) || + IsXMLToken(sAttr, XML_CONDITION) ) + { + bIsVisible = sal_False; + } + // else: ignore + break; + case XML_TOK_SECTION_IS_HIDDEN: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttr)) + { + bIsCurrentlyVisible = !bTmp; + bIsCurrentlyVisibleOK = sal_True; + } + } + break; + case XML_TOK_SECTION_PROTECTION_KEY: + SvXMLUnitConverter::decodeBase64(aSequence, sAttr); + bSequenceOK = sal_True; + break; + case XML_TOK_SECTION_PROTECT: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttr)) + { + bProtect = bTmp; + } + break; + } + default: + ; // ignore + break; + } + } +} + +void XMLSectionImportContext::EndElement() +{ + // get rid of last paragraph + // (unless it's the only paragraph in the section) + UniReference<XMLTextImportHelper> rHelper = GetImport().GetTextImport(); + rHelper->GetCursor()->goRight(1, sal_False); + if (bHasContent) + { + rHelper->GetCursor()->goLeft(1, sal_True); + rHelper->GetText()->insertString(rHelper->GetCursorAsRange(), + sEmpty, sal_True); + } + + // and delete second marker + rHelper->GetCursor()->goRight(1, sal_True); + rHelper->GetText()->insertString(rHelper->GetCursorAsRange(), + sEmpty, sal_True); + + // check for redlines to our endnode + rHelper->RedlineAdjustStartNodeCursor(sal_False); +} + +SvXMLImportContext* XMLSectionImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + // section-source (-dde) elements + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken(rLocalName, XML_SECTION_SOURCE) ) + { + pContext = new XMLSectionSourceImportContext(GetImport(), + nPrefix, rLocalName, + xSectionPropertySet); + } + else if ( (XML_NAMESPACE_OFFICE == nPrefix) && + IsXMLToken(rLocalName, XML_DDE_SOURCE) ) + { + pContext = new XMLSectionSourceDDEImportContext(GetImport(), + nPrefix, rLocalName, + xSectionPropertySet); + } + else + { + // otherwise: text context + pContext = GetImport().GetTextImport()->CreateTextChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + XML_TEXT_TYPE_SECTION ); + + // if that fails, default context + if (NULL == pContext) + { + pContext = new SvXMLImportContext( GetImport(), + nPrefix, rLocalName ); + } + else + bHasContent = sal_True; + } + + return pContext; +} + diff --git a/xmloff/source/text/XMLSectionImportContext.hxx b/xmloff/source/text/XMLSectionImportContext.hxx new file mode 100644 index 000000000000..313cf60b9ef1 --- /dev/null +++ b/xmloff/source/text/XMLSectionImportContext.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLSECTIONIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLSECTIONIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> + +namespace com { namespace sun { namespace star { + namespace text { class XTextRange; } + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } +class XMLTextImportHelper; + + +/** + * Import text sections. + * + * This context may *also* be used for index header sections. The + * differentiates its behaviour based on GetLocalName(). + */ +class XMLSectionImportContext : public SvXMLImportContext +{ + /// start position; ranges aquired via getStart(),getEnd() don't move + ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange> xStartRange; + + /// end position + ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange> xEndRange; + + /// TextSection (as XPropertySet) for passing down to data source elements + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> xSectionPropertySet; + + const ::rtl::OUString sTextSection; + const ::rtl::OUString sIndexHeaderSection; + const ::rtl::OUString sCondition; + const ::rtl::OUString sIsVisible; + const ::rtl::OUString sProtectionKey; + const ::rtl::OUString sIsProtected; + const ::rtl::OUString sIsCurrentlyVisible; + const ::rtl::OUString sEmpty; + + ::rtl::OUString sXmlId; + ::rtl::OUString sStyleName; + ::rtl::OUString sName; + ::rtl::OUString sCond; + ::com::sun::star::uno::Sequence<sal_Int8> aSequence; + sal_Bool bProtect; + sal_Bool bCondOK; + sal_Bool bIsVisible; + sal_Bool bValid; + sal_Bool bSequenceOK; + sal_Bool bIsCurrentlyVisible; + sal_Bool bIsCurrentlyVisibleOK; + + sal_Bool bHasContent; + +public: + + TYPEINFO(); + + XMLSectionImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + ~XMLSectionImportContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); + + void ProcessAttributes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx b/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx new file mode 100644 index 000000000000..25f456a5d584 --- /dev/null +++ b/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionSourceDDEImportContext.hxx" +#include "XMLSectionImportContext.hxx" +#include <com/sun/star/text/SectionFileLink.hpp> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <tools/debug.hxx> + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::XMultiPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +const sal_Char sAPI_DDECommandFile[] = "DDECommandFile"; +const sal_Char sAPI_DDECommandType[] = "DDECommandType"; +const sal_Char sAPI_DDECommandElement[] = "DDECommandElement"; +const sal_Char sAPI_IsAutomaticUpdate[] = "IsAutomaticUpdate"; + + +TYPEINIT1(XMLSectionSourceDDEImportContext, SvXMLImportContext); + +XMLSectionSourceDDEImportContext::XMLSectionSourceDDEImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rSectPropSet) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + rSectionPropertySet(rSectPropSet), + sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandFile)), + sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandType)), + sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_DDECommandElement)), + sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsAutomaticUpdate)) +{ +} + +XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext() +{ +} + +enum XMLSectionSourceDDEToken +{ + XML_TOK_SECTION_DDE_APPLICATION, + XML_TOK_SECTION_DDE_TOPIC, + XML_TOK_SECTION_DDE_ITEM, + XML_TOK_SECTION_IS_AUTOMATIC_UPDATE +}; + +static __FAR_DATA SvXMLTokenMapEntry aSectionSourceDDETokenMap[] = +{ + { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, + XML_TOK_SECTION_DDE_APPLICATION }, + { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_SECTION_DDE_TOPIC }, + { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_SECTION_DDE_ITEM }, + { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, + XML_TOK_SECTION_IS_AUTOMATIC_UPDATE }, + XML_TOKEN_MAP_END +}; + + +void XMLSectionSourceDDEImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + SvXMLTokenMap aTokenMap(aSectionSourceDDETokenMap); + OUString sApplication; + OUString sTopic; + OUString sItem; + sal_Bool bAutomaticUpdate = sal_False; + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + switch (aTokenMap.Get(nPrefix, sLocalName)) + { + case XML_TOK_SECTION_DDE_APPLICATION: + sApplication = xAttrList->getValueByIndex(nAttr); + break; + case XML_TOK_SECTION_DDE_TOPIC: + sTopic = xAttrList->getValueByIndex(nAttr); + break; + case XML_TOK_SECTION_DDE_ITEM: + sItem = xAttrList->getValueByIndex(nAttr); + break; + case XML_TOK_SECTION_IS_AUTOMATIC_UPDATE: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool( + bTmp, xAttrList->getValueByIndex(nAttr))) + { + bAutomaticUpdate = bTmp; + } + break; + } + default: + ; // ignore + break; + } + } + + // DDE not supported on all platforms; query property first + if (rSectionPropertySet->getPropertySetInfo()-> + hasPropertyByName(sDdeCommandFile)) + { + // use multi property set to force single update of connection #83654# + Sequence<OUString> aNames(4); + Sequence<Any> aValues(4); + + aValues[0] <<= sApplication; + aNames[0] = sDdeCommandFile; + + aValues[1] <<= sTopic; + aNames[1] = sDdeCommandType; + + aValues[2] <<= sItem; + aNames[2] = sDdeCommandElement; + + aValues[3].setValue(&bAutomaticUpdate, ::getBooleanCppuType()); + aNames[3] = sIsAutomaticUpdate; + + Reference<XMultiPropertySet> rMultiPropSet(rSectionPropertySet, + UNO_QUERY); + DBG_ASSERT(rMultiPropSet.is(), "we'd really like a XMultiPropertySet"); + if (rMultiPropSet.is()) + rMultiPropSet->setPropertyValues(aNames, aValues); + // else: ignore + } +} + +void XMLSectionSourceDDEImportContext::EndElement() +{ + // nothing to be done! +} + +SvXMLImportContext* XMLSectionSourceDDEImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & ) +{ + // ignore -> default context + return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); +} diff --git a/xmloff/source/text/XMLSectionSourceDDEImportContext.hxx b/xmloff/source/text/XMLSectionSourceDDEImportContext.hxx new file mode 100644 index 000000000000..89fd0e47248a --- /dev/null +++ b/xmloff/source/text/XMLSectionSourceDDEImportContext.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLSECTIONSOURCEDDEIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLSECTIONSOURCEDDEIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } + +class XMLSectionSourceDDEImportContext : public SvXMLImportContext +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rSectionPropertySet; + + const ::rtl::OUString sDdeCommandFile; + const ::rtl::OUString sDdeCommandType; + const ::rtl::OUString sDdeCommandElement; + const ::rtl::OUString sIsAutomaticUpdate; + +public: + + TYPEINFO(); + + XMLSectionSourceDDEImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rSectPropSet); + + ~XMLSectionSourceDDEImportContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLSectionSourceImportContext.cxx b/xmloff/source/text/XMLSectionSourceImportContext.cxx new file mode 100644 index 000000000000..7c2023228c2b --- /dev/null +++ b/xmloff/source/text/XMLSectionSourceImportContext.cxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLSectionSourceImportContext.hxx" +#include "XMLSectionImportContext.hxx" +#include <com/sun/star/text/SectionFileLink.hpp> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/beans/XPropertySet.hpp> + + +using ::rtl::OUString; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + + +TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext); + +XMLSectionSourceImportContext::XMLSectionSourceImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLocalName, + Reference<XPropertySet> & rSectPropSet) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + rSectionPropertySet(rSectPropSet) +{ +} + +XMLSectionSourceImportContext::~XMLSectionSourceImportContext() +{ +} + +enum XMLSectionSourceToken +{ + XML_TOK_SECTION_XLINK_HREF, + XML_TOK_SECTION_TEXT_FILTER_NAME, + XML_TOK_SECTION_TEXT_SECTION_NAME +}; + +static __FAR_DATA SvXMLTokenMapEntry aSectionSourceTokenMap[] = +{ + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF }, + { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME }, + { XML_NAMESPACE_TEXT, XML_SECTION_NAME, + XML_TOK_SECTION_TEXT_SECTION_NAME }, + XML_TOKEN_MAP_END +}; + + +void XMLSectionSourceImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + SvXMLTokenMap aTokenMap(aSectionSourceTokenMap); + OUString sURL; + OUString sFilterName; + OUString sSectionName; + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + switch (aTokenMap.Get(nPrefix, sLocalName)) + { + case XML_TOK_SECTION_XLINK_HREF: + sURL = xAttrList->getValueByIndex(nAttr); + break; + + case XML_TOK_SECTION_TEXT_FILTER_NAME: + sFilterName = xAttrList->getValueByIndex(nAttr); + break; + + case XML_TOK_SECTION_TEXT_SECTION_NAME: + sSectionName = xAttrList->getValueByIndex(nAttr); + break; + + default: + ; // ignore + break; + } + } + + // we only need them once + const OUString sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink")); + const OUString sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion")); + + Any aAny; + if ((sURL.getLength() > 0) || (sFilterName.getLength() > 0)) + { + SectionFileLink aFileLink; + aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL ); + aFileLink.FilterName = sFilterName; + + aAny <<= aFileLink; + rSectionPropertySet->setPropertyValue(sFileLink, aAny); + } + + if (sSectionName.getLength() > 0) + { + aAny <<= sSectionName; + rSectionPropertySet->setPropertyValue(sLinkRegion, aAny); + } +} + +void XMLSectionSourceImportContext::EndElement() +{ + // this space intentionally left blank. +} + +SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & ) +{ + // ignore -> default context + return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); +} diff --git a/xmloff/source/text/XMLSectionSourceImportContext.hxx b/xmloff/source/text/XMLSectionSourceImportContext.hxx new file mode 100644 index 000000000000..dc4ebc934c15 --- /dev/null +++ b/xmloff/source/text/XMLSectionSourceImportContext.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLSECTIONSOURCEIMPORTCONTEXT_HXX_ +#define _XMLOFF_XMLSECTIONSOURCEIMPORTCONTEXT_HXX_ + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } +namespace rtl { class OUString; } + +class XMLSectionSourceImportContext : public SvXMLImportContext +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rSectionPropertySet; + +public: + + TYPEINFO(); + + XMLSectionSourceImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rSectPropSet); + + ~XMLSectionSourceImportContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif diff --git a/xmloff/source/text/XMLStringBufferImportContext.cxx b/xmloff/source/text/XMLStringBufferImportContext.cxx new file mode 100644 index 000000000000..2d9df7ef1ef1 --- /dev/null +++ b/xmloff/source/text/XMLStringBufferImportContext.cxx @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLStringBufferImportContext.hxx" +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_P; + + +TYPEINIT1(XMLStringBufferImportContext, SvXMLImportContext); + +XMLStringBufferImportContext::XMLStringBufferImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& sLocalName, + OUStringBuffer& rBuffer) : + SvXMLImportContext(rImport, nPrefix, sLocalName), + rTextBuffer(rBuffer) +{ +} + +XMLStringBufferImportContext::~XMLStringBufferImportContext() +{ +} + +SvXMLImportContext *XMLStringBufferImportContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> &) +{ + return new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, rTextBuffer); +} + +void XMLStringBufferImportContext::Characters( + const OUString& rChars ) +{ + rTextBuffer.append(rChars); +} + +void XMLStringBufferImportContext::EndElement() +{ + // add return for paragraph elements + if ( (XML_NAMESPACE_TEXT == GetPrefix()) && + (IsXMLToken(GetLocalName(), XML_P)) ) + { + rTextBuffer.append(sal_Unicode(0x0a)); + } +} + diff --git a/xmloff/source/text/XMLTextCharStyleNamesElementExport.cxx b/xmloff/source/text/XMLTextCharStyleNamesElementExport.cxx new file mode 100644 index 000000000000..e4ed313d70de --- /dev/null +++ b/xmloff/source/text/XMLTextCharStyleNamesElementExport.cxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLTextCharStyleNamesElementExport.hxx" +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> + +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } +} } } + +using namespace ::com::sun::star::uno; +using ::com::sun::star::beans::XPropertySet; +using ::rtl::OUString; +using namespace ::xmloff::token; + +XMLTextCharStyleNamesElementExport::XMLTextCharStyleNamesElementExport( + SvXMLExport& rExp, + sal_Bool bDoSth, + sal_Bool bAllStyles, + const Reference < XPropertySet > & rPropSet, + const OUString& rPropName ) : + rExport( rExp ), + nCount( 0 ) +{ + if( bDoSth ) + { + Any aAny = rPropSet->getPropertyValue( rPropName ); + Sequence < OUString > aNames; + if( aAny >>= aNames ) + { + nCount = aNames.getLength(); + OSL_ENSURE( nCount > 0, "no char style found" ); + if ( bAllStyles ) ++nCount; + if( nCount > 1 ) + { + aName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN) ); + sal_Int32 i = nCount; + const OUString *pName = aNames.getConstArray(); + while( --i ) + { + rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + rExport.EncodeStyleName( *pName ) ); + rExport.StartElement( aName, sal_False ); + ++pName; + } + } + } + } +} + +XMLTextCharStyleNamesElementExport::~XMLTextCharStyleNamesElementExport() +{ + if( nCount > 1 ) + { + sal_Int32 i = nCount; + while( --i ) + rExport.EndElement( aName, sal_False ); + } +} + diff --git a/xmloff/source/text/XMLTextCharStyleNamesElementExport.hxx b/xmloff/source/text/XMLTextCharStyleNamesElementExport.hxx new file mode 100644 index 000000000000..41e6d61a4ed1 --- /dev/null +++ b/xmloff/source/text/XMLTextCharStyleNamesElementExport.hxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_XMLTEXTCHARSTYLENAMESELEMENTEXPORT_HXX +#define _XMLOFF_XMLTEXTCHARSTYLENAMESELEMENTEXPORT_HXX + +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.hxx> + + +namespace com { namespace sun { namespace star { + namespace beans { class XPropertySet; } +} } } + +class SvXMLExport; + +class XMLTextCharStyleNamesElementExport +{ + SvXMLExport& rExport; + ::rtl::OUString aName; + sal_Int32 nCount; + +public: + + XMLTextCharStyleNamesElementExport( + SvXMLExport& rExp, sal_Bool bDoSomething, sal_Bool bAllStyles, + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > & rPropSet, + const ::rtl::OUString& rPropName ); + ~XMLTextCharStyleNamesElementExport(); +}; + +#endif diff --git a/xmloff/source/text/XMLTextColumnsContext.cxx b/xmloff/source/text/XMLTextColumnsContext.cxx new file mode 100644 index 000000000000..48175ae33e4f --- /dev/null +++ b/xmloff/source/text/XMLTextColumnsContext.cxx @@ -0,0 +1,503 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/text/XTextColumns.hpp> +#include <com/sun/star/text/TextColumn.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <xmloff/xmltkmap.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include "XMLTextColumnsContext.hxx" +#define _SVSTDARR_USHORTS +#include <svl/svstdarr.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_COLUMN_WIDTH, + XML_TOK_COLUMN_MARGIN_LEFT, + XML_TOK_COLUMN_MARGIN_RIGHT, + XML_TOK_COLUMN_END=XML_TOK_UNKNOWN +}; + +enum SvXMLSepTokenMapAttrs +{ + XML_TOK_COLUMN_SEP_WIDTH, + XML_TOK_COLUMN_SEP_HEIGHT, + XML_TOK_COLUMN_SEP_COLOR, + XML_TOK_COLUMN_SEP_ALIGN, + XML_TOK_COLUMN_SEP_END=XML_TOK_UNKNOWN +}; + +static __FAR_DATA SvXMLTokenMapEntry aColAttrTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_REL_WIDTH, XML_TOK_COLUMN_WIDTH }, + { XML_NAMESPACE_FO, XML_START_INDENT, XML_TOK_COLUMN_MARGIN_LEFT }, + { XML_NAMESPACE_FO, XML_END_INDENT, XML_TOK_COLUMN_MARGIN_RIGHT }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aColSepAttrTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_WIDTH, XML_TOK_COLUMN_SEP_WIDTH }, + { XML_NAMESPACE_STYLE, XML_COLOR, XML_TOK_COLUMN_SEP_COLOR }, + { XML_NAMESPACE_STYLE, XML_HEIGHT, XML_TOK_COLUMN_SEP_HEIGHT }, + { XML_NAMESPACE_STYLE, XML_VERTICAL_ALIGN, XML_TOK_COLUMN_SEP_ALIGN }, + XML_TOKEN_MAP_END +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_Sep_Align_Enum[] = +{ + { XML_TOP, VerticalAlignment_TOP }, + { XML_MIDDLE, VerticalAlignment_MIDDLE }, + { XML_BOTTOM, VerticalAlignment_BOTTOM }, + { XML_TOKEN_INVALID, 0 } +}; + +class XMLTextColumnContext_Impl: public SvXMLImportContext +{ + text::TextColumn aColumn; + +public: + TYPEINFO(); + + XMLTextColumnContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< + xml::sax::XAttributeList > & xAttrList, + const SvXMLTokenMap& rTokenMap ); + + virtual ~XMLTextColumnContext_Impl(); + + text::TextColumn& getTextColumn() { return aColumn; } +}; + +TYPEINIT1( XMLTextColumnContext_Impl, SvXMLImportContext ); + +XMLTextColumnContext_Impl::XMLTextColumnContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< + xml::sax::XAttributeList > & xAttrList, + const SvXMLTokenMap& rTokenMap ) : + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + aColumn.Width = 0; + aColumn.LeftMargin = 0; + aColumn.RightMargin = 0; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nVal; + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_COLUMN_WIDTH: + { + sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'*' ); + if( nPos != -1 && nPos+1 == rValue.getLength() ) + { + OUString sTmp( rValue.copy( 0, nPos ) ); + if( GetImport().GetMM100UnitConverter(). + convertNumber( nVal, sTmp, 0, USHRT_MAX ) ) + aColumn.Width = nVal; + } + } + break; + case XML_TOK_COLUMN_MARGIN_LEFT: + if( GetImport().GetMM100UnitConverter(). + convertMeasure( nVal, rValue ) ) + aColumn.LeftMargin = nVal; + break; + case XML_TOK_COLUMN_MARGIN_RIGHT: + + if( GetImport().GetMM100UnitConverter(). + convertMeasure( nVal, rValue ) ) + aColumn.RightMargin = nVal; + break; + default: + break; + } + } +} + +XMLTextColumnContext_Impl::~XMLTextColumnContext_Impl() +{ +} + +// -------------------------------------------------------------------------- + +class XMLTextColumnSepContext_Impl: public SvXMLImportContext +{ + sal_Int32 nWidth; + sal_Int32 nColor; + sal_Int8 nHeight; + VerticalAlignment eVertAlign; + + +public: + TYPEINFO(); + + XMLTextColumnSepContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< + xml::sax::XAttributeList > & xAttrList, + const SvXMLTokenMap& rTokenMap ); + + virtual ~XMLTextColumnSepContext_Impl(); + + sal_Int32 GetWidth() const { return nWidth; } + sal_Int32 GetColor() const { return nColor; } + sal_Int8 GetHeight() const { return nHeight; } + VerticalAlignment GetVertAlign() const { return eVertAlign; } +}; + + +TYPEINIT1( XMLTextColumnSepContext_Impl, SvXMLImportContext ); + +XMLTextColumnSepContext_Impl::XMLTextColumnSepContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< + xml::sax::XAttributeList > & xAttrList, + const SvXMLTokenMap& rTokenMap ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + nWidth( 2 ), + nColor( 0 ), + nHeight( 100 ), + eVertAlign( VerticalAlignment_TOP ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nVal; + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_COLUMN_SEP_WIDTH: + if( GetImport().GetMM100UnitConverter(). + convertMeasure( nVal, rValue ) ) + nWidth = nVal; + break; + case XML_TOK_COLUMN_SEP_HEIGHT: + if( GetImport().GetMM100UnitConverter(). + convertPercent( nVal, rValue ) && + nVal >=1 && nVal <= 100 ) + nHeight = (sal_Int8)nVal; + break; + case XML_TOK_COLUMN_SEP_COLOR: + { + Color aColor; + if( GetImport().GetMM100UnitConverter(). + convertColor( aColor, rValue ) ) + nColor = (sal_Int32)aColor.GetColor(); + } + break; + case XML_TOK_COLUMN_SEP_ALIGN: + { + sal_uInt16 nAlign; + if( GetImport().GetMM100UnitConverter(). + convertEnum( nAlign, rValue, + pXML_Sep_Align_Enum ) ) + eVertAlign = (VerticalAlignment)nAlign; + } + break; + } + } +} + +XMLTextColumnSepContext_Impl::~XMLTextColumnSepContext_Impl() +{ +} + +// -------------------------------------------------------------------------- + +typedef XMLTextColumnContext_Impl *XMLTextColumnContext_ImplPtr; +SV_DECL_PTRARR( XMLTextColumnsArray_Impl, XMLTextColumnContext_ImplPtr, 5, 5 ) + +TYPEINIT1( XMLTextColumnsContext, XMLElementPropertyContext ); + +XMLTextColumnsContext::XMLTextColumnsContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList >& + xAttrList, + const XMLPropertyState& rProp, + ::std::vector< XMLPropertyState > &rProps ) +: XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ) +, sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")) +, sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")) +, sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")) +, sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")) +, sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")) +, sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")) +, sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance")) +, pColumns( 0 ) +, pColumnSep( 0 ) +, pColumnAttrTokenMap( new SvXMLTokenMap(aColAttrTokenMap) ) +, pColumnSepAttrTokenMap( new SvXMLTokenMap(aColSepAttrTokenMap) ) +, nCount( 0 ) +, bAutomatic( sal_False ) +, nAutomaticDistance( 0 ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + sal_Int32 nVal; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + if( XML_NAMESPACE_FO == nPrefix ) + { + if( IsXMLToken( aLocalName, XML_COLUMN_COUNT ) && + GetImport().GetMM100UnitConverter(). + convertNumber( nVal, rValue, 0, SHRT_MAX ) ) + { + nCount = (sal_Int16)nVal; + } + else if( IsXMLToken( aLocalName, XML_COLUMN_GAP ) ) + { + bAutomatic = GetImport().GetMM100UnitConverter(). + convertMeasure( nAutomaticDistance, rValue ); + } + } + } +} + +XMLTextColumnsContext::~XMLTextColumnsContext() +{ + if( pColumns ) + { + sal_uInt16 nColCount = pColumns->Count(); + while( nColCount ) + { + nColCount--; + XMLTextColumnContext_Impl *pColumn = (*pColumns)[nColCount]; + pColumns->Remove( nColCount, 1 ); + pColumn->ReleaseRef(); + } + } + if( pColumnSep ) + pColumnSep->ReleaseRef(); + + delete pColumns; + delete pColumnAttrTokenMap; + delete pColumnSepAttrTokenMap; +} + +SvXMLImportContext *XMLTextColumnsContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( rLocalName, XML_COLUMN ) ) + { + XMLTextColumnContext_Impl *pColumn = + new XMLTextColumnContext_Impl( GetImport(), nPrefix, rLocalName, + xAttrList, *pColumnAttrTokenMap ); + + // add new tabstop to array of tabstops + if( !pColumns ) + pColumns = new XMLTextColumnsArray_Impl; + + pColumns->Insert( pColumn, pColumns->Count() ); + pColumn->AddRef(); + + pContext = pColumn; + } + else if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( rLocalName, XML_COLUMN_SEP ) ) + { + pColumnSep = + new XMLTextColumnSepContext_Impl( GetImport(), nPrefix, rLocalName, + xAttrList, *pColumnSepAttrTokenMap ); + pColumnSep->AddRef(); + + pContext = pColumnSep; + } + else + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +void XMLTextColumnsContext::EndElement( ) +{ + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY); + if( !xFactory.is() ) + return; + + Reference<XInterface> xIfc = xFactory->createInstance( + OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextColumns"))); + if( !xIfc.is() ) + return; + + Reference< XTextColumns > xColumns( xIfc, UNO_QUERY ); + if ( 0 == nCount ) + { + // zero columns = no columns -> 1 column + xColumns->setColumnCount( 1 ); + } + else if( !bAutomatic && pColumns && + pColumns->Count() == (sal_uInt16)nCount ) + { + // if we have column descriptions, one per column, and we don't use + // automatic width, then set the column widths + + sal_Int32 nRelWidth = 0; + sal_uInt16 nColumnsWithWidth = 0; + sal_Int16 i; + + for( i = 0; i < nCount; i++ ) + { + const TextColumn& rColumn = + (*pColumns)[(sal_uInt16)i]->getTextColumn(); + if( rColumn.Width > 0 ) + { + nRelWidth += rColumn.Width; + nColumnsWithWidth++; + } + } + if( nColumnsWithWidth < nCount ) + { + sal_Int32 nColWidth = 0==nRelWidth + ? USHRT_MAX / nCount + : nRelWidth / nColumnsWithWidth; + + for( i=0; i < nCount; i++ ) + { + TextColumn& rColumn = + (*pColumns)[(sal_uInt16)i]->getTextColumn(); + if( rColumn.Width == 0 ) + { + rColumn.Width = nColWidth; + nRelWidth += rColumn.Width; + if( 0 == --nColumnsWithWidth ) + break; + } + } + } + + Sequence< TextColumn > aColumns( (sal_Int32)nCount ); + TextColumn *pTextColumns = aColumns.getArray(); + for( i=0; i < nCount; i++ ) + *pTextColumns++ = (*pColumns)[(sal_uInt16)i]->getTextColumn(); + + xColumns->setColumns( aColumns ); + } + else + { + // only set column count (and let the columns be distributed + // automatically) + + xColumns->setColumnCount( nCount ); + } + + Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY ); + if( xPropSet.is() ) + { + Any aAny; + sal_Bool bOn = pColumnSep != 0; + + aAny.setValue( &bOn, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sSeparatorLineIsOn, aAny ); + + if( pColumnSep ) + { + if( pColumnSep->GetWidth() ) + { + aAny <<= pColumnSep->GetWidth(); + xPropSet->setPropertyValue( sSeparatorLineWidth, aAny ); + } + if( pColumnSep->GetHeight() ) + { + aAny <<= pColumnSep->GetHeight(); + xPropSet->setPropertyValue( sSeparatorLineRelativeHeight, + aAny ); + } + + + aAny <<= pColumnSep->GetColor(); + xPropSet->setPropertyValue( sSeparatorLineColor, aAny ); + + + aAny <<= pColumnSep->GetVertAlign(); + xPropSet->setPropertyValue( sSeparatorLineVerticalAlignment, aAny ); + } + + // handle 'automatic columns': column distance + if( bAutomatic ) + { + aAny <<= nAutomaticDistance; + xPropSet->setPropertyValue( sAutomaticDistance, aAny ); + } + } + + aProp.maValue <<= xColumns; + + SetInsert( sal_True ); + XMLElementPropertyContext::EndElement(); + +} diff --git a/xmloff/source/text/XMLTextColumnsExport.cxx b/xmloff/source/text/XMLTextColumnsExport.cxx new file mode 100644 index 000000000000..695bdf47578f --- /dev/null +++ b/xmloff/source/text/XMLTextColumnsExport.cxx @@ -0,0 +1,189 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> + + +#include <com/sun/star/text/XTextColumns.hpp> +#include <com/sun/star/text/TextColumn.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + + +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlexp.hxx> +#include "XMLTextColumnsExport.hxx" + +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using namespace ::xmloff::token; + + +XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) : + rExport( rExp ), + sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")), + sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")), + sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")), + sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")), + sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")), + sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")), + sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance")) +{ +} + +void XMLTextColumnsExport::exportXML( const Any& rAny ) +{ + Reference < XTextColumns > xColumns; + rAny >>= xColumns; + + Sequence < TextColumn > aColumns = xColumns->getColumns(); + const TextColumn *pColumns = aColumns.getArray(); + sal_Int32 nCount = aColumns.getLength(); + + OUStringBuffer sValue; + GetExport().GetMM100UnitConverter().convertNumber( sValue, nCount ? nCount : 1 ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT, + sValue.makeStringAndClear() ); + + // handle 'automatic' columns + Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY ); + if( xPropSet.is() ) + { + Any aAny = xPropSet->getPropertyValue( sIsAutomatic ); + if ( *(sal_Bool*)aAny.getValue() ) + { + aAny = xPropSet->getPropertyValue( sAutomaticDistance ); + sal_Int32 nDistance = 0; + aAny >>= nDistance; + OUStringBuffer aBuffer; + GetExport().GetMM100UnitConverter().convertMeasure( + aBuffer, nDistance ); + GetExport().AddAttribute( XML_NAMESPACE_FO, + XML_COLUMN_GAP, + aBuffer.makeStringAndClear() ); + } + } + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS, + sal_True, sal_True ); + + if( xPropSet.is() ) + { + Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn ); + if( *(sal_Bool *)aAny.getValue() ) + { + // style:width + aAny = xPropSet->getPropertyValue( sSeparatorLineWidth ); + sal_Int32 nWidth = 0; + aAny >>= nWidth; + GetExport().GetMM100UnitConverter().convertMeasure( sValue, + nWidth ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH, + sValue.makeStringAndClear() ); + + // style:color + aAny = xPropSet->getPropertyValue( sSeparatorLineColor ); + sal_Int32 nColor = 0; + aAny >>= nColor; + GetExport().GetMM100UnitConverter().convertColor( sValue, + nColor ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR, + sValue.makeStringAndClear() ); + + // style:height + aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight ); + sal_Int8 nHeight = 0; + aAny >>= nHeight; + GetExport().GetMM100UnitConverter().convertPercent( sValue, + nHeight ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT, + sValue.makeStringAndClear() ); + + // style:vertical-align + aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment ); + VerticalAlignment eVertAlign; + aAny >>= eVertAlign; + + enum XMLTokenEnum eStr = XML_TOKEN_INVALID; + switch( eVertAlign ) + { +// case VerticalAlignment_TOP: eStr = XML_TOP; + case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break; + case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break; + default: + break; + } + + if( eStr != XML_TOKEN_INVALID) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_VERTICAL_ALIGN, eStr ); + + // style:column-sep + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, + XML_COLUMN_SEP, + sal_True, sal_True ); + } + } + + while( nCount-- ) + { + // style:rel-width + GetExport().GetMM100UnitConverter().convertNumber( sValue, + pColumns->Width ); + sValue.append( (sal_Unicode)'*' ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH, + sValue.makeStringAndClear() ); + + // fo:margin-left + GetExport().GetMM100UnitConverter().convertMeasure( sValue, + pColumns->LeftMargin ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT, + sValue.makeStringAndClear() ); + + // fo:margin-right + GetExport().GetMM100UnitConverter().convertMeasure( sValue, + pColumns->RightMargin ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT, + sValue.makeStringAndClear() ); + + // style:column + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN, + sal_True, sal_True ); + pColumns++; + } +} + + diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx new file mode 100644 index 000000000000..3216c6f05618 --- /dev/null +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -0,0 +1,1681 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "XMLAnchorTypePropHdl.hxx" +#include "XMLEmbeddedObjectImportContext.hxx" +#include <xmloff/XMLBase64ImportContext.hxx> +#include "XMLReplacementImageContext.hxx" +#include <xmloff/prstylei.hxx> +#include "xmloff/i18nmap.hxx" +#include "xexptran.hxx" +#include <xmloff/shapeimport.hxx> +#include <xmloff/XMLEventsImportContext.hxx> +#include "XMLImageMapContext.hxx" +#include "XMLTextFrameContext.hxx" + +#include "XMLTextListBlockContext.hxx" +#include "XMLTextListItemContext.hxx" +#include <xmloff/attrlist.hxx> +#include <comphelper/stl_types.hxx> + +#include <map> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::document; +using namespace ::xmloff::token; +using ::com::sun::star::document::XEventsSupplier; + +#define XML_TEXT_FRAME_TEXTBOX 1 +#define XML_TEXT_FRAME_GRAPHIC 2 +#define XML_TEXT_FRAME_OBJECT 3 +#define XML_TEXT_FRAME_OBJECT_OLE 4 +#define XML_TEXT_FRAME_APPLET 5 +#define XML_TEXT_FRAME_PLUGIN 6 +#define XML_TEXT_FRAME_FLOATING_FRAME 7 + +typedef ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess> ParamMap; + +class XMLTextFrameContextHyperlink_Impl +{ + OUString sHRef; + OUString sName; + OUString sTargetFrameName; + sal_Bool bMap; + +public: + + inline XMLTextFrameContextHyperlink_Impl( const OUString& rHRef, + const OUString& rName, + const OUString& rTargetFrameName, + sal_Bool bMap ); + + const OUString& GetHRef() const { return sHRef; } + const OUString& GetName() const { return sName; } + const OUString& GetTargetFrameName() const { return sTargetFrameName; } + sal_Bool GetMap() const { return bMap; } +}; + +inline XMLTextFrameContextHyperlink_Impl::XMLTextFrameContextHyperlink_Impl( + const OUString& rHRef, const OUString& rName, + const OUString& rTargetFrameName, sal_Bool bM ) : + sHRef( rHRef ), + sName( rName ), + sTargetFrameName( rTargetFrameName ), + bMap( bM ) +{ +} + +// --> OD 2009-07-22 #i73249# +class XMLTextFrameTitleOrDescContext_Impl : public SvXMLImportContext +{ + OUString& mrTitleOrDesc; + +public: + + TYPEINFO(); + + XMLTextFrameTitleOrDescContext_Impl( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + OUString& rTitleOrDesc ); + virtual ~XMLTextFrameTitleOrDescContext_Impl(); + + virtual void Characters( const OUString& rText ); +}; + +TYPEINIT1( XMLTextFrameTitleOrDescContext_Impl, SvXMLImportContext ); + +XMLTextFrameTitleOrDescContext_Impl::XMLTextFrameTitleOrDescContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + OUString& rTitleOrDesc ) + : SvXMLImportContext( rImport, nPrfx, rLName ) + , mrTitleOrDesc( rTitleOrDesc ) +{ +} + +XMLTextFrameTitleOrDescContext_Impl::~XMLTextFrameTitleOrDescContext_Impl() +{ +} + +void XMLTextFrameTitleOrDescContext_Impl::Characters( const OUString& rText ) +{ + mrTitleOrDesc += rText; +} +// <-- + +// ------------------------------------------------------------------------ + +class XMLTextFrameParam_Impl : public SvXMLImportContext +{ +public: + + TYPEINFO(); + + XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + sal_uInt16 nType, + ParamMap &rParamMap); + virtual ~XMLTextFrameParam_Impl(); +}; + +TYPEINIT1( XMLTextFrameParam_Impl, SvXMLImportContext ); + +XMLTextFrameParam_Impl::~XMLTextFrameParam_Impl() +{ +} + +XMLTextFrameParam_Impl::XMLTextFrameParam_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + sal_uInt16 /*nType*/, + ParamMap &rParamMap): + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + OUString sName, sValue; + sal_Bool bFoundValue = sal_False; // to allow empty values + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); + if ( XML_NAMESPACE_DRAW == nPrefix ) + { + if( IsXMLToken(aLocalName, XML_VALUE) ) + { + sValue = rValue; + bFoundValue=sal_True; + } + else if( IsXMLToken(aLocalName, XML_NAME) ) + { + sName = rValue; + } + } + } + if (sName.getLength() && bFoundValue ) + rParamMap[sName] = sValue; +} +class XMLTextFrameContourContext_Impl : public SvXMLImportContext +{ + Reference < XPropertySet > xPropSet; + +public: + + TYPEINFO(); + + XMLTextFrameContourContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const Reference < XPropertySet >& rPropSet, + sal_Bool bPath ); + virtual ~XMLTextFrameContourContext_Impl(); +}; + +TYPEINIT1( XMLTextFrameContourContext_Impl, SvXMLImportContext ); + +XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + const Reference < XPropertySet >& rPropSet, + sal_Bool bPath ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + xPropSet( rPropSet ) +{ + OUString sD, sPoints, sViewBox; + sal_Bool bPixelWidth = sal_False, bPixelHeight = sal_False; + sal_Bool bAuto = sal_False; + sal_Int32 nWidth = 0; + sal_Int32 nHeight = 0; + + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextContourAttrTokenMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_CONTOUR_VIEWBOX: + sViewBox = rValue; + break; + case XML_TOK_TEXT_CONTOUR_D: + if( bPath ) + sD = rValue; + break; + case XML_TOK_TEXT_CONTOUR_POINTS: + if( !bPath ) + sPoints = rValue; + break; + case XML_TOK_TEXT_CONTOUR_WIDTH: + if( GetImport().GetMM100UnitConverter().convertMeasurePx( nWidth, + rValue) ) + bPixelWidth = sal_True; + else + GetImport().GetMM100UnitConverter().convertMeasure( nWidth, + rValue); + break; + case XML_TOK_TEXT_CONTOUR_HEIGHT: + if( GetImport().GetMM100UnitConverter().convertMeasurePx( nHeight, + rValue) ) + bPixelHeight = sal_True; + else + GetImport().GetMM100UnitConverter().convertMeasure( nHeight, + rValue); + break; + case XML_TOK_TEXT_CONTOUR_AUTO: + bAuto = IsXMLToken(rValue, XML_TRUE); + break; + } + } + + OUString sContourPolyPolygon( + RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon") ); + Reference < XPropertySetInfo > xPropSetInfo = + rPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( + sContourPolyPolygon ) && + nWidth > 0 && nHeight > 0 && bPixelWidth == bPixelHeight && + (bPath ? sD : sPoints).getLength() ) + { + awt::Point aPoint( 0, 0 ); + awt::Size aSize( nWidth, nHeight ); + SdXMLImExViewBox aViewBox( sViewBox, + GetImport().GetMM100UnitConverter()); + Any aAny; + if( bPath ) + { + SdXMLImExSvgDElement aPoints( sD, aViewBox, aPoint, aSize, + GetImport().GetMM100UnitConverter() ); + aAny <<= aPoints.GetPointSequenceSequence(); + } + else + { + SdXMLImExPointsElement aPoints( sPoints, aViewBox, aPoint, aSize, + GetImport().GetMM100UnitConverter() ); + aAny <<= aPoints.GetPointSequenceSequence(); + } + + OUString sIsPixelContour( + RTL_CONSTASCII_USTRINGPARAM("IsPixelContour") ); + xPropSet->setPropertyValue( sContourPolyPolygon, aAny ); + + if( xPropSetInfo->hasPropertyByName( sIsPixelContour ) ) + { + aAny.setValue( &bPixelWidth, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsPixelContour, aAny ); + } + + OUString sIsAutomaticContour( + RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour") ); + if( xPropSetInfo->hasPropertyByName( sIsAutomaticContour ) ) + { + aAny.setValue( &bAuto, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsAutomaticContour, aAny ); + } + } +} + +XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl() +{ +} + +// ------------------------------------------------------------------------ + +class XMLTextFrameContext_Impl : public SvXMLImportContext +{ + ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextCursor > xOldTextCursor; + ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet > xPropSet; + ::com::sun::star::uno::Reference < + ::com::sun::star::io::XOutputStream > xBase64Stream; + + /// old list item and block (#89891#) + bool mbListContextPushed; + + const ::rtl::OUString sWidth; + const ::rtl::OUString sWidthType; + const ::rtl::OUString sRelativeWidth; + const ::rtl::OUString sHeight; + const ::rtl::OUString sRelativeHeight; + const ::rtl::OUString sSizeType; + const ::rtl::OUString sIsSyncWidthToHeight; + const ::rtl::OUString sIsSyncHeightToWidth; + const ::rtl::OUString sHoriOrient; + const ::rtl::OUString sHoriOrientPosition; + const ::rtl::OUString sVertOrient; + const ::rtl::OUString sVertOrientPosition; + const ::rtl::OUString sChainNextName; + const ::rtl::OUString sAnchorType; + const ::rtl::OUString sAnchorPageNo; + const ::rtl::OUString sGraphicURL; + const ::rtl::OUString sGraphicFilter; + // --> OD 2009-07-22 #i73249# +// const ::rtl::OUString sAlternativeText; + const ::rtl::OUString sTitle; + const ::rtl::OUString sDescription; + // <-- + const ::rtl::OUString sFrameStyleName; + const ::rtl::OUString sGraphicRotation; + const ::rtl::OUString sTextBoxServiceName; + const ::rtl::OUString sGraphicServiceName; + + ::rtl::OUString sName; + ::rtl::OUString sStyleName; + ::rtl::OUString sNextName; + ::rtl::OUString sHRef; + ::rtl::OUString sFilterName; + ::rtl::OUString sCode; + ::rtl::OUString sObject; + ::rtl::OUString sArchive; + ::rtl::OUString sMimeType; + ::rtl::OUString sFrameName; + ::rtl::OUString sAppletName; + ::rtl::OUString sFilterService; + ::rtl::OUString sBase64CharsLeft; + ::rtl::OUString sTblName; + + ParamMap aParamMap; + + sal_Int32 nX; + sal_Int32 nY; + sal_Int32 nWidth; + sal_Int32 nHeight; + sal_Int32 nZIndex; + sal_Int16 nPage; + sal_Int16 nRotation; + sal_Int16 nRelWidth; + sal_Int16 nRelHeight; + + sal_uInt16 nType; + ::com::sun::star::text::TextContentAnchorType eAnchorType; + + sal_Bool bMayScript : 1; + sal_Bool bMinWidth : 1; + sal_Bool bMinHeight : 1; + sal_Bool bSyncWidth : 1; + sal_Bool bSyncHeight : 1; + sal_Bool bCreateFailed : 1; + sal_Bool bOwnBase64Stream : 1; + + void Create( sal_Bool bHRefOrBase64 ); + +public: + + TYPEINFO(); + + sal_Bool CreateIfNotThere(); + + XMLTextFrameContext_Impl( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & rAttrList, + ::com::sun::star::text::TextContentAnchorType eAnchorType, + sal_uInt16 nType, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & rFrameAttrList ); + virtual ~XMLTextFrameContext_Impl(); + + virtual void EndElement(); + + virtual void Characters( const ::rtl::OUString& rChars ); + + SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + void SetHyperlink( const ::rtl::OUString& rHRef, + const ::rtl::OUString& rName, + const ::rtl::OUString& rTargetFrameName, + sal_Bool bMap ); + // --> OD 2009-07-22 #i73249# + void SetTitle( const ::rtl::OUString& rTitle ); + // <-- + void SetDesc( const ::rtl::OUString& rDesc ); + + ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; } + + const ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet >& GetPropSet() { return xPropSet; } +}; + +TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext ); + +void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ ) +{ + UniReference < XMLTextImportHelper > xTextImportHelper = + GetImport().GetTextImport(); + + switch ( nType) + { + case XML_TEXT_FRAME_OBJECT: + case XML_TEXT_FRAME_OBJECT_OLE: + if( xBase64Stream.is() ) + { + OUString sURL( GetImport().ResolveEmbeddedObjectURLFromBase64() ); + if( sURL.getLength() ) + xPropSet = GetImport().GetTextImport() + ->createAndInsertOLEObject( GetImport(), sURL, + sStyleName, + sTblName, + nWidth, nHeight ); + } + else if( sHRef.getLength() ) + { + OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef, + OUString() ) ); + + if( GetImport().IsPackageURL( sHRef ) ) + { + xPropSet = GetImport().GetTextImport() + ->createAndInsertOLEObject( GetImport(), sURL, + sStyleName, + sTblName, + nWidth, nHeight ); + } + else + { + // it should be an own OOo link that has no storage persistance + xPropSet = GetImport().GetTextImport() + ->createAndInsertOOoLink( GetImport(), + sURL, + sStyleName, + sTblName, + nWidth, nHeight ); + } + } + else + { + OUString sURL( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.ServiceName:") ); + sURL += sFilterService; + xPropSet = GetImport().GetTextImport() + ->createAndInsertOLEObject( GetImport(), sURL, + sStyleName, + sTblName, + nWidth, nHeight ); + + } + break; + case XML_TEXT_FRAME_APPLET: + { + xPropSet = GetImport().GetTextImport() + ->createAndInsertApplet( sAppletName, sCode, + bMayScript, sHRef, + nWidth, nHeight); + break; + } + case XML_TEXT_FRAME_PLUGIN: + { + if(sHRef.getLength()) + GetImport().GetAbsoluteReference(sHRef); + xPropSet = GetImport().GetTextImport() + ->createAndInsertPlugin( sMimeType, sHRef, + nWidth, nHeight); + + break; + } + case XML_TEXT_FRAME_FLOATING_FRAME: + { + xPropSet = GetImport().GetTextImport() + ->createAndInsertFloatingFrame( sFrameName, sHRef, + sStyleName, + nWidth, nHeight); + break; + } + default: + { + Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(), + UNO_QUERY ); + if( xFactory.is() ) + { + OUString sServiceName; + switch( nType ) + { + case XML_TEXT_FRAME_TEXTBOX: sServiceName = sTextBoxServiceName; break; + case XML_TEXT_FRAME_GRAPHIC: sServiceName = sGraphicServiceName; break; + } + Reference<XInterface> xIfc = xFactory->createInstance( sServiceName ); + DBG_ASSERT( xIfc.is(), "couldn't create frame" ); + if( xIfc.is() ) + xPropSet = Reference < XPropertySet >( xIfc, UNO_QUERY ); + } + } + } + + if( !xPropSet.is() ) + { + bCreateFailed = sal_True; + return; + } + + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + + // set name + Reference < XNamed > xNamed( xPropSet, UNO_QUERY ); + if( xNamed.is() ) + { + OUString sOrigName( xNamed->getName() ); + if( !sOrigName.getLength() || + (sName.getLength() && sOrigName != sName) ) + { + OUString sOldName( sName ); + sal_Int32 i = 0; + while( xTextImportHelper->HasFrameByName( sName ) ) + { + sName = sOldName; + sName += OUString::valueOf( ++i ); + } + xNamed->setName( sName ); + if( sName != sOldName ) + xTextImportHelper->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME, + sOldName, sName ); + } + } + + // frame style + XMLPropStyleContext *pStyle = 0; + if( sStyleName.getLength() ) + { + pStyle = xTextImportHelper->FindAutoFrameStyle( sStyleName ); + if( pStyle ) + sStyleName = pStyle->GetParentName(); + } + + Any aAny; + if( sStyleName.getLength() ) + { + OUString sDisplayStyleName( GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_SD_GRAPHICS_ID, sStyleName ) ); + const Reference < XNameContainer > & rStyles = + xTextImportHelper->GetFrameStyles(); + if( rStyles.is() && + rStyles->hasByName( sDisplayStyleName ) ) + { + aAny <<= sDisplayStyleName; + xPropSet->setPropertyValue( sFrameStyleName, aAny ); + } + } + + // anchor type (must be set before any other properties, because + // otherwise some orientations cannot be set or will be changed + // afterwards) + aAny <<= eAnchorType; + xPropSet->setPropertyValue( sAnchorType, aAny ); + + // hard properties + if( pStyle ) + pStyle->FillPropertySet( xPropSet ); + + + // x and y + sal_Int16 nHoriOrient = HoriOrientation::NONE; + aAny = xPropSet->getPropertyValue( sHoriOrient ); + aAny >>= nHoriOrient; + if( HoriOrientation::NONE == nHoriOrient ) + { + aAny <<= nX; + xPropSet->setPropertyValue( sHoriOrientPosition, aAny ); + } + + sal_Int16 nVertOrient = VertOrientation::NONE; + aAny = xPropSet->getPropertyValue( sVertOrient ); + aAny >>= nVertOrient; + if( VertOrientation::NONE == nVertOrient ) + { + aAny <<= nY; + xPropSet->setPropertyValue( sVertOrientPosition, aAny ); + } + + // width + if( nWidth > 0 ) + { + aAny <<= nWidth; + xPropSet->setPropertyValue( sWidth, aAny ); + } + if( nRelWidth > 0 || nWidth > 0 ) + { + aAny <<= nRelWidth; + xPropSet->setPropertyValue( sRelativeWidth, aAny ); + } + if( bSyncWidth || nWidth > 0 ) + { + sal_Bool bTmp = bSyncWidth; + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsSyncWidthToHeight, aAny ); + } + if( xPropSetInfo->hasPropertyByName( sWidthType ) && + (bMinWidth || nWidth > 0 || nRelWidth > 0 ) ) + { + sal_Int16 nSizeType = + (bMinWidth && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN + : SizeType::FIX; + aAny <<= nSizeType; + xPropSet->setPropertyValue( sWidthType, aAny ); + } + + if( nHeight > 0 ) + { + aAny <<= nHeight; + xPropSet->setPropertyValue( sHeight, aAny ); + } + if( nRelHeight > 0 || nHeight > 0 ) + { + aAny <<= nRelHeight; + xPropSet->setPropertyValue( sRelativeHeight, aAny ); + } + if( bSyncHeight || nHeight > 0 ) + { + sal_Bool bTmp = bSyncHeight; + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsSyncHeightToWidth, aAny ); + } + if( xPropSetInfo->hasPropertyByName( sSizeType ) && + (bMinHeight || nHeight > 0 || nRelHeight > 0 ) ) + { + sal_Int16 nSizeType = + (bMinHeight && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN + : SizeType::FIX; + aAny <<= nSizeType; + xPropSet->setPropertyValue( sSizeType, aAny ); + } + + if( XML_TEXT_FRAME_GRAPHIC == nType ) + { + // URL + OSL_ENSURE( sHRef.getLength() > 0 || xBase64Stream.is(), + "neither URL nor base64 image data given" ); + UniReference < XMLTextImportHelper > xTxtImport = + GetImport().GetTextImport(); + if( sHRef.getLength() ) + { + sal_Bool bForceLoad = xTxtImport->IsInsertMode() || + xTxtImport->IsBlockMode() || + xTxtImport->IsStylesOnlyMode() || + xTxtImport->IsOrganizerMode(); + sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad ); + } + else if( xBase64Stream.is() ) + { + sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ); + xBase64Stream = 0; + } + aAny <<= sHRef; + xPropSet->setPropertyValue( sGraphicURL, aAny ); + + // filter name + aAny <<=sFilterName; + xPropSet->setPropertyValue( sGraphicFilter, aAny ); + + // rotation + aAny <<= nRotation; + xPropSet->setPropertyValue( sGraphicRotation, aAny ); + } + + // page number (must be set after the frame is inserted, because it + // will be overwritten then inserting the frame. + if( TextContentAnchorType_AT_PAGE == eAnchorType && nPage > 0 ) + { + aAny <<= nPage; + xPropSet->setPropertyValue( sAnchorPageNo, aAny ); + } + + if( XML_TEXT_FRAME_OBJECT != nType && + XML_TEXT_FRAME_OBJECT_OLE != nType && + XML_TEXT_FRAME_APPLET != nType && + XML_TEXT_FRAME_PLUGIN!= nType && + XML_TEXT_FRAME_FLOATING_FRAME != nType) + { + Reference < XTextContent > xTxtCntnt( xPropSet, UNO_QUERY ); + xTextImportHelper->InsertTextContent( xTxtCntnt ); + } + + Reference < XShape > xShape( xPropSet, UNO_QUERY ); + + // #107848# + // Make adding the shepe to Z-Ordering dependent from if we are + // inside a inside_deleted_section (redlining). That is necessary + // since the shape will be removed again later. It would lead to + // errors if it would stay inside the Z-Ordering. Thus, the + // easiest way to solve that conflict is to not add it here. + if(!GetImport().HasTextImport() + || !GetImport().GetTextImport()->IsInsideDeleteContext()) + { + GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex ); + } + + if( XML_TEXT_FRAME_TEXTBOX == nType ) + { + xTextImportHelper->ConnectFrameChains( sName, sNextName, xPropSet ); + Reference < XTextFrame > xTxtFrame( xPropSet, UNO_QUERY ); + Reference < XText > xTxt = xTxtFrame->getText(); + xOldTextCursor = xTextImportHelper->GetCursor(); + xTextImportHelper->SetCursor( xTxt->createTextCursor() ); + + // remember old list item and block (#89892#) and reset them + // for the text frame + xTextImportHelper->PushListContext(); + mbListContextPushed = true; + } +} + +sal_Bool XMLTextFrameContext_Impl::CreateIfNotThere() +{ + if( !xPropSet.is() && + ( XML_TEXT_FRAME_OBJECT_OLE == nType || + XML_TEXT_FRAME_GRAPHIC == nType ) && + xBase64Stream.is() && !bCreateFailed ) + { + if( bOwnBase64Stream ) + xBase64Stream->closeOutput(); + Create( sal_True ); + } + + return xPropSet.is(); +} + +XMLTextFrameContext_Impl::XMLTextFrameContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & rAttrList, + TextContentAnchorType eATyp, + sal_uInt16 nNewType, + const Reference< XAttributeList > & rFrameAttrList ) +: SvXMLImportContext( rImport, nPrfx, rLName ) +, mbListContextPushed( false ) +, sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")) +, sWidthType(RTL_CONSTASCII_USTRINGPARAM("WidthType")) +, sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth")) +, sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")) +, sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight")) +, sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType")) +, sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight")) +, sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth")) +, sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")) +, sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")) +, sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient")) +, sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")) +, sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")) +, sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")) +, sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")) +, sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")) +, sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")) +// --> OD 2009-07-22 #i73249# +//, sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")) +, sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")) +, sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")) +// <-- +, sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName")) +, sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")) +, sTextBoxServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")) +, sGraphicServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GraphicObject")) +, nType( nNewType ) +, eAnchorType( eATyp ) +{ + nX = 0; + nY = 0; + nWidth = 0; + nHeight = 0; + nZIndex = -1; + nPage = 0; + nRotation = 0; + nRelWidth = 0; + nRelHeight = 0; + bMayScript = sal_False; + + bMinHeight = sal_False; + bMinWidth = sal_False; + bSyncWidth = sal_False; + bSyncHeight = sal_False; + bCreateFailed = sal_False; + bOwnBase64Stream = sal_False; + + UniReference < XMLTextImportHelper > xTxtImport = + GetImport().GetTextImport(); + const SvXMLTokenMap& rTokenMap = + xTxtImport->GetTextFrameAttrTokenMap(); + + sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0; + sal_Int16 nTotalAttrCount = nAttrCount + (rFrameAttrList.is() ? rFrameAttrList->getLength() : 0); + for( sal_Int16 i=0; i < nTotalAttrCount; i++ ) + { + const OUString& rAttrName = + i < nAttrCount ? rAttrList->getNameByIndex( i ) : rFrameAttrList->getNameByIndex( i-nAttrCount ); + const OUString& rValue = + i < nAttrCount ? rAttrList->getValueByIndex( i ): rFrameAttrList->getValueByIndex( i-nAttrCount ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_FRAME_STYLE_NAME: + sStyleName = rValue; + break; + case XML_TOK_TEXT_FRAME_NAME: + sName = rValue; + break; + case XML_TOK_TEXT_FRAME_FRAME_NAME: + sFrameName = rValue; + break; + case XML_TOK_TEXT_FRAME_APPLET_NAME: + sAppletName = rValue; + break; + case XML_TOK_TEXT_FRAME_ANCHOR_TYPE: + if( TextContentAnchorType_AT_PARAGRAPH == eAnchorType || + TextContentAnchorType_AT_CHARACTER == eAnchorType || + TextContentAnchorType_AS_CHARACTER == eAnchorType ) + { + + TextContentAnchorType eNew; + if( XMLAnchorTypePropHdl::convert( rValue, eNew ) && + ( TextContentAnchorType_AT_PARAGRAPH == eNew || + TextContentAnchorType_AT_CHARACTER == eNew || + TextContentAnchorType_AS_CHARACTER == eNew || + TextContentAnchorType_AT_PAGE == eNew) ) + eAnchorType = eNew; + } + break; + case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER: + { + sal_Int32 nTmp; + if( GetImport().GetMM100UnitConverter(). + convertNumber( nTmp, rValue, 1, SHRT_MAX ) ) + nPage = (sal_Int16)nTmp; + } + break; + case XML_TOK_TEXT_FRAME_X: + GetImport().GetMM100UnitConverter().convertMeasure( nX, rValue ); + break; + case XML_TOK_TEXT_FRAME_Y: + GetImport().GetMM100UnitConverter().convertMeasure( nY, rValue ); + break; + case XML_TOK_TEXT_FRAME_WIDTH: + // relative widths are obsolete since SRC617. Remove them some day! + if( rValue.indexOf( '%' ) != -1 ) + { + sal_Int32 nTmp; + GetImport().GetMM100UnitConverter().convertPercent( nTmp, + rValue ); + nRelWidth = (sal_Int16)nTmp; + } + else + { + GetImport().GetMM100UnitConverter().convertMeasure( nWidth, + rValue, 0 ); + } + break; + case XML_TOK_TEXT_FRAME_REL_WIDTH: + if( IsXMLToken(rValue, XML_SCALE) ) + { + bSyncWidth = sal_True; + } + else + { + sal_Int32 nTmp; + if( GetImport().GetMM100UnitConverter(). + convertPercent( nTmp, rValue ) ) + nRelWidth = (sal_Int16)nTmp; + } + break; + case XML_TOK_TEXT_FRAME_MIN_WIDTH: + if( rValue.indexOf( '%' ) != -1 ) + { + sal_Int32 nTmp; + GetImport().GetMM100UnitConverter().convertPercent( nTmp, + rValue ); + nRelWidth = (sal_Int16)nTmp; + } + else + { + GetImport().GetMM100UnitConverter().convertMeasure( nWidth, + rValue, 0 ); + } + bMinWidth = sal_True; + break; + case XML_TOK_TEXT_FRAME_HEIGHT: + // relative heights are obsolete since SRC617. Remove them some day! + if( rValue.indexOf( '%' ) != -1 ) + { + sal_Int32 nTmp; + GetImport().GetMM100UnitConverter().convertPercent( nTmp, + rValue ); + nRelHeight = (sal_Int16)nTmp; + } + else + { + GetImport().GetMM100UnitConverter().convertMeasure( nHeight, + rValue, 0 ); + } + break; + case XML_TOK_TEXT_FRAME_REL_HEIGHT: + if( IsXMLToken( rValue, XML_SCALE ) ) + { + bSyncHeight = sal_True; + } + else if( IsXMLToken( rValue, XML_SCALE_MIN ) ) + { + bSyncHeight = sal_True; + bMinHeight = sal_True; + } + else + { + sal_Int32 nTmp; + if( GetImport().GetMM100UnitConverter(). + convertPercent( nTmp, rValue ) ) + nRelHeight = (sal_Int16)nTmp; + } + break; + case XML_TOK_TEXT_FRAME_MIN_HEIGHT: + if( rValue.indexOf( '%' ) != -1 ) + { + sal_Int32 nTmp; + GetImport().GetMM100UnitConverter().convertPercent( nTmp, + rValue ); + nRelHeight = (sal_Int16)nTmp; + } + else + { + GetImport().GetMM100UnitConverter().convertMeasure( nHeight, + rValue, 0 ); + } + bMinHeight = sal_True; + break; + case XML_TOK_TEXT_FRAME_Z_INDEX: + GetImport().GetMM100UnitConverter().convertNumber( nZIndex, rValue, -1 ); + break; + case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME: + sNextName = rValue; + break; + case XML_TOK_TEXT_FRAME_HREF: + sHRef = rValue; + break; + case XML_TOK_TEXT_FRAME_FILTER_NAME: + sFilterName = rValue; + break; + case XML_TOK_TEXT_FRAME_TRANSFORM: + { + OUString sValue( rValue ); + sValue.trim(); + const OUString aRotate(GetXMLToken(XML_ROTATE)); + const sal_Int32 nRotateLen(aRotate.getLength()); + sal_Int32 nLen = sValue.getLength(); + if( nLen >= nRotateLen+3 && + 0 == sValue.compareTo( aRotate, nRotateLen ) && + '(' == sValue[nRotateLen] && + ')' == sValue[nLen-1] ) + { + sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) ); + sValue.trim(); + sal_Int32 nVal; + if( GetImport().GetMM100UnitConverter().convertNumber( nVal, sValue ) ) + nRotation = (sal_Int16)(nVal % 360 ); + } + } + break; + case XML_TOK_TEXT_FRAME_CODE: + sCode = rValue; + break; + case XML_TOK_TEXT_FRAME_OBJECT: + sObject = rValue; + break; + case XML_TOK_TEXT_FRAME_ARCHIVE: + sArchive = rValue; + break; + case XML_TOK_TEXT_FRAME_MAY_SCRIPT: + bMayScript = IsXMLToken( rValue, XML_TRUE ); + break; + case XML_TOK_TEXT_FRAME_MIME_TYPE: + sMimeType = rValue; + break; + case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE: + sTblName = rValue; + break; + } + } + + if( ( (XML_TEXT_FRAME_GRAPHIC == nType || + XML_TEXT_FRAME_OBJECT == nType || + XML_TEXT_FRAME_OBJECT_OLE == nType) && + !sHRef.getLength() ) || + ( XML_TEXT_FRAME_APPLET == nType && !sCode.getLength() ) || + ( XML_TEXT_FRAME_PLUGIN == nType && + sHRef.getLength() == 0 && sMimeType.getLength() == 0 ) ) + return; // no URL: no image or OLE object + + Create( sal_True ); +} + +XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl() +{ +} + +void XMLTextFrameContext_Impl::EndElement() +{ + CreateIfNotThere(); + + if( xOldTextCursor.is() ) + { + GetImport().GetTextImport()->DeleteParagraph(); + GetImport().GetTextImport()->SetCursor( xOldTextCursor ); + } + + // reinstall old list item (if necessary) #89892# + if (mbListContextPushed) { + GetImport().GetTextImport()->PopListContext(); + } + + if (( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN ) && xPropSet.is()) + GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap); +} + +SvXMLImportContext *XMLTextFrameContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_DRAW == nPrefix ) + { + if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) && + IsXMLToken( rLocalName, XML_PARAM ) ) + { + pContext = new XMLTextFrameParam_Impl( GetImport(), + nPrefix, rLocalName, + xAttrList, nType, aParamMap ); + } + } + else if( (XML_NAMESPACE_OFFICE == nPrefix) ) + { + if( IsXMLToken( rLocalName, XML_BINARY_DATA ) ) + { + if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed ) + { + switch( nType ) + { + case XML_TEXT_FRAME_GRAPHIC: + xBase64Stream = + GetImport().GetStreamForGraphicObjectURLFromBase64(); + break; + case XML_TEXT_FRAME_OBJECT_OLE: + xBase64Stream = + GetImport().GetStreamForEmbeddedObjectURLFromBase64(); + break; + } + if( xBase64Stream.is() ) + pContext = new XMLBase64ImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + xBase64Stream ); + } + } + } + // --> OD 2009-08-17 #i100480# + // correction of condition which also avoids warnings. + if( !pContext && + ( XML_TEXT_FRAME_OBJECT == nType && + ( ( XML_NAMESPACE_OFFICE == nPrefix && + IsXMLToken( rLocalName, XML_DOCUMENT ) ) || + ( XML_NAMESPACE_MATH == nPrefix && + IsXMLToken( rLocalName, XML_MATH ) ) ) ) ) + // <-- + { + if( !xPropSet.is() && !bCreateFailed ) + { + XMLEmbeddedObjectImportContext *pEContext = + new XMLEmbeddedObjectImportContext( GetImport(), nPrefix, + rLocalName, xAttrList ); + sFilterService = pEContext->GetFilterServiceName(); + if( sFilterService.getLength() != 0 ) + { + Create( sal_False ); + if( xPropSet.is() ) + { + Reference < XEmbeddedObjectSupplier > xEOS( xPropSet, + UNO_QUERY ); + OSL_ENSURE( xEOS.is(), + "no embedded object supplier for own object" ); + Reference<com::sun::star::lang::XComponent> aXComponent(xEOS->getEmbeddedObject()); + pEContext->SetComponent( aXComponent ); + } + } + pContext = pEContext; + } + } + if( !pContext && xOldTextCursor.is() ) // text-box + pContext = GetImport().GetTextImport()->CreateTextChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + XML_TEXT_TYPE_TEXTBOX ); + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + +void XMLTextFrameContext_Impl::Characters( const OUString& rChars ) +{ + if( ( XML_TEXT_FRAME_OBJECT_OLE == nType || + XML_TEXT_FRAME_GRAPHIC == nType) && + !xPropSet.is() && !bCreateFailed ) + { + OUString sTrimmedChars( rChars. trim() ); + if( sTrimmedChars.getLength() ) + { + if( !xBase64Stream.is() ) + { + if( XML_TEXT_FRAME_GRAPHIC == nType ) + { + xBase64Stream = + GetImport().GetStreamForGraphicObjectURLFromBase64(); + } + else + { + xBase64Stream = + GetImport().GetStreamForEmbeddedObjectURLFromBase64(); + } + if( xBase64Stream.is() ) + bOwnBase64Stream = sal_True; + } + if( bOwnBase64Stream && xBase64Stream.is() ) + { + OUString sChars; + if( sBase64CharsLeft ) + { + sChars = sBase64CharsLeft; + sChars += sTrimmedChars; + sBase64CharsLeft = OUString(); + } + else + { + sChars = sTrimmedChars; + } + Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 ); + sal_Int32 nCharsDecoded = + GetImport().GetMM100UnitConverter(). + decodeBase64SomeChars( aBuffer, sChars ); + xBase64Stream->writeBytes( aBuffer ); + if( nCharsDecoded != sChars.getLength() ) + sBase64CharsLeft = sChars.copy( nCharsDecoded ); + } + } + } +} + +void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef, + const OUString& rName, + const OUString& rTargetFrameName, + sal_Bool bMap ) +{ + static ::rtl::OUString s_HyperLinkURL( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")); + static ::rtl::OUString s_HyperLinkName( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")); + static ::rtl::OUString s_HyperLinkTarget( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")); + static ::rtl::OUString s_ServerMap( + RTL_CONSTASCII_USTRINGPARAM("ServerMap")); + if( !xPropSet.is() ) + return; + + UniReference< XMLTextImportHelper > xTxtImp = GetImport().GetTextImport(); + Reference < XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( !xPropSetInfo.is() || + !xPropSetInfo->hasPropertyByName(s_HyperLinkURL)) + return; + + Any aAny; + aAny <<= rHRef; + xPropSet->setPropertyValue( s_HyperLinkURL, aAny ); + + if (xPropSetInfo->hasPropertyByName(s_HyperLinkName)) + { + aAny <<= rName; + xPropSet->setPropertyValue(s_HyperLinkName, aAny); + } + + if (xPropSetInfo->hasPropertyByName(s_HyperLinkTarget)) + { + aAny <<= rTargetFrameName; + xPropSet->setPropertyValue( s_HyperLinkTarget, aAny ); + } + + if (xPropSetInfo->hasPropertyByName(s_ServerMap)) + { + aAny.setValue( &bMap, ::getBooleanCppuType() ); + xPropSet->setPropertyValue(s_ServerMap, aAny); + } +} + +// --> OD 2009-07-22 #i73249# +void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle ) +{ + if ( xPropSet.is() ) + { + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( sTitle ) ) + { + xPropSet->setPropertyValue( sTitle, makeAny( rTitle ) ); + } + } +} + +void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc ) +{ + if ( xPropSet.is() ) + { + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( sDescription ) ) + { + xPropSet->setPropertyValue( sDescription, makeAny( rDesc ) ); + } + } +} +// <-- + +//----------------------------------------------------------------------------------------------------- + +TYPEINIT1( XMLTextFrameContext, SvXMLImportContext ); + +sal_Bool XMLTextFrameContext::CreateIfNotThere() +{ + sal_Bool bRet = sal_False; + SvXMLImportContext *pContext = &m_xImplContext; + XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); + if( pImpl ) + bRet = pImpl->CreateIfNotThere(); + + return bRet; +} + +sal_Bool XMLTextFrameContext::CreateIfNotThere( ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet >& rPropSet ) +{ + SvXMLImportContext *pContext = &m_xImplContext; + XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); + if( pImpl ) + { + if( pImpl->CreateIfNotThere() ) + rPropSet = pImpl->GetPropSet(); + } + + return rPropSet.is(); +} + +XMLTextFrameContext::XMLTextFrameContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + TextContentAnchorType eATyp ) +: SvXMLImportContext( rImport, nPrfx, rLName ) +, m_xAttrList( new SvXMLAttributeList( xAttrList ) ) +, m_pHyperlink( 0 ) +// --> OD 2009-07-22 #i73249# +, m_sTitle() +, m_sDesc() +// <-- +, m_eDefaultAnchorType( eATyp ) + // --> OD 2006-03-10 #i51726# +, m_HasAutomaticStyleWithoutParentStyle( sal_False ) + // <-- +, m_bSupportsReplacement( sal_False ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); + // --> OD 2006-03-10 #i51726# + // New distinguish attribute between Writer objects and Draw objects is: + // Draw objects have an automatic style without a parent style + if ( XML_NAMESPACE_DRAW == nPrefix && + IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + { + OUString aStyleName = xAttrList->getValueByIndex( i ); + if( aStyleName.getLength() ) + { + UniReference < XMLTextImportHelper > xTxtImport = + GetImport().GetTextImport(); + XMLPropStyleContext* pStyle( 0L ); + pStyle = xTxtImport->FindAutoFrameStyle( aStyleName ); + if ( pStyle && !pStyle->GetParentName().getLength() ) + { + m_HasAutomaticStyleWithoutParentStyle = sal_True; + } + } + } + // <-- + else if ( XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_ANCHOR_TYPE ) ) + { + TextContentAnchorType eNew; + if( XMLAnchorTypePropHdl::convert( xAttrList->getValueByIndex(i), + eNew ) && + ( TextContentAnchorType_AT_PARAGRAPH == eNew || + TextContentAnchorType_AT_CHARACTER == eNew || + TextContentAnchorType_AS_CHARACTER == eNew || + TextContentAnchorType_AT_PAGE == eNew) ) + m_eDefaultAnchorType = eNew; + } + } +} + +XMLTextFrameContext::~XMLTextFrameContext() +{ + delete m_pHyperlink; +} + +void XMLTextFrameContext::EndElement() +{ + SvXMLImportContext *pContext = &m_xImplContext; + XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); + if( pImpl ) + { + pImpl->CreateIfNotThere(); + + // --> OD 2009-07-22 #i73249# +// // alternative text +// if( m_sDesc.getLength() ) +// pImpl->SetDesc( m_sDesc ); + // svg:title + if( m_sTitle.getLength() ) + { + pImpl->SetTitle( m_sTitle ); + } + if( m_sDesc.getLength() ) + { + pImpl->SetDesc( m_sDesc ); + } + // <-- + + if( m_pHyperlink ) + { + pImpl->SetHyperlink( m_pHyperlink->GetHRef(), m_pHyperlink->GetName(), + m_pHyperlink->GetTargetFrameName(), m_pHyperlink->GetMap() ); + delete m_pHyperlink; + m_pHyperlink = 0; + } + + } +} + +SvXMLImportContext *XMLTextFrameContext::CreateChildContext( + sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( !m_xImplContext.Is() ) + { + // no child exists + if( XML_NAMESPACE_DRAW == p_nPrefix ) + { + sal_uInt16 nFrameType = USHRT_MAX; + if( IsXMLToken( rLocalName, XML_TEXT_BOX ) ) + nFrameType = XML_TEXT_FRAME_TEXTBOX; + else if( IsXMLToken( rLocalName, XML_IMAGE ) ) + nFrameType = XML_TEXT_FRAME_GRAPHIC; + else if( IsXMLToken( rLocalName, XML_OBJECT ) ) + nFrameType = XML_TEXT_FRAME_OBJECT; + else if( IsXMLToken( rLocalName, XML_OBJECT_OLE ) ) + nFrameType = XML_TEXT_FRAME_OBJECT_OLE; + else if( IsXMLToken( rLocalName, XML_APPLET) ) + nFrameType = XML_TEXT_FRAME_APPLET; + else if( IsXMLToken( rLocalName, XML_PLUGIN ) ) + nFrameType = XML_TEXT_FRAME_PLUGIN; + else if( IsXMLToken( rLocalName, XML_FLOATING_FRAME ) ) + nFrameType = XML_TEXT_FRAME_FLOATING_FRAME; + + if( USHRT_MAX != nFrameType ) + { + // --> OD 2006-03-10 #i51726# + if ( ( XML_TEXT_FRAME_TEXTBOX == nFrameType || + XML_TEXT_FRAME_GRAPHIC == nFrameType ) && + m_HasAutomaticStyleWithoutParentStyle ) + // <-- + { + Reference < XShapes > xShapes; + pContext = GetImport().GetShapeImport()->CreateFrameChildContext( + GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList ); + } + else if( XML_TEXT_FRAME_PLUGIN == nFrameType ) + { + bool bMedia = false; + + // check, if we have a media object + for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n ) + { + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName ); + + if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) ) + { + if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) ) + bMedia = true; + + // leave this loop + n = nAttrCount - 1; + } + } + + if( bMedia ) + { + Reference < XShapes > xShapes; + pContext = GetImport().GetShapeImport()->CreateFrameChildContext( + GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList ); + } + } + else if( XML_TEXT_FRAME_OBJECT == nFrameType || + XML_TEXT_FRAME_OBJECT_OLE == nFrameType ) + { + m_bSupportsReplacement = sal_True; + } + + if( !pContext ) + { + + pContext = new XMLTextFrameContext_Impl( GetImport(), p_nPrefix, + rLocalName, xAttrList, + m_eDefaultAnchorType, + nFrameType, + m_xAttrList ); + } + + m_xImplContext = pContext; + } + } + } + else if( m_bSupportsReplacement && !m_xReplImplContext && + XML_NAMESPACE_DRAW == p_nPrefix && + IsXMLToken( rLocalName, XML_IMAGE ) ) + { + // read replacement image + Reference < XPropertySet > xPropSet; + if( CreateIfNotThere( xPropSet ) ) + { + pContext = new XMLReplacementImageContext( GetImport(), + p_nPrefix, rLocalName, xAttrList, xPropSet ); + m_xReplImplContext = pContext; + } + } + else if( m_xImplContext->ISA( XMLTextFrameContext_Impl ) ) + { + // the child is a writer frame + if( XML_NAMESPACE_SVG == p_nPrefix ) + { + // --> OD 2009-07-22 #i73249# +// bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion(); +// if( IsXMLToken( rLocalName, bOld ? XML_DESC : XML_TITLE ) ) +// pContext = new XMLTextFrameDescContext_Impl( GetImport(), p_nPrefix, rLocalName, +// xAttrList, m_sDesc ); + const bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion(); + if ( bOld ) + { + if ( IsXMLToken( rLocalName, XML_DESC ) ) + { + pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(), + p_nPrefix, + rLocalName, + m_sTitle ); + } + } + else + { + if( IsXMLToken( rLocalName, XML_TITLE ) ) + { + pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(), + p_nPrefix, + rLocalName, + m_sTitle ); + } + else if ( IsXMLToken( rLocalName, XML_DESC ) ) + { + pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(), + p_nPrefix, + rLocalName, + m_sDesc ); + } + } + // <-- + } + else if( XML_NAMESPACE_DRAW == p_nPrefix ) + { + Reference < XPropertySet > xPropSet; + if( IsXMLToken( rLocalName, XML_CONTOUR_POLYGON ) ) + { + if( CreateIfNotThere( xPropSet ) ) + pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName, + xAttrList, xPropSet, sal_False ); + } + else if( IsXMLToken( rLocalName, XML_CONTOUR_PATH ) ) + { + if( CreateIfNotThere( xPropSet ) ) + pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName, + xAttrList, xPropSet, sal_True ); + } + else if( IsXMLToken( rLocalName, XML_IMAGE_MAP ) ) + { + if( CreateIfNotThere( xPropSet ) ) + pContext = new XMLImageMapContext( GetImport(), p_nPrefix, rLocalName, xPropSet ); + } + } + else if( (XML_NAMESPACE_OFFICE == p_nPrefix) && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + { + // do we still have the frame object? + Reference < XPropertySet > xPropSet; + if( CreateIfNotThere( xPropSet ) ) + { + // is it an event supplier? + Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY); + if (xEventsSupplier.is()) + { + // OK, we have the events, so create the context + pContext = new XMLEventsImportContext(GetImport(), p_nPrefix, + rLocalName, xEventsSupplier); + } + } + } + } + else if( p_nPrefix == XML_NAMESPACE_SVG && // #i68101# + (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) + { + pContext = m_xImplContext->CreateChildContext( p_nPrefix, rLocalName, xAttrList ); + } + else + { + // the child is a drawing shape + pContext = GetImport().GetShapeImport()->CreateFrameChildContext( + &m_xImplContext, p_nPrefix, rLocalName, xAttrList ); + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); + + return pContext; +} + +void XMLTextFrameContext::SetHyperlink( const OUString& rHRef, + const OUString& rName, + const OUString& rTargetFrameName, + sal_Bool bMap ) +{ + OSL_ENSURE( !m_pHyperlink, "recursive SetHyperlink call" ); + delete m_pHyperlink; + m_pHyperlink = new XMLTextFrameContextHyperlink_Impl( + rHRef, rName, rTargetFrameName, bMap ); +} + +TextContentAnchorType XMLTextFrameContext::GetAnchorType() const +{ + SvXMLImportContext *pContext = &m_xImplContext; + XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); + if( pImpl ) + return pImpl->GetAnchorType(); + else + return m_eDefaultAnchorType; +} + +Reference < XTextContent > XMLTextFrameContext::GetTextContent() const +{ + Reference < XTextContent > xTxtCntnt; + SvXMLImportContext *pContext = &m_xImplContext; + XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); + if( pImpl ) + xTxtCntnt.set( pImpl->GetPropSet(), UNO_QUERY ); + + return xTxtCntnt; +} + +// --> OD 2004-08-24 #33242# +Reference < XShape > XMLTextFrameContext::GetShape() const +{ + Reference < XShape > xShape; + SvXMLImportContext* pContext = &m_xImplContext; + SvXMLShapeContext* pImpl = PTR_CAST( SvXMLShapeContext, pContext ); + if ( pImpl ) + { + xShape = pImpl->getShape(); + } + + return xShape; +} +// <-- diff --git a/xmloff/source/text/XMLTextFrameContext.hxx b/xmloff/source/text/XMLTextFrameContext.hxx new file mode 100644 index 000000000000..5b9b59c42671 --- /dev/null +++ b/xmloff/source/text/XMLTextFrameContext.hxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLTEXTFRAMECONTEXT_HXX +#define _XMLTEXTFRAMECONTEXT_HXX + +#ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP +#include <com/sun/star/text/TextContentAnchorType.hpp> +#endif +#include <xmloff/xmlictxt.hxx> + +namespace com { namespace sun { namespace star { + namespace text { class XTextCursor; class XTextContent; } +} } } + +class SvXMLAttributeList; +class XMLTextFrameContextHyperlink_Impl; + +class XMLTextFrameContext : public SvXMLImportContext +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > m_xAttrList; + + SvXMLImportContextRef m_xImplContext; + SvXMLImportContextRef m_xReplImplContext; + SvXMLAttributeList *m_pAttrList; + + XMLTextFrameContextHyperlink_Impl *m_pHyperlink; + // --> OD 2009-07-22 #i73249# + ::rtl::OUString m_sTitle; + // <-- + ::rtl::OUString m_sDesc; + + ::com::sun::star::text::TextContentAnchorType m_eDefaultAnchorType; + + // --> OD 2006-03-10 #i51726# + // The <draw:name> can longer be used to distinguish Writer graphic/text box + // objects and Draw graphic/text box objects. + // The new distinguish attribute is the parent style of the automatic style + // of the object. All Draw objects have an automatic style without a parent style. + sal_Bool m_HasAutomaticStyleWithoutParentStyle; + // <-- + sal_Bool m_bSupportsReplacement; + + sal_Bool CreateIfNotThere(); + sal_Bool CreateIfNotThere( ::com::sun::star::uno::Reference < + ::com::sun::star::beans::XPropertySet >& rPropSet ); + +public: + + TYPEINFO(); + + XMLTextFrameContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + ::com::sun::star::text::TextContentAnchorType eDfltAnchorType ); + virtual ~XMLTextFrameContext(); + + virtual void EndElement(); + + SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + void SetHyperlink( const ::rtl::OUString& rHRef, + const ::rtl::OUString& rName, + const ::rtl::OUString& rTargetFrameName, + sal_Bool bMap ); + + ::com::sun::star::text::TextContentAnchorType GetAnchorType() const; + + ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > GetTextContent() const; + // --> OD 2004-08-24 #i33242# + ::com::sun::star::uno::Reference < + ::com::sun::star::drawing::XShape > GetShape() const; + // <-- +}; + + +#endif diff --git a/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx b/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx new file mode 100644 index 000000000000..15cc68c9e675 --- /dev/null +++ b/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include "XMLTextFrameContext.hxx" +#include "XMLTextFrameHyperlinkContext.hxx" + +// OD 2004-04-21 #i26791# +#include <txtparaimphint.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext ); + +XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + TextContentAnchorType eATyp ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + eDefaultAnchorType( eATyp ), + bMap( sal_False ) +{ + OUString sShow; + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_HYPERLINK_HREF: + sHRef = GetImport().GetAbsoluteReference( rValue ); + break; + case XML_TOK_TEXT_HYPERLINK_NAME: + sName = rValue; + break; + case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME: + sTargetFrameName = rValue; + break; + case XML_TOK_TEXT_HYPERLINK_SHOW: + sShow = rValue; + break; + case XML_TOK_TEXT_HYPERLINK_SERVER_MAP: + { + sal_Bool bTmp; + if( rImport.GetMM100UnitConverter().convertBool( bTmp, + rValue ) ) + { + bMap = bTmp; + } + } + break; + } + } + + if( sShow.getLength() && !sTargetFrameName.getLength() ) + { + if( IsXMLToken( sShow, XML_NEW ) ) + sTargetFrameName = + OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ); + else if( IsXMLToken( sShow, XML_REPLACE ) ) + sTargetFrameName = + OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ); + } +} + +XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext() +{ +} + +void XMLTextFrameHyperlinkContext::EndElement() +{ +} + +SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + XMLTextFrameContext *pTextFrameContext = 0; + + if( XML_NAMESPACE_DRAW == nPrefix ) + { + if( IsXMLToken( rLocalName, XML_FRAME ) ) + pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix, + rLocalName, xAttrList, + eDefaultAnchorType ); + } + + if( pTextFrameContext ) + { + pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap ); + pContext = pTextFrameContext; + xFrameContext = pContext; + } + else + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + + +TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const +{ + if( xFrameContext.Is() ) + { + SvXMLImportContext *pContext = &xFrameContext; + return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType(); + } + else + return eDefaultAnchorType; + +} + +Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const +{ + Reference <XTextContent > xTxt; + if( xFrameContext.Is() ) + { + SvXMLImportContext *pContext = &xFrameContext; + xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent(); + } + + return xTxt; +} + +// --> OD 2004-08-24 #33242# +Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const +{ + Reference < drawing::XShape > xShape; + if( xFrameContext.Is() ) + { + SvXMLImportContext *pContext = &xFrameContext; + xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape(); + } + + return xShape; +} +// <-- + + diff --git a/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx b/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx new file mode 100644 index 000000000000..312f8268945c --- /dev/null +++ b/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLTEXTFRAMEHYPERLINKCONTEXT_HXX +#define _XMLTEXTFRAMEHYPERLINKCONTEXT_HXX + +#ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP +#include <com/sun/star/text/TextContentAnchorType.hpp> +#endif +#ifndef _COM_SUN_STAR_TEXT_XTEXTFRAME_HPP +#include <com/sun/star/text/XTextFrame.hpp> +#endif +#include <xmloff/xmlictxt.hxx> + +namespace com { namespace sun { namespace star { + namespace text { class XTextCursor; class XTextFrame; } + namespace beans { class XPropertySet; } +} } } + +// OD 2004-04-21 #i26791# +class XMLTextFrameHint_Impl; + +class XMLTextFrameHyperlinkContext : public SvXMLImportContext +{ + ::rtl::OUString sHRef; + ::rtl::OUString sName; + ::rtl::OUString sTargetFrameName; + ::com::sun::star::text::TextContentAnchorType eDefaultAnchorType; + SvXMLImportContextRef xFrameContext; + sal_Bool bMap; + +public: + + TYPEINFO(); + + XMLTextFrameHyperlinkContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + ::com::sun::star::text::TextContentAnchorType eDefaultAnchorType ); + virtual ~XMLTextFrameHyperlinkContext(); + + virtual void EndElement(); + + SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + ::com::sun::star::text::TextContentAnchorType GetAnchorType() const; + ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > GetTextContent() const; + // --> OD 2004-08-24 #i33242# + ::com::sun::star::uno::Reference < + ::com::sun::star::drawing::XShape > GetShape() const; + // <-- +}; + + +#endif diff --git a/xmloff/source/text/XMLTextHeaderFooterContext.cxx b/xmloff/source/text/XMLTextHeaderFooterContext.cxx new file mode 100644 index 000000000000..de74248f787b --- /dev/null +++ b/xmloff/source/text/XMLTextHeaderFooterContext.cxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XRelativeTextContentRemove.hpp> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include "XMLTextHeaderFooterContext.hxx" +#ifndef _XMLOFF_TEXTTABLECONTEXT_HXX_ +#include <xmloff/XMLTextTableContext.hxx> +#endif +#include <xmloff/xmlimp.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +//using namespace ::com::sun::star::style; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::beans; +//using namespace ::com::sun::star::container; +//using namespace ::com::sun::star::lang; +//using namespace ::com::sun::star::text; + + +TYPEINIT1( XMLTextHeaderFooterContext, SvXMLImportContext ); + +XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< + xml::sax::XAttributeList > &, + const Reference < XPropertySet > & rPageStylePropSet, + sal_Bool bFooter, sal_Bool bLft ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + xPropSet( rPageStylePropSet ), + sOn( OUString::createFromAscii( bFooter ? "FooterIsOn" : "HeaderIsOn" ) ), + sShareContent( OUString::createFromAscii( bFooter ? "FooterIsShared" + : "HeaderIsShared" ) ), + sText( OUString::createFromAscii( bFooter ? "FooterText" : "HeaderText" ) ), + sTextLeft( OUString::createFromAscii( bFooter ? "FooterTextLeft" + : "HeaderTextLeft" ) ), + bInsertContent( sal_True ), + bLeft( bLft ) +{ + if( bLeft ) + { + Any aAny; + + aAny = xPropSet->getPropertyValue( sOn ); + sal_Bool bOn = *(sal_Bool *)aAny.getValue(); + + if( bOn ) + { + aAny = xPropSet->getPropertyValue( sShareContent ); + sal_Bool bShared = *(sal_Bool *)aAny.getValue(); + if( bShared ) + { + // Don't share headers any longer + bShared = sal_False; + aAny.setValue( &bShared, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sShareContent, aAny ); + } + } + else + { + // If headers or footers are switched off, no content must be + // inserted. + bInsertContent = sal_False; + } + } +} + +XMLTextHeaderFooterContext::~XMLTextHeaderFooterContext() +{ +} + +SvXMLImportContext *XMLTextHeaderFooterContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + if( bInsertContent ) + { + if( !xOldTextCursor.is() ) + { + sal_Bool bRemoveContent = sal_True; + Any aAny; + if( bLeft ) + { + // Headers and footers are switched on already, + // and they aren't shared. + aAny = xPropSet->getPropertyValue( sTextLeft ); + } + else + { + aAny = xPropSet->getPropertyValue( sOn ); + sal_Bool bOn = *(sal_Bool *)aAny.getValue(); + + if( !bOn ) + { + // Switch header on + bOn = sal_True; + aAny.setValue( &bOn, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sOn, aAny ); + + // The content has not to be removed, because the header + // or footer is empty already. + bRemoveContent = sal_False; + } + + // If a header or footer is not shared, share it now. + aAny = xPropSet->getPropertyValue( sShareContent ); + sal_Bool bShared = *(sal_Bool *)aAny.getValue(); + if( !bShared ) + { + bShared = sal_True; + aAny.setValue( &bShared, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sShareContent, aAny ); + } + + aAny = xPropSet->getPropertyValue( sText ); + } + + Reference < XText > xText; + aAny >>= xText; + + if( bRemoveContent ) + { + OUString aText; + xText->setString( aText ); + } + + UniReference < XMLTextImportHelper > xTxtImport = + GetImport().GetTextImport(); + + xOldTextCursor = xTxtImport->GetCursor(); + xTxtImport->SetCursor( xText->createTextCursor() ); + } + + pContext = + GetImport().GetTextImport()->CreateTextChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + XML_TEXT_TYPE_HEADER_FOOTER ); + } + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + +void XMLTextHeaderFooterContext::EndElement() +{ + if( xOldTextCursor.is() ) + { + GetImport().GetTextImport()->DeleteParagraph(); + GetImport().GetTextImport()->SetCursor( xOldTextCursor ); + } + else if( !bLeft ) + { + // If no content has been inserted inro the header or footer, + // switch it off. + sal_Bool bOn = sal_False; + Any aAny; + aAny.setValue( &bOn, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sOn, aAny ); + } +} + diff --git a/xmloff/source/text/XMLTextListAutoStylePool.cxx b/xmloff/source/text/XMLTextListAutoStylePool.cxx new file mode 100644 index 000000000000..4422241d822f --- /dev/null +++ b/xmloff/source/text/XMLTextListAutoStylePool.cxx @@ -0,0 +1,319 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <svl/cntnrsrt.hxx> +#include <com/sun/star/ucb/XAnyCompareFactory.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmlnume.hxx> +#include "xmloff/XMLTextListAutoStylePool.hxx" +#include <xmloff/xmlexp.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::style; + + +int XMLTextListAutoStylePoolNameCmp_Impl( const OUString& r1, + const OUString& r2 ) +{ + return (int)r1.compareTo( r2 ); +} + +DECLARE_CONTAINER_SORT_DEL( XMLTextListAutoStylePoolNames_Impl, + OUString ) +IMPL_CONTAINER_SORT( XMLTextListAutoStylePoolNames_Impl, + OUString, + XMLTextListAutoStylePoolNameCmp_Impl ) + +class XMLTextListAutoStylePoolEntry_Impl +{ + OUString sName; + OUString sInternalName; + Reference < XIndexReplace > xNumRules; + sal_uInt32 nPos; + sal_Bool bIsNamed; + + +public: + + XMLTextListAutoStylePoolEntry_Impl( + sal_uInt32 nPos, + const Reference < XIndexReplace > & rNumRules, + XMLTextListAutoStylePoolNames_Impl& rNames, + const OUString& rPrefix, + sal_uInt32& rName ); + + XMLTextListAutoStylePoolEntry_Impl( + const Reference < XIndexReplace > & rNumRules ) : + xNumRules( rNumRules ), + nPos( 0 ), + bIsNamed( sal_False ) + { + Reference < XNamed > xNamed( xNumRules, UNO_QUERY ); + if( xNamed.is() ) + { + sInternalName = xNamed->getName(); + bIsNamed = sal_True; + } + } + + XMLTextListAutoStylePoolEntry_Impl( + const OUString& rInternalName ) : + sInternalName( rInternalName ), + nPos( 0 ), + bIsNamed( sal_True ) + { + } + + const OUString& GetName() const { return sName; } + const OUString& GetInternalName() const { return sInternalName; } + const Reference < XIndexReplace > & GetNumRules() const { return xNumRules; } + sal_uInt32 GetPos() const { return nPos; } + sal_Bool IsNamed() const { return bIsNamed; } +}; + +XMLTextListAutoStylePoolEntry_Impl::XMLTextListAutoStylePoolEntry_Impl( + sal_uInt32 nP, + const Reference < XIndexReplace > & rNumRules, + XMLTextListAutoStylePoolNames_Impl& rNames, + const OUString& rPrefix, + sal_uInt32& rName ) : + xNumRules( rNumRules ), + nPos( nP ), + bIsNamed( sal_False ) +{ + Reference < XNamed > xNamed( xNumRules, UNO_QUERY ); + if( xNamed.is() ) + { + sInternalName = xNamed->getName(); + bIsNamed = sal_True; + } + + // create a name that hasn't been used before. The created name has not + // to be added to the array, because it will never tried again + OUStringBuffer sBuffer( 7 ); + do + { + rName++; + sBuffer.append( rPrefix ); + sBuffer.append( (sal_Int32)rName ); + sName = sBuffer.makeStringAndClear(); + } + while( rNames.Seek_Entry( &sName, 0 ) ); +} + +int XMLTextListAutoStylePoolEntryCmp_Impl( + const XMLTextListAutoStylePoolEntry_Impl& r1, + const XMLTextListAutoStylePoolEntry_Impl& r2 ) +{ + int nRet; + if( r1.IsNamed() ) + { + if( r2.IsNamed() ) + nRet = (int)r1.GetInternalName().compareTo( r2.GetInternalName()); + else + nRet = -1; + } + else + { + if( r2.IsNamed() ) + nRet = 1; + else + nRet = (int)(r1.GetNumRules().get() - r2.GetNumRules().get()); + } + + return nRet; +} + +typedef XMLTextListAutoStylePoolEntry_Impl *XMLTextListAutoStylePoolEntryPtr; +DECLARE_CONTAINER_SORT( XMLTextListAutoStylePool_Impl, + XMLTextListAutoStylePoolEntry_Impl ) +IMPL_CONTAINER_SORT( XMLTextListAutoStylePool_Impl, + XMLTextListAutoStylePoolEntry_Impl, + XMLTextListAutoStylePoolEntryCmp_Impl ) + +XMLTextListAutoStylePool::XMLTextListAutoStylePool( SvXMLExport& rExp ) : + rExport( rExp ), + sPrefix( RTL_CONSTASCII_USTRINGPARAM("L") ), + pPool( new XMLTextListAutoStylePool_Impl( 5, 5 ) ), + pNames( new XMLTextListAutoStylePoolNames_Impl( 5, 5 ) ), + nName( 0 ) +{ + Reference<ucb::XAnyCompareFactory> xCompareFac( rExp.GetModel(), uno::UNO_QUERY ); + if( xCompareFac.is() ) + mxNumRuleCompare = xCompareFac->createAnyCompareByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberingRules" ) ) ); + sal_uInt16 nExportFlags = rExport.getExportFlags(); + sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0; + if( bStylesOnly ) + sPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM("ML") ); + +} + +XMLTextListAutoStylePool::~XMLTextListAutoStylePool() +{ + // The XMLTextListAutoStylePoolEntry_Impl object in the pool need delete explicitly in dtor. + ULONG nCount = pPool->Count(); + while ( nCount-- ) + delete pPool->Remove(nCount); + delete pPool; + + nCount = pNames->Count(); + while ( nCount-- ) + delete pNames->Remove(nCount); + delete pNames; +} + +void XMLTextListAutoStylePool::RegisterName( const OUString& rName ) +{ + OUString *pName = new OUString( rName ); + if( !pNames->Insert( pName ) ) + delete pName; +} + +sal_Bool XMLTextListAutoStylePool::HasName( const OUString& rName ) const +{ + return pNames->Seek_Entry( &rName, 0 ); +} + +sal_uInt32 XMLTextListAutoStylePool::Find( XMLTextListAutoStylePoolEntry_Impl* pEntry ) const +{ + ULONG nPos; + if( !pEntry->IsNamed() && mxNumRuleCompare.is() ) + { + const sal_uInt32 nCount = pPool->Count(); + + uno::Any aAny1, aAny2; + aAny1 <<= pEntry->GetNumRules(); + + for( nPos = 0; nPos < nCount; nPos++ ) + { + aAny2 <<= pPool->GetObject(nPos)->GetNumRules(); + + if( mxNumRuleCompare->compare( aAny1, aAny2 ) == 0 ) + return nPos; + } + } + else if( pPool->Seek_Entry( pEntry, &nPos ) ) + { + return nPos; + } + + return (sal_uInt32)-1; +} + +OUString XMLTextListAutoStylePool::Add( + const Reference < XIndexReplace > & rNumRules ) +{ + OUString sName; + XMLTextListAutoStylePoolEntry_Impl aTmp( rNumRules ); + + sal_uInt32 nPos = Find( &aTmp ); + if( nPos != (sal_uInt32)-1 ) + { + sName = pPool->GetObject( nPos )->GetName(); + } + else + { + XMLTextListAutoStylePoolEntry_Impl *pEntry = + new XMLTextListAutoStylePoolEntry_Impl( pPool->Count(), + rNumRules, *pNames, sPrefix, + nName ); + pPool->Insert( pEntry ); + sName = pEntry->GetName(); + } + + return sName; +} + +::rtl::OUString XMLTextListAutoStylePool::Find( + const Reference < XIndexReplace > & rNumRules ) const +{ + OUString sName; + XMLTextListAutoStylePoolEntry_Impl aTmp( rNumRules ); + + sal_uInt32 nPos = Find( &aTmp ); + if( nPos != (sal_uInt32)-1 ) + sName = pPool->GetObject( nPos )->GetName(); + + return sName; +} + +::rtl::OUString XMLTextListAutoStylePool::Find( + const OUString& rInternalName ) const +{ + OUString sName; + XMLTextListAutoStylePoolEntry_Impl aTmp( rInternalName ); + sal_uInt32 nPos = Find( &aTmp ); + if( nPos != (sal_uInt32)-1 ) + sName = pPool->GetObject( nPos )->GetName(); + + return sName; +} + +void XMLTextListAutoStylePool::exportXML() const +{ + sal_uInt32 nCount = pPool->Count(); + if( !nCount ) + return; + + XMLTextListAutoStylePoolEntry_Impl **aExpEntries = + new XMLTextListAutoStylePoolEntryPtr[nCount]; + + sal_uInt32 i; + for( i=0; i < nCount; i++ ) + { + aExpEntries[i] = 0; + } + for( i=0; i < nCount; i++ ) + { + XMLTextListAutoStylePoolEntry_Impl *pEntry = pPool->GetObject(i); + DBG_ASSERT( pEntry->GetPos() < nCount, "Illegal pos" ); + aExpEntries[pEntry->GetPos()] = pEntry; + } + + SvxXMLNumRuleExport aNumRuleExp( rExport ); + + for( i=0; i < nCount; i++ ) + { + XMLTextListAutoStylePoolEntry_Impl *pEntry = aExpEntries[i]; + aNumRuleExp.exportNumberingRule( pEntry->GetName(), + pEntry->GetNumRules() ); + } + delete [] aExpEntries; +} + + diff --git a/xmloff/source/text/XMLTextListBlockContext.cxx b/xmloff/source/text/XMLTextListBlockContext.cxx new file mode 100644 index 000000000000..25b0ba3078ea --- /dev/null +++ b/xmloff/source/text/XMLTextListBlockContext.cxx @@ -0,0 +1,336 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "XMLTextListItemContext.hxx" +#include "XMLTextListBlockContext.hxx" +#include "txtlists.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +TYPEINIT1( XMLTextListBlockContext, SvXMLImportContext ); + +// OD 2008-05-07 #refactorlists# +// add optional parameter <bRestartNumberingAtSubList> and its handling +XMLTextListBlockContext::XMLTextListBlockContext( + SvXMLImport& rImport, + XMLTextImportHelper& rTxtImp, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + const sal_Bool bRestartNumberingAtSubList ) +: SvXMLImportContext( rImport, nPrfx, rLName ) +, mrTxtImport( rTxtImp ) +// --> OD 2008-04-22 #refactorlists# +, msListStyleName() +// <-- +, mxParentListBlock( ) +, mnLevel( 0 ) +// --> OD 2008-05-07 #refactorlists# +//, mbRestartNumbering( sal_True ) +, mbRestartNumbering( sal_False ) +// <-- +, mbSetDefaults( sal_False ) +// --> OD 2008-04-22 #refactorlists# +, msListId() +, msContinueListId() +// <-- +{ + static ::rtl::OUString s_PropNameDefaultListId( + RTL_CONSTASCII_USTRINGPARAM("DefaultListId")); + { + // get the parent list block context (if any); this is a bit ugly... + XMLTextListBlockContext * pLB(0); + XMLTextListItemContext * pLI(0); + XMLNumberedParaContext * pNP(0); + rTxtImp.GetTextListHelper().ListContextTop(pLB, pLI, pNP); + mxParentListBlock = pLB; + } + // Inherit style name from parent list, as well as the flags whether + // numbering must be restarted and formats have to be created. + OUString sParentListStyleName; + // --> OD 2008-11-27 #158694# + sal_Bool bParentRestartNumbering( sal_False ); + // <-- + if( mxParentListBlock.Is() ) + { + XMLTextListBlockContext *pParent = + (XMLTextListBlockContext *)&mxParentListBlock; + msListStyleName = pParent->GetListStyleName(); + sParentListStyleName = msListStyleName; + mxNumRules = pParent->GetNumRules(); + mnLevel = pParent->GetLevel() + 1; + // --> OD 2008-05-07 #refactorlists# +// mbRestartNumbering = pParent->IsRestartNumbering(); + mbRestartNumbering = pParent->IsRestartNumbering() || + bRestartNumberingAtSubList; + // <-- + // --> OD 2008-11-27 #158694# + bParentRestartNumbering = pParent->IsRestartNumbering(); + // <-- + mbSetDefaults = pParent->mbSetDefaults; + // --> OD 2008-04-22 #refactorlists# + msListId = pParent->GetListId(); + msContinueListId = pParent->GetContinueListId(); + // <-- + } + + const SvXMLTokenMap& rTokenMap = mrTxtImport.GetTextListBlockAttrTokenMap(); + + // --> OD 2008-05-07 #refactorlists# + bool bIsContinueNumberingAttributePresent( false ); + // <-- + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_LIST_BLOCK_XMLID: + sXmlId = rValue; +//FIXME: there is no UNO API for lists + // --> OD 2008-07-31 #i92221# - xml:id is also the list ID + if ( mnLevel == 0 ) // root <list> element + { + msListId = rValue; + } + // <-- + break; + case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING: + mbRestartNumbering = !IsXMLToken(rValue, XML_TRUE); + // --> OD 2008-05-07 #refactorlists# + bIsContinueNumberingAttributePresent = true; + // <-- + break; + case XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME: + msListStyleName = rValue; + break; + // --> OD 2008-04-22 #refactorlists# + case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST: + if ( mnLevel == 0 ) // root <list> element + { + msContinueListId = rValue; + } + break; + } + } + + mxNumRules = XMLTextListsHelper::MakeNumRule(GetImport(), mxNumRules, + sParentListStyleName, msListStyleName, + mnLevel, &mbRestartNumbering, &mbSetDefaults ); + if( !mxNumRules.is() ) + return; + + // --> OD 2008-04-23 #refactorlists# + if ( mnLevel == 0 ) // root <list> element + { + XMLTextListsHelper& rTextListsHelper( mrTxtImport.GetTextListHelper() ); + // --> OD 2008-08-15 #i92811# + ::rtl::OUString sListStyleDefaultListId; + { + uno::Reference< beans::XPropertySet > xNumRuleProps( mxNumRules, UNO_QUERY ); + if ( xNumRuleProps.is() ) + { + uno::Reference< beans::XPropertySetInfo > xNumRulePropSetInfo( + xNumRuleProps->getPropertySetInfo()); + if (xNumRulePropSetInfo.is() && + xNumRulePropSetInfo->hasPropertyByName( + s_PropNameDefaultListId)) + { + xNumRuleProps->getPropertyValue(s_PropNameDefaultListId) + >>= sListStyleDefaultListId; + DBG_ASSERT( sListStyleDefaultListId.getLength() != 0, + "no default list id found at numbering rules instance. Serious defect -> please inform OD." ); + } + } + } + // <-- + if ( msListId.getLength() == 0 ) // no text:id property found + { + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild ); + if ( rImport.IsTextDocInOOoFileFormat() || + ( bBuildIdFound && nUPD == 680 ) ) + { + // handling former documents written by OpenOffice.org: + // use default list id of numbering rules instance, if existing + // --> OD 2008-08-15 #i92811# + if ( sListStyleDefaultListId.getLength() != 0 ) + { + msListId = sListStyleDefaultListId; + if ( !bIsContinueNumberingAttributePresent && + !mbRestartNumbering && + rTextListsHelper.IsListProcessed( msListId ) ) + { + mbRestartNumbering = sal_True; + } + } + // <-- + } + if ( msListId.getLength() == 0 ) + { + // generate a new list id for the list + msListId = rTextListsHelper.GenerateNewListId(); + } + } + + if ( bIsContinueNumberingAttributePresent && !mbRestartNumbering && + msContinueListId.getLength() == 0 ) + { + ::rtl::OUString Last( rTextListsHelper.GetLastProcessedListId() ); + if ( rTextListsHelper.GetListStyleOfLastProcessedList() == msListStyleName + && Last != msListId ) + { + msContinueListId = Last; + } + } + + if ( msContinueListId.getLength() > 0 ) + { + if ( !rTextListsHelper.IsListProcessed( msContinueListId ) ) + { + msContinueListId = ::rtl::OUString(); + } + else + { + // search continue list chain for master list and + // continue the master list. + ::rtl::OUString sTmpStr = + rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId ); + while ( sTmpStr.getLength() > 0 ) + { + msContinueListId = sTmpStr; + + sTmpStr = + rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId ); + } + } + } + + if ( !rTextListsHelper.IsListProcessed( msListId ) ) + { + // --> OD 2008-08-15 #i92811# + rTextListsHelper.KeepListAsProcessed( + msListId, msListStyleName, msContinueListId, + sListStyleDefaultListId ); + // <-- + } + } + // <-- + + // Remember this list block. + mrTxtImport.GetTextListHelper().PushListContext( this ); +} + +XMLTextListBlockContext::~XMLTextListBlockContext() +{ +} + +void XMLTextListBlockContext::EndElement() +{ + // Numbering has not to be restarted if it has been restarted within + // a child list. + XMLTextListBlockContext *pParent = + (XMLTextListBlockContext *)&mxParentListBlock; + if( pParent ) + { + pParent->mbRestartNumbering = mbRestartNumbering; + } + + // Restore current list block. + mrTxtImport.GetTextListHelper().PopListContext(); + + // Any paragraph following the list within the same list item must not + // be numbered. + mrTxtImport.GetTextListHelper().SetListItem( 0 ); +} + +SvXMLImportContext *XMLTextListBlockContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + const SvXMLTokenMap& rTokenMap = + mrTxtImport.GetTextListBlockElemTokenMap(); + sal_Bool bHeader = sal_False; + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_TEXT_LIST_HEADER: + bHeader = sal_True; + case XML_TOK_TEXT_LIST_ITEM: + pContext = new XMLTextListItemContext( GetImport(), mrTxtImport, + nPrefix, rLocalName, + xAttrList, bHeader ); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + +// --> OD 2008-04-22 #refactorlists# +const ::rtl::OUString& XMLTextListBlockContext::GetListId() const +{ + return msListId; +} + +const ::rtl::OUString& XMLTextListBlockContext::GetContinueListId() const +{ + return msContinueListId; +} +// <-- + diff --git a/xmloff/source/text/XMLTextListBlockContext.hxx b/xmloff/source/text/XMLTextListBlockContext.hxx new file mode 100644 index 000000000000..bd8011b631f7 --- /dev/null +++ b/xmloff/source/text/XMLTextListBlockContext.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLTEXTLISTBLOCKCONTEXT_HXX +#define _XMLTEXTLISTBLOCKCONTEXT_HXX + +#include <com/sun/star/container/XIndexReplace.hpp> +#include <xmloff/xmlictxt.hxx> + +class XMLTextImportHelper; + +class XMLTextListBlockContext : public SvXMLImportContext +{ + XMLTextImportHelper& mrTxtImport; + + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexReplace > mxNumRules; + + // text:style-name property of <list> element + ::rtl::OUString msListStyleName; + ::rtl::OUString sXmlId; + + SvXMLImportContextRef mxParentListBlock; + + sal_Int16 mnLevel; + sal_Bool mbRestartNumbering; + sal_Bool mbSetDefaults; + + // --> OD 2008-04-22 #refactorlists# + // text:id property of <list> element, only valid for root <list> element + ::rtl::OUString msListId; + // text:continue-list property of <list> element, only valid for root <list> element + ::rtl::OUString msContinueListId; + // <-- + +public: + + TYPEINFO(); + + // --> OD 2008-05-07 #refactorlists# + // add optional parameter <bRestartNumberingAtSubList> + XMLTextListBlockContext( + SvXMLImport& rImport, + XMLTextImportHelper& rTxtImp, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const sal_Bool bRestartNumberingAtSubList = sal_False ); + // <-- + virtual ~XMLTextListBlockContext(); + + virtual void EndElement(); + + SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + const ::rtl::OUString& GetListStyleName() const { return msListStyleName; } + sal_Int16 GetLevel() const { return mnLevel; } + sal_Bool IsRestartNumbering() const { return mbRestartNumbering; } + void ResetRestartNumbering() { mbRestartNumbering = sal_False; } + + const ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace >& GetNumRules() const + { return mxNumRules; } + + // --> OD 2008-04-22 #refactorlists# + const ::rtl::OUString& GetListId() const; + const ::rtl::OUString& GetContinueListId() const; + // <-- + +}; + + +#endif diff --git a/xmloff/source/text/XMLTextListItemContext.cxx b/xmloff/source/text/XMLTextListItemContext.cxx new file mode 100644 index 000000000000..d8effc0180de --- /dev/null +++ b/xmloff/source/text/XMLTextListItemContext.cxx @@ -0,0 +1,197 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "txtparai.hxx" +#include "txtlists.hxx" +#include "XMLTextListBlockContext.hxx" +#include <xmloff/txtimp.hxx> +// --> OD 2008-05-08 #refactorlists# +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <xmloff/xmlnumi.hxx> +// <-- + +#include "XMLTextListItemContext.hxx" + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +TYPEINIT1( XMLTextListItemContext, SvXMLImportContext ); + +XMLTextListItemContext::XMLTextListItemContext( + SvXMLImport& rImport, + XMLTextImportHelper& rTxtImp, + const sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + const sal_Bool bIsHeader ) + : SvXMLImportContext( rImport, nPrfx, rLName ), + rTxtImport( rTxtImp ), + nStartValue( -1 ), + // --> OD 2008-05-07 #refactorlists# + mnSubListCount( 0 ), + mxNumRulesOverride() + // <-- +{ + static ::rtl::OUString s_NumberingRules( + RTL_CONSTASCII_USTRINGPARAM("NumberingRules")); + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_START_VALUE ) ) + { + sal_Int32 nTmp = rValue.toInt32(); + if( nTmp >= 0 && nTmp <= SHRT_MAX ) + nStartValue = (sal_Int16)nTmp; + } + // --> OD 2008-05-08 #refactorlists# + else if ( nPrefix == XML_NAMESPACE_TEXT && + IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) ) + { + const ::rtl::OUString sListStyleOverrideName = rValue; + if ( sListStyleOverrideName.getLength() > 0 ) + { + OUString sDisplayStyleName( + GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST, + sListStyleOverrideName ) ); + const Reference < container::XNameContainer >& rNumStyles = + rTxtImp.GetNumberingStyles(); + if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) ) + { + Reference < style::XStyle > xStyle; + Any aAny = rNumStyles->getByName( sDisplayStyleName ); + aAny >>= xStyle; + + uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY ); + aAny = xPropSet->getPropertyValue(s_NumberingRules); + aAny >>= mxNumRulesOverride; + } + else + { + const SvxXMLListStyleContext* pListStyle = + rTxtImp.FindAutoListStyle( sListStyleOverrideName ); + if( pListStyle ) + { + mxNumRulesOverride = pListStyle->GetNumRules(); + if( !mxNumRulesOverride.is() ) + { + pListStyle->CreateAndInsertAuto(); + mxNumRulesOverride = pListStyle->GetNumRules(); + } + } + } + } + } + // <-- + else if ( (XML_NAMESPACE_XML == nPrefix) && + IsXMLToken(aLocalName, XML_ID) ) + { + (void) rValue; +//FIXME: there is no UNO API for list items + } + } + + // If this is a <text:list-item> element, then remember it as a sign + // that a bullet has to be generated. + if( !bIsHeader ) { + rTxtImport.GetTextListHelper().SetListItem( this ); + } + +} + +XMLTextListItemContext::~XMLTextListItemContext() +{ +} + +void XMLTextListItemContext::EndElement() +{ + // finish current list item + rTxtImport.GetTextListHelper().SetListItem( 0 ); +} + +SvXMLImportContext *XMLTextListItemContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap(); + sal_Bool bHeading = sal_False; + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_TEXT_H: + bHeading = sal_True; + case XML_TOK_TEXT_P: + pContext = new XMLParaContext( GetImport(), + nPrefix, rLocalName, + xAttrList, bHeading ); + if (rTxtImport.IsProgress()) + GetImport().GetProgressBarHelper()->Increment(); + + break; + case XML_TOK_TEXT_LIST: + // --> OD 2008-05-07 #refactorlists# +// pContext = new XMLTextListBlockContext( GetImport(), rTxtImport, +// nPrefix, rLocalName, +// xAttrList ); + ++mnSubListCount; + pContext = new XMLTextListBlockContext( GetImport(), rTxtImport, + nPrefix, rLocalName, + xAttrList, + (mnSubListCount > 1) ); + // <-- + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + + diff --git a/xmloff/source/text/XMLTextListItemContext.hxx b/xmloff/source/text/XMLTextListItemContext.hxx new file mode 100644 index 000000000000..81441a95880b --- /dev/null +++ b/xmloff/source/text/XMLTextListItemContext.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLTEXTLISTITEMCONTEXT_HXX +#define _XMLTEXTLISTITEMCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> + +class XMLTextImportHelper; + +class XMLTextListItemContext : public SvXMLImportContext +{ + XMLTextImportHelper& rTxtImport; + + sal_Int16 nStartValue; + + // --> OD 2008-05-07 #refactorlists# + // quantity of <text:list> child elements + sal_Int16 mnSubListCount; + // list style instance for text::style-override property + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexReplace > mxNumRulesOverride; + // <-- + +public: + + TYPEINFO(); + + XMLTextListItemContext( + SvXMLImport& rImport, + XMLTextImportHelper& rTxtImp, + const sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const sal_Bool bIsHeader = sal_False ); + virtual ~XMLTextListItemContext(); + + virtual void EndElement(); + + SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + sal_Bool HasStartValue() const { return -1 != nStartValue; } + sal_Int16 GetStartValue() const { return nStartValue; } + + // --> OD 2008-05-08 #refactorlists# + inline sal_Bool HasNumRulesOverride() const + { + return mxNumRulesOverride.is(); + } + inline const ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace >& GetNumRulesOverride() const + { + return mxNumRulesOverride; + } +}; + + +#endif diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx new file mode 100644 index 000000000000..4ac42d4abebd --- /dev/null +++ b/xmloff/source/text/XMLTextMarkImportContext.cxx @@ -0,0 +1,485 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLTextMarkImportContext.hxx" + + +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/odffields.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/rdf/XMetadatable.hpp> + +#include <com/sun/star/text/XFormField.hpp> + +#include "RDFaImportHelper.hxx" + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::xml::sax; +using namespace ::xmloff::token; + + +XMLFieldParamImportContext::XMLFieldParamImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrefix, + const OUString& rLocalName ) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + rHelper(rHlp) +{ +} + + +void XMLFieldParamImportContext::StartElement(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList) +{ + SvXMLImport& rImport = GetImport(); + ::rtl::OUString sName; + ::rtl::OUString sValue; + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if ( (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_NAME) ) + { + sName = xAttrList->getValueByIndex(nAttr); + } + if ( (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_VALUE) ) + { + sValue = xAttrList->getValueByIndex(nAttr); + } + } + if (rHelper.hasCurrentFieldCtx() && sName.getLength()>0) { + rHelper.addFieldParam(sName, sValue); + } +} + + +TYPEINIT1( XMLTextMarkImportContext, SvXMLImportContext); + +XMLTextMarkImportContext::XMLTextMarkImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrefix, + const OUString& rLocalName ) + : SvXMLImportContext(rImport, nPrefix, rLocalName) + , m_rHelper(rHlp) + , m_bHaveAbout(false) +{ +} + +enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd, + TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd, + TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd + }; + +static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] = +{ + { XML_REFERENCE_MARK, TypeReference }, + { XML_REFERENCE_MARK_START, TypeReferenceStart }, + { XML_REFERENCE_MARK_END, TypeReferenceEnd }, + { XML_BOOKMARK, TypeBookmark }, + { XML_BOOKMARK_START, TypeBookmarkStart }, + { XML_BOOKMARK_END, TypeBookmarkEnd }, + { XML_FIELDMARK, TypeFieldmark }, + { XML_FIELDMARK_START, TypeFieldmarkStart }, + { XML_FIELDMARK_END, TypeFieldmarkEnd }, + { XML_TOKEN_INVALID, 0 }, +}; + + +static const char *lcl_getFormFieldmarkName(rtl::OUString &name) +{ + static const char sCheckbox[]=ODF_FORMCHECKBOX; + static const char sFormDropDown[]=ODF_FORMDROPDOWN; + if (name.compareToAscii("msoffice.field.FORMCHECKBOX")==0) + return sCheckbox; + else if (name.compareToAscii(ODF_FORMCHECKBOX)==0) + return sCheckbox; + if (name.compareToAscii(ODF_FORMDROPDOWN)==0) + return sFormDropDown; + else + return NULL; +} + +static rtl::OUString lcl_getFieldmarkName(rtl::OUString &name) +{ + static const char sFormtext[]=ODF_FORMTEXT; + if (name.compareToAscii("msoffice.field.FORMTEXT")==0) + return rtl::OUString::createFromAscii(sFormtext); + else if (name.compareToAscii(ODF_FORMTEXT)==0) + return rtl::OUString::createFromAscii(sFormtext); + else + return name; +} + + +void XMLTextMarkImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + if (!FindName(GetImport(), xAttrList)) + { + m_sBookmarkName = OUString(); + } + + if (IsXMLToken(GetLocalName(), XML_FIELDMARK_END)) + { + m_sBookmarkName = m_rHelper.FindActiveBookmarkName(); + } + + if (IsXMLToken(GetLocalName(), XML_FIELDMARK_START) || IsXMLToken(GetLocalName(), XML_FIELDMARK)) + { + if (m_sBookmarkName.getLength() == 0) + { + m_sBookmarkName = ::rtl::OUString::createFromAscii("Unknown"); + } + m_rHelper.pushFieldCtx( m_sBookmarkName, m_sFieldName ); + } +} + +void XMLTextMarkImportContext::EndElement() +{ + SvXMLImportContext::EndElement(); + + static const OUString sAPI_reference_mark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ReferenceMark")); + static const OUString sAPI_bookmark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark")); + static const OUString sAPI_fieldmark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Fieldmark")); + static const OUString sAPI_formfieldmark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.FormFieldmark")); + + if (m_sBookmarkName.getLength() > 0) + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, GetLocalName(), + lcl_aMarkTypeMap)) + { + switch ((lcl_MarkType)nTmp) + { + case TypeReference: + // export point reference mark + CreateAndInsertMark(GetImport(), + sAPI_reference_mark, + m_sBookmarkName, + m_rHelper.GetCursorAsRange()->getStart(), + ::rtl::OUString()); + break; + + case TypeFieldmark: + case TypeBookmark: + { + const char *formFieldmarkName=lcl_getFormFieldmarkName(m_sFieldName); + bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && formFieldmarkName!=NULL); //@TODO handle abbreviation cases.. + // export point bookmark + const Reference<XInterface> xContent( + CreateAndInsertMark(GetImport(), + (bImportAsField?sAPI_formfieldmark:sAPI_bookmark), + m_sBookmarkName, + m_rHelper.GetCursorAsRange()->getStart(), + m_sXmlId) ); + if ((lcl_MarkType)nTmp==TypeFieldmark) { + if (xContent.is() && bImportAsField) { + // setup fieldmark... + Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY); + xFormField->setFieldType(rtl::OUString::createFromAscii(formFieldmarkName)); + if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) { + m_rHelper.setCurrentFieldParamsTo(xFormField); + } + } + m_rHelper.popFieldCtx(); + } + } + break; + + case TypeFieldmarkStart: + case TypeBookmarkStart: + // save XTextRange for later construction of bookmark + { + ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes > + pRDFaAttributes; + if (m_bHaveAbout && (TypeBookmarkStart + == static_cast<lcl_MarkType>(nTmp))) + { + pRDFaAttributes = + GetImport().GetRDFaImportHelper().ParseRDFa( + m_sAbout, m_sProperty, + m_sContent, m_sDatatype); + } + m_rHelper.InsertBookmarkStartRange( + m_sBookmarkName, + m_rHelper.GetCursorAsRange()->getStart(), + m_sXmlId, pRDFaAttributes); + } + break; + + case TypeFieldmarkEnd: + case TypeBookmarkEnd: + { + // get old range, and construct + Reference<XTextRange> xStartRange; + ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes > + pRDFaAttributes; + if (m_rHelper.FindAndRemoveBookmarkStartRange( + m_sBookmarkName, xStartRange, + m_sXmlId, pRDFaAttributes)) + { + Reference<XTextRange> xEndRange( + m_rHelper.GetCursorAsRange()->getStart()); + + // check if beginning and end are in same XText + if (xStartRange->getText() == xEndRange->getText()) + { + // create range for insertion + Reference<XTextCursor> xInsertionCursor = + m_rHelper.GetText()->createTextCursorByRange( + xEndRange); + try { + xInsertionCursor->gotoRange(xStartRange, sal_True); + } catch (uno::Exception&) { + OSL_ENSURE(false, + "cannot go to end position of bookmark"); + } + + //DBG_ASSERT(! xInsertionCursor->isCollapsed(), + // "we want no point mark"); + // can't assert, because someone could + // create a file with subsequence + // start/end elements + + Reference<XTextRange> xInsertionRange( + xInsertionCursor, UNO_QUERY); + + bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmarkEnd && m_rHelper.hasCurrentFieldCtx()); + + // insert reference + const Reference<XInterface> xContent( + CreateAndInsertMark(GetImport(), + (bImportAsField?sAPI_fieldmark:sAPI_bookmark), + m_sBookmarkName, + xInsertionRange, + m_sXmlId) ); + if (pRDFaAttributes) + { + const Reference<rdf::XMetadatable> + xMeta(xContent, UNO_QUERY); + GetImport().GetRDFaImportHelper().AddRDFa( + xMeta, pRDFaAttributes); + } + + if ((lcl_MarkType)nTmp==TypeFieldmarkEnd) { + if (xContent.is() && bImportAsField) { + // setup fieldmark... + Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY); + if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) { + rtl::OUString givenTypeName=m_rHelper.getCurrentFieldType(); + rtl::OUString fieldmarkTypeName=lcl_getFieldmarkName(givenTypeName); + + xFormField->setFieldType(fieldmarkTypeName); + m_rHelper.setCurrentFieldParamsTo(xFormField); + } + } + m_rHelper.popFieldCtx(); + } + } + // else: beginning/end in different XText -> ignore! + } + // else: no start found -> ignore! + break; + } + + case TypeReferenceStart: + case TypeReferenceEnd: + DBG_ERROR("reference start/end are handled in txtparai !"); + break; + + default: + DBG_ERROR("unknown mark type"); + break; + } + } + } +} + +SvXMLImportContext *XMLTextMarkImportContext::CreateChildContext( USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) +{ + return new XMLFieldParamImportContext(GetImport(), m_rHelper, + nPrefix, rLocalName); +} + + +Reference<XTextContent> XMLTextMarkImportContext::CreateAndInsertMark( + SvXMLImport& rImport, + const OUString& sServiceName, + const OUString& sMarkName, + const Reference<XTextRange> & rRange, + const OUString& i_rXmlId) +{ + // create mark + const Reference<XMultiServiceFactory> xFactory(rImport.GetModel(), + UNO_QUERY); + Reference<XInterface> xIfc; + + if (xFactory.is()) + { + xIfc = xFactory->createInstance(sServiceName); + + if (!xIfc.is()) + { + OSL_ENSURE(false, "CreateAndInsertMark: cannot create service?"); + return 0; + } + + // set name (unless there is no name (text:meta)) + const Reference<XNamed> xNamed(xIfc, UNO_QUERY); + if (xNamed.is()) + { + xNamed->setName(sMarkName); + } + else + { + if (sMarkName.getLength()) + { + OSL_ENSURE(false, "name given, but XNamed not supported?"); + return 0; + } + } + + // cast to XTextContent and attach to document + const Reference<XTextContent> xTextContent(xIfc, UNO_QUERY); + if (xTextContent.is()) + { + try + { + // if inserting marks, bAbsorb==sal_False will cause + // collapsing of the given XTextRange. + rImport.GetTextImport()->GetText()->insertTextContent(rRange, + xTextContent, sal_True); + + // xml:id for RDF metadata -- after insertion! + rImport.SetXmlId(xIfc, i_rXmlId); + + return xTextContent; + } + catch (com::sun::star::lang::IllegalArgumentException &) + { + OSL_ENSURE(false, "CreateAndInsertMark: cannot insert?"); + return 0; + } + } + } + return 0; +} + +sal_Bool XMLTextMarkImportContext::FindName( + SvXMLImport& rImport, + const Reference<XAttributeList> & xAttrList) +{ + sal_Bool bNameOK = sal_False; + + // find name attribute first + const sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + const sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken(sLocalName, XML_NAME) ) + { + m_sBookmarkName = xAttrList->getValueByIndex(nAttr); + bNameOK = sal_True; + } + else if ( (XML_NAMESPACE_XML == nPrefix) && + IsXMLToken(sLocalName, XML_ID) ) + { + m_sXmlId = xAttrList->getValueByIndex(nAttr); + } + else if ( XML_NAMESPACE_XHTML == nPrefix ) + { + // RDFa + if ( IsXMLToken( sLocalName, XML_ABOUT) ) + { + m_sAbout = xAttrList->getValueByIndex(nAttr); + m_bHaveAbout = true; + } + else if ( IsXMLToken( sLocalName, XML_PROPERTY) ) + { + m_sProperty = xAttrList->getValueByIndex(nAttr); + } + else if ( IsXMLToken( sLocalName, XML_CONTENT) ) + { + m_sContent = xAttrList->getValueByIndex(nAttr); + } + else if ( IsXMLToken( sLocalName, XML_DATATYPE) ) + { + m_sDatatype = xAttrList->getValueByIndex(nAttr); + } + } + else if ( (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_TYPE) ) + { + m_sFieldName = xAttrList->getValueByIndex(nAttr); + } + } + + return bNameOK; +} + diff --git a/xmloff/source/text/XMLTextMarkImportContext.hxx b/xmloff/source/text/XMLTextMarkImportContext.hxx new file mode 100644 index 000000000000..c2c6a701ef8b --- /dev/null +++ b/xmloff/source/text/XMLTextMarkImportContext.hxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLTEXTMARKIMPORTCONTEXT_HXX +#define _XMLOFF_XMLTEXTMARKIMPORTCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace text { + class XTextRange; + class XTextContent; + } + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} +class XMLTextImportHelper; + +class XMLFieldParamImportContext : public SvXMLImportContext +{ + XMLTextImportHelper& rHelper; +public: + XMLFieldParamImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); +}; + + +/** + * import bookmarks and reference marks + * ( <bookmark>, <bookmark-start>, <bookmark-end>, + * <reference>, <reference-start>, <reference-end> ) + * + * All elements are handled by the same class due to their similarities. + */ +class XMLTextMarkImportContext : public SvXMLImportContext +{ + + XMLTextImportHelper & m_rHelper; + ::rtl::OUString m_sBookmarkName; + ::rtl::OUString m_sFieldName; + ::rtl::OUString m_sXmlId; + // RDFa + bool m_bHaveAbout; + ::rtl::OUString m_sAbout; + ::rtl::OUString m_sProperty; + ::rtl::OUString m_sContent; + ::rtl::OUString m_sDatatype; + +public: + + TYPEINFO(); + + XMLTextMarkImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName ); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + +public: + static ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextContent > CreateAndInsertMark( + SvXMLImport& rImport, + const ::rtl::OUString& sServiceName, + const ::rtl::OUString& sMarkName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange> & rRange, + const ::rtl::OUString& i_rXmlId = ::rtl::OUString()); + + sal_Bool FindName( + SvXMLImport& rImport, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); +}; + +#endif diff --git a/xmloff/source/text/XMLTextMasterPageContext.cxx b/xmloff/source/text/XMLTextMasterPageContext.cxx new file mode 100644 index 000000000000..ba097f542098 --- /dev/null +++ b/xmloff/source/text/XMLTextMasterPageContext.cxx @@ -0,0 +1,293 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/style/PageStyleLayout.hpp> +#include <com/sun/star/beans/XMultiPropertyStates.hpp> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/XMLTextMasterPageContext.hxx> +#include "XMLTextHeaderFooterContext.hxx" +#include <xmloff/xmlimp.hxx> +#include "PageMasterImportContext.hxx" + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +//using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +Reference < XStyle > XMLTextMasterPageContext::Create() +{ + Reference < XStyle > xNewStyle; + + Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), + UNO_QUERY ); + if( xFactory.is() ) + { + Reference < XInterface > xIfc = + xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.style.PageStyle")) ); + if( xIfc.is() ) + xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY ); + } + + return xNewStyle; +} +TYPEINIT1( XMLTextMasterPageContext, SvXMLStyleContext ); + +XMLTextMasterPageContext::XMLTextMasterPageContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + sal_Bool bOverwrite ) +: SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_MASTER_PAGE ) +, sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ) +, sPageStyleLayout( RTL_CONSTASCII_USTRINGPARAM( "PageStyleLayout" ) ) +, sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ) +, bInsertHeader( sal_False ) +, bInsertFooter( sal_False ) +, bInsertHeaderLeft( sal_False ) +, bInsertFooterLeft( sal_False ) +, bHeaderInserted( sal_False ) +, bFooterInserted( sal_False ) +, bHeaderLeftInserted( sal_False ) +, bFooterLeftInserted( sal_False ) +{ + OUString sName, sDisplayName; + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); + if( XML_NAMESPACE_STYLE == nPrefix ) + { + if( IsXMLToken( aLocalName, XML_NAME ) ) + { + sName = xAttrList->getValueByIndex( i ); + } + else if( IsXMLToken( aLocalName, XML_DISPLAY_NAME ) ) + { + sDisplayName = xAttrList->getValueByIndex( i ); + } + else if( IsXMLToken( aLocalName, XML_NEXT_STYLE_NAME ) ) + { + sFollow = xAttrList->getValueByIndex( i ); + } + else if( IsXMLToken( aLocalName, XML_PAGE_LAYOUT_NAME ) ) + { + sPageMasterName = xAttrList->getValueByIndex( i ); + } + } + } + + if( sDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sName, + sDisplayName ); + } + else + { + sDisplayName = sName; + } + + if( 0 == sDisplayName.getLength() ) + return; + + Reference < XNameContainer > xPageStyles = + GetImport().GetTextImport()->GetPageStyles(); + if( !xPageStyles.is() ) + return; + + Any aAny; + sal_Bool bNew = sal_False; + if( xPageStyles->hasByName( sDisplayName ) ) + { + aAny = xPageStyles->getByName( sDisplayName ); + aAny >>= xStyle; + } + else + { + xStyle = Create(); + if( !xStyle.is() ) + return; + + aAny <<= xStyle; + xPageStyles->insertByName( sDisplayName, aAny ); + bNew = sal_True; + } + + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + aAny = xPropSet->getPropertyValue( sIsPhysical ); + bNew = !*(sal_Bool *)aAny.getValue(); + } + SetNew( bNew ); + + if( bOverwrite || bNew ) + { + Reference < XMultiPropertyStates > xMultiStates( xPropSet, + UNO_QUERY ); + OSL_ENSURE( xMultiStates.is(), + "text page style does not support multi property set" ); + if( xMultiStates.is() ) + xMultiStates->setAllPropertiesToDefault(); + + bInsertHeader = bInsertFooter = sal_True; + bInsertHeaderLeft = bInsertFooterLeft = sal_True; + } +} + +XMLTextMasterPageContext::~XMLTextMasterPageContext() +{ +} + +SvXMLImportContext *XMLTextMasterPageContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextMasterPageElemTokenMap(); + + sal_Bool bInsert = sal_False, bFooter = sal_False, bLeft = sal_False; + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_TEXT_MP_HEADER: + if( bInsertHeader && !bHeaderInserted ) + { + bInsert = sal_True; + bHeaderInserted = sal_True; + } + break; + case XML_TOK_TEXT_MP_FOOTER: + if( bInsertFooter && !bFooterInserted ) + { + bInsert = bFooter = sal_True; + bFooterInserted = sal_True; + } + break; + case XML_TOK_TEXT_MP_HEADER_LEFT: + if( bInsertHeaderLeft && bHeaderInserted && !bHeaderLeftInserted ) + bInsert = bLeft = sal_True; + break; + case XML_TOK_TEXT_MP_FOOTER_LEFT: + if( bInsertFooterLeft && bFooterInserted && !bFooterLeftInserted ) + bInsert = bFooter = bLeft = sal_True; + break; + } + + if( bInsert && xStyle.is() ) + { + pContext = CreateHeaderFooterContext( nPrefix, rLocalName, + xAttrList, + bFooter, bLeft ); + } + else + { + pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + } + + return pContext; +} + +SvXMLImportContext *XMLTextMasterPageContext::CreateHeaderFooterContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const sal_Bool bFooter, + const sal_Bool bLeft ) +{ + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + return new XMLTextHeaderFooterContext( GetImport(), + nPrefix, rLocalName, + xAttrList, + xPropSet, + bFooter, bLeft ); +} + +void XMLTextMasterPageContext::Finish( sal_Bool bOverwrite ) +{ + if( xStyle.is() && (IsNew() || bOverwrite) ) + { + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + if( sPageMasterName.getLength() ) + { + XMLPropStyleContext* pStyle = + GetImport().GetTextImport()->FindPageMaster( sPageMasterName ); + if (pStyle) + { + pStyle->FillPropertySet(xPropSet); + } + } + + Reference < XNameContainer > xPageStyles = + GetImport().GetTextImport()->GetPageStyles(); + if( !xPageStyles.is() ) + return; + + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( sFollowStyle ) ) + { + OUString sDisplayFollow( + GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_MASTER_PAGE, sFollow ) ); + if( !sDisplayFollow.getLength() || + !xPageStyles->hasByName( sDisplayFollow ) ) + sDisplayFollow = xStyle->getName(); + + Any aAny = xPropSet->getPropertyValue( sFollowStyle ); + OUString sCurrFollow; + aAny >>= sCurrFollow; + if( sCurrFollow != sDisplayFollow ) + { + aAny <<= sDisplayFollow; + xPropSet->setPropertyValue( sFollowStyle, aAny ); + } + } + } +} diff --git a/xmloff/source/text/XMLTextMasterPageExport.cxx b/xmloff/source/text/XMLTextMasterPageExport.cxx new file mode 100644 index 000000000000..dbffabc3d920 --- /dev/null +++ b/xmloff/source/text/XMLTextMasterPageExport.cxx @@ -0,0 +1,185 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <xmloff/xmlexp.hxx> +#include <xmloff/XMLTextMasterPageExport.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport& rExp ) : + XMLPageExport( rExp ), + sHeaderText( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) ), + sHeaderOn( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" ) ), + sHeaderShareContent( RTL_CONSTASCII_USTRINGPARAM( "HeaderIsShared" ) ), + sHeaderTextLeft( RTL_CONSTASCII_USTRINGPARAM( "HeaderTextLeft" ) ), + sFooterText( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) ), + sFooterOn( RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" ) ), + sFooterShareContent( RTL_CONSTASCII_USTRINGPARAM( "FooterIsShared" ) ), + sFooterTextLeft( RTL_CONSTASCII_USTRINGPARAM( "FooterTextLeft" ) ) +{ +} + +XMLTextMasterPageExport::~XMLTextMasterPageExport() +{ +} + + +void XMLTextMasterPageExport::exportHeaderFooterContent( + const Reference< XText >& rText, + sal_Bool bAutoStyles, sal_Bool bExportParagraph ) +{ + DBG_ASSERT( rText.is(), "There is the text" ); + + // tracked changes (autostyles + changes list) + GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText); + GetExport().GetTextParagraphExport()->exportTrackedChanges(rText, + bAutoStyles); + if( bAutoStyles ) + GetExport().GetTextParagraphExport() + ->collectTextAutoStyles( rText, sal_True, bExportParagraph ); + else + { + GetExport().GetTextParagraphExport()->exportTextDeclarations( rText ); + GetExport().GetTextParagraphExport()->exportText( rText, sal_True, bExportParagraph ); + } + + // tracked changes (end of XText) + GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText(); +} + +void XMLTextMasterPageExport::exportMasterPageContent( + const Reference < XPropertySet > & rPropSet, + sal_Bool bAutoStyles ) +{ + Any aAny; + + Reference < XText > xHeaderText; + aAny = rPropSet->getPropertyValue( sHeaderText ); + aAny >>= xHeaderText; + + Reference < XText > xHeaderTextLeft; + aAny = rPropSet->getPropertyValue( sHeaderTextLeft ); + aAny >>= xHeaderTextLeft; + + Reference < XText > xFooterText; + aAny = rPropSet->getPropertyValue( sFooterText ); + aAny >>= xFooterText; + + Reference < XText > xFooterTextLeft; + aAny = rPropSet->getPropertyValue( sFooterTextLeft ); + aAny >>= xFooterTextLeft; + + if( bAutoStyles ) + { + if( xHeaderText.is() ) + exportHeaderFooterContent( xHeaderText, sal_True ); + if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText ) + exportHeaderFooterContent( xHeaderTextLeft, sal_True ); + if( xFooterText.is() ) + exportHeaderFooterContent( xFooterText, sal_True ); + if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText ) + exportHeaderFooterContent( xFooterTextLeft, sal_True ); + } + else + { + aAny = rPropSet->getPropertyValue( sHeaderOn ); + sal_Bool bHeader = *(sal_Bool *)aAny.getValue(); + + sal_Bool bHeaderLeft = sal_False; + if( bHeader ) + { + aAny = rPropSet->getPropertyValue( sHeaderShareContent ); + bHeaderLeft = !*(sal_Bool *)aAny.getValue(); + } + + if( xHeaderText.is() ) + { + if( !bHeader ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DISPLAY, XML_FALSE ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_HEADER, sal_True, sal_True ); + exportHeaderFooterContent( xHeaderText, sal_False ); + } + + if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText ) + { + if( !bHeaderLeft ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DISPLAY, XML_FALSE ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_HEADER_LEFT, sal_True, sal_True ); + exportHeaderFooterContent( xHeaderTextLeft, sal_False ); + } + + aAny = rPropSet->getPropertyValue( sFooterOn ); + sal_Bool bFooter = *(sal_Bool *)aAny.getValue(); + + sal_Bool bFooterLeft = sal_False; + if( bFooter ) + { + aAny = rPropSet->getPropertyValue( sFooterShareContent ); + bFooterLeft = !*(sal_Bool *)aAny.getValue(); + } + + if( xFooterText.is() ) + { + if( !bFooter ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DISPLAY, XML_FALSE ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_FOOTER, sal_True, sal_True ); + exportHeaderFooterContent( xFooterText, sal_False ); + } + + if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText ) + { + if( !bFooterLeft ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DISPLAY, XML_FALSE ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_FOOTER_LEFT, sal_True, sal_True ); + exportHeaderFooterContent( xFooterTextLeft, sal_False ); + } + } +} + diff --git a/xmloff/source/text/XMLTextMasterStylesContext.cxx b/xmloff/source/text/XMLTextMasterStylesContext.cxx new file mode 100644 index 000000000000..38428dabb8d1 --- /dev/null +++ b/xmloff/source/text/XMLTextMasterStylesContext.cxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> + + +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/nmspmap.hxx> + +#ifndef _XMLTEXTMASTERPAGECONTEXT_HXX +#include <xmloff/XMLTextMasterPageContext.hxx> +#endif +#ifndef _XMLTEXTMASTERSTYLESCONTEXT_HXX +#include <xmloff/XMLTextMasterStylesContext.hxx> +#endif + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; + +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_MASTER_PAGE; + +// ------------------------------------------------------------------------ + +TYPEINIT1( XMLTextMasterStylesContext, SvXMLStylesContext ); + +sal_Bool XMLTextMasterStylesContext::InsertStyleFamily( sal_uInt16 ) const +{ + return sal_True; +} + +XMLTextMasterStylesContext::XMLTextMasterStylesContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList ) : + SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ) +{ +} + +XMLTextMasterStylesContext::~XMLTextMasterStylesContext() +{ +} + +SvXMLStyleContext *XMLTextMasterStylesContext::CreateStyleChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( rLocalName, XML_MASTER_PAGE ) && + InsertStyleFamily( XML_STYLE_FAMILY_MASTER_PAGE ) ) + pContext = new XMLTextMasterPageContext( + GetImport(), nPrefix, rLocalName, + xAttrList, + !GetImport().GetTextImport()->IsInsertMode() ); + + // any other style will be ignored here! + + return pContext; +} + +SvXMLStyleContext *XMLTextMasterStylesContext::CreateStyleStyleChildContext( + sal_uInt16 /*nFamily*/, + sal_uInt16 /*nPrefix*/, + const OUString& /*rLocalName*/, + const Reference< XAttributeList > & /*xAttrList*/ ) +{ + return 0; +} diff --git a/xmloff/source/text/XMLTextNumRuleInfo.cxx b/xmloff/source/text/XMLTextNumRuleInfo.cxx new file mode 100644 index 000000000000..cbb0d976a836 --- /dev/null +++ b/xmloff/source/text/XMLTextNumRuleInfo.cxx @@ -0,0 +1,261 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <tools/debug.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include "XMLTextNumRuleInfo.hxx" +// --> OD 2008-04-25 #refactorlists# +#include "xmloff/XMLTextListAutoStylePool.hxx" +// <-- + +using ::rtl::OUString; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::style; + +// --> OD 2008-05-08 #refactorlists# +// Complete refactoring of the class and enhancement of the class for lists. +XMLTextNumRuleInfo::XMLTextNumRuleInfo() + : msNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")) + , msNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel")) + , msNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue")) + , msParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart")) + , msNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber")) + , msNumberingIsOutline(RTL_CONSTASCII_USTRINGPARAM("NumberingIsOutline")) + , msPropNameListId(RTL_CONSTASCII_USTRINGPARAM("ListId")) + , msPropNameStartWith(RTL_CONSTASCII_USTRINGPARAM("StartWith")) + // --> OD 2008-11-26 #158694# + , msContinueingPreviousSubTree(RTL_CONSTASCII_USTRINGPARAM("ContinueingPreviousSubTree")) + , msListLabelStringProp(RTL_CONSTASCII_USTRINGPARAM("ListLabelString")) + // <-- + , mxNumRules() + , msNumRulesName() + , msListId() + , mnListStartValue( -1 ) + , mnListLevel( 0 ) + , mbIsNumbered( sal_False ) + , mbIsRestart( sal_False ) + , mnListLevelStartValue( -1 ) + , mbOutlineStyleAsNormalListStyle( sal_False ) +{ + Reset(); +} + +// --> OD 2006-09-27 #i69627# +void XMLTextNumRuleInfo::Set( + const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > & xTextContent, + const sal_Bool bOutlineStyleAsNormalListStyle, + const XMLTextListAutoStylePool& rListAutoPool, + // --> OD 2008-11-26 #158694# + const sal_Bool bExportTextNumberElement ) + // <-- +{ + Reset(); + // --> OD 2006-09-27 #i69627# + mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle; + // <-- + + Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + + // check if this paragraph supports a numbering + if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) ) + return; + + if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel ) + { + if( xPropSetInfo->hasPropertyByName( msNumberingRules ) ) + { + xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules; + } + } + else + { + // in applications using the outliner we always have a numbering rule, + // so a void property no numbering + mnListLevel = 0; + } + + // --> OD 2008-12-17 #i97312# + if ( mxNumRules.is() && mxNumRules->getCount() < 1 ) + { + DBG_ASSERT( false, + "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" ); + Reset(); + return; + } + // <-- + + // --> OD 2010-01-13 #b6912256# + if ( mnListLevel < 0 ) + { + DBG_ASSERT( false, + "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" ); + Reset(); + return; + } + + // --> OD 2006-09-27 #i69627# + bool bSuppressListStyle( false ); + if ( mxNumRules.is() ) + { + if ( !mbOutlineStyleAsNormalListStyle ) + { + sal_Bool bIsOutline = sal_False; + Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY); + if ( xNumRulesProps.is() && + xNumRulesProps->getPropertySetInfo()-> + hasPropertyByName( msNumberingIsOutline ) ) + { + xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline; + bSuppressListStyle = bIsOutline ? true : false; + } + } + } + + if( mxNumRules.is() && !bSuppressListStyle ) + // <-- + { + // First try to find the numbering rules in the list auto style pool. + // If not found, the numbering rules instance has to be named. + msNumRulesName = rListAutoPool.Find( mxNumRules ); + if ( msNumRulesName.getLength() == 0 ) + { + Reference < XNamed > xNamed( mxNumRules, UNO_QUERY ); + DBG_ASSERT( xNamed.is(), + "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." ); + if( xNamed.is() ) + { + msNumRulesName = xNamed->getName(); + } + } + DBG_ASSERT( msNumRulesName.getLength() > 0, + "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." ); + + if( xPropSetInfo->hasPropertyByName( msPropNameListId ) ) + { + xPropSet->getPropertyValue( msPropNameListId ) >>= msListId; + } + + // --> OD 2008-11-26 #158694# + mbContinueingPreviousSubTree = sal_False; + if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) ) + { + xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree; + } + // <-- + + mbIsNumbered = sal_True; + if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) ) + { + if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) ) + { + OSL_ENSURE( false, "numbered paragraph without number info" ); + mbIsNumbered = sal_False; + } + } + + if( mbIsNumbered ) + { + if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) ) + { + xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart; + } + if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) ) + { + xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue; + } + } + + OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" ); + if( mnListLevel >= mxNumRules->getCount() ) + { + Reset(); + return; + } + + Sequence<PropertyValue> aProps; + mxNumRules->getByIndex( mnListLevel ) >>= aProps; + + const PropertyValue* pPropArray = aProps.getConstArray(); + sal_Int32 nCount = aProps.getLength(); + for( sal_Int32 i=0; i<nCount; i++ ) + { + const PropertyValue& rProp = pPropArray[i]; + + if ( rProp.Name == msPropNameStartWith ) + { + rProp.Value >>= mnListLevelStartValue; + break; + } + } + + // --> OD 2008-11-26 #158694# + msListLabelString = ::rtl::OUString(); + if ( bExportTextNumberElement && + xPropSetInfo->hasPropertyByName( msListLabelStringProp ) ) + { + xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString; + } + // <-- + + // paragraph's list level range is [0..9] representing list levels [1..10] + ++mnListLevel; + } + else + { + mnListLevel = 0; + } +} + +sal_Bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const +{ + sal_Bool bRet( sal_True ); + // Currently only the text documents support <ListId>. + if ( rCmp.msListId.getLength() > 0 || + msListId.getLength() > 0 ) + { + bRet = rCmp.msListId == msListId; + } + else + { + bRet = HasSameNumRules( rCmp ); + } + + return bRet; +} +// <-- diff --git a/xmloff/source/text/XMLTextNumRuleInfo.hxx b/xmloff/source/text/XMLTextNumRuleInfo.hxx new file mode 100644 index 000000000000..52879b7d8a60 --- /dev/null +++ b/xmloff/source/text/XMLTextNumRuleInfo.hxx @@ -0,0 +1,200 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLTEXTNUMRULEINFO_HXX +#define _XMLOFF_XMLTEXTNUMRULEINFO_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/container/XIndexReplace.hpp> + +namespace com { namespace sun { namespace star { + namespace text { class XTextContent; } +} } } +#include <sal/types.h> + +class XMLTextListAutoStylePool; + +/** information about list and list style for a certain paragraph + + OD 2008-04-24 #refactorlists# + Complete refactoring of the class and enhancement of the class for lists. + These changes are considered by method <XMLTextParagraphExport::exportListChange(..)> +*/ +class XMLTextNumRuleInfo +{ + const ::rtl::OUString msNumberingRules; + const ::rtl::OUString msNumberingLevel; + const ::rtl::OUString msNumberingStartValue; + const ::rtl::OUString msParaIsNumberingRestart; + const ::rtl::OUString msNumberingIsNumber; + const ::rtl::OUString msNumberingIsOutline; + const ::rtl::OUString msPropNameListId; + const ::rtl::OUString msPropNameStartWith; + // --> OD 2008-11-26 #158694# + const ::rtl::OUString msContinueingPreviousSubTree; + const ::rtl::OUString msListLabelStringProp; + // <-- + + // numbering rules instance and its name + ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace > mxNumRules; + ::rtl::OUString msNumRulesName; + + // paragraph's list attributes + ::rtl::OUString msListId; + sal_Int16 mnListStartValue; + sal_Int16 mnListLevel; + sal_Bool mbIsNumbered; + sal_Bool mbIsRestart; + + // numbering rules' attributes + // --> OD 2008-05-07 #refactorlists# + sal_Int16 mnListLevelStartValue; + // <-- + + // --> OD 2006-09-27 #i69627# + sal_Bool mbOutlineStyleAsNormalListStyle; + // <-- + + // --> OD 2008-11-26 #158694# + sal_Bool mbContinueingPreviousSubTree; + ::rtl::OUString msListLabelString; + // <-- +public: + + XMLTextNumRuleInfo(); + + inline XMLTextNumRuleInfo& operator=( const XMLTextNumRuleInfo& rInfo ); + + // --> OD 2008-11-26 #158694# + void Set( const ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextContent > & rTextContnt, + const sal_Bool bOutlineStyleAsNormalListStyle, + const XMLTextListAutoStylePool& rListAutoPool, + const sal_Bool bExportTextNumberElement ); + // <-- + inline void Reset(); + + inline const ::rtl::OUString& GetNumRulesName() const + { + return msNumRulesName; + } + inline const ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace >& GetNumRules() const + { + return mxNumRules; + } + inline sal_Int16 GetListLevelStartValue() const + { + return mnListLevelStartValue; + } + + inline const ::rtl::OUString& GetListId() const + { + return msListId; + } + + inline sal_Int16 GetLevel() const + { + return mnListLevel; + } + + inline sal_Bool HasStartValue() const + { + return mnListStartValue != -1; + } + inline sal_uInt32 GetStartValue() const + { + return mnListStartValue; + } + + inline sal_Bool IsNumbered() const + { + return mbIsNumbered; + } + inline sal_Bool IsRestart() const + { + return mbIsRestart; + } + + sal_Bool BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const; + + inline sal_Bool HasSameNumRules( const XMLTextNumRuleInfo& rCmp ) const + { + return rCmp.msNumRulesName == msNumRulesName; + } + + // --> OD 2008-11-26 #158694# + inline sal_Bool IsContinueingPreviousSubTree() const + { + return mbContinueingPreviousSubTree; + } + inline const ::rtl::OUString& ListLabelString() const + { + return msListLabelString; + } + // <-- +}; + +inline XMLTextNumRuleInfo& XMLTextNumRuleInfo::operator=( + const XMLTextNumRuleInfo& rInfo ) +{ + msNumRulesName = rInfo.msNumRulesName; + mxNumRules = rInfo.mxNumRules; + msListId = rInfo.msListId; + mnListStartValue = rInfo.mnListStartValue; + mnListLevel = rInfo.mnListLevel; + mbIsNumbered = rInfo.mbIsNumbered; + mbIsRestart = rInfo.mbIsRestart; + // --> OD 2006-09-27 #i69627# + mbOutlineStyleAsNormalListStyle = rInfo.mbOutlineStyleAsNormalListStyle; + // <-- + // --> OD 2008-11-26 #158694# + mbContinueingPreviousSubTree = rInfo.mbContinueingPreviousSubTree; + msListLabelString = rInfo.msListLabelString; + // <-- + + return *this; +} + +inline void XMLTextNumRuleInfo::Reset() +{ + mxNumRules = 0; + msNumRulesName = ::rtl::OUString(); + msListId = ::rtl::OUString(); + mnListStartValue = -1; + mnListLevel = 0; + // --> OD 2006-09-27 #i69627# + mbIsNumbered = mbIsRestart = + mbOutlineStyleAsNormalListStyle = sal_False; + // <-- + // --> OD 2008-11-26 #158694# + mbContinueingPreviousSubTree = sal_False; + msListLabelString = ::rtl::OUString(); + // <-- +} +#endif // _XMLOFF_XMLTEXTNUMRULEINFO_HXX diff --git a/xmloff/source/text/XMLTextPropertySetContext.cxx b/xmloff/source/text/XMLTextPropertySetContext.cxx new file mode 100644 index 000000000000..31c5777f4d57 --- /dev/null +++ b/xmloff/source/text/XMLTextPropertySetContext.cxx @@ -0,0 +1,158 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include "XMLTextPropertySetContext.hxx" +#include "XMLTextColumnsContext.hxx" +#include "XMLBackgroundImageContext.hxx" +#include "XMLSectionFootnoteConfigImport.hxx" + +#ifndef _XMLOFF_TXTPRMAP_HXX +#include <xmloff/txtprmap.hxx> +#endif +#include "xmltabi.hxx" +#ifndef _XMLOFF_TXTDROPI_HXX +#include "txtdropi.hxx" +#endif + +using ::rtl::OUString; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; + +XMLTextPropertySetContext::XMLTextPropertySetContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap, + OUString& rDCTextStyleName ) : + SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily, + rProps, rMap ), + rDropCapTextStyleName( rDCTextStyleName ) +{ +} + +XMLTextPropertySetContext::~XMLTextPropertySetContext() +{ +} + +SvXMLImportContext *XMLTextPropertySetContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp ) +{ + SvXMLImportContext *pContext = 0; + + switch( mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex ) ) + { + case CTF_TABSTOP: + pContext = new SvxXMLTabStopImportContext( GetImport(), nPrefix, + rLocalName, rProp, + rProperties ); + break; + case CTF_TEXTCOLUMNS: +#ifndef SVX_LIGHT + pContext = new XMLTextColumnsContext( GetImport(), nPrefix, + rLocalName, xAttrList, rProp, + rProperties ); +#else + // create default context to skip content + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + break; + + case CTF_DROPCAPFORMAT: + { + DBG_ASSERT( rProp.mnIndex >= 2 && + CTF_DROPCAPWHOLEWORD == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-2 ), + "invalid property map!"); + XMLTextDropCapImportContext *pDCContext = + new XMLTextDropCapImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + rProp, + rProp.mnIndex-2, + rProperties ); + rDropCapTextStyleName = pDCContext->GetStyleName(); + pContext = pDCContext; + } + break; + + case CTF_BACKGROUND_URL: + { + DBG_ASSERT( rProp.mnIndex >= 2 && + CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-2 ) && + CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-1 ), + "invalid property map!"); + + // #99657# Transparency might be there as well... but doesn't have + // to. Thus, this is checked with an if, rather than with an assertion. + sal_Int32 nTranspIndex = -1; + if( (rProp.mnIndex >= 3) && + ( CTF_BACKGROUND_TRANSPARENCY == + mxMapper->getPropertySetMapper()->GetEntryContextId( + rProp.mnIndex-3 ) ) ) + nTranspIndex = rProp.mnIndex-3; + + pContext = + new XMLBackgroundImageContext( GetImport(), nPrefix, + rLocalName, xAttrList, + rProp, + rProp.mnIndex-2, + rProp.mnIndex-1, + nTranspIndex, + rProperties ); + } + break; +#ifndef SVX_LIGHT + case CTF_SECTION_FOOTNOTE_END: + case CTF_SECTION_ENDNOTE_END: + pContext = new XMLSectionFootnoteConfigImport( + GetImport(), nPrefix, rLocalName, rProperties, + mxMapper->getPropertySetMapper()); + break; +#endif // #ifndef SVX_LIGHT + } + + if( !pContext ) + pContext = SvXMLPropertySetContext::CreateChildContext( nPrefix, rLocalName, + xAttrList, + rProperties, rProp ); + + return pContext; +} + + diff --git a/xmloff/source/text/XMLTextPropertySetContext.hxx b/xmloff/source/text/XMLTextPropertySetContext.hxx new file mode 100644 index 000000000000..a1b3888b9ed6 --- /dev/null +++ b/xmloff/source/text/XMLTextPropertySetContext.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX +#define _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX + +#include <xmloff/xmlprcon.hxx> + + +class XMLTextPropertySetContext : public SvXMLPropertySetContext +{ +// SvXMLImportContextRef xTabStop; +// SvXMLImportContextRef xBackground; +// SvXMLImportContextRef xDropCap; + ::rtl::OUString& rDropCapTextStyleName; + +public: + XMLTextPropertySetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap, + ::rtl::OUString& rDopCapTextStyleName ); + + virtual ~XMLTextPropertySetContext(); + + using SvXMLPropertySetContext::CreateChildContext; + virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp); +}; + + +#endif // _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX diff --git a/xmloff/source/text/XMLTextShapeImportHelper.cxx b/xmloff/source/text/XMLTextShapeImportHelper.cxx new file mode 100644 index 000000000000..3c5df81cb597 --- /dev/null +++ b/xmloff/source/text/XMLTextShapeImportHelper.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/text/XTextContent.hpp> +#ifndef _COM_SUN_STAR_TEXT_TEXTCONTENTANCHORTYPE_HPP +#include <com/sun/star/text/TextContentAnchorType.hpp> +#endif + +#ifndef _XMLOFF_XMLTIMP_HXX_ +#include <xmloff/xmlimp.hxx> +#endif +#include <xmloff/txtimp.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include "XMLAnchorTypePropHdl.hxx" +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include "xmloff/XMLTextShapeImportHelper.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::xml::sax; + +XMLTextShapeImportHelper::XMLTextShapeImportHelper( + SvXMLImport& rImp ) : + XMLShapeImportHelper( rImp, rImp.GetModel(), + XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ), + rImport( rImp ), + sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")), + sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")), + sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")) +{ + Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY ); + if( xDPS.is() ) + { + Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY ); + pushGroupForSorting( xShapes ); + } + +} + +XMLTextShapeImportHelper::~XMLTextShapeImportHelper() +{ + popGroupAndSort(); +} + +void XMLTextShapeImportHelper::addShape( + Reference< XShape >& rShape, + const Reference< XAttributeList >& xAttrList, + Reference< XShapes >& rShapes ) +{ + if( rShapes.is() ) + { + // It's a group shape or 3DScene , so we have to call the base class method. + XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes ); + return; + } + + TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH; + sal_Int16 nPage = 0; + sal_Int32 nY = 0; + + UniReference < XMLTextImportHelper > xTxtImport = + rImport.GetTextImport(); + const SvXMLTokenMap& rTokenMap = + xTxtImport->GetTextFrameAttrTokenMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_FRAME_ANCHOR_TYPE: + { + TextContentAnchorType eNew; + // OD 2004-06-01 #i26791# - allow all anchor types + if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) ) + { + eAnchorType = eNew; + } + } + break; + case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER: + { + sal_Int32 nTmp; + if( rImport.GetMM100UnitConverter(). + convertNumber( nTmp, rValue, 1, SHRT_MAX ) ) + nPage = (sal_Int16)nTmp; + } + break; + case XML_TOK_TEXT_FRAME_Y: + rImport.GetMM100UnitConverter().convertMeasure( nY, rValue ); + break; + } + } + + Reference < XPropertySet > xPropSet( rShape, UNO_QUERY ); + Any aAny; + + // anchor type + aAny <<= eAnchorType; + xPropSet->setPropertyValue( sAnchorType, aAny ); + + Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY ); + xTxtImport->InsertTextContent( xTxtCntnt ); + + // page number (must be set after the frame is inserted, because it + // will be overwritten then inserting the frame. + switch( eAnchorType ) + { + case TextContentAnchorType_AT_PAGE: + // only set positive page numbers + if ( nPage > 0 ) + { + aAny <<= nPage; + xPropSet->setPropertyValue( sAnchorPageNo, aAny ); + } + break; + case TextContentAnchorType_AS_CHARACTER: + aAny <<= nY; + xPropSet->setPropertyValue( sVertOrientPosition, aAny ); + break; + default: + break; + } +} diff --git a/xmloff/source/text/XMLTextShapeStyleContext.cxx b/xmloff/source/text/XMLTextShapeStyleContext.cxx new file mode 100644 index 000000000000..46aac523b55a --- /dev/null +++ b/xmloff/source/text/XMLTextShapeStyleContext.cxx @@ -0,0 +1,255 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP +#include <com/sun/star/document/XEventsSupplier.hpp> +#endif +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "XMLTextPropertySetContext.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/XMLEventsImportContext.hxx> +#include "XMLShapePropertySetContext.hxx" +#include "XMLTextColumnsContext.hxx" +#include "XMLBackgroundImageContext.hxx" +#ifndef _XMLOFF_TXTPRMAP_HXX +#include <xmloff/txtprmap.hxx> +#endif + +#ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX +#include <xmloff/XMLTextShapeStyleContext.hxx> +#endif + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext +{ +public: + XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< XAttributeList >& xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap ); + + virtual ~XMLTextShapePropertySetContext_Impl(); + + using SvXMLPropertySetContext::CreateChildContext; + virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList >& xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp); +}; + +XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap ) : + XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily, + rProps, rMap ) +{ +} + +XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl() +{ +} + +SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp ) +{ + SvXMLImportContext *pContext = 0; + + switch( mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex ) ) + { + case CTF_TEXTCOLUMNS: + pContext = new XMLTextColumnsContext( GetImport(), nPrefix, + rLocalName, xAttrList, rProp, + rProperties ); + break; + + case CTF_BACKGROUND_URL: + DBG_ASSERT( rProp.mnIndex >= 3 && + CTF_BACKGROUND_TRANSPARENCY == + mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-3 ) && + CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-2 ) && + CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-1 ), + "invalid property map!"); + pContext = + new XMLBackgroundImageContext( GetImport(), nPrefix, + rLocalName, xAttrList, + rProp, + rProp.mnIndex-2, + rProp.mnIndex-1, + rProp.mnIndex-3, + rProperties ); + break; + } + + if( !pContext ) + pContext = XMLShapePropertySetContext::CreateChildContext( + nPrefix, rLocalName, xAttrList, rProperties, rProp ); + + return pContext; +} + +//----------------------------------------------------------------------------- + +void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + if( XML_NAMESPACE_STYLE == nPrefixKey && + IsXMLToken( rLocalName, XML_AUTO_UPDATE ) ) + { + if( IsXMLToken( rValue, XML_TRUE ) ) + bAutoUpdate = sal_True; + } + else + { + XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } +} + +TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext ); + +XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, sal_uInt16 nFamily, + sal_Bool /*bDefaultStyle*/ ) : + XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, + nFamily ), + sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ), + bAutoUpdate( sal_False ) +{ +} + +XMLTextShapeStyleContext::~XMLTextShapeStyleContext() +{ +} + +SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix ) + { + sal_uInt32 nFamily = 0; + if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TEXT; + else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_PARAGRAPH; + else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_GRAPHIC; + if( nFamily ) + { + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + GetStyles()->GetImportPropertyMapper( GetFamily() ); + if( xImpPrMap.is() ) + { + pContext = new XMLTextShapePropertySetContext_Impl( + GetImport(), nPrefix, rLocalName, xAttrList, nFamily, + GetProperties(), xImpPrMap ); + } + } + } + else if ( (XML_NAMESPACE_OFFICE == nPrefix) && + IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + { + // create and remember events import context + // (for delayed processing of events) + pContext = new XMLEventsImportContext( GetImport(), nPrefix, + rLocalName); + xEventContext = pContext; + } + + if( !pContext ) + pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + + return pContext; +} + +void XMLTextShapeStyleContext::CreateAndInsert( sal_Bool bOverwrite ) +{ + XMLShapeStyleContext::CreateAndInsert( bOverwrite ); + Reference < XStyle > xStyle = GetStyle(); + if( !xStyle.is() || !(bOverwrite || IsNew()) ) + return; + + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) ) + { + Any aAny; + sal_Bool bTmp = bAutoUpdate; + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsAutoUpdate, aAny ); + } + + // tell the style about it's events (if applicable) + if( xEventContext.Is() ) + { + // set event suppplier and release reference to context + Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY); + ((XMLEventsImportContext *)&xEventContext)->SetEvents(xEventsSupplier); + xEventContext = 0; + } +} + + +void XMLTextShapeStyleContext::Finish( sal_Bool bOverwrite ) +{ + XMLPropStyleContext::Finish( bOverwrite ); +} diff --git a/xmloff/source/text/XMLTextTableContext.cxx b/xmloff/source/text/XMLTextTableContext.cxx new file mode 100644 index 000000000000..0859aaa220e4 --- /dev/null +++ b/xmloff/source/text/XMLTextTableContext.cxx @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/XMLTextTableContext.hxx> + +using ::rtl::OUString; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; + + +TYPEINIT1( XMLTextTableContext, SvXMLImportContext ); + +XMLTextTableContext::XMLTextTableContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName ) : + SvXMLImportContext( rImport, nPrfx, rLName ) +{ +} + +XMLTextTableContext::~XMLTextTableContext() +{ +} diff --git a/xmloff/source/text/XMLTrackedChangesImportContext.cxx b/xmloff/source/text/XMLTrackedChangesImportContext.cxx new file mode 100644 index 000000000000..9fc143bf4330 --- /dev/null +++ b/xmloff/source/text/XMLTrackedChangesImportContext.cxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLTrackedChangesImportContext.hxx" +#include "XMLChangedRegionImportContext.hxx" +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.h> +#include <xmloff/xmlimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> + + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::xml::sax::XAttributeList; +using namespace ::xmloff::token; + + + +TYPEINIT1( XMLTrackedChangesImportContext, SvXMLImportContext ); + +XMLTrackedChangesImportContext::XMLTrackedChangesImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName) : + SvXMLImportContext(rImport, nPrefix, rLocalName) +{ +} + +XMLTrackedChangesImportContext::~XMLTrackedChangesImportContext() +{ +} + +void XMLTrackedChangesImportContext::StartElement( + const Reference<XAttributeList> & xAttrList ) +{ + sal_Bool bTrackChanges = sal_True; + + // scan for text:track-changes and text:protection-key attributes + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 i = 0; i < nLength; i++ ) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + if ( XML_NAMESPACE_TEXT == nPrefix ) + { + if ( IsXMLToken( sLocalName, XML_TRACK_CHANGES ) ) + { + sal_Bool bTmp; + if( SvXMLUnitConverter::convertBool( + bTmp, xAttrList->getValueByIndex(i)) ) + { + bTrackChanges = bTmp; + } + } + } + } + + // set tracked changes + GetImport().GetTextImport()->SetRecordChanges( bTrackChanges ); +} + + +SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList) +{ + SvXMLImportContext* pContext = NULL; + + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken( rLocalName, XML_CHANGED_REGION ) ) + { + pContext = new XMLChangedRegionImportContext(GetImport(), + nPrefix, rLocalName); + } + + if (NULL == pContext) + { + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + } + + return pContext; +} diff --git a/xmloff/source/text/XMLTrackedChangesImportContext.hxx b/xmloff/source/text/XMLTrackedChangesImportContext.hxx new file mode 100644 index 000000000000..a9906351e1cd --- /dev/null +++ b/xmloff/source/text/XMLTrackedChangesImportContext.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + + +#ifndef _XMLOFF_XMLTRACKEDCHANGESIMPORTCONTEXT_HXX +#define _XMLOFF_XMLTRACKEDCHANGESIMPORTCONTEXT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/uno/Reference.h> + + +namespace com { namespace sun { namespace star { + namespace text { + class XTextRange; + } + namespace xml { namespace sax { + class XAttributeList; + } } +} } } +namespace rtl { + class OUString; +} +class XMLTextImportHelper; + +/** + */ +class XMLTrackedChangesImportContext : public SvXMLImportContext +{ +public: + + TYPEINFO(); + + XMLTrackedChangesImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName); + + ~XMLTrackedChangesImportContext(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + virtual SvXMLImportContext* CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); +}; + +#endif diff --git a/xmloff/source/text/txtdrope.cxx b/xmloff/source/text/txtdrope.cxx new file mode 100644 index 000000000000..1c31ad94dd1d --- /dev/null +++ b/xmloff/source/text/txtdrope.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/style/DropCapFormat.hpp> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include "txtdrope.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + + +XMLTextDropCapExport::XMLTextDropCapExport( SvXMLExport& rExp ) : + rExport(rExp) +{ +} + +XMLTextDropCapExport::~XMLTextDropCapExport() +{ +} + +void XMLTextDropCapExport::exportXML( const Any& rAny, + sal_Bool bWholeWord, + const OUString& rStyleName ) +{ + DropCapFormat aFormat; + rAny >>= aFormat; + OUString sValue; + OUStringBuffer sBuffer; + if( aFormat.Lines > 1 ) + { + SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter(); + + // style:lines + rUnitConv.convertNumber( sBuffer, (sal_Int32)aFormat.Lines ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LINES, + sBuffer.makeStringAndClear() ); + + // style:length + if( bWholeWord ) + { + sValue = GetXMLToken(XML_WORD); + } + else if( aFormat.Count > 1 ) + { + rUnitConv.convertNumber( sBuffer, (sal_Int32)aFormat.Count ); + sValue = sBuffer.makeStringAndClear(); + } + if( sValue.getLength() ) + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LENGTH, sValue ); + + // style:distance + if( aFormat.Distance > 0 ) + { + rUnitConv.convertMeasure( sBuffer, aFormat.Distance ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_DISTANCE, + sBuffer.makeStringAndClear() ); + } + + // style:style-name + if( rStyleName.getLength() ) + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_STYLE_NAME, + rExport.EncodeStyleName( rStyleName ) ); + } + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, XML_DROP_CAP, + sal_False, sal_False ); +} + + + diff --git a/xmloff/source/text/txtdrope.hxx b/xmloff/source/text/txtdrope.hxx new file mode 100644 index 000000000000..1102e37c5989 --- /dev/null +++ b/xmloff/source/text/txtdrope.hxx @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_TXTDROPE_HXX +#define _XMLOFF_TXTDROPE_HXX + + +class SvXMLExport; +namespace com { namespace sun { namespace star { namespace uno { + class Any; } } } } +namespace rtl { class OUString; } + +class XMLTextDropCapExport +{ + SvXMLExport& rExport; + +public: + + XMLTextDropCapExport( SvXMLExport& rExport ); + ~XMLTextDropCapExport(); + + void exportXML( const ::com::sun::star::uno::Any& rAny, + sal_Bool bWholeWord, + const ::rtl::OUString& rStyleName ); +}; + + +#endif diff --git a/xmloff/source/text/txtdropi.cxx b/xmloff/source/text/txtdropi.cxx new file mode 100644 index 000000000000..1968a7e7b1a0 --- /dev/null +++ b/xmloff/source/text/txtdropi.cxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/style/DropCapFormat.hpp> +#include "txtdropi.hxx" +#include <xmloff/xmltkmap.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::xmloff::token; + + +enum SvXMLTokenMapDropAttrs +{ + XML_TOK_DROP_LINES, + XML_TOK_DROP_LENGTH, + XML_TOK_DROP_DISTANCE, + XML_TOK_DROP_STYLE, + XML_TOK_DROP_END=XML_TOK_UNKNOWN +}; + +static __FAR_DATA SvXMLTokenMapEntry aDropAttrTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES }, + { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH }, + { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE }, + { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE }, + XML_TOKEN_MAP_END +}; + +TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext ); +void XMLTextDropCapImportContext::ProcessAttrs( + const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + SvXMLTokenMap aTokenMap( aDropAttrTokenMap ); + + DropCapFormat aFormat; + sal_Bool bWholeWord = sal_False; + + sal_Int32 nTmp; + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_DROP_LINES: + if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 0, 255 ) ) + { + aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp; + } + break; + + case XML_TOK_DROP_LENGTH: + if( IsXMLToken( rValue, XML_WORD ) ) + { + bWholeWord = sal_True; + } + else if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 1, 255 ) ) + { + bWholeWord = sal_False; + aFormat.Count = (sal_Int8)nTmp; + } + break; + + case XML_TOK_DROP_DISTANCE: + if( GetImport().GetMM100UnitConverter().convertMeasure( nTmp, rValue, 0 ) ) + { + aFormat.Distance = (sal_uInt16)nTmp; + } + break; + + case XML_TOK_DROP_STYLE: + sStyleName = rValue; + break; + } + } + + if( aFormat.Lines > 1 && aFormat.Count < 1 ) + aFormat.Count = 1; + + aProp.maValue <<= aFormat; + + aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() ); +} + +XMLTextDropCapImportContext::XMLTextDropCapImportContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + const XMLPropertyState& rProp, + sal_Int32 nWholeWordIdx, + ::std::vector< XMLPropertyState > &rProps ) : + XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), + aWholeWordProp( nWholeWordIdx ) +{ + ProcessAttrs( xAttrList ); +} + +XMLTextDropCapImportContext::~XMLTextDropCapImportContext() +{ +} + +void XMLTextDropCapImportContext::EndElement() +{ + SetInsert( sal_True ); + XMLElementPropertyContext::EndElement(); + + if( -1 != aWholeWordProp.mnIndex ) + rProperties.push_back( aWholeWordProp ); +} + + diff --git a/xmloff/source/text/txtdropi.hxx b/xmloff/source/text/txtdropi.hxx new file mode 100644 index 000000000000..459540904c2b --- /dev/null +++ b/xmloff/source/text/txtdropi.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#ifndef _TXTDROPI_HXX +#define _TXTDROPI_HXX + +#include "XMLElementPropertyContext.hxx" + + +namespace rtl { class OUString; } + +class XMLTextDropCapImportContext :public XMLElementPropertyContext +{ + XMLPropertyState aWholeWordProp; + ::rtl::OUString sStyleName; + +private: + void ProcessAttrs( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + +public: + TYPEINFO(); + + XMLTextDropCapImportContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const XMLPropertyState& rProp, + sal_Int32 nWholeWOrdIdx, + ::std::vector< XMLPropertyState > &rProps ); + + virtual ~XMLTextDropCapImportContext(); + + virtual void EndElement(); + + const ::rtl::OUString& GetStyleName() const { return sStyleName; } +}; + + +#endif diff --git a/xmloff/source/text/txtexppr.cxx b/xmloff/source/text/txtexppr.cxx new file mode 100644 index 000000000000..7b3c7e828683 --- /dev/null +++ b/xmloff/source/text/txtexppr.cxx @@ -0,0 +1,1026 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/txtprmap.hxx> +#include <com/sun/star/table/BorderLine.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/awt/FontFamily.hpp> +#include <com/sun/star/awt/FontPitch.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include "txtexppr.hxx" +#include <xmloff/xmlexp.hxx> +#include "XMLSectionFootnoteConfigExport.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::awt; + +void XMLTextExportPropertySetMapper::handleElementItem( + SvXMLExport& rExp, + const XMLPropertyState& rProperty, + sal_uInt16 nFlags, + const ::std::vector< XMLPropertyState > *pProperties, + sal_uInt32 nIdx ) const +{ + XMLTextExportPropertySetMapper *pThis = + ((XMLTextExportPropertySetMapper *)this); + + switch( getPropertySetMapper()->GetEntryContextId( rProperty.mnIndex ) ) + { + case CTF_DROPCAPFORMAT: + pThis->maDropCapExport.exportXML( rProperty.maValue, bDropWholeWord, + sDropCharStyle ); + pThis->bDropWholeWord = sal_False; + pThis->sDropCharStyle = OUString(); + break; + + case CTF_TABSTOP: + pThis->maTabStopExport.Export( rProperty.maValue ); + break; + + case CTF_TEXTCOLUMNS: + pThis->maTextColumnsExport.exportXML( rProperty.maValue ); + break; + + case CTF_BACKGROUND_URL: + { + DBG_ASSERT( pProperties && nIdx >= 3, + "property vector missing" ); + const Any *pPos = 0, *pFilter = 0, *pTrans = 0; + if( pProperties && nIdx >= 3 ) + { + const XMLPropertyState& rTrans = (*pProperties)[nIdx-3]; + // #99657# transparency may be there, but doesn't have to be. + // If it's there, it must be in the right position. + if( CTF_BACKGROUND_TRANSPARENCY == getPropertySetMapper() + ->GetEntryContextId( rTrans.mnIndex ) ) + pTrans = &rTrans.maValue; + + const XMLPropertyState& rPos = (*pProperties)[nIdx-2]; + DBG_ASSERT( CTF_BACKGROUND_POS == getPropertySetMapper() + ->GetEntryContextId( rPos.mnIndex ), + "invalid property map: pos expected" ); + if( CTF_BACKGROUND_POS == getPropertySetMapper() + ->GetEntryContextId( rPos.mnIndex ) ) + pPos = &rPos.maValue; + + const XMLPropertyState& rFilter = (*pProperties)[nIdx-1]; + DBG_ASSERT( CTF_BACKGROUND_FILTER == getPropertySetMapper() + ->GetEntryContextId( rFilter.mnIndex ), + "invalid property map: filter expected" ); + if( CTF_BACKGROUND_FILTER == getPropertySetMapper() + ->GetEntryContextId( rFilter.mnIndex ) ) + pFilter = &rFilter.maValue; + } + sal_uInt32 nPropIndex = rProperty.mnIndex; + pThis->maBackgroundImageExport.exportXML( + rProperty.maValue, pPos, pFilter, pTrans, + getPropertySetMapper()->GetEntryNameSpace( nPropIndex ), + getPropertySetMapper()->GetEntryXMLName( nPropIndex ) ); + } + break; + + case CTF_SECTION_FOOTNOTE_END: + XMLSectionFootnoteConfigExport::exportXML(rExp, sal_False, + pProperties, nIdx, + getPropertySetMapper()); + break; + + case CTF_SECTION_ENDNOTE_END: + XMLSectionFootnoteConfigExport::exportXML(rExp, sal_True, + pProperties, nIdx, + getPropertySetMapper()); + break; + + default: + SvXMLExportPropertyMapper::handleElementItem( rExp, rProperty, nFlags, pProperties, nIdx ); + break; + } +} + +void XMLTextExportPropertySetMapper::handleSpecialItem( + SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const ::std::vector< XMLPropertyState > *pProperties, + sal_uInt32 nIdx ) const +{ + XMLTextExportPropertySetMapper *pThis = + ((XMLTextExportPropertySetMapper *)this); + + switch( getPropertySetMapper()->GetEntryContextId( rProperty.mnIndex ) ) + { + case CTF_DROPCAPWHOLEWORD: + DBG_ASSERT( !bDropWholeWord, "drop whole word is set already!" ); + pThis->bDropWholeWord = *(sal_Bool *)rProperty.maValue.getValue(); + break; + case CTF_DROPCAPCHARSTYLE: + DBG_ASSERT( !sDropCharStyle.getLength(), + "drop char style is set already!" ); + rProperty.maValue >>= pThis->sDropCharStyle; + break; + case CTF_NUMBERINGSTYLENAME: + case CTF_PAGEDESCNAME: + case CTF_OLDTEXTBACKGROUND: + case CTF_BACKGROUND_POS: + case CTF_BACKGROUND_FILTER: + case CTF_BACKGROUND_TRANSPARENCY: + case CTF_SECTION_FOOTNOTE_NUM_OWN: + case CTF_SECTION_FOOTNOTE_NUM_RESTART: + case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT: + case CTF_SECTION_FOOTNOTE_NUM_TYPE: + case CTF_SECTION_FOOTNOTE_NUM_PREFIX: + case CTF_SECTION_FOOTNOTE_NUM_SUFFIX: + case CTF_SECTION_ENDNOTE_NUM_OWN: + case CTF_SECTION_ENDNOTE_NUM_RESTART: + case CTF_SECTION_ENDNOTE_NUM_RESTART_AT: + case CTF_SECTION_ENDNOTE_NUM_TYPE: + case CTF_SECTION_ENDNOTE_NUM_PREFIX: + case CTF_SECTION_ENDNOTE_NUM_SUFFIX: + case CTF_DEFAULT_OUTLINE_LEVEL: + case CTF_OLD_FLOW_WITH_TEXT: + // There's nothing to do here! + break; + default: + SvXMLExportPropertyMapper::handleSpecialItem(rAttrList, rProperty, rUnitConverter, rNamespaceMap, pProperties, nIdx ); + break; + } +} + +XMLTextExportPropertySetMapper::XMLTextExportPropertySetMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLExport& rExp ) : + SvXMLExportPropertyMapper( rMapper ), + rExport( rExp ), + bDropWholeWord( sal_False ), + maDropCapExport( rExp ), + maTabStopExport( rExp ), + maTextColumnsExport( rExp ), + maBackgroundImageExport( rExp ) +{ +} + +XMLTextExportPropertySetMapper::~XMLTextExportPropertySetMapper() +{ +} + +void XMLTextExportPropertySetMapper::ContextFontFilter( + XMLPropertyState *pFontNameState, + XMLPropertyState *pFontFamilyNameState, + XMLPropertyState *pFontStyleNameState, + XMLPropertyState *pFontFamilyState, + XMLPropertyState *pFontPitchState, + XMLPropertyState *pFontCharsetState ) const +{ + OUString sFamilyName; + OUString sStyleName; + sal_Int16 nFamily = FontFamily::DONTKNOW; + sal_Int16 nPitch = FontPitch::DONTKNOW; + rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW; + + OUString sTmp; + if( pFontFamilyNameState && (pFontFamilyNameState->maValue >>= sTmp ) ) + sFamilyName = sTmp; + if( pFontStyleNameState && (pFontStyleNameState->maValue >>= sTmp ) ) + sStyleName = sTmp; + + sal_Int16 nTmp = sal_Int16(); + if( pFontFamilyState && (pFontFamilyState->maValue >>= nTmp ) ) + nFamily = nTmp; + if( pFontPitchState && (pFontPitchState->maValue >>= nTmp ) ) + nPitch = nTmp; + if( pFontCharsetState && (pFontCharsetState->maValue >>= nTmp ) ) + eEnc = (rtl_TextEncoding)nTmp; + + OUString sName( ((SvXMLExport&)GetExport()).GetFontAutoStylePool()->Find( + sFamilyName, sStyleName, nFamily, nPitch, eEnc ) ); + if( sName.getLength() ) + { + pFontNameState->maValue <<= sName; + if( pFontFamilyNameState ) + pFontFamilyNameState->mnIndex = -1; + if( pFontStyleNameState ) + pFontStyleNameState->mnIndex = -1; + if( pFontFamilyState ) + pFontFamilyState->mnIndex = -1; + if( pFontPitchState ) + pFontPitchState->mnIndex = -1; + if( pFontCharsetState ) + pFontCharsetState->mnIndex = -1; + } + else + { + pFontNameState->mnIndex = -1; + } + + if( pFontFamilyNameState && (0 == sFamilyName.getLength()) ) + { + pFontFamilyNameState->mnIndex = -1; + } + + if( pFontStyleNameState && (0 == sStyleName.getLength()) ) + { + pFontStyleNameState->mnIndex = -1; + } +} + +void XMLTextExportPropertySetMapper::ContextFontHeightFilter( + XMLPropertyState* pCharHeightState, + XMLPropertyState* pCharPropHeightState, + XMLPropertyState* pCharDiffHeightState ) const +{ + if( pCharPropHeightState ) + { + sal_Int32 nTemp = 0; + pCharPropHeightState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pCharPropHeightState->mnIndex = -1; + pCharPropHeightState->maValue.clear(); + } + else + { + pCharHeightState->mnIndex = -1; + pCharHeightState->maValue.clear(); + } + } + if( pCharDiffHeightState ) + { + float nTemp = 0; + pCharDiffHeightState->maValue >>= nTemp; + if( nTemp == 0. ) + { + pCharDiffHeightState->mnIndex = -1; + pCharDiffHeightState->maValue.clear(); + } + else + { + pCharHeightState->mnIndex = -1; + pCharHeightState->maValue.clear(); + } + } + +} + +// helper method; implementation below +bool lcl_IsOutlineStyle(const SvXMLExport&, const OUString&); + + +void XMLTextExportPropertySetMapper::ContextFilter( + ::std::vector< XMLPropertyState >& rProperties, + Reference< XPropertySet > rPropSet ) const +{ + // filter font + XMLPropertyState *pFontNameState = 0; + XMLPropertyState *pFontFamilyNameState = 0; + XMLPropertyState *pFontStyleNameState = 0; + XMLPropertyState *pFontFamilyState = 0; + XMLPropertyState *pFontPitchState = 0; + XMLPropertyState *pFontCharsetState = 0; + XMLPropertyState *pFontNameCJKState = 0; + XMLPropertyState *pFontFamilyNameCJKState = 0; + XMLPropertyState *pFontStyleNameCJKState = 0; + XMLPropertyState *pFontFamilyCJKState = 0; + XMLPropertyState *pFontPitchCJKState = 0; + XMLPropertyState *pFontCharsetCJKState = 0; + XMLPropertyState *pFontNameCTLState = 0; + XMLPropertyState *pFontFamilyNameCTLState = 0; + XMLPropertyState *pFontStyleNameCTLState = 0; + XMLPropertyState *pFontFamilyCTLState = 0; + XMLPropertyState *pFontPitchCTLState = 0; + XMLPropertyState *pFontCharsetCTLState = 0; + + // filter char height point/percent + XMLPropertyState* pCharHeightState = NULL; + XMLPropertyState* pCharPropHeightState = NULL; + XMLPropertyState* pCharDiffHeightState = NULL; + XMLPropertyState* pCharHeightCJKState = NULL; + XMLPropertyState* pCharPropHeightCJKState = NULL; + XMLPropertyState* pCharDiffHeightCJKState = NULL; + XMLPropertyState* pCharHeightCTLState = NULL; + XMLPropertyState* pCharPropHeightCTLState = NULL; + XMLPropertyState* pCharDiffHeightCTLState = NULL; + + // filter left margin measure/percent + XMLPropertyState* pParaLeftMarginState = NULL; + XMLPropertyState* pParaLeftMarginRelState = NULL; + + // filter right margin measure/percent + XMLPropertyState* pParaRightMarginState = NULL; + XMLPropertyState* pParaRightMarginRelState = NULL; + + // filter first line indent measure/percent + XMLPropertyState* pParaFirstLineState = NULL; + XMLPropertyState* pParaFirstLineRelState = NULL; + + // filter ParaTopMargin/Relative + XMLPropertyState* pParaTopMarginState = NULL; + XMLPropertyState* pParaTopMarginRelState = NULL; + + // filter ParaTopMargin/Relative + XMLPropertyState* pParaBottomMarginState = NULL; + XMLPropertyState* pParaBottomMarginRelState = NULL; + + // filter (Left|Right|Top|Bottom|)BorderWidth + XMLPropertyState* pAllBorderWidthState = NULL; + XMLPropertyState* pLeftBorderWidthState = NULL; + XMLPropertyState* pRightBorderWidthState = NULL; + XMLPropertyState* pTopBorderWidthState = NULL; + XMLPropertyState* pBottomBorderWidthState = NULL; + + // filter (Left|Right|Top|)BorderDistance + XMLPropertyState* pAllBorderDistanceState = NULL; + XMLPropertyState* pLeftBorderDistanceState = NULL; + XMLPropertyState* pRightBorderDistanceState = NULL; + XMLPropertyState* pTopBorderDistanceState = NULL; + XMLPropertyState* pBottomBorderDistanceState = NULL; + + // filter (Left|Right|Top|Bottom|)Border + XMLPropertyState* pAllBorderState = NULL; + XMLPropertyState* pLeftBorderState = NULL; + XMLPropertyState* pRightBorderState = NULL; + XMLPropertyState* pTopBorderState = NULL; + XMLPropertyState* pBottomBorderState = NULL; + + // filter height properties + XMLPropertyState* pHeightMinAbsState = NULL; + XMLPropertyState* pHeightMinRelState = NULL; + XMLPropertyState* pHeightAbsState = NULL; + XMLPropertyState* pHeightRelState = NULL; + XMLPropertyState* pSizeTypeState = NULL; + + // filter width properties + XMLPropertyState* pWidthMinAbsState = NULL; + XMLPropertyState* pWidthMinRelState = NULL; + XMLPropertyState* pWidthAbsState = NULL; + XMLPropertyState* pWidthRelState = NULL; + XMLPropertyState* pWidthTypeState = NULL; + + // wrap + XMLPropertyState* pWrapState = NULL; + XMLPropertyState* pWrapContourState = NULL; + XMLPropertyState* pWrapContourModeState = NULL; + XMLPropertyState* pWrapParagraphOnlyState = NULL; + + // anchor + XMLPropertyState* pAnchorTypeState = NULL; + + // horizontal position and relation + XMLPropertyState* pHoriOrientState = NULL; + XMLPropertyState* pHoriOrientMirroredState = NULL; + XMLPropertyState* pHoriOrientRelState = NULL; + XMLPropertyState* pHoriOrientRelFrameState = NULL; + XMLPropertyState* pHoriOrientMirrorState = NULL; + // --> OD 2004-08-09 #i28749# - horizontal position and relation for shapes + XMLPropertyState* pShapeHoriOrientState = NULL; + XMLPropertyState* pShapeHoriOrientMirroredState = NULL; + XMLPropertyState* pShapeHoriOrientRelState = NULL; + XMLPropertyState* pShapeHoriOrientRelFrameState = NULL; + XMLPropertyState* pShapeHoriOrientMirrorState = NULL; + // <-- + + // vertical position and relation + XMLPropertyState* pVertOrientState = NULL; + XMLPropertyState* pVertOrientAtCharState = NULL; + XMLPropertyState* pVertOrientRelState = NULL; + XMLPropertyState* pVertOrientRelPageState = NULL; + XMLPropertyState* pVertOrientRelFrameState = NULL; + XMLPropertyState* pVertOrientRelAsCharState = NULL; + + // --> OD 2004-08-09 #i28749# - vertical position and relation for shapes + XMLPropertyState* pShapeVertOrientState = NULL; + XMLPropertyState* pShapeVertOrientAtCharState = NULL; + XMLPropertyState* pShapeVertOrientRelState = NULL; + XMLPropertyState* pShapeVertOrientRelPageState = NULL; + XMLPropertyState* pShapeVertOrientRelFrameState = NULL; + // <-- + + // filter underline color + XMLPropertyState* pUnderlineState = NULL; + XMLPropertyState* pUnderlineColorState = NULL; + XMLPropertyState* pUnderlineHasColorState = NULL; + + // filter list style name + XMLPropertyState* pListStyleName = NULL; + + // filter fo:clip + XMLPropertyState* pClip11State = NULL; + XMLPropertyState* pClipState = NULL; + + sal_Bool bNeedsAnchor = sal_False; + + for( ::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); + aIter != rProperties.end(); + ++aIter ) + { + XMLPropertyState *propertie = &(*aIter); + if( propertie->mnIndex == -1 ) + continue; + + switch( getPropertySetMapper()->GetEntryContextId( propertie->mnIndex ) ) + { + case CTF_CHARHEIGHT: pCharHeightState = propertie; break; + case CTF_CHARHEIGHT_REL: pCharPropHeightState = propertie; break; + case CTF_CHARHEIGHT_DIFF: pCharDiffHeightState = propertie; break; + case CTF_CHARHEIGHT_CJK: pCharHeightCJKState = propertie; break; + case CTF_CHARHEIGHT_REL_CJK: pCharPropHeightCJKState = propertie; break; + case CTF_CHARHEIGHT_DIFF_CJK: pCharDiffHeightCJKState = propertie; break; + case CTF_CHARHEIGHT_CTL: pCharHeightCTLState = propertie; break; + case CTF_CHARHEIGHT_REL_CTL: pCharPropHeightCTLState = propertie; break; + case CTF_CHARHEIGHT_DIFF_CTL: pCharDiffHeightCTLState = propertie; break; + case CTF_PARALEFTMARGIN: pParaLeftMarginState = propertie; break; + case CTF_PARALEFTMARGIN_REL: pParaLeftMarginRelState = propertie; break; + case CTF_PARARIGHTMARGIN: pParaRightMarginState = propertie; break; + case CTF_PARARIGHTMARGIN_REL: pParaRightMarginRelState = propertie; break; + case CTF_PARAFIRSTLINE: pParaFirstLineState = propertie; break; + case CTF_PARAFIRSTLINE_REL: pParaFirstLineRelState = propertie; break; + case CTF_PARATOPMARGIN: pParaTopMarginState = propertie; break; + case CTF_PARATOPMARGIN_REL: pParaTopMarginRelState = propertie; break; + case CTF_PARABOTTOMMARGIN: pParaBottomMarginState = propertie; break; + case CTF_PARABOTTOMMARGIN_REL: pParaBottomMarginRelState = propertie; break; + case CTF_ALLBORDERWIDTH: pAllBorderWidthState = propertie; break; + case CTF_LEFTBORDERWIDTH: pLeftBorderWidthState = propertie; break; + case CTF_RIGHTBORDERWIDTH: pRightBorderWidthState = propertie; break; + case CTF_TOPBORDERWIDTH: pTopBorderWidthState = propertie; break; + case CTF_BOTTOMBORDERWIDTH: pBottomBorderWidthState = propertie; break; + case CTF_ALLBORDERDISTANCE: pAllBorderDistanceState = propertie; break; + case CTF_LEFTBORDERDISTANCE: pLeftBorderDistanceState = propertie; break; + case CTF_RIGHTBORDERDISTANCE: pRightBorderDistanceState = propertie; break; + case CTF_TOPBORDERDISTANCE: pTopBorderDistanceState = propertie; break; + case CTF_BOTTOMBORDERDISTANCE: pBottomBorderDistanceState = propertie; break; + case CTF_ALLBORDER: pAllBorderState = propertie; break; + case CTF_LEFTBORDER: pLeftBorderState = propertie; break; + case CTF_RIGHTBORDER: pRightBorderState = propertie; break; + case CTF_TOPBORDER: pTopBorderState = propertie; break; + case CTF_BOTTOMBORDER: pBottomBorderState = propertie; break; + + case CTF_FRAMEHEIGHT_MIN_ABS: pHeightMinAbsState = propertie; break; + case CTF_FRAMEHEIGHT_MIN_REL: pHeightMinRelState = propertie; break; + case CTF_FRAMEHEIGHT_ABS: pHeightAbsState = propertie; break; + case CTF_FRAMEHEIGHT_REL: pHeightRelState = propertie; break; + case CTF_SIZETYPE: pSizeTypeState = propertie; break; + + case CTF_FRAMEWIDTH_MIN_ABS: pWidthMinAbsState = propertie; break; + case CTF_FRAMEWIDTH_MIN_REL: pWidthMinRelState = propertie; break; + case CTF_FRAMEWIDTH_ABS: pWidthAbsState = propertie; break; + case CTF_FRAMEWIDTH_REL: pWidthRelState = propertie; break; + case CTF_FRAMEWIDTH_TYPE: pWidthTypeState = propertie; break; + + case CTF_WRAP: pWrapState = propertie; break; + case CTF_WRAP_CONTOUR: pWrapContourState = propertie; break; + case CTF_WRAP_CONTOUR_MODE: pWrapContourModeState = propertie; break; + case CTF_WRAP_PARAGRAPH_ONLY: pWrapParagraphOnlyState = propertie; break; + case CTF_ANCHORTYPE: pAnchorTypeState = propertie; break; + + case CTF_HORIZONTALPOS: pHoriOrientState = propertie; bNeedsAnchor = sal_True; break; + case CTF_HORIZONTALPOS_MIRRORED: pHoriOrientMirroredState = propertie; bNeedsAnchor = sal_True; break; + case CTF_HORIZONTALREL: pHoriOrientRelState = propertie; bNeedsAnchor = sal_True; break; + case CTF_HORIZONTALREL_FRAME: pHoriOrientRelFrameState = propertie; bNeedsAnchor = sal_True; break; + case CTF_HORIZONTALMIRROR: pHoriOrientMirrorState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALPOS: pVertOrientState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALPOS_ATCHAR: pVertOrientAtCharState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALREL: pVertOrientRelState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALREL_PAGE: pVertOrientRelPageState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALREL_FRAME: pVertOrientRelFrameState = propertie; bNeedsAnchor = sal_True; break; + case CTF_VERTICALREL_ASCHAR: pVertOrientRelAsCharState = propertie; bNeedsAnchor = sal_True; break; + + // --> OD 2004-08-09 #i28749# - handle new CTFs for shape positioning properties + case CTF_SHAPE_HORIZONTALPOS: pShapeHoriOrientState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_HORIZONTALPOS_MIRRORED: pShapeHoriOrientMirroredState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_HORIZONTALREL: pShapeHoriOrientRelState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_HORIZONTALREL_FRAME: pShapeHoriOrientRelFrameState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_HORIZONTALMIRROR: pShapeHoriOrientMirrorState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_VERTICALPOS: pShapeVertOrientState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_VERTICALPOS_ATCHAR: pShapeVertOrientAtCharState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_VERTICALREL: pShapeVertOrientRelState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_VERTICALREL_PAGE: pShapeVertOrientRelPageState = propertie; bNeedsAnchor = sal_True; break; + case CTF_SHAPE_VERTICALREL_FRAME: pShapeVertOrientRelFrameState = propertie; bNeedsAnchor = sal_True; break; + // <-- + + case CTF_FONTNAME: pFontNameState = propertie; break; + case CTF_FONTFAMILYNAME: pFontFamilyNameState = propertie; break; + case CTF_FONTSTYLENAME: pFontStyleNameState = propertie; break; + case CTF_FONTFAMILY: pFontFamilyState = propertie; break; + case CTF_FONTPITCH: pFontPitchState = propertie; break; + case CTF_FONTCHARSET: pFontCharsetState = propertie; break; + + case CTF_FONTNAME_CJK: pFontNameCJKState = propertie; break; + case CTF_FONTFAMILYNAME_CJK: pFontFamilyNameCJKState = propertie; break; + case CTF_FONTSTYLENAME_CJK: pFontStyleNameCJKState = propertie; break; + case CTF_FONTFAMILY_CJK: pFontFamilyCJKState = propertie; break; + case CTF_FONTPITCH_CJK: pFontPitchCJKState = propertie; break; + case CTF_FONTCHARSET_CJK: pFontCharsetCJKState = propertie; break; + + case CTF_FONTNAME_CTL: pFontNameCTLState = propertie; break; + case CTF_FONTFAMILYNAME_CTL: pFontFamilyNameCTLState = propertie; break; + case CTF_FONTSTYLENAME_CTL: pFontStyleNameCTLState = propertie; break; + case CTF_FONTFAMILY_CTL: pFontFamilyCTLState = propertie; break; + case CTF_FONTPITCH_CTL: pFontPitchCTLState = propertie; break; + case CTF_FONTCHARSET_CTL: pFontCharsetCTLState = propertie; break; + case CTF_UNDERLINE: pUnderlineState = propertie; break; + case CTF_UNDERLINE_COLOR: pUnderlineColorState = propertie; break; + case CTF_UNDERLINE_HASCOLOR: pUnderlineHasColorState = propertie; break; + case CTF_NUMBERINGSTYLENAME: pListStyleName = propertie; break; + case CTF_TEXT_CLIP11: pClip11State = propertie; break; + case CTF_TEXT_CLIP: pClipState = propertie; break; + } + } + + if( pFontNameState ) + ContextFontFilter( pFontNameState, pFontFamilyNameState, + pFontStyleNameState, pFontFamilyState, + pFontPitchState, pFontCharsetState ); + if( pFontNameCJKState ) + ContextFontFilter( pFontNameCJKState, pFontFamilyNameCJKState, + pFontStyleNameCJKState, pFontFamilyCJKState, + pFontPitchCJKState, pFontCharsetCJKState ); + if( pFontNameCTLState ) + ContextFontFilter( pFontNameCTLState, pFontFamilyNameCTLState, + pFontStyleNameCTLState, pFontFamilyCTLState, + pFontPitchCTLState, pFontCharsetCTLState ); + + if( pCharHeightState && (pCharPropHeightState || pCharDiffHeightState ) ) + ContextFontHeightFilter( pCharHeightState, pCharPropHeightState, + pCharDiffHeightState ); + if( pCharHeightCJKState && + (pCharPropHeightCJKState || pCharDiffHeightCJKState ) ) + ContextFontHeightFilter( pCharHeightCJKState, pCharPropHeightCJKState, + pCharDiffHeightCJKState ); + if( pCharHeightCTLState && + (pCharPropHeightCTLState || pCharDiffHeightCTLState ) ) + ContextFontHeightFilter( pCharHeightCTLState, pCharPropHeightCTLState, + pCharDiffHeightCTLState ); + if( pUnderlineColorState || pUnderlineHasColorState ) + { + sal_Bool bClear = !pUnderlineState; + if( !bClear ) + { + sal_Int16 nUnderline = 0; + pUnderlineState->maValue >>= nUnderline; + bClear = FontUnderline::NONE == nUnderline; + } + if( bClear ) + { + if( pUnderlineColorState ) + pUnderlineColorState->mnIndex = -1; + if( pUnderlineHasColorState ) + pUnderlineHasColorState->mnIndex = -1; + } + } + + if( pParaLeftMarginState && pParaLeftMarginRelState ) + { + sal_Int32 nTemp = 0; + pParaLeftMarginRelState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pParaLeftMarginRelState->mnIndex = -1; + pParaLeftMarginRelState->maValue.clear(); + } + else + { + pParaLeftMarginState->mnIndex = -1; + pParaLeftMarginState->maValue.clear(); + } + + } + + if( pParaRightMarginState && pParaRightMarginRelState ) + { + sal_Int32 nTemp = 0; + pParaRightMarginRelState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pParaRightMarginRelState->mnIndex = -1; + pParaRightMarginRelState->maValue.clear(); + } + else + { + pParaRightMarginState->mnIndex = -1; + pParaRightMarginState->maValue.clear(); + } + } + + if( pParaFirstLineState && pParaFirstLineRelState ) + { + sal_Int32 nTemp = 0; + pParaFirstLineRelState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pParaFirstLineRelState->mnIndex = -1; + pParaFirstLineRelState->maValue.clear(); + } + else + { + pParaFirstLineState->mnIndex = -1; + pParaFirstLineState->maValue.clear(); + } + } + + if( pParaTopMarginState && pParaTopMarginRelState ) + { + sal_Int32 nTemp = 0; + pParaTopMarginRelState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pParaTopMarginRelState->mnIndex = -1; + pParaTopMarginRelState->maValue.clear(); + } + else + { + pParaTopMarginState->mnIndex = -1; + pParaTopMarginState->maValue.clear(); + } + + } + + if( pParaBottomMarginState && pParaBottomMarginRelState ) + { + sal_Int32 nTemp = 0; + pParaBottomMarginRelState->maValue >>= nTemp; + if( nTemp == 100 ) + { + pParaBottomMarginRelState->mnIndex = -1; + pParaBottomMarginRelState->maValue.clear(); + } + else + { + pParaBottomMarginState->mnIndex = -1; + pParaBottomMarginState->maValue.clear(); + } + + } + + if( pAllBorderWidthState ) + { + if( pLeftBorderWidthState && pRightBorderWidthState && pTopBorderWidthState && pBottomBorderWidthState ) + { + table::BorderLine aLeft, aRight, aTop, aBottom; + + pLeftBorderWidthState->maValue >>= aLeft; + pRightBorderWidthState->maValue >>= aRight; + pTopBorderWidthState->maValue >>= aTop; + pBottomBorderWidthState->maValue >>= aBottom; + if( aLeft.Color == aRight.Color && aLeft.InnerLineWidth == aRight.InnerLineWidth && + aLeft.OuterLineWidth == aRight.OuterLineWidth && aLeft.LineDistance == aRight.LineDistance && + aLeft.Color == aTop.Color && aLeft.InnerLineWidth == aTop.InnerLineWidth && + aLeft.OuterLineWidth == aTop.OuterLineWidth && aLeft.LineDistance == aTop.LineDistance && + aLeft.Color == aBottom.Color && aLeft.InnerLineWidth == aBottom.InnerLineWidth && + aLeft.OuterLineWidth == aBottom.OuterLineWidth && aLeft.LineDistance == aBottom.LineDistance ) + { + pLeftBorderWidthState->mnIndex = -1; + pLeftBorderWidthState->maValue.clear(); + pRightBorderWidthState->mnIndex = -1; + pRightBorderWidthState->maValue.clear(); + pTopBorderWidthState->mnIndex = -1; + pTopBorderWidthState->maValue.clear(); + pBottomBorderWidthState->mnIndex = -1; + pBottomBorderWidthState->maValue.clear(); + } + else + { + pAllBorderWidthState->mnIndex = -1; + pAllBorderWidthState->maValue.clear(); + } + } + else + { + pAllBorderWidthState->mnIndex = -1; + pAllBorderWidthState->maValue.clear(); + } + } + + if( pAllBorderDistanceState ) + { + if( pLeftBorderDistanceState && pRightBorderDistanceState && pTopBorderDistanceState && pBottomBorderDistanceState ) + { + sal_Int32 aLeft = 0, aRight = 0, aTop = 0, aBottom = 0; + + pLeftBorderDistanceState->maValue >>= aLeft; + pRightBorderDistanceState->maValue >>= aRight; + pTopBorderDistanceState->maValue >>= aTop; + pBottomBorderDistanceState->maValue >>= aBottom; + if( aLeft == aRight && aLeft == aTop && aLeft == aBottom ) + { + pLeftBorderDistanceState->mnIndex = -1; + pLeftBorderDistanceState->maValue.clear(); + pRightBorderDistanceState->mnIndex = -1; + pRightBorderDistanceState->maValue.clear(); + pTopBorderDistanceState->mnIndex = -1; + pTopBorderDistanceState->maValue.clear(); + pBottomBorderDistanceState->mnIndex = -1; + pBottomBorderDistanceState->maValue.clear(); + } + else + { + pAllBorderDistanceState->mnIndex = -1; + pAllBorderDistanceState->maValue.clear(); + } + } + else + { + pAllBorderDistanceState->mnIndex = -1; + pAllBorderDistanceState->maValue.clear(); + } + } + + if( pAllBorderState ) + { + if( pLeftBorderState && pRightBorderState && pTopBorderState && pBottomBorderState ) + { + table::BorderLine aLeft, aRight, aTop, aBottom; + + pLeftBorderState->maValue >>= aLeft; + pRightBorderState->maValue >>= aRight; + pTopBorderState->maValue >>= aTop; + pBottomBorderState->maValue >>= aBottom; + if( aLeft.Color == aRight.Color && aLeft.InnerLineWidth == aRight.InnerLineWidth && + aLeft.OuterLineWidth == aRight.OuterLineWidth && aLeft.LineDistance == aRight.LineDistance && + aLeft.Color == aTop.Color && aLeft.InnerLineWidth == aTop.InnerLineWidth && + aLeft.OuterLineWidth == aTop.OuterLineWidth && aLeft.LineDistance == aTop.LineDistance && + aLeft.Color == aBottom.Color && aLeft.InnerLineWidth == aBottom.InnerLineWidth && + aLeft.OuterLineWidth == aBottom.OuterLineWidth && aLeft.LineDistance == aBottom.LineDistance ) + { + pLeftBorderState->mnIndex = -1; + pLeftBorderState->maValue.clear(); + pRightBorderState->mnIndex = -1; + pRightBorderState->maValue.clear(); + pTopBorderState->mnIndex = -1; + pTopBorderState->maValue.clear(); + pBottomBorderState->mnIndex = -1; + pBottomBorderState->maValue.clear(); + } + else + { + pAllBorderState->mnIndex = -1; + pAllBorderState->maValue.clear(); + } + } + else + { + pAllBorderState->mnIndex = -1; + pAllBorderState->maValue.clear(); + } + } + + sal_Int16 nSizeType = SizeType::FIX; + if( pSizeTypeState ) + { + pSizeTypeState->maValue >>= nSizeType; + pSizeTypeState->mnIndex = -1; + } + + if( pHeightMinAbsState ) + { + sal_Int16 nRel = sal_Int16(); + if( (SizeType::FIX == nSizeType) || + ( pHeightMinRelState && + ( !(pHeightMinRelState->maValue >>= nRel) || nRel > 0 ) ) ) + { + pHeightMinAbsState->mnIndex = -1; + } + + // export SizeType::VARIABLE als min-width="0" + if( SizeType::VARIABLE == nSizeType ) + pHeightMinAbsState->maValue <<= static_cast<sal_Int32>( 0 ); + } + if( pHeightMinRelState && SizeType::MIN != nSizeType) + pHeightMinRelState->mnIndex = -1; + if( pHeightAbsState && pHeightMinAbsState && + -1 != pHeightMinAbsState->mnIndex ) + pHeightAbsState->mnIndex = -1; + if( pHeightRelState && SizeType::FIX != nSizeType) + pHeightRelState->mnIndex = -1; + + // frame width + nSizeType = SizeType::FIX; + if( pWidthTypeState ) + { + pWidthTypeState->maValue >>= nSizeType; + pWidthTypeState->mnIndex = -1; + } + if( pWidthMinAbsState ) + { + sal_Int16 nRel = sal_Int16(); + if( (SizeType::FIX == nSizeType) || + ( pWidthMinRelState && + ( !(pWidthMinRelState->maValue >>= nRel) || nRel > 0 ) ) ) + { + pWidthMinAbsState->mnIndex = -1; + } + + // export SizeType::VARIABLE als min-width="0" + if( SizeType::VARIABLE == nSizeType ) + pWidthMinAbsState->maValue <<= static_cast<sal_Int32>( 0 ); + } + if( pWidthMinRelState && SizeType::MIN != nSizeType) + pWidthMinRelState->mnIndex = -1; + if( pWidthAbsState && pWidthMinAbsState && + -1 != pWidthMinAbsState->mnIndex ) + pWidthAbsState->mnIndex = -1; + if( pWidthRelState && SizeType::FIX != nSizeType) + pWidthRelState->mnIndex = -1; + + if( pWrapState ) + { + WrapTextMode eVal; + pWrapState->maValue >>= eVal; + switch( eVal ) + { + case WrapTextMode_NONE: + // no wrapping: disable para-only and contour + if( pWrapParagraphOnlyState ) + pWrapParagraphOnlyState->mnIndex = -1; + // no break + case WrapTextMode_THROUGHT: + // wrap through: disable only contour + if( pWrapContourState ) + pWrapContourState->mnIndex = -1; + break; + default: + break; + } + if( pWrapContourModeState && + (!pWrapContourState || + !*(sal_Bool *)pWrapContourState ->maValue.getValue() ) ) + pWrapContourModeState->mnIndex = -1; + } + + TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH; + if( pAnchorTypeState ) + pAnchorTypeState->maValue >>= eAnchor; + else if( bNeedsAnchor ) + { + Any aAny = rPropSet->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ) ); + aAny >>= eAnchor; + } + + // states for frame positioning attributes + { + if( pHoriOrientState && pHoriOrientMirroredState ) + { + if( pHoriOrientMirrorState && + *(sal_Bool *)pHoriOrientMirrorState->maValue.getValue() ) + pHoriOrientState->mnIndex = -1; + else + pHoriOrientMirroredState->mnIndex = -1; + } + if( pHoriOrientMirrorState ) + pHoriOrientMirrorState->mnIndex = -1; + + if( pHoriOrientRelState && TextContentAnchorType_AT_FRAME == eAnchor ) + pHoriOrientRelState->mnIndex = -1; + if( pHoriOrientRelFrameState && TextContentAnchorType_AT_FRAME != eAnchor ) + pHoriOrientRelFrameState->mnIndex = -1;; + + if( pVertOrientState && TextContentAnchorType_AT_CHARACTER == eAnchor ) + pVertOrientState->mnIndex = -1; + if( pVertOrientAtCharState && TextContentAnchorType_AT_CHARACTER != eAnchor ) + pVertOrientAtCharState->mnIndex = -1; + if( pVertOrientRelState && TextContentAnchorType_AT_PARAGRAPH != eAnchor && + TextContentAnchorType_AT_CHARACTER != eAnchor ) + pVertOrientRelState->mnIndex = -1; + if( pVertOrientRelPageState && TextContentAnchorType_AT_PAGE != eAnchor ) + pVertOrientRelPageState->mnIndex = -1; + if( pVertOrientRelFrameState && TextContentAnchorType_AT_FRAME != eAnchor ) + pVertOrientRelFrameState->mnIndex = -1; + if( pVertOrientRelAsCharState && TextContentAnchorType_AS_CHARACTER != eAnchor ) + pVertOrientRelAsCharState->mnIndex = -1; + } + + // --> OD 2004-08-09 #i28749# - states for shape positioning properties + if ( eAnchor != TextContentAnchorType_AS_CHARACTER && + ( GetExport().getExportFlags() & EXPORT_OASIS ) == 0 ) + { + // no export of shape positioning properties, + // if shape isn't anchored as-character and + // destination file format is OpenOffice.org file format + if ( pShapeHoriOrientState ) + pShapeHoriOrientState->mnIndex = -1; + if ( pShapeHoriOrientMirroredState ) + pShapeHoriOrientMirroredState->mnIndex = -1; + if ( pShapeHoriOrientRelState ) + pShapeHoriOrientRelState->mnIndex = -1; + if ( pShapeHoriOrientRelFrameState ) + pShapeHoriOrientRelFrameState->mnIndex = -1; + if ( pShapeHoriOrientMirrorState ) + pShapeHoriOrientMirrorState->mnIndex = -1; + if ( pShapeVertOrientState ) + pShapeVertOrientState->mnIndex = -1; + if ( pShapeVertOrientAtCharState ) + pShapeVertOrientAtCharState->mnIndex = -1; + if ( pShapeVertOrientRelState ) + pShapeVertOrientRelState->mnIndex = -1; + if ( pShapeVertOrientRelPageState ) + pShapeVertOrientRelPageState->mnIndex = -1; + if ( pShapeVertOrientRelFrameState ) + pShapeVertOrientRelFrameState->mnIndex = -1; + } + else + { + // handling of shape positioning property states as for frames - see above + if( pShapeHoriOrientState && pShapeHoriOrientMirroredState ) + { + if( pShapeHoriOrientMirrorState && + *(sal_Bool *)pShapeHoriOrientMirrorState->maValue.getValue() ) + pShapeHoriOrientState->mnIndex = -1; + else + pShapeHoriOrientMirroredState->mnIndex = -1; + } + if( pShapeHoriOrientMirrorState ) + pShapeHoriOrientMirrorState->mnIndex = -1; + + if( pShapeHoriOrientRelState && TextContentAnchorType_AT_FRAME == eAnchor ) + pShapeHoriOrientRelState->mnIndex = -1; + if( pShapeHoriOrientRelFrameState && TextContentAnchorType_AT_FRAME != eAnchor ) + pShapeHoriOrientRelFrameState->mnIndex = -1;; + + if( pShapeVertOrientState && TextContentAnchorType_AT_CHARACTER == eAnchor ) + pShapeVertOrientState->mnIndex = -1; + if( pShapeVertOrientAtCharState && TextContentAnchorType_AT_CHARACTER != eAnchor ) + pShapeVertOrientAtCharState->mnIndex = -1; + if( pShapeVertOrientRelState && TextContentAnchorType_AT_PARAGRAPH != eAnchor && + TextContentAnchorType_AT_CHARACTER != eAnchor ) + pShapeVertOrientRelState->mnIndex = -1; + if( pShapeVertOrientRelPageState && TextContentAnchorType_AT_PAGE != eAnchor ) + pShapeVertOrientRelPageState->mnIndex = -1; + if( pShapeVertOrientRelFrameState && TextContentAnchorType_AT_FRAME != eAnchor ) + pShapeVertOrientRelFrameState->mnIndex = -1; + } + // <-- + + // list style name: remove list style if it is the default outline style + if( pListStyleName != NULL ) + { + OUString sListStyleName; + pListStyleName->maValue >>= sListStyleName; + if( lcl_IsOutlineStyle( GetExport(), sListStyleName ) ) + pListStyleName->mnIndex = -1; + } + + if( pClipState != NULL && pClip11State != NULL ) + pClip11State->mnIndex = -1; + + SvXMLExportPropertyMapper::ContextFilter(rProperties,rPropSet); +} + + +bool lcl_IsOutlineStyle(const SvXMLExport &rExport, const OUString & rName) +{ + Reference< XChapterNumberingSupplier > + xCNSupplier(rExport.GetModel(), UNO_QUERY); + + OUString sOutlineName; + OUString sName(RTL_CONSTASCII_USTRINGPARAM("Name")); + + if (xCNSupplier.is()) + { + Reference<XPropertySet> xNumRule( + xCNSupplier->getChapterNumberingRules(), UNO_QUERY ); + DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" ); + if (xNumRule.is()) + { + xNumRule->getPropertyValue(sName) >>= sOutlineName; + } + } + + return rName == sOutlineName; +} diff --git a/xmloff/source/text/txtexppr.hxx b/xmloff/source/text/txtexppr.hxx new file mode 100644 index 000000000000..583727713fbf --- /dev/null +++ b/xmloff/source/text/txtexppr.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_TXTEXPPR_HXX +#define _XMLOFF_TXTEXPPR_HXX + + +#include <xmloff/xmlexppr.hxx> +#include "txtdrope.hxx" +#include "xmloff/xmltabe.hxx" +#include "XMLTextColumnsExport.hxx" +#ifndef _XMLOFF_XMLBACKGROUNDIMAGEEXPORT_HXX +#include "XMLBackgroundImageExport.hxx" +#endif + +class SvXMLExport; +class XMLTextExportPropertySetMapper: public SvXMLExportPropertyMapper +{ + SvXMLExport& rExport; + + ::rtl::OUString sDropCharStyle; + sal_Bool bDropWholeWord; + + void ContextFontFilter( + XMLPropertyState *pFontNameState, + XMLPropertyState *pFontFamilyNameState, + XMLPropertyState *pFontStyleNameState, + XMLPropertyState *pFontFamilyState, + XMLPropertyState *pFontPitchState, + XMLPropertyState *pFontCharsetState ) const; + void ContextFontHeightFilter( + XMLPropertyState* pCharHeightState, + XMLPropertyState* pCharPropHeightState, + XMLPropertyState* pCharDiffHeightState ) const; + +protected: +// SvXMLUnitConverter& mrUnitConverter; +// const Reference< xml::sax::XDocumentHandler > & mrHandler; + XMLTextDropCapExport maDropCapExport; + SvxXMLTabStopExport maTabStopExport; + XMLTextColumnsExport maTextColumnsExport; + XMLBackgroundImageExport maBackgroundImageExport; + + /** Application-specific filter. By default do nothing. */ + virtual void ContextFilter( + ::std::vector< XMLPropertyState >& rProperties, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > rPropSet ) const; + const SvXMLExport& GetExport() const { return rExport; } + +public: + + XMLTextExportPropertySetMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLExport& rExt ); + virtual ~XMLTextExportPropertySetMapper(); + + virtual void handleElementItem( + SvXMLExport& rExport, + const XMLPropertyState& rProperty, + sal_uInt16 nFlags, + const ::std::vector< XMLPropertyState > *pProperties = 0, + sal_uInt32 nIdx = 0 ) const; + + virtual void handleSpecialItem( + SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const ::std::vector< XMLPropertyState > *pProperties = 0, + sal_uInt32 nIdx = 0 ) const; +}; + + +#endif diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx new file mode 100644 index 000000000000..173c2f780162 --- /dev/null +++ b/xmloff/source/text/txtflde.cxx @@ -0,0 +1,3619 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +/** @#file + * + * export of all text fields + */ +#include "txtflde.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlnumfe.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlement.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlnume.hxx> +#include "xmloff/numehelp.hxx" + +#include <xmloff/families.hxx> +#include <xmloff/XMLEventExport.hxx> +#include "XMLTextCharStyleNamesElementExport.hxx" +#include <xmloff/nmspmap.hxx> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/text/UserDataPart.hpp> +#include <com/sun/star/text/PageNumberType.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <com/sun/star/text/ReferenceFieldPart.hpp> +#include <com/sun/star/text/ReferenceFieldSource.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> + +#include <com/sun/star/text/SetVariableType.hpp> +#include <com/sun/star/text/PlaceholderType.hpp> +#include <com/sun/star/text/FilenameDisplayFormat.hpp> +#include <com/sun/star/text/ChapterFormat.hpp> +#include <com/sun/star/text/TemplateDisplayFormat.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/util/NumberFormat.hpp> +#include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/sdb/CommandType.hpp> +#include <com/sun/star/rdf/XMetadatable.hpp> +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> +#include <rtl/math.hxx> + +#include <vector> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::container; +using namespace ::xmloff::token; + + +static sal_Char __READONLY_DATA FIELD_SERVICE_SENDER[] = "ExtendedUser"; +static sal_Char __READONLY_DATA FIELD_SERVICE_AUTHOR[] = "Author"; +static sal_Char __READONLY_DATA FIELD_SERVICE_JUMPEDIT[] = "JumpEdit"; +static sal_Char __READONLY_DATA FIELD_SERVICE_GETEXP[] = "GetExpression"; +static sal_Char __READONLY_DATA FIELD_SERVICE_SETEXP[] = "SetExpression"; +static sal_Char __READONLY_DATA FIELD_SERVICE_USER[] = "User"; +static sal_Char __READONLY_DATA FIELD_SERVICE_INPUT[] = "Input"; +static sal_Char __READONLY_DATA FIELD_SERVICE_USERINPUT[] = "InputUser"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DATETIME[] = "DateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_PAGENUMBER[] = "PageNumber"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NEXT[] = "DatabaseNextSet"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DB_SELECT[] = "DatabaseNumberOfSet"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NUMBER[] = "DatabaseSetNumber"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DB_DISPLAY[] = "Database"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NAME[] = "DatabaseName"; +static sal_Char __READONLY_DATA FIELD_SERVICE_CONDITIONAL_TEXT[] = "ConditionalText"; +static sal_Char __READONLY_DATA FIELD_SERVICE_HIDDEN_TEXT[] = "HiddenText"; +static sal_Char __READONLY_DATA FIELD_SERVICE_HIDDEN_PARAGRAPH[] = "HiddenParagraph"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR[] = "DocInfo.ChangeAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2[] = "docinfo.ChangeAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME[] = "DocInfo.ChangeDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2[] = "docinfo.ChangeDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_EDIT_TIME[] = "DocInfo.EditTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_EDIT_TIME2[] = "docinfo.EditTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_DESCRIPTION[] = "DocInfo.Description"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_DESCRIPTION2[] = "docinfo.Description"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR[] = "DocInfo.CreateAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2[] = "docinfo.CreateAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME[] = "DocInfo.CreateDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2[] = "docinfo.CreateDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CUSTOM[] = "DocInfo.Custom"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CUSTOM2[] = "docinfo.Custom"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR[] = "DocInfo.PrintAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2[] = "docinfo.PrintAuthor"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME[] = "DocInfo.PrintDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2[] = "docinfo.PrintDateTime"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_KEY_WORDS[] = "DocInfo.KeyWords"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_KEY_WORDS2[] = "docinfo.KeyWords"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_SUBJECT[] = "DocInfo.Subject"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_SUBJECT2[] = "docinfo.Subject"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_TITLE[] = "DocInfo.Title"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_TITLE2[] = "docinfo.Title"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_REVISION[] = "DocInfo.Revision"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_REVISION2[] = "docinfo.Revision"; +static sal_Char __READONLY_DATA FIELD_SERVICE_FILE_NAME[] = "FileName"; +static sal_Char __READONLY_DATA FIELD_SERVICE_CHAPTER[] = "Chapter"; +static sal_Char __READONLY_DATA FIELD_SERVICE_TEMPLATE_NAME[] = "TemplateName"; +static sal_Char __READONLY_DATA FIELD_SERVICE_PAGE_COUNT[] = "PageCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_PARAGRAPH_COUNT[] = "ParagraphCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_WORD_COUNT[] = "WordCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_CHARACTER_COUNT[] = "CharacterCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_TABLE_COUNT[] = "TableCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_GRAPHIC_COUNT[] = "GraphicObjectCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_OBJECT_COUNT[] = "EmbeddedObjectCount"; +static sal_Char __READONLY_DATA FIELD_SERVICE_REFERENCE_PAGE_SET[] = "ReferencePageSet"; +static sal_Char __READONLY_DATA FIELD_SERVICE_REFERENCE_PAGE_GET[] = "ReferencePageGet"; +static sal_Char __READONLY_DATA FIELD_SERVICE_SHEET_NAME[] = "SheetName"; +static sal_Char __READONLY_DATA FIELD_SERVICE_MACRO[] = "Macro"; +static sal_Char __READONLY_DATA FIELD_SERVICE_GET_REFERENCE[] = "GetReference"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DDE[] = "DDE"; +static sal_Char __READONLY_DATA FIELD_SERVICE_URL[] = "URL"; +static sal_Char __READONLY_DATA FIELD_SERVICE_BIBLIOGRAPHY[] = "Bibliography"; +static sal_Char __READONLY_DATA FIELD_SERVICE_SCRIPT[] = "Script"; +static sal_Char __READONLY_DATA FIELD_SERVICE_ANNOTATION[] = "Annotation"; +static sal_Char __READONLY_DATA FIELD_SERVICE_COMBINED_CHARACTERS[] = "CombinedCharacters"; +static sal_Char __READONLY_DATA FIELD_SERVICE_META[] = "MetadataField"; +static sal_Char __READONLY_DATA FIELD_SERVICE_MEASURE[] = "Measure"; +static sal_Char __READONLY_DATA FIELD_SERVICE_TABLE_FORMULA[] = "TableFormula"; +static sal_Char __READONLY_DATA FIELD_SERVICE_DROP_DOWN[] = "DropDown"; + +SvXMLEnumStringMapEntry __READONLY_DATA aFieldServiceNameMapping[] = +{ + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SENDER, FIELD_ID_SENDER ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_AUTHOR, FIELD_ID_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_JUMPEDIT, FIELD_ID_PLACEHOLDER ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GETEXP, FIELD_ID_VARIABLE_GET ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SETEXP, FIELD_ID_VARIABLE_SET ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USER, FIELD_ID_USER_GET ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_INPUT, FIELD_ID_TEXT_INPUT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USERINPUT, FIELD_ID_USER_INPUT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DATETIME, FIELD_ID_TIME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGENUMBER, FIELD_ID_PAGENUMBER ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_SET, FIELD_ID_REFPAGE_SET ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_GET, FIELD_ID_REFPAGE_GET ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NEXT, FIELD_ID_DATABASE_NEXT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_SELECT, FIELD_ID_DATABASE_SELECT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NUMBER, FIELD_ID_DATABASE_NUMBER ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_DISPLAY, FIELD_ID_DATABASE_DISPLAY ), + // workaround for #no-bug#: Database/DataBase + ENUM_STRING_MAP_ENTRY( "DataBase", FIELD_ID_DATABASE_DISPLAY ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NAME, FIELD_ID_DATABASE_NAME ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR, FIELD_ID_DOCINFO_CREATION_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2, FIELD_ID_DOCINFO_CREATION_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME, FIELD_ID_DOCINFO_CREATION_TIME), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2, FIELD_ID_DOCINFO_CREATION_TIME), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR, FIELD_ID_DOCINFO_SAVE_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2, FIELD_ID_DOCINFO_SAVE_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME, FIELD_ID_DOCINFO_SAVE_TIME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2, FIELD_ID_DOCINFO_SAVE_TIME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME, FIELD_ID_DOCINFO_EDIT_DURATION ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME2, FIELD_ID_DOCINFO_EDIT_DURATION ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION, FIELD_ID_DOCINFO_DESCRIPTION ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION2, FIELD_ID_DOCINFO_DESCRIPTION ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM, FIELD_ID_DOCINFO_CUSTOM ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM2, FIELD_ID_DOCINFO_CUSTOM ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR, FIELD_ID_DOCINFO_PRINT_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2, FIELD_ID_DOCINFO_PRINT_AUTHOR ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME, FIELD_ID_DOCINFO_PRINT_TIME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2, FIELD_ID_DOCINFO_PRINT_TIME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS, FIELD_ID_DOCINFO_KEYWORDS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS2, FIELD_ID_DOCINFO_KEYWORDS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT, FIELD_ID_DOCINFO_SUBJECT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT2, FIELD_ID_DOCINFO_SUBJECT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE, FIELD_ID_DOCINFO_TITLE ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE2, FIELD_ID_DOCINFO_TITLE ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION, FIELD_ID_DOCINFO_REVISION ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION2, FIELD_ID_DOCINFO_REVISION ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CONDITIONAL_TEXT, FIELD_ID_CONDITIONAL_TEXT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_TEXT, FIELD_ID_HIDDEN_TEXT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_PARAGRAPH, FIELD_ID_HIDDEN_PARAGRAPH ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_FILE_NAME, FIELD_ID_FILE_NAME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHAPTER, FIELD_ID_CHAPTER ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TEMPLATE_NAME, FIELD_ID_TEMPLATE_NAME ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGE_COUNT, FIELD_ID_COUNT_PAGES ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PARAGRAPH_COUNT, FIELD_ID_COUNT_PARAGRAPHS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_WORD_COUNT, FIELD_ID_COUNT_WORDS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHARACTER_COUNT, FIELD_ID_COUNT_CHARACTERS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_COUNT, FIELD_ID_COUNT_TABLES ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GRAPHIC_COUNT, FIELD_ID_COUNT_GRAPHICS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_OBJECT_COUNT, FIELD_ID_COUNT_OBJECTS ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MACRO, FIELD_ID_MACRO ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GET_REFERENCE, FIELD_ID_REF_REFERENCE ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DDE, FIELD_ID_DDE ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_BIBLIOGRAPHY, FIELD_ID_BIBLIOGRAPHY ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SCRIPT, FIELD_ID_SCRIPT ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_ANNOTATION, FIELD_ID_ANNOTATION ), + + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_COMBINED_CHARACTERS, FIELD_ID_COMBINED_CHARACTERS ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_META, FIELD_ID_META ), + + // non-writer fields + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SHEET_NAME, FIELD_ID_SHEET_NAME ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_URL, FIELD_ID_URL ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MEASURE, FIELD_ID_MEASURE ), + + // deprecated fields + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_FORMULA, FIELD_ID_TABLE_FORMULA ), + ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DROP_DOWN, FIELD_ID_DROP_DOWN ), + + ENUM_STRING_MAP_END() +}; + + + +// property accessor helper functions +inline sal_Bool GetBoolProperty(const OUString&, + const Reference<XPropertySet> &); +inline sal_Bool GetOptionalBoolProperty(const OUString&, + const Reference<XPropertySet> &, + const Reference<XPropertySetInfo> &, + sal_Bool bDefault); +inline double GetDoubleProperty(const OUString&, + const Reference<XPropertySet> &); +inline OUString const GetStringProperty(const OUString&, + const Reference<XPropertySet> &); +inline sal_Int32 GetIntProperty(const OUString&, + const Reference<XPropertySet> &); +inline sal_Int16 GetInt16Property(const OUString&, + const Reference<XPropertySet> &); +inline sal_Int8 GetInt8Property(const OUString&, + const Reference<XPropertySet> &); +inline DateTime const GetDateTimeProperty( const OUString& sPropName, + const Reference<XPropertySet> & xPropSet); +inline Date const GetDateProperty( const OUString& sPropName, + const Reference<XPropertySet> & xPropSet); +inline Sequence<OUString> const GetStringSequenceProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet); + + + +XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp, + XMLPropertyState* pCombinedCharState) + : rExport(rExp), + pUsedMasters(NULL), + sServicePrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.")), + sFieldMasterPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.FieldMaster.")), + sPresentationServicePrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TextField.")), + + sPropertyAdjust(RTL_CONSTASCII_USTRINGPARAM("Adjust")), + sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM("Author")), + sPropertyChapterFormat(RTL_CONSTASCII_USTRINGPARAM("ChapterFormat")), + sPropertyChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ChapterNumberingLevel")), + sPropertyCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")), + sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM("Condition")), + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM("Content")), + sPropertyDataBaseName(RTL_CONSTASCII_USTRINGPARAM("DataBaseName")), + sPropertyDataBaseURL(RTL_CONSTASCII_USTRINGPARAM("DataBaseURL")), + sPropertyDataColumnName(RTL_CONSTASCII_USTRINGPARAM("DataColumnName")), + sPropertyDataCommandType(RTL_CONSTASCII_USTRINGPARAM("DataCommandType")), + sPropertyDataTableName(RTL_CONSTASCII_USTRINGPARAM("DataTableName")), + sPropertyDate(RTL_CONSTASCII_USTRINGPARAM("Date")), + sPropertyDateTime(RTL_CONSTASCII_USTRINGPARAM("DateTime")), + sPropertyDateTimeValue(RTL_CONSTASCII_USTRINGPARAM("DateTimeValue")), + sPropertyDDECommandElement(RTL_CONSTASCII_USTRINGPARAM("DDECommandElement")), + sPropertyDDECommandFile(RTL_CONSTASCII_USTRINGPARAM("DDECommandFile")), + sPropertyDDECommandType(RTL_CONSTASCII_USTRINGPARAM("DDECommandType")), + sPropertyDependentTextFields(RTL_CONSTASCII_USTRINGPARAM("DependentTextFields")), + sPropertyFalseContent(RTL_CONSTASCII_USTRINGPARAM("FalseContent")), + sPropertyFields(RTL_CONSTASCII_USTRINGPARAM("Fields")), + sPropertyFieldSubType(RTL_CONSTASCII_USTRINGPARAM("UserDataType")), + sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM("FileFormat")), + sPropertyFullName(RTL_CONSTASCII_USTRINGPARAM("FullName")), + sPropertyHint(RTL_CONSTASCII_USTRINGPARAM("Hint")), + sPropertyInstanceName(RTL_CONSTASCII_USTRINGPARAM("InstanceName")), + sPropertyIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticUpdate")), + sPropertyIsConditionTrue(RTL_CONSTASCII_USTRINGPARAM("IsConditionTrue")), + sPropertyIsDataBaseFormat(RTL_CONSTASCII_USTRINGPARAM("DataBaseFormat")), + sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM("IsDate")), + sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM("IsExpression")), + sPropertyIsFixed(RTL_CONSTASCII_USTRINGPARAM("IsFixed")), + sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM("IsFixedLanguage")), + sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM("IsHidden")), + sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM("Input")), + sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")), + sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM("IsVisible")), + sPropertyItems(RTL_CONSTASCII_USTRINGPARAM("Items")), + sPropertyLevel(RTL_CONSTASCII_USTRINGPARAM("Level")), + sPropertyMacro(RTL_CONSTASCII_USTRINGPARAM("Macro")), + sPropertyMeasureKind(RTL_CONSTASCII_USTRINGPARAM("Kind")), + sPropertyName(RTL_CONSTASCII_USTRINGPARAM("Name")), + sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")), + sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM("NumberingSeparator")), + sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")), + sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM("Offset")), + sPropertyOn(RTL_CONSTASCII_USTRINGPARAM("On")), + sPropertyPlaceholder(RTL_CONSTASCII_USTRINGPARAM("PlaceHolder")), + sPropertyPlaceholderType(RTL_CONSTASCII_USTRINGPARAM("PlaceHolderType")), + sPropertyReferenceFieldPart(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldPart")), + sPropertyReferenceFieldSource(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldSource")), + sPropertyReferenceFieldType(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldType")), + sPropertyRevision(RTL_CONSTASCII_USTRINGPARAM("Revision")), + sPropertyScriptType(RTL_CONSTASCII_USTRINGPARAM("ScriptType")), + sPropertySelectedItem(RTL_CONSTASCII_USTRINGPARAM("SelectedItem")), + sPropertySequenceNumber(RTL_CONSTASCII_USTRINGPARAM("SequenceNumber")), + sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM("SequenceValue")), + sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM("SetNumber")), + sPropertySourceName(RTL_CONSTASCII_USTRINGPARAM("SourceName")), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM("SubType")), + sPropertyTargetFrame(RTL_CONSTASCII_USTRINGPARAM("TargetFrame")), + sPropertyTrueContent(RTL_CONSTASCII_USTRINGPARAM("TrueContent")), + sPropertyURL(RTL_CONSTASCII_USTRINGPARAM("URL")), + sPropertyURLContent(RTL_CONSTASCII_USTRINGPARAM("URLContent")), + sPropertyUserText(RTL_CONSTASCII_USTRINGPARAM("UserText")), + sPropertyValue(RTL_CONSTASCII_USTRINGPARAM("Value")), + sPropertyVariableName(RTL_CONSTASCII_USTRINGPARAM("VariableName")), + sPropertyVariableSubType(RTL_CONSTASCII_USTRINGPARAM("VariableSubtype")), + sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM("Help")), + sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM("Tooltip")), + sPropertyTextRange(RTL_CONSTASCII_USTRINGPARAM("TextRange")), + pCombinedCharactersPropertyState(pCombinedCharState) +{ + SetExportOnlyUsedFieldDeclarations(); +} + +XMLTextFieldExport::~XMLTextFieldExport() +{ + delete pCombinedCharactersPropertyState; + delete pUsedMasters; +} + +/// get the field ID (as in FieldIDEnum) from XTextField +enum FieldIdEnum XMLTextFieldExport::GetFieldID( + const Reference<XTextField> & rTextField, + const Reference<XPropertySet> & xPropSet) +{ + // get service names for rTextField (via XServiceInfo service) + Reference<XServiceInfo> xService(rTextField, UNO_QUERY); + const Sequence<OUString> aServices = xService->getSupportedServiceNames(); + const OUString* pNames = aServices.getConstArray(); + sal_Int32 nCount = aServices.getLength(); + + OUString sFieldName; // service name postfix of current field + + // search for TextField service name + while( nCount-- ) + { + if (pNames->matchIgnoreAsciiCase(sServicePrefix)) + { + // TextField found => postfix is field type! + sFieldName = pNames->copy(sServicePrefix.getLength()); + break; + } + + ++pNames; + } + + // if this is not a normal text field, check if its a presentation text field + if( sFieldName.getLength() == 0 ) + { + const OUString* pNames2 = aServices.getConstArray(); + sal_Int32 nCount2 = aServices.getLength(); + // search for TextField service name + while( nCount2-- ) + { + if( 0 == pNames2->compareTo(sPresentationServicePrefix, sPresentationServicePrefix.getLength())) + { + // TextField found => postfix is field type! + sFieldName = pNames2->copy(sPresentationServicePrefix.getLength()); + break; + } + + ++pNames2; + } + + if( sFieldName.getLength() != 0 ) + { + if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "Header" ) ) == 0 ) + { + return FIELD_ID_DRAW_HEADER; + } + else if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "Footer" ) ) == 0 ) + { + return FIELD_ID_DRAW_FOOTER; + } + else if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateTime" ) ) == 0 ) + { + return FIELD_ID_DRAW_DATE_TIME; + } + } + } + + // map postfix of service name to field ID + DBG_ASSERT(sFieldName.getLength()>0, "no TextField service found!"); + return MapFieldName(sFieldName, xPropSet); +} + +enum FieldIdEnum XMLTextFieldExport::MapFieldName( + const OUString& sFieldName, // field (master) name + const Reference<XPropertySet> & xPropSet) // for subtype +{ + // we'll proceed in 2 steps: + // a) map service name to preliminary FIELD_ID + // b) map those prelim. FIELD_IDs that correspond to several field types + // (in our (XML) world) to final FIELD IDs + + + // a) find prelim. FIELD_ID via aFieldServiceMapping + + // check for non-empty service name + DBG_ASSERT(sFieldName.getLength()>0, "no valid service name!"); + enum FieldIdEnum nToken = FIELD_ID_UNKNOWN; + if (sFieldName.getLength() > 0) + { + // map name to prelim. ID + sal_uInt16 nTmp; + sal_Bool bRet = GetExport().GetMM100UnitConverter().convertEnum( + nTmp, sFieldName, aFieldServiceNameMapping); + + // check return + DBG_ASSERT(bRet, "Unknown field service name encountered!"); + if (! bRet) + { + nToken = FIELD_ID_UNKNOWN; + } + else + { + nToken = (enum FieldIdEnum)nTmp; + } + } else { + // invalid service name + nToken = FIELD_ID_UNKNOWN; + } + + // b) map prelim. to final FIELD_IDs + switch (nToken) { + case FIELD_ID_VARIABLE_SET: + if (GetBoolProperty(sPropertyIsInput, xPropSet)) + { + nToken = FIELD_ID_VARIABLE_INPUT; + } + else + { + switch (GetIntProperty(sPropertySubType, xPropSet)) + { + case SetVariableType::STRING: // text field + case SetVariableType::VAR: // num field + nToken = FIELD_ID_VARIABLE_SET; + break; + case SetVariableType::SEQUENCE: + nToken = FIELD_ID_SEQUENCE; + break; + case SetVariableType::FORMULA: + default: + nToken = FIELD_ID_UNKNOWN; + break; + } + } + break; + + case FIELD_ID_VARIABLE_GET: + switch (GetIntProperty(sPropertySubType, xPropSet)) + { + case SetVariableType::STRING: // text field + case SetVariableType::VAR: // num field + nToken = FIELD_ID_VARIABLE_GET; + break; + case SetVariableType::FORMULA: + nToken = FIELD_ID_EXPRESSION; + break; + case SetVariableType::SEQUENCE: + default: + nToken = FIELD_ID_UNKNOWN; + break; + } + break; + + case FIELD_ID_TIME: + if (GetBoolProperty(sPropertyIsDate, xPropSet)) + { + nToken = FIELD_ID_DATE; + } + break; + + case FIELD_ID_PAGENUMBER: + // NumberingType not available in non-Writer apps + if (xPropSet->getPropertySetInfo()-> + hasPropertyByName(sPropertyNumberingType)) + { + if (NumberingType::CHAR_SPECIAL == GetIntProperty( + sPropertyNumberingType, xPropSet)) + { + nToken = FIELD_ID_PAGESTRING; + } + } + break; + + case FIELD_ID_DOCINFO_CREATION_TIME: + if (GetBoolProperty(sPropertyIsDate, xPropSet)) + { + nToken = FIELD_ID_DOCINFO_CREATION_DATE; + } + break; + + case FIELD_ID_DOCINFO_PRINT_TIME: + if (GetBoolProperty(sPropertyIsDate, xPropSet)) + { + nToken = FIELD_ID_DOCINFO_PRINT_DATE; + } + break; + + case FIELD_ID_DOCINFO_SAVE_TIME: + if (GetBoolProperty(sPropertyIsDate, xPropSet)) + { + nToken = FIELD_ID_DOCINFO_SAVE_DATE; + } + break; + + case FIELD_ID_REF_REFERENCE: + switch (GetInt16Property(sPropertyReferenceFieldSource, xPropSet)) + { + case ReferenceFieldSource::REFERENCE_MARK: + nToken = FIELD_ID_REF_REFERENCE; + break; + case ReferenceFieldSource::SEQUENCE_FIELD: + nToken = FIELD_ID_REF_SEQUENCE; + break; + case ReferenceFieldSource::BOOKMARK: + nToken = FIELD_ID_REF_BOOKMARK; + break; + case ReferenceFieldSource::FOOTNOTE: + nToken = FIELD_ID_REF_FOOTNOTE; + break; + case ReferenceFieldSource::ENDNOTE: + nToken = FIELD_ID_REF_ENDNOTE; + break; + default: + nToken = FIELD_ID_UNKNOWN; + break; + } + break; + + case FIELD_ID_COMBINED_CHARACTERS: + case FIELD_ID_SCRIPT: + case FIELD_ID_ANNOTATION: + case FIELD_ID_BIBLIOGRAPHY: + case FIELD_ID_DDE: + case FIELD_ID_MACRO: + case FIELD_ID_REFPAGE_SET: + case FIELD_ID_REFPAGE_GET: + case FIELD_ID_COUNT_PAGES: + case FIELD_ID_COUNT_PARAGRAPHS: + case FIELD_ID_COUNT_WORDS: + case FIELD_ID_COUNT_CHARACTERS: + case FIELD_ID_COUNT_TABLES: + case FIELD_ID_COUNT_GRAPHICS: + case FIELD_ID_COUNT_OBJECTS: + case FIELD_ID_CONDITIONAL_TEXT: + case FIELD_ID_HIDDEN_TEXT: + case FIELD_ID_HIDDEN_PARAGRAPH: + case FIELD_ID_DOCINFO_CREATION_AUTHOR: + case FIELD_ID_DOCINFO_DESCRIPTION: + case FIELD_ID_DOCINFO_CUSTOM: + case FIELD_ID_DOCINFO_PRINT_AUTHOR: + case FIELD_ID_DOCINFO_TITLE: + case FIELD_ID_DOCINFO_SUBJECT: + case FIELD_ID_DOCINFO_KEYWORDS: + case FIELD_ID_DOCINFO_REVISION: + case FIELD_ID_DOCINFO_EDIT_DURATION: + case FIELD_ID_DOCINFO_SAVE_AUTHOR: + case FIELD_ID_TEXT_INPUT: + case FIELD_ID_USER_INPUT: + case FIELD_ID_AUTHOR: + case FIELD_ID_SENDER: + case FIELD_ID_PLACEHOLDER: + case FIELD_ID_USER_GET: + case FIELD_ID_DATABASE_NEXT: + case FIELD_ID_DATABASE_SELECT: + case FIELD_ID_DATABASE_DISPLAY: + case FIELD_ID_DATABASE_NAME: + case FIELD_ID_DATABASE_NUMBER: + case FIELD_ID_TEMPLATE_NAME: + case FIELD_ID_CHAPTER: + case FIELD_ID_FILE_NAME: + case FIELD_ID_META: + case FIELD_ID_SHEET_NAME: + case FIELD_ID_MEASURE: + case FIELD_ID_URL: + case FIELD_ID_TABLE_FORMULA: + case FIELD_ID_DROP_DOWN: + ; // these field IDs are final + break; + + default: + nToken = FIELD_ID_UNKNOWN; + } + + // ... and return final FIELD_ID + return nToken; +} + +// is string or numeric field? +sal_Bool XMLTextFieldExport::IsStringField( + FieldIdEnum nFieldType, + const Reference<XPropertySet> & xPropSet) +{ + switch (nFieldType) { + + case FIELD_ID_VARIABLE_GET: + case FIELD_ID_VARIABLE_SET: + case FIELD_ID_VARIABLE_INPUT: + { + // depends on field sub type + return ( GetIntProperty(sPropertySubType, xPropSet) == + SetVariableType::STRING ); + } + + case FIELD_ID_USER_GET: + case FIELD_ID_USER_INPUT: + { + Reference<XTextField> xTextField(xPropSet, UNO_QUERY); + DBG_ASSERT(xTextField.is(), "field is no XTextField!"); + sal_Bool bRet = GetBoolProperty(sPropertyIsExpression, + GetMasterPropertySet(xTextField)); + return !bRet; + } + + case FIELD_ID_META: + return 0 > GetIntProperty(sPropertyNumberFormat, xPropSet); + + case FIELD_ID_DATABASE_DISPLAY: + // TODO: depends on... ??? + // workaround #no-bug#: no data type + return 5100 == GetIntProperty(sPropertyNumberFormat, xPropSet); + + case FIELD_ID_TABLE_FORMULA: + // legacy field: always a number field (because it always has + // a number format) + return sal_False; + + case FIELD_ID_COUNT_PAGES: + case FIELD_ID_COUNT_PARAGRAPHS: + case FIELD_ID_COUNT_WORDS: + case FIELD_ID_COUNT_CHARACTERS: + case FIELD_ID_COUNT_TABLES: + case FIELD_ID_COUNT_GRAPHICS: + case FIELD_ID_COUNT_OBJECTS: + case FIELD_ID_DOCINFO_SAVE_TIME: + case FIELD_ID_DOCINFO_SAVE_DATE: + case FIELD_ID_DOCINFO_CREATION_DATE: + case FIELD_ID_DOCINFO_CREATION_TIME: + case FIELD_ID_DOCINFO_PRINT_TIME: + case FIELD_ID_DOCINFO_PRINT_DATE: + case FIELD_ID_DOCINFO_EDIT_DURATION: + case FIELD_ID_DOCINFO_REVISION: + case FIELD_ID_DATABASE_NUMBER: + case FIELD_ID_EXPRESSION: + case FIELD_ID_SEQUENCE: + case FIELD_ID_DATE: + case FIELD_ID_TIME: + case FIELD_ID_PAGENUMBER: + case FIELD_ID_REFPAGE_SET: + case FIELD_ID_REFPAGE_GET: + case FIELD_ID_DOCINFO_CUSTOM: + // always number + return sal_False; + + case FIELD_ID_COMBINED_CHARACTERS: + case FIELD_ID_BIBLIOGRAPHY: + case FIELD_ID_DDE: + case FIELD_ID_REF_REFERENCE: + case FIELD_ID_REF_SEQUENCE: + case FIELD_ID_REF_BOOKMARK: + case FIELD_ID_REF_FOOTNOTE: + case FIELD_ID_REF_ENDNOTE: + case FIELD_ID_MACRO: + case FIELD_ID_TEMPLATE_NAME: + case FIELD_ID_CHAPTER: + case FIELD_ID_FILE_NAME: + case FIELD_ID_CONDITIONAL_TEXT: + case FIELD_ID_HIDDEN_TEXT: + case FIELD_ID_HIDDEN_PARAGRAPH: + case FIELD_ID_DOCINFO_CREATION_AUTHOR: + case FIELD_ID_DOCINFO_DESCRIPTION: + case FIELD_ID_DOCINFO_PRINT_AUTHOR: + case FIELD_ID_DOCINFO_TITLE: + case FIELD_ID_DOCINFO_SUBJECT: + case FIELD_ID_DOCINFO_KEYWORDS: + case FIELD_ID_DOCINFO_SAVE_AUTHOR: + case FIELD_ID_DATABASE_NAME: + case FIELD_ID_TEXT_INPUT: + case FIELD_ID_SENDER: + case FIELD_ID_AUTHOR: + case FIELD_ID_PAGESTRING: + case FIELD_ID_SHEET_NAME: + case FIELD_ID_MEASURE: + case FIELD_ID_URL: + case FIELD_ID_DROP_DOWN: + // always string: + return sal_True; + + case FIELD_ID_SCRIPT: + case FIELD_ID_ANNOTATION: + case FIELD_ID_DATABASE_NEXT: + case FIELD_ID_DATABASE_SELECT: + case FIELD_ID_VARIABLE_DECL: + case FIELD_ID_USER_DECL: + case FIELD_ID_SEQUENCE_DECL: + case FIELD_ID_PLACEHOLDER: + case FIELD_ID_UNKNOWN: + case FIELD_ID_DRAW_HEADER: + case FIELD_ID_DRAW_FOOTER: + case FIELD_ID_DRAW_DATE_TIME: + default: + DBG_ERROR("unkown field type/field has no content"); + return sal_True; // invalid info; string in case of doubt + } +} + +/// export the styles needed by the given field. Called on first pass +/// through document +void XMLTextFieldExport::ExportFieldAutoStyle( + const Reference<XTextField> & rTextField, const sal_Bool bProgress, + const sal_Bool bRecursive ) +{ + // get property set + Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY); + + // add field master to list of used field masters (if desired) + if (NULL != pUsedMasters) + { + Reference<XDependentTextField> xDepField(rTextField, UNO_QUERY); + if (xDepField.is()) + { + Reference<XText> xOurText = rTextField->getAnchor()->getText(); + + map<Reference<XText>, set<OUString> >::iterator aMapIter = + pUsedMasters->find(xOurText); + + // insert a list for our XText (if necessary) + if (aMapIter == pUsedMasters->end()) + { + set<OUString> aSet; + (*pUsedMasters)[xOurText] = aSet; + aMapIter = pUsedMasters->find(xOurText); + } + + // insert this text field master + OUString sFieldMasterName = GetStringProperty( + sPropertyInstanceName, xDepField->getTextFieldMaster()); + if (sFieldMasterName.getLength() > 0) + aMapIter->second.insert( sFieldMasterName ); + } + // else: no dependent field -> no master -> ignore + } + + // get Field ID + FieldIdEnum nToken = GetFieldID(rTextField, xPropSet); + + // export the character style for all fields + // with one exception: combined character fields export their own + // text style below + Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY); + if (FIELD_ID_COMBINED_CHARACTERS != nToken) + { + GetExport().GetTextParagraphExport()->Add( + XML_STYLE_FAMILY_TEXT_TEXT, xRangePropSet); + } + + // process special styles for each field (e.g. data styles) + switch (nToken) { + + case FIELD_ID_DATABASE_DISPLAY: + { + sal_Int32 nFormat = GetIntProperty(sPropertyNumberFormat, xPropSet); + // workaround: #no-bug#; see IsStringField(...) + if ( (5100 != nFormat) && + !GetBoolProperty(sPropertyIsDataBaseFormat, xPropSet) ) + { + GetExport().addDataStyle(nFormat); + } + break; + } + + case FIELD_ID_DATE: + case FIELD_ID_TIME: + { + // date and time fields are always number fields, but the + // NumberFormat property is optional (e.g. Calc doesn't + // support it) + Reference<XPropertySetInfo> xPropSetInfo( + xPropSet->getPropertySetInfo() ); + if ( xPropSetInfo->hasPropertyByName( sPropertyNumberFormat ) ) + { + sal_Int32 nFormat = + GetIntProperty(sPropertyNumberFormat, xPropSet); + + // nFormat may be -1 for numeric fields that display their + // variable name. (Maybe this should be a field type, then?) + if (nFormat != -1) + { + if( ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + xPropSet, xPropSetInfo, sal_False ) ) + { + nFormat = + GetExport().dataStyleForceSystemLanguage(nFormat); + } + + GetExport().addDataStyle( nFormat, + nToken == FIELD_ID_TIME ); + } + } + } + break; + + case FIELD_ID_META: + // recurse into content (does not export element, so can be done first) + if (bRecursive) + { + ExportMetaField(xPropSet, true, bProgress); + } + // fall-through: for the meta-field itself! + case FIELD_ID_DOCINFO_PRINT_TIME: + case FIELD_ID_DOCINFO_PRINT_DATE: + case FIELD_ID_DOCINFO_CREATION_DATE: + case FIELD_ID_DOCINFO_CREATION_TIME: + case FIELD_ID_DOCINFO_SAVE_TIME: + case FIELD_ID_DOCINFO_SAVE_DATE: + case FIELD_ID_DOCINFO_EDIT_DURATION: + case FIELD_ID_VARIABLE_SET: + case FIELD_ID_VARIABLE_GET: + case FIELD_ID_VARIABLE_INPUT: + case FIELD_ID_USER_GET: + case FIELD_ID_EXPRESSION: + case FIELD_ID_TABLE_FORMULA: + case FIELD_ID_DOCINFO_CUSTOM: + // register number format, if this is a numeric field + if (! IsStringField(nToken, xPropSet)) { + + sal_Int32 nFormat = + GetIntProperty(sPropertyNumberFormat, xPropSet); + + // nFormat may be -1 for numeric fields that display their + // variable name. (Maybe this should be a field type, then?) + if (nFormat != -1) + { + // handle formats for fixed language fields + // for all these fields (except table formula) + if( ( nToken != FIELD_ID_TABLE_FORMULA ) && + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + xPropSet, xPropSet->getPropertySetInfo(), + sal_False ) ) + { + nFormat = + GetExport().dataStyleForceSystemLanguage(nFormat); + } + + GetExport().addDataStyle(nFormat); + } + } + break; + + case FIELD_ID_COMBINED_CHARACTERS: + { + // export text style with the addition of the combined characters + DBG_ASSERT(NULL != pCombinedCharactersPropertyState, + "need proper PropertyState for combined characters"); + const XMLPropertyState *aStates[] = { pCombinedCharactersPropertyState, 0 }; + GetExport().GetTextParagraphExport()->Add( + XML_STYLE_FAMILY_TEXT_TEXT, xRangePropSet, + aStates); + break; + } + + case FIELD_ID_SCRIPT: + case FIELD_ID_ANNOTATION: + case FIELD_ID_BIBLIOGRAPHY: + case FIELD_ID_DDE: + case FIELD_ID_REF_REFERENCE: + case FIELD_ID_REF_SEQUENCE: + case FIELD_ID_REF_BOOKMARK: + case FIELD_ID_REF_FOOTNOTE: + case FIELD_ID_REF_ENDNOTE: + case FIELD_ID_MACRO: + case FIELD_ID_REFPAGE_SET: + case FIELD_ID_REFPAGE_GET: + case FIELD_ID_COUNT_PAGES: + case FIELD_ID_COUNT_PARAGRAPHS: + case FIELD_ID_COUNT_WORDS: + case FIELD_ID_COUNT_CHARACTERS: + case FIELD_ID_COUNT_TABLES: + case FIELD_ID_COUNT_GRAPHICS: + case FIELD_ID_COUNT_OBJECTS: + case FIELD_ID_CONDITIONAL_TEXT: + case FIELD_ID_HIDDEN_TEXT: + case FIELD_ID_HIDDEN_PARAGRAPH: + case FIELD_ID_DOCINFO_CREATION_AUTHOR: + case FIELD_ID_DOCINFO_DESCRIPTION: + case FIELD_ID_DOCINFO_PRINT_AUTHOR: + case FIELD_ID_DOCINFO_TITLE: + case FIELD_ID_DOCINFO_SUBJECT: + case FIELD_ID_DOCINFO_KEYWORDS: + case FIELD_ID_DOCINFO_REVISION: + case FIELD_ID_DOCINFO_SAVE_AUTHOR: + case FIELD_ID_SEQUENCE: + case FIELD_ID_PAGENUMBER: + case FIELD_ID_PAGESTRING: + case FIELD_ID_AUTHOR: + case FIELD_ID_SENDER: + case FIELD_ID_PLACEHOLDER: + case FIELD_ID_USER_INPUT: + case FIELD_ID_TEXT_INPUT: + case FIELD_ID_DATABASE_NEXT: + case FIELD_ID_DATABASE_SELECT: + case FIELD_ID_DATABASE_NAME: + case FIELD_ID_DATABASE_NUMBER: + case FIELD_ID_TEMPLATE_NAME: + case FIELD_ID_CHAPTER: + case FIELD_ID_FILE_NAME: + case FIELD_ID_SHEET_NAME: + case FIELD_ID_MEASURE: + case FIELD_ID_URL: + case FIELD_ID_DROP_DOWN: + case FIELD_ID_DRAW_DATE_TIME: + case FIELD_ID_DRAW_FOOTER: + case FIELD_ID_DRAW_HEADER: + ; // no formats for these fields! + break; + + case FIELD_ID_UNKNOWN: + default: + DBG_ERROR("unkown field type!"); + // ignore -> no format for unkowns + break; + } +} + +/// export the given field to XML. Called on second pass through document +void XMLTextFieldExport::ExportField( + const Reference<XTextField> & rTextField, sal_Bool bProgress ) +{ + // get property set + Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY); + + // get property set of range (for the attributes) + Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY); + + // get Field ID + enum FieldIdEnum nToken = GetFieldID(rTextField, xPropSet); + + // special treatment for combined characters field, because it is + // exported as a style + const XMLPropertyState* aStates[] = { pCombinedCharactersPropertyState, 0 }; + const XMLPropertyState **pStates = + FIELD_ID_COMBINED_CHARACTERS == nToken + ? aStates + : 0; + + // find out whether we need to set the style or hyperlink + sal_Bool bHasHyperlink; + sal_Bool bIsUICharStyle; + sal_Bool bHasAutoStyle; + OUString sStyle = GetExport().GetTextParagraphExport()-> + FindTextStyleAndHyperlink( xRangePropSet, bHasHyperlink, bIsUICharStyle, + bHasAutoStyle, pStates ); + sal_Bool bHasStyle = (sStyle.getLength() > 0); + + // export hyperlink (if we have one) + Reference < XPropertySetInfo > xRangePropSetInfo; + if( bHasHyperlink ) + { + Reference<XPropertyState> xRangePropState( xRangePropSet, UNO_QUERY ); + xRangePropSetInfo = xRangePropSet->getPropertySetInfo(); + bHasHyperlink = + GetExport().GetTextParagraphExport()->addHyperlinkAttributes( + xRangePropSet, xRangePropState, + xRangePropSetInfo ); + } + SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink, + XML_NAMESPACE_TEXT, XML_A, + sal_False, sal_False ); + + if( bHasHyperlink ) + { + // export events (if supported) + OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM( + "HyperLinkEvents")); + if (xRangePropSetInfo->hasPropertyByName(sHyperLinkEvents)) + { + Any aAny = xRangePropSet->getPropertyValue(sHyperLinkEvents); + Reference<XNameReplace> xName; + aAny >>= xName; + GetExport().GetEventExport().Export(xName, sal_False); + } + } + + { + XMLTextCharStyleNamesElementExport aCharStylesExport( + GetExport(), bIsUICharStyle && + GetExport().GetTextParagraphExport() + ->GetCharStyleNamesPropInfoCache().hasProperty( + xRangePropSet, xRangePropSetInfo ), bHasAutoStyle, + xRangePropSet, sPropertyCharStyleNames ); + + // export span with style (if necessary) + // (except for combined characters field) + if( bHasStyle ) + { + // export <text:span> element + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyle ) ); + } + SvXMLElementExport aSpan( GetExport(), bHasStyle, + XML_NAMESPACE_TEXT, XML_SPAN, + sal_False, sal_False); + + // finally, export the field itself + ExportFieldHelper( rTextField, xPropSet, xRangePropSet, nToken, + bProgress ); + } +} + +/// export the given field to XML. Called on second pass through document +void XMLTextFieldExport::ExportFieldHelper( + const Reference<XTextField> & rTextField, + const Reference<XPropertySet> & rPropSet, + const Reference<XPropertySet> &, + enum FieldIdEnum nToken, + sal_Bool bProgress ) +{ + // get property set info (because some attributes are not support + // in all implementations) + Reference<XPropertySetInfo> xPropSetInfo(rPropSet->getPropertySetInfo()); + + OUString sPresentation = rTextField->getPresentation(sal_False); + + // process each field type + switch (nToken) { + case FIELD_ID_AUTHOR: + // author field: fixed, field (sub-)type + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), sal_True); + ExportElement(MapAuthorFieldName(rPropSet), sPresentation); + break; + + case FIELD_ID_SENDER: + // sender field: fixed, field (sub-)type + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), sal_True); + ExportElement(MapSenderFieldName(rPropSet), sPresentation); + break; + + case FIELD_ID_PLACEHOLDER: + // placeholder field: type, name, description + ProcessString(XML_PLACEHOLDER_TYPE, + MapPlaceholderType( + GetInt16Property(sPropertyPlaceholderType, rPropSet))); + ProcessString(XML_DESCRIPTION, + GetStringProperty(sPropertyHint,rPropSet), sal_True); + ExportElement(XML_PLACEHOLDER, sPresentation); + break; + + case FIELD_ID_VARIABLE_SET: + { + // variable set field: name, visible, format&value + ProcessString(XML_NAME, + GetStringProperty(sPropertyVariableName, rPropSet)); + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + sal_False); + ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyContent, rPropSet), + sPresentation); + ProcessValueAndType(IsStringField(nToken, rPropSet), + GetIntProperty(sPropertyNumberFormat, rPropSet), + GetStringProperty(sPropertyContent, rPropSet), + sPresentation, + GetDoubleProperty(sPropertyValue, rPropSet), + sal_True, sal_True, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + ExportElement(XML_VARIABLE_SET, sPresentation); + break; + } + case FIELD_ID_VARIABLE_GET: + { + // variable get field: name, format&value + ProcessString(XML_NAME, + GetStringProperty(sPropertyContent, rPropSet)); + sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet); + ProcessDisplay(sal_True, bCmd); + // #i81766# for older versions export of the value-type + sal_Bool bExportValueType = !bCmd && ( GetExport().getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE ); + // show style, unless name will be shown + ProcessValueAndType(IsStringField(nToken, rPropSet), + GetIntProperty(sPropertyNumberFormat, rPropSet), + sEmpty, sEmpty, 0.0, // values not used + sal_False, + bExportValueType, + !bCmd, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + ExportElement(XML_VARIABLE_GET, sPresentation); + break; + } + case FIELD_ID_VARIABLE_INPUT: + // variable input field: name, description, format&value + ProcessString(XML_NAME, + GetStringProperty(sPropertyVariableName, rPropSet)); + ProcessString(XML_DESCRIPTION, + GetStringProperty(sPropertyHint , rPropSet)); + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + sal_False); + ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyContent, rPropSet), + sPresentation); + ProcessValueAndType(IsStringField(nToken, rPropSet), + GetIntProperty(sPropertyNumberFormat, rPropSet), + GetStringProperty(sPropertyContent, rPropSet), + sPresentation, + GetDoubleProperty(sPropertyValue, rPropSet), + sal_True, sal_True, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + ExportElement(XML_VARIABLE_INPUT, sPresentation); + break; + + case FIELD_ID_USER_GET: + // user field: name, hidden, style + { + sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet); + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + bCmd); + ProcessValueAndType(IsStringField(nToken, rPropSet), + GetIntProperty(sPropertyNumberFormat, rPropSet), + sEmpty, sEmpty, 0.0, // values not used + sal_False, sal_False, !bCmd, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + + // name from FieldMaster + ProcessString(XML_NAME, + GetStringProperty(sPropertyName, + GetMasterPropertySet(rTextField))); + ExportElement(XML_USER_FIELD_GET, sPresentation); + break; + } + + case FIELD_ID_USER_INPUT: + // user input field: name (from FieldMaster), description +// ProcessString(XML_NAME, +// GetStringProperty(sPropertyName, +// GetMasterPropertySet(rTextField))); + ProcessString(XML_NAME, + GetStringProperty(sPropertyContent, rPropSet)); + ProcessString(XML_DESCRIPTION, + GetStringProperty(sPropertyHint, rPropSet)); + ExportElement(XML_USER_FIELD_INPUT, sPresentation); + break; + + case FIELD_ID_SEQUENCE: + { + // sequence field: name, formula, seq-format + OUString sName = GetStringProperty(sPropertyVariableName, rPropSet); + // TODO: use reference name only if actually beeing referenced. + ProcessString(XML_REF_NAME, + MakeSequenceRefName( + GetInt16Property(sPropertySequenceValue, rPropSet), + sName)); + ProcessString(XML_NAME, sName); + ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyContent, rPropSet), + sPresentation); + ProcessNumberingType(GetInt16Property(sPropertyNumberingType, + rPropSet)); + ExportElement(XML_SEQUENCE, sPresentation); + break; + } + + case FIELD_ID_EXPRESSION: + { + // formula field: formula, format&value + sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet); + ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyContent, rPropSet), + sPresentation); + ProcessDisplay(sal_True, bCmd); + ProcessValueAndType(IsStringField(nToken, rPropSet), + GetIntProperty(sPropertyNumberFormat, rPropSet), + GetStringProperty(sPropertyContent, rPropSet), + sPresentation, + GetDoubleProperty(sPropertyValue, rPropSet), + !bCmd, !bCmd, !bCmd, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + ExportElement(XML_EXPRESSION, sPresentation); + break; + } + + case FIELD_ID_TEXT_INPUT: + // text input field: description and string-value + ProcessString(XML_DESCRIPTION, + GetStringProperty(sPropertyHint, rPropSet)); + ProcessString(XML_HELP, + GetStringProperty(sPropertyHelp, rPropSet), true); + ProcessString(XML_HINT, + GetStringProperty(sPropertyTooltip, rPropSet), true); + ExportElement(XML_TEXT_INPUT, sPresentation); + break; + + case FIELD_ID_TIME: + // all properties (except IsDate) are optional! + if (xPropSetInfo->hasPropertyByName(sPropertyNumberFormat)) + { + ProcessValueAndType(sal_False, + GetIntProperty(sPropertyNumberFormat,rPropSet), + sEmpty, sEmpty, 0.0, // not used + sal_False, sal_False, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ), + sal_True); + } + if (xPropSetInfo->hasPropertyByName(sPropertyDateTimeValue)) + { + // no value -> current time + ProcessDateTime(XML_TIME_VALUE, + GetDateTimeProperty(sPropertyDateTimeValue, + rPropSet), + sal_False ); + } + if (xPropSetInfo->hasPropertyByName(sPropertyDateTime)) + { + // no value -> current time + ProcessDateTime(XML_TIME_VALUE, + GetDateTimeProperty(sPropertyDateTime,rPropSet), + sal_False ); + } + if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed)) + { + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), + sal_False); + } + if (xPropSetInfo->hasPropertyByName(sPropertyAdjust)) + { + // adjust value given as integer in minutes + ProcessDateTime(XML_TIME_ADJUST, + GetIntProperty(sPropertyAdjust, rPropSet), + sal_False, sal_True, sal_True); + } + ExportElement(XML_TIME, sPresentation); + break; + + case FIELD_ID_DATE: + // all properties (except IsDate) are optional! + if (xPropSetInfo->hasPropertyByName(sPropertyNumberFormat)) + { + ProcessValueAndType(sal_False, + GetIntProperty(sPropertyNumberFormat,rPropSet), + sEmpty, sEmpty, 0.0, // not used + sal_False, sal_False, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + } + if (xPropSetInfo->hasPropertyByName(sPropertyDateTimeValue)) + { + // no value -> current date + ProcessDateTime(XML_DATE_VALUE, + GetDateTimeProperty(sPropertyDateTimeValue, + rPropSet), + // #96457#: date fields should also save time + sal_False); + } + // TODO: remove double-handling after SRC614 + else if (xPropSetInfo->hasPropertyByName(sPropertyDateTime)) + { + ProcessDateTime(XML_DATE_VALUE, + GetDateTimeProperty(sPropertyDateTime,rPropSet), + // #96457#: date fields should also save time + sal_False); + } + if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed)) + { + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), + sal_False); + } + if (xPropSetInfo->hasPropertyByName(sPropertyAdjust)) + { + // adjust value given as number of days + ProcessDateTime(XML_DATE_ADJUST, + GetIntProperty(sPropertyAdjust, rPropSet), + sal_True, sal_True, sal_True); + } + ExportElement(XML_DATE, sPresentation); + break; + + case FIELD_ID_PAGENUMBER: + // all properties are optional + if (xPropSetInfo->hasPropertyByName(sPropertyNumberingType)) + { + ProcessNumberingType(GetInt16Property(sPropertyNumberingType, + rPropSet)); + } + if (xPropSetInfo->hasPropertyByName(sPropertyOffset)) + { + sal_Int32 nAdjust = GetIntProperty(sPropertyOffset, rPropSet); + + if (xPropSetInfo->hasPropertyByName(sPropertySubType)) + { + // property SubType used in MapPageNumebrName + ProcessString(XML_SELECT_PAGE, + MapPageNumberName(rPropSet, nAdjust)); + } + ProcessIntegerDef(XML_PAGE_ADJUST, nAdjust, 0); + } + ExportElement(XML_PAGE_NUMBER, sPresentation); + break; + + case FIELD_ID_PAGESTRING: + { + ProcessString(XML_STRING_VALUE, + GetStringProperty(sPropertyUserText, rPropSet), + sPresentation); + sal_Int32 nDummy = 0; // MapPageNumberName need int + ProcessString(XML_SELECT_PAGE, MapPageNumberName(rPropSet, nDummy)); + if( 0 == ( GetExport().getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE ) ) + ExportElement(XML_PAGE_CONTINUATION, sPresentation); + else + ExportElement(XML_PAGE_CONTINUATION_STRING, sPresentation); + break; + } + + case FIELD_ID_DATABASE_NAME: + ProcessString(XML_TABLE_NAME, + GetStringProperty(sPropertyDataTableName, rPropSet)); + ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet)); + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + sal_False); + ExportDataBaseElement(XML_DATABASE_NAME, sPresentation, + rPropSet, xPropSetInfo); + break; + + case FIELD_ID_DATABASE_NUMBER: + ProcessString(XML_TABLE_NAME, + GetStringProperty(sPropertyDataTableName, rPropSet)); + ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet)); + ProcessNumberingType( + GetInt16Property(sPropertyNumberingType,rPropSet)); + ProcessInteger(XML_VALUE, + GetIntProperty(sPropertySetNumber, rPropSet)); + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + sal_False); + ExportDataBaseElement(XML_DATABASE_ROW_NUMBER, sPresentation, + rPropSet, xPropSetInfo); + break; + + case FIELD_ID_DATABASE_NEXT: + ProcessString(XML_TABLE_NAME, + GetStringProperty(sPropertyDataTableName, rPropSet)); + ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet)); + ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyCondition, rPropSet)); + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation for database next field"); + ExportDataBaseElement(XML_DATABASE_NEXT, OUString(), + rPropSet, xPropSetInfo); + break; + + case FIELD_ID_DATABASE_SELECT: + ProcessString(XML_TABLE_NAME, + GetStringProperty(sPropertyDataTableName, rPropSet)); + ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet)); + ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyCondition, rPropSet)); + ProcessInteger(XML_ROW_NUMBER, + GetIntProperty(sPropertySetNumber, rPropSet)); + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation for database select field"); + ExportDataBaseElement(XML_DATABASE_ROW_SELECT, OUString(), + rPropSet, xPropSetInfo); + break; + + case FIELD_ID_DATABASE_DISPLAY: + { + // get database, table and column name from field master + const Reference<XPropertySet> & xMaster = GetMasterPropertySet(rTextField); + ProcessString(XML_TABLE_NAME, + GetStringProperty(sPropertyDataTableName, xMaster)); + ProcessCommandType(GetIntProperty(sPropertyDataCommandType, xMaster)); + ProcessString(XML_COLUMN_NAME, + GetStringProperty(sPropertyDataColumnName, xMaster)); + // export number format if available (happens only for numbers!) + if (!GetBoolProperty(sPropertyIsDataBaseFormat, rPropSet)) + { + ProcessValueAndType(sal_False, // doesn't happen for text + GetIntProperty(sPropertyNumberFormat,rPropSet), + sEmpty, sEmpty, 0.0, // not used + sal_False, sal_False, sal_True, sal_False); + } + ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet), + sal_False); + ExportDataBaseElement(XML_DATABASE_DISPLAY, sPresentation, + xMaster, xMaster->getPropertySetInfo()); + break; + } + + case FIELD_ID_DOCINFO_REVISION: + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False); + ExportElement(MapDocInfoFieldName(nToken), sPresentation); + break; + + case FIELD_ID_DOCINFO_EDIT_DURATION: + case FIELD_ID_DOCINFO_SAVE_TIME: + case FIELD_ID_DOCINFO_CREATION_TIME: + case FIELD_ID_DOCINFO_PRINT_TIME: + case FIELD_ID_DOCINFO_SAVE_DATE: + case FIELD_ID_DOCINFO_CREATION_DATE: + case FIELD_ID_DOCINFO_PRINT_DATE: + ProcessValueAndType(sal_False, + GetIntProperty(sPropertyNumberFormat, rPropSet), + sEmpty, sEmpty, 0.0, + sal_False, sal_False, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False ) ); + + // todo: export date/time value, but values not available -> core bug + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False); + ExportElement(MapDocInfoFieldName(nToken), sPresentation); + break; + + case FIELD_ID_DOCINFO_CREATION_AUTHOR: + case FIELD_ID_DOCINFO_DESCRIPTION: + case FIELD_ID_DOCINFO_PRINT_AUTHOR: + case FIELD_ID_DOCINFO_TITLE: + case FIELD_ID_DOCINFO_SUBJECT: + case FIELD_ID_DOCINFO_KEYWORDS: + case FIELD_ID_DOCINFO_SAVE_AUTHOR: + if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed)) + { + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False); + } + ExportElement(MapDocInfoFieldName(nToken), sPresentation); + break; + + case FIELD_ID_DOCINFO_CUSTOM: + { + ProcessValueAndType(sal_False, // doesn't happen for text + GetIntProperty(sPropertyNumberFormat,rPropSet), + sEmpty, sEmpty, 0.0, // not used + sal_False, sal_False, sal_True, + ! GetOptionalBoolProperty( + sPropertyIsFixedLanguage, + rPropSet, xPropSetInfo, sal_False )); + uno::Any aAny = rPropSet->getPropertyValue( sPropertyName ); + ::rtl::OUString sName; + aAny >>= sName; + ProcessString(XML_NAME, sName); + ProcessBoolean(XML_FIXED, GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False); + ExportElement(XML_USER_DEFINED, sPresentation); + break; + } + + case FIELD_ID_COUNT_PAGES: + case FIELD_ID_COUNT_PARAGRAPHS: + case FIELD_ID_COUNT_WORDS: + case FIELD_ID_COUNT_CHARACTERS: + case FIELD_ID_COUNT_TABLES: + case FIELD_ID_COUNT_GRAPHICS: + case FIELD_ID_COUNT_OBJECTS: + // all properties optional (applies to pages only, but I'll do + // it for all for sake of common implementation) + if (xPropSetInfo->hasPropertyByName(sPropertyNumberingType)) + { + ProcessNumberingType(GetInt16Property(sPropertyNumberingType, + rPropSet)); + } + ExportElement(MapCountFieldName(nToken), sPresentation); + break; + + case FIELD_ID_CONDITIONAL_TEXT: + ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyCondition, rPropSet)); + ProcessString(XML_STRING_VALUE_IF_TRUE, + GetStringProperty(sPropertyTrueContent, rPropSet)); + ProcessString(XML_STRING_VALUE_IF_FALSE, + GetStringProperty(sPropertyFalseContent, rPropSet)); + ProcessBoolean(XML_CURRENT_VALUE, + GetBoolProperty(sPropertyIsConditionTrue, rPropSet), + sal_False); + ExportElement(XML_CONDITIONAL_TEXT, sPresentation); + break; + + case FIELD_ID_HIDDEN_TEXT: + ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyCondition, rPropSet)); + ProcessString(XML_STRING_VALUE, + GetStringProperty(sPropertyContent, rPropSet)); + ProcessBoolean(XML_IS_HIDDEN, + GetBoolProperty(sPropertyIsHidden, rPropSet), + sal_False); + ExportElement(XML_HIDDEN_TEXT, sPresentation); + break; + + case FIELD_ID_HIDDEN_PARAGRAPH: + ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyCondition, rPropSet)); + ProcessBoolean(XML_IS_HIDDEN, + GetBoolProperty(sPropertyIsHidden, rPropSet), + sal_False); + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation for hidden paragraph field"); + ExportElement(XML_HIDDEN_PARAGRAPH); + break; + + case FIELD_ID_TEMPLATE_NAME: + ProcessString(XML_DISPLAY, + MapTemplateDisplayFormat( + GetInt16Property(sPropertyFileFormat, rPropSet))); + ExportElement(XML_TEMPLATE_NAME, sPresentation); + break; + + case FIELD_ID_CHAPTER: + ProcessString(XML_DISPLAY, + MapChapterDisplayFormat( + GetInt16Property(sPropertyChapterFormat, rPropSet))); + // API numbers 0..9, we number 1..10 + ProcessInteger(XML_OUTLINE_LEVEL, + GetInt8Property(sPropertyLevel, rPropSet) + 1); + ExportElement(XML_CHAPTER, sPresentation); + break; + + case FIELD_ID_FILE_NAME: + // all properties are optional + if (xPropSetInfo->hasPropertyByName(sPropertyFileFormat)) + { + ProcessString(XML_DISPLAY, + MapFilenameDisplayFormat( + GetInt16Property(sPropertyFileFormat, rPropSet))); + } + if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed)) + { + ProcessBoolean(XML_FIXED, + GetBoolProperty(sPropertyIsFixed, rPropSet), + sal_False); + } + ExportElement(XML_FILE_NAME, sPresentation); + break; + + case FIELD_ID_REFPAGE_SET: + ProcessBoolean(XML_ACTIVE, + GetBoolProperty(sPropertyOn, rPropSet), sal_True); + ProcessIntegerDef(XML_PAGE_ADJUST, + GetInt16Property(sPropertyOffset, rPropSet), 0); + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation page variable field"); + ExportElement(XML_PAGE_VARIABLE_SET); + break; + + case FIELD_ID_REFPAGE_GET: + ProcessNumberingType( + GetInt16Property(sPropertyNumberingType, rPropSet)); + ExportElement(XML_PAGE_VARIABLE_GET, sPresentation); + break; + + case FIELD_ID_MACRO: + ExportMacro( rPropSet, sPresentation ); + break; + + case FIELD_ID_REF_SEQUENCE: + // reference to sequence: format, name, find value (and element) + // was: if (nSeqNumber != -1) ... + ProcessString(XML_REFERENCE_FORMAT, + MapReferenceType(GetInt16Property( + sPropertyReferenceFieldPart, rPropSet)), + XML_TEMPLATE); + ProcessString(XML_REF_NAME, + MakeSequenceRefName( + GetInt16Property(sPropertySequenceNumber, rPropSet), + GetStringProperty(sPropertySourceName, rPropSet) ) ); + ExportElement( + MapReferenceSource( + GetInt16Property(sPropertyReferenceFieldSource, rPropSet)), + sPresentation); + break; + + case FIELD_ID_REF_REFERENCE: + case FIELD_ID_REF_BOOKMARK: + // reference to bookmarks, references: format, name (and element) + ProcessString(XML_REFERENCE_FORMAT, + MapReferenceType(GetInt16Property( + sPropertyReferenceFieldPart, rPropSet)), + XML_TEMPLATE); + ProcessString(XML_REF_NAME, + GetStringProperty(sPropertySourceName, rPropSet)); + ExportElement( + MapReferenceSource(GetInt16Property( + sPropertyReferenceFieldSource, rPropSet)), + sPresentation); + break; + + case FIELD_ID_REF_FOOTNOTE: + case FIELD_ID_REF_ENDNOTE: + // reference to end-/footnote: format, generate name, (and element) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_NOTE_CLASS, + FIELD_ID_REF_ENDNOTE==nToken ? XML_ENDNOTE : XML_FOOTNOTE ); + ProcessString(XML_REFERENCE_FORMAT, + MapReferenceType(GetInt16Property( + sPropertyReferenceFieldPart, rPropSet)), + XML_TEMPLATE); + ProcessString(XML_REF_NAME, + MakeFootnoteRefName(GetInt16Property( + sPropertySequenceNumber, rPropSet))); + ExportElement( + MapReferenceSource(GetInt16Property( + sPropertyReferenceFieldSource, rPropSet)), + sPresentation); + break; + + case FIELD_ID_DDE: + // name from field master + ProcessString(XML_CONNECTION_NAME, + + GetStringProperty(sPropertyName, + GetMasterPropertySet(rTextField))); + ExportElement(XML_DDE_CONNECTION, sPresentation); + break; + + case FIELD_ID_SHEET_NAME: + // name of spreadsheet (Calc only) + ExportElement(XML_SHEET_NAME, sPresentation); + break; + + case FIELD_ID_URL: + { + // this field is a special case because it gets mapped onto a + // hyperlink, rather than one of the regular text field. + ProcessString(XML_HREF, GetExport().GetRelativeReference(GetStringProperty(sPropertyURL, rPropSet)), + sal_False, XML_NAMESPACE_XLINK); + ProcessString(XML_TARGET_FRAME_NAME, + GetStringProperty(sPropertyTargetFrame,rPropSet), + sal_True, XML_NAMESPACE_OFFICE); + SvXMLElementExport aUrlField(rExport, XML_NAMESPACE_TEXT, XML_A, + sal_False, sal_False); + GetExport().Characters(sPresentation); + break; + } + + case FIELD_ID_BIBLIOGRAPHY: + { + ProcessBibliographyData(rPropSet); + ExportElement(XML_BIBLIOGRAPHY_MARK, sPresentation); + break; + } + + case FIELD_ID_SCRIPT: + ProcessString(XML_LANGUAGE, + GetStringProperty(sPropertyScriptType, rPropSet), + sal_True, XML_NAMESPACE_SCRIPT); + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation for script field"); + if (GetBoolProperty(sPropertyURLContent, rPropSet)) + { + ProcessString(XML_HREF, + GetExport().GetRelativeReference(GetStringProperty(sPropertyContent, rPropSet)), + sal_False, XML_NAMESPACE_XLINK); + ExportElement(XML_SCRIPT); + } + else + { + ExportElement(XML_SCRIPT, + GetStringProperty(sPropertyContent, rPropSet)); + } + break; + + case FIELD_ID_ANNOTATION: + { + // check for empty presentation (just in case) + DBG_ASSERT(sPresentation.equals(sEmpty), + "Unexpected presentation for annotation field"); + + // annotation element + content + SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE, + XML_ANNOTATION, sal_False, sal_True); + + // author + OUString aAuthor( GetStringProperty(sPropertyAuthor, rPropSet) ); + if( aAuthor.getLength() ) + { + SvXMLElementExport aCreatorElem( GetExport(), XML_NAMESPACE_DC, + XML_CREATOR, sal_True, + sal_False ); + GetExport().Characters(aAuthor); + } + + // date time + DateTime aDate( GetDateTimeProperty(sPropertyDateTimeValue, rPropSet) ); + { + OUStringBuffer aBuffer; + GetExport().GetMM100UnitConverter().convertDateTime(aBuffer, + aDate, + sal_True); + SvXMLElementExport aDateElem( GetExport(), XML_NAMESPACE_DC, + XML_DATE, sal_True, + sal_False ); + GetExport().Characters(aBuffer.makeStringAndClear()); + } + + com::sun::star::uno::Reference < com::sun::star::text::XText > xText; + try + { + com::sun::star::uno::Any aRet = rPropSet->getPropertyValue(sPropertyTextRange); + aRet >>= xText; + } + catch ( com::sun::star::uno::Exception& ) + {} + + if ( xText.is() ) + GetExport().GetTextParagraphExport()->exportText( xText ); + else + ProcessParagraphSequence(GetStringProperty(sPropertyContent,rPropSet)); + break; + } + + case FIELD_ID_COMBINED_CHARACTERS: + { + // The style with the combined characters attribute has + // already been handled in the ExportField method. So all that + // is left to do now is to export the characters. + GetExport().Characters(sPresentation); + break; + } + + case FIELD_ID_META: + { + ExportMetaField(rPropSet, false, bProgress); + break; + } + + case FIELD_ID_MEASURE: + { + ProcessString(XML_KIND, MapMeasureKind(GetInt16Property(sPropertyMeasureKind, rPropSet))); + ExportElement( XML_MEASURE, sPresentation ); + break; + } + + case FIELD_ID_TABLE_FORMULA: + ProcessString( XML_FORMULA, XML_NAMESPACE_OOOW, + GetStringProperty(sPropertyContent, rPropSet) ); + ProcessDisplay( sal_True, + GetBoolProperty(sPropertyIsShowFormula, rPropSet), + sal_True ); + ProcessValueAndType( sal_False, + GetIntProperty(sPropertyNumberFormat, rPropSet), + sEmpty, sEmpty, 0.0f, + sal_False, sal_False, sal_True, + sal_False, sal_False ); + ExportElement( XML_TABLE_FORMULA, sPresentation ); + break; + + case FIELD_ID_DROP_DOWN: + { + ProcessString(XML_NAME, GetStringProperty(sPropertyName, rPropSet)); + ProcessString(XML_HELP, + GetStringProperty(sPropertyHelp, rPropSet), true); + ProcessString(XML_HINT, + GetStringProperty(sPropertyTooltip, rPropSet), true); + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_TEXT, XML_DROPDOWN, + sal_False, sal_False ); + ProcessStringSequence + (GetStringSequenceProperty( sPropertyItems, rPropSet ), + GetStringProperty( sPropertySelectedItem, rPropSet ) ); + + GetExport().Characters( sPresentation ); + } + break; + + case FIELD_ID_DRAW_HEADER: + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_HEADER, sal_False, sal_False ); + } + break; + + case FIELD_ID_DRAW_FOOTER: + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_FOOTER, sal_False, sal_False ); + } + break; + + case FIELD_ID_DRAW_DATE_TIME: + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_DATE_TIME, sal_False, sal_False ); + } + break; + + case FIELD_ID_UNKNOWN: + default: + DBG_ERROR("unkown field type encountered!"); + // always export content + GetExport().Characters(sPresentation); + } +} + + +/// export field declarations / field masters +void XMLTextFieldExport::ExportFieldDeclarations() +{ + Reference<XText> xEmptyText; + ExportFieldDeclarations(xEmptyText); +} + +/// export field declarations / field masters +void XMLTextFieldExport::ExportFieldDeclarations( + const Reference<XText> & rText ) +{ + // store lists for decl elements + vector<OUString> aVarName; + vector<OUString> aUserName; + vector<OUString> aSeqName; + vector<OUString> aDdeName; + + // get text fields supplier and field master name access + Reference<XTextFieldsSupplier> xTextFieldsSupp(GetExport().GetModel(), + UNO_QUERY); + if( !xTextFieldsSupp.is() ) + return; + + Reference<container::XNameAccess> xFieldMasterNameAccess( + xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY); + + // where to get the text field masters from? + // a) we get a specific XText: then use pUsedMasters + // b) the XText is empty: then export all text fields + Sequence<OUString> aFieldMasters; + if (rText.is()) + { + // export only used masters + DBG_ASSERT(NULL != pUsedMasters, + "field masters must be recorded in order to be " + "written out separatly" ); + if (NULL != pUsedMasters) + { + map<Reference<XText>, set<OUString> > ::iterator aMapIter = + pUsedMasters->find(rText); + if (aMapIter != pUsedMasters->end()) + { + // found the set of used field masters + set<OUString> & rOurMasters = aMapIter->second; + + // copy set to sequence + aFieldMasters.realloc( rOurMasters.size() ); + sal_Int32 i = 0; + for( set<OUString>::iterator aSetIter = rOurMasters.begin(); + aSetIter != rOurMasters.end(); + aSetIter++, i++ ) + { + aFieldMasters[i] = *aSetIter; + } + + pUsedMasters->erase(rText); + } + // else: XText not found -> ignore + } + // else: no field masters have been recorded -> ignore + } + else + { + // no XText: export all! + aFieldMasters = xFieldMasterNameAccess->getElementNames(); + } + + for(sal_Int32 i=0; i<aFieldMasters.getLength(); i++) { + + // get field master name + OUString sFieldMaster = aFieldMasters[i]; + + // workaround for #no-bug# + static const sal_Char sDB[] = + "com.sun.star.text.FieldMaster.DataBase."; + if ( sFieldMaster.matchIgnoreAsciiCaseAsciiL( sDB, sizeof(sDB)-1) ) + { + continue; + } + + + OUString sFieldMasterType; + OUString sVarName; + ExplodeFieldMasterName(sFieldMaster, sFieldMasterType, sVarName); + + // get XPropertySet of this field master + Reference<XPropertySet> xPropSet; + Any aAny = xFieldMasterNameAccess->getByName(sFieldMaster); + aAny >>= xPropSet; + + // save interesting field masters + if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_SETEXP)) + { + sal_Int32 nType = GetIntProperty(sPropertySubType, xPropSet); + + // sequence or variable? + if ( SetVariableType::SEQUENCE == nType ) + { + aSeqName.push_back( sFieldMaster ); + } + else + { + aVarName.push_back( sFieldMaster ); + } + } + else if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_USER)) + { + aUserName.push_back( sFieldMaster ); + } + else if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_DDE)) + { + aDdeName.push_back( sFieldMaster ); + } + else + { + ; // ignore + } + } + + // now process fields: + + // variable field masters: + if ( !aVarName.empty() ) + { + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_TEXT, + XML_VARIABLE_DECLS, + sal_True, sal_True ); + + for (vector<OUString>::iterator aVarIter = aVarName.begin(); + aVarIter != aVarName.end(); + aVarIter++) { + + OUString sName = *aVarIter; + + // get field master property set + Reference<XPropertySet> xPropSet; + Any aAny = xFieldMasterNameAccess->getByName(sName); + aAny >>= xPropSet; + + // field name and type + OUString sFieldMasterType; + OUString sVarName; + ExplodeFieldMasterName(sName, sFieldMasterType, sVarName); + + // determine string/numeric field + sal_Bool bIsString = ( GetIntProperty(sPropertySubType, xPropSet) + == SetVariableType::STRING ); + + // get dependent field property set + Reference<XPropertySet> xFieldPropSet; + if (GetDependentFieldPropertySet(xPropSet, xFieldPropSet)) + { + // process value and type. + ProcessValueAndType( + bIsString, + GetIntProperty(sPropertyNumberFormat, xFieldPropSet), + sEmpty, sEmpty, 0.0, + sal_False, sal_True, sal_False, sal_False); + } + else + { + // If no dependent field is found, only string and + // float types can be supported + + // number format: 0 is default number format for 1st + // language. should be: getDefaultNumberFormat(Locale) + // from NumberFormats + ProcessValueAndType( + bIsString, + 0, sEmpty, sEmpty, 0.0, + sal_False, sal_True, sal_False, sal_False); + } + + ProcessString(XML_NAME, sVarName); + ExportElement(XML_VARIABLE_DECL, sal_True); + } + } + // else: no declarations element + + // sequence field masters: + if ( !aSeqName.empty() ) + { + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_TEXT, + XML_SEQUENCE_DECLS, + sal_True, sal_True ); + + for (vector<OUString>::iterator aSeqIter = aSeqName.begin(); + aSeqIter != aSeqName.end(); + aSeqIter++) { + + OUString sName = *aSeqIter; + + // get field master property set + Reference<XPropertySet> xPropSet; + Any aAny = xFieldMasterNameAccess->getByName(sName); + aAny >>= xPropSet; + + // field name and type + OUString sFieldMasterType; + OUString sVarName; + ExplodeFieldMasterName(sName, sFieldMasterType, sVarName); + + // outline level + sal_Int32 nLevel = 1 + GetIntProperty( + sPropertyChapterNumberingLevel, xPropSet); + DBG_ASSERT(nLevel >= 0, "illegal outline level"); + DBG_ASSERT(nLevel < 127, "possible illegal outline level"); + ProcessInteger(XML_DISPLAY_OUTLINE_LEVEL, nLevel); + + // separation character + if (nLevel > 0) { + ProcessString(XML_SEPARATION_CHARACTER, GetStringProperty( + sPropertyNumberingSeparator, xPropSet)); + } + ProcessString(XML_NAME, sVarName); + ExportElement(XML_SEQUENCE_DECL, sal_True); + } + } + // else: no declarations element + + // user field field masters: + if ( !aUserName.empty() ) + { + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_TEXT, + XML_USER_FIELD_DECLS, + sal_True, sal_True ); + + for (vector<OUString>::iterator aUserIter = aUserName.begin(); + aUserIter != aUserName.end(); + aUserIter++) { + + OUString sName = *aUserIter; + + // get field master property set + Reference<XPropertySet> xPropSet; + Any aAny = xFieldMasterNameAccess->getByName(sName); + aAny >>= xPropSet; + + // field name and type + OUString sFieldMasterType; + OUString sVarName; + ExplodeFieldMasterName(sName, sFieldMasterType, sVarName); + + if (GetBoolProperty(sPropertyIsExpression, xPropSet)) + { + // expression: + ProcessValueAndType( + sal_False, + 0, sEmpty, sEmpty, + GetDoubleProperty(sPropertyValue, xPropSet), + sal_True, + sal_True, + sal_False, + sal_False); + } + else + { + // string: write regardless of default + ProcessString(XML_VALUE_TYPE, XML_STRING, sal_False, + XML_NAMESPACE_OFFICE); + ProcessString(XML_STRING_VALUE, + GetStringProperty(sPropertyContent, xPropSet), + sal_False, XML_NAMESPACE_OFFICE ); + } + ProcessString(XML_NAME, sVarName); + ExportElement(XML_USER_FIELD_DECL, sal_True); + } + } + // else: no declarations element + + // DDE field field masters: + if ( !aDdeName.empty() ) + { + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_TEXT, + XML_DDE_CONNECTION_DECLS, + sal_True, sal_True ); + + for (vector<OUString>::iterator aDdeIter = aDdeName.begin(); + aDdeIter != aDdeName.end(); + aDdeIter++) + { + OUString sName = *aDdeIter; + + // get field master property set + Reference<XPropertySet> xPropSet; + Any aAny = xFieldMasterNameAccess->getByName(sName); + aAny >>= xPropSet; + + // check if this connection is being used by a field + Reference<XPropertySet> xDummy; + if (GetDependentFieldPropertySet(xPropSet, xDummy)) + { + + ProcessString(XML_NAME, + GetStringProperty(sPropertyName, xPropSet), + sal_False, XML_NAMESPACE_OFFICE); + + // export elements; can't use ProcessString because + // elements are in office namespace + ProcessString(XML_DDE_APPLICATION, + GetStringProperty(sPropertyDDECommandType, + xPropSet), + sal_False, XML_NAMESPACE_OFFICE); + ProcessString(XML_DDE_TOPIC, + GetStringProperty(sPropertyDDECommandFile, + xPropSet), + sal_False, XML_NAMESPACE_OFFICE); + ProcessString(XML_DDE_ITEM, + GetStringProperty(sPropertyDDECommandElement, + xPropSet), + sal_False, XML_NAMESPACE_OFFICE); + sal_Bool bIsAutomaticUpdate = GetBoolProperty( + sPropertyIsAutomaticUpdate, xPropSet); + if (bIsAutomaticUpdate) + { + GetExport().AddAttribute(XML_NAMESPACE_OFFICE, + XML_AUTOMATIC_UPDATE, + XML_TRUE); + } + + ExportElement(XML_DDE_CONNECTION_DECL, sal_True); + } + // else: no dependent field -> no export of field declaration + } + } + // else: no declarations element +} + +void XMLTextFieldExport::SetExportOnlyUsedFieldDeclarations( + sal_Bool bExportOnlyUsed) +{ + delete pUsedMasters; + pUsedMasters = NULL; + + // create used masters set (if none is used) + if (bExportOnlyUsed) + pUsedMasters = new map<Reference<XText>, set<OUString> > ; +} + +void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName, + sal_Bool bAddSpace) +{ + // can't call ExportElement(eElementName, const OUString&) with empty + // string because xmlprinter only uses empty tags if no content + // (not even empty content) was written. + + DBG_ASSERT(XML_TOKEN_INVALID != eElementName, "invalid element name!"); + if (XML_TOKEN_INVALID != eElementName) + { + // Element + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + eElementName, bAddSpace, bAddSpace ); + } // else: ignore +} + +void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName, + const OUString& sContent, + sal_Bool bAddSpace) +{ + DBG_ASSERT(eElementName != XML_TOKEN_INVALID, "invalid element name!"); + if (eElementName != XML_TOKEN_INVALID) + { + // Element + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + eElementName, bAddSpace, bAddSpace ); + // export content + GetExport().Characters(sContent); + } else { + // always export content + GetExport().Characters(sContent); + } +} + +void XMLTextFieldExport::ExportMacro( + const Reference<XPropertySet> & rPropSet, + const OUString& rContent ) +{ + // some strings we'll need + OUString sEventType( RTL_CONSTASCII_USTRINGPARAM( "EventType" )); + OUString sStarBasic( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" )); + OUString sScript( RTL_CONSTASCII_USTRINGPARAM( "Script" )); + OUString sLibrary( RTL_CONSTASCII_USTRINGPARAM( "Library" )); + OUString sMacroName( RTL_CONSTASCII_USTRINGPARAM( "MacroName" )); + OUString sOnClick( RTL_CONSTASCII_USTRINGPARAM( "OnClick" )); + OUString sPropertyMacroLibrary( RTL_CONSTASCII_USTRINGPARAM( "MacroLibrary" )); + OUString sPropertyMacroName( RTL_CONSTASCII_USTRINGPARAM( "MacroName" )); + OUString sPropertyScriptURL( RTL_CONSTASCII_USTRINGPARAM( "ScriptURL" )); + + + // the description attribute + ProcessString(XML_DESCRIPTION, + GetStringProperty(sPropertyHint, rPropSet), + rContent); + + // the element + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_EXECUTE_MACRO, sal_False, sal_False ); + + // the <office:events>-macro: + + // 1) build sequence of PropertyValues + Sequence<PropertyValue> aSeq; + OUString sName; + rPropSet->getPropertyValue( sPropertyScriptURL ) >>= sName; + + // if the ScriptURL property is not empty then this is a Scripting + // Framework URL, otherwise treat it as a Basic Macro + if (sName.getLength() != 0) + { + aSeq = Sequence<PropertyValue> (2); + PropertyValue* pArr = aSeq.getArray(); + pArr[0].Name = sEventType; + pArr[0].Value <<= sScript; + pArr[1].Name = sScript; + pArr[1].Value = rPropSet->getPropertyValue( sPropertyScriptURL ); + } + else + { + aSeq = Sequence<PropertyValue> (3); + PropertyValue* pArr = aSeq.getArray(); + pArr[0].Name = sEventType; + pArr[0].Value <<= sStarBasic; + pArr[1].Name = sLibrary; + pArr[1].Value = rPropSet->getPropertyValue( sPropertyMacroLibrary ); + pArr[2].Name = sMacroName; + pArr[2].Value = rPropSet->getPropertyValue( sPropertyMacroName ); + } + + // 2) export the sequence + GetExport().GetEventExport().ExportSingleEvent( aSeq, sOnClick, sal_False ); + + // and finally, the field presentation + GetExport().Characters(rContent); +} + +void XMLTextFieldExport::ExportMetaField( + const Reference<XPropertySet> & i_xMeta, + bool i_bAutoStyles, sal_Bool i_bProgress ) +{ + bool doExport(!i_bAutoStyles); // do not export element if autostyles + // check version >= 1.2 + switch (GetExport().getDefaultVersion()) { + case SvtSaveOptions::ODFVER_011: // fall thru + case SvtSaveOptions::ODFVER_010: doExport = false; break; + default: break; + } + + const Reference < XEnumerationAccess > xEA( i_xMeta, UNO_QUERY_THROW ); + const Reference < XEnumeration > xTextEnum( xEA->createEnumeration() ); + + if (doExport) + { + const Reference<rdf::XMetadatable> xMeta( i_xMeta, UNO_QUERY_THROW ); + + // style:data-style-name + ProcessValueAndType(sal_False, + GetIntProperty(sPropertyNumberFormat, i_xMeta), + sEmpty, sEmpty, 0.0, sal_False, sal_False, sal_True, + sal_False, sal_False /*, sal_False*/ ); + + // text:meta-field without xml:id is invalid + xMeta->ensureMetadataReference(); + + // xml:id for RDF metadata + GetExport().AddAttributeXmlId(xMeta); + } + + SvXMLElementExport aElem( GetExport(), doExport, + XML_NAMESPACE_TEXT, XML_META_FIELD, sal_False, sal_False ); + + // recurse to export content + GetExport().GetTextParagraphExport()-> + exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_bProgress ); +} + +/// export all data-style related attributes +void XMLTextFieldExport::ProcessValueAndType( + sal_Bool bIsString, /// do we process a string or a number? + sal_Int32 nFormatKey, /// format key for NumberFormatter; inv. if string + const OUString& sContent, /// string content; possibly invalid + const OUString& sDefault, /// default string + double fValue, /// float content; possibly invalid + sal_Bool bExportValue, /// export value attribute? + sal_Bool bExportValueType, /// export value-type attribute? + sal_Bool bExportStyle, /// export style-sttribute? + sal_Bool bForceSystemLanguage, /// export language attributes? + sal_Bool bTimeStyle) // exporting a time style? +{ + // String or number? + if (bIsString) + { + + // string: attributes value-type=string, string-value=... + + if (bExportValue || bExportValueType) + { + XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes( + GetExport(), sContent, sDefault, bExportValue); + } + + } + else + { + + // number: value-type=..., value...=..., data-style-name=... + + DBG_ASSERT(bExportValueType || !bExportValue, "value w/o value type not supported!"); + + // take care of illegal formats + // (shouldn't happen, but does if document is corrupted) + if (-1 != nFormatKey) + { + if (bExportValue || bExportValueType) + { + XMLNumberFormatAttributesExportHelper:: + SetNumberFormatAttributes( + GetExport(), nFormatKey, fValue, bExportValue); + } + + if (bExportStyle) + { + // don't export language (if desired) + if( bForceSystemLanguage ) + nFormatKey = + GetExport().dataStyleForceSystemLanguage( nFormatKey ); + + OUString sDataStyleName = + GetExport().getDataStyleName(nFormatKey, bTimeStyle); + if( sDataStyleName.getLength() > 0 ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DATA_STYLE_NAME, + sDataStyleName ); + } // else: ignore (no valid number format) + } // else: ignore (no number format) + } + } +} + + + +/// process display related properties +void XMLTextFieldExport::ProcessDisplay(sal_Bool bIsVisible, + sal_Bool bIsCommand, + sal_Bool bValueDefault) +{ + enum XMLTokenEnum eValue; + + if (bIsVisible) + { + eValue = bIsCommand ? XML_FORMULA : XML_VALUE; + } + else + { + eValue = XML_NONE; + } + + // omit attribute if default + if (!bValueDefault || (eValue != XML_VALUE)) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eValue); + } +} + + + +/// export boolean property +void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName, + sal_Bool bBool, sal_Bool bDefault) +{ + DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token"); + if ( XML_TOKEN_INVALID == eName ) + return; + + // write attribute (if different than default) + // negate to force 0/1 values (and make sal_Bool comparable) + if ((!bBool) != (!bDefault)) { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName, + (bBool ? XML_TRUE : XML_FALSE) ); + } +} + + + + +/// export string attribute +void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName, + const OUString& sValue, + sal_Bool bOmitEmpty, + sal_uInt16 nPrefix) +{ + DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token"); + if ( XML_TOKEN_INVALID == eName ) + return; + + // check for empty string, if applicable + if ( bOmitEmpty && (sValue.getLength()==0) ) + return; + + // write attribute + GetExport().AddAttribute(nPrefix, eName, sValue); +} + +void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName, + sal_uInt16 nValuePrefix, + const OUString& sValue, + sal_Bool bOmitEmpty, + sal_uInt16 nPrefix) +{ + OUString sQValue = + GetExport().GetNamespaceMap().GetQNameByKey( nValuePrefix, sValue, sal_False ); + ProcessString( eName, sQValue, bOmitEmpty, nPrefix ); +} + +/// export a string attribute +void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName, + const ::rtl::OUString& sValue, + const ::rtl::OUString& sDefault, + sal_uInt16 nPrefix) +{ + if (sValue != sDefault) + { + ProcessString(eName, sValue, sal_False, nPrefix); + } +} + +/// export a string attribute +void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName, + sal_uInt16 nValuePrefix, + const ::rtl::OUString& sValue, + const ::rtl::OUString& sDefault, + sal_uInt16 nPrefix) +{ + if (sValue != sDefault) + { + ProcessString(eName, nValuePrefix, sValue, sal_False, nPrefix); + } +} + + +/// export string attribute +void XMLTextFieldExport::ProcessString( + enum XMLTokenEnum eName, + enum XMLTokenEnum eValue, + sal_Bool bOmitEmpty, + sal_uInt16 nPrefix) +{ + DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token" ); + DBG_ASSERT( bOmitEmpty || (eValue != XML_TOKEN_INVALID), + "invalid value token" ); + if ( XML_TOKEN_INVALID == eName ) + return; + + // check for empty string, if applicable + if (bOmitEmpty && (eValue == XML_TOKEN_INVALID)) + return; + + GetExport().AddAttribute(nPrefix, eName, eValue); +} + +/// export a string attribute +void XMLTextFieldExport::ProcessString( + enum XMLTokenEnum eName, + enum XMLTokenEnum eValue, + enum XMLTokenEnum eDefault, + sal_uInt16 nPrefix) +{ + if ( eValue != eDefault ) + ProcessString( eName, eValue, sal_False, nPrefix); +} + + +/// export a string as a sequence of paragraphs +void XMLTextFieldExport::ProcessParagraphSequence( + const ::rtl::OUString& sParagraphSequence) +{ + // iterate over all string-pieces separated by return (0x0a) and + // put each inside a paragraph element. + SvXMLTokenEnumerator aEnumerator(sParagraphSequence, sal_Char(0x0a)); + OUString aSubString; + while (aEnumerator.getNextToken(aSubString)) + { + SvXMLElementExport aParagraph( + GetExport(), XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False); + GetExport().Characters(aSubString); + } +} + +// export an integer attribute +void XMLTextFieldExport::ProcessInteger(enum XMLTokenEnum eName, + sal_Int32 nNum) +{ + DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token"); + if ( XML_TOKEN_INVALID == eName ) + return; + + GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName, + OUString::valueOf(nNum)); +} + +/// export an integer attribute, omit if default +void XMLTextFieldExport::ProcessIntegerDef(enum XMLTokenEnum eName, + sal_Int32 nNum, sal_Int32 nDefault) +{ + if (nNum != nDefault) + ProcessInteger(eName, nNum); +} + + + +/// export a numbering type +void XMLTextFieldExport::ProcessNumberingType(sal_Int16 nNumberingType) +{ + // process only if real format (not: like page descriptor) + if (NumberingType::PAGE_DESCRIPTOR != nNumberingType) + { + OUStringBuffer sTmp( 10 ); + // number type: num format + GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, + nNumberingType ); + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT, + sTmp.makeStringAndClear() ); + // and letter sync, if applicable + GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp, + nNumberingType ); + + if (sTmp.getLength()) + { + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, + sTmp.makeStringAndClear() ); + } + } + // else: like page descriptor => ignore +} + + +/// export a date, time, or duration +void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, + double dValue, + sal_Bool bIsDate, + sal_Bool bIsDuration, + sal_Bool bOmitDurationIfZero, + sal_uInt16 nPrefix) +{ + // truncate for date granularity + if (bIsDate) + { + dValue = ::rtl::math::approxFloor(dValue); + } + + OUStringBuffer aBuffer; + if (bIsDuration) + { + // date/time durationM handle bOmitDurationIfZero + if (!bOmitDurationIfZero || !::rtl::math::approxEqual(dValue, 0.0)) + { + rExport.GetMM100UnitConverter().convertTime(aBuffer, dValue); + } + } + else + { + // date/time value + rExport.GetMM100UnitConverter().convertDateTime(aBuffer, dValue); + } + + // output attribute + ProcessString(eName, aBuffer.makeStringAndClear(), sal_True, nPrefix); +} + +/// export a date or time +void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, + const DateTime& rTime, + sal_Bool bIsDate, + sal_uInt16 nPrefix) +{ + OUStringBuffer aBuffer; + + DateTime aDateTime(rTime); + + // truncate dates + if(bIsDate) + { + aDateTime.HundredthSeconds = 0; + aDateTime.Seconds = 0; + aDateTime.Minutes = 0; + aDateTime.Hours = 0; + } + + // date/time value + rExport.GetMM100UnitConverter().convertDateTime(aBuffer, aDateTime); + + // output attribute + ProcessString(eName, aBuffer.makeStringAndClear(), sal_True, nPrefix); +} + +/// export date according to ISO 8601 +void XMLTextFieldExport::ProcessDate( + enum XMLTokenEnum eName, + const ::com::sun::star::util::Date& rDate, + sal_uInt16 nPrefix) +{ + // the easiest way: delegate to ProcessDateTime (as date) + DateTime aDateTime; + aDateTime.Day = rDate.Day; + aDateTime.Month = rDate.Month; + aDateTime.Year = rDate.Year; + ProcessDateTime(eName, aDateTime, sal_True, nPrefix); +} + + +/// export a date, time, or duration +void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, + sal_Int32 nMinutes, + sal_Bool bIsDate, + sal_Bool bIsDuration, + sal_Bool bOmitDurationIfZero, + sal_uInt16 nPrefix) +{ + // handle bOmitDurationIfZero here, because we can precisely compare ints + if (!(bIsDuration && bOmitDurationIfZero && (nMinutes==0))) + { + ProcessDateTime(eName, (double)nMinutes / (double)(24*60), + bIsDate, bIsDuration, bOmitDurationIfZero, nPrefix); + } +} + + +SvXMLEnumMapEntry __READONLY_DATA aBibliographyDataTypeMap[] = +{ + { XML_ARTICLE, BibliographyDataType::ARTICLE }, + { XML_BOOK, BibliographyDataType::BOOK }, + { XML_BOOKLET, BibliographyDataType::BOOKLET }, + { XML_CONFERENCE, BibliographyDataType::CONFERENCE }, + { XML_CUSTOM1, BibliographyDataType::CUSTOM1 }, + { XML_CUSTOM2, BibliographyDataType::CUSTOM2 }, + { XML_CUSTOM3, BibliographyDataType::CUSTOM3 }, + { XML_CUSTOM4, BibliographyDataType::CUSTOM4 }, + { XML_CUSTOM5, BibliographyDataType::CUSTOM5 }, + { XML_EMAIL, BibliographyDataType::EMAIL }, + { XML_INBOOK, BibliographyDataType::INBOOK }, + { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION }, + { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS }, + { XML_JOURNAL, BibliographyDataType::JOURNAL }, + { XML_MANUAL, BibliographyDataType::MANUAL }, + { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS }, + { XML_MISC, BibliographyDataType::MISC }, + { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS }, + { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS }, + { XML_TECHREPORT, BibliographyDataType::TECHREPORT }, + { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED }, + { XML_WWW, BibliographyDataType::WWW }, + { XML_TOKEN_INVALID, 0 } +}; + + + +void XMLTextFieldExport::ProcessBibliographyData( + const Reference<XPropertySet>& rPropSet) +{ + // get the values + Any aAny = rPropSet->getPropertyValue(sPropertyFields); + Sequence<PropertyValue> aValues; + aAny >>= aValues; + + // one attribute per value (unless empty) + sal_Int32 nLength = aValues.getLength(); + for (sal_Int32 i = 0; i < nLength; i++) + { + if (aValues[i].Name.equalsAsciiL("BibiliographicType", + sizeof("BibiliographicType")-1)) + { + sal_Int16 nTypeId = 0; + aValues[i].Value >>= nTypeId; + OUStringBuffer sBuf; + + if (SvXMLUnitConverter::convertEnum(sBuf, nTypeId, + aBibliographyDataTypeMap)) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + XML_BIBLIOGRAPHY_TYPE, + sBuf.makeStringAndClear()); + } + // else: ignore this argument + } + else + { + OUString sStr; + aValues[i].Value >>= sStr; + + if (sStr.getLength() > 0) + { + rExport.AddAttribute(XML_NAMESPACE_TEXT, + MapBibliographyFieldName(aValues[i].Name), + sStr); + } + } + } +} + +/// export CommandTypeAttribute +void XMLTextFieldExport::ProcessCommandType( + sal_Int32 nCommandType) +{ + enum XMLTokenEnum eToken = XML_TOKEN_INVALID; + switch( nCommandType ) + { + case sdb::CommandType::TABLE: eToken = XML_TABLE; break; + case sdb::CommandType::QUERY: eToken = XML_QUERY; break; + case sdb::CommandType::COMMAND: eToken = XML_COMMAND; break; + } + + if( eToken != XML_TOKEN_INVALID ) + rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_TABLE_TYPE, eToken ); +} + + +void XMLTextFieldExport::ProcessStringSequence( + const Sequence<OUString>& rSequence, + const OUString sSelected ) +{ + // find selected element + sal_Int32 nSelected = -1; + sal_Int32 nLength = rSequence.getLength(); + const OUString* pSequence = rSequence.getConstArray(); + for( sal_Int32 i = 0; i < nLength; i++ ) + { + if( pSequence[i] == sSelected ) + nSelected = i; + } + + // delegate to ProcessStringSequence(OUString,sal_Int32) + ProcessStringSequence( rSequence, nSelected ); +} + +void XMLTextFieldExport::ProcessStringSequence( + const Sequence<OUString>& rSequence, + sal_Int32 nSelected ) +{ + sal_Int32 nLength = rSequence.getLength(); + const OUString* pSequence = rSequence.getConstArray(); + for( sal_Int32 i = 0; i < nLength; i++ ) + { + if( i == nSelected ) + rExport.AddAttribute( XML_NAMESPACE_TEXT, + XML_CURRENT_SELECTED, XML_TRUE ); + rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_VALUE, pSequence[i] ); + SvXMLElementExport aElement( rExport, XML_NAMESPACE_TEXT, XML_LABEL, + sal_False, sal_False ); + } +} + +void XMLTextFieldExport::ExportDataBaseElement( + enum XMLTokenEnum eElementName, + const OUString& sPresentation, + const Reference<XPropertySet>& rPropertySet, + const Reference<XPropertySetInfo>& rPropertySetInfo ) +{ + DBG_ASSERT( eElementName != XML_TOKEN_INVALID, "need token" ); + DBG_ASSERT( rPropertySet.is(), "need property set" ); + DBG_ASSERT( rPropertySetInfo.is(), "need property set info" ); + + // get database properties + OUString sDataBaseName; + OUString sDataBaseURL; + OUString sStr; + if( ( rPropertySet->getPropertyValue( sPropertyDataBaseName ) >>= sStr ) + && ( sStr.getLength() > 0 ) ) + { + sDataBaseName = sStr; + } + else if( rPropertySetInfo->hasPropertyByName( sPropertyDataBaseURL ) && + (rPropertySet->getPropertyValue( sPropertyDataBaseURL ) >>= sStr) && + (sStr.getLength() > 0) ) + { + sDataBaseURL = sStr; + } + + // add database name property (if present) + if( sDataBaseName.getLength() > 0 ) + rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_DATABASE_NAME, + sDataBaseName ); + SvXMLElementExport aDataBaseElement( GetExport(), + XML_NAMESPACE_TEXT, eElementName, + sal_False, sal_False ); + + // write URL as children + if( sDataBaseURL.getLength() > 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sDataBaseURL ); + SvXMLElementExport aDataSourceElement( + GetExport(), XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE, + sal_False, sal_False ); + } + + // write presentation + rExport.Characters( sPresentation ); +} + + + +// explode a field master name into field type and field name +sal_Bool XMLTextFieldExport::ExplodeFieldMasterName( + const OUString& sMasterName, OUString& sFieldType, OUString& sVarName) +{ + sal_Int32 nLength = sFieldMasterPrefix.getLength(); + sal_Int32 nSeparator = sMasterName.indexOf('.', nLength); + sal_Bool bReturn = sal_True; + +#ifdef DBG_UTIL + // check for service name + bReturn &= (0 == sFieldMasterPrefix.compareTo(sMasterName, nLength)); +#endif + + // '.' found? + if (nSeparator <= nLength) { + nSeparator = sMasterName.getLength(); + DBG_WARNING("no field var name!"); + bReturn = sal_False; + } + else + { + sFieldType = sMasterName.copy(nLength, nSeparator-nLength); + sVarName = sMasterName.copy(nSeparator+1); + } + + return bReturn; +} + + +// for XDependentTextFields, get PropertySet of FieldMaster +Reference<XPropertySet> XMLTextFieldExport::GetMasterPropertySet( + const Reference<XTextField> & rTextField) +{ + // name, value => get Property set of TextFieldMaster + Reference<XDependentTextField> xDep(rTextField, UNO_QUERY); + return xDep->getTextFieldMaster(); +} + +// get PropertySet of (any; the first) dependent field +sal_Bool XMLTextFieldExport::GetDependentFieldPropertySet( + const Reference<XPropertySet> & xMaster, + Reference<XPropertySet> & xField) +{ + Any aAny; + Sequence<Reference<XDependentTextField> > aFields; + aAny = xMaster->getPropertyValue(sPropertyDependentTextFields); + aAny >>= aFields; + + // any fields? + if (aFields.getLength() > 0) + { + // get first one and return + Reference<XDependentTextField> xTField = aFields[0]; + xField = Reference<XPropertySet>(xTField, UNO_QUERY); + DBG_ASSERT(xField.is(), + "Surprisinlgy, this TextField refuses to be a PropertySet!"); + return sal_True; + } + else + { + return sal_False; + } +} + + +/// map placeholder type +enum XMLTokenEnum XMLTextFieldExport::MapPlaceholderType(sal_uInt16 nType) +{ + enum XMLTokenEnum eType = XML_TEXT; + + switch (nType) + { + case PlaceholderType::TEXT: + eType = XML_TEXT; + break; + + case PlaceholderType::TABLE: + eType = XML_TABLE; + break; + + case PlaceholderType::TEXTFRAME: + eType = XML_TEXT_BOX; + break; + + case PlaceholderType::GRAPHIC: + eType = XML_IMAGE; + break; + + case PlaceholderType::OBJECT: + eType = XML_OBJECT; + break; + + default: + // unkown placeholder: XML_TEXT + DBG_ERROR("unkown placeholder type"); + } + + return eType; +} + + +/// element name for author fields +enum XMLTokenEnum XMLTextFieldExport::MapAuthorFieldName( + const Reference<XPropertySet> & xPropSet) +{ + // Initalen oder voller Name? + return GetBoolProperty(sPropertyFullName, xPropSet) + ? XML_AUTHOR_NAME : XML_AUTHOR_INITIALS; +} + +enum XMLTokenEnum XMLTextFieldExport::MapPageNumberName( + const Reference<XPropertySet> & xPropSet, + sal_Int32& nOffset) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + PageNumberType ePage; + Any aAny = xPropSet->getPropertyValue(sPropertySubType); + ePage = *(PageNumberType*)aAny.getValue(); + + switch (ePage) + { + case PageNumberType_PREV: + eName = XML_PREVIOUS; + nOffset += 1; + break; + case PageNumberType_CURRENT: + eName = XML_CURRENT; + break; + case PageNumberType_NEXT: + eName = XML_NEXT; + nOffset -= 1; + break; + default: + DBG_ERROR("unknown page number type"); + eName = XML_TOKEN_INVALID; + break; + } + + return eName; +} + +/// map TemplateDisplayFormat to XML +enum XMLTokenEnum XMLTextFieldExport::MapTemplateDisplayFormat(sal_Int16 nFormat) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + + switch (nFormat) + { + case TemplateDisplayFormat::FULL: + eName = XML_FULL; + break; + case TemplateDisplayFormat::PATH: + eName = XML_PATH; + break; + case TemplateDisplayFormat::NAME: + eName = XML_NAME; + break; + case TemplateDisplayFormat::NAME_AND_EXT: + eName = XML_NAME_AND_EXTENSION; + break; + case TemplateDisplayFormat::AREA: + eName = XML_AREA; + break; + case TemplateDisplayFormat::TITLE: + eName = XML_TITLE; + break; + default: + DBG_ERROR("unknown template display format"); + eName = XML_TOKEN_INVALID; + break; + } + + return eName; +} + +/// map count/statistics field token to XML name +enum XMLTokenEnum XMLTextFieldExport::MapCountFieldName(FieldIdEnum nToken) +{ + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + + switch (nToken) + { + case FIELD_ID_COUNT_PAGES: + eElement = XML_PAGE_COUNT; + break; + case FIELD_ID_COUNT_PARAGRAPHS: + eElement = XML_PARAGRAPH_COUNT; + break; + case FIELD_ID_COUNT_WORDS: + eElement = XML_WORD_COUNT; + break; + case FIELD_ID_COUNT_CHARACTERS: + eElement = XML_CHARACTER_COUNT; + break; + case FIELD_ID_COUNT_TABLES: + eElement = XML_TABLE_COUNT; + break; + case FIELD_ID_COUNT_GRAPHICS: + eElement = XML_IMAGE_COUNT; + break; + case FIELD_ID_COUNT_OBJECTS: + eElement = XML_OBJECT_COUNT; + break; + default: + DBG_ERROR("no count field token"); + eElement = XML_TOKEN_INVALID; + break; + } + + return eElement; +} + +/// map ChapterDisplayFormat to XML string +enum XMLTokenEnum XMLTextFieldExport::MapChapterDisplayFormat(sal_Int16 nFormat) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + + switch (nFormat) + { + case ChapterFormat::NAME: + eName = XML_NAME; + break; + case ChapterFormat::NUMBER: + eName = XML_NUMBER; + break; + case ChapterFormat::NAME_NUMBER: + eName = XML_NUMBER_AND_NAME; + break; + case ChapterFormat::NO_PREFIX_SUFFIX: + eName = XML_PLAIN_NUMBER_AND_NAME; + break; + case ChapterFormat::DIGIT: + eName = XML_PLAIN_NUMBER; + break; + default: + DBG_ERROR("unkown chapter display format"); + eName = XML_TOKEN_INVALID; + break; + } + + return eName; +} + + +/// map FilenameDisplayFormat to XML attribute names +enum XMLTokenEnum XMLTextFieldExport::MapFilenameDisplayFormat(sal_Int16 nFormat) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + + switch (nFormat) + { + case FilenameDisplayFormat::FULL: + eName = XML_FULL; + break; + case FilenameDisplayFormat::PATH: + eName = XML_PATH; + break; + case FilenameDisplayFormat::NAME: + eName = XML_NAME; + break; + case FilenameDisplayFormat::NAME_AND_EXT: + eName = XML_NAME_AND_EXTENSION; + break; + default: + DBG_ERROR("unknown filename display format"); + } + + return eName; +} + + +/// map ReferenceFieldPart to XML string +enum XMLTokenEnum XMLTextFieldExport::MapReferenceType(sal_Int16 nType) +{ + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + + switch (nType) + { + case ReferenceFieldPart::PAGE: + eElement = XML_PAGE; + break; + case ReferenceFieldPart::CHAPTER: + eElement = XML_CHAPTER; + break; + case ReferenceFieldPart::TEXT: + eElement = XML_TEXT; + break; + case ReferenceFieldPart::UP_DOWN: + eElement = XML_DIRECTION; + break; + case ReferenceFieldPart::CATEGORY_AND_NUMBER: + eElement = XML_CATEGORY_AND_VALUE; + break; + case ReferenceFieldPart::ONLY_CAPTION: + eElement = XML_CAPTION; + break; + case ReferenceFieldPart::ONLY_SEQUENCE_NUMBER: + eElement = XML_VALUE; + break; + case ReferenceFieldPart::PAGE_DESC: + // small hack: this value never gets written, because + // XML_TEMPLATE is default + eElement = XML_TEMPLATE; + break; + // --> OD 2007-09-14 #i81002# + case ReferenceFieldPart::NUMBER: + eElement = XML_NUMBER; + break; + case ReferenceFieldPart::NUMBER_NO_CONTEXT: + eElement = XML_NUMBER_NO_SUPERIOR; + break; + case ReferenceFieldPart::NUMBER_FULL_CONTEXT: + eElement = XML_NUMBER_ALL_SUPERIOR; + break; + // <-- + default: + DBG_ERROR("unknown reference type"); + eElement = XML_TEMPLATE; + break; + } + + return eElement; +} + +/// map ReferenceFieldPart to XML string +enum XMLTokenEnum XMLTextFieldExport::MapReferenceSource(sal_Int16 nType) +{ + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + + switch (nType) + { + case ReferenceFieldSource::REFERENCE_MARK: + eElement = XML_REFERENCE_REF; + break; + case ReferenceFieldSource::SEQUENCE_FIELD: + eElement = XML_SEQUENCE_REF; + break; + case ReferenceFieldSource::BOOKMARK: + eElement = XML_BOOKMARK_REF; + break; + case ReferenceFieldSource::FOOTNOTE: + case ReferenceFieldSource::ENDNOTE: + eElement = XML_NOTE_REF; + break; + default: + DBG_ERROR("unkown reference source"); + break; + } + + return eElement; +} + + +/// element name for sender fields +enum XMLTokenEnum XMLTextFieldExport::MapSenderFieldName( + const Reference<XPropertySet> & xPropSet) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + + // sub-field type + switch (GetInt16Property(sPropertyFieldSubType, xPropSet)) + { + case UserDataPart::COMPANY : + eName = XML_SENDER_COMPANY; + break; + case UserDataPart::FIRSTNAME : + eName = XML_SENDER_FIRSTNAME; + break; + case UserDataPart::NAME : + eName = XML_SENDER_LASTNAME; + break; + case UserDataPart::SHORTCUT : + eName = XML_SENDER_INITIALS; + break; + case UserDataPart::STREET : + eName = XML_SENDER_STREET; + break; + case UserDataPart::COUNTRY : + eName = XML_SENDER_COUNTRY; + break; + case UserDataPart::ZIP : + eName = XML_SENDER_POSTAL_CODE; + break; + case UserDataPart::CITY : + eName = XML_SENDER_CITY; + break; + case UserDataPart::TITLE : + eName = XML_SENDER_TITLE; + break; + case UserDataPart::POSITION : + eName = XML_SENDER_POSITION; + break; + case UserDataPart::PHONE_PRIVATE : + eName = XML_SENDER_PHONE_PRIVATE; + break; + case UserDataPart::PHONE_COMPANY : + eName = XML_SENDER_PHONE_WORK; + break; + case UserDataPart::FAX : + eName = XML_SENDER_FAX; + break; + case UserDataPart::EMAIL : + eName = XML_SENDER_EMAIL; + break; + case UserDataPart::STATE : + eName = XML_SENDER_STATE_OR_PROVINCE; + break; + default: + DBG_WARNING("unknown sender type"); + eName = XML_TOKEN_INVALID; + break; + } + + return eName; +} + +enum XMLTokenEnum XMLTextFieldExport::MapDocInfoFieldName( + enum FieldIdEnum nToken) +{ + enum XMLTokenEnum eElement = XML_TOKEN_INVALID; + + switch (nToken) + { + case FIELD_ID_DOCINFO_CREATION_AUTHOR: + eElement = XML_INITIAL_CREATOR; + break; + case FIELD_ID_DOCINFO_CREATION_DATE: + eElement = XML_CREATION_DATE; + break; + case FIELD_ID_DOCINFO_CREATION_TIME: + eElement = XML_CREATION_TIME; + break; + case FIELD_ID_DOCINFO_DESCRIPTION: + eElement = XML_DESCRIPTION; + break; + case FIELD_ID_DOCINFO_PRINT_TIME: + eElement = XML_PRINT_TIME; + break; + case FIELD_ID_DOCINFO_PRINT_DATE: + eElement = XML_PRINT_DATE; + break; + case FIELD_ID_DOCINFO_PRINT_AUTHOR: + eElement = XML_PRINTED_BY; + break; + case FIELD_ID_DOCINFO_TITLE: + eElement = XML_TITLE; + break; + case FIELD_ID_DOCINFO_SUBJECT: + eElement = XML_SUBJECT; + break; + case FIELD_ID_DOCINFO_KEYWORDS: + eElement = XML_KEYWORDS; + break; + case FIELD_ID_DOCINFO_REVISION: + eElement = XML_EDITING_CYCLES; + break; + case FIELD_ID_DOCINFO_EDIT_DURATION: + eElement = XML_EDITING_DURATION; + break; + case FIELD_ID_DOCINFO_SAVE_TIME: + eElement = XML_MODIFICATION_TIME; + break; + case FIELD_ID_DOCINFO_SAVE_DATE: + eElement = XML_MODIFICATION_DATE; + break; + case FIELD_ID_DOCINFO_SAVE_AUTHOR: + eElement = XML_CREATOR; + break; + default: + DBG_WARNING("unknown docinfo field type!"); + eElement = XML_TOKEN_INVALID; + break; + } + + return eElement; +} + +enum XMLTokenEnum XMLTextFieldExport::MapBibliographyFieldName(OUString sName) +{ + enum XMLTokenEnum eName = XML_TOKEN_INVALID; + + if (sName.equalsAsciiL("Identifier", sizeof("Identifier")-1)) + { + eName = XML_IDENTIFIER; + } + else if (sName.equalsAsciiL("BibiliographicType", + sizeof("BibiliographicType")-1)) + { + eName = XML_BIBLIOGRAPHY_TYPE; + } + else if (sName.equalsAsciiL("Address", sizeof("Address")-1)) + { + eName = XML_ADDRESS; + } + else if (sName.equalsAsciiL("Annote", sizeof("Annote")-1)) + { + eName = XML_ANNOTE; + } + else if (sName.equalsAsciiL("Author", sizeof("Author")-1)) + { + eName = XML_AUTHOR; + } + else if (sName.equalsAsciiL("Booktitle", sizeof("Booktitle")-1)) + { + eName = XML_BOOKTITLE; + } + else if (sName.equalsAsciiL("Chapter", sizeof("Chapter")-1)) + { + eName = XML_CHAPTER; + } + else if (sName.equalsAsciiL("Edition", sizeof("Edition")-1)) + { + eName = XML_EDITION; + } + else if (sName.equalsAsciiL("Editor", sizeof("Editor")-1)) + { + eName = XML_EDITOR; + } + else if (sName.equalsAsciiL("Howpublished", sizeof("Howpublished")-1)) + { + eName = XML_HOWPUBLISHED; + } + else if (sName.equalsAsciiL("Institution", sizeof("Institution")-1)) + { + eName = XML_INSTITUTION; + } + else if (sName.equalsAsciiL("Journal", sizeof("Journal")-1)) + { + eName = XML_JOURNAL; + } + else if (sName.equalsAsciiL("Month", sizeof("Month")-1)) + { + eName = XML_MONTH; + } + else if (sName.equalsAsciiL("Note", sizeof("Note")-1)) + { + eName = XML_NOTE; + } + else if (sName.equalsAsciiL("Number", sizeof("Number")-1)) + { + eName = XML_NUMBER; + } + else if (sName.equalsAsciiL("Organizations", sizeof("Organizations")-1)) + { + eName = XML_ORGANIZATIONS; + } + else if (sName.equalsAsciiL("Pages", sizeof("Pages")-1)) + { + eName = XML_PAGES; + } + else if (sName.equalsAsciiL("Publisher", sizeof("Publisher")-1)) + { + eName = XML_PUBLISHER; + } + else if (sName.equalsAsciiL("School", sizeof("School")-1)) + { + eName = XML_SCHOOL; + } + else if (sName.equalsAsciiL("Series", sizeof("Series")-1)) + { + eName = XML_SERIES; + } + else if (sName.equalsAsciiL("Title", sizeof("Title")-1)) + { + eName = XML_TITLE; + } + else if (sName.equalsAsciiL("Report_Type", sizeof("Report_Type")-1)) + { + eName = XML_REPORT_TYPE; + } + else if (sName.equalsAsciiL("Volume", sizeof("Volume")-1)) + { + eName = XML_VOLUME; + } + else if (sName.equalsAsciiL("Year", sizeof("Year")-1)) + { + eName = XML_YEAR; + } + else if (sName.equalsAsciiL("URL", sizeof("URL")-1)) + { + eName = XML_URL; + } + else if (sName.equalsAsciiL("Custom1", sizeof("Custom1")-1)) + { + eName = XML_CUSTOM1; + } + else if (sName.equalsAsciiL("Custom2", sizeof("Custom2")-1)) + { + eName = XML_CUSTOM2; + } + else if (sName.equalsAsciiL("Custom3", sizeof("Custom3")-1)) + { + eName = XML_CUSTOM3; + } + else if (sName.equalsAsciiL("Custom4", sizeof("Custom4")-1)) + { + eName = XML_CUSTOM4; + } + else if (sName.equalsAsciiL("Custom5", sizeof("Custom5")-1)) + { + eName = XML_CUSTOM5; + } + else if (sName.equalsAsciiL("ISBN", sizeof("ISBN")-1)) + { + eName = XML_ISBN; + } + else + { + DBG_ERROR("Unknown bibliography info data"); + eName = XML_TOKEN_INVALID; + } + + return eName; +} + +enum XMLTokenEnum XMLTextFieldExport::MapMeasureKind(sal_Int16 nKind) +{ + switch( nKind ) + { + case 0: + return XML_VALUE; + case 1: + return XML_UNIT; + } + return XML_GAP; +} + +OUString XMLTextFieldExport::MakeFootnoteRefName( + sal_Int16 nSeqNo) +{ + // generate foot-/endnote ID + OUStringBuffer aBuf; + aBuf.appendAscii("ftn"); + aBuf.append((sal_Int32)nSeqNo); + return aBuf.makeStringAndClear(); +} + +OUString XMLTextFieldExport::MakeSequenceRefName( + sal_Int16 nSeqNo, + const OUString& rSeqName) +{ + // generate foot-/endnote ID + OUStringBuffer aBuf; + aBuf.appendAscii("ref"); + aBuf.append(rSeqName); + aBuf.append((sal_Int32)nSeqNo); + return aBuf.makeStringAndClear(); +} + +// +// Property accessor helper functions +// + +// to be relegated (does that word exist?) to a more appropriate place +// + + +inline sal_Bool GetBoolProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + sal_Bool bBool = *(sal_Bool *)aAny.getValue(); + return bBool; +} + +inline sal_Bool GetOptionalBoolProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet, + const Reference<XPropertySetInfo> & xPropSetInfo, + sal_Bool bDefault) +{ + return xPropSetInfo->hasPropertyByName( sPropName ) + ? GetBoolProperty( sPropName, xPropSet ) : bDefault; +} + +inline double GetDoubleProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + double fDouble = 0.0; + aAny >>= fDouble; + return fDouble; +} + +inline OUString const GetStringProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + OUString sString; + aAny >>= sString; + return sString; +} + +inline sal_Int32 GetIntProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + sal_Int32 nInt = 0; + aAny >>= nInt; + return nInt; +} + +inline sal_Int16 GetInt16Property( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + sal_Int16 nInt = 0; + aAny >>= nInt; + return nInt; +} + +inline sal_Int8 GetInt8Property( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + sal_Int8 nInt = 0; + aAny >>= nInt; + return nInt; +} + +inline DateTime const GetDateTimeProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + DateTime aTime; + aAny >>= aTime; + return aTime; +} + +inline Date const GetDateProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + Date aDate; + aAny >>= aDate; + return aDate; +} + +inline Sequence<OUString> const GetStringSequenceProperty( + const OUString& sPropName, + const Reference<XPropertySet> & xPropSet) +{ + Any aAny = xPropSet->getPropertyValue(sPropName); + Sequence<OUString> aSequence; + aAny >>= aSequence; + return aSequence; +} diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx new file mode 100644 index 000000000000..3a4d6e6b7749 --- /dev/null +++ b/xmloff/source/text/txtfldi.cxx @@ -0,0 +1,4129 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +/** @#file + * + * Import of all text fields except those from txtvfldi.cxx + * (variable related text fields and database display fields) + */ +#include "txtfldi.hxx" +#include "txtvfldi.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/txtimp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlement.hxx> +#include "XMLStringBufferImportContext.hxx" +#include <xmloff/XMLEventsImportContext.hxx> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/text/UserDataPart.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <com/sun/star/text/PlaceholderType.hpp> +#include <com/sun/star/text/ReferenceFieldPart.hpp> +#include <com/sun/star/text/ReferenceFieldSource.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> +#include <com/sun/star/text/SetVariableType.hpp> +#include <com/sun/star/text/FilenameDisplayFormat.hpp> +#include <com/sun/star/text/ChapterFormat.hpp> +#include <com/sun/star/text/TemplateDisplayFormat.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/text/BibliographyDataField.hpp> +#include <com/sun/star/util/XUpdatable.hpp> +#include <com/sun/star/sdb/CommandType.hpp> + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/math.hxx> +#include <tools/debug.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::xml::sax; +using namespace ::xmloff::token; + + +// +// SO API string constants +// + +// service prefix and service anems +const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField."; +const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster."; +const sal_Char sAPI_presentation_prefix[] = "com.sun.star.presentation.TextField."; + +const sal_Char sAPI_extended_user[] = "ExtendedUser"; +const sal_Char sAPI_user_data_type[] = "UserDataType"; +const sal_Char sAPI_jump_edit[] = "JumpEdit"; +const sal_Char sAPI_get_expression[] = "GetExpression"; +const sal_Char sAPI_set_expression[] = "SetExpression"; +const sal_Char sAPI_user[] = "User"; +const sal_Char sAPI_date_time[] = "DateTime"; +const sal_Char sAPI_page_number[] = "PageNumber"; +const sal_Char sAPI_database_next[] = "DatabaseNextSet"; +const sal_Char sAPI_database_select[] = "DatabaseNumberOfSet"; +const sal_Char sAPI_database_number[] = "DatabaseSetNumber"; +const sal_Char sAPI_database[] = "Database"; +const sal_Char sAPI_database_name[] = "DatabaseName"; +const sal_Char sAPI_docinfo_change_author[] = "DocInfo.ChangeAuthor"; +const sal_Char sAPI_docinfo_change_date_time[] = "DocInfo.ChangeDateTime"; +const sal_Char sAPI_docinfo_edit_time[] = "DocInfo.EditTime"; +const sal_Char sAPI_docinfo_description[] = "DocInfo.Description"; +const sal_Char sAPI_docinfo_create_author[] = "DocInfo.CreateAuthor"; +const sal_Char sAPI_docinfo_create_date_time[] = "DocInfo.CreateDateTime"; +const sal_Char sAPI_docinfo_custom[] = "DocInfo.Custom"; +const sal_Char sAPI_docinfo_print_author[] = "DocInfo.PrintAuthor"; +const sal_Char sAPI_docinfo_print_date_time[] = "DocInfo.PrintDateTime"; +const sal_Char sAPI_docinfo_keywords[] = "DocInfo.KeyWords"; +const sal_Char sAPI_docinfo_subject[] = "DocInfo.Subject"; +const sal_Char sAPI_docinfo_title[] = "DocInfo.Title"; +const sal_Char sAPI_docinfo_revision[] = "DocInfo.Revision"; +const sal_Char sAPI_hidden_paragraph[] = "HiddenParagraph"; +const sal_Char sAPI_hidden_text[] = "HiddenText"; +const sal_Char sAPI_conditional_text[] = "ConditionalText"; +const sal_Char sAPI_file_name[] = "FileName"; +const sal_Char sAPI_chapter[] = "Chapter"; +const sal_Char sAPI_template_name[] = "TemplateName"; +const sal_Char sAPI_page_count[] = "PageCount"; +const sal_Char sAPI_paragraph_count[] = "ParagraphCount"; +const sal_Char sAPI_word_count[] = "WordCount"; +const sal_Char sAPI_character_count[] = "CharacterCount"; +const sal_Char sAPI_table_count[] = "TableCount"; +const sal_Char sAPI_graphic_object_count[] = "GraphicObjectCount"; +const sal_Char sAPI_embedded_object_count[] = "EmbeddedObjectCount"; +const sal_Char sAPI_reference_page_set[] = "ReferencePageSet"; +const sal_Char sAPI_reference_page_get[] = "ReferencePageGet"; +const sal_Char sAPI_macro[] = "Macro"; +const sal_Char sAPI_dde[] = "DDE"; +const sal_Char sAPI_get_reference[] = "GetReference"; +const sal_Char sAPI_sheet_name[] = "SheetName"; +const sal_Char sAPI_url[] = "URL"; +const sal_Char sAPI_bibliography[] = "Bibliography"; +const sal_Char sAPI_annotation[] = "Annotation"; +const sal_Char sAPI_script[] = "Script"; +const sal_Char sAPI_measure[] = "Measure"; +const sal_Char sAPI_drop_down[] = "DropDown"; +const sal_Char sAPI_header[] = "Header"; +const sal_Char sAPI_footer[] = "Footer"; +const sal_Char sAPI_datetime[] = "DateTime"; + +// property names +const sal_Char sAPI_is_fixed[] = "IsFixed"; +const sal_Char sAPI_content[] = "Content"; +const sal_Char sAPI_value[] = "Value"; +const sal_Char sAPI_author[] = "Author"; +const sal_Char sAPI_full_name[] = "FullName"; +const sal_Char sAPI_place_holder_type[] = "PlaceHolderType"; +const sal_Char sAPI_place_holder[] = "PlaceHolder"; +const sal_Char sAPI_hint[] = "Hint"; +const sal_Char sAPI_variable_name[] = "VariableName"; +const sal_Char sAPI_name[] = "Name"; +const sal_Char sAPI_sub_type[] = "SubType"; +const sal_Char sAPI_numbering_separator[] = "NumberingSeparator"; +const sal_Char sAPI_chapter_numbering_level[] = "ChapterNumberingLevel"; +const sal_Char sAPI_variable_subtype[] = "VariableSubtype"; +const sal_Char sAPI_formula[] = "Formula"; +const sal_Char sAPI_date_time_value[] = "DateTimeValue"; +const sal_Char sAPI_number_format[] = "NumberFormat"; +const sal_Char sAPI_user_text[] = "UserText"; +const sal_Char sAPI_numbering_type[] = "NumberingType"; +const sal_Char sAPI_offset[] = "Offset"; +const sal_Char sAPI_data_base_name[] = "DataBaseName"; +const sal_Char sAPI_data_base_u_r_l[] = "DataBaseURL"; +const sal_Char sAPI_data_table_name[] = "DataTableName"; +const sal_Char sAPI_condition[] = "Condition"; +const sal_Char sAPI_set_number[] = "SetNumber"; +const sal_Char sAPI_is_data_base_format[] = "DataBaseFormat"; +const sal_Char sAPI_true_content[] = "TrueContent"; +const sal_Char sAPI_false_content[] = "FalseContent"; +const sal_Char sAPI_revision[] = "Revision"; +const sal_Char sAPI_file_format[] = "FileFormat"; +const sal_Char sAPI_chapter_format[] = "ChapterFormat"; +const sal_Char sAPI_level[] = "Level"; +const sal_Char sAPI_is_date[] = "IsDate"; +const sal_Char sAPI_adjust[] = "Adjust"; +const sal_Char sAPI_on[] = "On"; +const sal_Char sAPI_is_automatic_update[] = "IsAutomaticUpdate"; +const sal_Char sAPI_source_name[] = "SourceName"; +const sal_Char sAPI_current_presentation[] = "CurrentPresentation"; +const sal_Char sAPI_reference_field_part[] = "ReferenceFieldPart"; +const sal_Char sAPI_reference_field_source[] = "ReferenceFieldSource"; +const sal_Char sAPI_dde_command_type[] = "DDECommandType"; +const sal_Char sAPI_dde_command_file[] = "DDECommandFile"; +const sal_Char sAPI_dde_command_element[] = "DDECommandElement"; +// sAPI_url: also used as service name +const sal_Char sAPI_target_frame[] = "TargetFrame"; +const sal_Char sAPI_representation[] = "Representation"; +const sal_Char sAPI_date[] = "Date"; +const sal_Char sAPI_url_content[] = "URLContent"; +const sal_Char sAPI_script_type[] = "ScriptType"; +const sal_Char sAPI_is_hidden[] = "IsHidden"; +const sal_Char sAPI_is_condition_true[] = "IsConditionTrue"; +const sal_Char sAPI_data_command_type[] = "DataCommandType"; +const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage"; +const sal_Char sAPI_is_visible[] = "IsVisible"; +const sal_Char sAPI_TextRange[] = "TextRange"; + +const sal_Char sAPI_true[] = "TRUE"; + + +TYPEINIT1( XMLTextFieldImportContext, SvXMLImportContext); + +XMLTextFieldImportContext::XMLTextFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + const sal_Char* pService, + sal_uInt16 nPrefix, const OUString& rElementName) +: SvXMLImportContext( rImport, nPrefix, rElementName ) +, sIsFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)) +, rTextImportHelper(rHlp) +, sServicePrefix(RTL_CONSTASCII_USTRINGPARAM(sAPI_textfield_prefix)) +, bValid(sal_False) +{ + DBG_ASSERT(NULL != pService, "Need service name!"); + sServiceName = OUString::createFromAscii(pService); +} + +void XMLTextFieldImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // process attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) { + + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + ProcessAttribute(rTextImportHelper.GetTextFieldAttrTokenMap(). + Get(nPrefix, sLocalName), + xAttrList->getValueByIndex(i) ); + } +} + +XMLTextFieldImportContext::~XMLTextFieldImportContext() { +} + +OUString XMLTextFieldImportContext::GetContent() +{ + if (sContent.getLength()==0) + { + sContent = sContentBuffer.makeStringAndClear(); + } + + return sContent; +} + +void XMLTextFieldImportContext::EndElement() +{ + DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!"); + if (bValid) + { + + // create field/Service + Reference<XPropertySet> xPropSet; + if (CreateField(xPropSet, sServicePrefix + GetServiceName())) + { + // set field properties + PrepareField(xPropSet); + + // attach field to document + Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY); + + // workaround for #80606# + try + { + rTextImportHelper.InsertTextContent(xTextContent); + } + catch (lang::IllegalArgumentException e) + { + // ignore + } + return; + } + } + + // in case of error: write element content + rTextImportHelper.InsertString(GetContent()); +} + +void XMLTextFieldImportContext::Characters(const OUString& rContent) +{ + sContentBuffer.append(rContent); +} + +sal_Bool XMLTextFieldImportContext::CreateField( + Reference<XPropertySet> & xField, + const OUString& rServiceName) +{ + // instantiate new XTextField: + // ask import for model, model is factory, ask factory to create service + + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY); + if( xFactory.is() ) + { + Reference<XInterface> xIfc = xFactory->createInstance(rServiceName); + if( xIfc.is() ) + { + Reference<XPropertySet> xTmp( xIfc, UNO_QUERY ); + + xField = xTmp; + } else { + return sal_False; // can't create instance + } + } else { + return sal_False; // can't get MultiServiceFactory + } + + return sal_True; +} + +/// create the appropriate field context from +XMLTextFieldImportContext* +XMLTextFieldImportContext::CreateTextFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrefix, + const OUString& rName, + sal_uInt16 nToken) +{ + XMLTextFieldImportContext* pContext = NULL; + + switch (nToken) + { + case XML_TOK_TEXT_SENDER_FIRSTNAME: + case XML_TOK_TEXT_SENDER_LASTNAME: + case XML_TOK_TEXT_SENDER_INITIALS: + case XML_TOK_TEXT_SENDER_TITLE: + case XML_TOK_TEXT_SENDER_POSITION: + case XML_TOK_TEXT_SENDER_EMAIL: + case XML_TOK_TEXT_SENDER_PHONE_PRIVATE: + case XML_TOK_TEXT_SENDER_FAX: + case XML_TOK_TEXT_SENDER_COMPANY: + case XML_TOK_TEXT_SENDER_PHONE_WORK: + case XML_TOK_TEXT_SENDER_STREET: + case XML_TOK_TEXT_SENDER_CITY: + case XML_TOK_TEXT_SENDER_POSTAL_CODE: + case XML_TOK_TEXT_SENDER_COUNTRY: + case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE: + pContext = + new XMLSenderFieldImportContext( rImport, rHlp, + nPrefix, rName, nToken ); + break; + + case XML_TOK_TEXT_AUTHOR_NAME: + case XML_TOK_TEXT_AUTHOR_INITIALS: + pContext = + new XMLAuthorFieldImportContext( rImport, rHlp, + nPrefix, rName, nToken ); + break; + + case XML_TOK_TEXT_PLACEHOLDER: + pContext = + new XMLPlaceholderFieldImportContext( rImport, rHlp, + nPrefix, rName); + break; + case XML_TOK_TEXT_SEQUENCE: + pContext = + new XMLSequenceFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_TEXT_INPUT: + pContext = + new XMLTextInputFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_EXPRESSION: + pContext = + new XMLExpressionFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_VARIABLE_SET: + pContext = + new XMLVariableSetFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_VARIABLE_INPUT: + pContext = + new XMLVariableInputFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_VARIABLE_GET: + pContext = + new XMLVariableGetFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_USER_FIELD_GET: + pContext = new XMLUserFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_USER_FIELD_INPUT: + pContext = new XMLUserFieldInputImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_TIME: + pContext = new XMLTimeFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_PAGE_CONTINUATION_STRING: + case XML_TOK_TEXT_PAGE_CONTINUATION: + pContext = new XMLPageContinuationImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_PAGE_NUMBER: + pContext = new XMLPageNumberImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_DATE: + pContext = new XMLDateFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_DATABASE_NAME: + pContext = new XMLDatabaseNameImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DATABASE_NEXT: + pContext = new XMLDatabaseNextImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DATABASE_SELECT: + pContext = new XMLDatabaseSelectImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DATABASE_ROW_NUMBER: + pContext = new XMLDatabaseNumberImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DATABASE_DISPLAY: + pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_CONDITIONAL_TEXT: + pContext = new XMLConditionalTextImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_HIDDEN_TEXT: + pContext = new XMLHiddenTextImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_HIDDEN_PARAGRAPH: + pContext = new XMLHiddenParagraphImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DOCUMENT_DESCRIPTION: + case XML_TOK_TEXT_DOCUMENT_TITLE: + case XML_TOK_TEXT_DOCUMENT_SUBJECT: + case XML_TOK_TEXT_DOCUMENT_KEYWORDS: + pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp, + nPrefix, rName, + nToken, sal_True, + sal_False ); + break; + case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR: + case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR: + case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR: + pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp, + nPrefix, rName, + nToken, sal_False, + sal_True ); + break; + + case XML_TOK_TEXT_DOCUMENT_CREATION_DATE: + case XML_TOK_TEXT_DOCUMENT_CREATION_TIME: + case XML_TOK_TEXT_DOCUMENT_PRINT_DATE: + case XML_TOK_TEXT_DOCUMENT_PRINT_TIME: + case XML_TOK_TEXT_DOCUMENT_SAVE_DATE: + case XML_TOK_TEXT_DOCUMENT_SAVE_TIME: + case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION: + pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp, + nPrefix, rName, + nToken ); + break; + + case XML_TOK_TEXT_DOCUMENT_REVISION: + pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp, + nPrefix, rName, + nToken ); + break; + + case XML_TOK_TEXT_DOCUMENT_USER_DEFINED: + pContext = new XMLUserDocInfoImportContext( rImport, rHlp, + nPrefix, rName, + nToken ); + break; + + case XML_TOK_TEXT_FILENAME: + pContext = new XMLFileNameImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_CHAPTER: + pContext = new XMLChapterImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_TEMPLATENAME: + pContext = new XMLTemplateNameImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_WORD_COUNT: + case XML_TOK_TEXT_PARAGRAPH_COUNT: + case XML_TOK_TEXT_TABLE_COUNT: + case XML_TOK_TEXT_CHARACTER_COUNT: + case XML_TOK_TEXT_IMAGE_COUNT: + case XML_TOK_TEXT_OBJECT_COUNT: + case XML_TOK_TEXT_PAGE_COUNT: + pContext = new XMLCountFieldImportContext( rImport, rHlp, + nPrefix, rName, nToken); + break; + + case XML_TOK_TEXT_GET_PAGE_VAR: + pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_SET_PAGE_VAR: + pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_MACRO: + pContext = new XMLMacroFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_DDE: + pContext = new XMLDdeFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_REFERENCE_REF: + case XML_TOK_TEXT_BOOKMARK_REF: + case XML_TOK_TEXT_NOTE_REF: + case XML_TOK_TEXT_SEQUENCE_REF: + pContext = new XMLReferenceFieldImportContext( rImport, rHlp, + nToken, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_SHEET_NAME: + pContext = new XMLSheetNameImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_BIBLIOGRAPHY_MARK: + pContext = new XMLBibliographyFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_ANNOTATION: + pContext = new XMLAnnotationImportContext( rImport, rHlp, + nPrefix, rName); + break; + + case XML_TOK_TEXT_SCRIPT: + pContext = new XMLScriptImportContext( rImport, rHlp, + nPrefix, rName); + break; + + case XML_TOK_TEXT_MEASURE: + pContext = new XMLMeasureFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + case XML_TOK_TEXT_TABLE_FORMULA: + pContext = new XMLTableFormulaImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_TEXT_DROPDOWN: + pContext = new XMLDropDownFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_DRAW_HEADER: + pContext = new XMLHeaderFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_DRAW_FOOTER: + pContext = new XMLFooterFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + case XML_TOK_DRAW_DATE_TIME: + pContext = new XMLDateTimeFieldImportContext( rImport, rHlp, + nPrefix, rName ); + break; + + default: + // ignore! May not even be a textfield. + // (Reminder: This method is called inside default:-branch) + pContext = NULL; + break; + } + + return pContext; +} + + +void XMLTextFieldImportContext::ForceUpdate( + const Reference<XPropertySet> & rPropertySet) +{ + // force update + Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY); + if (xUpdate.is()) + { + xUpdate->update(); + } + else + { + DBG_ERROR("Expected XUpdatable support!"); + } +} + + + +// +// XMLSenderFieldImportContext +// + +TYPEINIT1( XMLSenderFieldImportContext, XMLTextFieldImportContext); + +XMLSenderFieldImportContext::XMLSenderFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName, + sal_uInt16 nToken) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_extended_user,nPrfx, sLocalName) +, sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)) +, sPropertyFieldSubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_user_data_type)) +, sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +, bFixed(sal_True) +, nElementToken(nToken) +{ +} + +void XMLSenderFieldImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + bValid = sal_True; + switch (nElementToken) { + case XML_TOK_TEXT_SENDER_FIRSTNAME: + nSubType = UserDataPart::FIRSTNAME; + break; + case XML_TOK_TEXT_SENDER_LASTNAME: + nSubType = UserDataPart::NAME; + break; + case XML_TOK_TEXT_SENDER_INITIALS: + nSubType = UserDataPart::SHORTCUT; + break; + case XML_TOK_TEXT_SENDER_TITLE: + nSubType = UserDataPart::TITLE; + break; + case XML_TOK_TEXT_SENDER_POSITION: + nSubType = UserDataPart::POSITION; + break; + case XML_TOK_TEXT_SENDER_EMAIL: + nSubType = UserDataPart::EMAIL; + break; + case XML_TOK_TEXT_SENDER_PHONE_PRIVATE: + nSubType = UserDataPart::PHONE_PRIVATE; + break; + case XML_TOK_TEXT_SENDER_FAX: + nSubType = UserDataPart::FAX; + break; + case XML_TOK_TEXT_SENDER_COMPANY: + nSubType = UserDataPart::COMPANY; + break; + case XML_TOK_TEXT_SENDER_PHONE_WORK: + nSubType = UserDataPart::PHONE_COMPANY; + break; + case XML_TOK_TEXT_SENDER_STREET: + nSubType = UserDataPart::STREET; + break; + case XML_TOK_TEXT_SENDER_CITY: + nSubType = UserDataPart::CITY; + break; + case XML_TOK_TEXT_SENDER_POSTAL_CODE: + nSubType = UserDataPart::ZIP; + break; + case XML_TOK_TEXT_SENDER_COUNTRY: + nSubType = UserDataPart::COUNTRY; + break; + case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE: + nSubType = UserDataPart::STATE; + break; + default: + bValid = sal_False; + break; + } + + // process Attributes + XMLTextFieldImportContext::StartElement(xAttrList); +} + +void XMLSenderFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue) +{ + if (XML_TOK_TEXTFIELD_FIXED == nAttrToken) { + + // set bVal + sal_Bool bVal; + sal_Bool bRet = GetImport().GetMM100UnitConverter(). + convertBool(bVal, sAttrValue); + + // set bFixed if successfull + if (bRet) { + bFixed = bVal; + } + } +} + +void XMLSenderFieldImportContext::PrepareField( + const Reference<XPropertySet> & rPropSet) +{ + // set members + Any aAny; + aAny <<= nSubType; + rPropSet->setPropertyValue(sPropertyFieldSubType, aAny); + + // set fixed + aAny.setValue( &bFixed, ::getBooleanCppuType() ); + rPropSet->setPropertyValue(sPropertyFixed, aAny); + + // set content if fixed + if (bFixed) + { + // in organizer or styles-only mode: force update + if (GetImport().GetTextImport()->IsOrganizerMode() || + GetImport().GetTextImport()->IsStylesOnlyMode() ) + { + ForceUpdate(rPropSet); + } + else + { + aAny <<= GetContent(); + rPropSet->setPropertyValue(sPropertyContent, aAny); + } + } +} + + + +// +// XMLAuthorFieldImportContext +// + +TYPEINIT1( XMLAuthorFieldImportContext, XMLSenderFieldImportContext); + +XMLAuthorFieldImportContext::XMLAuthorFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName, + sal_uInt16 nToken) +: XMLSenderFieldImportContext(rImport, rHlp, nPrfx, sLocalName, nToken) +, bAuthorFullName(sal_True) +, sServiceAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author)) +, sPropertyAuthorFullName(RTL_CONSTASCII_USTRINGPARAM(sAPI_full_name)) +, sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)) +, sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +{ + // overwrite service name from XMLSenderFieldImportContext + SetServiceName(sServiceAuthor); +} + +void XMLAuthorFieldImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) { + + bAuthorFullName = (XML_TOK_TEXT_AUTHOR_INITIALS != nElementToken); + bValid = sal_True; + + // process Attributes + XMLTextFieldImportContext::StartElement(xAttrList); +} + +void XMLAuthorFieldImportContext::PrepareField( + const Reference<XPropertySet> & rPropSet) +{ + // set members + Any aAny; + aAny.setValue( &bAuthorFullName, ::getBooleanCppuType() ); + rPropSet->setPropertyValue(sPropertyAuthorFullName, aAny); + + aAny.setValue( &bFixed, ::getBooleanCppuType() ); + rPropSet->setPropertyValue(sPropertyFixed, aAny); + + // set content if fixed + if (bFixed) + { + // organizer or styles-only mode: force update + if (GetImport().GetTextImport()->IsOrganizerMode() || + GetImport().GetTextImport()->IsStylesOnlyMode() ) + { + ForceUpdate(rPropSet); + } + else + { + aAny <<= GetContent(); + rPropSet->setPropertyValue(sPropertyContent, aAny); + } + } +} + + +// +// page continuation string +// + +TYPEINIT1( XMLPageContinuationImportContext, XMLTextFieldImportContext ); + +static SvXMLEnumMapEntry __READONLY_DATA lcl_aSelectPageAttrMap[] = +{ + { XML_PREVIOUS, PageNumberType_PREV }, + { XML_CURRENT, PageNumberType_CURRENT }, + { XML_NEXT, PageNumberType_NEXT }, + { XML_TOKEN_INVALID, 0 }, +}; + +XMLPageContinuationImportContext::XMLPageContinuationImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName) +, sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)) +, sPropertyUserText(RTL_CONSTASCII_USTRINGPARAM(sAPI_user_text)) +, sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)) +, eSelectPage(PageNumberType_CURRENT) +, sStringOK(sal_False) +{ + bValid = sal_True; +} + +void XMLPageContinuationImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch(nAttrToken) + { + case XML_TOK_TEXTFIELD_SELECT_PAGE: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, + lcl_aSelectPageAttrMap) + && (PageNumberType_CURRENT != nTmp) ) + { + eSelectPage = (PageNumberType)nTmp; + } + break; + } + case XML_TOK_TEXTFIELD_STRING_VALUE: + sString = sAttrValue; + sStringOK = sal_True; + break; + } +} + +void XMLPageContinuationImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= eSelectPage; + xPropertySet->setPropertyValue(sPropertySubType, aAny); + + aAny <<= (sStringOK ? sString : GetContent()); + xPropertySet->setPropertyValue(sPropertyUserText, aAny); + + aAny <<= style::NumberingType::CHAR_SPECIAL; + xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); +} + + + +// +// page number field +// + +TYPEINIT1( XMLPageNumberImportContext, XMLTextFieldImportContext ); + +XMLPageNumberImportContext::XMLPageNumberImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName) +, sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)) +, sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)) +, sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM(sAPI_offset)) +, sNumberSync(GetXMLToken(XML_FALSE)) +, nPageAdjust(0) +, eSelectPage(PageNumberType_CURRENT) +, sNumberFormatOK(sal_False) +{ + bValid = sal_True; +} + +void XMLPageNumberImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NUM_FORMAT: + sNumberFormat = sAttrValue; + sNumberFormatOK = sal_True; + break; + case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC: + sNumberSync = sAttrValue; + break; + case XML_TOK_TEXTFIELD_SELECT_PAGE: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, + lcl_aSelectPageAttrMap)) + { + eSelectPage = (PageNumberType)nTmp; + } + break; + } + case XML_TOK_TEXTFIELD_PAGE_ADJUST: + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue)) + { + nPageAdjust = (sal_Int16)nTmp; + } + break; + } + } +} + +void XMLPageNumberImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + // all properties are optional + Reference<XPropertySetInfo> xPropertySetInfo( + xPropertySet->getPropertySetInfo()); + + if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType)) + { + sal_Int16 nNumType; + if( sNumberFormatOK ) + { + nNumType= style::NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumberFormat, + sNumberSync ); + } + else + nNumType = style::NumberingType::PAGE_DESCRIPTOR; + + aAny <<= nNumType; + xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); + } + + if (xPropertySetInfo->hasPropertyByName(sPropertyOffset)) + { + // adjust offset + switch (eSelectPage) + { + case PageNumberType_PREV: + nPageAdjust--; + break; + case PageNumberType_CURRENT: + break; + case PageNumberType_NEXT: + nPageAdjust++; + break; + default: + DBG_WARNING("unknown page number type"); + } + aAny <<= nPageAdjust; + xPropertySet->setPropertyValue(sPropertyOffset, aAny); + } + + if (xPropertySetInfo->hasPropertyByName(sPropertySubType)) + { + aAny <<= eSelectPage; + xPropertySet->setPropertyValue(sPropertySubType, aAny); + } +} + + + +// +// Placeholder +// + +TYPEINIT1( XMLPlaceholderFieldImportContext, XMLTextFieldImportContext); + +XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_jump_edit,nPrfx, sLocalName) +, sPropertyPlaceholderType(RTL_CONSTASCII_USTRINGPARAM(sAPI_place_holder_type)) +, sPropertyPlaceholder(RTL_CONSTASCII_USTRINGPARAM(sAPI_place_holder)) +, sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)) +{ +} + +/// process attribute values +void XMLPlaceholderFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) { + case XML_TOK_TEXTFIELD_DESCRIPTION: + sDescription = sAttrValue; + break; + + case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE: + bValid = sal_True; + if (IsXMLToken(sAttrValue, XML_TABLE)) + { + nPlaceholderType = PlaceholderType::TABLE; + } + else if (IsXMLToken(sAttrValue, XML_TEXT)) + { + nPlaceholderType = PlaceholderType::TEXT; + } + else if (IsXMLToken(sAttrValue, XML_TEXT_BOX)) + { + nPlaceholderType = PlaceholderType::TEXTFRAME; + } + else if (IsXMLToken(sAttrValue, XML_IMAGE)) + { + nPlaceholderType = PlaceholderType::GRAPHIC; + } + else if (IsXMLToken(sAttrValue, XML_OBJECT)) + { + nPlaceholderType = PlaceholderType::OBJECT; + } + else + { + bValid = sal_False; + } + break; + + default: + ; // ignore + } +} + +void XMLPlaceholderFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) { + + Any aAny; + aAny <<= sDescription; + xPropertySet->setPropertyValue(sPropertyHint, aAny); + + // remove <...> around content (if present) + OUString aContent = GetContent(); + sal_Int32 nStart = 0; + sal_Int32 nLength = aContent.getLength(); + if ((nLength > 0) && (aContent.getStr()[0] == '<')) + { + --nLength; + ++nStart; + } + if ((nLength > 0) && (aContent.getStr()[aContent.getLength()-1] == '>')) + { + --nLength; + } + aAny <<= aContent.copy(nStart, nLength); + xPropertySet->setPropertyValue(sPropertyPlaceholder, aAny); + + aAny <<= nPlaceholderType; + xPropertySet->setPropertyValue(sPropertyPlaceholderType, aAny); +} + + +// +// time field +// + +TYPEINIT1( XMLTimeFieldImportContext, XMLTextFieldImportContext); + +XMLTimeFieldImportContext::XMLTimeFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time, nPrfx, sLocalName) +, sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)) +, sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)) +, sPropertyDateTimeValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time_value)) +, sPropertyDateTime(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time)) +, sPropertyAdjust(RTL_CONSTASCII_USTRINGPARAM(sAPI_adjust)) +, sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_date)) +, sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)) +, fTimeValue(0.0) +, nAdjust(0) +, nFormatKey(0) +, bTimeOK(sal_False) +, bFormatOK(sal_False) +, bFixed(sal_False) +, bIsDate(sal_False) +, bIsDefaultLanguage( sal_True ) +{ + bValid = sal_True; // always valid! +} + +void XMLTimeFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_TIME_VALUE: + { + double fTmp; + if (GetImport().GetMM100UnitConverter(). + convertDateTime(fTmp, sAttrValue)) + { + fTimeValue = fTmp; + bTimeOK = sal_True; + } + + if (GetImport().GetMM100UnitConverter(). + convertDateTime(aDateTimeValue, sAttrValue )) + { + bTimeOK = sal_True; + } + break; + } + case XML_TOK_TEXTFIELD_FIXED: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bFixed = bTmp; + } + break; + } + case XML_TOK_TEXTFIELD_DATA_STYLE_NAME: + { + sal_Int32 nKey = GetImportHelper().GetDataStyleKey( + sAttrValue, &bIsDefaultLanguage); + if (-1 != nKey) + { + nFormatKey = nKey; + bFormatOK = sal_True; + } + break; + } + case XML_TOK_TEXTFIELD_TIME_ADJUST: + { + double fTmp; + + if (SvXMLUnitConverter::convertTime(fTmp, sAttrValue)) + { + // convert to minutes + nAdjust = (sal_Int32)::rtl::math::approxFloor(fTmp * 60 * 24); + } + break; + } + } +} + +void XMLTimeFieldImportContext::PrepareField( + const Reference<XPropertySet> & rPropertySet) +{ + Any aAny; + + // all properties are optional (except IsDate) + Reference<XPropertySetInfo> xPropertySetInfo( + rPropertySet->getPropertySetInfo()); + + if (xPropertySetInfo->hasPropertyByName(sPropertyFixed)) + { + aAny.setValue( &bFixed, ::getBooleanCppuType() ); + rPropertySet->setPropertyValue(sPropertyFixed, aAny); + } + + aAny.setValue( &bIsDate, ::getBooleanCppuType() ); + rPropertySet->setPropertyValue(sPropertyIsDate, aAny); + + if (xPropertySetInfo->hasPropertyByName(sPropertyAdjust)) + { + aAny <<= nAdjust; + rPropertySet->setPropertyValue(sPropertyAdjust, aAny); + } + + // set value + if (bFixed) + { + // organizer or styles-only mode: force update + if (GetImport().GetTextImport()->IsOrganizerMode() || + GetImport().GetTextImport()->IsStylesOnlyMode() ) + { + ForceUpdate(rPropertySet); + } + else + { + // normal mode: set value (if present) + if (bTimeOK) + { + if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue)) + { + aAny <<= aDateTimeValue; + rPropertySet->setPropertyValue(sPropertyDateTimeValue,aAny); + } + else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime)) + { + aAny <<= aDateTimeValue; + rPropertySet->setPropertyValue(sPropertyDateTime, aAny); + } + } + } + } + + if (bFormatOK && + xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat)) + { + aAny <<= nFormatKey; + rPropertySet->setPropertyValue(sPropertyNumberFormat, aAny); + + if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) ) + { + sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage; + aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() ); + rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny ); + } + } +} + + + +// +// date field +// + +TYPEINIT1( XMLDateFieldImportContext, XMLTimeFieldImportContext ); + +XMLDateFieldImportContext::XMLDateFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTimeFieldImportContext(rImport, rHlp, nPrfx, sLocalName) +{ + bIsDate = sal_True; // always a date! +} + +void XMLDateFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DATE_VALUE: + { + double fTmp; + + if (GetImport().GetMM100UnitConverter(). + convertDateTime(fTmp, sAttrValue)) + { + // #96457#: don't truncate in order to read date+time + fTimeValue = fTmp; + bTimeOK = sal_True; + } + + if (GetImport().GetMM100UnitConverter(). + convertDateTime(aDateTimeValue, sAttrValue )) + { + bTimeOK = sal_True; + } + break; + } + case XML_TOK_TEXTFIELD_DATE_ADJUST: + // delegate to superclass, pretending it was a time-adjust attr. + XMLTimeFieldImportContext::ProcessAttribute( + XML_TOK_TEXTFIELD_TIME_ADJUST, + sAttrValue); + break; + case XML_TOK_TEXTFIELD_TIME_VALUE: + case XML_TOK_TEXTFIELD_TIME_ADJUST: + ; // ignore time-adjust and time-value attributes + break; + default: + // all others: delegate to super-class + XMLTimeFieldImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + } +} + + + + +// +// database field superclass +// + +TYPEINIT1( XMLDatabaseFieldImportContext, XMLTextFieldImportContext ); + +XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + const sal_Char* pServiceName, sal_uInt16 nPrfx, + const OUString& sLocalName, bool bUseDisply) +: XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, sLocalName) +, sPropertyDataBaseName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_base_name)) +, sPropertyDataBaseURL(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_base_u_r_l)) +, sPropertyTableName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_table_name)) +, sPropertyDataCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_command_type)) +, sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)) +, nCommandType( sdb::CommandType::TABLE ) +, bCommandTypeOK(sal_False) +, bDisplay( sal_True ) +, bDisplayOK( false ) +, bUseDisplay( bUseDisply ) +, bDatabaseOK(sal_False) +, bDatabaseNameOK(sal_False) +, bDatabaseURLOK(sal_False) +, bTableOK(sal_False) +{ +} + +void XMLDatabaseFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DATABASE_NAME: + sDatabaseName = sAttrValue; + bDatabaseOK = sal_True; + bDatabaseNameOK = sal_True; + break; + case XML_TOK_TEXTFIELD_TABLE_NAME: + sTableName = sAttrValue; + bTableOK = sal_True; + break; + case XML_TOK_TEXTFIELD_TABLE_TYPE: + if( IsXMLToken( sAttrValue, XML_TABLE ) ) + { + nCommandType = sdb::CommandType::TABLE; + bCommandTypeOK = sal_True; + } + else if( IsXMLToken( sAttrValue, XML_QUERY ) ) + { + nCommandType = sdb::CommandType::QUERY; + bCommandTypeOK = sal_True; + } + else if( IsXMLToken( sAttrValue, XML_COMMAND ) ) + { + nCommandType = sdb::CommandType::COMMAND; + bCommandTypeOK = sal_True; + } + break; + case XML_TOK_TEXTFIELD_DISPLAY: + if( IsXMLToken( sAttrValue, XML_NONE ) ) + { + bDisplay = sal_False; + bDisplayOK = true; + } + else if( IsXMLToken( sAttrValue, XML_VALUE ) ) + { + bDisplay = sal_True; + bDisplayOK = true; + } + break; + } +} + +SvXMLImportContext* XMLDatabaseFieldImportContext::CreateChildContext( + sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& xAttrList ) +{ + if( ( p_nPrefix == XML_NAMESPACE_FORM ) && + IsXMLToken( rLocalName, XML_CONNECTION_RESOURCE ) ) + { + // process attribute list directly + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 n = 0; n < nLength; n++ ) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName ); + + if( ( nPrefix == XML_NAMESPACE_XLINK ) && + IsXMLToken( sLocalName, XML_HREF ) ) + { + sDatabaseURL = xAttrList->getValueByIndex(n); + bDatabaseOK = sal_True; + bDatabaseURLOK = sal_True; + } + } + + // we call ProcessAttribute in order to set bValid appropriatly + ProcessAttribute( XML_TOKEN_INVALID, OUString() ); + } + + return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName, + xAttrList); +} + + +void XMLDatabaseFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= sTableName; + xPropertySet->setPropertyValue(sPropertyTableName, aAny); + + if( bDatabaseNameOK ) + { + aAny <<= sDatabaseName; + xPropertySet->setPropertyValue(sPropertyDataBaseName, aAny); + } + else if( bDatabaseURLOK ) + { + aAny <<= sDatabaseURL; + xPropertySet->setPropertyValue(sPropertyDataBaseURL, aAny); + } + + // #99980# load/save command type for all fields; also load + // old documents without command type + if( bCommandTypeOK ) + { + aAny <<= nCommandType; + xPropertySet->setPropertyValue( sPropertyDataCommandType, aAny ); + } + + if( bUseDisplay && bDisplayOK ) + { + aAny.setValue( &bDisplay, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue( sPropertyIsVisible, aAny ); + } +} + + + +// +// database name field +// + +TYPEINIT1( XMLDatabaseNameImportContext, XMLDatabaseFieldImportContext ); + +XMLDatabaseNameImportContext::XMLDatabaseNameImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_name, + nPrfx, sLocalName, true) +{ +} + +void XMLDatabaseNameImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + // delegate to superclass and check for success + XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue); + bValid = bDatabaseOK && bTableOK; +} + + + +// +// database next field +// + +TYPEINIT1( XMLDatabaseNextImportContext, XMLDatabaseFieldImportContext ); + +XMLDatabaseNextImportContext::XMLDatabaseNextImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + const sal_Char* pServiceName, sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName, + nPrfx, sLocalName, false), + sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)), + sTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_true)), + sCondition(), + bConditionOK(sal_False) +{ +} + +XMLDatabaseNextImportContext::XMLDatabaseNextImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) +: XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_next, nPrfx, sLocalName, false) +, sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)) +, sTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_true)) +, bConditionOK(sal_False) +{ +} + +void XMLDatabaseNextImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken) + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName( + sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sCondition = sTmp; + bConditionOK = sal_True; + } + else + sCondition = sAttrValue; + } + else + { + XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + } + + bValid = bDatabaseOK && bTableOK; +} + +void XMLDatabaseNextImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= bConditionOK ? sCondition : sTrue; + xPropertySet->setPropertyValue(sPropertyCondition, aAny); + + XMLDatabaseFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// database select field +// + +TYPEINIT1( XMLDatabaseSelectImportContext, XMLDatabaseNextImportContext ); + +XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const ::rtl::OUString& sLocalName) : + XMLDatabaseNextImportContext(rImport, rHlp, sAPI_database_select, + nPrfx, sLocalName), + sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_set_number)), + nNumber(0), + bNumberOK(sal_False) +{ +} + +void XMLDatabaseSelectImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + if (XML_TOK_TEXTFIELD_ROW_NUMBER == nAttrToken) + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( nTmp, sAttrValue + /* , nMin, nMax ??? */ )) + { + nNumber = nTmp; + bNumberOK = sal_True; + } + } + else + { + XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue); + } + + bValid = bTableOK && bDatabaseOK && bNumberOK; +} + +void XMLDatabaseSelectImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= nNumber; + xPropertySet->setPropertyValue(sPropertySetNumber, aAny); + + XMLDatabaseNextImportContext::PrepareField(xPropertySet); +} + + + +// +// database display row number field +// + +TYPEINIT1( XMLDatabaseNumberImportContext, XMLDatabaseFieldImportContext ); + +XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_number, + nPrfx, sLocalName, true), + sPropertyNumberingType( + RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)), + sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_set_number)), + sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("1")), + sNumberSync(GetXMLToken(XML_FALSE)), + nValue(0), + bValueOK(sal_False) +{ +} + +void XMLDatabaseNumberImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NUM_FORMAT: + sNumberFormat = sAttrValue; + break; + case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC: + sNumberSync = sAttrValue; + break; + case XML_TOK_TEXTFIELD_VALUE: + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( nTmp, sAttrValue )) + { + nValue = nTmp; + bValueOK = sal_True; + } + break; + } + default: + XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + } + + bValid = bTableOK && bDatabaseOK; +} + +void XMLDatabaseNumberImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + sal_Int16 nNumType = style::NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumberFormat, + sNumberSync ); + aAny <<= nNumType; + xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); + + if (bValueOK) + { + aAny <<= nValue; + xPropertySet->setPropertyValue(sPropertySetNumber, aAny); + } + + XMLDatabaseFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// Simple doc info fields +// + +TYPEINIT1( XMLSimpleDocInfoImportContext, XMLTextFieldImportContext ); + +XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken, + sal_Bool bContent, sal_Bool bAuthor) +: XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),nPrfx, sLocalName) +, sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)) +, sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +, sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author)) +, sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)) +, bFixed(sal_False) +, bHasAuthor(bAuthor) +, bHasContent(bContent) +{ + bValid = sal_True; +} + +void XMLSimpleDocInfoImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + if (XML_TOK_TEXTFIELD_FIXED == nAttrToken) + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bFixed = bTmp; + } + } +} + +void XMLSimpleDocInfoImportContext::PrepareField( + const Reference<XPropertySet> & rPropertySet) +{ + // title field in Calc has no Fixed property + Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo()); + if (xPropertySetInfo->hasPropertyByName(sPropertyFixed)) + { + Any aAny; + aAny.setValue(&bFixed, ::getBooleanCppuType() ); + rPropertySet->setPropertyValue(sPropertyFixed, aAny); + + // set Content and CurrentPresentation (if fixed) + if (bFixed) + { + // in organizer-mode or styles-only-mode, only force update + if (GetImport().GetTextImport()->IsOrganizerMode() || + GetImport().GetTextImport()->IsStylesOnlyMode() ) + { + ForceUpdate(rPropertySet); + } + else + { + // set content (author, if that's the name) and current + // presentation + aAny <<= GetContent(); + + if (bFixed && bHasAuthor) + { + rPropertySet->setPropertyValue(sPropertyAuthor, aAny); + } + + if (bFixed && bHasContent) + { + rPropertySet->setPropertyValue(sPropertyContent, aAny); + } + + rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); + } + } + } +} + +const sal_Char* XMLSimpleDocInfoImportContext::MapTokenToServiceName( + sal_uInt16 nToken) +{ + const sal_Char* pServiceName = NULL; + + switch(nToken) + { + case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR: + pServiceName = sAPI_docinfo_create_author; + break; + case XML_TOK_TEXT_DOCUMENT_CREATION_DATE: + pServiceName = sAPI_docinfo_create_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_CREATION_TIME: + pServiceName = sAPI_docinfo_create_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_DESCRIPTION: + pServiceName = sAPI_docinfo_description; + break; + case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION: + pServiceName = sAPI_docinfo_edit_time; + break; + case XML_TOK_TEXT_DOCUMENT_USER_DEFINED: + pServiceName = sAPI_docinfo_custom; + break; + case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR: + pServiceName = sAPI_docinfo_print_author; + break; + case XML_TOK_TEXT_DOCUMENT_PRINT_DATE: + pServiceName = sAPI_docinfo_print_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_PRINT_TIME: + pServiceName = sAPI_docinfo_print_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_KEYWORDS: + pServiceName = sAPI_docinfo_keywords; + break; + case XML_TOK_TEXT_DOCUMENT_SUBJECT: + pServiceName = sAPI_docinfo_subject; + break; + case XML_TOK_TEXT_DOCUMENT_REVISION: + pServiceName = sAPI_docinfo_revision; + break; + case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR: + pServiceName = sAPI_docinfo_change_author; + break; + case XML_TOK_TEXT_DOCUMENT_SAVE_DATE: + pServiceName = sAPI_docinfo_change_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_SAVE_TIME: + pServiceName = sAPI_docinfo_change_date_time; + break; + case XML_TOK_TEXT_DOCUMENT_TITLE: + pServiceName = sAPI_docinfo_title; + break; + + default: + DBG_ERROR("no docinfo field token"); + pServiceName = NULL; + break; + } + + return pServiceName; +} + + +// +// revision field +// + +TYPEINIT1( XMLRevisionDocInfoImportContext, XMLSimpleDocInfoImportContext ); + +XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName, sal_uInt16 nToken) : + XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName, + nToken, sal_False, sal_False), + sPropertyRevision(RTL_CONSTASCII_USTRINGPARAM(sAPI_revision)) +{ + bValid = sal_True; +} + +void XMLRevisionDocInfoImportContext::PrepareField( + const Reference<XPropertySet> & rPropertySet) +{ + XMLSimpleDocInfoImportContext::PrepareField(rPropertySet); + + // set revision number + // if fixed, if not in organizer-mode, if not in styles-only-mode + if (bFixed) + { + if ( GetImport().GetTextImport()->IsOrganizerMode() || + GetImport().GetTextImport()->IsStylesOnlyMode() ) + { + ForceUpdate(rPropertySet); + } + else + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber(nTmp, GetContent())) + { + Any aAny; + aAny <<= nTmp; + rPropertySet->setPropertyValue(sPropertyRevision, aAny); + } + } + } +} + + + +// +// DocInfo fields with date/time attributes +// + +TYPEINIT1( XMLDateTimeDocInfoImportContext, XMLSimpleDocInfoImportContext ); + +XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName, sal_uInt16 nToken) +: XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,nToken, sal_False, sal_False) +, sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)) +, sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_date)) +, sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)) +, nFormat(0) +, bFormatOK(sal_False) +, bIsDefaultLanguage(sal_True) +{ + // we allow processing of EDIT_DURATION here, because import of actual + // is not supported anyway. If it was, we'd need an extra import class + // because times and time durations are presented differently! + + bValid = sal_True; + switch (nToken) + { + case XML_TOK_TEXT_DOCUMENT_CREATION_DATE: + case XML_TOK_TEXT_DOCUMENT_PRINT_DATE: + case XML_TOK_TEXT_DOCUMENT_SAVE_DATE: + bIsDate = sal_True; + bHasDateTime = sal_True; + break; + case XML_TOK_TEXT_DOCUMENT_CREATION_TIME: + case XML_TOK_TEXT_DOCUMENT_PRINT_TIME: + case XML_TOK_TEXT_DOCUMENT_SAVE_TIME: + bIsDate = sal_False; + bHasDateTime = sal_True; + break; + case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION: + bIsDate = sal_False; + bHasDateTime = sal_False; + break; + default: + DBG_ERROR( + "XMLDateTimeDocInfoImportContext needs date/time doc. fields"); + bValid = sal_False; + break; + } +} + +void XMLDateTimeDocInfoImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DATA_STYLE_NAME: + { + sal_Int32 nKey = GetImportHelper().GetDataStyleKey( + sAttrValue, &bIsDefaultLanguage); + if (-1 != nKey) + { + nFormat = nKey; + bFormatOK = sal_True; + } + break; + } + case XML_TOK_TEXTFIELD_FIXED: + XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + default: + // ignore -> we can't set date/time value anyway! + break; + } +} + +void XMLDateTimeDocInfoImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // process fixed and presentation + XMLSimpleDocInfoImportContext::PrepareField(xPropertySet); + + Any aAny; + + if (bHasDateTime) + { + aAny.setValue( &bIsDate, ::getBooleanCppuType()); + xPropertySet->setPropertyValue(sPropertyIsDate, aAny); + } + + if (bFormatOK) + { + aAny <<= nFormat; + xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny); + + if( xPropertySet->getPropertySetInfo()-> + hasPropertyByName( sPropertyIsFixedLanguage ) ) + { + sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage; + aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny ); + } + } + + // can't set date/time/duration value! Sorry. +} + + +// +// user defined docinfo fields +// + +TYPEINIT1( XMLUserDocInfoImportContext, XMLSimpleDocInfoImportContext ); + +XMLUserDocInfoImportContext::XMLUserDocInfoImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) : + XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, + sLocalName, nToken, + sal_False, sal_False) + , sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)) + , sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)) + , sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)) + , nFormat(0) + , bFormatOK(sal_False) + , bIsDefaultLanguage( sal_True ) +{ + bValid = sal_False; +} + +void XMLUserDocInfoImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DATA_STYLE_NAME: + { + sal_Int32 nKey = GetImportHelper().GetDataStyleKey( + sAttrValue, &bIsDefaultLanguage); + if (-1 != nKey) + { + nFormat = nKey; + bFormatOK = sal_True; + } + break; + } + case XML_TOK_TEXTFIELD_NAME: + { + if (!bValid) + { + SetServiceName(OUString::createFromAscii( sAPI_docinfo_custom ) ); + aName = sAttrValue; + bValid = sal_True; + } + break; + } + + default: + XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + } +} + +void XMLUserDocInfoImportContext::PrepareField( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & xPropertySet) +{ + uno::Any aAny; + if ( aName.getLength() ) + { + aAny <<= aName; + xPropertySet->setPropertyValue(sPropertyName, aAny); + } + Reference<XPropertySetInfo> xPropertySetInfo( + xPropertySet->getPropertySetInfo()); + if (bFormatOK && + xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat)) + { + aAny <<= nFormat; + xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny); + + if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) ) + { + sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage; + aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny ); + } + } + + // call superclass to handle "fixed" + XMLSimpleDocInfoImportContext::PrepareField(xPropertySet); +} + + +// +// import hidden paragraph fields +// + +TYPEINIT1( XMLHiddenParagraphImportContext, XMLTextFieldImportContext ); + +XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_paragraph, + nPrfx, sLocalName), + sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)), + sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_hidden)), + sCondition(), + bIsHidden(sal_False) +{ +} + +void XMLHiddenParagraphImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken) + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName( + sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sCondition = sTmp; + bValid = sal_True; + } + else + sCondition = sAttrValue; + } + else if (XML_TOK_TEXTFIELD_IS_HIDDEN == nAttrToken) + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bIsHidden = bTmp; + } + } +} + +void XMLHiddenParagraphImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + aAny <<= sCondition; + xPropertySet->setPropertyValue(sPropertyCondition, aAny); + + aAny.setValue( &bIsHidden, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue(sPropertyIsHidden, aAny); +} + + + +// +// import conditional text (<text:conditional-text>) +// + +TYPEINIT1( XMLConditionalTextImportContext, XMLTextFieldImportContext ); + +XMLConditionalTextImportContext::XMLConditionalTextImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_conditional_text, + nPrfx, sLocalName), + sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)), + sPropertyTrueContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_true_content)), + sPropertyFalseContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_false_content)), + sPropertyIsConditionTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_condition_true)), + sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)), + bConditionOK(sal_False), + bTrueOK(sal_False), + bFalseOK(sal_False), + bCurrentValue(sal_False) +{ +} + +void XMLConditionalTextImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_CONDITION: + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + _GetKeyByAttrName( sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sCondition = sTmp; + bConditionOK = sal_True; + } + else + sCondition = sAttrValue; + } + break; + case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE: + sFalseContent = sAttrValue; + bFalseOK = sal_True; + break; + case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE: + sTrueContent = sAttrValue; + bTrueOK = sal_True; + break; + case XML_TOK_TEXTFIELD_CURRENT_VALUE: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bCurrentValue = bTmp; + } + break; + } + } + + bValid = bConditionOK && bFalseOK && bTrueOK; +} + +void XMLConditionalTextImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= sCondition; + xPropertySet->setPropertyValue(sPropertyCondition, aAny); + + aAny <<= sFalseContent; + xPropertySet->setPropertyValue(sPropertyFalseContent, aAny); + + aAny <<= sTrueContent; + xPropertySet->setPropertyValue(sPropertyTrueContent, aAny); + + aAny.setValue( &bCurrentValue, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue(sPropertyIsConditionTrue, aAny); + + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); +} + + + +// +// hidden text +// + +TYPEINIT1( XMLHiddenTextImportContext, XMLTextFieldImportContext); + +XMLHiddenTextImportContext::XMLHiddenTextImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_text, + nPrfx, sLocalName), + sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)), + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)), + sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_hidden)), + bConditionOK(sal_False), + bStringOK(sal_False), + bIsHidden(sal_False) +{ +} + +void XMLHiddenTextImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_CONDITION: + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + _GetKeyByAttrName( sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sCondition = sTmp; + bConditionOK = sal_True; + } + else + sCondition = sAttrValue; + } + break; + case XML_TOK_TEXTFIELD_STRING_VALUE: + sString = sAttrValue; + bStringOK = sal_True; + break; + case XML_TOK_TEXTFIELD_IS_HIDDEN: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bIsHidden = bTmp; + } + break; + } + } + + bValid = bConditionOK && bStringOK; +} + +void XMLHiddenTextImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= sCondition; + xPropertySet->setPropertyValue(sPropertyCondition, aAny); + + aAny <<= sString; + xPropertySet->setPropertyValue(sPropertyContent, aAny); + + aAny.setValue( &bIsHidden, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue(sPropertyIsHidden, aAny); +} + + + +// +// file name fields +// + +TYPEINIT1( XMLFileNameImportContext, XMLTextFieldImportContext ); + +static const SvXMLEnumMapEntry aFilenameDisplayMap[] = +{ + { XML_PATH, FilenameDisplayFormat::PATH }, + { XML_NAME, FilenameDisplayFormat::NAME }, + { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT }, + { XML_FULL, FilenameDisplayFormat::FULL }, + { XML_TOKEN_INVALID, 0 } +}; + +XMLFileNameImportContext::XMLFileNameImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_file_name, + nPrfx, sLocalName), + sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)), + sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_file_format)), + sPropertyCurrentPresentation( + RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)), + nFormat(FilenameDisplayFormat::FULL), + bFixed(sal_False) +{ + bValid = sal_True; +} + +void XMLFileNameImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_FIXED: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bFixed = bTmp; + } + break; + } + case XML_TOK_TEXTFIELD_DISPLAY: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, + aFilenameDisplayMap)) + { + nFormat = (sal_uInt16)nTmp; + } + break; + } + default: + ; // unkown attribute: ignore + break; + } +} + +void XMLFileNameImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + // properties are optional + Reference<XPropertySetInfo> xPropertySetInfo( + xPropertySet->getPropertySetInfo()); + + if (xPropertySetInfo->hasPropertyByName(sPropertyFixed)) + { + aAny <<= bFixed; + xPropertySet->setPropertyValue(sPropertyFixed, aAny); + } + + if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat)) + { + aAny <<= nFormat; + xPropertySet->setPropertyValue(sPropertyFileFormat, aAny); + } + + if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation)) + { + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); + } +} + + +// +// template name field +// + +static const SvXMLEnumMapEntry aTemplateDisplayMap[] = +{ + { XML_FULL, TemplateDisplayFormat::FULL }, + { XML_PATH, TemplateDisplayFormat::PATH }, + { XML_NAME, TemplateDisplayFormat::NAME }, + { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT }, + { XML_AREA, TemplateDisplayFormat::AREA }, + { XML_TITLE, TemplateDisplayFormat::TITLE }, + { XML_TOKEN_INVALID, 0 } +}; + +TYPEINIT1( XMLTemplateNameImportContext, XMLTextFieldImportContext ); + +XMLTemplateNameImportContext::XMLTemplateNameImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_template_name, + nPrfx, sLocalName), + sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_file_format)), + nFormat(TemplateDisplayFormat::FULL) +{ + bValid = sal_True; +} + +void XMLTemplateNameImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DISPLAY: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, + aTemplateDisplayMap)) + { + nFormat = (sal_uInt16)nTmp; + } + break; + } + default: + ; // unknown attribute: ignore + break; + } +} + +void XMLTemplateNameImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= nFormat; + xPropertySet->setPropertyValue(sPropertyFileFormat, aAny); +} + + +// +// import chapter fields +// + +TYPEINIT1( XMLChapterImportContext, XMLTextFieldImportContext ); + +static const SvXMLEnumMapEntry aChapterDisplayMap[] = +{ + { XML_NAME, ChapterFormat::NAME }, + { XML_NUMBER, ChapterFormat::NUMBER }, + { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER }, + { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX }, + { XML_PLAIN_NUMBER, ChapterFormat::DIGIT }, + { XML_TOKEN_INVALID, 0 } +}; + +XMLChapterImportContext::XMLChapterImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_chapter, + nPrfx, sLocalName), + sPropertyChapterFormat( + RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_format)), + sPropertyLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_level)), + nFormat(ChapterFormat::NAME_NUMBER), + nLevel(0) +{ + bValid = sal_True; +} + +void XMLChapterImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DISPLAY: + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, + aChapterDisplayMap)) + { + nFormat = (sal_Int16)nTmp; + } + break; + } + case XML_TOK_TEXTFIELD_OUTLINE_LEVEL: + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( + nTmp, sAttrValue, 1, + GetImport().GetTextImport()->GetChapterNumbering()->getCount() + )) + { + // API numbers 0..9, we number 1..10 + nLevel = (sal_Int8)nTmp; + nLevel--; + } + break; + } + default: + ; // unknown attribute: ignore + break; + } +} + +void XMLChapterImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= nFormat; + xPropertySet->setPropertyValue(sPropertyChapterFormat, aAny); + + aAny <<= nLevel; + xPropertySet->setPropertyValue(sPropertyLevel, aAny); +} + + +// +// counting fields +// + +TYPEINIT1( XMLCountFieldImportContext, XMLTextFieldImportContext ); + +XMLCountFieldImportContext::XMLCountFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) : + XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken), + nPrfx, sLocalName), + sPropertyNumberingType( + RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)), + sNumberFormat(), + sLetterSync(), + bNumberFormatOK(sal_False) +{ + bValid = sal_True; +} + +void XMLCountFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NUM_FORMAT: + sNumberFormat = sAttrValue; + bNumberFormatOK = sal_True; + break; + case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC: + sLetterSync = sAttrValue; + break; + } +} + +void XMLCountFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + // properties optional + // (only page count, but do for all to save common implementation) + + if (xPropertySet->getPropertySetInfo()-> + hasPropertyByName(sPropertyNumberingType)) + { + sal_Int16 nNumType; + if( bNumberFormatOK ) + { + nNumType= style::NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumberFormat, + sLetterSync ); + } + else + nNumType = style::NumberingType::PAGE_DESCRIPTOR; + aAny <<= nNumType; + xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); + } +} + +const sal_Char* XMLCountFieldImportContext::MapTokenToServiceName( + sal_uInt16 nToken) +{ + const sal_Char* pServiceName = NULL; + + switch (nToken) + { + case XML_TOK_TEXT_WORD_COUNT: + pServiceName = sAPI_word_count; + break; + case XML_TOK_TEXT_PARAGRAPH_COUNT: + pServiceName = sAPI_paragraph_count; + break; + case XML_TOK_TEXT_TABLE_COUNT: + pServiceName = sAPI_table_count; + break; + case XML_TOK_TEXT_CHARACTER_COUNT: + pServiceName = sAPI_character_count; + break; + case XML_TOK_TEXT_IMAGE_COUNT: + pServiceName = sAPI_graphic_object_count; + break; + case XML_TOK_TEXT_OBJECT_COUNT: + pServiceName = sAPI_embedded_object_count; + break; + case XML_TOK_TEXT_PAGE_COUNT: + pServiceName = sAPI_page_count; + break; + default: + pServiceName = NULL; + DBG_ERROR("unknown count field!"); + break; + } + + return pServiceName; +} + + + +// +// page variable import +// + +TYPEINIT1( XMLPageVarGetFieldImportContext, XMLTextFieldImportContext ); + +XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_get, + nPrfx, sLocalName), + sPropertyNumberingType( + RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)), + sNumberFormat(), + sLetterSync(), + bNumberFormatOK(sal_False) +{ + bValid = sal_True; +} + +void XMLPageVarGetFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NUM_FORMAT: + sNumberFormat = sAttrValue; + bNumberFormatOK = sal_True; + break; + case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC: + sLetterSync = sAttrValue; + break; + } +} + +void XMLPageVarGetFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + sal_Int16 nNumType; + if( bNumberFormatOK ) + { + nNumType= style::NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, + sNumberFormat, + sLetterSync ); + } + else + nNumType = style::NumberingType::PAGE_DESCRIPTOR; + aAny <<= nNumType; + xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); + + // display old content (#96657#) + aAny <<= GetContent(); + xPropertySet->setPropertyValue( + OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)), + aAny ); +} + + + +// +// page variable set fields +// + +TYPEINIT1(XMLPageVarSetFieldImportContext, XMLTextFieldImportContext); + +XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_set, + nPrfx, sLocalName), + sPropertyOn(RTL_CONSTASCII_USTRINGPARAM(sAPI_on)), + sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM(sAPI_offset)), + nAdjust(0), + bActive(sal_True) +{ + bValid = sal_True; +} + +void XMLPageVarSetFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_ACTIVE: + { + sal_Bool bTmp; + if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue)) + { + bActive = bTmp; + } + } + case XML_TOK_TEXTFIELD_PAGE_ADJUST: + { + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue)) + { + nAdjust = (sal_Int16)nTmp; + } + } + } +} + +void XMLPageVarSetFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny.setValue(&bActive, ::getBooleanCppuType()); + xPropertySet->setPropertyValue(sPropertyOn, aAny); + + aAny <<= nAdjust; + xPropertySet->setPropertyValue(sPropertyOffset, aAny); +} + + + +// +// macro fields +// + +TYPEINIT1( XMLMacroFieldImportContext, XMLTextFieldImportContext ); + +XMLMacroFieldImportContext::XMLMacroFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_macro, + nPrfx, sLocalName), + sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)), + sPropertyMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")), + sPropertyScriptURL(RTL_CONSTASCII_USTRINGPARAM("ScriptURL")), + bDescriptionOK(sal_False) +{ +} + +SvXMLImportContext* XMLMacroFieldImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if ( (nPrefix == XML_NAMESPACE_OFFICE) && + IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + { + // create events context and remember it! + pContext = new XMLEventsImportContext( + GetImport(), nPrefix, rLocalName ); + xEventContext = pContext; + bValid = sal_True; + } + else + pContext = SvXMLImportContext::CreateChildContext( + nPrefix, rLocalName, xAttrList); + + return pContext; +} + + +void XMLMacroFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_DESCRIPTION: + sDescription = sAttrValue; + bDescriptionOK = sal_True; + break; + case XML_TOK_TEXTFIELD_NAME: + sMacro = sAttrValue; + bValid = sal_True; + break; + } +} + +void XMLMacroFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + OUString sOnClick(RTL_CONSTASCII_USTRINGPARAM("OnClick")); + OUString sPropertyMacroLibrary(RTL_CONSTASCII_USTRINGPARAM("MacroLibrary")); + + aAny <<= (bDescriptionOK ? sDescription : GetContent()); + xPropertySet->setPropertyValue(sPropertyHint, aAny); + + // if we have an events child element, we'll look for the OnClick + // event if not, it may be an old (pre-638i) document. Then, we'll + // have to look at the name attribute. + OUString sMacroName; + OUString sLibraryName; + OUString sScriptURL; + + if ( xEventContext.Is() ) + { + // get event sequence + XMLEventsImportContext* pEvents = + (XMLEventsImportContext*)&xEventContext; + Sequence<PropertyValue> aValues; + pEvents->GetEventSequence( sOnClick, aValues ); + + sal_Int32 nLength = aValues.getLength(); + for( sal_Int32 i = 0; i < nLength; i++ ) + { + if ( aValues[i].Name.equalsAsciiL( "ScriptType", + sizeof("ScriptType")-1 ) ) + { + // ignore ScriptType + } + else if ( aValues[i].Name.equalsAsciiL( "Library", + sizeof("Library")-1 ) ) + { + aValues[i].Value >>= sLibraryName; + } + else if ( aValues[i].Name.equalsAsciiL( "MacroName", + sizeof("MacroName")-1 ) ) + { + aValues[i].Value >>= sMacroName; + } + if ( aValues[i].Name.equalsAsciiL( "Script", + sizeof("Script")-1 ) ) + { + aValues[i].Value >>= sScriptURL; + } + } + } + else + { + // disassemble old-style macro-name: Everything before the + // third-last dot is the library + sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos-- + const sal_Unicode* pBuf = sMacro.getStr(); + for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ ) + { + nPos--; + while ( (pBuf[nPos] != '.') && (nPos > 0) ) + nPos--; + } + + if (nPos > 0) + { + sLibraryName = sMacro.copy(0, nPos); + sMacroName = sMacro.copy(nPos+1); + } + else + sMacroName = sMacro; + } + + aAny <<= sScriptURL; + xPropertySet->setPropertyValue(sPropertyScriptURL, aAny); + + aAny <<= sMacroName; + xPropertySet->setPropertyValue(sPropertyMacroName, aAny); + + aAny <<= sLibraryName; + xPropertySet->setPropertyValue(sPropertyMacroLibrary, aAny); +} + + + +// +// reference field import +// + +TYPEINIT1( XMLReferenceFieldImportContext, XMLTextFieldImportContext ); + +XMLReferenceFieldImportContext::XMLReferenceFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nToken, sal_uInt16 nPrfx, const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_get_reference, nPrfx, sLocalName) +, sPropertyReferenceFieldPart(RTL_CONSTASCII_USTRINGPARAM(sAPI_reference_field_part)) +, sPropertyReferenceFieldSource(RTL_CONSTASCII_USTRINGPARAM(sAPI_reference_field_source)) +, sPropertySourceName(RTL_CONSTASCII_USTRINGPARAM(sAPI_source_name)) +, sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)) +, nElementToken(nToken) +, nType(ReferenceFieldPart::PAGE_DESC) +, bNameOK(sal_False) +, bTypeOK(sal_False) +, bSeqNumberOK(sal_False) +{ +} + +static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] = +{ + { XML_PAGE, ReferenceFieldPart::PAGE}, + { XML_CHAPTER, ReferenceFieldPart::CHAPTER }, + { XML_TEXT, ReferenceFieldPart::TEXT }, + { XML_DIRECTION, ReferenceFieldPart::UP_DOWN }, + { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER }, + { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION }, + { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER }, + // --> OD 2007-09-14 #i81002# + { XML_NUMBER, ReferenceFieldPart::NUMBER }, + { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT }, + { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT }, + // <-- + { XML_TOKEN_INVALID, 0 } +}; + +void XMLReferenceFieldImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + bTypeOK = sal_True; + switch (nElementToken) + { + case XML_TOK_TEXT_REFERENCE_REF: + nSource = ReferenceFieldSource::REFERENCE_MARK; + break; + case XML_TOK_TEXT_BOOKMARK_REF: + nSource = ReferenceFieldSource::BOOKMARK; + break; + case XML_TOK_TEXT_NOTE_REF: + nSource = ReferenceFieldSource::FOOTNOTE; + break; + case XML_TOK_TEXT_SEQUENCE_REF: + nSource = ReferenceFieldSource::SEQUENCE_FIELD; + break; + default: + bTypeOK = sal_False; + DBG_ERROR("unknown reference field"); + break; + } + + XMLTextFieldImportContext::StartElement(xAttrList); +} + + +void XMLReferenceFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NOTE_CLASS: + if( IsXMLToken( sAttrValue, XML_ENDNOTE ) ) + nSource = ReferenceFieldSource::ENDNOTE; + break; + case XML_TOK_TEXTFIELD_REF_NAME: + sName = sAttrValue; + bNameOK = sal_True; + break; + case XML_TOK_TEXTFIELD_REFERENCE_FORMAT: + { + sal_uInt16 nToken; + if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue, + lcl_aReferenceTypeTokenMap)) + { + nType = nToken; + } + + // check for sequence-only-attributes + if ( (XML_TOK_TEXT_SEQUENCE_REF != nElementToken) && + ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) || + (nType == ReferenceFieldPart::ONLY_CAPTION) || + (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) ) + { + nType = ReferenceFieldPart::PAGE_DESC; + } + + break; + } + } + + // bValid: we need proper element type and name + bValid = bTypeOK && bNameOK; +} + +void XMLReferenceFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= nType; + xPropertySet->setPropertyValue(sPropertyReferenceFieldPart, aAny); + + aAny <<= nSource; + xPropertySet->setPropertyValue(sPropertyReferenceFieldSource, aAny); + + switch (nElementToken) + { + case XML_TOK_TEXT_REFERENCE_REF: + case XML_TOK_TEXT_BOOKMARK_REF: + aAny <<= sName; + xPropertySet->setPropertyValue(sPropertySourceName, aAny); + break; + + case XML_TOK_TEXT_NOTE_REF: + GetImportHelper().ProcessFootnoteReference(sName, xPropertySet); + break; + + case XML_TOK_TEXT_SEQUENCE_REF: + GetImportHelper().ProcessSequenceReference(sName, xPropertySet); + break; + } + + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); +} + + + +// +// field declarations container +// + +enum DdeFieldDeclAttrs +{ + XML_TOK_DDEFIELD_NAME, + XML_TOK_DDEFIELD_APPLICATION, + XML_TOK_DDEFIELD_TOPIC, + XML_TOK_DDEFIELD_ITEM, + XML_TOK_DDEFIELD_UPDATE +}; + +static __FAR_DATA SvXMLTokenMapEntry aDdeDeclAttrTokenMap[] = +{ + { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_DDEFIELD_NAME }, + { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, XML_TOK_DDEFIELD_APPLICATION }, + { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_DDEFIELD_TOPIC }, + { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_DDEFIELD_ITEM }, + { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TOK_DDEFIELD_UPDATE }, + XML_TOKEN_MAP_END +}; + +TYPEINIT1( XMLDdeFieldDeclsImportContext, SvXMLImportContext ); + +XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& sLocalName) : + SvXMLImportContext(rImport, nPrfx, sLocalName), + aTokenMap(aDdeDeclAttrTokenMap) +{ +} + +SvXMLImportContext * XMLDdeFieldDeclsImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_TEXT == nPrefix) && + (IsXMLToken(rLocalName, XML_DDE_CONNECTION_DECL)) ) + { + return new XMLDdeFieldDeclImportContext(GetImport(), nPrefix, + rLocalName, aTokenMap); + } + else + { + return SvXMLImportContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } +} + + + +// +// import dde field declaration +// + +TYPEINIT1( XMLDdeFieldDeclImportContext, SvXMLImportContext ); + +XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& sLocalName, const SvXMLTokenMap& rMap) +: SvXMLImportContext(rImport, nPrfx, sLocalName) +, sPropertyIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_automatic_update)) +, sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)) +, sPropertyDDECommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_type)) +, sPropertyDDECommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_file)) +, sPropertyDDECommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_element)) +, rTokenMap(rMap) +{ + DBG_ASSERT(XML_NAMESPACE_TEXT == nPrfx, "wrong prefix"); + DBG_ASSERT(IsXMLToken(sLocalName, XML_DDE_CONNECTION_DECL), "wrong name"); +} + +void XMLDdeFieldDeclImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + OUString sName; + OUString sCommandApplication; + OUString sCommandTopic; + OUString sCommandItem; + + sal_Bool bUpdate = sal_False; + sal_Bool bNameOK = sal_False; + sal_Bool bCommandApplicationOK = sal_False; + sal_Bool bCommandTopicOK = sal_False; + sal_Bool bCommandItemOK = sal_False; + + // process attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) + { + + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + switch (rTokenMap.Get(nPrefix, sLocalName)) + { + case XML_TOK_DDEFIELD_NAME: + sName = xAttrList->getValueByIndex(i); + bNameOK = sal_True; + break; + case XML_TOK_DDEFIELD_APPLICATION: + sCommandApplication = xAttrList->getValueByIndex(i); + bCommandApplicationOK = sal_True; + break; + case XML_TOK_DDEFIELD_TOPIC: + sCommandTopic = xAttrList->getValueByIndex(i); + bCommandTopicOK = sal_True; + break; + case XML_TOK_DDEFIELD_ITEM: + sCommandItem = xAttrList->getValueByIndex(i); + bCommandItemOK = sal_True; + break; + case XML_TOK_DDEFIELD_UPDATE: + { + sal_Bool bTmp; + if ( SvXMLUnitConverter::convertBool( + bTmp, xAttrList->getValueByIndex(i)) ) + { + bUpdate = bTmp; + } + break; + } + } + } + + // valid data? + if (bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK) + { + // make service name + OUStringBuffer sBuf; + sBuf.appendAscii(sAPI_fieldmaster_prefix); + sBuf.appendAscii(sAPI_dde); + + // create DDE TextFieldMaster + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(), + UNO_QUERY); + if( xFactory.is() ) + { + /* #i6432# There might be multiple occurances of one DDE + declaration if it is used in more than one of + header/footer/body. createInstance will throw an exception if we + try to create the second, third, etc. instance of such a + declaration. Thus we ignore the exception. Otherwise this will + lead to an unloadable document. */ + try + { + Reference<XInterface> xIfc = + xFactory->createInstance(sBuf.makeStringAndClear()); + if( xIfc.is() ) + { + Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY ); + if (xPropSet.is() && + xPropSet->getPropertySetInfo()->hasPropertyByName( + sPropertyDDECommandType)) + { + Any aAny; + + aAny <<= sName; + xPropSet->setPropertyValue(sPropertyName, aAny); + + aAny <<= sCommandApplication; + xPropSet->setPropertyValue(sPropertyDDECommandType, aAny); + + aAny <<= sCommandTopic; + xPropSet->setPropertyValue(sPropertyDDECommandFile, aAny); + + aAny <<= sCommandItem; + xPropSet->setPropertyValue(sPropertyDDECommandElement, + aAny); + + aAny.setValue(&bUpdate, ::getBooleanCppuType()); + xPropSet->setPropertyValue(sPropertyIsAutomaticUpdate, + aAny); + } + // else: ignore (can't get XPropertySet, or DDE + // properties are not supported) + } + // else: ignore + } + catch ( const Exception& ) + { + //ignore + } + } + // else: ignore + } + // else: ignore +} + + + +// +// DDE field import +// + +TYPEINIT1( XMLDdeFieldImportContext, XMLTextFieldImportContext ); + +XMLDdeFieldImportContext::XMLDdeFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_dde, + nPrfx, sLocalName), + sName() + ,sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +{ +} + +void XMLDdeFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + if (XML_TOK_TEXTFIELD_CONNECTION_NAME == nAttrToken) + { + sName = sAttrValue; + bValid = sal_True; + } +} + +void XMLDdeFieldImportContext::EndElement() +{ + if (bValid) + { + // find master + OUStringBuffer sBuf; + sBuf.appendAscii(sAPI_fieldmaster_prefix); + sBuf.appendAscii(sAPI_dde); + sBuf.append(sal_Unicode('.')); + sBuf.append(sName); + OUString sMasterName = sBuf.makeStringAndClear(); + + Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(), + UNO_QUERY); + Reference<container::XNameAccess> xFieldMasterNameAccess( + xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY); + + if (xFieldMasterNameAccess->hasByName(sMasterName)) + { + Reference<XPropertySet> xMaster; + Any aAny = xFieldMasterNameAccess->getByName(sMasterName); + aAny >>= xMaster; + //apply the content to the master + xMaster->setPropertyValue( sPropertyContent, uno::makeAny( GetContent())); + // master exists: create text field and attach + Reference<XPropertySet> xField; + sBuf.appendAscii(sAPI_textfield_prefix); + sBuf.appendAscii(sAPI_dde); + if (CreateField(xField, sBuf.makeStringAndClear())) + { + Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY); + xDepTextField->attachTextFieldMaster(xMaster); + + // attach field to document + Reference<XTextContent> xTextContent(xField, UNO_QUERY); + if (xTextContent.is()) + { + GetImportHelper().InsertTextContent(xTextContent); + + // we're lucky. nothing else to prepare. + } + // else: fail, because text content could not be created + } + // else: fail, because field could not be created + } + // else: fail, because no master was found (faulty document?!) + } + // not valid: ignore +} + +void XMLDdeFieldImportContext::PrepareField( + const Reference<XPropertySet> &) +{ + // empty, since not needed. +} + + +// +// sheet name fields +// + +TYPEINIT1(XMLSheetNameImportContext, XMLTextFieldImportContext); + +XMLSheetNameImportContext::XMLSheetNameImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_sheet_name, + nPrfx, sLocalName) +{ + bValid = sal_True; // always valid! +} + +void XMLSheetNameImportContext::ProcessAttribute( + sal_uInt16, + const ::rtl::OUString& ) +{ + // no attributes -> nothing to be done +} + +void XMLSheetNameImportContext::PrepareField( + const Reference<XPropertySet> &) +{ + // no attributes -> nothing to be done +} + + +// +// URL fields (Calc, Impress, Draw) +// + +TYPEINIT1(XMLUrlFieldImportContext, XMLTextFieldImportContext); + +XMLUrlFieldImportContext::XMLUrlFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_url, + nPrfx, sLocalName), + sPropertyURL(RTL_CONSTASCII_USTRINGPARAM(sAPI_url)), + sPropertyTargetFrame(RTL_CONSTASCII_USTRINGPARAM(sAPI_target_frame)), + sPropertyRepresentation(RTL_CONSTASCII_USTRINGPARAM( + sAPI_representation)), + bFrameOK(sal_False) +{ +} + +void XMLUrlFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_HREF: + sURL = GetImport().GetAbsoluteReference( sAttrValue ); + bValid = sal_True; + break; + case XML_TOK_TEXTFIELD_TARGET_FRAME: + sFrame = sAttrValue; + bFrameOK = sal_True; + break; + default: + // ignore + break; + } +} + +void XMLUrlFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + aAny <<= sURL; + xPropertySet->setPropertyValue(sPropertyURL, aAny); + + if (bFrameOK) + { + aAny <<= sFrame; + xPropertySet->setPropertyValue(sPropertyTargetFrame, aAny); + } + + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyRepresentation, aAny); +} + + +TYPEINIT1(XMLBibliographyFieldImportContext, XMLTextFieldImportContext); + + +XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_bibliography, + nPrfx, sLocalName), + sPropertyFields(RTL_CONSTASCII_USTRINGPARAM("Fields")), + aValues() +{ + bValid = sal_True; +} + +// TODO: this is the same map as is used in the text field export +SvXMLEnumMapEntry __READONLY_DATA aBibliographyDataTypeMap[] = +{ + { XML_ARTICLE, BibliographyDataType::ARTICLE }, + { XML_BOOK, BibliographyDataType::BOOK }, + { XML_BOOKLET, BibliographyDataType::BOOKLET }, + { XML_CONFERENCE, BibliographyDataType::CONFERENCE }, + { XML_CUSTOM1, BibliographyDataType::CUSTOM1 }, + { XML_CUSTOM2, BibliographyDataType::CUSTOM2 }, + { XML_CUSTOM3, BibliographyDataType::CUSTOM3 }, + { XML_CUSTOM4, BibliographyDataType::CUSTOM4 }, + { XML_CUSTOM5, BibliographyDataType::CUSTOM5 }, + { XML_EMAIL, BibliographyDataType::EMAIL }, + { XML_INBOOK, BibliographyDataType::INBOOK }, + { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION }, + { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS }, + { XML_JOURNAL, BibliographyDataType::JOURNAL }, + { XML_MANUAL, BibliographyDataType::MANUAL }, + { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS }, + { XML_MISC, BibliographyDataType::MISC }, + { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS }, + { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS }, + { XML_TECHREPORT, BibliographyDataType::TECHREPORT }, + { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED }, + { XML_WWW, BibliographyDataType::WWW }, + { XML_TOKEN_INVALID, 0 } +}; + + +// we'll process attributes on our own and forfit the standard +// tecfield mechanism, because our attributes have zero overlp with +// all the oher textfields. +void XMLBibliographyFieldImportContext::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // iterate over attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) { + + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + if (nPrefix == XML_NAMESPACE_TEXT) + { + PropertyValue aValue; + aValue.Name = OUString::createFromAscii( + MapBibliographyFieldName(sLocalName)); + Any aAny; + + // special treatment for bibliography type + // biblio vs bibilio: #96658#; also read old documents + if (IsXMLToken(sLocalName, XML_BIBILIOGRAPHIC_TYPE) || + IsXMLToken(sLocalName, XML_BIBLIOGRAPHY_TYPE) ) + { + sal_uInt16 nTmp; + if (SvXMLUnitConverter::convertEnum( + nTmp, xAttrList->getValueByIndex(i), + aBibliographyDataTypeMap)) + { + aAny <<= (sal_Int16)nTmp; + aValue.Value = aAny; + + aValues.push_back(aValue); + } + } + else + { + aAny <<= xAttrList->getValueByIndex(i); + aValue.Value = aAny; + + aValues.push_back(aValue); + } + } + // else: unknown namespace -> ignore + } +} + +void XMLBibliographyFieldImportContext::ProcessAttribute( + sal_uInt16, + const OUString& ) +{ + // attributes are handled in StartElement + DBG_ERROR("This should not have happened."); +} + + +void XMLBibliographyFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // convert vector into sequence + sal_Int32 nCount = aValues.size(); + Sequence<PropertyValue> aValueSequence(nCount); + for(sal_Int32 i = 0; i < nCount; i++) + { + aValueSequence[i] = aValues[i]; + } + + // set sequence + Any aAny; + aAny <<= aValueSequence; + xPropertySet->setPropertyValue(sPropertyFields, aAny); +} + +const sal_Char* XMLBibliographyFieldImportContext::MapBibliographyFieldName( + OUString sName) +{ + const sal_Char* pName = NULL; + + if (IsXMLToken(sName, XML_IDENTIFIER)) + { + pName = "Identifier"; + } + else if (IsXMLToken(sName, XML_BIBILIOGRAPHIC_TYPE) || + IsXMLToken(sName, XML_BIBLIOGRAPHY_TYPE) ) + { + // biblio... vs bibilio...: #96658#: also read old documents + pName = "BibiliographicType"; + } + else if (IsXMLToken(sName, XML_ADDRESS)) + { + pName = "Address"; + } + else if (IsXMLToken(sName, XML_ANNOTE)) + { + pName = "Annote"; + } + else if (IsXMLToken(sName, XML_AUTHOR)) + { + pName = "Author"; + } + else if (IsXMLToken(sName, XML_BOOKTITLE)) + { + pName = "Booktitle"; + } + else if (IsXMLToken(sName, XML_CHAPTER)) + { + pName = "Chapter"; + } + else if (IsXMLToken(sName, XML_EDITION)) + { + pName = "Edition"; + } + else if (IsXMLToken(sName, XML_EDITOR)) + { + pName = "Editor"; + } + else if (IsXMLToken(sName, XML_HOWPUBLISHED)) + { + pName = "Howpublished"; + } + else if (IsXMLToken(sName, XML_INSTITUTION)) + { + pName = "Institution"; + } + else if (IsXMLToken(sName, XML_JOURNAL)) + { + pName = "Journal"; + } + else if (IsXMLToken(sName, XML_MONTH)) + { + pName = "Month"; + } + else if (IsXMLToken(sName, XML_NOTE)) + { + pName = "Note"; + } + else if (IsXMLToken(sName, XML_NUMBER)) + { + pName = "Number"; + } + else if (IsXMLToken(sName, XML_ORGANIZATIONS)) + { + pName = "Organizations"; + } + else if (IsXMLToken(sName, XML_PAGES)) + { + pName = "Pages"; + } + else if (IsXMLToken(sName, XML_PUBLISHER)) + { + pName = "Publisher"; + } + else if (IsXMLToken(sName, XML_SCHOOL)) + { + pName = "School"; + } + else if (IsXMLToken(sName, XML_SERIES)) + { + pName = "Series"; + } + else if (IsXMLToken(sName, XML_TITLE)) + { + pName = "Title"; + } + else if (IsXMLToken(sName, XML_REPORT_TYPE)) + { + pName = "Report_Type"; + } + else if (IsXMLToken(sName, XML_VOLUME)) + { + pName = "Volume"; + } + else if (IsXMLToken(sName, XML_YEAR)) + { + pName = "Year"; + } + else if (IsXMLToken(sName, XML_URL)) + { + pName = "URL"; + } + else if (IsXMLToken(sName, XML_CUSTOM1)) + { + pName = "Custom1"; + } + else if (IsXMLToken(sName, XML_CUSTOM2)) + { + pName = "Custom2"; + } + else if (IsXMLToken(sName, XML_CUSTOM3)) + { + pName = "Custom3"; + } + else if (IsXMLToken(sName, XML_CUSTOM4)) + { + pName = "Custom4"; + } + else if (IsXMLToken(sName, XML_CUSTOM5)) + { + pName = "Custom5"; + } + else if (IsXMLToken(sName, XML_ISBN)) + { + pName = "ISBN"; + } + else + { + DBG_ERROR("Unknown bibliography info data"); + pName = NULL; + } + + return pName; +} + + +// +// Annotation Field +// + +TYPEINIT1(XMLAnnotationImportContext, XMLTextFieldImportContext); + +XMLAnnotationImportContext::XMLAnnotationImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_annotation, + nPrfx, sLocalName), + sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author)), + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)), + // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE? + sPropertyDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time_value)), + sPropertyTextRange(RTL_CONSTASCII_USTRINGPARAM(sAPI_TextRange)) +{ + bValid = sal_True; + + // remember old list item and block (#91964#) and reset them + // for the text frame + // do this in the constructor, not in CreateChildContext (#i93392#) + GetImport().GetTextImport()->PushListContext(); +} + +void XMLAnnotationImportContext::ProcessAttribute( + sal_uInt16, + const OUString& ) +{ + // ignore +} + +SvXMLImportContext* XMLAnnotationImportContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = 0; + if( XML_NAMESPACE_DC == nPrefix ) + { + if( IsXMLToken( rLocalName, XML_CREATOR ) ) + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, aAuthorBuffer); + else if( IsXMLToken( rLocalName, XML_DATE ) ) + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, + rLocalName, aDateBuffer); + } + + if( !pContext ) + { + try + { + if ( !mxField.is() ) + CreateField( mxField, sServicePrefix + GetServiceName() ); + Any aAny = mxField->getPropertyValue( sPropertyTextRange ); + Reference< XText > xText; + aAny >>= xText; + if( xText.is() ) + { + UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); + if( !mxCursor.is() ) + { + mxOldCursor = xTxtImport->GetCursor(); + mxCursor = xText->createTextCursor(); + } + + if( mxCursor.is() ) + { + xTxtImport->SetCursor( mxCursor ); + pContext = xTxtImport->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList ); + } + } + } + catch ( Exception& ) + {} + + if( !pContext ) + pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, aTextBuffer); + } + + return pContext; +} + +void XMLAnnotationImportContext::EndElement() +{ + DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!"); + if( mxCursor.is() ) + { + // delete addition newline + const OUString aEmpty; + mxCursor->gotoEnd( sal_False ); + mxCursor->goLeft( 1, sal_True ); + mxCursor->setString( aEmpty ); + + // reset cursor + GetImport().GetTextImport()->ResetCursor(); + } + + if( mxOldCursor.is() ) + GetImport().GetTextImport()->SetCursor( mxOldCursor ); + + // reinstall old list item #91964# + GetImport().GetTextImport()->PopListContext(); + + if ( bValid ) + { + if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) ) + { + // set field properties + PrepareField( mxField ); + + // attach field to document + Reference < XTextContent > xTextContent( mxField, UNO_QUERY ); + + // workaround for #80606# + try + { + GetImportHelper().InsertTextContent( xTextContent ); + } + catch (lang::IllegalArgumentException) + { + // ignore + } + } + } + else + GetImportHelper().InsertString(GetContent()); +} + +void XMLAnnotationImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // import (possibly empty) author + OUString sAuthor( aAuthorBuffer.makeStringAndClear() ); + xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor)); + + DateTime aDateTime; + if (SvXMLUnitConverter::convertDateTime(aDateTime, + aDateBuffer.makeStringAndClear())) + { + /* + Date aDate; + aDate.Year = aDateTime.Year; + aDate.Month = aDateTime.Month; + aDate.Day = aDateTime.Day; + xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate)); + */ + xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDateTime)); + } + + OUString sBuffer = aTextBuffer.makeStringAndClear(); + if ( sBuffer.getLength() ) + { + // delete last paragraph mark (if necessary) + if (sal_Char(0x0a) == sBuffer.getStr()[sBuffer.getLength()-1]) + sBuffer = sBuffer.copy(0, sBuffer.getLength()-1); + xPropertySet->setPropertyValue(sPropertyContent, makeAny(sBuffer)); + } +} + + + +// +// script field +// + +TYPEINIT1(XMLScriptImportContext, XMLTextFieldImportContext); + +XMLScriptImportContext::XMLScriptImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) +: XMLTextFieldImportContext(rImport, rHlp, sAPI_script, nPrfx, sLocalName) +, sPropertyScriptType(RTL_CONSTASCII_USTRINGPARAM(sAPI_script_type)) +, sPropertyURLContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_url_content)) +, sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +, bContentOK(sal_False) +, bScriptTypeOK(sal_False) +, bUrlContent(sal_False) +{ +} + +void XMLScriptImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_HREF: + sContent = GetImport().GetAbsoluteReference( sAttrValue ); + bContentOK = sal_True; + break; + + case XML_TOK_TEXTFIELD_LANGUAGE: + sScriptType = sAttrValue; + bScriptTypeOK = sal_True; + break; + + default: + // ignore + break; + } + + // always valid (even without ScriptType; cf- #96531#) + bValid = sal_True; +} + +void XMLScriptImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + // if href attribute was present, we use it. Else we use element content + if (! bContentOK) + { + sContent = GetContent(); + } + aAny <<= sContent; + xPropertySet->setPropertyValue(sPropertyContent, aAny); + + // URL or script text? We use URL if we have an href-attribute + aAny.setValue(&bContentOK, ::getBooleanCppuType()); + xPropertySet->setPropertyValue(sPropertyURLContent, aAny); + + aAny <<= sScriptType; + xPropertySet->setPropertyValue(sPropertyScriptType, aAny); +} + +// +// measure field +// + +TYPEINIT1(XMLMeasureFieldImportContext, XMLTextFieldImportContext); + +XMLMeasureFieldImportContext::XMLMeasureFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& sLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_measure, + nPrfx, sLocalName), + mnKind( 0 ) +{ +} + +void XMLMeasureFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_MEASURE_KIND: + if( IsXMLToken( sAttrValue, XML_VALUE ) ) + { + mnKind = 0; bValid = sal_True; + } + else if( IsXMLToken( sAttrValue, XML_UNIT ) ) + { + mnKind = 1; bValid = sal_True; + } + else if( IsXMLToken( sAttrValue, XML_GAP ) ) + { + mnKind = 2; bValid = sal_True; + } + break; + } +} + +void XMLMeasureFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + aAny <<= mnKind; + xPropertySet->setPropertyValue(OUString::createFromAscii("Kind"), aAny); +} + + + +// +// dropdown field +// + + +TYPEINIT1( XMLDropDownFieldImportContext, XMLTextFieldImportContext ); + +XMLDropDownFieldImportContext::XMLDropDownFieldImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const ::rtl::OUString& sLocalName) : + XMLTextFieldImportContext( rImport, rHlp, sAPI_drop_down, + nPrfx, sLocalName ), + aLabels(), + sName(), + nSelected( -1 ), + bNameOK( false ), + bHelpOK(false), + bHintOK(false), + sPropertyItems( RTL_CONSTASCII_USTRINGPARAM( "Items" ) ), + sPropertySelectedItem( RTL_CONSTASCII_USTRINGPARAM( "SelectedItem" ) ), + sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), + sPropertyHelp( RTL_CONSTASCII_USTRINGPARAM( "Help" ) ), + sPropertyToolTip( RTL_CONSTASCII_USTRINGPARAM( "Tooltip" ) ) +{ + bValid = sal_True; +} + +bool lcl_ProcessLabel( const SvXMLImport& rImport, + const Reference<XAttributeList>& xAttrList, + OUString& rLabel, + bool& rIsSelected ) +{ + bool bValid = false; + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 n = 0; n < nLength; n++ ) + { + OUString sLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName ); + OUString sValue = xAttrList->getValueByIndex(n); + + if( nPrefix == XML_NAMESPACE_TEXT ) + { + if( IsXMLToken( sLocalName, XML_VALUE ) ) + { + rLabel = sValue; + bValid = true; + } + else if( IsXMLToken( sLocalName, XML_CURRENT_SELECTED ) ) + { + sal_Bool bTmp; + if( SvXMLUnitConverter::convertBool( bTmp, sValue ) ) + rIsSelected = bTmp; + } + } + } + return bValid; +} + +SvXMLImportContext* XMLDropDownFieldImportContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& xAttrList ) +{ + if( nPrefix == XML_NAMESPACE_TEXT && + IsXMLToken( rLocalName, XML_LABEL ) ) + { + OUString sLabel; + bool bIsSelected = sal_False; + if( lcl_ProcessLabel( GetImport(), xAttrList, sLabel, bIsSelected ) ) + { + if( bIsSelected ) + nSelected = static_cast<sal_Int32>( aLabels.size() ); + aLabels.push_back( sLabel ); + } + } + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); +} + +void XMLDropDownFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const ::rtl::OUString& sAttrValue ) +{ + if( nAttrToken == XML_TOK_TEXTFIELD_NAME ) + { + sName = sAttrValue; + bNameOK = true; + } + else if (nAttrToken == XML_TOK_TEXTFIELD_HELP) + { + sHelp = sAttrValue; + bHelpOK = true; + } + else if (nAttrToken == XML_TOK_TEXTFIELD_HINT) + { + sHint = sAttrValue; + bHintOK = true; + } +} + +void XMLDropDownFieldImportContext::PrepareField( + const Reference<XPropertySet>& xPropertySet) +{ + // create sequence + sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() ); + Sequence<OUString> aSequence( nLength ); + OUString* pSequence = aSequence.getArray(); + for( sal_Int32 n = 0; n < nLength; n++ ) + pSequence[n] = aLabels[n]; + + // now set values: + Any aAny; + + aAny <<= aSequence; + xPropertySet->setPropertyValue( sPropertyItems, aAny ); + + if( nSelected >= 0 && nSelected < nLength ) + { + aAny <<= pSequence[nSelected]; + xPropertySet->setPropertyValue( sPropertySelectedItem, aAny ); + } + + // set name + if( bNameOK ) + { + aAny <<= sName; + xPropertySet->setPropertyValue( sPropertyName, aAny ); + } + // set help + if( bHelpOK ) + { + aAny <<= sHelp; + xPropertySet->setPropertyValue( sPropertyHelp, aAny ); + } + // set hint + if( bHintOK ) + { + aAny <<= sHint; + xPropertySet->setPropertyValue( sPropertyToolTip, aAny ); + } + +} + +/** import header fields (<draw:header>) */ +TYPEINIT1( XMLHeaderFieldImportContext, XMLTextFieldImportContext ); + +XMLHeaderFieldImportContext::XMLHeaderFieldImportContext( + SvXMLImport& rImport, /// XML Import + XMLTextImportHelper& rHlp, /// Text import helper + sal_uInt16 nPrfx, /// namespace prefix + const ::rtl::OUString& sLocalName) /// element name w/o prefix +: XMLTextFieldImportContext(rImport, rHlp, sAPI_header, nPrfx, sLocalName ) +{ + sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix ); + bValid = sal_True; +} + +/// process attribute values +void XMLHeaderFieldImportContext::ProcessAttribute( sal_uInt16, const ::rtl::OUString& ) +{ +} + +/// prepare XTextField for insertion into document +void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &) +{ +} + +/** import footer fields (<draw:footer>) */ +TYPEINIT1( XMLFooterFieldImportContext, XMLTextFieldImportContext ); + +XMLFooterFieldImportContext::XMLFooterFieldImportContext( + SvXMLImport& rImport, /// XML Import + XMLTextImportHelper& rHlp, /// Text import helper + sal_uInt16 nPrfx, /// namespace prefix + const ::rtl::OUString& sLocalName) /// element name w/o prefix +: XMLTextFieldImportContext(rImport, rHlp, sAPI_footer, nPrfx, sLocalName ) +{ + sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix ); + bValid = sal_True; +} + +/// process attribute values +void XMLFooterFieldImportContext::ProcessAttribute( sal_uInt16, const ::rtl::OUString& ) +{ +} + +/// prepare XTextField for insertion into document +void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &) +{ +} + + +/** import footer fields (<draw:date-and-time>) */ +TYPEINIT1( XMLDateTimeFieldImportContext, XMLTextFieldImportContext ); + +XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext( + SvXMLImport& rImport, /// XML Import + XMLTextImportHelper& rHlp, /// Text import helper + sal_uInt16 nPrfx, /// namespace prefix + const ::rtl::OUString& sLocalName) /// element name w/o prefix +: XMLTextFieldImportContext(rImport, rHlp, sAPI_datetime, nPrfx, sLocalName ) +{ + sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix ); + bValid = sal_True; +} + +/// process attribute values +void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16, + const ::rtl::OUString& ) +{ +} + +/// prepare XTextField for insertion into document +void XMLDateTimeFieldImportContext::PrepareField( + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> &) +{ +} diff --git a/xmloff/source/text/txtftne.cxx b/xmloff/source/text/txtftne.cxx new file mode 100644 index 000000000000..df9a03f25fdd --- /dev/null +++ b/xmloff/source/text/txtftne.cxx @@ -0,0 +1,393 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +/** @#file + * + * This file implements XMLTextParagraphExport methods to export + * - footnotes + * - endnotes + * - footnote configuration elements + * - endnote configuration elements + */ +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XFootnote.hpp> +#include <com/sun/star/text/XFootnotesSupplier.hpp> +#include <com/sun/star/text/XEndnotesSupplier.hpp> +#include <com/sun/star/text/FootnoteNumbering.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlnumfe.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/families.hxx> +#include <xmloff/xmlnume.hxx> +#include "XMLTextCharStyleNamesElementExport.hxx" +#include <xmloff/XMLEventExport.hxx> +#ifndef _XMLOFF_TXTPARAE_HXX +#include <xmloff/txtparae.hxx> +#endif + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::container; +using namespace ::xmloff::token; + + +void XMLTextParagraphExport::exportTextFootnote( + const Reference<XPropertySet> & rPropSet, + const OUString& rText, + sal_Bool bAutoStyles, sal_Bool bIsProgress ) +{ + // get footnote and associated text + Any aAny; + aAny = rPropSet->getPropertyValue(sFootnote); + Reference<XFootnote> xFootnote; + aAny >>= xFootnote; + Reference<XText> xText(xFootnote, UNO_QUERY); + + // are we an endnote? + Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY ); + sal_Bool bIsEndnote = xServiceInfo->supportsService(sTextEndnoteService); + + if (bAutoStyles) + { + // handle formatting of citation mark + Add( XML_STYLE_FAMILY_TEXT_TEXT, rPropSet ); + + // handle formatting within footnote + exportTextFootnoteHelper(xFootnote, xText, rText, + bAutoStyles, bIsEndnote, bIsProgress ); + } + else + { + // create span (for citation mark) if necessary; footnote content + // wil be handled via exportTextFootnoteHelper, exportText + sal_Bool bHasHyperlink; + sal_Bool bIsUICharStyle = sal_False; + sal_Bool bHasAutoStyle = sal_False; + + OUString sStyle = FindTextStyleAndHyperlink( rPropSet, bHasHyperlink, + bIsUICharStyle, bHasAutoStyle ); + + // export hyperlink (if we have one) + Reference < XPropertySetInfo > xPropSetInfo; + if( bHasHyperlink ) + { + Reference<XPropertyState> xPropState( rPropSet, UNO_QUERY ); + xPropSetInfo = rPropSet->getPropertySetInfo(); + bHasHyperlink = + addHyperlinkAttributes( rPropSet, xPropState, xPropSetInfo ); + } + SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink, + XML_NAMESPACE_TEXT, XML_A, + sal_False, sal_False ); + + if( bHasHyperlink ) + { + // export events (if supported) + OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM( + "HyperLinkEvents")); + if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents)) + { + Any a = rPropSet->getPropertyValue(sHyperLinkEvents); + Reference<XNameReplace> xName; + a >>= xName; + GetExport().GetEventExport().Export(xName, sal_False); + } + } + + { + XMLTextCharStyleNamesElementExport aCharStylesExport( + GetExport(), bIsUICharStyle && + aCharStyleNamesPropInfoCache.hasProperty( + rPropSet ), bHasAutoStyle, + rPropSet, sCharStyleNames ); + if( sStyle.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyle ) ); + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_SPAN, sal_False, sal_False ); + exportTextFootnoteHelper(xFootnote, xText, rText, + bAutoStyles, bIsEndnote, bIsProgress ); + } + else + { + exportTextFootnoteHelper(xFootnote, xText, rText, + bAutoStyles, bIsEndnote, bIsProgress ); + } + } + } +} + + +void XMLTextParagraphExport::exportTextFootnoteHelper( + const Reference<XFootnote> & rFootnote, + const Reference<XText> & rText, + const OUString& rTextString, + sal_Bool bAutoStyles, + sal_Bool bIsEndnote, + sal_Bool bIsProgress ) +{ + if (bAutoStyles) + { + exportText(rText, bAutoStyles, bIsProgress, sal_True ); + } + else + { + // export reference Id (for reference fields) + Reference<XPropertySet> xPropSet(rFootnote, UNO_QUERY); + Any aAny = xPropSet->getPropertyValue(sReferenceId); + sal_Int32 nNumber = 0; + aAny >>= nNumber; + OUStringBuffer aBuf; + aBuf.appendAscii("ftn"); + aBuf.append(nNumber); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_ID, + aBuf.makeStringAndClear()); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS, + GetXMLToken( bIsEndnote ? XML_ENDNOTE + : XML_FOOTNOTE ) ); + + SvXMLElementExport aNote(GetExport(), XML_NAMESPACE_TEXT, + XML_NOTE, sal_False, sal_False); + { + // handle label vs. automatic numbering + OUString sLabel = rFootnote->getLabel(); + if (sLabel.getLength()>0) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_LABEL, + sLabel); + } + // else: automatic numbering -> no attribute + + SvXMLElementExport aCite(GetExport(), XML_NAMESPACE_TEXT, + XML_NOTE_CITATION, sal_False, sal_False); + GetExport().Characters(rTextString); + } + + { + SvXMLElementExport aBody(GetExport(), XML_NAMESPACE_TEXT, + XML_NOTE_BODY, sal_False, sal_False); + exportText(rText, bAutoStyles, bIsProgress, sal_True ); + } + } +} + + +void XMLTextParagraphExport::exportTextFootnoteConfiguration() +{ + // footnote settings + Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(), + UNO_QUERY); + Reference<XPropertySet> aFootnoteConfiguration( + aFootnotesSupplier->getFootnoteSettings()); + exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, sal_False); + + // endnote settings + Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(), + UNO_QUERY); + Reference<XPropertySet> aEndnoteConfiguration( + aEndnotesSupplier->getEndnoteSettings()); + exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, sal_True); +} + + +void lcl_exportString( + SvXMLExport& rExport, + const Reference<XPropertySet> & rPropSet, + const OUString& sProperty, + sal_uInt16 nPrefix, + enum XMLTokenEnum eElement, + sal_Bool bEncodeName, + sal_Bool bOmitIfEmpty) +{ + DBG_ASSERT( eElement != XML_TOKEN_INVALID, "need element token"); + + Any aAny = rPropSet->getPropertyValue(sProperty); + OUString sTmp; + aAny >>= sTmp; + if (!bOmitIfEmpty || (sTmp.getLength() > 0)) + { + if( bEncodeName ) + sTmp = rExport.EncodeStyleName( sTmp ); + rExport.AddAttribute(nPrefix, eElement, sTmp); + } +} + +void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper( + const Reference<XPropertySet> & rFootnoteConfig, + sal_Bool bIsEndnote) +{ + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS, + GetXMLToken( bIsEndnote ? XML_ENDNOTE + : XML_FOOTNOTE ) ); + // default/paragraph style + lcl_exportString( GetExport(), rFootnoteConfig, + sParaStyleName, + XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME, + sal_True, sal_True); + + // citation style + lcl_exportString( GetExport(), rFootnoteConfig, + sCharStyleName, + XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME, + sal_True, sal_True); + + // citation body style + lcl_exportString( GetExport(), rFootnoteConfig, + sAnchorCharStyleName, + XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME, + sal_True, sal_True); + + // page style + lcl_exportString( GetExport(), rFootnoteConfig, + sPageStyleName, + XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME, + sal_True, sal_True ); + + // prefix + lcl_exportString( GetExport(), rFootnoteConfig, sPrefix, + XML_NAMESPACE_STYLE, XML_NUM_PREFIX, sal_False, sal_True); + + // suffix + lcl_exportString( GetExport(), rFootnoteConfig, sSuffix, + XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, sal_False, sal_True); + + + + Any aAny; + + // numbering style + OUStringBuffer sBuffer; + aAny = rFootnoteConfig->getPropertyValue(sNumberingType); + sal_Int16 nNumbering = 0; + aAny >>= nNumbering; + GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering); + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT, + sBuffer.makeStringAndClear() ); + GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering); + if (sBuffer.getLength() ) + { + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, + sBuffer.makeStringAndClear()); + } + + // StartAt / start-value + aAny = rFootnoteConfig->getPropertyValue(sStartAt); + sal_Int16 nOffset = 0; + aAny >>= nOffset; + SvXMLUnitConverter::convertNumber(sBuffer, (sal_Int32)nOffset); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE, + sBuffer.makeStringAndClear()); + + // some properties are for footnotes only + if (!bIsEndnote) + { + // footnotes position + aAny = rFootnoteConfig->getPropertyValue( + sPositionEndOfDoc); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION, + ( (*(sal_Bool *)aAny.getValue()) ? + XML_DOCUMENT : XML_PAGE ) ); + + aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting); + sal_Int16 nTmp = 0; + aAny >>= nTmp; + enum XMLTokenEnum eElement; + switch (nTmp) + { + case FootnoteNumbering::PER_PAGE: + eElement = XML_PAGE; + break; + case FootnoteNumbering::PER_CHAPTER: + eElement = XML_CHAPTER; + break; + case FootnoteNumbering::PER_DOCUMENT: + default: + eElement = XML_DOCUMENT; + break; + } + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_START_NUMBERING_AT, eElement); + } + + // element + SvXMLElementExport aFootnoteConfigElement( + GetExport(), XML_NAMESPACE_TEXT, + XML_NOTES_CONFIGURATION, + sal_True, sal_True); + + // two element for footnote content + if (!bIsEndnote) + { + OUString sTmp; + + // end notice / quo vadis + aAny = rFootnoteConfig->getPropertyValue(sEndNotice); + aAny >>= sTmp; + + if (sTmp.getLength() > 0) + { + SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT, + XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD, + sal_True, sal_False); + GetExport().Characters(sTmp); + } + + // begin notice / ergo sum + aAny = rFootnoteConfig->getPropertyValue(sBeginNotice); + aAny >>= sTmp; + + if (sTmp.getLength() > 0) + { + SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT, + XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD, + sal_True, sal_False); + GetExport().Characters(sTmp); + } + } +} diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx new file mode 100644 index 000000000000..d3591ece238c --- /dev/null +++ b/xmloff/source/text/txtimp.cxx @@ -0,0 +1,3062 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <vector> + +#include <boost/scoped_array.hpp> +#include <boost/tuple/tuple.hpp> + +#include <tools/solar.h> +#include <tools/debug.hxx> +#ifndef _SVSTDARR_STRINGSDTOR_DECL +#define _SVSTDARR_STRINGSDTOR +#include <svl/svstdarr.hxx> +#endif +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include <com/sun/star/text/XTextFramesSupplier.hpp> +#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp> +#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/text/XFormField.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ucb/XAnyCompareFactory.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/txtstyli.hxx> +#include <xmloff/families.hxx> +#include <xmloff/xmlnumfi.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimppr.hxx> + +#include "txtparai.hxx" +#include <xmloff/txtimp.hxx> +#include <xmloff/txtprmap.hxx> +#include "xmloff/txtimppr.hxx" +#include <xmloff/xmlimp.hxx> +#include "txtvfldi.hxx" +#include "xmloff/i18nmap.hxx" +#include "XMLTextListItemContext.hxx" +#include "XMLTextListBlockContext.hxx" +#include "XMLTextFrameContext.hxx" +#include "XMLPropertyBackpatcher.hxx" +#include "XMLTextFrameHyperlinkContext.hxx" +#include "XMLSectionImportContext.hxx" +#include "XMLIndexTOCContext.hxx" +#include <xmloff/XMLFontStylesContext.hxx> +#include <xmloff/ProgressBarHelper.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/XMLEventsImportContext.hxx> +#include "XMLTrackedChangesImportContext.hxx" +#include "XMLChangeImportContext.hxx" +#include "XMLAutoMarkFileContext.hxx" + +#include "XMLCalculationSettingsContext.hxx" +#include <xmloff/formsimp.hxx> +#include "XMLNumberStylesImport.hxx" +// --> OD 2006-10-12 #i69629# +#include <com/sun/star/beans/XPropertyState.hpp> +// <-- + +// --> OD 2008-04-25 #refactorlists# +#include <txtlists.hxx> +// <-- +#include <xmloff/odffields.hxx> +#include <comphelper/stlunosequence.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::ucb::XAnyCompare; + +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::lang; +using namespace ::xmloff::token; +using ::com::sun::star::util::DateTime; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star; +using ::comphelper::UStringLess; + + + +static __FAR_DATA SvXMLTokenMapEntry aTextElemTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_P, XML_TOK_TEXT_P }, + { XML_NAMESPACE_TEXT, XML_H, XML_TOK_TEXT_H }, + { XML_NAMESPACE_TEXT, XML_LIST, XML_TOK_TEXT_LIST }, + { XML_NAMESPACE_DRAW, XML_FRAME, XML_TOK_TEXT_FRAME_PAGE }, + { XML_NAMESPACE_DRAW, XML_A, XML_TOK_DRAW_A_PAGE }, + { XML_NAMESPACE_TABLE,XML_TABLE, XML_TOK_TABLE_TABLE }, +// { XML_NAMESPACE_TABLE,XML_SUB_TABLE, XML_TOK_TABLE_SUBTABLE }, + { XML_NAMESPACE_TEXT, XML_VARIABLE_DECLS, XML_TOK_TEXT_VARFIELD_DECLS }, + { XML_NAMESPACE_TEXT, XML_USER_FIELD_DECLS, XML_TOK_TEXT_USERFIELD_DECLS }, + { XML_NAMESPACE_TEXT, XML_SEQUENCE_DECLS, XML_TOK_TEXT_SEQUENCE_DECLS }, + { XML_NAMESPACE_TEXT, XML_DDE_CONNECTION_DECLS, XML_TOK_TEXT_DDE_DECLS }, + { XML_NAMESPACE_TEXT, XML_SECTION, XML_TOK_TEXT_SECTION }, + { XML_NAMESPACE_TEXT, XML_TABLE_OF_CONTENT, XML_TOK_TEXT_TOC }, + { XML_NAMESPACE_TEXT, XML_OBJECT_INDEX, XML_TOK_TEXT_OBJECT_INDEX }, + { XML_NAMESPACE_TEXT, XML_TABLE_INDEX, XML_TOK_TEXT_TABLE_INDEX }, + { XML_NAMESPACE_TEXT, XML_ILLUSTRATION_INDEX, XML_TOK_TEXT_ILLUSTRATION_INDEX }, + { XML_NAMESPACE_TEXT, XML_USER_INDEX, XML_TOK_TEXT_USER_INDEX }, + { XML_NAMESPACE_TEXT, XML_ALPHABETICAL_INDEX, XML_TOK_TEXT_ALPHABETICAL_INDEX }, + { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY, XML_TOK_TEXT_BIBLIOGRAPHY_INDEX }, + { XML_NAMESPACE_TEXT, XML_INDEX_TITLE, XML_TOK_TEXT_INDEX_TITLE }, + { XML_NAMESPACE_TEXT, XML_TRACKED_CHANGES, XML_TOK_TEXT_TRACKED_CHANGES }, + { XML_NAMESPACE_TEXT, XML_CHANGE_START, XML_TOK_TEXT_CHANGE_START }, + { XML_NAMESPACE_TEXT, XML_CHANGE_END, XML_TOK_TEXT_CHANGE_END }, + { XML_NAMESPACE_TEXT, XML_CHANGE, XML_TOK_TEXT_CHANGE }, + { XML_NAMESPACE_OFFICE, XML_FORMS, XML_TOK_TEXT_FORMS }, + { XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, XML_TOK_TEXT_CALCULATION_SETTINGS }, + { XML_NAMESPACE_TEXT, XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE, XML_TOK_TEXT_AUTOMARK }, + // --> FLR #i52127# + { XML_NAMESPACE_TEXT, XML_NUMBERED_PARAGRAPH, XML_TOK_TEXT_NUMBERED_PARAGRAPH }, + // <-- + + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextPElemTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_SPAN, XML_TOK_TEXT_SPAN }, + { XML_NAMESPACE_TEXT, XML_TAB, XML_TOK_TEXT_TAB_STOP }, + { XML_NAMESPACE_TEXT, XML_LINE_BREAK, XML_TOK_TEXT_LINE_BREAK }, + { XML_NAMESPACE_TEXT, XML_SOFT_PAGE_BREAK, XML_TOK_TEXT_SOFT_PAGE_BREAK }, + { XML_NAMESPACE_TEXT, XML_S, XML_TOK_TEXT_S }, + { XML_NAMESPACE_TEXT, XML_A, XML_TOK_TEXT_HYPERLINK }, + { XML_NAMESPACE_TEXT, XML_RUBY, XML_TOK_TEXT_RUBY }, + + { XML_NAMESPACE_TEXT, XML_NOTE, XML_TOK_TEXT_NOTE }, + { XML_NAMESPACE_TEXT, XML_BOOKMARK, XML_TOK_TEXT_BOOKMARK }, + { XML_NAMESPACE_TEXT, XML_BOOKMARK_START, XML_TOK_TEXT_BOOKMARK_START }, + { XML_NAMESPACE_TEXT, XML_BOOKMARK_END, XML_TOK_TEXT_BOOKMARK_END }, + { XML_NAMESPACE_TEXT, XML_REFERENCE_MARK, XML_TOK_TEXT_REFERENCE }, + { XML_NAMESPACE_TEXT, XML_REFERENCE_MARK_START, + XML_TOK_TEXT_REFERENCE_START }, + { XML_NAMESPACE_TEXT, XML_REFERENCE_MARK_END, + XML_TOK_TEXT_REFERENCE_END }, + + { XML_NAMESPACE_DRAW, XML_FRAME, XML_TOK_TEXT_FRAME }, + { XML_NAMESPACE_DRAW, XML_A, XML_TOK_DRAW_A }, + + // index marks + { XML_NAMESPACE_TEXT, XML_TOC_MARK, XML_TOK_TEXT_TOC_MARK }, + { XML_NAMESPACE_TEXT, XML_TOC_MARK_START, XML_TOK_TEXT_TOC_MARK_START }, + { XML_NAMESPACE_TEXT, XML_TOC_MARK_END, XML_TOK_TEXT_TOC_MARK_END }, + { XML_NAMESPACE_TEXT, XML_USER_INDEX_MARK, XML_TOK_TEXT_USER_INDEX_MARK }, + { XML_NAMESPACE_TEXT, XML_USER_INDEX_MARK_START, + XML_TOK_TEXT_USER_INDEX_MARK_START }, + { XML_NAMESPACE_TEXT, XML_USER_INDEX_MARK_END, + XML_TOK_TEXT_USER_INDEX_MARK_END }, + { XML_NAMESPACE_TEXT, XML_ALPHABETICAL_INDEX_MARK, + XML_TOK_TEXT_ALPHA_INDEX_MARK }, + { XML_NAMESPACE_TEXT, XML_ALPHABETICAL_INDEX_MARK_START, + XML_TOK_TEXT_ALPHA_INDEX_MARK_START }, + { XML_NAMESPACE_TEXT, XML_ALPHABETICAL_INDEX_MARK_END, + XML_TOK_TEXT_ALPHA_INDEX_MARK_END }, + + // sender fields + { XML_NAMESPACE_TEXT, XML_SENDER_FIRSTNAME,XML_TOK_TEXT_SENDER_FIRSTNAME}, + { XML_NAMESPACE_TEXT, XML_SENDER_LASTNAME, XML_TOK_TEXT_SENDER_LASTNAME }, + { XML_NAMESPACE_TEXT, XML_SENDER_INITIALS, XML_TOK_TEXT_SENDER_INITIALS }, + { XML_NAMESPACE_TEXT, XML_SENDER_TITLE, XML_TOK_TEXT_SENDER_TITLE }, + { XML_NAMESPACE_TEXT, XML_SENDER_POSITION, XML_TOK_TEXT_SENDER_POSITION }, + { XML_NAMESPACE_TEXT, XML_SENDER_EMAIL, XML_TOK_TEXT_SENDER_EMAIL }, + { XML_NAMESPACE_TEXT, XML_SENDER_PHONE_PRIVATE, + XML_TOK_TEXT_SENDER_PHONE_PRIVATE }, + { XML_NAMESPACE_TEXT, XML_SENDER_FAX, XML_TOK_TEXT_SENDER_FAX }, + { XML_NAMESPACE_TEXT, XML_SENDER_COMPANY, XML_TOK_TEXT_SENDER_COMPANY }, + { XML_NAMESPACE_TEXT, XML_SENDER_PHONE_WORK, + XML_TOK_TEXT_SENDER_PHONE_WORK }, + { XML_NAMESPACE_TEXT, XML_SENDER_STREET, XML_TOK_TEXT_SENDER_STREET }, + { XML_NAMESPACE_TEXT, XML_SENDER_CITY, XML_TOK_TEXT_SENDER_CITY }, + { XML_NAMESPACE_TEXT, XML_SENDER_POSTAL_CODE, + XML_TOK_TEXT_SENDER_POSTAL_CODE }, + { XML_NAMESPACE_TEXT, XML_SENDER_COUNTRY, XML_TOK_TEXT_SENDER_COUNTRY }, + { XML_NAMESPACE_TEXT, XML_SENDER_STATE_OR_PROVINCE, + XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE }, + + // misc. document fields + { XML_NAMESPACE_TEXT, XML_AUTHOR_NAME, XML_TOK_TEXT_AUTHOR_NAME }, + { XML_NAMESPACE_TEXT, XML_AUTHOR_INITIALS, XML_TOK_TEXT_AUTHOR_INITIALS }, + { XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_TEXT_DATE }, + { XML_NAMESPACE_TEXT, XML_TIME, XML_TOK_TEXT_TIME }, + { XML_NAMESPACE_TEXT, XML_PAGE_NUMBER, XML_TOK_TEXT_PAGE_NUMBER }, + { XML_NAMESPACE_TEXT, XML_PAGE_CONTINUATION_STRING, + XML_TOK_TEXT_PAGE_CONTINUATION_STRING }, + + // variable fields + { XML_NAMESPACE_TEXT, XML_VARIABLE_SET, XML_TOK_TEXT_VARIABLE_SET }, + { XML_NAMESPACE_TEXT, XML_VARIABLE_GET, XML_TOK_TEXT_VARIABLE_GET }, + { XML_NAMESPACE_TEXT, XML_VARIABLE_INPUT, XML_TOK_TEXT_VARIABLE_INPUT }, + { XML_NAMESPACE_TEXT, XML_USER_FIELD_GET, XML_TOK_TEXT_USER_FIELD_GET }, + { XML_NAMESPACE_TEXT, XML_USER_FIELD_INPUT,XML_TOK_TEXT_USER_FIELD_INPUT}, + { XML_NAMESPACE_TEXT, XML_SEQUENCE, XML_TOK_TEXT_SEQUENCE }, + { XML_NAMESPACE_TEXT, XML_EXPRESSION, XML_TOK_TEXT_EXPRESSION }, + { XML_NAMESPACE_TEXT, XML_TEXT_INPUT, XML_TOK_TEXT_TEXT_INPUT }, + + // database fields + { XML_NAMESPACE_TEXT, XML_DATABASE_DISPLAY, + XML_TOK_TEXT_DATABASE_DISPLAY }, + { XML_NAMESPACE_TEXT, XML_DATABASE_NEXT, + XML_TOK_TEXT_DATABASE_NEXT }, + { XML_NAMESPACE_TEXT, XML_DATABASE_ROW_SELECT, + XML_TOK_TEXT_DATABASE_SELECT }, + { XML_NAMESPACE_TEXT, XML_DATABASE_ROW_NUMBER, + XML_TOK_TEXT_DATABASE_ROW_NUMBER }, + { XML_NAMESPACE_TEXT, XML_DATABASE_NAME, XML_TOK_TEXT_DATABASE_NAME }, + + // docinfo fields + { XML_NAMESPACE_TEXT, XML_INITIAL_CREATOR, + XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR }, + { XML_NAMESPACE_TEXT, XML_DESCRIPTION, XML_TOK_TEXT_DOCUMENT_DESCRIPTION}, + { XML_NAMESPACE_TEXT, XML_PRINTED_BY, XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR}, + { XML_NAMESPACE_TEXT, XML_TITLE, XML_TOK_TEXT_DOCUMENT_TITLE }, + { XML_NAMESPACE_TEXT, XML_SUBJECT, XML_TOK_TEXT_DOCUMENT_SUBJECT }, + { XML_NAMESPACE_TEXT, XML_KEYWORDS, XML_TOK_TEXT_DOCUMENT_KEYWORDS }, + { XML_NAMESPACE_TEXT, XML_CREATOR, XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR }, + { XML_NAMESPACE_TEXT, XML_EDITING_CYCLES, + XML_TOK_TEXT_DOCUMENT_REVISION }, + { XML_NAMESPACE_TEXT, XML_CREATION_DATE, + XML_TOK_TEXT_DOCUMENT_CREATION_DATE }, + { XML_NAMESPACE_TEXT, XML_CREATION_TIME, + XML_TOK_TEXT_DOCUMENT_CREATION_TIME }, + { XML_NAMESPACE_TEXT, XML_PRINT_DATE, XML_TOK_TEXT_DOCUMENT_PRINT_DATE }, + { XML_NAMESPACE_TEXT, XML_PRINT_TIME, XML_TOK_TEXT_DOCUMENT_PRINT_TIME }, + { XML_NAMESPACE_TEXT, XML_MODIFICATION_DATE, + XML_TOK_TEXT_DOCUMENT_SAVE_DATE }, + { XML_NAMESPACE_TEXT, XML_MODIFICATION_TIME, + XML_TOK_TEXT_DOCUMENT_SAVE_TIME }, + { XML_NAMESPACE_TEXT, XML_EDITING_DURATION, + XML_TOK_TEXT_DOCUMENT_EDIT_DURATION }, + { XML_NAMESPACE_TEXT, XML_USER_DEFINED, + XML_TOK_TEXT_DOCUMENT_USER_DEFINED }, + + // misc fields + { XML_NAMESPACE_TEXT, XML_PLACEHOLDER, XML_TOK_TEXT_PLACEHOLDER }, + { XML_NAMESPACE_TEXT, XML_HIDDEN_TEXT, XML_TOK_TEXT_HIDDEN_TEXT }, + { XML_NAMESPACE_TEXT, XML_HIDDEN_PARAGRAPH, + XML_TOK_TEXT_HIDDEN_PARAGRAPH }, + { XML_NAMESPACE_TEXT, XML_CONDITIONAL_TEXT, + XML_TOK_TEXT_CONDITIONAL_TEXT }, + { XML_NAMESPACE_TEXT, XML_FILE_NAME, XML_TOK_TEXT_FILENAME }, + { XML_NAMESPACE_TEXT, XML_CHAPTER, XML_TOK_TEXT_CHAPTER }, + { XML_NAMESPACE_TEXT, XML_TEMPLATE_NAME, XML_TOK_TEXT_TEMPLATENAME }, + { XML_NAMESPACE_TEXT, XML_PARAGRAPH_COUNT, XML_TOK_TEXT_PARAGRAPH_COUNT }, + { XML_NAMESPACE_TEXT, XML_WORD_COUNT, XML_TOK_TEXT_WORD_COUNT }, + { XML_NAMESPACE_TEXT, XML_TABLE_COUNT, XML_TOK_TEXT_TABLE_COUNT }, + { XML_NAMESPACE_TEXT, XML_CHARACTER_COUNT, XML_TOK_TEXT_CHARACTER_COUNT }, + { XML_NAMESPACE_TEXT, XML_IMAGE_COUNT, XML_TOK_TEXT_IMAGE_COUNT }, + { XML_NAMESPACE_TEXT, XML_OBJECT_COUNT, XML_TOK_TEXT_OBJECT_COUNT }, + { XML_NAMESPACE_TEXT, XML_PAGE_COUNT, XML_TOK_TEXT_PAGE_COUNT }, + { XML_NAMESPACE_TEXT, XML_PAGE_VARIABLE_GET, XML_TOK_TEXT_GET_PAGE_VAR }, + { XML_NAMESPACE_TEXT, XML_PAGE_VARIABLE_SET, XML_TOK_TEXT_SET_PAGE_VAR }, + { XML_NAMESPACE_TEXT, XML_EXECUTE_MACRO, XML_TOK_TEXT_MACRO }, + { XML_NAMESPACE_TEXT, XML_DDE_CONNECTION, XML_TOK_TEXT_DDE }, + { XML_NAMESPACE_TEXT, XML_REFERENCE_REF, XML_TOK_TEXT_REFERENCE_REF }, + { XML_NAMESPACE_TEXT, XML_BOOKMARK_REF, XML_TOK_TEXT_BOOKMARK_REF }, + { XML_NAMESPACE_TEXT, XML_SEQUENCE_REF, XML_TOK_TEXT_SEQUENCE_REF }, + { XML_NAMESPACE_TEXT, XML_NOTE_REF, XML_TOK_TEXT_NOTE_REF }, + { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY_MARK, + XML_TOK_TEXT_BIBLIOGRAPHY_MARK }, + { XML_NAMESPACE_OFFICE, XML_ANNOTATION, XML_TOK_TEXT_ANNOTATION }, + { XML_NAMESPACE_TEXT, XML_SCRIPT, XML_TOK_TEXT_SCRIPT }, + { XML_NAMESPACE_TEXT, XML_TABLE_FORMULA, XML_TOK_TEXT_TABLE_FORMULA }, + { XML_NAMESPACE_TEXT, XML_DROPDOWN, XML_TOK_TEXT_DROPDOWN }, + + // Calc fields + { XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_TEXT_SHEET_NAME }, + + // draw fields + { XML_NAMESPACE_TEXT, XML_MEASURE, XML_TOK_TEXT_MEASURE }, + + // RDF metadata + { XML_NAMESPACE_TEXT, XML_META, XML_TOK_TEXT_META }, + { XML_NAMESPACE_TEXT, XML_META_FIELD, XML_TOK_TEXT_META_FIELD }, + + // redlining (aka change tracking) + { XML_NAMESPACE_TEXT, XML_CHANGE_START, XML_TOK_TEXTP_CHANGE_START }, + { XML_NAMESPACE_TEXT, XML_CHANGE_END , XML_TOK_TEXTP_CHANGE_END }, + { XML_NAMESPACE_TEXT, XML_CHANGE, XML_TOK_TEXTP_CHANGE }, + + { XML_NAMESPACE_PRESENTATION, XML_HEADER, XML_TOK_DRAW_HEADER }, + { XML_NAMESPACE_PRESENTATION, XML_FOOTER, XML_TOK_DRAW_FOOTER }, + { XML_NAMESPACE_PRESENTATION, XML_DATE_TIME, XML_TOK_DRAW_DATE_TIME }, + { XML_NAMESPACE_TEXT, XML_PAGE_CONTINUATION, XML_TOK_TEXT_PAGE_CONTINUATION }, + + { XML_NAMESPACE_FIELD, XML_FIELDMARK, XML_TOK_TEXT_FIELDMARK }, + { XML_NAMESPACE_FIELD, XML_FIELDMARK_START, XML_TOK_TEXT_FIELDMARK_START }, + { XML_NAMESPACE_FIELD, XML_FIELDMARK_END, XML_TOK_TEXT_FIELDMARK_END }, + + + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextPAttrTokenMap[] = +{ + { XML_NAMESPACE_XML , XML_ID, XML_TOK_TEXT_P_XMLID }, + { XML_NAMESPACE_XHTML, XML_ABOUT, XML_TOK_TEXT_P_ABOUT }, + { XML_NAMESPACE_XHTML, XML_PROPERTY, XML_TOK_TEXT_P_PROPERTY }, + { XML_NAMESPACE_XHTML, XML_CONTENT, XML_TOK_TEXT_P_CONTENT }, + { XML_NAMESPACE_XHTML, XML_DATATYPE, XML_TOK_TEXT_P_DATATYPE }, + { XML_NAMESPACE_TEXT, XML_ID, XML_TOK_TEXT_P_TEXTID }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_TEXT_P_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_COND_STYLE_NAME, + XML_TOK_TEXT_P_COND_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,XML_TOK_TEXT_P_LEVEL }, + { XML_NAMESPACE_TEXT, XML_IS_LIST_HEADER,XML_TOK_TEXT_P_IS_LIST_HEADER }, + { XML_NAMESPACE_TEXT, XML_RESTART_NUMBERING,XML_TOK_TEXT_P_RESTART_NUMBERING }, + { XML_NAMESPACE_TEXT, XML_START_VALUE,XML_TOK_TEXT_P_START_VALUE }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextNumberedParagraphAttrTokenMap[] = +{ + { XML_NAMESPACE_XML , XML_ID, XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID }, + { XML_NAMESPACE_TEXT, XML_LIST_ID, + XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID }, + { XML_NAMESPACE_TEXT, XML_LEVEL, XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, + XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_CONTINUE_NUMBERING, + XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING }, + { XML_NAMESPACE_TEXT, XML_START_VALUE, + XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextListBlockAttrTokenMap[] = +{ + { XML_NAMESPACE_XML , XML_ID, XML_TOK_TEXT_LIST_BLOCK_XMLID }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, + XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_CONTINUE_NUMBERING, + XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING }, + // --> OD 2008-04-22 #refactorlists# + { XML_NAMESPACE_TEXT, XML_CONTINUE_LIST, + XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextListBlockElemTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_LIST_HEADER, XML_TOK_TEXT_LIST_HEADER }, + { XML_NAMESPACE_TEXT, XML_LIST_ITEM, XML_TOK_TEXT_LIST_ITEM }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextFrameAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_TEXT_FRAME_STYLE_NAME }, + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_TEXT_FRAME_NAME }, + { XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, XML_TOK_TEXT_FRAME_ANCHOR_TYPE }, + { XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER, XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER }, + { XML_NAMESPACE_SVG, XML_X, XML_TOK_TEXT_FRAME_X }, + { XML_NAMESPACE_SVG, XML_Y, XML_TOK_TEXT_FRAME_Y }, + { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_TEXT_FRAME_WIDTH }, + { XML_NAMESPACE_FO, XML_MIN_WIDTH, XML_TOK_TEXT_FRAME_MIN_WIDTH }, + { XML_NAMESPACE_STYLE, XML_REL_WIDTH, XML_TOK_TEXT_FRAME_REL_WIDTH }, + { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_TEXT_FRAME_HEIGHT }, + { XML_NAMESPACE_FO, XML_MIN_HEIGHT, XML_TOK_TEXT_FRAME_MIN_HEIGHT }, + { XML_NAMESPACE_STYLE, XML_REL_HEIGHT, XML_TOK_TEXT_FRAME_REL_HEIGHT }, + { XML_NAMESPACE_DRAW, XML_CHAIN_NEXT_NAME, XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME }, + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_TEXT_FRAME_HREF }, + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_TEXT_FRAME_FILTER_NAME }, + { XML_NAMESPACE_DRAW, XML_ZINDEX, XML_TOK_TEXT_FRAME_Z_INDEX }, + { XML_NAMESPACE_SVG, XML_TRANSFORM, XML_TOK_TEXT_FRAME_TRANSFORM }, + { XML_NAMESPACE_DRAW, XML_CLASS_ID, XML_TOK_TEXT_FRAME_CLASS_ID }, + { XML_NAMESPACE_DRAW, XML_CODE, XML_TOK_TEXT_FRAME_CODE }, + { XML_NAMESPACE_DRAW, XML_OBJECT, XML_TOK_TEXT_FRAME_OBJECT }, + { XML_NAMESPACE_DRAW, XML_ARCHIVE, XML_TOK_TEXT_FRAME_ARCHIVE }, + { XML_NAMESPACE_DRAW, XML_MAY_SCRIPT, XML_TOK_TEXT_FRAME_MAY_SCRIPT }, + { XML_NAMESPACE_DRAW, XML_MIME_TYPE, XML_TOK_TEXT_FRAME_MIME_TYPE }, + { XML_NAMESPACE_DRAW, XML_APPLET_NAME, XML_TOK_TEXT_FRAME_APPLET_NAME }, + { XML_NAMESPACE_DRAW, XML_FRAME_NAME, XML_TOK_TEXT_FRAME_FRAME_NAME }, + { XML_NAMESPACE_DRAW, XML_NOTIFY_ON_UPDATE_OF_RANGES, XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE }, + { XML_NAMESPACE_DRAW, XML_NOTIFY_ON_UPDATE_OF_TABLE, XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextContourAttrTokenMap[] = +{ + { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_TEXT_CONTOUR_WIDTH }, + { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_TEXT_CONTOUR_HEIGHT }, + { XML_NAMESPACE_SVG, XML_VIEWBOX, XML_TOK_TEXT_CONTOUR_VIEWBOX }, + { XML_NAMESPACE_SVG, XML_D, XML_TOK_TEXT_CONTOUR_D }, + { XML_NAMESPACE_DRAW,XML_POINTS, XML_TOK_TEXT_CONTOUR_POINTS }, + { XML_NAMESPACE_DRAW,XML_RECREATE_ON_EDIT, XML_TOK_TEXT_CONTOUR_AUTO }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextHyperlinkAttrTokenMap[] = +{ + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_TEXT_HYPERLINK_HREF }, + { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_TEXT_HYPERLINK_NAME }, + { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_TEXT_HYPERLINK_SHOW }, + { XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, XML_TOK_TEXT_HYPERLINK_TARGET_FRAME }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_TEXT_HYPERLINK_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_VISITED_STYLE_NAME, XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME }, + { XML_NAMESPACE_OFFICE, XML_SERVER_MAP, XML_TOK_TEXT_HYPERLINK_SERVER_MAP }, + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextMasterPageElemTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_HEADER, XML_TOK_TEXT_MP_HEADER }, + { XML_NAMESPACE_STYLE, XML_FOOTER, XML_TOK_TEXT_MP_FOOTER }, + { XML_NAMESPACE_STYLE, XML_HEADER_LEFT, XML_TOK_TEXT_MP_HEADER_LEFT }, + { XML_NAMESPACE_STYLE, XML_FOOTER_LEFT, XML_TOK_TEXT_MP_FOOTER_LEFT }, + + XML_TOKEN_MAP_END +}; + +static __FAR_DATA SvXMLTokenMapEntry aTextFieldAttrTokenMap[] = +{ + { XML_NAMESPACE_TEXT, XML_FIXED, XML_TOK_TEXTFIELD_FIXED }, + { XML_NAMESPACE_TEXT, XML_DESCRIPTION, XML_TOK_TEXTFIELD_DESCRIPTION }, + { XML_NAMESPACE_TEXT, XML_HELP, XML_TOK_TEXTFIELD_HELP }, + { XML_NAMESPACE_TEXT, XML_HINT, XML_TOK_TEXTFIELD_HINT }, + { XML_NAMESPACE_TEXT, XML_PLACEHOLDER_TYPE, + XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE }, + { XML_NAMESPACE_TEXT, XML_NAME, XML_TOK_TEXTFIELD_NAME }, + { XML_NAMESPACE_TEXT, XML_FORMULA, XML_TOK_TEXTFIELD_FORMULA }, + { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_TEXTFIELD_NUM_FORMAT }, + { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, + XML_TOK_TEXTFIELD_NUM_LETTER_SYNC }, + { XML_NAMESPACE_TEXT, XML_DISPLAY_FORMULA, + XML_TOK_TEXTFIELD_DISPLAY_FORMULA }, + { XML_NAMESPACE_TEXT, XML_VALUE_TYPE, XML_TOK_TEXTFIELD_VALUE_TYPE }, // #i32362#: src680m48++ saves text:value-type + { XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TOK_TEXTFIELD_VALUE_TYPE }, + { XML_NAMESPACE_TEXT, XML_VALUE, XML_TOK_TEXTFIELD_VALUE }, + { XML_NAMESPACE_OFFICE, XML_VALUE, XML_TOK_TEXTFIELD_VALUE }, + { XML_NAMESPACE_TEXT, XML_STRING_VALUE, XML_TOK_TEXTFIELD_STRING_VALUE }, + { XML_NAMESPACE_OFFICE, XML_STRING_VALUE, XML_TOK_TEXTFIELD_STRING_VALUE }, + { XML_NAMESPACE_TEXT, XML_DATE_VALUE, XML_TOK_TEXTFIELD_DATE_VALUE }, + { XML_NAMESPACE_OFFICE, XML_DATE_VALUE, XML_TOK_TEXTFIELD_DATE_VALUE }, + { XML_NAMESPACE_TEXT, XML_TIME_VALUE, XML_TOK_TEXTFIELD_TIME_VALUE }, + { XML_NAMESPACE_OFFICE, XML_TIME_VALUE, XML_TOK_TEXTFIELD_TIME_VALUE }, + { XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_TOK_TEXTFIELD_BOOL_VALUE}, + { XML_NAMESPACE_OFFICE, XML_CURRENCY, XML_TOK_TEXTFIELD_CURRENCY}, + { XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, + XML_TOK_TEXTFIELD_DATA_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_DISPLAY_OUTLINE_LEVEL, + XML_TOK_TEXTFIELD_NUMBERING_LEVEL }, + { XML_NAMESPACE_TEXT, XML_SEPARATION_CHARACTER, + XML_TOK_TEXTFIELD_NUMBERING_SEPARATOR }, + { XML_NAMESPACE_TEXT, XML_DISPLAY, XML_TOK_TEXTFIELD_DISPLAY }, + { XML_NAMESPACE_TEXT, XML_TIME_ADJUST, XML_TOK_TEXTFIELD_TIME_ADJUST }, + { XML_NAMESPACE_TEXT, XML_DATE_ADJUST, XML_TOK_TEXTFIELD_DATE_ADJUST }, + { XML_NAMESPACE_TEXT, XML_PAGE_ADJUST, XML_TOK_TEXTFIELD_PAGE_ADJUST }, + { XML_NAMESPACE_TEXT, XML_SELECT_PAGE, XML_TOK_TEXTFIELD_SELECT_PAGE }, + { XML_NAMESPACE_TEXT, XML_DATABASE_NAME, XML_TOK_TEXTFIELD_DATABASE_NAME}, + { XML_NAMESPACE_TEXT, XML_TABLE_NAME, XML_TOK_TEXTFIELD_TABLE_NAME }, + { XML_NAMESPACE_TEXT, XML_COLUMN_NAME, XML_TOK_TEXTFIELD_COLUMN_NAME }, + { XML_NAMESPACE_TEXT, XML_ROW_NUMBER, XML_TOK_TEXTFIELD_ROW_NUMBER }, + { XML_NAMESPACE_TEXT, XML_CONDITION, XML_TOK_TEXTFIELD_CONDITION }, + { XML_NAMESPACE_TEXT, XML_STRING_VALUE_IF_TRUE, + XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE }, + { XML_NAMESPACE_TEXT, XML_STRING_VALUE_IF_FALSE, + XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE }, + { XML_NAMESPACE_TEXT, XML_EDITING_CYCLES, XML_TOK_TEXTFIELD_REVISION }, + { XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL, XML_TOK_TEXTFIELD_OUTLINE_LEVEL}, + { XML_NAMESPACE_TEXT, XML_ACTIVE, XML_TOK_TEXTFIELD_ACTIVE }, + { XML_NAMESPACE_TEXT, XML_NOTE_CLASS, XML_TOK_TEXTFIELD_NOTE_CLASS }, + { XML_NAMESPACE_TEXT, XML_REFERENCE_FORMAT, + XML_TOK_TEXTFIELD_REFERENCE_FORMAT }, + { XML_NAMESPACE_TEXT, XML_REF_NAME, XML_TOK_TEXTFIELD_REF_NAME }, + { XML_NAMESPACE_TEXT, XML_CONNECTION_NAME, + XML_TOK_TEXTFIELD_CONNECTION_NAME }, + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_TEXTFIELD_HREF }, + { XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, + XML_TOK_TEXTFIELD_TARGET_FRAME }, + { XML_NAMESPACE_TEXT, XML_ANNOTATION, XML_TOK_TEXTFIELD_ANNOTATION }, + { XML_NAMESPACE_SCRIPT, XML_LANGUAGE, XML_TOK_TEXTFIELD_LANGUAGE }, + { XML_NAMESPACE_TEXT, XML_KIND, XML_TOK_TEXTFIELD_MEASURE_KIND }, + { XML_NAMESPACE_TEXT, XML_IS_HIDDEN, XML_TOK_TEXTFIELD_IS_HIDDEN }, + { XML_NAMESPACE_TEXT, XML_CURRENT_VALUE, + XML_TOK_TEXTFIELD_CURRENT_VALUE }, + { XML_NAMESPACE_TEXT, XML_TABLE_TYPE, XML_TOK_TEXTFIELD_TABLE_TYPE }, + + XML_TOKEN_MAP_END +}; + + +// maximum allowed length of combined characters field +#define MAX_COMBINED_CHARACTERS 6 + +struct SAL_DLLPRIVATE XMLTextImportHelper::Impl + : private ::boost::noncopyable +{ + ::std::auto_ptr<SvXMLTokenMap> m_pTextElemTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextPElemTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextPAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextFieldAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextNumberedParagraphAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextListBlockAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextListBlockElemTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextFrameAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextContourAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextHyperlinkAttrTokenMap; + ::std::auto_ptr<SvXMLTokenMap> m_pTextMasterPageElemTokenMap; + ::std::auto_ptr<SvStringsDtor> m_pPrevFrmNames; + ::std::auto_ptr<SvStringsDtor> m_pNextFrmNames; + + // --> OD 2008-04-25 #refactorlists# + ::std::auto_ptr<XMLTextListsHelper> m_pTextListsHelper; + // <-- + + SvXMLImportContextRef m_xAutoStyles; + SvXMLImportContextRef m_xFontDecls; + + XMLSectionList_Impl m_SectionList; + + UniReference< SvXMLImportPropertyMapper > m_xParaImpPrMap; + UniReference< SvXMLImportPropertyMapper > m_xTextImpPrMap; + UniReference< SvXMLImportPropertyMapper > m_xFrameImpPrMap; + UniReference< SvXMLImportPropertyMapper > m_xSectionImpPrMap; + UniReference< SvXMLImportPropertyMapper > m_xRubyImpPrMap; + + ::std::auto_ptr<SvI18NMap> m_pRenameMap; + // --> OD 2006-10-12 #i69629# - change and extend data structure: + // - data structure contains candidates of paragraph styles, which + // will be assigned to the outline style + // - data structure contains more than one candidate for each list level + // of the outline style + ::boost::scoped_array< ::std::vector< ::rtl::OUString > > + m_pOutlineStylesCandidates; + // <-- + + // start range, xml:id, RDFa stuff + typedef ::boost::tuple< + uno::Reference<text::XTextRange>, ::rtl::OUString, + ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes > > + BookmarkMapEntry_t; + /// start ranges for open bookmarks + ::std::map< ::rtl::OUString, BookmarkMapEntry_t, + ::comphelper::UStringLess> m_BookmarkStartRanges; + + typedef ::std::vector< ::rtl::OUString > BookmarkVector_t; + BookmarkVector_t m_BookmarkVector; + + /// name of the last 'open' redline that started between paragraphs + ::rtl::OUString m_sOpenRedlineIdentifier; + + uno::Reference<text::XText> m_xText; + uno::Reference<text::XTextCursor> m_xCursor; + uno::Reference<text::XTextRange> m_xCursorAsRange; + uno::Reference<container::XNameContainer> m_xParaStyles; + uno::Reference<container::XNameContainer> m_xTextStyles; + uno::Reference<container::XNameContainer> m_xNumStyles; + uno::Reference<container::XNameContainer> m_xFrameStyles; + uno::Reference<container::XNameContainer> m_xPageStyles; + uno::Reference<container::XIndexReplace> m_xChapterNumbering; + uno::Reference<container::XNameAccess> m_xTextFrames; + uno::Reference<container::XNameAccess> m_xGraphics; + uno::Reference<container::XNameAccess> m_xObjects; + uno::Reference<lang::XMultiServiceFactory> m_xServiceFactory; + + SvXMLImport & m_rSvXMLImport; + + bool m_bInsertMode : 1; + bool m_bStylesOnlyMode : 1; + bool m_bBlockMode : 1; + bool m_bProgress : 1; + bool m_bOrganizerMode : 1; + bool m_bBodyContentStarted : 1; + + // #107848# + // One more flag to remember if we are inside a deleted redline section + bool m_bInsideDeleteContext : 1; + + typedef ::std::pair< ::rtl::OUString, ::rtl::OUString> field_name_type_t; + typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > field_param_t; + typedef ::std::vector< field_param_t > field_params_t; + typedef ::std::pair< field_name_type_t, field_params_t > field_stack_item_t; + typedef ::std::stack< field_stack_item_t > field_stack_t; + + field_stack_t m_FieldStack; + + ::rtl::OUString m_sCellParaStyleDefault; + + Impl( uno::Reference<frame::XModel> const& rModel, + SvXMLImport & rImport, + bool const bInsertMode, bool const bStylesOnlyMode, + bool const bProgress, bool const bBlockMode, + bool const bOrganizerMode) + : m_pTextElemTokenMap( 0 ) + , m_pTextPElemTokenMap( 0 ) + , m_pTextPAttrTokenMap( 0 ) + , m_pTextFieldAttrTokenMap( 0 ) + , m_pTextNumberedParagraphAttrTokenMap( 0 ) + , m_pTextListBlockAttrTokenMap( 0 ) + , m_pTextListBlockElemTokenMap( 0 ) + , m_pTextFrameAttrTokenMap( 0 ) + , m_pTextContourAttrTokenMap( 0 ) + , m_pTextHyperlinkAttrTokenMap( 0 ) + , m_pTextMasterPageElemTokenMap( 0 ) + , m_pPrevFrmNames( 0 ) + , m_pNextFrmNames( 0 ) + // --> OD 2008-04-25 #refactorlists# + , m_pTextListsHelper( new XMLTextListsHelper() ) + // <-- + , m_pRenameMap( 0 ) + // --> OD 2006-10-12 #i69629# + , m_pOutlineStylesCandidates( 0 ) + // <-- + , m_xServiceFactory( rModel, UNO_QUERY ) + , m_rSvXMLImport( rImport ) + , m_bInsertMode( bInsertMode ) + , m_bStylesOnlyMode( bStylesOnlyMode ) + , m_bBlockMode( bBlockMode ) + , m_bProgress( bProgress ) + , m_bOrganizerMode( bOrganizerMode ) + , m_bBodyContentStarted( true ) + // #107848# Initialize inside_deleted_section flag correctly + , m_bInsideDeleteContext( false ) + { + } + + void InitOutlineStylesCandidates() + { + if (!m_pOutlineStylesCandidates) + { + size_t const size(m_xChapterNumbering->getCount()); + m_pOutlineStylesCandidates.reset( + new ::std::vector< ::rtl::OUString >[size] ); + } + } + +}; + + +uno::Reference< text::XText > & XMLTextImportHelper::GetText() +{ + return m_pImpl->m_xText; +} + +uno::Reference< text::XTextCursor > & XMLTextImportHelper::GetCursor() +{ + return m_pImpl->m_xCursor; +} + +uno::Reference< text::XTextRange > & XMLTextImportHelper::GetCursorAsRange() +{ + return m_pImpl->m_xCursorAsRange; +} + +bool XMLTextImportHelper::IsInsertMode() const +{ + return m_pImpl->m_bInsertMode; +} + +bool XMLTextImportHelper::IsStylesOnlyMode() const +{ + return m_pImpl->m_bStylesOnlyMode; +} + +bool XMLTextImportHelper::IsBlockMode() const +{ + return m_pImpl->m_bBlockMode; +} + +bool XMLTextImportHelper::IsOrganizerMode() const +{ + return m_pImpl->m_bOrganizerMode; +} + +bool XMLTextImportHelper::IsProgress() const +{ + return m_pImpl->m_bProgress; +} + +XMLSectionList_Impl & XMLTextImportHelper::GetSectionList() +{ + return m_pImpl->m_SectionList; +} + +uno::Reference<container::XNameContainer> const& +XMLTextImportHelper::GetParaStyles() const +{ + return m_pImpl->m_xParaStyles; +} + +uno::Reference<container::XNameContainer> const& +XMLTextImportHelper::GetTextStyles() const +{ + return m_pImpl->m_xTextStyles; +} + +uno::Reference<container::XNameContainer> const& +XMLTextImportHelper::GetNumberingStyles() const +{ + return m_pImpl->m_xNumStyles; +} + +uno::Reference<container::XNameContainer> const& +XMLTextImportHelper::GetFrameStyles() const +{ + return m_pImpl->m_xFrameStyles; +} + +uno::Reference<container::XNameContainer> const& +XMLTextImportHelper::GetPageStyles() const +{ + return m_pImpl->m_xPageStyles; +} + +uno::Reference<container::XIndexReplace> const& +XMLTextImportHelper::GetChapterNumbering() const +{ + return m_pImpl->m_xChapterNumbering; +} + +UniReference< SvXMLImportPropertyMapper > const& +XMLTextImportHelper::GetParaImportPropertySetMapper() const +{ + return m_pImpl->m_xParaImpPrMap; +} + +UniReference< SvXMLImportPropertyMapper > const& +XMLTextImportHelper::GetTextImportPropertySetMapper() const +{ + return m_pImpl->m_xTextImpPrMap; +} + +UniReference< SvXMLImportPropertyMapper > const& +XMLTextImportHelper::GetFrameImportPropertySetMapper() const +{ + return m_pImpl->m_xFrameImpPrMap; +} + +UniReference< SvXMLImportPropertyMapper > const& +XMLTextImportHelper::GetSectionImportPropertySetMapper() const +{ + return m_pImpl->m_xSectionImpPrMap; +} + +UniReference< SvXMLImportPropertyMapper > const& +XMLTextImportHelper::GetRubyImportPropertySetMapper() const +{ + return m_pImpl->m_xRubyImpPrMap; +} + +void XMLTextImportHelper::SetInsideDeleteContext(bool const bNew) +{ + m_pImpl->m_bInsideDeleteContext = bNew; +} + +bool XMLTextImportHelper::IsInsideDeleteContext() const +{ + return m_pImpl->m_bInsideDeleteContext; +} + +SvXMLImport & XMLTextImportHelper::GetXMLImport() +{ + return m_pImpl->m_rSvXMLImport; +} + +XMLTextListsHelper & XMLTextImportHelper::GetTextListHelper() +{ + return *m_pImpl->m_pTextListsHelper; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextElemTokenMap() +{ + if (!m_pImpl->m_pTextElemTokenMap.get()) + { + m_pImpl->m_pTextElemTokenMap.reset( + new SvXMLTokenMap( aTextElemTokenMap )); + } + return *m_pImpl->m_pTextElemTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextPElemTokenMap() +{ + if (!m_pImpl->m_pTextPElemTokenMap.get()) + { + m_pImpl->m_pTextPElemTokenMap.reset( + new SvXMLTokenMap( aTextPElemTokenMap )); + } + return *m_pImpl->m_pTextPElemTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextPAttrTokenMap() +{ + if (!m_pImpl->m_pTextPAttrTokenMap.get()) + { + m_pImpl->m_pTextPAttrTokenMap.reset( + new SvXMLTokenMap( aTextPAttrTokenMap )); + } + return *m_pImpl->m_pTextPAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextFrameAttrTokenMap() +{ + if (!m_pImpl->m_pTextFrameAttrTokenMap.get()) + { + m_pImpl->m_pTextFrameAttrTokenMap.reset( + new SvXMLTokenMap( aTextFrameAttrTokenMap )); + } + return *m_pImpl->m_pTextFrameAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextContourAttrTokenMap() +{ + if (!m_pImpl->m_pTextContourAttrTokenMap.get()) + { + m_pImpl->m_pTextContourAttrTokenMap.reset( + new SvXMLTokenMap( aTextContourAttrTokenMap )); + } + return *m_pImpl->m_pTextContourAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextHyperlinkAttrTokenMap() +{ + if (!m_pImpl->m_pTextHyperlinkAttrTokenMap.get()) + { + m_pImpl->m_pTextHyperlinkAttrTokenMap.reset( + new SvXMLTokenMap( aTextHyperlinkAttrTokenMap )); + } + return *m_pImpl->m_pTextHyperlinkAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextMasterPageElemTokenMap() +{ + if (!m_pImpl->m_pTextMasterPageElemTokenMap.get()) + { + m_pImpl->m_pTextMasterPageElemTokenMap.reset( + new SvXMLTokenMap( aTextMasterPageElemTokenMap )); + } + return *m_pImpl->m_pTextMasterPageElemTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextFieldAttrTokenMap() +{ + if (!m_pImpl->m_pTextFieldAttrTokenMap.get()) + { + m_pImpl->m_pTextFieldAttrTokenMap.reset( + new SvXMLTokenMap( aTextFieldAttrTokenMap )); + } + return *m_pImpl->m_pTextFieldAttrTokenMap; +} + + +namespace +{ + class FieldParamImporter + { + public: + typedef pair<OUString,OUString> field_param_t; + typedef vector<field_param_t> field_params_t; + FieldParamImporter(const field_params_t* const pInParams, Reference<XNameContainer> xOutParams) + : m_pInParams(pInParams) + , m_xOutParams(xOutParams) + { }; + void Import(); + + private: + const field_params_t* const m_pInParams; + Reference<XNameContainer> m_xOutParams; + }; + + void FieldParamImporter::Import() + { + ::std::vector<OUString> vListEntries; + ::std::map<OUString, Any> vOutParams; + for(field_params_t::const_iterator pCurrent = m_pInParams->begin(); + pCurrent != m_pInParams->end(); + ++pCurrent) + { + if(pCurrent->first.equalsAscii(ODF_FORMDROPDOWN_RESULT)) + { + // sal_Int32 + vOutParams[pCurrent->first] = makeAny(pCurrent->second.toInt32()); + } + else if(pCurrent->first.equalsAscii(ODF_FORMCHECKBOX_RESULT)) + { + // bool + vOutParams[pCurrent->first] = makeAny(pCurrent->second.toBoolean()); + } + else if(pCurrent->first.equalsAscii(ODF_FORMDROPDOWN_LISTENTRY)) + { + // sequence + vListEntries.push_back(pCurrent->second); + } + else + vOutParams[pCurrent->first] = makeAny(pCurrent->second); + } + if(!vListEntries.empty()) + { + Sequence<OUString> vListEntriesSeq(vListEntries.size()); + copy(vListEntries.begin(), vListEntries.end(), ::comphelper::stl_begin(vListEntriesSeq)); + vOutParams[OUString::createFromAscii(ODF_FORMDROPDOWN_LISTENTRY)] = makeAny(vListEntriesSeq); + } + for(::std::map<OUString, Any>::const_iterator pCurrent = vOutParams.begin(); + pCurrent != vOutParams.end(); + ++pCurrent) + { + try + { + m_xOutParams->insertByName(pCurrent->first, pCurrent->second); + } + catch(ElementExistException) + { } + } + } +} + +XMLTextImportHelper::XMLTextImportHelper( + uno::Reference<frame::XModel> const& rModel, + SvXMLImport& rImport, + bool const bInsertMode, bool const bStylesOnlyMode, + bool const bProgress, bool const bBlockMode, + bool const bOrganizerMode) + : m_pImpl( new Impl(rModel, rImport, bInsertMode, bStylesOnlyMode, + bProgress, bBlockMode, bOrganizerMode) ) + , m_pBackpatcherImpl( MakeBackpatcherImpl() ) +{ + static ::rtl::OUString s_PropNameDefaultListId( + RTL_CONSTASCII_USTRINGPARAM("DefaultListId")); + + Reference< XChapterNumberingSupplier > xCNSupplier( rModel, UNO_QUERY ); + + if( xCNSupplier.is() ) + { + m_pImpl->m_xChapterNumbering = xCNSupplier->getChapterNumberingRules(); + // --> OD 2008-05-15 #refactorlists# + if (m_pImpl->m_xChapterNumbering.is()) + { + Reference< XPropertySet > const xNumRuleProps( + m_pImpl->m_xChapterNumbering, UNO_QUERY); + if ( xNumRuleProps.is() ) + { + Reference< XPropertySetInfo > xNumRulePropSetInfo( + xNumRuleProps->getPropertySetInfo()); + if (xNumRulePropSetInfo.is() && + xNumRulePropSetInfo->hasPropertyByName( + s_PropNameDefaultListId)) + { + ::rtl::OUString sListId; + xNumRuleProps->getPropertyValue(s_PropNameDefaultListId) + >>= sListId; + DBG_ASSERT( sListId.getLength() != 0, + "no default list id found at chapter numbering rules instance. Serious defect -> please inform OD." ); + if ( sListId.getLength() ) + { + Reference< XNamed > const xChapterNumNamed( + m_pImpl->m_xChapterNumbering, UNO_QUERY); + if ( xChapterNumNamed.is() ) + { + m_pImpl->m_pTextListsHelper->KeepListAsProcessed( + sListId, + xChapterNumNamed->getName(), + ::rtl::OUString() ); + } + } + } + } + } + // <-- + } + + Reference< XStyleFamiliesSupplier > xFamiliesSupp( rModel, UNO_QUERY ); +// DBG_ASSERT( xFamiliesSupp.is(), "no chapter numbering supplier" ); for clipboard there may be documents without styles + + if( xFamiliesSupp.is() ) + { + Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies()); + + const OUString aParaStyles(RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles")); + if( xFamilies->hasByName( aParaStyles ) ) + { + m_pImpl->m_xParaStyles.set(xFamilies->getByName(aParaStyles), + UNO_QUERY); + } + + const OUString aCharStyles(RTL_CONSTASCII_USTRINGPARAM("CharacterStyles")); + if( xFamilies->hasByName( aCharStyles ) ) + { + m_pImpl->m_xTextStyles.set(xFamilies->getByName(aCharStyles), + UNO_QUERY); + } + + const OUString aNumStyles(RTL_CONSTASCII_USTRINGPARAM("NumberingStyles")); + if( xFamilies->hasByName( aNumStyles ) ) + { + m_pImpl->m_xNumStyles.set(xFamilies->getByName(aNumStyles), + UNO_QUERY); + } + + const OUString aFrameStyles(RTL_CONSTASCII_USTRINGPARAM("FrameStyles")); + if( xFamilies->hasByName( aFrameStyles ) ) + { + m_pImpl->m_xFrameStyles.set(xFamilies->getByName(aFrameStyles), + UNO_QUERY); + } + + const OUString aPageStyles(RTL_CONSTASCII_USTRINGPARAM("PageStyles")); + if( xFamilies->hasByName( aPageStyles ) ) + { + m_pImpl->m_xPageStyles.set(xFamilies->getByName(aPageStyles), + UNO_QUERY); + } + } + + Reference < XTextFramesSupplier > xTFS( rModel, UNO_QUERY ); + if( xTFS.is() ) + { + m_pImpl->m_xTextFrames.set(xTFS->getTextFrames()); + } + + Reference < XTextGraphicObjectsSupplier > xTGOS( rModel, UNO_QUERY ); + if( xTGOS.is() ) + { + m_pImpl->m_xGraphics.set(xTGOS->getGraphicObjects()); + } + + Reference < XTextEmbeddedObjectsSupplier > xTEOS( rModel, UNO_QUERY ); + if( xTEOS.is() ) + { + m_pImpl->m_xObjects.set(xTEOS->getEmbeddedObjects()); + } + + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA ); + m_pImpl->m_xParaImpPrMap = + new XMLTextImportPropertyMapper( pPropMapper, rImport ); + + pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT ); + m_pImpl->m_xTextImpPrMap = + new XMLTextImportPropertyMapper( pPropMapper, rImport ); + + pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME ); + m_pImpl->m_xFrameImpPrMap = + new XMLTextImportPropertyMapper( pPropMapper, rImport ); + + pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION ); + m_pImpl->m_xSectionImpPrMap = + new XMLTextImportPropertyMapper( pPropMapper, rImport ); + + pPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_RUBY ); + m_pImpl->m_xRubyImpPrMap = + new SvXMLImportPropertyMapper( pPropMapper, rImport ); +} + +XMLTextImportHelper::~XMLTextImportHelper() +{ +} + +SvXMLImportPropertyMapper *XMLTextImportHelper::CreateShapeExtPropMapper(SvXMLImport& rImport) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME ); + return new XMLTextImportPropertyMapper( pPropMapper, rImport, + const_cast<XMLFontStylesContext*>(rImport.GetFontDecls()) ); +} + +SvXMLImportPropertyMapper *XMLTextImportHelper::CreateCharExtPropMapper(SvXMLImport& rImport, XMLFontStylesContext *pFontDecls) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT ); + if (!pFontDecls) + pFontDecls = const_cast<XMLFontStylesContext*>(rImport.GetFontDecls()); + return new XMLTextImportPropertyMapper( pPropMapper, rImport, pFontDecls ); +} + +SvXMLImportPropertyMapper *XMLTextImportHelper::CreateParaExtPropMapper(SvXMLImport& rImport, XMLFontStylesContext *pFontDecls) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA ); + if (!pFontDecls) + pFontDecls = const_cast<XMLFontStylesContext*>(rImport.GetFontDecls()); + return new XMLTextImportPropertyMapper( pPropMapper, rImport, pFontDecls ); +} + +SvXMLImportPropertyMapper *XMLTextImportHelper::CreateParaDefaultExtPropMapper(SvXMLImport& rImport, XMLFontStylesContext* pFontDecls) +{ + if (!pFontDecls) + pFontDecls = const_cast<XMLFontStylesContext*>(rImport.GetFontDecls()); + + XMLPropertySetMapper* pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA ); + SvXMLImportPropertyMapper* pImportMapper = new XMLTextImportPropertyMapper( pPropMapper, rImport, pFontDecls ); + + pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT_ADDITIONAL_DEFAULTS ); + pImportMapper->ChainImportMapper( new XMLTextImportPropertyMapper( pPropMapper, rImport, pFontDecls ) ); + + return pImportMapper; +} + +SvXMLImportPropertyMapper* + XMLTextImportHelper::CreateTableDefaultExtPropMapper( + SvXMLImport& rImport, + XMLFontStylesContext* ) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TABLE_DEFAULTS ); + return new SvXMLImportPropertyMapper( pPropMapper, rImport ); +} + +SvXMLImportPropertyMapper* + XMLTextImportHelper::CreateTableRowDefaultExtPropMapper( + SvXMLImport& rImport, + XMLFontStylesContext* ) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TABLE_ROW_DEFAULTS ); + return new SvXMLImportPropertyMapper( pPropMapper, rImport ); +} + +void XMLTextImportHelper::SetCursor( const Reference < XTextCursor > & rCursor ) +{ + m_pImpl->m_xCursor.set(rCursor); + m_pImpl->m_xText.set(rCursor->getText()); + m_pImpl->m_xCursorAsRange.set( rCursor, UNO_QUERY ); +} + +void XMLTextImportHelper::ResetCursor() +{ + m_pImpl->m_xCursor.set(0); + m_pImpl->m_xText.set(0); + m_pImpl->m_xCursorAsRange.set(0); +} + + +sal_Bool XMLTextImportHelper::HasFrameByName( const OUString& rName ) const +{ + return (m_pImpl->m_xTextFrames.is() && + m_pImpl->m_xTextFrames->hasByName(rName)) + || (m_pImpl->m_xGraphics.is() && + m_pImpl->m_xGraphics->hasByName(rName)) + || (m_pImpl->m_xObjects.is() && + m_pImpl->m_xObjects->hasByName(rName)); +} + +void XMLTextImportHelper::InsertString( const OUString& rChars ) +{ + DBG_ASSERT(m_pImpl->m_xText.is(), "no text"); + DBG_ASSERT(m_pImpl->m_xCursorAsRange.is(), "no range"); + if (m_pImpl->m_xText.is()) + { + m_pImpl->m_xText->insertString(m_pImpl->m_xCursorAsRange, + rChars, sal_False); + } +} + +void XMLTextImportHelper::InsertString( const OUString& rChars, + sal_Bool& rIgnoreLeadingSpace ) +{ + DBG_ASSERT(m_pImpl->m_xText.is(), "no text"); + DBG_ASSERT(m_pImpl->m_xCursorAsRange.is(), "no range"); + if (m_pImpl->m_xText.is()) + { + sal_Int32 nLen = rChars.getLength(); + OUStringBuffer sChars( nLen ); + + for( sal_Int32 i=0; i < nLen; i++ ) + { + sal_Unicode c = rChars[i]; + switch( c ) + { + case 0x20: + case 0x09: + case 0x0a: + case 0x0d: + if( !rIgnoreLeadingSpace ) + sChars.append( (sal_Unicode)0x20 ); + rIgnoreLeadingSpace = sal_True; + break; + default: + rIgnoreLeadingSpace = sal_False; + sChars.append( c ); + break; + } + } + m_pImpl->m_xText->insertString(m_pImpl->m_xCursorAsRange, + sChars.makeStringAndClear(), sal_False); + } +} + +void XMLTextImportHelper::InsertControlCharacter( sal_Int16 nControl ) +{ + DBG_ASSERT(m_pImpl->m_xText.is(), "no text"); + DBG_ASSERT(m_pImpl->m_xCursorAsRange.is(), "no range"); + if (m_pImpl->m_xText.is()) + { + m_pImpl->m_xText->insertControlCharacter( + m_pImpl->m_xCursorAsRange, nControl, sal_False); + } +} + +void XMLTextImportHelper::InsertTextContent( + Reference < XTextContent > & xContent ) +{ + DBG_ASSERT(m_pImpl->m_xText.is(), "no text"); + DBG_ASSERT(m_pImpl->m_xCursorAsRange.is(), "no range"); + if (m_pImpl->m_xText.is()) + { + m_pImpl->m_xText->insertTextContent( + m_pImpl->m_xCursorAsRange, xContent, sal_False); + } +} + +void XMLTextImportHelper::DeleteParagraph() +{ + DBG_ASSERT(m_pImpl->m_xText.is(), "no text"); + DBG_ASSERT(m_pImpl->m_xCursor.is(), "no cursor"); + DBG_ASSERT(m_pImpl->m_xCursorAsRange.is(), "no range"); + + sal_Bool bDelete = sal_True; + Reference < XEnumerationAccess > const xEnumAccess( + m_pImpl->m_xCursor, UNO_QUERY); + if( xEnumAccess.is() ) + { + Reference < XEnumeration > xEnum(xEnumAccess->createEnumeration()); + DBG_ASSERT( xEnum->hasMoreElements(), "empty text enumeration" ); + if( xEnum->hasMoreElements() ) + { + Reference < XComponent > xComp( xEnum->nextElement(), UNO_QUERY ); + DBG_ASSERT( xComp.is(), "got no component" ); + if( xComp.is() ) + { + xComp->dispose(); + bDelete = sal_False; + } + } + } + if( bDelete ) + { + if (m_pImpl->m_xCursor->goLeft( 1, sal_True )) + { + OUString sEmpty; + m_pImpl->m_xText->insertString(m_pImpl->m_xCursorAsRange, + sEmpty, sal_True); + } + } +} + +OUString XMLTextImportHelper::ConvertStarFonts( const OUString& rChars, + const OUString& rStyleName, + sal_uInt8& rFlags, + sal_Bool bPara, + SvXMLImport& rImport ) const +{ + OUStringBuffer sChars( rChars ); + sal_Bool bConverted = sal_False; + for( sal_Int32 j=0; j<rChars.getLength(); j++ ) + { + sal_Unicode c = rChars[j]; + if( c >= 0xf000 && c <= 0xf0ff ) + { + if( (rFlags & CONV_STAR_FONT_FLAGS_VALID) == 0 ) + { + XMLTextStyleContext *pStyle = 0; + sal_uInt16 nFamily = bPara ? XML_STYLE_FAMILY_TEXT_PARAGRAPH + : XML_STYLE_FAMILY_TEXT_TEXT; + if (rStyleName.getLength() && m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( nFamily, rStyleName, + sal_True ); + pStyle = PTR_CAST( XMLTextStyleContext,pTempStyle); + } + + if( pStyle ) + { + sal_Int32 nCount = pStyle->_GetProperties().size(); + if( nCount ) + { + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles) + ->GetImportPropertyMapper(nFamily); + if( xImpPrMap.is() ) + { + UniReference<XMLPropertySetMapper> rPropMapper = + xImpPrMap->getPropertySetMapper(); + for( sal_Int32 i=0; i < nCount; i++ ) + { + const XMLPropertyState& rProp = pStyle->_GetProperties()[i]; + sal_Int32 nIdx = rProp.mnIndex; + sal_uInt32 nContextId = rPropMapper->GetEntryContextId(nIdx); + if( CTF_FONTFAMILYNAME == nContextId ) + { + rFlags &= ~(CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH); + OUString sFontName; + rProp.maValue >>= sFontName; + OUString sStarBats( RTL_CONSTASCII_USTRINGPARAM("StarBats" ) ); + OUString sStarMath( RTL_CONSTASCII_USTRINGPARAM("StarMath" ) ); + if( sFontName.equalsIgnoreAsciiCase( sStarBats ) ) + rFlags |= CONV_FROM_STAR_BATS; + else if( sFontName.equalsIgnoreAsciiCase( sStarMath ) ) + rFlags |= CONV_FROM_STAR_MATH; + break; + } + } + } + } + + } + + rFlags |= CONV_STAR_FONT_FLAGS_VALID; + } + if( (rFlags & CONV_FROM_STAR_BATS ) != 0 ) + { + sChars.setCharAt( j, rImport.ConvStarBatsCharToStarSymbol( c ) ); + bConverted = sal_True; + } + else if( (rFlags & CONV_FROM_STAR_MATH ) != 0 ) + { + sChars.setCharAt( j, rImport.ConvStarMathCharToStarSymbol( c ) ); + bConverted = sal_True; + } + } + } + + return bConverted ? sChars.makeStringAndClear() : rChars; +} + +// --> OD 2006-10-12 #i69629# +// helper method to determine, if a paragraph style has a list style (inclusive +// an empty one) inherits a list style (inclusive an empty one) from one of its parents +// --> OD 2007-01-29 #i73973# +// apply special case, that found list style equals the chapter numbering, also +// to the found list styles of the parent styles. +sal_Bool lcl_HasListStyle( OUString sStyleName, + const Reference < XNameContainer >& xParaStyles, + SvXMLImport& rImport, + const OUString& sNumberingStyleName, + const OUString& sOutlineStyleName ) +{ + sal_Bool bRet( sal_False ); + + if ( !xParaStyles->hasByName( sStyleName ) ) + { + // error case + return sal_True; + } + + Reference< XPropertyState > xPropState( xParaStyles->getByName( sStyleName ), + UNO_QUERY ); + if ( !xPropState.is() ) + { + // error case + return sal_False; + } + + if ( xPropState->getPropertyState( sNumberingStyleName ) == PropertyState_DIRECT_VALUE ) + { + // list style found + bRet = sal_True; + // special case: the set list style equals the chapter numbering + Reference< XPropertySet > xPropSet( xPropState, UNO_QUERY ); + if ( xPropSet.is() ) + { + OUString sListStyle; + xPropSet->getPropertyValue( sNumberingStyleName ) >>= sListStyle; + if ( sListStyle.getLength() != 0 && + sListStyle == sOutlineStyleName ) + { + bRet = sal_False; + } + } + } + else + { + // --> OD 2007-12-07 #i77708# + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + // --> OD 2008-03-19 #i86058# +// rImport.getBuildIds( nUPD, nBuild ); + const bool bBuildIdFound = rImport.getBuildIds( nUPD, nBuild ); + // <-- + // <-- + // search list style at parent + Reference<XStyle> xStyle( xPropState, UNO_QUERY ); + while ( xStyle.is() ) + { + OUString aParentStyle( xStyle->getParentStyle() ); + if ( aParentStyle.getLength() > 0 ) + { + aParentStyle = + rImport.GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_PARAGRAPH, + aParentStyle ); + } + if ( aParentStyle.getLength() == 0 || + !xParaStyles->hasByName( aParentStyle ) ) + { + // no list style found + break; + } + else + { + xPropState = Reference< XPropertyState >( + xParaStyles->getByName( aParentStyle ), + UNO_QUERY ); + if ( !xPropState.is() ) + { + // error case + return sal_True; + } + if ( xPropState->getPropertyState( sNumberingStyleName ) == PropertyState_DIRECT_VALUE ) + { + // list style found + bRet = sal_True; + // --> OD 2007-01-29 #i73973# + // special case: the found list style equals the chapter numbering + Reference< XPropertySet > xPropSet( xPropState, UNO_QUERY ); + if ( xPropSet.is() ) + { + OUString sListStyle; + xPropSet->getPropertyValue( sNumberingStyleName ) >>= sListStyle; + if ( sListStyle.getLength() != 0 && + sListStyle == sOutlineStyleName ) + { + bRet = sal_False; + } + // --> OD 2007-12-07 #i77708# + // special handling for text documents from OOo version prior OOo 2.4 + // --> OD 2008-03-19 #i86058# + // check explicitly on certain versions and on import of + // text documents in OpenOffice.org file format + else if ( sListStyle.getLength() == 0 && + ( rImport.IsTextDocInOOoFileFormat() || + ( bBuildIdFound && + ( ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0 + ( nUPD == 680 && nBuild <= 9238 ) ) ) ) ) // OOo 2.0 - OOo 2.3.1 + { + bRet = sal_False; + } + // <-- + } + // <-- + break; + } + else + { + // search list style at parent + xStyle = Reference<XStyle>( xPropState, UNO_QUERY ); + } + } + } + } + + return bRet; +} +// <-- +OUString XMLTextImportHelper::SetStyleAndAttrs( + SvXMLImport& rImport, + const Reference < XTextCursor >& rCursor, + const OUString& rStyleName, + sal_Bool bPara, + sal_Bool bOutlineLevelAttrFound, + sal_Int8 nOutlineLevel, + // --> OD 2007-08-17 #i80724# + sal_Bool bSetListAttrs ) + // <-- +{ + static ::rtl::OUString s_ParaStyleName( + RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")); + static ::rtl::OUString s_CharStyleName( + RTL_CONSTASCII_USTRINGPARAM("CharStyleName")); + static ::rtl::OUString s_NumberingRules( + RTL_CONSTASCII_USTRINGPARAM("NumberingRules")); + static ::rtl::OUString s_NumberingIsNumber( + RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber")); + static ::rtl::OUString s_NumberingLevel( + RTL_CONSTASCII_USTRINGPARAM("NumberingLevel")); + static ::rtl::OUString s_ParaIsNumberingRestart( + RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart")); + static ::rtl::OUString s_NumberingStartValue( + RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue")); + static ::rtl::OUString s_PropNameListId( + RTL_CONSTASCII_USTRINGPARAM("ListId")); + static ::rtl::OUString s_PageDescName( + RTL_CONSTASCII_USTRINGPARAM("PageDescName")); + static ::rtl::OUString s_ServiceCombinedCharacters( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.text.TextField.CombinedCharacters")); + static ::rtl::OUString s_Content(RTL_CONSTASCII_USTRINGPARAM("Content")); + static ::rtl::OUString s_OutlineLevel( + RTL_CONSTASCII_USTRINGPARAM("OutlineLevel")); + static ::rtl::OUString s_NumberingStyleName( + RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName")); + + const sal_uInt16 nFamily = bPara ? XML_STYLE_FAMILY_TEXT_PARAGRAPH + : XML_STYLE_FAMILY_TEXT_TEXT; + XMLTextStyleContext *pStyle = 0; + OUString sStyleName( rStyleName ); + if (sStyleName.getLength() && m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( nFamily, sStyleName, sal_True ); + pStyle = PTR_CAST( XMLTextStyleContext,pTempStyle); + } + if( pStyle ) + sStyleName = pStyle->GetParentName(); + + Reference < XPropertySet > xPropSet( rCursor, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo( + xPropSet->getPropertySetInfo()); + + // style + if( sStyleName.getLength() ) + { + sStyleName = rImport.GetStyleDisplayName( nFamily, sStyleName ); + const String& rPropName = (bPara) ? s_ParaStyleName : s_CharStyleName; + const Reference < XNameContainer > & rStyles = (bPara) + ? m_pImpl->m_xParaStyles + : m_pImpl->m_xTextStyles; + if( rStyles.is() && + xPropSetInfo->hasPropertyByName( rPropName ) && + rStyles->hasByName( sStyleName ) ) + { + xPropSet->setPropertyValue( rPropName, makeAny(sStyleName) ); + } + else + sStyleName = OUString(); + } + + // --> OD 2008-09-10 #i70748# + // The outline level needs to be only applied as list level, if the heading + // is not inside a list and if it by default applies the outline style. + bool bApplyOutlineLevelAsListLevel( false ); + // --> OD 2007-08-17 #i80724# + if (bSetListAttrs && bPara + && xPropSetInfo->hasPropertyByName( s_NumberingRules)) + // <-- + { + // Set numbering rules + Reference< XIndexReplace > const xNumRules( + xPropSet->getPropertyValue(s_NumberingRules), UNO_QUERY); + + XMLTextListBlockContext * pListBlock(0); + XMLTextListItemContext * pListItem(0); + XMLNumberedParaContext * pNumberedParagraph(0); + GetTextListHelper().ListContextTop( + pListBlock, pListItem, pNumberedParagraph); + + OSL_ENSURE(!(pListBlock && pNumberedParagraph), "XMLTextImportHelper::" + "SetStyleAndAttrs: both list and numbered-paragraph???"); + + Reference < XIndexReplace > xNewNumRules; + sal_Int8 nLevel(-1); + ::rtl::OUString sListId; + sal_Int16 nStartValue(-1); + bool bNumberingIsNumber(true); + + if (pListBlock) { + + if (!pListItem) { + bNumberingIsNumber = false; // list-header + } + // --> OD 2008-05-08 #refactorlists# + // consider text:style-override property of <text:list-item> + xNewNumRules.set( + (pListItem != 0 && pListItem->HasNumRulesOverride()) + ? pListItem->GetNumRulesOverride() + : pListBlock->GetNumRules() ); + // <-- + nLevel = static_cast<sal_Int8>(pListBlock->GetLevel()); + + if ( pListItem && pListItem->HasStartValue() ) { + nStartValue = pListItem->GetStartValue(); + } + + // --> OD 2008-08-15 #i92811# + sListId = m_pImpl->m_pTextListsHelper->GetListIdForListBlock( + *pListBlock); + // <-- + } + else if (pNumberedParagraph) + { + xNewNumRules.set(pNumberedParagraph->GetNumRules()); + nLevel = static_cast<sal_Int8>(pNumberedParagraph->GetLevel()); + sListId = pNumberedParagraph->GetListId(); + nStartValue = pNumberedParagraph->GetStartValue(); + } + + + if (pListBlock || pNumberedParagraph) + { + // --> OD 2009-08-24 #i101349# + // Assure that list style of automatic paragraph style is applied at paragraph. + sal_Bool bApplyNumRules = pStyle && pStyle->IsListStyleSet(); + if ( !bApplyNumRules ) + { + sal_Bool bSameNumRules = xNewNumRules == xNumRules; + if( !bSameNumRules && xNewNumRules.is() && xNumRules.is() ) + { + // If the interface pointers are different then this does + // not mean that the num rules are different. Further tests + // are required then. However, if only one num rule is + // set, no tests are required of course. + Reference< XNamed > xNewNamed( xNewNumRules, UNO_QUERY ); + Reference< XNamed > xNamed( xNumRules, UNO_QUERY ); + if( xNewNamed.is() && xNamed.is() ) + { + bSameNumRules = xNewNamed->getName() == xNamed->getName(); + } + else + { + Reference< XAnyCompare > xNumRuleCompare( xNumRules, UNO_QUERY ); + if( xNumRuleCompare.is() ) + { + bSameNumRules = (xNumRuleCompare->compare( Any(xNumRules), Any(xNewNumRules) ) == 0); + } + } + } + bApplyNumRules = !bSameNumRules; + } + + if ( bApplyNumRules ) + // <-- + { + // #102607# This may except when xNewNumRules contains + // a Writer-NumRule-Implementation bug gets applied to + // a shape. Since this may occur inside a document + // (e.g. when edited), this must be handled + // gracefully. + try + { + xPropSet->setPropertyValue( + s_NumberingRules, makeAny(xNewNumRules) ); + } + catch( Exception e ) + { + ; // I would really like to use a warning here, + // but I can't access the XMLErrorHandler from + // here. + } + } + + if (!bNumberingIsNumber && + xPropSetInfo->hasPropertyByName(s_NumberingIsNumber)) + { + xPropSet->setPropertyValue(s_NumberingIsNumber, Any(sal_False)); + } + + xPropSet->setPropertyValue( s_NumberingLevel, Any(nLevel) ); + + if( pListBlock && pListBlock->IsRestartNumbering() ) + { + // TODO: property missing + if (xPropSetInfo->hasPropertyByName(s_ParaIsNumberingRestart)) + { + sal_Bool bTmp = sal_True; + xPropSet->setPropertyValue(s_ParaIsNumberingRestart, + makeAny(bTmp) ); + } + pListBlock->ResetRestartNumbering(); + } + + if ( 0 <= nStartValue && + xPropSetInfo->hasPropertyByName(s_NumberingStartValue)) + { + xPropSet->setPropertyValue(s_NumberingStartValue, + makeAny(nStartValue)); + } + + // --> OD 2008-04-23 #refactorlists# + if (xPropSetInfo->hasPropertyByName(s_PropNameListId)) + { + if (sListId.getLength()) { + xPropSet->setPropertyValue(s_PropNameListId, + makeAny(sListId) ); + } + } + // <-- + + GetTextListHelper().SetListItem( (XMLTextListItemContext *)0 ); + } + else + { + // If the paragraph is not in a list but its style, remove it from + // the list. + // --> OD 2005-10-25 #126347# - do not remove it, if the list + // of the style is the chapter numbering rule. + if( xNumRules.is() ) + { + bool bRemove( true ); + // --> OD 2008-12-17 #i70748# - special handling for document from OOo 2.x + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + const bool bBuildIdFound = rImport.getBuildIds( nUPD, nBuild ); + DBG_ASSERT( ( bBuildIdFound && nUPD == 680 ) || + !pStyle || + !pStyle->IsListStyleSet() || + pStyle->GetListStyle().getLength() == 0, + "automatic paragraph style with list style name, but paragraph not in list???" ); + if ( ( bBuildIdFound && nUPD == 680 ) || + !pStyle || !pStyle->IsListStyleSet() ) + { + if (m_pImpl->m_xChapterNumbering.is()) + { + Reference< XNamed > xNumNamed( xNumRules, UNO_QUERY ); + Reference< XNamed > const xChapterNumNamed ( + m_pImpl->m_xChapterNumbering, UNO_QUERY); + if ( xNumNamed.is() && xChapterNumNamed.is() && + xNumNamed->getName() == xChapterNumNamed->getName() ) + { + bRemove = false; + // --> OD 2008-09-10 #i70748# + bApplyOutlineLevelAsListLevel = true; + // <-- + } + } + } + // <-- + if ( bRemove ) + { + xPropSet->setPropertyValue( s_NumberingRules, Any() ); + } + } + // <-- + } + } + + // hard paragraph properties + if( pStyle ) + { + pStyle->FillPropertySet( xPropSet ); + if( bPara && pStyle->HasMasterPageName() && + xPropSetInfo->hasPropertyByName(s_PageDescName)) + { + OUString sDisplayName( + rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_MASTER_PAGE, + pStyle->GetMasterPageName()) ); + if( !sDisplayName.getLength() || + (m_pImpl->m_xPageStyles.is() && + m_pImpl->m_xPageStyles->hasByName( sDisplayName))) + { + xPropSet->setPropertyValue(s_PageDescName, + makeAny(sDisplayName)); + } + } + if( bPara && pStyle->GetDropCapStyleName().getLength() && + m_pImpl->m_xTextStyles.is()) + { + OUString sDisplayName( + rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, + pStyle->GetDropCapStyleName()) ); + if (m_pImpl->m_xTextStyles->hasByName(sDisplayName) && + xPropSetInfo->hasPropertyByName( sDisplayName ) ) + { + xPropSet->setPropertyValue( pStyle->sDropCapCharStyleName, makeAny(sDisplayName) ); + } + } + + // combined characters special treatment + if (!bPara && pStyle->HasCombinedCharactersLetter()) + { + // insert combined characters text field + if (m_pImpl->m_xServiceFactory.is()) + { + uno::Reference<beans::XPropertySet> const xTmp( + m_pImpl->m_xServiceFactory->createInstance( + s_ServiceCombinedCharacters), UNO_QUERY); + if( xTmp.is() ) + { + // fix cursor if larger than possible for + // combined characters field + if (rCursor->getString().getLength() > + MAX_COMBINED_CHARACTERS) + { + rCursor->gotoRange(rCursor->getStart(), sal_False); + rCursor->goRight(MAX_COMBINED_CHARACTERS, sal_True); + } + + // set field value (the combined character string) + xTmp->setPropertyValue(s_Content, + makeAny(rCursor->getString())); + + // insert the field over it's original text + Reference<XTextRange> xRange(rCursor, UNO_QUERY); + Reference<XTextContent> xTextContent(xTmp, UNO_QUERY); + if (m_pImpl->m_xText.is() && xRange.is()) + { + // #i107225# the combined characters need to be inserted first + // the selected text has to be removed afterwards + m_pImpl->m_xText->insertTextContent( xRange->getStart(), xTextContent, sal_True ); + + if( xRange->getString().getLength() ) + { + try + { + uno::Reference< text::XTextCursor > xCrsr = xRange->getText()->createTextCursorByRange( xRange->getStart() ); + xCrsr->goLeft( 1, true ); + uno::Reference< beans::XPropertySet> xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW ); + //the hard properties of the removed text need to be applied to the combined characters field + pStyle->FillPropertySet( xCrsrProperties ); + xCrsr->collapseToEnd(); + xCrsr->gotoRange( xRange->getEnd(), true ); + xCrsr->setString( ::rtl::OUString() ); + } + catch( const uno::Exception& rEx ) + { + (void)rEx; + } + } + } + } + } + } + } + + // outline level; set after list style has been set + // --> OD 2005-08-25 #i53198# + // Complete re-worked and corrected: + // - set outline level at paragraph + // - set numbering level at paragraph, if none is already set + // - assure that style is marked as an outline style for the corresponding + // outline level. + // - DO NOT set type of numbering rule to outline. + // - DO NOT set numbering rule directly at the paragraph. + + // --> OD 2008-12-09 #i70748# + // Some minor rework and adjust access to paragraph styles + if ( bPara ) + { + // --> OD 2009-08-18 #i103817# + sal_Int16 nCurrentOutlineLevelInheritedFromParagraphStyle = 0; + const bool bHasOutlineLevelProp( + xPropSetInfo->hasPropertyByName(s_OutlineLevel)); + if ( bHasOutlineLevelProp ) + { + xPropSet->getPropertyValue(s_OutlineLevel) + >>= nCurrentOutlineLevelInheritedFromParagraphStyle; + } + // <-- + //if ( bPara && nOutlineLevel != -1 ) //#outline level,removed by zhaojianwei + if ( nOutlineLevel > 0 ) //add by zhaojianwei + { + //#outline level,removed by zhaojianwei + if ( bHasOutlineLevelProp ) + { + // In case that the value equals the value of its paragraph style + // attribute outline level, the paragraph attribute value is left unset + if ( nCurrentOutlineLevelInheritedFromParagraphStyle != nOutlineLevel ) + { + xPropSet->setPropertyValue( s_OutlineLevel, + makeAny( static_cast<sal_Int16>(nOutlineLevel) ) ); + } + }//<-end,zhaojianwei + + // --> OD 2008-09-10 #i70748# + if ( bApplyOutlineLevelAsListLevel ) + { + sal_Int16 nNumLevel = -1; + xPropSet->getPropertyValue( s_NumberingLevel ) >>= nNumLevel; + if ( nNumLevel == -1 || + nNumLevel != (nOutlineLevel - 1) ) + { + xPropSet->setPropertyValue( s_NumberingLevel, + makeAny( static_cast<sal_Int8>(nOutlineLevel - 1) ) ); + } + } + // <-- + // --> OD 2006-10-13 #i69629# - correction: + // - for text document from version OOo 2.0.4/SO 8 PU4 and earlier + // the paragraph style of a heading should be assigned to the + // corresponding list level of the outline style. + // - for other text documents the paragraph style of a heading is only + // a candidate for an assignment to the list level of the outline + // style, if it has no direct list style property and (if exists) the + // automatic paragraph style has also no direct list style set. + if (m_pImpl->m_xParaStyles->hasByName(sStyleName)) + { + bool bOutlineStyleCandidate( false ); + + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + // --> OD 2007-12-19 #152540# + const bool bBuildIdFound = rImport.getBuildIds( nUPD, nBuild ); + // --> OD 2007-07-25 #i73509# + // --> OD 2008-03-19 #i86058# - check explicitly on certain versions + if ( rImport.IsTextDocInOOoFileFormat() || + ( bBuildIdFound && + ( nUPD == 645 || nUPD == 641 ) ) ) + { + bOutlineStyleCandidate = true; + } + else if ( nUPD == 680 && nBuild <= 9073 ) /* BuildId of OOo 2.0.4/SO8 PU4 */ + { + bOutlineStyleCandidate = bOutlineLevelAttrFound; + } + // <-- +// else +// { +// Reference< XPropertyState > xStylePropState( +// xParaStyles->getByName( sStyleName ), UNO_QUERY ); +// if ( xStylePropState.is() && +// xStylePropState->getPropertyState( sNumberingStyleName ) == PropertyState_DIRECT_VALUE ) +// { +// bOutlineStyleCandidate = false; +// } +// // --> OD 2007-01-11 #i73361# +// // The automatic paragraph style doesn't have to be considered. +// // else if ( pStyle && /* automatic paragraph style */ +// // pStyle->IsListStyleSet() ) +// // { +// // bOutlineStyleCandidate = false; +// // } +// // <-- +// else +// { +// bOutlineStyleCandidate = true; +// } +// } + + if ( bOutlineStyleCandidate ) + { + AddOutlineStyleCandidate( nOutlineLevel, sStyleName ); + } + // --> OD 2009-08-18 #i103817# + // Assure that heading applies the outline style + if ( ( !pStyle || !pStyle->IsListStyleSet() ) && + !bOutlineStyleCandidate && + m_pImpl->m_xChapterNumbering.is()) + { + OUString sEmptyStr; + if ( !lcl_HasListStyle( sStyleName, + m_pImpl->m_xParaStyles, GetXMLImport(), + s_NumberingStyleName, + sEmptyStr ) ) + { + // heading not in a list --> apply outline style + xPropSet->setPropertyValue( s_NumberingRules, + makeAny(m_pImpl->m_xChapterNumbering) ); + xPropSet->setPropertyValue( s_NumberingLevel, + makeAny(static_cast<sal_Int8>(nOutlineLevel - 1))); + } + } + // <-- + } + // <-- + } + //-> #outlinelevel added by zhaojianwei + //handle for text:p,if the paragraphstyle outlinelevel is set to[1~10] + else if( bHasOutlineLevelProp ) + { + if ( nCurrentOutlineLevelInheritedFromParagraphStyle != 0 ) + { + sal_Int16 nZero = 0; + xPropSet->setPropertyValue(s_OutlineLevel, + makeAny( static_cast<sal_Int16>(nZero) )); + } + }//<-end,zhaojianwei + } + // <-- + + return sStyleName; +} + +void XMLTextImportHelper::FindOutlineStyleName( ::rtl::OUString& rStyleName, + sal_Int8 nOutlineLevel ) +{ + static ::rtl::OUString s_HeadingStyleName( + RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName")); + + // style name empty? + if( rStyleName.getLength() == 0 ) + { + // Empty? Then we need o do stuff. Let's do error checking first. + if (m_pImpl->m_xChapterNumbering.is() && + ( nOutlineLevel > 0 ) && + (nOutlineLevel <= m_pImpl->m_xChapterNumbering->getCount())) + { + nOutlineLevel--; // for the remainder, the level's are 0-based + + // empty style name: look-up previously used name + + // if we don't have a previously used name, we'll use the default + m_pImpl->InitOutlineStylesCandidates(); + if (m_pImpl->m_pOutlineStylesCandidates[nOutlineLevel].empty()) + { + // no other name used previously? Then use default + + // iterate over property value sequence to find the style name + Sequence<PropertyValue> aProperties; + m_pImpl->m_xChapterNumbering->getByIndex( nOutlineLevel ) + >>= aProperties; + for( sal_Int32 i = 0; i < aProperties.getLength(); i++ ) + { + if (aProperties[i].Name == s_HeadingStyleName) + { + rtl::OUString aOutlineStyle; + aProperties[i].Value >>= aOutlineStyle; + m_pImpl->m_pOutlineStylesCandidates[nOutlineLevel] + .push_back( aOutlineStyle ); + break; // early out, if we found it!. + } + } + } + + // finally, we'll use the previously used style name for this + // format (or the default we've just put into that style) + // --> OD 2006-11-06 #i71249# - take last added one + rStyleName = + m_pImpl->m_pOutlineStylesCandidates[nOutlineLevel].back(); + // <-- + } + // else: nothing we can do, so we'll leave it empty + } + // else: we already had a style name, so we let it pass. +} + +void XMLTextImportHelper::AddOutlineStyleCandidate( const sal_Int8 nOutlineLevel, + const OUString& rStyleName ) +{ + if (rStyleName.getLength() + && m_pImpl->m_xChapterNumbering.is() + && (nOutlineLevel > 0) + && (nOutlineLevel <= m_pImpl->m_xChapterNumbering->getCount())) + { + m_pImpl->InitOutlineStylesCandidates(); + m_pImpl->m_pOutlineStylesCandidates[nOutlineLevel-1].push_back( + rStyleName); + } +} + +void XMLTextImportHelper::SetOutlineStyles( sal_Bool bSetEmptyLevels ) +{ + static ::rtl::OUString s_NumberingStyleName( + RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName")); + static ::rtl::OUString s_HeadingStyleName( + RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName")); + + if ((m_pImpl->m_pOutlineStylesCandidates != NULL || bSetEmptyLevels) && + m_pImpl->m_xChapterNumbering.is() && + !IsInsertMode()) + { + bool bChooseLastOne( false ); + { + if ( GetXMLImport().IsTextDocInOOoFileFormat() ) + { + bChooseLastOne = true; + } + else + { + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + if ( GetXMLImport().getBuildIds( nUPD, nBuild ) ) + { + // check explicitly on certain versions + bChooseLastOne = ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0 + ( nUPD == 680 && nBuild <= 9073 ); // OOo 2.0 - OOo 2.0.4 + } + } + } + + OUString sOutlineStyleName; + { + Reference<XPropertySet> xChapterNumRule( + m_pImpl->m_xChapterNumbering, UNO_QUERY); + const OUString sName(RTL_CONSTASCII_USTRINGPARAM("Name")); + xChapterNumRule->getPropertyValue(sName) >>= sOutlineStyleName; + } + + const sal_Int32 nCount = m_pImpl->m_xChapterNumbering->getCount(); + // --> OD 2009-11-13 #i106218# + // First collect all paragraph styles choosen for assignment to each + // list level of the outline style, then perform the intrinsic assignment. + // Reason: The assignment of a certain paragraph style to a list level + // of the outline style causes side effects on the children + // paragraph styles in Writer. + ::std::vector<OUString> sChosenStyles(nCount); + // <-- + for( sal_Int32 i=0; i < nCount; ++i ) + { + if ( bSetEmptyLevels || + (m_pImpl->m_pOutlineStylesCandidates && + !m_pImpl->m_pOutlineStylesCandidates[i].empty())) + { + // determine, which candidate is one to be assigned to the list + // level of the outline style + if (m_pImpl->m_pOutlineStylesCandidates && + !m_pImpl->m_pOutlineStylesCandidates[i].empty()) + { + if ( bChooseLastOne ) + { + sChosenStyles[i] = + m_pImpl->m_pOutlineStylesCandidates[i].back(); + } + else + { + for (sal_uInt32 j = 0; + j < m_pImpl->m_pOutlineStylesCandidates[i].size(); + ++j) + { + if (!lcl_HasListStyle( + m_pImpl->m_pOutlineStylesCandidates[i][j], + m_pImpl->m_xParaStyles, GetXMLImport(), + s_NumberingStyleName, + sOutlineStyleName)) + { + sChosenStyles[i] = + m_pImpl->m_pOutlineStylesCandidates[i][j]; + break; + } + } + } + } + } + } + // --> OD 2009-11-13 #i106218# + Sequence < PropertyValue > aProps( 1 ); + PropertyValue *pProps = aProps.getArray(); + pProps->Name = s_HeadingStyleName; + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + // --> OD 2009-12-11 #i107610# + if ( bSetEmptyLevels || + sChosenStyles[i].getLength() > 0 ) + // <-- + { + pProps->Value <<= sChosenStyles[i]; + m_pImpl->m_xChapterNumbering->replaceByIndex(i, + makeAny( aProps )); + } + } + // <-- + } +} + +void XMLTextImportHelper::SetHyperlink( + SvXMLImport& rImport, + const Reference < XTextCursor >& rCursor, + const OUString& rHRef, + const OUString& rName, + const OUString& rTargetFrameName, + const OUString& rStyleName, + const OUString& rVisitedStyleName, + XMLEventsImportContext* pEvents) +{ + static ::rtl::OUString s_HyperLinkURL( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")); + static ::rtl::OUString s_HyperLinkName( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")); + static ::rtl::OUString s_HyperLinkTarget( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")); + static ::rtl::OUString s_UnvisitedCharStyleName( + RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")); + static ::rtl::OUString s_VisitedCharStyleName( + RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")); + static ::rtl::OUString s_HyperLinkEvents( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkEvents")); + + Reference < XPropertySet > xPropSet( rCursor, UNO_QUERY ); + Reference < XPropertySetInfo > xPropSetInfo( + xPropSet->getPropertySetInfo()); + if (!xPropSetInfo.is() || !xPropSetInfo->hasPropertyByName(s_HyperLinkURL)) + return; + + xPropSet->setPropertyValue(s_HyperLinkURL, makeAny(rHRef)); + + if (xPropSetInfo->hasPropertyByName(s_HyperLinkName)) + { + xPropSet->setPropertyValue(s_HyperLinkName, makeAny(rName)); + } + + if (xPropSetInfo->hasPropertyByName(s_HyperLinkTarget)) + { + xPropSet->setPropertyValue(s_HyperLinkTarget, + makeAny(rTargetFrameName)); + } + + if ( (pEvents != NULL) && + xPropSetInfo->hasPropertyByName(s_HyperLinkEvents)) + { + // The API treats events at hyperlinks differently from most + // other properties: You have to set a name replace with the + // events in it. The easiest way to to this is to 1) get + // events, 2) set new ones, and 3) then put events back. + uno::Reference<XNameReplace> const xReplace( + xPropSet->getPropertyValue(s_HyperLinkEvents), UNO_QUERY); + if (xReplace.is()) + { + // set events + pEvents->SetEvents(xReplace); + + // put events + xPropSet->setPropertyValue(s_HyperLinkEvents, makeAny(xReplace)); + } + } + + if (m_pImpl->m_xTextStyles.is()) + { + OUString sDisplayName( + rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, rStyleName ) ); + if( sDisplayName.getLength() && + xPropSetInfo->hasPropertyByName(s_UnvisitedCharStyleName) && + m_pImpl->m_xTextStyles->hasByName(sDisplayName)) + { + xPropSet->setPropertyValue(s_UnvisitedCharStyleName, + makeAny(sDisplayName)); + } + + sDisplayName = + rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, rVisitedStyleName ); + if( sDisplayName.getLength() && + xPropSetInfo->hasPropertyByName(s_VisitedCharStyleName) && + m_pImpl->m_xTextStyles->hasByName(sDisplayName)) + { + xPropSet->setPropertyValue(s_VisitedCharStyleName, + makeAny(sDisplayName)); + } + } +} + +void XMLTextImportHelper::SetRuby( + SvXMLImport& rImport, + const Reference < XTextCursor >& rCursor, + const OUString& rStyleName, + const OUString& rTextStyleName, + const OUString& rText ) +{ + Reference<XPropertySet> xPropSet(rCursor, UNO_QUERY); + + OUString sRubyText(RTL_CONSTASCII_USTRINGPARAM("RubyText")); + OUString sRubyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("RubyCharStyleName")); + + // if we have one Ruby property, we assume all of them are present + if (xPropSet.is() && + xPropSet->getPropertySetInfo()->hasPropertyByName( sRubyText )) + { + // the ruby text + xPropSet->setPropertyValue(sRubyText, makeAny(rText)); + + // the ruby style (ruby-adjust) + XMLPropStyleContext *pStyle = 0; + if (rStyleName.getLength() && m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( XML_STYLE_FAMILY_TEXT_RUBY, + rStyleName, sal_True ); + pStyle = PTR_CAST(XMLPropStyleContext,pTempStyle); + + if (NULL != pStyle) + pStyle->FillPropertySet( xPropSet ); + } + + // the ruby text character style + if (m_pImpl->m_xTextStyles.is()) + { + OUString sDisplayName( + rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, rTextStyleName ) ); + if( (sDisplayName.getLength() > 0) && +// xPropSetInfo->hasPropertyByName( sRubyCharStyleName ) && + m_pImpl->m_xTextStyles->hasByName( sDisplayName )) + { + xPropSet->setPropertyValue(sRubyCharStyleName, makeAny(sDisplayName)); + } + } + } +} + +void XMLTextImportHelper::SetAutoStyles( SvXMLStylesContext *pStyles ) +{ + m_pImpl->m_xAutoStyles = pStyles; +} + +void XMLTextImportHelper::SetFontDecls( XMLFontStylesContext *pFontDecls ) +{ + m_pImpl->m_xFontDecls = pFontDecls; + ((XMLTextImportPropertyMapper *)m_pImpl->m_xParaImpPrMap.get()) + ->SetFontDecls( pFontDecls ); + ((XMLTextImportPropertyMapper *)m_pImpl->m_xTextImpPrMap.get()) + ->SetFontDecls( pFontDecls ); +} + +const XMLFontStylesContext *XMLTextImportHelper::GetFontDecls() const +{ + return (XMLFontStylesContext *)&m_pImpl->m_xFontDecls; +} + +sal_Bool XMLTextImportHelper::HasDrawNameAttribute( + const Reference< XAttributeList > & xAttrList, + SvXMLNamespaceMap& rNamespaceMap ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + rNamespaceMap.GetKeyByAttrName( rAttrName, &aLocalName ); + if( XML_NAMESPACE_DRAW == nPrefix && + IsXMLToken( aLocalName, XML_NAME ) ) + { + return xAttrList->getValueByIndex(i).getLength() != 0; + } + } + + return sal_False; +} + +SvXMLImportContext *XMLTextImportHelper::CreateTextChildContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList, + XMLTextType eType ) +{ + SvXMLImportContext *pContext = 0; + + const SvXMLTokenMap& rTokenMap = GetTextElemTokenMap(); + sal_Bool bHeading = sal_False; + sal_Bool bContent = sal_True; + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + switch( nToken ) + { + case XML_TOK_TEXT_H: + bHeading = sal_True; + case XML_TOK_TEXT_P: + pContext = new XMLParaContext( rImport, + nPrefix, rLocalName, + xAttrList, bHeading ); + if (m_pImpl->m_bProgress && XML_TEXT_TYPE_SHAPE != eType) + { + rImport.GetProgressBarHelper()->Increment(); + } + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH: + pContext = new XMLNumberedParaContext( + rImport, nPrefix, rLocalName, xAttrList ); + break; + case XML_TOK_TEXT_LIST: + pContext = new XMLTextListBlockContext( rImport, *this, + nPrefix, rLocalName, + xAttrList ); + break; + case XML_TOK_TABLE_TABLE: + if( XML_TEXT_TYPE_BODY == eType || + XML_TEXT_TYPE_TEXTBOX == eType || + XML_TEXT_TYPE_SECTION == eType || + XML_TEXT_TYPE_HEADER_FOOTER == eType || + XML_TEXT_TYPE_CHANGED_REGION == eType || + XML_TEXT_TYPE_CELL == eType ) + pContext = CreateTableChildContext( rImport, nPrefix, rLocalName, + xAttrList ); + break; + case XML_TOK_TEXT_SEQUENCE_DECLS: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_HEADER_FOOTER == eType ) + { + pContext = new XMLVariableDeclsImportContext( + rImport, *this, nPrefix, rLocalName, VarTypeSequence); + bContent = sal_False; + } + break; + + case XML_TOK_TEXT_VARFIELD_DECLS: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_HEADER_FOOTER == eType ) + { + pContext = new XMLVariableDeclsImportContext( + rImport, *this, nPrefix, rLocalName, VarTypeSimple); + bContent = sal_False; + } + break; + + case XML_TOK_TEXT_USERFIELD_DECLS: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted)|| + XML_TEXT_TYPE_HEADER_FOOTER == eType ) + { + pContext = new XMLVariableDeclsImportContext( + rImport, *this, nPrefix, rLocalName, VarTypeUserField); + bContent = sal_False; + } + break; + + case XML_TOK_TEXT_DDE_DECLS: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_HEADER_FOOTER == eType ) + { + pContext = new XMLDdeFieldDeclsImportContext( + rImport, nPrefix, rLocalName); + bContent = sal_False; + } + break; + + case XML_TOK_TEXT_FRAME_PAGE: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_TEXTBOX == eType || + XML_TEXT_TYPE_CHANGED_REGION == eType ) + { + TextContentAnchorType eAnchorType = + XML_TEXT_TYPE_TEXTBOX == eType ? TextContentAnchorType_AT_FRAME + : TextContentAnchorType_AT_PAGE; + pContext = new XMLTextFrameContext( rImport, nPrefix, + rLocalName, xAttrList, + eAnchorType ); + bContent = sal_False; + } + break; + + case XML_TOK_DRAW_A_PAGE: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_TEXTBOX == eType || + XML_TEXT_TYPE_CHANGED_REGION == eType) + { + TextContentAnchorType eAnchorType = + XML_TEXT_TYPE_TEXTBOX == eType ? TextContentAnchorType_AT_FRAME + : TextContentAnchorType_AT_PAGE; + pContext = new XMLTextFrameHyperlinkContext( rImport, nPrefix, + rLocalName, xAttrList, + eAnchorType ); + bContent = sal_False; + } + break; + + case XML_TOK_TEXT_INDEX_TITLE: + case XML_TOK_TEXT_SECTION: +#ifndef SVX_LIGHT + pContext = new XMLSectionImportContext( rImport, nPrefix, rLocalName ); +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + break; + + case XML_TOK_TEXT_TOC: + case XML_TOK_TEXT_OBJECT_INDEX: + case XML_TOK_TEXT_TABLE_INDEX: + case XML_TOK_TEXT_ILLUSTRATION_INDEX: + case XML_TOK_TEXT_USER_INDEX: + case XML_TOK_TEXT_ALPHABETICAL_INDEX: + case XML_TOK_TEXT_BIBLIOGRAPHY_INDEX: +#ifndef SVX_LIGHT + if( XML_TEXT_TYPE_SHAPE != eType ) + pContext = new XMLIndexTOCContext( rImport, nPrefix, rLocalName ); +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + break; + + case XML_TOK_TEXT_TRACKED_CHANGES: +#ifndef SVX_LIGHT + pContext = new XMLTrackedChangesImportContext( rImport, nPrefix, + rLocalName); +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + bContent = sal_False; + break; + + case XML_TOK_TEXT_CHANGE: + case XML_TOK_TEXT_CHANGE_START: + case XML_TOK_TEXT_CHANGE_END: + pContext = new XMLChangeImportContext( + rImport, nPrefix, rLocalName, + (XML_TOK_TEXT_CHANGE_END != nToken), + (XML_TOK_TEXT_CHANGE_START != nToken), + sal_True); + break; + + case XML_TOK_TEXT_FORMS: +#ifndef SVX_LIGHT + pContext = rImport.GetFormImport()->createOfficeFormsContext(rImport, nPrefix, rLocalName); +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + bContent = sal_False; + break; + + case XML_TOK_TEXT_AUTOMARK: + if( XML_TEXT_TYPE_BODY == eType ) + { + pContext = new XMLAutoMarkFileContext(rImport, nPrefix,rLocalName); + } + bContent = sal_False; + break; + + case XML_TOK_TEXT_CALCULATION_SETTINGS: +#ifndef SVX_LIGHT + pContext = new XMLCalculationSettingsContext ( rImport, nPrefix, rLocalName, xAttrList); +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + bContent = sal_False; + break; + + default: + if ((XML_TEXT_TYPE_BODY == eType && m_pImpl->m_bBodyContentStarted) || + XML_TEXT_TYPE_TEXTBOX == eType || + XML_TEXT_TYPE_CHANGED_REGION == eType ) + { + Reference < XShapes > xShapes; + pContext = rImport.GetShapeImport()->CreateGroupChildContext( + rImport, nPrefix, rLocalName, xAttrList, xShapes ); + bContent = sal_False; + } + } + +// if( !pContext ) +// pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + // handle open redlines + if ( (XML_TOK_TEXT_CHANGE != nToken) && + (XML_TOK_TEXT_CHANGE_END != nToken) && + (XML_TOK_TEXT_CHANGE_START != nToken) ) + { +// ResetOpenRedlineId(); + } + + if( XML_TEXT_TYPE_BODY == eType && bContent ) + { + m_pImpl->m_bBodyContentStarted = sal_False; + } + + return pContext; +} + +SvXMLImportContext *XMLTextImportHelper::CreateTableChildContext( + SvXMLImport&, + sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, + const Reference< XAttributeList > & ) +{ + return 0; +} + +/// get data style key for use with NumberFormat property +sal_Int32 XMLTextImportHelper::GetDataStyleKey(const OUString& sStyleName, + sal_Bool* pIsSystemLanguage ) +{ + const SvXMLStyleContext* pStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, + sStyleName, sal_True ); + + // get appropriate context + + + // first check if its a impress and draw only number format + // this is needed since its also a SvXMLNumFormatContext, + // that was needed to support them for controls in impress/draw also + SdXMLNumberFormatImportContext* pSdNumStyle = PTR_CAST( SdXMLNumberFormatImportContext, pStyle ); + if( pSdNumStyle ) + { + return pSdNumStyle->GetDrawKey(); + } + else + { + SvXMLNumFormatContext* pNumStyle = PTR_CAST( SvXMLNumFormatContext, pStyle ); + if( pNumStyle ) + { + if( pIsSystemLanguage != NULL ) + *pIsSystemLanguage = pNumStyle->IsSystemLanguage(); + + // return key + return pNumStyle->GetKey(); + } + } + return -1; +} + +const SvxXMLListStyleContext *XMLTextImportHelper::FindAutoListStyle( const OUString& rName ) const +{ + const SvxXMLListStyleContext *pStyle = 0; + if (m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( XML_STYLE_FAMILY_TEXT_LIST, rName, + sal_True ); + pStyle = PTR_CAST( SvxXMLListStyleContext ,pTempStyle); + } + + return pStyle; +} + +XMLPropStyleContext *XMLTextImportHelper::FindAutoFrameStyle( const OUString& rName ) const +{ + XMLPropStyleContext *pStyle = 0; + if (m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( XML_STYLE_FAMILY_SD_GRAPHICS_ID, rName, + sal_True ); + pStyle = PTR_CAST( XMLPropStyleContext ,pTempStyle); + } + + return pStyle; +} + +XMLPropStyleContext* XMLTextImportHelper::FindSectionStyle( + const OUString& rName ) const +{ + XMLPropStyleContext* pStyle = NULL; + if (m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( + XML_STYLE_FAMILY_TEXT_SECTION, + rName, sal_True ); + pStyle = PTR_CAST( XMLPropStyleContext,pTempStyle); + } + + return pStyle; +} + +XMLPropStyleContext* XMLTextImportHelper::FindPageMaster( + const OUString& rName ) const +{ + XMLPropStyleContext* pStyle = NULL; + if (m_pImpl->m_xAutoStyles.Is()) + { + const SvXMLStyleContext* pTempStyle = + ((SvXMLStylesContext *)&m_pImpl->m_xAutoStyles)-> + FindStyleChildContext( + XML_STYLE_FAMILY_PAGE_MASTER, + rName, sal_True ); + pStyle = PTR_CAST( XMLPropStyleContext,pTempStyle); + } + + return pStyle; +} + + +void XMLTextImportHelper::PushListContext(XMLTextListBlockContext *i_pListBlock) +{ + GetTextListHelper().PushListContext(i_pListBlock); +} + +void XMLTextImportHelper::PopListContext() +{ + GetTextListHelper().PopListContext(); +} + + +const SvXMLTokenMap& XMLTextImportHelper::GetTextNumberedParagraphAttrTokenMap() +{ + if (!m_pImpl->m_pTextNumberedParagraphAttrTokenMap.get()) + { + m_pImpl->m_pTextNumberedParagraphAttrTokenMap.reset( + new SvXMLTokenMap( aTextNumberedParagraphAttrTokenMap ) ); + } + return *m_pImpl->m_pTextNumberedParagraphAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextListBlockAttrTokenMap() +{ + if (!m_pImpl->m_pTextListBlockAttrTokenMap.get()) + { + m_pImpl->m_pTextListBlockAttrTokenMap.reset( + new SvXMLTokenMap( aTextListBlockAttrTokenMap ) ); + } + return *m_pImpl->m_pTextListBlockAttrTokenMap; +} + +const SvXMLTokenMap& XMLTextImportHelper::GetTextListBlockElemTokenMap() +{ + if (!m_pImpl->m_pTextListBlockElemTokenMap.get()) + { + m_pImpl->m_pTextListBlockElemTokenMap.reset( + new SvXMLTokenMap( aTextListBlockElemTokenMap ) ); + } + return *m_pImpl->m_pTextListBlockElemTokenMap; +} + +SvI18NMap& XMLTextImportHelper::GetRenameMap() +{ + if (!m_pImpl->m_pRenameMap.get()) + { + m_pImpl->m_pRenameMap.reset( new SvI18NMap() ); + } + return *m_pImpl->m_pRenameMap; +} + +void XMLTextImportHelper::InsertBookmarkStartRange( + const OUString sName, + const Reference<XTextRange> & rRange, + OUString const& i_rXmlId, + ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes > & i_rpRDFaAttributes) +{ + m_pImpl->m_BookmarkStartRanges[sName] = + ::boost::make_tuple(rRange, i_rXmlId, i_rpRDFaAttributes); + m_pImpl->m_BookmarkVector.push_back(sName); +} + +sal_Bool XMLTextImportHelper::FindAndRemoveBookmarkStartRange( + const OUString sName, + Reference<XTextRange> & o_rRange, + OUString & o_rXmlId, + ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes > & o_rpRDFaAttributes) +{ + if (m_pImpl->m_BookmarkStartRanges.count(sName)) + { + Impl::BookmarkMapEntry_t & rEntry = + (*m_pImpl->m_BookmarkStartRanges.find(sName)).second; + o_rRange.set(rEntry.get<0>()); + o_rXmlId = rEntry.get<1>(); + o_rpRDFaAttributes = rEntry.get<2>(); + m_pImpl->m_BookmarkStartRanges.erase(sName); + Impl::BookmarkVector_t::iterator it(m_pImpl->m_BookmarkVector.begin()); + while (it != m_pImpl->m_BookmarkVector.end() && it->compareTo(sName)!=0) + { + it++; + } + if (it!=m_pImpl->m_BookmarkVector.end()) { + m_pImpl->m_BookmarkVector.erase(it); + } + return sal_True; + } + else + { + return sal_False; + } +} + +::rtl::OUString XMLTextImportHelper::FindActiveBookmarkName() +{ + if (!m_pImpl->m_BookmarkVector.empty()) { + return m_pImpl->m_BookmarkVector.back(); + } else return ::rtl::OUString(); // return the empty string on error... +} + +::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > XMLTextImportHelper::GetRangeFor(::rtl::OUString &sName) +{ + return m_pImpl->m_BookmarkStartRanges[sName].get<0>(); +} + + +void XMLTextImportHelper::pushFieldCtx( ::rtl::OUString name, ::rtl::OUString type ) +{ + m_pImpl->m_FieldStack.push(Impl::field_stack_item_t( + Impl::field_name_type_t(name, type), Impl::field_params_t())); +} + +void XMLTextImportHelper::popFieldCtx() +{ + m_pImpl->m_FieldStack.pop(); +} + +void XMLTextImportHelper::addFieldParam( ::rtl::OUString name, ::rtl::OUString value ) +{ + DBG_ASSERT(!m_pImpl->m_FieldStack.empty(), + "stack is empty: not good! Do a pushFieldCtx before..."); + if (!m_pImpl->m_FieldStack.empty()) { + Impl::field_stack_item_t & FieldStackItem(m_pImpl->m_FieldStack.top()); + FieldStackItem.second.push_back(Impl::field_param_t( name, value )); + } +} +::rtl::OUString XMLTextImportHelper::getCurrentFieldName() +{ + DBG_ASSERT(!m_pImpl->m_FieldStack.empty(), + "stack is empty: not good! Do a pushFieldCtx before..."); + if (!m_pImpl->m_FieldStack.empty()) { + return m_pImpl->m_FieldStack.top().first.first; + } else return ::rtl::OUString(); +} + +::rtl::OUString XMLTextImportHelper::getCurrentFieldType() +{ + DBG_ASSERT(!m_pImpl->m_FieldStack.empty(), + "stack is empty: not good! Do a pushFieldCtx before..."); + if (!m_pImpl->m_FieldStack.empty()) { + return m_pImpl->m_FieldStack.top().first.second; + } else return ::rtl::OUString(); +} + +bool XMLTextImportHelper::hasCurrentFieldCtx() +{ + return !m_pImpl->m_FieldStack.empty(); +} + +void XMLTextImportHelper::setCurrentFieldParamsTo(::com::sun::star::uno::Reference< ::com::sun::star::text::XFormField> &xFormField) +{ + DBG_ASSERT(!m_pImpl->m_FieldStack.empty(), + "stack is empty: not good! Do a pushFieldCtx before..."); + if (!m_pImpl->m_FieldStack.empty() && xFormField.is()) + { + FieldParamImporter(&m_pImpl->m_FieldStack.top().second, + xFormField->getParameters()).Import(); + } +} + + +void XMLTextImportHelper::ConnectFrameChains( + const OUString& rFrmName, + const OUString& rNextFrmName, + const Reference < XPropertySet >& rFrmPropSet ) +{ + static ::rtl::OUString s_ChainNextName( + RTL_CONSTASCII_USTRINGPARAM("ChainNextName")); + static ::rtl::OUString s_ChainPrevName( + RTL_CONSTASCII_USTRINGPARAM("ChainPrevName")); + + if( !rFrmName.getLength() ) + return; + + if( rNextFrmName.getLength() ) + { + OUString sNextFrmName(GetRenameMap().Get( XML_TEXT_RENAME_TYPE_FRAME, + rNextFrmName )); + if (m_pImpl->m_xTextFrames.is() + && m_pImpl->m_xTextFrames->hasByName(sNextFrmName)) + { + rFrmPropSet->setPropertyValue(s_ChainNextName, + makeAny(sNextFrmName)); + } + else + { + if (!m_pImpl->m_pPrevFrmNames.get()) + { + m_pImpl->m_pPrevFrmNames.reset( new SvStringsDtor ); + m_pImpl->m_pNextFrmNames.reset( new SvStringsDtor ); + } + m_pImpl->m_pPrevFrmNames->Insert( new String( rFrmName ), + m_pImpl->m_pPrevFrmNames->Count() ); + m_pImpl->m_pNextFrmNames->Insert( new String( sNextFrmName ), + m_pImpl->m_pNextFrmNames->Count() ); + } + } + if (m_pImpl->m_pPrevFrmNames.get() && m_pImpl->m_pPrevFrmNames->Count()) + { + sal_uInt16 nCount = m_pImpl->m_pPrevFrmNames->Count(); + for( sal_uInt16 i=0; i<nCount; i++ ) + { + String *pNext = (*m_pImpl->m_pNextFrmNames)[i]; + if( OUString(*pNext) == rFrmName ) + { + // The previuous frame must exist, because it existing than + // inserting the entry + String *pPrev = (*m_pImpl->m_pPrevFrmNames)[i]; + + rFrmPropSet->setPropertyValue(s_ChainPrevName, + makeAny(OUString( *pPrev ))); + + m_pImpl->m_pPrevFrmNames->Remove( i, 1 ); + m_pImpl->m_pNextFrmNames->Remove( i, 1 ); + delete pPrev; + delete pNext; + + // There cannot be more than one previous frames + break; + } + } + } +} + +sal_Bool XMLTextImportHelper::IsInFrame() const +{ + static ::rtl::OUString s_TextFrame( + RTL_CONSTASCII_USTRINGPARAM("TextFrame")); + + sal_Bool bIsInFrame = sal_False; + + // are we currently in a text frame? yes, if the cursor has a + // TextFrame property and it's non-NULL + Reference<XPropertySet> xPropSet(((XMLTextImportHelper *)this)->GetCursor(), UNO_QUERY); + if (xPropSet.is()) + { + if (xPropSet->getPropertySetInfo()->hasPropertyByName(s_TextFrame)) + { + uno::Reference<XTextFrame> const xFrame( + xPropSet->getPropertyValue(s_TextFrame), UNO_QUERY); + + if (xFrame.is()) + { + bIsInFrame = sal_True; + } + } + } + + return bIsInFrame; +} + +sal_Bool XMLTextImportHelper::IsInHeaderFooter() const +{ + return sal_False; +} + +Reference< XPropertySet> XMLTextImportHelper::createAndInsertOLEObject( + SvXMLImport&, + const OUString& /*rHRef*/, + const OUString& /*rStyleName*/, + const OUString& /*rTblName*/, + sal_Int32 /*nWidth*/, sal_Int32 /*nHeight*/ ) +{ + Reference< XPropertySet> xPropSet; + return xPropSet; +} + +Reference< XPropertySet> XMLTextImportHelper::createAndInsertOOoLink( + SvXMLImport&, + const OUString& /*rHRef*/, + const OUString& /*rStyleName*/, + const OUString& /*rTblName*/, + sal_Int32 /*nWidth*/, sal_Int32 /*nHeight*/ ) +{ + Reference< XPropertySet> xPropSet; + return xPropSet; +} + +Reference< XPropertySet> XMLTextImportHelper::createAndInsertApplet( + const OUString& /*rCode*/, + const OUString& /*rName*/, + sal_Bool /*bMayScript*/, + const OUString& /*rHRef*/, + sal_Int32 /*nWidth*/, sal_Int32 /*nHeight*/ ) +{ + Reference< XPropertySet> xPropSet; + return xPropSet; +} +Reference< XPropertySet> XMLTextImportHelper::createAndInsertPlugin( + const OUString& /*rMimeType*/, + const OUString& /*rHRef*/, + sal_Int32 /*nWidth*/, sal_Int32 /*nHeight*/ ) +{ + Reference< XPropertySet> xPropSet; + return xPropSet; +} +Reference< XPropertySet> XMLTextImportHelper::createAndInsertFloatingFrame( + const OUString& /*rName*/, + const OUString& /*rHRef*/, + const OUString& /*rStyleName*/, + sal_Int32 /*nWidth*/, sal_Int32 /*nHeight*/ ) +{ + Reference< XPropertySet> xPropSet; + return xPropSet; +} + +void XMLTextImportHelper::endAppletOrPlugin( + const Reference < XPropertySet> &, + std::map < const rtl::OUString, rtl::OUString, UStringLess > &) +{ +} +// redline helper: dummy implementation to be overridden in sw/filter/xml +void XMLTextImportHelper::RedlineAdd( + const OUString& /*rType*/, + const OUString& /*rId*/, + const OUString& /*rAuthor*/, + const OUString& /*rComment*/, + const DateTime& /*rDateTime*/, + sal_Bool /*bMergeLastPara*/) +{ + // dummy implementation: do nothing +} + +Reference<XTextCursor> XMLTextImportHelper::RedlineCreateText( + Reference<XTextCursor> & /*rOldCursor*/, + const OUString& /*rId*/) +{ + // dummy implementation: do nothing + Reference<XTextCursor> xRet; + return xRet; +} + +void XMLTextImportHelper::RedlineSetCursor( + const OUString& /*rId*/, + sal_Bool /*bStart*/, + sal_Bool /*bIsOutsideOfParagraph*/) +{ + // dummy implementation: do nothing +} + +void XMLTextImportHelper::RedlineAdjustStartNodeCursor(sal_Bool) +{ + // dummy implementation: do nothing +} + +void XMLTextImportHelper::SetShowChanges( sal_Bool ) +{ + // dummy implementation: do nothing +} + +void XMLTextImportHelper::SetRecordChanges( sal_Bool ) +{ + // dummy implementation: do nothing +} +void XMLTextImportHelper::SetChangesProtectionKey(const Sequence<sal_Int8> &) +{ + // dummy implementation: do nothing +} + + +OUString XMLTextImportHelper::GetOpenRedlineId() +{ + return m_pImpl->m_sOpenRedlineIdentifier; +} + +void XMLTextImportHelper::SetOpenRedlineId( ::rtl::OUString& rId) +{ + m_pImpl->m_sOpenRedlineIdentifier = rId; +} + +void XMLTextImportHelper::ResetOpenRedlineId() +{ + OUString sEmpty; + SetOpenRedlineId(sEmpty); +} + +void +XMLTextImportHelper::SetCellParaStyleDefault(::rtl::OUString const& rNewValue) +{ + m_pImpl->m_sCellParaStyleDefault = rNewValue; +} + +::rtl::OUString const& XMLTextImportHelper::GetCellParaStyleDefault() +{ + return m_pImpl->m_sCellParaStyleDefault; +} + diff --git a/xmloff/source/text/txtimppr.cxx b/xmloff/source/text/txtimppr.cxx new file mode 100644 index 000000000000..dceac7a26890 --- /dev/null +++ b/xmloff/source/text/txtimppr.cxx @@ -0,0 +1,728 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/awt/FontFamily.hpp> +#include <com/sun/star/awt/FontPitch.hpp> +#include <com/sun/star/table/BorderLine.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <tools/string.hxx> +#include <xmloff/XMLFontStylesContext.hxx> +#include <xmloff/txtprmap.hxx> +#include <xmloff/xmlimp.hxx> +#include "xmloff/txtimppr.hxx" + +#define XML_LINE_LEFT 0 +#define XML_LINE_RIGHT 1 +#define XML_LINE_TOP 2 +#define XML_LINE_BOTTOM 3 +#define MIN_BORDER_DIST 49 + +using ::rtl::OUString; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::table; +using namespace ::com::sun::star::text; + +sal_Bool XMLTextImportPropertyMapper::handleSpecialItem( + XMLPropertyState& rProperty, + ::std::vector< XMLPropertyState >& rProperties, + const ::rtl::OUString& rValue, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nIndex = rProperty.mnIndex; + switch( getPropertySetMapper()->GetEntryContextId( nIndex ) ) + { + case CTF_FONTNAME: + case CTF_FONTNAME_CJK: + case CTF_FONTNAME_CTL: + if( xFontDecls.Is() ) + { + DBG_ASSERT( + ( CTF_FONTFAMILYNAME == + getPropertySetMapper()->GetEntryContextId(nIndex+1) && + CTF_FONTSTYLENAME == + getPropertySetMapper()->GetEntryContextId(nIndex+2) && + CTF_FONTFAMILY == + getPropertySetMapper()->GetEntryContextId(nIndex+3) && + CTF_FONTPITCH == + getPropertySetMapper()->GetEntryContextId(nIndex+4) && + CTF_FONTCHARSET == + getPropertySetMapper()->GetEntryContextId(nIndex+5) ) || + ( CTF_FONTFAMILYNAME_CJK == + getPropertySetMapper()->GetEntryContextId(nIndex+1) && + CTF_FONTSTYLENAME_CJK == + getPropertySetMapper()->GetEntryContextId(nIndex+2) && + CTF_FONTFAMILY_CJK == + getPropertySetMapper()->GetEntryContextId(nIndex+3) && + CTF_FONTPITCH_CJK == + getPropertySetMapper()->GetEntryContextId(nIndex+4) && + CTF_FONTCHARSET_CJK == + getPropertySetMapper()->GetEntryContextId(nIndex+5) ) || + ( CTF_FONTFAMILYNAME_CTL == + getPropertySetMapper()->GetEntryContextId(nIndex+1) && + CTF_FONTSTYLENAME_CTL == + getPropertySetMapper()->GetEntryContextId(nIndex+2) && + CTF_FONTFAMILY_CTL == + getPropertySetMapper()->GetEntryContextId(nIndex+3) && + CTF_FONTPITCH_CTL == + getPropertySetMapper()->GetEntryContextId(nIndex+4) && + CTF_FONTCHARSET_CTL == + getPropertySetMapper()->GetEntryContextId(nIndex+5) ), + "illegal property map" ); + + ((XMLFontStylesContext *)&xFontDecls)->FillProperties( + rValue, rProperties, + rProperty.mnIndex+1, rProperty.mnIndex+2, + rProperty.mnIndex+3, rProperty.mnIndex+4, + rProperty.mnIndex+5 ); + bRet = sal_False; // the property hasn't been filled + } + break; + + // If we want to do StarMath/StarSymbol font conversion, then we'll + // want these special items to be treated just like regular ones... + // For the Writer, we'll catch and convert them in _FillPropertySet; + // the other apps probably don't care. For the other apps, we just + // imitate the default non-special-item mechanism. + case CTF_FONTFAMILYNAME: + case CTF_FONTFAMILYNAME_CJK: + case CTF_FONTFAMILYNAME_CTL: + bRet = getPropertySetMapper()->importXML( rValue, rProperty, + rUnitConverter ); + break; + + case CTF_TEXT_DISPLAY: + bRet = getPropertySetMapper()->importXML( rValue, rProperty, + rUnitConverter ); + if( SvXMLImport::OOo_2x == GetImport().getGeneratorVersion() ) + { + sal_Bool bHidden; + rProperty.maValue >>= bHidden; + bHidden = !bHidden; + rProperty.maValue <<= bHidden; + } + break; + default: + bRet = SvXMLImportPropertyMapper::handleSpecialItem( rProperty, + rProperties, rValue, rUnitConverter, rNamespaceMap ); + break; + } + + return bRet; +} + +XMLTextImportPropertyMapper::XMLTextImportPropertyMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLImport& rImp, + XMLFontStylesContext *pFontDecls ) : + SvXMLImportPropertyMapper( rMapper, rImp ), + nSizeTypeIndex( -2 ), + nWidthTypeIndex( -2 ), + xFontDecls( pFontDecls ) +{ +} + +XMLTextImportPropertyMapper::~XMLTextImportPropertyMapper() +{ +} + +void XMLTextImportPropertyMapper::SetFontDecls( + XMLFontStylesContext *pFontDecls ) +{ + xFontDecls = pFontDecls; +} + +void XMLTextImportPropertyMapper::FontFinished( + XMLPropertyState *pFontFamilyNameState, + XMLPropertyState *pFontStyleNameState, + XMLPropertyState *pFontFamilyState, + XMLPropertyState *pFontPitchState, + XMLPropertyState *pFontCharsetState ) const +{ + if( pFontFamilyNameState && pFontFamilyNameState->mnIndex != -1 ) + { + OUString sName; + pFontFamilyNameState->maValue >>= sName; + if( !sName.getLength() ) + pFontFamilyNameState->mnIndex = -1; + } + if( !pFontFamilyNameState || pFontFamilyNameState->mnIndex == -1 ) + { + if( pFontStyleNameState ) + pFontStyleNameState->mnIndex = -1; + if( pFontFamilyState ) + pFontFamilyState->mnIndex = -1; + if( pFontPitchState ) + pFontPitchState->mnIndex = -1; + if( pFontCharsetState ) + pFontCharsetState->mnIndex = -1; + } +} + +/** since the properties "CharFontFamilyName", "CharFontStyleName", "CharFontFamily", + "CharFontPitch" and "CharFontSet" and theire CJK and CTL counterparts are only + usable as a union, we add defaults to all values that are not set as long as we + have an "CharFontFamilyName" + + #99928# CL */ +void XMLTextImportPropertyMapper::FontDefaultsCheck( + XMLPropertyState* pFontFamilyName, + XMLPropertyState* pFontStyleName, + XMLPropertyState* pFontFamily, + XMLPropertyState* pFontPitch, + XMLPropertyState* pFontCharSet, + XMLPropertyState** ppNewFontStyleName, + XMLPropertyState** ppNewFontFamily, + XMLPropertyState** ppNewFontPitch, + XMLPropertyState** ppNewFontCharSet ) const +{ + if( pFontFamilyName ) + { + OUString sEmpty; + Any aAny; + + if( !pFontStyleName ) + { + aAny <<= sEmpty; + #ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pFontFamilyName->mnIndex + 1 ); + DBG_ASSERT( nTmp == CTF_FONTSTYLENAME || nTmp == CTF_FONTSTYLENAME_CJK || nTmp == CTF_FONTSTYLENAME_CTL, + "wrong property context id" ); + #endif + *ppNewFontStyleName = new XMLPropertyState( pFontFamilyName->mnIndex + 1, + aAny ); + } + + if( !pFontFamily ) + { + aAny <<= (sal_Int16)com::sun::star::awt::FontFamily::DONTKNOW; + + #ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pFontFamilyName->mnIndex + 2 ); + DBG_ASSERT( nTmp == CTF_FONTFAMILY || nTmp == CTF_FONTFAMILY_CJK || nTmp == CTF_FONTFAMILY_CTL, + "wrong property context id" ); + #endif + *ppNewFontFamily = new XMLPropertyState( pFontFamilyName->mnIndex + 2, + aAny ); + } + + if( !pFontPitch ) + { + aAny <<= (sal_Int16)com::sun::star::awt::FontPitch::DONTKNOW; + #ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pFontFamilyName->mnIndex + 3 ); + DBG_ASSERT( nTmp == CTF_FONTPITCH || nTmp == CTF_FONTPITCH_CJK || nTmp == CTF_FONTPITCH_CTL, + "wrong property context id" ); + #endif + *ppNewFontPitch = new XMLPropertyState( pFontFamilyName->mnIndex + 3, + aAny ); + } + + if( !pFontCharSet ) + { + aAny <<= (sal_Int16)gsl_getSystemTextEncoding(); + #ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pFontFamilyName->mnIndex + 4 ); + DBG_ASSERT( nTmp == CTF_FONTCHARSET || nTmp == CTF_FONTCHARSET_CJK || nTmp == CTF_FONTCHARSET_CTL, + "wrong property context id" ); + #endif + *ppNewFontCharSet = new XMLPropertyState( pFontFamilyName->mnIndex + 4, + aAny ); + } + } +} + +void XMLTextImportPropertyMapper::finished( + ::std::vector< XMLPropertyState >& rProperties, + sal_Int32 /*nStartIndex*/, sal_Int32 /*nEndIndex*/ ) const +{ + sal_Bool bHasAnyHeight = sal_False; + sal_Bool bHasAnyMinHeight = sal_False; + sal_Bool bHasAnyWidth = sal_False; + sal_Bool bHasAnyMinWidth = sal_False; + + XMLPropertyState* pFontFamilyName = 0; + XMLPropertyState* pFontStyleName = 0; + XMLPropertyState* pFontFamily = 0; + XMLPropertyState* pFontPitch = 0; + XMLPropertyState* pFontCharSet = 0; + XMLPropertyState* pNewFontStyleName = 0; + XMLPropertyState* pNewFontFamily = 0; + XMLPropertyState* pNewFontPitch = 0; + XMLPropertyState* pNewFontCharSet = 0; + XMLPropertyState* pFontFamilyNameCJK = 0; + XMLPropertyState* pFontStyleNameCJK = 0; + XMLPropertyState* pFontFamilyCJK = 0; + XMLPropertyState* pFontPitchCJK = 0; + XMLPropertyState* pFontCharSetCJK = 0; + XMLPropertyState* pNewFontStyleNameCJK = 0; + XMLPropertyState* pNewFontFamilyCJK = 0; + XMLPropertyState* pNewFontPitchCJK = 0; + XMLPropertyState* pNewFontCharSetCJK = 0; + XMLPropertyState* pFontFamilyNameCTL = 0; + XMLPropertyState* pFontStyleNameCTL = 0; + XMLPropertyState* pFontFamilyCTL = 0; + XMLPropertyState* pFontPitchCTL = 0; + XMLPropertyState* pFontCharSetCTL = 0; + XMLPropertyState* pNewFontStyleNameCTL = 0; + XMLPropertyState* pNewFontFamilyCTL = 0; + XMLPropertyState* pNewFontPitchCTL = 0; + XMLPropertyState* pNewFontCharSetCTL = 0; + XMLPropertyState* pAllBorderDistance = 0; + XMLPropertyState* pBorderDistances[4] = { 0, 0, 0, 0 }; + XMLPropertyState* pNewBorderDistances[4] = { 0, 0, 0, 0 }; + XMLPropertyState* pAllBorder = 0; + XMLPropertyState* pBorders[4] = { 0, 0, 0, 0 }; + XMLPropertyState* pNewBorders[4] = { 0, 0, 0, 0 }; + XMLPropertyState* pAllBorderWidth = 0; + XMLPropertyState* pBorderWidths[4] = { 0, 0, 0, 0 }; + XMLPropertyState* pAnchorType = 0; + XMLPropertyState* pVertOrient = 0; + XMLPropertyState* pVertOrientRelAsChar = 0; + XMLPropertyState* pBackTransparency = NULL; // transparency in % + XMLPropertyState* pBackTransparent = NULL; // transparency as boolean + sal_uInt16 i; // for the "for" loop + + for( ::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); + aIter != rProperties.end(); + ++aIter ) + { + XMLPropertyState* property = &(*aIter); + if( -1 == property->mnIndex ) + continue; + + switch( getPropertySetMapper()->GetEntryContextId( property->mnIndex ) ) + { + case CTF_FONTFAMILYNAME: pFontFamilyName = property; break; + case CTF_FONTSTYLENAME: pFontStyleName = property; break; + case CTF_FONTFAMILY: pFontFamily = property; break; + case CTF_FONTPITCH: pFontPitch = property; break; + case CTF_FONTCHARSET: pFontCharSet = property; break; + + case CTF_FONTFAMILYNAME_CJK: pFontFamilyNameCJK = property; break; + case CTF_FONTSTYLENAME_CJK: pFontStyleNameCJK = property; break; + case CTF_FONTFAMILY_CJK: pFontFamilyCJK = property; break; + case CTF_FONTPITCH_CJK: pFontPitchCJK = property; break; + case CTF_FONTCHARSET_CJK: pFontCharSetCJK = property; break; + + case CTF_FONTFAMILYNAME_CTL: pFontFamilyNameCTL = property; break; + case CTF_FONTSTYLENAME_CTL: pFontStyleNameCTL = property; break; + case CTF_FONTFAMILY_CTL: pFontFamilyCTL = property; break; + case CTF_FONTPITCH_CTL: pFontPitchCTL = property; break; + case CTF_FONTCHARSET_CTL: pFontCharSetCTL = property; break; + + case CTF_ALLBORDERDISTANCE: pAllBorderDistance = property; break; + case CTF_LEFTBORDERDISTANCE: pBorderDistances[XML_LINE_LEFT] = property; break; + case CTF_RIGHTBORDERDISTANCE: pBorderDistances[XML_LINE_RIGHT] = property; break; + case CTF_TOPBORDERDISTANCE: pBorderDistances[XML_LINE_TOP] = property; break; + case CTF_BOTTOMBORDERDISTANCE: pBorderDistances[XML_LINE_BOTTOM] = property; break; + case CTF_ALLBORDER: pAllBorder = property; break; + case CTF_LEFTBORDER: pBorders[XML_LINE_LEFT] = property; break; + case CTF_RIGHTBORDER: pBorders[XML_LINE_RIGHT] = property; break; + case CTF_TOPBORDER: pBorders[XML_LINE_TOP] = property; break; + case CTF_BOTTOMBORDER: pBorders[XML_LINE_BOTTOM] = property; break; + + case CTF_ALLBORDERWIDTH: pAllBorderWidth = property; break; + case CTF_LEFTBORDERWIDTH: pBorderWidths[XML_LINE_LEFT] = property; break; + case CTF_RIGHTBORDERWIDTH: pBorderWidths[XML_LINE_RIGHT] = property; break; + case CTF_TOPBORDERWIDTH: pBorderWidths[XML_LINE_TOP] = property; break; + case CTF_BOTTOMBORDERWIDTH: pBorderWidths[XML_LINE_BOTTOM] = property; break; + case CTF_ANCHORTYPE: pAnchorType = property; break; + case CTF_VERTICALPOS: pVertOrient = property; break; + case CTF_VERTICALREL_ASCHAR: pVertOrientRelAsChar = property; break; + + case CTF_FRAMEHEIGHT_MIN_ABS: + case CTF_FRAMEHEIGHT_MIN_REL: +// case CTF_SYNCHEIGHT_MIN: + bHasAnyMinHeight = sal_True; + // no break here! + case CTF_FRAMEHEIGHT_ABS: + case CTF_FRAMEHEIGHT_REL: +// case CTF_SYNCHEIGHT: + bHasAnyHeight = sal_True; break; + case CTF_FRAMEWIDTH_MIN_ABS: + case CTF_FRAMEWIDTH_MIN_REL: + bHasAnyMinWidth = sal_True; + // no break here! + case CTF_FRAMEWIDTH_ABS: + case CTF_FRAMEWIDTH_REL: + bHasAnyWidth = sal_True; break; + case CTF_BACKGROUND_TRANSPARENCY: pBackTransparency = property; break; + case CTF_BACKGROUND_TRANSPARENT: pBackTransparent = property; break; + + } + } + + if( pFontFamilyName || pFontStyleName || pFontFamily || + pFontPitch || pFontCharSet ) + FontFinished( pFontFamilyName, pFontStyleName, pFontFamily, + pFontPitch, pFontCharSet ); + if( pFontFamilyNameCJK || pFontStyleNameCJK || pFontFamilyCJK || + pFontPitchCJK || pFontCharSetCJK ) + FontFinished( pFontFamilyNameCJK, pFontStyleNameCJK, pFontFamilyCJK, + pFontPitchCJK, pFontCharSetCJK ); + if( pFontFamilyNameCTL || pFontStyleNameCTL || pFontFamilyCTL || + pFontPitchCTL || pFontCharSetCTL ) + FontFinished( pFontFamilyNameCTL, pFontStyleNameCTL, pFontFamilyCTL, + pFontPitchCTL, pFontCharSetCTL ); + + for( i = 0; i < 4; i++ ) + { + if( pAllBorderDistance && !pBorderDistances[i] ) + { +#ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pAllBorderDistance->mnIndex + i + 1 ); + DBG_ASSERT( nTmp >= CTF_LEFTBORDERDISTANCE && + nTmp <= CTF_BOTTOMBORDERDISTANCE, + "wrong property context id" ); +#endif + pNewBorderDistances[i] = + new XMLPropertyState( pAllBorderDistance->mnIndex + i + 1, + pAllBorderDistance->maValue ); + pBorderDistances[i] = pNewBorderDistances[i]; + } + if( pAllBorder && !pBorders[i] ) + { +#ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pAllBorder->mnIndex + i + 1 ); + DBG_ASSERT( nTmp >= CTF_LEFTBORDER && nTmp <= CTF_BOTTOMBORDER, + "wrong property context id" ); +#endif + pNewBorders[i] = new XMLPropertyState( pAllBorder->mnIndex + i + 1, + pAllBorder->maValue ); + pBorders[i] = pNewBorders[i]; + } + if( !pBorderWidths[i] ) + pBorderWidths[i] = pAllBorderWidth; + else + pBorderWidths[i]->mnIndex = -1; + +#ifdef XML_CHECK_UI_CONSTRAINS + sal_Bool bHasBorder = sal_False; + if( pBorders[i] ) + { + table::BorderLine aBorderLine; + pBorders[i]->maValue >>= aBorderLine; + + if( pBorderWidths[i] ) + { + table::BorderLine aBorderLineWidth; + pBorderWidths[i]->maValue >>= aBorderLineWidth; + aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; + aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; + aBorderLine.LineDistance = aBorderLineWidth.LineDistance; + + pBorders[i]->maValue <<= aBorderLine; + } + bHasBorder = (aBorderLine.OuterLineWidth + + aBorderLine.InnerLineWidth) > 0; + } + if( bHasBorder ) + { + if( !pBorderDistances[i] ) + { +#ifdef DBG_UTIL + sal_Int16 nTmp = getPropertySetMapper()->GetEntryContextId( + pBorders[i]->mnIndex + 5 ); + DBG_ASSERT( nTmp >= CTF_LEFTBORDERDISTANCE && + nTmp <= CTF_BOTTOMBORDERDISTANCE, + "wrong property context id" ); +#endif + + pNewBorderDistances[i] = + new XMLPropertyState( pBorders[i]->mnIndex + 5 ); + pNewBorderDistances[i]->maValue <<= (sal_Int32)MIN_BORDER_DIST; + pBorderDistances[i] = pNewBorderDistances[i]; + } + else + { + sal_Int32 nDist; + pBorderDistances[i]->maValue >>= nDist; + if( nDist < MIN_BORDER_DIST ) + pBorderDistances[i]->maValue <<= (sal_Int32)MIN_BORDER_DIST; + } + } + else + { + if( pBorderDistances[i] ) + { + sal_Int32 nDist; + pBorderDistances[i]->maValue >>= nDist; + if( nDist > 0 ) + pBorderDistances[i]->maValue <<= (sal_Int32)0; + } + } +#else + if( pBorders[i] && pBorderWidths[i] ) + { + table::BorderLine aBorderLine; + pBorders[i]->maValue >>= aBorderLine; + + table::BorderLine aBorderLineWidth; + pBorderWidths[i]->maValue >>= aBorderLineWidth; + + aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; + aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; + aBorderLine.LineDistance = aBorderLineWidth.LineDistance; + + pBorders[i]->maValue <<= aBorderLine; + } +#endif + } + if( pAllBorderDistance ) + pAllBorderDistance->mnIndex = -1; + + if( pAllBorder ) + pAllBorder->mnIndex = -1; + + if( pAllBorderWidth ) + pAllBorderWidth->mnIndex = -1; + + if( pVertOrient && pVertOrientRelAsChar ) + { + sal_Int16 nVertOrient; + pVertOrient->maValue >>= nVertOrient; + sal_Int16 nVertOrientRel = 0; + pVertOrientRelAsChar->maValue >>= nVertOrientRel; + switch( nVertOrient ) + { + case VertOrientation::TOP: + nVertOrient = nVertOrientRel; + break; + case VertOrientation::CENTER: + switch( nVertOrientRel ) + { + case VertOrientation::CHAR_TOP: + nVertOrient = VertOrientation::CHAR_CENTER; + break; + case VertOrientation::LINE_TOP: + nVertOrient = VertOrientation::LINE_CENTER; + break; + } + break; + case VertOrientation::BOTTOM: + switch( nVertOrientRel ) + { + case VertOrientation::CHAR_TOP: + nVertOrient = VertOrientation::CHAR_BOTTOM; + break; + case VertOrientation::LINE_TOP: + nVertOrient = VertOrientation::LINE_BOTTOM; + break; + } + break; + } + pVertOrient->maValue <<= nVertOrient; + pVertOrientRelAsChar->mnIndex = -1; + } + + FontDefaultsCheck( pFontFamilyName, + pFontStyleName, pFontFamily, pFontPitch, pFontCharSet, + &pNewFontStyleName, &pNewFontFamily, &pNewFontPitch, &pNewFontCharSet ); + + FontDefaultsCheck( pFontFamilyNameCJK, + pFontStyleNameCJK, pFontFamilyCJK, pFontPitchCJK, pFontCharSetCJK, + &pNewFontStyleNameCJK, &pNewFontFamilyCJK, &pNewFontPitchCJK, &pNewFontCharSetCJK ); + + FontDefaultsCheck( pFontFamilyNameCTL, + pFontStyleNameCTL, pFontFamilyCTL, pFontPitchCTL, pFontCharSetCTL, + &pNewFontStyleNameCTL, &pNewFontFamilyCTL, &pNewFontPitchCTL, &pNewFontCharSetCTL ); + + // #i5775# don't overwrite %transparency with binary transparency + if( ( pBackTransparency != NULL ) && ( pBackTransparent != NULL ) ) + { + if( ! *(sal_Bool*)(pBackTransparent->maValue.getValue()) ) + pBackTransparent->mnIndex = -1; + } + + + // insert newly created properties. This inavlidates all iterators! + // Most of the pXXX variables in this method are iterators and will be + // invalidated!!! + + if( pNewFontStyleName ) + { + rProperties.push_back( *pNewFontStyleName ); + delete pNewFontStyleName; + } + + if( pNewFontFamily ) + { + rProperties.push_back( *pNewFontFamily ); + delete pNewFontFamily; + } + + if( pNewFontPitch ) + { + rProperties.push_back( *pNewFontPitch ); + delete pNewFontPitch; + } + + if( pNewFontCharSet ) + { + rProperties.push_back( *pNewFontCharSet ); + delete pNewFontCharSet; + } + + if( pNewFontStyleNameCJK ) + { + rProperties.push_back( *pNewFontStyleNameCJK ); + delete pNewFontStyleNameCJK; + } + + if( pNewFontFamilyCJK ) + { + rProperties.push_back( *pNewFontFamilyCJK ); + delete pNewFontFamilyCJK; + } + + if( pNewFontPitchCJK ) + { + rProperties.push_back( *pNewFontPitchCJK ); + delete pNewFontPitchCJK; + } + + if( pNewFontCharSetCJK ) + { + rProperties.push_back( *pNewFontCharSetCJK ); + delete pNewFontCharSetCJK; + } + + if( pNewFontStyleNameCTL) + { + rProperties.push_back( *pNewFontStyleNameCTL ); + delete pNewFontStyleNameCTL; + } + + if( pNewFontFamilyCTL ) + { + rProperties.push_back( *pNewFontFamilyCTL ); + delete pNewFontFamilyCTL; + } + + if( pNewFontPitchCTL ) + { + rProperties.push_back( *pNewFontPitchCTL ); + delete pNewFontPitchCTL; + } + + if( pNewFontCharSetCTL ) + { + rProperties.push_back( *pNewFontCharSetCTL ); + delete pNewFontCharSetCTL; + } + + for( i=0; i<4; i++ ) + { + if( pNewBorderDistances[i] ) + { + rProperties.push_back( *pNewBorderDistances[i] ); + delete pNewBorderDistances[i]; + } + if( pNewBorders[i] ) + { + rProperties.push_back( *pNewBorders[i] ); + delete pNewBorders[i]; + } + } + + if( bHasAnyHeight ) + { + if( nSizeTypeIndex == -2 ) + { + const_cast < XMLTextImportPropertyMapper * > ( this ) + ->nSizeTypeIndex = -1; + sal_Int32 nPropCount = getPropertySetMapper()->GetEntryCount(); + for( sal_Int32 j=0; j < nPropCount; j++ ) + { + if( CTF_SIZETYPE == getPropertySetMapper() + ->GetEntryContextId( j ) ) + { + const_cast < XMLTextImportPropertyMapper * > ( this ) + ->nSizeTypeIndex = j; + break; + } + } + } + if( nSizeTypeIndex != -1 ) + { + XMLPropertyState aSizeTypeState( nSizeTypeIndex ); + aSizeTypeState.maValue <<= (sal_Int16)( bHasAnyMinHeight + ? SizeType::MIN + : SizeType::FIX); + rProperties.push_back( aSizeTypeState ); + } + } + + if( bHasAnyWidth ) + { + if( nWidthTypeIndex == -2 ) + { + const_cast < XMLTextImportPropertyMapper * > ( this ) + ->nWidthTypeIndex = -1; + sal_Int32 nCount = getPropertySetMapper()->GetEntryCount(); + for( sal_Int32 j=0; j < nCount; j++ ) + { + if( CTF_FRAMEWIDTH_TYPE == getPropertySetMapper() + ->GetEntryContextId( j ) ) + { + const_cast < XMLTextImportPropertyMapper * > ( this ) + ->nWidthTypeIndex = j; + break; + } + } + } + if( nWidthTypeIndex != -1 ) + { + XMLPropertyState aSizeTypeState( nWidthTypeIndex ); + aSizeTypeState.maValue <<= (sal_Int16)( bHasAnyMinWidth + ? SizeType::MIN + : SizeType::FIX); + rProperties.push_back( aSizeTypeState ); + } + } + + // DO NOT USE ITERATORS/POINTERS INTO THE rProperties-VECTOR AFTER + // THIS LINE. All iterators into the rProperties-vector, especially all + // pXXX-type variables set in the first switch statement of this method, + // may have been invalidated by the above push_back() calls! +} + + diff --git a/xmloff/source/text/txtlists.cxx b/xmloff/source/text/txtlists.cxx new file mode 100644 index 000000000000..ab90e2ae4000 --- /dev/null +++ b/xmloff/source/text/txtlists.cxx @@ -0,0 +1,541 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#include "precompiled_xmloff.hxx" + +#include <txtlists.hxx> + +#include <tools/debug.hxx> +#include <tools/date.hxx> +#include <tools/time.hxx> + +#include <xmloff/txtimp.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnumi.hxx> + +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include "XMLTextListItemContext.hxx" +#include "XMLTextListBlockContext.hxx" +#include "txtparai.hxx" + + +using namespace ::com::sun::star; + + +XMLTextListsHelper::XMLTextListsHelper() + : mpProcessedLists( 0 ), + msLastProcessedListId(), + msListStyleOfLastProcessedList(), + // --> OD 2008-08-15 #i92811# + mpMapListIdToListStyleDefaultListId( 0 ), + // <-- + mpContinuingLists( 0 ), + mpListStack( 0 ) +{ +} + +XMLTextListsHelper::~XMLTextListsHelper() +{ + if ( mpProcessedLists ) + { + mpProcessedLists->clear(); + delete mpProcessedLists; + } + // --> OD 2008-08-15 #i92811# + if ( mpMapListIdToListStyleDefaultListId ) + { + mpMapListIdToListStyleDefaultListId->clear(); + delete mpMapListIdToListStyleDefaultListId; + } + // <-- + if ( mpContinuingLists ) + { + mpContinuingLists->clear(); + delete mpContinuingLists; + } + if ( mpListStack ) + { + mpListStack->clear(); + delete mpListStack; + } +} + +void XMLTextListsHelper::PushListContext( + XMLTextListBlockContext *i_pListBlock) +{ +// fprintf(stderr, "PushListContext\n"); + mListStack.push(::boost::make_tuple(i_pListBlock, + static_cast<XMLTextListItemContext*>(0), + static_cast<XMLNumberedParaContext*>(0))); +} + +void XMLTextListsHelper::PushListContext( + XMLNumberedParaContext *i_pNumberedParagraph) +{ +// fprintf(stderr, "PushListContext(NP)\n"); + mListStack.push(::boost::make_tuple( + static_cast<XMLTextListBlockContext*>(0), + static_cast<XMLTextListItemContext*>(0), i_pNumberedParagraph)); +} + +void XMLTextListsHelper::PopListContext() +{ + OSL_ENSURE(mListStack.size(), + "internal error: PopListContext: mListStack empty"); +// fprintf(stderr, "PopListContext\n"); + if ( !mListStack.empty()) + mListStack.pop(); +} + +void XMLTextListsHelper::ListContextTop( + XMLTextListBlockContext*& o_pListBlockContext, + XMLTextListItemContext*& o_pListItemContext, + XMLNumberedParaContext*& o_pNumberedParagraphContext ) +{ + if ( !mListStack.empty() ) { + o_pListBlockContext = + static_cast<XMLTextListBlockContext*>(&mListStack.top().get<0>()); + o_pListItemContext = + static_cast<XMLTextListItemContext *>(&mListStack.top().get<1>()); + o_pNumberedParagraphContext = + static_cast<XMLNumberedParaContext *>(&mListStack.top().get<2>()); + } +} + +void XMLTextListsHelper::SetListItem( XMLTextListItemContext *i_pListItem ) +{ + // may be cleared by ListBlockContext for upper list... + if (i_pListItem) { + OSL_ENSURE(mListStack.size(), + "internal error: SetListItem: mListStack empty"); + OSL_ENSURE(mListStack.top().get<0>(), + "internal error: SetListItem: mListStack has no ListBlock"); + OSL_ENSURE(!mListStack.top().get<1>(), + "error: SetListItem: list item already exists"); + } + if ( !mListStack.empty() ) { + mListStack.top().get<1>() = i_pListItem; + } +} + +// --> OD 2008-08-15 #i92811# - handling for parameter <sListStyleDefaultListId> +void XMLTextListsHelper::KeepListAsProcessed( ::rtl::OUString sListId, + ::rtl::OUString sListStyleName, + ::rtl::OUString sContinueListId, + ::rtl::OUString sListStyleDefaultListId ) +{ + if ( IsListProcessed( sListId ) ) + { + DBG_ASSERT( false, + "<XMLTextListsHelper::KeepListAsProcessed(..)> - list id already added" ); + return; + } + + if ( mpProcessedLists == 0 ) + { + mpProcessedLists = new tMapForLists(); + } + + ::std::pair< ::rtl::OUString, ::rtl::OUString > + aListData( sListStyleName, sContinueListId ); + (*mpProcessedLists)[ sListId ] = aListData; + + msLastProcessedListId = sListId; + msListStyleOfLastProcessedList = sListStyleName; + + // --> OD 2008-08-15 #i92811# + if ( sListStyleDefaultListId.getLength() != 0 ) + { + if ( mpMapListIdToListStyleDefaultListId == 0 ) + { + mpMapListIdToListStyleDefaultListId = new tMapForLists(); + } + + if ( mpMapListIdToListStyleDefaultListId->find( sListStyleName ) == + mpMapListIdToListStyleDefaultListId->end() ) + { + ::std::pair< ::rtl::OUString, ::rtl::OUString > + aListIdMapData( sListId, sListStyleDefaultListId ); + (*mpMapListIdToListStyleDefaultListId)[ sListStyleName ] = + aListIdMapData; + } + } + // <-- +} + +sal_Bool XMLTextListsHelper::IsListProcessed( const ::rtl::OUString sListId ) const +{ + if ( mpProcessedLists == 0 ) + { + return sal_False; + } + + return mpProcessedLists->find( sListId ) != mpProcessedLists->end(); +} + +::rtl::OUString XMLTextListsHelper::GetListStyleOfProcessedList( + const ::rtl::OUString sListId ) const +{ + if ( mpProcessedLists != 0 ) + { + tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId ); + if ( aIter != mpProcessedLists->end() ) + { + return (*aIter).second.first; + } + } + + return ::rtl::OUString(); +} + +::rtl::OUString XMLTextListsHelper::GetContinueListIdOfProcessedList( + const ::rtl::OUString sListId ) const +{ + if ( mpProcessedLists != 0 ) + { + tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId ); + if ( aIter != mpProcessedLists->end() ) + { + return (*aIter).second.second; + } + } + + return ::rtl::OUString(); +} + +const ::rtl::OUString& XMLTextListsHelper::GetLastProcessedListId() const +{ + return msLastProcessedListId; +} + +const ::rtl::OUString& XMLTextListsHelper::GetListStyleOfLastProcessedList() const +{ + return msListStyleOfLastProcessedList; +} + +::rtl::OUString XMLTextListsHelper::GenerateNewListId() const +{ + // --> OD 2008-08-06 #i92478# + ::rtl::OUString sTmpStr( ::rtl::OUString::createFromAscii( "list" ) ); + // <-- + sal_Int64 n = Time().GetTime(); + n += Date().GetDate(); + n += rand(); + // --> OD 2008-08-06 #i92478# + sTmpStr += ::rtl::OUString::valueOf( n ); + // <-- + + long nHitCount = 0; + ::rtl::OUString sNewListId( sTmpStr ); + if ( mpProcessedLists != 0 ) + { + while ( mpProcessedLists->find( sNewListId ) != mpProcessedLists->end() ) + { + ++nHitCount; + sNewListId = sTmpStr; + sNewListId += ::rtl::OUString::valueOf( nHitCount ); + } + } + + return sNewListId; +} + +// --> OD 2008-08-15 #i92811# +// provide list id for a certain list block for import +::rtl::OUString XMLTextListsHelper::GetListIdForListBlock( XMLTextListBlockContext& rListBlock ) +{ + ::rtl::OUString sListBlockListId( rListBlock.GetContinueListId() ); + if ( sListBlockListId.getLength() == 0 ) + { + sListBlockListId = rListBlock.GetListId(); + } + + if ( mpMapListIdToListStyleDefaultListId != 0 ) + { + if ( sListBlockListId.getLength() != 0 ) + { + const ::rtl::OUString sListStyleName = + GetListStyleOfProcessedList( sListBlockListId ); + + tMapForLists::const_iterator aIter = + mpMapListIdToListStyleDefaultListId->find( sListStyleName ); + if ( aIter != mpMapListIdToListStyleDefaultListId->end() ) + { + if ( (*aIter).second.first == sListBlockListId ) + { + sListBlockListId = (*aIter).second.second; + } + } + } + } + + return sListBlockListId; +} +// <-- + +void XMLTextListsHelper::StoreLastContinuingList( ::rtl::OUString sListId, + ::rtl::OUString sContinuingListId ) +{ + if ( mpContinuingLists == 0 ) + { + mpContinuingLists = new tMapForContinuingLists(); + } + + (*mpContinuingLists)[ sListId ] = sContinuingListId; +} + +::rtl::OUString XMLTextListsHelper::GetLastContinuingListId( + ::rtl::OUString sListId ) const +{ + if ( mpContinuingLists != 0) + { + tMapForContinuingLists::const_iterator aIter = + mpContinuingLists->find( sListId ); + if ( aIter != mpContinuingLists->end() ) + { + return (*aIter).second; + } + } + + return sListId; +} + +void XMLTextListsHelper::PushListOnStack( ::rtl::OUString sListId, + ::rtl::OUString sListStyleName ) +{ + if ( mpListStack == 0 ) + { + mpListStack = new tStackForLists(); + } + ::std::pair< ::rtl::OUString, ::rtl::OUString > + aListData( sListId, sListStyleName ); + mpListStack->push_back( aListData ); +} +void XMLTextListsHelper::PopListFromStack() +{ + if ( mpListStack != 0 && + mpListStack->size() > 0 ) + { + mpListStack->pop_back(); + } +} + +sal_Bool XMLTextListsHelper::EqualsToTopListStyleOnStack( const ::rtl::OUString sListId ) const +{ + return mpListStack != 0 + ? sListId == mpListStack->back().second + : sal_False; +} + +::rtl::OUString +XMLTextListsHelper::GetNumberedParagraphListId( + const sal_uInt16 i_Level, + const ::rtl::OUString i_StyleName) +{ + if (!i_StyleName.getLength()) { + OSL_ENSURE(false, "invalid numbered-paragraph: no style-name"); + } + if (i_StyleName.getLength() + && (i_Level < mLastNumberedParagraphs.size()) + && (mLastNumberedParagraphs[i_Level].first == i_StyleName) ) + { + OSL_ENSURE(mLastNumberedParagraphs[i_Level].second.getLength(), + "internal error: numbered-paragraph style-name but no list-id?"); + return mLastNumberedParagraphs[i_Level].second; + } else { + return GenerateNewListId(); + } +} + +static void +ClampLevel(uno::Reference<container::XIndexReplace> const& i_xNumRules, + sal_Int16 & io_rLevel) +{ + OSL_ENSURE(i_xNumRules.is(), "internal error: ClampLevel: NumRules null"); + if (i_xNumRules.is()) { + const sal_Int32 nLevelCount( i_xNumRules->getCount() ); + if ( io_rLevel >= nLevelCount ) { + io_rLevel = sal::static_int_cast< sal_Int16 >(nLevelCount-1); + } + } +} + +uno::Reference<container::XIndexReplace> +XMLTextListsHelper::EnsureNumberedParagraph( + SvXMLImport & i_rImport, + const ::rtl::OUString i_ListId, + sal_Int16 & io_rLevel, const ::rtl::OUString i_StyleName) +{ + OSL_ENSURE(i_ListId.getLength(), "inavlid ListId"); + OSL_ENSURE(io_rLevel >= 0, "inavlid Level"); + NumParaList_t & rNPList( mNPLists[i_ListId] ); + const ::rtl::OUString none; // default + if ( rNPList.empty() && (0 != io_rLevel)) { + // create default list style for top level + sal_Int16 lev(0); + rNPList.push_back(::std::make_pair(none, + MakeNumRule(i_rImport, 0, none, none, lev) )); + } + // create num rule first because this might clamp the level... + uno::Reference<container::XIndexReplace> xNumRules; + if ((0 == io_rLevel) || rNPList.empty() || i_StyleName.getLength()) { + // no parent to inherit from, or explicit style given => new numrules! + // index of parent: level - 1, but maybe that does not exist + const size_t parent( std::min(static_cast<size_t>(io_rLevel), + rNPList.size()) - 1 ); + xNumRules = MakeNumRule(i_rImport, + io_rLevel > 0 ? rNPList[parent].second : 0, + io_rLevel > 0 ? rNPList[parent].first : none, + i_StyleName, io_rLevel); + } else { + // no style given, but has a parent => reuse parent numrules! + ClampLevel(rNPList.back().second, io_rLevel); + } + if (static_cast<sal_uInt16>(io_rLevel) + 1U > rNPList.size()) { + // new level: need to enlarge + for (size_t i = rNPList.size(); + i < static_cast<size_t>(io_rLevel); ++i) { + rNPList.push_back(rNPList.back()); + } + rNPList.push_back(xNumRules.is() + ? ::std::make_pair(i_StyleName, xNumRules) + : rNPList.back()); + } else { + // old level: no need to enlarge; possibly shrink + if (xNumRules.is()) { + rNPList[io_rLevel] = std::make_pair(i_StyleName, xNumRules); + } + if (static_cast<sal_uInt16>(io_rLevel) + 1U < rNPList.size()) { + rNPList.erase(rNPList.begin() + io_rLevel + 1, rNPList.end()); + } + } + // remember the list id + if (mLastNumberedParagraphs.size() <= static_cast<size_t>(io_rLevel)) { + mLastNumberedParagraphs.resize(io_rLevel+1); + } + mLastNumberedParagraphs[io_rLevel] = std::make_pair(i_StyleName, i_ListId); + return rNPList.back().second; +} + +/** extracted from the XMLTextListBlockContext constructor */ +uno::Reference<container::XIndexReplace> +XMLTextListsHelper::MakeNumRule( + SvXMLImport & i_rImport, + const uno::Reference<container::XIndexReplace>& i_rNumRule, + const ::rtl::OUString i_ParentStyleName, + const ::rtl::OUString i_StyleName, + sal_Int16 & io_rLevel, + sal_Bool* o_pRestartNumbering, + sal_Bool* io_pSetDefaults) +{ + static ::rtl::OUString s_NumberingRules( + RTL_CONSTASCII_USTRINGPARAM("NumberingRules")); + uno::Reference<container::XIndexReplace> xNumRules(i_rNumRule); + if ( i_StyleName.getLength() && + i_StyleName != i_ParentStyleName ) + { + const ::rtl::OUString sDisplayStyleName( + i_rImport.GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST, + i_StyleName) ); + const uno::Reference < container::XNameContainer >& rNumStyles( + i_rImport.GetTextImport()->GetNumberingStyles() ); + if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) ) + { + uno::Reference < style::XStyle > xStyle; + uno::Any any = rNumStyles->getByName( sDisplayStyleName ); + any >>= xStyle; + + // --> OD 2008-05-07 #refactorlists# - no longer needed +// // If the style has not been used, the restart numbering has +// // to be set never. +// if ( mbRestartNumbering && !xStyle->isInUse() ) +// { +// mbRestartNumbering = sal_False; +// } + // <-- + + uno::Reference< beans::XPropertySet > xPropSet( xStyle, + uno::UNO_QUERY ); + any = xPropSet->getPropertyValue(s_NumberingRules); + any >>= xNumRules; + } + else + { + const SvxXMLListStyleContext *pListStyle( + i_rImport.GetTextImport()->FindAutoListStyle( i_StyleName ) ); + if( pListStyle ) + { + xNumRules = pListStyle->GetNumRules(); + // --> OD 2008-05-07 #refactorlists# - no longer needed +// sal_Bool bUsed = mxNumRules.is(); + // <-- + if( !xNumRules.is() ) + { + pListStyle->CreateAndInsertAuto(); + xNumRules = pListStyle->GetNumRules(); + } + // --> OD 2008-05-07 #refactorlists# - no longer needed +// if( mbRestartNumbering && !bUsed ) +// mbRestartNumbering = sal_False; + // <-- + } + } + } + + sal_Bool bSetDefaults(io_pSetDefaults ? *io_pSetDefaults : sal_False); + if ( !xNumRules.is() ) + { + // If no style name has been specified for this style and for any + // parent or if no num rule with the specified name exists, + // create a new one. + + xNumRules = + SvxXMLListStyleContext::CreateNumRule( i_rImport.GetModel() ); + DBG_ASSERT( xNumRules.is(), "got no numbering rule" ); + if ( !xNumRules.is() ) + return xNumRules; + + // Because it is a new num rule, numbering must not be restarted. + if (o_pRestartNumbering) *o_pRestartNumbering = sal_False; + bSetDefaults = sal_True; + if (io_pSetDefaults) *io_pSetDefaults = bSetDefaults; + } + + ClampLevel(xNumRules, io_rLevel); + + if ( bSetDefaults ) + { + // Because there is no list style sheet for this style, a default + // format must be set for any level of this num rule. + SvxXMLListStyleContext::SetDefaultStyle( xNumRules, io_rLevel, + sal_False ); + } + + return xNumRules; +} + diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx new file mode 100644 index 000000000000..89b5c5c1ee48 --- /dev/null +++ b/xmloff/source/text/txtparae.cxx @@ -0,0 +1,3873 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "unointerfacetouniqueidentifiermapper.hxx" +#include <tools/debug.hxx> +#ifndef _SVSTDARR_LONGS_DECL +#define _SVSTDARR_LONGS +#include <svl/svstdarr.hxx> +#endif +#include <svl/svarray.hxx> +#include <rtl/ustrbuf.hxx> +#include <sal/types.h> + +#include <vector> +#include <list> +#include <hash_map> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextSectionsSupplier.hpp> +#include <com/sun/star/text/XTextTablesSupplier.hpp> +#include <com/sun/star/text/XNumberingRulesSupplier.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp>//#outline level,add by zhaojianwei +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XFootnote.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/container/XContentEnumerationAccess.hpp> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/XTextFramesSupplier.hpp> +#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp> +#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/document/XRedlinesSupplier.hpp> + +#include <com/sun/star/text/XBookmarksSupplier.hpp> +#include <com/sun/star/text/XFormField.hpp> + +#include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/text/SectionFileLink.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/text/XTextShapesSupplier.hpp> + +#include <com/sun/star/style/XAutoStylesSupplier.hpp> +#include <com/sun/star/style/XAutoStyleFamily.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/text/XFootnotesSupplier.hpp> +#include <com/sun/star/text/XEndnotesSupplier.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlaustp.hxx> +#include <xmloff/families.hxx> +#include "txtexppr.hxx" +#include <xmloff/xmlnumfe.hxx> +#include <xmloff/xmlnume.hxx> +#include <xmloff/xmluconv.hxx> +#include "XMLAnchorTypePropHdl.hxx" +#include "xexptran.hxx" +#include <xmloff/ProgressBarHelper.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> +#include "txtflde.hxx" +#include <xmloff/txtprmap.hxx> +#include "XMLImageMapExport.hxx" +#include "XMLTextNumRuleInfo.hxx" +#include "xmloff/XMLTextListAutoStylePool.hxx" +#include <xmloff/txtparae.hxx> +#include "XMLSectionExport.hxx" +#include "XMLIndexMarkExport.hxx" +#include <xmloff/XMLEventExport.hxx> +#include "XMLRedlineExport.hxx" +#include "MultiPropertySetHelper.hxx" +#include <xmloff/formlayerexport.hxx> +#include "XMLTextCharStyleNamesElementExport.hxx" +#include <comphelper/stlunosequence.hxx> + +// --> OD 2008-04-25 #refactorlists# +#include <txtlists.hxx> +// <-- +#include <com/sun/star/rdf/XMetadatable.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::frame; +using namespace ::xmloff; +using namespace ::xmloff::token; + +namespace +{ + class TextContentSet + { + public: + typedef Reference<XTextContent> text_content_ref_t; + typedef list<text_content_ref_t> contents_t; + typedef back_insert_iterator<contents_t> inserter_t; + typedef contents_t::const_iterator const_iterator_t; + + inserter_t getInserter() + { return back_insert_iterator<contents_t>(m_vTextContents); }; + const_iterator_t getBegin() const + { return m_vTextContents.begin(); }; + const_iterator_t getEnd() const + { return m_vTextContents.end(); }; + + private: + contents_t m_vTextContents; + }; + + struct FrameRefHash + : public unary_function<Reference<XTextFrame>, size_t> + { + size_t operator()(const Reference<XTextFrame> xFrame) const + { return sal::static_int_cast<size_t>(reinterpret_cast<sal_uIntPtr>(xFrame.get())); } + }; + + static bool lcl_TextContentsUnfiltered(const Reference<XTextContent>&) + { return true; }; + + static bool lcl_ShapeFilter(const Reference<XTextContent>& xTxtContent) + { + static const OUString sTextFrameService = OUString::createFromAscii("com.sun.star.text.TextFrame"); + static const OUString sTextGraphicService = OUString::createFromAscii("com.sun.star.text.TextGraphicObject"); + static const OUString sTextEmbeddedService = OUString::createFromAscii("com.sun.star.text.TextEmbeddedObject"); + Reference<XShape> xShape(xTxtContent, UNO_QUERY); + if(!xShape.is()) + return false; + Reference<XServiceInfo> xServiceInfo(xTxtContent, UNO_QUERY); + if(xServiceInfo->supportsService(sTextFrameService) || + xServiceInfo->supportsService(sTextGraphicService) || + xServiceInfo->supportsService(sTextEmbeddedService) ) + return false; + return true; + }; + + class BoundFrames + { + public: + typedef bool (*filter_t)(const Reference<XTextContent>&); + BoundFrames( + const Reference<XEnumerationAccess> xEnumAccess, + const filter_t& rFilter) + : m_xEnumAccess(xEnumAccess) + { + Fill(rFilter); + }; + BoundFrames() + {}; + const TextContentSet* GetPageBoundContents() const + { return &m_vPageBounds; }; + const TextContentSet* GetFrameBoundContents(const Reference<XTextFrame>& rParentFrame) const + { + framebound_map_t::const_iterator it = m_vFrameBoundsOf.find(rParentFrame); + if(it == m_vFrameBoundsOf.end()) + return NULL; + return &(it->second); + }; + Reference<XEnumeration> createEnumeration() const + { + if(!m_xEnumAccess.is()) + return Reference<XEnumeration>(); + return m_xEnumAccess->createEnumeration(); + }; + + private: + typedef hash_map< + Reference<XTextFrame>, + TextContentSet, + FrameRefHash> framebound_map_t; + TextContentSet m_vPageBounds; + framebound_map_t m_vFrameBoundsOf; + const Reference<XEnumerationAccess> m_xEnumAccess; + void Fill(const filter_t& rFilter); + static const OUString our_sAnchorType; + static const OUString our_sAnchorFrame; + }; + const OUString BoundFrames::our_sAnchorType = OUString::createFromAscii("AnchorType"); + const OUString BoundFrames::our_sAnchorFrame = OUString::createFromAscii("AnchorFrame"); + + class FieldParamExporter + { + public: + FieldParamExporter(SvXMLExport* const pExport, Reference<XNameContainer> xFieldParams) + : m_pExport(pExport) + , m_xFieldParams(xFieldParams) + { }; + void Export(); + + private: + SvXMLExport* const m_pExport; + const Reference<XNameContainer> m_xFieldParams; + + void ExportParameter(const OUString& sKey, const OUString& sValue); + }; +} + +namespace xmloff +{ + class BoundFrameSets + { + public: + BoundFrameSets(const Reference<XInterface> xModel); + const BoundFrames* GetTexts() const + { return m_pTexts.get(); }; + const BoundFrames* GetGraphics() const + { return m_pGraphics.get(); }; + const BoundFrames* GetEmbeddeds() const + { return m_pEmbeddeds.get(); }; + const BoundFrames* GetShapes() const + { return m_pShapes.get(); }; + private: + auto_ptr<BoundFrames> m_pTexts; + auto_ptr<BoundFrames> m_pGraphics; + auto_ptr<BoundFrames> m_pEmbeddeds; + auto_ptr<BoundFrames> m_pShapes; + }; +} + +typedef OUString *OUStringPtr; +SV_DECL_PTRARR_DEL( OUStrings_Impl, OUStringPtr, 20, 10 ) +SV_IMPL_PTRARR( OUStrings_Impl, OUStringPtr ) + +SV_DECL_PTRARR_SORT_DEL( OUStringsSort_Impl, OUStringPtr, 20, 10 ) +SV_IMPL_OP_PTRARR_SORT( OUStringsSort_Impl, OUStringPtr ) + +#ifdef DBG_UTIL +static int txtparae_bContainsIllegalCharacters = sal_False; +#endif + +// The following map shows which property values are required: +// +// property auto style pass export +// -------------------------------------------------------- +// ParaStyleName if style exists always +// ParaConditionalStyleName if style exists always +// NumberingRules if style exists always +// TextSection always always +// ParaChapterNumberingLevel never always +// NumberingIsNumber never always + +// The conclusion is that for auto styles the first three properties +// should be queried using a multi property set if, and only if, an +// auto style needs to be exported. TextSection should be queried by +// an individual call to getPropertyvalue, because this seems to be +// less expensive than querying the first three properties if they aren't +// required. + +// For the export pass all properties can be queried using a multi property +// set. + +static const sal_Char* aParagraphPropertyNamesAuto[] = +{ + "NumberingRules", + "ParaConditionalStyleName", + "ParaStyleName", + NULL +}; + +enum eParagraphPropertyNamesEnumAuto +{ + NUMBERING_RULES_AUTO = 0, + PARA_CONDITIONAL_STYLE_NAME_AUTO = 1, + PARA_STYLE_NAME_AUTO = 2 +}; + +static const sal_Char* aParagraphPropertyNames[] = +{ + "NumberingIsNumber", + "NumberingStyleName", //#outline level,add by zhaojianwei + + //"ParaChapterNumberingLevel", //#outline level,remove by zhaojianwei + "OutlineLevel", //<-end,add by zhaojianwei + "ParaConditionalStyleName", + "ParaStyleName", + "TextSection", + NULL +}; + +enum eParagraphPropertyNamesEnum +{ + NUMBERING_IS_NUMBER = 0, + PARA_NUMBERING_STYLENAME = 1, //#outline level,add by zhaojianwei + //PARA_CHAPTER_NUMERBING_LEVEL = 1, //#outline level,remove by zhaojianwei + PARA_OUTLINE_LEVEL=2, //<-end.add by zhaojianwei + PARA_CONDITIONAL_STYLE_NAME = 3, + PARA_STYLE_NAME = 4, + TEXT_SECTION = 5 +}; + +void BoundFrames::Fill(const filter_t& rFilter) +{ + if(!m_xEnumAccess.is()) + return; + const Reference< XEnumeration > xEnum = m_xEnumAccess->createEnumeration(); + if(!xEnum.is()) + return; + while(xEnum->hasMoreElements()) + { + Reference<XPropertySet> xPropSet(xEnum->nextElement(), UNO_QUERY); + Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY); + if(!xPropSet.is() || !xTextContent.is()) + continue; + TextContentAnchorType eAnchor; + xPropSet->getPropertyValue(our_sAnchorType) >>= eAnchor; + if(TextContentAnchorType_AT_PAGE != eAnchor && TextContentAnchorType_AT_FRAME != eAnchor) + continue; + if(!rFilter(xTextContent)) + continue; + + TextContentSet::inserter_t pInserter = m_vPageBounds.getInserter(); + if(TextContentAnchorType_AT_FRAME == eAnchor) + { + Reference<XTextFrame> xAnchorTxtFrame( + xPropSet->getPropertyValue(our_sAnchorFrame), + uno::UNO_QUERY); + pInserter = m_vFrameBoundsOf[xAnchorTxtFrame].getInserter(); + } + *pInserter++ = xTextContent; + } +} + +BoundFrameSets::BoundFrameSets(const Reference<XInterface> xModel) + : m_pTexts(new BoundFrames()) + , m_pGraphics(new BoundFrames()) + , m_pEmbeddeds(new BoundFrames()) + , m_pShapes(new BoundFrames()) +{ + const Reference<XTextFramesSupplier> xTFS(xModel, UNO_QUERY); + const Reference<XTextGraphicObjectsSupplier> xGOS(xModel, UNO_QUERY); + const Reference<XTextEmbeddedObjectsSupplier> xEOS(xModel, UNO_QUERY); + const Reference<XDrawPageSupplier> xDPS(xModel, UNO_QUERY); + if(xTFS.is()) + m_pTexts = auto_ptr<BoundFrames>(new BoundFrames( + Reference<XEnumerationAccess>(xTFS->getTextFrames(), UNO_QUERY), + &lcl_TextContentsUnfiltered)); + if(xGOS.is()) + m_pGraphics = auto_ptr<BoundFrames>(new BoundFrames( + Reference<XEnumerationAccess>(xGOS->getGraphicObjects(), UNO_QUERY), + &lcl_TextContentsUnfiltered)); + if(xEOS.is()) + m_pEmbeddeds = auto_ptr<BoundFrames>(new BoundFrames( + Reference<XEnumerationAccess>(xEOS->getEmbeddedObjects(), UNO_QUERY), + &lcl_TextContentsUnfiltered)); + if(xDPS.is()) + m_pShapes = auto_ptr<BoundFrames>(new BoundFrames( + Reference<XEnumerationAccess>(xDPS->getDrawPage(), UNO_QUERY), + &lcl_ShapeFilter)); +}; + +void FieldParamExporter::Export() +{ + static const Type aStringType = ::getCppuType((OUString*)0); + static const Type aBoolType = ::getCppuType((sal_Bool*)0); + static const Type aSeqType = ::getCppuType((Sequence<OUString>*)0); + static const Type aIntType = ::getCppuType((sal_Int32*)0); + Sequence<OUString> vParameters(m_xFieldParams->getElementNames()); + for(const OUString* pCurrent=::comphelper::stl_begin(vParameters); pCurrent!=::comphelper::stl_end(vParameters); ++pCurrent) + { + const Any aValue = m_xFieldParams->getByName(*pCurrent); + const Type aValueType = aValue.getValueType(); + if(aValueType == aStringType) + { + OUString sValue; + aValue >>= sValue; + ExportParameter(*pCurrent,sValue); + } + else if(aValueType == aBoolType) + { + sal_Bool bValue = false; + aValue >>= bValue; + ExportParameter(*pCurrent,OUString::createFromAscii(bValue ? "true" : "false")); + } + else if(aValueType == aSeqType) + { + Sequence<OUString> vValue; + aValue >>= vValue; + for(OUString* pSeqCurrent = ::comphelper::stl_begin(vValue); pSeqCurrent != ::comphelper::stl_end(vValue); ++pSeqCurrent) + { + ExportParameter(*pCurrent, *pSeqCurrent); + } + } + else if(aValueType == aIntType) + { + sal_Int32 nValue = 0; + aValue >>= nValue; + ExportParameter(*pCurrent, OUStringBuffer().append(nValue).makeStringAndClear()); + } + } +} + +void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& sValue) +{ + m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, sKey); + m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, sValue); + m_pExport->StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False); + m_pExport->EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False); +} + +void XMLTextParagraphExport::Add( sal_uInt16 nFamily, + const Reference < XPropertySet > & rPropSet, + const XMLPropertyState** ppAddStates, bool bDontSeek ) +{ + UniReference < SvXMLExportPropertyMapper > xPropMapper; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + xPropMapper = GetParaPropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_TEXT: + xPropMapper = GetTextPropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_FRAME: + xPropMapper = GetAutoFramePropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_SECTION: + xPropMapper = GetSectionPropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_RUBY: + xPropMapper = GetRubyPropMapper(); + break; + } + DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" ); + + vector< XMLPropertyState > xPropStates = + xPropMapper->Filter( rPropSet ); + + if( ppAddStates ) + { + while( *ppAddStates ) + { + xPropStates.push_back( **ppAddStates ); + ppAddStates++; + } + } + + if( !xPropStates.empty() ) + { + Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo()); + OUString sParent, sCondParent; + sal_uInt16 nIgnoreProps = 0; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + if( xPropSetInfo->hasPropertyByName( sParaStyleName ) ) + { + rPropSet->getPropertyValue( sParaStyleName ) >>= sParent; + } + if( xPropSetInfo->hasPropertyByName( sParaConditionalStyleName ) ) + { + rPropSet->getPropertyValue( sParaConditionalStyleName ) >>= sCondParent; + } + if( xPropSetInfo->hasPropertyByName( sNumberingRules ) ) + { + Reference < XIndexReplace > xNumRule(rPropSet->getPropertyValue( sNumberingRules ), uno::UNO_QUERY); + if( xNumRule.is() && xNumRule->getCount() ) + { + Reference < XNamed > xNamed( xNumRule, UNO_QUERY ); + OUString sName; + if( xNamed.is() ) + sName = xNamed->getName(); + sal_Bool bAdd = !sName.getLength(); + if( !bAdd ) + { + Reference < XPropertySet > xNumPropSet( xNumRule, + UNO_QUERY ); + const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ); + if( xNumPropSet.is() && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sIsAutomatic ) ) + { + bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue(); + // --> OD 2007-01-12 #i73361# - check on outline style + const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) ); + if ( bAdd && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sNumberingIsOutline ) ) + { + bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue()); + } + // <-- + } + else + { + bAdd = sal_True; + } + } + if( bAdd ) + pListAutoPool->Add( xNumRule ); + } + } + break; + case XML_STYLE_FAMILY_TEXT_TEXT: + { + // Get parent and remove hyperlinks (they aren't of interest) + UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper()); + for( ::std::vector< XMLPropertyState >::iterator i(xPropStates.begin()); + nIgnoreProps < 2 && i != xPropStates.end(); ) + { + if( i->mnIndex == -1 ) + { + ++i; + continue; + } + + switch( xPM->GetEntryContextId(i->mnIndex) ) + { + case CTF_CHAR_STYLE_NAME: + case CTF_HYPERLINK_URL: + i->mnIndex = -1; + nIgnoreProps++; + i = xPropStates.erase( i ); + break; + default: + ++i; + break; + } + } + } + break; + case XML_STYLE_FAMILY_TEXT_FRAME: + if( xPropSetInfo->hasPropertyByName( sFrameStyleName ) ) + { + rPropSet->getPropertyValue( sFrameStyleName ) >>= sParent; + } + break; + case XML_STYLE_FAMILY_TEXT_SECTION: + case XML_STYLE_FAMILY_TEXT_RUBY: + ; // section styles have no parents + break; + } + if( (xPropStates.size() - nIgnoreProps) > 0 ) + { + GetAutoStylePool().Add( nFamily, sParent, xPropStates, bDontSeek ); + if( sCondParent.getLength() && sParent != sCondParent ) + GetAutoStylePool().Add( nFamily, sCondParent, xPropStates ); + } + } +} + +bool lcl_validPropState( const XMLPropertyState& rState ) +{ + return rState.mnIndex != -1; +} + +void XMLTextParagraphExport::Add( sal_uInt16 nFamily, + MultiPropertySetHelper& rPropSetHelper, + const Reference < XPropertySet > & rPropSet, + const XMLPropertyState** ppAddStates) +{ + UniReference < SvXMLExportPropertyMapper > xPropMapper; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + xPropMapper = GetParaPropMapper(); + break; + } + DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" ); + + vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet )); + if( ppAddStates ) + { + while( *ppAddStates ) + { + xPropStates.push_back( **ppAddStates ); + ++ppAddStates; + } + } + + if( rPropSetHelper.hasProperty( NUMBERING_RULES_AUTO ) ) + { + Reference < XIndexReplace > xNumRule(rPropSetHelper.getValue( NUMBERING_RULES_AUTO, + rPropSet, sal_True ), uno::UNO_QUERY); + if( xNumRule.is() && xNumRule->getCount() ) + { + Reference < XNamed > xNamed( xNumRule, UNO_QUERY ); + OUString sName; + if( xNamed.is() ) + sName = xNamed->getName(); + sal_Bool bAdd = !sName.getLength(); + if( !bAdd ) + { + Reference < XPropertySet > xNumPropSet( xNumRule, + UNO_QUERY ); + const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ); + if( xNumPropSet.is() && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sIsAutomatic ) ) + { + bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue(); + // --> OD 2007-01-12 #i73361# - check on outline style + const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) ); + if ( bAdd && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sNumberingIsOutline ) ) + { + bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue()); + } + // <-- + } + else + { + bAdd = sal_True; + } + } + if( bAdd ) + pListAutoPool->Add( xNumRule ); + } + } + + if( !xPropStates.empty() ) + { + OUString sParent, sCondParent; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + if( rPropSetHelper.hasProperty( PARA_STYLE_NAME_AUTO ) ) + { + rPropSetHelper.getValue( PARA_STYLE_NAME_AUTO, rPropSet, + sal_True ) >>= sParent; + } + if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME_AUTO ) ) + { + rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME_AUTO, + rPropSet, sal_True ) >>= sCondParent; + } + + break; + } + + if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() ) + { + GetAutoStylePool().Add( nFamily, sParent, xPropStates ); + if( sCondParent.getLength() && sParent != sCondParent ) + GetAutoStylePool().Add( nFamily, sCondParent, xPropStates ); + } + } +} + +OUString XMLTextParagraphExport::Find( + sal_uInt16 nFamily, + const Reference < XPropertySet > & rPropSet, + const OUString& rParent, + const XMLPropertyState** ppAddStates) const +{ + OUString sName( rParent ); + UniReference < SvXMLExportPropertyMapper > xPropMapper; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + xPropMapper = GetParaPropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_FRAME: + xPropMapper = GetAutoFramePropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_SECTION: + xPropMapper = GetSectionPropMapper(); + break; + case XML_STYLE_FAMILY_TEXT_RUBY: + xPropMapper = GetRubyPropMapper(); + break; + } + DBG_ASSERT( xPropMapper.is(), "There is the property mapper?" ); + if( !xPropMapper.is() ) + return sName; + vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet )); + if( ppAddStates ) + { + while( *ppAddStates ) + { + xPropStates.push_back( **ppAddStates ); + ++ppAddStates; + } + } + if( find_if( xPropStates.begin(), xPropStates.end(), lcl_validPropState ) != xPropStates.end() ) + sName = GetAutoStylePool().Find( nFamily, sName, xPropStates ); + + return sName; +} + +OUString XMLTextParagraphExport::FindTextStyleAndHyperlink( + const Reference < XPropertySet > & rPropSet, + sal_Bool& rbHyperlink, + sal_Bool& rbHasCharStyle, + sal_Bool& rbHasAutoStyle, + const XMLPropertyState** ppAddStates ) const +{ + UniReference < SvXMLExportPropertyMapper > xPropMapper(GetTextPropMapper()); + vector< XMLPropertyState > xPropStates(xPropMapper->Filter( rPropSet )); + + // Get parent and remove hyperlinks (they aren't of interest) + OUString sName; + rbHyperlink = rbHasCharStyle = rbHasAutoStyle = sal_False; + sal_uInt16 nIgnoreProps = 0; + UniReference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper()); + ::std::vector< XMLPropertyState >::iterator aFirstDel = xPropStates.end(); + ::std::vector< XMLPropertyState >::iterator aSecondDel = xPropStates.end(); + + for( ::std::vector< XMLPropertyState >::iterator + i = xPropStates.begin(); + nIgnoreProps < 2 && i != xPropStates.end(); + i++ ) + { + if( i->mnIndex == -1 ) + continue; + + switch( xPM->GetEntryContextId(i->mnIndex) ) + { + case CTF_CHAR_STYLE_NAME: + i->maValue >>= sName; + i->mnIndex = -1; + rbHasCharStyle = sName.getLength() > 0; + if( nIgnoreProps ) + aSecondDel = i; + else + aFirstDel = i; + nIgnoreProps++; + break; + case CTF_HYPERLINK_URL: + rbHyperlink = sal_True; + i->mnIndex = -1; + if( nIgnoreProps ) + aSecondDel = i; + else + aFirstDel = i; + nIgnoreProps++; + break; + } + } + if( ppAddStates ) + { + while( *ppAddStates ) + { + xPropStates.push_back( **ppAddStates ); + ppAddStates++; + } + } + if( (xPropStates.size() - nIgnoreProps) > 0L ) + { + // erase the character style, otherwise the autostyle cannot be found! + // erase the hyperlink, otherwise the autostyle cannot be found! + if ( nIgnoreProps ) + { + // If two elements of a vector have to be deleted, + // we should delete the second one first. + if( --nIgnoreProps ) + xPropStates.erase( aSecondDel ); + xPropStates.erase( aFirstDel ); + } + OUString sParent; // AutoStyles should not have parents! + sName = GetAutoStylePool().Find( XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates ); + DBG_ASSERT( sName.getLength(), "AutoStyle could not be found" ); + rbHasAutoStyle = sal_True; + } + + return sName; +} + +OUString XMLTextParagraphExport::FindTextStyle( + const Reference < XPropertySet > & rPropSet, + sal_Bool& rHasCharStyle ) const +{ + sal_Bool bDummy; + sal_Bool bDummy2; + return FindTextStyleAndHyperlink( rPropSet, bDummy, rHasCharStyle, bDummy2 ); +} + + +// --> OD 2008-04-25 #refactorlists# +// adjustments to support lists independent from list style +void XMLTextParagraphExport::exportListChange( + const XMLTextNumRuleInfo& rPrevInfo, + const XMLTextNumRuleInfo& rNextInfo ) +{ + // end a list + if ( rPrevInfo.GetLevel() > 0 ) + { + bool bRootListToBeClosed = false; + sal_Int16 nListLevelsToBeClosed = 0; + if ( !rNextInfo.BelongsToSameList( rPrevInfo ) || + rNextInfo.GetLevel() <= 0 ) + { + // close complete previous list + bRootListToBeClosed = true; + nListLevelsToBeClosed = rPrevInfo.GetLevel(); + } + else if ( rPrevInfo.GetLevel() > rNextInfo.GetLevel() ) + { + // close corresponding sub lists + DBG_ASSERT( rNextInfo.GetLevel() > 0, + "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." ); + nListLevelsToBeClosed = rPrevInfo.GetLevel() - rNextInfo.GetLevel(); + } + + if ( nListLevelsToBeClosed > 0 && + pListElements && + pListElements->Count() >= ( 2 * nListLevelsToBeClosed ) ) + { + do { + for( sal_uInt16 j = 0; j < 2; ++j ) + { + OUString *pElem = (*pListElements)[pListElements->Count()-1]; + pListElements->Remove( pListElements->Count()-1 ); + + GetExport().EndElement( *pElem, sal_True ); + + delete pElem; + } + + // remove closed list from list stack + mpTextListsHelper->PopListFromStack(); + + --nListLevelsToBeClosed; + } while ( nListLevelsToBeClosed > 0 ); + } + } + + const bool bExportODF = + ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0; + const SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion = + GetExport().getDefaultVersion(); + + // start a new list + if ( rNextInfo.GetLevel() > 0 ) + { + bool bRootListToBeStarted = false; + sal_Int16 nListLevelsToBeOpened = 0; + if ( !rPrevInfo.BelongsToSameList( rNextInfo ) || + rPrevInfo.GetLevel() <= 0 ) + { + // new root list + bRootListToBeStarted = true; + nListLevelsToBeOpened = rNextInfo.GetLevel(); + } + else if ( rNextInfo.GetLevel() > rPrevInfo.GetLevel() ) + { + // open corresponding sub lists + DBG_ASSERT( rPrevInfo.GetLevel() > 0, + "<rPrevInfo.GetLevel() > 0> not hold. Serious defect -> please inform OD." ); + nListLevelsToBeOpened = rNextInfo.GetLevel() - rPrevInfo.GetLevel(); + } + + if ( nListLevelsToBeOpened > 0 ) + { + const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() ); + // Currently only the text documents support <ListId>. + // Thus, for other document types <sListId> is empty. + const ::rtl::OUString sListId( rNextInfo.GetListId() ); + bool bExportListStyle( true ); + bool bRestartNumberingAtContinuedRootList( false ); + sal_Int16 nRestartValueForContinuedRootList( -1 ); + // --> OD 2008-11-26 #158694# + bool bContinueingPreviousSubList = !bRootListToBeStarted && + rNextInfo.IsContinueingPreviousSubTree(); + // <-- + do { + GetExport().CheckAttrList(); + + if ( bRootListToBeStarted ) + { + if ( !mpTextListsHelper->IsListProcessed( sListId ) ) + { + if ( bExportODF && + eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 && + sListId.getLength() > 0 ) + { + // --> OD 2008-07-31 #i92221# + GetExport().AddAttribute( XML_NAMESPACE_XML, + XML_ID, + sListId ); + // <-- + } + mpTextListsHelper->KeepListAsProcessed( sListId, + sListStyleName, + ::rtl::OUString() ); + } + else + { + const ::rtl::OUString sNewListId( + mpTextListsHelper->GenerateNewListId() ); + if ( bExportODF && + eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 && + sListId.getLength() > 0 ) + { + // --> OD 2008-07-31 #i92221# + GetExport().AddAttribute( XML_NAMESPACE_XML, + XML_ID, + sNewListId ); + // <-- + } + + const ::rtl::OUString sContinueListId = + mpTextListsHelper->GetLastContinuingListId( sListId ); + // store that list with list id <sNewListId> is last list, + // which has continued list with list id <sListId> + mpTextListsHelper->StoreLastContinuingList( sListId, + sNewListId ); + if ( sListStyleName == + mpTextListsHelper->GetListStyleOfLastProcessedList() && + // --> OD 2008-08-15 #i92811# + sContinueListId == + mpTextListsHelper->GetLastProcessedListId() && + // <-- + !rNextInfo.IsRestart() ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_CONTINUE_NUMBERING, + XML_TRUE ); + } + else + { + if ( bExportODF && + eODFDefaultVersion >= SvtSaveOptions::ODFVER_012 && + sListId.getLength() > 0 ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_CONTINUE_LIST, + sContinueListId ); + } + + if ( rNextInfo.IsRestart() && + ( nListLevelsToBeOpened != 1 || + !rNextInfo.HasStartValue() ) ) + { + bRestartNumberingAtContinuedRootList = true; + nRestartValueForContinuedRootList = + rNextInfo.GetListLevelStartValue(); + } + } + + mpTextListsHelper->KeepListAsProcessed( sNewListId, + sListStyleName, + sContinueListId ); + } + + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sListStyleName ) ); + bExportListStyle = false; + + bRootListToBeStarted = false; + } + else if ( bExportListStyle && + !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sListStyleName ) ); + bExportListStyle = false; + } + + // --> OD 2008-11-26 #158694# + if ( bContinueingPreviousSubList ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_CONTINUE_NUMBERING, XML_TRUE ); + bContinueingPreviousSubList = false; + } + // <-- + + enum XMLTokenEnum eLName = XML_LIST; + + OUString *pElem = new OUString( + GetExport().GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, + GetXMLToken(eLName) ) ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( *pElem, sal_False ); + + if( !pListElements ) + pListElements = new OUStrings_Impl; + pListElements->Insert( pElem, pListElements->Count() ); + + mpTextListsHelper->PushListOnStack( sListId, + sListStyleName ); + + // <text:list-header> or <text:list-item> + GetExport().CheckAttrList(); + + // --> OD 2009-06-24 #i97309# + // export start value in case of <bRestartNumberingAtContinuedRootList> + // at correct list item + if ( nListLevelsToBeOpened == 1 ) + { + if ( rNextInfo.HasStartValue() ) + { + OUStringBuffer aBuffer; + aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, + aBuffer.makeStringAndClear() ); + } + else if ( bRestartNumberingAtContinuedRootList ) + { + OUStringBuffer aBuffer; + aBuffer.append( (sal_Int32)nRestartValueForContinuedRootList ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_START_VALUE, + aBuffer.makeStringAndClear() ); + bRestartNumberingAtContinuedRootList = false; + } + } + // <-- + + eLName = ( rNextInfo.IsNumbered() || nListLevelsToBeOpened > 1 ) + ? XML_LIST_ITEM + : XML_LIST_HEADER; + pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, + GetXMLToken(eLName) ) ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( *pElem, sal_False ); + + pListElements->Insert( pElem, pListElements->Count() ); + + // --> OD 2008-11-26 #158694# + // export of <text:number> element for last opened <text:list-item>, if requested + if ( GetExport().exportTextNumberElement() && + eLName == XML_LIST_ITEM && nListLevelsToBeOpened == 1 && // last iteration --> last opened <text:list-item> + rNextInfo.ListLabelString().getLength() > 0 ) + { + const ::rtl::OUString aTextNumberElem = + OUString( GetExport().GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, + GetXMLToken(XML_NUMBER) ) ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( aTextNumberElem, sal_False ); + GetExport().Characters( rNextInfo.ListLabelString() ); + GetExport().EndElement( aTextNumberElem, sal_True ); + } + // <-- + + --nListLevelsToBeOpened; + } while ( nListLevelsToBeOpened > 0 ); + } + } + + if ( rNextInfo.GetLevel() > 0 && + rNextInfo.IsNumbered() && + rPrevInfo.BelongsToSameList( rNextInfo ) && + rPrevInfo.GetLevel() >= rNextInfo.GetLevel() ) + { + // close previous list-item + DBG_ASSERT( pListElements && pListElements->Count() >= 2, + "SwXMLExport::ExportListChange: list elements missing" ); + + OUString *pElem = (*pListElements)[pListElements->Count()-1]; + GetExport().EndElement( *pElem, sal_True ); + + pListElements->Remove( pListElements->Count()-1 ); + delete pElem; + + // --> OD 2009-11-12 #i103745# - only for sub lists + if ( rNextInfo.IsRestart() && !rNextInfo.HasStartValue() && + rNextInfo.GetLevel() != 1 ) + // <-- + { + // start new sub list respectively list on same list level + pElem = (*pListElements)[pListElements->Count()-1]; + GetExport().EndElement( *pElem, sal_True ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( *pElem, sal_False ); + } + + // open new list-item + GetExport().CheckAttrList(); + if( rNextInfo.HasStartValue() ) + { + OUStringBuffer aBuffer; + aBuffer.append( (sal_Int32)rNextInfo.GetStartValue() ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, + aBuffer.makeStringAndClear() ); + } + // --> OD 2009-11-12 #i103745# - handle restart without start value on list level 1 + else if ( rNextInfo.IsRestart() && /*!rNextInfo.HasStartValue() &&*/ + rNextInfo.GetLevel() == 1 ) + { + OUStringBuffer aBuffer; + aBuffer.append( (sal_Int32)rNextInfo.GetListLevelStartValue() ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, + aBuffer.makeStringAndClear() ); + } + // <-- + if ( ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 && + GetExport().getDefaultVersion() >= SvtSaveOptions::ODFVER_012 ) + { + const ::rtl::OUString sListStyleName( rNextInfo.GetNumRulesName() ); + if ( !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_STYLE_OVERRIDE, + GetExport().EncodeStyleName( sListStyleName ) ); + } + } + pElem = new OUString( GetExport().GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, + GetXMLToken(XML_LIST_ITEM) ) ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( *pElem, sal_False ); + + pListElements->Insert( pElem, pListElements->Count() ); + + // --> OD 2008-11-26 #158694# + // export of <text:number> element for <text:list-item>, if requested + if ( GetExport().exportTextNumberElement() && + rNextInfo.ListLabelString().getLength() > 0 ) + { + const ::rtl::OUString aTextNumberElem = + OUString( GetExport().GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, + GetXMLToken(XML_NUMBER) ) ); + GetExport().IgnorableWhitespace(); + GetExport().StartElement( aTextNumberElem, sal_False ); + GetExport().Characters( rNextInfo.ListLabelString() ); + GetExport().EndElement( aTextNumberElem, sal_True ); + } + // <-- + } +} +// <-- + +XMLTextParagraphExport::XMLTextParagraphExport( + SvXMLExport& rExp, + SvXMLAutoStylePoolP & rASP + ) : + XMLStyleExport( rExp, OUString(), &rASP ), + rAutoStylePool( rASP ), + pBoundFrameSets(new BoundFrameSets(GetExport().GetModel())), + pFieldExport( 0 ), + pListElements( 0 ), + // --> OD 2008-05-07 #refactorlists# - no longer needed +// pExportedLists( 0 ), + // <-- + pListAutoPool( new XMLTextListAutoStylePool( this->GetExport() ) ), + pSectionExport( NULL ), + pIndexMarkExport( NULL ), + + pRedlineExport( NULL ), + pHeadingStyles( NULL ), + + bProgress( sal_False ), + bBlock( sal_False ), + + bOpenRuby( sal_False ), + // --> OD 2008-04-25 #refactorlists# + mpTextListsHelper( 0 ), + maTextListsHelperStack(), + // <-- + + sActualSize(RTL_CONSTASCII_USTRINGPARAM("ActualSize")), + // --> OD 2009-07-22 #i73249# +// sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")), + sTitle(RTL_CONSTASCII_USTRINGPARAM("Title")), + sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")), + // <-- + sAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName")), + sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")), + sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")), + sBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice")), + sBookmark(RTL_CONSTASCII_USTRINGPARAM("Bookmark")), + sCategory(RTL_CONSTASCII_USTRINGPARAM("Category")), + sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName")), + sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")), + sCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")), + sContourPolyPolygon(RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon")), + sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex")), + sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark")), + sEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice")), + sFootnote(RTL_CONSTASCII_USTRINGPARAM("Footnote")), + sFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting")), + sFrame(RTL_CONSTASCII_USTRINGPARAM("Frame")), + sFrameHeightAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameHeightAbsolute")), + sFrameHeightPercent(RTL_CONSTASCII_USTRINGPARAM("FrameHeightPercent")), + sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName")), + sFrameWidthAbsolute(RTL_CONSTASCII_USTRINGPARAM("FrameWidthAbsolute")), + sFrameWidthPercent(RTL_CONSTASCII_USTRINGPARAM("FrameWidthPercent")), + sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")), + sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")), + sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), + sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")), + sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")), + sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")), + sHyperLinkName(RTL_CONSTASCII_USTRINGPARAM("HyperLinkName")), + sHyperLinkTarget(RTL_CONSTASCII_USTRINGPARAM("HyperLinkTarget")), + sHyperLinkURL(RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")), + sIsAutomaticContour(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour")), + sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed")), + sIsPixelContour(RTL_CONSTASCII_USTRINGPARAM("IsPixelContour")), + sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart")), + sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth")), + sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight")), + sNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules")), + sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")), + sPageDescName(RTL_CONSTASCII_USTRINGPARAM("PageDescName")), + sPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName")), + sParaChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ParaChapterNumberingLevel")), + sParaConditionalStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaConditionalStyleName")), + sParagraphService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Paragraph")), + sParaStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")), + sPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc")), + sPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix")), + sRedline(RTL_CONSTASCII_USTRINGPARAM("Redline")), + sReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId")), + sReferenceMark(RTL_CONSTASCII_USTRINGPARAM("ReferenceMark")), + sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight")), + sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth")), + sRuby(RTL_CONSTASCII_USTRINGPARAM("Ruby")), + sRubyAdjust(RTL_CONSTASCII_USTRINGPARAM("RubyAdjust")), + sRubyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("RubyCharStyleName")), + sRubyText(RTL_CONSTASCII_USTRINGPARAM("RubyText")), + sServerMap(RTL_CONSTASCII_USTRINGPARAM("ServerMap")), + sShapeService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shape")), + sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType")), + sSoftPageBreak( RTL_CONSTASCII_USTRINGPARAM( "SoftPageBreak" ) ), + sStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt")), + sSuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix")), + sTableService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextTable")), + sText(RTL_CONSTASCII_USTRINGPARAM("Text")), + sTextContentService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextContent")), + sTextEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject")), + sTextEndnoteService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote")), + sTextField(RTL_CONSTASCII_USTRINGPARAM("TextField")), + sTextFieldService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField")), + sTextFrameService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame")), + sTextGraphicService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextGraphicObject")), + sTextPortionType(RTL_CONSTASCII_USTRINGPARAM("TextPortionType")), + sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection")), + sUnvisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("UnvisitedCharStyleName")), + sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient")), + sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition")), + sVisitedCharStyleName(RTL_CONSTASCII_USTRINGPARAM("VisitedCharStyleName")), + sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")), + sWidthType( RTL_CONSTASCII_USTRINGPARAM( "WidthType" ) ), + sTextFieldStart( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStart" ) ), + sTextFieldEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldEnd" ) ), + sTextFieldStartEnd( RTL_CONSTASCII_USTRINGPARAM( "TextFieldStartEnd" ) ), + aCharStyleNamesPropInfoCache( sCharStyleNames ) +{ + UniReference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TEXT_PROP_MAP_PARA )); + xParaPropMapper = new XMLTextExportPropertySetMapper( xPropMapper, + GetExport() ); + + OUString sFamily( GetXMLToken(XML_PARAGRAPH) ); + OUString aPrefix( String( 'P' ) ); + rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_PARAGRAPH, sFamily, + xParaPropMapper, aPrefix ); + + xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT ); + xTextPropMapper = new XMLTextExportPropertySetMapper( xPropMapper, + GetExport() ); + sFamily = OUString( GetXMLToken(XML_TEXT) ); + aPrefix = OUString( String( 'T' ) ); + rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_TEXT, sFamily, + xTextPropMapper, aPrefix ); + + xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_AUTO_FRAME ); + xAutoFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper, + GetExport() ); + sFamily = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME) ); + aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "fr" ) ); + rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_FRAME, sFamily, + xAutoFramePropMapper, aPrefix ); + + xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_SECTION ); + xSectionPropMapper = new XMLTextExportPropertySetMapper( xPropMapper, + GetExport() ); + sFamily = OUString( GetXMLToken( XML_SECTION ) ); + aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Sect" ) ); + rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_SECTION, sFamily, + xSectionPropMapper, aPrefix ); + + xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_RUBY ); + xRubyPropMapper = new SvXMLExportPropertyMapper( xPropMapper ); + sFamily = OUString( GetXMLToken( XML_RUBY ) ); + aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM( "Ru" ) ); + rAutoStylePool.AddFamily( XML_STYLE_FAMILY_TEXT_RUBY, sFamily, + xRubyPropMapper, aPrefix ); + + xPropMapper = new XMLTextPropertySetMapper( TEXT_PROP_MAP_FRAME ); + xFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper, + GetExport() ); + + pSectionExport = new XMLSectionExport( rExp, *this ); + pIndexMarkExport = new XMLIndexMarkExport( rExp, *this ); + + if( ! IsBlockMode() && + Reference<XRedlinesSupplier>( GetExport().GetModel(), UNO_QUERY ).is()) + pRedlineExport = new XMLRedlineExport( rExp ); + + // The text field helper needs a pre-constructed XMLPropertyState + // to export the combined characters field. We construct that + // here, because we need the text property mapper to do it. + + // construct Any value, then find index + sal_Int32 nIndex = xTextPropMapper->getPropertySetMapper()->FindEntryIndex( + "", XML_NAMESPACE_STYLE, + GetXMLToken(XML_TEXT_COMBINE)); + pFieldExport = new XMLTextFieldExport( rExp, new XMLPropertyState( nIndex, uno::makeAny(sal_True) ) ); + + // --> OD 2008-05-08 #refactorlists# + PushNewTextListsHelper(); + // <-- +} + +XMLTextParagraphExport::~XMLTextParagraphExport() +{ + delete pHeadingStyles; + delete pRedlineExport; + delete pIndexMarkExport; + delete pSectionExport; + delete pFieldExport; + delete pListElements; + // --> OD 2008-05-07 #refactorlists# - no longer needed +// delete pExportedLists; + // <-- + delete pListAutoPool; +#ifdef DBG_UTIL + txtparae_bContainsIllegalCharacters = sal_False; +#endif + // --> OD 2008-04-25 #refactorlists# + // also deletes <mpTextListsHelper> + PopTextListsHelper(); + DBG_ASSERT( maTextListsHelperStack.size() == 0, + "misusage of text lists helper stack - it is not empty. Serious defect - please inform OD" ); + // <-- +} + +SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateShapeExtPropMapper( + SvXMLExport& rExport ) +{ + UniReference < XMLPropertySetMapper > xPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE ); + return new XMLTextExportPropertySetMapper( xPropMapper, rExport ); +} + +SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateCharExtPropMapper( + SvXMLExport& rExport) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT ); + return new XMLTextExportPropertySetMapper( pPropMapper, rExport ); +} + +SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaExtPropMapper( + SvXMLExport& rExport) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_SHAPE_PARA ); + return new XMLTextExportPropertySetMapper( pPropMapper, rExport ); +} + +SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaDefaultExtPropMapper( + SvXMLExport& rExport) +{ + XMLPropertySetMapper *pPropMapper = + new XMLTextPropertySetMapper( TEXT_PROP_MAP_TEXT_ADDITIONAL_DEFAULTS ); + return new XMLTextExportPropertySetMapper( pPropMapper, rExport ); +} + +void XMLTextParagraphExport::exportPageFrames( sal_Bool bAutoStyles, + sal_Bool bIsProgress ) +{ + const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetPageBoundContents(); + const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetPageBoundContents(); + const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetPageBoundContents(); + const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetPageBoundContents(); + for(TextContentSet::const_iterator_t it = pTexts->getBegin(); + it != pTexts->getEnd(); + ++it) + exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True); + for(TextContentSet::const_iterator_t it = pGraphics->getBegin(); + it != pGraphics->getEnd(); + ++it) + exportTextGraphic(*it, bAutoStyles); + for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin(); + it != pEmbeddeds->getEnd(); + ++it) + exportTextEmbedded(*it, bAutoStyles); + for(TextContentSet::const_iterator_t it = pShapes->getBegin(); + it != pShapes->getEnd(); + ++it) + exportShape(*it, bAutoStyles); +} + +void XMLTextParagraphExport::exportFrameFrames( + sal_Bool bAutoStyles, + sal_Bool bIsProgress, + const Reference < XTextFrame > *pParentTxtFrame ) +{ + const TextContentSet* const pTexts = pBoundFrameSets->GetTexts()->GetFrameBoundContents(*pParentTxtFrame); + if(pTexts) + for(TextContentSet::const_iterator_t it = pTexts->getBegin(); + it != pTexts->getEnd(); + ++it) + exportTextFrame(*it, bAutoStyles, bIsProgress, sal_True); + const TextContentSet* const pGraphics = pBoundFrameSets->GetGraphics()->GetFrameBoundContents(*pParentTxtFrame); + if(pGraphics) + for(TextContentSet::const_iterator_t it = pGraphics->getBegin(); + it != pGraphics->getEnd(); + ++it) + exportTextGraphic(*it, bAutoStyles); + const TextContentSet* const pEmbeddeds = pBoundFrameSets->GetEmbeddeds()->GetFrameBoundContents(*pParentTxtFrame); + if(pEmbeddeds) + for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin(); + it != pEmbeddeds->getEnd(); + ++it) + exportTextEmbedded(*it, bAutoStyles); + const TextContentSet* const pShapes = pBoundFrameSets->GetShapes()->GetFrameBoundContents(*pParentTxtFrame); + if(pShapes) + for(TextContentSet::const_iterator_t it = pShapes->getBegin(); + it != pShapes->getEnd(); + ++it) + exportShape(*it, bAutoStyles); +} + +// bookmarks, reference marks (and TOC marks) are the same except for the +// element names. We use the same method for export and it an array with +// the proper element names +static const enum XMLTokenEnum lcl_XmlReferenceElements[] = { + XML_REFERENCE_MARK, XML_REFERENCE_MARK_START, XML_REFERENCE_MARK_END }; +static const enum XMLTokenEnum lcl_XmlBookmarkElements[] = { + XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END }; + +// This function replaces the text portion iteration during auto style +// collection. +bool XMLTextParagraphExport::collectTextAutoStylesOptimized( sal_Bool bIsProgress ) +{ + GetExport().GetShapeExport(); // make sure the graphics styles family is added + + const sal_Bool bAutoStyles = sal_True; + const sal_Bool bExportContent = sal_False; + + // Export AutoStyles: + Reference< XAutoStylesSupplier > xAutoStylesSupp( GetExport().GetModel(), UNO_QUERY ); + if ( xAutoStylesSupp.is() ) + { + Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles(); + OUString sName; + sal_uInt16 nFamily; + + for ( int i = 0; i < 3; ++i ) + { + if ( 0 == i ) + { + sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) ); + nFamily = XML_STYLE_FAMILY_TEXT_TEXT; + } + else if ( 1 == i ) + { + sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "RubyStyles" ) ); + nFamily = XML_STYLE_FAMILY_TEXT_RUBY; + } + else + { + sName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ); + nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH; + } + + Any aAny = xAutoStyleFamilies->getByName( sName ); + Reference< XAutoStyleFamily > xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue(); + Reference < XEnumeration > xAutoStylesEnum( xAutoStyles->createEnumeration() ); + + while ( xAutoStylesEnum->hasMoreElements() ) + { + aAny = xAutoStylesEnum->nextElement(); + Reference< XAutoStyle > xAutoStyle = *(Reference<XAutoStyle>*)aAny.getValue(); + Reference < XPropertySet > xPSet( xAutoStyle, uno::UNO_QUERY ); + Add( nFamily, xPSet, 0, true ); + } + } + } + + // Export Field AutoStyles: + Reference< XTextFieldsSupplier > xTextFieldsSupp( GetExport().GetModel(), UNO_QUERY ); + if ( xTextFieldsSupp.is() ) + { + Reference< XEnumerationAccess > xTextFields = xTextFieldsSupp->getTextFields(); + Reference < XEnumeration > xTextFieldsEnum( xTextFields->createEnumeration() ); + + while ( xTextFieldsEnum->hasMoreElements() ) + { + Any aAny = xTextFieldsEnum->nextElement(); + Reference< XTextField > xTextField = *(Reference<XTextField>*)aAny.getValue(); + exportTextField( xTextField, bAutoStyles, bIsProgress, + !xAutoStylesSupp.is() ); + try + { + Reference < XPropertySet > xSet( xTextField, UNO_QUERY ); + Reference < XText > xText; + Any a = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("TextRange") ); + a >>= xText; + if ( xText.is() ) + { + exportText( xText, sal_True, bIsProgress, bExportContent ); + GetExport().GetTextParagraphExport() + ->collectTextAutoStyles( xText ); + } + } + catch (Exception&) + { + } + } + } + + // Export text frames: + Reference<XEnumeration> xTextFramesEnum = pBoundFrameSets->GetTexts()->createEnumeration(); + if(xTextFramesEnum.is()) + while(xTextFramesEnum->hasMoreElements()) + { + Reference<XTextContent> xTxtCntnt(xTextFramesEnum->nextElement(), UNO_QUERY); + if(xTxtCntnt.is()) + exportTextFrame(xTxtCntnt, bAutoStyles, bIsProgress, bExportContent, 0); + } + + // Export graphic objects: + Reference<XEnumeration> xGraphicsEnum = pBoundFrameSets->GetGraphics()->createEnumeration(); + if(xGraphicsEnum.is()) + while(xGraphicsEnum->hasMoreElements()) + { + Reference<XTextContent> xTxtCntnt(xGraphicsEnum->nextElement(), UNO_QUERY); + if(xTxtCntnt.is()) + exportTextGraphic(xTxtCntnt, true, 0); + } + + // Export embedded objects: + Reference<XEnumeration> xEmbeddedsEnum = pBoundFrameSets->GetEmbeddeds()->createEnumeration(); + if(xEmbeddedsEnum.is()) + while(xEmbeddedsEnum->hasMoreElements()) + { + Reference<XTextContent> xTxtCntnt(xEmbeddedsEnum->nextElement(), UNO_QUERY); + if(xTxtCntnt.is()) + exportTextEmbedded(xTxtCntnt, true, 0); + } + + // Export shapes: + Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration(); + if(xShapesEnum.is()) + while(xShapesEnum->hasMoreElements()) + { + Reference<XTextContent> xTxtCntnt(xShapesEnum->nextElement(), UNO_QUERY); + if(xTxtCntnt.is()) + { + Reference<XServiceInfo> xServiceInfo(xTxtCntnt, UNO_QUERY); + if( xServiceInfo->supportsService(sShapeService)) + exportShape(xTxtCntnt, true, 0); + } + } + + sal_Int32 nCount; + // AutoStyles for sections + Reference< XTextSectionsSupplier > xSectionsSupp( GetExport().GetModel(), UNO_QUERY ); + if ( xSectionsSupp.is() ) + { + Reference< XIndexAccess > xSections( xSectionsSupp->getTextSections(), UNO_QUERY ); + if ( xSections.is() ) + { + nCount = xSections->getCount(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + Any aAny = xSections->getByIndex( i ); + Reference< XTextSection > xSection = *(Reference<XTextSection>*)aAny.getValue(); + Reference < XPropertySet > xPSet( xSection, uno::UNO_QUERY ); + Add( XML_STYLE_FAMILY_TEXT_SECTION, xPSet ); + } + } + } + + // AutoStyles for tables (Note: suppress autostyle collection for paragraphs in exportTable) + Reference< XTextTablesSupplier > xTablesSupp( GetExport().GetModel(), UNO_QUERY ); + if ( xTablesSupp.is() ) + { + Reference< XIndexAccess > xTables( xTablesSupp->getTextTables(), UNO_QUERY ); + if ( xTables.is() ) + { + nCount = xTables->getCount(); + for( sal_Int32 i = 0; i < nCount; ++i ) + { + Any aAny = xTables->getByIndex( i ); + Reference< XTextTable > xTable = *(Reference<XTextTable>*)aAny.getValue(); + Reference < XTextContent > xTextContent( xTable, uno::UNO_QUERY ); + exportTable( xTextContent, sal_True, sal_True ); + } + } + } + + Reference< XNumberingRulesSupplier > xNumberingRulesSupp( GetExport().GetModel(), UNO_QUERY ); + if ( xNumberingRulesSupp.is() ) + { + Reference< XIndexAccess > xNumberingRules = xNumberingRulesSupp->getNumberingRules(); + nCount = xNumberingRules->getCount(); + // --> OD 2007-01-12 #i73361# + const OUString sNumberingIsOutline( RTL_CONSTASCII_USTRINGPARAM( "NumberingIsOutline" ) ); + // <-- + for( sal_Int32 i = 0; i < nCount; ++i ) + { + Reference< XIndexReplace > xNumRule( xNumberingRules->getByIndex( i ), UNO_QUERY ); + if( xNumRule.is() && xNumRule->getCount() ) + { + Reference < XNamed > xNamed( xNumRule, UNO_QUERY ); + OUString sName; + if( xNamed.is() ) + sName = xNamed->getName(); + sal_Bool bAdd = !sName.getLength(); + if( !bAdd ) + { + Reference < XPropertySet > xNumPropSet( xNumRule, + UNO_QUERY ); + const OUString sIsAutomatic( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ); + if( xNumPropSet.is() && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sIsAutomatic ) ) + { + bAdd = *(sal_Bool *)xNumPropSet->getPropertyValue( sIsAutomatic ).getValue(); + // --> OD 2007-01-12 #i73361# - check on outline style + if ( bAdd && + xNumPropSet->getPropertySetInfo() + ->hasPropertyByName( sNumberingIsOutline ) ) + { + bAdd = !(*(sal_Bool *)xNumPropSet->getPropertyValue( sNumberingIsOutline ).getValue()); + } + // <-- + } + else + { + bAdd = sal_True; + } + } + if( bAdd ) + pListAutoPool->Add( xNumRule ); + } + } + } + + return true; +} + +void XMLTextParagraphExport::exportText( + const Reference < XText > & rText, + sal_Bool bAutoStyles, + sal_Bool bIsProgress, + sal_Bool bExportParagraph ) +{ + if( bAutoStyles ) + GetExport().GetShapeExport(); // make sure the graphics styles family + // is added + Reference < XEnumerationAccess > xEA( rText, UNO_QUERY ); + Reference < XEnumeration > xParaEnum(xEA->createEnumeration()); + Reference < XPropertySet > xPropertySet( rText, UNO_QUERY ); + Reference < XTextSection > xBaseSection; + + // #97718# footnotes don't supply paragraph enumerations in some cases + // This is always a bug, but at least we don't want to crash. + DBG_ASSERT( xParaEnum.is(), "We need a paragraph enumeration" ); + if( ! xParaEnum.is() ) + return; + + sal_Bool bExportLevels = sal_True; + + if (xPropertySet.is()) + { + Reference < XPropertySetInfo > xInfo ( xPropertySet->getPropertySetInfo() ); + + if( xInfo.is() ) + { + if (xInfo->hasPropertyByName( sTextSection )) + { + xPropertySet->getPropertyValue(sTextSection) >>= xBaseSection ; + } + +/* #i35937# + // for applications that use the outliner we need to check if + // the current text object needs the level information exported + if( !bAutoStyles ) + { + // fixme: move string to class member, couldn't do now because + // of no incompatible build + OUString sHasLevels( RTL_CONSTASCII_USTRINGPARAM("HasLevels") ); + if (xInfo->hasPropertyByName( sHasLevels ) ) + { + xPropertySet->getPropertyValue(sHasLevels) >>= bExportLevels; + } + } +*/ + } + } + + // #96530# Export redlines at start & end of XText before & after + // exporting the text content enumeration + if( !bAutoStyles && (pRedlineExport != NULL) ) + pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True ); + exportTextContentEnumeration( xParaEnum, bAutoStyles, xBaseSection, + bIsProgress, bExportParagraph, 0, bExportLevels ); + if( !bAutoStyles && (pRedlineExport != NULL) ) + pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False ); +} + +void XMLTextParagraphExport::exportText( + const Reference < XText > & rText, + const Reference < XTextSection > & rBaseSection, + sal_Bool bAutoStyles, + sal_Bool bIsProgress, + sal_Bool bExportParagraph ) +{ + if( bAutoStyles ) + GetExport().GetShapeExport(); // make sure the graphics styles family + // is added + Reference < XEnumerationAccess > xEA( rText, UNO_QUERY ); + Reference < XEnumeration > xParaEnum(xEA->createEnumeration()); + + // #98165# don't continue without a paragraph enumeration + if( ! xParaEnum.is() ) + return; + + // #96530# Export redlines at start & end of XText before & after + // exporting the text content enumeration + Reference<XPropertySet> xPropertySet; + if( !bAutoStyles && (pRedlineExport != NULL) ) + { + xPropertySet.set(rText, uno::UNO_QUERY ); + pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_True ); + } + exportTextContentEnumeration( xParaEnum, bAutoStyles, rBaseSection, + bIsProgress, bExportParagraph ); + if( !bAutoStyles && (pRedlineExport != NULL) ) + pRedlineExport->ExportStartOrEndRedline( xPropertySet, sal_False ); +} + +sal_Bool XMLTextParagraphExport::exportTextContentEnumeration( + const Reference < XEnumeration > & rContEnum, + sal_Bool bAutoStyles, + const Reference < XTextSection > & rBaseSection, + sal_Bool bIsProgress, + sal_Bool bExportParagraph, + const Reference < XPropertySet > *pRangePropSet, + sal_Bool bExportLevels ) +{ + DBG_ASSERT( rContEnum.is(), "No enumeration to export!" ); + sal_Bool bHasMoreElements = rContEnum->hasMoreElements(); + if( !bHasMoreElements ) + return sal_False; + + XMLTextNumRuleInfo aPrevNumInfo; + XMLTextNumRuleInfo aNextNumInfo; + + sal_Bool bHasContent = sal_False; + Reference<XTextSection> xCurrentTextSection(rBaseSection); + + MultiPropertySetHelper aPropSetHelper( + bAutoStyles ? aParagraphPropertyNamesAuto : + aParagraphPropertyNames ); + + sal_Bool bHoldElement = sal_False; + Reference < XTextContent > xTxtCntnt; + while( bHoldElement || bHasMoreElements ) + { + if (bHoldElement) + { + bHoldElement = sal_False; + } + else + { + xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY); + + aPropSetHelper.resetValues(); + + } + + Reference<XServiceInfo> xServiceInfo( xTxtCntnt, UNO_QUERY ); + if( xServiceInfo->supportsService( sParagraphService ) ) + { + if( bExportLevels ) + { + if( bAutoStyles ) + { + exportListAndSectionChange( xCurrentTextSection, xTxtCntnt, + aPrevNumInfo, aNextNumInfo, + bAutoStyles ); + } + else + { + // --> OD 2006-09-27 #i69627# + // --> OD 2008-04-24 #refactorlists# + // pass list auto style pool to <XMLTextNumRuleInfo> instance + // --> OD 2008-11-26 #158694# + // pass info about request to export <text:number> element + // to <XMLTextNumRuleInfo> instance + aNextNumInfo.Set( xTxtCntnt, + GetExport().writeOutlineStyleAsNormalListStyle(), + GetListAutoStylePool(), + GetExport().exportTextNumberElement() ); + // <-- + + exportListAndSectionChange( xCurrentTextSection, aPropSetHelper, + TEXT_SECTION, xTxtCntnt, + aPrevNumInfo, aNextNumInfo, + bAutoStyles ); + } + } + + // if we found a mute section: skip all section content + if (pSectionExport->IsMuteSection(xCurrentTextSection)) + { + // Make sure headings are exported anyway. + if( !bAutoStyles ) + pSectionExport->ExportMasterDocHeadingDummies(); + + while (rContEnum->hasMoreElements() && + pSectionExport->IsInSection( xCurrentTextSection, + xTxtCntnt, sal_True )) + { + xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY); + aPropSetHelper.resetValues(); + aNextNumInfo.Reset(); + } + // the first non-mute element still needs to be processed + bHoldElement = + ! pSectionExport->IsInSection( xCurrentTextSection, + xTxtCntnt, sal_False ); + } + else + exportParagraph( xTxtCntnt, bAutoStyles, bIsProgress, + bExportParagraph, aPropSetHelper ); + bHasContent = sal_True; + } + else if( xServiceInfo->supportsService( sTableService ) ) + { + if( !bAutoStyles ) + { + aNextNumInfo.Reset(); + } + + exportListAndSectionChange( xCurrentTextSection, xTxtCntnt, + aPrevNumInfo, aNextNumInfo, + bAutoStyles ); + + if (! pSectionExport->IsMuteSection(xCurrentTextSection)) + { + // export start + end redlines (for wholly redlined tables) + if ((! bAutoStyles) && (NULL != pRedlineExport)) + pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_True); + + exportTable( xTxtCntnt, bAutoStyles, bIsProgress ); + + if ((! bAutoStyles) && (NULL != pRedlineExport)) + pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, sal_False); + } + else if( !bAutoStyles ) + { + // Make sure headings are exported anyway. + pSectionExport->ExportMasterDocHeadingDummies(); + } + + bHasContent = sal_True; + } + else if( xServiceInfo->supportsService( sTextFrameService ) ) + { + exportTextFrame( xTxtCntnt, bAutoStyles, bIsProgress, sal_True, pRangePropSet ); + } + else if( xServiceInfo->supportsService( sTextGraphicService ) ) + { + exportTextGraphic( xTxtCntnt, bAutoStyles, pRangePropSet ); + } + else if( xServiceInfo->supportsService( sTextEmbeddedService ) ) + { + exportTextEmbedded( xTxtCntnt, bAutoStyles, pRangePropSet ); + } + else if( xServiceInfo->supportsService( sShapeService ) ) + { + exportShape( xTxtCntnt, bAutoStyles, pRangePropSet ); + } + else + { + DBG_ASSERT( !xTxtCntnt.is(), "unknown text content" ); + } + + if( !bAutoStyles ) + { + aPrevNumInfo = aNextNumInfo; + } + + bHasMoreElements = rContEnum->hasMoreElements(); + } + + if( bExportLevels && bHasContent && !bAutoStyles ) + { + aNextNumInfo.Reset(); + + // close open lists and sections; no new styles + exportListAndSectionChange( xCurrentTextSection, rBaseSection, + aPrevNumInfo, aNextNumInfo, + bAutoStyles ); + } + + return sal_True; +} + +void XMLTextParagraphExport::exportParagraph( + const Reference < XTextContent > & rTextContent, + sal_Bool bAutoStyles, sal_Bool bIsProgress, sal_Bool bExportParagraph, + MultiPropertySetHelper& rPropSetHelper) +{ + sal_Int16 nOutlineLevel = -1; + + if( bIsProgress ) + { + ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper(); + pProgress->SetValue( pProgress->GetValue()+1 ); + } + + // get property set or multi property set and initialize helper + Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY ); + Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY ); + + // check for supported properties + if( !rPropSetHelper.checkedProperties() ) + rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() ); + +// if( xMultiPropSet.is() ) +// rPropSetHelper.getValues( xMultiPropSet ); +// else +// rPropSetHelper.getValues( xPropSet ); + + if( bExportParagraph ) + { + if( bAutoStyles ) + { + Add( XML_STYLE_FAMILY_TEXT_PARAGRAPH, rPropSetHelper, xPropSet ); + } + else + { + // xml:id for RDF metadata + GetExport().AddAttributeXmlId(rTextContent); + GetExport().AddAttributesRDFa(rTextContent); + + OUString sStyle; + if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) ) + { + if( xMultiPropSet.is() ) + rPropSetHelper.getValue( PARA_STYLE_NAME, + xMultiPropSet ) >>= sStyle; + else + rPropSetHelper.getValue( PARA_STYLE_NAME, + xPropSet ) >>= sStyle; + } + + Reference< XInterface > xRef( rTextContent, UNO_QUERY ); + if( xRef.is() ) + { + const OUString& rIdentifier = GetExport().getInterfaceToIdentifierMapper().getIdentifier( xRef ); + if( rIdentifier.getLength() ) + { + // FIXME: this is just temporary until EditEngine + // paragraphs implement XMetadatable. + // then that must be used and not the mapper, because + // when both can be used we get two xml:id! + uno::Reference<rdf::XMetadatable> const xMeta(xRef, + uno::UNO_QUERY); + OSL_ENSURE(!xMeta.is(), "paragraph that implements " + "XMetadatable used in interfaceToIdentifierMapper?"); + GetExport().AddAttributeIdLegacy(XML_NAMESPACE_TEXT, + rIdentifier); + } + } + + OUString sAutoStyle( sStyle ); + sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle ); + if( sAutoStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sAutoStyle ) ); + + if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) ) + { + OUString sCondStyle; + if( xMultiPropSet.is() ) + rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME, + xMultiPropSet ) >>= sCondStyle; + else + rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME, + xPropSet ) >>= sCondStyle; + if( sCondStyle != sStyle ) + { + sCondStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, + sCondStyle ); + if( sCondStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_COND_STYLE_NAME, + GetExport().EncodeStyleName( sCondStyle ) ); + } + } + + //if( rPropSetHelper.hasProperty( PARA_CHAPTER_NUMERBING_LEVEL ) ) //#outline level,zhaojianwei + if( rPropSetHelper.hasProperty( PARA_OUTLINE_LEVEL ) ) //<-end + { + if( xMultiPropSet.is() ) + //rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL, //#outline level,zhaojianwei + rPropSetHelper.getValue( PARA_OUTLINE_LEVEL, //<-end + xMultiPropSet ) >>= nOutlineLevel; + else + //rPropSetHelper.getValue( PARA_CHAPTER_NUMERBING_LEVEL, //#outline level,zhaojianwei + rPropSetHelper.getValue( PARA_OUTLINE_LEVEL, //<-end + xPropSet ) >>= nOutlineLevel; + + //if( -1 != nOutlineLevel ) //#outline level,zhaojianwei + if( 0 < nOutlineLevel ) //<-end,zhaojianwei + { + OUStringBuffer sTmp; + //sTmp.append( sal_Int32( nOutlineLevel + 1 ) ); //#outline level,zhaojianwei + sTmp.append( sal_Int32( nOutlineLevel) ); //<-end,zhaojianwei + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_OUTLINE_LEVEL, + sTmp.makeStringAndClear() ); + + if( rPropSetHelper.hasProperty( NUMBERING_IS_NUMBER ) ) + { + bool bIsNumber = false; + if( xMultiPropSet.is() ) + rPropSetHelper.getValue( + NUMBERING_IS_NUMBER, xMultiPropSet ) >>= bIsNumber; + else + rPropSetHelper.getValue( + NUMBERING_IS_NUMBER, xPropSet ) >>= bIsNumber; + + OUString sListStyleName; + if( xMultiPropSet.is() ) + rPropSetHelper.getValue( + PARA_NUMBERING_STYLENAME, xMultiPropSet ) >>= sListStyleName; + else + rPropSetHelper.getValue( + PARA_NUMBERING_STYLENAME, xPropSet ) >>= sListStyleName; + + + + bool bAssignedtoOutlineStyle = false;//#outline level,add by zhaojianwei + { + Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(), UNO_QUERY ); + + OUString sOutlineName; + if (xCNSupplier.is()) + { + Reference< XIndexReplace > xNumRule ( xCNSupplier->getChapterNumberingRules() ); + DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" ); + + if (xNumRule.is()) + { + Reference< XPropertySet > xNumRulePropSet( xNumRule, UNO_QUERY ); + xNumRulePropSet->getPropertyValue( + OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) ) >>= sOutlineName; + bAssignedtoOutlineStyle = ( sListStyleName == sOutlineName ); + } + } + + } //<end,zhaojianwei + + //if( ! bIsNumber ) //#outline level,removed by zhaojianwei + if( ! bIsNumber && bAssignedtoOutlineStyle ) //#outline level,add by zhaojianwei + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_IS_LIST_HEADER, + XML_TRUE ); + } + + { + String sParaIsNumberingRestart + (RTL_CONSTASCII_USTRINGPARAM + ("ParaIsNumberingRestart")); + bool bIsRestartNumbering = false; + + Reference< XPropertySetInfo > + xPropSetInfo(xMultiPropSet.is() ? + xMultiPropSet->getPropertySetInfo(): + xPropSet->getPropertySetInfo()); + + if (xPropSetInfo-> + hasPropertyByName(sParaIsNumberingRestart)) + { + xPropSet->getPropertyValue(sParaIsNumberingRestart) + >>= bIsRestartNumbering; + } + + if (bIsRestartNumbering) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_RESTART_NUMBERING, + XML_TRUE); + + String sNumberingStartValue + (RTL_CONSTASCII_USTRINGPARAM + ("NumberingStartValue")); + + + sal_Int32 nStartValue = 0; + + if (xPropSetInfo-> + hasPropertyByName(sNumberingStartValue)) + { + xPropSet->getPropertyValue(sNumberingStartValue) + >>= nStartValue; + + OUStringBuffer sTmpStartValue; + + sTmpStartValue.append(nStartValue); + + GetExport(). + AddAttribute(XML_NAMESPACE_TEXT, + XML_START_VALUE, + sTmpStartValue. + makeStringAndClear()); + } + } + } + } + } + } + } + + Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY ); + Reference < XEnumeration > xTextEnum; + xTextEnum = xEA->createEnumeration(); + const sal_Bool bHasPortions = xTextEnum.is(); + + Reference < XEnumeration> xContentEnum; + Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY ); + if( xCEA.is() ) + xContentEnum.set(xCEA->createContentEnumeration( sTextContentService )); + const sal_Bool bHasContentEnum = xContentEnum.is() && + xContentEnum->hasMoreElements(); + + Reference < XTextSection > xSection; + if( bHasContentEnum ) + { + // For the auto styles, the multi property set helper is only used + // if hard attributes are existing. Therfor, it seems to be a better + // strategy to have the TextSection property seperate, because otherwise + // we always retrieve the style names even if they are not required. + if( bAutoStyles ) + { + if( xPropSet->getPropertySetInfo()->hasPropertyByName( sTextSection ) ) + { + xSection.set(xPropSet->getPropertyValue( sTextSection ), uno::UNO_QUERY); + } + } + else + { + if( rPropSetHelper.hasProperty( TEXT_SECTION ) ) + { + xSection.set(rPropSetHelper.getValue( TEXT_SECTION ), uno::UNO_QUERY); + } + } + } + + if( bAutoStyles ) + { + sal_Bool bPrevCharIsSpace = sal_True; + if( bHasContentEnum ) + bPrevCharIsSpace = !exportTextContentEnumeration( + xContentEnum, bAutoStyles, xSection, + bIsProgress, sal_True, 0, sal_True ); + if ( bHasPortions ) + exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress ); + } + else + { + sal_Bool bPrevCharIsSpace = sal_True; + enum XMLTokenEnum eElem = + //-1 == nOutlineLevel ? XML_P : XML_H; //#outline level,zhaojianwei + 0 < nOutlineLevel ? XML_H : XML_P; //<-end,zhaojianwei + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem, + sal_True, sal_False ); + if( bHasContentEnum ) + bPrevCharIsSpace = !exportTextContentEnumeration( + xContentEnum, bAutoStyles, xSection, + bIsProgress ); + exportTextRangeEnumeration( xTextEnum, bAutoStyles, bIsProgress, + bPrevCharIsSpace ); + } +} + +void XMLTextParagraphExport::exportTextRangeEnumeration( + const Reference < XEnumeration > & rTextEnum, + sal_Bool bAutoStyles, sal_Bool bIsProgress, + sal_Bool bPrvChrIsSpc ) +{ + static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata")); + sal_Bool bPrevCharIsSpace = bPrvChrIsSpc; + + while( rTextEnum->hasMoreElements() ) + { + Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY); + Reference < XTextRange > xTxtRange(xPropSet, uno::UNO_QUERY); + Reference<XPropertySetInfo> xPropInfo(xPropSet->getPropertySetInfo()); + + if (xPropInfo->hasPropertyByName(sTextPortionType)) + { + rtl::OUString sType; + xPropSet->getPropertyValue(sTextPortionType) >>= sType; + + if( sType.equals(sText)) + { + exportTextRange( xTxtRange, bAutoStyles, + bPrevCharIsSpace ); + } + else if( sType.equals(sTextField)) + { + exportTextField( xTxtRange, bAutoStyles, bIsProgress ); + bPrevCharIsSpace = sal_False; + } + else if( sType.equals( sFrame ) ) + { + Reference < XEnumeration> xContentEnum; + Reference < XContentEnumerationAccess > xCEA( xTxtRange, + UNO_QUERY ); + if( xCEA.is() ) + xContentEnum.set(xCEA->createContentEnumeration( + sTextContentService )); + // frames are never in sections + Reference<XTextSection> xSection; + if( xContentEnum.is() ) + exportTextContentEnumeration( xContentEnum, + bAutoStyles, + xSection, bIsProgress, sal_True, + &xPropSet ); + + bPrevCharIsSpace = sal_False; + } + else if (sType.equals(sFootnote)) + { + exportTextFootnote(xPropSet, + xTxtRange->getString(), + bAutoStyles, bIsProgress ); + bPrevCharIsSpace = sal_False; + } + else if (sType.equals(sBookmark)) + { + exportTextMark(xPropSet, + sBookmark, + lcl_XmlBookmarkElements, + bAutoStyles); + } + else if (sType.equals(sReferenceMark)) + { + exportTextMark(xPropSet, + sReferenceMark, + lcl_XmlReferenceElements, + bAutoStyles); + } + else if (sType.equals(sDocumentIndexMark)) + { + pIndexMarkExport->ExportIndexMark(xPropSet, bAutoStyles); + } + else if (sType.equals(sRedline)) + { + if (NULL != pRedlineExport) + pRedlineExport->ExportChange(xPropSet, bAutoStyles); + } + else if (sType.equals(sRuby)) + { + exportRuby(xPropSet, bAutoStyles); + } + else if (sType.equals(sMeta)) + { + exportMeta(xPropSet, bAutoStyles, bIsProgress); + } + else if (sType.equals(sTextFieldStart)) + { + Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); + if (xBookmark.is()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); + } + Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); + if (xFormField.is()) + { + GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType()); + } + GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False); + if (xFormField.is()) + { + FieldParamExporter(&GetExport(), xFormField->getParameters()).Export(); + } + GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False); + } + else if (sType.equals(sTextFieldEnd)) + { + GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False); + GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_END, sal_False); + } + else if (sType.equals(sTextFieldStartEnd)) + { + Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); + if (xBookmark.is()) + { + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); + } + Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); + if (xFormField.is()) + { + GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType()); + } + GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False); + if (xFormField.is()) + { + FieldParamExporter(&GetExport(), xFormField->getParameters()).Export(); + } + GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False); + } + else if (sType.equals(sSoftPageBreak)) + { + exportSoftPageBreak(xPropSet, bAutoStyles); + } + else { + DBG_ERROR("unknown text portion type"); + } + } + else + { + Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY ); + if( xServiceInfo->supportsService( sTextFieldService ) ) + { + exportTextField( xTxtRange, bAutoStyles, bIsProgress ); + bPrevCharIsSpace = sal_False; + } + else + { + // no TextPortionType property -> non-Writer app -> text + exportTextRange( xTxtRange, bAutoStyles, bPrevCharIsSpace ); + } + } + } + +// now that there are nested enumerations for meta(-field), this may be valid! +// DBG_ASSERT( !bOpenRuby, "Red Alert: Ruby still open!" ); +} + +void XMLTextParagraphExport::exportTable( + const Reference < XTextContent > &, + sal_Bool /*bAutoStyles*/, sal_Bool /*bIsProgress*/ ) +{ +} + +void XMLTextParagraphExport::exportTextField( + const Reference < XTextRange > & rTextRange, + sal_Bool bAutoStyles, sal_Bool bIsProgress ) +{ + Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY ); + // non-Writer apps need not support Property TextField, so test first + if (xPropSet->getPropertySetInfo()->hasPropertyByName( sTextField )) + { + Reference < XTextField > xTxtFld(xPropSet->getPropertyValue( sTextField ), uno::UNO_QUERY); + DBG_ASSERT( xTxtFld.is(), "text field missing" ); + if( xTxtFld.is() ) + { + exportTextField(xTxtFld, bAutoStyles, bIsProgress, sal_True); + } + else + { + // write only characters + GetExport().Characters(rTextRange->getString()); + } + } +} + +void XMLTextParagraphExport::exportTextField( + const Reference < XTextField > & xTextField, + const sal_Bool bAutoStyles, const sal_Bool bIsProgress, + const sal_Bool bRecursive ) +{ + if ( bAutoStyles ) + { + pFieldExport->ExportFieldAutoStyle( xTextField, bIsProgress, + bRecursive ); + } + else + { + pFieldExport->ExportField( xTextField, bIsProgress ); + } +} + +void XMLTextParagraphExport::exportSoftPageBreak( + const Reference<XPropertySet> & , + sal_Bool ) +{ + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_SOFT_PAGE_BREAK, sal_False, + sal_False ); +} + +void XMLTextParagraphExport::exportTextMark( + const Reference<XPropertySet> & rPropSet, + const OUString sProperty, + const enum XMLTokenEnum pElements[], + sal_Bool bAutoStyles) +{ + // mib said: "Hau wech!" + // + // (Originally, I'd export a span element in case the (book|reference)mark + // was formatted. This actually makes a difference in case some pervert + // sets a point reference mark in the document and, say, formats it bold. + // This basically meaningless formatting will now been thrown away + // (aka cleaned up), since mib said: ... dvo + + if (!bAutoStyles) + { + // name element + Reference<XNamed> xName(rPropSet->getPropertyValue(sProperty), UNO_QUERY); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, + xName->getName()); + + // start, end, or point-reference? + sal_Int8 nElement; + if( *(sal_Bool *)rPropSet->getPropertyValue(sIsCollapsed).getValue() ) + { + nElement = 0; + } + else + { + nElement = *(sal_Bool *)rPropSet->getPropertyValue(sIsStart).getValue() ? 1 : 2; + } + + // bookmark, bookmark-start: xml:id and RDFa for RDF metadata + if( nElement < 2 ) { + GetExport().AddAttributeXmlId(xName); + const uno::Reference<text::XTextContent> xTextContent( + xName, uno::UNO_QUERY_THROW); + GetExport().AddAttributesRDFa(xTextContent); + } + + // export element + DBG_ASSERT(pElements != NULL, "illegal element array"); + DBG_ASSERT(nElement >= 0, "illegal element number"); + DBG_ASSERT(nElement <= 2, "illegal element number"); + SvXMLElementExport aElem(GetExport(), + XML_NAMESPACE_TEXT, pElements[nElement], + sal_False, sal_False); + } + // else: no styles. (see above) +} + +sal_Bool lcl_txtpara_isBoundAsChar( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertySetInfo > & rPropSetInfo ) +{ + sal_Bool bIsBoundAsChar = sal_False; + OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) ); + if( rPropSetInfo->hasPropertyByName( sAnchorType ) ) + { + TextContentAnchorType eAnchor; + rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor; + bIsBoundAsChar = TextContentAnchorType_AS_CHARACTER == eAnchor; + } + + return bIsBoundAsChar; +} + +sal_Int32 XMLTextParagraphExport::addTextFrameAttributes( + const Reference < XPropertySet >& rPropSet, + sal_Bool bShape, + OUString *pMinHeightValue ) +{ + sal_Int32 nShapeFeatures = SEF_DEFAULT; + + // draw:name (#97662#: not for shapes, since those names will be + // treated in the shape export) + if( !bShape ) + { + Reference < XNamed > xNamed( rPropSet, UNO_QUERY ); + if( xNamed.is() ) + { + OUString sName( xNamed->getName() ); + if( sName.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + xNamed->getName() ); + } + } + + OUStringBuffer sValue; + + // text:anchor-type + TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH; + rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor; + { + XMLAnchorTypePropHdl aAnchorTypeHdl; + OUString sTmp; + aAnchorTypeHdl.exportXML( sTmp, uno::makeAny(eAnchor), + GetExport().GetMM100UnitConverter() ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, sTmp ); + } + + // text:anchor-page-number + if( TextContentAnchorType_AT_PAGE == eAnchor ) + { + sal_Int16 nPage = 0; + rPropSet->getPropertyValue( sAnchorPageNo ) >>= nPage; + GetExport().GetMM100UnitConverter().convertNumber( sValue, + (sal_Int32)nPage ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER, + sValue.makeStringAndClear() ); + } + else + { + // #92210# + nShapeFeatures |= SEF_EXPORT_NO_WS; + } + + // OD 2004-06-01 #i27691# - correction: no export of svg:x, if object + // is anchored as-character. + if ( !bShape && + eAnchor != TextContentAnchorType_AS_CHARACTER ) + { + // svg:x + sal_Int16 nHoriOrient = HoriOrientation::NONE; + rPropSet->getPropertyValue( sHoriOrient ) >>= nHoriOrient; + if( HoriOrientation::NONE == nHoriOrient ) + { + sal_Int32 nPos = 0; + rPropSet->getPropertyValue( sHoriOrientPosition ) >>= nPos; + GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos ); + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_X, + sValue.makeStringAndClear() ); + } + } + else if( TextContentAnchorType_AS_CHARACTER == eAnchor ) + nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_X); + + if( !bShape || TextContentAnchorType_AS_CHARACTER == eAnchor ) + { + // svg:y + sal_Int16 nVertOrient = VertOrientation::NONE; + rPropSet->getPropertyValue( sVertOrient ) >>= nVertOrient; + if( VertOrientation::NONE == nVertOrient ) + { + sal_Int32 nPos = 0; + rPropSet->getPropertyValue( sVertOrientPosition ) >>= nPos; + GetExport().GetMM100UnitConverter().convertMeasure( sValue, nPos ); + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_Y, + sValue.makeStringAndClear() ); + } + if( bShape ) + nShapeFeatures = (nShapeFeatures & ~SEF_EXPORT_Y); + } + + + Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo()); + + // svg:width + sal_Int16 nWidthType = SizeType::FIX; + if( xPropSetInfo->hasPropertyByName( sWidthType ) ) + { + rPropSet->getPropertyValue( sWidthType ) >>= nWidthType; + } + if( xPropSetInfo->hasPropertyByName( sWidth ) ) + { + sal_Int32 nWidth = 0; + // VAR size will be written as zero min-size + if( SizeType::VARIABLE != nWidthType ) + { + rPropSet->getPropertyValue( sWidth ) >>= nWidth; + } + GetExport().GetMM100UnitConverter().convertMeasure( sValue, nWidth ); + if( SizeType::FIX != nWidthType ) + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_WIDTH, + sValue.makeStringAndClear() ); + else + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH, + sValue.makeStringAndClear() ); + } + sal_Bool bSyncWidth = sal_False; + if( xPropSetInfo->hasPropertyByName( sIsSyncWidthToHeight ) ) + { + bSyncWidth = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncWidthToHeight ).getValue(); + if( bSyncWidth ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH, + XML_SCALE ); + } + if( !bSyncWidth && xPropSetInfo->hasPropertyByName( sRelativeWidth ) ) + { + sal_Int16 nRelWidth = 0; + rPropSet->getPropertyValue( sRelativeWidth ) >>= nRelWidth; + DBG_ASSERT( nRelWidth >= 0 && nRelWidth <= 254, + "Got illegal relative width from API" ); + if( nRelWidth > 0 ) + { + GetExport().GetMM100UnitConverter().convertPercent( sValue, + nRelWidth ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH, + sValue.makeStringAndClear() ); + } + } + + // svg:height, fo:min-height or style:rel-height + sal_Int16 nSizeType = SizeType::FIX; + if( xPropSetInfo->hasPropertyByName( sSizeType ) ) + { + rPropSet->getPropertyValue( sSizeType ) >>= nSizeType; + } + sal_Bool bSyncHeight = sal_False; + if( xPropSetInfo->hasPropertyByName( sIsSyncHeightToWidth ) ) + { + bSyncHeight = *(sal_Bool *)rPropSet->getPropertyValue( sIsSyncHeightToWidth ).getValue(); + } + sal_Int16 nRelHeight = 0; + if( !bSyncHeight && xPropSetInfo->hasPropertyByName( sRelativeHeight ) ) + { + rPropSet->getPropertyValue( sRelativeHeight ) >>= nRelHeight; + } + if( xPropSetInfo->hasPropertyByName( sHeight ) ) + { + sal_Int32 nHeight = 0; + if( SizeType::VARIABLE != nSizeType ) + { + rPropSet->getPropertyValue( sHeight ) >>= nHeight; + } + GetExport().GetMM100UnitConverter().convertMeasure( sValue, + nHeight ); + if( SizeType::FIX != nSizeType && 0==nRelHeight && !bSyncHeight && + pMinHeightValue ) + *pMinHeightValue = sValue.makeStringAndClear(); + else + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT, + sValue.makeStringAndClear() ); + } + if( bSyncHeight ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT, + SizeType::MIN == nSizeType ? XML_SCALE_MIN : XML_SCALE ); + + } + else if( nRelHeight > 0 ) + { + GetExport().GetMM100UnitConverter().convertPercent( sValue, + nRelHeight ); + if( SizeType::MIN == nSizeType ) + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT, + sValue.makeStringAndClear() ); + else + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT, + sValue.makeStringAndClear() ); + } + + OUString sZOrder( RTL_CONSTASCII_USTRINGPARAM( "ZOrder" ) ); + if( xPropSetInfo->hasPropertyByName( sZOrder ) ) + { + sal_Int32 nZIndex = 0; + rPropSet->getPropertyValue( sZOrder ) >>= nZIndex; + if( -1 != nZIndex ) + { + GetExport().GetMM100UnitConverter().convertNumber( sValue, + nZIndex ); + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX, + sValue.makeStringAndClear() ); + } + } + + return nShapeFeatures; +} + +void XMLTextParagraphExport::exportAnyTextFrame( + const Reference < XTextContent > & rTxtCntnt, + FrameType eType, + sal_Bool bAutoStyles, + sal_Bool bIsProgress, + sal_Bool bExportContent, + const Reference < XPropertySet > *pRangePropSet) +{ + Reference < XPropertySet > xPropSet( rTxtCntnt, UNO_QUERY ); + + if( bAutoStyles ) + { + if( FT_EMBEDDED == eType ) + _collectTextEmbeddedAutoStyles( xPropSet ); + // --> OD 2004-08-09 #i28745# - no text frame style for shapes + else if ( FT_SHAPE != eType ) + Add( XML_STYLE_FAMILY_TEXT_FRAME, xPropSet ); + // <-- + + if( pRangePropSet && lcl_txtpara_isBoundAsChar( xPropSet, + xPropSet->getPropertySetInfo() ) ) + Add( XML_STYLE_FAMILY_TEXT_TEXT, *pRangePropSet ); + + switch( eType ) + { + case FT_TEXT: + { + // frame bound frames + if ( bExportContent ) + { + Reference < XTextFrame > xTxtFrame( rTxtCntnt, UNO_QUERY ); + Reference < XText > xTxt(xTxtFrame->getText()); + exportFrameFrames( sal_True, bIsProgress, &xTxtFrame ); + exportText( xTxt, bAutoStyles, bIsProgress, sal_True ); + } + } + break; + case FT_SHAPE: + { + Reference < XShape > xShape( rTxtCntnt, UNO_QUERY ); + GetExport().GetShapeExport()->collectShapeAutoStyles( xShape ); + } + break; + default: + break; + } + } + else + { + Reference< XPropertySetInfo > xPropSetInfo(xPropSet->getPropertySetInfo()); + Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY ); + { + sal_Bool bAddCharStyles = pRangePropSet && + lcl_txtpara_isBoundAsChar( xPropSet, xPropSetInfo ); + + sal_Bool bIsUICharStyle; + sal_Bool bHasAutoStyle = sal_False; + sal_Bool bDummy; + + OUString sStyle; + + if( bAddCharStyles ) + sStyle = FindTextStyleAndHyperlink( *pRangePropSet, bDummy, bIsUICharStyle, bHasAutoStyle ); + else + bIsUICharStyle = sal_False; + + XMLTextCharStyleNamesElementExport aCharStylesExport( + GetExport(), bIsUICharStyle && + aCharStyleNamesPropInfoCache.hasProperty( + *pRangePropSet ), bHasAutoStyle, + *pRangePropSet, sCharStyleNames ); + + if( sStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyle ) ); + { + SvXMLElementExport aElem( GetExport(), sStyle.getLength() > 0, + XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False ); + { + SvXMLElementExport aElement( GetExport(), + FT_SHAPE != eType && + addHyperlinkAttributes( xPropSet, + xPropState,xPropSetInfo ), + XML_NAMESPACE_DRAW, XML_A, sal_False, sal_False ); + switch( eType ) + { + case FT_TEXT: + _exportTextFrame( xPropSet, xPropSetInfo, bIsProgress ); + break; + case FT_GRAPHIC: + _exportTextGraphic( xPropSet, xPropSetInfo ); + break; + case FT_EMBEDDED: + _exportTextEmbedded( xPropSet, xPropSetInfo ); + break; + case FT_SHAPE: + { + Reference < XShape > xShape( rTxtCntnt, UNO_QUERY ); + sal_Int32 nFeatures = + addTextFrameAttributes( xPropSet, sal_True ); + GetExport().GetShapeExport() + ->exportShape( xShape, nFeatures ); + } + break; + } + } + } + } + } +} + +void XMLTextParagraphExport::_exportTextFrame( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertySetInfo > & rPropSetInfo, + sal_Bool bIsProgress ) +{ + Reference < XTextFrame > xTxtFrame( rPropSet, UNO_QUERY ); + Reference < XText > xTxt(xTxtFrame->getText()); + + OUString sStyle; + if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) ) + { + rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle; + } + + OUString sAutoStyle( sStyle ); + OUString aMinHeightValue; + sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle ); + if( sAutoStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME, + GetExport().EncodeStyleName( sAutoStyle ) ); + addTextFrameAttributes( rPropSet, sal_False, &aMinHeightValue ); + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, + XML_FRAME, sal_False, sal_True ); + + if( aMinHeightValue.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT, + aMinHeightValue ); + + // draw:chain-next-name + if( rPropSetInfo->hasPropertyByName( sChainNextName ) ) + { + OUString sNext; + if( (rPropSet->getPropertyValue( sChainNextName ) >>= sNext) && sNext.getLength() > 0 ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, + XML_CHAIN_NEXT_NAME, + sNext ); + } + + { + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW, + XML_TEXT_BOX, sal_True, sal_True ); + + // frame bound frames + exportFramesBoundToFrame( xTxtFrame, bIsProgress ); + + exportText( xTxt, sal_False, bIsProgress, sal_True ); + } + + // script:events + Reference<XEventsSupplier> xEventsSupp( xTxtFrame, UNO_QUERY ); + GetExport().GetEventExport().Export(xEventsSupp); + + // image map + GetExport().GetImageMapExport().Export( rPropSet ); + + // --> OD 2009-07-22 #i73249# + // svg:title and svg:desc + exportTitleAndDescription( rPropSet, rPropSetInfo ); + // <-- +} + +void XMLTextParagraphExport::exportContour( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertySetInfo > & rPropSetInfo ) +{ + if( !rPropSetInfo->hasPropertyByName( sContourPolyPolygon ) ) + return; + + PointSequenceSequence aSourcePolyPolygon; + rPropSet->getPropertyValue( sContourPolyPolygon ) >>= aSourcePolyPolygon; + + if( !aSourcePolyPolygon.getLength() ) + return; + + awt::Point aPoint( 0, 0 ); + awt::Size aSize( 0, 0 ); + sal_Int32 nPolygons = aSourcePolyPolygon.getLength(); + const PointSequence *pPolygons = aSourcePolyPolygon.getConstArray(); + while( nPolygons-- ) + { + sal_Int32 nPoints = pPolygons->getLength(); + const awt::Point *pPoints = pPolygons->getConstArray(); + while( nPoints-- ) + { + if( aSize.Width < pPoints->X ) + aSize.Width = pPoints->X; + if( aSize.Height < pPoints->Y ) + aSize.Height = pPoints->Y; + pPoints++; + } + pPolygons++; + } + + sal_Bool bPixel = sal_False; + if( rPropSetInfo->hasPropertyByName( sIsPixelContour ) ) + { + bPixel = *(sal_Bool *)rPropSet->getPropertyValue( sIsPixelContour ).getValue(); + } + + // svg: width + OUStringBuffer aStringBuffer( 10 ); + if( bPixel ) + GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Width); + else + GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Width); + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH, + aStringBuffer.makeStringAndClear() ); + + // svg: height + if( bPixel ) + GetExport().GetMM100UnitConverter().convertMeasurePx(aStringBuffer, aSize.Height); + else + GetExport().GetMM100UnitConverter().convertMeasure(aStringBuffer, aSize.Height); + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT, + aStringBuffer.makeStringAndClear() ); + + // svg:viewbox + SdXMLImExViewBox aViewBox(0, 0, aSize.Width, aSize.Height); + GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX, + aViewBox.GetExportString()); + + sal_Int32 nOuterCnt( aSourcePolyPolygon.getLength() ); + + enum XMLTokenEnum eElem = XML_TOKEN_INVALID; + if( 1L == nOuterCnt ) + { + // simple polygon shape, can be written as svg:points sequence + /*const*/ PointSequence* pSequence = + (PointSequence*)aSourcePolyPolygon.getConstArray(); + + SdXMLImExPointsElement aPoints( pSequence, aViewBox, aPoint, aSize ); + + // write point array + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_POINTS, + aPoints.GetExportString()); + eElem = XML_CONTOUR_POLYGON; + } + else + { + // polypolygon, needs to be written as a svg:path sequence + /*const*/ PointSequence* pOuterSequence = + (PointSequence*)aSourcePolyPolygon.getConstArray(); + if(pOuterSequence) + { + // prepare svx:d element export + SdXMLImExSvgDElement aSvgDElement( aViewBox ); + + for(sal_Int32 a(0L); a < nOuterCnt; a++) + { + /*const*/ PointSequence* pSequence = pOuterSequence++; + if(pSequence) + { + aSvgDElement.AddPolygon(pSequence, 0L, aPoint, + aSize, sal_True ); + } + } + + // write point array + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_D, + aSvgDElement.GetExportString()); + eElem = XML_CONTOUR_PATH; + } + } + + if( rPropSetInfo->hasPropertyByName( sIsAutomaticContour ) ) + { + sal_Bool bTmp = *(sal_Bool *)rPropSet->getPropertyValue( + sIsAutomaticContour ).getValue(); + GetExport().AddAttribute( XML_NAMESPACE_DRAW, + XML_RECREATE_ON_EDIT, bTmp ? XML_TRUE : XML_FALSE ); + } + + // write object now + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, eElem, + sal_True, sal_True ); +} + +void XMLTextParagraphExport::_exportTextGraphic( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertySetInfo > & rPropSetInfo ) +{ + OUString sStyle; + if( rPropSetInfo->hasPropertyByName( sFrameStyleName ) ) + { + rPropSet->getPropertyValue( sFrameStyleName ) >>= sStyle; + } + + OUString sAutoStyle( sStyle ); + sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_FRAME, rPropSet, sStyle ); + if( sAutoStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME, + GetExport().EncodeStyleName( sAutoStyle ) ); + addTextFrameAttributes( rPropSet, sal_False ); + + // svg:transform + sal_Int16 nVal = 0; + rPropSet->getPropertyValue( sGraphicRotation ) >>= nVal; + if( nVal != 0 ) + { + OUStringBuffer sRet( GetXMLToken(XML_ROTATE).getLength()+4 ); + sRet.append( GetXMLToken(XML_ROTATE)); + sRet.append( (sal_Unicode)'(' ); + GetExport().GetMM100UnitConverter().convertNumber( sRet, (sal_Int32)nVal ); + sRet.append( (sal_Unicode)')' ); + GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_TRANSFORM, + sRet.makeStringAndClear() ); + } + + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, + XML_FRAME, sal_False, sal_True ); + + // xlink:href + OUString sOrigURL; + rPropSet->getPropertyValue( sGraphicURL ) >>= sOrigURL; + OUString sURL(GetExport().AddEmbeddedGraphicObject( sOrigURL )); + setTextEmbeddedGraphicURL( rPropSet, sURL ); + + // If there still is no url, then then graphic is empty + if( sURL.getLength() ) + { + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sURL ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, + XML_ONLOAD ); + } + + // draw:filter-name + OUString sGrfFilter; + rPropSet->getPropertyValue( sGraphicFilter ) >>= sGrfFilter; + if( sGrfFilter.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME, + sGrfFilter ); + + { + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW, + XML_IMAGE, sal_False, sal_True ); + + // optional office:binary-data + GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL ); + } + + // script:events + Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY ); + GetExport().GetEventExport().Export(xEventsSupp); + + // image map + GetExport().GetImageMapExport().Export( rPropSet ); + + // --> OD 2009-07-22 #i73249# + // svg:title and svg:desc + exportTitleAndDescription( rPropSet, rPropSetInfo ); + // <-- + + // draw:contour + exportContour( rPropSet, rPropSetInfo ); +} + +void XMLTextParagraphExport::_collectTextEmbeddedAutoStyles(const Reference < XPropertySet > & ) +{ + DBG_ASSERT( !this, "no API implementation avialable" ); +} + +void XMLTextParagraphExport::_exportTextEmbedded( + const Reference < XPropertySet > &, + const Reference < XPropertySetInfo > & ) +{ + DBG_ASSERT( !this, "no API implementation avialable" ); +} + +void XMLTextParagraphExport::exportEvents( const Reference < XPropertySet > & rPropSet ) +{ + // script:events + Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY ); + GetExport().GetEventExport().Export(xEventsSupp); + + // image map + OUString sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")); + if (rPropSet->getPropertySetInfo()->hasPropertyByName(sImageMap)) + GetExport().GetImageMapExport().Export( rPropSet ); +} + +// --> OD 2009-07-22 #i73249# +void XMLTextParagraphExport::exportTitleAndDescription( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertySetInfo > & rPropSetInfo ) +{ + // svg:title + if( rPropSetInfo->hasPropertyByName( sTitle ) ) + { + OUString sObjTitle; + rPropSet->getPropertyValue( sTitle ) >>= sObjTitle; + if( sObjTitle.getLength() ) + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG, + XML_TITLE, sal_True, sal_False ); + GetExport().Characters( sObjTitle ); + } + } + + // svg:description + if( rPropSetInfo->hasPropertyByName( sDescription ) ) + { + OUString sObjDesc; + rPropSet->getPropertyValue( sDescription ) >>= sObjDesc; + if( sObjDesc.getLength() ) + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG, + XML_DESC, sal_True, sal_False ); + GetExport().Characters( sObjDesc ); + } + } +} +// <-- + +void XMLTextParagraphExport::setTextEmbeddedGraphicURL( + const Reference < XPropertySet >&, + OUString& /*rStreamName*/ ) const +{ +} + +sal_Bool XMLTextParagraphExport::addHyperlinkAttributes( + const Reference < XPropertySet > & rPropSet, + const Reference < XPropertyState > & rPropState, + const Reference < XPropertySetInfo > & rPropSetInfo ) +{ + sal_Bool bExport = sal_False; + OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName; + sal_Bool bServerMap = sal_False; + +/* bool bHyperLinkURL = false; + bool bHyperLinkName = false; + bool bHyperLinkTarget = false; + bool bServer = false; + bool bUnvisitedCharStyleName = false; + bool bVisitedCharStyleName = false; + + const Reference< XMultiPropertySet > xMultiPropertySet( rPropSet, UNO_QUERY ); + if ( xMultiPropertySet.is() ) + { + sal_uInt32 nCount = 0; + Sequence< OUString > aPropertyNames( 6 ); + OUString* pArray = aPropertyNames.getArray(); + + if ( rPropSetInfo->hasPropertyByName( sServerMap ) ) + { + bServer = true; + pArray[ nCount++ ] = sServerMap; + } + if ( rPropSetInfo->hasPropertyByName( sHyperLinkName ) ) + { + bHyperLinkName = true; + pArray[ nCount++ ] = sHyperLinkName; + } + if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) ) + { + bHyperLinkTarget = true; + pArray[ nCount++ ] = sHyperLinkTarget; + } + if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) ) + { + bHyperLinkURL = true; + pArray[ nCount++ ] = sHyperLinkURL; + } + if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) ) + { + bUnvisitedCharStyleName = true; + pArray[ nCount++ ] = sUnvisitedCharStyleName; + } + if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) ) + { + bVisitedCharStyleName = true; + pArray[ nCount++ ] = sVisitedCharStyleName; + } + + aPropertyNames.realloc( nCount ); + + if ( nCount ) + { + Sequence< PropertyState > aPropertyStates( nCount ); + PropertyState* pStateArray = aPropertyStates.getArray(); + + if ( rPropState.is() ) + aPropertyStates = rPropState->getPropertyStates( aPropertyNames ); + + Sequence< Any > aPropertyValues ( xMultiPropertySet->getPropertyValues( aPropertyNames ) ); + Any* pValueArray = aPropertyValues.getArray(); + + sal_uInt32 nIdx = 0; + + if ( bServer ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + bServerMap = *(sal_Bool *)pValueArray[ nIdx ].getValue(); + if( bServerMap ) + bExport = sal_True; + } + ++nIdx; + } + if ( bHyperLinkName ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + pValueArray[ nIdx ] >>= sName; + if( sName.getLength() > 0 ) + bExport = sal_True; + } + ++nIdx; + } + if ( bHyperLinkTarget ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + pValueArray[ nIdx ] >>= sTargetFrame; + if( sTargetFrame.getLength() ) + bExport = sal_True; + } + ++nIdx; + } + if ( bHyperLinkURL ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + pValueArray[ nIdx ] >>= sHRef; + if( sHRef.getLength() > 0 ) + bExport = sal_True; + } + ++nIdx; + } + if ( bUnvisitedCharStyleName ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + pValueArray[ nIdx ] >>= sUStyleName; + if( sUStyleName.getLength() ) + bExport = sal_True; + } + ++nIdx; + } + if ( bVisitedCharStyleName ) + { + if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] ) + { + pValueArray[ nIdx ] >>= sVStyleName; + if( sVStyleName.getLength() ) + bExport = sal_True; + } + ++nIdx; + } + } + } + else + {*/ + if( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sHyperLinkURL ) ) ) + { + rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef; + + if( sHRef.getLength() > 0 ) + bExport = sal_True; + } + + if( rPropSetInfo->hasPropertyByName( sHyperLinkName ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sHyperLinkName ) ) ) + { + rPropSet->getPropertyValue( sHyperLinkName ) >>= sName; + if( sName.getLength() > 0 ) + bExport = sal_True; + } + + if( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sHyperLinkTarget ) ) ) + { + rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame; + if( sTargetFrame.getLength() ) + bExport = sal_True; + } + + if( rPropSetInfo->hasPropertyByName( sServerMap ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sServerMap ) ) ) + { + bServerMap = *(sal_Bool *)rPropSet->getPropertyValue( sServerMap ).getValue(); + if( bServerMap ) + bExport = sal_True; + } + + if( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sUnvisitedCharStyleName ) ) ) + { + rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName; + if( sUStyleName.getLength() ) + bExport = sal_True; + } + + if( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) && + ( !rPropState.is() || PropertyState_DIRECT_VALUE == + rPropState->getPropertyState( sVisitedCharStyleName ) ) ) + { + rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName; + if( sVStyleName.getLength() ) + bExport = sal_True; + } + + if( bExport ) + { + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) ); + + if( sName.getLength() > 0 ) + GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName ); + + if( sTargetFrame.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_OFFICE, + XML_TARGET_FRAME_NAME, sTargetFrame ); + enum XMLTokenEnum eTok = + sTargetFrame.equalsAsciiL( "_blank", sizeof("_blank")-1 ) + ? XML_NEW : XML_REPLACE; + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, eTok ); + } + + if( bServerMap ) + GetExport().AddAttribute( XML_NAMESPACE_OFFICE, + XML_SERVER_MAP, XML_TRUE ); + + if( sUStyleName.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) ); + + if( sVStyleName.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) ); + } + + return bExport; +} + +void XMLTextParagraphExport::exportTextRange( + const Reference < XTextRange > & rTextRange, + sal_Bool bAutoStyles, + sal_Bool& rPrevCharIsSpace ) +{ + Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY ); + if( bAutoStyles ) + { + Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet ); + } + else + { + sal_Bool bHyperlink = sal_False; + sal_Bool bIsUICharStyle = sal_False; + sal_Bool bHasAutoStyle = sal_False; + + OUString sStyle(FindTextStyleAndHyperlink( xPropSet, bHyperlink, + bIsUICharStyle, bHasAutoStyle )); + + Reference < XPropertySetInfo > xPropSetInfo; + if( bHyperlink ) + { + Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY ); + xPropSetInfo.set(xPropSet->getPropertySetInfo()); + bHyperlink = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo ); + } + SvXMLElementExport aElem( GetExport(), bHyperlink, XML_NAMESPACE_TEXT, + XML_A, sal_False, sal_False ); + if( bHyperlink ) + { + // export events (if supported) + OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM( + "HyperLinkEvents")); + if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents)) + { + Reference<XNameReplace> xName(xPropSet->getPropertyValue(sHyperLinkEvents), uno::UNO_QUERY); + GetExport().GetEventExport().Export(xName, sal_False); + } + } + + { + XMLTextCharStyleNamesElementExport aCharStylesExport( + GetExport(), bIsUICharStyle && + aCharStyleNamesPropInfoCache.hasProperty( + xPropSet, xPropSetInfo ), bHasAutoStyle, + xPropSet, sCharStyleNames ); + + OUString aText(rTextRange->getString()); + if( sStyle.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sStyle ) ); + { + // in a block to make sure it is destroyed before the text:a element + SvXMLElementExport aElement( GetExport(), sStyle.getLength() > 0, + XML_NAMESPACE_TEXT, XML_SPAN, sal_False, + sal_False ); + exportText( aText, rPrevCharIsSpace ); + } + } + } +} + +void XMLTextParagraphExport::exportText( const OUString& rText, + sal_Bool& rPrevCharIsSpace ) +{ + sal_Int32 nExpStartPos = 0; + sal_Int32 nEndPos = rText.getLength(); + sal_Int32 nSpaceChars = 0; + for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ ) + { + sal_Unicode cChar = rText[nPos]; + sal_Bool bExpCharAsText = sal_True; + sal_Bool bExpCharAsElement = sal_False; + sal_Bool bCurrCharIsSpace = sal_False; + switch( cChar ) + { + case 0x0009: // Tab + case 0x000A: // LF + // These characters are exported as text. + bExpCharAsElement = sal_True; + bExpCharAsText = sal_False; + break; + case 0x000D: + break; // legal character + case 0x0020: // Blank + if( rPrevCharIsSpace ) + { + // If the previous character is a space character, + // too, export a special space element. + bExpCharAsText = sal_False; + } + bCurrCharIsSpace = sal_True; + break; + default: + if( cChar < 0x0020 ) + { +#ifdef DBG_UTIL + OSL_ENSURE( txtparae_bContainsIllegalCharacters || + cChar >= 0x0020, + "illegal character in text content" ); + txtparae_bContainsIllegalCharacters = sal_True; +#endif + bExpCharAsText = sal_False; + } + break; + } + + // If the current character is not exported as text + // the text that has not been exported by now has to be exported now. + if( nPos > nExpStartPos && !bExpCharAsText ) + { + DBG_ASSERT( 0==nSpaceChars, "pending spaces" ); + OUString sExp( rText.copy( nExpStartPos, nPos - nExpStartPos ) ); + GetExport().Characters( sExp ); + nExpStartPos = nPos; + } + + // If there are spaces left that have not been exported and the + // current chracter is not a space , the pending spaces have to be + // exported now. + if( nSpaceChars > 0 && !bCurrCharIsSpace ) + { + DBG_ASSERT( nExpStartPos == nPos, " pending characters" ); + + if( nSpaceChars > 1 ) + { + OUStringBuffer sTmp; + sTmp.append( (sal_Int32)nSpaceChars ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C, + sTmp.makeStringAndClear() ); + } + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_S, sal_False, sal_False ); + + nSpaceChars = 0; + } + + // If the current character has to be exported as a special + // element, the elemnt will be exported now. + if( bExpCharAsElement ) + { + switch( cChar ) + { + case 0x0009: // Tab + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_TAB, sal_False, + sal_False ); + } + break; + case 0x000A: // LF + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_LINE_BREAK, sal_False, + sal_False ); + } + break; + } + } + + // If the current character is a space, and the previous one + // is a space, too, the number of pending spaces is incremented + // only. + if( bCurrCharIsSpace && rPrevCharIsSpace ) + nSpaceChars++; + rPrevCharIsSpace = bCurrCharIsSpace; + + // If the currect character is not exported as text, the start + // position for text is the position behind the current position. + if( !bExpCharAsText ) + { + DBG_ASSERT( nExpStartPos == nPos, "wrong export start pos" ); + nExpStartPos = nPos+1; + } + } + + if( nExpStartPos < nEndPos ) + { + DBG_ASSERT( 0==nSpaceChars, " pending spaces " ); + OUString sExp( rText.copy( nExpStartPos, nEndPos - nExpStartPos ) ); + GetExport().Characters( sExp ); + } + + // If there are some spaces left, they have to be exported now. + if( nSpaceChars > 0 ) + { + if( nSpaceChars > 1 ) + { + OUStringBuffer sTmp; + sTmp.append( (sal_Int32)nSpaceChars ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C, + sTmp.makeStringAndClear() ); + } + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_S, + sal_False, sal_False ); + } +} + +void XMLTextParagraphExport::exportTextDeclarations() +{ + pFieldExport->ExportFieldDeclarations(); + + // get XPropertySet from the document and ask for AutoMarkFileURL. + // If it exists, export the auto-mark-file element. + Reference<XPropertySet> xPropertySet( GetExport().GetModel(), UNO_QUERY ); + if (xPropertySet.is()) + { + OUString sUrl; + OUString sIndexAutoMarkFileURL( + RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL")); + if (xPropertySet->getPropertySetInfo()->hasPropertyByName( + sIndexAutoMarkFileURL)) + { + xPropertySet->getPropertyValue(sIndexAutoMarkFileURL) >>= sUrl; + if (sUrl.getLength() > 0) + { + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, + GetExport().GetRelativeReference(sUrl) ); + SvXMLElementExport aAutoMarkElement( + GetExport(), XML_NAMESPACE_TEXT, + XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE, + sal_True, sal_True ); + } + } + } +} + +void XMLTextParagraphExport::exportTextDeclarations( + const Reference<XText> & rText ) +{ + pFieldExport->ExportFieldDeclarations(rText); +} + +void XMLTextParagraphExport::exportUsedDeclarations( sal_Bool bOnlyUsed ) +{ + pFieldExport->SetExportOnlyUsedFieldDeclarations( bOnlyUsed ); +} + + +void XMLTextParagraphExport::exportTrackedChanges(sal_Bool bAutoStyles) +{ + if (NULL != pRedlineExport) + pRedlineExport->ExportChangesList( bAutoStyles ); +} + +void XMLTextParagraphExport::exportTrackedChanges( + const Reference<XText> & rText, + sal_Bool bAutoStyle) +{ + if (NULL != pRedlineExport) + pRedlineExport->ExportChangesList(rText, bAutoStyle); +} + +void XMLTextParagraphExport::recordTrackedChangesForXText( + const Reference<XText> & rText ) +{ + if (NULL != pRedlineExport) + pRedlineExport->SetCurrentXText(rText); +} + +void XMLTextParagraphExport::recordTrackedChangesNoXText() +{ + if (NULL != pRedlineExport) + pRedlineExport->SetCurrentXText(); +} + + +void XMLTextParagraphExport::exportTextAutoStyles() +{ + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_PARAGRAPH, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() ); + + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_TEXT, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() ); + + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_FRAME, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() ); + + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_SECTION, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() ); + + GetAutoStylePool().exportXML( XML_STYLE_FAMILY_TEXT_RUBY, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() ); + + pListAutoPool->exportXML(); +} + +void XMLTextParagraphExport::exportRuby( + const Reference<XPropertySet> & rPropSet, + sal_Bool bAutoStyles ) +{ + // early out: a collapsed ruby makes no sense + if (*(sal_Bool*)rPropSet->getPropertyValue(sIsCollapsed).getValue()) + return; + + // start value ? + sal_Bool bStart = (*(sal_Bool*)rPropSet->getPropertyValue(sIsStart).getValue()); + + if (bAutoStyles) + { + // ruby auto styles + if (bStart) + Add( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet ); + } + else + { + // prepare element names + OUString aRuby(GetXMLToken(XML_RUBY)); + OUString sTextRuby(GetExport().GetNamespaceMap(). + GetQNameByKey(XML_NAMESPACE_TEXT, aRuby)); + OUString sRubyBase(GetXMLToken(XML_RUBY_BASE)); + OUString sTextRubyBase(GetExport().GetNamespaceMap(). + GetQNameByKey(XML_NAMESPACE_TEXT, sRubyBase)); + + if (bStart) + { + // ruby start + + // we can only start a ruby if none is open + DBG_ASSERT(! bOpenRuby, "Can't open a ruby inside of ruby!"); + if( bOpenRuby ) + return; + + // save ruby text + ruby char style + rPropSet->getPropertyValue(sRubyText) >>= sOpenRubyText; + rPropSet->getPropertyValue(sRubyCharStyleName) >>= sOpenRubyCharStyle; + + // ruby style + GetExport().CheckAttrList(); + OUString sEmpty; + OUString sStyleName(Find( XML_STYLE_FAMILY_TEXT_RUBY, rPropSet, + sEmpty )); + DBG_ASSERT(sStyleName.getLength() > 0, "I can't find the style!"); + GetExport().AddAttribute(XML_NAMESPACE_TEXT, + XML_STYLE_NAME, sStyleName); + + // export <text:ruby> and <text:ruby-base> start elements + GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY, sal_False); + GetExport().ClearAttrList(); + GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY_BASE, + sal_False ); + bOpenRuby = sal_True; + } + else + { + // ruby end + + // check for an open ruby + DBG_ASSERT(bOpenRuby, "Can't close a ruby if none is open!"); + if( !bOpenRuby ) + return; + + // close <text:ruby-base> + GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY_BASE, + sal_False); + + // write the ruby text (with char style) + { + if (sOpenRubyCharStyle.getLength() > 0) + GetExport().AddAttribute( + XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sOpenRubyCharStyle) ); + + SvXMLElementExport aRubyElement( + GetExport(), XML_NAMESPACE_TEXT, XML_RUBY_TEXT, + sal_False, sal_False); + + GetExport().Characters(sOpenRubyText); + } + + // and finally, close the ruby + GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY, sal_False); + bOpenRuby = sal_False; + } + } +} + +void XMLTextParagraphExport::exportMeta( + const Reference<XPropertySet> & i_xPortion, + sal_Bool i_bAutoStyles, sal_Bool i_isProgress) +{ + static OUString sMeta(RTL_CONSTASCII_USTRINGPARAM("InContentMetadata")); + + bool doExport(!i_bAutoStyles); // do not export element if autostyles + // check version >= 1.2 + switch (GetExport().getDefaultVersion()) { + case SvtSaveOptions::ODFVER_011: // fall thru + case SvtSaveOptions::ODFVER_010: doExport = false; break; + default: break; + } + + const Reference< XTextContent > xTextContent( + i_xPortion->getPropertyValue(sMeta), UNO_QUERY_THROW); + const Reference< XEnumerationAccess > xEA( xTextContent, UNO_QUERY_THROW ); + const Reference< XEnumeration > xTextEnum( xEA->createEnumeration() ); + + if (doExport) + { + const Reference<rdf::XMetadatable> xMeta(xTextContent, UNO_QUERY_THROW); + + // text:meta with neither xml:id nor RDFa is invalid + xMeta->ensureMetadataReference(); + + // xml:id and RDFa for RDF metadata + GetExport().AddAttributeXmlId(xMeta); + GetExport().AddAttributesRDFa(xTextContent); + } + + SvXMLElementExport aElem( GetExport(), doExport, + XML_NAMESPACE_TEXT, XML_META, sal_False, sal_False ); + + // recurse to export content + exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_isProgress ); +} + + +void XMLTextParagraphExport::PreventExportOfControlsInMuteSections( + const Reference<XIndexAccess> & rShapes, + UniReference<xmloff::OFormLayerXMLExport> xFormExport ) +{ + // check parameters ad pre-conditions + if( ( ! rShapes.is() ) || ( ! xFormExport.is() ) ) + { + // if we don't have shapes or a form export, there's nothing to do + return; + } + DBG_ASSERT( pSectionExport != NULL, "We need the section export." ); + + Reference<XEnumeration> xShapesEnum = pBoundFrameSets->GetShapes()->createEnumeration(); + if(!xShapesEnum.is()) + return; + while( xShapesEnum->hasMoreElements() ) + { + // now we need to check + // 1) if this is a control shape, and + // 2) if it's in a mute section + // if both answers are 'yes', notify the form layer export + + // we join accessing the shape and testing for control + Reference<XControlShape> xControlShape(xShapesEnum->nextElement(), UNO_QUERY); + if( xControlShape.is() ) + { + // Reference<XPropertySet> xPropSet( xControlShape, UNO_QUERY ); + // Reference<XTextContent> xTextContent; + // xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ) ) >>= xTextContent; + + Reference<XTextContent> xTextContent( xControlShape, UNO_QUERY ); + if( xTextContent.is() ) + { + if( pSectionExport->IsMuteSection( xTextContent, sal_False ) ) + { + // Ah, we've found a shape that + // 1) is a control shape + // 2) is anchored in a mute section + // so: don't export it! + xFormExport->excludeFromExport( + xControlShape->getControl() ); + } + // else: not in mute section -> should be exported -> nothing + // to do + } + // else: no anchor -> ignore + } + // else: no control shape -> nothing to do + } +} +sal_Int32 XMLTextParagraphExport::GetHeadingLevel( const OUString& rStyleName ) +{ + if( !pHeadingStyles ) + { + pHeadingStyles = new XMLStringVector; + SvxXMLNumRuleExport::GetOutlineStyles( *pHeadingStyles, + GetExport().GetModel() ); + } + for( XMLStringVector::size_type i=0; i < pHeadingStyles->size(); ++i ) + { + if( (*pHeadingStyles)[i] == rStyleName ) + return static_cast < sal_Int32 >( i ); + } + + return -1; +} + +// --> OD 2008-05-08 #refactorlists# +void XMLTextParagraphExport::PushNewTextListsHelper() +{ + mpTextListsHelper = new XMLTextListsHelper(); + maTextListsHelperStack.push_back( mpTextListsHelper ); +} + +void XMLTextParagraphExport::PopTextListsHelper() +{ + delete mpTextListsHelper; + mpTextListsHelper = 0; + maTextListsHelperStack.pop_back(); + if ( !maTextListsHelperStack.empty() ) + { + mpTextListsHelper = maTextListsHelperStack.back(); + } +} +// <-- diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx new file mode 100644 index 000000000000..697d3e6cd069 --- /dev/null +++ b/xmloff/source/text/txtparai.cxx @@ -0,0 +1,2446 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "unointerfacetouniqueidentifiermapper.hxx" +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> + +#include <tools/string.hxx> +#include <svl/svarray.hxx> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/rdf/XMetadatable.hpp> + + +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/txtimp.hxx> +#include "txtparai.hxx" +#include "txtfldi.hxx" +#include <xmloff/xmluconv.hxx> +#include "XMLFootnoteImportContext.hxx" +#include "XMLTextMarkImportContext.hxx" +#include "XMLTextFrameContext.hxx" +#include <xmloff/XMLCharContext.hxx> +#include "XMLTextFrameHyperlinkContext.hxx" +#include <xmloff/XMLEventsImportContext.hxx> +#include "XMLChangeImportContext.hxx" +#include "txtlists.hxx" + + +// OD 2004-04-21 #i26791# +#include <txtparaimphint.hxx> +typedef XMLHint_Impl *XMLHint_ImplPtr; +SV_DECL_PTRARR_DEL( XMLHints_Impl, XMLHint_ImplPtr, 5, 5 ) +SV_IMPL_PTRARR( XMLHints_Impl, XMLHint_ImplPtr ) +// OD 2004-04-21 #i26791# +#include <com/sun/star/beans/XPropertySet.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; +using ::com::sun::star::container::XEnumerationAccess; +using ::com::sun::star::container::XEnumeration; + + +TYPEINIT1( XMLCharContext, SvXMLImportContext ); + +XMLCharContext::XMLCharContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_Unicode c, + sal_Bool bCount ) : + SvXMLImportContext( rImport, nPrfx, rLName ) + ,m_nControl(0) + ,m_nCount(1) + ,m_c(c) +{ + if( bCount ) + { + const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap(); + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_C ) ) + { + sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32(); + if( nTmp > 0L ) + { + if( nTmp > USHRT_MAX ) + m_nCount = USHRT_MAX; + else + m_nCount = (sal_uInt16)nTmp; + } + } + } + } +} + +XMLCharContext::XMLCharContext( + SvXMLImport& rImp, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > &, + sal_Int16 nControl ) : + SvXMLImportContext( rImp, nPrfx, rLName ) + ,m_nControl(nControl) + ,m_nCount(0) +{ +} + +XMLCharContext::~XMLCharContext() +{ +} +// ----------------------------------------------------------------------------- +void XMLCharContext::EndElement() +{ + if ( !m_nCount ) + InsertControlCharacter( m_nControl ); + else + { + if( 1U == m_nCount ) + { + OUString sBuff( &m_c, 1 ); + InsertString(sBuff); + } + else + { + OUStringBuffer sBuff( m_nCount ); + while( m_nCount-- ) + sBuff.append( &m_c, 1 ); + + InsertString(sBuff.makeStringAndClear() ); + } + } +} +// ----------------------------------------------------------------------------- +void XMLCharContext::InsertControlCharacter(sal_Int16 _nControl) +{ + GetImport().GetTextImport()->InsertControlCharacter( _nControl ); +} +void XMLCharContext::InsertString(const ::rtl::OUString& _sString) +{ + GetImport().GetTextImport()->InsertString( _sString ); +} + +// --------------------------------------------------------------------- + +/** import start of reference (<text:reference-start>) */ +class XMLStartReferenceContext_Impl : public SvXMLImportContext +{ +public: + TYPEINFO(); + + // Do everything in constructor. Well ... + XMLStartReferenceContext_Impl ( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + XMLHints_Impl& rHnts, + const Reference<xml::sax::XAttributeList> & xAttrList); + + static sal_Bool FindName( + SvXMLImport& rImport, + const Reference<xml::sax::XAttributeList> & xAttrList, + OUString& rName); +}; + +TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext ); + +XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + XMLHints_Impl& rHints, + const Reference<xml::sax::XAttributeList> & xAttrList) : + SvXMLImportContext(rImport, nPrefix, rLocalName) +{ + OUString sName; + + if (FindName(GetImport(), xAttrList, sName)) + { + XMLHint_Impl* pHint = new XMLReferenceHint_Impl( + sName, rImport.GetTextImport()->GetCursor()->getStart() ); + + // degenerates to point reference, if no end is found! + pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() ); + + rHints.Insert(pHint, rHints.Count()); + } +} + +sal_Bool XMLStartReferenceContext_Impl::FindName( + SvXMLImport& rImport, + const Reference<xml::sax::XAttributeList> & xAttrList, + OUString& rName) +{ + sal_Bool bNameOK( sal_False ); + + // find name attribute first + const sal_Int16 nLength( xAttrList->getLength() ); + for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + const sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if ( (XML_NAMESPACE_TEXT == nPrefix) && + IsXMLToken(sLocalName, XML_NAME) ) + { + rName = xAttrList->getValueByIndex(nAttr); + bNameOK = sal_True; + } + } + + return bNameOK; +} + +// --------------------------------------------------------------------- + +/** import end of reference (<text:reference-end>) */ +class XMLEndReferenceContext_Impl : public SvXMLImportContext +{ +public: + TYPEINFO(); + + // Do everything in constructor. Well ... + XMLEndReferenceContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + XMLHints_Impl& rHnts, + const Reference<xml::sax::XAttributeList> & xAttrList); +}; + +TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext ); + +XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + XMLHints_Impl& rHints, + const Reference<xml::sax::XAttributeList> & xAttrList) : + SvXMLImportContext(rImport, nPrefix, rLocalName) +{ + OUString sName; + + // borrow from XMLStartReferenceContext_Impl + if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName)) + { + // search for reference start + sal_uInt16 nCount = rHints.Count(); + for(sal_uInt16 nPos = 0; nPos < nCount; nPos++) + { + XMLHint_Impl *pHint = rHints[nPos]; + if ( pHint->IsReference() && + sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) ) + { + // set end and stop searching + pHint->SetEnd(GetImport().GetTextImport()-> + GetCursor()->getStart() ); + break; + } + } + // else: no start (in this paragraph) -> ignore + } +} + +// --------------------------------------------------------------------- + +class XMLImpSpanContext_Impl : public SvXMLImportContext +{ + const OUString sTextFrame; + + XMLHints_Impl& rHints; + XMLStyleHint_Impl *pHint; + + sal_Bool& rIgnoreLeadingSpace; + + sal_uInt8 nStarFontsConvFlags; + +public: + + TYPEINFO(); + + XMLImpSpanContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace + ,sal_uInt8 nSFConvFlags + ); + + virtual ~XMLImpSpanContext_Impl(); + + static SvXMLImportContext *CreateChildContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_uInt16 nToken, XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace + ,sal_uInt8 nStarFontsConvFlags = 0 + ); + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + + virtual void Characters( const OUString& rChars ); +}; +// --------------------------------------------------------------------- + +class XMLImpHyperlinkContext_Impl : public SvXMLImportContext +{ + XMLHints_Impl& rHints; + XMLHyperlinkHint_Impl *pHint; + + sal_Bool& rIgnoreLeadingSpace; + +public: + + TYPEINFO(); + + XMLImpHyperlinkContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ); + + virtual ~XMLImpHyperlinkContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + + virtual void Characters( const OUString& rChars ); +}; + +TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext ); + +XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rHints( rHnts ), + pHint( new XMLHyperlinkHint_Impl( + GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ), + rIgnoreLeadingSpace( rIgnLeadSpace ) +{ + OUString sShow; + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_HYPERLINK_HREF: + pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) ); + break; + case XML_TOK_TEXT_HYPERLINK_NAME: + pHint->SetName( rValue ); + break; + case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME: + pHint->SetTargetFrameName( rValue ); + break; + case XML_TOK_TEXT_HYPERLINK_SHOW: + sShow = rValue; + break; + case XML_TOK_TEXT_HYPERLINK_STYLE_NAME: + pHint->SetStyleName( rValue ); + break; + case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME: + pHint->SetVisitedStyleName( rValue ); + break; + } + } + + if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() ) + { + if( IsXMLToken( sShow, XML_NEW ) ) + pHint->SetTargetFrameName( + OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) ); + else if( IsXMLToken( sShow, XML_REPLACE ) ) + pHint->SetTargetFrameName( + OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) ); + } + rHints.Insert( pHint, rHints.Count() ); +} + +XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl() +{ + if( pHint ) + pHint->SetEnd( GetImport().GetTextImport() + ->GetCursorAsRange()->getStart() ); +} + +SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + if ( (nPrefix == XML_NAMESPACE_OFFICE) && + IsXMLToken(rLocalName, XML_EVENT_LISTENERS) ) + { + XMLEventsImportContext* pCtxt = new XMLEventsImportContext( + GetImport(), nPrefix, rLocalName); + pHint->SetEventsContext(pCtxt); + return pCtxt; + } + else + { + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextPElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + + return XMLImpSpanContext_Impl::CreateChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + nToken, rHints, rIgnoreLeadingSpace ); + } +} + +void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars ) +{ + GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace ); +} + +// --------------------------------------------------------------------- + +class XMLImpRubyBaseContext_Impl : public SvXMLImportContext +{ + XMLHints_Impl& rHints; + + sal_Bool& rIgnoreLeadingSpace; + +public: + + TYPEINFO(); + + XMLImpRubyBaseContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ); + + virtual ~XMLImpRubyBaseContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + + virtual void Characters( const OUString& rChars ); +}; + +TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext ); + +XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > &, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rHints( rHnts ), + rIgnoreLeadingSpace( rIgnLeadSpace ) +{ +} + +XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl() +{ +} + +SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextPElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + + return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix, + rLocalName, xAttrList, + nToken, rHints, rIgnoreLeadingSpace ); +} + +void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars ) +{ + GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace ); +} + +// --------------------------------------------------------------------- + +class XMLImpRubyContext_Impl : public SvXMLImportContext +{ + XMLHints_Impl& rHints; + + sal_Bool& rIgnoreLeadingSpace; + + Reference < XTextRange > m_xStart; + OUString m_sStyleName; + OUString m_sTextStyleName; + OUString m_sText; + +public: + + TYPEINFO(); + + XMLImpRubyContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ); + + virtual ~XMLImpRubyContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + + void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; } + void AppendText( const OUString& s ) { m_sText += s; } +}; + +// --------------------------------------------------------------------- + +class XMLImpRubyTextContext_Impl : public SvXMLImportContext +{ + XMLImpRubyContext_Impl & m_rRubyContext; + +public: + + TYPEINFO(); + + XMLImpRubyTextContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLImpRubyContext_Impl & rParent ); + + virtual ~XMLImpRubyTextContext_Impl(); + + virtual void Characters( const OUString& rChars ); +}; + +TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext ); + +XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLImpRubyContext_Impl & rParent ) + : SvXMLImportContext( rImport, nPrfx, rLName ) + , m_rRubyContext( rParent ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + { + m_rRubyContext.SetTextStyleName( rValue ); + break; + } + } +} + +XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl() +{ +} + +void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars ) +{ + m_rRubyContext.AppendText( rChars ); +} + +// --------------------------------------------------------------------- + +TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext ); + +XMLImpRubyContext_Impl::XMLImpRubyContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rHints( rHnts ), + rIgnoreLeadingSpace( rIgnLeadSpace ) + , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + { + m_sStyleName = rValue; + break; + } + } +} + +XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl() +{ + const UniReference < XMLTextImportHelper > xTextImport( + GetImport().GetTextImport()); + const Reference < XTextCursor > xAttrCursor( + xTextImport->GetText()->createTextCursorByRange( m_xStart )); + xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(), + sal_True); + xTextImport->SetRuby( GetImport(), xAttrCursor, + m_sStyleName, m_sTextStyleName, m_sText ); +} + +SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext; + if( XML_NAMESPACE_TEXT == nPrefix ) + { + if( IsXMLToken( rLocalName, XML_RUBY_BASE ) ) + pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix, + rLocalName, + xAttrList, + rHints, + rIgnoreLeadingSpace ); + else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) ) + pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix, + rLocalName, + xAttrList, + *this ); + else + pContext = new SvXMLImportContext( + GetImport(), nPrefix, rLocalName ); + } + else + pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + + return pContext; +} + +// --------------------------------------------------------------------- + +/** for text:meta and text:meta-field + */ +class XMLMetaImportContextBase : public SvXMLImportContext +{ + XMLHints_Impl& m_rHints; + + sal_Bool& m_rIgnoreLeadingSpace; + + /// start position + Reference<XTextRange> m_xStart; + +protected: + OUString m_XmlId; + +public: + TYPEINFO(); + + XMLMetaImportContextBase( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ); + + virtual ~XMLMetaImportContextBase(); + + virtual void StartElement( + const Reference<xml::sax::XAttributeList> & i_xAttrList); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 i_nPrefix, const OUString& i_rLocalName, + const Reference< xml::sax::XAttributeList > & i_xAttrList); + + virtual void Characters( const OUString& i_rChars ); + + virtual void ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue); + + virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange) + = 0; +}; + +TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext ); + +XMLMetaImportContextBase::XMLMetaImportContextBase( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ) + : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ) + , m_rHints( i_rHints ) + , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace ) + , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) +{ +} + +XMLMetaImportContextBase::~XMLMetaImportContextBase() +{ +} + +void XMLMetaImportContextBase::StartElement( + const Reference<xml::sax::XAttributeList> & i_xAttrList) +{ + const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0); + for ( sal_Int16 i = 0; i < nAttrCount; ++i ) + { + const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) ); + const OUString& rValue( i_xAttrList->getValueByIndex( i ) ); + + OUString sLocalName; + const sal_uInt16 nPrefix( + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &sLocalName )); + ProcessAttribute(nPrefix, sLocalName, rValue); + } +} + +void XMLMetaImportContextBase::EndElement() +{ + OSL_ENSURE(m_xStart.is(), "no mxStart?"); + if (!m_xStart.is()) return; + + const Reference<XTextRange> xEndRange( + GetImport().GetTextImport()->GetCursorAsRange()->getStart() ); + + // create range for insertion + const Reference<XTextCursor> xInsertionCursor( + GetImport().GetTextImport()->GetText()->createTextCursorByRange( + xEndRange) ); + xInsertionCursor->gotoRange(m_xStart, sal_True); + + const Reference<XTextRange> xInsertionRange(xInsertionCursor, UNO_QUERY); + + InsertMeta(xInsertionRange); +} + +SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext( + sal_uInt16 i_nPrefix, const OUString& i_rLocalName, + const Reference< xml::sax::XAttributeList > & i_xAttrList ) +{ + const SvXMLTokenMap& rTokenMap( + GetImport().GetTextImport()->GetTextPElemTokenMap() ); + const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) ); + + return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix, + i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace ); +} + +void XMLMetaImportContextBase::Characters( const OUString& i_rChars ) +{ + GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace); +} + +void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue) +{ + if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) ) + { + m_XmlId = i_rValue; + } +} + + +// --------------------------------------------------------------------- + +/** text:meta */ +class XMLMetaImportContext : public XMLMetaImportContextBase +{ + // RDFa + bool m_bHaveAbout; + ::rtl::OUString m_sAbout; + ::rtl::OUString m_sProperty; + ::rtl::OUString m_sContent; + ::rtl::OUString m_sDatatype; + +public: + TYPEINFO(); + + XMLMetaImportContext( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ); + + virtual void ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue); + + virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange); +}; + +TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase ); + +XMLMetaImportContext::XMLMetaImportContext( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ) + : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName, + i_rHints, i_rIgnoreLeadingSpace ) + , m_bHaveAbout(false) +{ +} + +void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue) +{ + if ( XML_NAMESPACE_XHTML == i_nPrefix ) + { + // RDFa + if ( IsXMLToken( i_rLocalName, XML_ABOUT) ) + { + m_sAbout = i_rValue; + m_bHaveAbout = true; + } + else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) ) + { + m_sProperty = i_rValue; + } + else if ( IsXMLToken( i_rLocalName, XML_CONTENT) ) + { + m_sContent = i_rValue; + } + else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) ) + { + m_sDatatype = i_rValue; + } + } + else + { + XMLMetaImportContextBase::ProcessAttribute( + i_nPrefix, i_rLocalName, i_rValue); + } +} + +void XMLMetaImportContext::InsertMeta( + const Reference<XTextRange> & i_xInsertionRange) +{ + OSL_ENSURE(!m_bHaveAbout == !m_sProperty.getLength(), + "XMLMetaImportContext::InsertMeta: invalid RDFa?"); + if (m_XmlId.getLength() || (m_bHaveAbout && m_sProperty.getLength())) + { + // insert mark + const uno::Reference<rdf::XMetadatable> xMeta( + XMLTextMarkImportContext::CreateAndInsertMark( + GetImport(), + OUString::createFromAscii( + "com.sun.star.text.InContentMetadata"), + OUString(), + i_xInsertionRange, m_XmlId), + uno::UNO_QUERY); + OSL_ENSURE(xMeta.is(), "cannot insert Meta?"); + + if (xMeta.is() && m_bHaveAbout) + { + GetImport().AddRDFa(xMeta, + m_sAbout, m_sProperty, m_sContent, m_sDatatype); + } + } + else + { + OSL_TRACE("invalid <text:meta>: no xml:id, no valid RDFa"); + } +} + +// --------------------------------------------------------------------- + +/** text:meta-field */ +class XMLMetaFieldImportContext : public XMLMetaImportContextBase +{ + OUString m_DataStyleName; + +public: + TYPEINFO(); + + XMLMetaFieldImportContext( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ); + + virtual void ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue); + + virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange); +}; + +TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase ); + +XMLMetaFieldImportContext::XMLMetaFieldImportContext( + SvXMLImport& i_rImport, + const sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + XMLHints_Impl& i_rHints, + sal_Bool & i_rIgnoreLeadingSpace ) + : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName, + i_rHints, i_rIgnoreLeadingSpace ) +{ +} + +void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix, + OUString const & i_rLocalName, OUString const & i_rValue) +{ + if ( XML_NAMESPACE_STYLE == i_nPrefix && + IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) ) + { + m_DataStyleName = i_rValue; + } + else + { + XMLMetaImportContextBase::ProcessAttribute( + i_nPrefix, i_rLocalName, i_rValue); + } +} + +void XMLMetaFieldImportContext::InsertMeta( + const Reference<XTextRange> & i_xInsertionRange) +{ + if (m_XmlId.getLength()) // valid? + { + // insert mark + const Reference<XPropertySet> xPropertySet( + XMLTextMarkImportContext::CreateAndInsertMark( + GetImport(), + OUString::createFromAscii( + "com.sun.star.text.textfield.MetadataField"), + OUString(), + i_xInsertionRange, m_XmlId), + UNO_QUERY); + OSL_ENSURE(xPropertySet.is(), "cannot insert MetaField?"); + if (!xPropertySet.is()) return; + + if (m_DataStyleName.getLength()) + { + sal_Bool isDefaultLanguage(sal_True); + + const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey( + m_DataStyleName, & isDefaultLanguage) ); + + if (-1 != nKey) + { + static ::rtl::OUString sPropertyIsFixedLanguage( + ::rtl::OUString::createFromAscii("IsFixedLanguage") ); + Any any; + any <<= nKey; + xPropertySet->setPropertyValue( + OUString::createFromAscii("NumberFormat"), any); + if ( xPropertySet->getPropertySetInfo()-> + hasPropertyByName( sPropertyIsFixedLanguage ) ) + { + any <<= static_cast<bool>(!isDefaultLanguage); + xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, + any ); + } + } + } + } + else + { + OSL_TRACE("invalid <text:meta-field>: no xml:id"); + } +} + + +// --------------------------------------------------------------------- + + +/** + * Process index marks. + * + * All *-mark-end index marks should instantiate *this* class (because + * it doesn't process attributes other than ID), while the *-mark and + * *-mark-start classes should instantiate the apporpiate subclasses. + */ +class XMLIndexMarkImportContext_Impl : public SvXMLImportContext +{ + const OUString sAlternativeText; + + XMLHints_Impl& rHints; + const enum XMLTextPElemTokens eToken; + OUString sID; + +public: + TYPEINFO(); + + XMLIndexMarkImportContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + enum XMLTextPElemTokens nTok, + XMLHints_Impl& rHnts); + + void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList); + +protected: + + /// process all attributes + void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList, + Reference<beans::XPropertySet>& rPropSet); + + /** + * All marks can be created immediatly. Since we don't care about + * the element content, ProcessAttribute should set the properties + * immediatly. + * + * This method tolerates an empty PropertySet; subclasses however + * are not expected to. + */ + virtual void ProcessAttribute(sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet); + + static void GetServiceName(OUString& sServiceName, + enum XMLTextPElemTokens nToken); + + sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet, + const OUString& rServiceName); +}; + + +TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext ); + +XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + enum XMLTextPElemTokens eTok, + XMLHints_Impl& rHnts) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText")), + rHints(rHnts), + eToken(eTok) +{ +} + +void XMLIndexMarkImportContext_Impl::StartElement( + const Reference<xml::sax::XAttributeList> & xAttrList) +{ + // get Cursor position (needed for all cases) + Reference<XTextRange> xPos( + GetImport().GetTextImport()->GetCursor()->getStart()); + Reference<beans::XPropertySet> xMark; + + switch (eToken) + { + case XML_TOK_TEXT_TOC_MARK: + case XML_TOK_TEXT_USER_INDEX_MARK: + case XML_TOK_TEXT_ALPHA_INDEX_MARK: + { + // single mark: create mark and insert + OUString sService; + GetServiceName(sService, eToken); + if (CreateMark(xMark, sService)) + { + ProcessAttributes(xAttrList, xMark); + XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos); + rHints.Insert(pHint, rHints.Count()); + } + // else: can't create mark -> ignore + break; + } + + case XML_TOK_TEXT_TOC_MARK_START: + case XML_TOK_TEXT_USER_INDEX_MARK_START: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_START: + { + // start: create mark and insert (if ID is found) + OUString sService; + GetServiceName(sService, eToken); + if (CreateMark(xMark, sService)) + { + ProcessAttributes(xAttrList, xMark); + if (sID.getLength() > 0) + { + // process only if we find an ID + XMLHint_Impl* pHint = + new XMLIndexMarkHint_Impl(xMark, xPos, sID); + rHints.Insert(pHint, rHints.Count()); + } + // else: no ID -> we'll never find the end -> ignore + } + // else: can't create mark -> ignore + break; + } + + case XML_TOK_TEXT_TOC_MARK_END: + case XML_TOK_TEXT_USER_INDEX_MARK_END: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_END: + { + // end: search for ID and set end of mark + + // call process attributes with empty XPropertySet: + ProcessAttributes(xAttrList, xMark); + if (sID.getLength() > 0) + { + // if we have an ID, find the hint and set the end position + sal_uInt16 nCount = rHints.Count(); + for(sal_uInt16 nPos = 0; nPos < nCount; nPos++) + { + XMLHint_Impl *pHint = rHints[nPos]; + if ( pHint->IsIndexMark() && + sID.equals( + ((XMLIndexMarkHint_Impl *)pHint)->GetID()) ) + { + // set end and stop searching + pHint->SetEnd(xPos); + break; + } + } + } + // else: no ID -> ignore + break; + } + + default: + DBG_ERROR("unknown index mark type!"); + break; + } +} + +void XMLIndexMarkImportContext_Impl::ProcessAttributes( + const Reference<xml::sax::XAttributeList> & xAttrList, + Reference<beans::XPropertySet>& rPropSet) +{ + // process attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + ProcessAttribute(nPrefix, sLocalName, + xAttrList->getValueByIndex(i), + rPropSet); + } +} + +void XMLIndexMarkImportContext_Impl::ProcessAttribute( + sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet) +{ + // we only know ID + string-value attribute; + // (former: marks, latter: -start + -end-marks) + // the remainder is handled in sub-classes + switch (eToken) + { + case XML_TOK_TEXT_TOC_MARK: + case XML_TOK_TEXT_USER_INDEX_MARK: + case XML_TOK_TEXT_ALPHA_INDEX_MARK: + if ( (XML_NAMESPACE_TEXT == nNamespace) && + IsXMLToken( sLocalName, XML_STRING_VALUE ) ) + { + rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue)); + } + // else: ignore! + break; + + case XML_TOK_TEXT_TOC_MARK_START: + case XML_TOK_TEXT_USER_INDEX_MARK_START: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_START: + case XML_TOK_TEXT_TOC_MARK_END: + case XML_TOK_TEXT_USER_INDEX_MARK_END: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_END: + if ( (XML_NAMESPACE_TEXT == nNamespace) && + IsXMLToken( sLocalName, XML_ID ) ) + { + sID = sValue; + } + // else: ignore + break; + + default: + DBG_ERROR("unknown index mark type!"); + break; + } +} + +static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] = + "com.sun.star.text.ContentIndexMark"; +static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] = + "com.sun.star.text.UserIndexMark"; +static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] = + "com.sun.star.text.DocumentIndexMark"; + + +void XMLIndexMarkImportContext_Impl::GetServiceName( + OUString& sServiceName, + enum XMLTextPElemTokens eToken) +{ + switch (eToken) + { + case XML_TOK_TEXT_TOC_MARK: + case XML_TOK_TEXT_TOC_MARK_START: + case XML_TOK_TEXT_TOC_MARK_END: + { + OUString sTmp(RTL_CONSTASCII_USTRINGPARAM( + sAPI_com_sun_star_text_ContentIndexMark)); + sServiceName = sTmp; + break; + } + + case XML_TOK_TEXT_USER_INDEX_MARK: + case XML_TOK_TEXT_USER_INDEX_MARK_START: + case XML_TOK_TEXT_USER_INDEX_MARK_END: + { + OUString sTmp(RTL_CONSTASCII_USTRINGPARAM( + sAPI_com_sun_star_text_UserIndexMark)); + sServiceName = sTmp; + break; + } + + case XML_TOK_TEXT_ALPHA_INDEX_MARK: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_START: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_END: + { + OUString sTmp(RTL_CONSTASCII_USTRINGPARAM( + sAPI_com_sun_star_text_DocumentIndexMark)); + sServiceName = sTmp; + break; + } + + default: + { + DBG_ERROR("unknown index mark type!"); + OUString sTmp; + sServiceName = sTmp; + break; + } + } +} + + +sal_Bool XMLIndexMarkImportContext_Impl::CreateMark( + Reference<beans::XPropertySet>& rPropSet, + const OUString& rServiceName) +{ + Reference<lang::XMultiServiceFactory> + xFactory(GetImport().GetModel(), UNO_QUERY); + + if( xFactory.is() ) + { + Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY ); + if (xPropSet.is()) + rPropSet = xPropSet; + return sal_True; + } + + return sal_False; +} + + +class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl +{ + const OUString sLevel; + +public: + TYPEINFO(); + + XMLTOCMarkImportContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + enum XMLTextPElemTokens nTok, + XMLHints_Impl& rHnts); + +protected: + + /** process outline level */ + virtual void ProcessAttribute(sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet); +}; + +TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl ); + + +XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, + enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) : + XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName, + nTok, rHnts), + sLevel(RTL_CONSTASCII_USTRINGPARAM("Level")) +{ +} + +void XMLTOCMarkImportContext_Impl::ProcessAttribute( + sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet) +{ + DBG_ASSERT(rPropSet.is(), "need PropertySet"); + + if ((XML_NAMESPACE_TEXT == nNamespace) && + IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) ) + { + // ouline level: set Level property + sal_Int32 nTmp; + if ( SvXMLUnitConverter::convertNumber( nTmp, sValue ) + && nTmp >= 1 + && nTmp < GetImport().GetTextImport()-> + GetChapterNumbering()->getCount() ) + { + rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1))); + } + // else: value out of range -> ignore + } + else + { + // else: delegate to superclass + XMLIndexMarkImportContext_Impl::ProcessAttribute( + nNamespace, sLocalName, sValue, rPropSet); + } +} + +class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl +{ + const OUString sUserIndexName; + const OUString sLevel; + +public: + TYPEINFO(); + + XMLUserIndexMarkImportContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + enum XMLTextPElemTokens nTok, + XMLHints_Impl& rHnts); + +protected: + + /** process index name */ + virtual void ProcessAttribute(sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet); +}; + +TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl); + +XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, + enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) : + XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName, + nTok, rHnts), + sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName")), + sLevel(RTL_CONSTASCII_USTRINGPARAM("Level")) +{ +} + +void XMLUserIndexMarkImportContext_Impl::ProcessAttribute( + sal_uInt16 nNamespace, OUString sLocalName, OUString sValue, + Reference<beans::XPropertySet>& rPropSet) +{ + if ( XML_NAMESPACE_TEXT == nNamespace ) + { + if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) ) + { + rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) ) + { + // ouline level: set Level property + sal_Int32 nTmp; + if (SvXMLUnitConverter::convertNumber( + nTmp, sValue, 0, + GetImport().GetTextImport()->GetChapterNumbering()->getCount())) + { + rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1))); + } + // else: value out of range -> ignore + } + else + { + // else: unknown text property: delegate to super class + XMLIndexMarkImportContext_Impl::ProcessAttribute( + nNamespace, sLocalName, sValue, rPropSet); + } + } + else + { + // else: unknown namespace: delegate to super class + XMLIndexMarkImportContext_Impl::ProcessAttribute( + nNamespace, sLocalName, sValue, rPropSet); + } +} + + +class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl +{ + const OUString sPrimaryKey; + const OUString sSecondaryKey; + const OUString sTextReading; + const OUString sPrimaryKeyReading; + const OUString sSecondaryKeyReading; + const OUString sMainEntry; + +public: + TYPEINFO(); + + XMLAlphaIndexMarkImportContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + enum XMLTextPElemTokens nTok, + XMLHints_Impl& rHnts); + +protected: + + /** process primary + secondary keys */ + virtual void ProcessAttribute(sal_uInt16 nNamespace, + OUString sLocalName, + OUString sValue, + Reference<beans::XPropertySet>& rPropSet); +}; + +TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl, + XMLIndexMarkImportContext_Impl ); + +XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, + enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) : + XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName, + nTok, rHnts), + sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey")), + sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey")), + sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading")), + sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading")), + sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading")), + sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry")) +{ +} + +void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute( + sal_uInt16 nNamespace, OUString sLocalName, OUString sValue, + Reference<beans::XPropertySet>& rPropSet) +{ + if (XML_NAMESPACE_TEXT == nNamespace) + { + if ( IsXMLToken( sLocalName, XML_KEY1 ) ) + { + rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_KEY2 ) ) + { + rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) ) + { + rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) ) + { + rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) ) + { + rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue)); + } + else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) ) + { + sal_Bool bMainEntry = sal_False, bTmp; + + if (SvXMLUnitConverter::convertBool(bTmp, sValue)) + bMainEntry = bTmp; + + rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry)); + } + else + { + XMLIndexMarkImportContext_Impl::ProcessAttribute( + nNamespace, sLocalName, sValue, rPropSet); + } + } + else + { + XMLIndexMarkImportContext_Impl::ProcessAttribute( + nNamespace, sLocalName, sValue, rPropSet); + } +} + + +// --------------------------------------------------------------------- + +TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext ); + +XMLImpSpanContext_Impl::XMLImpSpanContext_Impl( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + XMLHints_Impl& rHnts, + sal_Bool& rIgnLeadSpace + ,sal_uInt8 nSFConvFlags + ) +: SvXMLImportContext( rImport, nPrfx, rLName ) +, sTextFrame(RTL_CONSTASCII_USTRINGPARAM("TextFrame")) +, rHints( rHnts ) +, pHint( 0 ) +, rIgnoreLeadingSpace( rIgnLeadSpace ) +, nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) ) +{ + OUString aStyleName; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + if( XML_NAMESPACE_TEXT == nPrefix && + IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + aStyleName = xAttrList->getValueByIndex( i ); + } + + if( aStyleName.getLength() ) + { + pHint = new XMLStyleHint_Impl( aStyleName, + GetImport().GetTextImport()->GetCursorAsRange()->getStart() ); + rHints.Insert( pHint, rHints.Count() ); + } +} + +XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl() +{ + if( pHint ) + pHint->SetEnd( GetImport().GetTextImport() + ->GetCursorAsRange()->getStart() ); +} + +SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_uInt16 nToken, + XMLHints_Impl& rHints, + sal_Bool& rIgnoreLeadingSpace + ,sal_uInt8 nStarFontsConvFlags + ) +{ + SvXMLImportContext *pContext = 0; + + switch( nToken ) + { + case XML_TOK_TEXT_SPAN: + pContext = new XMLImpSpanContext_Impl( rImport, nPrefix, + rLocalName, xAttrList, + rHints, + rIgnoreLeadingSpace + ,nStarFontsConvFlags + ); + break; + + case XML_TOK_TEXT_TAB_STOP: + pContext = new XMLCharContext( rImport, nPrefix, + rLocalName, xAttrList, + 0x0009, sal_False ); + rIgnoreLeadingSpace = sal_False; + break; + + case XML_TOK_TEXT_LINE_BREAK: + pContext = new XMLCharContext( rImport, nPrefix, + rLocalName, xAttrList, + ControlCharacter::LINE_BREAK ); + rIgnoreLeadingSpace = sal_False; + break; + + case XML_TOK_TEXT_S: + pContext = new XMLCharContext( rImport, nPrefix, + rLocalName, xAttrList, + 0x0020, sal_True ); + break; + + case XML_TOK_TEXT_HYPERLINK: + { + // test for HyperLinkURL property. If present, insert link as + // text property (StarWriter), else try to insert as text + // field (StarCalc, StarDraw, ...) + Reference<beans::XPropertySet> xPropSet( + rImport.GetTextImport()->GetCursor(), + UNO_QUERY ); + + const OUString sHyperLinkURL( + RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL")); + + if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL)) + { + pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix, + rLocalName, xAttrList, + rHints, + rIgnoreLeadingSpace ); + } + else + { + pContext = new XMLUrlFieldImportContext( rImport, + *rImport.GetTextImport().get(), + nPrefix, rLocalName); + //whitespace handling like other fields + rIgnoreLeadingSpace = sal_False; + + } + break; + } + + case XML_TOK_TEXT_RUBY: + pContext = new XMLImpRubyContext_Impl( rImport, nPrefix, + rLocalName, xAttrList, + rHints, + rIgnoreLeadingSpace ); + break; + + case XML_TOK_TEXT_NOTE: +#ifndef SVX_LIGHT + if (rImport.GetTextImport()->IsInFrame()) + { + // we must not insert footnotes into text frames + pContext = new SvXMLImportContext( rImport, nPrefix, + rLocalName ); + } + else + { + pContext = new XMLFootnoteImportContext( rImport, + *rImport.GetTextImport().get(), + nPrefix, rLocalName ); + } +#else + // create default context to skip content + pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName ); +#endif // #ifndef SVX_LIGHT + rIgnoreLeadingSpace = sal_False; + break; + + case XML_TOK_TEXT_REFERENCE: + case XML_TOK_TEXT_BOOKMARK: + case XML_TOK_TEXT_BOOKMARK_START: + case XML_TOK_TEXT_BOOKMARK_END: + pContext = new XMLTextMarkImportContext( rImport, + *rImport.GetTextImport().get(), + nPrefix, rLocalName ); + break; + + case XML_TOK_TEXT_FIELDMARK: + case XML_TOK_TEXT_FIELDMARK_START: + case XML_TOK_TEXT_FIELDMARK_END: + pContext = new XMLTextMarkImportContext( rImport, + *rImport.GetTextImport().get(), + nPrefix, rLocalName ); + break; + + case XML_TOK_TEXT_REFERENCE_START: + pContext = new XMLStartReferenceContext_Impl( rImport, + nPrefix, rLocalName, + rHints, xAttrList ); + break; + + case XML_TOK_TEXT_REFERENCE_END: + pContext = new XMLEndReferenceContext_Impl( rImport, + nPrefix, rLocalName, + rHints, xAttrList ); + break; + + case XML_TOK_TEXT_FRAME: + { + Reference < XTextRange > xAnchorPos = + rImport.GetTextImport()->GetCursor()->getStart(); + XMLTextFrameContext *pTextFrameContext = + new XMLTextFrameContext( rImport, nPrefix, + rLocalName, xAttrList, + TextContentAnchorType_AS_CHARACTER ); + // --> OD 2004-08-24 #i33242# - remove check for text content. + // Check for text content is done on the processing of the hint + if( TextContentAnchorType_AT_CHARACTER == + pTextFrameContext->GetAnchorType() ) + // <-- + { + rHints.Insert( new XMLTextFrameHint_Impl( + pTextFrameContext, xAnchorPos ), + rHints.Count() ); + } + pContext = pTextFrameContext; + rIgnoreLeadingSpace = sal_False; + } + break; + case XML_TOK_DRAW_A: + { + Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart()); + pContext = + new XMLTextFrameHyperlinkContext( rImport, nPrefix, + rLocalName, xAttrList, + TextContentAnchorType_AS_CHARACTER ); + XMLTextFrameHint_Impl *pHint = + new XMLTextFrameHint_Impl( pContext, xAnchorPos); + rHints.Insert( pHint, rHints.Count() ); + } + break; + + case XML_TOK_TEXT_TOC_MARK: + case XML_TOK_TEXT_TOC_MARK_START: + pContext = new XMLTOCMarkImportContext_Impl( + rImport, nPrefix, rLocalName, + (enum XMLTextPElemTokens)nToken, rHints); + break; + + case XML_TOK_TEXT_USER_INDEX_MARK: + case XML_TOK_TEXT_USER_INDEX_MARK_START: + pContext = new XMLUserIndexMarkImportContext_Impl( + rImport, nPrefix, rLocalName, + (enum XMLTextPElemTokens)nToken, rHints); + break; + + case XML_TOK_TEXT_ALPHA_INDEX_MARK: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_START: + pContext = new XMLAlphaIndexMarkImportContext_Impl( + rImport, nPrefix, rLocalName, + (enum XMLTextPElemTokens)nToken, rHints); + break; + + case XML_TOK_TEXT_TOC_MARK_END: + case XML_TOK_TEXT_USER_INDEX_MARK_END: + case XML_TOK_TEXT_ALPHA_INDEX_MARK_END: + pContext = new XMLIndexMarkImportContext_Impl( + rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken, + rHints); + break; + + case XML_TOK_TEXTP_CHANGE_START: + case XML_TOK_TEXTP_CHANGE_END: + case XML_TOK_TEXTP_CHANGE: + pContext = new XMLChangeImportContext( + rImport, nPrefix, rLocalName, + (nToken != XML_TOK_TEXTP_CHANGE_END), + (nToken != XML_TOK_TEXTP_CHANGE_START), + sal_False); + break; + + case XML_TOK_TEXT_META: + pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName, + rHints, rIgnoreLeadingSpace ); + break; + + case XML_TOK_TEXT_META_FIELD: + pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName, + rHints, rIgnoreLeadingSpace ); + break; + + default: + // none of the above? then it's probably a text field! + pContext = + XMLTextFieldImportContext::CreateTextFieldImportContext( + rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName, + nToken); + // #108784# import draw elements (except control shapes in headers) + if( pContext == NULL && + !( rImport.GetTextImport()->IsInHeaderFooter() && + nPrefix == XML_NAMESPACE_DRAW && + IsXMLToken( rLocalName, XML_CONTROL ) ) ) + { + Reference < XShapes > xShapes; + SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext( + rImport, nPrefix, rLocalName, xAttrList, xShapes ); + pContext = pShapeContext; + // OD 2004-04-20 #i26791# - keep shape in a text frame hint to + // adjust its anchor position, if its at-character anchored + Reference < XTextRange > xAnchorPos = + rImport.GetTextImport()->GetCursor()->getStart(); + rHints.Insert( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ), + rHints.Count() ); + } + if( !pContext ) + { + // ignore unknown content + pContext = + new SvXMLImportContext( rImport, nPrefix, rLocalName ); + } + // Behind fields, shapes and any unknown content blanks aren't ignored + rIgnoreLeadingSpace = sal_False; + } + + return pContext; +} + +SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextPElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + + return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList, + nToken, rHints, rIgnoreLeadingSpace + ,nStarFontsConvFlags + ); +} + +void XMLImpSpanContext_Impl::Characters( const OUString& rChars ) +{ + OUString sStyleName; + if( pHint ) + sStyleName = pHint->GetStyleName(); + OUString sChars = + GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName, + nStarFontsConvFlags, + sal_False, GetImport() ); + GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace ); +} + +// --------------------------------------------------------------------- + +TYPEINIT1( XMLParaContext, SvXMLImportContext ); + +XMLParaContext::XMLParaContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_Bool bHead ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ), + m_bHaveAbout(false), + nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ), + pHints( 0 ), + // --> OD 2007-07-25 #i73509# + mbOutlineLevelAttrFound( sal_False ), + // <-- + bIgnoreLeadingSpace( sal_True ), + bHeading( bHead ), + bIsListHeader( false ), + bIsRestart (false), + nStartValue(0) + ,nStarFontsConvFlags( 0 ) +{ + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextPAttrTokenMap(); + + bool bHaveXmlId( false ); + OUString aCondStyleName, sClassNames; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_P_XMLID: + m_sXmlId = rValue; + bHaveXmlId = true; + break; + case XML_TOK_TEXT_P_ABOUT: + m_sAbout = rValue; + m_bHaveAbout = true; + break; + case XML_TOK_TEXT_P_PROPERTY: + m_sProperty = rValue; + break; + case XML_TOK_TEXT_P_CONTENT: + m_sContent = rValue; + break; + case XML_TOK_TEXT_P_DATATYPE: + m_sDatatype = rValue; + break; + case XML_TOK_TEXT_P_TEXTID: + if (!bHaveXmlId) { m_sXmlId = rValue; } + break; + case XML_TOK_TEXT_P_STYLE_NAME: + sStyleName = rValue; + break; + case XML_TOK_TEXT_P_CLASS_NAMES: + sClassNames = rValue; + break; + case XML_TOK_TEXT_P_COND_STYLE_NAME: + aCondStyleName = rValue; + break; + case XML_TOK_TEXT_P_LEVEL: + { + sal_Int32 nTmp = rValue.toInt32(); + if( nTmp > 0L ) + { + if( nTmp > 127 ) + nTmp = 127; + nOutlineLevel = (sal_Int8)nTmp; + } + // --> OD 2007-07-25 #i73509# + mbOutlineLevelAttrFound = sal_True; + // <-- + } + break; + case XML_TOK_TEXT_P_IS_LIST_HEADER: + { + sal_Bool bBool; + if( SvXMLUnitConverter::convertBool( bBool, rValue ) ) + { + bIsListHeader = bBool; + } + } + break; + case XML_TOK_TEXT_P_RESTART_NUMBERING: + { + sal_Bool bBool; + if (SvXMLUnitConverter::convertBool(bBool, rValue)) + { + bIsRestart = bBool; + } + } + break; + case XML_TOK_TEXT_P_START_VALUE: + { + nStartValue = sal::static_int_cast< sal_Int16 >( + rValue.toInt32()); + } + break; + } + } + + if( aCondStyleName.getLength() ) + sStyleName = aCondStyleName; + else if( sClassNames.getLength() ) + { + sal_Int32 nDummy = 0; + sStyleName = sClassNames.getToken( 0, ' ', nDummy ); + } +} + +XMLParaContext::~XMLParaContext() +{ + UniReference < XMLTextImportHelper > xTxtImport( + GetImport().GetTextImport()); + Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() ); + if( !xCrsrRange.is() ) + return; // Robust (defect file) + Reference < XTextRange > xEnd(xCrsrRange->getStart()); + + // if we have an id set for this paragraph, get a cursor for this + // paragraph and register it with the given identifier + // FIXME: this is just temporary, and should be removed when + // EditEngine paragraphs implement XMetadatable! + if (m_sXmlId.getLength()) + { + Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) ); + if( xIdCursor.is() ) + { + xIdCursor->gotoRange( xEnd, sal_True ); + Reference< XInterface > xRef( xIdCursor, UNO_QUERY ); + GetImport().getInterfaceToIdentifierMapper().registerReference( + m_sXmlId, xRef); + } + } + + // insert a paragraph break + xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH ); + + // create a cursor that select the whole last paragraph + Reference < XTextCursor > xAttrCursor( + xTxtImport->GetText()->createTextCursorByRange( xStart )); + if( !xAttrCursor.is() ) + return; // Robust (defect file) + xAttrCursor->gotoRange( xEnd, sal_True ); + + // xml:id for RDF metadata + if (m_sXmlId.getLength() || m_bHaveAbout || m_sProperty.getLength()) + { + try { + const uno::Reference<container::XEnumerationAccess> xEA + (xAttrCursor, uno::UNO_QUERY_THROW); + const uno::Reference<container::XEnumeration> xEnum( + xEA->createEnumeration(), uno::UNO_QUERY_THROW); + OSL_ENSURE(xEnum->hasMoreElements(), "xml:id: no paragraph?"); + if (xEnum->hasMoreElements()) { + uno::Reference<rdf::XMetadatable> xMeta; + xEnum->nextElement() >>= xMeta; + OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable"); + GetImport().SetXmlId(xMeta, m_sXmlId); + if (m_bHaveAbout) + { + GetImport().AddRDFa(xMeta, + m_sAbout, m_sProperty, m_sContent, m_sDatatype); + } + OSL_ENSURE(!xEnum->hasMoreElements(), "xml:id: > 1 paragraph?"); + } + } catch (uno::Exception &) { + OSL_TRACE("XMLParaContext::~XMLParaContext: exception"); + } + } + + OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault()); + if( sCellParaStyleName.getLength() > 0 ) + { + // --> OD 2007-08-16 #i80724# + // suppress handling of outline and list attributes, + // because of side effects of method <SetStyleAndAttrs(..)> + xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor, + sCellParaStyleName, + sal_True, + sal_False, -1, // suppress outline handling + sal_False ); // suppress list attributes handling + // <-- + } + + // #103445# for headings without style name, find the proper style + if( bHeading && (sStyleName.getLength() == 0) ) + xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel ); + + // set style and hard attributes at the previous paragraph + // --> OD 2007-07-25 #i73509# - add paramter <mbOutlineLevelAttrFound> + sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor, + sStyleName, + sal_True, + mbOutlineLevelAttrFound, + bHeading ? nOutlineLevel : -1 ); + // <-- + + // handle list style header + if (bHeading && (bIsListHeader || bIsRestart)) + { + Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY ); + + if (xPropSet.is()) + { + if (bIsListHeader) + { + OUString sNumberingIsNumber + (RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber")); + if(xPropSet->getPropertySetInfo()-> + hasPropertyByName(sNumberingIsNumber)) + { + xPropSet->setPropertyValue + (sNumberingIsNumber, makeAny( false ) ); + } + } + if (bIsRestart) + { + OUString sParaIsNumberingRestart + (RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart")); + OUString sNumberingStartValue + (RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue")); + if (xPropSet->getPropertySetInfo()-> + hasPropertyByName(sParaIsNumberingRestart)) + { + xPropSet->setPropertyValue + (sParaIsNumberingRestart, makeAny(true)); + } + + if (xPropSet->getPropertySetInfo()-> + hasPropertyByName(sNumberingStartValue)) + { + xPropSet->setPropertyValue + (sNumberingStartValue, makeAny(nStartValue)); + } + } + + } + } + + if( pHints && pHints->Count() ) + { + for( sal_uInt16 i=0; i<pHints->Count(); i++ ) + { + XMLHint_Impl *pHint = (*pHints)[i]; + xAttrCursor->gotoRange( pHint->GetStart(), sal_False ); + xAttrCursor->gotoRange( pHint->GetEnd(), sal_True ); + switch( pHint->GetType() ) + { + case XML_HINT_STYLE: + { + const OUString& rStyleName = + ((XMLStyleHint_Impl *)pHint)->GetStyleName(); + if( rStyleName.getLength() ) + xTxtImport->SetStyleAndAttrs( GetImport(), + xAttrCursor, rStyleName, + sal_False ); + } + break; + case XML_HINT_REFERENCE: + { + const OUString& rRefName = + ((XMLReferenceHint_Impl *)pHint)->GetRefName(); + if( rRefName.getLength() ) + { + if( !pHint->GetEnd().is() ) + pHint->SetEnd(xEnd); + + // convert XCursor to XTextRange + Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY); + + // reference name uses rStyleName member + // borrow from XMLTextMarkImportContext + XMLTextMarkImportContext::CreateAndInsertMark( + GetImport(), + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.text.ReferenceMark")), + rRefName, + xRange); + } + } + break; + case XML_HINT_HYPERLINK: + { + const XMLHyperlinkHint_Impl *pHHint = + (const XMLHyperlinkHint_Impl *)pHint; + xTxtImport->SetHyperlink( GetImport(), + xAttrCursor, + pHHint->GetHRef(), + pHHint->GetName(), + pHHint->GetTargetFrameName(), + pHHint->GetStyleName(), + pHHint->GetVisitedStyleName(), + pHHint->GetEventsContext() ); + } + break; + case XML_HINT_INDEX_MARK: + { + Reference<beans::XPropertySet> xMark( + ((const XMLIndexMarkHint_Impl *)pHint)->GetMark()); + Reference<XTextContent> xContent(xMark, UNO_QUERY); + Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY); + xTxtImport->GetText()->insertTextContent( + xRange, xContent, sal_True ); + } + break; + case XML_HINT_TEXT_FRAME: + { + const XMLTextFrameHint_Impl *pFHint = + (const XMLTextFrameHint_Impl *)pHint; + // --> OD 2004-08-24 #i33242# - check for text content + Reference < XTextContent > xTextContent = + pFHint->GetTextContent(); + if ( xTextContent.is() ) + { + // OD 2004-04-20 #i26791# + Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY); + if ( pFHint->IsBoundAtChar() ) + { + xTextContent->attach( xRange ); + } + } + // <-- + // --> OD 2004-08-24 #i33242# - consider, that hint can + // also contain a shape - e.g. drawing object of type 'Text'. + else + { + Reference < XShape > xShape = pFHint->GetShape(); + if ( xShape.is() ) + { + // determine anchor type + Reference < XPropertySet > xPropSet( xShape, UNO_QUERY ); + TextContentAnchorType eAnchorType = + TextContentAnchorType_AT_PARAGRAPH; + { + OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) ); + Any aAny = xPropSet->getPropertyValue( sAnchorType ); + aAny >>= eAnchorType; + } + if ( TextContentAnchorType_AT_CHARACTER == eAnchorType ) + { + // set anchor position for at-character anchored objects + Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY); + Any aPos; + aPos <<= xRange; + OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ); + xPropSet->setPropertyValue(sTextRange, aPos); + } + } + } + // <-- + } + break; + // --> DVO, OD 2004-07-14 #i26791# + case XML_HINT_DRAW: + { + const XMLDrawHint_Impl *pDHint = + static_cast<const XMLDrawHint_Impl*>(pHint); + // --> OD 2004-08-24 #i33242# - improvement: hint directly + // provides the shape. + Reference < XShape > xShape = pDHint->GetShape(); + if ( xShape.is() ) + { + // determine anchor type + Reference < XPropertySet > xPropSet( xShape, UNO_QUERY ); + TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH; + { + OUString sAnchorType( RTL_CONSTASCII_USTRINGPARAM( "AnchorType" ) ); + Any aAny = xPropSet->getPropertyValue( sAnchorType ); + aAny >>= eAnchorType; + } + if ( TextContentAnchorType_AT_CHARACTER == eAnchorType ) + { + // set anchor position for at-character anchored objects + Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY); + Any aPos; + aPos <<= xRange; + OUString sTextRange( RTL_CONSTASCII_USTRINGPARAM( "TextRange" ) ); + xPropSet->setPropertyValue(sTextRange, aPos); + } + } + // <-- + } + break; + // <-- + + default: + DBG_ASSERT( !this, "What's this" ); + break; + } + } + } + delete pHints; +} + +SvXMLImportContext *XMLParaContext::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + const SvXMLTokenMap& rTokenMap = + GetImport().GetTextImport()->GetTextPElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + if( !pHints ) + pHints = new XMLHints_Impl; + return XMLImpSpanContext_Impl::CreateChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, + nToken, *pHints, bIgnoreLeadingSpace + , nStarFontsConvFlags + ); +} + +void XMLParaContext::Characters( const OUString& rChars ) +{ + OUString sChars = + GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName, + nStarFontsConvFlags, + sal_True, GetImport() ); + GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace ); +} + + + +TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext ); + +XMLNumberedParaContext::XMLNumberedParaContext( + SvXMLImport& i_rImport, + sal_uInt16 i_nPrefix, + const OUString& i_rLocalName, + const Reference< xml::sax::XAttributeList > & i_xAttrList ) : + SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ), + m_Level(0), + m_StartValue(-1), + m_ListId(), + m_xNumRules() +{ + ::rtl::OUString StyleName; + + const SvXMLTokenMap& rTokenMap( + i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() ); + + const sal_Int16 nAttrCount( i_xAttrList.is() ? + i_xAttrList->getLength() : 0 ); + for ( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const ::rtl::OUString& rAttrName( i_xAttrList->getNameByIndex( i ) ); + const ::rtl::OUString& rValue ( i_xAttrList->getValueByIndex( i ) ); + + ::rtl::OUString aLocalName; + const sal_uInt16 nPrefix( + GetImport().GetNamespaceMap().GetKeyByAttrName( + rAttrName, &aLocalName ) ); + switch( rTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID: + m_XmlId = rValue; +//FIXME: there is no UNO API for lists + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID: + m_ListId = rValue; + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL: + { + sal_Int32 nTmp = rValue.toInt32(); + if ( nTmp >= 1 && nTmp <= SHRT_MAX ) { + m_Level = static_cast<sal_uInt16>(nTmp) - 1; + } + } + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME: + StyleName = rValue; + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING: + // this attribute is deprecated +// ContinuteNumbering = IsXMLToken(rValue, XML_TRUE); + break; + case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE: + { + sal_Int32 nTmp = rValue.toInt32(); + if ( nTmp >= 0 && nTmp <= SHRT_MAX ) { + m_StartValue = static_cast<sal_Int16>(nTmp); + } + } + break; + } + } + + XMLTextListsHelper& rTextListsHelper( + i_rImport.GetTextImport()->GetTextListHelper() ); + if (!m_ListId.getLength()) { + OSL_ENSURE( ! i_rImport.GetODFVersion().equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("1.2") ), + "invalid numbered-paragraph: no list-id (1.2)"); + m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level, + StyleName); + OSL_ENSURE(m_ListId.getLength(), "numbered-paragraph: no ListId"); + if (!m_ListId.getLength()) { + return; + } + } + m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport, + m_ListId, m_Level, StyleName); + + OSL_ENSURE(m_xNumRules.is(), "numbered-paragraph: no NumRules"); + + i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this ); +} + +XMLNumberedParaContext::~XMLNumberedParaContext() +{ +} + +void XMLNumberedParaContext::EndElement() +{ + if (m_ListId.getLength()) { + GetImport().GetTextImport()->PopListContext(); + } +} + +SvXMLImportContext *XMLNumberedParaContext::CreateChildContext( + sal_uInt16 i_nPrefix, const OUString& i_rLocalName, + const Reference< xml::sax::XAttributeList > & i_xAttrList ) +{ + SvXMLImportContext *pContext( 0 ); + + if ( XML_NAMESPACE_TEXT == i_nPrefix ) + { + bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) ); + if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) ) + { + pContext = new XMLParaContext( GetImport(), + i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader ); +// ignore text:number } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) { + } + } + + if (!pContext) { + pContext = SvXMLImportContext::CreateChildContext( + i_nPrefix, i_rLocalName, i_xAttrList ); + } + + return pContext; +} diff --git a/xmloff/source/text/txtparai.hxx b/xmloff/source/text/txtparai.hxx new file mode 100644 index 000000000000..ecd593ca3d4f --- /dev/null +++ b/xmloff/source/text/txtparai.hxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_TEXTPARAI_HXX_ +#define _XMLOFF_TEXTPARAI_HXX_ + + +#include <com/sun/star/uno/Reference.h> +#include <xmloff/xmlictxt.hxx> + +class XMLHints_Impl; +namespace com { namespace sun { namespace star { +namespace text { class XTextRange; } +namespace xml { namespace sax { class XAttributeList; } } +} } } + +#define CONV_FROM_STAR_BATS 1 +#define CONV_FROM_STAR_MATH 2 +#define CONV_STAR_FONT_FLAGS_VALID 4 + +class XMLParaContext : public SvXMLImportContext +{ + ::com::sun::star::uno::Reference < + ::com::sun::star::text::XTextRange > xStart; // xub_StrLen nStart; + ::rtl::OUString sStyleName; + ::rtl::OUString m_sXmlId; + ::rtl::OUString m_sAbout; + ::rtl::OUString m_sProperty; + ::rtl::OUString m_sContent; + ::rtl::OUString m_sDatatype; + bool m_bHaveAbout; + sal_Int8 nOutlineLevel; + XMLHints_Impl *pHints; + // --> OD 2007-07-25 #i73509# + sal_Bool mbOutlineLevelAttrFound; + // <-- + sal_Bool bIgnoreLeadingSpace; + sal_Bool bHeading; + sal_Bool bIsListHeader; + sal_Bool bIsRestart; + sal_Int16 nStartValue; + sal_uInt8 nStarFontsConvFlags; + +public: + + TYPEINFO(); + + XMLParaContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + sal_Bool bHeading ); + + virtual ~XMLParaContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + virtual void Characters( const ::rtl::OUString& rChars ); + +}; + +class XMLNumberedParaContext : public SvXMLImportContext +{ + /// text:list-level MINUS 1 + sal_Int16 m_Level; + /// text:start-value + sal_Int16 m_StartValue; + /// xml:id + ::rtl::OUString m_XmlId; + /// text:list-id + ::rtl::OUString m_ListId; + /// text:style-name + ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace > m_xNumRules; + +public: + + TYPEINFO(); + + XMLNumberedParaContext( SvXMLImport& i_rImport, + sal_uInt16 i_nPrefix, + const ::rtl::OUString& i_rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & i_xAttrList ); + + virtual ~XMLNumberedParaContext(); + + virtual void EndElement(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 i_nPrefix, + const ::rtl::OUString& i_rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & i_xAttrList ); + + sal_Int16 GetLevel() const { return m_Level; } + const ::com::sun::star::uno::Reference < + ::com::sun::star::container::XIndexReplace >& GetNumRules() const + { return m_xNumRules; } + const ::rtl::OUString& GetListId() const { return m_ListId; } + sal_Int16 GetStartValue() const { return m_StartValue; } + +}; + +#endif diff --git a/xmloff/source/text/txtparaimphint.hxx b/xmloff/source/text/txtparaimphint.hxx new file mode 100644 index 000000000000..17c1a155692c --- /dev/null +++ b/xmloff/source/text/txtparaimphint.hxx @@ -0,0 +1,296 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_TXTPARAIMPHINT_HXX +#define _XMLOFF_TXTPARAIMPHINT_HXX + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> +#include <svl/svarray.hxx> +#include <xmloff/xmlimp.hxx> +#include "XMLTextFrameContext.hxx" +#include <xmloff/XMLEventsImportContext.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +// --------------------------------------------------------------------- + +#define XML_HINT_STYLE 1 +#define XML_HINT_REFERENCE 2 +#define XML_HINT_HYPERLINK 3 +#define XML_HINT_INDEX_MARK 5 +#define XML_HINT_TEXT_FRAME 6 +// --> DVO, OD 2004-07-14 #i26791# +#define XML_HINT_DRAW 7 +// <-- + +class XMLHint_Impl +{ + Reference < XTextRange > xStart; + Reference < XTextRange > xEnd; + + sal_uInt8 nType; + +public: + + XMLHint_Impl( sal_uInt8 nTyp, + const Reference < XTextRange > & rS, + const Reference < XTextRange > & rE ) : + xStart( rS ), + xEnd( rE ), + nType( nTyp ) + { + } + + XMLHint_Impl( sal_uInt8 nTyp, + const Reference < XTextRange > & rS ) : + xStart( rS ), + nType( nTyp ) + { + } + + virtual ~XMLHint_Impl() {} + + const Reference < XTextRange > & GetStart() const { return xStart; } + const Reference < XTextRange > & GetEnd() const { return xEnd; } + void SetEnd( const Reference < XTextRange > & rPos ) { xEnd = rPos; } + + // We don't use virtual methods to differ between the sub classes, + // because this seems to be to expensive if compared to inline methods. + sal_uInt8 GetType() const { return nType; } + sal_Bool IsStyle() { return XML_HINT_STYLE==nType; } + sal_Bool IsReference() { return XML_HINT_REFERENCE==nType; } + sal_Bool IsHyperlink() { return XML_HINT_HYPERLINK==nType; } + sal_Bool IsIndexMark() { return XML_HINT_INDEX_MARK==nType; } +}; + +class XMLStyleHint_Impl : public XMLHint_Impl +{ + OUString sStyleName; + +public: + + XMLStyleHint_Impl( const OUString& rStyleName, + const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_STYLE, rPos, rPos ), + sStyleName( rStyleName ) + { + } + virtual ~XMLStyleHint_Impl() {} + + const OUString& GetStyleName() const { return sStyleName; } +}; + +class XMLReferenceHint_Impl : public XMLHint_Impl +{ + OUString sRefName; + +public: + + XMLReferenceHint_Impl( const OUString& rRefName, + const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_REFERENCE, rPos, rPos ), + sRefName( rRefName ) + { + } + + virtual ~XMLReferenceHint_Impl() {} + + const OUString& GetRefName() const { return sRefName; } +}; + +class XMLHyperlinkHint_Impl : public XMLHint_Impl +{ + OUString sHRef; + OUString sName; + OUString sTargetFrameName; + OUString sStyleName; + OUString sVisitedStyleName; + XMLEventsImportContext* pEvents; + +public: + + XMLHyperlinkHint_Impl( const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_HYPERLINK, rPos, rPos ), + pEvents( NULL ) + { + } + + virtual ~XMLHyperlinkHint_Impl() + { + if (NULL != pEvents) + pEvents->ReleaseRef(); + } + + void SetHRef( const OUString& s ) { sHRef = s; } + const OUString& GetHRef() const { return sHRef; } + void SetName( const OUString& s ) { sName = s; } + const OUString& GetName() const { return sName; } + void SetTargetFrameName( const OUString& s ) { sTargetFrameName = s; } + const OUString& GetTargetFrameName() const { return sTargetFrameName; } + void SetStyleName( const OUString& s ) { sStyleName = s; } + const OUString& GetStyleName() const { return sStyleName; } + void SetVisitedStyleName( const OUString& s ) { sVisitedStyleName = s; } + const OUString& GetVisitedStyleName() const { return sVisitedStyleName; } + XMLEventsImportContext* GetEventsContext() const + { + return pEvents; + } + void SetEventsContext( XMLEventsImportContext* pCtxt ) + { + pEvents = pCtxt; + if (pEvents != NULL) + pEvents->AddRef(); + } +}; + + +class XMLIndexMarkHint_Impl : public XMLHint_Impl +{ + const Reference<beans::XPropertySet> xIndexMarkPropSet; + + const OUString sID; + +public: + + XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet, + const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ), + xIndexMarkPropSet( rPropSet ), + sID() + { + } + + XMLIndexMarkHint_Impl( const Reference < beans::XPropertySet > & rPropSet, + const Reference < XTextRange > & rPos, + OUString sIDString) : + XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ), + xIndexMarkPropSet( rPropSet ), + sID(sIDString) + { + } + + virtual ~XMLIndexMarkHint_Impl() {} + + const Reference<beans::XPropertySet> & GetMark() const + { return xIndexMarkPropSet; } + const OUString& GetID() const { return sID; } +}; + + +class XMLTextFrameHint_Impl : public XMLHint_Impl +{ + // OD 2004-04-20 #i26791# + SvXMLImportContextRef xContext; + +public: + + XMLTextFrameHint_Impl( SvXMLImportContext* pContext, + const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_TEXT_FRAME, rPos, rPos ), + xContext( pContext ) + { + } + + virtual ~XMLTextFrameHint_Impl() + { + } + + Reference < XTextContent > GetTextContent() const + { + Reference <XTextContent > xTxt; + SvXMLImportContext *pContext = &xContext; + if( pContext->ISA( XMLTextFrameContext ) ) + xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent(); + else if( pContext->ISA( XMLTextFrameHyperlinkContext ) ) + xTxt = PTR_CAST( XMLTextFrameHyperlinkContext, pContext ) + ->GetTextContent(); + + return xTxt; + } + + // --> OD 2004-08-24 #i33242# + Reference < drawing::XShape > GetShape() const + { + Reference < drawing::XShape > xShape; + SvXMLImportContext *pContext = &xContext; + if( pContext->ISA( XMLTextFrameContext ) ) + xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape(); + else if( pContext->ISA( XMLTextFrameHyperlinkContext ) ) + xShape = PTR_CAST( XMLTextFrameHyperlinkContext, pContext )->GetShape(); + + return xShape; + } + // <-- + + sal_Bool IsBoundAtChar() const + { + sal_Bool bRet = sal_False; + SvXMLImportContext *pContext = &xContext; + if( pContext->ISA( XMLTextFrameContext ) ) + bRet = TextContentAnchorType_AT_CHARACTER == + PTR_CAST( XMLTextFrameContext, pContext ) + ->GetAnchorType(); + else if( pContext->ISA( XMLTextFrameHyperlinkContext ) ) + bRet = TextContentAnchorType_AT_CHARACTER == + PTR_CAST( XMLTextFrameHyperlinkContext, pContext ) + ->GetAnchorType(); + return bRet; + } +}; + +// --> DVO, OD 2004-07-14 #i26791# +class XMLDrawHint_Impl : public XMLHint_Impl +{ + SvXMLImportContextRef xContext; + +public: + + XMLDrawHint_Impl( SvXMLShapeContext* pContext, + const Reference < XTextRange > & rPos ) : + XMLHint_Impl( XML_HINT_DRAW, rPos, rPos ), + xContext( pContext ) + { + } + + virtual ~XMLDrawHint_Impl() + { + } + + // --> OD 2004-08-24 #i33242# + Reference < drawing::XShape > GetShape() const + { + return static_cast<SvXMLShapeContext*>(&xContext)->getShape(); + } + // <-- +}; +// <-- +#endif diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx new file mode 100644 index 000000000000..3a26fe37c794 --- /dev/null +++ b/xmloff/source/text/txtprhdl.cxx @@ -0,0 +1,1492 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/fontenum.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/style/DropCapFormat.hpp> +#include <com/sun/star/text/FontRelief.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/XTextColumns.hpp> +#include <com/sun/star/text/TextColumn.hpp> +#include <com/sun/star/text/RelOrientation.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/RubyAdjust.hpp> +#include <com/sun/star/text/FontEmphasis.hpp> +#include <com/sun/star/text/ParagraphVertAlign.hpp> +#include <xmloff/xmltypes.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include "XMLAnchorTypePropHdl.hxx" +#include <xmloff/XMLConstantsPropertyHandler.hxx> +#include "XMLClipPropertyHandler.hxx" +#ifndef _XMLOFF_XMLTEXTCOLUMNSPPROPERTYHANDLER_HXX +#include "XMLTextColumnsPropertyHandler.hxx" +#endif +#include <xmloff/NamedBoolPropertyHdl.hxx> +#ifndef _XMLOFF_TXTPRHDL_HXX +#include "txtprhdl.hxx" +#endif +// OD 2004-05-05 #i28701# +#include <com/sun/star/text/WrapInfluenceOnPosition.hpp> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +//using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +//using namespace ::com::sun::star::container; +//using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + + +#define CONSTASCII_USTRINGPARAM_CMP(s) s, sizeof(s)-1 + +// --------------------------------------------------------------------------- + +SvXMLEnumMapEntry __READONLY_DATA pXML_HoriPos_Enum[] = +{ + { XML_FROM_LEFT, HoriOrientation::NONE }, + { XML_FROM_INSIDE, HoriOrientation::NONE }, // import only + { XML_LEFT, HoriOrientation::LEFT }, + { XML_INSIDE, HoriOrientation::LEFT }, // import only + { XML_CENTER, HoriOrientation::CENTER }, + { XML_RIGHT, HoriOrientation::RIGHT }, + { XML_OUTSIDE, HoriOrientation::RIGHT }, // import only + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_HoriPosMirrored_Enum[] = +{ + { XML_FROM_INSIDE, HoriOrientation::NONE }, + { XML_INSIDE, HoriOrientation::LEFT }, + { XML_CENTER, HoriOrientation::CENTER }, + { XML_OUTSIDE, HoriOrientation::RIGHT }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_HoriRel_Enum[] = +{ + { XML_PARAGRAPH, RelOrientation::FRAME }, + { XML_PARAGRAPH_CONTENT, RelOrientation::PRINT_AREA }, + { XML_PAGE, RelOrientation::PAGE_FRAME }, + { XML_PAGE_CONTENT, RelOrientation::PAGE_PRINT_AREA }, + { XML_PARAGRAPH_START_MARGIN, RelOrientation::FRAME_LEFT }, + { XML_PARAGRAPH_END_MARGIN, RelOrientation::FRAME_RIGHT }, + { XML_PAGE_START_MARGIN, RelOrientation::PAGE_LEFT }, + { XML_PAGE_END_MARGIN, RelOrientation::PAGE_RIGHT }, + { XML_CHAR, RelOrientation::CHAR }, + { XML_FRAME, RelOrientation::FRAME }, // import only + { XML_FRAME_CONTENT, RelOrientation::PRINT_AREA }, // import only + { XML_FRAME_START_MARGIN, RelOrientation::FRAME_LEFT }, // import only + { XML_FRAME_END_MARGIN, RelOrientation::FRAME_RIGHT }, // import only + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_HoriRelFrame_Enum[] = +{ + { XML_FRAME, RelOrientation::FRAME }, + { XML_FRAME_CONTENT, RelOrientation::PRINT_AREA }, + { XML_PAGE, RelOrientation::PAGE_FRAME }, + { XML_PAGE_CONTENT, RelOrientation::PAGE_PRINT_AREA }, + { XML_FRAME_START_MARGIN, RelOrientation::FRAME_LEFT }, + { XML_FRAME_END_MARGIN, RelOrientation::FRAME_RIGHT }, + { XML_PAGE_START_MARGIN, RelOrientation::PAGE_LEFT }, + { XML_PAGE_END_MARGIN, RelOrientation::PAGE_RIGHT }, + { XML_CHAR, RelOrientation::CHAR }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_HoriMirror_Enum[] = +{ + { XML_FROM_LEFT, sal_False }, + { XML_FROM_INSIDE, sal_True }, + { XML_LEFT, sal_False }, + { XML_INSIDE, sal_True }, + { XML_CENTER, sal_False }, + { XML_RIGHT, sal_False }, + { XML_OUTSIDE, sal_True }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertPos_Enum[] = +{ + { XML_FROM_TOP, VertOrientation::NONE }, + { XML_TOP, VertOrientation::TOP }, + { XML_TOP, VertOrientation::CHAR_TOP }, // export only + { XML_TOP, VertOrientation::LINE_TOP }, // export only + { XML_MIDDLE, VertOrientation::CENTER }, + { XML_MIDDLE, VertOrientation::CHAR_CENTER }, // export only + { XML_MIDDLE, VertOrientation::LINE_CENTER }, // export only + { XML_BOTTOM, VertOrientation::BOTTOM }, + { XML_BOTTOM, VertOrientation::CHAR_BOTTOM }, // export only + { XML_BOTTOM, VertOrientation::LINE_BOTTOM }, // export only + { XML_BELOW, VertOrientation::CHAR_BOTTOM }, // import only + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertPosAtChar_Enum[] = +{ + { XML_FROM_TOP, VertOrientation::NONE }, + { XML_TOP, VertOrientation::TOP }, + { XML_TOP, VertOrientation::CHAR_TOP }, // export only + { XML_TOP, VertOrientation::LINE_TOP }, // export only + { XML_MIDDLE, VertOrientation::CENTER }, + { XML_MIDDLE, VertOrientation::CHAR_CENTER }, // export only + { XML_MIDDLE, VertOrientation::LINE_CENTER }, // export only + { XML_BOTTOM, VertOrientation::BOTTOM }, + { XML_BELOW, VertOrientation::CHAR_BOTTOM }, // export only + { XML_BOTTOM, VertOrientation::LINE_BOTTOM }, // export only + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertRel_Enum[] = +{ + { XML_PARAGRAPH, RelOrientation::FRAME }, + { XML_PARAGRAPH_CONTENT, RelOrientation::PRINT_AREA }, + { XML_CHAR, RelOrientation::CHAR }, + // DVO, OD 17.09.2003 #i18732# - allow vertical alignment at page + { XML_PAGE, RelOrientation::PAGE_FRAME }, + { XML_PAGE_CONTENT, RelOrientation::PAGE_PRINT_AREA }, + { XML_FRAME, RelOrientation::FRAME }, // import only + { XML_FRAME_CONTENT, RelOrientation::PRINT_AREA }, // import only + // OD 13.11.2003 #i22341# - new vertical alignment at top of line + { XML_LINE, RelOrientation::TEXT_LINE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertRelPage_Enum[] = +{ + { XML_PAGE, RelOrientation::FRAME }, + { XML_PAGE_CONTENT, RelOrientation::PRINT_AREA }, + { XML_PAGE, RelOrientation::PAGE_FRAME }, + { XML_PAGE_CONTENT, RelOrientation::PAGE_PRINT_AREA }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertRelFrame_Enum[] = +{ + { XML_FRAME, RelOrientation::FRAME }, + { XML_FRAME_CONTENT, RelOrientation::PRINT_AREA }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VertRelAsChar_Enum[] = +{ + { XML_BASELINE, VertOrientation::TOP }, + { XML_BASELINE, VertOrientation::CENTER }, // export only + { XML_BASELINE, VertOrientation::BOTTOM }, // export only + { XML_TEXT, VertOrientation::CHAR_TOP }, + { XML_TEXT, VertOrientation::CHAR_CENTER }, // export only + { XML_TEXT, VertOrientation::CHAR_BOTTOM }, // export only + { XML_LINE, VertOrientation::LINE_TOP }, + { XML_LINE, VertOrientation::LINE_CENTER }, // export only + { XML_LINE, VertOrientation::LINE_BOTTOM }, // export only + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_RubyAdjust_Enum[] = +{ + { XML_LEFT, RubyAdjust_LEFT }, + { XML_CENTER, RubyAdjust_CENTER }, + { XML_RIGHT, RubyAdjust_RIGHT }, + { XML_DISTRIBUTE_LETTER, RubyAdjust_BLOCK }, + { XML_DISTRIBUTE_SPACE, RubyAdjust_INDENT_BLOCK }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_FontRelief_Enum[] = +{ + { XML_NONE, FontRelief::NONE }, + { XML_ENGRAVED, FontRelief::ENGRAVED }, + { XML_EMBOSSED, FontRelief::EMBOSSED }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry __READONLY_DATA pXML_VerticalAlign_Enum[] = +{ + { XML_TOP, ParagraphVertAlign::TOP }, + { XML_MIDDLE, ParagraphVertAlign::CENTER }, + { XML_BOTTOM, ParagraphVertAlign::BOTTOM }, + { XML_BASELINE, ParagraphVertAlign::BASELINE }, + { XML_AUTO, ParagraphVertAlign::AUTOMATIC }, + { XML_TOKEN_INVALID, 0 } +}; + +// OD 2004-05-05 #i28701# +SvXMLEnumMapEntry __READONLY_DATA pXML_WrapInfluenceOnPosition_Enum[] = +{ + // --> OD 2004-10-18 #i35017# - tokens have been renamed and + // <XML_ITERATIVE> has been added + { XML_ONCE_SUCCESSIVE, WrapInfluenceOnPosition::ONCE_SUCCESSIVE }, + { XML_ONCE_CONCURRENT, WrapInfluenceOnPosition::ONCE_CONCURRENT }, + { XML_ITERATIVE, WrapInfluenceOnPosition::ITERATIVE }, + // <-- + { XML_TOKEN_INVALID, 0 } +}; + +// --------------------------------------------------------------------------- + +class XMLDropCapPropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLDropCapPropHdl_Impl (); + + virtual bool equals( + const ::com::sun::star::uno::Any& r1, + const ::com::sun::star::uno::Any& r2 ) const; + + /// TabStops will be imported/exported as XML-Elements. So the Import/Export-work must be done at another place. + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +XMLDropCapPropHdl_Impl::~XMLDropCapPropHdl_Impl () +{ +} + +bool XMLDropCapPropHdl_Impl::equals( + const Any& r1, + const Any& r2 ) const +{ + DropCapFormat aFormat1, aFormat2; + r1 >>= aFormat1; + r2 >>= aFormat2; + + return (aFormat1.Lines <=1 && aFormat2.Lines <=1) || + (aFormat1.Lines == aFormat2.Lines && + aFormat1.Count == aFormat2.Count && + aFormat1.Distance == aFormat2.Distance); +} + +sal_Bool XMLDropCapPropHdl_Impl::importXML( + const OUString&, + Any&, + const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "drop caps are an element import property" ); + return sal_False; +} + +sal_Bool XMLDropCapPropHdl_Impl::exportXML( + OUString&, + const Any&, + const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "drop caps are an element export property" ); + return sal_False; +} + +// --------------------------------------------------------------------------- + +class XMLOpaquePropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLOpaquePropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLOpaquePropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_Bool bVal = sal_False; + if( IsXMLToken( rStrImpValue, XML_FOREGROUND ) ) + bVal = sal_True; + else if( !IsXMLToken( rStrImpValue, XML_BACKGROUND ) ) + bRet = sal_False; + + if( bRet ) + rValue.setValue( &bVal, ::getBooleanCppuType() ); + + return bRet; +} + +sal_Bool XMLOpaquePropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( *(sal_Bool *)rValue.getValue() ) + rStrExpValue = GetXMLToken( XML_FOREGROUND ); + else + rStrExpValue = GetXMLToken( XML_BACKGROUND ); + + return sal_True; +} + +XMLOpaquePropHdl_Impl::~XMLOpaquePropHdl_Impl () +{ +} + +// --------------------------------------------------------------------------- + +class XMLContourModePropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLContourModePropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLContourModePropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_Bool bVal = sal_False; + if( IsXMLToken( rStrImpValue, XML_OUTSIDE ) ) + bVal = sal_True; + else if( ! IsXMLToken( rStrImpValue, XML_FULL ) ) + bRet = sal_False; + + if( bRet ) + rValue.setValue( &bVal, ::getBooleanCppuType() ); + + return bRet; +} + +sal_Bool XMLContourModePropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( *(sal_Bool *)rValue.getValue() ) + rStrExpValue = GetXMLToken( XML_OUTSIDE ); + else + rStrExpValue = GetXMLToken( XML_FULL ); + + return sal_True; +} + +XMLContourModePropHdl_Impl::~XMLContourModePropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +class XMLParagraphOnlyPropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLParagraphOnlyPropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLParagraphOnlyPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_Bool bVal = sal_False; + + if( ! IsXMLToken( rStrImpValue, XML_NO_LIMIT ) ) + { + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + bVal = 1 == nValue; + } + + if( bRet ) + rValue.setValue( &bVal, ::getBooleanCppuType() ); + + return bRet; +} + +sal_Bool XMLParagraphOnlyPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( *(sal_Bool *)rValue.getValue() ) + rStrExpValue = GetXMLToken( XML_1 ); + else + rStrExpValue = GetXMLToken( XML_NO_LIMIT ); + + return sal_True; +} + +XMLParagraphOnlyPropHdl_Impl::~XMLParagraphOnlyPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +SvXMLEnumMapEntry __READONLY_DATA pXML_Wrap_Enum[] = +{ + { XML_NONE, WrapTextMode_NONE }, + { XML_RUN_THROUGH, WrapTextMode_THROUGHT }, + { XML_PARALLEL, WrapTextMode_PARALLEL }, + { XML_DYNAMIC, WrapTextMode_DYNAMIC }, + { XML_LEFT, WrapTextMode_LEFT }, + { XML_RIGHT, WrapTextMode_RIGHT }, + { XML_TOKEN_INVALID, 0 } +}; + +class XMLWrapPropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLWrapPropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLWrapPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_uInt16 nWrap; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nWrap, rStrImpValue, + pXML_Wrap_Enum ); + + if( bRet ) + rValue <<= (WrapTextMode)nWrap; + + return bRet; +} + +sal_Bool XMLWrapPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + WrapTextMode eVal; + + rValue >>= eVal; + + sal_Bool bRet = SvXMLUnitConverter::convertEnum( aOut, eVal, pXML_Wrap_Enum, XML_NONE ); + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +XMLWrapPropHdl_Impl::~XMLWrapPropHdl_Impl () +{ +} + +// --------------------------------------------------------------------------- + +class XMLFrameProtectPropHdl_Impl : public XMLPropertyHandler +{ + const OUString sVal; +public: + XMLFrameProtectPropHdl_Impl( enum XMLTokenEnum eVal ) : + sVal( GetXMLToken(eVal) ) {} + virtual ~XMLFrameProtectPropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLFrameProtectPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_Bool bVal = sal_False; + if( ! IsXMLToken( rStrImpValue, XML_NONE ) ) + { + bRet = sal_False; + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + OUString aToken; + while( aTokenEnum.getNextToken( aToken ) ) + { + bRet = sal_True; + if( aToken == sVal ) + { + bVal = sal_True; + break; + } + } + } + + if( bRet ) + rValue.setValue( &bVal, ::getBooleanCppuType() ); + + return bRet; +} + +sal_Bool XMLFrameProtectPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( *(sal_Bool *)rValue.getValue() ) + { + if( !rStrExpValue.getLength() || + IsXMLToken( rStrExpValue, XML_NONE ) ) + { + rStrExpValue = sVal; + } + else + { + OUStringBuffer aOut( rStrExpValue.getLength() + 1 + + sVal.getLength() ); + aOut.append( rStrExpValue ); + aOut.append( (sal_Unicode)' ' ); + aOut.append( sVal ); + rStrExpValue = aOut.makeStringAndClear(); + } + } + else if( !rStrExpValue.getLength() ) + { + rStrExpValue = GetXMLToken( XML_NONE ); + } + + return sal_True; +} + +XMLFrameProtectPropHdl_Impl::~XMLFrameProtectPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +SvXMLEnumMapEntry __READONLY_DATA pXML_Anchor_Enum[] = +{ + { XML_CHAR, TextContentAnchorType_AT_CHARACTER }, + { XML_PAGE, TextContentAnchorType_AT_PAGE }, + { XML_FRAME, TextContentAnchorType_AT_FRAME }, + { XML_PARAGRAPH, TextContentAnchorType_AT_PARAGRAPH }, + { XML_AS_CHAR, TextContentAnchorType_AS_CHARACTER }, + { XML_TOKEN_INVALID, 0 } +}; + + +sal_Bool XMLAnchorTypePropHdl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_uInt16 nAnchor; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nAnchor, rStrImpValue, + pXML_Anchor_Enum ); + + if( bRet ) + rValue <<= (TextContentAnchorType)nAnchor; + + return bRet; +} + +sal_Bool XMLAnchorTypePropHdl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + TextContentAnchorType eVal; + + rValue >>= eVal; + + sal_Bool bRet = SvXMLUnitConverter::convertEnum( aOut, eVal, pXML_Anchor_Enum, XML_PARAGRAPH ); + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +XMLAnchorTypePropHdl::~XMLAnchorTypePropHdl() +{ +} + +sal_Bool XMLAnchorTypePropHdl::convert( const OUString& rStrImpValue, + TextContentAnchorType& rType ) +{ + sal_uInt16 nAnchor; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nAnchor, rStrImpValue, + pXML_Anchor_Enum ); + if( bRet ) + rType = (TextContentAnchorType)nAnchor; + return bRet; +} + +// --------------------------------------------------------------------------- + + +XMLTextColumnsPropertyHandler::~XMLTextColumnsPropertyHandler () +{ +} + +bool XMLTextColumnsPropertyHandler::equals( + const Any& r1, + const Any& r2 ) const +{ + Reference < XTextColumns > xColumns1; + r1 >>= xColumns1; + + Reference < XTextColumns > xColumns2; + r2 >>= xColumns2; + + if( xColumns1->getColumnCount() != xColumns2->getColumnCount() || + xColumns1->getReferenceValue() != xColumns2->getReferenceValue() ) + return sal_False; + + Sequence < TextColumn > aColumns1 = xColumns1->getColumns(); + Sequence < TextColumn > aColumns2 = xColumns2->getColumns(); + sal_Int32 nCount = aColumns1.getLength(); + if( aColumns2.getLength() != nCount ) + return sal_False; + + const TextColumn *pColumns1 = aColumns1.getArray(); + const TextColumn *pColumns2 = aColumns2.getArray(); + + while( nCount-- ) + { + if( pColumns1->Width != pColumns2->Width || + pColumns1->LeftMargin != pColumns2->LeftMargin || + pColumns1->RightMargin != pColumns2->RightMargin ) + return sal_False; + + pColumns1++; + pColumns2++; + } + + return sal_True; +} + +sal_Bool XMLTextColumnsPropertyHandler::importXML( + const OUString&, + Any&, + const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "columns are an element import property" ); + return sal_False; +} + +sal_Bool XMLTextColumnsPropertyHandler::exportXML( + OUString&, + const Any&, + const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "columns are an element export property" ); + return sal_False; +} + +// --------------------------------------------------------------------------- + +class XMLHoriMirrorPropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLHoriMirrorPropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLHoriMirrorPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_uInt16 nHoriMirror; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nHoriMirror, rStrImpValue, + pXML_HoriMirror_Enum ); + + if( bRet ) + { + sal_Bool bTmp = nHoriMirror != 0; + rValue.setValue( &bTmp, ::getBooleanCppuType() ); + } + + return bRet; +} + +sal_Bool XMLHoriMirrorPropHdl_Impl::exportXML( + OUString&, + const Any&, + const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "HorMirror properyt shouldn't be exported" ); + + return sal_False; +} + +XMLHoriMirrorPropHdl_Impl::~XMLHoriMirrorPropHdl_Impl () +{ +} + +// --------------------------------------------------------------------------- + +class XMLGrfMirrorPropHdl_Impl : public XMLPropertyHandler +{ + const OUString sVal; + sal_Bool bHori; + +public: + XMLGrfMirrorPropHdl_Impl( enum XMLTokenEnum eVal, sal_Bool bH ) : + sVal( GetXMLToken( eVal ) ), + bHori( bH ) {} + virtual ~XMLGrfMirrorPropHdl_Impl (); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLGrfMirrorPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_Bool bVal = sal_False; + if( ! IsXMLToken( rStrImpValue, XML_NONE ) ) + { + bRet = sal_False; + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + OUString aToken; + while( aTokenEnum.getNextToken( aToken ) ) + { + bRet = sal_True; + if( aToken == sVal || + (bHori && IsXMLToken( aToken, XML_HORIZONTAL ) ) ) + { + bVal = sal_True; + break; + } + } + } + + if( bRet ) + rValue.setValue( &bVal, ::getBooleanCppuType() ); + + return bRet; +} + +sal_Bool XMLGrfMirrorPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( *(sal_Bool *)rValue.getValue() ) + { + if( !rStrExpValue.getLength() || + IsXMLToken( rStrExpValue, XML_NONE ) ) + { + rStrExpValue = sVal; + } + else if( bHori && + // --> OD 2005-05-12 #i49139# + // XML_HORIZONTAL_ON_LEFT_PAGES and XML_HORIZONTAL_ON_RIGHT_PAGES + // are replaced by XML_HORIZONTAL_ON_EVEN and XML_HORIZONTAL_ON_ODD. + ( IsXMLToken( rStrExpValue, XML_HORIZONTAL_ON_EVEN ) || + IsXMLToken( rStrExpValue, XML_HORIZONTAL_ON_ODD ) )) + // <-- + { + rStrExpValue = GetXMLToken( XML_HORIZONTAL ); + } + else + { + OUStringBuffer aOut( rStrExpValue.getLength() + 1 + + sVal.getLength() ); + aOut.append( rStrExpValue ); + aOut.append( (sal_Unicode)' ' ); + aOut.append( sVal ); + rStrExpValue = aOut.makeStringAndClear(); + } + } + else if( !rStrExpValue.getLength() ) + { + rStrExpValue = GetXMLToken( XML_NONE ); + } + + return sal_True; +} + +XMLGrfMirrorPropHdl_Impl::~XMLGrfMirrorPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +SvXMLEnumMapEntry __READONLY_DATA pXML_Emphasize_Enum[] = +{ + { XML_NONE, FontEmphasis::NONE }, + { XML_DOT, FontEmphasis::DOT_ABOVE }, + { XML_CIRCLE, FontEmphasis::CIRCLE_ABOVE }, + { XML_DISC, FontEmphasis::DISK_ABOVE }, + { XML_ACCENT, FontEmphasis::ACCENT_ABOVE }, + { XML_TOKEN_INVALID, 0 } +}; +class XMLTextEmphasizePropHdl_Impl : public XMLPropertyHandler +{ +public: + XMLTextEmphasizePropHdl_Impl() {} + virtual ~XMLTextEmphasizePropHdl_Impl(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLTextEmphasizePropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + sal_uInt16 nVal = FontEmphasis::NONE; + sal_Bool bBelow = sal_False; + sal_Bool bHasPos = sal_False, bHasType = sal_False; + OUString aToken; + + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + while( aTokenEnum.getNextToken( aToken ) ) + { + if( !bHasPos && IsXMLToken( aToken, XML_ABOVE ) ) + { + bBelow = sal_False; + bHasPos = sal_True; + } + else if( !bHasPos && IsXMLToken( aToken, XML_BELOW ) ) + { + bBelow = sal_True; + bHasPos = sal_True; + } + else if( !bHasType && + SvXMLUnitConverter::convertEnum( nVal, aToken, + pXML_Emphasize_Enum )) + { + bHasType = sal_True; + } + else + { + bRet = sal_False; + break; + } + } + + if( bRet ) + { + if( FontEmphasis::NONE != nVal && bBelow ) + nVal += 10; + rValue <<= (sal_Int16)nVal; + } + + return bRet; +} + +sal_Bool XMLTextEmphasizePropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut( 15 ); + sal_Bool bRet = sal_True; + sal_Int16 nType = sal_Int16(); + if( rValue >>= nType ) + { + sal_Bool bBelow = sal_False; + if( nType > 10 ) + { + bBelow = sal_True; + nType -= 10; + } + bRet = SvXMLUnitConverter::convertEnum( aOut, nType, + pXML_Emphasize_Enum, + XML_DOT ); + if( bRet ) + { + if( nType != 0 ) + { + enum XMLTokenEnum ePos = bBelow ? XML_BELOW : XML_ABOVE; + aOut.append( (sal_Unicode)' ' ); + aOut.append( GetXMLToken(ePos) ); + } + rStrExpValue = aOut.makeStringAndClear(); + } + } + + return bRet; +} + +XMLTextEmphasizePropHdl_Impl::~XMLTextEmphasizePropHdl_Impl() +{ +} + + +// --------------------------------------------------------------------------- + +class XMLTextCombineCharPropHdl_Impl : public XMLPropertyHandler +{ +public: + XMLTextCombineCharPropHdl_Impl() {} + virtual ~XMLTextCombineCharPropHdl_Impl(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLTextCombineCharPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( rStrImpValue.getLength() ) + rValue <<= rStrImpValue.copy( 0, 1 ); + else + rValue <<= rStrImpValue; + + return sal_True; +} + +sal_Bool XMLTextCombineCharPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + rValue >>= rStrExpValue; + + return sal_True; +} + +XMLTextCombineCharPropHdl_Impl::~XMLTextCombineCharPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +class XMLTextRelWidthHeightPropHdl_Impl : public XMLPropertyHandler +{ +public: + XMLTextRelWidthHeightPropHdl_Impl() {} + virtual ~XMLTextRelWidthHeightPropHdl_Impl(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLTextRelWidthHeightPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet; + sal_Int32 nValue; + bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ); + if( bRet ) + rValue <<= (sal_Int16)nValue; + + return bRet; +} + +sal_Bool XMLTextRelWidthHeightPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + if( (rValue >>= nValue) && nValue > 0 ) + { + OUStringBuffer aOut; + SvXMLUnitConverter::convertPercent( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +XMLTextRelWidthHeightPropHdl_Impl::~XMLTextRelWidthHeightPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +class XMLTextSyncWidthHeightPropHdl_Impl : public XMLPropertyHandler +{ + const OUString sValue; + +public: + XMLTextSyncWidthHeightPropHdl_Impl( enum XMLTokenEnum eValue ) : + sValue( GetXMLToken(eValue) ) {} + virtual ~XMLTextSyncWidthHeightPropHdl_Impl(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLTextSyncWidthHeightPropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bValue = (rStrImpValue == sValue ); + rValue.setValue( &bValue, ::getBooleanCppuType() ); + + return sal_True; +} + +sal_Bool XMLTextSyncWidthHeightPropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + if( *(sal_Bool *)rValue.getValue() ) + { + rStrExpValue = sValue; + bRet = sal_True; + } + + return bRet; +} + +XMLTextSyncWidthHeightPropHdl_Impl::~XMLTextSyncWidthHeightPropHdl_Impl() +{ +} + +// --------------------------------------------------------------------------- + +class XMLTextRotationAnglePropHdl_Impl : public XMLPropertyHandler +{ + +public: + XMLTextRotationAnglePropHdl_Impl() {} + virtual ~XMLTextRotationAnglePropHdl_Impl(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLTextRotationAnglePropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue; + sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + if( bRet ) + { + nValue = (nValue % 360 ); + if( nValue < 0 ) + nValue = 360 + nValue; + sal_Int16 nAngle; + if( nValue < 45 || nValue > 315 ) + nAngle = 0; + else if( nValue < 180 ) + nAngle = 900; + else /* if nValalue <= 315 ) */ + nAngle = 2700; + rValue <<= nAngle; + } + + return bRet; +} + +sal_Bool XMLTextRotationAnglePropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int16 nAngle = sal_Int16(); + sal_Bool bRet = ( rValue >>= nAngle ); + if( bRet ) + { + OUStringBuffer aOut; + SvXMLUnitConverter::convertNumber( aOut, nAngle / 10 ); + rStrExpValue = aOut.makeStringAndClear(); + } + OSL_ENSURE( bRet, "illegal rotation angle" ); + + return bRet; +} + +XMLTextRotationAnglePropHdl_Impl::~XMLTextRotationAnglePropHdl_Impl() +{ +} +// --------------------------------------------------------------------------- +class XMLNumber8OneBasedHdl : public XMLPropertyHandler +{ + +public: + XMLNumber8OneBasedHdl() {} + virtual ~XMLNumber8OneBasedHdl() {}; + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& ) const; +}; + +sal_Bool XMLNumber8OneBasedHdl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue = 0; + sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + if( bRet ) + rValue <<= static_cast<sal_Int8>( nValue - 1 ); + return bRet; +} + +sal_Bool XMLNumber8OneBasedHdl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int8 nValue = sal_Int8(); + sal_Bool bRet = ( rValue >>= nValue ); + if( bRet ) + { + OUStringBuffer aOut; + SvXMLUnitConverter::convertNumber( aOut, nValue + 1 ); + rStrExpValue = aOut.makeStringAndClear(); + } + return bRet; +} +// --------------------------------------------------------------------------- +class XMLTextPropertyHandlerFactory_Impl +{ +public: + const XMLPropertyHandler *GetPropertyHandler( sal_Int32 nType ) const; + + XMLTextPropertyHandlerFactory_Impl(); + ~XMLTextPropertyHandlerFactory_Impl(); +}; + +const XMLPropertyHandler *XMLTextPropertyHandlerFactory_Impl::GetPropertyHandler + ( sal_Int32 nType ) const +{ + const XMLPropertyHandler* pHdl = 0; + switch( nType ) + { + case XML_TYPE_TEXT_DROPCAP: + pHdl = new XMLDropCapPropHdl_Impl; + break; + case XML_TYPE_TEXT_WRAP: + pHdl = new XMLWrapPropHdl_Impl; + break; + case XML_TYPE_TEXT_PARAGRAPH_ONLY: + pHdl = new XMLParagraphOnlyPropHdl_Impl; + break; + case XML_TYPE_TEXT_WRAP_OUTSIDE: + pHdl = new XMLContourModePropHdl_Impl; + break; + case XML_TYPE_TEXT_OPAQUE: + pHdl = new XMLOpaquePropHdl_Impl; + break; + case XML_TYPE_TEXT_PROTECT_CONTENT: + pHdl = new XMLFrameProtectPropHdl_Impl( XML_CONTENT ); + break; + case XML_TYPE_TEXT_PROTECT_SIZE: + pHdl = new XMLFrameProtectPropHdl_Impl( XML_SIZE ); + break; + case XML_TYPE_TEXT_PROTECT_POSITION: + pHdl = new XMLFrameProtectPropHdl_Impl( XML_POSITION ); + break; + case XML_TYPE_TEXT_ANCHOR_TYPE: + pHdl = new XMLAnchorTypePropHdl; + break; + case XML_TYPE_TEXT_COLUMNS: + pHdl = new XMLTextColumnsPropertyHandler; + break; + case XML_TYPE_TEXT_HORIZONTAL_POS: + pHdl = new XMLConstantsPropertyHandler( pXML_HoriPos_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_HORIZONTAL_POS_MIRRORED: + pHdl = new XMLConstantsPropertyHandler( pXML_HoriPosMirrored_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_HORIZONTAL_REL: + pHdl = new XMLConstantsPropertyHandler( pXML_HoriRel_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_HORIZONTAL_REL_FRAME: + pHdl = new XMLConstantsPropertyHandler( pXML_HoriRelFrame_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_HORIZONTAL_MIRROR: + pHdl = new XMLHoriMirrorPropHdl_Impl; + break; + case XML_TYPE_TEXT_VERTICAL_POS: + pHdl = new XMLConstantsPropertyHandler( pXML_VertPos_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_VERTICAL_POS_AT_CHAR: + pHdl = new XMLConstantsPropertyHandler( pXML_VertPosAtChar_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_VERTICAL_REL: + pHdl = new XMLConstantsPropertyHandler( pXML_VertRel_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_VERTICAL_REL_PAGE: + pHdl = new XMLConstantsPropertyHandler( pXML_VertRelPage_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_VERTICAL_REL_FRAME: + pHdl = new XMLConstantsPropertyHandler( pXML_VertRelFrame_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_VERTICAL_REL_AS_CHAR: + pHdl = new XMLConstantsPropertyHandler( pXML_VertRelAsChar_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_MIRROR_VERTICAL: + pHdl = new XMLGrfMirrorPropHdl_Impl( XML_VERTICAL, sal_False ); + break; + case XML_TYPE_TEXT_MIRROR_HORIZONTAL_LEFT: + // --> OD 2005-05-12 #i49139# + // XML_HORIZONTAL_ON_LEFT_PAGES is replaced by XML_HORIZONTAL_ON_EVEN. + pHdl = new XMLGrfMirrorPropHdl_Impl( XML_HORIZONTAL_ON_EVEN, sal_True ); + // <-- + break; + case XML_TYPE_TEXT_MIRROR_HORIZONTAL_RIGHT: + // --> OD 2005-05-12 #i49139# + // XML_HORIZONTAL_ON_RIGHT_PAGES is replaced by XML_HORIZONTAL_ON_ODD. + pHdl = new XMLGrfMirrorPropHdl_Impl( XML_HORIZONTAL_ON_ODD, sal_True ); + // <-- + break; + case XML_TYPE_TEXT_CLIP: + pHdl = new XMLClipPropertyHandler( sal_False ); + break; + case XML_TYPE_TEXT_CLIP11: + pHdl = new XMLClipPropertyHandler( sal_True ); + break; + case XML_TYPE_TEXT_EMPHASIZE: + pHdl = new XMLTextEmphasizePropHdl_Impl; + break; + case XML_TYPE_TEXT_COMBINE: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_LINES ), + GetXMLToken( XML_NONE ) ); + break; + case XML_TYPE_TEXT_COMBINE_CHARACTERS: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_LETTERS ), + GetXMLToken( XML_NONE ) ); + break; + case XML_TYPE_TEXT_COMBINECHAR: + pHdl = new XMLTextCombineCharPropHdl_Impl; + break; + case XML_TYPE_TEXT_AUTOSPACE: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_IDEOGRAPH_ALPHA ), + GetXMLToken( XML_NONE ) ); + break; + case XML_TYPE_TEXT_PUNCTUATION_WRAP: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_HANGING ), + GetXMLToken( XML_SIMPLE ) ); + break; + case XML_TYPE_TEXT_LINE_BREAK: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_STRICT ), + GetXMLToken( XML_NORMAL ) ); + break; + case XML_TYPE_TEXT_REL_WIDTH_HEIGHT: + pHdl = new XMLTextRelWidthHeightPropHdl_Impl; + break; + case XML_TYPE_TEXT_SYNC_WIDTH_HEIGHT: + pHdl = new XMLTextSyncWidthHeightPropHdl_Impl( XML_SCALE ); + break; + case XML_TYPE_TEXT_SYNC_WIDTH_HEIGHT_MIN: + pHdl = new XMLTextSyncWidthHeightPropHdl_Impl( XML_SCALE_MIN ); + break; + case XML_TYPE_TEXT_RUBY_ADJUST: + pHdl = new XMLConstantsPropertyHandler( pXML_RubyAdjust_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_FONT_RELIEF: + pHdl = new XMLConstantsPropertyHandler( pXML_FontRelief_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_ROTATION_ANGLE: + pHdl = new XMLTextRotationAnglePropHdl_Impl; + break; + case XML_TYPE_TEXT_ROTATION_SCALE: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_FIXED ), + GetXMLToken( XML_LINE_HEIGHT ) ); + break; + case XML_TYPE_TEXT_VERTICAL_ALIGN: + pHdl = new XMLConstantsPropertyHandler( pXML_VerticalAlign_Enum, XML_TOKEN_INVALID ); + break; + case XML_TYPE_TEXT_RUBY_POSITION: + pHdl = new XMLNamedBoolPropertyHdl( ::xmloff::token::XML_ABOVE, + ::xmloff::token::XML_BELOW ); + break; + // OD 2004-05-05 #i28701# + case XML_TYPE_WRAP_INFLUENCE_ON_POSITION: + pHdl = new XMLConstantsPropertyHandler( pXML_WrapInfluenceOnPosition_Enum, + XML_TOKEN_INVALID ); + break; + case XML_TYPE_BORDER_MODEL: + pHdl = new XMLNamedBoolPropertyHdl( xmloff::token::XML_COLLAPSING, + xmloff::token::XML_SEPARATING ); + break; + case XML_TYPE_TEXT_LINE_MODE: + pHdl = new XMLNamedBoolPropertyHdl( + ::xmloff::token::XML_SKIP_WHITE_SPACE, + ::xmloff::token::XML_CONTINUOUS); + break; + case XML_TYPE_TEXT_KEEP: + pHdl = new XMLNamedBoolPropertyHdl( + ::xmloff::token::XML_ALWAYS, + ::xmloff::token::XML_AUTO); + break; + case XML_TYPE_TEXT_NKEEP: + pHdl = new XMLNamedBoolPropertyHdl( + ::xmloff::token::XML_AUTO, + ::xmloff::token::XML_ALWAYS); + break; + case XML_TYPE_TEXT_NUMBER8_ONE_BASED: + pHdl = new XMLNumber8OneBasedHdl(); + break; + } + + return pHdl; +} + +XMLTextPropertyHandlerFactory_Impl::XMLTextPropertyHandlerFactory_Impl() +{ +} + +XMLTextPropertyHandlerFactory_Impl::~XMLTextPropertyHandlerFactory_Impl() +{ +} + +// ---------------------------------------------------------------------------- + +XMLTextPropertyHandlerFactory::XMLTextPropertyHandlerFactory() : + XMLPropertyHandlerFactory(), + pImpl( new XMLTextPropertyHandlerFactory_Impl ) +{ +} + +XMLTextPropertyHandlerFactory::~XMLTextPropertyHandlerFactory() +{ + delete pImpl; +} + +const XMLPropertyHandler *XMLTextPropertyHandlerFactory::GetPropertyHandler( + sal_Int32 nType ) const +{ + const XMLPropertyHandler *pHdl = + XMLPropertyHandlerFactory::GetPropertyHandler( nType ); + + if( !pHdl ) + { + const XMLPropertyHandler *pNewHdl = pImpl->GetPropertyHandler( nType ); + + if( pNewHdl ) + PutHdlCache( nType, pNewHdl ); + + pHdl = pNewHdl; + } + + return pHdl; +} + + diff --git a/xmloff/source/text/txtprhdl.hxx b/xmloff/source/text/txtprhdl.hxx new file mode 100644 index 000000000000..b643b76757d6 --- /dev/null +++ b/xmloff/source/text/txtprhdl.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _XMLOFF_TEXTPRHDL_HXX_ +#define _XMLOFF_TEXTPRHDL_HXX_ + + +#include <xmloff/prhdlfac.hxx> + +class XMLTextPropertyHandlerFactory_Impl; + +class XMLTextPropertyHandlerFactory : public XMLPropertyHandlerFactory +{ + XMLTextPropertyHandlerFactory_Impl *pImpl; + +public: + + XMLTextPropertyHandlerFactory(); + virtual ~XMLTextPropertyHandlerFactory(); + + virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const ; +}; + + +#endif diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx new file mode 100644 index 000000000000..fbc53ef3e16e --- /dev/null +++ b/xmloff/source/text/txtprmap.cxx @@ -0,0 +1,903 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#ifndef _XMLOFF_TXTPRHDL_HXX +#include "txtprhdl.hxx" +#endif +#ifndef _XMLOFF_TXTPRMAP_HXX +#include <xmloff/txtprmap.hxx> +#endif + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +#define _M_E( a, p, l, t, c ) \ + { a, sizeof(a)-1, XML_NAMESPACE_##p, XML_##l, t, c, SvtSaveOptions::ODFVER_010 } + +#define _M_EV( a, p, l, t, c, v ) \ + { a, sizeof(a)-1, XML_NAMESPACE_##p, XML_##l, t, c, v } + +#define _M_ED( a, p, l, t, c ) \ + { a, sizeof(a)-1, XML_NAMESPACE_##p, XML_##l, (t) | MID_FLAG_DEFAULT_ITEM_EXPORT, c, SvtSaveOptions::ODFVER_010 } + +// text properties +#define MT_E( a, p, l, t, c ) \ + _M_E( a, p, l, (t|XML_TYPE_PROP_TEXT), c ) +#define MT_ED( a, p, l, t, c ) \ + _M_ED( a, p, l, (t|XML_TYPE_PROP_TEXT), c ) + +// paragraph properties +#define MP_E( a, p, l, t, c ) \ + _M_E( a, p, l, (t|XML_TYPE_PROP_PARAGRAPH), c ) +#define MP_ED( a, p, l, t, c ) \ + _M_ED( a, p, l, (t|XML_TYPE_PROP_PARAGRAPH), c ) + +// graphic properties +#define MG_E( a, p, l, t, c ) \ + _M_E( a, p, l, (t|XML_TYPE_PROP_GRAPHIC), c ) +#define MG_ED( a, p, l, t, c ) \ + _M_ED( a, p, l, (t|XML_TYPE_PROP_GRAPHIC), c ) +#define MG_EV( a, p, l, t, c, v ) \ + _M_EV( a, p, l, (t|XML_TYPE_PROP_GRAPHIC), c, v ) + +// section properties +#define MS_E( a, p, l, t, c ) \ + _M_E( a, p, l, (t|XML_TYPE_PROP_SECTION), c ) +#define MS_ED( a, p, l, t, c ) \ + _M_ED( a, p, l, (t|XML_TYPE_PROP_SECTION), c ) + +// ruby properties +#define MR_E( a, p, l, t, c ) \ + _M_E( a, p, l, (t|XML_TYPE_PROP_RUBY), c ) +#define MR_ED( a, p, l, t, c ) \ + _M_ED( a, p, l, (t|XML_TYPE_PROP_RUBY), c ) + +#define M_END() \ + { NULL, 0, 0, XML_TOKEN_INVALID, 0, 0, SvtSaveOptions::ODFVER_010 } + + +XMLPropertyMapEntry aXMLParaPropMap[] = +{ + // RES_UNKNOWNATR_CONTAINER + MP_E( "ParaUserDefinedAttributes", TEXT, XMLNS, XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ), + // RES_LR_SPACE + MP_E( "ParaLeftMargin", FO, MARGIN_LEFT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_PARALEFTMARGIN ), + MP_E( "ParaLeftMarginRelative", FO, MARGIN_LEFT, XML_TYPE_PERCENT16, CTF_PARALEFTMARGIN_REL ), + MP_E( "ParaRightMargin", FO, MARGIN_RIGHT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_PARARIGHTMARGIN ), + MP_E( "ParaRightMarginRelative", FO, MARGIN_RIGHT, XML_TYPE_PERCENT16, CTF_PARARIGHTMARGIN_REL ), + // RES_UL_SPACE + MP_E( "ParaTopMargin", FO, MARGIN_TOP, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_PARATOPMARGIN ), + MP_E( "ParaTopMarginRelative", FO, MARGIN_TOP, XML_TYPE_PERCENT16, CTF_PARATOPMARGIN_REL ), + MP_E( "ParaBottomMargin", FO, MARGIN_BOTTOM, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_PARABOTTOMMARGIN ), + MP_E( "ParaBottomMarginRelative",FO, MARGIN_BOTTOM, XML_TYPE_PERCENT16, CTF_PARABOTTOMMARGIN_REL ), + // RES_CHRATR_CASEMAP + MT_E( "CharCaseMap", FO, FONT_VARIANT, XML_TYPE_TEXT_CASEMAP_VAR, 0 ), + MT_E( "CharCaseMap", FO, TEXT_TRANSFORM, XML_TYPE_TEXT_CASEMAP, 0 ), + // RES_CHRATR_COLOR + MT_ED( "CharColor", FO, COLOR, XML_TYPE_COLORAUTO|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CONTOUR + MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_CROSSEDOUT + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_STYLE, XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_TYPE, XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_WIDTH, XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_TEXT, XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY, 0), + // RES_CHRATR_ESCAPEMENT + MT_E( "CharEscapement", STYLE, TEXT_POSITION, XML_TYPE_TEXT_ESCAPEMENT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharEscapementHeight", STYLE, TEXT_POSITION, XML_TYPE_TEXT_ESCAPEMENT_HEIGHT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + // RES_CHRATR_FONT + MT_ED( "CharFontName", STYLE, FONT_NAME, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME ), + MT_ED( "CharFontName", FO, FONT_FAMILY, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME ), + MT_ED( "CharFontStyleName",STYLE, FONT_STYLE_NAME, XML_TYPE_STRING, CTF_FONTSTYLENAME ), + MT_ED( "CharFontFamily", STYLE, FONT_FAMILY_GENERIC,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY ), + MT_ED( "CharFontPitch", STYLE, FONT_PITCH, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH ), + MT_ED( "CharFontCharSet", STYLE, FONT_CHARSET, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET ), + // RES_CHRATR_FONTSIZE + MT_ED( "CharHeight", FO, FONT_SIZE, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT ), + MT_ED( "CharPropHeight",FO, FONT_SIZE, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL ), + MT_ED( "CharDiffHeight",STYLE,FONT_SIZE_REL, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF ), + // RES_CHRATR_KERNING + MT_E( "CharKerning", FO, LETTER_SPACING, XML_TYPE_TEXT_KERNING, 0 ), + // RES_CHRATR_LANGUAGE + MT_ED( "CharLocale", FO, LANGUAGE, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocale", FO, COUNTRY, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_POSTURE + MT_E( "CharPosture", FO, FONT_STYLE, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_PROPORTIONALFONTSIZE + // TODO: not used? + // RES_CHRATR_SHADOWED + MT_E( "CharShadowed", FO, TEXT_SHADOW, XML_TYPE_TEXT_SHADOWED, 0 ), + // RES_CHRATR_UNDERLINE + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_STYLE, XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, CTF_UNDERLINE ), + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_TYPE, XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_WIDTH, XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharUnderlineColor", STYLE, TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, CTF_UNDERLINE_COLOR ), + MT_E( "CharUnderlineHasColor", STYLE, TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, CTF_UNDERLINE_HASCOLOR ), + // RES_CHRATR_WEIGHT + MT_E( "CharWeight", FO, FONT_WEIGHT, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_WORDLINEMODE + MT_E( "CharWordMode", STYLE, TEXT_UNDERLINE_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharWordMode", STYLE, TEXT_OVERLINE_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharWordMode", STYLE, TEXT_LINE_THROUGH_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_AUTOKERN + MT_E( "CharAutoKerning", STYLE, LETTER_KERNING, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_BLINK + MT_E( "CharFlash", STYLE, TEXT_BLINKING, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_NOHYPHEN + // TODO: not used? + // RES_CHRATR_NOLINEBREAK + // TODO: not used? + // RES_CHRATR_BACKGROUND + MT_E( "CharBackColor", FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharBackTransparent", FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MT_E( "CharBackColor", FO, TEXT_BACKGROUND_COLOR, XML_TYPE_COLOR|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_OLDTEXTBACKGROUND ), + // RES_CHRATR_CJK_FONT + MT_ED( "CharFontNameAsian", STYLE, FONT_NAME_ASIAN, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME_CJK ), + MT_ED( "CharFontNameAsian", STYLE, FONT_FAMILY_ASIAN, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME_CJK ), + MT_ED( "CharFontStyleNameAsian",STYLE, FONT_STYLE_NAME_ASIAN, XML_TYPE_STRING, CTF_FONTSTYLENAME_CJK ), + MT_ED( "CharFontFamilyAsian", STYLE, FONT_FAMILY_GENERIC_ASIAN,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY_CJK ), + MT_ED( "CharFontPitchAsian", STYLE, FONT_PITCH_ASIAN, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH_CJK ), + MT_ED( "CharFontCharSetAsian", STYLE, FONT_CHARSET_ASIAN, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET_CJK ), + // RES_CHRATR_CJK_FONTSIZE + MT_ED( "CharHeightAsian", STYLE, FONT_SIZE_ASIAN, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_CJK ), + MT_ED( "CharPropHeightAsian",STYLE, FONT_SIZE_ASIAN, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL_CJK ), + MT_ED( "CharDiffHeightAsian",STYLE,FONT_SIZE_REL_ASIAN, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF_CJK ), + // RES_CHRATR_CJK_LANGUAGE + MT_ED( "CharLocaleAsian", STYLE, LANGUAGE_ASIAN, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocaleAsian", STYLE, COUNTRY_ASIAN, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CJK_POSTURE + MT_E( "CharPostureAsian", STYLE, FONT_STYLE_ASIAN, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_CJK_WEIGHT + MT_E( "CharWeightAsian", STYLE, FONT_WEIGHT_ASIAN, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_CTL_FONT + MT_ED( "CharFontNameComplex", STYLE, FONT_NAME_COMPLEX, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME_CTL ), + MT_ED( "CharFontNameComplex", STYLE, FONT_FAMILY_COMPLEX, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME_CTL ), + MT_ED( "CharFontStyleNameComplex",STYLE, FONT_STYLE_NAME_COMPLEX, XML_TYPE_STRING, CTF_FONTSTYLENAME_CTL ), + MT_ED( "CharFontFamilyComplex", STYLE, FONT_FAMILY_GENERIC_COMPLEX,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY_CTL ), + MT_ED( "CharFontPitchComplex", STYLE, FONT_PITCH_COMPLEX, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH_CTL ), + MT_ED( "CharFontCharSetComplex", STYLE, FONT_CHARSET_COMPLEX, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET_CTL ), + // RES_CHRATR_CTL_FONTSIZE + MT_ED( "CharHeightComplex", STYLE, FONT_SIZE_COMPLEX, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_CTL ), + MT_ED( "CharPropHeightComplex",STYLE, FONT_SIZE_COMPLEX, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL_CTL ), + MT_ED( "CharDiffHeightComplex",STYLE,FONT_SIZE_REL_COMPLEX, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF_CTL ), + // RES_CHRATR_CTL_LANGUAGE + MT_ED( "CharLocaleComplex", STYLE, LANGUAGE_COMPLEX, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocaleComplex", STYLE, COUNTRY_COMPLEX, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CTL_POSTURE + MT_E( "CharPostureComplex", STYLE, FONT_STYLE_COMPLEX, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_CTL_WEIGHT + MT_E( "CharWeightComplex", STYLE, FONT_WEIGHT_COMPLEX, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_ROTATE + MT_E( "CharRotation", STYLE, TEXT_ROTATION_ANGLE, XML_TYPE_TEXT_ROTATION_ANGLE, 0 ), + MT_E( "CharRotationIsFitToLine", STYLE, TEXT_ROTATION_SCALE, XML_TYPE_TEXT_ROTATION_SCALE, 0 ), + // RES_CHRATR_EMPHASIS_MARK + MT_E( "CharEmphasis", STYLE, TEXT_EMPHASIZE, XML_TYPE_TEXT_EMPHASIZE, 0 ), + // RES_CHRATR_TWO_LINES + MT_E( "CharCombineIsOn", STYLE, TEXT_COMBINE, XML_TYPE_TEXT_COMBINE, 0 ), + MT_E( "CharCombinePrefix", STYLE, TEXT_COMBINE_START_CHAR, XML_TYPE_TEXT_COMBINECHAR, 0 ), + MT_E( "CharCombineSuffix", STYLE, TEXT_COMBINE_END_CHAR, XML_TYPE_TEXT_COMBINECHAR, 0 ), + // RES_CHRATR_SCALEW + MT_E( "CharScaleWidth", STYLE, TEXT_SCALE, XML_TYPE_PERCENT16, 0 ), + //RES_CHRATR_RELIEF + MT_E( "CharRelief", STYLE, FONT_RELIEF, XML_TYPE_TEXT_FONT_RELIEF, 0 ), + // RES_CHRATR_HIDDEN + MT_E( "CharHidden", TEXT, DISPLAY, XML_TYPE_TEXT_HIDDEN_AS_DISPLAY|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_TEXT_DISPLAY ), + // RES_CHRATR_OVERLINE + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_STYLE, XML_TYPE_TEXT_OVERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_TYPE, XML_TYPE_TEXT_OVERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_WIDTH, XML_TYPE_TEXT_OVERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverlineColor", STYLE, TEXT_OVERLINE_COLOR, XML_TYPE_TEXT_OVERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharOverlineHasColor", STYLE, TEXT_OVERLINE_COLOR, XML_TYPE_TEXT_OVERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + + // RES_TXTATR_INETFMT + // TODO + // RES_TXTATR_REFMARK + // TODO + // RES_TXTATR_TOXMARK + // TODO + // RES_TXTATR_CHARFMT +// M_E_SI( TEXT, style_name, RES_TXTATR_CHARFMT, 0 ), + // RES_TXTATR_CJK_RUBY + // TODO + // RES_TXTATR_FIELD + // TODO + // RES_TXTATR_FLYCNT + // TODO + // RES_TXTATR_FTN + // TODO + // RES_TXTATR_SOFTHYPH + // TODO + // RES_TXTATR_HARDBLANK + // TODO + + // RES_PARATR_LINESPACING + MP_E( "ParaLineSpacing", FO, LINE_HEIGHT, XML_TYPE_LINE_SPACE_FIXED, 0 ), + MP_E( "ParaLineSpacing", STYLE, LINE_HEIGHT_AT_LEAST, XML_TYPE_LINE_SPACE_MINIMUM, 0 ), + MP_E( "ParaLineSpacing", STYLE, LINE_SPACING, XML_TYPE_LINE_SPACE_DISTANCE, 0 ), + // RES_PARATR_ADJUST + MP_E( "ParaAdjust", FO, TEXT_ALIGN, XML_TYPE_TEXT_ADJUST, CTF_SD_SHAPE_PARA_ADJUST ), + MP_E( "ParaLastLineAdjust", FO, TEXT_ALIGN_LAST, XML_TYPE_TEXT_ADJUSTLAST, CTF_PARA_ADJUSTLAST ), + MP_E( "ParaExpandSingleWord",STYLE, JUSTIFY_SINGLE_WORD,XML_TYPE_BOOL, 0 ), + // RES_PARATR_SPLIT + MP_E( "ParaSplit", FO, KEEP_TOGETHER, XML_TYPE_TEXT_SPLIT, 0 ), + // RES_PARATR_ORPHANS + MP_E( "ParaOrphans", FO, ORPHANS, XML_TYPE_NUMBER8, 0 ), + // RES_PARATR_WIDOWS + MP_E( "ParaWidows", FO, WIDOWS, XML_TYPE_NUMBER8, 0 ), + // RES_PARATR_TABSTOP + MP_ED( "ParaTabStops", STYLE, TAB_STOPS, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_TABSTOP, CTF_TABSTOP ), // this is not realy a string! + // RES_PARATR_HYPHENZONE + MT_E( "ParaIsHyphenation", FO, HYPHENATE, XML_TYPE_BOOL, 0 ), + MT_E( "ParaHyphenationMaxLeadingChars", FO, HYPHENATION_REMAIN_CHAR_COUNT, XML_TYPE_NUMBER16, 0 ), + MT_E( "ParaHyphenationMaxTrailingChars",FO, HYPHENATION_PUSH_CHAR_COUNT, XML_TYPE_NUMBER16, 0 ), + MP_E( "ParaHyphenationMaxHyphens", FO, HYPHENATION_LADDER_COUNT, XML_TYPE_NUMBER16_NONE, 0 ), + // RES_PARATR_DROP + MP_E( "DropCapWholeWord", STYLE, LENGTH, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BOOL, CTF_DROPCAPWHOLEWORD ), + MP_E( "DropCapCharStyleName", STYLE, STYLE_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_DROPCAPCHARSTYLE ), + MP_E( "DropCapFormat", STYLE, DROP_CAP, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_DROPCAP, CTF_DROPCAPFORMAT ), + // RES_PARATR_REGISTER + MP_E( "ParaRegisterModeActive", STYLE, REGISTER_TRUE, XML_TYPE_BOOL, 0 ), + // RES_PARATR_NUMRULE + MP_E( "NumberingStyleName", STYLE, LIST_STYLE_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STYLENAME, CTF_NUMBERINGSTYLENAME ), + MP_E( "NumberingRules", TEXT, ENABLE_NUMBERING, MID_FLAG_NO_PROPERTY|XML_TYPE_BOOL, CTF_ALIEN_ATTRIBUTE_IMPORT ), + + // RES_FILL_ORDER + // not required + // RES_FRM_SIZE + // not required + // RES_PAPER_BIN + // not required + // RES_LR_SPACE + + MP_E( "ParaFirstLineIndent", FO, TEXT_INDENT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_PARAFIRSTLINE ), + MP_E( "ParaFirstLineIndentRelative", FO, TEXT_INDENT, XML_TYPE_PERCENT, CTF_PARAFIRSTLINE_REL ), + MP_E( "ParaIsAutoFirstLineIndent", STYLE, AUTO_TEXT_INDENT, XML_TYPE_BOOL, 0 ), + // RES_PAGEDESC + MP_E( "PageDescName", STYLE, MASTER_PAGE_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STYLENAME, CTF_PAGEDESCNAME ), + MP_E( "PageNumberOffset", STYLE, PAGE_NUMBER, XML_TYPE_NUMBER16_AUTO, 0 ), + // RES_BREAK : TODO: does this work? + MP_E( "BreakType", FO, BREAK_BEFORE, XML_TYPE_TEXT_BREAKBEFORE|MID_FLAG_MULTI_PROPERTY, 0 ), + MP_E( "BreakType", FO, BREAK_AFTER, XML_TYPE_TEXT_BREAKAFTER, 0 ), + // RES_CNTNT + // not required + // RES_HEADER + // not required + // RES_FOOTER + // not required + // RES_PRINT + // not required + // RES_OPAQUE + // not required + // RES_PROTECT + // not required + // RES_SURROUND + // not required + // RES_VERT_ORIENT + // not required + // RES_HORI_ORIENT + // not required + // RES_ANCHOR + // not required + // RES_BACKGROUND + MP_E( "ParaBackColor", FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MP_E( "ParaBackTransparent", FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MP_E( "ParaBackGraphicLocation", STYLE, POSITION, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BUILDIN_CMP_ONLY, CTF_BACKGROUND_POS ), + MP_E( "ParaBackGraphicFilter",STYLE, FILTER_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_FILTER ), + MP_E( "ParaBackGraphicURL", STYLE, BACKGROUND_IMAGE, MID_FLAG_ELEMENT_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_URL ), + // RES_BOX + MP_E( "LeftBorder", STYLE, BORDER_LINE_WIDTH, XML_TYPE_BORDER_WIDTH, CTF_ALLBORDERWIDTH ), + MP_E( "LeftBorder", STYLE, BORDER_LINE_WIDTH_LEFT, XML_TYPE_BORDER_WIDTH, CTF_LEFTBORDERWIDTH ), + MP_E( "RightBorder", STYLE, BORDER_LINE_WIDTH_RIGHT, XML_TYPE_BORDER_WIDTH, CTF_RIGHTBORDERWIDTH ), + MP_E( "TopBorder", STYLE, BORDER_LINE_WIDTH_TOP, XML_TYPE_BORDER_WIDTH, CTF_TOPBORDERWIDTH ), + MP_E( "BottomBorder", STYLE, BORDER_LINE_WIDTH_BOTTOM, XML_TYPE_BORDER_WIDTH, CTF_BOTTOMBORDERWIDTH ), + + MP_E( "LeftBorderDistance", FO, PADDING, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_ALLBORDERDISTANCE ), // need special import filtering + MP_E( "LeftBorderDistance", FO, PADDING_LEFT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_LEFTBORDERDISTANCE ), + MP_E( "RightBorderDistance", FO, PADDING_RIGHT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_RIGHTBORDERDISTANCE ), + MP_E( "TopBorderDistance", FO, PADDING_TOP, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_TOPBORDERDISTANCE ), + MP_E( "BottomBorderDistance",FO, PADDING_BOTTOM, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_BOTTOMBORDERDISTANCE ), + + MP_E( "LeftBorder", FO, BORDER, XML_TYPE_BORDER, CTF_ALLBORDER ), + MP_E( "LeftBorder", FO, BORDER_LEFT, XML_TYPE_BORDER, CTF_LEFTBORDER ), + MP_E( "RightBorder", FO, BORDER_RIGHT, XML_TYPE_BORDER, CTF_RIGHTBORDER ), + MP_E( "TopBorder", FO, BORDER_TOP, XML_TYPE_BORDER, CTF_TOPBORDER ), + MP_E( "BottomBorder", FO, BORDER_BOTTOM, XML_TYPE_BORDER, CTF_BOTTOMBORDER ), + // RES_SHADOW + MP_E( "ParaShadowFormat", STYLE, SHADOW, XML_TYPE_TEXT_SHADOW, 0 ), + // RES_FRMMACRO + // not required + // RES_COL + // not required + // RES_KEEP + MP_E( "ParaKeepTogether", FO, KEEP_WITH_NEXT, XML_TYPE_TEXT_KEEP, 0 ), + // RES_URL + // not required + // RES_EDIT_IN_READONLY + // not required + // RES_LAYOUT_SPLIT + // not required + // RES_CHAIN + // not required + + // RES_LINENUMBER + MP_E( "ParaLineNumberCount", TEXT, NUMBER_LINES, XML_TYPE_BOOL, 0 ), + MP_E( "ParaLineNumberStartValue", TEXT, LINE_NUMBER, XML_TYPE_NUMBER, 0 ), + + // RES_FTN_AT_TXTEND + // not required + // RES_END_AT_TXTEND + // not required + MP_ED( "ParaIsCharacterDistance", STYLE, TEXT_AUTOSPACE, XML_TYPE_TEXT_AUTOSPACE, 0 ), + MP_ED( "ParaIsHangingPunctuation", STYLE, PUNCTUATION_WRAP, XML_TYPE_TEXT_PUNCTUATION_WRAP, 0 ), + MP_ED( "ParaIsForbiddenRules", STYLE, LINE_BREAK, XML_TYPE_TEXT_LINE_BREAK, 0 ), + MP_E( "TabStopDistance", STYLE, TAB_STOP_DISTANCE, XML_TYPE_MEASURE, 0 ), + + // RES_PARATR_VERTALIGN + MP_E( "ParaVertAlignment", STYLE, VERTICAL_ALIGN, XML_TYPE_TEXT_VERTICAL_ALIGN, 0 ), + + // RES_PARATR_SNAPTOGRID + MP_E( "SnapToGrid", STYLE, SNAP_TO_LAYOUT_GRID, XML_TYPE_BOOL, 0 ), + + MP_ED( "WritingMode", STYLE, WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT, CTF_TEXTWRITINGMODE ), + + MP_E( "ParaIsConnectBorder", STYLE, JOIN_BORDER, XML_TYPE_BOOL, 0 ), + + MP_E( "DefaultOutlineLevel", STYLE, DEFAULT_OUTLINE_LEVEL, XML_TYPE_TEXT_NUMBER8_ONE_BASED|MID_FLAG_SPECIAL_ITEM_EXPORT|MID_FLAG_NO_PROPERTY_IMPORT, CTF_DEFAULT_OUTLINE_LEVEL ), + + MP_ED( "FontIndependentLineSpacing", STYLE, FONT_INDEPENDENT_LINE_SPACING, XML_TYPE_BOOL, 0 ), + + M_END() +}; + + +XMLPropertyMapEntry aXMLAdditionalTextDefaultsMap[] = +{ + // RES_FOLLOW_TEXT_FLOW - DVO, OD 01.10.2003 #i18732# + MG_ED( "IsFollowingTextFlow", STYLE, FLOW_WITH_TEXT, XML_TYPE_BOOL, 0 ), + + // OD 2004-05-05 #i28701# - RES_WRAP_INFLUENCE_ON_OBJPOS + MG_ED( "WrapInfluenceOnPosition", DRAW, WRAP_INFLUENCE_ON_POSITION, XML_TYPE_WRAP_INFLUENCE_ON_POSITION, 0 ), + + M_END() +}; + +XMLPropertyMapEntry aXMLTextPropMap[] = +{ + // RES_CHRATR_CASEMAP + MT_E( "CharCaseMap", FO, FONT_VARIANT, XML_TYPE_TEXT_CASEMAP_VAR, 0 ), + MT_E( "CharCaseMap", FO, TEXT_TRANSFORM, XML_TYPE_TEXT_CASEMAP, 0 ), + // RES_CHRATR_COLOR + MT_ED( "CharColor", FO, COLOR, XML_TYPE_COLORAUTO|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CONTOUR + MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_CROSSEDOUT + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_STYLE, XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_TYPE, XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_WIDTH, XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY, 0), + MT_E( "CharStrikeout", STYLE, TEXT_LINE_THROUGH_TEXT, XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY, 0), + // RES_CHRATR_ESCAPEMENT + MT_E( "CharEscapement", STYLE, TEXT_POSITION, XML_TYPE_TEXT_ESCAPEMENT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharEscapementHeight", STYLE, TEXT_POSITION, XML_TYPE_TEXT_ESCAPEMENT_HEIGHT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + // RES_CHRATR_FONT + MT_ED( "CharFontName", STYLE, FONT_NAME, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME ), + MT_ED( "CharFontName", FO, FONT_FAMILY, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME ), + MT_ED( "CharFontStyleName",STYLE, FONT_STYLE_NAME, XML_TYPE_STRING, CTF_FONTSTYLENAME ), + MT_ED( "CharFontFamily", STYLE, FONT_FAMILY_GENERIC,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY ), + MT_ED( "CharFontPitch", STYLE, FONT_PITCH, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH ), + MT_ED( "CharFontCharSet", STYLE, FONT_CHARSET, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET ), + // RES_CHRATR_FONTSIZE + MT_ED( "CharHeight", FO, FONT_SIZE, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT ), + MT_ED( "CharPropHeight",FO, FONT_SIZE, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL ), + MT_ED( "CharDiffHeight",STYLE,FONT_SIZE_REL, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF ), + // RES_CHRATR_KERNING + MT_E( "CharKerning", FO, LETTER_SPACING, XML_TYPE_TEXT_KERNING, 0 ), + // RES_CHRATR_LANGUAGE + MT_ED( "CharLocale", FO, LANGUAGE, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocale", FO, COUNTRY, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_POSTURE + MT_E( "CharPosture", FO, FONT_STYLE, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_PROPORTIONALFONTSIZE + // TODO: not used? + // RES_CHRATR_SHADOWED + MT_E( "CharShadowed", FO, TEXT_SHADOW, XML_TYPE_TEXT_SHADOWED, 0 ), + // BIS HIER GEPRUEFT! + // RES_CHRATR_UNDERLINE + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_STYLE, XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, CTF_UNDERLINE ), + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_TYPE, XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharUnderline", STYLE, TEXT_UNDERLINE_WIDTH, XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharUnderlineColor", STYLE, TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, CTF_UNDERLINE_COLOR ), + MT_E( "CharUnderlineHasColor", STYLE, TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, CTF_UNDERLINE_HASCOLOR ), + // RES_CHRATR_WEIGHT + MT_E( "CharWeight", FO, FONT_WEIGHT, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_WORDLINEMODE + MT_E( "CharWordMode", STYLE, TEXT_UNDERLINE_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharWordMode", STYLE, TEXT_OVERLINE_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharWordMode", STYLE, TEXT_LINE_THROUGH_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_AUTOKERN + MT_E( "CharAutoKerning", STYLE, LETTER_KERNING, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_BLINK + MT_E( "CharFlash", STYLE, TEXT_BLINKING, XML_TYPE_BOOL, 0 ), + // RES_CHRATR_NOHYPHEN + // TODO: not used? + // RES_CHRATR_NOLINEBREAK + // TODO: not used? + // RES_CHRATR_BACKGROUND + MT_E( "CharBackColor", FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharBackTransparent", FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MT_E( "CharBackColor", FO, TEXT_BACKGROUND_COLOR, XML_TYPE_COLOR|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_OLDTEXTBACKGROUND ), + // RES_CHRATR_CJK_FONT + MT_ED( "CharFontNameAsian", STYLE, FONT_NAME_ASIAN, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME_CJK ), + MT_ED( "CharFontNameAsian", STYLE, FONT_FAMILY_ASIAN, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME_CJK ), + MT_ED( "CharFontStyleNameAsian",STYLE, FONT_STYLE_NAME_ASIAN, XML_TYPE_STRING, CTF_FONTSTYLENAME_CJK ), + MT_ED( "CharFontFamilyAsian", STYLE, FONT_FAMILY_GENERIC_ASIAN,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY_CJK ), + MT_ED( "CharFontPitchAsian", STYLE, FONT_PITCH_ASIAN, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH_CJK ), + MT_ED( "CharFontCharSetAsian", STYLE, FONT_CHARSET_ASIAN, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET_CJK ), + // RES_CHRATR_CJK_FONTSIZE + MT_ED( "CharHeightAsian", STYLE, FONT_SIZE_ASIAN, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_CJK ), + MT_ED( "CharPropHeightAsian",STYLE, FONT_SIZE_ASIAN, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL_CJK ), + MT_ED( "CharDiffHeightAsian",STYLE,FONT_SIZE_REL_ASIAN, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF_CJK ), + // RES_CHRATR_CJK_LANGUAGE + MT_ED( "CharLocaleAsian", STYLE, LANGUAGE_ASIAN, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocaleAsian", STYLE, COUNTRY_ASIAN, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CJK_POSTURE + MT_E( "CharPostureAsian", STYLE, FONT_STYLE_ASIAN, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_CJK_WEIGHT + MT_E( "CharWeightAsian", STYLE, FONT_WEIGHT_ASIAN, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_CTL_FONT + MT_ED( "CharFontNameComplex", STYLE, FONT_NAME_COMPLEX, XML_TYPE_STRING|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTNAME_CTL ), + MT_ED( "CharFontNameComplex", STYLE, FONT_FAMILY_COMPLEX, XML_TYPE_TEXT_FONTFAMILYNAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FONTFAMILYNAME_CTL ), + MT_ED( "CharFontStyleNameComplex",STYLE, FONT_STYLE_NAME_COMPLEX, XML_TYPE_STRING, CTF_FONTSTYLENAME_CTL ), + MT_ED( "CharFontFamilyComplex", STYLE, FONT_FAMILY_GENERIC_COMPLEX,XML_TYPE_TEXT_FONTFAMILY, CTF_FONTFAMILY_CTL ), + MT_ED( "CharFontPitchComplex", STYLE, FONT_PITCH_COMPLEX, XML_TYPE_TEXT_FONTPITCH, CTF_FONTPITCH_CTL ), + MT_ED( "CharFontCharSetComplex", STYLE, FONT_CHARSET_COMPLEX, XML_TYPE_TEXT_FONTENCODING, CTF_FONTCHARSET_CTL ), + // RES_CHRATR_CTL_FONTSIZE + MT_ED( "CharHeightComplex", STYLE, FONT_SIZE_COMPLEX, XML_TYPE_CHAR_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_CTL ), + MT_ED( "CharPropHeightComplex",STYLE, FONT_SIZE_COMPLEX, XML_TYPE_CHAR_HEIGHT_PROP|MID_FLAG_MULTI_PROPERTY, CTF_CHARHEIGHT_REL_CTL ), + MT_ED( "CharDiffHeightComplex",STYLE,FONT_SIZE_REL_COMPLEX, XML_TYPE_CHAR_HEIGHT_DIFF, CTF_CHARHEIGHT_DIFF_CTL ), + // RES_CHRATR_CTL_LANGUAGE + MT_ED( "CharLocaleComplex", STYLE, LANGUAGE_COMPLEX, XML_TYPE_CHAR_LANGUAGE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_ED( "CharLocaleComplex", STYLE, COUNTRY_COMPLEX, XML_TYPE_CHAR_COUNTRY|MID_FLAG_MERGE_PROPERTY, 0 ), + // RES_CHRATR_CTL_POSTURE + MT_E( "CharPostureComplex", STYLE, FONT_STYLE_COMPLEX, XML_TYPE_TEXT_POSTURE, 0 ), + // RES_CHRATR_CTL_WEIGHT + MT_E( "CharWeightComplex", STYLE, FONT_WEIGHT_COMPLEX, XML_TYPE_TEXT_WEIGHT, 0 ), + // RES_CHRATR_ROTATE + MT_E( "CharRotation", STYLE, TEXT_ROTATION_ANGLE, XML_TYPE_TEXT_ROTATION_ANGLE, 0 ), + MT_E( "CharRotationIsFitToLine", STYLE, TEXT_ROTATION_SCALE, XML_TYPE_TEXT_ROTATION_SCALE, 0 ), + // RES_CHRATR_EMPHASIS_MARK + MT_E( "CharEmphasis", STYLE, TEXT_EMPHASIZE, XML_TYPE_TEXT_EMPHASIZE, 0 ), + // RES_CHRATR_TWO_LINES + MT_E( "CharCombineIsOn", STYLE, TEXT_COMBINE, XML_TYPE_TEXT_COMBINE|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharCombinePrefix", STYLE, TEXT_COMBINE_START_CHAR, XML_TYPE_TEXT_COMBINECHAR, 0 ), + MT_E( "CharCombineSuffix", STYLE, TEXT_COMBINE_END_CHAR, XML_TYPE_TEXT_COMBINECHAR, 0 ), + // RES_CHRATR_SCALEW + MT_E( "CharScaleWidth", STYLE, TEXT_SCALE, XML_TYPE_PERCENT16, 0 ), + // combined characters field, does not correspond to a property + MT_E( "", STYLE, TEXT_COMBINE, XML_TYPE_TEXT_COMBINE_CHARACTERS|MID_FLAG_NO_PROPERTY, CTF_COMBINED_CHARACTERS_FIELD ), + //RES_CHRATR_RELIEF + MT_E( "CharRelief", STYLE, FONT_RELIEF, XML_TYPE_TEXT_FONT_RELIEF, 0 ), + // RES_CHRATR_HIDDEN + MT_E( "CharHidden", TEXT, DISPLAY, XML_TYPE_TEXT_HIDDEN_AS_DISPLAY|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_TEXT_DISPLAY ), + // RES_CHRATR_OVERLINE + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_STYLE, XML_TYPE_TEXT_OVERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_TYPE, XML_TYPE_TEXT_OVERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverline", STYLE, TEXT_OVERLINE_WIDTH, XML_TYPE_TEXT_OVERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ), + MT_E( "CharOverlineColor", STYLE, TEXT_OVERLINE_COLOR, XML_TYPE_TEXT_OVERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ), + MT_E( "CharOverlineHasColor", STYLE, TEXT_OVERLINE_COLOR, XML_TYPE_TEXT_OVERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + + // RES_TXTATR_INETFMT + MT_E( "HyperLinkURL", TEXT, XMLNS, XML_TYPE_STRING|MID_FLAG_NO_PROPERTY_IMPORT, CTF_HYPERLINK_URL ), + // RES_TXTATR_REFMARK + // TODO + // RES_TXTATR_TOXMARK + // TODO + // RES_TXTATR_CHARFMT + MT_E( "CharStyleName", TEXT, STYLE_NAME, XML_TYPE_STRING|MID_FLAG_NO_PROPERTY_IMPORT, CTF_CHAR_STYLE_NAME ), + // RES_TXTATR_CJK_RUBY + // TODO + // RES_TXTATR_FIELD + // TODO + // RES_TXTATR_FLYCNT + // TODO + // RES_TXTATR_FTN + // TODO + // RES_TXTATR_SOFTHYPH + // TODO + // RES_TXTATR_HARDBLANK + // TODO + // RES_UNKNOWNATR_CONTAINER + MT_E( "TextUserDefinedAttributes", TEXT, XMLNS, XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ), + MT_ED( "ParaIsCharacterDistance", STYLE, TEXT_AUTOSPACE, XML_TYPE_TEXT_AUTOSPACE, 0 ), + MT_ED( "ParaIsHangingPunctuation", STYLE, PUNCTUATION_WRAP, XML_TYPE_TEXT_PUNCTUATION_WRAP, 0 ), + MT_ED( "ParaIsForbiddenRules", STYLE, LINE_BREAK, XML_TYPE_TEXT_LINE_BREAK, 0 ), + MT_E( "TabStopDistance", STYLE, TAB_STOP_DISTANCE, XML_TYPE_MEASURE, 0 ), + + M_END() +}; + +XMLPropertyMapEntry aXMLFramePropMap[] = +{ + // RES_FILL_ORDER + // TODO: not required??? + // RES_FRM_SIZE + MG_ED( "Width", SVG, WIDTH, XML_TYPE_MEASURE, CTF_FRAMEWIDTH_ABS ), + MG_ED( "Width", FO, MIN_WIDTH, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_FRAMEWIDTH_MIN_ABS ), + MG_ED( "RelativeWidth", FO, MIN_WIDTH, XML_TYPE_TEXT_REL_WIDTH_HEIGHT, CTF_FRAMEWIDTH_MIN_REL ), + MG_ED( "RelativeWidth", STYLE, REL_WIDTH, XML_TYPE_TEXT_REL_WIDTH_HEIGHT, CTF_FRAMEWIDTH_REL ), + MG_ED( "WidthType", FO, TEXT_BOX, XML_TYPE_NUMBER16|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_FRAMEWIDTH_TYPE ), +// M_ED( "RelativeWidth", STYLE, REL_WIDTH, XML_TYPE_TEXT_REL_WIDTH_HEIGHT|MID_FLAG_MULTI_PROPERTY, 0 ), +// M_ED( "IsSyncWidthToHeight",STYLE, REL_WIDTH, XML_TYPE_TEXT_SYNC_WIDTH_HEIGHT|MID_FLAG_MULTI_PROPERTY, 0 ), + + MG_ED( "Height", SVG, HEIGHT, XML_TYPE_MEASURE, CTF_FRAMEHEIGHT_ABS ), + MG_ED( "Height", FO, MIN_HEIGHT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, CTF_FRAMEHEIGHT_MIN_ABS ), + MG_ED( "RelativeHeight", FO, MIN_HEIGHT, XML_TYPE_TEXT_REL_WIDTH_HEIGHT, CTF_FRAMEHEIGHT_MIN_REL ), + MG_ED( "RelativeHeight", STYLE, REL_HEIGHT, XML_TYPE_TEXT_REL_WIDTH_HEIGHT, CTF_FRAMEHEIGHT_REL ), +// M_ED( "RelativeHeight", STYLE, REL_HEIGHT, XML_TYPE_TEXT_REL_WIDTH_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_FRAMEHEIGHT_REL ), +// M_ED( "IsSyncHeightToWidth",STYLE, REL_HEIGHT, XML_TYPE_TEXT_SYNC_WIDTH_HEIGHT|MID_FLAG_MULTI_PROPERTY, CTF_SYNCHEIGHT ), +// M_ED( "IsSyncHeightToWidth",STYLE, REL_HEIGHT, XML_TYPE_TEXT_SYNC_WIDTH_HEIGHT_MIN, CTF_SYNCHEIGHT_MIN ), + MG_ED( "SizeType", FO, TEXT_BOX, XML_TYPE_NUMBER16|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_SIZETYPE ), + // RES_PAPER_BIN + // not required + // RES_ANCHOR + // moved to here because it is not used for automatic styles + MG_ED( "AnchorType", TEXT, ANCHOR_TYPE, XML_TYPE_TEXT_ANCHOR_TYPE, CTF_ANCHORTYPE ), + // AnchorPage number is not required for styles! + MG_ED( "HoriOrientPosition", SVG, X, XML_TYPE_MEASURE, 0 ), + MG_ED( "VertOrientPosition", SVG, Y, XML_TYPE_MEASURE, 0 ), + // ***** The map for automatic styles starts here ***** + // RES_LR_SPACE + MG_E( "LeftMargin", FO, MARGIN_LEFT, XML_TYPE_MEASURE, 0), + MG_E( "RightMargin", FO, MARGIN_RIGHT, XML_TYPE_MEASURE, 0 ), + // RES_UL_SPACE + MG_E( "TopMargin", FO, MARGIN_TOP, XML_TYPE_MEASURE, 0 ), + MG_E( "BottomMargin", FO, MARGIN_BOTTOM, XML_TYPE_MEASURE, 0 ), + // RES_PAGEDESC + // not required + // RES_BREAK + // not required + // RES_CNTNT + // not required (accessed using API) + // RES_HEADER + // not required + // RES_FOOTER + // not required + // RES_PRINT + MG_E( "Print", STYLE, PRINT_CONTENT, XML_TYPE_BOOL, 0 ), + // RES_OPAQUE + MG_ED( "Opaque", STYLE, RUN_THROUGH, XML_TYPE_TEXT_OPAQUE, 0 ), + // RES_PROTECT + MG_E( "ContentProtected", STYLE, PROTECT, XML_TYPE_TEXT_PROTECT_CONTENT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MG_E( "SizeProtected", STYLE, PROTECT, XML_TYPE_TEXT_PROTECT_SIZE|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MG_E( "PositionProtected", STYLE, PROTECT, XML_TYPE_TEXT_PROTECT_POSITION|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + // RES_SURROUND + MG_ED( "TextWrap", STYLE, WRAP, XML_TYPE_TEXT_WRAP, CTF_WRAP ), + MG_ED( "SurroundAnchorOnly", STYLE, NUMBER_WRAPPED_PARAGRAPHS, XML_TYPE_TEXT_PARAGRAPH_ONLY, CTF_WRAP_PARAGRAPH_ONLY ), + MG_E( "SurroundContour", STYLE, WRAP_CONTOUR, XML_TYPE_BOOL, CTF_WRAP_CONTOUR ), + MG_E( "ContourOutside", STYLE, WRAP_CONTOUR_MODE, XML_TYPE_TEXT_WRAP_OUTSIDE, CTF_WRAP_CONTOUR_MODE ), + // RES_VERT_ORIENT + MG_ED( "VertOrient", STYLE, VERTICAL_POS, XML_TYPE_TEXT_VERTICAL_POS, CTF_VERTICALPOS ), + MG_ED( "VertOrient", STYLE, VERTICAL_POS, XML_TYPE_TEXT_VERTICAL_POS_AT_CHAR, CTF_VERTICALPOS_ATCHAR ), + MG_ED( "VertOrient", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_AS_CHAR|MID_FLAG_MULTI_PROPERTY, CTF_VERTICALREL_ASCHAR ), + MG_ED( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL, CTF_VERTICALREL ), + MG_ED( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_PAGE|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_VERTICALREL_PAGE ), + MG_ED( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_FRAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_VERTICALREL_FRAME ), + // RES_HORI_ORIENT + MG_ED( "HoriOrient", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_POS|MID_FLAG_MULTI_PROPERTY, CTF_HORIZONTALPOS ), + MG_ED( "PageToggle", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_MIRROR, CTF_HORIZONTALMIRROR ), + MG_ED( "HoriOrient", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_POS_MIRRORED|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_HORIZONTALPOS_MIRRORED ), + MG_ED( "HoriOrientRelation", STYLE, HORIZONTAL_REL, XML_TYPE_TEXT_HORIZONTAL_REL, CTF_HORIZONTALREL ), + MG_ED( "HoriOrientRelation", STYLE, HORIZONTAL_REL, XML_TYPE_TEXT_HORIZONTAL_REL_FRAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_HORIZONTALREL_FRAME ), + // RES_ANCHOR + // see above + // RES_BACKGROUND + MG_ED( "BackColorRGB", FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MG_ED( "BackTransparent", FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, CTF_BACKGROUND_TRANSPARENT ), + MG_ED( "BackColorTransparency", STYLE, BACKGROUND_TRANSPARENCY, XML_TYPE_PERCENT8, CTF_BACKGROUND_TRANSPARENCY ), + + MG_E( "BackGraphicTransparency", STYLE, BACKGROUND_IMAGE_TRANSPARENCY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_PERCENT8, CTF_BACKGROUND_TRANSPARENCY ), + MG_E( "BackGraphicLocation", STYLE, POSITION, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BUILDIN_CMP_ONLY, CTF_BACKGROUND_POS ), + MG_E( "BackGraphicFilter",STYLE, FILTER_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_FILTER ), + MG_E( "BackGraphicURL", STYLE, BACKGROUND_IMAGE, MID_FLAG_ELEMENT_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_URL ), + + // RES_BOX + MG_ED( "LeftBorder", STYLE, BORDER_LINE_WIDTH, XML_TYPE_BORDER_WIDTH, CTF_ALLBORDERWIDTH ), + MG_ED( "LeftBorder", STYLE, BORDER_LINE_WIDTH_LEFT, XML_TYPE_BORDER_WIDTH, CTF_LEFTBORDERWIDTH ), + MG_ED( "RightBorder", STYLE, BORDER_LINE_WIDTH_RIGHT, XML_TYPE_BORDER_WIDTH, CTF_RIGHTBORDERWIDTH ), + MG_ED( "TopBorder", STYLE, BORDER_LINE_WIDTH_TOP, XML_TYPE_BORDER_WIDTH, CTF_TOPBORDERWIDTH ), + MG_ED( "BottomBorder", STYLE, BORDER_LINE_WIDTH_BOTTOM, XML_TYPE_BORDER_WIDTH, CTF_BOTTOMBORDERWIDTH ), + + MG_ED( "LeftBorderDistance", FO, PADDING, XML_TYPE_MEASURE, CTF_ALLBORDERDISTANCE ), // need special import filtering + MG_ED( "LeftBorderDistance", FO, PADDING_LEFT, XML_TYPE_MEASURE, CTF_LEFTBORDERDISTANCE ), + MG_ED( "RightBorderDistance", FO, PADDING_RIGHT, XML_TYPE_MEASURE, CTF_RIGHTBORDERDISTANCE ), + MG_ED( "TopBorderDistance", FO, PADDING_TOP, XML_TYPE_MEASURE, CTF_TOPBORDERDISTANCE ), + MG_ED( "BottomBorderDistance",FO, PADDING_BOTTOM, XML_TYPE_MEASURE, CTF_BOTTOMBORDERDISTANCE ), + + // There is an additional property for controls! + MG_ED( "LeftBorder", FO, BORDER, XML_TYPE_BORDER|MID_FLAG_MULTI_PROPERTY, CTF_ALLBORDER ), + MG_ED( "LeftBorder", FO, BORDER_LEFT, XML_TYPE_BORDER, CTF_LEFTBORDER ), + MG_ED( "RightBorder", FO, BORDER_RIGHT, XML_TYPE_BORDER, CTF_RIGHTBORDER ), + MG_ED( "TopBorder", FO, BORDER_TOP, XML_TYPE_BORDER, CTF_TOPBORDER ), + MG_ED( "BottomBorder", FO, BORDER_BOTTOM, XML_TYPE_BORDER, CTF_BOTTOMBORDER ), + // RES_SHADOW + MG_E( "ShadowFormat", STYLE, SHADOW, XML_TYPE_TEXT_SHADOW, 0 ), + // RES_FRMMACRO + // TODO + // RES_COL + MG_E( "TextColumns", STYLE, COLUMNS, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_COLUMNS, CTF_TEXTCOLUMNS ), + // RES_KEEP + // not required + // RES_URL + // not required (exprted as draw:a element) + // RES_EDIT_IN_READONLY + MG_ED( "EditInReadonly", STYLE, EDITABLE, XML_TYPE_BOOL, 0 ), + // RES_LAYOUT_SPLIT + // not required + // RES_CHAIN + // not required (exported at text:text-box element) + // RES_LINENUMBER + // not required + // RES_FTN_AT_TXTEND + // not required + // RES_END_AT_TXTEND + // not required + // RES_COLUMNBALANCE + // TODO + // RES_UNKNOWNATR_CONTAINER +// M_E_SE( TEXT, xmlns, RES_UNKNOWNATR_CONTAINER, 0 ), + // RES_GRFATR_MIRRORGRF (vertical MUST be processed after horizontal!) + MG_E( "HoriMirroredOnEvenPages", STYLE, MIRROR, XML_TYPE_TEXT_MIRROR_HORIZONTAL_LEFT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MG_E( "HoriMirroredOnOddPages", STYLE, MIRROR, XML_TYPE_TEXT_MIRROR_HORIZONTAL_RIGHT|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + MG_E( "VertMirrored", STYLE, MIRROR, XML_TYPE_TEXT_MIRROR_VERTICAL|MID_FLAG_MERGE_ATTRIBUTE|MID_FLAG_MULTI_PROPERTY, 0 ), + // RES_GRFATR_CROPGRF + MG_EV( "GraphicCrop", FO, CLIP, XML_TYPE_TEXT_CLIP, CTF_TEXT_CLIP, SvtSaveOptions::ODFVER_012 ), + MG_E( "GraphicCrop", FO, CLIP, XML_TYPE_TEXT_CLIP11, CTF_TEXT_CLIP11 ), + // RES_GRFATR_ROTATION + // not required (exported as svg:transform attribute) + // RES_GRFATR_LUMINANCE + MG_E( "AdjustLuminance", DRAW, LUMINANCE, XML_TYPE_PERCENT16, 0 ), // signed? + // RES_GRFATR_CONTRAST + MG_E( "AdjustContrast", DRAW, CONTRAST, XML_TYPE_PERCENT16, 0 ), // signed? + // RES_GRFATR_CHANNELR + MG_E( "AdjustRed", DRAW, RED, XML_TYPE_PERCENT16, 0 ), // signed? + // RES_GRFATR_CHANNELG + MG_E( "AdjustGreen", DRAW, GREEN, XML_TYPE_PERCENT16, 0 ), // signed? + // RES_GRFATR_CHANNELB + MG_E( "AdjustBlue", DRAW, BLUE, XML_TYPE_PERCENT16, 0 ), // signed? + // RES_GRFATR_GAMMA + MG_E( "Gamma", DRAW, GAMMA, XML_TYPE_DOUBLE_PERCENT, 0 ), // signed? + // RES_GRFATR_INVERT + MG_E( "GraphicIsInverted", DRAW, COLOR_INVERSION, XML_TYPE_BOOL, 0 ), + // RES_GRFATR_TRANSPARENCY + MG_E( "Transparency", DRAW, IMAGE_OPACITY, XML_TYPE_NEG_PERCENT16|MID_FLAG_MULTI_PROPERTY, 0 ), // #i25616# + // RES_GRFATR_DRAWMODE + MG_E( "GraphicColorMode", DRAW, COLOR_MODE, XML_TYPE_COLOR_MODE, 0 ), + MG_E( "WritingMode", STYLE, WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT, 0 ), + // RES_FOLLOW_TEXT_FLOW - DVO, OD 01.10.2003 #i18732# + MG_E( "IsFollowingTextFlow", DRAW, FLOW_WITH_TEXT, XML_TYPE_BOOL|MID_FLAG_SPECIAL_ITEM_EXPORT, CTF_OLD_FLOW_WITH_TEXT ), + MG_E( "IsFollowingTextFlow", STYLE, FLOW_WITH_TEXT, XML_TYPE_BOOL, 0 ), + // OD 2004-05-05 #i28701# - RES_WRAP_INFLUENCE_ON_OBJPOS + MG_E( "WrapInfluenceOnPosition", DRAW, WRAP_INFLUENCE_ON_POSITION, XML_TYPE_WRAP_INFLUENCE_ON_POSITION, 0 ), + + // special entries for floating frames + MG_E( "", DRAW, FRAME_DISPLAY_SCROLLBAR, XML_TYPE_BOOL|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_FRAME_DISPLAY_SCROLLBAR ), + MG_E( "", DRAW, FRAME_DISPLAY_BORDER, XML_TYPE_BOOL|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_FRAME_DISPLAY_BORDER ), + MG_E( "", DRAW, FRAME_MARGIN_HORIZONTAL, XML_TYPE_MEASURE_PX|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_FRAME_MARGIN_HORI ), + MG_E( "", DRAW, FRAME_MARGIN_VERTICAL, XML_TYPE_MEASURE_PX|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_FRAME_MARGIN_VERT ), + MG_E( "", DRAW, VISIBLE_AREA_LEFT, XML_TYPE_MEASURE|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_OLE_VIS_AREA_LEFT ), + MG_E( "", DRAW, VISIBLE_AREA_TOP, XML_TYPE_MEASURE|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_OLE_VIS_AREA_TOP ), + MG_E( "", DRAW, VISIBLE_AREA_WIDTH, XML_TYPE_MEASURE|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_OLE_VIS_AREA_WIDTH ), + MG_E( "", DRAW, VISIBLE_AREA_HEIGHT, XML_TYPE_MEASURE|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_OLE_VIS_AREA_HEIGHT ), + MG_E( "", DRAW, DRAW_ASPECT, XML_TYPE_TEXT_DRAW_ASPECT|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_OLE_DRAW_ASPECT ), + MG_E( "UserDefinedAttributes", TEXT, XMLNS, XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ), + + M_END() +}; + +XMLPropertyMapEntry aXMLShapePropMap[] = +{ + // RES_LR_SPACE + MG_E( "LeftMargin", FO, MARGIN_LEFT, XML_TYPE_MEASURE, 0), + MG_E( "RightMargin", FO, MARGIN_RIGHT, XML_TYPE_MEASURE, 0 ), + // RES_UL_SPACE + MG_E( "TopMargin", FO, MARGIN_TOP, XML_TYPE_MEASURE, 0 ), + MG_E( "BottomMargin", FO, MARGIN_BOTTOM, XML_TYPE_MEASURE, 0 ), + // RES_OPAQUE + MG_ED( "Opaque", STYLE, RUN_THROUGH, XML_TYPE_TEXT_OPAQUE, 0 ), + // RES_SURROUND + MG_E( "TextWrap", STYLE, WRAP, XML_TYPE_TEXT_WRAP, CTF_WRAP ), + MG_E( "SurroundAnchorOnly", STYLE, NUMBER_WRAPPED_PARAGRAPHS, XML_TYPE_TEXT_PARAGRAPH_ONLY, CTF_WRAP_PARAGRAPH_ONLY ), + MG_E( "SurroundContour", STYLE, WRAP_CONTOUR, XML_TYPE_BOOL, CTF_WRAP_CONTOUR ), + MG_E( "ContourOutside", STYLE, WRAP_CONTOUR_MODE, XML_TYPE_TEXT_WRAP_OUTSIDE, CTF_WRAP_CONTOUR_MODE ), + // --> OD 2004-08-09 #i28749# - use own CTF ids for positioning attributes + // RES_VERT_ORIENT + MG_E( "VertOrient", STYLE, VERTICAL_POS, XML_TYPE_TEXT_VERTICAL_POS, CTF_SHAPE_VERTICALPOS ), + // OD 2004-04-16 #i26791# - add property for at-character anchored shapes + MG_E( "VertOrient", STYLE, VERTICAL_POS, XML_TYPE_TEXT_VERTICAL_POS_AT_CHAR, CTF_SHAPE_VERTICALPOS_ATCHAR ), + MG_E( "VertOrient", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_AS_CHAR|MID_FLAG_MULTI_PROPERTY, CTF_VERTICALREL_ASCHAR ), + MG_E( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL, CTF_SHAPE_VERTICALREL ), + MG_E( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_PAGE|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_SHAPE_VERTICALREL_PAGE ), + MG_E( "VertOrientRelation", STYLE, VERTICAL_REL, XML_TYPE_TEXT_VERTICAL_REL_FRAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_SHAPE_VERTICALREL_FRAME ), + // RES_HORI_ORIENT + MG_E( "HoriOrient", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_POS|MID_FLAG_MULTI_PROPERTY, CTF_SHAPE_HORIZONTALPOS ), + MG_E( "PageToggle", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_MIRROR, CTF_SHAPE_HORIZONTALMIRROR ), + MG_E( "HoriOrient", STYLE, HORIZONTAL_POS, XML_TYPE_TEXT_HORIZONTAL_POS_MIRRORED|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_SHAPE_HORIZONTALPOS_MIRRORED ), + MG_E( "HoriOrientRelation", STYLE, HORIZONTAL_REL, XML_TYPE_TEXT_HORIZONTAL_REL, CTF_SHAPE_HORIZONTALREL ), + MG_E( "HoriOrientRelation", STYLE, HORIZONTAL_REL, XML_TYPE_TEXT_HORIZONTAL_REL_FRAME|MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_SHAPE_HORIZONTALREL_FRAME ), + // <-- + // OD 2004-05-05 #i28701# - RES_WRAP_INFLUENCE_ON_OBJPOS + MG_ED( "WrapInfluenceOnPosition", DRAW, WRAP_INFLUENCE_ON_POSITION, XML_TYPE_WRAP_INFLUENCE_ON_POSITION, 0 ), + // UserDefinedAttributes is already contained in the map this one is + // chained to. + + // RES_FOLLOW_TEXT_FLOW - OD 2004-04-21 #i26791# + MG_ED( "IsFollowingTextFlow", STYLE, FLOW_WITH_TEXT, XML_TYPE_BOOL, 0 ), + + M_END() +}; + +XMLPropertyMapEntry aXMLSectionPropMap[] = +{ + // RES_COL + MS_E( "TextColumns", STYLE, COLUMNS, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_COLUMNS, CTF_TEXTCOLUMNS ), + + // RES_BACKGROUND + MS_E( "BackColor", FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MS_E( "BackTransparent", FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MS_E( "BackGraphicLocation", STYLE, POSITION, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BUILDIN_CMP_ONLY, CTF_BACKGROUND_POS ), + MS_E( "BackGraphicFilter",STYLE, FILTER_NAME, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_FILTER ), + MS_E( "BackGraphicURL", STYLE, BACKGROUND_IMAGE, MID_FLAG_ELEMENT_ITEM|XML_TYPE_STRING, CTF_BACKGROUND_URL ), + + // move protect-flag into section element +// M_E( "IsProtected", STYLE, PROTECT, XML_TYPE_BOOL, 0 ), + + MS_E( "DontBalanceTextColumns", TEXT, DONT_BALANCE_TEXT_COLUMNS, XML_TYPE_BOOL, 0 ), + + MS_E( "WritingMode", STYLE, WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT, 0 ), + + MS_E( "SectionLeftMargin", FO, MARGIN_LEFT, XML_TYPE_MEASURE, 0), + MS_E( "SectionRightMargin", FO, MARGIN_RIGHT, XML_TYPE_MEASURE, 0), + + // section footnote settings + MS_E( "FootnoteIsOwnNumbering", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BOOL, CTF_SECTION_FOOTNOTE_NUM_OWN ), + MS_E( "FootnoteIsRestartNumbering", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BOOL, CTF_SECTION_FOOTNOTE_NUM_RESTART ), + MS_E( "FootnoteRestartNumberingAt", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_NUMBER16,CTF_SECTION_FOOTNOTE_NUM_RESTART_AT ), + MS_E( "FootnoteNumberingType", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_NUMBER16,CTF_SECTION_FOOTNOTE_NUM_TYPE ), + MS_E( "FootnoteNumberingPrefix", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_SECTION_FOOTNOTE_NUM_PREFIX ), + MS_E( "FootnoteNumberingSuffix", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_SECTION_FOOTNOTE_NUM_SUFFIX ), + MS_E( "FootnoteIsCollectAtTextEnd", TEXT, NOTES_CONFIGURATION, MID_FLAG_ELEMENT_ITEM|XML_TYPE_BOOL, CTF_SECTION_FOOTNOTE_END ), + + // section footnote settings + MS_E( "EndnoteIsOwnNumbering", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BOOL, CTF_SECTION_ENDNOTE_NUM_OWN ), + MS_E( "EndnoteIsRestartNumbering", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_BOOL, CTF_SECTION_ENDNOTE_NUM_RESTART ), + MS_E( "EndnoteRestartNumberingAt", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_NUMBER16,CTF_SECTION_ENDNOTE_NUM_RESTART_AT ), + MS_E( "EndnoteNumberingType", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_NUMBER16,CTF_SECTION_ENDNOTE_NUM_TYPE ), + MS_E( "EndnoteNumberingPrefix", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_SECTION_ENDNOTE_NUM_PREFIX ), + MS_E( "EndnoteNumberingSuffix", TEXT, _EMPTY, MID_FLAG_SPECIAL_ITEM|XML_TYPE_STRING, CTF_SECTION_ENDNOTE_NUM_SUFFIX ), + MS_E( "EndnoteIsCollectAtTextEnd", TEXT, NOTES_CONFIGURATION, MID_FLAG_ELEMENT_ITEM|XML_TYPE_BOOL, CTF_SECTION_ENDNOTE_END ), + MS_E( "UserDefinedAttributes", TEXT, XMLNS, XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ), + + // --> FME 2004-06-22 #114856# edit in readonly sections + // RES_EDIT_IN_READONLY + MS_E( "EditInReadonly", STYLE, EDITABLE, XML_TYPE_BOOL, 0 ), + // <-- + + M_END() +}; + +XMLPropertyMapEntry aXMLRubyPropMap[] = +{ + MR_E( "RubyAdjust", STYLE, RUBY_ALIGN, XML_TYPE_TEXT_RUBY_ADJUST, 0 ), + MR_E( "RubyIsAbove", STYLE, RUBY_POSITION, XML_TYPE_TEXT_RUBY_POSITION, 0 ), + M_END() +}; + + +XMLPropertyMapEntry aXMLTableDefaultsMap[] = +{ + // RES_COLLAPSING_BORDERS: only occurs in tables, but we need to + // read/write the default for this item + _M_ED( "CollapsingBorders", TABLE, BORDER_MODEL, XML_TYPE_PROP_TABLE | XML_TYPE_BORDER_MODEL | MID_FLAG_NO_PROPERTY_IMPORT, CTF_BORDER_MODEL ), + + M_END() +}; + +XMLPropertyMapEntry aXMLTableRowDefaultsMap[] = +{ + // RES_ROW_SPLIT: only occurs in table rows, but we need to + // read/write the default for this item + _M_ED( "IsSplitAllowed", FO, KEEP_TOGETHER, XML_TYPE_PROP_TABLE_ROW | XML_TYPE_TEXT_NKEEP | MID_FLAG_NO_PROPERTY_IMPORT, CTF_KEEP_TOGETHER ), + + M_END() +}; + +XMLPropertyMapEntry *lcl_txtprmap_getMap( sal_uInt16 nType ) +{ + XMLPropertyMapEntry *pMap = 0; + switch( nType ) + { + case TEXT_PROP_MAP_TEXT: + pMap = aXMLTextPropMap; + break; + case TEXT_PROP_MAP_SHAPE_PARA: + pMap = &(aXMLParaPropMap[1]); + DBG_ASSERT( pMap->meXMLName == XML_MARGIN_LEFT, "shape para map changed" ); + break; + case TEXT_PROP_MAP_PARA: + pMap = aXMLParaPropMap; + break; + case TEXT_PROP_MAP_FRAME: + pMap = aXMLFramePropMap; + break; + case TEXT_PROP_MAP_AUTO_FRAME: + pMap = &(aXMLFramePropMap[13]); + DBG_ASSERT( pMap->meXMLName == XML_MARGIN_LEFT, "frame map changed" ); + break; + case TEXT_PROP_MAP_SHAPE: + pMap = aXMLShapePropMap; + break; + case TEXT_PROP_MAP_SECTION: + pMap = aXMLSectionPropMap; + break; + case TEXT_PROP_MAP_RUBY: + pMap = aXMLRubyPropMap; + break; + case TEXT_PROP_MAP_TEXT_ADDITIONAL_DEFAULTS: + pMap = aXMLAdditionalTextDefaultsMap; + break; + case TEXT_PROP_MAP_TABLE_DEFAULTS: + pMap = aXMLTableDefaultsMap; + break; + case TEXT_PROP_MAP_TABLE_ROW_DEFAULTS: + pMap = aXMLTableRowDefaultsMap; + break; + } + DBG_ASSERT( pMap, "illegal map type" ); + return pMap; +} + +const XMLPropertyMapEntry* XMLTextPropertySetMapper::getPropertyMapForType( sal_uInt16 _nType ) +{ + return lcl_txtprmap_getMap( _nType ); +} + +XMLTextPropertySetMapper::XMLTextPropertySetMapper( sal_uInt16 nType ) : + XMLPropertySetMapper( lcl_txtprmap_getMap( nType ), + new XMLTextPropertyHandlerFactory ) +{ +} + +XMLTextPropertySetMapper::~XMLTextPropertySetMapper() +{ +} diff --git a/xmloff/source/text/txtsecte.cxx b/xmloff/source/text/txtsecte.cxx new file mode 100644 index 000000000000..b18d3fab086d --- /dev/null +++ b/xmloff/source/text/txtsecte.cxx @@ -0,0 +1,258 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#ifndef _XMLOFF_TXTPARAE_HXX +#include <xmloff/txtparae.hxx> +#endif +#include <tools/debug.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +#include <vector> + + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/PropertyValues.hpp> +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/text/SectionFileLink.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/families.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmltkmap.hxx> +#include "XMLTextNumRuleInfo.hxx" +#include "XMLSectionExport.hxx" +#include "XMLRedlineExport.hxx" +#ifndef _XMLOFF_MULTIPROPERTYSETHELPER_HXX +#include "MultiPropertySetHelper.hxx" +#endif + +using namespace ::com::sun::star; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::uno; +using namespace ::std; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::PropertyValues; +using ::com::sun::star::beans::PropertyState; +using ::com::sun::star::container::XIndexReplace; +using ::com::sun::star::container::XNamed; +using ::com::sun::star::lang::XServiceInfo; + +Reference<XText> lcl_findXText(const Reference<XTextSection>& rSect) +{ + Reference<XText> xText; + + Reference<XTextContent> xTextContent(rSect, UNO_QUERY); + if (xTextContent.is()) + { + xText.set(xTextContent->getAnchor()->getText()); + } + + return xText; +} + +void XMLTextParagraphExport::exportListAndSectionChange( + Reference<XTextSection> & rPrevSection, + const Reference<XTextContent> & rNextSectionContent, + const XMLTextNumRuleInfo& rPrevRule, + const XMLTextNumRuleInfo& rNextRule, + sal_Bool bAutoStyles) +{ + Reference<XTextSection> xNextSection; + + // first: get current XTextSection + Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY); + if (xPropSet.is()) + { + if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection)) + { + xPropSet->getPropertyValue(sTextSection) >>= xNextSection; + } + // else: no current section + } + + exportListAndSectionChange(rPrevSection, xNextSection, + rPrevRule, rNextRule, bAutoStyles); +} + +void XMLTextParagraphExport::exportListAndSectionChange( + Reference<XTextSection> & rPrevSection, + MultiPropertySetHelper& rPropSetHelper, + sal_Int16 nTextSectionId, + const Reference<XTextContent> & rNextSectionContent, + const XMLTextNumRuleInfo& rPrevRule, + const XMLTextNumRuleInfo& rNextRule, + sal_Bool bAutoStyles) +{ + Reference<XTextSection> xNextSection; + + // first: get current XTextSection + Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY); + if (xPropSet.is()) + { + if( !rPropSetHelper.checkedProperties() ) + rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() ); + if( rPropSetHelper.hasProperty( nTextSectionId )) + { + xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet, + sal_True ), uno::UNO_QUERY); + } + // else: no current section + } + + exportListAndSectionChange(rPrevSection, xNextSection, + rPrevRule, rNextRule, bAutoStyles); +} + +void XMLTextParagraphExport::exportListAndSectionChange( + Reference<XTextSection> & rPrevSection, + const Reference<XTextSection> & rNextSection, + const XMLTextNumRuleInfo& rPrevRule, + const XMLTextNumRuleInfo& rNextRule, + sal_Bool bAutoStyles) +{ + // old != new? -> maybe we have to start or end a new section + if (rPrevSection != rNextSection) + { + // a new section started, or an old one gets closed! + + // close old list + XMLTextNumRuleInfo aEmptyNumRuleInfo; + if ( !bAutoStyles ) + exportListChange(rPrevRule, aEmptyNumRuleInfo); + + // Build stacks of old and new sections + // Sections on top of mute sections should not be on the stack + vector< Reference<XTextSection> > aOldStack; + Reference<XTextSection> aCurrent(rPrevSection); + while(aCurrent.is()) + { + // if we have a mute section, ignore all its children + // (all previous ones) + if (pSectionExport->IsMuteSection(aCurrent)) + aOldStack.clear(); + + aOldStack.push_back(aCurrent); + aCurrent.set(aCurrent->getParentSection()); + } + + vector< Reference<XTextSection> > aNewStack; + aCurrent.set(rNextSection); + sal_Bool bMute = sal_False; + while(aCurrent.is()) + { + // if we have a mute section, ignore all its children + // (all previous ones) + if (pSectionExport->IsMuteSection(aCurrent)) + { + aNewStack.clear(); + bMute = sal_True; + } + + aNewStack.push_back(aCurrent); + aCurrent.set(aCurrent->getParentSection()); + } + + // compare the two stacks + vector<Reference<XTextSection> > ::reverse_iterator aOld = + aOldStack.rbegin(); + vector<Reference<XTextSection> > ::reverse_iterator aNew = + aNewStack.rbegin(); + // compare bottom sections and skip equal section + while ( (aOld != aOldStack.rend()) && + (aNew != aNewStack.rend()) && + (*aOld) == (*aNew) ) + { + ++aOld; + ++aNew; + } + + // close all elements of aOld ... + // (order: newest to oldest) + if (aOld != aOldStack.rend()) + { + vector<Reference<XTextSection> > ::iterator aOldForward( + aOldStack.begin()); + while ((aOldForward != aOldStack.end()) && + (*aOldForward != *aOld)) + { + if ( !bAutoStyles && (NULL != pRedlineExport) ) + pRedlineExport->ExportStartOrEndRedline(*aOldForward, + sal_False); + pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles); + ++aOldForward; + } + if (aOldForward != aOldStack.end()) + { + if ( !bAutoStyles && (NULL != pRedlineExport) ) + pRedlineExport->ExportStartOrEndRedline(*aOldForward, + sal_False); + pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles); + } + } + + // ...then open all of aNew + // (order: oldest to newest) + while (aNew != aNewStack.rend()) + { + if ( !bAutoStyles && (NULL != pRedlineExport) ) + pRedlineExport->ExportStartOrEndRedline(*aNew, sal_True); + pSectionExport->ExportSectionStart(*aNew, bAutoStyles); + ++aNew; + } + + // start new list + if ( !bAutoStyles && !bMute ) + exportListChange(aEmptyNumRuleInfo, rNextRule); + } + else + { + // list change, if sections have not changed + if ( !bAutoStyles ) + exportListChange(rPrevRule, rNextRule); + } + + // save old section (old numRule gets saved in calling method) + rPrevSection.set(rNextSection); +} + diff --git a/xmloff/source/text/txtstyle.cxx b/xmloff/source/text/txtstyle.cxx new file mode 100644 index 000000000000..b771a3ea17a2 --- /dev/null +++ b/xmloff/source/text/txtstyle.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <com/sun/star/style/ParagraphStyleCategory.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/families.hxx> +#include <xmloff/txtparae.hxx> +#include <xmloff/xmlnume.hxx> +#include <xmloff/xmlexp.hxx> +#include "XMLSectionExport.hxx" +#include "XMLLineNumberingExport.hxx" +#include "txtexppr.hxx" +#include <xmloff/txtprmap.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +void XMLTextParagraphExport::exportStyleAttributes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::style::XStyle > & rStyle ) +{ + OUString sName; + Any aAny; + Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo( + xPropSet->getPropertySetInfo()); + if( xPropSetInfo->hasPropertyByName( sCategory ) ) + { + sal_Int16 nCategory = 0; + xPropSet->getPropertyValue( sCategory ) >>= nCategory; + enum XMLTokenEnum eValue = XML_TOKEN_INVALID; + if( -1 != nCategory ) + { + switch( nCategory ) + { + case ParagraphStyleCategory::TEXT: + eValue = XML_TEXT; + break; + case ParagraphStyleCategory::CHAPTER: + eValue = XML_CHAPTER; + break; + case ParagraphStyleCategory::LIST: + eValue = XML_LIST; + break; + case ParagraphStyleCategory::INDEX: + eValue = XML_INDEX; + break; + case ParagraphStyleCategory::EXTRA: + eValue = XML_EXTRA; + break; + case ParagraphStyleCategory::HTML: + eValue = XML_HTML; + break; + } + } + if( eValue != XML_TOKEN_INVALID ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_CLASS, eValue); + } + if( xPropSetInfo->hasPropertyByName( sPageDescName ) ) + { + Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); + if( PropertyState_DIRECT_VALUE == + xPropState->getPropertyState( sPageDescName ) ) + { + xPropSet->getPropertyValue( sPageDescName ) >>= sName; + // fix for #i5551# if( sName.getLength() > 0 ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_MASTER_PAGE_NAME, + GetExport().EncodeStyleName( sName ) ); + } + } + //sal_Int32 nOutlineLevel = //#outline level, zhaojianwei, moved to styleexp.cxx - XMLStyleExport::exportStyle(¡¡) + // GetExport().GetTextParagraphExport()->GetHeadingLevel( rStyle->getName() ); + //if( nOutlineLevel != -1 ) + //{ + // OUStringBuffer sTmp; + // sTmp.append( static_cast<sal_Int32>(nOutlineLevel+1L) ); + // GetExport().AddAttribute( XML_NAMESPACE_STYLE, + // XML_DEFAULT_OUTLINE_LEVEL, + // sTmp.makeStringAndClear() ); + //} + + if( bProgress ) + { + ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper(); + pProgress->SetValue( pProgress->GetValue()+2 ); + } +} + +void XMLTextParagraphExport::exportNumStyles( sal_Bool bUsed ) +{ + SvxXMLNumRuleExport aNumRuleExport( GetExport() ); + aNumRuleExport.exportStyles( bUsed, pListAutoPool, !IsBlockMode() ); +} + +void XMLTextParagraphExport::exportTextStyles( sal_Bool bUsed, sal_Bool bProg ) +{ + sal_Bool bOldProg = bProgress; + bProgress = bProg; + + Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY); + if (xFactory.is()) + { + OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ); + Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY); + if (xPropSet.is()) + { + exportDefaultStyle( xPropSet, GetXMLToken(XML_PARAGRAPH), GetParaPropMapper()); + + exportDefaultStyle( + xPropSet, + GetXMLToken(XML_TABLE), + new XMLTextExportPropertySetMapper( + new XMLTextPropertySetMapper( + TEXT_PROP_MAP_TABLE_DEFAULTS ), + GetExport() ) ); + + exportDefaultStyle( + xPropSet, + GetXMLToken(XML_TABLE_ROW), + new XMLTextExportPropertySetMapper( + new XMLTextPropertySetMapper( + TEXT_PROP_MAP_TABLE_ROW_DEFAULTS ), + GetExport() ) ); + } + } + exportStyleFamily( "ParagraphStyles", GetXMLToken(XML_PARAGRAPH), GetParaPropMapper(), + bUsed, XML_STYLE_FAMILY_TEXT_PARAGRAPH, 0); + exportStyleFamily( "CharacterStyles", GetXMLToken(XML_TEXT), GetTextPropMapper(), + bUsed, XML_STYLE_FAMILY_TEXT_TEXT ); + // get shape export to make sure the the frame family is added correctly. + GetExport().GetShapeExport(); + exportStyleFamily( "FrameStyles", OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)), GetFramePropMapper(), + bUsed, XML_STYLE_FAMILY_TEXT_FRAME, 0); + exportNumStyles( bUsed ); + if( !IsBlockMode() ) + { + exportTextFootnoteConfiguration(); + XMLSectionExport::ExportBibliographyConfiguration(GetExport()); + XMLLineNumberingExport aLineNumberingExport(GetExport()); + aLineNumberingExport.Export(); + } + + bProgress = bOldProg; +} diff --git a/xmloff/source/text/txtstyli.cxx b/xmloff/source/text/txtstyli.cxx new file mode 100644 index 000000000000..601bef9cdf63 --- /dev/null +++ b/xmloff/source/text/txtstyli.cxx @@ -0,0 +1,579 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include "XMLTextPropertySetContext.hxx" +#include "xmloff/xmlnmspe.hxx" +#include "xmloff/XMLEventsImportContext.hxx" +#include "xmloff/attrlist.hxx" +#include "xmloff/families.hxx" +#include "xmloff/txtprmap.hxx" +#include "xmloff/txtstyli.hxx" +#include "xmloff/xmlimp.hxx" +#include "xmloff/xmltkmap.hxx" +#include "xmloff/xmltoken.hxx" +#include "xmloff/xmluconv.hxx" + +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/style/ParagraphStyleCategory.hpp> +#include <com/sun/star/style/XStyle.hpp> + +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +// STL includes +#include <algorithm> +#include <functional> +#include <utility> +#include <vector> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +//using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +static __FAR_DATA SvXMLEnumMapEntry aCategoryMap[] = +{ + { XML_TEXT, ParagraphStyleCategory::TEXT }, + { XML_CHAPTER, ParagraphStyleCategory::CHAPTER }, + { XML_LIST, ParagraphStyleCategory::LIST }, + { XML_INDEX, ParagraphStyleCategory::INDEX }, + { XML_EXTRA, ParagraphStyleCategory::EXTRA }, + { XML_HTML, ParagraphStyleCategory::HTML }, + { XML_TOKEN_INVALID, 0 } +}; + +void XMLTextStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + if( XML_NAMESPACE_STYLE == nPrefixKey ) + { + // TODO: use a map here + if( IsXMLToken( rLocalName, XML_AUTO_UPDATE ) ) + { + if( IsXMLToken( rValue, XML_TRUE ) ) + bAutoUpdate = sal_True; + } + else if( IsXMLToken( rLocalName, XML_LIST_STYLE_NAME ) ) + { + sListStyleName = rValue; + // --> OD 2006-09-21 #i69523# + mbListStyleSet = sal_True; + // <-- + } + else if( IsXMLToken( rLocalName, XML_MASTER_PAGE_NAME ) ) + { + sMasterPageName = rValue; + bHasMasterPageName = sal_True; + } + else if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) ) + { + sDataStyleName = rValue; + } + else if( IsXMLToken( rLocalName, XML_CLASS ) ) + { + sCategoryVal = rValue; + } + else if( IsXMLToken( rLocalName, XML_DEFAULT_OUTLINE_LEVEL ) ) + { + sal_Int32 nTmp; + if( SvXMLUnitConverter::convertNumber( nTmp, rValue ) && + // nTmp > 0 && nTmp < 256 ) //#outline level, removed by zhaojianwei + 0 <= nTmp && nTmp <= 10 ) //<-end,add by zhaojianwei + nOutlineLevel = static_cast< sal_Int8 >( nTmp ); + } + else + { + XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } + } + else + { + XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } +} + +TYPEINIT1( XMLTextStyleContext, XMLPropStyleContext ); + +XMLTextStyleContext::XMLTextStyleContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, sal_uInt16 nFamily, + sal_Bool bDefaultStyle ) +: XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ) +, sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ) +, sCategory( RTL_CONSTASCII_USTRINGPARAM( "Category" ) ) +, sNumberingStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyleName" ) ) +, sOutlineLevel(RTL_CONSTASCII_USTRINGPARAM( "OutlineLevel" ) )//#outline level,add by zhaojianwei +, sDropCapCharStyleName( RTL_CONSTASCII_USTRINGPARAM( "DropCapCharStyleName" ) ) +, sPageDescName( RTL_CONSTASCII_USTRINGPARAM( "PageDescName" ) ) +//, nOutlineLevel( 0 ) // removed by zhaojianwei +, nOutlineLevel( -1 ) //<-end, add by zhaojianwei +, bAutoUpdate( sal_False ) +, bHasMasterPageName( sal_False ) +, bHasCombinedCharactersLetter( sal_False ) +// --> OD 2006-09-21 #i69523# +, mbListStyleSet( sal_False ) +// <-- +, pEventContext( NULL ) +{ +} + +XMLTextStyleContext::~XMLTextStyleContext() +{ +} + +SvXMLImportContext *XMLTextStyleContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix ) + { + sal_uInt32 nFamily = 0; + if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TEXT; + else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_PARAGRAPH; + else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_SECTION; + else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE; + else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE_ROW; + if( nFamily ) + { + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + GetStyles()->GetImportPropertyMapper( GetFamily() ); + if( xImpPrMap.is() ) + pContext = new XMLTextPropertySetContext( GetImport(), nPrefix, + rLocalName, xAttrList, + nFamily, + GetProperties(), + xImpPrMap, + sDropCapTextStyleName ); + } + } + else if ( (XML_NAMESPACE_OFFICE == nPrefix) && + IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + { + // create and remember events import context + // (for delayed processing of events) + pEventContext = new XMLEventsImportContext( GetImport(), nPrefix, + rLocalName); + pEventContext->AddRef(); + pContext = pEventContext; + } + + if( !pContext ) + pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + + return pContext; +} + +void XMLTextStyleContext::CreateAndInsert( sal_Bool bOverwrite ) +{ + XMLPropStyleContext::CreateAndInsert( bOverwrite ); + Reference < XStyle > xStyle = GetStyle(); + if( !xStyle.is() || !(bOverwrite || IsNew()) ) + return; + + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) ) + { + Any aAny; + sal_Bool bTmp = bAutoUpdate; + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsAutoUpdate, aAny ); + } + + sal_uInt16 nCategory = ParagraphStyleCategory::TEXT; + if( XML_STYLE_FAMILY_TEXT_PARAGRAPH == GetFamily() && + sCategoryVal.getLength() && xStyle->isUserDefined() && + xPropSetInfo->hasPropertyByName( sCategory ) && + SvXMLUnitConverter::convertEnum( nCategory, sCategoryVal, aCategoryMap ) ) + { + Any aAny; + aAny <<= (sal_Int16)nCategory; + xPropSet->setPropertyValue( sCategory, aAny ); + } + + // tell the style about it's events (if applicable) + if (NULL != pEventContext) + { + // set event suppplier and release reference to context + Reference<document::XEventsSupplier> xEventsSupplier(xStyle,UNO_QUERY); + pEventContext->SetEvents(xEventsSupplier); + pEventContext->ReleaseRef(); + } + + // --> OD 2006-10-12 #i69629# + if ( nOutlineLevel > 0 ) + { + GetImport().GetTextImport()->AddOutlineStyleCandidate( nOutlineLevel, + GetDisplayName() ); + } + // <-- +} + +void XMLTextStyleContext::SetDefaults( ) +{ + if( ( GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) || + ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE ) || + ( GetFamily() == XML_STYLE_FAMILY_TABLE_ROW ) ) + { + Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY); + if (xFactory.is()) + { + Reference < XInterface > xInt = xFactory->createInstance ( + OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) ); + Reference < XPropertySet > xProperties ( xInt, UNO_QUERY ); + if ( xProperties.is() ) + FillPropertySet ( xProperties ); + } + } +} + +void XMLTextStyleContext::Finish( sal_Bool bOverwrite ) +{ + XMLPropStyleContext::Finish( bOverwrite ); + + Reference < XStyle > xStyle = GetStyle(); + // --> OD 2006-09-21 #i69523# + // consider set empty list style +// if ( !( sListStyleName.getLength() || + if ( !( mbListStyleSet || + nOutlineLevel >= 0 || //#outline level,add by zhaojianwei + sDropCapTextStyleName.getLength() || + bHasMasterPageName ) || + !xStyle.is() || + !( bOverwrite || IsNew() ) ) + return; + // <-- + + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + + //#outline level,add by zhaojianwei + if( xPropSetInfo->hasPropertyByName( sOutlineLevel )) + { + Any aAny; + if( nOutlineLevel >= 0 ) + { + aAny <<= nOutlineLevel; + xPropSet->setPropertyValue( sOutlineLevel, aAny ); + } + } + //<-end,zhaojianwei + + + // --> OD 2006-09-21 #i69523# + // consider set empty list style +// if( sListStyleName.getLength() ) + if ( mbListStyleSet && + xPropSetInfo->hasPropertyByName( sNumberingStyleName ) ) + { + // --> OD 2006-10-12 #i70223# + // Only for text document from version prior OOo 2.1 resp. SO 8 PU5: + // - Do not apply list style, if paragraph style has a default outline + // level > 0 and thus, will be assigned to the corresponding list + // level of the outline style. + bool bApplyListStyle( true ); + if ( nOutlineLevel > 0 ) + { + // --> OD 2007-12-19 #152540# + if ( GetImport().IsTextDocInOOoFileFormat() ) + { + bApplyListStyle = false; + } + else + { + sal_Int32 nUPD( 0 ); + sal_Int32 nBuild( 0 ); + // --> OD 2008-03-19 #i86058# + // check explicitly on certain versions + if ( GetImport().getBuildIds( nUPD, nBuild ) && + ( ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0 + ( nUPD == 680 && nBuild <= 9073 ) ) ) // OOo 2.0 - OOo 2.0.4 + { + bApplyListStyle = false; + } + // <-- + } + // <-- + } + + if ( bApplyListStyle ) + { + if ( !sListStyleName.getLength() ) + { + Any aAny; + aAny <<= sListStyleName /* empty string */; + xPropSet->setPropertyValue( sNumberingStyleName, aAny ); + } + else + { + // change list style name to display name + OUString sDisplayListStyleName( + GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST, + sListStyleName ) ); + // The families container must exist + const Reference < XNameContainer >& rNumStyles = + GetImport().GetTextImport()->GetNumberingStyles(); + // if( rNumStyles.is() && rNumStyles->hasByName( sDisplayListStyleName ) && + // xPropSetInfo->hasPropertyByName( sNumberingStyleName ) ) + if ( rNumStyles.is() && + rNumStyles->hasByName( sDisplayListStyleName ) ) + { + Any aAny; + aAny <<= sDisplayListStyleName; + xPropSet->setPropertyValue( sNumberingStyleName, aAny ); + } + } + } + // <-- + } + // <-- + + if( sDropCapTextStyleName.getLength() ) + { + // change list style name to display name + OUString sDisplayDropCapTextStyleName( + GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_TEXT, + sDropCapTextStyleName ) ); + // The families cointaner must exist + const Reference < XNameContainer >& rTextStyles = + GetImport().GetTextImport()->GetTextStyles(); + if( rTextStyles.is() && + rTextStyles->hasByName( sDisplayDropCapTextStyleName ) && + xPropSetInfo->hasPropertyByName( sDropCapCharStyleName ) ) + { + Any aAny; + aAny <<= sDisplayDropCapTextStyleName; + xPropSet->setPropertyValue( sDropCapCharStyleName, aAny ); + } + } + + if( bHasMasterPageName ) + { + OUString sDisplayName( + GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_MASTER_PAGE, sMasterPageName ) ); + // The families cointaner must exist + const Reference < XNameContainer >& rPageStyles = + GetImport().GetTextImport()->GetPageStyles(); + if( ( !sDisplayName.getLength() || + (rPageStyles.is() && + rPageStyles->hasByName( sDisplayName )) ) && + xPropSetInfo->hasPropertyByName( sPageDescName ) ) + { + Any aAny; + aAny <<= sDisplayName; + xPropSet->setPropertyValue( sPageDescName, aAny ); + } + } +} + +void XMLTextStyleContext::FillPropertySet( + const Reference<XPropertySet > & rPropSet ) +{ + // imitate the FillPropertySet of the super class, so we get a chance to + // catch the combined characters attribute + + // imitate XMLPropStyleContext::FillPropertySet(...) + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)GetStyles())->GetImportPropertyMapper(GetFamily()); + DBG_ASSERT( xImpPrMap.is(), "Where is the import prop mapper?" ); + if( xImpPrMap.is() ) + { + + // imitate SvXMLImportPropertyMapper::FillPropertySet(...) + + // The reason for this is that we have no other way to + // efficiently intercept the value of combined characters. To + // get that value, we could iterate through the map once more, + // but instead we chose to insert the code into this + // iteration. I haven't been able to come up with a much more + // intelligent solution. + + + struct _ContextID_Index_Pair aContextIDs[] = + { + { CTF_COMBINED_CHARACTERS_FIELD, -1 }, + { CTF_KEEP_TOGETHER, -1 }, + { CTF_BORDER_MODEL, -1 }, + { CTF_TEXT_DISPLAY, -1 }, + { CTF_FONTFAMILYNAME, -1 }, + { CTF_FONTFAMILYNAME_CJK, -1 }, + { CTF_FONTFAMILYNAME_CTL, -1 }, + { -1, -1 } + }; + + // get property set info + Reference< XPropertySetInfo > xInfo( rPropSet->getPropertySetInfo(), UNO_SET_THROW ); + + bool bAutomatic = false; + if( ((SvXMLStylesContext *)GetStyles())->IsAutomaticStyle() && + ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT || GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) ) + { + bAutomatic = true; + if( GetAutoName().getLength() ) + { + OUString sAutoProp = ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT ) ? + OUString( RTL_CONSTASCII_USTRINGPARAM("CharAutoStyleName") ): + OUString( RTL_CONSTASCII_USTRINGPARAM("ParaAutoStyleName") ); + try + { + if ( xInfo->hasPropertyByName( sAutoProp ) ) + rPropSet->setPropertyValue( sAutoProp, makeAny(GetAutoName()) ); + else + bAutomatic = false; + } + catch( const RuntimeException& ) { throw; } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + bAutomatic = false; + } + } + } + if( bAutomatic ) + xImpPrMap->CheckSpecialContext( GetProperties(), rPropSet, aContextIDs ); + else + xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs ); + + // have we found a combined characters + sal_Int32 nIndex = aContextIDs[0].nIndex; + if ( nIndex != -1 ) + { + Any& rAny = GetProperties()[nIndex].maValue; + sal_Bool bVal = *(sal_Bool*)rAny.getValue(); + bHasCombinedCharactersLetter = bVal; + } + + // keep-together: the application default is different from + // the file format default. Hence, if we always set this + // value; if we didn't find one, we'll set to false, the file + // format default. + // border-model: same + if( IsDefaultStyle() && GetFamily() == XML_STYLE_FAMILY_TABLE_ROW ) + { + OUString sIsSplitAllowed = + OUString( RTL_CONSTASCII_USTRINGPARAM( "IsSplitAllowed" ) ); + DBG_ASSERT( rPropSet->getPropertySetInfo()->hasPropertyByName( sIsSplitAllowed ), + "property missing?" ); + rPropSet->setPropertyValue( sIsSplitAllowed, + (aContextIDs[1].nIndex == -1) + ? makeAny( false ) + : GetProperties()[aContextIDs[1].nIndex].maValue ); + } + + if( IsDefaultStyle() && GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE ) + { + OUString sCollapsingBorders( + OUString( RTL_CONSTASCII_USTRINGPARAM( "CollapsingBorders" ) ) ); + DBG_ASSERT( rPropSet->getPropertySetInfo()->hasPropertyByName( sCollapsingBorders ), + "property missing?" ); + rPropSet->setPropertyValue( sCollapsingBorders, + (aContextIDs[2].nIndex == -1) + ? makeAny( false ) + : GetProperties()[aContextIDs[2].nIndex].maValue ); + } + + + // check for StarBats and StarMath fonts + + // iterate over aContextIDs entries 3..6 + for ( sal_Int32 i = 3; i < 7; i++ ) + { + nIndex = aContextIDs[i].nIndex; + if ( nIndex != -1 ) + { + // Found! + struct XMLPropertyState& rState = GetProperties()[nIndex]; + Any rAny = rState.maValue; + sal_Int32 nMapperIndex = rState.mnIndex; + + // Now check for font name in rState and set corrected value, + // if necessary. + OUString sFontName; + rAny >>= sFontName; + if ( sFontName.getLength() > 0 ) + { + OUString sStarBats( RTL_CONSTASCII_USTRINGPARAM("StarBats" ) ); + OUString sStarMath( RTL_CONSTASCII_USTRINGPARAM("StarMath" ) ); + if ( sFontName.equalsIgnoreAsciiCase( sStarBats ) || + sFontName.equalsIgnoreAsciiCase( sStarMath ) ) + { + // construct new value + sFontName = OUString( + RTL_CONSTASCII_USTRINGPARAM("StarSymbol") ); + Any aAny( rAny ); + aAny <<= sFontName; + + // get property set mapper + UniReference<XMLPropertySetMapper> rPropMapper = + xImpPrMap->getPropertySetMapper(); + + // set property + OUString rPropertyName( + rPropMapper->GetEntryAPIName(nMapperIndex) ); + if ( xInfo->hasPropertyByName( rPropertyName ) ) + { + rPropSet->setPropertyValue( rPropertyName, aAny ); + } + } + // else: "normal" style name -> no correction is necessary + } + // else: no style name found -> illegal value -> ignore + } + } + } +} diff --git a/xmloff/source/text/txtvfldi.cxx b/xmloff/source/text/txtvfldi.cxx new file mode 100644 index 000000000000..64a8b37a3539 --- /dev/null +++ b/xmloff/source/text/txtvfldi.cxx @@ -0,0 +1,1474 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +/** @#file + * + * export of all variable related text fields (and database display field) + */ +#include "txtvfldi.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/xmlnumi.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include "xmloff/i18nmap.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlement.hxx> +#include <com/sun/star/text/SetVariableType.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/xml/sax/XAttributeList.hpp> + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <tools/debug.hxx> + + +// service names +static const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField."; +static const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster."; +static const sal_Char sAPI_input[] = "Input"; +static const sal_Char sAPI_input_user[] = "InputUser"; +static const sal_Char sAPI_get_expression[] = "GetExpression"; +static const sal_Char sAPI_set_expression[] = "SetExpression"; +static const sal_Char sAPI_user[] = "User"; +static const sal_Char sAPI_table_formula[] = "TableFormula"; +static const sal_Char sAPI_database[] = "com.sun.star.text.TextField.Database"; +static const sal_Char sAPI_fieldmaster_database[] = "com.sun.star.text.FieldMaster.Database"; + +// property names +static const sal_Char sAPI_hint[] = "Hint"; +static const sal_Char sAPI_help[] = "Help"; +static const sal_Char sAPI_tooltip[] = "Tooltip"; +static const sal_Char sAPI_content[] = "Content"; +static const sal_Char sAPI_sub_type[] = "SubType"; +static const sal_Char sAPI_is_expression[] = "IsExpression"; +static const sal_Char sAPI_is_input[] = "Input"; +static const sal_Char sAPI_is_show_formula[] = "IsShowFormula"; +static const sal_Char sAPI_numbering_type[] = "NumberingType"; +static const sal_Char sAPI_number_format[] = "NumberFormat"; +static const sal_Char sAPI_name[] = "Name"; +static const sal_Char sAPI_numbering_separator[] = "NumberingSeparator"; +static const sal_Char sAPI_chapter_numbering_level[]= "ChapterNumberingLevel"; +static const sal_Char sAPI_value[] = "Value"; +static const sal_Char sAPI_is_visible[] = "IsVisible"; +static const sal_Char sAPI_variable_subtype[] = "VariableSubtype"; +static const sal_Char sAPI_data_column_name[] = "DataColumnName"; +static const sal_Char sAPI_is_data_base_format[] = "DataBaseFormat"; +static const sal_Char sAPI_current_presentation[] = "CurrentPresentation"; +static const sal_Char sAPI_sequence_value[] = "SequenceValue"; +static const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage"; + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::style; +using namespace ::xmloff::token; + + + +// +// XMLVarFieldImportContext: superclass for all variable related fields +// + +TYPEINIT1( XMLVarFieldImportContext, XMLTextFieldImportContext ); + +XMLVarFieldImportContext::XMLVarFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + const sal_Char* pServiceName, sal_uInt16 nPrfx, + const OUString& rLocalName, + sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault, + sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible, + sal_Bool bIsDisplayFormula, + sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, + sal_Bool bPresentation) : + XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, rLocalName), + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)), + sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)), + sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM(sAPI_help)), + sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM(sAPI_tooltip)), + sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)), + sPropertyIsDisplayFormula(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_show_formula)), + sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)), + aValueHelper(rImport, rHlp, bType, bStyle, bValue, sal_False), + bDisplayFormula(sal_False), + bDisplayNone(sal_False), + bNameOK(sal_False), + bFormulaOK(sal_False), + bDescriptionOK(sal_False), + bHelpOK(sal_False), + bHintOK(sal_False), + bDisplayOK(sal_False), + bSetName(bName), + bSetFormula(bFormula), + bSetFormulaDefault(bFormulaDefault), + bSetDescription(bDescription), + bSetHelp(bHelp), + bSetHint(bHint), + bSetVisible(bVisible), + bSetDisplayFormula(bIsDisplayFormula), + bSetPresentation(bPresentation) +{ +} + +void XMLVarFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NAME: + sName = sAttrValue; + bNameOK = sal_True; + bValid = sal_True; // we assume: field with name is valid! + break; + case XML_TOK_TEXTFIELD_DESCRIPTION: + sDescription = sAttrValue; + bDescriptionOK = sal_True; + break; + case XML_TOK_TEXTFIELD_HELP: + sHelp = sAttrValue; + bHelpOK = true; + break; + case XML_TOK_TEXTFIELD_HINT: + sHint = sAttrValue; + bHintOK = true; + break; + case XML_TOK_TEXTFIELD_FORMULA: + { + OUString sTmp; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + _GetKeyByAttrName( sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sFormula = sTmp; + bFormulaOK = sal_True; + } + else + sFormula = sAttrValue; + } + break; + case XML_TOK_TEXTFIELD_DISPLAY: + if (IsXMLToken(sAttrValue, XML_FORMULA)) + { + bDisplayFormula = sal_True; + bDisplayNone = sal_False; + bDisplayOK = sal_True; + } + else if (IsXMLToken(sAttrValue, XML_VALUE)) + { + bDisplayFormula = sal_False; + bDisplayNone = sal_False; + bDisplayOK = sal_True; + } + else if (IsXMLToken(sAttrValue, XML_NONE)) + { + bDisplayFormula = sal_False; + bDisplayNone = sal_True; + bDisplayOK = sal_True; + } // else: no change + DBG_ASSERT(!(bDisplayFormula && bDisplayNone), + "illegal display values"); + break; + default: + // delegate all others to value helper + aValueHelper.ProcessAttribute(nAttrToken, sAttrValue); + break; + } +} + +void XMLVarFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // bSetName: not implemented + + if (bSetFormula) + { + if (!bFormulaOK && bSetFormulaDefault) + { + sFormula = GetContent(); + bFormulaOK = sal_True; + } + + if (bFormulaOK) + { + Any aAny; + aAny <<= sFormula; + xPropertySet->setPropertyValue(sPropertyContent, aAny); + } + } + + if (bSetDescription && bDescriptionOK) + { + Any aAny; + aAny <<= sDescription; + xPropertySet->setPropertyValue(sPropertyHint, aAny); + } + + if (bSetHelp && bHelpOK) + { + Any aAny; + aAny <<= sHelp; + xPropertySet->setPropertyValue(sPropertyHelp, aAny); + } + + if (bSetHint && bHintOK) + { + Any aAny; + aAny <<= sHint; + xPropertySet->setPropertyValue(sPropertyTooltip, aAny); + } + + if (bSetVisible && bDisplayOK) + { + Any aAny; + sal_Bool bTmp = ! (bDisplayNone && bDisplayOK); + aAny.setValue( &bTmp, ::getBooleanCppuType()); + xPropertySet->setPropertyValue(sPropertyIsVisible, aAny); + } + + // workaround for #no-bug#: display formula by default + if (xPropertySet->getPropertySetInfo()-> + hasPropertyByName(sPropertyIsDisplayFormula) && + !bSetDisplayFormula) + { + bDisplayFormula = sal_False; + bSetDisplayFormula = sal_True; + } + + + if (bSetDisplayFormula) + { + Any aAny; + sal_Bool bTmp = bDisplayFormula && bDisplayOK; + aAny.setValue( &bTmp, ::getBooleanCppuType()); + xPropertySet->setPropertyValue(sPropertyIsDisplayFormula, aAny); + } + + // delegate to value helper + aValueHelper.SetDefault(GetContent()); + aValueHelper.PrepareField(xPropertySet); + + // finally, set the curren presentation + if (bSetPresentation) + { + Any aAny; + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); + } +} + + + + + +// +// variable set fields +// + +TYPEINIT1( XMLSetVarFieldImportContext, XMLVarFieldImportContext ); + +XMLSetVarFieldImportContext::XMLSetVarFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + const sal_Char* pServiceName, sal_uInt16 nPrfx, + const OUString& rLocalName, VarType eVarType, + sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault, + sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible, sal_Bool bIsDisplayFormula, + sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bPresentation) : + XMLVarFieldImportContext(rImport, rHlp, pServiceName, + nPrfx, rLocalName, + bName, bFormula, bFormulaDefault, + bDescription, bHelp, bHint, bVisible, bIsDisplayFormula, + bType, bStyle, bValue, bPresentation), + eFieldType(eVarType) +{ +} + +void XMLSetVarFieldImportContext::EndElement() +{ + // should we call PrepareField on the field, or rather on it's master? + // currently: call on field (just like superclass) + // possible alternatives: call on master + // call field or master depending on variable + // PrepareMaster() in addition to PrepareField() + + DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!"); + + if (bValid) + { + DBG_ASSERT(GetName().getLength()>0, "variable name needed!"); + + // find field master + Reference<XPropertySet> xMaster; + if (FindFieldMaster(xMaster)) + { + // create field/Service + Reference<XPropertySet> xPropSet; + if (CreateField(xPropSet, OUString::createFromAscii(sAPI_textfield_prefix) + GetServiceName())) + { + Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY); + if (xDepTextField.is()) + { + // attach field to field master + xDepTextField->attachTextFieldMaster(xMaster); + + // attach field to document + Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY); + if (xTextContent.is()) + { + try { + // insert, set field properties and exit! + GetImportHelper().InsertTextContent(xTextContent); + PrepareField(xPropSet); + } catch (lang::IllegalArgumentException & /*e*/) + { + // ignore e: #i54023# + }; + return; + } + } + } + } + } + + // above: exit on success; so for all error cases we end up here! + // write element content + GetImportHelper().InsertString(GetContent()); +} + +sal_Bool XMLSetVarFieldImportContext::FindFieldMaster( + Reference<XPropertySet> & xMaster) +{ + // currently: delegate to XMLVariableDeclImportContext; + // shoud eventually go here + return XMLVariableDeclImportContext::FindFieldMaster(xMaster, + GetImport(), + GetImportHelper(), + GetName(), + eFieldType); +} + + + +// +// sequence field +// + +TYPEINIT1( XMLSequenceFieldImportContext, XMLSetVarFieldImportContext ); + +XMLSequenceFieldImportContext::XMLSequenceFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName) : + XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression, + nPrfx, rLocalName, VarTypeSequence, + // name, formula + sal_True, sal_True, sal_True, + sal_False, sal_False, sal_False, sal_False, + sal_False, + sal_False, sal_False, sal_False, sal_True), + + sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)), + sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_sequence_value)), + sNumFormat(OUString::valueOf(sal_Unicode('1'))), + sNumFormatSync(GetXMLToken(XML_FALSE)), + bRefNameOK(sal_False) +{ +} + +void XMLSequenceFieldImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_NUM_FORMAT: + sNumFormat = sAttrValue; + break; + case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC: + sNumFormatSync = sAttrValue; + break; + case XML_TOK_TEXTFIELD_REF_NAME: + sRefName = sAttrValue; + bRefNameOK = sal_True; + break; + default: + // delegate to super class (name, formula) + XMLSetVarFieldImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + } // switch +} + +void XMLSequenceFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // delegate to super class (formula) + XMLSetVarFieldImportContext::PrepareField(xPropertySet); + + // set format + sal_Int16 nNumType = NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, sNumFormatSync ); + Any aAny; + aAny <<= nNumType; + xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny); + + // handle reference name + if (bRefNameOK) + { + aAny = xPropertySet->getPropertyValue(sPropertySequenceValue); + sal_Int16 nValue = 0; + aAny >>= nValue; + GetImportHelper().InsertSequenceID(sRefName, GetName(), nValue); + } +} + + + +// +// variable set field +// + +TYPEINIT1( XMLVariableSetFieldImportContext, XMLSetVarFieldImportContext ); + +XMLVariableSetFieldImportContext::XMLVariableSetFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName) : + XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression, + nPrfx, rLocalName, VarTypeSimple, + // name, formula, value&type, style, + // display none + sal_True, sal_True, sal_True, + sal_False, sal_False, sal_False, + sal_True, sal_False, + sal_True, sal_True, sal_True, + sal_True), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)) +{ +} + +void XMLVariableSetFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // set type + Any aAny; + aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR); + xPropertySet->setPropertyValue(sPropertySubType, aAny); + + // the remainder is handled by super class + XMLSetVarFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// variable input field +// + +TYPEINIT1( XMLVariableInputFieldImportContext, XMLSetVarFieldImportContext ); + +XMLVariableInputFieldImportContext::XMLVariableInputFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& rLocalName) : + XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression, + nPrfx, rLocalName, VarTypeSimple, + // name, description, display none/formula, + // value&type, style, formula + sal_True, sal_True, sal_True, + sal_True, sal_True, sal_True, + sal_True, sal_False, + sal_True, sal_True, sal_True, + sal_True), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)), + sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_input)) +{ +} + +void XMLVariableInputFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // set type (input field) + Any aAny; + sal_Bool bTrue = sal_True; + aAny.setValue( &bTrue, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue(sPropertyIsInput, aAny); + + // set type + aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR); + xPropertySet->setPropertyValue(sPropertySubType, aAny); + + // the remainder is handled by super class + XMLSetVarFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// user field +// + +TYPEINIT1( XMLUserFieldImportContext, XMLSetVarFieldImportContext ); + +XMLUserFieldImportContext::XMLUserFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName) : + XMLSetVarFieldImportContext(rImport, rHlp, sAPI_user, nPrfx, + rLocalName, VarTypeUserField, + // name, display none/formula, style + sal_True, sal_False, sal_False, + sal_False, sal_False, sal_False, sal_True, + sal_True, + sal_False, sal_True, sal_False, + sal_False) +{ +} + + + +// +// user input field +// + +TYPEINIT1( XMLUserFieldInputImportContext, XMLVarFieldImportContext ); + +// bug: doesn't work (SO API lacking) +XMLUserFieldInputImportContext::XMLUserFieldInputImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& rLocalName) : + XMLVarFieldImportContext(rImport, rHlp, sAPI_input_user, + nPrfx, rLocalName, + // name, description, style + sal_True, sal_False, sal_False, + sal_True, sal_False, sal_False, + sal_False, sal_False, + sal_False /*???*/, sal_True, sal_False, + sal_False) +{ +} + +void XMLUserFieldInputImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + aAny <<= GetName(); + xPropertySet->setPropertyValue(sPropertyContent, aAny); + + // delegate to super class + XMLVarFieldImportContext::PrepareField(xPropertySet); +} + + +// +// variable get field +// + +TYPEINIT1( XMLVariableGetFieldImportContext, XMLVarFieldImportContext ); + +XMLVariableGetFieldImportContext::XMLVariableGetFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName) : + XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression, + nPrfx, rLocalName, + // name, style, display formula + sal_True, sal_False, sal_False, + sal_False, sal_False, sal_False, + sal_False, sal_True, + sal_True, sal_True, sal_False, + sal_True), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)) +{ +} + +void XMLVariableGetFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // set name + Any aAny; + aAny <<= GetName(); + xPropertySet->setPropertyValue(sPropertyContent, aAny); + + // the remainder is handled by super class + XMLVarFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// expression field +// + +TYPEINIT1( XMLExpressionFieldImportContext, XMLVarFieldImportContext ); + +XMLExpressionFieldImportContext::XMLExpressionFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName) : + XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression, + nPrfx, rLocalName, + // formula, type, style, display formula + sal_False, sal_True, sal_True, + sal_False, sal_False, sal_False, + sal_False, sal_True, + sal_True, sal_True, sal_False, + sal_True), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)) +{ + bValid = sal_True; // always valid +} + + +void XMLExpressionFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + sal_Int16 nSubType = SetVariableType::FORMULA; + Any aAny; + aAny <<= nSubType; + xPropertySet->setPropertyValue(sPropertySubType, aAny); + + // delegate to super class + XMLVarFieldImportContext::PrepareField(xPropertySet); +} + + + +// +// text input field +// + +TYPEINIT1( XMLTextInputFieldImportContext, XMLVarFieldImportContext ); + +XMLTextInputFieldImportContext::XMLTextInputFieldImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& sLocalName) : + XMLVarFieldImportContext(rImport, rHlp, sAPI_input, + nPrfx, sLocalName, + // description + sal_False, sal_False, sal_False, + sal_True, sal_True, sal_True, + sal_False, sal_False, + sal_False, sal_False, sal_False, + sal_False), + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)) +{ + bValid = sal_True; // always valid +} + +void XMLTextInputFieldImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + XMLVarFieldImportContext::PrepareField(xPropertySet); + + Any aAny; + aAny <<= GetContent(); + xPropertySet->setPropertyValue(sPropertyContent, aAny); +} + + +// +// table formula field +// + +TYPEINIT1( XMLTableFormulaImportContext, XMLTextFieldImportContext ); + +XMLTableFormulaImportContext::XMLTableFormulaImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, + const OUString& rLocalName) : + XMLTextFieldImportContext(rImport, rHlp, sAPI_table_formula, + nPrfx, rLocalName), + sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")), + sPropertyCurrentPresentation( + RTL_CONSTASCII_USTRINGPARAM("CurrentPresentation")), + aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_True), + sFormula(), + bIsShowFormula(sal_False) +{ +} + +XMLTableFormulaImportContext::~XMLTableFormulaImportContext() +{ +} + +void XMLTableFormulaImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, + const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_FORMULA: + aValueHelper.ProcessAttribute( nAttrToken, sAttrValue ); + bValid = sal_True; // we need a formula! + break; + + case XML_TOK_TEXTFIELD_DATA_STYLE_NAME: + aValueHelper.ProcessAttribute( nAttrToken, sAttrValue ); + break; + case XML_TOK_TEXTFIELD_DISPLAY: + if ( sAttrValue.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("formula")) ) + bIsShowFormula = sal_True; + break; + default: + // unknown attribute -> ignore + break; + } +} + +void XMLTableFormulaImportContext::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + // set format and formula + aValueHelper.PrepareField( xPropertySet ); + + Any aAny; + + // set 'show formula' and presentation + aAny.setValue( &bIsShowFormula, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue( sPropertyIsShowFormula, aAny ); + + aAny <<= GetContent(); + xPropertySet->setPropertyValue( sPropertyCurrentPresentation, aAny ); +} + + + +// +// variable declarations +// +// Should be adapted to XMLVarField-/XMLSetVarFieldImportContext scheme! +// + + + +// +// declaration containter import (<variable/user-field/sequence-decls>) +// + +TYPEINIT1( XMLVariableDeclsImportContext, SvXMLImportContext ); + +XMLVariableDeclsImportContext::XMLVariableDeclsImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& rLocalName, enum VarType eVarType) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + eVarDeclsContextType(eVarType), + rImportHelper(rHlp) +{ +} + +SvXMLImportContext* XMLVariableDeclsImportContext::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference<xml::sax::XAttributeList> & xAttrList ) +{ + enum XMLTokenEnum eElementName; + SvXMLImportContext* pImportContext = NULL; + + if( XML_NAMESPACE_TEXT == nPrefix ) + { + switch (eVarDeclsContextType) + { + case VarTypeSequence: + eElementName = XML_SEQUENCE_DECL; + break; + case VarTypeSimple: + eElementName = XML_VARIABLE_DECL; + break; + case VarTypeUserField: + eElementName = XML_USER_FIELD_DECL; + break; + default: + DBG_ERROR("unknown field type!"); + eElementName = XML_SEQUENCE_DECL; + break; + } + + if( IsXMLToken( rLocalName, eElementName ) ) + { + pImportContext = new XMLVariableDeclImportContext( + GetImport(), rImportHelper, nPrefix, rLocalName, xAttrList, + eVarDeclsContextType); + } + } + + // if no context was created, use default context + if (NULL == pImportContext) { + pImportContext = SvXMLImportContext::CreateChildContext(nPrefix, + rLocalName, + xAttrList); + } + + return pImportContext; +} + + + +// +// declaration import (<variable/user-field/sequence-decl> elements) +// + +TYPEINIT1( XMLVariableDeclImportContext, SvXMLImportContext ); + +XMLVariableDeclImportContext::XMLVariableDeclImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, + sal_uInt16 nPrfx, const OUString& rLocalName, + const Reference<xml::sax::XAttributeList> & xAttrList, + enum VarType eVarType) : + SvXMLImportContext(rImport, nPrfx, rLocalName), + // bug?? which properties for userfield/userfieldmaster + sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)), + sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)), + sPropertyNumberingLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_numbering_level)), + sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_separator)), + sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_expression)), + aValueHelper(rImport, rHlp, sal_True, sal_False, sal_True, sal_False), + nNumLevel(-1), cSeparationChar('.') +{ + if ( (XML_NAMESPACE_TEXT == nPrfx) && + ( ( IsXMLToken( rLocalName, XML_SEQUENCE_DECL )) || + ( IsXMLToken( rLocalName, XML_VARIABLE_DECL)) || + ( IsXMLToken( rLocalName, XML_USER_FIELD_DECL)) )) { + + // TODO: check validity (need name!) + + // parse attributes + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 i=0; i<nLength; i++) { + + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + sal_uInt16 nToken = rHlp. + GetTextFieldAttrTokenMap().Get(nPrefix, sLocalName); + + switch (nToken) + { + case XML_TOK_TEXTFIELD_NAME: + sName = xAttrList->getValueByIndex(i); + break; + case XML_TOK_TEXTFIELD_NUMBERING_LEVEL: + { + sal_Int32 nLevel; + sal_Bool bRet = SvXMLUnitConverter::convertNumber( + nLevel, xAttrList->getValueByIndex(i), 0, + GetImport().GetTextImport()->GetChapterNumbering()-> + getCount()); + if (bRet) + { + nNumLevel = static_cast< sal_Int8 >( nLevel-1 ); // API numbers -1..9 + } + break; + } + case XML_TOK_TEXTFIELD_NUMBERING_SEPARATOR: + cSeparationChar = + (sal_Char)xAttrList->getValueByIndex(i).toChar(); + break; + + default: + // delegate to value helper + aValueHelper.ProcessAttribute(nToken, + xAttrList->getValueByIndex(i)); + break; + } + } + + Reference<XPropertySet> xFieldMaster; + if (FindFieldMaster(xFieldMaster, GetImport(), rHlp, + sName, eVarType)) + { + // now we have a field master: process attributes! + Any aAny; + + switch (eVarType) + { + case VarTypeSequence: + aAny <<= nNumLevel; + xFieldMaster->setPropertyValue(sPropertyNumberingLevel, aAny); + + if (nNumLevel >= 0) + { + OUString sStr(&cSeparationChar, 1); + aAny <<= sStr; + xFieldMaster->setPropertyValue( + sPropertyNumberingSeparator, aAny); + } + break; + case VarTypeSimple: + { + // set string or non-string SubType (#93192#) + // The SubType was already set in the FindFieldMaster + // method, but it needs to be adjusted if it's a string. + aAny <<= aValueHelper.IsStringValue() + ? SetVariableType::STRING : SetVariableType::VAR; + xFieldMaster->setPropertyValue(sPropertySubType, aAny); + } + break; + case VarTypeUserField: + { + sal_Bool bTmp = !aValueHelper.IsStringValue(); + aAny.setValue(&bTmp, ::getBooleanCppuType()); + xFieldMaster->setPropertyValue(sPropertyIsExpression, aAny); + aValueHelper.PrepareField(xFieldMaster); + break; + } + default: + DBG_ERROR("unkown varfield type"); + } // switch + } // else: no field master found/constructed + } // else: no sequence-decl +} + + + +sal_Bool XMLVariableDeclImportContext::FindFieldMaster( + Reference<XPropertySet> & xMaster, SvXMLImport& rImport, + XMLTextImportHelper& rImportHelper, + const OUString& sVarName, enum VarType eVarType) +{ + static sal_Int32 nCollisionCount = 0; + + // rename field + // currently: no family in use! Use 0. + OUString sName = rImportHelper.GetRenameMap().Get( + sal::static_int_cast< USHORT >(eVarType), sVarName); + + // get text fields supplier and field masters + Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(), + UNO_QUERY); + Reference<container::XNameAccess> xFieldMasterNameAccess( + xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY); + + OUStringBuffer sBuffer; + sBuffer.appendAscii(sAPI_fieldmaster_prefix); + sBuffer.appendAscii(sAPI_set_expression); + sBuffer.appendAscii("."); + sBuffer.append(sName); + OUString sVarServiceName = sBuffer.makeStringAndClear(); + + sBuffer.appendAscii(sAPI_fieldmaster_prefix); + sBuffer.appendAscii(sAPI_user); + sBuffer.appendAscii("."); + sBuffer.append(sName); + OUString sUserServiceName = sBuffer.makeStringAndClear(); + + if (xFieldMasterNameAccess->hasByName(sVarServiceName)) { + // variable field master already in document + + Any aAny = xFieldMasterNameAccess->getByName(sVarServiceName); + aAny >>= xMaster; + + aAny = xMaster->getPropertyValue( + // sPropertySubType + OUString::createFromAscii(sAPI_sub_type) + ); + sal_Int16 nType = 0; + aAny >>= nType; + + enum VarType eFMVarType = + (SetVariableType::SEQUENCE == nType) ? + VarTypeSequence : VarTypeSimple; + + if (eFMVarType != eVarType) + { + OUString sNew; + + // FIXME! cant find if name is taken already!!!! + + nCollisionCount++; + OUStringBuffer aBuf; + aBuf.append(sName); + aBuf.appendAscii("_renamed_"); + aBuf.append(nCollisionCount); + sNew = aBuf.makeStringAndClear(); + + rImportHelper.GetRenameMap().Add( + sal::static_int_cast< USHORT >(eVarType), sName, sNew); + + // call FindFieldMaster recursively to create new master + return FindFieldMaster(xMaster, rImport, rImportHelper, + sNew, eVarType); + } + } else if (xFieldMasterNameAccess->hasByName(sUserServiceName)) { + // user field: get field master + Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName); + aAny >>= xMaster; + + if (VarTypeUserField != eVarType) { + // find new name that is not taken + OUString sNew; + + // FIXME! cant find if name is taken already!!!! + + nCollisionCount++; + OUStringBuffer aBuf; + aBuf.append(sName); + aBuf.appendAscii("_renamed_"); + aBuf.append(nCollisionCount); + sNew = aBuf.makeStringAndClear(); + + rImportHelper.GetRenameMap().Add( + sal::static_int_cast< USHORT >(eVarType), sName, sNew); + + // call FindFieldMaster recursively to create new master + return FindFieldMaster(xMaster, rImport, rImportHelper, + sNew, eVarType); + } + } else { + // field name not used: create field master + + // import -> model is MultiServiceFactory -> createInstance + Reference<lang::XMultiServiceFactory> + xFactory(rImport.GetModel(),UNO_QUERY); + if( xFactory.is() ) { + + OUStringBuffer sService; + sService.appendAscii(sAPI_fieldmaster_prefix); + sService.appendAscii((eVarType==VarTypeUserField) ? + sAPI_user : sAPI_set_expression); + Reference<XInterface> xIfc = + xFactory->createInstance( sService.makeStringAndClear() ); + if (xIfc.is()) { + Reference<XPropertySet> xTmp( xIfc, UNO_QUERY ); + xMaster = xTmp; + + // set name + Any aAny; + aAny <<= sName; + xMaster->setPropertyValue( + // sPropertyName + OUString::createFromAscii(sAPI_name) + , aAny); + + if (eVarType != VarTypeUserField) { + // set subtype for setexp field + + aAny <<= ((eVarType == VarTypeSimple) ? + SetVariableType::VAR : + SetVariableType::SEQUENCE); + xMaster->setPropertyValue( + // sPropertySubType + OUString::createFromAscii(sAPI_sub_type) + , aAny); + } // else : user field: no subtype + + } else { + return sal_False; + } + } else { + return sal_False; + } + } + + DBG_ASSERT(xMaster.is(), "no field master found!?!"); + return sal_True; +} + + +// +// Database Display field import +// + + +TYPEINIT1( XMLDatabaseDisplayImportContext, XMLDatabaseFieldImportContext ); + +XMLDatabaseDisplayImportContext::XMLDatabaseDisplayImportContext( + SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx, + const OUString& rLocalName) : + XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database, + nPrfx, rLocalName, false), + sPropertyColumnName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_column_name)), + sPropertyDatabaseFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_data_base_format)), + sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)), + sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)), + aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_False), + bColumnOK(sal_False), + bDisplay( sal_True ), + bDisplayOK( sal_False ) +{ +} + +void XMLDatabaseDisplayImportContext::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_COLUMN_NAME: + sColumnName = sAttrValue; + bColumnOK = sal_True; + break; + case XML_TOK_TEXTFIELD_DISPLAY: + { + sal_Bool bNone = IsXMLToken( sAttrValue, XML_NONE ); + sal_Bool bValue = IsXMLToken( sAttrValue, XML_VALUE ); + bDisplay = bValue; + bDisplayOK = bNone || bValue; + } + break; + case XML_TOK_TEXTFIELD_DATABASE_NAME: + case XML_TOK_TEXTFIELD_TABLE_NAME: + case XML_TOK_TEXTFIELD_TABLE_TYPE: + // handled by super class + XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, + sAttrValue); + break; + default: + // remainder handled by value helper + aValueHelper.ProcessAttribute(nAttrToken, sAttrValue); + break; + } + + bValid = bTableOK && bDatabaseOK && bColumnOK; +} + +void XMLDatabaseDisplayImportContext::EndElement() +{ + // we have an EndElement of our own, because database fields need + // to be attached to a field master before they can be inserted into + // the document. Database stuff (database, table, column) all goes + // to the field master, value & style go to the field. + + if (bValid) + { + + // so here goes: we start with the master + Reference<XPropertySet> xMaster; + + // create and prepare field master first + if (CreateField(xMaster, + OUString(RTL_CONSTASCII_USTRINGPARAM( + sAPI_fieldmaster_database)))) + { + Any aAny; + aAny <<= sColumnName; + xMaster->setPropertyValue(sPropertyColumnName, aAny); + + // fieldmaster takes database, table and column name + XMLDatabaseFieldImportContext::PrepareField(xMaster); + + // create field + Reference<XPropertySet> xField; + if (CreateField(xField, + OUString(RTL_CONSTASCII_USTRINGPARAM( + sAPI_database)))) + { + // attach field master + Reference<XDependentTextField> xDepField(xField, UNO_QUERY); + if (xDepField.is()) + { + // attach field to field master + xDepField->attachTextFieldMaster(xMaster); + + // attach field to document + Reference<XTextContent> xTextContent(xField, UNO_QUERY); + if (xTextContent.is()) + { + // insert, set field properties and exit! + GetImportHelper().InsertTextContent(xTextContent); + + // prepare field: format from database? + sal_Bool bTmp = !aValueHelper.IsFormatOK(); + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xField->setPropertyValue(sPropertyDatabaseFormat,aAny); + + // value, value-type and format done by value helper + aValueHelper.PrepareField(xField); + + // visibility + if( bDisplayOK ) + { + aAny.setValue( &bDisplay, ::getBooleanCppuType() ); + xField->setPropertyValue(sPropertyIsVisible, aAny); + } + + // set presentation + aAny <<= GetContent(); + xField->setPropertyValue(sPropertyCurrentPresentation, + aAny); + + // success! + return; + } + } + } + } + } + + // above: exit on success; so for all error cases we end up here! + // write element content + GetImportHelper().InsertString(GetContent()); +} + + +// +// value import helper +// + +enum ValueType +{ + XML_VALUE_TYPE_STRING, + XML_VALUE_TYPE_FLOAT, + XML_VALUE_TYPE_CURRENCY, + XML_VALUE_TYPE_PERCENTAGE, + XML_VALUE_TYPE_DATE, + XML_VALUE_TYPE_TIME, + XML_VALUE_TYPE_BOOLEAN +}; + +static SvXMLEnumMapEntry __READONLY_DATA aValueTypeMap[] = +{ + { XML_FLOAT, XML_VALUE_TYPE_FLOAT }, + { XML_CURRENCY, XML_VALUE_TYPE_CURRENCY }, + { XML_PERCENTAGE, XML_VALUE_TYPE_PERCENTAGE }, + { XML_DATE, XML_VALUE_TYPE_DATE }, + { XML_TIME, XML_VALUE_TYPE_TIME }, + { XML_BOOLEAN, XML_VALUE_TYPE_BOOLEAN }, + { XML_STRING, XML_VALUE_TYPE_STRING }, + { XML_TOKEN_INVALID, 0 } +}; + +XMLValueImportHelper::XMLValueImportHelper( + SvXMLImport& rImprt, + XMLTextImportHelper& rHlp, + sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bFormula) : + sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)), + sPropertyValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_value)), + sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)), + sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)), + + rImport(rImprt), + rHelper(rHlp), + + fValue(0.0), + nFormatKey(0), + bIsDefaultLanguage(sal_True), + + bStringType(sal_False), + bFormatOK(sal_False), + bTypeOK(sal_False), + bStringValueOK(sal_False), + bFloatValueOK(sal_False), + bFormulaOK(sal_False), + + bSetType(bType), + bSetValue(bValue), + bSetStyle(bStyle), + bSetFormula(bFormula), + + bStringDefault(sal_True), + bFormulaDefault(sal_True) +{ +} + +XMLValueImportHelper::~XMLValueImportHelper() +{ +} + +void XMLValueImportHelper::ProcessAttribute( + sal_uInt16 nAttrToken, const OUString& sAttrValue ) +{ + switch (nAttrToken) + { + case XML_TOK_TEXTFIELD_VALUE_TYPE: + { + // convert enum + sal_uInt16 nTmp = 0; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + nTmp, sAttrValue, aValueTypeMap); + + if (bRet) { + ValueType eValueType = (ValueType)nTmp; + + bTypeOK = sal_True; + + switch (eValueType) + { + case XML_VALUE_TYPE_STRING: + bStringType = sal_True; + break; + case XML_VALUE_TYPE_FLOAT: + case XML_VALUE_TYPE_CURRENCY: + case XML_VALUE_TYPE_PERCENTAGE: + case XML_VALUE_TYPE_DATE: + case XML_VALUE_TYPE_TIME: + case XML_VALUE_TYPE_BOOLEAN: + bStringType = sal_False; + break; + + default: + DBG_ERROR("unknown value type"); + bTypeOK = sal_False; + } + } + break; + } + + case XML_TOK_TEXTFIELD_VALUE: + { + double fTmp; + sal_Bool bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue); + if (bRet) { + bFloatValueOK = sal_True; + fValue = fTmp; + } + break; + } + + case XML_TOK_TEXTFIELD_TIME_VALUE: + { + double fTmp; + sal_Bool bRet = SvXMLUnitConverter::convertTime(fTmp,sAttrValue); + if (bRet) { + bFloatValueOK = sal_True; + fValue = fTmp; + } + break; + } + + case XML_TOK_TEXTFIELD_DATE_VALUE: + { + double fTmp; + sal_Bool bRet = rImport.GetMM100UnitConverter(). + convertDateTime(fTmp,sAttrValue); + if (bRet) { + bFloatValueOK = sal_True; + fValue = fTmp; + } + break; + } + + case XML_TOK_TEXTFIELD_BOOL_VALUE: + { + sal_Bool bTmp; + sal_Bool bRet = SvXMLUnitConverter::convertBool(bTmp,sAttrValue); + if (bRet) { + bFloatValueOK = sal_True; + fValue = (bTmp ? 1.0 : 0.0); + } + else + { + double fTmp; + bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue); + if (bRet) { + bFloatValueOK = sal_True; + fValue = fTmp; + } + } + break; + } + + case XML_TOK_TEXTFIELD_STRING_VALUE: + sValue = sAttrValue; + bStringValueOK = sal_True; + break; + + case XML_TOK_TEXTFIELD_FORMULA: + { + OUString sTmp; + sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + _GetKeyByAttrName( sAttrValue, &sTmp, sal_False ); + if( XML_NAMESPACE_OOOW == nPrefix ) + { + sFormula = sTmp; + bFormulaOK = sal_True; + } + else + sFormula = sAttrValue; + } + break; + + case XML_TOK_TEXTFIELD_DATA_STYLE_NAME: + { + sal_Int32 nKey = rHelper.GetDataStyleKey( + sAttrValue, &bIsDefaultLanguage); + if (-1 != nKey) + { + nFormatKey = nKey; + bFormatOK = sal_True; + } + break; + } + } // switch +} + +void XMLValueImportHelper::PrepareField( + const Reference<XPropertySet> & xPropertySet) +{ + Any aAny; + + if (bSetType) + { + // ??? how to set type? + } + + if (bSetFormula) + { + aAny <<= (!bFormulaOK && bFormulaDefault) ? sDefault : sFormula; + xPropertySet->setPropertyValue(sPropertyContent, aAny); + } + + // format/style + if (bSetStyle && bFormatOK) + { + aAny <<= nFormatKey; + xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny); + + if( xPropertySet->getPropertySetInfo()-> + hasPropertyByName( sPropertyIsFixedLanguage ) ) + { + sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage; + aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() ); + xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny ); + } + } + + // value: string or float + if (bSetValue) + { + if (bStringType) + { + aAny <<= (!bStringValueOK && bStringDefault) ? sDefault : sValue; + xPropertySet->setPropertyValue(sPropertyContent, aAny); + } + else + { + aAny <<= fValue; + xPropertySet->setPropertyValue(sPropertyValue, aAny); + } + } +} + |