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
|
|
|
|
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
|
2017-03-02 12:20:07 +02:00
|
|
|
static HTMLOptionEnum<HTMLScriptLanguage> const aScriptLangOptEnums[] =
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-03-06 09:30:34 +02:00
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTMLScriptLanguage::StarBasic },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_javascript, HTMLScriptLanguage::JavaScript },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_javascript11, HTMLScriptLanguage::JavaScript },
|
|
|
|
{ OOO_STRING_SVTOOLS_HTML_LG_livescript, HTMLScriptLanguage::JavaScript },
|
2017-03-02 12:20:07 +02:00
|
|
|
{ nullptr, (HTMLScriptLanguage)0 }
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
2016-01-13 09:58:40 +02:00
|
|
|
void 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
|
|
|
|
2014-12-18 13:33:54 +01:00
|
|
|
rLangString.clear();
|
2017-03-06 09:30:34 +02:00
|
|
|
rLang = HTMLScriptLanguage::JavaScript;
|
2014-12-18 13:33:54 +01:00
|
|
|
rSrc.clear();
|
|
|
|
rLibrary.clear();
|
|
|
|
rModule.clear();
|
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
|
|
|
{
|
2014-09-29 15:27:46 +02:00
|
|
|
const HTMLOption& aOption = aScriptOptions[--i];
|
2011-07-22 15:39:18 -04:00
|
|
|
switch( aOption.GetToken() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-04-20 15:47:57 +02:00
|
|
|
case HtmlOptionId::LANGUAGE:
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-07-22 15:39:18 -04:00
|
|
|
rLangString = aOption.GetString();
|
2017-03-02 12:20:07 +02:00
|
|
|
HTMLScriptLanguage nLang;
|
2011-07-22 15:39:18 -04:00
|
|
|
if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
|
2017-03-20 09:01:33 +02:00
|
|
|
rLang = nLang;
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2017-03-06 09:30:34 +02:00
|
|
|
rLang = HTMLScriptLanguage::Unknown;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-04-20 15:47:57 +02:00
|
|
|
case HtmlOptionId::SRC:
|
2011-07-22 15:39:18 -04:00
|
|
|
rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
2017-04-20 15:47:57 +02:00
|
|
|
case HtmlOptionId::SDLIBRARY:
|
2011-07-22 15:39:18 -04:00
|
|
|
rLibrary = aOption.GetString();
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-20 15:47:57 +02:00
|
|
|
case HtmlOptionId::SDMODULE:
|
2011-07-22 15:39:18 -04:00
|
|
|
rModule = aOption.GetString();
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
2017-04-20 15:47:57 +02:00
|
|
|
default: break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 17:16:37 +02:00
|
|
|
void HTMLParser::RemoveSGMLComment( OUString &rString, 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 ) )
|
2017-07-11 11:04:35 +02:00
|
|
|
rString = rString.copy( 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-10-21 10:21:01 +02:00
|
|
|
if( 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;
|
2017-07-11 11:04:35 +02:00
|
|
|
rString = rString.copy( nPos );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 10:21:01 +02:00
|
|
|
if( 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: */
|