xref: /trunk/main/svtools/source/svhtml/htmlsupp.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <ctype.h>
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir #include <tools/urlobj.hxx>
30cdf0e10cSrcweir #ifndef _SVSTDARR_HXX
31cdf0e10cSrcweir #define _SVSTDARR_ULONGS
32cdf0e10cSrcweir #include <svl/svstdarr.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <svtools/parhtml.hxx>
36cdf0e10cSrcweir #include <svtools/htmltokn.h>
37cdf0e10cSrcweir #include <svtools/htmlkywd.hxx>
38cdf0e10cSrcweir 
39*1dda6fa0Smseidel /* */
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // Tabellen zum Umwandeln von Options-Werten in Strings
42cdf0e10cSrcweir 
43cdf0e10cSrcweir static HTMLOptionEnum __READONLY_DATA aScriptLangOptEnums[] =
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC   },
46cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_javascript,    HTML_SL_JAVASCRIPT  },
47cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT    },
48cdf0e10cSrcweir     { OOO_STRING_SVTOOLS_HTML_LG_livescript,    HTML_SL_JAVASCRIPT  },
49cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_unused_javascript, HTML_SL_UNUSEDJS },
50cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_vbscript,  HTML_SL_VBSCRIPT    },
51cdf0e10cSrcweir //  { OOO_STRING_SVTOOLS_HTML_LG_starone,       HTML_SL_STARONE     },
52cdf0e10cSrcweir     { 0,                    0                   }
53cdf0e10cSrcweir };
54cdf0e10cSrcweir 
ParseScriptOptions(String & rLangString,const String & rBaseURL,HTMLScriptLanguage & rLang,String & rSrc,String & rLibrary,String & rModule)55cdf0e10cSrcweir sal_Bool HTMLParser::ParseScriptOptions( String& rLangString, const String& rBaseURL,
56cdf0e10cSrcweir                                      HTMLScriptLanguage& rLang,
57cdf0e10cSrcweir                                      String& rSrc,
58cdf0e10cSrcweir                                      String& rLibrary,
59cdf0e10cSrcweir                                      String& rModule )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     const HTMLOptions *pScriptOptions = GetOptions();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     rLangString.Erase();
64cdf0e10cSrcweir     rLang = HTML_SL_JAVASCRIPT;
65cdf0e10cSrcweir     rSrc.Erase();
66cdf0e10cSrcweir     rLibrary.Erase();
67cdf0e10cSrcweir     rModule.Erase();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     for( sal_uInt16 i = pScriptOptions->Count(); i; )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         const HTMLOption *pOption = (*pScriptOptions)[ --i ];
72cdf0e10cSrcweir         switch( pOption->GetToken() )
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir         case HTML_O_LANGUAGE:
75cdf0e10cSrcweir             {
76cdf0e10cSrcweir                 rLangString = pOption->GetString();
77cdf0e10cSrcweir                 sal_uInt16 nLang;
78cdf0e10cSrcweir                 if( pOption->GetEnum( nLang, aScriptLangOptEnums ) )
79cdf0e10cSrcweir                     rLang = (HTMLScriptLanguage)nLang;
80cdf0e10cSrcweir                 else
81cdf0e10cSrcweir                     rLang = HTML_SL_UNKNOWN;
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir             break;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         case HTML_O_SRC:
86cdf0e10cSrcweir             rSrc = INetURLObject::GetAbsURL( rBaseURL, pOption->GetString() );
87cdf0e10cSrcweir             break;
88cdf0e10cSrcweir         case HTML_O_SDLIBRARY:
89cdf0e10cSrcweir             rLibrary = pOption->GetString();
90cdf0e10cSrcweir             break;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         case HTML_O_SDMODULE:
93cdf0e10cSrcweir             rModule = pOption->GetString();
94cdf0e10cSrcweir             break;
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     return sal_True;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
RemoveSGMLComment(String & rString,sal_Bool bFull)101cdf0e10cSrcweir void HTMLParser::RemoveSGMLComment( String &rString, sal_Bool bFull )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     sal_Unicode c = 0;
104cdf0e10cSrcweir     while( rString.Len() &&
105cdf0e10cSrcweir            ( ' '==(c=rString.GetChar(0)) || '\t'==c || '\r'==c || '\n'==c ) )
106cdf0e10cSrcweir         rString.Erase( 0, 1 );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     while( rString.Len() &&
109cdf0e10cSrcweir            ( ' '==(c=rString.GetChar( rString.Len()-1))
110cdf0e10cSrcweir            || '\t'==c || '\r'==c || '\n'==c ) )
111cdf0e10cSrcweir         rString.Erase( rString.Len()-1 );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     // SGML-Kommentare entfernen
115cdf0e10cSrcweir     if( rString.Len() >= 4 &&
116cdf0e10cSrcweir         rString.CompareToAscii( "<!--", 4 ) == COMPARE_EQUAL )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         xub_StrLen nPos = 3;
119cdf0e10cSrcweir         if( bFull )
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             // die gesamte Zeile !
122cdf0e10cSrcweir             nPos = 4;
123cdf0e10cSrcweir             while( nPos < rString.Len() &&
124cdf0e10cSrcweir                 ( ( c = rString.GetChar( nPos )) != '\r' && c != '\n' ) )
125cdf0e10cSrcweir                 ++nPos;
126cdf0e10cSrcweir             if( c == '\r' && nPos+1 < rString.Len() &&
127cdf0e10cSrcweir                 '\n' == rString.GetChar( nPos+1 ))
128cdf0e10cSrcweir                 ++nPos;
129cdf0e10cSrcweir             else if( c != '\n' )
130cdf0e10cSrcweir                 nPos = 3;
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         rString.Erase( 0, ++nPos );
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     if( rString.Len() >=3 &&
136cdf0e10cSrcweir         rString.Copy(rString.Len()-3).CompareToAscii("-->")
137cdf0e10cSrcweir             == COMPARE_EQUAL )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         rString.Erase( rString.Len()-3 );
140cdf0e10cSrcweir         if( bFull )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             // auch noch ein "//" oder "'" und ggf CR/LF davor
143cdf0e10cSrcweir             rString.EraseTrailingChars();
144cdf0e10cSrcweir             xub_StrLen nDel = 0, nLen = rString.Len();
145cdf0e10cSrcweir             if( nLen >= 2 &&
146cdf0e10cSrcweir                 rString.Copy(nLen-2).CompareToAscii("//") == COMPARE_EQUAL )
147cdf0e10cSrcweir             {
148cdf0e10cSrcweir                 nDel = 2;
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir             else if( nLen && '\'' == rString.GetChar(nLen-1) )
151cdf0e10cSrcweir             {
152cdf0e10cSrcweir                 nDel = 1;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir             if( nDel && nLen >= nDel+1 )
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 c = rString.GetChar( nLen-(nDel+1) );
157cdf0e10cSrcweir                 if( '\r'==c || '\n'==c )
158cdf0e10cSrcweir                 {
159cdf0e10cSrcweir                     nDel++;
160cdf0e10cSrcweir                     if( '\n'==c && nLen >= nDel+1 &&
161cdf0e10cSrcweir                         '\r'==rString.GetChar( nLen-(nDel+1) ) )
162cdf0e10cSrcweir                         nDel++;
163cdf0e10cSrcweir                 }
164cdf0e10cSrcweir             }
165cdf0e10cSrcweir             rString.Erase( nLen-nDel );
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir }
169