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