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