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