xref: /trunk/main/svtools/source/svhtml/htmlsupp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3) !
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <ctype.h>
32*cdf0e10cSrcweir #include <stdio.h>
33*cdf0e10cSrcweir #include <tools/urlobj.hxx>
34*cdf0e10cSrcweir #ifndef _SVSTDARR_HXX
35*cdf0e10cSrcweir #define _SVSTDARR_ULONGS
36*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <svtools/parhtml.hxx>
40*cdf0e10cSrcweir #include <svtools/htmltokn.h>
41*cdf0e10cSrcweir #include <svtools/htmlkywd.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /*  */
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // Tabellen zum Umwandeln von Options-Werten in Strings
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir static HTMLOptionEnum __READONLY_DATA aScriptLangOptEnums[] =
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC   },
50*cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_javascript,    HTML_SL_JAVASCRIPT  },
51*cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT    },
52*cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_livescript,    HTML_SL_JAVASCRIPT  },
53*cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_unused_javascript, HTML_SL_UNUSEDJS },
54*cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_vbscript,  HTML_SL_VBSCRIPT    },
55*cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_starone,       HTML_SL_STARONE     },
56*cdf0e10cSrcweir     { 0,                    0                   }
57*cdf0e10cSrcweir };
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir sal_Bool HTMLParser::ParseScriptOptions( String& rLangString, const String& rBaseURL,
60*cdf0e10cSrcweir                                      HTMLScriptLanguage& rLang,
61*cdf0e10cSrcweir                                      String& rSrc,
62*cdf0e10cSrcweir                                      String& rLibrary,
63*cdf0e10cSrcweir                                      String& rModule )
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     const HTMLOptions *pScriptOptions = GetOptions();
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     rLangString.Erase();
68*cdf0e10cSrcweir     rLang = HTML_SL_JAVASCRIPT;
69*cdf0e10cSrcweir     rSrc.Erase();
70*cdf0e10cSrcweir     rLibrary.Erase();
71*cdf0e10cSrcweir     rModule.Erase();
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     for( sal_uInt16 i = pScriptOptions->Count(); i; )
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         const HTMLOption *pOption = (*pScriptOptions)[ --i ];
76*cdf0e10cSrcweir         switch( pOption->GetToken() )
77*cdf0e10cSrcweir         {
78*cdf0e10cSrcweir         case HTML_O_LANGUAGE:
79*cdf0e10cSrcweir             {
80*cdf0e10cSrcweir                 rLangString = pOption->GetString();
81*cdf0e10cSrcweir                 sal_uInt16 nLang;
82*cdf0e10cSrcweir                 if( pOption->GetEnum( nLang, aScriptLangOptEnums ) )
83*cdf0e10cSrcweir                     rLang = (HTMLScriptLanguage)nLang;
84*cdf0e10cSrcweir                 else
85*cdf0e10cSrcweir                     rLang = HTML_SL_UNKNOWN;
86*cdf0e10cSrcweir             }
87*cdf0e10cSrcweir             break;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         case HTML_O_SRC:
90*cdf0e10cSrcweir             rSrc = INetURLObject::GetAbsURL( rBaseURL, pOption->GetString() );
91*cdf0e10cSrcweir             break;
92*cdf0e10cSrcweir         case HTML_O_SDLIBRARY:
93*cdf0e10cSrcweir             rLibrary = pOption->GetString();
94*cdf0e10cSrcweir             break;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         case HTML_O_SDMODULE:
97*cdf0e10cSrcweir             rModule = pOption->GetString();
98*cdf0e10cSrcweir             break;
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     return sal_True;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir void HTMLParser::RemoveSGMLComment( String &rString, sal_Bool bFull )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     sal_Unicode c = 0;
108*cdf0e10cSrcweir     while( rString.Len() &&
109*cdf0e10cSrcweir            ( ' '==(c=rString.GetChar(0)) || '\t'==c || '\r'==c || '\n'==c ) )
110*cdf0e10cSrcweir         rString.Erase( 0, 1 );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     while( rString.Len() &&
113*cdf0e10cSrcweir            ( ' '==(c=rString.GetChar( rString.Len()-1))
114*cdf0e10cSrcweir            || '\t'==c || '\r'==c || '\n'==c ) )
115*cdf0e10cSrcweir         rString.Erase( rString.Len()-1 );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // SGML-Kommentare entfernen
119*cdf0e10cSrcweir     if( rString.Len() >= 4 &&
120*cdf0e10cSrcweir         rString.CompareToAscii( "<!--", 4 ) == COMPARE_EQUAL )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         xub_StrLen nPos = 3;
123*cdf0e10cSrcweir         if( bFull )
124*cdf0e10cSrcweir         {
125*cdf0e10cSrcweir             // die gesamte Zeile !
126*cdf0e10cSrcweir             nPos = 4;
127*cdf0e10cSrcweir             while( nPos < rString.Len() &&
128*cdf0e10cSrcweir                 ( ( c = rString.GetChar( nPos )) != '\r' && c != '\n' ) )
129*cdf0e10cSrcweir                 ++nPos;
130*cdf0e10cSrcweir             if( c == '\r' && nPos+1 < rString.Len() &&
131*cdf0e10cSrcweir                 '\n' == rString.GetChar( nPos+1 ))
132*cdf0e10cSrcweir                 ++nPos;
133*cdf0e10cSrcweir             else if( c != '\n' )
134*cdf0e10cSrcweir                 nPos = 3;
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir         rString.Erase( 0, ++nPos );
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     if( rString.Len() >=3 &&
140*cdf0e10cSrcweir         rString.Copy(rString.Len()-3).CompareToAscii("-->")
141*cdf0e10cSrcweir             == COMPARE_EQUAL )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         rString.Erase( rString.Len()-3 );
144*cdf0e10cSrcweir         if( bFull )
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             // auch noch ein "//" oder "'" und ggf CR/LF davor
147*cdf0e10cSrcweir             rString.EraseTrailingChars();
148*cdf0e10cSrcweir             xub_StrLen nDel = 0, nLen = rString.Len();
149*cdf0e10cSrcweir             if( nLen >= 2 &&
150*cdf0e10cSrcweir                 rString.Copy(nLen-2).CompareToAscii("//") == COMPARE_EQUAL )
151*cdf0e10cSrcweir             {
152*cdf0e10cSrcweir                 nDel = 2;
153*cdf0e10cSrcweir             }
154*cdf0e10cSrcweir             else if( nLen && '\'' == rString.GetChar(nLen-1) )
155*cdf0e10cSrcweir             {
156*cdf0e10cSrcweir                 nDel = 1;
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir             if( nDel && nLen >= nDel+1 )
159*cdf0e10cSrcweir             {
160*cdf0e10cSrcweir                 c = rString.GetChar( nLen-(nDel+1) );
161*cdf0e10cSrcweir                 if( '\r'==c || '\n'==c )
162*cdf0e10cSrcweir                 {
163*cdf0e10cSrcweir                     nDel++;
164*cdf0e10cSrcweir                     if( '\n'==c && nLen >= nDel+1 &&
165*cdf0e10cSrcweir                         '\r'==rString.GetChar( nLen-(nDel+1) ) )
166*cdf0e10cSrcweir                         nDel++;
167*cdf0e10cSrcweir                 }
168*cdf0e10cSrcweir             }
169*cdf0e10cSrcweir             rString.Erase( nLen-nDel );
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174