LCOV - code coverage report
Current view: top level - xmloff/source/xforms - xformsexport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 306 9.2 %
Date: 2015-06-13 12:38:46 Functions: 6 28 21.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <xmloff/xformsexport.hxx>
      22             : 
      23             : #include "XFormsModelExport.hxx"
      24             : #include "xformsapi.hxx"
      25             : 
      26             : #include <xmloff/xmlexp.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmlnmspe.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include "DomExport.hxx"
      31             : 
      32             : #include <sax/tools/converter.hxx>
      33             : 
      34             : #include <comphelper/processfactory.hxx>
      35             : 
      36             : #include <tools/debug.hxx>
      37             : #include <tools/diagnose_ex.h>
      38             : #include <com/sun/star/container/XIndexAccess.hpp>
      39             : #include <com/sun/star/container/XNameAccess.hpp>
      40             : #include <com/sun/star/document/NamedPropertyValues.hpp>
      41             : #include <com/sun/star/xml/dom/XDocument.hpp>
      42             : #include <com/sun/star/form/binding/XValueBinding.hpp>
      43             : #include <com/sun/star/form/binding/XBindableValue.hpp>
      44             : #include <com/sun/star/form/binding/XListEntrySink.hpp>
      45             : #include <com/sun/star/form/binding/XListEntrySource.hpp>
      46             : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
      47             : #include <com/sun/star/xforms/XModel.hpp>
      48             : #include <com/sun/star/xforms/XDataTypeRepository.hpp>
      49             : #include <com/sun/star/xforms/XFormsSupplier.hpp>
      50             : #include <com/sun/star/beans/PropertyValue.hpp>
      51             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      52             : #include <com/sun/star/container/XEnumeration.hpp>
      53             : #include <com/sun/star/container/XNameContainer.hpp>
      54             : #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
      55             : #include <com/sun/star/xsd/DataTypeClass.hpp>
      56             : #include <com/sun/star/xsd/XDataType.hpp>
      57             : #include <com/sun/star/util/Date.hpp>
      58             : #include <com/sun/star/util/Time.hpp>
      59             : #include <com/sun/star/util/DateTime.hpp>
      60             : #include <com/sun/star/util/Duration.hpp>
      61             : 
      62             : using namespace com::sun::star;
      63             : using namespace com::sun::star::uno;
      64             : using namespace xmloff::token;
      65             : 
      66             : using com::sun::star::beans::XPropertySet;
      67             : using com::sun::star::beans::XPropertySetInfo;
      68             : using com::sun::star::container::XIndexAccess;
      69             : using com::sun::star::container::XNameAccess;
      70             : using com::sun::star::container::XNameContainer;
      71             : using com::sun::star::container::XEnumerationAccess;
      72             : using com::sun::star::container::XEnumeration;
      73             : using com::sun::star::xml::dom::XDocument;
      74             : using com::sun::star::form::binding::XValueBinding;
      75             : using com::sun::star::form::binding::XBindableValue;
      76             : using com::sun::star::form::binding::XListEntrySink;
      77             : using com::sun::star::form::submission::XSubmissionSupplier;
      78             : using com::sun::star::beans::PropertyValue;
      79             : using com::sun::star::xsd::XDataType;
      80             : using com::sun::star::xforms::XDataTypeRepository;
      81             : using com::sun::star::xforms::XFormsSupplier;
      82             : using com::sun::star::util::Duration;
      83             : 
      84           2 : void exportXForms( SvXMLExport& rExport )
      85             : {
      86           2 :     Reference<XFormsSupplier> xSupplier( rExport.GetModel(), UNO_QUERY );
      87           2 :     if( xSupplier.is() )
      88             :     {
      89           2 :         Reference<XNameContainer> xForms = xSupplier->getXForms();
      90           2 :         if( xForms.is() )
      91             :         {
      92           0 :             Sequence<OUString> aNames = xForms->getElementNames();
      93           0 :             const OUString* pNames = aNames.getConstArray();
      94           0 :             sal_Int32 nNames = aNames.getLength();
      95             : 
      96           0 :             for( sal_Int32 n = 0; n < nNames; n++ )
      97             :             {
      98           0 :                 Reference<XPropertySet> xModel( xForms->getByName( pNames[n] ),
      99           0 :                                                 UNO_QUERY );
     100           0 :                 exportXFormsModel( rExport, xModel );
     101           0 :             }
     102           2 :         }
     103           2 :     }
     104           2 : }
     105             : 
     106             : 
     107             : void exportXFormsInstance( SvXMLExport&, const Sequence<PropertyValue>& );
     108             : void exportXFormsBinding( SvXMLExport&, const Reference<XPropertySet>& );
     109             : void exportXFormsSubmission( SvXMLExport&, const Reference<XPropertySet>& );
     110             : void exportXFormsSchemas( SvXMLExport&, const Reference<com::sun::star::xforms::XModel>& );
     111             : 
     112             : 
     113             : typedef OUString (*convert_t)( const Any& );
     114             : typedef struct
     115             : {
     116             :     const sal_Char* pPropertyName;
     117             :     sal_uInt16 nPropertyNameLength;
     118             :     sal_uInt16 nNamespace;
     119             :     sal_uInt16 nToken;
     120             :     convert_t aConverter;
     121             : } ExportTable;
     122             : static void lcl_export( const Reference<XPropertySet>& rPropertySet,
     123             :                  SvXMLExport& rExport,
     124             :                  const ExportTable* pTable );
     125             : 
     126             : #define TABLE_ENTRY(NAME,NAMESPACE,TOKEN,CONVERTER) { NAME,sizeof(NAME)-1,XML_NAMESPACE_##NAMESPACE,xmloff::token::XML_##TOKEN, CONVERTER }
     127             : #define TABLE_END { NULL, 0, 0, 0, NULL }
     128             : 
     129             : // any conversion functions
     130             : OUString xforms_string( const Any& );
     131             : OUString xforms_bool( const Any& );
     132             : OUString xforms_whitespace( const Any& );
     133             : template<typename T, void (*FUNC)( OUStringBuffer&, T )> OUString xforms_convert( const Any& );
     134             : template<typename T, void (*FUNC)( OUStringBuffer&, const T& )> OUString xforms_convertRef( const Any& );
     135             : 
     136             : void xforms_formatDate( OUStringBuffer& aBuffer, const util::Date& aDate );
     137             : void xforms_formatTime( OUStringBuffer& aBuffer, const com::sun::star::util::Time& aTime );
     138             : void xforms_formatDateTime( OUStringBuffer& aBuffer, const util::DateTime& aDateTime );
     139             : 
     140             : convert_t xforms_int32    = &xforms_convert<sal_Int32,&::sax::Converter::convertNumber>;
     141             : convert_t xforms_double   = &xforms_convert<double,&::sax::Converter::convertDouble>;
     142             : convert_t xforms_dateTime = &xforms_convertRef<util::DateTime,&xforms_formatDateTime>;
     143             : convert_t xforms_date     = &xforms_convertRef<util::Date,&xforms_formatDate>;
     144             : convert_t xforms_time     = &xforms_convertRef<com::sun::star::util::Time,&xforms_formatTime>;
     145             : 
     146             : // other functions
     147             : static OUString lcl_getXSDType( SvXMLExport& rExport,
     148             :                          const Reference<XPropertySet>& xType );
     149             : 
     150             : 
     151             : 
     152             : // the model
     153             : 
     154             : 
     155             : static const ExportTable aXFormsModelTable[] =
     156             : {
     157             :     TABLE_ENTRY( "ID", NONE, ID, xforms_string ),
     158             :     TABLE_ENTRY( "SchemaRef", NONE, SCHEMA, xforms_string ),
     159             :     TABLE_END
     160             : };
     161             : 
     162           0 : void exportXFormsModel( SvXMLExport& rExport,
     163             :                         const Reference<XPropertySet>& xModelPropSet )
     164             : {
     165             :     // no model -> don't do anything!
     166           0 :     Reference<com::sun::star::xforms::XModel> xModel( xModelPropSet, UNO_QUERY );
     167           0 :     if( ! xModel.is() || ! xModelPropSet.is() )
     168           0 :         return;
     169             : 
     170           0 :     lcl_export( xModelPropSet, rExport, aXFormsModelTable );
     171             :     SvXMLElementExport aModelElement( rExport, XML_NAMESPACE_XFORMS, XML_MODEL,
     172           0 :                                       true, true );
     173             : 
     174             :     // instances
     175           0 :     Reference<XIndexAccess> xInstances( xModel->getInstances(),
     176           0 :                                         UNO_QUERY_THROW);
     177           0 :     sal_Int32 nCount = xInstances->getCount();
     178           0 :     sal_Int32 i = 0;
     179           0 :     for( i = 0; i < nCount; i++ )
     180             :     {
     181           0 :         Sequence<PropertyValue> aInstance;
     182           0 :         xInstances->getByIndex( i ) >>= aInstance;
     183           0 :         exportXFormsInstance( rExport, aInstance );
     184           0 :     }
     185             : 
     186             : 
     187             :     // bindings
     188           0 :     Reference<XIndexAccess> xBindings( xModel->getBindings(), UNO_QUERY_THROW);
     189           0 :     nCount = xBindings->getCount();
     190           0 :     for( i = 0; i < nCount; i++ )
     191             :     {
     192           0 :         Reference<XPropertySet> aBinding( xBindings->getByIndex( i ),
     193           0 :                                           UNO_QUERY_THROW );
     194           0 :         exportXFormsBinding( rExport, aBinding );
     195           0 :     }
     196             : 
     197             :     // submissions
     198           0 :     Reference<XIndexAccess> xSubmissions( xModel->getSubmissions(),
     199           0 :                                           UNO_QUERY_THROW );
     200           0 :     nCount = xSubmissions->getCount();
     201           0 :     for( i = 0; i < nCount; i++ )
     202             :     {
     203           0 :         Reference<XPropertySet> xSubmission( xSubmissions->getByIndex( i ),
     204           0 :                                           UNO_QUERY_THROW );
     205           0 :         exportXFormsSubmission( rExport, xSubmission );
     206           0 :     }
     207             : 
     208             :     // schemas
     209           0 :     exportXFormsSchemas( rExport, xModel );
     210             : }
     211             : 
     212             : 
     213             : // the instance
     214             : 
     215             : 
     216           0 : void exportXFormsInstance( SvXMLExport& rExport,
     217             :                            const Sequence<PropertyValue>& xInstance )
     218             : {
     219           0 :     OUString sId;
     220           0 :     OUString sURL;
     221           0 :     Reference<XDocument> xDoc;
     222             : 
     223           0 :     const PropertyValue* pInstance = xInstance.getConstArray();
     224           0 :     sal_Int32 nCount = xInstance.getLength();
     225           0 :     for( sal_Int32 i = 0; i < nCount; i++ )
     226             :     {
     227           0 :         OUString sName = pInstance[i].Name;
     228           0 :         const Any& rAny = pInstance[i].Value;
     229           0 :         if ( sName == "ID" )
     230           0 :             rAny >>= sId;
     231           0 :         else if ( sName == "URL" )
     232           0 :             rAny >>= sURL;
     233           0 :         else if ( sName == "Instance" )
     234           0 :             rAny >>= xDoc;
     235           0 :     }
     236             : 
     237           0 :     if( !sId.isEmpty() )
     238           0 :         rExport.AddAttribute( XML_NAMESPACE_NONE, XML_ID, sId );
     239             : 
     240           0 :     if( !sURL.isEmpty() )
     241           0 :         rExport.AddAttribute( XML_NAMESPACE_NONE, XML_SRC, sURL );
     242             : 
     243             :     SvXMLElementExport aElem( rExport, XML_NAMESPACE_XFORMS, XML_INSTANCE,
     244           0 :                               true, true );
     245           0 :     rExport.IgnorableWhitespace();
     246           0 :     if( xDoc.is() )
     247             :     {
     248           0 :         exportDom( rExport, xDoc );
     249           0 :     }
     250           0 : }
     251             : 
     252             : 
     253             : 
     254             : // the binding
     255             : 
     256             : 
     257             : static const ExportTable aXFormsBindingTable[] =
     258             : {
     259             :     TABLE_ENTRY( "BindingID",            NONE, ID,         xforms_string ),
     260             :     TABLE_ENTRY( "BindingExpression",    NONE, NODESET,    xforms_string ),
     261             :     TABLE_ENTRY( "ReadonlyExpression",   NONE, READONLY,   xforms_string ),
     262             :     TABLE_ENTRY( "RelevantExpression",   NONE, RELEVANT,   xforms_string ),
     263             :     TABLE_ENTRY( "RequiredExpression",   NONE, REQUIRED,   xforms_string ),
     264             :     TABLE_ENTRY( "ConstraintExpression", NONE, CONSTRAINT, xforms_string ),
     265             :     TABLE_ENTRY( "CalculateExpression",  NONE, CALCULATE,  xforms_string ),
     266             :     // type handled separatly, for type name <-> XSD type conversion
     267             :     // TABLE_ENTRY( "Type",                 NONE, TYPE,       xforms_string ),
     268             :     TABLE_END
     269             : };
     270             : 
     271           0 : void exportXFormsBinding( SvXMLExport& rExport,
     272             :                         const Reference<XPropertySet>& xBinding )
     273             : {
     274             :     // name check; generate binding ID if necessary
     275             :     {
     276           0 :         OUString sName;
     277           0 :         xBinding->getPropertyValue( "BindingID" ) >>= sName;
     278           0 :         if( sName.isEmpty() )
     279             :         {
     280             :             // if we don't have a name yet, generate one on the fly
     281           0 :             OUStringBuffer aBuffer;
     282           0 :             aBuffer.append( "bind_" );
     283           0 :             sal_Int64 nId = reinterpret_cast<sal_uInt64>( xBinding.get() );
     284           0 :             aBuffer.append( nId , 16 );
     285           0 :             sName = aBuffer.makeStringAndClear();
     286           0 :             xBinding->setPropertyValue( "BindingID", makeAny(sName));
     287           0 :         }
     288             :     }
     289             : 
     290           0 :     lcl_export( xBinding, rExport, aXFormsBindingTable );
     291             : 
     292             :     // handle type attribute
     293             :     {
     294           0 :         OUString sTypeName;
     295           0 :         xBinding->getPropertyValue( "Type" ) >>= sTypeName;
     296             : 
     297             :         try
     298             :         {
     299             :             // now get type, and determine whether it's a standard type. If
     300             :             // so, export the XSD name
     301             :             Reference<com::sun::star::xforms::XModel> xModel(
     302           0 :                 xBinding->getPropertyValue( "Model" ),
     303           0 :                 UNO_QUERY );
     304             :             Reference<XDataTypeRepository> xRepository(
     305           0 :                 xModel.is() ? xModel->getDataTypeRepository() : Reference<XDataTypeRepository>() );
     306           0 :             if( xRepository.is() )
     307             :             {
     308             :                 Reference<XPropertySet> xDataType(
     309           0 :                     xRepository->getDataType( sTypeName ),
     310           0 :                     UNO_QUERY );
     311             : 
     312             :                 // if it's a basic data type, write out the XSD name
     313             :                 // for the XSD type class
     314           0 :                 bool bIsBasic = false;
     315           0 :                 xDataType->getPropertyValue( "IsBasic" ) >>= bIsBasic;
     316           0 :                 if( bIsBasic )
     317           0 :                     sTypeName = lcl_getXSDType( rExport, xDataType );
     318           0 :             }
     319             :         }
     320           0 :         catch( Exception& )
     321             :         {
     322             :             ; // ignore; just use typename
     323             :         }
     324             : 
     325             :         // now that we have the proper type name, write out the attribute
     326           0 :         if( !sTypeName.isEmpty() )
     327             :         {
     328             :             rExport.AddAttribute( XML_NAMESPACE_NONE, XML_TYPE,
     329           0 :                                   sTypeName );
     330           0 :         }
     331             :     }
     332             : 
     333             :     // we need to ensure all the namespaces in the binding will work correctly.
     334             :     // to do so, we will write out all missing namespace declaractions.
     335           0 :     const SvXMLNamespaceMap& rMap = rExport.GetNamespaceMap();
     336             :     Reference<XNameAccess> xNamespaces(
     337           0 :         xBinding->getPropertyValue( "ModelNamespaces" ), UNO_QUERY);
     338           0 :     if( xNamespaces.is() )
     339             :     {
     340             :         // iterate over Prefixes for this binding
     341           0 :         Sequence<OUString> aPrefixes = xNamespaces->getElementNames();
     342           0 :         const OUString* pPrefixes = aPrefixes.getConstArray();
     343           0 :         sal_Int32 nPrefixes = aPrefixes.getLength();
     344           0 :         for( sal_Int32 i = 0; i < nPrefixes; i++ )
     345             :         {
     346           0 :             const OUString& rPrefix = pPrefixes[i];
     347           0 :             OUString sURI;
     348           0 :             xNamespaces->getByName( rPrefix ) >>= sURI;
     349             : 
     350             :             // check whether prefix/URI pair is in map; else write declaration
     351             :             // (we don't need to change the map, since this element has no
     352             :             // other content)
     353           0 :             sal_uInt16 nKey = rMap.GetKeyByPrefix( rPrefix );
     354           0 :             if( nKey == XML_NAMESPACE_UNKNOWN  ||
     355           0 :                 rMap.GetNameByKey( nKey ) != sURI )
     356             :             {
     357           0 :                 rExport.AddAttribute( "xmlns:" + rPrefix, sURI );
     358             :             }
     359           0 :         }
     360             :     }
     361             : 
     362             :     SvXMLElementExport aElement( rExport, XML_NAMESPACE_XFORMS, XML_BIND,
     363           0 :                                  true, true );
     364           0 : }
     365             : 
     366             : 
     367             : 
     368             : // the submission
     369             : 
     370             : 
     371             : static const ExportTable aXFormsSubmissionTable[] =
     372             : {
     373             :     TABLE_ENTRY( "ID",         NONE, ID,        xforms_string ),
     374             :     TABLE_ENTRY( "Bind",       NONE, BIND,      xforms_string ),
     375             :     TABLE_ENTRY( "Ref",        NONE, REF,       xforms_string ),
     376             :     TABLE_ENTRY( "Action",     NONE, ACTION,    xforms_string ),
     377             :     TABLE_ENTRY( "Method",     NONE, METHOD,    xforms_string ),
     378             :     TABLE_ENTRY( "Version",    NONE, VERSION,   xforms_string ),
     379             :     TABLE_ENTRY( "Indent",     NONE, INDENT,    xforms_bool ),
     380             :     TABLE_ENTRY( "MediaType",  NONE, MEDIATYPE, xforms_string ),
     381             :     TABLE_ENTRY( "Encoding",   NONE, ENCODING, xforms_string ),
     382             :     TABLE_ENTRY( "OmitXmlDeclaration",  NONE, OMIT_XML_DECLARATION, xforms_bool ),
     383             :     TABLE_ENTRY( "Standalone", NONE, STANDALONE, xforms_bool ),
     384             :     TABLE_ENTRY( "CDataSectionElement", NONE, CDATA_SECTION_ELEMENTS, xforms_string ),
     385             :     TABLE_ENTRY( "Replace",    NONE, REPLACE, xforms_string ),
     386             :     TABLE_ENTRY( "Separator",  NONE, SEPARATOR, xforms_string ),
     387             :     TABLE_ENTRY( "IncludeNamespacePrefixes", NONE, INCLUDENAMESPACEPREFIXES, xforms_string ),
     388             :     TABLE_END
     389             : };
     390             : 
     391           0 : void exportXFormsSubmission( SvXMLExport& rExport,
     392             :                              const Reference<XPropertySet>& xSubmission )
     393             : {
     394           0 :     lcl_export( xSubmission, rExport, aXFormsSubmissionTable );
     395             :     SvXMLElementExport aElement( rExport, XML_NAMESPACE_XFORMS, XML_SUBMISSION,
     396           0 :                                  true, true );
     397           0 : }
     398             : 
     399             : 
     400             : 
     401             : 
     402             : // export data types as XSD schema
     403             : 
     404             : 
     405             : static const ExportTable aDataTypeFacetTable[] =
     406             : {
     407             :     TABLE_ENTRY( "Length",               XSD, LENGTH,         xforms_int32 ),
     408             :     TABLE_ENTRY( "MinLength",            XSD, MINLENGTH,      xforms_int32 ),
     409             :     TABLE_ENTRY( "MaxLength",            XSD, MAXLENGTH,      xforms_int32 ),
     410             :     TABLE_ENTRY( "MinInclusiveInt",      XSD, MININCLUSIVE,   xforms_int32 ),
     411             :     TABLE_ENTRY( "MinExclusiveInt",      XSD, MINEXCLUSIVE,   xforms_int32 ),
     412             :     TABLE_ENTRY( "MaxInclusiveInt",      XSD, MAXINCLUSIVE,   xforms_int32 ),
     413             :     TABLE_ENTRY( "MaxExclusiveInt",      XSD, MAXEXCLUSIVE,   xforms_int32 ),
     414             :     TABLE_ENTRY( "MinInclusiveDouble",   XSD, MININCLUSIVE,   xforms_double ),
     415             :     TABLE_ENTRY( "MinExclusiveDouble",   XSD, MINEXCLUSIVE,   xforms_double ),
     416             :     TABLE_ENTRY( "MaxInclusiveDouble",   XSD, MAXINCLUSIVE,   xforms_double ),
     417             :     TABLE_ENTRY( "MaxExclusiveDouble",   XSD, MAXEXCLUSIVE,   xforms_double ),
     418             :     TABLE_ENTRY( "MinInclusiveDate",     XSD, MININCLUSIVE,   xforms_date ),
     419             :     TABLE_ENTRY( "MinExclusiveDate",     XSD, MINEXCLUSIVE,   xforms_date ),
     420             :     TABLE_ENTRY( "MaxInclusiveDate",     XSD, MAXINCLUSIVE,   xforms_date ),
     421             :     TABLE_ENTRY( "MaxExclusiveDate",     XSD, MAXEXCLUSIVE,   xforms_date ),
     422             :     TABLE_ENTRY( "MinInclusiveTime",     XSD, MININCLUSIVE,   xforms_time ),
     423             :     TABLE_ENTRY( "MinExclusiveTime",     XSD, MINEXCLUSIVE,   xforms_time ),
     424             :     TABLE_ENTRY( "MaxInclusiveTime",     XSD, MAXINCLUSIVE,   xforms_time ),
     425             :     TABLE_ENTRY( "MaxExclusiveTime",     XSD, MAXEXCLUSIVE,   xforms_time ),
     426             :     TABLE_ENTRY( "MinInclusiveDateTime", XSD, MININCLUSIVE,   xforms_dateTime ),
     427             :     TABLE_ENTRY( "MinExclusiveDateTime", XSD, MINEXCLUSIVE,   xforms_dateTime ),
     428             :     TABLE_ENTRY( "MaxInclusiveDateTime", XSD, MAXINCLUSIVE,   xforms_dateTime ),
     429             :     TABLE_ENTRY( "MaxExclusiveDateTime", XSD, MAXEXCLUSIVE,   xforms_dateTime ),
     430             :     TABLE_ENTRY( "Pattern",              XSD, PATTERN,        xforms_string ),
     431             :     // ??? XML_ENUMERATION,
     432             :     TABLE_ENTRY( "WhiteSpace",           XSD, WHITESPACE,     xforms_whitespace ),
     433             :     TABLE_ENTRY( "TotalDigits",          XSD, TOTALDIGITS,    xforms_int32 ),
     434             :     TABLE_ENTRY( "FractionDigits",       XSD, FRACTIONDIGITS, xforms_int32 ),
     435             :     TABLE_END
     436         152 : };
     437             : 
     438             : // export facets through table; use the same table as lcl_export does
     439           0 : static void lcl_exportDataTypeFacets( SvXMLExport& rExport,
     440             :                                const Reference<XPropertySet>& rPropertySet,
     441             :                                const ExportTable* pTable )
     442             : {
     443           0 :     Reference<XPropertySetInfo> xInfo = rPropertySet->getPropertySetInfo();
     444           0 :     for( const ExportTable* pCurrent = pTable;
     445           0 :          pCurrent->pPropertyName != NULL;
     446             :          pCurrent++ )
     447             :     {
     448           0 :         OUString sName( OUString::createFromAscii( pCurrent->pPropertyName ) );
     449           0 :         if( xInfo->hasPropertyByName( sName ) )
     450             :         {
     451             :             OUString sValue = (*pCurrent->aConverter)(
     452           0 :                 rPropertySet->getPropertyValue( sName ) );
     453             : 
     454           0 :             if( !sValue.isEmpty() )
     455             :             {
     456           0 :                 rExport.AddAttribute( XML_NAMESPACE_NONE, XML_VALUE, sValue );
     457             :                 SvXMLElementExport aFacet(
     458             :                     rExport,
     459             :                     pCurrent->nNamespace,
     460             :                     static_cast<XMLTokenEnum>( pCurrent->nToken ),
     461           0 :                     true, true );
     462           0 :             }
     463             :         }
     464           0 :     }
     465           0 : }
     466             : 
     467           0 : static OUString lcl_getXSDType( SvXMLExport& rExport,
     468             :                          const Reference<XPropertySet>& xType )
     469             : {
     470             :     // we use string as default...
     471           0 :     XMLTokenEnum eToken = XML_STRING;
     472             : 
     473           0 :     sal_uInt16 nDataTypeClass = 0;
     474           0 :     xType->getPropertyValue( "TypeClass" ) >>= nDataTypeClass;
     475           0 :     switch( nDataTypeClass )
     476             :     {
     477             :     case com::sun::star::xsd::DataTypeClass::STRING:
     478           0 :         eToken = XML_STRING;
     479           0 :         break;
     480             :     case com::sun::star::xsd::DataTypeClass::anyURI:
     481           0 :         eToken = XML_ANYURI;
     482           0 :         break;
     483             :     case com::sun::star::xsd::DataTypeClass::DECIMAL:
     484           0 :         eToken = XML_DECIMAL;
     485           0 :         break;
     486             :     case com::sun::star::xsd::DataTypeClass::DOUBLE:
     487           0 :         eToken = XML_DOUBLE;
     488           0 :         break;
     489             :     case com::sun::star::xsd::DataTypeClass::FLOAT:
     490           0 :         eToken = XML_FLOAT;
     491           0 :         break;
     492             :     case com::sun::star::xsd::DataTypeClass::BOOLEAN:
     493           0 :         eToken = XML_BOOLEAN;
     494           0 :         break;
     495             :     case com::sun::star::xsd::DataTypeClass::DATETIME:
     496           0 :         eToken = XML_DATETIME_XSD;
     497           0 :         break;
     498             :     case com::sun::star::xsd::DataTypeClass::TIME:
     499           0 :         eToken = XML_TIME;
     500           0 :         break;
     501             :     case com::sun::star::xsd::DataTypeClass::DATE:
     502           0 :         eToken = XML_DATE;
     503           0 :         break;
     504             :     case com::sun::star::xsd::DataTypeClass::gYear:
     505           0 :         eToken = XML_YEAR;
     506           0 :         break;
     507             :     case com::sun::star::xsd::DataTypeClass::gDay:
     508           0 :         eToken = XML_DAY;
     509           0 :         break;
     510             :     case com::sun::star::xsd::DataTypeClass::gMonth:
     511           0 :         eToken = XML_MONTH;
     512           0 :         break;
     513             :     case com::sun::star::xsd::DataTypeClass::DURATION:
     514             :     case com::sun::star::xsd::DataTypeClass::gYearMonth:
     515             :     case com::sun::star::xsd::DataTypeClass::gMonthDay:
     516             :     case com::sun::star::xsd::DataTypeClass::hexBinary:
     517             :     case com::sun::star::xsd::DataTypeClass::base64Binary:
     518             :     case com::sun::star::xsd::DataTypeClass::QName:
     519             :     case com::sun::star::xsd::DataTypeClass::NOTATION:
     520             :     default:
     521             :         OSL_FAIL( "unknown data type" );
     522             :     }
     523             : 
     524           0 :     return rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_XSD,
     525           0 :                                                     GetXMLToken( eToken ) );
     526             : }
     527             : 
     528           0 : static void lcl_exportDataType( SvXMLExport& rExport,
     529             :                          const Reference<XPropertySet>& xType )
     530             : {
     531             :     // we do not need to export basic types; exit if we have one
     532           0 :     bool bIsBasic = false;
     533           0 :     xType->getPropertyValue( "IsBasic" ) >>= bIsBasic;
     534           0 :     if( bIsBasic )
     535           0 :         return;
     536             : 
     537             :     // no basic type -> export
     538             : 
     539             :     // <xsd:simpleType name="...">
     540           0 :     OUString sName;
     541           0 :     xType->getPropertyValue( "Name" ) >>= sName;
     542           0 :     rExport.AddAttribute( XML_NAMESPACE_NONE, XML_NAME, sName );
     543             :     SvXMLElementExport aSimpleType( rExport,
     544             :                                     XML_NAMESPACE_XSD, XML_SIMPLETYPE,
     545           0 :                                     true, true );
     546             : 
     547             :     // <xsd:restriction base="xsd:...">
     548             :     rExport.AddAttribute( XML_NAMESPACE_NONE, XML_BASE,
     549           0 :                           lcl_getXSDType( rExport, xType ) );
     550             :     SvXMLElementExport aRestriction( rExport,
     551             :                                      XML_NAMESPACE_XSD,
     552             :                                      XML_RESTRICTION,
     553           0 :                                      true, true );
     554             : 
     555             :     // export facets
     556             :     lcl_exportDataTypeFacets( rExport,
     557             :                               xType,
     558           0 :                               aDataTypeFacetTable );
     559             : }
     560             : 
     561           0 : void exportXFormsSchemas( SvXMLExport& rExport,
     562             :                           const Reference<com::sun::star::xforms::XModel>& xModel )
     563             : {
     564             :     // TODO: for now, we'll fake this...
     565             :     {
     566             :         SvXMLElementExport aSchemaElem( rExport, XML_NAMESPACE_XSD, XML_SCHEMA,
     567           0 :                                         true, true );
     568             : 
     569             :         // now get data type repositry, and export
     570           0 :         Reference<XEnumerationAccess> xTypes( xModel->getDataTypeRepository(),
     571           0 :                                               UNO_QUERY );
     572           0 :         if( xTypes.is() )
     573             :         {
     574           0 :             Reference<XEnumeration> xEnum = xTypes->createEnumeration();
     575             :             DBG_ASSERT( xEnum.is(), "no enum?" );
     576           0 :             while( xEnum->hasMoreElements() )
     577             :             {
     578           0 :                 Reference<XPropertySet> xType( xEnum->nextElement(), UNO_QUERY );
     579           0 :                 lcl_exportDataType( rExport, xType );
     580           0 :             }
     581           0 :         }
     582             :     }
     583             : 
     584             :     // export other, 'foreign' schemas
     585           0 :     Reference<XPropertySet> xPropSet( xModel, UNO_QUERY );
     586           0 :     if( xPropSet.is() )
     587             :     {
     588             :         Reference<XDocument> xDocument(
     589           0 :             xPropSet->getPropertyValue( "ForeignSchema" ),
     590           0 :             UNO_QUERY );
     591             : 
     592           0 :         if( xDocument.is() )
     593           0 :             exportDom( rExport, xDocument );
     594           0 :     }
     595           0 : }
     596             : 
     597             : 
     598             : 
     599             : 
     600             : // helper functions
     601             : 
     602             : 
     603           0 : static void lcl_export( const Reference<XPropertySet>& rPropertySet,
     604             :                  SvXMLExport& rExport,
     605             :                  const ExportTable* pTable )
     606             : {
     607           0 :     for( const ExportTable* pCurrent = pTable;
     608           0 :          pCurrent->pPropertyName != NULL;
     609             :          pCurrent++ )
     610             :     {
     611           0 :         Any aAny = rPropertySet->getPropertyValue(
     612           0 :                        OUString::createFromAscii( pCurrent->pPropertyName ) );
     613           0 :         OUString sValue = (*pCurrent->aConverter)( aAny );
     614             : 
     615           0 :         if( !sValue.isEmpty() )
     616             :             rExport.AddAttribute(
     617             :                 pCurrent->nNamespace,
     618             :                 static_cast<XMLTokenEnum>( pCurrent->nToken ),
     619           0 :                 sValue );
     620           0 :     }
     621           0 : }
     622             : 
     623             : 
     624             : 
     625             : 
     626             : // any conversion functions
     627             : 
     628             : 
     629             : template<typename T, void (*FUNC)( OUStringBuffer&, T )>
     630           0 : OUString xforms_convert( const Any& rAny )
     631             : {
     632           0 :     OUStringBuffer aBuffer;
     633           0 :     T aData = T();
     634           0 :     if( rAny >>= aData )
     635             :     {
     636           0 :         FUNC( aBuffer, aData );
     637             :     }
     638           0 :     return aBuffer.makeStringAndClear();
     639             : }
     640             : 
     641             : template<typename T, void (*FUNC)( OUStringBuffer&, const T& )>
     642           0 : OUString xforms_convertRef( const Any& rAny )
     643             : {
     644           0 :     OUStringBuffer aBuffer;
     645           0 :     T aData;
     646           0 :     if( rAny >>= aData )
     647             :     {
     648           0 :         FUNC( aBuffer, aData );
     649             :     }
     650           0 :     return aBuffer.makeStringAndClear();
     651             : }
     652             : 
     653           0 : OUString xforms_string( const Any& rAny )
     654             : {
     655           0 :     OUString aResult;
     656           0 :     rAny >>= aResult;
     657           0 :     return aResult;
     658             : }
     659             : 
     660           0 : OUString xforms_bool( const Any& rAny )
     661             : {
     662           0 :     bool bResult = bool();
     663           0 :     if( rAny >>= bResult )
     664           0 :         return GetXMLToken( bResult ? XML_TRUE : XML_FALSE );
     665             :     OSL_FAIL( "expected boolean value" );
     666           0 :     return OUString();
     667             : }
     668             : 
     669           0 : void xforms_formatDate( OUStringBuffer& aBuffer, const util::Date& rDate )
     670             : {
     671             :     aBuffer.append(OUString::number(static_cast<sal_Int32>( rDate.Year ) )
     672           0 :             + "-" + OUString::number(static_cast<sal_Int32>( rDate.Month ))
     673           0 :             + "-" + OUString::number(static_cast<sal_Int32>( rDate.Day )) );
     674           0 : }
     675             : 
     676           0 : void xforms_formatTime( OUStringBuffer& aBuffer, const com::sun::star::util::Time& rTime )
     677             : {
     678           0 :     Duration aDuration;
     679           0 :     aDuration.Hours = rTime.Hours;
     680           0 :     aDuration.Minutes = rTime.Minutes;
     681           0 :     aDuration.Seconds = rTime.Seconds;
     682           0 :     aDuration.NanoSeconds = rTime.NanoSeconds;
     683           0 :     ::sax::Converter::convertDuration( aBuffer, aDuration );
     684           0 : }
     685             : 
     686           0 : void xforms_formatDateTime( OUStringBuffer& aBuffer, const util::DateTime& aDateTime )
     687             : {
     688           0 :     ::sax::Converter::convertDateTime(aBuffer, aDateTime, 0);
     689           0 : }
     690             : 
     691           0 : OUString xforms_whitespace( const Any& rAny )
     692             : {
     693           0 :     OUString sResult;
     694           0 :     sal_uInt16 n = sal_uInt16();
     695           0 :     if( rAny >>= n )
     696             :     {
     697           0 :         switch( n )
     698             :         {
     699             :         case com::sun::star::xsd::WhiteSpaceTreatment::Preserve:
     700           0 :             sResult = GetXMLToken( XML_PRESERVE );
     701           0 :             break;
     702             :         case com::sun::star::xsd::WhiteSpaceTreatment::Replace:
     703           0 :             sResult = GetXMLToken( XML_REPLACE );
     704           0 :             break;
     705             :         case com::sun::star::xsd::WhiteSpaceTreatment::Collapse:
     706           0 :             sResult = GetXMLToken( XML_COLLAPSE );
     707           0 :             break;
     708             :         }
     709             :     }
     710           0 :     return sResult;
     711             : }
     712             : 
     713             : 
     714             : /// return name of Binding
     715           0 : static OUString lcl_getXFormsBindName( const Reference<XPropertySet>& xBinding )
     716             : {
     717           0 :     OUString sProp( "BindingID" );
     718             : 
     719           0 :     OUString sReturn;
     720           0 :     if( xBinding.is() &&
     721           0 :         xBinding->getPropertySetInfo()->hasPropertyByName( sProp ) )
     722             :     {
     723           0 :         xBinding->getPropertyValue( sProp ) >>= sReturn;
     724             :     }
     725           0 :     return sReturn;
     726             : }
     727             : 
     728             : // return name of binding
     729           2 : OUString getXFormsBindName( const Reference<XPropertySet>& xControl )
     730             : {
     731           2 :     Reference<XBindableValue> xBindable( xControl, UNO_QUERY );
     732           2 :     return xBindable.is()
     733             :         ? lcl_getXFormsBindName(
     734           0 :             Reference<XPropertySet>( xBindable->getValueBinding(), UNO_QUERY ))
     735           2 :         : OUString();
     736             : }
     737             : 
     738             : // return name of list binding
     739           2 : OUString getXFormsListBindName( const Reference<XPropertySet>& xControl )
     740             : {
     741           2 :     Reference<XListEntrySink> xListEntrySink( xControl, UNO_QUERY );
     742           2 :     return xListEntrySink.is()
     743             :         ? lcl_getXFormsBindName(
     744           0 :             Reference<XPropertySet>( xListEntrySink->getListEntrySource(),
     745             :                                      UNO_QUERY ) )
     746           2 :         : OUString();
     747             : }
     748             : 
     749           2 : OUString getXFormsSubmissionName( const Reference<XPropertySet>& xBinding )
     750             : {
     751           2 :     OUString sReturn;
     752             : 
     753           4 :     Reference<XSubmissionSupplier> xSubmissionSupplier( xBinding, UNO_QUERY );
     754           2 :     if( xSubmissionSupplier.is() )
     755             :     {
     756             :         Reference<XPropertySet> xPropertySet(
     757           2 :             xSubmissionSupplier->getSubmission(), UNO_QUERY );
     758           4 :         OUString sProp( "ID" );
     759           6 :         if( xPropertySet.is() &&
     760           2 :             xPropertySet->getPropertySetInfo()->hasPropertyByName( sProp ) )
     761             :         {
     762           0 :             xPropertySet->getPropertyValue( sProp ) >>= sReturn;
     763           2 :         }
     764             :     }
     765             : 
     766           4 :     return sReturn;
     767             : }
     768             : 
     769           0 : void getXFormsSettings( const Reference< XNameAccess >& _rXForms, Sequence< PropertyValue >& _out_rSettings )
     770             : {
     771           0 :     _out_rSettings = Sequence< PropertyValue >();
     772             : 
     773             :     OSL_PRECOND( _rXForms.is(), "getXFormsSettings: invalid XForms container!" );
     774           0 :     if ( !_rXForms.is() )
     775           0 :         return;
     776             : 
     777             :     try
     778             :     {
     779             :         // we want to export some special properties of our XForms models as config-item-map-named,
     780             :         // which implies we need a PropertyValue whose value is an XNameAccess, whose keys
     781             :         // are the names of the XForm models, and which in turn provides named sequences of
     782             :         // PropertyValues - which denote the actual property values of the given named model.
     783             : 
     784           0 :         Sequence< OUString > aModelNames( _rXForms->getElementNames() );
     785             : 
     786           0 :         Reference< XNameContainer > xModelSettings = document::NamedPropertyValues::create( comphelper::getProcessComponentContext() );
     787             : 
     788           0 :         for (   const OUString* pModelName = aModelNames.getConstArray();
     789           0 :                 pModelName != aModelNames.getConstArray() + aModelNames.getLength();
     790             :                 ++pModelName
     791             :             )
     792             :         {
     793           0 :             Reference< XPropertySet > xModelProps( _rXForms->getByName( *pModelName ), UNO_QUERY_THROW );
     794             : 
     795           0 :             Sequence< PropertyValue > aModelSettings( 1 );
     796           0 :             aModelSettings[0].Name = "ExternalData";
     797           0 :             aModelSettings[0].Value = xModelProps->getPropertyValue( aModelSettings[0].Name );
     798             : 
     799           0 :             xModelSettings->insertByName( *pModelName, makeAny( aModelSettings ) );
     800           0 :         }
     801             : 
     802           0 :         if ( xModelSettings->hasElements() )
     803             :         {
     804           0 :             _out_rSettings.realloc( 1 );
     805           0 :             _out_rSettings[0].Name = "XFormModels";
     806           0 :             _out_rSettings[0].Value <<= xModelSettings;
     807           0 :         }
     808             :     }
     809           0 :     catch( const Exception& )
     810             :     {
     811             :         DBG_UNHANDLED_EXCEPTION();
     812             :     }
     813         456 : }
     814             : 
     815             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11