1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #ifndef _INETDEF_HXX 32 #include <svl/inetdef.hxx> 33 #endif 34 #include "svtools/htmlkywd.hxx" 35 36 //!(dv) #include <chaos2/cntapi.hxx> 37 #include <rtl/tencinfo.h> 38 39 #include <unotools/configmgr.hxx> 40 #include "svl/urihelper.hxx" 41 #include <tools/datetime.hxx> 42 43 #include <sfx2/frmhtmlw.hxx> 44 #include <sfx2/evntconf.hxx> 45 #include <sfx2/frame.hxx> 46 #include <sfx2/app.hxx> 47 #include <sfx2/viewfrm.hxx> 48 #include <sfx2/docfile.hxx> 49 #include "sfx2/sfxresid.hxx" 50 #include <sfx2/objsh.hxx> 51 #include <sfx2/sfx.hrc> 52 #include "bastyp.hrc" 53 54 #include <comphelper/string.hxx> 55 #include <comphelper/processfactory.hxx> 56 57 #include <com/sun/star/script/XTypeConverter.hpp> 58 #include <com/sun/star/document/XDocumentProperties.hpp> 59 60 61 // ----------------------------------------------------------------------- 62 63 using namespace ::com::sun::star; 64 65 static sal_Char __READONLY_DATA sHTML_SC_yes[] = "YES"; 66 static sal_Char __READONLY_DATA sHTML_SC_no[] = "NO"; 67 static sal_Char __READONLY_DATA sHTML_SC_auto[] = "AUTO"; 68 static sal_Char __READONLY_DATA sHTML_MIME_text_html[] = "text/html; charset="; 69 70 /* not used anymore? 71 static HTMLOutEvent __FAR_DATA aFrameSetEventTable[] = 72 { 73 { sHTML_O_SDonload, sHTML_O_onload, SFX_EVENT_OPENDOC }, 74 { sHTML_O_SDonunload, sHTML_O_onunload, SFX_EVENT_PREPARECLOSEDOC }, 75 { sHTML_O_SDonfocus, sHTML_O_onfocus, SFX_EVENT_ACTIVATEDOC }, 76 { sHTML_O_SDonblur, sHTML_O_onblur, SFX_EVENT_DEACTIVATEDOC }, 77 { 0, 0, 0 } 78 }; 79 */ 80 81 #if defined(UNX) 82 const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012"; 83 #else 84 const sal_Char __FAR_DATA SfxFrameHTMLWriter::sNewLine[] = "\015\012"; 85 #endif 86 87 void SfxFrameHTMLWriter::OutMeta( SvStream& rStrm, 88 const sal_Char *pIndent, 89 const String& rName, 90 const String& rContent, sal_Bool bHTTPEquiv, 91 rtl_TextEncoding eDestEnc, 92 String *pNonConvertableChars ) 93 { 94 rStrm << sNewLine; 95 if( pIndent ) 96 rStrm << pIndent; 97 98 ByteString sOut( '<' ); 99 (((sOut += OOO_STRING_SVTOOLS_HTML_meta) += ' ') 100 += (bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name)) += "=\""; 101 rStrm << sOut.GetBuffer(); 102 103 HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars ); 104 105 ((sOut = "\" ") += OOO_STRING_SVTOOLS_HTML_O_content) += "=\""; 106 rStrm << sOut.GetBuffer(); 107 108 HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">"; 109 } 110 111 void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL, 112 const uno::Reference<document::XDocumentProperties> & i_xDocProps, 113 const sal_Char *pIndent, 114 rtl_TextEncoding eDestEnc, 115 String *pNonConvertableChars ) 116 { 117 const sal_Char *pCharSet = 118 rtl_getBestMimeCharsetFromTextEncoding( eDestEnc ); 119 120 if( pCharSet ) 121 { 122 String aContentType = String::CreateFromAscii( sHTML_MIME_text_html ); 123 aContentType.AppendAscii( pCharSet ); 124 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, sal_True, 125 eDestEnc, pNonConvertableChars ); 126 } 127 128 // Titel (auch wenn er leer ist) 129 rStrm << sNewLine; 130 if( pIndent ) 131 rStrm << pIndent; 132 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title ); 133 if( i_xDocProps.is() ) 134 { 135 const String& rTitle = i_xDocProps->getTitle(); 136 if( rTitle.Len() ) 137 HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars ); 138 } 139 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, sal_False ); 140 141 // Target-Frame 142 if( i_xDocProps.is() ) 143 { 144 const String& rTarget = i_xDocProps->getDefaultTarget(); 145 if( rTarget.Len() ) 146 { 147 rStrm << sNewLine; 148 if( pIndent ) 149 rStrm << pIndent; 150 151 ByteString sOut( '<' ); 152 (((sOut += OOO_STRING_SVTOOLS_HTML_base) += ' ') += OOO_STRING_SVTOOLS_HTML_O_target) += "=\""; 153 rStrm << sOut.GetBuffer(); 154 HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars ) 155 << "\">"; 156 } 157 } 158 159 // Who we are 160 String sGenerator( SfxResId( STR_HTML_GENERATOR ) ); 161 sGenerator.SearchAndReplaceAscii( "%1", String( DEFINE_CONST_UNICODE( TOOLS_INETDEF_OS ) ) ); 162 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, sal_False, eDestEnc, pNonConvertableChars ); 163 164 if( i_xDocProps.is() ) 165 { 166 // Reload 167 if( (i_xDocProps->getAutoloadSecs() != 0) || 168 !i_xDocProps->getAutoloadURL().equalsAscii("") ) 169 { 170 String sContent = String::CreateFromInt32( 171 i_xDocProps->getAutoloadSecs() ); 172 173 const String &rReloadURL = i_xDocProps->getAutoloadURL(); 174 if( rReloadURL.Len() ) 175 { 176 sContent.AppendAscii( ";URL=" ); 177 sContent += String( 178 URIHelper::simpleNormalizedMakeRelative( 179 rBaseURL, rReloadURL)); 180 } 181 182 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, sal_True, 183 eDestEnc, pNonConvertableChars ); 184 } 185 186 // Author 187 const String& rAuthor = i_xDocProps->getAuthor(); 188 if( rAuthor.Len() ) 189 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, sal_False, 190 eDestEnc, pNonConvertableChars ); 191 192 // created 193 ::util::DateTime uDT = i_xDocProps->getCreationDate(); 194 Date aD(uDT.Day, uDT.Month, uDT.Year); 195 Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 196 String sOut = String::CreateFromInt32(aD.GetDate()); 197 sOut += ';'; 198 sOut += String::CreateFromInt32(aT.GetTime()); 199 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, sal_False, 200 eDestEnc, pNonConvertableChars ); 201 202 // changedby 203 const String& rChangedBy = i_xDocProps->getModifiedBy(); 204 if( rChangedBy.Len() ) 205 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, sal_False, 206 eDestEnc, pNonConvertableChars ); 207 208 // changed 209 uDT = i_xDocProps->getModificationDate(); 210 Date aD2(uDT.Day, uDT.Month, uDT.Year); 211 Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 212 sOut = String::CreateFromInt32(aD2.GetDate()); 213 sOut += ';'; 214 sOut += String::CreateFromInt32(aT2.GetTime()); 215 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, sal_False, 216 eDestEnc, pNonConvertableChars ); 217 218 // Subject 219 const String& rTheme = i_xDocProps->getSubject(); 220 if( rTheme.Len() ) 221 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, sal_False, 222 eDestEnc, pNonConvertableChars ); 223 224 // Description 225 const String& rComment = i_xDocProps->getDescription(); 226 if( rComment.Len() ) 227 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, sal_False, 228 eDestEnc, pNonConvertableChars); 229 230 // Keywords 231 String Keywords = ::comphelper::string::convertCommaSeparated( 232 i_xDocProps->getKeywords()); 233 if( Keywords.Len() ) 234 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, sal_False, 235 eDestEnc, pNonConvertableChars); 236 237 uno::Reference < script::XTypeConverter > xConverter( 238 ::comphelper::getProcessServiceFactory()->createInstance( 239 ::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), 240 uno::UNO_QUERY_THROW ); 241 uno::Reference<beans::XPropertySet> xUserDefinedProps( 242 i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); 243 DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null"); 244 uno::Reference<beans::XPropertySetInfo> xPropInfo = 245 xUserDefinedProps->getPropertySetInfo(); 246 DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null"); 247 uno::Sequence<beans::Property> props = xPropInfo->getProperties(); 248 for (sal_Int32 i = 0; i < props.getLength(); ++i) { 249 try { 250 ::rtl::OUString name = props[i].Name; 251 ::rtl::OUString str; 252 uno::Any aStr = xConverter->convertToSimpleType( 253 xUserDefinedProps->getPropertyValue(name), 254 uno::TypeClass_STRING); 255 aStr >>= str; 256 String valstr(str); 257 valstr.EraseTrailingChars(); 258 OutMeta( rStrm, pIndent, name, valstr, sal_False, 259 eDestEnc, pNonConvertableChars ); 260 } catch (uno::Exception &) { 261 // may happen with concurrent modification... 262 DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception"); 263 } 264 } 265 } 266 } 267 /* 268 void SfxFrameHTMLWriter::OutHeader( rtl_TextEncoding eDestEnc ) 269 { 270 // <HTML> 271 // <HEAD> 272 // <TITLE>Titel</TITLE> 273 // </HEAD> 274 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_html ) << sNewLine; 275 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head ); 276 277 Out_DocInfo( Strm(), &pDoc->GetDocInfo(), "\t", eDestEnc ); 278 Strm() << sNewLine; 279 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head, sal_False ) << sNewLine; 280 281 //! OutScript(); // Hier fehlen noch die Scripten im Header 282 } 283 */ 284 285 void SfxFrameHTMLWriter::Out_FrameDescriptor( 286 SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet, 287 rtl_TextEncoding eDestEnc, String *pNonConvertableChars ) 288 { 289 try 290 { 291 ByteString sOut; 292 ::rtl::OUString aStr; 293 uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameURL") ); 294 if ( (aAny >>= aStr) && aStr.getLength() ) 295 { 296 String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI ); 297 if( aURL.Len() ) 298 { 299 aURL = URIHelper::simpleNormalizedMakeRelative( 300 rBaseURL, aURL ); 301 ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_src) += "=\""; 302 rOut << sOut.GetBuffer(); 303 HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars ); 304 sOut = '\"'; 305 } 306 } 307 308 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameName") ); 309 if ( (aAny >>= aStr) && aStr.getLength() ) 310 { 311 ((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_name) += "=\""; 312 rOut << sOut.GetBuffer(); 313 HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars ); 314 sOut = '\"'; 315 } 316 317 sal_Int32 nVal = SIZE_NOT_SET; 318 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth") ); 319 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET ) 320 (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginwidth) += '=') += ByteString::CreateFromInt32( nVal ); 321 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight") ); 322 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET ) 323 (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_marginheight) += '=') += ByteString::CreateFromInt32( nVal ); 324 325 sal_Bool bVal = sal_True; 326 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll") ); 327 if ( (aAny >>= bVal) && !bVal ) 328 { 329 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode") ); 330 if ( aAny >>= bVal ) 331 { 332 const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no; 333 (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_scrolling) += '=') += pStr; 334 } 335 } 336 337 // frame border (MS+Netscape-Erweiterung) 338 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder") ); 339 if ( (aAny >>= bVal) && !bVal ) 340 { 341 aAny = xSet->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder") ); 342 if ( aAny >>= bVal ) 343 { 344 const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no; 345 (((sOut += ' ') += OOO_STRING_SVTOOLS_HTML_O_frameborder) += '=') += pStr; 346 } 347 } 348 349 // TODO/LATER: currently not supported attributes 350 // resize 351 //if( !pFrame->IsResizable() ) 352 // (sOut += ' ') += sHTML_O_noresize; 353 // 354 //if ( pFrame->GetWallpaper() ) 355 //{ 356 // ((sOut += ' ') += sHTML_O_bordercolor) += '='; 357 // rOut << sOut.GetBuffer(); 358 // HTMLOutFuncs::Out_Color( rOut, pFrame->GetWallpaper()->GetColor(), eDestEnc ); 359 //} 360 //else 361 rOut << sOut.GetBuffer(); 362 } 363 catch ( uno::Exception& ) 364 { 365 } 366 } 367 368 String SfxFrameHTMLWriter::CreateURL( SfxFrame* pFrame ) 369 { 370 String aRet; 371 SfxObjectShell* pShell = pFrame->GetCurrentDocument(); 372 if( !aRet.Len() && pShell ) 373 { 374 aRet = pShell->GetMedium()->GetName(); 375 //!(dv) CntAnchor::ToPresentationURL( aRet ); 376 } 377 378 return aRet; 379 } 380 381 382