Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : : #include <comphelper/string.hxx>
31 : : #include <rtl/strbuf.hxx>
32 : : #include <sfx2/sfx.hrc>
33 : : #include <basic/sbx.hxx>
34 : : #include <basic/basmgr.hxx>
35 : : #include <basic/sbmod.hxx>
36 : : #include <sfx2/evntconf.hxx>
37 : : #include <sfx2/app.hxx>
38 : : #include <svtools/htmlout.hxx>
39 : : #include <svtools/htmltokn.h>
40 : : #include <svtools/htmlkywd.hxx>
41 : :
42 : : #include <com/sun/star/document/XEventsSupplier.hpp>
43 : : #include <com/sun/star/uno/Reference.hxx>
44 : :
45 : : #include <fmtornt.hxx>
46 : : #include <fmtfld.hxx>
47 : :
48 : : #include "doc.hxx"
49 : : #include "docsh.hxx"
50 : : #include "docufld.hxx"
51 : : #include "wrthtml.hxx"
52 : : #include "swhtml.hxx"
53 : :
54 : :
55 : : using namespace ::com::sun::star;
56 : : using namespace ::com::sun::star::uno;
57 : : using namespace ::com::sun::star::container;
58 : :
59 : :
60 : : static HTMLOutEvent aBodyEventTable[] =
61 : : {
62 : : { OOO_STRING_SVTOOLS_HTML_O_SDonload, OOO_STRING_SVTOOLS_HTML_O_onload, SFX_EVENT_OPENDOC },
63 : : { OOO_STRING_SVTOOLS_HTML_O_SDonunload, OOO_STRING_SVTOOLS_HTML_O_onunload, SFX_EVENT_PREPARECLOSEDOC },
64 : : { OOO_STRING_SVTOOLS_HTML_O_SDonfocus, OOO_STRING_SVTOOLS_HTML_O_onfocus, SFX_EVENT_ACTIVATEDOC },
65 : : { OOO_STRING_SVTOOLS_HTML_O_SDonblur, OOO_STRING_SVTOOLS_HTML_O_onblur, SFX_EVENT_DEACTIVATEDOC },
66 : : { 0, 0, 0 }
67 : : };
68 : :
69 : :
70 : 0 : void SwHTMLParser::NewScript()
71 : : {
72 : : ParseScriptOptions( aScriptType, sBaseURL, eScriptLang, aScriptURL,
73 : 0 : aBasicLib, aBasicModule );
74 : :
75 [ # # ]: 0 : if( aScriptURL.Len() )
76 : : {
77 : : // Den Inhalt des Script-Tags ignorieren
78 : 0 : bIgnoreRawData = sal_True;
79 : : }
80 : 0 : }
81 : :
82 : 0 : void SwHTMLParser::EndScript()
83 : : {
84 : 0 : sal_Bool bInsIntoBasic = sal_False,
85 : 0 : bInsSrcIntoFld = sal_False;
86 : :
87 [ # # ]: 0 : switch( eScriptLang )
88 : : {
89 : : case HTML_SL_STARBASIC:
90 : 0 : bInsIntoBasic = sal_True;
91 : 0 : break;
92 : : default:
93 : 0 : bInsSrcIntoFld = sal_True;
94 : 0 : break;
95 : : }
96 : :
97 : 0 : bIgnoreRawData = sal_False;
98 [ # # ][ # # ]: 0 : aScriptSource = convertLineEnd(aScriptSource, GetSystemLineEnd());
99 : :
100 : : // Ausser StarBasic und unbenutzem JavaScript jedes Script oder den
101 : : // Modulnamen in einem Feld merken merken
102 [ # # ][ # # ]: 0 : if( bInsSrcIntoFld && !bIgnoreHTMLComments )
103 : : {
104 : : SwScriptFieldType *pType =
105 [ # # ]: 0 : (SwScriptFieldType*)pDoc->GetSysFldType( RES_SCRIPTFLD );
106 : :
107 : : SwScriptField aFld( pType, aScriptType,
108 : 0 : aScriptURL.Len() ? aScriptURL : aScriptSource,
109 [ # # ][ # # ]: 0 : aScriptURL.Len()!=0 );
110 [ # # ][ # # ]: 0 : InsertAttr( SwFmtFld( aFld ) );
[ # # ][ # # ]
111 : : }
112 : :
113 : 0 : SwDocShell *pDocSh = pDoc->GetDocShell();
114 [ # # ]: 0 : if( aScriptSource.Len() && pDocSh &&
[ # # # # ]
[ # # ][ # # ]
115 : 0 : bInsIntoBasic && IsNewDoc() )
116 : : {
117 : : // Fuer JavaScript und StarBasic noch ein Basic-Modul anlegen
118 : : // Das Basic entfernt natuerlich weiterhin keine SGML-Kommentare
119 [ # # ]: 0 : RemoveSGMLComment( aScriptSource, sal_True );
120 : :
121 : : // get library name
122 : 0 : ::rtl::OUString aLibName;
123 [ # # ]: 0 : if( aBasicLib.Len() )
124 [ # # ]: 0 : aLibName = aBasicLib;
125 : : else
126 [ # # ]: 0 : aLibName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard"));
127 : :
128 : : // get module library container
129 [ # # ][ # # ]: 0 : Reference< script::XLibraryContainer > xModLibContainer( pDocSh->GetBasicContainer(), UNO_QUERY );
130 : :
131 [ # # ]: 0 : if ( xModLibContainer.is() )
132 : : {
133 : 0 : Reference< container::XNameContainer > xModLib;
134 [ # # ][ # # ]: 0 : if ( xModLibContainer->hasByName( aLibName ) )
[ # # ]
135 : : {
136 : : // get module library
137 [ # # ][ # # ]: 0 : Any aElement = xModLibContainer->getByName( aLibName );
138 [ # # ]: 0 : aElement >>= xModLib;
139 : : }
140 : : else
141 : : {
142 : : // create module library
143 [ # # ][ # # ]: 0 : xModLib = xModLibContainer->createLibrary( aLibName );
[ # # ]
144 : : }
145 : :
146 [ # # ]: 0 : if ( xModLib.is() )
147 : : {
148 [ # # ]: 0 : if( !aBasicModule.Len() )
149 : : {
150 : : // create module name
151 : 0 : sal_Bool bFound = sal_True;
152 [ # # ]: 0 : while( bFound )
153 : : {
154 [ # # ]: 0 : aBasicModule.AssignAscii( "Modul" );
155 [ # # ][ # # ]: 0 : aBasicModule += String::CreateFromInt32( (sal_Int32)(++nSBModuleCnt) );
[ # # ]
156 [ # # ][ # # ]: 0 : bFound = xModLib->hasByName( ::rtl::OUString( aBasicModule ) );
[ # # ]
157 : : }
158 : : }
159 : :
160 : : // create module
161 [ # # ]: 0 : ::rtl::OUString aModName( aBasicModule );
162 [ # # ][ # # ]: 0 : if ( !xModLib->hasByName( aModName ) )
[ # # ]
163 : : {
164 : 0 : Any aElement;
165 [ # # ][ # # ]: 0 : aElement <<= ::rtl::OUString( aScriptSource );
166 [ # # ][ # # ]: 0 : xModLib->insertByName( aModName , aElement );
167 : 0 : }
168 : 0 : }
169 : : }
170 : :
171 : : // get dialog library container
172 [ # # ][ # # ]: 0 : Reference< script::XLibraryContainer > xDlgLibContainer( pDocSh->GetDialogContainer(), UNO_QUERY );
173 : :
174 [ # # ]: 0 : if ( xDlgLibContainer.is() )
175 : : {
176 [ # # ][ # # ]: 0 : if ( !xDlgLibContainer->hasByName( aLibName ) )
[ # # ]
177 : : {
178 : : // create dialog library
179 [ # # ][ # # ]: 0 : xDlgLibContainer->createLibrary( aLibName );
180 : : }
181 : 0 : }
182 : : }
183 : :
184 : 0 : aScriptSource.Erase();
185 : 0 : aScriptType.Erase();
186 : 0 : aScriptURL.Erase();
187 : :
188 : 0 : aBasicLib.Erase();
189 : 0 : aBasicModule.Erase();
190 : 0 : }
191 : :
192 : 0 : void SwHTMLParser::AddScriptSource()
193 : : {
194 : : // Hier merken wir und nur ein par Strings
195 [ # # ]: 0 : if( aToken.Len() > 2 &&
[ # # # # ]
[ # # ]
196 : 0 : (HTML_SL_STARBASIC==eScriptLang && aToken.GetChar( 0 ) == '\'') )
197 : : {
198 : 0 : xub_StrLen nPos = STRING_NOTFOUND;
199 [ # # ]: 0 : if( !aBasicLib.Len() )
200 : : {
201 : 0 : nPos = aToken.SearchAscii( OOO_STRING_SVTOOLS_HTML_SB_library );
202 [ # # ]: 0 : if( nPos != STRING_NOTFOUND )
203 : : {
204 : : aBasicLib =
205 [ # # ]: 0 : aToken.Copy( nPos + sizeof(OOO_STRING_SVTOOLS_HTML_SB_library) - 1 );
206 [ # # ][ # # ]: 0 : aBasicLib = comphelper::string::strip(aBasicLib, ' ');
207 : : }
208 : : }
209 : :
210 [ # # ][ # # ]: 0 : if( !aBasicModule.Len() && nPos==STRING_NOTFOUND )
[ # # ]
211 : : {
212 : 0 : nPos = aToken.SearchAscii( OOO_STRING_SVTOOLS_HTML_SB_module );
213 [ # # ]: 0 : if( nPos != STRING_NOTFOUND )
214 : : {
215 : : aBasicModule =
216 [ # # ]: 0 : aToken.Copy( nPos + sizeof(OOO_STRING_SVTOOLS_HTML_SB_module) - 1 );
217 [ # # ][ # # ]: 0 : aBasicModule = comphelper::string::strip(aBasicModule, ' ');
218 : : }
219 : : }
220 : :
221 [ # # ]: 0 : if( nPos==STRING_NOTFOUND )
222 : : {
223 [ # # ]: 0 : if( aScriptSource.Len() )
224 : 0 : aScriptSource += '\n';
225 : 0 : (aScriptSource += aToken);
226 : : }
227 : : }
228 [ # # ][ # # ]: 0 : else if( aScriptSource.Len() || aToken.Len() )
[ # # ]
229 : : {
230 : : // Leerzeilen am Anfang werden ignoriert
231 [ # # ]: 0 : if( aScriptSource.Len() )
232 : : {
233 : 0 : aScriptSource += '\n';
234 : : }
235 : : else
236 : : {
237 : : // Wir stehen hinter dem CR/LF der Zeile davor
238 : 0 : nScriptStartLineNr = GetLineNr() - 1;
239 : : }
240 : 0 : aScriptSource += aToken;
241 : : }
242 : 0 : }
243 : :
244 : 0 : void SwHTMLParser::InsertBasicDocEvent( rtl::OUString aEvent, const String& rName,
245 : : ScriptType eScrType,
246 : : const String& rScrType )
247 : : {
248 : : OSL_ENSURE( rName.Len(), "InsertBasicDocEvent() ohne Macro gerufen" );
249 [ # # ]: 0 : if( !rName.Len() )
250 : : return;
251 : :
252 : 0 : SwDocShell *pDocSh = pDoc->GetDocShell();
253 : : OSL_ENSURE( pDocSh, "Wo ist die DocShell?" );
254 [ # # ]: 0 : if( !pDocSh )
255 : : return;
256 : :
257 [ # # ][ # # ]: 0 : String sEvent(convertLineEnd(rName, GetSystemLineEnd()));
[ # # ]
258 [ # # ]: 0 : String sScriptType;
259 [ # # ]: 0 : if( EXTENDED_STYPE == eScrType )
260 [ # # ]: 0 : sScriptType = rScrType;
261 : :
262 : : SfxEventConfiguration::ConfigureEvent( aEvent, SvxMacro( sEvent, sScriptType, eScrType ),
263 [ # # ][ # # ]: 0 : pDocSh );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
264 : : }
265 : :
266 : 2 : void SwHTMLWriter::OutBasic()
267 : : {
268 : : #ifndef DISABLE_SCRIPTING
269 [ + - ]: 2 : if( !bCfgStarBasic )
270 : 2 : return;
271 : :
272 : 0 : BasicManager *pBasicMan = pDoc->GetDocShell()->GetBasicManager();
273 : : OSL_ENSURE( pBasicMan, "Wo ist der Basic-Manager?" );
274 : : // nur das DocumentBasic schreiben
275 [ # # ][ # # ]: 0 : if( !pBasicMan || pBasicMan == SFX_APP()->GetBasicManager() )
[ # # ]
276 : : {
277 : 0 : return;
278 : : }
279 : :
280 : : // und jetzt alle StarBasic-Module und alle unbenutzen JavaSrript-Module
281 : : // ausgeben
282 [ # # ]: 2 : for( sal_uInt16 i=0; i<pBasicMan->GetLibCount(); i++ )
283 : : {
284 : 0 : StarBASIC *pBasic = pBasicMan->GetLib( i );
285 : 0 : const String& rLibName = pBasic->GetName();
286 : :
287 : 0 : SbxArray *pModules = pBasic->GetModules();
288 [ # # ]: 0 : for( sal_uInt16 j=0; j<pModules->Count(); j++ )
289 : : {
290 [ # # ][ # # ]: 0 : const SbModule *pModule = PTR_CAST( SbModule, pModules->Get(j) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
291 : : OSL_ENSURE( pModule, "Wo ist das Modul?" );
292 : :
293 : 0 : rtl::OUString sLang(SVX_MACRO_LANGUAGE_STARBASIC);
294 : 0 : ScriptType eType = STARBASIC;
295 : :
296 [ # # ][ # # ]: 0 : if( 0==i && 0==j )
297 : : {
298 [ # # ]: 0 : OutNewLine();
299 : 0 : rtl::OStringBuffer sOut;
300 [ # # ][ # # ]: 0 : sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta)
301 [ # # ][ # # ]: 0 : .append(' ').append(OOO_STRING_SVTOOLS_HTML_O_httpequiv)
302 [ # # ]: 0 : .append("=\"")
303 [ # # ]: 0 : .append(OOO_STRING_SVTOOLS_HTML_META_content_script_type)
304 [ # # ][ # # ]: 0 : .append("\" ").append(OOO_STRING_SVTOOLS_HTML_O_content)
305 [ # # ]: 0 : .append("=\"text/x-");
306 [ # # ][ # # ]: 0 : Strm() << sOut.getStr();
307 : : // Entities aren't welcome here
308 [ # # ][ # # ]: 0 : Strm() << rtl::OUStringToOString(sLang, eDestEnc).getStr()
[ # # ]
309 [ # # ]: 0 : << "\">";
310 : : }
311 : :
312 [ # # ]: 0 : const String& rModName = pModule->GetName();
313 [ # # ][ # # ]: 0 : Strm() << SwHTMLWriter::sNewLine; // nicht einruecken!
314 [ # # ][ # # ]: 0 : HTMLOutFuncs::OutScript( Strm(), GetBaseURL(), pModule->GetSource(),
315 : : sLang, eType, aEmptyStr,
316 : : &rLibName, &rModName,
317 [ # # ][ # # ]: 0 : eDestEnc, &aNonConvertableCharacters );
[ # # ]
318 : 0 : }
319 : : }
320 : : #endif
321 : : }
322 : :
323 : : static const char* aEventNames[] =
324 : : {
325 : : "OnLoad", "OnPrepareUnload", "OnFocus", "OnUnfocus"
326 : : };
327 : :
328 : 2 : void SwHTMLWriter::OutBasicBodyEvents()
329 : : {
330 : 2 : SwDocShell *pDocSh = pDoc->GetDocShell();
331 [ + - ]: 2 : if( !pDocSh )
332 : 2 : return;
333 : :
334 [ + - ][ + - ]: 2 : SvxMacroTableDtor *pDocTable = new SvxMacroTableDtor;
335 : :
336 [ + - ][ + - ]: 2 : uno::Reference< document::XEventsSupplier > xSup( pDocSh->GetModel(), uno::UNO_QUERY );
337 [ + - ][ + - ]: 2 : uno::Reference < container::XNameReplace > xEvents = xSup->getEvents();
338 [ + + ]: 10 : for ( sal_Int32 i=0; i<4; i++ )
339 : : {
340 [ + - ][ + - ]: 8 : SvxMacro* pMacro = SfxEventConfiguration::ConvertToMacro( xEvents->getByName( ::rtl::OUString::createFromAscii(aEventNames[i]) ), pDocSh, sal_True );
[ + - ]
341 [ - + ]: 8 : if ( pMacro )
342 : : {
343 [ # # ]: 0 : pDocTable->Insert( aBodyEventTable[i].nEvent, *pMacro );
344 [ # # ][ # # ]: 0 : delete pMacro;
345 : : }
346 : : }
347 : :
348 [ + - ][ - + ]: 2 : if( pDocTable && !pDocTable->empty() )
[ - + ]
349 [ # # ]: 0 : HTMLOutFuncs::Out_Events( Strm(), *pDocTable, aBodyEventTable,
350 [ # # ]: 2 : bCfgStarBasic, eDestEnc, &aNonConvertableCharacters );
351 : : }
352 : :
353 : :
354 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|