1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "xmloff/xformsexport.hxx"
23 #include "XFormsModelExport.hxx"
24 #include "xformsapi.hxx"
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/nmspmap.hxx>
30 #include "DomExport.hxx"
32 #include <sax/tools/converter.hxx>
34 #include <comphelper/componentcontext.hxx>
35 #include <comphelper/processfactory.hxx>
37 #include "tools/debug.hxx"
38 #include <tools/diagnose_ex.h>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/document/NamedPropertyValues.hpp>
42 #include <com/sun/star/xml/dom/XDocument.hpp>
43 #include <com/sun/star/form/binding/XValueBinding.hpp>
44 #include <com/sun/star/form/binding/XBindableValue.hpp>
45 #include <com/sun/star/form/binding/XListEntrySink.hpp>
46 #include <com/sun/star/form/binding/XListEntrySource.hpp>
47 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
48 #include <com/sun/star/xforms/XModel.hpp>
49 #include <com/sun/star/xforms/XDataTypeRepository.hpp>
50 #include <com/sun/star/xforms/XFormsSupplier.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/container/XEnumerationAccess.hpp>
53 #include <com/sun/star/container/XEnumeration.hpp>
54 #include <com/sun/star/container/XNameContainer.hpp>
55 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
56 #include <com/sun/star/xsd/DataTypeClass.hpp>
57 #include <com/sun/star/xsd/XDataType.hpp>
58 #include <com/sun/star/util/Date.hpp>
59 #include <com/sun/star/util/Time.hpp>
60 #include <com/sun/star/util/DateTime.hpp>
61 #include <com/sun/star/util/Duration.hpp>
63 using namespace com::sun::star
;
64 using namespace com::sun::star::uno
;
65 using namespace xmloff::token
;
67 using com::sun::star::beans::XPropertySet
;
68 using com::sun::star::beans::XPropertySetInfo
;
69 using com::sun::star::container::XIndexAccess
;
70 using com::sun::star::container::XNameAccess
;
71 using com::sun::star::container::XNameContainer
;
72 using com::sun::star::container::XEnumerationAccess
;
73 using com::sun::star::container::XEnumeration
;
74 using com::sun::star::xml::dom::XDocument
;
75 using com::sun::star::form::binding::XValueBinding
;
76 using com::sun::star::form::binding::XBindableValue
;
77 using com::sun::star::form::binding::XListEntrySink
;
78 using com::sun::star::form::submission::XSubmissionSupplier
;
79 using com::sun::star::beans::PropertyValue
;
80 using com::sun::star::xsd::XDataType
;
81 using com::sun::star::xforms::XDataTypeRepository
;
82 using com::sun::star::xforms::XFormsSupplier
;
83 using com::sun::star::util::Duration
;
85 void exportXForms( SvXMLExport
& rExport
)
87 Reference
<XFormsSupplier
> xSupplier( rExport
.GetModel(), UNO_QUERY
);
90 Reference
<XNameContainer
> xForms
= xSupplier
->getXForms();
93 Sequence
<OUString
> aNames
= xForms
->getElementNames();
94 const OUString
* pNames
= aNames
.getConstArray();
95 sal_Int32 nNames
= aNames
.getLength();
97 for( sal_Int32 n
= 0; n
< nNames
; n
++ )
99 Reference
<XPropertySet
> xModel( xForms
->getByName( pNames
[n
] ),
101 exportXFormsModel( rExport
, xModel
);
108 void exportXFormsInstance( SvXMLExport
&, const Sequence
<PropertyValue
>& );
109 void exportXFormsBinding( SvXMLExport
&, const Reference
<XPropertySet
>& );
110 void exportXFormsSubmission( SvXMLExport
&, const Reference
<XPropertySet
>& );
111 void exportXFormsSchemas( SvXMLExport
&, const Reference
<com::sun::star::xforms::XModel
>& );
114 typedef OUString (*convert_t
)( const Any
& );
117 const sal_Char
* pPropertyName
;
118 sal_uInt16 nPropertyNameLength
;
119 sal_uInt16 nNamespace
;
121 convert_t aConverter
;
123 static void lcl_export( const Reference
<XPropertySet
>& rPropertySet
,
124 SvXMLExport
& rExport
,
125 const ExportTable
* pTable
);
127 #define TABLE_ENTRY(NAME,NAMESPACE,TOKEN,CONVERTER) { NAME,sizeof(NAME)-1,XML_NAMESPACE_##NAMESPACE,xmloff::token::XML_##TOKEN, CONVERTER }
128 #define TABLE_END { NULL, 0, 0, 0, NULL }
130 // any conversion functions
131 OUString
xforms_string( const Any
& );
132 OUString
xforms_bool( const Any
& );
133 OUString
xforms_whitespace( const Any
& );
134 template<typename T
, void (*FUNC
)( OUStringBuffer
&, T
)> OUString
xforms_convert( const Any
& );
135 template<typename T
, void (*FUNC
)( OUStringBuffer
&, const T
& )> OUString
xforms_convertRef( const Any
& );
137 void xforms_formatDate( OUStringBuffer
& aBuffer
, const util::Date
& aDate
);
138 void xforms_formatTime( OUStringBuffer
& aBuffer
, const com::sun::star::util::Time
& aTime
);
139 void xforms_formatDateTime( OUStringBuffer
& aBuffer
, const util::DateTime
& aDateTime
);
141 convert_t xforms_int32
= &xforms_convert
<sal_Int32
,&::sax::Converter::convertNumber
>;
142 convert_t xforms_double
= &xforms_convert
<double,&::sax::Converter::convertDouble
>;
143 convert_t xforms_dateTime
= &xforms_convertRef
<util::DateTime
,&xforms_formatDateTime
>;
144 convert_t xforms_date
= &xforms_convertRef
<util::Date
,&xforms_formatDate
>;
145 convert_t xforms_time
= &xforms_convertRef
<com::sun::star::util::Time
,&xforms_formatTime
>;
148 static OUString
lcl_getXSDType( SvXMLExport
& rExport
,
149 const Reference
<XPropertySet
>& xType
);
156 static const ExportTable aXFormsModelTable
[] =
158 TABLE_ENTRY( "ID", NONE
, ID
, xforms_string
),
159 TABLE_ENTRY( "SchemaRef", NONE
, SCHEMA
, xforms_string
),
163 void exportXFormsModel( SvXMLExport
& rExport
,
164 const Reference
<XPropertySet
>& xModelPropSet
)
166 // no model -> don't do anything!
167 Reference
<com::sun::star::xforms::XModel
> xModel( xModelPropSet
, UNO_QUERY
);
168 if( ! xModel
.is() || ! xModelPropSet
.is() )
171 lcl_export( xModelPropSet
, rExport
, aXFormsModelTable
);
172 SvXMLElementExport
aModelElement( rExport
, XML_NAMESPACE_XFORMS
, XML_MODEL
,
173 sal_True
, sal_True
);
176 Reference
<XIndexAccess
> xInstances( xModel
->getInstances(),
178 sal_Int32 nCount
= xInstances
->getCount();
180 for( i
= 0; i
< nCount
; i
++ )
182 Sequence
<PropertyValue
> aInstance
;
183 xInstances
->getByIndex( i
) >>= aInstance
;
184 exportXFormsInstance( rExport
, aInstance
);
189 Reference
<XIndexAccess
> xBindings( xModel
->getBindings(), UNO_QUERY_THROW
);
190 nCount
= xBindings
->getCount();
191 for( i
= 0; i
< nCount
; i
++ )
193 Reference
<XPropertySet
> aBinding( xBindings
->getByIndex( i
),
195 exportXFormsBinding( rExport
, aBinding
);
199 Reference
<XIndexAccess
> xSubmissions( xModel
->getSubmissions(),
201 nCount
= xSubmissions
->getCount();
202 for( i
= 0; i
< nCount
; i
++ )
204 Reference
<XPropertySet
> xSubmission( xSubmissions
->getByIndex( i
),
206 exportXFormsSubmission( rExport
, xSubmission
);
210 exportXFormsSchemas( rExport
, xModel
);
217 static const ExportTable aXFormsInstanceTable
[] =
219 TABLE_ENTRY( "InstanceURL", NONE
, SRC
, xforms_string
),
223 void exportXFormsInstance( SvXMLExport
& rExport
,
224 const Sequence
<PropertyValue
>& xInstance
)
228 Reference
<XDocument
> xDoc
;
230 const PropertyValue
* pInstance
= xInstance
.getConstArray();
231 sal_Int32 nCount
= xInstance
.getLength();
232 for( sal_Int32 i
= 0; i
< nCount
; i
++ )
234 OUString sName
= pInstance
[i
].Name
;
235 const Any
& rAny
= pInstance
[i
].Value
;
238 else if ( sName
== "URL" )
240 else if ( sName
== "Instance" )
245 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_ID
, sId
);
247 if( !sURL
.isEmpty() )
248 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_SRC
, sURL
);
250 SvXMLElementExport
aElem( rExport
, XML_NAMESPACE_XFORMS
, XML_INSTANCE
,
251 sal_True
, sal_True
);
252 rExport
.IgnorableWhitespace();
255 exportDom( rExport
, xDoc
);
264 static const ExportTable aXFormsBindingTable
[] =
266 TABLE_ENTRY( "BindingID", NONE
, ID
, xforms_string
),
267 TABLE_ENTRY( "BindingExpression", NONE
, NODESET
, xforms_string
),
268 TABLE_ENTRY( "ReadonlyExpression", NONE
, READONLY
, xforms_string
),
269 TABLE_ENTRY( "RelevantExpression", NONE
, RELEVANT
, xforms_string
),
270 TABLE_ENTRY( "RequiredExpression", NONE
, REQUIRED
, xforms_string
),
271 TABLE_ENTRY( "ConstraintExpression", NONE
, CONSTRAINT
, xforms_string
),
272 TABLE_ENTRY( "CalculateExpression", NONE
, CALCULATE
, xforms_string
),
273 // type handled separatly, for type name <-> XSD type conversion
274 // TABLE_ENTRY( "Type", NONE, TYPE, xforms_string ),
278 void exportXFormsBinding( SvXMLExport
& rExport
,
279 const Reference
<XPropertySet
>& xBinding
)
281 // name check; generate binding ID if necessary
284 xBinding
->getPropertyValue( "BindingID" ) >>= sName
;
285 if( sName
.isEmpty() )
287 // if we don't have a name yet, generate one on the fly
288 OUStringBuffer aBuffer
;
289 aBuffer
.append( "bind_" );
290 sal_Int64 nId
= reinterpret_cast<sal_uInt64
>( xBinding
.get() );
291 aBuffer
.append( nId
, 16 );
292 sName
= aBuffer
.makeStringAndClear();
293 xBinding
->setPropertyValue( "BindingID", makeAny(sName
));
297 lcl_export( xBinding
, rExport
, aXFormsBindingTable
);
299 // handle type attribute
302 xBinding
->getPropertyValue( "Type" ) >>= sTypeName
;
306 // now get type, and determine whether its a standard type. If
307 // so, export the XSD name
308 Reference
<com::sun::star::xforms::XModel
> xModel(
309 xBinding
->getPropertyValue( "Model" ),
311 Reference
<XDataTypeRepository
> xRepository(
312 xModel
.is() ? xModel
->getDataTypeRepository() : Reference
<XDataTypeRepository
>() );
313 if( xRepository
.is() )
315 Reference
<XPropertySet
> xDataType(
316 xRepository
->getDataType( sTypeName
),
319 // if it's a basic data type, write out the XSD name
320 // for the XSD type class
321 bool bIsBasic
= false;
322 xDataType
->getPropertyValue( "IsBasic" ) >>= bIsBasic
;
324 sTypeName
= lcl_getXSDType( rExport
, xDataType
);
329 ; // ignore; just use typename
332 // now that we have the proper type name, write out the attribute
333 if( !sTypeName
.isEmpty() )
335 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_TYPE
,
340 // we need to ensure all the namespaces in the binding will work correctly.
341 // to do so, we will write out all missing namespace declaractions.
342 const SvXMLNamespaceMap
& rMap
= rExport
.GetNamespaceMap();
343 Reference
<XNameAccess
> xNamespaces(
344 xBinding
->getPropertyValue( "ModelNamespaces" ), UNO_QUERY
);
345 if( xNamespaces
.is() )
347 // iterate over Prefixes for this binding
348 Sequence
<OUString
> aPrefixes
= xNamespaces
->getElementNames();
349 const OUString
* pPrefixes
= aPrefixes
.getConstArray();
350 sal_Int32 nPrefixes
= aPrefixes
.getLength();
351 for( sal_Int32 i
= 0; i
< nPrefixes
; i
++ )
353 const OUString
& rPrefix
= pPrefixes
[i
];
355 xNamespaces
->getByName( rPrefix
) >>= sURI
;
357 // check whether prefix/URI pair is in map; else write declaration
358 // (we don't need to change the map, since this element has no
360 sal_uInt16 nKey
= rMap
.GetKeyByPrefix( rPrefix
);
361 if( nKey
== XML_NAMESPACE_UNKNOWN
||
362 rMap
.GetNameByKey( nKey
) != sURI
)
364 rExport
.AddAttribute( "xmlns:" + rPrefix
, sURI
);
369 SvXMLElementExport
aElement( rExport
, XML_NAMESPACE_XFORMS
, XML_BIND
,
370 sal_True
, sal_True
);
378 static const ExportTable aXFormsSubmissionTable
[] =
380 TABLE_ENTRY( "ID", NONE
, ID
, xforms_string
),
381 TABLE_ENTRY( "Bind", NONE
, BIND
, xforms_string
),
382 TABLE_ENTRY( "Ref", NONE
, REF
, xforms_string
),
383 TABLE_ENTRY( "Action", NONE
, ACTION
, xforms_string
),
384 TABLE_ENTRY( "Method", NONE
, METHOD
, xforms_string
),
385 TABLE_ENTRY( "Version", NONE
, VERSION
, xforms_string
),
386 TABLE_ENTRY( "Indent", NONE
, INDENT
, xforms_bool
),
387 TABLE_ENTRY( "MediaType", NONE
, MEDIATYPE
, xforms_string
),
388 TABLE_ENTRY( "Encoding", NONE
, ENCODING
, xforms_string
),
389 TABLE_ENTRY( "OmitXmlDeclaration", NONE
, OMIT_XML_DECLARATION
, xforms_bool
),
390 TABLE_ENTRY( "Standalone", NONE
, STANDALONE
, xforms_bool
),
391 TABLE_ENTRY( "CDataSectionElement", NONE
, CDATA_SECTION_ELEMENTS
, xforms_string
),
392 TABLE_ENTRY( "Replace", NONE
, REPLACE
, xforms_string
),
393 TABLE_ENTRY( "Separator", NONE
, SEPARATOR
, xforms_string
),
394 TABLE_ENTRY( "IncludeNamespacePrefixes", NONE
, INCLUDENAMESPACEPREFIXES
, xforms_string
),
398 void exportXFormsSubmission( SvXMLExport
& rExport
,
399 const Reference
<XPropertySet
>& xSubmission
)
401 lcl_export( xSubmission
, rExport
, aXFormsSubmissionTable
);
402 SvXMLElementExport
aElement( rExport
, XML_NAMESPACE_XFORMS
, XML_SUBMISSION
,
403 sal_True
, sal_True
);
409 // export data types as XSD schema
412 static const ExportTable aDataTypeFacetTable
[] =
414 TABLE_ENTRY( "Length", XSD
, LENGTH
, xforms_int32
),
415 TABLE_ENTRY( "MinLength", XSD
, MINLENGTH
, xforms_int32
),
416 TABLE_ENTRY( "MaxLength", XSD
, MAXLENGTH
, xforms_int32
),
417 TABLE_ENTRY( "MinInclusiveInt", XSD
, MININCLUSIVE
, xforms_int32
),
418 TABLE_ENTRY( "MinExclusiveInt", XSD
, MINEXCLUSIVE
, xforms_int32
),
419 TABLE_ENTRY( "MaxInclusiveInt", XSD
, MAXINCLUSIVE
, xforms_int32
),
420 TABLE_ENTRY( "MaxExclusiveInt", XSD
, MAXEXCLUSIVE
, xforms_int32
),
421 TABLE_ENTRY( "MinInclusiveDouble", XSD
, MININCLUSIVE
, xforms_double
),
422 TABLE_ENTRY( "MinExclusiveDouble", XSD
, MINEXCLUSIVE
, xforms_double
),
423 TABLE_ENTRY( "MaxInclusiveDouble", XSD
, MAXINCLUSIVE
, xforms_double
),
424 TABLE_ENTRY( "MaxExclusiveDouble", XSD
, MAXEXCLUSIVE
, xforms_double
),
425 TABLE_ENTRY( "MinInclusiveDate", XSD
, MININCLUSIVE
, xforms_date
),
426 TABLE_ENTRY( "MinExclusiveDate", XSD
, MINEXCLUSIVE
, xforms_date
),
427 TABLE_ENTRY( "MaxInclusiveDate", XSD
, MAXINCLUSIVE
, xforms_date
),
428 TABLE_ENTRY( "MaxExclusiveDate", XSD
, MAXEXCLUSIVE
, xforms_date
),
429 TABLE_ENTRY( "MinInclusiveTime", XSD
, MININCLUSIVE
, xforms_time
),
430 TABLE_ENTRY( "MinExclusiveTime", XSD
, MINEXCLUSIVE
, xforms_time
),
431 TABLE_ENTRY( "MaxInclusiveTime", XSD
, MAXINCLUSIVE
, xforms_time
),
432 TABLE_ENTRY( "MaxExclusiveTime", XSD
, MAXEXCLUSIVE
, xforms_time
),
433 TABLE_ENTRY( "MinInclusiveDateTime", XSD
, MININCLUSIVE
, xforms_dateTime
),
434 TABLE_ENTRY( "MinExclusiveDateTime", XSD
, MINEXCLUSIVE
, xforms_dateTime
),
435 TABLE_ENTRY( "MaxInclusiveDateTime", XSD
, MAXINCLUSIVE
, xforms_dateTime
),
436 TABLE_ENTRY( "MaxExclusiveDateTime", XSD
, MAXEXCLUSIVE
, xforms_dateTime
),
437 TABLE_ENTRY( "Pattern", XSD
, PATTERN
, xforms_string
),
438 // ??? XML_ENUMERATION,
439 TABLE_ENTRY( "WhiteSpace", XSD
, WHITESPACE
, xforms_whitespace
),
440 TABLE_ENTRY( "TotalDigits", XSD
, TOTALDIGITS
, xforms_int32
),
441 TABLE_ENTRY( "FractionDigits", XSD
, FRACTIONDIGITS
, xforms_int32
),
445 // export facets through table; use the same table as lcl_export does
446 static void lcl_exportDataTypeFacets( SvXMLExport
& rExport
,
447 const Reference
<XPropertySet
>& rPropertySet
,
448 const ExportTable
* pTable
)
450 Reference
<XPropertySetInfo
> xInfo
= rPropertySet
->getPropertySetInfo();
451 for( const ExportTable
* pCurrent
= pTable
;
452 pCurrent
->pPropertyName
!= NULL
;
455 OUString
sName( OUString::createFromAscii( pCurrent
->pPropertyName
) );
456 if( xInfo
->hasPropertyByName( sName
) )
458 OUString sValue
= (*pCurrent
->aConverter
)(
459 rPropertySet
->getPropertyValue( sName
) );
461 if( !sValue
.isEmpty() )
463 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_VALUE
, sValue
);
464 SvXMLElementExport
aFacet(
466 pCurrent
->nNamespace
,
467 static_cast<XMLTokenEnum
>( pCurrent
->nToken
),
468 sal_True
, sal_True
);
474 static OUString
lcl_getXSDType( SvXMLExport
& rExport
,
475 const Reference
<XPropertySet
>& xType
)
477 // we use string as default...
478 XMLTokenEnum eToken
= XML_STRING
;
480 sal_uInt16 nDataTypeClass
= 0;
481 xType
->getPropertyValue( "TypeClass" ) >>= nDataTypeClass
;
482 switch( nDataTypeClass
)
484 case com::sun::star::xsd::DataTypeClass::STRING
:
487 case com::sun::star::xsd::DataTypeClass::anyURI
:
490 case com::sun::star::xsd::DataTypeClass::DECIMAL
:
491 eToken
= XML_DECIMAL
;
493 case com::sun::star::xsd::DataTypeClass::DOUBLE
:
496 case com::sun::star::xsd::DataTypeClass::FLOAT
:
499 case com::sun::star::xsd::DataTypeClass::BOOLEAN
:
500 eToken
= XML_BOOLEAN
;
502 case com::sun::star::xsd::DataTypeClass::DATETIME
:
503 eToken
= XML_DATETIME_XSD
;
505 case com::sun::star::xsd::DataTypeClass::TIME
:
508 case com::sun::star::xsd::DataTypeClass::DATE
:
511 case com::sun::star::xsd::DataTypeClass::gYear
:
514 case com::sun::star::xsd::DataTypeClass::gDay
:
517 case com::sun::star::xsd::DataTypeClass::gMonth
:
520 case com::sun::star::xsd::DataTypeClass::DURATION
:
521 case com::sun::star::xsd::DataTypeClass::gYearMonth
:
522 case com::sun::star::xsd::DataTypeClass::gMonthDay
:
523 case com::sun::star::xsd::DataTypeClass::hexBinary
:
524 case com::sun::star::xsd::DataTypeClass::base64Binary
:
525 case com::sun::star::xsd::DataTypeClass::QName
:
526 case com::sun::star::xsd::DataTypeClass::NOTATION
:
528 OSL_FAIL( "unknown data type" );
531 return rExport
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_XSD
,
532 GetXMLToken( eToken
) );
535 static void lcl_exportDataType( SvXMLExport
& rExport
,
536 const Reference
<XPropertySet
>& xType
)
538 // we do not need to export basic types; exit if we have one
539 bool bIsBasic
= false;
540 xType
->getPropertyValue( "IsBasic" ) >>= bIsBasic
;
544 // no basic type -> export
546 // <xsd:simpleType name="...">
548 xType
->getPropertyValue( "Name" ) >>= sName
;
549 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_NAME
, sName
);
550 SvXMLElementExport
aSimpleType( rExport
,
551 XML_NAMESPACE_XSD
, XML_SIMPLETYPE
,
552 sal_True
, sal_True
);
554 // <xsd:restriction base="xsd:...">
555 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_BASE
,
556 lcl_getXSDType( rExport
, xType
) );
557 SvXMLElementExport
aRestriction( rExport
,
560 sal_True
, sal_True
);
563 lcl_exportDataTypeFacets( rExport
,
564 Reference
<XPropertySet
>( xType
, UNO_QUERY
),
565 aDataTypeFacetTable
);
568 void exportXFormsSchemas( SvXMLExport
& rExport
,
569 const Reference
<com::sun::star::xforms::XModel
>& xModel
)
571 // TODO: for now, we'll fake this...
573 SvXMLElementExport
aSchemaElem( rExport
, XML_NAMESPACE_XSD
, XML_SCHEMA
,
574 sal_True
, sal_True
);
576 // now get data type repositry, and export
577 Reference
<XEnumerationAccess
> xTypes( xModel
->getDataTypeRepository(),
581 Reference
<XEnumeration
> xEnum
= xTypes
->createEnumeration();
582 DBG_ASSERT( xEnum
.is(), "no enum?" );
583 while( xEnum
->hasMoreElements() )
585 Reference
<XPropertySet
> xType( xEnum
->nextElement(), UNO_QUERY
);
586 lcl_exportDataType( rExport
, xType
);
591 // export other, 'foreign' schemas
592 Reference
<XPropertySet
> xPropSet( xModel
, UNO_QUERY
);
595 Reference
<XDocument
> xDocument(
596 xPropSet
->getPropertyValue( "ForeignSchema" ),
600 exportDom( rExport
, xDocument
);
610 static void lcl_export( const Reference
<XPropertySet
>& rPropertySet
,
611 SvXMLExport
& rExport
,
612 const ExportTable
* pTable
)
614 for( const ExportTable
* pCurrent
= pTable
;
615 pCurrent
->pPropertyName
!= NULL
;
618 Any aAny
= rPropertySet
->getPropertyValue(
619 OUString::createFromAscii( pCurrent
->pPropertyName
) );
620 OUString sValue
= (*pCurrent
->aConverter
)( aAny
);
622 if( !sValue
.isEmpty() )
623 rExport
.AddAttribute(
624 pCurrent
->nNamespace
,
625 static_cast<XMLTokenEnum
>( pCurrent
->nToken
),
633 // any conversion functions
636 template<typename T
, void (*FUNC
)( OUStringBuffer
&, T
)>
637 OUString
xforms_convert( const Any
& rAny
)
639 OUStringBuffer aBuffer
;
643 FUNC( aBuffer
, aData
);
645 return aBuffer
.makeStringAndClear();
648 template<typename T
, void (*FUNC
)( OUStringBuffer
&, const T
& )>
649 OUString
xforms_convertRef( const Any
& rAny
)
651 OUStringBuffer aBuffer
;
655 FUNC( aBuffer
, aData
);
657 return aBuffer
.makeStringAndClear();
660 OUString
xforms_string( const Any
& rAny
)
667 OUString
xforms_bool( const Any
& rAny
)
669 bool bResult
= bool();
670 if( rAny
>>= bResult
)
671 return GetXMLToken( bResult
? XML_TRUE
: XML_FALSE
);
672 OSL_FAIL( "expected boolean value" );
676 void xforms_formatDate( OUStringBuffer
& aBuffer
, const util::Date
& rDate
)
678 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Year
) );
679 aBuffer
.append( sal_Unicode('-') );
680 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Month
) );
681 aBuffer
.append( sal_Unicode('-') );
682 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Day
) );
685 void xforms_formatTime( OUStringBuffer
& aBuffer
, const com::sun::star::util::Time
& rTime
)
688 aDuration
.Hours
= rTime
.Hours
;
689 aDuration
.Minutes
= rTime
.Minutes
;
690 aDuration
.Seconds
= rTime
.Seconds
;
691 aDuration
.NanoSeconds
= rTime
.NanoSeconds
;
692 ::sax::Converter::convertDuration( aBuffer
, aDuration
);
695 void xforms_formatDateTime( OUStringBuffer
& aBuffer
, const util::DateTime
& aDateTime
)
697 ::sax::Converter::convertDateTime( aBuffer
, aDateTime
);
700 OUString
xforms_whitespace( const Any
& rAny
)
703 sal_uInt16 n
= sal_uInt16();
708 case com::sun::star::xsd::WhiteSpaceTreatment::Preserve
:
709 sResult
= GetXMLToken( XML_PRESERVE
);
711 case com::sun::star::xsd::WhiteSpaceTreatment::Replace
:
712 sResult
= GetXMLToken( XML_REPLACE
);
714 case com::sun::star::xsd::WhiteSpaceTreatment::Collapse
:
715 sResult
= GetXMLToken( XML_COLLAPSE
);
723 /// return name of Binding
724 static OUString
lcl_getXFormsBindName( const Reference
<XPropertySet
>& xBinding
)
726 OUString
sProp( "BindingID" );
730 xBinding
->getPropertySetInfo()->hasPropertyByName( sProp
) )
732 xBinding
->getPropertyValue( sProp
) >>= sReturn
;
737 // return name of binding
738 OUString
getXFormsBindName( const Reference
<XPropertySet
>& xControl
)
740 Reference
<XBindableValue
> xBindable( xControl
, UNO_QUERY
);
741 return xBindable
.is()
742 ? lcl_getXFormsBindName(
743 Reference
<XPropertySet
>( xBindable
->getValueBinding(), UNO_QUERY
))
747 // return name of list binding
748 OUString
getXFormsListBindName( const Reference
<XPropertySet
>& xControl
)
750 Reference
<XListEntrySink
> xListEntrySink( xControl
, UNO_QUERY
);
751 return xListEntrySink
.is()
752 ? lcl_getXFormsBindName(
753 Reference
<XPropertySet
>( xListEntrySink
->getListEntrySource(),
758 OUString
getXFormsSubmissionName( const Reference
<XPropertySet
>& xBinding
)
762 Reference
<XSubmissionSupplier
> xSubmissionSupplier( xBinding
, UNO_QUERY
);
763 if( xSubmissionSupplier
.is() )
765 Reference
<XPropertySet
> xPropertySet(
766 xSubmissionSupplier
->getSubmission(), UNO_QUERY
);
767 OUString
sProp( "ID" );
768 if( xPropertySet
.is() &&
769 xPropertySet
->getPropertySetInfo()->hasPropertyByName( sProp
) )
771 xPropertySet
->getPropertyValue( sProp
) >>= sReturn
;
778 void getXFormsSettings( const Reference
< XNameAccess
>& _rXForms
, Sequence
< PropertyValue
>& _out_rSettings
)
780 _out_rSettings
= Sequence
< PropertyValue
>();
782 OSL_PRECOND( _rXForms
.is(), "getXFormsSettings: invalid XForms container!" );
783 if ( !_rXForms
.is() )
788 // we want to export some special properties of our XForms models as config-item-map-named,
789 // which implies we need a PropertyValue whose value is an XNameAccess, whose keys
790 // are the names of the XForm models, and which in turn provides named sequences of
791 // PropertyValues - which denote the actual property values of the given named model.
793 Sequence
< OUString
> aModelNames( _rXForms
->getElementNames() );
795 Reference
< XNameContainer
> xModelSettings
= document::NamedPropertyValues::create( comphelper::getProcessComponentContext() );
797 for ( const OUString
* pModelName
= aModelNames
.getConstArray();
798 pModelName
!= aModelNames
.getConstArray() + aModelNames
.getLength();
802 Reference
< XPropertySet
> xModelProps( _rXForms
->getByName( *pModelName
), UNO_QUERY_THROW
);
804 Sequence
< PropertyValue
> aModelSettings( 1 );
805 aModelSettings
[0].Name
= OUString( "ExternalData" );
806 aModelSettings
[0].Value
= xModelProps
->getPropertyValue( aModelSettings
[0].Name
);
808 xModelSettings
->insertByName( *pModelName
, makeAny( aModelSettings
) );
811 if ( xModelSettings
->hasElements() )
813 _out_rSettings
.realloc( 1 );
814 _out_rSettings
[0].Name
= OUString( "XFormModels" );
815 _out_rSettings
[0].Value
<<= xModelSettings
;
818 catch( const Exception
& )
820 DBG_UNHANDLED_EXCEPTION();
824 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */