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