LibreOffice Module sfx2 (master) 1
frmhtmlw.cxx
Go to the documentation of this file.
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#include <sal/log.hxx>
24
25#include <svl/urihelper.hxx>
26#include <tools/stream.hxx>
27#include <tools/debug.hxx>
28#include <unotools/resmgr.hxx>
29#include <svtools/htmlout.hxx>
30
31#include <sfx2/frmdescr.hxx>
32#include <sfx2/frmhtmlw.hxx>
33#include <strings.hxx>
34
36#include <comphelper/string.hxx>
37
38#include <com/sun/star/script/Converter.hpp>
39#include <com/sun/star/document/XDocumentProperties.hpp>
40#include <com/sun/star/beans/XPropertySet.hpp>
41
42#include <rtl/bootstrap.hxx>
43#include <rtl/strbuf.hxx>
45
46using namespace ::com::sun::star;
47
48char const sHTML_SC_yes[] = "YES";
49char const sHTML_SC_no[] = "NO";
50
52 const char *pIndent,
53 const OUString& rName,
54 const OUString& rContent,
55 bool bHTTPEquiv,
56 OUString *pNonConvertableChars )
57{
59 if( pIndent )
60 rStrm.WriteOString( pIndent );
61
62 OStringBuffer sOut;
63 sOut.append("<" OOO_STRING_SVTOOLS_HTML_meta " ")
64 .append(bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
65 rStrm.WriteOString( sOut );
66 sOut.setLength(0);
67
68 HTMLOutFuncs::Out_String( rStrm, rName, pNonConvertableChars );
69
70 sOut.append("\" " OOO_STRING_SVTOOLS_HTML_O_content "=\"");
71 rStrm.WriteOString( sOut );
72 sOut.setLength(0);
73
74 HTMLOutFuncs::Out_String( rStrm, rContent, pNonConvertableChars ).WriteOString( "\"/>" );
75}
76
77void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const OUString& rBaseURL,
78 const uno::Reference<document::XDocumentProperties> & i_xDocProps,
79 const char *pIndent,
80 OUString *pNonConvertableChars )
81{
82 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, "text/html; charset=utf-8", true,
83 pNonConvertableChars );
84
85 // Title (regardless if empty)
87 if( pIndent )
88 rStrm.WriteOString( pIndent );
90 if( i_xDocProps.is() )
91 {
92 const OUString& rTitle = i_xDocProps->getTitle();
93 if( !rTitle.isEmpty() )
94 HTMLOutFuncs::Out_String( rStrm, rTitle, pNonConvertableChars );
95 }
97
98 // Target-Frame
99 if( i_xDocProps.is() )
100 {
101 const OUString& rTarget = i_xDocProps->getDefaultTarget();
102 if( !rTarget.isEmpty() )
103 {
105 if( pIndent )
106 rStrm.WriteOString( pIndent );
107
110 HTMLOutFuncs::Out_String( rStrm, rTarget, pNonConvertableChars )
111 .WriteOString( "\">" );
112 }
113 }
114
115 // Who we are
117 OUString os( "$_OS" );
118 ::rtl::Bootstrap::expandMacros(os);
119 sGenerator = sGenerator.replaceFirst( "%1", os );
120 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, false, pNonConvertableChars );
121
122 if( !i_xDocProps.is() )
123 return;
124
125 // Reload
126 if( (i_xDocProps->getAutoloadSecs() != 0) ||
127 !i_xDocProps->getAutoloadURL().isEmpty() )
128 {
129 OUString sContent = OUString::number(
130 i_xDocProps->getAutoloadSecs() );
131
132 const OUString &rReloadURL = i_xDocProps->getAutoloadURL();
133 if( !rReloadURL.isEmpty() )
134 {
135 sContent += ";URL=" + URIHelper::simpleNormalizedMakeRelative(
136 rBaseURL, rReloadURL);
137 }
138
139 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, true,
140 pNonConvertableChars );
141 }
142
143 // Author
144 const OUString& rAuthor = i_xDocProps->getAuthor();
145 if( !rAuthor.isEmpty() )
146 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, false,
147 pNonConvertableChars );
148
149 // created
150 ::util::DateTime uDT = i_xDocProps->getCreationDate();
151 OUStringBuffer aBuffer;
153
154 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, aBuffer.makeStringAndClear(), false,
155 pNonConvertableChars );
156
157 // changedby
158 const OUString& rChangedBy = i_xDocProps->getModifiedBy();
159 if( !rChangedBy.isEmpty() )
160 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, false,
161 pNonConvertableChars );
162
163 // changed
164 uDT = i_xDocProps->getModificationDate();
166
167 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, aBuffer.makeStringAndClear(), false,
168 pNonConvertableChars );
169
170 // Subject
171 const OUString& rTheme = i_xDocProps->getSubject();
172 if( !rTheme.isEmpty() )
174 pNonConvertableChars );
175
176 // Description
177 const OUString& rComment = i_xDocProps->getDescription();
178 if( !rComment.isEmpty() )
179 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, false,
180 pNonConvertableChars);
181
182 // Keywords
183 OUString Keywords = ::comphelper::string::convertCommaSeparated(
184 i_xDocProps->getKeywords());
185 if( !Keywords.isEmpty() )
187 pNonConvertableChars);
188
189 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(
190 ::comphelper::getProcessComponentContext() ) );
191 uno::Reference<beans::XPropertySet> xUserDefinedProps(
192 i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
193 uno::Reference<beans::XPropertySetInfo> xPropInfo =
194 xUserDefinedProps->getPropertySetInfo();
195 DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
196 const uno::Sequence<beans::Property> props = xPropInfo->getProperties();
197 for (const auto& rProp : props)
198 {
199 try
200 {
201 OUString name = rProp.Name;
202 uno::Any aStr = xConverter->convertToSimpleType(
203 xUserDefinedProps->getPropertyValue(name),
204 uno::TypeClass_STRING);
205 OUString str;
206 aStr >>= str;
207 OUString valstr(comphelper::string::stripEnd(str, ' '));
208 OutMeta( rStrm, pIndent, name, valstr, false,
209 pNonConvertableChars );
210 }
211 catch (const uno::Exception&)
212 {
213 // may happen with concurrent modification...
214 SAL_INFO("sfx", "SfxFrameHTMLWriter::Out_DocInfo: exception");
215 }
216 }
217}
218
220 SvStream& rOut, const OUString& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet )
221{
222 try
223 {
224 OStringBuffer sOut;
225 OUString aStr;
226 uno::Any aAny = xSet->getPropertyValue("FrameURL");
227 if ( (aAny >>= aStr) && !aStr.isEmpty() )
228 {
230 if( !aURL.isEmpty() )
231 {
233 rBaseURL, aURL );
234 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_src "=\"");
235 rOut.WriteOString( sOut );
236 sOut.setLength(0);
238 sOut.append('\"');
239 }
240 }
241
242 aAny = xSet->getPropertyValue("FrameName");
243 if ( (aAny >>= aStr) && !aStr.isEmpty() )
244 {
245 sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_name "=\"");
246 rOut.WriteOString( sOut );
247 sOut.setLength(0);
249 sOut.append('\"');
250 }
251
252 sal_Int32 nVal = SIZE_NOT_SET;
253 aAny = xSet->getPropertyValue("FrameMarginWidth");
254 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
255 {
257 "=" + OString::number(nVal));
258 }
259 aAny = xSet->getPropertyValue("FrameMarginHeight");
260 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
261 {
263 "=" + OString::number(nVal));
264 }
265
266 bool bVal = true;
267 aAny = xSet->getPropertyValue("FrameIsAutoScroll");
268 if ( (aAny >>= bVal) && !bVal )
269 {
270 aAny = xSet->getPropertyValue("FrameIsScrollingMode");
271 if ( aAny >>= bVal )
272 {
273 const char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
274 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_scrolling) +
275 pStr);
276 }
277 }
278
279 // frame border (MS+Netscape-Extension)
280 aAny = xSet->getPropertyValue("FrameIsAutoBorder");
281 if ( (aAny >>= bVal) && !bVal )
282 {
283 aAny = xSet->getPropertyValue("FrameIsBorder");
284 if ( aAny >>= bVal )
285 {
286 const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
287 sOut.append(OString::Concat(" " OOO_STRING_SVTOOLS_HTML_O_frameborder
288 "=") + pStr);
289 }
290 }
291 rOut.WriteOString( sOut );
292 sOut.setLength(0);
293 }
294 catch (const uno::Exception&)
295 {
296 }
297}
298/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static void Out_DocInfo(SvStream &rStrm, const OUString &rBaseURL, const css::uno::Reference< css::document::XDocumentProperties > &, const char *pIndent, OUString *pNonConvertableChars=nullptr)
Definition: frmhtmlw.cxx:77
static void Out_FrameDescriptor(SvStream &, const OUString &rBaseURL, const css::uno::Reference< css::beans::XPropertySet > &xSet)
Definition: frmhtmlw.cxx:219
static SAL_DLLPRIVATE void OutMeta(SvStream &rStrm, const char *pIndent, const OUString &rName, const OUString &rContent, bool bHTTPEquiv, OUString *pNonConvertableChars=nullptr)
Definition: frmhtmlw.cxx:51
SvStream & WriteOString(std::string_view rStr)
static void convertTimeOrDateTime(OUStringBuffer &rBuffer, const css::util::DateTime &rDateTime)
#define SAL_NEWLINE_STRING
#define DBG_ASSERT(sCon, aError)
URL aURL
Reference< XTypeConverter > xConverter
FilterGroup & rTarget
#define SIZE_NOT_SET
Definition: frmdescr.hxx:46
char const sHTML_SC_no[]
Definition: frmhtmlw.cxx:49
char const sHTML_SC_yes[]
Definition: frmhtmlw.cxx:48
#define OOO_STRING_SVTOOLS_HTML_O_httpequiv
#define OOO_STRING_SVTOOLS_HTML_META_changed
#define OOO_STRING_SVTOOLS_HTML_meta
#define OOO_STRING_SVTOOLS_HTML_O_target
#define OOO_STRING_SVTOOLS_HTML_O_scrolling
#define OOO_STRING_SVTOOLS_HTML_title
#define OOO_STRING_SVTOOLS_HTML_META_created
#define OOO_STRING_SVTOOLS_HTML_META_refresh
#define OOO_STRING_SVTOOLS_HTML_O_marginwidth
#define OOO_STRING_SVTOOLS_HTML_O_src
#define OOO_STRING_SVTOOLS_HTML_O_marginheight
#define OOO_STRING_SVTOOLS_HTML_O_frameborder
#define OOO_STRING_SVTOOLS_HTML_base
#define OOO_STRING_SVTOOLS_HTML_O_content
#define OOO_STRING_SVTOOLS_HTML_META_keywords
#define OOO_STRING_SVTOOLS_HTML_META_description
#define OOO_STRING_SVTOOLS_HTML_META_author
#define OOO_STRING_SVTOOLS_HTML_META_changedby
#define OOO_STRING_SVTOOLS_HTML_O_name
#define OOO_STRING_SVTOOLS_HTML_META_content_type
#define OOO_STRING_SVTOOLS_HTML_META_classification
#define OOO_STRING_SVTOOLS_HTML_META_generator
const char * name
#define SAL_INFO(area, stream)
aStr
Definition: mgetempl.cxx:407
OUString ExpandVariables(const OUString &rString)
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
OString stripEnd(const OString &rIn, char c)
void SvStream & rStrm
dictionary props
constexpr OUStringLiteral STR_HTML_GENERATOR
Definition: strings.hxx:14
static SVT_DLLPUBLIC SvStream & Out_AsciiTag(SvStream &, std::string_view rStr, bool bOn=true)
static SVT_DLLPUBLIC SvStream & Out_String(SvStream &, const OUString &, OUString *pNonConvertableChars=nullptr)
std::unique_ptr< char[]> aBuffer