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

Generated by: LCOV version 1.10