1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "RtfReader.hxx"
30 #include <tools/debug.hxx>
31 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
32 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
33 #include <com/sun/star/sdbcx/XAppend.hpp>
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include <com/sun/star/awt/FontDescriptor.hpp>
37 #include <com/sun/star/awt/FontWeight.hpp>
38 #include <com/sun/star/awt/FontStrikeout.hpp>
39 #include <com/sun/star/awt/FontSlant.hpp>
40 #include <com/sun/star/awt/FontUnderline.hpp>
41 #include <com/sun/star/util/NumberFormat.hpp>
42 #include <com/sun/star/util/XNumberFormatTypes.hpp>
43 #include "dbustrings.hrc"
44 #include <svtools/rtftoken.h>
45 #include "dbu_misc.hrc"
46 #include <vcl/msgbox.hxx>
47 #include <connectivity/dbconversion.hxx>
48 #include <connectivity/dbtools.hxx>
49 #include <comphelper/extract.hxx>
50 #include <tools/color.hxx>
51 #include "WExtendPages.hxx"
52 #include "moduledbu.hxx"
53 #include "QEnumTypes.hxx"
54 #include "UITools.hxx"
55 #include <vcl/svapp.hxx>
56 #include <rtl/logfile.hxx>
58 using namespace dbaui
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::beans
;
61 using namespace ::com::sun::star::container
;
62 using namespace ::com::sun::star::sdbc
;
63 using namespace ::com::sun::star::sdbcx
;
64 using namespace ::com::sun::star::awt
;
67 // ==========================================================================
69 // ==========================================================================
70 ORTFReader::ORTFReader( SvStream
& rIn
,
71 const SharedConnection
& _rxConnection
,
72 const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxNumberF
,
73 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rM
,
74 const TColumnVector
* pList
,
75 const OTypeInfoMap
* _pInfoMap
)
77 ,ODatabaseExport( _rxConnection
, _rxNumberF
, _rM
, pList
, _pInfoMap
, rIn
)
79 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::ORTFReader" );
80 DBG_CTOR(ORTFReader
,NULL
);
81 m_bAppendFirstLine
= false;
83 // ---------------------------------------------------------------------------
84 ORTFReader::ORTFReader(SvStream
& rIn
,
86 const TPositions
&_rColumnPositions
,
87 const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxNumberF
,
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rM
,
89 const TColumnVector
* pList
,
90 const OTypeInfoMap
* _pInfoMap
,
91 sal_Bool _bAutoIncrementEnabled
)
93 ,ODatabaseExport( nRows
, _rColumnPositions
, _rxNumberF
, _rM
, pList
, _pInfoMap
, _bAutoIncrementEnabled
, rIn
)
95 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::ORTFReader" );
96 DBG_CTOR(ORTFReader
,NULL
);
97 m_bAppendFirstLine
= false;
99 // ---------------------------------------------------------------------------
100 ORTFReader::~ORTFReader()
102 DBG_DTOR(ORTFReader
,NULL
);
104 // ---------------------------------------------------------------------------
105 SvParserState
ORTFReader::CallParser()
107 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::CallParser" );
108 DBG_CHKTHIS(ORTFReader
,NULL
);
109 rInput
.Seek(STREAM_SEEK_TO_BEGIN
);
111 SvParserState eParseState
= SvRTFParser::CallParser();
112 SetColumnTypes(m_pColumnList
,m_pInfoMap
);
113 return m_bFoundTable
? eParseState
: SVPAR_ERROR
;
115 // ---------------------------------------------------------------------------
116 void ORTFReader::NextToken( int nToken
)
118 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::NextToken" );
119 DBG_CHKTHIS(ORTFReader
,NULL
);
120 if(m_bError
|| !m_nRows
) // falls Fehler oder keine Rows mehr zur "Uberpr"ufung dann gleich zur"uck
123 if(m_xConnection
.is()) // gibt an welcher CTOR gerufen wurde und damit, ob eine Tabelle erstellt werden soll
130 int nTmpToken2
= GetNextToken();
138 case RTF_RED
: aColor
.SetRed((sal_uInt8
)nTokenValue
); break;
139 case RTF_BLUE
: aColor
.SetBlue((sal_uInt8
)nTokenValue
); break;
140 case RTF_GREEN
: aColor
.SetGreen((sal_uInt8
)nTokenValue
); break;
143 nTmpToken2
= GetNextToken();
145 while(aToken
.GetChar(0) != ';' && eState
!= SVPAR_ERROR
&& eState
!= SVPAR_ACCEPTED
);
146 m_vecColor
.push_back(aColor
.GetRGBColor());
147 nTmpToken2
= GetNextToken();
149 while(nTmpToken2
== RTF_RED
&& eState
!= SVPAR_ERROR
&& eState
!= SVPAR_ACCEPTED
);
155 case RTF_LANG
: // Sprache abfragen
156 m_nDefToken
= (rtl_TextEncoding
)nTokenValue
;
160 bool bInsertRow
= true;
161 if ( !m_xTable
.is() ) // erste Zeile als Header verwenden
163 sal_uInt32 nTell
= rInput
.Tell(); // ver�ndert vielleicht die Position des Streams
165 m_bError
= !CreateTable(nToken
);
166 bInsertRow
= m_bAppendFirstLine
;
167 if ( m_bAppendFirstLine
)
173 if ( bInsertRow
&& !m_bError
)
177 m_pUpdateHelper
->moveToInsertRow(); // sonst neue Zeile anh"angen
179 catch(SQLException
& e
)
180 // UpdateFehlerbehandlung
193 m_bInTbl
= sal_True
; // jetzt befinden wir uns in einer Tabellenbeschreibung
197 if(m_bInTbl
) // wichtig, da wir sonst auch die Namen der Fonts bekommen
198 m_sTextToken
+= aToken
;
204 insertValueIntoColumn();
206 catch(SQLException
& e
)
207 // UpdateFehlerbehandlung
216 // es kann vorkommen, da� die letzte Celle nicht mit \cell abgeschlossen ist
219 insertValueIntoColumn();
221 if(m_bIsAutoIncrement
) // if bSetAutoIncrement then I have to set the autoincrement
222 m_pUpdateHelper
->updateInt(1,m_nRowCount
);
223 m_pUpdateHelper
->insertRow();
225 catch(SQLException
& e
)
226 //////////////////////////////////////////////////////////////////////
227 // UpdateFehlerbehandlung
235 else // Zweig nur f"ur Typpr"ufung g"ultig
240 // Der Spalten Kopf z"ahlt nicht mit
245 while(GetNextToken() != RTF_ROW
&& eState
!= SVPAR_ERROR
&& eState
!= SVPAR_ACCEPTED
);
255 m_sTextToken
+= aToken
;
269 // ---------------------------------------------------------------------------
270 sal_Bool
ORTFReader::CreateTable(int nToken
)
272 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::CreateTable" );
273 DBG_CHKTHIS(ORTFReader
,NULL
);
274 String
aTableName(ModuleRes(STR_TBL_TITLE
));
275 aTableName
= aTableName
.GetToken(0,' ');
276 aTableName
= String(::dbtools::createUniqueName(m_xTables
,::rtl::OUString(aTableName
)));
278 int nTmpToken2
= nToken
;
281 FontDescriptor aFont
= ::dbaui::CreateFontDescriptor(Application::GetSettings().GetStyleSettings().GetAppFont());
286 case RTF_UNKNOWNCONTROL
:
287 case RTF_UNKNOWNDATA
:
288 m_bInTbl
= sal_False
;
300 aColumnName
+= aToken
;
304 aColumnName
.EraseLeadingChars();
305 aColumnName
.EraseTrailingChars();
306 if (!aColumnName
.Len() || m_bAppendFirstLine
)
307 aColumnName
= String(ModuleRes(STR_COLUMN_NAME
));
309 CreateDefaultColumn(aColumnName
);
316 aFont
.Weight
= ::com::sun::star::awt::FontWeight::BOLD
;
319 aFont
.Slant
= ::com::sun::star::awt::FontSlant_ITALIC
;
322 aFont
.Underline
= ::com::sun::star::awt::FontUnderline::SINGLE
;
325 aFont
.Strikeout
= ::com::sun::star::awt::FontStrikeout::SINGLE
;
329 while((nTmpToken2
= GetNextToken()) != RTF_TROWD
&& eState
!= SVPAR_ERROR
&& eState
!= SVPAR_ACCEPTED
);
331 sal_Bool bOk
= !m_vDestVector
.empty();
334 if ( aColumnName
.Len() )
336 if ( m_bAppendFirstLine
)
337 aColumnName
= String(ModuleRes(STR_COLUMN_NAME
));
338 CreateDefaultColumn(aColumnName
);
341 m_bInTbl
= sal_False
;
342 m_bFoundTable
= sal_True
;
344 if ( isCheckEnabled() )
347 if(!m_vecColor
.empty())
348 aTextColor
<<= m_vecColor
[0];
350 bOk
= !executeWizard(aTableName
,aTextColor
,aFont
) && m_xTable
.is();
354 // -----------------------------------------------------------------------------
355 void ORTFReader::release()
357 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::release" );
358 DBG_CHKTHIS(ORTFReader
,NULL
);
362 // -----------------------------------------------------------------------------
363 TypeSelectionPageFactory
ORTFReader::getTypeSelectionPageFactory()
365 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "misc", "Ocke.Janssen@sun.com", "ORTFReader::getTypeSelectionPageFactory" );
366 DBG_CHKTHIS(ORTFReader
,NULL
);
367 return &OWizRTFExtend::Create
;
369 // -----------------------------------------------------------------------------
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */