summaryrefslogtreecommitdiff
path: root/svtools/source/svhtml
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2009-06-16 16:15:54 +0000
committerIvo Hinkelmann <ihi@openoffice.org>2009-06-16 16:15:54 +0000
commitff40d5a47de6525d580ac10d9009f91b358e1705 (patch)
tree9cf5478720e968e985197de67e9eaa531b63f3c1 /svtools/source/svhtml
parent38dddedf06c27bde422e0387047852daa0d06cb7 (diff)
CWS-TOOLING: integrate CWS fwk103
2009-05-26 12:44:25 +0200 mst r272292 : #i100727# - svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx: + fix warning: rename method to prevent overloading 2009-05-19 13:42:31 +0200 mav r272075 : #i101356# add comment 2009-05-19 10:56:24 +0200 mav r272062 : #i101356# register the singleton correctly 2009-05-19 10:25:42 +0200 mav r272060 : #i101356# register the singleton correctly 2009-05-18 12:48:48 +0200 mav r272013 : #i91306# fix the typo 2009-05-14 08:50:06 +0200 mav r271871 : #i101356# reduce the amount of macros 2009-05-13 13:26:08 +0200 mav r271858 : #i101356# reduce the amount of macros 2009-05-13 11:29:16 +0200 mav r271849 : #i101356# reduce the amount of macros 2009-05-12 12:09:42 +0200 mav r271815 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 12:03:20 +0200 mav r271814 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:58:48 +0200 mav r271813 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:53:05 +0200 mav r271812 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:48:36 +0200 mav r271810 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:43:45 +0200 mav r271809 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:39:38 +0200 mav r271808 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:37:38 +0200 mav r271806 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:33:58 +0200 mav r271805 : #i101356# allow to generate a small log if a document can not be stored 2009-05-12 11:30:01 +0200 mav r271804 : #i101356# allow to generate a small log if a document can not be stored 2009-05-06 17:43:38 +0200 mst r271607 : #i100727# - svtools/source/svhtml/parhtml.cxx: + adapt code to renaming of HTML constants (sb107) 2009-05-05 11:14:18 +0200 mav r271507 : #i101222# avoid warning 2009-05-05 10:27:23 +0200 mav r271505 : #i101426# send the modified() notification only when the document can be modified 2009-05-05 10:25:07 +0200 mav r271504 : #i101426# send the modified() notification only when the document is modified 2009-05-05 08:42:48 +0200 mav r271497 : CWS-TOOLING: rebase CWS fwk103 to trunk@271427 (milestone: DEV300:m47) 2009-04-30 13:32:11 +0200 mav r271412 : #i100518# check the template folders quietly 2009-04-29 20:04:25 +0200 mst r271393 : - sw/source/filter/html/swhtml.cxx: + fix wrong initialization order in constructor 2009-04-28 12:28:46 +0200 mav r271319 : #i99142# set the error correctly 2009-04-28 08:44:48 +0200 mav r271305 : #i99050# clear hidden flag if necessary 2009-04-28 08:40:10 +0200 mav r271304 : #i99050# avoid crash 2009-04-22 07:40:11 +0200 mav r271056 : #i101093# lets not affect the performance 2009-04-15 09:30:47 +0200 cd r270820 : #i99771# Fix warnings for gcc 4.4 2009-04-15 09:19:52 +0200 cd r270819 : #i99771# Fix warnings for gcc 4.4 2009-04-15 08:42:34 +0200 cd r270817 : #i99771# Fix warnings for gcc 4.4 2009-04-14 14:31:01 +0200 mav r270768 : #i99493# fix typo 2009-04-01 12:45:43 +0200 mst r270317 : fix #i100727# - svtools/inc/svtools/svparser.hxx, svtools/source/svrtf/svparser.cxx, sfx2/inc/sfx2/docfile.hxx, sfx2/source/doc/{objmisc.cxx,docfile.cxx}: + move SvKeyValue stuff from sfx2 to svtools - svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx, sfx2/inc/sfx2/sfxhtml.hxx, sfx2/source/bastyp/sfxhtml.cxx: + move ParseMetaOptions() and GetEncodingByMIME() from SfxHTMLParser (sfx2) to HTMLParser (svtools) + make HTMLParser::ParseMetaOptions() a virtual function + HTMLParser::ParseMetaOptions() calls GetExtendedCompatibilityTextEncoding() + new template method HTMLParser::AddMetaUserDefined() - svtools/source/svhtml/makefile.mk: + enable exceptions for parhtml.cxx - dbaccess/source/ui/misc/HtmlReader.cxx, sc/source/filter/html/htmlpars.cxx: + remove encoding related code duplication - sw/source/filter/html/{swhtml{.hxx,.cxx},htmlfld.cxx}: + new SwHTMLParser::AddMetaUserDefined() for import of DOCINFO field subtypes INFO[1-4] + do not use DocumentInfo for import of DOCINFO field subtypes INFO[1-4] 2009-03-31 17:01:35 +0200 mav r270288 : #i91214# fix typo 2009-03-31 15:19:41 +0200 mav r270285 : #i100123# allow to turn OOo locking mechanics off 2009-03-31 15:00:36 +0200 mav r270284 : #i100123# allow to turn OOo locking mechanics off 2009-03-31 12:19:13 +0200 mav r270270 : #i100123# taking the lock file over throws no exception 2009-03-30 13:57:21 +0200 mav r270227 : #i100351# fix the typo 2009-03-30 13:47:26 +0200 mav r270225 : #i99885# let OK be default button 2009-03-29 19:38:55 +0200 mav r270190 : CWS-TOOLING: rebase CWS fwk103 to trunk@270033 (milestone: DEV300:m45) 2009-03-16 16:39:48 +0100 mav r269558 : #i93558# convert the attributes as well 2009-03-13 15:35:55 +0100 mav r269488 : #i93558# improve manifest.xml parsing 2009-03-13 08:47:00 +0100 mav r269454 : #i96205# allow to remove password on SaveAs 2009-03-12 13:36:07 +0100 mav r269398 : #i91306# show special error in case of shared document 2009-03-12 13:33:35 +0100 mav r269397 : #i91306# introduce the new error-message 2009-03-12 11:40:42 +0100 mst r269378 : fix #i90877# - svtools/source/uno/unoevent.cxx: + use proper operator delete[] 2009-02-26 15:23:10 +0100 mav r268526 : #i91214# do not use ATL 2009-02-26 14:19:06 +0100 mav r268516 : #i98909# integrate the patch 2009-02-10 17:29:52 +0100 cd r267568 : #i98649# Make sure that we catch the NoSuchElementException when a module is not installed.
Diffstat (limited to 'svtools/source/svhtml')
-rw-r--r--svtools/source/svhtml/makefile.mk2
-rw-r--r--svtools/source/svhtml/parhtml.cxx250
2 files changed, 251 insertions, 1 deletions
diff --git a/svtools/source/svhtml/makefile.mk b/svtools/source/svhtml/makefile.mk
index 577cc83e65c7..b597763ac390 100644
--- a/svtools/source/svhtml/makefile.mk
+++ b/svtools/source/svhtml/makefile.mk
@@ -34,6 +34,8 @@ PRJ=..$/..
PRJNAME=svtools
TARGET=svhtml
+ENABLE_EXCEPTIONS=TRUE
+
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index 3413cd3e7fb8..215133c8efb4 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -43,10 +43,21 @@
#include <svtools/svstdarr.hxx>
#endif
+#include <tools/tenccvt.hxx>
+#include <tools/datetime.hxx>
+#include <svtools/inettype.hxx>
+#include <comphelper/string.hxx>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
#include <svtools/parhtml.hxx>
#include "htmltokn.h"
#include "htmlkywd.hxx"
+
+using namespace ::com::sun::star;
+
+
const sal_Int32 MAX_LEN( 1024L );
//static sal_Unicode sTmpBuffer[ MAX_LEN+1 ];
const sal_Int32 MAX_MACRO_LEN( 1024 );
@@ -2080,7 +2091,6 @@ BOOL HTMLParser::InternalImgToPrivateURL( String& rURL )
return bFound;
}
-
#ifdef USED
void HTMLParser::SaveState( int nToken )
{
@@ -2093,3 +2103,241 @@ void HTMLParser::RestoreState()
}
#endif
+
+enum eHtmlMetas {
+ HTML_META_NONE = 0,
+ HTML_META_AUTHOR,
+ HTML_META_DESCRIPTION,
+ HTML_META_KEYWORDS,
+ HTML_META_REFRESH,
+ HTML_META_CLASSIFICATION,
+ HTML_META_CREATED,
+ HTML_META_CHANGEDBY,
+ HTML_META_CHANGED,
+ HTML_META_GENERATOR,
+ HTML_META_SDFOOTNOTE,
+ HTML_META_SDENDNOTE,
+ HTML_META_CONTENT_TYPE
+};
+
+// <META NAME=xxx>
+#ifdef __MINGW32__ // for runtime pseudo reloc
+static HTMLOptionEnum aHTMLMetaNameTable[] =
+#else
+static HTMLOptionEnum __READONLY_DATA aHTMLMetaNameTable[] =
+#endif
+{
+ { OOO_STRING_SVTOOLS_HTML_META_author, HTML_META_AUTHOR },
+ { OOO_STRING_SVTOOLS_HTML_META_changed, HTML_META_CHANGED },
+ { OOO_STRING_SVTOOLS_HTML_META_changedby, HTML_META_CHANGEDBY },
+ { OOO_STRING_SVTOOLS_HTML_META_classification,HTML_META_CLASSIFICATION},
+ { OOO_STRING_SVTOOLS_HTML_META_content_type, HTML_META_CONTENT_TYPE },
+ { OOO_STRING_SVTOOLS_HTML_META_created, HTML_META_CREATED },
+ { OOO_STRING_SVTOOLS_HTML_META_description, HTML_META_DESCRIPTION },
+ { OOO_STRING_SVTOOLS_HTML_META_keywords, HTML_META_KEYWORDS },
+ { OOO_STRING_SVTOOLS_HTML_META_generator, HTML_META_GENERATOR },
+ { OOO_STRING_SVTOOLS_HTML_META_refresh, HTML_META_REFRESH },
+ { OOO_STRING_SVTOOLS_HTML_META_sdendnote, HTML_META_SDENDNOTE },
+ { OOO_STRING_SVTOOLS_HTML_META_sdfootnote, HTML_META_SDFOOTNOTE },
+ { 0, 0 }
+};
+
+
+void HTMLParser::AddMetaUserDefined( ::rtl::OUString const & )
+{
+}
+
+bool HTMLParser::ParseMetaOptionsImpl(
+ const uno::Reference<document::XDocumentProperties> & i_xDocProps,
+ SvKeyValueIterator *i_pHTTPHeader,
+ const HTMLOptions *i_pOptions,
+ rtl_TextEncoding& o_rEnc )
+{
+ String aName, aContent;
+ USHORT nAction = HTML_META_NONE;
+ bool bHTTPEquiv = false, bChanged = false;
+
+ for ( USHORT i = i_pOptions->Count(); i; )
+ {
+ const HTMLOption *pOption = (*i_pOptions)[ --i ];
+ switch ( pOption->GetToken() )
+ {
+ case HTML_O_NAME:
+ aName = pOption->GetString();
+ if ( HTML_META_NONE==nAction )
+ {
+ pOption->GetEnum( nAction, aHTMLMetaNameTable );
+ }
+ break;
+ case HTML_O_HTTPEQUIV:
+ aName = pOption->GetString();
+ pOption->GetEnum( nAction, aHTMLMetaNameTable );
+ bHTTPEquiv = true;
+ break;
+ case HTML_O_CONTENT:
+ aContent = pOption->GetString();
+ break;
+ }
+ }
+
+ if ( bHTTPEquiv || HTML_META_DESCRIPTION != nAction )
+ {
+ // if it is not a Description, remove CRs and LFs from CONTENT
+ aContent.EraseAllChars( _CR );
+ aContent.EraseAllChars( _LF );
+ }
+ else
+ {
+ // convert line endings for Description
+ aContent.ConvertLineEnd();
+ }
+
+
+ if ( bHTTPEquiv && i_pHTTPHeader )
+ {
+ // #57232#: Netscape seems to just ignore a closing ", so we do too
+ if ( aContent.Len() && '"' == aContent.GetChar( aContent.Len()-1 ) )
+ {
+ aContent.Erase( aContent.Len() - 1 );
+ }
+ SvKeyValue aKeyValue( aName, aContent );
+ i_pHTTPHeader->Append( aKeyValue );
+ }
+
+ switch ( nAction )
+ {
+ case HTML_META_AUTHOR:
+ if (i_xDocProps.is()) {
+ i_xDocProps->setAuthor( aContent );
+ bChanged = true;
+ }
+ break;
+ case HTML_META_DESCRIPTION:
+ if (i_xDocProps.is()) {
+ i_xDocProps->setDescription( aContent );
+ bChanged = true;
+ }
+ break;
+ case HTML_META_KEYWORDS:
+ if (i_xDocProps.is()) {
+ i_xDocProps->setKeywords(
+ ::comphelper::string::convertCommaSeparated(aContent));
+ bChanged = true;
+ }
+ break;
+ case HTML_META_CLASSIFICATION:
+ if (i_xDocProps.is()) {
+ i_xDocProps->setSubject( aContent );
+ bChanged = true;
+ }
+ break;
+
+ case HTML_META_CHANGEDBY:
+ if (i_xDocProps.is()) {
+ i_xDocProps->setModifiedBy( aContent );
+ }
+ break;
+
+ case HTML_META_CREATED:
+ case HTML_META_CHANGED:
+ if ( i_xDocProps.is() && aContent.Len() &&
+ aContent.GetTokenCount() == 2 )
+ {
+ Date aDate( (ULONG)aContent.GetToken(0).ToInt32() );
+ Time aTime( (ULONG)aContent.GetToken(1).ToInt32() );
+ DateTime aDateTime( aDate, aTime );
+ ::util::DateTime uDT(aDateTime.Get100Sec(),
+ aDateTime.GetSec(), aDateTime.GetMin(),
+ aDateTime.GetHour(), aDateTime.GetDay(),
+ aDateTime.GetMonth(), aDateTime.GetYear());
+ if ( HTML_META_CREATED==nAction )
+ i_xDocProps->setCreationDate( uDT );
+ else
+ i_xDocProps->setModificationDate( uDT );
+ bChanged = true;
+ }
+ break;
+
+ case HTML_META_REFRESH:
+ DBG_ASSERT( !bHTTPEquiv || i_pHTTPHeader,
+ "Reload-URL aufgrund unterlassener MUSS-Aenderung verlorengegangen" );
+ break;
+
+ case HTML_META_CONTENT_TYPE:
+ if ( aContent.Len() )
+ {
+ o_rEnc = GetEncodingByMIME( aContent );
+ }
+ break;
+
+ case HTML_META_NONE:
+ if ( !bHTTPEquiv )
+ {
+ if (i_xDocProps.is())
+ {
+ uno::Reference<beans::XPropertyContainer> xUDProps
+ = i_xDocProps->getUserDefinedProperties();
+ try {
+ xUDProps->addProperty(aName,
+ beans::PropertyAttribute::REMOVEABLE,
+ uno::makeAny(::rtl::OUString(aContent)));
+ AddMetaUserDefined(aName);
+ bChanged = true;
+ } catch (uno::Exception &) {
+ // ignore
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return bChanged;
+}
+
+bool HTMLParser::ParseMetaOptions(
+ const uno::Reference<document::XDocumentProperties> & i_xDocProps,
+ SvKeyValueIterator *i_pHeader )
+{
+ USHORT nContentOption = HTML_O_CONTENT;
+ rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
+
+ bool bRet = ParseMetaOptionsImpl( i_xDocProps, i_pHeader,
+ GetOptions(&nContentOption),
+ eEnc );
+
+ // If the encoding is set by a META tag, it may only overwrite the
+ // current encoding if both, the current and the new encoding, are 1-BYTE
+ // encodings. Everything else cannot lead to reasonable results.
+ if (RTL_TEXTENCODING_DONTKNOW != eEnc &&
+ rtl_isOctetTextEncoding( eEnc ) &&
+ rtl_isOctetTextEncoding( GetSrcEncoding() ) )
+ {
+ eEnc = GetExtendedCompatibilityTextEncoding( eEnc ); // #89973#
+ SetSrcEncoding( eEnc );
+ }
+
+ return bRet;
+}
+
+rtl_TextEncoding HTMLParser::GetEncodingByMIME( const String& rMime )
+{
+ ByteString sType;
+ ByteString sSubType;
+ INetContentTypeParameterList aParameters;
+ ByteString sMime( rMime, RTL_TEXTENCODING_ASCII_US );
+ if (INetContentTypes::parse(sMime, sType, sSubType, &aParameters))
+ {
+ const INetContentTypeParameter * pCharset
+ = aParameters.find("charset");
+ if (pCharset != 0)
+ {
+ ByteString sValue( pCharset->m_sValue, RTL_TEXTENCODING_ASCII_US );
+ return GetExtendedCompatibilityTextEncoding(
+ rtl_getTextEncodingFromMimeCharset( sValue.GetBuffer() ) );
+ }
+ }
+ return RTL_TEXTENCODING_DONTKNOW;
+}
+