2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-15 17:28:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-09-17 14:26:47 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
2011-11-22 23:40:24 +00:00
|
|
|
#include <comphelper/string.hxx>
|
2007-06-27 21:00:38 +00:00
|
|
|
#include <svtools/parhtml.hxx>
|
2010-04-16 23:00:12 +02:00
|
|
|
#include <svtools/htmltokn.h>
|
|
|
|
#include <svtools/htmlkywd.hxx>
|
2011-11-22 23:40:24 +00:00
|
|
|
#include <tools/urlobj.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-05-06 21:34:07 +02:00
|
|
|
// Table for converting option values into strings
|
2010-12-12 10:14:17 +01:00
|
|
|
static HTMLOptionEnum const aScriptLangOptEnums[] =
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-04-27 11:24:10 +00:00
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_javascript, HTML_SL_JAVASCRIPT },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_livescript, HTML_SL_JAVASCRIPT },
|
2000-09-18 16:07:07 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-08-09 13:51:08 +02:00
|
|
|
bool HTMLParser::ParseScriptOptions( OUString& rLangString, const OUString& rBaseURL,
|
2000-09-18 16:07:07 +00:00
|
|
|
HTMLScriptLanguage& rLang,
|
2013-08-09 13:51:08 +02:00
|
|
|
OUString& rSrc,
|
|
|
|
OUString& rLibrary,
|
|
|
|
OUString& rModule )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-07-22 15:39:18 -04:00
|
|
|
const HTMLOptions& aScriptOptions = GetOptions();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-08-09 13:51:08 +02:00
|
|
|
rLangString = "";
|
2000-09-18 16:07:07 +00:00
|
|
|
rLang = HTML_SL_JAVASCRIPT;
|
2013-08-09 13:51:08 +02:00
|
|
|
rSrc = "";
|
|
|
|
rLibrary = "";
|
|
|
|
rModule = "";
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-07-22 15:39:18 -04:00
|
|
|
for( size_t i = aScriptOptions.size(); i; )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-07-22 15:39:18 -04:00
|
|
|
const HTMLOption& aOption = aScriptOptions[--i];
|
|
|
|
switch( aOption.GetToken() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
case HTML_O_LANGUAGE:
|
|
|
|
{
|
2011-07-22 15:39:18 -04:00
|
|
|
rLangString = aOption.GetString();
|
2010-11-05 10:31:15 +08:00
|
|
|
sal_uInt16 nLang;
|
2011-07-22 15:39:18 -04:00
|
|
|
if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
rLang = (HTMLScriptLanguage)nLang;
|
|
|
|
else
|
|
|
|
rLang = HTML_SL_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HTML_O_SRC:
|
2011-07-22 15:39:18 -04:00
|
|
|
rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
case HTML_O_SDLIBRARY:
|
2011-07-22 15:39:18 -04:00
|
|
|
rLibrary = aOption.GetString();
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HTML_O_SDMODULE:
|
2011-07-22 15:39:18 -04:00
|
|
|
rModule = aOption.GetString();
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 15:39:18 -04:00
|
|
|
return true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 13:51:08 +02:00
|
|
|
void HTMLParser::RemoveSGMLComment( OUString &rString, sal_Bool bFull )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-16 09:29:57 +00:00
|
|
|
sal_Unicode c = 0;
|
2013-08-09 13:51:08 +02:00
|
|
|
while( !rString.isEmpty() &&
|
|
|
|
( ' '==(c=rString[0]) || '\t'==c || '\r'==c || '\n'==c ) )
|
|
|
|
rString = rString.copy( 1, rString.getLength() - 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-08-09 13:51:08 +02:00
|
|
|
while( !rString.isEmpty() &&
|
|
|
|
( ' '==(c=rString[rString.getLength()-1])
|
2000-09-18 16:07:07 +00:00
|
|
|
|| '\t'==c || '\r'==c || '\n'==c ) )
|
2013-08-09 13:51:08 +02:00
|
|
|
rString = rString.copy( 0, rString.getLength()-1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
|
2011-05-06 21:34:07 +02:00
|
|
|
// remove SGML comments
|
2013-08-09 13:51:08 +02:00
|
|
|
if( rString.getLength() >= 4 &&
|
|
|
|
rString.startsWith( "<!--" ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-08-09 13:51:08 +02:00
|
|
|
sal_Int32 nPos = 3;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bFull )
|
|
|
|
{
|
2011-05-06 21:34:07 +02:00
|
|
|
// the whole line
|
2006-10-12 14:27:55 +00:00
|
|
|
nPos = 4;
|
2013-08-09 13:51:08 +02:00
|
|
|
while( nPos < rString.getLength() &&
|
|
|
|
( ( c = rString[nPos] ) != '\r' && c != '\n' ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
++nPos;
|
2013-08-09 13:51:08 +02:00
|
|
|
if( c == '\r' && nPos+1 < rString.getLength() &&
|
|
|
|
'\n' == rString[nPos+1] )
|
2000-09-18 16:07:07 +00:00
|
|
|
++nPos;
|
|
|
|
else if( c != '\n' )
|
2006-10-12 14:27:55 +00:00
|
|
|
nPos = 3;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2013-08-09 13:51:08 +02:00
|
|
|
++nPos;
|
|
|
|
rString = rString.copy( nPos, rString.getLength() - nPos );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 13:51:08 +02:00
|
|
|
if( rString.getLength() >=3 &&
|
|
|
|
rString.endsWith("-->") )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-08-09 13:51:08 +02:00
|
|
|
rString = rString.copy( 0, rString.getLength()-3 );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bFull )
|
|
|
|
{
|
2011-05-06 21:34:07 +02:00
|
|
|
// "//" or "'", maybe preceding CR/LF
|
2011-11-22 23:40:24 +00:00
|
|
|
rString = comphelper::string::stripEnd(rString, ' ');
|
2013-08-09 13:51:08 +02:00
|
|
|
sal_Int32 nDel = 0, nLen = rString.getLength();
|
2006-10-12 14:27:55 +00:00
|
|
|
if( nLen >= 2 &&
|
2013-08-09 13:51:08 +02:00
|
|
|
rString.endsWith("//") )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2006-10-12 14:27:55 +00:00
|
|
|
nDel = 2;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2013-08-09 13:51:08 +02:00
|
|
|
else if( nLen && '\'' == rString[nLen-1] )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2006-10-12 14:27:55 +00:00
|
|
|
nDel = 1;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2006-10-12 14:27:55 +00:00
|
|
|
if( nDel && nLen >= nDel+1 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-08-09 13:51:08 +02:00
|
|
|
c = rString[nLen-(nDel+1)];
|
2000-09-18 16:07:07 +00:00
|
|
|
if( '\r'==c || '\n'==c )
|
|
|
|
{
|
|
|
|
nDel++;
|
2006-10-12 14:27:55 +00:00
|
|
|
if( '\n'==c && nLen >= nDel+1 &&
|
2013-08-09 13:51:08 +02:00
|
|
|
'\r'==rString[nLen-(nDel+1)] )
|
2000-09-18 16:07:07 +00:00
|
|
|
nDel++;
|
|
|
|
}
|
|
|
|
}
|
2013-08-09 13:51:08 +02:00
|
|
|
rString = rString.copy( 0, nLen-nDel );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|