1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlbas.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
37 #include <sfx2/sfx.hrc>
39 #define _SVSTDARR_STRINGSSORTDTOR
40 #include <svtools/svstdarr.hxx>
41 #include <basic/sbx.hxx>
42 #include <basic/basmgr.hxx>
43 #include <basic/sbmod.hxx>
44 #include <sfx2/evntconf.hxx>
45 #include <sfx2/app.hxx>
46 #include <svtools/htmlout.hxx>
47 #include <svtools/htmltokn.h>
48 #include <svtools/htmlkywd.hxx>
51 #include <fmtornt.hxx>
56 #include "docufld.hxx"
57 #include "wrthtml.hxx"
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::container
;
66 static HTMLOutEvent __FAR_DATA aBodyEventTable
[] =
68 { OOO_STRING_SVTOOLS_HTML_O_SDonload
, OOO_STRING_SVTOOLS_HTML_O_onload
, SFX_EVENT_OPENDOC
},
69 { OOO_STRING_SVTOOLS_HTML_O_SDonunload
, OOO_STRING_SVTOOLS_HTML_O_onunload
, SFX_EVENT_PREPARECLOSEDOC
},
70 { OOO_STRING_SVTOOLS_HTML_O_SDonfocus
, OOO_STRING_SVTOOLS_HTML_O_onfocus
, SFX_EVENT_ACTIVATEDOC
},
71 { OOO_STRING_SVTOOLS_HTML_O_SDonblur
, OOO_STRING_SVTOOLS_HTML_O_onblur
, SFX_EVENT_DEACTIVATEDOC
},
76 void SwHTMLParser::NewScript()
78 ParseScriptOptions( aScriptType
, sBaseURL
, eScriptLang
, aScriptURL
,
79 aBasicLib
, aBasicModule
);
81 if( aScriptURL
.Len() )
83 // Den Inhalt des Script-Tags ignorieren
84 bIgnoreRawData
= TRUE
;
88 void SwHTMLParser::EndScript()
90 BOOL bInsIntoBasic
= FALSE
,
91 bInsSrcIntoFld
= FALSE
;
95 case HTML_SL_STARBASIC
:
99 bInsSrcIntoFld
= TRUE
;
103 bIgnoreRawData
= FALSE
;
104 aScriptSource
.ConvertLineEnd();
106 // MIB 23.5.97: SGML-Kommentare brauchen nicht mehr entfernt zu werden,
107 // weil JS das jetzt selber kann.
108 // RemoveSGMLComment( aScriptSource, TRUE );
110 // Ausser StarBasic und unbenutzem JavaScript jedes Script oder den
111 // Modulnamen in einem Feld merken merken
112 if( bInsSrcIntoFld
&& !bIgnoreHTMLComments
)
114 SwScriptFieldType
*pType
=
115 (SwScriptFieldType
*)pDoc
->GetSysFldType( RES_SCRIPTFLD
);
117 SwScriptField
aFld( pType
, aScriptType
,
118 aScriptURL
.Len() ? aScriptURL
: aScriptSource
,
119 aScriptURL
.Len()!=0 );
120 InsertAttr( SwFmtFld( aFld
) );
123 SwDocShell
*pDocSh
= pDoc
->GetDocShell();
124 if( aScriptSource
.Len() && pDocSh
&&
125 bInsIntoBasic
&& IsNewDoc() )
127 // Fuer JavaScript und StarBasic noch ein Basic-Modul anlegen
128 // Das Basic entfernt natuerlich weiterhin keine SGML-Kommentare
129 RemoveSGMLComment( aScriptSource
, TRUE
);
132 ::rtl::OUString aLibName
;
133 if( aBasicLib
.Len() )
134 aLibName
= aBasicLib
;
136 aLibName
= ::rtl::OUString::createFromAscii( "Standard" );
138 // get module library container
139 Reference
< script::XLibraryContainer
> xModLibContainer( pDocSh
->GetBasicContainer(), UNO_QUERY
);
141 if ( xModLibContainer
.is() )
143 Reference
< container::XNameContainer
> xModLib
;
144 if ( xModLibContainer
->hasByName( aLibName
) )
146 // get module library
147 Any aElement
= xModLibContainer
->getByName( aLibName
);
148 aElement
>>= xModLib
;
152 // create module library
153 xModLib
= xModLibContainer
->createLibrary( aLibName
);
158 if( !aBasicModule
.Len() )
160 // create module name
164 aBasicModule
.AssignAscii( "Modul" );
165 aBasicModule
+= String::CreateFromInt32( (sal_Int32
)(++nSBModuleCnt
) );
166 bFound
= xModLib
->hasByName( ::rtl::OUString( aBasicModule
) );
171 ::rtl::OUString
aModName( aBasicModule
);
172 if ( !xModLib
->hasByName( aModName
) )
175 aElement
<<= ::rtl::OUString( aScriptSource
);
176 xModLib
->insertByName( aModName
, aElement
);
181 // get dialog library container
182 Reference
< script::XLibraryContainer
> xDlgLibContainer( pDocSh
->GetDialogContainer(), UNO_QUERY
);
184 if ( xDlgLibContainer
.is() )
186 if ( !xDlgLibContainer
->hasByName( aLibName
) )
188 // create dialog library
189 xDlgLibContainer
->createLibrary( aLibName
);
194 aScriptSource
.Erase();
199 aBasicModule
.Erase();
202 void SwHTMLParser::AddScriptSource()
204 // Hier merken wir und nur ein par Strings
205 if( aToken
.Len() > 2 &&
206 (HTML_SL_STARBASIC
==eScriptLang
&& aToken
.GetChar( 0 ) == '\'') )
208 xub_StrLen nPos
= STRING_NOTFOUND
;
209 if( !aBasicLib
.Len() )
211 nPos
= aToken
.SearchAscii( OOO_STRING_SVTOOLS_HTML_SB_library
);
212 if( nPos
!= STRING_NOTFOUND
)
215 aToken
.Copy( nPos
+ sizeof(OOO_STRING_SVTOOLS_HTML_SB_library
) - 1 );
216 aBasicLib
.EraseLeadingChars().EraseTrailingChars();
220 if( !aBasicModule
.Len() && nPos
==STRING_NOTFOUND
)
222 nPos
= aToken
.SearchAscii( OOO_STRING_SVTOOLS_HTML_SB_module
);
223 if( nPos
!= STRING_NOTFOUND
)
226 aToken
.Copy( nPos
+ sizeof(OOO_STRING_SVTOOLS_HTML_SB_module
) - 1 );
227 aBasicModule
.EraseLeadingChars().EraseTrailingChars();
231 if( nPos
==STRING_NOTFOUND
)
233 if( aScriptSource
.Len() )
234 aScriptSource
+= '\n';
235 (aScriptSource
+= aToken
);
238 else if( aScriptSource
.Len() || aToken
.Len() )
240 // Leerzeilen am Anfang werden ignoriert
241 if( aScriptSource
.Len() )
243 aScriptSource
+= '\n';
247 // Wir stehen hinter dem CR/LF der Zeile davor
248 nScriptStartLineNr
= GetLineNr() - 1;
250 aScriptSource
+= aToken
;
254 void SwHTMLParser::InsertBasicDocEvent( USHORT nEvent
, const String
& rName
,
256 const String
& rScrType
)
258 ASSERT( rName
.Len(), "InsertBasicDocEvent() ohne Macro gerufen" );
262 SwDocShell
*pDocSh
= pDoc
->GetDocShell();
263 ASSERT( pDocSh
, "Wo ist die DocShell?" );
267 String
sEvent( rName
);
268 sEvent
.ConvertLineEnd();
270 if( EXTENDED_STYPE
== eScrType
)
271 sScriptType
= rScrType
;
273 SfxEventConfiguration
* pECfg
= SFX_APP()->GetEventConfig();
274 pECfg
->ConfigureEvent( nEvent
, SvxMacro( sEvent
, sScriptType
, eScrType
),
278 void SwHTMLWriter::OutBasic()
283 SFX_APP()->EnterBasicCall();
285 BasicManager
*pBasicMan
= pDoc
->GetDocShell()->GetBasicManager();
286 ASSERT( pBasicMan
, "Wo ist der Basic-Manager?" );
287 //JP 17.07.96: Bug 29538 - nur das DocumentBasic schreiben
288 if( !pBasicMan
|| pBasicMan
== SFX_APP()->GetBasicManager() )
290 SFX_APP()->LeaveBasicCall();
294 // und jetzt alle StarBasic-Module und alle unbenutzen JavaSrript-Module
296 for( USHORT i
=0; i
<pBasicMan
->GetLibCount(); i
++ )
298 StarBASIC
*pBasic
= pBasicMan
->GetLib( i
);
299 const String
& rLibName
= pBasic
->GetName();
301 SbxArray
*pModules
= pBasic
->GetModules();
302 for( USHORT j
=0; j
<pModules
->Count(); j
++ )
304 const SbModule
*pModule
= PTR_CAST( SbModule
, pModules
->Get(j
) );
305 ASSERT( pModule
, "Wo ist das Modul?" );
308 String::CreateFromAscii( SVX_MACRO_LANGUAGE_STARBASIC
) );
309 ScriptType eType
= STARBASIC
;
314 ByteString
sOut( '<' );
315 sOut
.Append( OOO_STRING_SVTOOLS_HTML_meta
);
317 sOut
.Append( OOO_STRING_SVTOOLS_HTML_O_httpequiv
);
318 sOut
.Append( "=\"" );
319 sOut
.Append( OOO_STRING_SVTOOLS_HTML_META_content_script_type
);
320 sOut
.Append( "\" " );
321 sOut
.Append( OOO_STRING_SVTOOLS_HTML_O_content
);
322 sOut
.Append( "=\"text/x-" );
323 Strm() << sOut
.GetBuffer();
324 // Entities aren't welcome here
325 ByteString
sLang8( sLang
, eDestEnc
);
326 Strm() << sLang8
.GetBuffer() << "\">";
329 const String
& rModName
= pModule
->GetName();
330 Strm() << SwHTMLWriter::sNewLine
; // nicht einruecken!
331 HTMLOutFuncs::OutScript( Strm(), GetBaseURL(), pModule
->GetSource(),
332 sLang
, eType
, aEmptyStr
,
333 &rLibName
, &rModName
,
334 eDestEnc
, &aNonConvertableCharacters
);
338 SFX_APP()->LeaveBasicCall();
342 void SwHTMLWriter::OutBasicBodyEvents()
344 SwDocShell
*pDocSh
= pDoc
->GetDocShell();
348 SfxEventConfiguration
* pECfg
= SFX_APP()->GetEventConfig();
349 ASSERT( pECfg
, "Wo ist die Event-Konfiguration?" );
353 SvxMacroTableDtor
*pMacTable
= pECfg
->GetDocEventTable( pDocSh
);
354 if( pMacTable
&& pMacTable
->Count() )
355 HTMLOutFuncs::Out_Events( Strm(), *pMacTable
, aBodyEventTable
,
356 bCfgStarBasic
, eDestEnc
, &aNonConvertableCharacters
);