LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - TokenWriter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 562 0.2 %
Date: 2014-11-03 Functions: 2 27 7.4 %
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 "TokenWriter.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include <osl/diagnose.h>
      24             : #include "RtfReader.hxx"
      25             : #include "HtmlReader.hxx"
      26             : #include "dbustrings.hrc"
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <comphelper/string.hxx>
      29             : #include <comphelper/types.hxx>
      30             : #include <connectivity/dbtools.hxx>
      31             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      32             : #include <com/sun/star/sdbc/XConnection.hpp>
      33             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      34             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      35             : #include <com/sun/star/sdbc/XRowSet.hpp>
      36             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      37             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      38             : #include <com/sun/star/sdbc/XDataSource.hpp>
      39             : #include <com/sun/star/awt/FontWeight.hpp>
      40             : #include <com/sun/star/awt/FontStrikeout.hpp>
      41             : #include <com/sun/star/awt/FontSlant.hpp>
      42             : #include <com/sun/star/awt/FontUnderline.hpp>
      43             : #include <com/sun/star/document/DocumentProperties.hpp>
      44             : #include <svtools/htmlkywd.hxx>
      45             : #include <svtools/rtfkeywd.hxx>
      46             : #include <tools/color.hxx>
      47             : #include <svtools/htmlout.hxx>
      48             : #include <sfx2/frmhtmlw.hxx>
      49             : #include <svl/numuno.hxx>
      50             : #include <vcl/svapp.hxx>
      51             : #include "UITools.hxx"
      52             : #include <toolkit/helper/vclunohelper.hxx>
      53             : #include <vcl/outdev.hxx>
      54             : #include <vcl/settings.hxx>
      55             : #include <svtools/rtfout.hxx>
      56             : #include <svtools/htmlcfg.hxx>
      57             : #include <connectivity/formattedcolumnvalue.hxx>
      58             : #include <unotools/syslocale.hxx>
      59             : #include <boost/scoped_array.hpp>
      60             : 
      61             : using namespace dbaui;
      62             : using namespace dbtools;
      63             : using namespace svx;
      64             : using namespace ::com::sun::star;
      65             : using namespace ::com::sun::star::uno;
      66             : using namespace ::com::sun::star::beans;
      67             : using namespace ::com::sun::star::container;
      68             : using namespace ::com::sun::star::sdbc;
      69             : using namespace ::com::sun::star::sdb;
      70             : using namespace ::com::sun::star::frame;
      71             : using namespace ::com::sun::star::lang;
      72             : using namespace ::com::sun::star::sdbcx;
      73             : using namespace ::com::sun::star::awt;
      74             : using namespace ::com::sun::star::util;
      75             : using ::com::sun::star::frame::XModel;
      76             : 
      77             : const static char sMyBegComment[]   = "<!-- ";
      78             : const static char sMyEndComment[]   = " -->";
      79             : const static char sFontFamily[]     = "font-family: ";
      80             : const static char sFontSize[]       = "font-size: ";
      81             : 
      82             : #define SBA_FORMAT_SELECTION_COUNT  4
      83             : #define CELL_X                      1437
      84             : 
      85           0 : ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor& _aDataDescriptor,
      86             :                                              const Reference< XComponentContext >& _rM,
      87             :                                              const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
      88             :                                              const OUString& rExchange)
      89             :     :m_bBookmarkSelection( false )
      90             :     ,m_xFormatter(_rxNumberF)
      91             :     ,m_xContext(_rM)
      92             :     ,m_nCommandType(CommandType::TABLE)
      93             :     ,m_bNeedToReInitialize(false)
      94             :     ,m_pReader(NULL)
      95             :     ,m_pRowMarker(NULL)
      96             :     ,m_bInInitialize(false)
      97           0 :     ,m_bCheckOnly(false)
      98             : {
      99           0 :     m_eDestEnc = osl_getThreadTextEncoding();
     100             : 
     101           0 :     osl_atomic_increment( &m_refCount );
     102           0 :     impl_initFromDescriptor( _aDataDescriptor, false );
     103             : 
     104           0 :     sal_Int32 nCount = comphelper::string::getTokenCount(rExchange, char(11));
     105           0 :     if( nCount > SBA_FORMAT_SELECTION_COUNT && !rExchange.getToken(4, ';').isEmpty())
     106             :     {
     107           0 :         m_pRowMarker = new sal_Int32[nCount-SBA_FORMAT_SELECTION_COUNT];
     108           0 :         for(sal_Int32 i=SBA_FORMAT_SELECTION_COUNT; i<nCount; ++i)
     109           0 :             m_pRowMarker[i-SBA_FORMAT_SELECTION_COUNT] = rExchange.getToken(i,char(11)).toInt32();
     110             :     }
     111           0 :     osl_atomic_decrement( &m_refCount );
     112           0 : }
     113             : 
     114             : // import data
     115           0 : ODatabaseImportExport::ODatabaseImportExport( const ::dbtools::SharedConnection& _rxConnection,
     116             :         const Reference< XNumberFormatter >& _rxNumberF, const Reference< XComponentContext >& _rM )
     117             :     :m_bBookmarkSelection( false )
     118             :     ,m_pStream(NULL)
     119             :     ,m_xConnection(_rxConnection)
     120             :     ,m_xFormatter(_rxNumberF)
     121             :     ,m_xContext(_rM)
     122             :     ,m_nCommandType(::com::sun::star::sdb::CommandType::TABLE)
     123             :     ,m_bNeedToReInitialize(false)
     124             :     ,m_pReader(NULL)
     125             :     ,m_pRowMarker(NULL)
     126             :     ,m_bInInitialize(false)
     127           0 :     ,m_bCheckOnly(false)
     128             : {
     129           0 :     m_eDestEnc = osl_getThreadTextEncoding();
     130             :     try
     131             :     {
     132           0 :         SvtSysLocale aSysLocale;
     133           0 :         m_aLocale = aSysLocale.GetLanguageTag().getLocale();
     134             :     }
     135           0 :     catch(Exception&)
     136             :     {
     137             :     }
     138           0 : }
     139             : 
     140           0 : ODatabaseImportExport::~ODatabaseImportExport()
     141             : {
     142           0 :     acquire();
     143             : 
     144           0 :     dispose();
     145             : 
     146           0 :     if(m_pReader)
     147           0 :         m_pReader->release();
     148           0 :     delete m_pRowMarker;
     149           0 : }
     150             : 
     151           0 : void ODatabaseImportExport::dispose()
     152             : {
     153             :     // remove me as listener
     154           0 :     Reference< XComponent >  xComponent(m_xConnection, UNO_QUERY);
     155           0 :     if (xComponent.is())
     156             :     {
     157           0 :         Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
     158           0 :         xComponent->removeEventListener(xEvt);
     159             :     }
     160           0 :     m_xConnection.clear();
     161             : 
     162           0 :     ::comphelper::disposeComponent(m_xRow);
     163             : 
     164           0 :     m_xObject.clear();
     165           0 :     m_xResultSetMetaData.clear();
     166           0 :     m_xResultSet.clear();
     167           0 :     m_xRow.clear();
     168           0 :     m_xRowLocate.clear();
     169           0 :     m_xFormatter.clear();
     170           0 : }
     171             : 
     172           0 : void SAL_CALL ODatabaseImportExport::disposing( const EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     173             : {
     174           0 :     Reference<XConnection> xCon(Source.Source,UNO_QUERY);
     175           0 :     if(m_xConnection.is() && m_xConnection == xCon)
     176             :     {
     177           0 :         m_xConnection.clear();
     178           0 :         dispose();
     179           0 :         m_bNeedToReInitialize = true;
     180           0 :     }
     181           0 : }
     182             : 
     183           0 : void ODatabaseImportExport::initialize( const ODataAccessDescriptor& _aDataDescriptor )
     184             : {
     185           0 :     impl_initFromDescriptor( _aDataDescriptor, true );
     186           0 : }
     187             : 
     188           0 : void ODatabaseImportExport::impl_initFromDescriptor( const ODataAccessDescriptor& _aDataDescriptor, bool _bPlusDefaultInit)
     189             : {
     190           0 :     if ( !_bPlusDefaultInit )
     191             :     {
     192           0 :         m_sDataSourceName = _aDataDescriptor.getDataSource();
     193           0 :         _aDataDescriptor[daCommandType] >>= m_nCommandType;
     194           0 :         _aDataDescriptor[daCommand]     >>= m_sName;
     195             :         // some additional information
     196           0 :         if(_aDataDescriptor.has(daConnection))
     197             :         {
     198           0 :             Reference< XConnection > xPureConn( _aDataDescriptor[daConnection], UNO_QUERY );
     199           0 :             m_xConnection.reset( xPureConn, SharedConnection::NoTakeOwnership );
     200           0 :             Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
     201           0 :             Reference< XComponent >  xComponent(m_xConnection, UNO_QUERY);
     202           0 :             if (xComponent.is() && xEvt.is())
     203           0 :                 xComponent->addEventListener(xEvt);
     204             :         }
     205             : 
     206           0 :         if ( _aDataDescriptor.has( daSelection ) )
     207           0 :             _aDataDescriptor[ daSelection ] >>= m_aSelection;
     208             : 
     209           0 :         if ( _aDataDescriptor.has( daBookmarkSelection ) )
     210           0 :             _aDataDescriptor[ daBookmarkSelection ] >>= m_bBookmarkSelection;
     211             : 
     212           0 :         if ( _aDataDescriptor.has( daCursor ) )
     213             :         {
     214           0 :             _aDataDescriptor[ daCursor ] >>= m_xResultSet;
     215           0 :             m_xRowLocate.set( m_xResultSet, UNO_QUERY );
     216             :         }
     217             : 
     218           0 :         if ( m_aSelection.getLength() != 0 )
     219             :         {
     220           0 :             if ( !m_xResultSet.is() )
     221             :             {
     222             :                 SAL_WARN("dbaccess.ui", "ODatabaseImportExport::impl_initFromDescriptor: selection without result set is nonsense!" );
     223           0 :                 m_aSelection.realloc( 0 );
     224             :             }
     225             :         }
     226             : 
     227           0 :         if ( m_aSelection.getLength() != 0 )
     228             :         {
     229           0 :             if ( m_bBookmarkSelection && !m_xRowLocate.is() )
     230             :             {
     231             :                 SAL_WARN("dbaccess.ui", "ODatabaseImportExport::impl_initFromDescriptor: no XRowLocate -> no bookmars!" );
     232           0 :                 m_aSelection.realloc( 0 );
     233             :             }
     234             :         }
     235             :     }
     236             :     else
     237           0 :         initialize();
     238             : 
     239             :     try
     240             :     {
     241           0 :         SvtSysLocale aSysLocale;
     242           0 :         m_aLocale = aSysLocale.GetLanguageTag().getLocale();
     243             :     }
     244           0 :     catch(Exception&)
     245             :     {
     246             :     }
     247           0 : }
     248             : 
     249           0 : void ODatabaseImportExport::initialize()
     250             : {
     251           0 :     m_bInInitialize = true;
     252           0 :     m_bNeedToReInitialize = false;
     253             : 
     254           0 :     if ( !m_xConnection.is() )
     255             :     {   // we need a connection
     256             :         OSL_ENSURE(!m_sDataSourceName.isEmpty(),"There must be a datsource name!");
     257           0 :         Reference<XNameAccess> xDatabaseContext( DatabaseContext::create(m_xContext), UNO_QUERY_THROW);
     258           0 :         Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
     259             : 
     260           0 :         Reference< XConnection > xConnection;
     261           0 :         SQLExceptionInfo aInfo = ::dbaui::createConnection( m_sDataSourceName, xDatabaseContext, m_xContext, xEvt, xConnection );
     262           0 :         m_xConnection.reset( xConnection );
     263             : 
     264           0 :         if(aInfo.isValid() && aInfo.getType() == SQLExceptionInfo::SQL_EXCEPTION)
     265           0 :             throw *static_cast<const SQLException*>(aInfo);
     266             :     }
     267             : 
     268           0 :     Reference<XNameAccess> xNameAccess;
     269           0 :     switch(m_nCommandType)
     270             :     {
     271             :         case CommandType::TABLE:
     272             :             {
     273             :                 // only for tables
     274           0 :                 Reference<XTablesSupplier> xSup(m_xConnection,UNO_QUERY);
     275           0 :                 if(xSup.is())
     276           0 :                     xNameAccess = xSup->getTables();
     277             :             }
     278           0 :             break;
     279             :         case CommandType::QUERY:
     280             :             {
     281           0 :                 Reference<XQueriesSupplier> xSup(m_xConnection,UNO_QUERY);
     282           0 :                 if(xSup.is())
     283           0 :                     xNameAccess = xSup->getQueries();
     284             :             }
     285           0 :             break;
     286             :     }
     287           0 :     if(xNameAccess.is() && xNameAccess->hasByName(m_sName))
     288             :     {
     289           0 :         Reference<XPropertySet> xSourceObject;
     290           0 :         xNameAccess->getByName(m_sName) >>= m_xObject;
     291             :     }
     292             : 
     293           0 :     if(m_xObject.is())
     294             :     {
     295             :         try
     296             :         {
     297           0 :             if(m_xObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_FONT))
     298           0 :                 m_xObject->getPropertyValue(PROPERTY_FONT) >>= m_aFont;
     299             : 
     300             :             // the result set may be already set with the datadescriptor
     301           0 :             if ( !m_xResultSet.is() )
     302             :             {
     303           0 :                 m_xResultSet.set( m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.sdb.RowSet", m_xContext), UNO_QUERY );
     304           0 :                 Reference< XPropertySet > xProp( m_xResultSet, UNO_QUERY_THROW );
     305           0 :                 xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( m_xConnection.getTyped() ) );
     306           0 :                 xProp->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( m_nCommandType ) );
     307           0 :                 xProp->setPropertyValue( PROPERTY_COMMAND, makeAny( m_sName ) );
     308           0 :                 Reference< XRowSet > xRowSet( xProp, UNO_QUERY );
     309           0 :                 xRowSet->execute();
     310             :             }
     311           0 :             impl_initializeRowMember_throw();
     312             :         }
     313           0 :         catch(Exception& )
     314             :         {
     315           0 :             m_xRow = NULL;
     316           0 :             m_xResultSetMetaData = NULL;
     317           0 :             ::comphelper::disposeComponent(m_xResultSet);
     318           0 :             throw;
     319             :         }
     320             :     }
     321           0 :     if ( m_aFont.Name.isEmpty() )
     322             :     {
     323             :         vcl::Font aApplicationFont = OutputDevice::GetDefaultFont(
     324             :             DEFAULTFONT_SANS_UNICODE,
     325           0 :             Application::GetSettings().GetUILanguageTag().getLanguageType(),
     326             :             DEFAULTFONT_FLAGS_ONLYONE
     327           0 :         );
     328           0 :         m_aFont = VCLUnoHelper::CreateFontDescriptor( aApplicationFont );
     329             :     }
     330             : 
     331           0 :     m_bInInitialize = false;
     332           0 : }
     333             : 
     334           0 : bool ODatabaseImportExport::Write()
     335             : {
     336           0 :     if ( m_bNeedToReInitialize )
     337             :     {
     338           0 :         if ( !m_bInInitialize )
     339           0 :             initialize();
     340             :     }
     341           0 :     return true;
     342             : }
     343             : 
     344           0 : bool ODatabaseImportExport::Read()
     345             : {
     346           0 :     if ( m_bNeedToReInitialize )
     347             :     {
     348           0 :         if ( !m_bInInitialize )
     349           0 :             initialize();
     350             :     }
     351           0 :     return true;
     352             : }
     353             : 
     354           0 : void ODatabaseImportExport::impl_initializeRowMember_throw()
     355             : {
     356           0 :     if ( !m_xRow.is() && m_xResultSet.is() )
     357             :     {
     358           0 :         m_xRow.set( m_xResultSet, UNO_QUERY );
     359           0 :         m_xRowLocate.set( m_xResultSet, UNO_QUERY );
     360           0 :         m_xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(m_xRow,UNO_QUERY)->getMetaData();
     361           0 :         Reference<XColumnsSupplier> xSup(m_xResultSet,UNO_QUERY_THROW);
     362           0 :         m_xRowSetColumns.set(xSup->getColumns(),UNO_QUERY_THROW);
     363             :     }
     364           0 : }
     365             : 
     366           0 : bool ORTFImportExport::Write()
     367             : {
     368           0 :     ODatabaseImportExport::Write();
     369           0 :     m_pStream->WriteChar( '{' ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_RTF );
     370           0 :     m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_ANSI ).WriteCharPtr( SAL_NEWLINE_STRING );
     371           0 :     rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_MS_1252;
     372             : 
     373           0 :     bool bBold          = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
     374           0 :     bool bItalic        = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
     375           0 :     bool bUnderline     = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
     376           0 :     bool bStrikeout     = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
     377             : 
     378           0 :     sal_Int32 nColor = 0;
     379           0 :     if(m_xObject.is())
     380           0 :         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
     381           0 :     ::Color aColor(nColor);
     382             : 
     383           0 :     OString aFonts(OUStringToOString(m_aFont.Name, eDestEnc));
     384           0 :     if (aFonts.isEmpty())
     385             :     {
     386           0 :         OUString aName = Application::GetSettings().GetStyleSettings().GetAppFont().GetName();
     387           0 :         aFonts = OUStringToOString(aName, eDestEnc);
     388             :     }
     389             : 
     390           0 :     m_pStream->WriteCharPtr( "{\\fonttbl" );
     391           0 :     sal_Int32 nTokenCount = comphelper::string::getTokenCount(aFonts, ';');
     392           0 :     for(sal_Int32 j=0; j<nTokenCount; ++j)
     393             :     {
     394           0 :         m_pStream->WriteCharPtr( "\\f" );
     395           0 :         m_pStream->WriteInt32AsString(j);
     396           0 :         m_pStream->WriteCharPtr( "\\fcharset0\\fnil " );
     397           0 :         m_pStream->WriteCharPtr( comphelper::string::getToken(aFonts, j, ';').getStr() );
     398           0 :         m_pStream->WriteChar( ';' );
     399             :     }
     400           0 :     m_pStream->WriteChar( '}' ) ;
     401           0 :     m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     402             :     // write the rtf color table
     403           0 :     m_pStream->WriteChar( '{' ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_COLORTBL ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_RED );
     404           0 :     m_pStream->WriteUInt32AsString(aColor.GetRed());
     405           0 :     m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_GREEN );
     406           0 :     m_pStream->WriteUInt32AsString(aColor.GetGreen());
     407           0 :     m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_BLUE );
     408           0 :     m_pStream->WriteUInt32AsString(aColor.GetBlue());
     409             : 
     410           0 :     m_pStream->WriteCharPtr( ";\\red255\\green255\\blue255;\\red192\\green192\\blue192;}" )
     411           0 :                 .WriteCharPtr( SAL_NEWLINE_STRING );
     412             : 
     413             :     static char const aTRRH[] = "\\trrh-270\\pard\\intbl";
     414             :     static char const aFS[] = "\\fs20\\f0\\cf0\\cb2";
     415             :     static char const aCell1[] = "\\clbrdrl\\brdrs\\brdrcf0\\clbrdrt\\brdrs\\brdrcf0\\clbrdrb\\brdrs\\brdrcf0\\clbrdrr\\brdrs\\brdrcf0\\clshdng10000\\clcfpat2\\cellx";
     416             : 
     417           0 :     m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_TROWD ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_TRGAPH );
     418           0 :     m_pStream->WriteInt32AsString(40);
     419           0 :     m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     420             : 
     421           0 :     if(m_xObject.is())
     422             :     {
     423           0 :         Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
     424           0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
     425           0 :         Sequence< OUString> aNames(xColumns->getElementNames());
     426           0 :         const OUString* pIter = aNames.getConstArray();
     427             : 
     428           0 :         sal_Int32 nCount = aNames.getLength();
     429           0 :         bool bUseResultMetaData = false;
     430           0 :         if ( !nCount )
     431             :         {
     432           0 :             nCount = m_xResultSetMetaData->getColumnCount();
     433           0 :             bUseResultMetaData = true;
     434             :         }
     435             : 
     436           0 :         for( sal_Int32 i=1; i<=nCount; ++i )
     437             :         {
     438           0 :             m_pStream->WriteCharPtr( aCell1 );
     439           0 :             m_pStream->WriteInt32AsString(i*CELL_X);
     440           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     441             :         }
     442             : 
     443             :         // column description
     444           0 :         m_pStream->WriteChar( '{' ).WriteCharPtr( SAL_NEWLINE_STRING );
     445           0 :         m_pStream->WriteCharPtr( aTRRH );
     446             : 
     447           0 :         boost::scoped_array<OString> pHorzChar(new OString[nCount]);
     448             : 
     449           0 :         for ( sal_Int32 i=1; i <= nCount; ++i )
     450             :         {
     451           0 :             sal_Int32 nAlign = 0;
     452           0 :             OUString sColumnName;
     453           0 :             if ( bUseResultMetaData )
     454           0 :                 sColumnName = m_xResultSetMetaData->getColumnName(i);
     455             :             else
     456             :             {
     457           0 :                 sColumnName = *pIter;
     458           0 :                 Reference<XPropertySet> xColumn;
     459           0 :                 xColumns->getByName(sColumnName) >>= xColumn;
     460           0 :                 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
     461           0 :                 ++pIter;
     462             :             }
     463             : 
     464             :             const char* pChar;
     465           0 :             switch( nAlign )
     466             :             {
     467           0 :                 case 1: pChar = OOO_STRING_SVTOOLS_RTF_QC;  break;
     468           0 :                 case 2: pChar = OOO_STRING_SVTOOLS_RTF_QR;  break;
     469             :                 case 0:
     470           0 :                 default:pChar = OOO_STRING_SVTOOLS_RTF_QL;  break;
     471             :             }
     472             : 
     473           0 :             pHorzChar[i-1] = pChar; // to avoid to always rummage in the ITEMSET later on
     474             : 
     475           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     476           0 :             m_pStream->WriteChar( '{' );
     477           0 :             m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_QC );   // column header always centered
     478             : 
     479           0 :             if ( bBold )        m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_B );
     480           0 :             if ( bItalic )      m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_I );
     481           0 :             if ( bUnderline )   m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_UL );
     482           0 :             if ( bStrikeout )   m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_STRIKE );
     483             : 
     484           0 :             m_pStream->WriteCharPtr( aFS );
     485           0 :             m_pStream->WriteChar( ' ' );
     486           0 :             RTFOutFuncs::Out_String(*m_pStream,sColumnName,eDestEnc);
     487             : 
     488           0 :             m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_CELL );
     489           0 :             m_pStream->WriteChar( '}' );
     490           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     491           0 :             m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_PARD ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_INTBL );
     492           0 :         }
     493             : 
     494           0 :         m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_ROW );
     495           0 :         m_pStream->WriteCharPtr( SAL_NEWLINE_STRING ).WriteChar( '}' );
     496           0 :         m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     497             : 
     498           0 :         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
     499           0 :         sal_Int32 k=1;
     500           0 :         sal_Int32 kk=0;
     501           0 :         if ( m_aSelection.getLength() )
     502             :         {
     503           0 :             const Any* pSelIter = m_aSelection.getConstArray();
     504           0 :             const Any* pEnd   = pSelIter + m_aSelection.getLength();
     505             : 
     506           0 :             bool bContinue = true;
     507           0 :             for( ; pSelIter != pEnd && bContinue; ++pSelIter )
     508             :             {
     509           0 :                 if ( m_bBookmarkSelection )
     510             :                 {
     511           0 :                     bContinue = m_xRowLocate->moveToBookmark( *pSelIter );
     512             :                 }
     513             :                 else
     514             :                 {
     515           0 :                     sal_Int32 nPos = -1;
     516           0 :                     OSL_VERIFY( *pSelIter >>= nPos );
     517           0 :                     bContinue = ( m_xResultSet->absolute( nPos ) );
     518             :                 }
     519             : 
     520           0 :                 if ( bContinue )
     521           0 :                     appendRow( pHorzChar.get(), nCount, k, kk );
     522             :             }
     523             :         }
     524             :         else
     525             :         {
     526           0 :             m_xResultSet->beforeFirst(); // set back before the first row
     527           0 :             while(m_xResultSet->next())
     528             :             {
     529           0 :                 appendRow(pHorzChar.get(),nCount,k,kk);
     530             :             }
     531           0 :         }
     532             :     }
     533             : 
     534           0 :     m_pStream->WriteChar( '}' ).WriteCharPtr( SAL_NEWLINE_STRING );
     535           0 :     m_pStream->WriteUChar(  0 );
     536           0 :     return ((*m_pStream).GetError() == SVSTREAM_OK);
     537             : }
     538             : 
     539           0 : void ORTFImportExport::appendRow(OString* pHorzChar,sal_Int32 _nColumnCount,sal_Int32& k,sal_Int32& kk)
     540             : {
     541           0 :     if(!m_pRowMarker || m_pRowMarker[kk] == k)
     542             :     {
     543           0 :         ++kk;
     544           0 :         m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_TROWD ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_TRGAPH );
     545           0 :         m_pStream->WriteInt32AsString(40);
     546           0 :         m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     547             : 
     548             :         static char const aCell2[] = "\\clbrdrl\\brdrs\\brdrcf2\\clbrdrt\\brdrs\\brdrcf2\\clbrdrb\\brdrs\\brdrcf2\\clbrdrr\\brdrs\\brdrcf2\\clshdng10000\\clcfpat1\\cellx";
     549             :         static char const aTRRH[] = "\\trrh-270\\pard\\intbl";
     550             : 
     551           0 :         for ( sal_Int32 i=1; i<=_nColumnCount; ++i )
     552             :         {
     553           0 :             m_pStream->WriteCharPtr( aCell2 );
     554           0 :             m_pStream->WriteInt32AsString(i*CELL_X);
     555           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     556             :         }
     557             : 
     558           0 :         const bool bBold            = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
     559           0 :         const bool bItalic      = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
     560           0 :         const bool bUnderline       = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
     561           0 :         const bool bStrikeout       = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
     562           0 :         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
     563             : 
     564           0 :         m_pStream->WriteChar( '{' );
     565           0 :         m_pStream->WriteCharPtr( aTRRH );
     566           0 :         for ( sal_Int32 i=1; i <= _nColumnCount; ++i )
     567             :         {
     568           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     569           0 :             m_pStream->WriteChar( '{' );
     570           0 :             m_pStream->WriteCharPtr( pHorzChar[i-1].getStr() );
     571             : 
     572           0 :             if ( bBold )        m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_B );
     573           0 :             if ( bItalic )      m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_I );
     574           0 :             if ( bUnderline )   m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_UL );
     575           0 :             if ( bStrikeout )   m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_STRIKE );
     576             : 
     577           0 :             m_pStream->WriteCharPtr( "\\fs20\\f1\\cf0\\cb1 " );
     578             : 
     579             :             try
     580             :             {
     581           0 :                 Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
     582           0 :                 dbtools::FormattedColumnValue aFormatedValue(m_xContext,xRowSet,xColumn);
     583           0 :                 OUString sValue = aFormatedValue.getFormattedValue();
     584           0 :                 if ( !sValue.isEmpty() )
     585           0 :                     RTFOutFuncs::Out_String(*m_pStream,sValue,m_eDestEnc);
     586             :             }
     587           0 :             catch (Exception&)
     588             :             {
     589             :                 SAL_WARN("dbaccess.ui","RTF WRITE!");
     590             :             }
     591             : 
     592           0 :             m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_CELL );
     593           0 :             m_pStream->WriteChar( '}' );
     594           0 :             m_pStream->WriteCharPtr( SAL_NEWLINE_STRING );
     595           0 :             m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_PARD ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_INTBL );
     596             :         }
     597           0 :         m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_RTF_ROW ).WriteCharPtr( SAL_NEWLINE_STRING );
     598           0 :         m_pStream->WriteChar( '}' );
     599             :     }
     600           0 :     ++k;
     601           0 : }
     602             : 
     603           0 : bool ORTFImportExport::Read()
     604             : {
     605           0 :     ODatabaseImportExport::Read();
     606           0 :     SvParserState eState = SVPAR_ERROR;
     607           0 :     if ( m_pStream )
     608             :     {
     609           0 :         m_pReader = new ORTFReader((*m_pStream),m_xConnection,m_xFormatter,m_xContext);
     610           0 :         static_cast<ORTFReader*>(m_pReader)->AddFirstRef();
     611           0 :         if ( isCheckEnabled() )
     612           0 :             m_pReader->enableCheckOnly();
     613           0 :         eState = static_cast<ORTFReader*>(m_pReader)->CallParser();
     614           0 :         m_pReader->release();
     615           0 :         m_pReader = NULL;
     616             :     }
     617             : 
     618           0 :     return eState != SVPAR_ERROR;
     619             : }
     620             : 
     621             : const sal_Int16 OHTMLImportExport::nDefaultFontSize[SBA_HTML_FONTSIZES] =
     622             : {
     623             :     HTMLFONTSZ1_DFLT, HTMLFONTSZ2_DFLT, HTMLFONTSZ3_DFLT, HTMLFONTSZ4_DFLT,
     624             :     HTMLFONTSZ5_DFLT, HTMLFONTSZ6_DFLT, HTMLFONTSZ7_DFLT
     625             : };
     626             : 
     627             : sal_Int16 OHTMLImportExport::nFontSize[SBA_HTML_FONTSIZES] = { 0 };
     628             : 
     629             : const sal_Int16 OHTMLImportExport::nCellSpacing = 0;
     630             : const char OHTMLImportExport::sIndentSource[nIndentMax+1] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
     631             : 
     632             : // Macros for HTML-Export
     633             : #define TAG_ON( tag )       HTMLOutFuncs::Out_AsciiTag( (*m_pStream), tag )
     634             : #define TAG_OFF( tag )      HTMLOutFuncs::Out_AsciiTag( (*m_pStream), tag, false )
     635             : #define OUT_LF()            m_pStream->WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() )
     636             : #define TAG_ON_LF( tag )    (TAG_ON( tag ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() ))
     637             : #define TAG_OFF_LF( tag )   (TAG_OFF( tag ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() ))
     638             : 
     639           0 : OHTMLImportExport::OHTMLImportExport(const ::svx::ODataAccessDescriptor& _aDataDescriptor,
     640             :                                      const Reference< XComponentContext >& _rM,
     641             :                                      const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
     642             :                                      const OUString& rExchange)
     643             :         : ODatabaseImportExport(_aDataDescriptor,_rM,_rxNumberF,rExchange)
     644           0 :     ,m_nIndent(0)
     645             : #if OSL_DEBUG_LEVEL > 0
     646             :     ,m_bCheckFont(false)
     647             : #endif
     648             : {
     649             :     // set HTML configuration
     650           0 :     SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
     651           0 :     m_eDestEnc = rHtmlOptions.GetTextEncoding();
     652           0 :     strncpy( sIndent, sIndentSource ,std::min(sizeof(sIndent),sizeof(sIndentSource)));
     653           0 :     sIndent[0] = 0;
     654           0 : }
     655             : 
     656           0 : bool OHTMLImportExport::Write()
     657             : {
     658           0 :     ODatabaseImportExport::Write();
     659           0 :     if(m_xObject.is())
     660             :     {
     661           0 :         m_pStream->WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype40 ).WriteChar( '>' ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( SAL_NEWLINE_STRING );
     662           0 :         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_html );
     663           0 :         WriteHeader();
     664           0 :         OUT_LF();
     665           0 :         WriteBody();
     666           0 :         OUT_LF();
     667           0 :         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_html );
     668             : 
     669           0 :         return ((*m_pStream).GetError() == SVSTREAM_OK);
     670             :     }
     671           0 :     return false;
     672             : }
     673             : 
     674           0 : bool OHTMLImportExport::Read()
     675             : {
     676           0 :     ODatabaseImportExport::Read();
     677           0 :     SvParserState eState = SVPAR_ERROR;
     678           0 :     if ( m_pStream )
     679             :     {
     680           0 :         m_pReader = new OHTMLReader((*m_pStream),m_xConnection,m_xFormatter,m_xContext);
     681           0 :         static_cast<OHTMLReader*>(m_pReader)->AddFirstRef();
     682           0 :         if ( isCheckEnabled() )
     683           0 :             m_pReader->enableCheckOnly();
     684           0 :         m_pReader->SetTableName(m_sDefaultTableName);
     685           0 :         eState = static_cast<OHTMLReader*>(m_pReader)->CallParser();
     686           0 :         m_pReader->release();
     687           0 :         m_pReader = NULL;
     688             :     }
     689             : 
     690           0 :     return eState != SVPAR_ERROR;
     691             : }
     692             : 
     693           0 : void OHTMLImportExport::WriteHeader()
     694             : {
     695             :     uno::Reference<document::XDocumentProperties> xDocProps(
     696           0 :         document::DocumentProperties::create( m_xContext ) );
     697           0 :     if (xDocProps.is()) {
     698           0 :         xDocProps->setTitle(m_sName);
     699             :     }
     700             : 
     701           0 :     IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_head );
     702             : 
     703             :     SfxFrameHTMLWriter::Out_DocInfo( (*m_pStream), OUString(),
     704           0 :         xDocProps, sIndent );
     705           0 :     OUT_LF();
     706           0 :     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_head );
     707           0 : }
     708             : 
     709           0 : void OHTMLImportExport::WriteBody()
     710             : {
     711           0 :     IncIndent(1);
     712           0 :     m_pStream->WriteCharPtr( "<" ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_style ).WriteCharPtr( " " ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_type ).WriteCharPtr( "=\"text/css\">" );
     713             : 
     714           0 :     m_pStream->WriteCharPtr( sMyBegComment ); OUT_LF();
     715           0 :     m_pStream->WriteCharPtr( OOO_STRING_SVTOOLS_HTML_body ).WriteCharPtr( " { " ).WriteCharPtr( sFontFamily ).WriteChar( '"' ).WriteCharPtr( OUStringToOString(m_aFont.Name, osl_getThreadTextEncoding()).getStr() ).WriteChar( '\"' );
     716             :         // TODO : think about the encoding of the font name
     717           0 :     m_pStream->WriteCharPtr( "; " ).WriteCharPtr( sFontSize );
     718           0 :     m_pStream->WriteInt32AsString(m_aFont.Height);
     719           0 :     m_pStream->WriteChar( '}' );
     720             : 
     721           0 :     OUT_LF();
     722           0 :     m_pStream->WriteCharPtr( sMyEndComment );
     723           0 :     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_style );
     724           0 :     OUT_LF();
     725             : 
     726             :     // default Textcolour black
     727           0 :     m_pStream->WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_body ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_text ).WriteChar( '=' );
     728           0 :     sal_Int32 nColor = 0;
     729           0 :     if(m_xObject.is())
     730           0 :         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
     731           0 :     ::Color aColor(nColor);
     732           0 :     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
     733             : 
     734           0 :     m_pStream->WriteCharPtr( " " OOO_STRING_SVTOOLS_HTML_O_bgcolor "=" );
     735           0 :     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
     736             : 
     737           0 :     m_pStream->WriteChar( '>' ); OUT_LF();
     738             : 
     739           0 :     WriteTables();
     740             : 
     741           0 :     TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_body );
     742           0 : }
     743             : 
     744           0 : void OHTMLImportExport::WriteTables()
     745             : {
     746           0 :     OString aStrOut  = OOO_STRING_SVTOOLS_HTML_table;
     747           0 :     aStrOut = aStrOut + " ";
     748           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_frame;
     749           0 :     aStrOut = aStrOut + "=";
     750           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_TF_void;
     751             : 
     752           0 :     Sequence< OUString> aNames;
     753           0 :     Reference<XNameAccess> xColumns;
     754           0 :     bool bUseResultMetaData = false;
     755           0 :     if(m_xObject.is())
     756             :     {
     757           0 :         Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
     758           0 :         xColumns = xColSup->getColumns();
     759           0 :         aNames = xColumns->getElementNames();
     760           0 :         if ( !aNames.getLength() )
     761             :         {
     762           0 :             sal_Int32 nCount = m_xResultSetMetaData->getColumnCount();
     763           0 :             aNames.realloc(nCount);
     764           0 :             for (sal_Int32 i= 0; i < nCount; ++i)
     765           0 :                 aNames[i] = m_xResultSetMetaData->getColumnName(i+1);
     766           0 :             bUseResultMetaData = true;
     767           0 :         }
     768             :     }
     769             : 
     770           0 :     aStrOut = aStrOut + " ";
     771           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_align;
     772           0 :     aStrOut = aStrOut + "=";
     773           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_AL_left;
     774           0 :     aStrOut = aStrOut + " ";
     775           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_cellspacing;
     776           0 :     aStrOut = aStrOut + "=";
     777           0 :     aStrOut = aStrOut + OString::number(nCellSpacing);
     778           0 :     aStrOut = aStrOut + " ";
     779           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_cols;
     780           0 :     aStrOut = aStrOut + "=";
     781           0 :     aStrOut = aStrOut + OString::number(aNames.getLength());
     782           0 :     aStrOut = aStrOut + " ";
     783           0 :     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_border;
     784           0 :     aStrOut = aStrOut + "=1";
     785             : 
     786           0 :     IncIndent(1);
     787           0 :     TAG_ON( aStrOut.getStr() );
     788             : 
     789           0 :     FontOn();
     790             : 
     791           0 :     TAG_ON( OOO_STRING_SVTOOLS_HTML_caption );
     792           0 :     TAG_ON( OOO_STRING_SVTOOLS_HTML_bold );
     793             : 
     794           0 :     m_pStream->WriteCharPtr( OUStringToOString(m_sName, osl_getThreadTextEncoding()).getStr() );
     795             :         // TODO : think about the encoding of the name
     796           0 :     TAG_OFF( OOO_STRING_SVTOOLS_HTML_bold );
     797           0 :     TAG_OFF( OOO_STRING_SVTOOLS_HTML_caption );
     798             : 
     799           0 :     FontOff();
     800           0 :     OUT_LF();
     801             :     // </FONT>
     802             : 
     803           0 :     IncIndent(1);
     804           0 :     TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_thead );
     805             : 
     806           0 :     IncIndent(1);
     807           0 :     TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
     808             : 
     809           0 :     if(m_xObject.is())
     810             :     {
     811           0 :         boost::scoped_array<sal_Int32> pFormat(new sal_Int32[aNames.getLength()]);
     812             : 
     813           0 :         boost::scoped_array<const char *> pHorJustify(new const char*[aNames.getLength()]);
     814           0 :         boost::scoped_array<sal_Int32> pColWidth(new sal_Int32[aNames.getLength()]);
     815             : 
     816           0 :         sal_Int32 nHeight = 0;
     817           0 :         m_xObject->getPropertyValue(PROPERTY_ROW_HEIGHT) >>= nHeight;
     818             : 
     819             :         // 1. writing the column description
     820           0 :         const OUString* pIter = aNames.getConstArray();
     821           0 :         const OUString* pEnd = pIter + aNames.getLength();
     822             : 
     823           0 :         for( sal_Int32 i=0;pIter != pEnd; ++pIter,++i )
     824             :         {
     825           0 :             sal_Int32 nAlign = 0;
     826           0 :             pFormat[i] = 0;
     827           0 :             pColWidth[i] = 100;
     828           0 :             if ( !bUseResultMetaData )
     829             :             {
     830           0 :                 Reference<XPropertySet> xColumn;
     831           0 :                 xColumns->getByName(*pIter) >>= xColumn;
     832           0 :                 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
     833           0 :                 pFormat[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_FORMATKEY));
     834           0 :                 pColWidth[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_WIDTH));
     835             :             }
     836             : 
     837           0 :             switch( nAlign )
     838             :             {
     839           0 :                 case 1:     pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_center; break;
     840           0 :                 case 2:     pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_right;  break;
     841           0 :                 default:    pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_left;       break;
     842             :             }
     843             : 
     844           0 :             if(i == aNames.getLength()-1)
     845           0 :                 IncIndent(-1);
     846             : 
     847           0 :             WriteCell(pFormat[i],pColWidth[i],nHeight,pHorJustify[i],*pIter,OOO_STRING_SVTOOLS_HTML_tableheader);
     848             :         }
     849             : 
     850           0 :         IncIndent(-1);
     851           0 :         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
     852           0 :         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_thead );
     853             : 
     854           0 :         IncIndent(1);
     855           0 :         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tbody );
     856             : 
     857             :         // 2. and now the data
     858           0 :         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
     859           0 :         sal_Int32 j=1;
     860           0 :         sal_Int32 kk=0;
     861           0 :         m_xResultSet->beforeFirst(); // set back before the first row
     862           0 :         while(m_xResultSet->next())
     863             :         {
     864           0 :             IncIndent(1);
     865           0 :             TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
     866             : 
     867           0 :             if(!m_pRowMarker || m_pRowMarker[kk] == j)
     868             :             {
     869           0 :                 ++kk;
     870           0 :                 for(sal_Int32 i=1;i<=aNames.getLength();++i)
     871             :                 {
     872           0 :                     if(i == aNames.getLength())
     873           0 :                         IncIndent(-1);
     874             : 
     875           0 :                     OUString aValue;
     876             :                     try
     877             :                     {
     878           0 :                         Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
     879           0 :                         dbtools::FormattedColumnValue aFormatedValue(m_xContext,xRowSet,xColumn);
     880           0 :                         OUString sValue = aFormatedValue.getFormattedValue();
     881           0 :                         if (!sValue.isEmpty())
     882             :                         {
     883           0 :                             aValue = sValue;
     884           0 :                         }
     885             :                     }
     886           0 :                     catch( const Exception& )
     887             :                     {
     888             :                         DBG_UNHANDLED_EXCEPTION();
     889             :                     }
     890           0 :                     WriteCell(pFormat[i-1],pColWidth[i-1],nHeight,pHorJustify[i-1],aValue,OOO_STRING_SVTOOLS_HTML_tabledata);
     891           0 :                 }
     892             :             }
     893           0 :             ++j;
     894           0 :             TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
     895           0 :         }
     896             :     }
     897             :     else
     898             :     {
     899           0 :         IncIndent(-1);
     900           0 :         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
     901           0 :         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_thead );
     902             : 
     903           0 :         IncIndent(1);
     904           0 :         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tbody );
     905             :     }
     906             : 
     907           0 :     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tbody );
     908           0 :     IncIndent(-1); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_table );
     909           0 : }
     910             : 
     911           0 : void OHTMLImportExport::WriteCell( sal_Int32 nFormat, sal_Int32 nWidthPixel, sal_Int32 nHeightPixel, const char* pChar,
     912             :                                    const OUString& rValue, const char* pHtmlTag)
     913             : {
     914           0 :     OString aStrTD = pHtmlTag;
     915             : 
     916           0 :     nWidthPixel  = nWidthPixel  ? nWidthPixel   : 86;
     917           0 :     nHeightPixel = nHeightPixel ? nHeightPixel  : 17;
     918             : 
     919             :     // despite the <TABLE COLS=n> and <COL WIDTH=x> designation necessary,
     920             :     // as Netscape is not paying attention to them.
     921             :     // column width
     922           0 :     aStrTD = aStrTD + " ";
     923           0 :     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_width;
     924           0 :     aStrTD = aStrTD + "=";
     925           0 :     aStrTD = aStrTD + OString::number(nWidthPixel);
     926             :     // line height
     927           0 :     aStrTD = aStrTD + " ";
     928           0 :     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_height;
     929           0 :     aStrTD = aStrTD + "=";
     930           0 :     aStrTD = aStrTD + OString::number(nHeightPixel);
     931             : 
     932           0 :     aStrTD = aStrTD + " ";
     933           0 :     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_align;
     934           0 :     aStrTD = aStrTD + "=";
     935           0 :     aStrTD = aStrTD + pChar;
     936             : 
     937           0 :     Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = m_xFormatter->getNumberFormatsSupplier();
     938           0 :     SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
     939           0 :     SvNumberFormatter* pFormatter = pSupplierImpl ? pSupplierImpl->GetNumberFormatter() : NULL;
     940           0 :     if(pFormatter)
     941             :     {
     942           0 :         double fVal = 0.0;
     943             : 
     944             :         try
     945             :         {
     946           0 :             fVal = m_xFormatter->convertStringToNumber(nFormat,rValue);
     947           0 :             HTMLOutFuncs::CreateTableDataOptionsValNum(false, fVal,nFormat, *pFormatter);
     948             :         }
     949           0 :         catch(const Exception&)
     950             :         {
     951           0 :             HTMLOutFuncs::CreateTableDataOptionsValNum(false, fVal,nFormat, *pFormatter);
     952             :         }
     953             :     }
     954             : 
     955           0 :     TAG_ON( aStrTD.getStr() );
     956             : 
     957           0 :     FontOn();
     958             : 
     959           0 :     bool bBold          = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
     960           0 :     bool bItalic        = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
     961           0 :     bool bUnderline     = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
     962           0 :     bool bStrikeout     = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
     963             : 
     964           0 :     if ( bBold )        TAG_ON( OOO_STRING_SVTOOLS_HTML_bold );
     965           0 :     if ( bItalic )      TAG_ON( OOO_STRING_SVTOOLS_HTML_italic );
     966           0 :     if ( bUnderline )   TAG_ON( OOO_STRING_SVTOOLS_HTML_underline );
     967           0 :     if ( bStrikeout )   TAG_ON( OOO_STRING_SVTOOLS_HTML_strike );
     968             : 
     969           0 :     if ( rValue.isEmpty() )
     970           0 :         TAG_ON( OOO_STRING_SVTOOLS_HTML_linebreak );        // no completely empty cell
     971             :     else
     972           0 :         HTMLOutFuncs::Out_String( (*m_pStream), rValue ,m_eDestEnc);
     973             : 
     974           0 :     if ( bStrikeout )   TAG_OFF( OOO_STRING_SVTOOLS_HTML_strike );
     975           0 :     if ( bUnderline )   TAG_OFF( OOO_STRING_SVTOOLS_HTML_underline );
     976           0 :     if ( bItalic )      TAG_OFF( OOO_STRING_SVTOOLS_HTML_italic );
     977           0 :     if ( bBold )        TAG_OFF( OOO_STRING_SVTOOLS_HTML_bold );
     978             : 
     979           0 :     FontOff();
     980             : 
     981           0 :     TAG_OFF_LF( pHtmlTag );
     982           0 : }
     983             : 
     984           0 : void OHTMLImportExport::FontOn()
     985             : {
     986             : #if OSL_DEBUG_LEVEL > 0
     987             :         m_bCheckFont = true;
     988             : #endif
     989             : 
     990             :     // <FONT FACE="xxx">
     991           0 :     OString aStrOut  = "<";
     992           0 :     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_font;
     993           0 :     aStrOut  = aStrOut + " ";
     994           0 :     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_O_face;
     995           0 :     aStrOut  = aStrOut + "=";
     996           0 :     aStrOut  = aStrOut + "\"";
     997           0 :     aStrOut  = aStrOut + OUStringToOString(m_aFont.Name,osl_getThreadTextEncoding());
     998             :         // TODO : think about the encoding of the font name
     999           0 :     aStrOut  = aStrOut + "\"";
    1000           0 :     aStrOut  = aStrOut + " ";
    1001           0 :     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_O_color;
    1002           0 :     aStrOut  = aStrOut + "=";
    1003           0 :     m_pStream->WriteCharPtr( aStrOut.getStr() );
    1004             : 
    1005           0 :     sal_Int32 nColor = 0;
    1006           0 :     if(m_xObject.is())
    1007           0 :         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
    1008           0 :     ::Color aColor(nColor);
    1009             : 
    1010           0 :     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
    1011           0 :     m_pStream->WriteCharPtr( ">" );
    1012           0 : }
    1013             : 
    1014           0 : inline void OHTMLImportExport::FontOff()
    1015             : {
    1016             :     OSL_ENSURE(m_bCheckFont,"Kein FontOn() gerufen");
    1017           0 :     TAG_OFF( OOO_STRING_SVTOOLS_HTML_font );
    1018             : #if OSL_DEBUG_LEVEL > 0
    1019             :     m_bCheckFont = false;
    1020             : #endif
    1021           0 : }
    1022             : 
    1023           0 : void OHTMLImportExport::IncIndent( sal_Int16 nVal )
    1024             : {
    1025           0 :     sIndent[m_nIndent] = '\t';
    1026           0 :     m_nIndent = m_nIndent + nVal;
    1027           0 :     if ( m_nIndent < 0 )
    1028           0 :         m_nIndent = 0;
    1029           0 :     else if ( m_nIndent > nIndentMax )
    1030           0 :         m_nIndent = nIndentMax;
    1031           0 :     sIndent[m_nIndent] = 0;
    1032          72 : }
    1033             : 
    1034             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10