LCOV - code coverage report
Current view: top level - xmloff/source/xforms - XFormsBindContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 49 0.0 %
Date: 2014-11-03 Functions: 0 7 0.0 %
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 "XFormsBindContext.hxx"
      22             : 
      23             : #include "xformsapi.hxx"
      24             : 
      25             : #include <xmloff/xmlimp.hxx>
      26             : #include <xmloff/xmlerror.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmltkmap.hxx>
      29             : #include <xmloff/xmlnmspe.hxx>
      30             : #include <xmloff/nmspmap.hxx>
      31             : 
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/xforms/XModel2.hpp>
      34             : 
      35             : #include <tools/debug.hxx>
      36             : 
      37             : using com::sun::star::beans::XPropertySet;
      38             : using com::sun::star::uno::Reference;
      39             : using com::sun::star::uno::makeAny;
      40             : using com::sun::star::uno::UNO_QUERY;
      41             : using com::sun::star::uno::UNO_QUERY_THROW;
      42             : using com::sun::star::container::XNameContainer;
      43             : using com::sun::star::xml::sax::XAttributeList;
      44             : using com::sun::star::xforms::XModel2;
      45             : using namespace xmloff::token;
      46             : 
      47             : 
      48             : 
      49             : 
      50             : static const struct SvXMLTokenMapEntry aAttributeMap[] =
      51             : {
      52             :     TOKEN_MAP_ENTRY( NONE, NODESET ),
      53             :     TOKEN_MAP_ENTRY( NONE, ID ),
      54             :     TOKEN_MAP_ENTRY( NONE, READONLY ),
      55             :     TOKEN_MAP_ENTRY( NONE, RELEVANT ),
      56             :     TOKEN_MAP_ENTRY( NONE, REQUIRED ),
      57             :     TOKEN_MAP_ENTRY( NONE, CONSTRAINT ),
      58             :     TOKEN_MAP_ENTRY( NONE, CALCULATE ),
      59             :     TOKEN_MAP_ENTRY( NONE, TYPE ),
      60             :     XML_TOKEN_MAP_END
      61             : };
      62             : 
      63             : // helper function; see below
      64             : static void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&,
      65             :                                  Reference<XNameContainer>& );
      66             : 
      67           0 : XFormsBindContext::XFormsBindContext(
      68             :     SvXMLImport& rImport,
      69             :     sal_uInt16 nPrefix,
      70             :     const OUString& rLocalName,
      71             :     const Reference<XModel2>& xModel ) :
      72             :         TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ),
      73             :         mxModel( xModel ),
      74           0 :         mxBinding( NULL )
      75             : {
      76             :     // attach binding to model
      77           0 :     mxBinding = mxModel->createBinding();
      78             :     DBG_ASSERT( mxBinding.is(), "can't create binding" );
      79           0 :     mxModel->getBindings()->insert( makeAny( mxBinding ) );
      80           0 : }
      81             : 
      82           0 : XFormsBindContext::~XFormsBindContext()
      83             : {
      84           0 : }
      85             : 
      86           0 : void XFormsBindContext::HandleAttribute( sal_uInt16 nToken,
      87             :                                          const OUString& rValue )
      88             : {
      89           0 :     switch( nToken )
      90             :     {
      91             :     case XML_NODESET:
      92           0 :         xforms_setValue( mxBinding, "BindingExpression", rValue );
      93           0 :         break;
      94             :     case XML_ID:
      95           0 :         xforms_setValue( mxBinding, "BindingID", rValue );
      96           0 :         break;
      97             :     case XML_READONLY:
      98           0 :         xforms_setValue( mxBinding, "ReadonlyExpression", rValue );
      99           0 :         break;
     100             :     case XML_RELEVANT:
     101           0 :         xforms_setValue( mxBinding, "RelevantExpression", rValue );
     102           0 :         break;
     103             :     case XML_REQUIRED:
     104           0 :         xforms_setValue( mxBinding, "RequiredExpression", rValue );
     105           0 :         break;
     106             :     case XML_CONSTRAINT:
     107           0 :         xforms_setValue( mxBinding, "ConstraintExpression", rValue );
     108           0 :         break;
     109             :     case XML_CALCULATE:
     110           0 :         xforms_setValue( mxBinding, "CalculateExpression", rValue );
     111           0 :         break;
     112             :     case XML_TYPE:
     113             :         xforms_setValue( mxBinding, "Type",
     114           0 :                       makeAny( xforms_getTypeName( mxModel->getDataTypeRepository(),
     115           0 :                                        GetImport().GetNamespaceMap(),
     116           0 :                                        rValue ) ) );
     117           0 :         break;
     118             :     default:
     119             :         OSL_FAIL( "should not happen" );
     120           0 :         break;
     121             :     }
     122           0 : }
     123             : 
     124           0 : void XFormsBindContext::StartElement(
     125             :     const Reference<XAttributeList>& xAttributeList )
     126             : {
     127             :     // we need to register the namespaces
     128             :     Reference<XNameContainer> xContainer(
     129           0 :         mxBinding->getPropertyValue( "BindingNamespaces" ),
     130           0 :         UNO_QUERY );
     131             : 
     132             :     DBG_ASSERT( xContainer.is(), "binding should have a namespace container" );
     133           0 :     if( xContainer.is() )
     134           0 :         lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer);
     135             : 
     136             :     // call super-class for attribute handling
     137           0 :     TokenContext::StartElement( xAttributeList );
     138           0 : }
     139             : 
     140             : /** will be called for each child element */
     141           0 : SvXMLImportContext* XFormsBindContext::HandleChild(
     142             :     sal_uInt16,
     143             :     sal_uInt16,
     144             :     const OUString&,
     145             :     const Reference<XAttributeList>& )
     146             : {
     147             :     OSL_FAIL( "no children supported" );
     148           0 :     return NULL;
     149             : }
     150             : 
     151             : 
     152           0 : static void lcl_fillNamespaceContainer(
     153             :     const SvXMLNamespaceMap& aMap,
     154             :     Reference<XNameContainer>& xContainer )
     155             : {
     156           0 :     sal_uInt16 nKeyIter = aMap.GetFirstKey();
     157           0 :     do
     158             :     {
     159             :         // get prefix and namespace
     160           0 :         const OUString& sPrefix = aMap.GetPrefixByKey( nKeyIter );
     161           0 :         const OUString& sNamespace = aMap.GetNameByKey( nKeyIter );
     162             : 
     163             :         // as a hack, we will ignore our own 'default' namespaces
     164             :         DBG_ASSERT( !sPrefix.isEmpty(), "no prefix?" );
     165           0 :         if( !sPrefix.startsWith("_") &&
     166             :             nKeyIter >= XML_OLD_NAMESPACE_META_IDX )
     167             :         {
     168             :             // insert prefix (use replace if already known)
     169           0 :             if( xContainer->hasByName( sPrefix ) )
     170           0 :                 xContainer->replaceByName( sPrefix, makeAny( sNamespace ) );
     171             :             else
     172           0 :                 xContainer->insertByName( sPrefix, makeAny( sNamespace ) );
     173             :         }
     174             : 
     175             :         // proceed to next
     176           0 :         nKeyIter = aMap.GetNextKey( nKeyIter );
     177             :     }
     178             :     while( nKeyIter != XML_NAMESPACE_UNKNOWN );
     179           0 : }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10