LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/bastyp - frmhtmlw.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 149 0.0 %
Date: 2012-12-27 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "svtools/htmlkywd.hxx"
      21             : 
      22             : #include <rtl/tencinfo.h>
      23             : 
      24             : #include <unotools/configmgr.hxx>
      25             : #include "svl/urihelper.hxx"
      26             : #include <tools/datetime.hxx>
      27             : 
      28             : #include <sfx2/frmhtmlw.hxx>
      29             : #include <sfx2/evntconf.hxx>
      30             : #include <sfx2/frame.hxx>
      31             : #include <sfx2/app.hxx>
      32             : #include <sfx2/viewfrm.hxx>
      33             : #include <sfx2/docfile.hxx>
      34             : #include "sfx2/sfxresid.hxx"
      35             : #include <sfx2/objsh.hxx>
      36             : #include <sfx2/sfx.hrc>
      37             : #include "bastyp.hrc"
      38             : 
      39             : #include <comphelper/processfactory.hxx>
      40             : #include <comphelper/string.hxx>
      41             : 
      42             : #include <com/sun/star/script/Converter.hpp>
      43             : #include <com/sun/star/document/XDocumentProperties.hpp>
      44             : 
      45             : #include <rtl/bootstrap.hxx>
      46             : #include <rtl/strbuf.hxx>
      47             : 
      48             : 
      49             : // -----------------------------------------------------------------------
      50             : 
      51             : using namespace ::com::sun::star;
      52             : 
      53             : static sal_Char const sHTML_SC_yes[] =  "YES";
      54             : static sal_Char const sHTML_SC_no[] =       "NO";
      55             : static sal_Char const sHTML_SC_auto[] = "AUTO";
      56             : static sal_Char const sHTML_MIME_text_html[] =  "text/html; charset=";
      57             : 
      58             : #if defined(UNX)
      59             : const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012";
      60             : #else
      61             : const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\015\012";
      62             : #endif
      63             : 
      64           0 : void SfxFrameHTMLWriter::OutMeta( SvStream& rStrm,
      65             :                                   const sal_Char *pIndent,
      66             :                                   const String& rName,
      67             :                                   const String& rContent, sal_Bool bHTTPEquiv,
      68             :                                      rtl_TextEncoding eDestEnc,
      69             :                                   String *pNonConvertableChars  )
      70             : {
      71           0 :     rStrm << sNewLine;
      72           0 :     if( pIndent )
      73           0 :         rStrm << pIndent;
      74             : 
      75           0 :     rtl::OStringBuffer sOut;
      76           0 :     sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta).append(' ')
      77           0 :         .append(bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
      78           0 :     rStrm << sOut.makeStringAndClear().getStr();
      79             : 
      80           0 :     HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars );
      81             : 
      82           0 :     sOut.append("\" ").append(OOO_STRING_SVTOOLS_HTML_O_content).append("=\"");
      83           0 :     rStrm << sOut.makeStringAndClear().getStr();
      84             : 
      85           0 :     HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">";
      86           0 : }
      87             : 
      88           0 : void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL,
      89             :         const uno::Reference<document::XDocumentProperties> & i_xDocProps,
      90             :         const sal_Char *pIndent,
      91             :         rtl_TextEncoding eDestEnc,
      92             :         String *pNonConvertableChars    )
      93             : {
      94             :     const sal_Char *pCharSet =
      95           0 :                 rtl_getBestMimeCharsetFromTextEncoding( eDestEnc );
      96             : 
      97           0 :     if( pCharSet )
      98             :     {
      99           0 :         String aContentType = rtl::OUString(sHTML_MIME_text_html);
     100           0 :         aContentType.AppendAscii( pCharSet );
     101             :         OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, sal_True,
     102           0 :                  eDestEnc, pNonConvertableChars );
     103             :     }
     104             : 
     105             :     // Titel (auch wenn er leer ist)
     106           0 :     rStrm << sNewLine;
     107           0 :     if( pIndent )
     108           0 :         rStrm << pIndent;
     109           0 :     HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title );
     110           0 :     if( i_xDocProps.is() )
     111             :     {
     112           0 :         const String& rTitle = i_xDocProps->getTitle();
     113           0 :         if( rTitle.Len() )
     114           0 :             HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars );
     115             :     }
     116           0 :     HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, sal_False );
     117             : 
     118             :     // Target-Frame
     119           0 :     if( i_xDocProps.is() )
     120             :     {
     121           0 :         const String& rTarget = i_xDocProps->getDefaultTarget();
     122           0 :         if( rTarget.Len() )
     123             :         {
     124           0 :             rStrm << sNewLine;
     125           0 :             if( pIndent )
     126           0 :                 rStrm << pIndent;
     127             : 
     128           0 :             rtl::OStringBuffer sOut;
     129           0 :             sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_base).append(' ')
     130           0 :                 .append(OOO_STRING_SVTOOLS_HTML_O_target).append("=\"");
     131           0 :             rStrm << sOut.makeStringAndClear().getStr();
     132           0 :             HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars )
     133           0 :                 << "\">";
     134           0 :         }
     135             :     }
     136             : 
     137             :     // Who we are
     138           0 :     String sGenerator( SfxResId(STR_HTML_GENERATOR).toString() );
     139           0 :     ::rtl::OUString os( "$_OS" );
     140           0 :     ::rtl::Bootstrap::expandMacros(os);
     141           0 :     sGenerator.SearchAndReplaceAscii( "%1", os );
     142           0 :     OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, sal_False, eDestEnc, pNonConvertableChars );
     143             : 
     144           0 :     if( i_xDocProps.is() )
     145             :     {
     146             :         // Reload
     147           0 :         if( (i_xDocProps->getAutoloadSecs() != 0) ||
     148           0 :             !i_xDocProps->getAutoloadURL().isEmpty() )
     149             :         {
     150             :             String sContent = String::CreateFromInt32(
     151           0 :                                 i_xDocProps->getAutoloadSecs() );
     152             : 
     153           0 :             const String &rReloadURL = i_xDocProps->getAutoloadURL();
     154           0 :             if( rReloadURL.Len() )
     155             :             {
     156           0 :                 sContent.AppendAscii( ";URL=" );
     157             :                 sContent += String(
     158             :                     URIHelper::simpleNormalizedMakeRelative(
     159           0 :                         rBaseURL, rReloadURL));
     160             :             }
     161             : 
     162             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, sal_True,
     163           0 :                      eDestEnc, pNonConvertableChars );
     164             :         }
     165             : 
     166             :         // Author
     167           0 :         const String& rAuthor = i_xDocProps->getAuthor();
     168           0 :         if( rAuthor.Len() )
     169             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, sal_False,
     170           0 :                      eDestEnc, pNonConvertableChars );
     171             : 
     172             :         // created
     173           0 :         ::util::DateTime uDT = i_xDocProps->getCreationDate();
     174           0 :         Date aD(uDT.Day, uDT.Month, uDT.Year);
     175           0 :         Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
     176           0 :         String sOut = String::CreateFromInt32(aD.GetDate());
     177           0 :         sOut += ';';
     178           0 :         sOut += String::CreateFromInt32(aT.GetTime());
     179             :         OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, sal_False,
     180           0 :                  eDestEnc, pNonConvertableChars );
     181             : 
     182             :         // changedby
     183           0 :         const String& rChangedBy = i_xDocProps->getModifiedBy();
     184           0 :         if( rChangedBy.Len() )
     185             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, sal_False,
     186           0 :                      eDestEnc, pNonConvertableChars );
     187             : 
     188             :         // changed
     189           0 :         uDT = i_xDocProps->getModificationDate();
     190           0 :         Date aD2(uDT.Day, uDT.Month, uDT.Year);
     191           0 :         Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
     192           0 :         sOut = String::CreateFromInt32(aD2.GetDate());
     193           0 :         sOut += ';';
     194           0 :         sOut += String::CreateFromInt32(aT2.GetTime());
     195             :         OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, sal_False,
     196           0 :                  eDestEnc, pNonConvertableChars );
     197             : 
     198             :         // Subject
     199           0 :         const String& rTheme = i_xDocProps->getSubject();
     200           0 :         if( rTheme.Len() )
     201             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, sal_False,
     202           0 :                      eDestEnc, pNonConvertableChars );
     203             : 
     204             :         // Description
     205           0 :         const String& rComment = i_xDocProps->getDescription();
     206           0 :         if( rComment.Len() )
     207             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, sal_False,
     208           0 :                      eDestEnc, pNonConvertableChars);
     209             : 
     210             :         // Keywords
     211             :         String Keywords = ::comphelper::string::convertCommaSeparated(
     212           0 :             i_xDocProps->getKeywords());
     213           0 :         if( Keywords.Len() )
     214             :             OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, sal_False,
     215           0 :                      eDestEnc, pNonConvertableChars);
     216             : 
     217             :         uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(
     218           0 :             ::comphelper::getProcessComponentContext() ) );
     219             :         uno::Reference<beans::XPropertySet> xUserDefinedProps(
     220           0 :             i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
     221             :         DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
     222             :         uno::Reference<beans::XPropertySetInfo> xPropInfo =
     223           0 :             xUserDefinedProps->getPropertySetInfo();
     224             :         DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
     225           0 :         uno::Sequence<beans::Property> props = xPropInfo->getProperties();
     226           0 :         for (sal_Int32 i = 0; i < props.getLength(); ++i)
     227             :         {
     228             :             try
     229             :             {
     230           0 :                 ::rtl::OUString name = props[i].Name;
     231           0 :                 uno::Any aStr = xConverter->convertToSimpleType(
     232           0 :                         xUserDefinedProps->getPropertyValue(name),
     233           0 :                         uno::TypeClass_STRING);
     234           0 :                 ::rtl::OUString str;
     235           0 :                 aStr >>= str;
     236           0 :                 String valstr(comphelper::string::stripEnd(str, ' '));
     237             :                 OutMeta( rStrm, pIndent, name, valstr, sal_False,
     238           0 :                          eDestEnc, pNonConvertableChars );
     239             :             }
     240           0 :             catch (const uno::Exception&)
     241             :             {
     242             :                 // may happen with concurrent modification...
     243             :                 DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
     244             :             }
     245           0 :         }
     246           0 :     }
     247           0 : }
     248             : 
     249           0 : void SfxFrameHTMLWriter::Out_FrameDescriptor(
     250             :     SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet,
     251             :     rtl_TextEncoding eDestEnc, String *pNonConvertableChars )
     252             : {
     253             :     try
     254             :     {
     255           0 :         rtl::OStringBuffer sOut;
     256           0 :         ::rtl::OUString aStr;
     257           0 :         uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString("FrameURL") );
     258           0 :         if ( (aAny >>= aStr) && !aStr.isEmpty() )
     259             :         {
     260           0 :             String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI );
     261           0 :             if( aURL.Len() )
     262             :             {
     263             :                 aURL = URIHelper::simpleNormalizedMakeRelative(
     264           0 :                     rBaseURL, aURL );
     265           0 :                 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_src)
     266           0 :                     .append(RTL_CONSTASCII_STRINGPARAM("=\""));
     267           0 :                 rOut << sOut.makeStringAndClear().getStr();
     268           0 :                 HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars );
     269           0 :                 sOut.append('\"');
     270           0 :             }
     271             :         }
     272             : 
     273           0 :         aAny = xSet->getPropertyValue( ::rtl::OUString("FrameName") );
     274           0 :         if ( (aAny >>= aStr) && !aStr.isEmpty() )
     275             :         {
     276           0 :             sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name)
     277           0 :                 .append(RTL_CONSTASCII_STRINGPARAM("=\""));
     278           0 :             rOut << sOut.makeStringAndClear().getStr();
     279           0 :             HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars );
     280           0 :             sOut.append('\"');
     281             :         }
     282             : 
     283           0 :         sal_Int32 nVal = SIZE_NOT_SET;
     284           0 :         aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginWidth") );
     285           0 :         if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
     286             :         {
     287           0 :             sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginwidth)
     288           0 :                 .append('=').append(nVal);
     289             :         }
     290           0 :         aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginHeight") );
     291           0 :         if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
     292             :         {
     293           0 :             sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginheight)
     294           0 :                 .append('=').append(nVal);
     295             :         }
     296             : 
     297           0 :         sal_Bool bVal = sal_True;
     298           0 :         aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoScroll") );
     299           0 :         if ( (aAny >>= bVal) && !bVal )
     300             :         {
     301           0 :             aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsScrollingMode") );
     302           0 :             if ( aAny >>= bVal )
     303             :             {
     304           0 :                 const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
     305           0 :                 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolling)
     306           0 :                     .append(pStr);
     307             :             }
     308             :         }
     309             : 
     310             :         // frame border (MS+Netscape-Extension)
     311           0 :         aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoBorder") );
     312           0 :         if ( (aAny >>= bVal) && !bVal )
     313             :         {
     314           0 :             aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsBorder") );
     315           0 :             if ( aAny >>= bVal )
     316             :             {
     317           0 :                 const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
     318           0 :                 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_frameborder)
     319           0 :                     .append('=').append(pStr);
     320             :             }
     321             :         }
     322           0 :         rOut << sOut.getStr();
     323             :     }
     324           0 :     catch (const uno::Exception&)
     325             :     {
     326             :     }
     327           0 : }
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10