LibreOffice Module dbaccess (master) 1
TokenWriter.cxx
Go to the documentation of this file.
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>
22#include <tools/stream.hxx>
23#include <osl/diagnose.h>
24#include <rtl/tencinfo.h>
25#include <sal/log.hxx>
27#include <RtfReader.hxx>
28#include <HtmlReader.hxx>
29#include <strings.hxx>
30#include <comphelper/types.hxx>
32#include <com/sun/star/sdb/CommandType.hpp>
33#include <com/sun/star/sdb/DatabaseContext.hpp>
34#include <com/sun/star/sdbc/XConnection.hpp>
35#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
37#include <com/sun/star/sdbc/XRowSet.hpp>
38#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
39#include <com/sun/star/sdb/XQueriesSupplier.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 <utility>
52#include <vcl/svapp.hxx>
53#include <UITools.hxx>
55#include <vcl/outdev.hxx>
56#include <vcl/settings.hxx>
57#include <svtools/rtfout.hxx>
58#include <svtools/htmlcfg.hxx>
59#include <o3tl/string_view.hxx>
61#include <memory>
62
63using namespace dbaui;
64using namespace dbtools;
65using namespace svx;
66using namespace ::com::sun::star;
67using namespace ::com::sun::star::uno;
68using namespace ::com::sun::star::beans;
69using namespace ::com::sun::star::container;
70using namespace ::com::sun::star::sdbc;
71using namespace ::com::sun::star::sdb;
72using namespace ::com::sun::star::lang;
73using namespace ::com::sun::star::sdbcx;
74using namespace ::com::sun::star::awt;
75using namespace ::com::sun::star::util;
76
77#define CELL_X 1437
78
79ODatabaseImportExport::ODatabaseImportExport(const svx::ODataAccessDescriptor& _aDataDescriptor,
82 :m_bBookmarkSelection( false )
83 ,m_pStream(nullptr)
84 ,m_xFormatter(_rxNumberF)
85 ,m_xContext(_rM)
87 ,m_bNeedToReInitialize(false)
88 ,m_bInInitialize(false)
89 ,m_bCheckOnly(false)
90{
91 m_eDestEnc = osl_getThreadTextEncoding();
93 osl_atomic_increment( &m_refCount );
94 impl_initFromDescriptor( _aDataDescriptor, false );
95 osl_atomic_decrement( &m_refCount );
96}
97
98// import data
99ODatabaseImportExport::ODatabaseImportExport( ::dbtools::SharedConnection _xConnection,
101 :m_bBookmarkSelection( false )
102 ,m_pStream(nullptr)
103 ,m_xConnection(std::move(_xConnection))
104 ,m_xFormatter(_rxNumberF)
105 ,m_xContext(_rM)
106 ,m_nCommandType(css::sdb::CommandType::TABLE)
107 ,m_bNeedToReInitialize(false)
108 ,m_bInInitialize(false)
109 ,m_bCheckOnly(false)
110{
111 m_eDestEnc = osl_getThreadTextEncoding();
112}
113
114ODatabaseImportExport::~ODatabaseImportExport()
115{
116 acquire();
117 dispose();
118}
119
121{
122 // remove me as listener
123 Reference< XComponent > xComponent(m_xConnection, UNO_QUERY);
124 if (xComponent.is())
125 {
127 xComponent->removeEventListener(xEvt);
128 }
130
131 ::comphelper::disposeComponent(m_xRow);
132
133 m_xObject.clear();
134 m_xResultSetMetaData.clear();
135 m_xResultSet.clear();
136 m_xRow.clear();
137 m_xRowLocate.clear();
138 m_xFormatter.clear();
139}
140
141void SAL_CALL ODatabaseImportExport::disposing( const EventObject& Source )
142{
143 Reference<XConnection> xCon(Source.Source,UNO_QUERY);
144 if(m_xConnection.is() && m_xConnection == xCon)
145 {
147 dispose();
149 }
150}
151
153{
154 impl_initFromDescriptor( _aDataDescriptor, true );
155}
156
157void ODatabaseImportExport::impl_initFromDescriptor( const ODataAccessDescriptor& _aDataDescriptor, bool _bPlusDefaultInit)
158{
159 if ( !_bPlusDefaultInit )
160 {
161 m_sDataSourceName = _aDataDescriptor.getDataSource();
162 _aDataDescriptor[DataAccessDescriptorProperty::CommandType] >>= m_nCommandType;
163 _aDataDescriptor[DataAccessDescriptorProperty::Command] >>= m_sName;
164 // some additional information
165 if(_aDataDescriptor.has(DataAccessDescriptorProperty::Connection))
166 {
167 Reference< XConnection > xPureConn( _aDataDescriptor[DataAccessDescriptorProperty::Connection], UNO_QUERY );
170 Reference< XComponent > xComponent(m_xConnection, UNO_QUERY);
171 if (xComponent.is() && xEvt.is())
172 xComponent->addEventListener(xEvt);
173 }
174
175 if ( _aDataDescriptor.has( DataAccessDescriptorProperty::Selection ) )
176 _aDataDescriptor[ DataAccessDescriptorProperty::Selection ] >>= m_aSelection;
177
178 if ( _aDataDescriptor.has( DataAccessDescriptorProperty::BookmarkSelection ) )
179 _aDataDescriptor[ DataAccessDescriptorProperty::BookmarkSelection ] >>= m_bBookmarkSelection;
180
181 if ( _aDataDescriptor.has( DataAccessDescriptorProperty::Cursor ) )
182 {
183 _aDataDescriptor[ DataAccessDescriptorProperty::Cursor ] >>= m_xResultSet;
184 m_xRowLocate.set( m_xResultSet, UNO_QUERY );
185 }
186
187 if ( m_aSelection.hasElements() )
188 {
189 if ( !m_xResultSet.is() )
190 {
191 SAL_WARN("dbaccess.ui", "ODatabaseImportExport::impl_initFromDescriptor: selection without result set is nonsense!" );
192 m_aSelection.realloc( 0 );
193 }
194 }
195
196 if ( m_aSelection.hasElements() )
197 {
198 if ( m_bBookmarkSelection && !m_xRowLocate.is() )
199 {
200 SAL_WARN("dbaccess.ui", "ODatabaseImportExport::impl_initFromDescriptor: no XRowLocate -> no bookmarks!" );
201 m_aSelection.realloc( 0 );
202 }
203 }
204 }
205 else
206 initialize();
207}
208
210{
211 m_bInInitialize = true;
212 m_bNeedToReInitialize = false;
213
214 if ( !m_xConnection.is() )
215 { // we need a connection
216 OSL_ENSURE(!m_sDataSourceName.isEmpty(),"There must be a datsource name!");
217 Reference<XNameAccess> xDatabaseContext( DatabaseContext::create(m_xContext), UNO_QUERY_THROW);
219
220 Reference< XConnection > xConnection;
221 SQLExceptionInfo aInfo = ::dbaui::createConnection( m_sDataSourceName, xDatabaseContext, m_xContext, xEvt, xConnection );
222 m_xConnection.reset( xConnection );
223
224 if(aInfo.isValid() && aInfo.getType() == SQLExceptionInfo::TYPE::SQLException)
225 throw *static_cast<const SQLException*>(aInfo);
226 }
227
228 Reference<XNameAccess> xNameAccess;
229 switch(m_nCommandType)
230 {
232 {
233 // only for tables
235 if(xSup.is())
236 xNameAccess = xSup->getTables();
237 }
238 break;
240 {
242 if(xSup.is())
243 xNameAccess = xSup->getQueries();
244 }
245 break;
246 }
247 if(xNameAccess.is() && xNameAccess->hasByName(m_sName))
248 {
249 xNameAccess->getByName(m_sName) >>= m_xObject;
250 }
251
252 if(m_xObject.is())
253 {
254 try
255 {
256 if(m_xObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_FONT))
257 m_xObject->getPropertyValue(PROPERTY_FONT) >>= m_aFont;
258
259 // the result set may be already set with the datadescriptor
260 if ( !m_xResultSet.is() )
261 {
262 m_xResultSet.set( m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.sdb.RowSet", m_xContext), UNO_QUERY );
263 Reference< XPropertySet > xProp( m_xResultSet, UNO_QUERY_THROW );
264 xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, Any( m_xConnection.getTyped() ) );
265 xProp->setPropertyValue( PROPERTY_COMMAND_TYPE, Any( m_nCommandType ) );
266 xProp->setPropertyValue( PROPERTY_COMMAND, Any( m_sName ) );
267 Reference< XRowSet > xRowSet( xProp, UNO_QUERY );
268 xRowSet->execute();
269 }
270 if ( !m_xRow.is() && m_xResultSet.is() )
271 {
272 m_xRow.set( m_xResultSet, UNO_QUERY );
273 m_xRowLocate.set( m_xResultSet, UNO_QUERY );
274 m_xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(m_xRow,UNO_QUERY_THROW)->getMetaData();
275 Reference<XColumnsSupplier> xSup(m_xResultSet,UNO_QUERY_THROW);
276 m_xRowSetColumns.set(xSup->getColumns(),UNO_QUERY_THROW);
277 }
278 }
279 catch(Exception& )
280 {
281 m_xRow = nullptr;
282 m_xResultSetMetaData = nullptr;
283 ::comphelper::disposeComponent(m_xResultSet);
284 throw;
285 }
286 }
287 if ( m_aFont.Name.isEmpty() )
288 {
289 vcl::Font aApplicationFont = OutputDevice::GetDefaultFont(
290 DefaultFontType::SANS_UNICODE,
291 Application::GetSettings().GetUILanguageTag().getLanguageType(),
292 GetDefaultFontFlags::OnlyOne
293 );
294 m_aFont = VCLUnoHelper::CreateFontDescriptor( aApplicationFont );
295 }
296
297 m_bInInitialize = false;
298}
299
301{
303 {
304 if ( !m_bInInitialize )
305 initialize();
306 }
307 return true;
308}
309
311{
313 {
314 if ( !m_bInInitialize )
315 initialize();
316 }
317 return true;
318}
319
321{
325 if (sal_uInt32 nCpg = rtl_getWindowsCodePageFromTextEncoding(m_eDestEnc); nCpg && nCpg != 65001)
326 {
328 }
330
331 bool bBold = ( css::awt::FontWeight::BOLD == m_aFont.Weight );
332 bool bItalic = ( css::awt::FontSlant_ITALIC == m_aFont.Slant );
333 bool bUnderline = ( css::awt::FontUnderline::NONE != m_aFont.Underline );
334 bool bStrikeout = ( css::awt::FontStrikeout::NONE != m_aFont.Strikeout );
335
336 ::Color aColor;
337 if(m_xObject.is())
338 m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= aColor;
339
340 OString aFonts(OUStringToOString(m_aFont.Name, RTL_TEXTENCODING_MS_1252));
341 if (aFonts.isEmpty())
342 {
344 aFonts = OUStringToOString(aName, RTL_TEXTENCODING_MS_1252);
345 }
346
347 m_pStream->WriteOString( "{\\fonttbl" );
348 if (!aFonts.isEmpty())
349 {
350 sal_Int32 nIdx{0};
351 sal_Int32 nTok{-1}; // to compensate pre-increment
352 do {
353 m_pStream->WriteOString( "\\f" );
355 m_pStream->WriteOString( "\\fcharset0\\fnil " );
356 m_pStream->WriteOString( o3tl::getToken(aFonts, 0, ';', nIdx) );
357 m_pStream->WriteChar( ';' );
358 } while (nIdx>=0);
359 }
360 m_pStream->WriteChar( '}' ) ;
362 // write the rtf color table
369
370 m_pStream->WriteOString( ";\\red255\\green255\\blue255;\\red192\\green192\\blue192;}" )
372
373 static char const aCell1[] = "\\clbrdrl\\brdrs\\brdrcf0\\clbrdrt\\brdrs\\brdrcf0\\clbrdrb\\brdrs\\brdrcf0\\clbrdrr\\brdrs\\brdrcf0\\clshdng10000\\clcfpat2\\cellx";
374
376 m_pStream->WriteOString("40");
378
379 if(m_xObject.is())
380 {
381 Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
382 Reference<XNameAccess> xColumns = xColSup->getColumns();
383 Sequence< OUString> aNames(xColumns->getElementNames());
384 const OUString* pIter = aNames.getConstArray();
385
386 sal_Int32 nCount = aNames.getLength();
387 bool bUseResultMetaData = false;
388 if ( !nCount )
389 {
390 nCount = m_xResultSetMetaData->getColumnCount();
391 bUseResultMetaData = true;
392 }
393
394 for( sal_Int32 i=1; i<=nCount; ++i )
395 {
396 m_pStream->WriteOString( aCell1 );
399 }
400
401 // column description
403 m_pStream->WriteOString( "\\trrh-270\\pard\\intbl" );
404
405 std::unique_ptr<OString[]> pHorzChar(new OString[nCount]);
406
407 for ( sal_Int32 i=1; i <= nCount; ++i )
408 {
409 sal_Int32 nAlign = 0;
410 OUString sColumnName;
411 if ( bUseResultMetaData )
412 sColumnName = m_xResultSetMetaData->getColumnName(i);
413 else
414 {
415 sColumnName = *pIter;
417 xColumns->getByName(sColumnName) >>= xColumn;
418 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
419 ++pIter;
420 }
421
422 const char* pChar;
423 switch( nAlign )
424 {
425 case 1: pChar = OOO_STRING_SVTOOLS_RTF_QC; break;
426 case 2: pChar = OOO_STRING_SVTOOLS_RTF_QR; break;
427 case 0:
428 default:pChar = OOO_STRING_SVTOOLS_RTF_QL; break;
429 }
430
431 pHorzChar[i-1] = pChar; // to avoid to always rummage in the ITEMSET later on
432
434 m_pStream->WriteChar( '{' );
435 m_pStream->WriteOString( OOO_STRING_SVTOOLS_RTF_QC ); // column header always centered
436
441
442 m_pStream->WriteOString( "\\fs20\\f0\\cf0\\cb2" );
443 m_pStream->WriteChar( ' ' );
445
447 m_pStream->WriteChar( '}' );
450 }
451
455
456 sal_Int32 k=1;
457 sal_Int32 kk=0;
458 if ( m_aSelection.hasElements() )
459 {
460 const Any* pSelIter = m_aSelection.getConstArray();
461 const Any* pEnd = pSelIter + m_aSelection.getLength();
462
463 bool bContinue = true;
464 for( ; pSelIter != pEnd && bContinue; ++pSelIter )
465 {
467 {
468 bContinue = m_xRowLocate->moveToBookmark( *pSelIter );
469 }
470 else
471 {
472 sal_Int32 nPos = -1;
473 OSL_VERIFY( *pSelIter >>= nPos );
474 bContinue = ( m_xResultSet->absolute( nPos ) );
475 }
476
477 if ( bContinue )
478 appendRow( pHorzChar.get(), nCount, k, kk );
479 }
480 }
481 else
482 {
483 m_xResultSet->beforeFirst(); // set back before the first row
484 while(m_xResultSet->next())
485 {
486 appendRow(pHorzChar.get(),nCount,k,kk);
487 }
488 }
489 }
490
492 m_pStream->WriteUChar( 0 );
493 return ((*m_pStream).GetError() == ERRCODE_NONE);
494}
495
496void ORTFImportExport::appendRow(OString const * pHorzChar,sal_Int32 _nColumnCount,sal_Int32& k,sal_Int32& kk)
497{
498 ++kk;
500 m_pStream->WriteOString("40");
502
503 static char const aCell2[] = "\\clbrdrl\\brdrs\\brdrcf2\\clbrdrt\\brdrs\\brdrcf2\\clbrdrb\\brdrs\\brdrcf2\\clbrdrr\\brdrs\\brdrcf2\\clshdng10000\\clcfpat1\\cellx";
504
505 for ( sal_Int32 i=1; i<=_nColumnCount; ++i )
506 {
507 m_pStream->WriteOString( aCell2 );
510 }
511
512 const bool bBold = ( css::awt::FontWeight::BOLD == m_aFont.Weight );
513 const bool bItalic = ( css::awt::FontSlant_ITALIC == m_aFont.Slant );
514 const bool bUnderline = ( css::awt::FontUnderline::NONE != m_aFont.Underline );
515 const bool bStrikeout = ( css::awt::FontStrikeout::NONE != m_aFont.Strikeout );
516 Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
517
518 m_pStream->WriteChar( '{' );
519 m_pStream->WriteOString( "\\trrh-270\\pard\\intbl" );
520 for ( sal_Int32 i=1; i <= _nColumnCount; ++i )
521 {
523 m_pStream->WriteChar( '{' );
524 m_pStream->WriteOString( pHorzChar[i-1] );
525
530
531 m_pStream->WriteOString( "\\fs20\\f1\\cf0\\cb1 " );
532
533 try
534 {
535 Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
536 dbtools::FormattedColumnValue aFormatedValue(m_xContext,xRowSet,xColumn);
537 OUString sValue = aFormatedValue.getFormattedValue();
538 if ( !sValue.isEmpty() )
540 }
541 catch (Exception&)
542 {
543 SAL_WARN("dbaccess.ui","RTF WRITE!");
544 }
545
547 m_pStream->WriteChar( '}' );
550 }
552 m_pStream->WriteChar( '}' );
553 ++k;
554}
555
557{
559 SvParserState eState = SvParserState::Error;
560 if ( m_pStream )
561 {
563 if ( isCheckEnabled() )
564 xReader->enableCheckOnly();
565 eState = xReader->CallParser();
566 }
567
568 return eState != SvParserState::Error;
569}
570
571const sal_Int16 OHTMLImportExport::nCellSpacing = 0;
572const 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";
573
577 : ODatabaseImportExport(_aDataDescriptor,_rM,_rxNumberF)
578 ,m_nIndent(0)
579#if OSL_DEBUG_LEVEL > 0
580 ,m_bCheckFont(false)
581#endif
582{
583 // set HTML configuration
584 m_eDestEnc = RTL_TEXTENCODING_UTF8;
585 strncpy( sIndent, sIndentSource ,std::min(sizeof(sIndent),sizeof(sIndentSource)));
586 sIndent[0] = 0;
587}
588
590{
592 if(m_xObject.is())
593 {
596 WriteHeader();
598 WriteBody();
601
602 return ((*m_pStream).GetError() == ERRCODE_NONE);
603 }
604 return false;
605}
606
608{
610 SvParserState eState = SvParserState::Error;
611 if ( m_pStream )
612 {
614 if ( isCheckEnabled() )
615 xReader->enableCheckOnly();
616 xReader->SetTableName(m_sDefaultTableName);
617 eState = xReader->CallParser();
618 }
619
620 return eState != SvParserState::Error;
621}
622
624{
625 uno::Reference<document::XDocumentProperties> xDocProps(
626 document::DocumentProperties::create( m_xContext ) );
627 if (xDocProps.is()) {
628 xDocProps->setTitle(m_sName);
629 }
630
631 IncIndent(1);
633
635 xDocProps, sIndent );
637 IncIndent(-1);
640}
641
643{
644 IncIndent(1);
646
647 m_pStream->WriteOString( "<!-- " );
649 m_pStream->WriteOString( OOO_STRING_SVTOOLS_HTML_body ).WriteOString( " { " ).WriteOString( "font-family: " ).WriteChar( '"' ).WriteOString( OUStringToOString(m_aFont.Name, osl_getThreadTextEncoding()) ).WriteChar( '\"' );
650 // TODO : think about the encoding of the font name
651 m_pStream->WriteOString( "; " ).WriteOString( "font-size: " );
653 m_pStream->WriteChar( '}' );
654
656 m_pStream->WriteOString( " -->" );
657 IncIndent(-1);
661
662 // default Textcolour black
664 ::Color aColor;
665 if(m_xObject.is())
666 m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= aColor;
668
671
672 m_pStream->WriteChar( '>' );
674
675 WriteTables();
676
678}
679
681{
682 OString aStrOut = OOO_STRING_SVTOOLS_HTML_table
683 " "
685 "="
687
688 Sequence< OUString> aNames;
689 Reference<XNameAccess> xColumns;
690 bool bUseResultMetaData = false;
691 if(m_xObject.is())
692 {
693 Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
694 xColumns = xColSup->getColumns();
695 aNames = xColumns->getElementNames();
696 if ( !aNames.hasElements() )
697 {
698 sal_Int32 nCount = m_xResultSetMetaData->getColumnCount();
699 aNames.realloc(nCount);
700 auto aNamesRange = asNonConstRange(aNames);
701 for (sal_Int32 i= 0; i < nCount; ++i)
702 aNamesRange[i] = m_xResultSetMetaData->getColumnName(i+1);
703 bUseResultMetaData = true;
704 }
705 }
706
707 aStrOut += " "
709 "="
711 " "
713 "=" +
714 OString::number(nCellSpacing) +
715 " "
717 "=" +
718 OString::number(aNames.getLength()) +
719 " "
721 "=1";
722
723 IncIndent(1);
725
726 FontOn();
727
730
731 m_pStream->WriteOString( OUStringToOString(m_sName, osl_getThreadTextEncoding()) );
732 // TODO : think about the encoding of the name
735
736 FontOff();
738 // </FONT>
739
740 IncIndent(1);
742
743 IncIndent(1);
745
746 if(m_xObject.is())
747 {
748 std::unique_ptr<sal_Int32[]> pFormat(new sal_Int32[aNames.getLength()]);
749
750 std::unique_ptr<const char *[]> pHorJustify(new const char*[aNames.getLength()]);
751 std::unique_ptr<sal_Int32[]> pColWidth(new sal_Int32[aNames.getLength()]);
752
753 sal_Int32 nHeight = 0;
754 m_xObject->getPropertyValue(PROPERTY_ROW_HEIGHT) >>= nHeight;
755
756 // 1. writing the column description
757 const OUString* pIter = aNames.getConstArray();
758 const OUString* pEnd = pIter + aNames.getLength();
759
760 for( sal_Int32 i=0;pIter != pEnd; ++pIter,++i )
761 {
762 sal_Int32 nAlign = 0;
763 pFormat[i] = 0;
764 pColWidth[i] = 100;
765 if ( !bUseResultMetaData )
766 {
768 xColumns->getByName(*pIter) >>= xColumn;
769 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
770 pFormat[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_FORMATKEY));
771 pColWidth[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_WIDTH));
772 }
773
774 switch( nAlign )
775 {
776 case 1: pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_center; break;
777 case 2: pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_right; break;
778 default: pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_left; break;
779 }
780
781 if(i == aNames.getLength()-1)
782 IncIndent(-1);
783
784 WriteCell(pFormat[i],pColWidth[i],nHeight,pHorJustify[i],*pIter,OOO_STRING_SVTOOLS_HTML_tableheader);
785 }
786
787 IncIndent(-1);
790
791 IncIndent(1);
793
794 // 2. and now the data
795 Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
796 m_xResultSet->beforeFirst(); // set back before the first row
797 while(m_xResultSet->next())
798 {
799 IncIndent(1);
801
802 for(sal_Int32 i=1;i<=aNames.getLength();++i)
803 {
804 if(i == aNames.getLength())
805 IncIndent(-1);
806
807 OUString aValue;
808 try
809 {
810 Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
811 dbtools::FormattedColumnValue aFormatedValue(m_xContext,xRowSet,xColumn);
812 OUString sValue = aFormatedValue.getFormattedValue();
813 if (!sValue.isEmpty())
814 {
815 aValue = sValue;
816 }
817 }
818 catch( const Exception& )
819 {
820 DBG_UNHANDLED_EXCEPTION("dbaccess");
821 }
822 WriteCell(pFormat[i-1],pColWidth[i-1],nHeight,pHorJustify[i-1],aValue,OOO_STRING_SVTOOLS_HTML_tabledata);
823 }
825 }
826 }
827 else
828 {
829 IncIndent(-1);
832
833 IncIndent(1);
835 }
836
837 IncIndent(-1);
840 IncIndent(-1);
842}
843
844void OHTMLImportExport::WriteCell( sal_Int32 nFormat, sal_Int32 nWidthPixel, sal_Int32 nHeightPixel, const char* pChar,
845 const OUString& rValue, const char* pHtmlTag)
846{
847 OString aStrTD = pHtmlTag;
848
849 nWidthPixel = nWidthPixel ? nWidthPixel : 86;
850 nHeightPixel = nHeightPixel ? nHeightPixel : 17;
851
852 // despite the <TABLE COLS=n> and <COL WIDTH=x> designation necessary,
853 // as Netscape is not paying attention to them.
854 // column width
855 aStrTD += " "
857 "=" +
858 OString::number(nWidthPixel) +
859 // line height
860 " "
862 "=" +
863 OString::number(nHeightPixel) +
864 " "
866 "=" +
867 pChar;
868
869 SvNumberFormatsSupplierObj* pSupplierImpl = m_xFormatter.is() ? comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(m_xFormatter->getNumberFormatsSupplier()) : nullptr;
870 SvNumberFormatter* pFormatter = pSupplierImpl ? pSupplierImpl->GetNumberFormatter() : nullptr;
871 if(pFormatter)
872 {
873 double fVal = 0.0;
874
875 try
876 {
877 fVal = m_xFormatter->convertStringToNumber(nFormat,rValue);
878 HTMLOutFuncs::CreateTableDataOptionsValNum(false, fVal,nFormat, *pFormatter);
879 }
880 catch(const Exception&)
881 {
882 HTMLOutFuncs::CreateTableDataOptionsValNum(false, fVal,nFormat, *pFormatter);
883 }
884 }
885
887
888 FontOn();
889
890 bool bBold = ( css::awt::FontWeight::BOLD == m_aFont.Weight );
891 bool bItalic = ( css::awt::FontSlant_ITALIC == m_aFont.Slant );
892 bool bUnderline = ( css::awt::FontUnderline::NONE != m_aFont.Underline );
893 bool bStrikeout = ( css::awt::FontStrikeout::NONE != m_aFont.Strikeout );
894
899
900 if ( rValue.isEmpty() )
902 else
904
909
910 FontOff();
911
913}
914
916{
917#if OSL_DEBUG_LEVEL > 0
918 m_bCheckFont = true;
919#endif
920
921 // <FONT FACE="xxx">
922 OString aStrOut = "<"
924 " "
926 "="
927 "\"" +
928 OUStringToOString(m_aFont.Name,osl_getThreadTextEncoding()) +
929 // TODO : think about the encoding of the font name
930 "\""
931 " "
933 "=";
934 m_pStream->WriteOString( aStrOut );
935
936 ::Color aColor;
937 if(m_xObject.is())
938 m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= aColor;
939
941 m_pStream->WriteOString( ">" );
942}
943
945{
946#if OSL_DEBUG_LEVEL > 0
947 OSL_ENSURE(m_bCheckFont,"No FontOn() called");
948#endif
950#if OSL_DEBUG_LEVEL > 0
951 m_bCheckFont = false;
952#endif
953}
954
955void OHTMLImportExport::IncIndent( sal_Int16 nVal )
956{
957 sIndent[m_nIndent] = '\t';
958 m_nIndent = m_nIndent + nVal;
959 if ( m_nIndent < 0 )
960 m_nIndent = 0;
961 else if ( m_nIndent > nIndentMax )
963 sIndent[m_nIndent] = 0;
964}
965
966/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CELL_X
Definition: TokenWriter.cxx:77
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
static void Out_DocInfo(SvStream &rStrm, const OUString &rBaseURL, const css::uno::Reference< css::document::XDocumentProperties > &, const char *pIndent, OUString *pNonConvertableChars=nullptr)
const vcl::Font & GetAppFont() const
SvNumberFormatter * GetNumberFormatter() const
SvStream & WriteNumberAsString(N n)
SvStream & WriteUChar(unsigned char nChar)
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteChar(char nChar)
static css::awt::FontDescriptor CreateFontDescriptor(const vcl::Font &rFont)
css::uno::Reference< css::container::XIndexAccess > m_xRowSetColumns
Definition: TokenWriter.hxx:63
css::uno::Sequence< css::uno::Any > m_aSelection
Definition: TokenWriter.hxx:53
void impl_initFromDescriptor(const svx::ODataAccessDescriptor &_aDataDescriptor, bool _bPlusDefaultInit)
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet
Definition: TokenWriter.hxx:59
css::uno::Reference< css::sdbcx::XRowLocate > m_xRowLocate
Definition: TokenWriter.hxx:61
css::awt::FontDescriptor m_aFont
Definition: TokenWriter.hxx:56
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xResultSetMetaData
Definition: TokenWriter.hxx:62
rtl_TextEncoding m_eDestEnc
Definition: TokenWriter.hxx:76
SharedConnection m_xConnection
Definition: TokenWriter.hxx:58
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
css::uno::Reference< css::util::XNumberFormatter > m_xFormatter
Definition: TokenWriter.hxx:64
css::uno::Reference< css::beans::XPropertySet > m_xObject
Definition: TokenWriter.hxx:57
css::uno::Reference< css::sdbc::XRow > m_xRow
Definition: TokenWriter.hxx:60
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: TokenWriter.hxx:65
char sIndent[nIndentMax+1]
void WriteCell(sal_Int32 nFormat, sal_Int32 nWidthPixel, sal_Int32 nHeightPixel, const char *pChar, const OUString &rValue, const char *pHtmlTag)
const char * GetIndentStr() const
OHTMLImportExport(const svx::ODataAccessDescriptor &_aDataDescriptor, const css::uno::Reference< css::uno::XComponentContext > &_rM, const css::uno::Reference< css::util::XNumberFormatter > &_rxNumberF)
void IncIndent(sal_Int16 nVal)
static const sal_Int16 nCellSpacing
static const char sIndentSource[]
virtual bool Read() override
virtual bool Write() override
virtual bool Read() override
virtual bool Write() override
void appendRow(OString const *pHorzChar, sal_Int32 _nColumnCount, sal_Int32 &k, sal_Int32 &kk)
OUString getFormattedValue() const
bool has(DataAccessDescriptorProperty _eWhich) const
OUString getDataSource() const
const css::uno::Reference< INTERFACE > & getTyped() const
void reset(const css::uno::Reference< INTERFACE > &_rxComponent, AssignmentMode _eMode=TakeOwnership)
const OUString & GetFamilyName() const
#define SAL_NEWLINE_STRING
Reference< XComponentContext > m_xContext
sal_Int32 m_nCommandType
int nCount
#define DBG_UNHANDLED_EXCEPTION(...)
#define ERRCODE_NONE
Reference< XColumn > xColumn
GtkMediaStream * m_pStream
#define OOO_STRING_SVTOOLS_HTML_O_height
#define OOO_STRING_SVTOOLS_HTML_head
#define OOO_STRING_SVTOOLS_HTML_body
#define OOO_STRING_SVTOOLS_HTML_O_color
#define OOO_STRING_SVTOOLS_HTML_AL_left
#define OOO_STRING_SVTOOLS_HTML_caption
#define OOO_STRING_SVTOOLS_HTML_frame
#define OOO_STRING_SVTOOLS_HTML_O_align
#define OOO_STRING_SVTOOLS_HTML_tabledata
#define OOO_STRING_SVTOOLS_HTML_strike
#define OOO_STRING_SVTOOLS_HTML_tablerow
#define OOO_STRING_SVTOOLS_HTML_TF_void
#define OOO_STRING_SVTOOLS_HTML_tableheader
#define OOO_STRING_SVTOOLS_HTML_style
#define OOO_STRING_SVTOOLS_HTML_html
#define OOO_STRING_SVTOOLS_HTML_bold
#define OOO_STRING_SVTOOLS_HTML_tbody
#define OOO_STRING_SVTOOLS_HTML_AL_center
#define OOO_STRING_SVTOOLS_HTML_O_text
#define OOO_STRING_SVTOOLS_HTML_O_cellspacing
#define OOO_STRING_SVTOOLS_HTML_O_cols
#define OOO_STRING_SVTOOLS_HTML_doctype
#define OOO_STRING_SVTOOLS_HTML_AL_right
#define OOO_STRING_SVTOOLS_HTML_doctype5
#define OOO_STRING_SVTOOLS_HTML_O_border
#define OOO_STRING_SVTOOLS_HTML_underline
#define OOO_STRING_SVTOOLS_HTML_thead
#define OOO_STRING_SVTOOLS_HTML_O_type
#define OOO_STRING_SVTOOLS_HTML_O_bgcolor
#define OOO_STRING_SVTOOLS_HTML_table
#define OOO_STRING_SVTOOLS_HTML_font
#define OOO_STRING_SVTOOLS_HTML_O_width
#define OOO_STRING_SVTOOLS_HTML_linebreak
#define OOO_STRING_SVTOOLS_HTML_italic
#define OOO_STRING_SVTOOLS_HTML_O_face
OUString aName
sal_uInt16 nPos
#define SAL_WARN(area, stream)
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
SVT_DLLPUBLIC SvStream & Out_String(SvStream &, std::u16string_view, rtl_TextEncoding eDestEnc=RTL_TEXTENCODING_MS_1252)
@ Exception
const sal_Int16 nIndentMax
::dbtools::SQLExceptionInfo createConnection(const OUString &_rsDataSourceName, const css::uno::Reference< css::container::XNameAccess > &_xDatabaseContext, const css::uno::Reference< css::uno::XComponentContext > &_rxContext, css::uno::Reference< css::lang::XEventListener > const &_rEvtLst, css::uno::Reference< css::sdbc::XConnection > &_rOUTConnection)
creates a new connection and appends the eventlistener
int i
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Reference< XConnection > m_xConnection
Definition: objectnames.cxx:79
#define OOO_STRING_SVTOOLS_RTF_CELL
#define OOO_STRING_SVTOOLS_RTF_ANSICPG
#define OOO_STRING_SVTOOLS_RTF_QC
#define OOO_STRING_SVTOOLS_RTF_RED
#define OOO_STRING_SVTOOLS_RTF_B
#define OOO_STRING_SVTOOLS_RTF_RTF
#define OOO_STRING_SVTOOLS_RTF_STRIKE
#define OOO_STRING_SVTOOLS_RTF_UL
#define OOO_STRING_SVTOOLS_RTF_QL
#define OOO_STRING_SVTOOLS_RTF_QR
#define OOO_STRING_SVTOOLS_RTF_BLUE
#define OOO_STRING_SVTOOLS_RTF_ROW
#define OOO_STRING_SVTOOLS_RTF_ANSI
#define OOO_STRING_SVTOOLS_RTF_INTBL
#define OOO_STRING_SVTOOLS_RTF_TROWD
#define OOO_STRING_SVTOOLS_RTF_TRGAPH
#define OOO_STRING_SVTOOLS_RTF_GREEN
#define OOO_STRING_SVTOOLS_RTF_COLORTBL
#define OOO_STRING_SVTOOLS_RTF_I
#define OOO_STRING_SVTOOLS_RTF_PARD
constexpr OUStringLiteral PROPERTY_WIDTH(u"Width")
constexpr OUStringLiteral PROPERTY_COMMAND(u"Command")
constexpr OUStringLiteral PROPERTY_TEXTCOLOR(u"TextColor")
constexpr OUStringLiteral PROPERTY_FORMATKEY(u"FormatKey")
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
constexpr OUStringLiteral PROPERTY_FONT(u"FontDescriptor")
constexpr OUStringLiteral PROPERTY_ALIGN(u"Align")
constexpr OUStringLiteral PROPERTY_ROW_HEIGHT(u"RowHeight")
constexpr OUStringLiteral PROPERTY_COMMAND_TYPE(u"CommandType")
static SVT_DLLPUBLIC SvStream & Out_AsciiTag(SvStream &, std::string_view rStr, bool bOn=true)
static SVT_DLLPUBLIC SvStream & Out_String(SvStream &, const OUString &, OUString *pNonConvertableChars=nullptr)
static SVT_DLLPUBLIC OString CreateTableDataOptionsValNum(bool bValue, double fVal, sal_uInt32 nFormat, SvNumberFormatter &rFormatter, OUString *pNonConvertableChars=nullptr)
static SVT_DLLPUBLIC SvStream & Out_Color(SvStream &, const Color &, bool bXHTML=false)
SvParserState
const char * pChar