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

Generated by: LCOV version 1.10