LCOV - code coverage report
Current view: top level - extensions/source/bibliography - bibconfig.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 226 0.0 %
Date: 2015-06-13 12:38:46 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", ConfigItemMode::DelayedUpdate)
      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 = *static_cast<sal_Bool const *>(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_Int32 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             :     assert(!IsModified()); // should have been committed
     196           0 :     delete pMappingsArr;
     197           0 : }
     198             : 
     199           0 : BibDBDescriptor BibConfig::GetBibliographyURL()
     200             : {
     201           0 :     BibDBDescriptor aRet;
     202           0 :     aRet.sDataSource = sDataSource;
     203           0 :     aRet.sTableOrQuery = sTableOrQuery;
     204           0 :     aRet.nCommandType = nTblOrQuery;
     205           0 :     return aRet;
     206             : };
     207             : 
     208           0 : void BibConfig::SetBibliographyURL(const BibDBDescriptor& rDesc)
     209             : {
     210           0 :     sDataSource = rDesc.sDataSource;
     211           0 :     sTableOrQuery = rDesc.sTableOrQuery;
     212           0 :     nTblOrQuery = rDesc.nCommandType;
     213           0 :     SetModified();
     214           0 : };
     215             : 
     216           0 : void BibConfig::Notify( const com::sun::star::uno::Sequence<OUString>& )
     217             : {
     218           0 : }
     219             : 
     220           0 : void    BibConfig::ImplCommit()
     221             : {
     222           0 :     const Sequence<OUString> aPropertyNames = GetPropertyNames();
     223           0 :     Sequence<Any> aValues(aPropertyNames.getLength());
     224           0 :     Any* pValues = aValues.getArray();
     225             : 
     226           0 :     for(int nProp = 0; nProp < aPropertyNames.getLength(); nProp++)
     227             :     {
     228           0 :         switch(nProp)
     229             :         {
     230           0 :             case  0: pValues[nProp] <<= sDataSource; break;
     231           0 :             case  1: pValues[nProp] <<= sTableOrQuery; break;
     232           0 :             case  2: pValues[nProp] <<= nTblOrQuery;  break;
     233           0 :             case  3: pValues[nProp] <<= nBeamerSize;  break;
     234           0 :             case  4: pValues[nProp] <<= nViewSize;  break;
     235           0 :             case  5: pValues[nProp] <<= sQueryText;  break;
     236           0 :             case  6: pValues[nProp] <<= sQueryField;  break;
     237             :             case  7:
     238           0 :                 pValues[nProp].setValue(&bShowColumnAssignmentWarning, cppu::UnoType<bool>::get());
     239           0 :             break;
     240             :         }
     241             :     }
     242           0 :     PutProperties(aPropertyNames, aValues);
     243           0 :     ClearNodeSet(cDataSourceHistory);
     244           0 :     Sequence< PropertyValue > aNodeValues(pMappingsArr->size() * 3);
     245           0 :     PropertyValue* pNodeValues = aNodeValues.getArray();
     246             : 
     247           0 :     sal_Int32 nIndex = 0;
     248           0 :     OUString sName("DataSourceName");
     249           0 :     OUString sTable("Command");
     250           0 :     OUString sCommandType("CommandType");
     251           0 :     for(sal_Int32 i = 0; i < (sal_Int32)pMappingsArr->size(); i++)
     252             :     {
     253           0 :         const Mapping* pMapping = &(*pMappingsArr)[i];
     254           0 :         OUString sPrefix(cDataSourceHistory);
     255           0 :         sPrefix += "/_";
     256           0 :         sPrefix += OUString::number(i);
     257           0 :         sPrefix += "/";
     258           0 :         pNodeValues[nIndex].Name    = sPrefix;
     259           0 :         pNodeValues[nIndex].Name    += sName;
     260           0 :         pNodeValues[nIndex++].Value <<= pMapping->sURL;
     261           0 :         pNodeValues[nIndex].Name    = sPrefix;
     262           0 :         pNodeValues[nIndex].Name    += sTable;
     263           0 :         pNodeValues[nIndex++].Value <<= pMapping->sTableName;
     264           0 :         pNodeValues[nIndex].Name    = sPrefix;
     265           0 :         pNodeValues[nIndex].Name    += sCommandType;
     266           0 :         pNodeValues[nIndex++].Value <<= pMapping->nCommandType;
     267           0 :         SetSetProperties(cDataSourceHistory, aNodeValues);
     268             : 
     269           0 :         sPrefix += "Fields";
     270           0 :         sal_Int32 nFieldAssignment = 0;
     271           0 :         OUString sFieldName = "/ProgrammaticFieldName";
     272           0 :         OUString sDatabaseFieldName = "/AssignedFieldName";
     273           0 :         ClearNodeSet( sPrefix );
     274             : 
     275           0 :         while(nFieldAssignment < COLUMN_COUNT &&
     276           0 :             !pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName.isEmpty())
     277             :         {
     278           0 :             OUString sSubPrefix(sPrefix);
     279           0 :             sSubPrefix += "/_";
     280           0 :             sSubPrefix += OUString::number(nFieldAssignment);
     281           0 :             Sequence< PropertyValue > aAssignmentValues(2);
     282           0 :             PropertyValue* pAssignmentValues = aAssignmentValues.getArray();
     283           0 :             pAssignmentValues[0].Name   = sSubPrefix;
     284           0 :             pAssignmentValues[0].Name   += sFieldName;
     285           0 :             pAssignmentValues[0].Value <<= pMapping->aColumnPairs[nFieldAssignment].sLogicalColumnName;
     286           0 :             pAssignmentValues[1].Name   = sSubPrefix;
     287           0 :             pAssignmentValues[1].Name   += sDatabaseFieldName;
     288           0 :             pAssignmentValues[1].Value <<= pMapping->aColumnPairs[nFieldAssignment].sRealColumnName;
     289           0 :             SetSetProperties( sPrefix, aAssignmentValues );
     290           0 :             nFieldAssignment++;
     291           0 :         }
     292           0 :     }
     293           0 : }
     294             : 
     295           0 : const Mapping*  BibConfig::GetMapping(const BibDBDescriptor& rDesc) const
     296             : {
     297           0 :     for(size_t i = 0; i < pMappingsArr->size(); i++)
     298             :     {
     299           0 :         Mapping& rMapping = (*pMappingsArr)[i];
     300           0 :         bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
     301           0 :         if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
     302           0 :             return &rMapping;
     303             :     }
     304           0 :     return 0;
     305             : }
     306             : 
     307           0 : void BibConfig::SetMapping(const BibDBDescriptor& rDesc, const Mapping* pSetMapping)
     308             : {
     309           0 :     for(size_t i = 0; i < pMappingsArr->size(); i++)
     310             :     {
     311           0 :         Mapping& rMapping = (*pMappingsArr)[i];
     312           0 :         bool bURLEqual = rDesc.sDataSource.equals(rMapping.sURL);
     313           0 :         if(rDesc.sTableOrQuery == rMapping.sTableName && bURLEqual)
     314             :         {
     315           0 :             pMappingsArr->erase(pMappingsArr->begin()+i);
     316           0 :             break;
     317             :         }
     318             :     }
     319           0 :     Mapping* pNew = new Mapping(*pSetMapping);
     320           0 :     pMappingsArr->push_back(pNew);
     321           0 :     SetModified();
     322           0 : }
     323             : 
     324           0 : DBChangeDialogConfig_Impl::DBChangeDialogConfig_Impl()
     325             : {
     326           0 : }
     327             : 
     328           0 : DBChangeDialogConfig_Impl::~DBChangeDialogConfig_Impl()
     329             : {
     330           0 : }
     331             : 
     332           0 : const Sequence<OUString>& DBChangeDialogConfig_Impl::GetDataSourceNames()
     333             : {
     334           0 :     if(!aSourceNames.getLength())
     335             :     {
     336           0 :         Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     337           0 :         Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
     338           0 :         aSourceNames = xDBContext->getElementNames();
     339             :     }
     340           0 :     return aSourceNames;
     341             : }
     342             : 
     343             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11