Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / bastyp / frmhtmlw.cxx
blobe822d9d7dc0dd3568fbd4c523d6e93170dba0573
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "svtools/htmlkywd.hxx"
22 #include <rtl/tencinfo.h>
24 #include <unotools/configmgr.hxx>
25 #include "svl/urihelper.hxx"
26 #include <tools/datetime.hxx>
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"
39 #include <comphelper/processfactory.hxx>
40 #include <comphelper/string.hxx>
42 #include <com/sun/star/script/Converter.hpp>
43 #include <com/sun/star/document/XDocumentProperties.hpp>
45 #include <rtl/bootstrap.hxx>
46 #include <rtl/strbuf.hxx>
49 // -----------------------------------------------------------------------
51 using namespace ::com::sun::star;
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=";
58 #if defined(UNX)
59 const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012";
60 #else
61 const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\015\012";
62 #endif
64 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 )
71 rStrm << sNewLine;
72 if( pIndent )
73 rStrm << pIndent;
75 OStringBuffer sOut;
76 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta).append(' ')
77 .append(bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
78 rStrm << sOut.makeStringAndClear().getStr();
80 HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars );
82 sOut.append("\" ").append(OOO_STRING_SVTOOLS_HTML_O_content).append("=\"");
83 rStrm << sOut.makeStringAndClear().getStr();
85 HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">";
88 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 )
94 const sal_Char *pCharSet =
95 rtl_getBestMimeCharsetFromTextEncoding( eDestEnc );
97 if( pCharSet )
99 String aContentType = OUString(sHTML_MIME_text_html);
100 aContentType.AppendAscii( pCharSet );
101 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, sal_True,
102 eDestEnc, pNonConvertableChars );
105 // Titel (auch wenn er leer ist)
106 rStrm << sNewLine;
107 if( pIndent )
108 rStrm << pIndent;
109 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title );
110 if( i_xDocProps.is() )
112 const String& rTitle = i_xDocProps->getTitle();
113 if( rTitle.Len() )
114 HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars );
116 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, sal_False );
118 // Target-Frame
119 if( i_xDocProps.is() )
121 const String& rTarget = i_xDocProps->getDefaultTarget();
122 if( rTarget.Len() )
124 rStrm << sNewLine;
125 if( pIndent )
126 rStrm << pIndent;
128 OStringBuffer sOut;
129 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_base).append(' ')
130 .append(OOO_STRING_SVTOOLS_HTML_O_target).append("=\"");
131 rStrm << sOut.makeStringAndClear().getStr();
132 HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars )
133 << "\">";
137 // Who we are
138 String sGenerator( SfxResId(STR_HTML_GENERATOR).toString() );
139 OUString os( "$_OS" );
140 ::rtl::Bootstrap::expandMacros(os);
141 sGenerator.SearchAndReplaceAscii( "%1", os );
142 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, sal_False, eDestEnc, pNonConvertableChars );
144 if( i_xDocProps.is() )
146 // Reload
147 if( (i_xDocProps->getAutoloadSecs() != 0) ||
148 !i_xDocProps->getAutoloadURL().isEmpty() )
150 String sContent = OUString::number(
151 i_xDocProps->getAutoloadSecs() );
153 const String &rReloadURL = i_xDocProps->getAutoloadURL();
154 if( rReloadURL.Len() )
156 sContent.AppendAscii( ";URL=" );
157 sContent += String(
158 URIHelper::simpleNormalizedMakeRelative(
159 rBaseURL, rReloadURL));
162 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, sal_True,
163 eDestEnc, pNonConvertableChars );
166 // Author
167 const String& rAuthor = i_xDocProps->getAuthor();
168 if( rAuthor.Len() )
169 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, sal_False,
170 eDestEnc, pNonConvertableChars );
172 // created
173 ::util::DateTime uDT = i_xDocProps->getCreationDate();
174 Date aD(uDT.Day, uDT.Month, uDT.Year);
175 Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
176 String sOut = OUString::number(aD.GetDate());
177 sOut += ';';
178 sOut += OUString::number(aT.GetTime());
179 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, sal_False,
180 eDestEnc, pNonConvertableChars );
182 // changedby
183 const String& rChangedBy = i_xDocProps->getModifiedBy();
184 if( rChangedBy.Len() )
185 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, sal_False,
186 eDestEnc, pNonConvertableChars );
188 // changed
189 uDT = i_xDocProps->getModificationDate();
190 Date aD2(uDT.Day, uDT.Month, uDT.Year);
191 Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
192 sOut = OUString::number(aD2.GetDate());
193 sOut += ';';
194 sOut += OUString::number(aT2.GetTime());
195 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, sal_False,
196 eDestEnc, pNonConvertableChars );
198 // Subject
199 const String& rTheme = i_xDocProps->getSubject();
200 if( rTheme.Len() )
201 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, sal_False,
202 eDestEnc, pNonConvertableChars );
204 // Description
205 const String& rComment = i_xDocProps->getDescription();
206 if( rComment.Len() )
207 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, sal_False,
208 eDestEnc, pNonConvertableChars);
210 // Keywords
211 String Keywords = ::comphelper::string::convertCommaSeparated(
212 i_xDocProps->getKeywords());
213 if( Keywords.Len() )
214 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, sal_False,
215 eDestEnc, pNonConvertableChars);
217 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(
218 ::comphelper::getProcessComponentContext() ) );
219 uno::Reference<beans::XPropertySet> xUserDefinedProps(
220 i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
221 DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
222 uno::Reference<beans::XPropertySetInfo> xPropInfo =
223 xUserDefinedProps->getPropertySetInfo();
224 DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
225 uno::Sequence<beans::Property> props = xPropInfo->getProperties();
226 for (sal_Int32 i = 0; i < props.getLength(); ++i)
230 OUString name = props[i].Name;
231 uno::Any aStr = xConverter->convertToSimpleType(
232 xUserDefinedProps->getPropertyValue(name),
233 uno::TypeClass_STRING);
234 OUString str;
235 aStr >>= str;
236 String valstr(comphelper::string::stripEnd(str, ' '));
237 OutMeta( rStrm, pIndent, name, valstr, sal_False,
238 eDestEnc, pNonConvertableChars );
240 catch (const uno::Exception&)
242 // may happen with concurrent modification...
243 DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
249 void SfxFrameHTMLWriter::Out_FrameDescriptor(
250 SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet,
251 rtl_TextEncoding eDestEnc, String *pNonConvertableChars )
255 OStringBuffer sOut;
256 OUString aStr;
257 uno::Any aAny = xSet->getPropertyValue( OUString("FrameURL") );
258 if ( (aAny >>= aStr) && !aStr.isEmpty() )
260 String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI );
261 if( aURL.Len() )
263 aURL = URIHelper::simpleNormalizedMakeRelative(
264 rBaseURL, aURL );
265 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_src)
266 .append(RTL_CONSTASCII_STRINGPARAM("=\""));
267 rOut << sOut.makeStringAndClear().getStr();
268 HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars );
269 sOut.append('\"');
273 aAny = xSet->getPropertyValue( OUString("FrameName") );
274 if ( (aAny >>= aStr) && !aStr.isEmpty() )
276 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name)
277 .append(RTL_CONSTASCII_STRINGPARAM("=\""));
278 rOut << sOut.makeStringAndClear().getStr();
279 HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars );
280 sOut.append('\"');
283 sal_Int32 nVal = SIZE_NOT_SET;
284 aAny = xSet->getPropertyValue( OUString("FrameMarginWidth") );
285 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
287 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginwidth)
288 .append('=').append(nVal);
290 aAny = xSet->getPropertyValue( OUString("FrameMarginHeight") );
291 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
293 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginheight)
294 .append('=').append(nVal);
297 sal_Bool bVal = sal_True;
298 aAny = xSet->getPropertyValue( OUString("FrameIsAutoScroll") );
299 if ( (aAny >>= bVal) && !bVal )
301 aAny = xSet->getPropertyValue( OUString("FrameIsScrollingMode") );
302 if ( aAny >>= bVal )
304 const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
305 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolling)
306 .append(pStr);
310 // frame border (MS+Netscape-Extension)
311 aAny = xSet->getPropertyValue( OUString("FrameIsAutoBorder") );
312 if ( (aAny >>= bVal) && !bVal )
314 aAny = xSet->getPropertyValue( OUString("FrameIsBorder") );
315 if ( aAny >>= bVal )
317 const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
318 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_frameborder)
319 .append('=').append(pStr);
322 rOut << sOut.getStr();
324 catch (const uno::Exception&)
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */