summaryrefslogtreecommitdiffstats
path: root/xmloff/source/xforms
diff options
context:
space:
mode:
Diffstat (limited to 'xmloff/source/xforms')
-rw-r--r--xmloff/source/xforms/SchemaContext.cxx76
-rw-r--r--xmloff/source/xforms/SchemaContext.hxx62
-rw-r--r--xmloff/source/xforms/SchemaRestrictionContext.cxx362
-rw-r--r--xmloff/source/xforms/SchemaRestrictionContext.hxx69
-rw-r--r--xmloff/source/xforms/SchemaSimpleTypeContext.cxx87
-rw-r--r--xmloff/source/xforms/SchemaSimpleTypeContext.hxx63
-rw-r--r--xmloff/source/xforms/TokenContext.cxx133
-rw-r--r--xmloff/source/xforms/TokenContext.hxx93
-rw-r--r--xmloff/source/xforms/XFormsBindContext.cxx173
-rw-r--r--xmloff/source/xforms/XFormsBindContext.hxx66
-rw-r--r--xmloff/source/xforms/XFormsInstanceContext.cxx138
-rw-r--r--xmloff/source/xforms/XFormsInstanceContext.hxx76
-rw-r--r--xmloff/source/xforms/XFormsModelContext.cxx135
-rw-r--r--xmloff/source/xforms/XFormsModelContext.hxx63
-rw-r--r--xmloff/source/xforms/XFormsModelExport.hxx36
-rw-r--r--xmloff/source/xforms/XFormsSubmissionContext.cxx162
-rw-r--r--xmloff/source/xforms/XFormsSubmissionContext.hxx62
-rw-r--r--xmloff/source/xforms/xformsapi.cxx297
-rw-r--r--xmloff/source/xforms/xformsapi.hxx78
-rw-r--r--xmloff/source/xforms/xformsexport.cxx795
-rw-r--r--xmloff/source/xforms/xformsimport.cxx187
21 files changed, 3213 insertions, 0 deletions
diff --git a/xmloff/source/xforms/SchemaContext.cxx b/xmloff/source/xforms/SchemaContext.cxx
new file mode 100644
index 000000000..6c19cbfa0
--- /dev/null
+++ b/xmloff/source/xforms/SchemaContext.cxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "SchemaContext.hxx"
+
+#include "SchemaSimpleTypeContext.hxx"
+
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/xmltkmap.hxx>
+
+#include <com/sun/star/xforms/XDataTypeRepository.hpp>
+
+using com::sun::star::uno::Reference;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xforms::XDataTypeRepository;
+using namespace xmloff::token;
+
+
+static const SvXMLTokenMapEntry aAttributes[] =
+{
+ XML_TOKEN_MAP_END
+};
+
+static const SvXMLTokenMapEntry aChildren[] =
+{
+ TOKEN_MAP_ENTRY( XSD, SIMPLETYPE ),
+ XML_TOKEN_MAP_END
+};
+
+SchemaContext::SchemaContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XDataTypeRepository>& rRepository ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
+ mxRepository( rRepository )
+{
+}
+
+void SchemaContext::HandleAttribute(
+ sal_uInt16,
+ const OUString& )
+{
+}
+
+SvXMLImportContext* SchemaContext::HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& )
+{
+ if ( nToken == XML_SIMPLETYPE )
+ return new SchemaSimpleTypeContext( GetImport(), nPrefix, rLocalName,
+ mxRepository );
+ return nullptr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/SchemaContext.hxx b/xmloff/source/xforms/SchemaContext.hxx
new file mode 100644
index 000000000..e679d2855
--- /dev/null
+++ b/xmloff/source/xforms/SchemaContext.hxx
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMACONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMACONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XDataTypeRepository; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the data type declarations from an xsd:schema element */
+class SchemaContext : public TokenContext
+{
+ css::uno::Reference<css::xforms::XDataTypeRepository> mxRepository;
+
+public:
+ SchemaContext( SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLName,
+ const css::uno::Reference<css::xforms::XDataTypeRepository>& rRepository );
+
+ // implement TokenContext methods:
+
+protected:
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/SchemaRestrictionContext.cxx b/xmloff/source/xforms/SchemaRestrictionContext.cxx
new file mode 100644
index 000000000..cafaab50b
--- /dev/null
+++ b/xmloff/source/xforms/SchemaRestrictionContext.cxx
@@ -0,0 +1,362 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "SchemaRestrictionContext.hxx"
+#include "xformsapi.hxx"
+
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/xmltkmap.hxx>
+#include <xmloff/xmlimp.hxx>
+
+#include <sax/tools/converter.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/Duration.hpp>
+#include <com/sun/star/xforms/XDataTypeRepository.hpp>
+#include <com/sun/star/xsd/DataTypeClass.hpp>
+#include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
+
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+
+
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::Exception;
+using com::sun::star::uno::Any;
+using com::sun::star::uno::makeAny;
+using namespace com::sun::star;
+using com::sun::star::util::Duration;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xforms::XDataTypeRepository;
+using namespace xmloff::token;
+
+
+static const SvXMLTokenMapEntry aAttributes[] =
+{
+ TOKEN_MAP_ENTRY( NONE, BASE ),
+ XML_TOKEN_MAP_END
+};
+
+static const SvXMLTokenMapEntry aChildren[] =
+{
+ TOKEN_MAP_ENTRY( XSD, LENGTH ),
+ TOKEN_MAP_ENTRY( XSD, MINLENGTH ),
+ TOKEN_MAP_ENTRY( XSD, MAXLENGTH ),
+ TOKEN_MAP_ENTRY( XSD, MININCLUSIVE ),
+ TOKEN_MAP_ENTRY( XSD, MINEXCLUSIVE ),
+ TOKEN_MAP_ENTRY( XSD, MAXINCLUSIVE ),
+ TOKEN_MAP_ENTRY( XSD, MAXEXCLUSIVE ),
+ TOKEN_MAP_ENTRY( XSD, PATTERN ),
+ // ??? XML_ENUMERATION
+ TOKEN_MAP_ENTRY( XSD, WHITESPACE ),
+ TOKEN_MAP_ENTRY( XSD, TOTALDIGITS ),
+ TOKEN_MAP_ENTRY( XSD, FRACTIONDIGITS ),
+ XML_TOKEN_MAP_END
+};
+
+
+SchemaRestrictionContext::SchemaRestrictionContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ Reference<css::xforms::XDataTypeRepository> const & rRepository,
+ const OUString& sTypeName ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
+ mxRepository( rRepository ),
+ msTypeName( sTypeName ),
+ msBaseName()
+{
+ SAL_WARN_IF( !mxRepository.is(), "xmloff", "need repository" );
+}
+
+void SchemaRestrictionContext::CreateDataType()
+{
+ // only do something if we don't have a data type already
+ if( mxDataType.is() )
+ return;
+
+ SAL_WARN_IF( msBaseName.isEmpty(), "xmloff", "no base name?" );
+ SAL_WARN_IF( !mxRepository.is(), "xmloff", "no repository?" );
+
+ try
+ {
+ mxDataType =
+ mxRepository->cloneDataType(
+ xforms_getBasicTypeName( mxRepository,
+ GetImport().GetNamespaceMap(),
+ msBaseName ),
+ msTypeName );
+ }
+ catch( const Exception& )
+ {
+ OSL_FAIL( "exception during type creation" );
+ }
+ SAL_WARN_IF( !mxDataType.is(), "xmloff", "can't create type" );
+}
+
+void SchemaRestrictionContext::HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ if( nToken == XML_BASE )
+ {
+ msBaseName = rValue;
+ }
+}
+
+typedef Any (*convert_t)( const OUString& );
+
+static Any xforms_string( const OUString& rValue )
+{
+ return makeAny( rValue );
+}
+
+static Any xforms_int32( const OUString& rValue )
+{
+ sal_Int32 nValue;
+ bool bSuccess = ::sax::Converter::convertNumber( nValue, rValue );
+ return bSuccess ? makeAny( nValue ) : Any();
+}
+
+static Any xforms_int16( const OUString& rValue )
+{
+ sal_Int32 nValue;
+ bool bSuccess = ::sax::Converter::convertNumber( nValue, rValue );
+ return bSuccess ? makeAny( static_cast<sal_Int16>( nValue ) ) : Any();
+}
+
+static Any xforms_whitespace( const OUString& rValue )
+{
+ Any aValue;
+ if( IsXMLToken( rValue, XML_PRESERVE ) )
+ aValue <<= css::xsd::WhiteSpaceTreatment::Preserve;
+ else if( IsXMLToken( rValue, XML_REPLACE ) )
+ aValue <<= css::xsd::WhiteSpaceTreatment::Replace;
+ else if( IsXMLToken( rValue, XML_COLLAPSE ) )
+ aValue <<= css::xsd::WhiteSpaceTreatment::Collapse;
+ return aValue;
+}
+
+static Any xforms_double( const OUString& rValue )
+{
+ double fValue;
+ bool bSuccess = ::sax::Converter::convertDouble( fValue, rValue );
+ return bSuccess ? makeAny( fValue ) : Any();
+}
+
+static Any xforms_date( const OUString& rValue )
+{
+ Any aAny;
+
+ // parse ISO date
+ sal_Int32 nPos1 = rValue.indexOf( '-' );
+ sal_Int32 nPos2 = rValue.indexOf( '-', nPos1 + 1 );
+ if( nPos1 > 0 && nPos2 > 0 )
+ {
+ util::Date aDate;
+ aDate.Year = static_cast<sal_uInt16>(
+ rValue.copy( 0, nPos1 ).toInt32() );
+ aDate.Month = static_cast<sal_uInt16>(
+ rValue.copy( nPos1 + 1, nPos2 - nPos1 - 1 ).toInt32() );
+ aDate.Day = static_cast<sal_uInt16>(
+ rValue.copy( nPos2 + 1 ).toInt32() );
+ aAny <<= aDate;
+ }
+ return aAny;
+}
+
+static Any xforms_dateTime( const OUString& rValue )
+{
+ util::DateTime aDateTime;
+ bool const bSuccess = ::sax::Converter::parseDateTime(aDateTime, rValue);
+ return bSuccess ? makeAny( aDateTime ) : Any();
+}
+
+static Any xforms_time( const OUString& rValue )
+{
+ Any aAny;
+ Duration aDuration;
+ if (::sax::Converter::convertDuration( aDuration, rValue ))
+ {
+ css::util::Time aTime;
+ aTime.Hours = aDuration.Hours;
+ aTime.Minutes = aDuration.Minutes;
+ aTime.Seconds = aDuration.Seconds;
+ aTime.NanoSeconds = aDuration.NanoSeconds;
+ aAny <<= aTime;
+ }
+ return aAny;
+}
+
+
+SvXMLImportContext* SchemaRestrictionContext::HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& xAttrList )
+{
+ // find value
+ OUString sValue;
+ sal_Int16 nLength = xAttrList->getLength();
+ for( sal_Int16 n = 0; n < nLength; n++ )
+ {
+ if( IsXMLToken( xAttrList->getNameByIndex( n ), XML_VALUE ) )
+ sValue = xAttrList->getValueByIndex( n );
+ }
+
+ // determine property name + suitable converter
+ OUString sPropertyName;
+ convert_t pConvert = nullptr;
+ switch( nToken )
+ {
+ case XML_LENGTH:
+ sPropertyName = "Length";
+ pConvert = &xforms_int32;
+ break;
+ case XML_MINLENGTH:
+ sPropertyName = "MinLength";
+ pConvert = &xforms_int32;
+ break;
+ case XML_MAXLENGTH:
+ sPropertyName = "MaxLength";
+ pConvert = &xforms_int32;
+ break;
+ case XML_TOTALDIGITS:
+ sPropertyName = "TotalDigits";
+ pConvert = &xforms_int32;
+ break;
+ case XML_FRACTIONDIGITS:
+ sPropertyName = "FractionDigits";
+ pConvert = &xforms_int32;
+ break;
+ case XML_PATTERN:
+ sPropertyName = "Pattern";
+ pConvert = &xforms_string;
+ break;
+ case XML_WHITESPACE:
+ sPropertyName = "WhiteSpace";
+ pConvert = &xforms_whitespace;
+ break;
+ case XML_MININCLUSIVE:
+ case XML_MINEXCLUSIVE:
+ case XML_MAXINCLUSIVE:
+ case XML_MAXEXCLUSIVE:
+ {
+ // these attributes are mapped to different properties.
+ // To determine the property name, we use an attribute
+ // dependent prefix and a type dependent suffix. The
+ // converter is only type dependent.
+
+ // first, attribute-dependent prefix
+ switch( nToken )
+ {
+ case XML_MININCLUSIVE:
+ sPropertyName = "MinInclusive";
+ break;
+ case XML_MINEXCLUSIVE:
+ sPropertyName = "MinExclusive";
+ break;
+ case XML_MAXINCLUSIVE:
+ sPropertyName = "MaxInclusive";
+ break;
+ case XML_MAXEXCLUSIVE:
+ sPropertyName = "MaxExclusive";
+ break;
+ }
+
+ // second, type-dependent suffix + converter
+ switch( xforms_getTypeClass( mxRepository,
+ GetImport().GetNamespaceMap(),
+ msBaseName ) )
+ {
+ case css::xsd::DataTypeClass::DECIMAL:
+ case css::xsd::DataTypeClass::DOUBLE:
+ case css::xsd::DataTypeClass::FLOAT:
+ sPropertyName += "Double";
+ pConvert = &xforms_double;
+ break;
+ case css::xsd::DataTypeClass::DATETIME:
+ sPropertyName += "DateTime";
+ pConvert = &xforms_dateTime;
+ break;
+ case css::xsd::DataTypeClass::DATE:
+ sPropertyName += "Date";
+ pConvert = &xforms_date;
+ break;
+ case css::xsd::DataTypeClass::TIME:
+ sPropertyName += "Time";
+ pConvert = &xforms_time;
+ break;
+ case css::xsd::DataTypeClass::gYear:
+ case css::xsd::DataTypeClass::gDay:
+ case css::xsd::DataTypeClass::gMonth:
+ sPropertyName += "Int";
+ pConvert = &xforms_int16;
+ break;
+
+ case css::xsd::DataTypeClass::STRING:
+ case css::xsd::DataTypeClass::anyURI:
+ case css::xsd::DataTypeClass::BOOLEAN:
+ // invalid: These shouldn't have min/max-inclusive
+ break;
+
+ /* data types not yet supported:
+ case css::xsd::DataTypeClass::DURATION:
+ case css::xsd::DataTypeClass::gYearMonth:
+ case css::xsd::DataTypeClass::gMonthDay:
+ case css::xsd::DataTypeClass::hexBinary:
+ case css::xsd::DataTypeClass::base64Binary:
+ case css::xsd::DataTypeClass::QName:
+ case css::xsd::DataTypeClass::NOTATION:
+ */
+ }
+ }
+ break;
+
+ default:
+ OSL_FAIL( "unknown facet" );
+ }
+
+ // finally, set the property
+ CreateDataType();
+ if( mxDataType.is()
+ && !sPropertyName.isEmpty()
+ && pConvert != nullptr
+ && mxDataType->getPropertySetInfo()->hasPropertyByName(sPropertyName) )
+ {
+ try
+ {
+ mxDataType->setPropertyValue( sPropertyName, pConvert( sValue ) );
+ }
+ catch( const Exception& )
+ {
+ ; // can't set property? Then ignore.
+ }
+ }
+
+ return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/SchemaRestrictionContext.hxx b/xmloff/source/xforms/SchemaRestrictionContext.hxx
new file mode 100644
index 000000000..d5c86a3fb
--- /dev/null
+++ b/xmloff/source/xforms/SchemaRestrictionContext.hxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMARESTRICTIONCONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMARESTRICTIONCONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XDataTypeRepository; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xsd:restriction element */
+class SchemaRestrictionContext : public TokenContext
+{
+ css::uno::Reference<css::xforms::XDataTypeRepository> mxRepository;
+ css::uno::Reference<css::beans::XPropertySet> mxDataType;
+ OUString const msTypeName;
+ OUString msBaseName;
+
+public:
+ SchemaRestrictionContext( SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLName,
+ css::uno::Reference<css::xforms::XDataTypeRepository> const & rRepository,
+ const OUString& sTypeName );
+
+private:
+ // create mxDataType (if not already present)
+ void CreateDataType();
+
+ // implement TokenContext methods:
+
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/SchemaSimpleTypeContext.cxx b/xmloff/source/xforms/SchemaSimpleTypeContext.cxx
new file mode 100644
index 000000000..0c01874ef
--- /dev/null
+++ b/xmloff/source/xforms/SchemaSimpleTypeContext.cxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "SchemaSimpleTypeContext.hxx"
+
+#include "SchemaRestrictionContext.hxx"
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/xmltkmap.hxx>
+
+#include <osl/diagnose.h>
+
+using com::sun::star::uno::Reference;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xforms::XDataTypeRepository;
+using namespace xmloff::token;
+
+
+static const SvXMLTokenMapEntry aAttributes[] =
+{
+ TOKEN_MAP_ENTRY( NONE, NAME ),
+ XML_TOKEN_MAP_END
+};
+
+static const SvXMLTokenMapEntry aChildren[] =
+{
+ TOKEN_MAP_ENTRY( XSD, RESTRICTION ),
+ XML_TOKEN_MAP_END
+};
+
+SchemaSimpleTypeContext::SchemaSimpleTypeContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XDataTypeRepository>& rRepository ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
+ mxRepository( rRepository )
+{
+}
+
+void SchemaSimpleTypeContext::HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ if( nToken == XML_NAME )
+ {
+ msTypeName = rValue;
+ }
+}
+
+SvXMLImportContext* SchemaSimpleTypeContext::HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& )
+{
+ switch( nToken )
+ {
+ case XML_RESTRICTION:
+ return new SchemaRestrictionContext( GetImport(),
+ nPrefix, rLocalName,
+ mxRepository, msTypeName );
+ break;
+ }
+
+ return nullptr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/SchemaSimpleTypeContext.hxx b/xmloff/source/xforms/SchemaSimpleTypeContext.hxx
new file mode 100644
index 000000000..da0e4f365
--- /dev/null
+++ b/xmloff/source/xforms/SchemaSimpleTypeContext.hxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMASIMPLETYPECONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_SCHEMASIMPLETYPECONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XDataTypeRepository; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xsd:simpleType element */
+class SchemaSimpleTypeContext : public TokenContext
+{
+ css::uno::Reference<css::xforms::XDataTypeRepository> mxRepository;
+ OUString msTypeName;
+
+public:
+ SchemaSimpleTypeContext( SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLName,
+ const css::uno::Reference<css::xforms::XDataTypeRepository>& rRepository );
+
+ // implement TokenContext methods:
+
+protected:
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/TokenContext.cxx b/xmloff/source/xforms/TokenContext.cxx
new file mode 100644
index 000000000..71215c439
--- /dev/null
+++ b/xmloff/source/xforms/TokenContext.cxx
@@ -0,0 +1,133 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+#include <sal/log.hxx>
+
+#include "TokenContext.hxx"
+#include <xmloff/xmltkmap.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlerror.hxx>
+
+#include <algorithm>
+
+using com::sun::star::uno::Reference;
+using com::sun::star::xml::sax::XAttributeList;
+
+const SvXMLTokenMapEntry aEmptyMap[1] =
+{
+ XML_TOKEN_MAP_END
+};
+
+TokenContext::TokenContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const SvXMLTokenMapEntry* pAttributes,
+ const SvXMLTokenMapEntry* pChildren )
+ : SvXMLImportContext( rImport, nPrefix, rLocalName ),
+ mpAttributes( pAttributes ),
+ mpChildren( pChildren )
+{
+}
+
+void TokenContext::StartElement(
+ const Reference<XAttributeList>& xAttributeList )
+{
+ // iterate over attributes
+ // - if in map: call HandleAttribute
+ // - xmlns:... : ignore
+ // - other: warning
+ SAL_WARN_IF( mpAttributes == nullptr, "xmloff", "no token map for attributes" );
+ SvXMLTokenMap aMap( mpAttributes );
+
+ sal_Int16 nCount = xAttributeList->getLength();
+ for( sal_Int16 i = 0; i < nCount; i++ )
+ {
+ // get key/local-name pair from namespace map
+ OUString sLocalName;
+ sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
+ GetKeyByAttrName( xAttributeList->getNameByIndex(i), &sLocalName );
+
+ // get token from token map
+ sal_uInt16 nToken = aMap.Get( nPrefix, sLocalName );
+
+ // and the value...
+ const OUString& rValue = xAttributeList->getValueByIndex(i);
+
+ if( nToken != XML_TOK_UNKNOWN )
+ {
+ HandleAttribute( nToken, rValue );
+ }
+ else if( nPrefix != XML_NAMESPACE_XMLNS )
+ {
+ // error handling, for all attribute that are not
+ // namespace declarations
+ GetImport().SetError( XMLERROR_UNKNOWN_ATTRIBUTE,
+ sLocalName, rValue);
+ }
+ }
+}
+
+SvXMLImportContextRef TokenContext::CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& xAttrList )
+{
+ // call HandleChild for elements in token map. Ignore other content.
+
+ SvXMLImportContext* pContext = nullptr;
+
+ SAL_WARN_IF( mpChildren == nullptr, "xmloff", "no token map for child elements" );
+ SvXMLTokenMap aMap( mpChildren );
+ sal_uInt16 nToken = aMap.Get( nPrefix, rLocalName );
+ if( nToken != XML_TOK_UNKNOWN )
+ {
+ // call handle child, and pass down arguments
+ pContext = HandleChild( nToken, nPrefix, rLocalName, xAttrList );
+ }
+
+ // error handling: create default context and generate warning
+ if( pContext == nullptr )
+ {
+ GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, rLocalName );
+ }
+ return pContext;
+}
+
+static bool lcl_IsWhiteSpace( sal_Unicode c )
+{
+ return c == ' '
+ || c == u'\x0009'
+ || c == u'\x000A'
+ || c == u'\x000D';
+}
+
+void TokenContext::Characters( const OUString& rCharacters )
+{
+ // get iterators for string data
+ const sal_Unicode* pBegin = rCharacters.getStr();
+ const sal_Unicode* pEnd = &( pBegin[ rCharacters.getLength() ] );
+
+ // raise error if non-whitespace character is found
+ if( !::std::all_of( pBegin, pEnd, lcl_IsWhiteSpace ) )
+ GetImport().SetError( XMLERROR_UNKNOWN_CHARACTERS, rCharacters );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/TokenContext.hxx b/xmloff/source/xforms/TokenContext.hxx
new file mode 100644
index 000000000..f52fb362d
--- /dev/null
+++ b/xmloff/source/xforms/TokenContext.hxx
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_TOKENCONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_TOKENCONTEXT_HXX
+
+#include <xmloff/xmlictxt.hxx>
+#include <xmloff/xmltkmap.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace uno { template<typename T> class Reference; }
+}
+
+class SvXMLImport;
+
+#define TOKEN_MAP_ENTRY(NAMESPACE,TOKEN) { XML_NAMESPACE_##NAMESPACE, xmloff::token::XML_##TOKEN, xmloff::token::XML_##TOKEN }
+
+extern const SvXMLTokenMapEntry aEmptyMap[1];
+
+/** handle attributes through an SvXMLTokenMap */
+class TokenContext : public SvXMLImportContext
+{
+protected:
+ const SvXMLTokenMapEntry* mpAttributes; /// static token map
+ const SvXMLTokenMapEntry* mpChildren; /// static token map
+
+public:
+ TokenContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const SvXMLTokenMapEntry* pAttributes,
+ const SvXMLTokenMapEntry* pChildren );
+
+ // implement SvXMLImportContext methods:
+
+ /** call HandleAttribute for each attribute in the token map;
+ * create a warning for all others. Classes that wish to override
+ * StartElement need to call the parent method. */
+ virtual void StartElement(
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+
+ /** call HandleChild for each child element in the token map;
+ * create a warning for all others. Classes that wish to override
+ * CreateChildContext may want to call the parent method for
+ * handling of defaults. */
+ virtual SvXMLImportContextRef CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+
+ /** Create a warning for all non-namespace character
+ * content. Classes that wish to deal with character content have
+ * to override this method anyway, and will thus get rid of the
+ * warnings. */
+ virtual void Characters( const OUString& rChars ) override;
+
+protected:
+ /** will be called for each attribute */
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) = 0;
+
+ /** will be called for each child element */
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+
+ // the following attributes are mainly to be used for child
+ // context creation
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) = 0;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsBindContext.cxx b/xmloff/source/xforms/XFormsBindContext.cxx
new file mode 100644
index 000000000..c975e8b65
--- /dev/null
+++ b/xmloff/source/xforms/XFormsBindContext.cxx
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "XFormsBindContext.hxx"
+
+#include "xformsapi.hxx"
+
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlerror.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmltkmap.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/nmspmap.hxx>
+
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/xforms/XModel2.hpp>
+
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::makeAny;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::container::XNameContainer;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xforms::XModel2;
+using namespace xmloff::token;
+
+
+static const struct SvXMLTokenMapEntry aAttributeMap[] =
+{
+ TOKEN_MAP_ENTRY( NONE, NODESET ),
+ TOKEN_MAP_ENTRY( NONE, ID ),
+ TOKEN_MAP_ENTRY( NONE, READONLY ),
+ TOKEN_MAP_ENTRY( NONE, RELEVANT ),
+ TOKEN_MAP_ENTRY( NONE, REQUIRED ),
+ TOKEN_MAP_ENTRY( NONE, CONSTRAINT ),
+ TOKEN_MAP_ENTRY( NONE, CALCULATE ),
+ TOKEN_MAP_ENTRY( NONE, TYPE ),
+ XML_TOKEN_MAP_END
+};
+
+// helper function; see below
+static void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
+ Reference<XNameContainer> const & );
+
+XFormsBindContext::XFormsBindContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XModel2>& xModel ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
+ mxModel( xModel )
+{
+ // attach binding to model
+ mxBinding = mxModel->createBinding();
+ SAL_WARN_IF( !mxBinding.is(), "xmloff", "can't create binding" );
+ mxModel->getBindings()->insert( makeAny( mxBinding ) );
+}
+
+void XFormsBindContext::HandleAttribute( sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ switch( nToken )
+ {
+ case XML_NODESET:
+ xforms_setValue( mxBinding, "BindingExpression", rValue );
+ break;
+ case XML_ID:
+ xforms_setValue( mxBinding, "BindingID", rValue );
+ break;
+ case XML_READONLY:
+ xforms_setValue( mxBinding, "ReadonlyExpression", rValue );
+ break;
+ case XML_RELEVANT:
+ xforms_setValue( mxBinding, "RelevantExpression", rValue );
+ break;
+ case XML_REQUIRED:
+ xforms_setValue( mxBinding, "RequiredExpression", rValue );
+ break;
+ case XML_CONSTRAINT:
+ xforms_setValue( mxBinding, "ConstraintExpression", rValue );
+ break;
+ case XML_CALCULATE:
+ xforms_setValue( mxBinding, "CalculateExpression", rValue );
+ break;
+ case XML_TYPE:
+ xforms_setValue( mxBinding, "Type",
+ makeAny( xforms_getTypeName( mxModel->getDataTypeRepository(),
+ GetImport().GetNamespaceMap(),
+ rValue ) ) );
+ break;
+ default:
+ OSL_FAIL( "should not happen" );
+ break;
+ }
+}
+
+void XFormsBindContext::StartElement(
+ const Reference<XAttributeList>& xAttributeList )
+{
+ // we need to register the namespaces
+ Reference<XNameContainer> xContainer(
+ mxBinding->getPropertyValue( "BindingNamespaces" ),
+ UNO_QUERY );
+
+ SAL_WARN_IF( !xContainer.is(), "xmloff", "binding should have a namespace container" );
+ if( xContainer.is() )
+ lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer);
+
+ // call super-class for attribute handling
+ TokenContext::StartElement( xAttributeList );
+}
+
+/** will be called for each child element */
+SvXMLImportContext* XFormsBindContext::HandleChild(
+ sal_uInt16,
+ sal_uInt16,
+ const OUString&,
+ const Reference<XAttributeList>& )
+{
+ OSL_FAIL( "no children supported" );
+ return nullptr;
+}
+
+
+static void lcl_fillNamespaceContainer(
+ const SvXMLNamespaceMap& aMap,
+ Reference<XNameContainer> const & xContainer )
+{
+ sal_uInt16 nKeyIter = aMap.GetFirstKey();
+ do
+ {
+ // get prefix and namespace
+ const OUString& sPrefix = aMap.GetPrefixByKey( nKeyIter );
+ const OUString& sNamespace = aMap.GetNameByKey( nKeyIter );
+
+ // as a hack, we will ignore our own 'default' namespaces
+ SAL_WARN_IF( sPrefix.isEmpty(), "xmloff", "no prefix?" );
+ if( !sPrefix.startsWith("_") &&
+ nKeyIter >= XML_NAMESPACE_META_SO52)
+ {
+ // insert prefix (use replace if already known)
+ if( xContainer->hasByName( sPrefix ) )
+ xContainer->replaceByName( sPrefix, makeAny( sNamespace ) );
+ else
+ xContainer->insertByName( sPrefix, makeAny( sNamespace ) );
+ }
+
+ // proceed to next
+ nKeyIter = aMap.GetNextKey( nKeyIter );
+ }
+ while( nKeyIter != XML_NAMESPACE_UNKNOWN );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsBindContext.hxx b/xmloff/source/xforms/XFormsBindContext.hxx
new file mode 100644
index 000000000..86a11f5ff
--- /dev/null
+++ b/xmloff/source/xforms/XFormsBindContext.hxx
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSBINDCONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSBINDCONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XModel2; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xforms:binding element */
+class XFormsBindContext : public TokenContext
+{
+ const css::uno::Reference<css::xforms::XModel2> mxModel;
+ css::uno::Reference<css::beans::XPropertySet> mxBinding;
+
+public:
+ XFormsBindContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xforms::XModel2>& xModel );
+
+ // implement SvXMLImportContext & TokenContext methods:
+
+ virtual void StartElement(
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+
+protected:
+ virtual void HandleAttribute( sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nNamespace,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsInstanceContext.cxx b/xmloff/source/xforms/XFormsInstanceContext.cxx
new file mode 100644
index 000000000..e1a81a3f6
--- /dev/null
+++ b/xmloff/source/xforms/XFormsInstanceContext.cxx
@@ -0,0 +1,138 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "XFormsInstanceContext.hxx"
+
+#include <DomBuilderContext.hxx>
+
+#include <rtl/ustring.hxx>
+#include <sal/log.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
+#include <com/sun/star/xforms/XModel2.hpp>
+#include <osl/diagnose.h>
+
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlerror.hxx>
+#include <xmloff/nmspmap.hxx>
+
+
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::makeAny;
+using com::sun::star::uno::Sequence;
+using com::sun::star::xforms::XModel2;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::xml::sax::XAttributeList;
+
+using xmloff::token::XML_SRC;
+using xmloff::token::XML_ID;
+
+static const SvXMLTokenMapEntry aAttributes[] =
+{
+ TOKEN_MAP_ENTRY( NONE, SRC ),
+ TOKEN_MAP_ENTRY( NONE, ID ),
+ XML_TOKEN_MAP_END
+};
+
+XFormsInstanceContext::XFormsInstanceContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XModel2> & xModel ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ),
+ mxModel( xModel )
+{
+ SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" );
+}
+
+SvXMLImportContextRef XFormsInstanceContext::CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& )
+{
+ SvXMLImportContext* pContext = nullptr;
+
+ // only the first element child of an xforms:instance element
+ // is used as an instance. The other children remainder must be
+ // ignored.
+ if( mxInstance.is() )
+ {
+ GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName );
+ }
+ else
+ {
+ // create new DomBuilderContext. Save reference to tree in Model.
+ DomBuilderContext* pInstance =
+ new DomBuilderContext( GetImport(), nPrefix, rLocalName );
+ mxInstance = pInstance->getTree();
+ pContext = pInstance;
+ }
+
+ SAL_WARN_IF( pContext == nullptr, "xmloff", "no context!" );
+ return pContext;
+
+}
+
+void XFormsInstanceContext::EndElement()
+{
+ Sequence<PropertyValue> aSequence( 3 );
+ PropertyValue* pSequence = aSequence.getArray();
+ pSequence[0].Name = "Instance";
+ pSequence[0].Value <<= mxInstance;
+ pSequence[1].Name = "ID";
+ pSequence[1].Value <<= msId;
+ pSequence[2].Name = "URL";
+ pSequence[2].Value <<= msURL;
+
+ mxModel->getInstances()->insert( makeAny( aSequence ) );
+}
+
+
+void XFormsInstanceContext::HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ switch( nToken )
+ {
+ case XML_SRC:
+ msURL = rValue;
+ break;
+ case XML_ID:
+ msId = rValue;
+ break;
+ default:
+ OSL_FAIL( "should not happen" );
+ break;
+ }
+}
+
+SvXMLImportContext* XFormsInstanceContext::HandleChild(
+ sal_uInt16,
+ sal_uInt16,
+ const OUString&,
+ const Reference<XAttributeList>& )
+{
+ OSL_FAIL( "to be handled by CreateChildContext" );
+ return nullptr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsInstanceContext.hxx b/xmloff/source/xforms/XFormsInstanceContext.hxx
new file mode 100644
index 000000000..46c443b5b
--- /dev/null
+++ b/xmloff/source/xforms/XFormsInstanceContext.hxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSINSTANCECONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSINSTANCECONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace xml::dom { class XDocument; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XModel2; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xforms:instance element */
+class XFormsInstanceContext : public TokenContext
+{
+ css::uno::Reference<css::xforms::XModel2> mxModel;
+ css::uno::Reference<css::xml::dom::XDocument> mxInstance;
+ OUString msId;
+ OUString msURL;
+
+public:
+ XFormsInstanceContext( SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLName,
+ const css::uno::Reference<css::xforms::XModel2> & xModel );
+
+ // implement SvXMLImportContext & TokenContext methods:
+ // We override CreateChildContext, because we want to read
+ // arbitrary DOM elements. For the attributes, we use the
+ // TokenContext mechanism.
+
+ virtual SvXMLImportContextRef CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList >& xAttrList ) override;
+
+ virtual void EndElement() override;
+
+protected:
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nNamespace,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsModelContext.cxx b/xmloff/source/xforms/XFormsModelContext.cxx
new file mode 100644
index 000000000..e846e54b5
--- /dev/null
+++ b/xmloff/source/xforms/XFormsModelContext.cxx
@@ -0,0 +1,135 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "XFormsModelContext.hxx"
+
+#include "XFormsBindContext.hxx"
+#include "XFormsSubmissionContext.hxx"
+#include "XFormsInstanceContext.hxx"
+#include "SchemaContext.hxx"
+#include "xformsapi.hxx"
+
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlerror.hxx>
+
+#include <osl/diagnose.h>
+
+#include <com/sun/star/util/XUpdatable.hpp>
+#include <com/sun/star/xforms/XModel2.hpp>
+
+
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::util::XUpdatable;
+using namespace com::sun::star::uno;
+using namespace xmloff::token;
+
+
+static const SvXMLTokenMapEntry aAttributes[] =
+{
+ TOKEN_MAP_ENTRY( NONE, ID ),
+ TOKEN_MAP_ENTRY( NONE, SCHEMA ),
+ XML_TOKEN_MAP_END
+};
+
+static const SvXMLTokenMapEntry aChildren[] =
+{
+ TOKEN_MAP_ENTRY( XFORMS, INSTANCE ),
+ TOKEN_MAP_ENTRY( XFORMS, BIND ),
+ TOKEN_MAP_ENTRY( XFORMS, SUBMISSION ),
+ TOKEN_MAP_ENTRY( XSD, SCHEMA ),
+ XML_TOKEN_MAP_END
+};
+
+
+XFormsModelContext::XFormsModelContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ),
+ mxModel( xforms_createXFormsModel() )
+{
+}
+
+void XFormsModelContext::HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ switch( nToken )
+ {
+ case XML_ID:
+ mxModel->setPropertyValue( "ID", makeAny( rValue ) );
+ break;
+ case XML_SCHEMA:
+ GetImport().SetError( XMLERROR_XFORMS_NO_SCHEMA_SUPPORT );
+ break;
+ default:
+ OSL_FAIL( "this should not happen" );
+ break;
+ }
+}
+
+SvXMLImportContext* XFormsModelContext::HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& )
+{
+ SvXMLImportContext* pContext = nullptr;
+
+ switch( nToken )
+ {
+ case XML_INSTANCE:
+ pContext = new XFormsInstanceContext( GetImport(), nPrefix, rLocalName,
+ mxModel );
+ break;
+ case XML_BIND:
+ pContext = new XFormsBindContext( GetImport(), nPrefix, rLocalName,
+ mxModel );
+ break;
+ case XML_SUBMISSION:
+ pContext = new XFormsSubmissionContext( GetImport(), nPrefix,
+ rLocalName, mxModel );
+ break;
+ case XML_SCHEMA:
+ pContext = new SchemaContext(
+ GetImport(), nPrefix, rLocalName, mxModel->getDataTypeRepository() );
+ break;
+ default:
+ OSL_FAIL( "Boooo!" );
+ break;
+ }
+
+ return pContext;
+}
+
+void XFormsModelContext::EndElement()
+{
+ // update before putting model into document
+ Reference<XUpdatable> xUpdate( mxModel, UNO_QUERY );
+ if( xUpdate.is() )
+ xUpdate->update();
+
+ GetImport().initXForms();
+ xforms_addXFormsModel( GetImport().GetModel(), mxModel );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsModelContext.hxx b/xmloff/source/xforms/XFormsModelContext.hxx
new file mode 100644
index 000000000..ff71c0795
--- /dev/null
+++ b/xmloff/source/xforms/XFormsModelContext.hxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSMODELCONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSMODELCONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/xforms/XModel2.hpp>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xforms:model element */
+class XFormsModelContext : public TokenContext
+{
+ css::uno::Reference<css::xforms::XModel2> mxModel;
+
+public:
+ XFormsModelContext( SvXMLImport& rImport,
+ sal_uInt16 nPrfx,
+ const OUString& rLName );
+
+ // implement SvXMLImportContext & TokenContext methods:
+
+ virtual void EndElement() override;
+
+protected:
+ virtual void HandleAttribute(
+ sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsModelExport.hxx b/xmloff/source/xforms/XFormsModelExport.hxx
new file mode 100644
index 000000000..b809c7e31
--- /dev/null
+++ b/xmloff/source/xforms/XFormsModelExport.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSMODELEXPORT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSMODELEXPORT_HXX
+
+#include <sal/types.h>
+
+class SvXMLExport;
+namespace com::sun::star {
+ namespace uno { template<typename T> class Reference; }
+ namespace beans { class XPropertySet; }
+}
+
+void exportXFormsModel( SvXMLExport&,
+ const css::uno::Reference<css::beans::XPropertySet>& );
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsSubmissionContext.cxx b/xmloff/source/xforms/XFormsSubmissionContext.cxx
new file mode 100644
index 000000000..254c7b97b
--- /dev/null
+++ b/xmloff/source/xforms/XFormsSubmissionContext.cxx
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "XFormsSubmissionContext.hxx"
+
+#include "xformsapi.hxx"
+
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmltkmap.hxx>
+#include <xmloff/nmspmap.hxx>
+
+#include <sax/tools/converter.hxx>
+
+#include <com/sun/star/xforms/XModel2.hpp>
+
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xforms::XModel2;
+
+using namespace com::sun::star::uno;
+using namespace xmloff::token;
+
+
+static const struct SvXMLTokenMapEntry aAttributeMap[] =
+{
+ TOKEN_MAP_ENTRY( NONE, ID ),
+ TOKEN_MAP_ENTRY( NONE, BIND ),
+ TOKEN_MAP_ENTRY( NONE, REF ),
+ TOKEN_MAP_ENTRY( NONE, ACTION ),
+ TOKEN_MAP_ENTRY( NONE, METHOD ),
+ TOKEN_MAP_ENTRY( NONE, VERSION ),
+ TOKEN_MAP_ENTRY( NONE, INDENT ),
+ TOKEN_MAP_ENTRY( NONE, MEDIATYPE ),
+ TOKEN_MAP_ENTRY( NONE, ENCODING ),
+ TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ),
+ TOKEN_MAP_ENTRY( NONE, STANDALONE ),
+ TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ),
+ TOKEN_MAP_ENTRY( NONE, REPLACE ),
+ TOKEN_MAP_ENTRY( NONE, SEPARATOR ),
+ TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ),
+ XML_TOKEN_MAP_END
+};
+
+XFormsSubmissionContext::XFormsSubmissionContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XModel2>& xModel ) :
+ TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
+ mxSubmission()
+{
+ // register submission with model
+ SAL_WARN_IF( !xModel.is(), "xmloff", "need model" );
+ mxSubmission = xModel->createSubmission().get();
+ SAL_WARN_IF( !mxSubmission.is(), "xmloff", "can't create submission" );
+ xModel->getSubmissions()->insert( makeAny( mxSubmission ) );
+}
+
+namespace {
+
+Any toBool( const OUString& rValue )
+{
+ Any aValue;
+ bool bValue(false);
+ if (::sax::Converter::convertBool( bValue, rValue ))
+ {
+ aValue <<= bValue;
+ }
+ return aValue;
+}
+
+} // namespace
+
+void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken,
+ const OUString& rValue )
+{
+ switch( nToken )
+ {
+ case XML_ID:
+ xforms_setValue( mxSubmission, "ID", rValue );
+ break;
+ case XML_BIND:
+ xforms_setValue( mxSubmission, "Bind", rValue );
+ break;
+ case XML_REF:
+ xforms_setValue( mxSubmission, "Ref", rValue );
+ break;
+ case XML_ACTION:
+ xforms_setValue( mxSubmission, "Action", rValue );
+ break;
+ case XML_METHOD:
+ xforms_setValue( mxSubmission, "Method", rValue );
+ break;
+ case XML_VERSION:
+ xforms_setValue( mxSubmission, "Version", rValue );
+ break;
+ case XML_INDENT:
+ xforms_setValue( mxSubmission, "Indent", toBool( rValue ) );
+ break;
+ case XML_MEDIATYPE:
+ xforms_setValue( mxSubmission, "MediaType", rValue );
+ break;
+ case XML_ENCODING:
+ xforms_setValue( mxSubmission, "Encoding", rValue );
+ break;
+ case XML_OMIT_XML_DECLARATION:
+ xforms_setValue( mxSubmission, "OmitXmlDeclaration",
+ toBool( rValue ) );
+ break;
+ case XML_STANDALONE:
+ xforms_setValue( mxSubmission, "Standalone", toBool( rValue ) );
+ break;
+ case XML_CDATA_SECTION_ELEMENTS:
+ xforms_setValue( mxSubmission, "CDataSectionElement", rValue );
+ break;
+ case XML_REPLACE:
+ xforms_setValue( mxSubmission, "Replace", rValue );
+ break;
+ case XML_SEPARATOR:
+ xforms_setValue( mxSubmission, "Separator", rValue );
+ break;
+ case XML_INCLUDENAMESPACEPREFIXES:
+ xforms_setValue( mxSubmission, "IncludeNamespacePrefixes", rValue );
+ break;
+ default:
+ OSL_FAIL( "unknown attribute" );
+ break;
+ }
+}
+
+/** will be called for each child element */
+SvXMLImportContext* XFormsSubmissionContext::HandleChild(
+ sal_uInt16,
+ sal_uInt16,
+ const OUString&,
+ const Reference<XAttributeList>& )
+{
+ OSL_FAIL( "no children supported" );
+ return nullptr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/XFormsSubmissionContext.hxx b/xmloff/source/xforms/XFormsSubmissionContext.hxx
new file mode 100644
index 000000000..f1b1a9019
--- /dev/null
+++ b/xmloff/source/xforms/XFormsSubmissionContext.hxx
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSSUBMISSIONCONTEXT_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSSUBMISSIONCONTEXT_HXX
+
+#include "TokenContext.hxx"
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { class XPropertySet; }
+ namespace xforms { class XModel2; }
+}
+
+class SvXMLImport;
+class SvXMLImportContext;
+
+/** import the xforms:submission element */
+class XFormsSubmissionContext : public TokenContext
+{
+ css::uno::Reference<css::beans::XPropertySet> mxSubmission;
+
+public:
+ XFormsSubmissionContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xforms::XModel2>& xModel );
+
+ // implement TokenContext methods:
+
+protected:
+ virtual void HandleAttribute( sal_uInt16 nToken,
+ const OUString& rValue ) override;
+
+ virtual SvXMLImportContext* HandleChild(
+ sal_uInt16 nToken,
+ sal_uInt16 nNamespace,
+ const OUString& rLocalName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
+
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/xformsapi.cxx b/xmloff/source/xforms/xformsapi.cxx
new file mode 100644
index 000000000..80e80ebd7
--- /dev/null
+++ b/xmloff/source/xforms/xformsapi.cxx
@@ -0,0 +1,297 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "xformsapi.hxx"
+
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/xforms/XFormsSupplier.hpp>
+#include <com/sun/star/xforms/XDataTypeRepository.hpp>
+#include <com/sun/star/xforms/Model.hpp>
+#include <com/sun/star/xforms/XModel2.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/xsd/DataTypeClass.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <osl/diagnose.h>
+#include <sal/log.hxx>
+
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/xmltkmap.hxx>
+
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::UNO_QUERY_THROW;
+using com::sun::star::beans::XPropertySet;
+using com::sun::star::container::XNameAccess;
+using com::sun::star::xforms::XFormsSupplier;
+using com::sun::star::xforms::XDataTypeRepository;
+using com::sun::star::xforms::Model;
+using com::sun::star::xforms::XModel2;
+using com::sun::star::container::XNameContainer;
+using com::sun::star::uno::makeAny;
+using com::sun::star::uno::Any;
+using com::sun::star::uno::Exception;
+
+using namespace com::sun::star;
+using namespace xmloff::token;
+
+Reference<XModel2> xforms_createXFormsModel()
+{
+ Reference<XModel2> xModel = Model::create( comphelper::getProcessComponentContext() );
+
+ return xModel;
+}
+
+void xforms_addXFormsModel(
+ const Reference<frame::XModel>& xDocument,
+ const Reference<xforms::XModel2>& xModel )
+{
+ bool bSuccess = false;
+ try
+ {
+ Reference<XFormsSupplier> xSupplier( xDocument, UNO_QUERY );
+ if( xSupplier.is() )
+ {
+ Reference<XNameContainer> xForms = xSupplier->getXForms();
+ if( xForms.is() )
+ {
+ OUString sName;
+ xModel->getPropertyValue("ID") >>= sName;
+ xForms->insertByName( sName, makeAny( xModel ) );
+ bSuccess = true;
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ ; // no success!
+ }
+
+ // TODO: implement proper error handling
+ SAL_WARN_IF( !bSuccess, "xmloff", "can't import model" );
+}
+
+static Reference<XPropertySet> lcl_findXFormsBindingOrSubmission(
+ Reference<frame::XModel> const & xDocument,
+ const OUString& rBindingID,
+ bool bBinding )
+{
+ // find binding by iterating over all models, and look for the
+ // given binding ID
+
+ Reference<XPropertySet> xRet;
+ try
+ {
+ // get supplier
+ Reference<XFormsSupplier> xSupplier( xDocument, UNO_QUERY );
+ if( xSupplier.is() )
+ {
+ // get XForms models
+ Reference<XNameContainer> xForms = xSupplier->getXForms();
+ if( xForms.is() )
+ {
+ // iterate over all models
+ const Sequence<OUString> aNames = xForms->getElementNames();
+ for( const auto& rName : aNames )
+ {
+ Reference<xforms::XModel2> xModel(
+ xForms->getByName( rName ), UNO_QUERY );
+ if( xModel.is() )
+ {
+ // ask model for bindings
+ Reference<XNameAccess> xBindings(
+ bBinding
+ ? xModel->getBindings()
+ : xModel->getSubmissions(),
+ UNO_QUERY_THROW );
+
+ // finally, ask binding for name
+ if( xBindings->hasByName( rBindingID ) )
+ xRet.set( xBindings->getByName( rBindingID ),
+ UNO_QUERY );
+ }
+
+ if (xRet.is())
+ break;
+ }
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ ; // no success!
+ }
+
+ // TODO: if (!xRet.is()) rImport.SetError(...);
+
+ return xRet;
+}
+
+Reference<XPropertySet> xforms_findXFormsBinding(
+ Reference<frame::XModel> const & xDocument,
+ const OUString& rBindingID )
+{
+ return lcl_findXFormsBindingOrSubmission( xDocument, rBindingID, true );
+}
+
+Reference<XPropertySet> xforms_findXFormsSubmission(
+ Reference<frame::XModel> const & xDocument,
+ const OUString& rBindingID )
+{
+ return lcl_findXFormsBindingOrSubmission( xDocument, rBindingID, false );
+}
+
+void xforms_setValue( Reference<XPropertySet> const & xPropertySet,
+ const OUString& rName,
+ const Any& rAny )
+{
+ xPropertySet->setPropertyValue( rName, rAny );
+}
+
+#define TOKEN_MAP_ENTRY(NAMESPACE,TOKEN) { XML_NAMESPACE_##NAMESPACE, xmloff::token::XML_##TOKEN, xmloff::token::XML_##TOKEN }
+static const SvXMLTokenMapEntry aTypes[] =
+{
+ TOKEN_MAP_ENTRY( XSD, STRING ),
+ TOKEN_MAP_ENTRY( XSD, DECIMAL ),
+ TOKEN_MAP_ENTRY( XSD, DOUBLE ),
+ TOKEN_MAP_ENTRY( XSD, FLOAT ),
+ TOKEN_MAP_ENTRY( XSD, BOOLEAN ),
+ TOKEN_MAP_ENTRY( XSD, ANYURI ),
+ TOKEN_MAP_ENTRY( XSD, DATETIME_XSD ),
+ TOKEN_MAP_ENTRY( XSD, DATE ),
+ TOKEN_MAP_ENTRY( XSD, TIME ),
+ TOKEN_MAP_ENTRY( XSD, YEAR ),
+ TOKEN_MAP_ENTRY( XSD, MONTH ),
+ TOKEN_MAP_ENTRY( XSD, DAY ),
+ XML_TOKEN_MAP_END
+};
+
+sal_uInt16 xforms_getTypeClass(
+ const Reference<XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName )
+{
+ // translate name into token for local name
+ OUString sLocalName;
+ sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrValueQName(rXMLName, &sLocalName);
+ static const SvXMLTokenMap aMap( aTypes );
+ sal_uInt16 nToken = aMap.Get( nPrefix, sLocalName );
+
+ sal_uInt16 nTypeClass = css::xsd::DataTypeClass::STRING;
+ if( nToken != XML_TOK_UNKNOWN )
+ {
+ // we found an XSD name: then get the proper API name for it
+ SAL_WARN_IF( !xRepository.is(), "xmloff", "can't find type without repository");
+ switch( nToken )
+ {
+ case XML_STRING:
+ nTypeClass = css::xsd::DataTypeClass::STRING;
+ break;
+ case XML_ANYURI:
+ nTypeClass = css::xsd::DataTypeClass::anyURI;
+ break;
+ case XML_DECIMAL:
+ nTypeClass = css::xsd::DataTypeClass::DECIMAL;
+ break;
+ case XML_DOUBLE:
+ nTypeClass = css::xsd::DataTypeClass::DOUBLE;
+ break;
+ case XML_FLOAT:
+ nTypeClass = css::xsd::DataTypeClass::FLOAT;
+ break;
+ case XML_BOOLEAN:
+ nTypeClass = css::xsd::DataTypeClass::BOOLEAN;
+ break;
+ case XML_DATETIME_XSD:
+ nTypeClass = css::xsd::DataTypeClass::DATETIME;
+ break;
+ case XML_DATE:
+ nTypeClass = css::xsd::DataTypeClass::DATE;
+ break;
+ case XML_TIME:
+ nTypeClass = css::xsd::DataTypeClass::TIME;
+ break;
+ case XML_YEAR:
+ nTypeClass = css::xsd::DataTypeClass::gYear;
+ break;
+ case XML_DAY:
+ nTypeClass = css::xsd::DataTypeClass::gDay;
+ break;
+ case XML_MONTH:
+ nTypeClass = css::xsd::DataTypeClass::gMonth;
+ break;
+
+ /* data types not yet supported:
+ nTypeClass = css::xsd::DataTypeClass::DURATION;
+ nTypeClass = css::xsd::DataTypeClass::gYearMonth;
+ nTypeClass = css::xsd::DataTypeClass::gMonthDay;
+ nTypeClass = css::xsd::DataTypeClass::hexBinary;
+ nTypeClass = css::xsd::DataTypeClass::base64Binary;
+ nTypeClass = css::xsd::DataTypeClass::QName;
+ nTypeClass = css::xsd::DataTypeClass::NOTATION;
+ */
+ }
+ }
+
+ return nTypeClass;
+}
+
+
+OUString xforms_getTypeName(
+ const Reference<XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName )
+{
+ OUString sLocalName;
+ sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrValueQName(rXMLName, &sLocalName);
+ static const SvXMLTokenMap aMap( aTypes );
+ sal_uInt16 nToken = aMap.Get( nPrefix, sLocalName );
+ return ( nToken == XML_TOK_UNKNOWN )
+ ? rXMLName
+ : xforms_getBasicTypeName( xRepository, rNamespaceMap, rXMLName );
+}
+
+OUString xforms_getBasicTypeName(
+ const Reference<XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName )
+{
+ OUString sTypeName = rXMLName;
+ try
+ {
+ sTypeName =
+ xRepository->getBasicDataType(
+ xforms_getTypeClass( xRepository, rNamespaceMap, rXMLName ) )
+ ->getName();
+ }
+ catch( const Exception& )
+ {
+ OSL_FAIL( "exception during type creation" );
+ }
+ return sTypeName;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/xformsapi.hxx b/xmloff/source/xforms/xformsapi.hxx
new file mode 100644
index 000000000..442937641
--- /dev/null
+++ b/xmloff/source/xforms/xformsapi.hxx
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSAPI_HXX
+#define INCLUDED_XMLOFF_SOURCE_XFORMS_XFORMSAPI_HXX
+
+
+// this is a collection of several functions to make dealing with the XForms
+// API a little easier
+
+
+#include <com/sun/star/uno/Any.hxx>
+
+namespace com::sun::star {
+ namespace beans { class XPropertySet; }
+ namespace frame { class XModel; }
+ namespace uno { template<class A> class Reference; }
+ namespace xforms { class XDataTypeRepository; class XModel2; }
+}
+class SvXMLNamespaceMap;
+
+css::uno::Reference<css::xforms::XModel2> xforms_createXFormsModel();
+
+void xforms_addXFormsModel(
+ const css::uno::Reference<css::frame::XModel>& xDocument,
+ const css::uno::Reference<css::xforms::XModel2>& xModel );
+
+css::uno::Reference<css::beans::XPropertySet> xforms_findXFormsBinding( css::uno::Reference<css::frame::XModel> const &, const OUString& );
+
+css::uno::Reference<css::beans::XPropertySet> xforms_findXFormsSubmission( css::uno::Reference<css::frame::XModel> const &, const OUString& );
+
+void xforms_setValue(
+ css::uno::Reference<css::beans::XPropertySet> const & xPropSet,
+ const OUString& rName,
+ const css::uno::Any& rAny );
+
+template<typename T>
+void xforms_setValue(
+ css::uno::Reference<css::beans::XPropertySet>& xPropSet,
+ const OUString& rName,
+ T& aValue )
+{
+ xforms_setValue( xPropSet, rName, css::uno::makeAny( aValue ) );
+}
+
+sal_uInt16 xforms_getTypeClass(
+ const css::uno::Reference<css::xforms::XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName );
+
+OUString xforms_getTypeName(
+ const css::uno::Reference<css::xforms::XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName );
+
+OUString xforms_getBasicTypeName(
+ const css::uno::Reference<css::xforms::XDataTypeRepository>& xRepository,
+ const SvXMLNamespaceMap& rNamespaceMap,
+ const OUString& rXMLName );
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/xformsexport.cxx b/xmloff/source/xforms/xformsexport.cxx
new file mode 100644
index 000000000..f3356c938
--- /dev/null
+++ b/xmloff/source/xforms/xformsexport.cxx
@@ -0,0 +1,795 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <xmloff/xformsexport.hxx>
+
+#include "XFormsModelExport.hxx"
+
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <DomExport.hxx>
+
+#include <sax/tools/converter.hxx>
+
+#include <comphelper/processfactory.hxx>
+
+#include <tools/diagnose_ex.h>
+#include <sal/log.hxx>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/document/NamedPropertyValues.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
+#include <com/sun/star/form/binding/XBindableValue.hpp>
+#include <com/sun/star/form/binding/XListEntrySink.hpp>
+#include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
+#include <com/sun/star/xforms/XModel.hpp>
+#include <com/sun/star/xforms/XDataTypeRepository.hpp>
+#include <com/sun/star/xforms/XFormsSupplier.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
+#include <com/sun/star/xsd/DataTypeClass.hpp>
+#include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/Time.hpp>
+#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/Duration.hpp>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+using namespace xmloff::token;
+
+using com::sun::star::beans::XPropertySet;
+using com::sun::star::beans::XPropertySetInfo;
+using com::sun::star::container::XIndexAccess;
+using com::sun::star::container::XNameAccess;
+using com::sun::star::container::XNameContainer;
+using com::sun::star::container::XEnumerationAccess;
+using com::sun::star::container::XEnumeration;
+using com::sun::star::xml::dom::XDocument;
+using com::sun::star::form::binding::XBindableValue;
+using com::sun::star::form::binding::XListEntrySink;
+using com::sun::star::form::submission::XSubmissionSupplier;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::xforms::XDataTypeRepository;
+using com::sun::star::xforms::XFormsSupplier;
+using com::sun::star::util::Duration;
+
+void exportXForms( SvXMLExport& rExport )
+{
+ Reference<XFormsSupplier> xSupplier( rExport.GetModel(), UNO_QUERY );
+ if( xSupplier.is() )
+ {
+ Reference<XNameContainer> xForms = xSupplier->getXForms();
+ if( xForms.is() )
+ {
+ const Sequence<OUString> aNames = xForms->getElementNames();
+
+ for( const auto& rName : aNames )
+ {
+ Reference<XPropertySet> xModel( xForms->getByName( rName ),
+ UNO_QUERY );
+ exportXFormsModel( rExport, xModel );
+ }
+ }
+ }
+}
+
+
+static void exportXFormsInstance( SvXMLExport&, const Sequence<PropertyValue>& );
+static void exportXFormsBinding( SvXMLExport&, const Reference<XPropertySet>& );
+static void exportXFormsSubmission( SvXMLExport&, const Reference<XPropertySet>& );
+static void exportXFormsSchemas( SvXMLExport&, const Reference<css::xforms::XModel>& );
+
+
+typedef OUString (*convert_t)( const Any& );
+
+namespace {
+
+struct ExportTable
+{
+ const char* pPropertyName;
+ sal_uInt16 const nNamespace;
+ sal_uInt16 nToken;
+ convert_t const aConverter;
+};
+
+}
+
+static void lcl_export( const Reference<XPropertySet>& rPropertySet,
+ SvXMLExport& rExport,
+ const ExportTable* pTable );
+
+#define TABLE_ENTRY(NAME,NAMESPACE,TOKEN,CONVERTER) { NAME,XML_NAMESPACE_##NAMESPACE,xmloff::token::XML_##TOKEN, CONVERTER }
+#define TABLE_END { nullptr, 0, 0, nullptr }
+
+// any conversion functions
+static OUString xforms_string( const Any& );
+static OUString xforms_bool( const Any& );
+static OUString xforms_whitespace( const Any& );
+template<typename T, void (*FUNC)( OUStringBuffer&, T )> static OUString xforms_convert( const Any& );
+template<typename T, void (*FUNC)( OUStringBuffer&, const T& )> static OUString xforms_convertRef( const Any& );
+
+static void xforms_formatDate( OUStringBuffer& aBuffer, const util::Date& aDate );
+static void xforms_formatTime( OUStringBuffer& aBuffer, const css::util::Time& aTime );
+static void xforms_formatDateTime( OUStringBuffer& aBuffer, const util::DateTime& aDateTime );
+
+static void convertNumber(OUStringBuffer & b, sal_Int32 n) {
+ b.append(n);
+}
+
+convert_t const xforms_int32 = &xforms_convert<sal_Int32,&convertNumber>;
+convert_t const xforms_double = &xforms_convert<double,&::sax::Converter::convertDouble>;
+convert_t const xforms_dateTime = &xforms_convertRef<util::DateTime,&xforms_formatDateTime>;
+convert_t const xforms_date = &xforms_convertRef<util::Date,&xforms_formatDate>;
+convert_t const xforms_time = &xforms_convertRef<css::util::Time,&xforms_formatTime>;
+
+// other functions
+static OUString lcl_getXSDType( SvXMLExport const & rExport,
+ const Reference<XPropertySet>& xType );
+
+
+// the model
+
+
+static const ExportTable aXFormsModelTable[] =
+{
+ TABLE_ENTRY( "ID", NONE, ID, xforms_string ),
+ TABLE_ENTRY( "SchemaRef", NONE, SCHEMA, xforms_string ),
+ TABLE_END
+};
+
+void exportXFormsModel( SvXMLExport& rExport,
+ const Reference<XPropertySet>& xModelPropSet )
+{
+ // no model -> don't do anything!
+ Reference<css::xforms::XModel> xModel( xModelPropSet, UNO_QUERY );
+ if( ! xModel.is() || ! xModelPropSet.is() )
+ return;
+
+ lcl_export( xModelPropSet, rExport, aXFormsModelTable );
+ SvXMLElementExport aModelElement( rExport, XML_NAMESPACE_XFORMS, XML_MODEL,
+ true, true );
+
+ // instances
+ Reference<XIndexAccess> xInstances( xModel->getInstances(),
+ UNO_QUERY_THROW);
+ sal_Int32 nCount = xInstances->getCount();
+ sal_Int32 i = 0;
+ for( i = 0; i < nCount; i++ )
+ {
+ Sequence<PropertyValue> aInstance;
+ xInstances->getByIndex( i ) >>= aInstance;
+ exportXFormsInstance( rExport, aInstance );
+ }
+
+
+ // bindings
+ Reference<XIndexAccess> xBindings( xModel->getBindings(), UNO_QUERY_THROW);
+ nCount = xBindings->getCount();
+ for( i = 0; i < nCount; i++ )
+ {
+ Reference<XPropertySet> aBinding( xBindings->getByIndex( i ),
+ UNO_QUERY_THROW );
+ exportXFormsBinding( rExport, aBinding );
+ }
+
+ // submissions
+ Reference<XIndexAccess> xSubmissions( xModel->getSubmissions(),
+ UNO_QUERY_THROW );
+ nCount = xSubmissions->getCount();
+ for( i = 0; i < nCount; i++ )
+ {
+ Reference<XPropertySet> xSubmission( xSubmissions->getByIndex( i ),
+ UNO_QUERY_THROW );
+ exportXFormsSubmission( rExport, xSubmission );
+ }
+
+ // schemas
+ exportXFormsSchemas( rExport, xModel );
+}
+
+
+// the instance
+
+
+void exportXFormsInstance( SvXMLExport& rExport,
+ const Sequence<PropertyValue>& xInstance )
+{
+ OUString sId;
+ OUString sURL;
+ Reference<XDocument> xDoc;
+
+ for( const auto& rProp : xInstance )
+ {
+ OUString sName = rProp.Name;
+ const Any& rAny = rProp.Value;
+ if ( sName == "ID" )
+ rAny >>= sId;
+ else if ( sName == "URL" )
+ rAny >>= sURL;
+ else if ( sName == "Instance" )
+ rAny >>= xDoc;
+ }
+
+ if( !sId.isEmpty() )
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_ID, sId );
+
+ if( !sURL.isEmpty() )
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_SRC, sURL );
+
+ SvXMLElementExport aElem( rExport, XML_NAMESPACE_XFORMS, XML_INSTANCE,
+ true, true );
+ rExport.IgnorableWhitespace();
+ if( xDoc.is() )
+ {
+ exportDom( rExport, xDoc );
+ }
+}
+
+
+// the binding
+
+
+static const ExportTable aXFormsBindingTable[] =
+{
+ TABLE_ENTRY( "BindingID", NONE, ID, xforms_string ),
+ TABLE_ENTRY( "BindingExpression", NONE, NODESET, xforms_string ),
+ TABLE_ENTRY( "ReadonlyExpression", NONE, READONLY, xforms_string ),
+ TABLE_ENTRY( "RelevantExpression", NONE, RELEVANT, xforms_string ),
+ TABLE_ENTRY( "RequiredExpression", NONE, REQUIRED, xforms_string ),
+ TABLE_ENTRY( "ConstraintExpression", NONE, CONSTRAINT, xforms_string ),
+ TABLE_ENTRY( "CalculateExpression", NONE, CALCULATE, xforms_string ),
+ // type handled separately, for type name <-> XSD type conversion
+ // TABLE_ENTRY( "Type", NONE, TYPE, xforms_string ),
+ TABLE_END
+};
+
+void exportXFormsBinding( SvXMLExport& rExport,
+ const Reference<XPropertySet>& xBinding )
+{
+ // name check; generate binding ID if necessary
+ {
+ OUString sName;
+ xBinding->getPropertyValue( "BindingID" ) >>= sName;
+ if( sName.isEmpty() )
+ {
+ // if we don't have a name yet, generate one on the fly
+ sal_Int64 nId = reinterpret_cast<sal_uInt64>( xBinding.get() );
+ sName = "bind_" + OUString::number( nId , 16 );
+ xBinding->setPropertyValue( "BindingID", makeAny(sName));
+ }
+ }
+
+ lcl_export( xBinding, rExport, aXFormsBindingTable );
+
+ // handle type attribute
+ {
+ OUString sTypeName;
+ xBinding->getPropertyValue( "Type" ) >>= sTypeName;
+
+ try
+ {
+ // now get type, and determine whether it's a standard type. If
+ // so, export the XSD name
+ Reference<css::xforms::XModel> xModel(
+ xBinding->getPropertyValue( "Model" ),
+ UNO_QUERY );
+ Reference<XDataTypeRepository> xRepository(
+ xModel.is() ? xModel->getDataTypeRepository() : Reference<XDataTypeRepository>() );
+ if( xRepository.is() )
+ {
+ Reference<XPropertySet> xDataType =
+ xRepository->getDataType( sTypeName );
+
+ // if it's a basic data type, write out the XSD name
+ // for the XSD type class
+ bool bIsBasic = false;
+ xDataType->getPropertyValue( "IsBasic" ) >>= bIsBasic;
+ if( bIsBasic )
+ sTypeName = lcl_getXSDType( rExport, xDataType );
+ }
+ }
+ catch( Exception& )
+ {
+ ; // ignore; just use typename
+ }
+
+ // now that we have the proper type name, write out the attribute
+ if( !sTypeName.isEmpty() )
+ {
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_TYPE,
+ sTypeName );
+ }
+ }
+
+ // we need to ensure all the namespaces in the binding will work correctly.
+ // to do so, we will write out all missing namespace declaractions.
+ const SvXMLNamespaceMap& rMap = rExport.GetNamespaceMap();
+ Reference<XNameAccess> xNamespaces(
+ xBinding->getPropertyValue( "ModelNamespaces" ), UNO_QUERY);
+ if( xNamespaces.is() )
+ {
+ // iterate over Prefixes for this binding
+ const Sequence<OUString> aPrefixes = xNamespaces->getElementNames();
+ for( const OUString& rPrefix : aPrefixes )
+ {
+ OUString sURI;
+ xNamespaces->getByName( rPrefix ) >>= sURI;
+
+ // check whether prefix/URI pair is in map; else write declaration
+ // (we don't need to change the map, since this element has no
+ // other content)
+ sal_uInt16 nKey = rMap.GetKeyByPrefix( rPrefix );
+ if( nKey == XML_NAMESPACE_UNKNOWN ||
+ rMap.GetNameByKey( nKey ) != sURI )
+ {
+ rExport.AddAttribute( "xmlns:" + rPrefix, sURI );
+ }
+ }
+ }
+
+ SvXMLElementExport aElement( rExport, XML_NAMESPACE_XFORMS, XML_BIND,
+ true, true );
+}
+
+
+// the submission
+
+
+static const ExportTable aXFormsSubmissionTable[] =
+{
+ TABLE_ENTRY( "ID", NONE, ID, xforms_string ),
+ TABLE_ENTRY( "Bind", NONE, BIND, xforms_string ),
+ TABLE_ENTRY( "Ref", NONE, REF, xforms_string ),
+ TABLE_ENTRY( "Action", NONE, ACTION, xforms_string ),
+ TABLE_ENTRY( "Method", NONE, METHOD, xforms_string ),
+ TABLE_ENTRY( "Version", NONE, VERSION, xforms_string ),
+ TABLE_ENTRY( "Indent", NONE, INDENT, xforms_bool ),
+ TABLE_ENTRY( "MediaType", NONE, MEDIATYPE, xforms_string ),
+ TABLE_ENTRY( "Encoding", NONE, ENCODING, xforms_string ),
+ TABLE_ENTRY( "OmitXmlDeclaration", NONE, OMIT_XML_DECLARATION, xforms_bool ),
+ TABLE_ENTRY( "Standalone", NONE, STANDALONE, xforms_bool ),
+ TABLE_ENTRY( "CDataSectionElement", NONE, CDATA_SECTION_ELEMENTS, xforms_string ),
+ TABLE_ENTRY( "Replace", NONE, REPLACE, xforms_string ),
+ TABLE_ENTRY( "Separator", NONE, SEPARATOR, xforms_string ),
+ TABLE_ENTRY( "IncludeNamespacePrefixes", NONE, INCLUDENAMESPACEPREFIXES, xforms_string ),
+ TABLE_END
+};
+
+void exportXFormsSubmission( SvXMLExport& rExport,
+ const Reference<XPropertySet>& xSubmission )
+{
+ lcl_export( xSubmission, rExport, aXFormsSubmissionTable );
+ SvXMLElementExport aElement( rExport, XML_NAMESPACE_XFORMS, XML_SUBMISSION,
+ true, true );
+}
+
+
+// export data types as XSD schema
+
+
+static const ExportTable aDataTypeFacetTable[] =
+{
+ TABLE_ENTRY( "Length", XSD, LENGTH, xforms_int32 ),
+ TABLE_ENTRY( "MinLength", XSD, MINLENGTH, xforms_int32 ),
+ TABLE_ENTRY( "MaxLength", XSD, MAXLENGTH, xforms_int32 ),
+ TABLE_ENTRY( "MinInclusiveInt", XSD, MININCLUSIVE, xforms_int32 ),
+ TABLE_ENTRY( "MinExclusiveInt", XSD, MINEXCLUSIVE, xforms_int32 ),
+ TABLE_ENTRY( "MaxInclusiveInt", XSD, MAXINCLUSIVE, xforms_int32 ),
+ TABLE_ENTRY( "MaxExclusiveInt", XSD, MAXEXCLUSIVE, xforms_int32 ),
+ TABLE_ENTRY( "MinInclusiveDouble", XSD, MININCLUSIVE, xforms_double ),
+ TABLE_ENTRY( "MinExclusiveDouble", XSD, MINEXCLUSIVE, xforms_double ),
+ TABLE_ENTRY( "MaxInclusiveDouble", XSD, MAXINCLUSIVE, xforms_double ),
+ TABLE_ENTRY( "MaxExclusiveDouble", XSD, MAXEXCLUSIVE, xforms_double ),
+ TABLE_ENTRY( "MinInclusiveDate", XSD, MININCLUSIVE, xforms_date ),
+ TABLE_ENTRY( "MinExclusiveDate", XSD, MINEXCLUSIVE, xforms_date ),
+ TABLE_ENTRY( "MaxInclusiveDate", XSD, MAXINCLUSIVE, xforms_date ),
+ TABLE_ENTRY( "MaxExclusiveDate", XSD, MAXEXCLUSIVE, xforms_date ),
+ TABLE_ENTRY( "MinInclusiveTime", XSD, MININCLUSIVE, xforms_time ),
+ TABLE_ENTRY( "MinExclusiveTime", XSD, MINEXCLUSIVE, xforms_time ),
+ TABLE_ENTRY( "MaxInclusiveTime", XSD, MAXINCLUSIVE, xforms_time ),
+ TABLE_ENTRY( "MaxExclusiveTime", XSD, MAXEXCLUSIVE, xforms_time ),
+ TABLE_ENTRY( "MinInclusiveDateTime", XSD, MININCLUSIVE, xforms_dateTime ),
+ TABLE_ENTRY( "MinExclusiveDateTime", XSD, MINEXCLUSIVE, xforms_dateTime ),
+ TABLE_ENTRY( "MaxInclusiveDateTime", XSD, MAXINCLUSIVE, xforms_dateTime ),
+ TABLE_ENTRY( "MaxExclusiveDateTime", XSD, MAXEXCLUSIVE, xforms_dateTime ),
+ TABLE_ENTRY( "Pattern", XSD, PATTERN, xforms_string ),
+ // ??? XML_ENUMERATION,
+ TABLE_ENTRY( "WhiteSpace", XSD, WHITESPACE, xforms_whitespace ),
+ TABLE_ENTRY( "TotalDigits", XSD, TOTALDIGITS, xforms_int32 ),
+ TABLE_ENTRY( "FractionDigits", XSD, FRACTIONDIGITS, xforms_int32 ),
+ TABLE_END
+};
+
+// export facets through table; use the same table as lcl_export does
+static void lcl_exportDataTypeFacets( SvXMLExport& rExport,
+ const Reference<XPropertySet>& rPropertySet,
+ const ExportTable* pTable )
+{
+ Reference<XPropertySetInfo> xInfo = rPropertySet->getPropertySetInfo();
+ for( const ExportTable* pCurrent = pTable;
+ pCurrent->pPropertyName != nullptr;
+ pCurrent++ )
+ {
+ OUString sName( OUString::createFromAscii( pCurrent->pPropertyName ) );
+ if( xInfo->hasPropertyByName( sName ) )
+ {
+ OUString sValue = (*pCurrent->aConverter)(
+ rPropertySet->getPropertyValue( sName ) );
+
+ if( !sValue.isEmpty() )
+ {
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_VALUE, sValue );
+ SvXMLElementExport aFacet(
+ rExport,
+ pCurrent->nNamespace,
+ static_cast<XMLTokenEnum>( pCurrent->nToken ),
+ true, true );
+ }
+ }
+ }
+}
+
+static OUString lcl_getXSDType( SvXMLExport const & rExport,
+ const Reference<XPropertySet>& xType )
+{
+ // we use string as default...
+ XMLTokenEnum eToken = XML_STRING;
+
+ sal_uInt16 nDataTypeClass = 0;
+ xType->getPropertyValue( "TypeClass" ) >>= nDataTypeClass;
+ switch( nDataTypeClass )
+ {
+ case css::xsd::DataTypeClass::STRING:
+ eToken = XML_STRING;
+ break;
+ case css::xsd::DataTypeClass::anyURI:
+ eToken = XML_ANYURI;
+ break;
+ case css::xsd::DataTypeClass::DECIMAL:
+ eToken = XML_DECIMAL;
+ break;
+ case css::xsd::DataTypeClass::DOUBLE:
+ eToken = XML_DOUBLE;
+ break;
+ case css::xsd::DataTypeClass::FLOAT:
+ eToken = XML_FLOAT;
+ break;
+ case css::xsd::DataTypeClass::BOOLEAN:
+ eToken = XML_BOOLEAN;
+ break;
+ case css::xsd::DataTypeClass::DATETIME:
+ eToken = XML_DATETIME_XSD;
+ break;
+ case css::xsd::DataTypeClass::TIME:
+ eToken = XML_TIME;
+ break;
+ case css::xsd::DataTypeClass::DATE:
+ eToken = XML_DATE;
+ break;
+ case css::xsd::DataTypeClass::gYear:
+ eToken = XML_YEAR;
+ break;
+ case css::xsd::DataTypeClass::gDay:
+ eToken = XML_DAY;
+ break;
+ case css::xsd::DataTypeClass::gMonth:
+ eToken = XML_MONTH;
+ break;
+ case css::xsd::DataTypeClass::DURATION:
+ case css::xsd::DataTypeClass::gYearMonth:
+ case css::xsd::DataTypeClass::gMonthDay:
+ case css::xsd::DataTypeClass::hexBinary:
+ case css::xsd::DataTypeClass::base64Binary:
+ case css::xsd::DataTypeClass::QName:
+ case css::xsd::DataTypeClass::NOTATION:
+ default:
+ OSL_FAIL( "unknown data type" );
+ }
+
+ return rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_XSD,
+ GetXMLToken( eToken ) );
+}
+
+static void lcl_exportDataType( SvXMLExport& rExport,
+ const Reference<XPropertySet>& xType )
+{
+ // we do not need to export basic types; exit if we have one
+ bool bIsBasic = false;
+ xType->getPropertyValue( "IsBasic" ) >>= bIsBasic;
+ if( bIsBasic )
+ return;
+
+ // no basic type -> export
+
+ // <xsd:simpleType name="...">
+ OUString sName;
+ xType->getPropertyValue( "Name" ) >>= sName;
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_NAME, sName );
+ SvXMLElementExport aSimpleType( rExport,
+ XML_NAMESPACE_XSD, XML_SIMPLETYPE,
+ true, true );
+
+ // <xsd:restriction base="xsd:...">
+ rExport.AddAttribute( XML_NAMESPACE_NONE, XML_BASE,
+ lcl_getXSDType( rExport, xType ) );
+ SvXMLElementExport aRestriction( rExport,
+ XML_NAMESPACE_XSD,
+ XML_RESTRICTION,
+ true, true );
+
+ // export facets
+ lcl_exportDataTypeFacets( rExport,
+ xType,
+ aDataTypeFacetTable );
+}
+
+void exportXFormsSchemas( SvXMLExport& rExport,
+ const Reference<css::xforms::XModel>& xModel )
+{
+ // TODO: for now, we'll fake this...
+ {
+ SvXMLElementExport aSchemaElem( rExport, XML_NAMESPACE_XSD, XML_SCHEMA,
+ true, true );
+
+ // now get data type repository, and export
+ Reference<XEnumerationAccess> xTypes = xModel->getDataTypeRepository();
+ if( xTypes.is() )
+ {
+ Reference<XEnumeration> xEnum = xTypes->createEnumeration();
+ SAL_WARN_IF( !xEnum.is(), "xmloff", "no enum?" );
+ while( xEnum->hasMoreElements() )
+ {
+ Reference<XPropertySet> xType( xEnum->nextElement(), UNO_QUERY );
+ lcl_exportDataType( rExport, xType );
+ }
+ }
+ }
+
+ // export other, 'foreign' schemas
+ Reference<XPropertySet> xPropSet( xModel, UNO_QUERY );
+ if( xPropSet.is() )
+ {
+ Reference<XDocument> xDocument(
+ xPropSet->getPropertyValue( "ForeignSchema" ),
+ UNO_QUERY );
+
+ if( xDocument.is() )
+ exportDom( rExport, xDocument );
+ }
+}
+
+
+// helper functions
+
+
+static void lcl_export( const Reference<XPropertySet>& rPropertySet,
+ SvXMLExport& rExport,
+ const ExportTable* pTable )
+{
+ for( const ExportTable* pCurrent = pTable;
+ pCurrent->pPropertyName != nullptr;
+ pCurrent++ )
+ {
+ Any aAny = rPropertySet->getPropertyValue(
+ OUString::createFromAscii( pCurrent->pPropertyName ) );
+ OUString sValue = (*pCurrent->aConverter)( aAny );
+
+ if( !sValue.isEmpty() )
+ rExport.AddAttribute(
+ pCurrent->nNamespace,
+ static_cast<XMLTokenEnum>( pCurrent->nToken ),
+ sValue );
+ }
+}
+
+
+// any conversion functions
+
+
+template<typename T, void (*FUNC)( OUStringBuffer&, T )>
+OUString xforms_convert( const Any& rAny )
+{
+ OUStringBuffer aBuffer;
+ T aData = T();
+ if( rAny >>= aData )
+ {
+ FUNC( aBuffer, aData );
+ }
+ return aBuffer.makeStringAndClear();
+}
+
+template<typename T, void (*FUNC)( OUStringBuffer&, const T& )>
+OUString xforms_convertRef( const Any& rAny )
+{
+ OUStringBuffer aBuffer;
+ T aData;
+ if( rAny >>= aData )
+ {
+ FUNC( aBuffer, aData );
+ }
+ return aBuffer.makeStringAndClear();
+}
+
+OUString xforms_string( const Any& rAny )
+{
+ OUString aResult;
+ rAny >>= aResult;
+ return aResult;
+}
+
+OUString xforms_bool( const Any& rAny )
+{
+ bool bResult = bool();
+ if( rAny >>= bResult )
+ return GetXMLToken( bResult ? XML_TRUE : XML_FALSE );
+ OSL_FAIL( "expected boolean value" );
+ return OUString();
+}
+
+void xforms_formatDate( OUStringBuffer& aBuffer, const util::Date& rDate )
+{
+ aBuffer.append(OUString::number(static_cast<sal_Int32>( rDate.Year ) ))
+ .append("-").append(OUString::number(static_cast<sal_Int32>( rDate.Month )))
+ .append("-").append(OUString::number(static_cast<sal_Int32>( rDate.Day )));
+}
+
+void xforms_formatTime( OUStringBuffer& aBuffer, const css::util::Time& rTime )
+{
+ Duration aDuration;
+ aDuration.Hours = rTime.Hours;
+ aDuration.Minutes = rTime.Minutes;
+ aDuration.Seconds = rTime.Seconds;
+ aDuration.NanoSeconds = rTime.NanoSeconds;
+ ::sax::Converter::convertDuration( aBuffer, aDuration );
+}
+
+void xforms_formatDateTime( OUStringBuffer& aBuffer, const util::DateTime& aDateTime )
+{
+ ::sax::Converter::convertDateTime(aBuffer, aDateTime, nullptr);
+}
+
+OUString xforms_whitespace( const Any& rAny )
+{
+ OUString sResult;
+ sal_uInt16 n = sal_uInt16();
+ if( rAny >>= n )
+ {
+ switch( n )
+ {
+ case css::xsd::WhiteSpaceTreatment::Preserve:
+ sResult = GetXMLToken( XML_PRESERVE );
+ break;
+ case css::xsd::WhiteSpaceTreatment::Replace:
+ sResult = GetXMLToken( XML_REPLACE );
+ break;
+ case css::xsd::WhiteSpaceTreatment::Collapse:
+ sResult = GetXMLToken( XML_COLLAPSE );
+ break;
+ }
+ }
+ return sResult;
+}
+
+
+/// return name of Binding
+static OUString lcl_getXFormsBindName( const Reference<XPropertySet>& xBinding )
+{
+ OUString sProp( "BindingID" );
+
+ OUString sReturn;
+ if( xBinding.is() &&
+ xBinding->getPropertySetInfo()->hasPropertyByName( sProp ) )
+ {
+ xBinding->getPropertyValue( sProp ) >>= sReturn;
+ }
+ return sReturn;
+}
+
+// return name of binding
+OUString getXFormsBindName( const Reference<XPropertySet>& xControl )
+{
+ Reference<XBindableValue> xBindable( xControl, UNO_QUERY );
+ return xBindable.is()
+ ? lcl_getXFormsBindName(
+ Reference<XPropertySet>( xBindable->getValueBinding(), UNO_QUERY ))
+ : OUString();
+}
+
+// return name of list binding
+OUString getXFormsListBindName( const Reference<XPropertySet>& xControl )
+{
+ Reference<XListEntrySink> xListEntrySink( xControl, UNO_QUERY );
+ return xListEntrySink.is()
+ ? lcl_getXFormsBindName(
+ Reference<XPropertySet>( xListEntrySink->getListEntrySource(),
+ UNO_QUERY ) )
+ : OUString();
+}
+
+OUString getXFormsSubmissionName( const Reference<XPropertySet>& xBinding )
+{
+ OUString sReturn;
+
+ Reference<XSubmissionSupplier> xSubmissionSupplier( xBinding, UNO_QUERY );
+ if( xSubmissionSupplier.is() )
+ {
+ Reference<XPropertySet> xPropertySet(
+ xSubmissionSupplier->getSubmission(), UNO_QUERY );
+ OUString sProp( "ID" );
+ if( xPropertySet.is() &&
+ xPropertySet->getPropertySetInfo()->hasPropertyByName( sProp ) )
+ {
+ xPropertySet->getPropertyValue( sProp ) >>= sReturn;
+ }
+ }
+
+ return sReturn;
+}
+
+void getXFormsSettings( const Reference< XNameAccess >& _rXForms, Sequence< PropertyValue >& _out_rSettings )
+{
+ _out_rSettings = Sequence< PropertyValue >();
+
+ OSL_PRECOND( _rXForms.is(), "getXFormsSettings: invalid XForms container!" );
+ if ( !_rXForms.is() )
+ return;
+
+ try
+ {
+ // we want to export some special properties of our XForms models as config-item-map-named,
+ // which implies we need a PropertyValue whose value is an XNameAccess, whose keys
+ // are the names of the XForm models, and which in turn provides named sequences of
+ // PropertyValues - which denote the actual property values of the given named model.
+
+ const Sequence< OUString > aModelNames( _rXForms->getElementNames() );
+
+ Reference< XNameContainer > xModelSettings = document::NamedPropertyValues::create( comphelper::getProcessComponentContext() );
+
+ for ( auto const & modelName : aModelNames )
+ {
+ Reference< XPropertySet > xModelProps( _rXForms->getByName( modelName ), UNO_QUERY_THROW );
+
+ Sequence< PropertyValue > aModelSettings( 1 );
+ aModelSettings[0].Name = "ExternalData";
+ aModelSettings[0].Value = xModelProps->getPropertyValue( aModelSettings[0].Name );
+
+ xModelSettings->insertByName( modelName, makeAny( aModelSettings ) );
+ }
+
+ if ( xModelSettings->hasElements() )
+ {
+ _out_rSettings.realloc( 1 );
+ _out_rSettings[0].Name = "XFormModels";
+ _out_rSettings[0].Value <<= xModelSettings;
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff");
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/xforms/xformsimport.cxx b/xmloff/source/xforms/xformsimport.cxx
new file mode 100644
index 000000000..4d07507a6
--- /dev/null
+++ b/xmloff/source/xforms/xformsimport.cxx
@@ -0,0 +1,187 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "XFormsModelContext.hxx"
+#include <utility>
+#include <xmloff/xformsimport.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/form/binding/XValueBinding.hpp>
+#include <com/sun/star/form/binding/XBindableValue.hpp>
+#include <com/sun/star/form/binding/XListEntrySource.hpp>
+#include <com/sun/star/form/binding/XListEntrySink.hpp>
+#include <com/sun/star/form/submission/XSubmission.hpp>
+#include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <rtl/ustring.hxx>
+#include "xformsapi.hxx"
+#include <comphelper/namedvaluecollection.hxx>
+#include <tools/diagnose_ex.h>
+
+using std::pair;
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::Exception;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::UNO_QUERY_THROW;
+using com::sun::star::uno::UNO_SET_THROW;
+using com::sun::star::uno::Sequence;
+using com::sun::star::beans::XPropertySet;
+using com::sun::star::beans::XPropertySetInfo;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::frame::XModel;
+using com::sun::star::container::XNameAccess;
+using com::sun::star::form::binding::XValueBinding;
+using com::sun::star::form::binding::XBindableValue;
+using com::sun::star::form::binding::XListEntrySource;
+using com::sun::star::form::binding::XListEntrySink;
+using com::sun::star::form::submission::XSubmission;
+using com::sun::star::form::submission::XSubmissionSupplier;
+
+SvXMLImportContext* createXFormsModelContext(
+ SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName )
+{
+ return new XFormsModelContext( rImport, nPrefix, rLocalName );
+}
+
+void bindXFormsValueBinding(Reference<XModel> const& xModel,
+ const pair<Reference<XPropertySet>, OUString>& aPair)
+{
+ Reference<XBindableValue> xBindable(
+ aPair.first,
+ UNO_QUERY );
+ Reference<XValueBinding> xBinding(
+ xforms_findXFormsBinding( xModel, aPair.second ),
+ UNO_QUERY );
+
+ if( xBindable.is() && xBinding.is() )
+ {
+ try
+ {
+ xBindable->setValueBinding( xBinding );
+ }
+ catch( const Exception& )
+ {
+ // ignore problems during binding
+ // TODO: call XML error handling
+ }
+ }
+}
+
+void bindXFormsListBinding(Reference<XModel> const& xModel,
+ const ::pair<Reference<XPropertySet>, OUString>& aPair)
+{
+ Reference<XListEntrySink> xListEntrySink(
+ aPair.first,
+ UNO_QUERY );
+ Reference<XListEntrySource> xListEntrySource(
+ xforms_findXFormsBinding( xModel, aPair.second ),
+ UNO_QUERY );
+
+ if( xListEntrySink.is() && xListEntrySource.is() )
+ {
+ try
+ {
+ xListEntrySink->setListEntrySource( xListEntrySource );
+ }
+ catch( const Exception& )
+ {
+ // ignore problems during binding
+ // TODO: call XML error handling
+ }
+ }
+}
+
+void bindXFormsSubmission(Reference<XModel> const& xModel,
+ const pair<Reference<XPropertySet>, OUString>& aPair)
+{
+ Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
+ Reference<XSubmission> xSubmission(
+ xforms_findXFormsSubmission( xModel, aPair.second ),
+ UNO_QUERY );
+
+ if( xSubmissionSupp.is() && xSubmission.is() )
+ {
+ try
+ {
+ xSubmissionSupp->setSubmission( xSubmission );
+ }
+ catch( const Exception& )
+ {
+ // ignore problems during binding
+ // TODO: call XML error handling
+ }
+ }
+}
+
+void applyXFormsSettings( const Reference< XNameAccess >& _rXForms, const Sequence< PropertyValue >& _rSettings )
+{
+ OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
+ if ( !_rXForms.is() )
+ return;
+
+ ::comphelper::NamedValueCollection aSettings( _rSettings );
+ Reference< XNameAccess > xModelSettings( aSettings.get( "XFormModels" ), UNO_QUERY );
+ if ( !xModelSettings.is() )
+ {
+ OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
+ return;
+ }
+
+ try
+ {
+ const Sequence< OUString > aSettingsForModels( xModelSettings->getElementNames() );
+ for ( auto const & modelName : aSettingsForModels )
+ {
+ // the settings for this particular model
+ Sequence< PropertyValue > aModelSettings;
+ OSL_VERIFY( xModelSettings->getByName( modelName ) >>= aModelSettings );
+
+ // the model itself
+ if ( !_rXForms->hasByName( modelName ) )
+ {
+ OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
+ continue;
+ }
+
+ // propagate the settings, being tolerant by omitting properties which are not supported
+ Reference< XPropertySet > xModelProps( _rXForms->getByName( modelName ), UNO_QUERY_THROW );
+ Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
+
+ for ( auto const & setting : std::as_const(aModelSettings) )
+ {
+ if ( !xModelPSI->hasPropertyByName( setting.Name ) )
+ {
+ OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
+ continue;
+ }
+
+ xModelProps->setPropertyValue( setting.Name, setting.Value );
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff");
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */