merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / svhtml / htmlsupp.cxx
blob0e6709cdcfaf7fdbe56dde377e91ba26d27b892a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlsupp.cxx,v $
10 * $Revision: 1.9 $
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_svtools.hxx"
34 #include <ctype.h>
35 #include <stdio.h>
36 #include <tools/urlobj.hxx>
37 #ifndef _SVSTDARR_HXX
38 #define _SVSTDARR_ULONGS
39 #include <svtools/svstdarr.hxx>
40 #endif
42 #include <svtools/parhtml.hxx>
43 #include "htmltokn.h"
44 #include "htmlkywd.hxx"
46 /* \f */
48 // Tabellen zum Umwandeln von Options-Werten in Strings
50 static HTMLOptionEnum __READONLY_DATA aScriptLangOptEnums[] =
52 { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC },
53 { OOO_STRING_SVTOOLS_HTML_LG_javascript, HTML_SL_JAVASCRIPT },
54 { OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT },
55 { OOO_STRING_SVTOOLS_HTML_LG_livescript, HTML_SL_JAVASCRIPT },
56 // { OOO_STRING_SVTOOLS_HTML_LG_unused_javascript, HTML_SL_UNUSEDJS },
57 // { OOO_STRING_SVTOOLS_HTML_LG_vbscript, HTML_SL_VBSCRIPT },
58 // { OOO_STRING_SVTOOLS_HTML_LG_starone, HTML_SL_STARONE },
59 { 0, 0 }
62 BOOL HTMLParser::ParseScriptOptions( String& rLangString, const String& rBaseURL,
63 HTMLScriptLanguage& rLang,
64 String& rSrc,
65 String& rLibrary,
66 String& rModule )
68 const HTMLOptions *pScriptOptions = GetOptions();
70 rLangString.Erase();
71 rLang = HTML_SL_JAVASCRIPT;
72 rSrc.Erase();
73 rLibrary.Erase();
74 rModule.Erase();
76 for( USHORT i = pScriptOptions->Count(); i; )
78 const HTMLOption *pOption = (*pScriptOptions)[ --i ];
79 switch( pOption->GetToken() )
81 case HTML_O_LANGUAGE:
83 rLangString = pOption->GetString();
84 USHORT nLang;
85 if( pOption->GetEnum( nLang, aScriptLangOptEnums ) )
86 rLang = (HTMLScriptLanguage)nLang;
87 else
88 rLang = HTML_SL_UNKNOWN;
90 break;
92 case HTML_O_SRC:
93 rSrc = INetURLObject::GetAbsURL( rBaseURL, pOption->GetString() );
94 break;
95 case HTML_O_SDLIBRARY:
96 rLibrary = pOption->GetString();
97 break;
99 case HTML_O_SDMODULE:
100 rModule = pOption->GetString();
101 break;
105 return TRUE;
108 void HTMLParser::RemoveSGMLComment( String &rString, BOOL bFull )
110 sal_Unicode c = 0;
111 while( rString.Len() &&
112 ( ' '==(c=rString.GetChar(0)) || '\t'==c || '\r'==c || '\n'==c ) )
113 rString.Erase( 0, 1 );
115 while( rString.Len() &&
116 ( ' '==(c=rString.GetChar( rString.Len()-1))
117 || '\t'==c || '\r'==c || '\n'==c ) )
118 rString.Erase( rString.Len()-1 );
121 // SGML-Kommentare entfernen
122 if( rString.Len() >= 4 &&
123 rString.CompareToAscii( "<!--", 4 ) == COMPARE_EQUAL )
125 xub_StrLen nPos = 3;
126 if( bFull )
128 // die gesamte Zeile !
129 nPos = 4;
130 while( nPos < rString.Len() &&
131 ( ( c = rString.GetChar( nPos )) != '\r' && c != '\n' ) )
132 ++nPos;
133 if( c == '\r' && nPos+1 < rString.Len() &&
134 '\n' == rString.GetChar( nPos+1 ))
135 ++nPos;
136 else if( c != '\n' )
137 nPos = 3;
139 rString.Erase( 0, ++nPos );
142 if( rString.Len() >=3 &&
143 rString.Copy(rString.Len()-3).CompareToAscii("-->")
144 == COMPARE_EQUAL )
146 rString.Erase( rString.Len()-3 );
147 if( bFull )
149 // auch noch ein "//" oder "'" und ggf CR/LF davor
150 rString.EraseTrailingChars();
151 xub_StrLen nDel = 0, nLen = rString.Len();
152 if( nLen >= 2 &&
153 rString.Copy(nLen-2).CompareToAscii("//") == COMPARE_EQUAL )
155 nDel = 2;
157 else if( nLen && '\'' == rString.GetChar(nLen-1) )
159 nDel = 1;
161 if( nDel && nLen >= nDel+1 )
163 c = rString.GetChar( nLen-(nDel+1) );
164 if( '\r'==c || '\n'==c )
166 nDel++;
167 if( '\n'==c && nLen >= nDel+1 &&
168 '\r'==rString.GetChar( nLen-(nDel+1) ) )
169 nDel++;
172 rString.Erase( nLen-nDel );