LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/misc - RtfReader.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 146 0.0 %
Date: 2012-12-27 Functions: 0 9 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             : #include "RtfReader.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      23             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      24             : #include <com/sun/star/sdbcx/XAppend.hpp>
      25             : #include <com/sun/star/sdbc/DataType.hpp>
      26             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      27             : #include <com/sun/star/awt/FontDescriptor.hpp>
      28             : #include <com/sun/star/awt/FontWeight.hpp>
      29             : #include <com/sun/star/awt/FontStrikeout.hpp>
      30             : #include <com/sun/star/awt/FontSlant.hpp>
      31             : #include <com/sun/star/awt/FontUnderline.hpp>
      32             : #include <com/sun/star/util/NumberFormat.hpp>
      33             : #include <com/sun/star/util/XNumberFormatTypes.hpp>
      34             : #include "dbustrings.hrc"
      35             : #include <svtools/rtftoken.h>
      36             : #include "dbu_misc.hrc"
      37             : #include <vcl/msgbox.hxx>
      38             : #include <connectivity/dbconversion.hxx>
      39             : #include <connectivity/dbtools.hxx>
      40             : #include <comphelper/extract.hxx>
      41             : #include <comphelper/string.hxx>
      42             : #include <tools/color.hxx>
      43             : #include "WExtendPages.hxx"
      44             : #include "moduledbu.hxx"
      45             : #include "QEnumTypes.hxx"
      46             : #include "UITools.hxx"
      47             : #include <vcl/svapp.hxx>
      48             : #include <rtl/logfile.hxx>
      49             : 
      50             : using namespace dbaui;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::com::sun::star::container;
      54             : using namespace ::com::sun::star::sdbc;
      55             : using namespace ::com::sun::star::sdbcx;
      56             : using namespace ::com::sun::star::awt;
      57             : 
      58             : DBG_NAME(ORTFReader)
      59             : // ==========================================================================
      60             : // ORTFReader
      61             : // ==========================================================================
      62           0 : ORTFReader::ORTFReader( SvStream& rIn,
      63             :                         const SharedConnection& _rxConnection,
      64             :                         const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
      65             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
      66             :                         const TColumnVector* pList,
      67             :                         const OTypeInfoMap* _pInfoMap)
      68             :     :SvRTFParser(rIn)
      69           0 :     ,ODatabaseExport( _rxConnection, _rxNumberF, _rxContext, pList, _pInfoMap, rIn )
      70             : {
      71             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::ORTFReader" );
      72             :     DBG_CTOR(ORTFReader,NULL);
      73           0 :     m_bAppendFirstLine = false;
      74           0 : }
      75             : // ---------------------------------------------------------------------------
      76           0 : ORTFReader::ORTFReader(SvStream& rIn,
      77             :                        sal_Int32 nRows,
      78             :                        const TPositions &_rColumnPositions,
      79             :                        const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
      80             :                        const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
      81             :                        const TColumnVector* pList,
      82             :                        const OTypeInfoMap* _pInfoMap,
      83             :                        sal_Bool _bAutoIncrementEnabled)
      84             :    :SvRTFParser(rIn)
      85           0 :    ,ODatabaseExport( nRows, _rColumnPositions, _rxNumberF, _rxContext, pList, _pInfoMap, _bAutoIncrementEnabled, rIn )
      86             : {
      87             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::ORTFReader" );
      88             :     DBG_CTOR(ORTFReader,NULL);
      89           0 :     m_bAppendFirstLine = false;
      90           0 : }
      91             : // ---------------------------------------------------------------------------
      92           0 : ORTFReader::~ORTFReader()
      93             : {
      94             :     DBG_DTOR(ORTFReader,NULL);
      95           0 : }
      96             : // ---------------------------------------------------------------------------
      97           0 : SvParserState ORTFReader::CallParser()
      98             : {
      99             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::CallParser" );
     100             :     DBG_CHKTHIS(ORTFReader,NULL);
     101           0 :     rInput.Seek(STREAM_SEEK_TO_BEGIN);
     102           0 :     rInput.ResetError();
     103           0 :     SvParserState  eParseState = SvRTFParser::CallParser();
     104           0 :     SetColumnTypes(m_pColumnList,m_pInfoMap);
     105           0 :     return m_bFoundTable ? eParseState : SVPAR_ERROR;
     106             : }
     107             : // ---------------------------------------------------------------------------
     108           0 : void ORTFReader::NextToken( int nToken )
     109             : {
     110             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::NextToken" );
     111             :     DBG_CHKTHIS(ORTFReader,NULL);
     112           0 :     if(m_bError || !m_nRows) // if there is an error or no more rows to check, return immediatelly
     113           0 :         return;
     114             : 
     115           0 :     if(m_xConnection.is())    // names, which CTOR was called and hence, if a table should be created
     116             :     {
     117           0 :         switch(nToken)
     118             :         {
     119             :             case RTF_COLORTBL:
     120             :                 {
     121             : 
     122           0 :                     int nTmpToken2 = GetNextToken();
     123           0 :                     do
     124             :                     {
     125           0 :                         Color aColor;
     126           0 :                         do
     127             :                         {
     128           0 :                             switch(nTmpToken2)
     129             :                             {
     130           0 :                                 case RTF_RED:   aColor.SetRed((sal_uInt8)nTokenValue); break;
     131           0 :                                 case RTF_BLUE:  aColor.SetBlue((sal_uInt8)nTokenValue); break;
     132           0 :                                 case RTF_GREEN: aColor.SetGreen((sal_uInt8)nTokenValue); break;
     133           0 :                                 default: break;
     134             :                             }
     135           0 :                             nTmpToken2 = GetNextToken();
     136             :                         }
     137           0 :                         while(aToken.GetChar(0) != ';' && eState != SVPAR_ERROR && eState != SVPAR_ACCEPTED);
     138           0 :                         m_vecColor.push_back(aColor.GetRGBColor());
     139           0 :                         nTmpToken2 = GetNextToken();
     140             :                     }
     141             :                     while(nTmpToken2 == RTF_RED && eState != SVPAR_ERROR && eState != SVPAR_ACCEPTED);
     142           0 :                     SkipToken();
     143             :                 }
     144           0 :                 break;
     145             : 
     146             :             case RTF_DEFLANG:
     147             :             case RTF_LANG: // inquire language
     148           0 :                 m_nDefToken = (rtl_TextEncoding)nTokenValue;
     149           0 :                 break;
     150             :             case RTF_TROWD:
     151             :                 {
     152           0 :                     bool bInsertRow = true;
     153           0 :                     if ( !m_xTable.is() ) // use first line as header
     154             :                     {
     155           0 :                         sal_uInt32 nTell = rInput.Tell(); // perhaps alters position of the stream
     156             : 
     157           0 :                         m_bError = !CreateTable(nToken);
     158           0 :                         bInsertRow = m_bAppendFirstLine;
     159           0 :                         if ( m_bAppendFirstLine )
     160             :                         {
     161           0 :                             rInput.Seek(nTell);
     162           0 :                             rInput.ResetError();
     163             :                         }
     164             :                     }
     165           0 :                     if ( bInsertRow && !m_bError)
     166             :                     {
     167             :                         try
     168             :                         {
     169           0 :                             m_pUpdateHelper->moveToInsertRow(); // otherwise append new line
     170             :                         }
     171           0 :                         catch(SQLException& e)
     172             :                         // handling update failure
     173             :                         {
     174           0 :                             showErrorDialog(e);
     175             :                         }
     176             :                     }
     177             :                 }
     178           0 :                 break;
     179             :             case RTF_INTBL:
     180           0 :                 if(m_bInTbl)
     181             :                 {
     182           0 :                     eraseTokens();
     183             :                 }
     184             : 
     185           0 :                 m_bInTbl = sal_True; // Now we are in a table description
     186           0 :                 break;
     187             :             case RTF_TEXTTOKEN:
     188             :             case RTF_SINGLECHAR:
     189           0 :                 if(m_bInTbl) // important, as otherwise we also get the names of the fonts
     190           0 :                     m_sTextToken += aToken;
     191           0 :                 break;
     192             :             case RTF_CELL:
     193             :                 {
     194             :                     try
     195             :                     {
     196           0 :                         insertValueIntoColumn();
     197             :                     }
     198           0 :                     catch(SQLException& e)
     199             :                     // handling update failure
     200             :                     {
     201           0 :                         showErrorDialog(e);
     202             :                     }
     203           0 :                     m_nColumnPos++;
     204           0 :                     eraseTokens();
     205             :                 }
     206           0 :                 break;
     207             :             case RTF_ROW:
     208             :                 // it can happen that the last cell is not concluded with \cell
     209             :                 try
     210             :                 {
     211           0 :                     insertValueIntoColumn();
     212           0 :                     m_nRowCount++;
     213           0 :                     if(m_bIsAutoIncrement) // if bSetAutoIncrement then I have to set the autoincrement
     214           0 :                         m_pUpdateHelper->updateInt(1,m_nRowCount);
     215           0 :                     m_pUpdateHelper->insertRow();
     216             :                 }
     217           0 :                 catch(SQLException& e)
     218             :                 //////////////////////////////////////////////////////////////////////
     219             :                 // handling update failure
     220             :                 {
     221           0 :                     showErrorDialog(e);
     222             :                 }
     223           0 :                 m_nColumnPos = 0;
     224           0 :                 break;
     225             :         }
     226             :     }
     227             :     else // branch only valid for type checking
     228             :     {
     229           0 :         switch(nToken)
     230             :         {
     231             :             case RTF_TROWD:
     232             :                 // The head of the column is not included
     233           0 :                 if(m_bHead)
     234             :                 {
     235           0 :                     do
     236             :                     {}
     237           0 :                     while(GetNextToken() != RTF_ROW && eState != SVPAR_ERROR && eState != SVPAR_ACCEPTED);
     238           0 :                     m_bHead = sal_False;
     239             :                 }
     240           0 :                 break;
     241             :             case RTF_INTBL:
     242           0 :                 m_bInTbl = sal_True;
     243           0 :                 break;
     244             :             case RTF_TEXTTOKEN:
     245             :             case RTF_SINGLECHAR:
     246           0 :                 if(m_bInTbl)
     247           0 :                     m_sTextToken += aToken;
     248           0 :                 break;
     249             :             case RTF_CELL:
     250           0 :                 adjustFormat();
     251           0 :                 m_nColumnPos++;
     252           0 :                 break;
     253             :             case RTF_ROW:
     254           0 :                 adjustFormat();
     255           0 :                 m_nColumnPos = 0;
     256           0 :                 m_nRows--;
     257           0 :                 break;
     258             :         }
     259             :     }
     260             : }
     261             : // ---------------------------------------------------------------------------
     262           0 : sal_Bool ORTFReader::CreateTable(int nToken)
     263             : {
     264             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::CreateTable" );
     265             :     DBG_CHKTHIS(ORTFReader,NULL);
     266           0 :     String aTableName(ModuleRes(STR_TBL_TITLE));
     267           0 :     aTableName = aTableName.GetToken(0,' ');
     268           0 :     aTableName = String(::dbtools::createUniqueName(m_xTables,::rtl::OUString(aTableName)));
     269             : 
     270           0 :     int nTmpToken2 = nToken;
     271           0 :     String aColumnName;
     272             : 
     273           0 :     FontDescriptor aFont = ::dbaui::CreateFontDescriptor(Application::GetSettings().GetStyleSettings().GetAppFont());
     274           0 :     do
     275             :     {
     276           0 :         switch(nTmpToken2)
     277             :         {
     278             :             case RTF_UNKNOWNCONTROL:
     279             :             case RTF_UNKNOWNDATA:
     280           0 :                 m_bInTbl = sal_False;
     281           0 :                 aColumnName.Erase();
     282           0 :                 break;
     283             :             case RTF_INTBL:
     284           0 :                 if(m_bInTbl)
     285           0 :                     aColumnName.Erase();
     286             : 
     287           0 :                 m_bInTbl = sal_True;
     288           0 :                 break;
     289             :             case RTF_TEXTTOKEN:
     290             :             case RTF_SINGLECHAR:
     291           0 :                 if(m_bInTbl)
     292           0 :                     aColumnName += aToken;
     293           0 :                 break;
     294             :             case RTF_CELL:
     295             :                 {
     296           0 :                     aColumnName = comphelper::string::strip(aColumnName, ' ');
     297           0 :                     if (!aColumnName.Len() || m_bAppendFirstLine )
     298           0 :                         aColumnName = String(ModuleRes(STR_COLUMN_NAME));
     299             : 
     300           0 :                     CreateDefaultColumn(aColumnName);
     301           0 :                     aColumnName.Erase();
     302             :                 }
     303           0 :                 break;
     304             :             case RTF_CF:
     305           0 :                 break;
     306             :             case RTF_B:
     307           0 :                 aFont.Weight = ::com::sun::star::awt::FontWeight::BOLD;
     308           0 :                 break;
     309             :             case RTF_I:
     310           0 :                 aFont.Slant = ::com::sun::star::awt::FontSlant_ITALIC;
     311           0 :                 break;
     312             :             case RTF_UL:
     313           0 :                 aFont.Underline = ::com::sun::star::awt::FontUnderline::SINGLE;
     314           0 :                 break;
     315             :             case RTF_STRIKE:
     316           0 :                 aFont.Strikeout = ::com::sun::star::awt::FontStrikeout::SINGLE;
     317           0 :                 break;
     318             :         }
     319             :     }
     320           0 :     while((nTmpToken2 = GetNextToken()) != RTF_TROWD && eState != SVPAR_ERROR && eState != SVPAR_ACCEPTED);
     321             : 
     322           0 :     sal_Bool bOk = !m_vDestVector.empty();
     323           0 :     if(bOk)
     324             :     {
     325           0 :         if ( aColumnName.Len() )
     326             :         {
     327           0 :             if ( m_bAppendFirstLine )
     328           0 :                 aColumnName = String(ModuleRes(STR_COLUMN_NAME));
     329           0 :             CreateDefaultColumn(aColumnName);
     330             :         }
     331             : 
     332           0 :         m_bInTbl        = sal_False;
     333           0 :         m_bFoundTable   = sal_True;
     334             : 
     335           0 :         if ( isCheckEnabled() )
     336           0 :             return sal_True;
     337           0 :         Any aTextColor;
     338           0 :         if(!m_vecColor.empty())
     339           0 :             aTextColor <<= m_vecColor[0];
     340             : 
     341           0 :         bOk = !executeWizard(aTableName,aTextColor,aFont) && m_xTable.is();
     342             :     }
     343           0 :     return bOk;
     344             : }
     345             : // -----------------------------------------------------------------------------
     346           0 : void ORTFReader::release()
     347             : {
     348             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::release" );
     349             :     DBG_CHKTHIS(ORTFReader,NULL);
     350           0 :     ReleaseRef();
     351           0 : }
     352             : 
     353             : // -----------------------------------------------------------------------------
     354           0 : TypeSelectionPageFactory ORTFReader::getTypeSelectionPageFactory()
     355             : {
     356             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFReader::getTypeSelectionPageFactory" );
     357             :     DBG_CHKTHIS(ORTFReader,NULL);
     358           0 :     return &OWizRTFExtend::Create;
     359             : }
     360             : // -----------------------------------------------------------------------------
     361             : 
     362             : 
     363             : 
     364             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10