LCOV - code coverage report
Current view: top level - extensions/source/bibliography - bibconfig.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 228 0.0 %
Date: 2014-04-14 Functions: 0 13 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 <bibconfig.hxx>
      22             : #include <com/sun/star/uno/Sequence.hxx>
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/container/XNameAccess.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      28             : #include <comphelper/processfactory.hxx>
      29             : 
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::beans;
      32             : using namespace ::com::sun::star::container;
      33             : using namespace ::com::sun::star::lang;
      34             : using namespace ::com::sun::star::sdb;
      35             : 
      36             : 
      37             : const char cDataSourceHistory[] = "DataSourceHistory";
      38             : 
      39           0 : Sequence<OUString> BibConfig::GetPropertyNames()
      40             : {
      41           0 :     static Sequence<OUString> aNames;
      42           0 :     if(!aNames.getLength())
      43             :     {
      44           0 :         aNames.realloc(8);
      45           0 :         OUString* pNames = aNames.getArray();
      46           0 :         pNames[0] = "CurrentDataSource/DataSourceName";
      47           0 :         pNames[1] = "CurrentDataSource/Command";
      48           0 :         pNames[2] = "CurrentDataSource/CommandType";
      49           0 :         pNames[3] = "BeamerHeight";
      50           0 :         pNames[4] = "ViewHeight";
      51           0 :         pNames[5] = "QueryText";
      52           0 :         pNames[6] = "QueryField";
      53           0 :         pNames[7] = "ShowColumnAssignmentWarning";
      54             :     }
      55           0 :     return aNames;
      56             : }
      57             : 
      58           0 : BibConfig::BibConfig()
      59             :     : ConfigItem("Office.DataAccess/Bibliography", CONFIG_MODE_DELAYED_UPDATE)
      60             :     , nTblOrQuery(0)
      61           0 :     , pMappingsArr(new MappingArray)
      62             :     , nBeamerSize(0)
      63             :     , nViewSize(0)
      64           0 :     , bShowColumnAssignmentWarning(false)
      65             : {
      66             :     //Names of the default columns
      67           0 :     aColumnDefaults[0] = "Identifier";
      68           0 :     aColumnDefaults[1] = "BibliographyType";
      69           0 :     aColumnDefaults[2] = "Author";
      70           0 :     aColumnDefaults[3] = "Title";
      71           0 :     aColumnDefaults[4] = "Year";
      72           0 :     aColumnDefaults[5] = "ISBN";
      73           0 :     aColumnDefaults[6] = "Booktitle";
      74           0 :     aColumnDefaults[7] = "Chapter";
      75           0 :     aColumnDefaults[8] = "Edition";
      76           0 :     aColumnDefaults[9] = "Editor";
      77           0 :     aColumnDefaults[10] = "Howpublished";
      78           0 :     aColumnDefaults[11] = "Institution";
      79           0 :     aColumnDefaults[12] = "Journal";
      80           0 :     aColumnDefaults[13] = "Month";
      81           0 :     aColumnDefaults[14] = "Note";
      82           0 :     aColumnDefaults[15] = "Annote";
      83           0 :     aColumnDefaults[16] = "Number";
      84           0 :     aColumnDefaults[17] = "Organizations";
      85           0 :     aColumnDefaults[18] = "Pages";
      86           0 :     aColumnDefaults[19] = "Publisher";
      87           0 :     aColumnDefaults[20] = "Address";
      88           0 :     aColumnDefaults[21] = "School";
      89           0 :     aColumnDefaults[22] = "Series";
      90           0 :     aColumnDefaults[23] = "ReportType";
      91           0 :     aColumnDefaults[24] = "Volume";
      92           0 :     aColumnDefaults[25] = "URL";
      93           0 :     aColumnDefaults[26] = "Custom1";
      94           0 :     aColumnDefaults[27] = "Custom2";
      95           0 :     aColumnDefaults[28] = "Custom3";
      96           0 :     aColumnDefaults[29] = "Custom4";
      97           0 :     aColumnDefaults[30] = "Custom5";
      98             : 
      99             : 
     100           0 :     const Sequence< OUString > aPropertyNames = GetPropertyNames();
     101           0 :     const Sequence<Any> aPropertyValues = GetProperties( aPropertyNames );
     102           0 :     const Any* pValues = aPropertyValues.getConstArray();
     103           0 :     if(aPropertyValues.getLength() == aPropertyNames.getLength())
     104             :     {
     105           0 :         for(int nProp = 0; nProp < aPropertyNames.getLength(); nProp++)
     106             :         {
     107           0 :             if(pValues[nProp].hasValue())
     108             :             {
     109           0 :                 switch(nProp)
     110             :                 {
     111           0 :                     case  0: pValues[nProp] >>= sDataSource; break;
     112           0 :                     case  1: pValues[nProp] >>= sTableOrQuery; break;
     113           0 :                     case  2: pValues[nProp] >>= nTblOrQuery;  break;
     114           0 :                     case  3: pValues[nProp] >>= nBeamerSize;  break;
     115           0 :                     case  4: pValues[nProp] >>= nViewSize  ;  break;
     116           0 :                     case  5: pValues[nProp] >>= sQueryText ;  break;
     117           0 :                     case  6: pValues[nProp] >>= sQueryField;  break;
     118             :                     case  7:
     119           0 :                         bShowColumnAssignmentWarning = *(sal_Bool*)pValues[nProp].getValue();
     120           0 :                     break;
     121             :                 }
     122             :             }
     123             :         }
     124             :     }
     125           0 :     OUString sName("DataSourceName");
     126           0 :     OUString sTable("Command");
     127           0 :     OUString sCommandType("CommandType");
     128           0 :     Sequence< OUString > aNodeNames = GetNodeNames(cDataSourceHistory);
     129           0 :     const OUString* pNodeNames = aNodeNames.getConstArray();
     130           0 :     for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength(); nNode++)
     131             :     {
     132           0 :         Sequence<OUString> aHistoryNames(3);
     133           0 :         OUString* pHistoryNames = aHistoryNames.getArray();
     134             : 
     135           0 :         OUString sPrefix(cDataSourceHistory);
     136           0 :         sPrefix += "/";
     137           0 :         sPrefix += pNodeNames[nNode];
     138           0 :         sPrefix += "/";
     139           0 :         pHistoryNames[0] = sPrefix;
     140           0 :         pHistoryNames[0] += sName;
     141           0 :         pHistoryNames[1] = sPrefix;
     142           0 :         pHistoryNames[1] += sTable;
     143           0 :         pHistoryNames[2] = sPrefix;
     144           0 :         pHistoryNames[2] += sCommandType;
     145             : 
     146           0 :         Sequence<Any> aHistoryValues = GetProperties( aHistoryNames );
     147           0 :         const Any* pHistoryValues = aHistoryValues.getConstArray();
     148             : 
     149           0 :         if(aHistoryValues.getLength() == aHistoryNames.getLength())
     150             :         {
     151           0 :             Mapping* pMapping = new Mapping;
     152           0 :             pHistoryValues[0] >>= pMapping->sURL;
     153           0 :             pHistoryValues[1] >>= pMapping->sTableName;
     154           0 :             pHistoryValues[2] >>= pMapping->nCommandType;
     155             :             //field assignment is contained in another set
     156           0 :             sPrefix += "Fields";
     157           0 :             Sequence< OUString > aAssignmentNodeNames = GetNodeNames(sPrefix);
     158           0 :             const OUString* pAssignmentNodeNames = aAssignmentNodeNames.getConstArray();
     159           0 :             Sequence<OUString> aAssignmentPropertyNames(aAssignmentNodeNames.getLength() * 2);
     160           0 :             OUString* pAssignmentPropertyNames = aAssignmentPropertyNames.getArray();
     161           0 :             sal_Int16 nFieldIdx = 0;
     162           0 :             for(sal_Int16 nField = 0; nField < aAssignmentNodeNames.getLength(); nField++)
     163             :             {
     164           0 :                 OUString sSubPrefix(sPrefix);
     165           0 :                 sSubPrefix += "/";
     166           0 :                 sSubPrefix += pAssignmentNodeNames[nField];
     167           0 :                 pAssignmentPropertyNames[nFieldIdx] = sSubPrefix;
     168           0 :                 pAssignmentPropertyNames[nFieldIdx++] += "/ProgrammaticFieldName";
     169           0 :                 pAssignmentPropertyNames[nFieldIdx] = sSubPrefix;
     170           0 :                 pAssignmentPropertyNames[nFieldIdx++]   += "/AssignedFieldName";
     171           0 :             }
     172           0 :             Sequence<Any> aAssignmentValues = GetProperties(aAssignmentPropertyNames);
     173           0 :             const Any* pAssignmentValues = aAssignmentValues.getConstArray();
     174           0 :             OUString sTempLogical;
     175           0 :             OUString sTempReal;
     176           0 :             sal_Int16 nSetMapping = 0;
     177           0 :             nFieldIdx = 0;
     178           0 :             for(sal_Int16 nFieldVal = 0; nFieldVal < aAssignmentValues.getLength() / 2; nFieldVal++)
     179             :             {
     180           0 :                 pAssignmentValues[nFieldIdx++] >>= sTempLogical;
     181           0 :                 pAssignmentValues[nFieldIdx++] >>= sTempReal;
     182           0 :                 if(!(sTempLogical.isEmpty() || sTempReal.isEmpty()))
     183             :                 {
     184           0 :                     pMapping->aColumnPairs[nSetMapping].sLogicalColumnName = sTempLogical;
     185           0 :                     pMapping->aColumnPairs[nSetMapping++].sRealColumnName = sTempReal;
     186             :                 }
     187             :             }
     188           0 :             pMappingsArr->push_back(pMapping);
     189             :         }
     190           0 :     }
     191           0 : }
     192             : 
     193           0 : BibConfig::~BibConfig()
     194             : {
     195           0 :     if(IsModified())
     196           0 :         Commit();
     197           0 :     delete pMappingsArr;
     198           0 : }
     199             : 
     200           0 : BibDBDescriptor BibConfig::GetBibliographyURL()
     201             : {
     202           0 :     BibDBDescriptor aRet;
     203           0 :     aRet.sDataSource = sDataSource;
     204           0 :     aRet.sTableOrQuery = sTableOrQuery;
     205           0 :     aRet.nCommandType = nTblOrQuery;
     206           0 :     return aRet;
     207             : };
     208             : 
     209           0 : void BibConfig::SetBibliographyURL(const BibDBDescriptor& rDesc)
     210             : {
     211           0 :     sDataSource = rDesc.sDataSource;
     212           0 :     sTableOrQuery = rDesc.sTableOrQuery;
     213           0 :     nTblOrQuery = rDesc.nCommandType;
     214           0 :     SetModified();
     215           0 : };
     216             : 
     217           0 : void BibConfig::Notify( const com::sun::star::uno::Sequence<OUString>& )
     218             : {
     219           0 : }
     220             : 
     221           0 : void    BibConfig::Commit()
     222             : {
     223           0 :     const Sequence<OUString> aPropertyNames = GetPropertyNames();
     224           0 :     Sequence<Any> aValues(aPropertyNames.getLength());
     225           0 :     Any* pValues = aValues.getArray();
     226             : 
     227           0 :     for(int nProp = 0; nProp < aPropertyNames.getLength(); nProp++)
     228             :     {
     229           0 :         switch(nProp)
     230             :         {
     231           0 :             case  0: pValues[nProp] <<= sDataSource; break;
     232           0 :             case  1: pValues[nProp] <<= sTableOrQuery; break;
     233           0 :             case  2: pValues[nProp] <<= nTblOrQuery;  break;
     234           0 :             case  3: pValues[nProp] <<= nBeamerSize;  break;
     235           0 :             case  4: pValues[nProp] <<= nViewSize;  break;
     236           0 :             case  5: pValues[nProp] <<= sQueryText;  break;
     237           0 :             case  6: pValues[nProp] <<= sQueryField;  break;
     238             :             case  7:
     239           0 :                 pValues[nProp].setValue(&bShowColumnAssignmentWarning, ::getBooleanCppuType());
     240           0 :             break;
     241             :         }
     242             :     }
     243           0 :     PutProperties(aPropertyNames, aValues);
     244           0 :     ClearNodeSet(cDataSourceHistory);
     245           0 :     Sequence< PropertyValue > aNodeValues(pMappingsArr->size() * 3);
     246           0 :     PropertyValue* pNodeValues = aNodeValues.getArray();
     247             : 
     248           0 :     sal_Int32 nIndex = 0;
     249           0 :     OUString sName("DataSourceName");
     250           0 :     OUString sTable("Command");
     251           0 :     OUString sCommandType("CommandType");
     252           0 :     for(sal_Int32 i = 0; i < (sal_Int32)pMappingsArr->size(); i++)
     253             :     {
     254           0 :         const Mapping* pMapping = &(*pMappingsArr)[i];
     255           0 :         OUString sPrefix(cDataSourceHistory);
     256           0 :         sPrefix += "/_";
     257           0 :         sPrefix += OUString::number(i);
     258           0 :         sPrefix += "/";
     259           0 :         pNodeValues[nIndex].Name    = sPrefix;
     260           0 :         pNodeValues[nIndex].Name    += sName;
     261           0 :         pNodeValues[nIndex++].Value <<= pMapping->sURL;
     262           0 :         pNodeValues[nIndex].Name    = sPrefix;
     263           0 :         pNodeValues[nIndex].Name    += sTable;
     264           0 :         pNodeValues[nIndex++].Value <<= pMapping->sTableName;
     265           0 :         pNodeValues[nIndex].Name    = sPrefix;
     266           0 :         pNodeValues[nIndex].Name    += sCommandType;
     267           0 :         pNodeValues[nIndex++].Value <<= pMapping->nCommandType;
     268           0 :         SetSetProperties(cDataSourceHistory, aNodeValues);
     269             : 
     270           0 :         sPrefix += "Fields";
     271           0 :         sal_Int32 nFieldAssignment = 0;
     272           0 :         OUString sFieldName = "/ProgrammaticFieldName";
     273           0 :         OUString sDatabaseFieldName = "/AssignedFieldName";
     274           0 :         ClearNodeSet( sPrefix );
     275             : 
     276           0 :         while(nFieldAssignment < COLUMN_COUNT &&
     277           0 :             !pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName.isEmpty())
     278             :         {
     279           0 :             OUString sSubPrefix(sPrefix);
     280           0 :             sSubPrefix += "/_";
     281           0 :             sSubPrefix += OUString::number(nFieldAssignment);
     282           0 :             Sequence< PropertyValue > aAssignmentValues(2);
     283           0 :             PropertyValue* pAssignmentValues = aAssignmentValues.getArray();
     284           0 :             pAssignmentValues[0].Name   = sSubPrefix;
     285           0 :             pAssignmentValues[0].Name   += sFieldName;
     286           0 :             pAssignmentValues[0].Value <<= pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName;
     287           0 :             pAssignmentValues[1].Name   = sSubPrefix;
     288           0 :             pAssignmentValues[1].Name   += sDatabaseFieldName;
     289           0 :             pAssignmentValues[1].Value <<= pMapping->aColumnPairs[nFieldAssignment].sRealColumnName;
     290           0 :             SetSetProperties( sPrefix, aAssignmentValues );
     291           0 :             nFieldAssignment++;
     292           0 :         }
     293           0 :     }
     294           0 : }
     295             : 
     296           0 : const Mapping*  BibConfig::GetMapping(const BibDBDescriptor& rDesc) const
     297             : {
     298           0 :     for(sal_uInt16 i = 0; i < pMappingsArr->size(); i++)
     299             :     {
     300           0 :         Mapping& rMapping = (*pMappingsArr)[i];
     301           0 :         sal_Bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
     302           0 :         if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
     303           0 :             return &rMapping;
     304             :     }
     305           0 :     return 0;
     306             : }
     307             : 
     308           0 : void BibConfig::SetMapping(const BibDBDescriptor& rDesc, const Mapping* pSetMapping)
     309             : {
     310           0 :     for(sal_uInt16 i = 0; i < pMappingsArr->size(); i++)
     311             :     {
     312           0 :         Mapping& rMapping = (*pMappingsArr)[i];
     313           0 :         sal_Bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
     314           0 :         if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
     315             :         {
     316           0 :             pMappingsArr->erase(pMappingsArr->begin()+i);
     317           0 :             break;
     318             :         }
     319             :     }
     320           0 :     Mapping* pNew = new Mapping(*pSetMapping);
     321           0 :     pMappingsArr->push_back(pNew);
     322           0 :     SetModified();
     323           0 : }
     324             : 
     325           0 : DBChangeDialogConfig_Impl::DBChangeDialogConfig_Impl()
     326             : {
     327           0 : }
     328             : 
     329           0 : DBChangeDialogConfig_Impl::~DBChangeDialogConfig_Impl()
     330             : {
     331           0 : }
     332             : 
     333           0 : const Sequence<OUString>& DBChangeDialogConfig_Impl::GetDataSourceNames()
     334             : {
     335           0 :     if(!aSourceNames.getLength())
     336             :     {
     337           0 :         Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     338           0 :         Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
     339           0 :         aSourceNames = xDBContext->getElementNames();
     340             :     }
     341           0 :     return aSourceNames;
     342             : }
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10