1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xformsexport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "xformsexport.hxx"
36 #include "XFormsModelExport.hxx"
37 #include "xformsapi.hxx"
39 #include <xmloff/xmlexp.hxx>
40 #include <xmloff/xmltoken.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include "DomExport.hxx"
44 #include <xmloff/xmluconv.hxx>
45 #include <comphelper/componentcontext.hxx>
46 #include <comphelper/processfactory.hxx>
48 #include "tools/debug.hxx"
49 #include <tools/diagnose_ex.h>
50 #include <com/sun/star/container/XIndexAccess.hpp>
51 #include <com/sun/star/container/XNameAccess.hpp>
52 #include <com/sun/star/xml/dom/XDocument.hpp>
53 #include <com/sun/star/form/binding/XValueBinding.hpp>
54 #include <com/sun/star/form/binding/XBindableValue.hpp>
55 #include <com/sun/star/form/binding/XListEntrySink.hpp>
56 #include <com/sun/star/form/binding/XListEntrySource.hpp>
57 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
58 #include <com/sun/star/xforms/XModel.hpp>
59 #include <com/sun/star/xforms/XDataTypeRepository.hpp>
60 #include <com/sun/star/xforms/XFormsSupplier.hpp>
61 #include <com/sun/star/beans/PropertyValue.hpp>
62 #include <com/sun/star/container/XEnumerationAccess.hpp>
63 #include <com/sun/star/container/XEnumeration.hpp>
64 #include <com/sun/star/container/XNameContainer.hpp>
65 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
66 #include <com/sun/star/xsd/DataTypeClass.hpp>
67 #include <com/sun/star/xsd/XDataType.hpp>
68 #include <com/sun/star/util/Date.hpp>
69 #include <com/sun/star/util/Time.hpp>
70 #include <com/sun/star/util/DateTime.hpp>
72 using namespace com::sun::star
;
73 using namespace com::sun::star::uno
;
74 using namespace xmloff::token
;
77 using rtl::OUStringBuffer
;
78 using com::sun::star::beans::XPropertySet
;
79 using com::sun::star::beans::XPropertySetInfo
;
80 using com::sun::star::container::XIndexAccess
;
81 using com::sun::star::container::XNameAccess
;
82 using com::sun::star::container::XNameContainer
;
83 using com::sun::star::container::XEnumerationAccess
;
84 using com::sun::star::container::XEnumeration
;
85 using com::sun::star::xml::dom::XDocument
;
86 using com::sun::star::form::binding::XValueBinding
;
87 using com::sun::star::form::binding::XBindableValue
;
88 using com::sun::star::form::binding::XListEntrySink
;
89 using com::sun::star::form::submission::XSubmissionSupplier
;
90 using com::sun::star::beans::PropertyValue
;
91 using com::sun::star::xsd::XDataType
;
92 using com::sun::star::xforms::XDataTypeRepository
;
93 using com::sun::star::xforms::XFormsSupplier
;
94 using com::sun::star::util::Date
;
95 using com::sun::star::util::DateTime
;
97 void exportXForms( SvXMLExport
& rExport
)
99 Reference
<XFormsSupplier
> xSupplier( rExport
.GetModel(), UNO_QUERY
);
102 Reference
<XNameContainer
> xForms
= xSupplier
->getXForms();
105 Sequence
<OUString
> aNames
= xForms
->getElementNames();
106 const OUString
* pNames
= aNames
.getConstArray();
107 sal_Int32 nNames
= aNames
.getLength();
109 for( sal_Int32 n
= 0; n
< nNames
; n
++ )
111 Reference
<XPropertySet
> xModel( xForms
->getByName( pNames
[n
] ),
113 exportXFormsModel( rExport
, xModel
);
120 void exportXFormsInstance( SvXMLExport
&, const Sequence
<PropertyValue
>& );
121 void exportXFormsBinding( SvXMLExport
&, const Reference
<XPropertySet
>& );
122 void exportXFormsSubmission( SvXMLExport
&, const Reference
<XPropertySet
>& );
123 void exportXFormsSchemas( SvXMLExport
&, const Reference
<com::sun::star::xforms::XModel
>& );
126 typedef OUString (*convert_t
)( const Any
& );
129 const sal_Char
* pPropertyName
;
130 sal_uInt16 nPropertyNameLength
;
131 sal_uInt16 nNamespace
;
133 convert_t aConverter
;
135 void lcl_export( const Reference
<XPropertySet
>& rPropertySet
,
136 SvXMLExport
& rExport
,
137 const ExportTable
* pTable
);
139 #define TABLE_ENTRY(NAME,NAMESPACE,TOKEN,CONVERTER) { NAME,sizeof(NAME)-1,XML_NAMESPACE_##NAMESPACE,xmloff::token::XML_##TOKEN, CONVERTER }
140 #define TABLE_END { NULL, 0, 0, 0, NULL }
143 // any conversion functions
144 OUString
lcl_string( const Any
& );
145 OUString
lcl_bool( const Any
& );
146 OUString
lcl_whitespace( const Any
& );
147 template<typename T
, void (*FUNC
)( OUStringBuffer
&, T
)> OUString
lcl_convert( const Any
& );
148 template<typename T
, void (*FUNC
)( OUStringBuffer
&, const T
& )> OUString
lcl_convertRef( const Any
& );
150 void lcl_formatDate( OUStringBuffer
& aBuffer
, const Date
& aDate
);
151 void lcl_formatTime( OUStringBuffer
& aBuffer
, const com::sun::star::util::Time
& aTime
);
152 void lcl_formatDateTime( OUStringBuffer
& aBuffer
, const DateTime
& aDateTime
);
154 convert_t lcl_int32
= &lcl_convert
<sal_Int32
,&SvXMLUnitConverter::convertNumber
>;
155 convert_t lcl_double
= &lcl_convert
<double,&SvXMLUnitConverter::convertDouble
>;
156 convert_t lcl_dateTime
= &lcl_convertRef
<DateTime
,&lcl_formatDateTime
>;
157 convert_t lcl_date
= &lcl_convertRef
<Date
,&lcl_formatDate
>;
158 convert_t lcl_time
= &lcl_convertRef
<com::sun::star::util::Time
,&lcl_formatTime
>;
161 OUString
lcl_getXSDType( SvXMLExport
& rExport
,
162 const Reference
<XPropertySet
>& xType
);
169 static const ExportTable aXFormsModelTable
[] =
171 TABLE_ENTRY( "ID", NONE
, ID
, lcl_string
),
172 TABLE_ENTRY( "SchemaRef", NONE
, SCHEMA
, lcl_string
),
176 void exportXFormsModel( SvXMLExport
& rExport
,
177 const Reference
<XPropertySet
>& xModelPropSet
)
179 // no model -> don't do anything!
180 Reference
<com::sun::star::xforms::XModel
> xModel( xModelPropSet
, UNO_QUERY
);
181 if( ! xModel
.is() || ! xModelPropSet
.is() )
184 lcl_export( xModelPropSet
, rExport
, aXFormsModelTable
);
185 SvXMLElementExport
aModelElement( rExport
, XML_NAMESPACE_XFORMS
, XML_MODEL
,
186 sal_True
, sal_True
);
189 Reference
<XIndexAccess
> xInstances( xModel
->getInstances(),
191 sal_Int32 nCount
= xInstances
->getCount();
193 for( i
= 0; i
< nCount
; i
++ )
195 Sequence
<PropertyValue
> aInstance
;
196 xInstances
->getByIndex( i
) >>= aInstance
;
197 exportXFormsInstance( rExport
, aInstance
);
202 Reference
<XIndexAccess
> xBindings( xModel
->getBindings(), UNO_QUERY_THROW
);
203 nCount
= xBindings
->getCount();
204 for( i
= 0; i
< nCount
; i
++ )
206 Reference
<XPropertySet
> aBinding( xBindings
->getByIndex( i
),
208 exportXFormsBinding( rExport
, aBinding
);
212 Reference
<XIndexAccess
> xSubmissions( xModel
->getSubmissions(),
214 nCount
= xSubmissions
->getCount();
215 for( i
= 0; i
< nCount
; i
++ )
217 Reference
<XPropertySet
> xSubmission( xSubmissions
->getByIndex( i
),
219 exportXFormsSubmission( rExport
, xSubmission
);
223 exportXFormsSchemas( rExport
, xModel
);
230 static const ExportTable aXFormsInstanceTable
[] =
232 TABLE_ENTRY( "InstanceURL", NONE
, SRC
, lcl_string
),
236 void exportXFormsInstance( SvXMLExport
& rExport
,
237 const Sequence
<PropertyValue
>& xInstance
)
241 Reference
<XDocument
> xDoc
;
243 const PropertyValue
* pInstance
= xInstance
.getConstArray();
244 sal_Int32 nCount
= xInstance
.getLength();
245 for( sal_Int32 i
= 0; i
< nCount
; i
++ )
247 OUString sName
= pInstance
[i
].Name
;
248 const Any
& rAny
= pInstance
[i
].Value
;
249 if( sName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ID") ) )
251 else if( sName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("URL") ) )
253 else if( sName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Instance") ))
257 if( sId
.getLength() > 0 )
258 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_ID
, sId
);
260 if( sURL
.getLength() > 0 )
261 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_SRC
, sURL
);
263 SvXMLElementExport
aElem( rExport
, XML_NAMESPACE_XFORMS
, XML_INSTANCE
,
264 sal_True
, sal_True
);
265 rExport
.IgnorableWhitespace();
268 exportDom( rExport
, xDoc
);
277 static const ExportTable aXFormsBindingTable
[] =
279 TABLE_ENTRY( "BindingID", NONE
, ID
, lcl_string
),
280 TABLE_ENTRY( "BindingExpression", NONE
, NODESET
, lcl_string
),
281 TABLE_ENTRY( "ReadonlyExpression", NONE
, READONLY
, lcl_string
),
282 TABLE_ENTRY( "RelevantExpression", NONE
, RELEVANT
, lcl_string
),
283 TABLE_ENTRY( "RequiredExpression", NONE
, REQUIRED
, lcl_string
),
284 TABLE_ENTRY( "ConstraintExpression", NONE
, CONSTRAINT
, lcl_string
),
285 TABLE_ENTRY( "CalculateExpression", NONE
, CALCULATE
, lcl_string
),
286 // type handled separatly, for type name <-> XSD type conversion
287 // TABLE_ENTRY( "Type", NONE, TYPE, lcl_string ),
291 void exportXFormsBinding( SvXMLExport
& rExport
,
292 const Reference
<XPropertySet
>& xBinding
)
294 // name check; generate binding ID if necessary
297 xBinding
->getPropertyValue( OUSTRING("BindingID") ) >>= sName
;
298 if( sName
.getLength() == 0 )
300 // if we don't have a name yet, generate one on the fly
301 OUStringBuffer aBuffer
;
302 aBuffer
.append( OUSTRING("bind_" ) );
303 sal_Int64 nId
= reinterpret_cast<sal_uInt64
>( xBinding
.get() );
304 aBuffer
.append( nId
, 16 );
305 sName
= aBuffer
.makeStringAndClear();
306 xBinding
->setPropertyValue( OUSTRING("BindingID"), makeAny(sName
));
310 lcl_export( xBinding
, rExport
, aXFormsBindingTable
);
312 // handle type attribute
315 xBinding
->getPropertyValue( OUSTRING("Type") ) >>= sTypeName
;
319 // now get type, and determine whether its a standard type. If
320 // so, export the XSD name
321 Reference
<com::sun::star::xforms::XModel
> xModel(
322 xBinding
->getPropertyValue( OUSTRING("Model") ),
324 Reference
<XDataTypeRepository
> xRepository(
325 xModel
.is() ? xModel
->getDataTypeRepository() : Reference
<XDataTypeRepository
>() );
326 if( xRepository
.is() )
328 Reference
<XPropertySet
> xDataType(
329 xRepository
->getDataType( sTypeName
),
332 // if it's a basic data type, write out the XSD name
333 // for the XSD type class
334 bool bIsBasic
= false;
335 xDataType
->getPropertyValue( OUSTRING("IsBasic") ) >>= bIsBasic
;
337 sTypeName
= lcl_getXSDType( rExport
, xDataType
);
342 ; // ignore; just use typename
345 // now that we have the proper type name, write out the attribute
346 if( sTypeName
.getLength() > 0 )
348 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_TYPE
,
353 // we need to ensure all the namespaces in the binding will work correctly.
354 // to do so, we will write out all missing namespace declaractions.
355 const SvXMLNamespaceMap
& rMap
= rExport
.GetNamespaceMap();
356 Reference
<XNameAccess
> xNamespaces(
357 xBinding
->getPropertyValue( OUSTRING("ModelNamespaces") ), UNO_QUERY
);
358 if( xNamespaces
.is() )
360 // iterate over Prefixes for this binding
361 Sequence
<OUString
> aPrefixes
= xNamespaces
->getElementNames();
362 const OUString
* pPrefixes
= aPrefixes
.getConstArray();
363 sal_Int32 nPrefixes
= aPrefixes
.getLength();
364 for( sal_Int32 i
= 0; i
< nPrefixes
; i
++ )
366 const OUString
& rPrefix
= pPrefixes
[i
];
368 xNamespaces
->getByName( rPrefix
) >>= sURI
;
370 // check whether prefix/URI pair is in map; else write declaration
371 // (we don't need to change the map, since this element has no
373 sal_uInt16 nKey
= rMap
.GetKeyByPrefix( rPrefix
);
374 if( nKey
== XML_NAMESPACE_UNKNOWN
||
375 rMap
.GetNameByKey( nKey
) != sURI
)
377 rExport
.AddAttribute( OUSTRING("xmlns:") + rPrefix
, sURI
);
382 SvXMLElementExport
aElement( rExport
, XML_NAMESPACE_XFORMS
, XML_BIND
,
383 sal_True
, sal_True
);
391 static const ExportTable aXFormsSubmissionTable
[] =
393 TABLE_ENTRY( "ID", NONE
, ID
, lcl_string
),
394 TABLE_ENTRY( "Bind", NONE
, BIND
, lcl_string
),
395 TABLE_ENTRY( "Ref", NONE
, REF
, lcl_string
),
396 TABLE_ENTRY( "Action", NONE
, ACTION
, lcl_string
),
397 TABLE_ENTRY( "Method", NONE
, METHOD
, lcl_string
),
398 TABLE_ENTRY( "Version", NONE
, VERSION
, lcl_string
),
399 TABLE_ENTRY( "Indent", NONE
, INDENT
, lcl_bool
),
400 TABLE_ENTRY( "MediaType", NONE
, MEDIATYPE
, lcl_string
),
401 TABLE_ENTRY( "Encoding", NONE
, ENCODING
, lcl_string
),
402 TABLE_ENTRY( "OmitXmlDeclaration", NONE
, OMIT_XML_DECLARATION
, lcl_bool
),
403 TABLE_ENTRY( "Standalone", NONE
, STANDALONE
, lcl_bool
),
404 TABLE_ENTRY( "CDataSectionElement", NONE
, CDATA_SECTION_ELEMENTS
, lcl_string
),
405 TABLE_ENTRY( "Replace", NONE
, REPLACE
, lcl_string
),
406 TABLE_ENTRY( "Separator", NONE
, SEPARATOR
, lcl_string
),
407 TABLE_ENTRY( "IncludeNamespacePrefixes", NONE
, INCLUDENAMESPACEPREFIXES
, lcl_string
),
411 void exportXFormsSubmission( SvXMLExport
& rExport
,
412 const Reference
<XPropertySet
>& xSubmission
)
414 lcl_export( xSubmission
, rExport
, aXFormsSubmissionTable
);
415 SvXMLElementExport
aElement( rExport
, XML_NAMESPACE_XFORMS
, XML_SUBMISSION
,
416 sal_True
, sal_True
);
422 // export data types as XSD schema
425 static const ExportTable aDataTypeFacetTable
[] =
427 TABLE_ENTRY( "Length", XSD
, LENGTH
, lcl_int32
),
428 TABLE_ENTRY( "MinLength", XSD
, MINLENGTH
, lcl_int32
),
429 TABLE_ENTRY( "MaxLength", XSD
, MAXLENGTH
, lcl_int32
),
430 TABLE_ENTRY( "MinInclusiveInt", XSD
, MININCLUSIVE
, lcl_int32
),
431 TABLE_ENTRY( "MinExclusiveInt", XSD
, MINEXCLUSIVE
, lcl_int32
),
432 TABLE_ENTRY( "MaxInclusiveInt", XSD
, MAXINCLUSIVE
, lcl_int32
),
433 TABLE_ENTRY( "MaxExclusiveInt", XSD
, MAXEXCLUSIVE
, lcl_int32
),
434 TABLE_ENTRY( "MinInclusiveDouble", XSD
, MININCLUSIVE
, lcl_double
),
435 TABLE_ENTRY( "MinExclusiveDouble", XSD
, MINEXCLUSIVE
, lcl_double
),
436 TABLE_ENTRY( "MaxInclusiveDouble", XSD
, MAXINCLUSIVE
, lcl_double
),
437 TABLE_ENTRY( "MaxExclusiveDouble", XSD
, MAXEXCLUSIVE
, lcl_double
),
438 TABLE_ENTRY( "MinInclusiveDate", XSD
, MININCLUSIVE
, lcl_date
),
439 TABLE_ENTRY( "MinExclusiveDate", XSD
, MINEXCLUSIVE
, lcl_date
),
440 TABLE_ENTRY( "MaxInclusiveDate", XSD
, MAXINCLUSIVE
, lcl_date
),
441 TABLE_ENTRY( "MaxExclusiveDate", XSD
, MAXEXCLUSIVE
, lcl_date
),
442 TABLE_ENTRY( "MinInclusiveTime", XSD
, MININCLUSIVE
, lcl_time
),
443 TABLE_ENTRY( "MinExclusiveTime", XSD
, MINEXCLUSIVE
, lcl_time
),
444 TABLE_ENTRY( "MaxInclusiveTime", XSD
, MAXINCLUSIVE
, lcl_time
),
445 TABLE_ENTRY( "MaxExclusiveTime", XSD
, MAXEXCLUSIVE
, lcl_time
),
446 TABLE_ENTRY( "MinInclusiveDateTime", XSD
, MININCLUSIVE
, lcl_dateTime
),
447 TABLE_ENTRY( "MinExclusiveDateTime", XSD
, MINEXCLUSIVE
, lcl_dateTime
),
448 TABLE_ENTRY( "MaxInclusiveDateTime", XSD
, MAXINCLUSIVE
, lcl_dateTime
),
449 TABLE_ENTRY( "MaxExclusiveDateTime", XSD
, MAXEXCLUSIVE
, lcl_dateTime
),
450 TABLE_ENTRY( "Pattern", XSD
, PATTERN
, lcl_string
),
451 // ??? XML_ENUMERATION,
452 TABLE_ENTRY( "WhiteSpace", XSD
, WHITESPACE
, lcl_whitespace
),
453 TABLE_ENTRY( "TotalDigits", XSD
, TOTALDIGITS
, lcl_int32
),
454 TABLE_ENTRY( "FractionDigits", XSD
, FRACTIONDIGITS
, lcl_int32
),
458 // export facets through table; use the same table as lcl_export does
459 void lcl_exportDataTypeFacets( SvXMLExport
& rExport
,
460 const Reference
<XPropertySet
>& rPropertySet
,
461 const ExportTable
* pTable
)
463 Reference
<XPropertySetInfo
> xInfo
= rPropertySet
->getPropertySetInfo();
464 for( const ExportTable
* pCurrent
= pTable
;
465 pCurrent
->pPropertyName
!= NULL
;
468 OUString
sName( OUString::createFromAscii( pCurrent
->pPropertyName
) );
469 if( xInfo
->hasPropertyByName( sName
) )
471 OUString sValue
= (*pCurrent
->aConverter
)(
472 rPropertySet
->getPropertyValue( sName
) );
474 if( sValue
.getLength() > 0 )
476 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_VALUE
, sValue
);
477 SvXMLElementExport
aFacet(
479 pCurrent
->nNamespace
,
480 static_cast<XMLTokenEnum
>( pCurrent
->nToken
),
481 sal_True
, sal_True
);
487 OUString
lcl_getXSDType( SvXMLExport
& rExport
,
488 const Reference
<XPropertySet
>& xType
)
490 // we use string as default...
491 XMLTokenEnum eToken
= XML_STRING
;
493 sal_uInt16 nDataTypeClass
= 0;
494 xType
->getPropertyValue( OUSTRING("TypeClass") ) >>= nDataTypeClass
;
495 switch( nDataTypeClass
)
497 case com::sun::star::xsd::DataTypeClass::STRING
:
500 case com::sun::star::xsd::DataTypeClass::anyURI
:
503 case com::sun::star::xsd::DataTypeClass::DECIMAL
:
504 eToken
= XML_DECIMAL
;
506 case com::sun::star::xsd::DataTypeClass::DOUBLE
:
509 case com::sun::star::xsd::DataTypeClass::FLOAT
:
512 case com::sun::star::xsd::DataTypeClass::BOOLEAN
:
513 eToken
= XML_BOOLEAN
;
515 case com::sun::star::xsd::DataTypeClass::DATETIME
:
516 eToken
= XML_DATETIME_XSD
;
518 case com::sun::star::xsd::DataTypeClass::TIME
:
521 case com::sun::star::xsd::DataTypeClass::DATE
:
524 case com::sun::star::xsd::DataTypeClass::gYear
:
527 case com::sun::star::xsd::DataTypeClass::gDay
:
530 case com::sun::star::xsd::DataTypeClass::gMonth
:
533 case com::sun::star::xsd::DataTypeClass::DURATION
:
534 case com::sun::star::xsd::DataTypeClass::gYearMonth
:
535 case com::sun::star::xsd::DataTypeClass::gMonthDay
:
536 case com::sun::star::xsd::DataTypeClass::hexBinary
:
537 case com::sun::star::xsd::DataTypeClass::base64Binary
:
538 case com::sun::star::xsd::DataTypeClass::QName
:
539 case com::sun::star::xsd::DataTypeClass::NOTATION
:
541 DBG_ERROR( "unknown data type" );
544 return rExport
.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_XSD
,
545 GetXMLToken( eToken
) );
548 void lcl_exportDataType( SvXMLExport
& rExport
,
549 const Reference
<XPropertySet
>& xType
)
551 // we do not need to export basic types; exit if we have one
552 bool bIsBasic
= false;
553 xType
->getPropertyValue( OUSTRING("IsBasic") ) >>= bIsBasic
;
557 // no basic type -> export
559 // <xsd:simpleType name="...">
561 xType
->getPropertyValue( OUSTRING("Name") ) >>= sName
;
562 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_NAME
, sName
);
563 SvXMLElementExport
aSimpleType( rExport
,
564 XML_NAMESPACE_XSD
, XML_SIMPLETYPE
,
565 sal_True
, sal_True
);
567 // <xsd:restriction base="xsd:...">
568 rExport
.AddAttribute( XML_NAMESPACE_NONE
, XML_BASE
,
569 lcl_getXSDType( rExport
, xType
) );
570 SvXMLElementExport
aRestriction( rExport
,
573 sal_True
, sal_True
);
576 lcl_exportDataTypeFacets( rExport
,
577 Reference
<XPropertySet
>( xType
, UNO_QUERY
),
578 aDataTypeFacetTable
);
581 void exportXFormsSchemas( SvXMLExport
& rExport
,
582 const Reference
<com::sun::star::xforms::XModel
>& xModel
)
584 // TODO: for now, we'll fake this...
586 SvXMLElementExport
aSchemaElem( rExport
, XML_NAMESPACE_XSD
, XML_SCHEMA
,
587 sal_True
, sal_True
);
589 // now get data type repositry, and export
590 Reference
<XEnumerationAccess
> xTypes( xModel
->getDataTypeRepository(),
594 Reference
<XEnumeration
> xEnum
= xTypes
->createEnumeration();
595 DBG_ASSERT( xEnum
.is(), "no enum?" );
596 while( xEnum
->hasMoreElements() )
598 Reference
<XPropertySet
> xType( xEnum
->nextElement(), UNO_QUERY
);
599 lcl_exportDataType( rExport
, xType
);
604 // export other, 'foreign' schemas
605 Reference
<XPropertySet
> xPropSet( xModel
, UNO_QUERY
);
608 Reference
<XDocument
> xDocument(
609 xPropSet
->getPropertyValue( OUSTRING("ForeignSchema") ),
613 exportDom( rExport
, xDocument
);
623 void lcl_export( const Reference
<XPropertySet
>& rPropertySet
,
624 SvXMLExport
& rExport
,
625 const ExportTable
* pTable
)
627 for( const ExportTable
* pCurrent
= pTable
;
628 pCurrent
->pPropertyName
!= NULL
;
631 Any aAny
= rPropertySet
->getPropertyValue(
632 OUString::createFromAscii( pCurrent
->pPropertyName
) );
633 OUString sValue
= (*pCurrent
->aConverter
)( aAny
);
635 if( sValue
.getLength() > 0 )
636 rExport
.AddAttribute(
637 pCurrent
->nNamespace
,
638 static_cast<XMLTokenEnum
>( pCurrent
->nToken
),
646 // any conversion functions
649 template<typename T
, void (*FUNC
)( OUStringBuffer
&, T
)>
650 OUString
lcl_convert( const Any
& rAny
)
652 OUStringBuffer aBuffer
;
656 FUNC( aBuffer
, aData
);
658 return aBuffer
.makeStringAndClear();
661 template<typename T
, void (*FUNC
)( OUStringBuffer
&, const T
& )>
662 OUString
lcl_convertRef( const Any
& rAny
)
664 OUStringBuffer aBuffer
;
668 FUNC( aBuffer
, aData
);
670 return aBuffer
.makeStringAndClear();
673 OUString
lcl_string( const Any
& rAny
)
680 OUString
lcl_bool( const Any
& rAny
)
682 bool bResult
= bool();
683 if( rAny
>>= bResult
)
684 return GetXMLToken( bResult
? XML_TRUE
: XML_FALSE
);
685 DBG_ERROR( "expected boolean value" );
689 void lcl_formatDate( OUStringBuffer
& aBuffer
, const Date
& rDate
)
691 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Year
) );
692 aBuffer
.append( sal_Unicode('-') );
693 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Month
) );
694 aBuffer
.append( sal_Unicode('-') );
695 aBuffer
.append( static_cast<sal_Int32
>( rDate
.Day
) );
698 void lcl_formatTime( OUStringBuffer
& aBuffer
, const com::sun::star::util::Time
& rTime
)
701 aDateTime
.Hours
= rTime
.Hours
;
702 aDateTime
.Minutes
= rTime
.Minutes
;
703 aDateTime
.Seconds
= rTime
.Seconds
;
704 aDateTime
.HundredthSeconds
= rTime
.HundredthSeconds
;
705 SvXMLUnitConverter::convertTime( aBuffer
, aDateTime
);
708 void lcl_formatDateTime( OUStringBuffer
& aBuffer
, const DateTime
& aDateTime
)
710 SvXMLUnitConverter::convertDateTime( aBuffer
, aDateTime
);
713 OUString
lcl_whitespace( const Any
& rAny
)
716 sal_uInt16 n
= sal_uInt16();
721 case com::sun::star::xsd::WhiteSpaceTreatment::Preserve
:
722 sResult
= GetXMLToken( XML_PRESERVE
);
724 case com::sun::star::xsd::WhiteSpaceTreatment::Replace
:
725 sResult
= GetXMLToken( XML_REPLACE
);
727 case com::sun::star::xsd::WhiteSpaceTreatment::Collapse
:
728 sResult
= GetXMLToken( XML_COLLAPSE
);
736 /// return name of Binding
737 OUString
lcl_getXFormsBindName( const Reference
<XPropertySet
>& xBinding
)
739 OUString
sProp( OUSTRING( "BindingID" ) );
743 xBinding
->getPropertySetInfo()->hasPropertyByName( sProp
) )
745 xBinding
->getPropertyValue( sProp
) >>= sReturn
;
750 // return name of binding
751 OUString
getXFormsBindName( const Reference
<XPropertySet
>& xControl
)
753 Reference
<XBindableValue
> xBindable( xControl
, UNO_QUERY
);
754 return xBindable
.is()
755 ? lcl_getXFormsBindName(
756 Reference
<XPropertySet
>( xBindable
->getValueBinding(), UNO_QUERY
))
760 // return name of list binding
761 OUString
getXFormsListBindName( const Reference
<XPropertySet
>& xControl
)
763 Reference
<XListEntrySink
> xListEntrySink( xControl
, UNO_QUERY
);
764 return xListEntrySink
.is()
765 ? lcl_getXFormsBindName(
766 Reference
<XPropertySet
>( xListEntrySink
->getListEntrySource(),
771 OUString
getXFormsSubmissionName( const Reference
<XPropertySet
>& xBinding
)
775 Reference
<XSubmissionSupplier
> xSubmissionSupplier( xBinding
, UNO_QUERY
);
776 if( xSubmissionSupplier
.is() )
778 Reference
<XPropertySet
> xPropertySet(
779 xSubmissionSupplier
->getSubmission(), UNO_QUERY
);
780 OUString
sProp( OUSTRING("ID") );
781 if( xPropertySet
.is() &&
782 xPropertySet
->getPropertySetInfo()->hasPropertyByName( sProp
) )
784 xPropertySet
->getPropertyValue( sProp
) >>= sReturn
;
791 void getXFormsSettings( const Reference
< XNameAccess
>& _rXForms
, Sequence
< PropertyValue
>& _out_rSettings
)
793 _out_rSettings
= Sequence
< PropertyValue
>();
795 OSL_PRECOND( _rXForms
.is(), "getXFormsSettings: invalid XForms container!" );
796 if ( !_rXForms
.is() )
801 // we want to export some special properties of our XForms models as config-item-map-named,
802 // which implies we need a PropertyValue whose value is an XNameAccess, whose keys
803 // are the names of the XForm models, and which in turn provides named sequences of
804 // PropertyValues - which denote the actual property values of the given named model.
806 Sequence
< ::rtl::OUString
> aModelNames( _rXForms
->getElementNames() );
808 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
809 Reference
< XNameContainer
> xModelSettings(
810 aContext
.createComponent( "com.sun.star.document.NamedPropertyValues" ),
813 for ( const ::rtl::OUString
* pModelName
= aModelNames
.getConstArray();
814 pModelName
!= aModelNames
.getConstArray() + aModelNames
.getLength();
818 Reference
< XPropertySet
> xModelProps( _rXForms
->getByName( *pModelName
), UNO_QUERY_THROW
);
820 Sequence
< PropertyValue
> aModelSettings( 1 );
821 aModelSettings
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ExternalData" ) );
822 aModelSettings
[0].Value
= xModelProps
->getPropertyValue( aModelSettings
[0].Name
);
824 xModelSettings
->insertByName( *pModelName
, makeAny( aModelSettings
) );
827 if ( xModelSettings
->hasElements() )
829 _out_rSettings
.realloc( 1 );
830 _out_rSettings
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XFormModels" ) );
831 _out_rSettings
[0].Value
<<= xModelSettings
;
834 catch( const Exception
& )
836 DBG_UNHANDLED_EXCEPTION();