Branch data 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/XTypeConverter.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 : 8 : 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 [ + - ]: 8 : rStrm << sNewLine;
72 [ + - ]: 8 : if( pIndent )
73 [ + - ]: 8 : rStrm << pIndent;
74 : :
75 : 8 : rtl::OStringBuffer sOut;
76 [ + - ][ + - ]: 8 : sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta).append(' ')
[ + - ]
77 [ + - ][ + - ]: 16 : .append(bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
[ + + ]
78 [ + - ]: 8 : rStrm << sOut.makeStringAndClear().getStr();
79 : :
80 [ + - ]: 8 : HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars );
81 : :
82 [ + - ][ + - ]: 8 : sOut.append("\" ").append(OOO_STRING_SVTOOLS_HTML_O_content).append("=\"");
[ + - ]
83 [ + - ]: 8 : rStrm << sOut.makeStringAndClear().getStr();
84 : :
85 [ + - ][ + - ]: 8 : HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">";
86 : 8 : }
87 : :
88 : 2 : 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 [ + - ]: 2 : rtl_getBestMimeCharsetFromTextEncoding( eDestEnc );
96 : :
97 [ + - ]: 2 : if( pCharSet )
98 : : {
99 [ + - ]: 2 : String aContentType = rtl::OUString(sHTML_MIME_text_html);
100 [ + - ]: 2 : aContentType.AppendAscii( pCharSet );
101 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, sal_True,
102 [ + - ][ + - ]: 2 : eDestEnc, pNonConvertableChars );
103 : : }
104 : :
105 : : // Titel (auch wenn er leer ist)
106 [ + - ]: 2 : rStrm << sNewLine;
107 [ + - ]: 2 : if( pIndent )
108 [ + - ]: 2 : rStrm << pIndent;
109 [ + - ]: 2 : HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title );
110 [ + - ]: 2 : if( i_xDocProps.is() )
111 : : {
112 [ + - ][ + - ]: 2 : const String& rTitle = i_xDocProps->getTitle();
[ + - ]
113 [ - + ]: 2 : if( rTitle.Len() )
114 [ # # ][ + - ]: 2 : HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars );
115 : : }
116 [ + - ]: 2 : HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, sal_False );
117 : :
118 : : // Target-Frame
119 [ + - ]: 2 : if( i_xDocProps.is() )
120 : : {
121 [ + - ][ + - ]: 2 : const String& rTarget = i_xDocProps->getDefaultTarget();
[ + - ]
122 [ - + ]: 2 : 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 [ + - ]: 2 : }
135 : : }
136 : :
137 : : // Who we are
138 [ + - ][ + - ]: 2 : String sGenerator( SfxResId(STR_HTML_GENERATOR).toString() );
[ + - ]
139 : 2 : ::rtl::OUString os( "$_OS" );
140 : 2 : ::rtl::Bootstrap::expandMacros(os);
141 [ + - ][ + - ]: 2 : sGenerator.SearchAndReplaceAscii( "%1", os );
[ + - ]
142 [ + - ]: 2 : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, sal_False, eDestEnc, pNonConvertableChars );
143 : :
144 [ + - ]: 2 : if( i_xDocProps.is() )
145 : : {
146 : : // Reload
147 [ + - ][ + - ]: 6 : if( (i_xDocProps->getAutoloadSecs() != 0) ||
[ + - - + ]
[ - + ]
148 [ + - ][ + - ]: 4 : !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 [ + - ][ + - ]: 2 : const String& rAuthor = i_xDocProps->getAuthor();
[ + - ]
168 [ - + ]: 2 : if( rAuthor.Len() )
169 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, sal_False,
170 [ # # ]: 0 : eDestEnc, pNonConvertableChars );
171 : :
172 : : // created
173 [ + - ][ + - ]: 2 : ::util::DateTime uDT = i_xDocProps->getCreationDate();
174 : 2 : Date aD(uDT.Day, uDT.Month, uDT.Year);
175 [ + - ]: 2 : Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
176 [ + - ]: 2 : String sOut = String::CreateFromInt32(aD.GetDate());
177 [ + - ]: 2 : sOut += ';';
178 [ + - ][ + - ]: 2 : sOut += String::CreateFromInt32(aT.GetTime());
[ + - ]
179 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, sal_False,
180 [ + - ]: 2 : eDestEnc, pNonConvertableChars );
181 : :
182 : : // changedby
183 [ + - ][ + - ]: 2 : const String& rChangedBy = i_xDocProps->getModifiedBy();
[ + - ]
184 [ - + ]: 2 : if( rChangedBy.Len() )
185 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, sal_False,
186 [ # # ]: 0 : eDestEnc, pNonConvertableChars );
187 : :
188 : : // changed
189 [ + - ][ + - ]: 2 : uDT = i_xDocProps->getModificationDate();
190 : 2 : Date aD2(uDT.Day, uDT.Month, uDT.Year);
191 [ + - ]: 2 : Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
192 [ + - ][ + - ]: 2 : sOut = String::CreateFromInt32(aD2.GetDate());
[ + - ]
193 [ + - ]: 2 : sOut += ';';
194 [ + - ][ + - ]: 2 : sOut += String::CreateFromInt32(aT2.GetTime());
[ + - ]
195 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, sal_False,
196 [ + - ]: 2 : eDestEnc, pNonConvertableChars );
197 : :
198 : : // Subject
199 [ + - ][ + - ]: 2 : const String& rTheme = i_xDocProps->getSubject();
[ + - ]
200 [ - + ]: 2 : if( rTheme.Len() )
201 : : OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, sal_False,
202 [ # # ]: 0 : eDestEnc, pNonConvertableChars );
203 : :
204 : : // Description
205 [ + - ][ + - ]: 2 : const String& rComment = i_xDocProps->getDescription();
[ + - ]
206 [ - + ]: 2 : 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 [ + - ][ + - ]: 2 : i_xDocProps->getKeywords());
[ + - ][ + - ]
[ + - ]
213 [ - + ]: 2 : 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(
218 [ + - ][ + - ]: 4 : ::comphelper::getProcessServiceFactory()->createInstance(
219 : 2 : ::rtl::OUString("com.sun.star.script.Converter")),
220 [ + - ][ + - ]: 2 : uno::UNO_QUERY_THROW );
221 : : uno::Reference<beans::XPropertySet> xUserDefinedProps(
222 [ + - ][ + - ]: 2 : i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
[ + - ]
223 : : DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
224 : : uno::Reference<beans::XPropertySetInfo> xPropInfo =
225 [ + - ][ + - ]: 2 : xUserDefinedProps->getPropertySetInfo();
226 : : DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
227 [ + - ][ + - ]: 2 : uno::Sequence<beans::Property> props = xPropInfo->getProperties();
228 [ - + ]: 2 : for (sal_Int32 i = 0; i < props.getLength(); ++i)
229 : : {
230 : : try
231 : : {
232 [ # # ]: 0 : ::rtl::OUString name = props[i].Name;
233 [ # # ]: 0 : uno::Any aStr = xConverter->convertToSimpleType(
234 [ # # ]: 0 : xUserDefinedProps->getPropertyValue(name),
235 [ # # ][ # # ]: 0 : uno::TypeClass_STRING);
236 : 0 : ::rtl::OUString str;
237 : 0 : aStr >>= str;
238 [ # # ][ # # ]: 0 : String valstr(comphelper::string::stripEnd(str, ' '));
239 : : OutMeta( rStrm, pIndent, name, valstr, sal_False,
240 [ # # ][ # # ]: 0 : eDestEnc, pNonConvertableChars );
[ # # ][ # # ]
[ # # ]
241 : : }
242 [ # # ]: 0 : catch (const uno::Exception&)
243 : : {
244 : : // may happen with concurrent modification...
245 : : DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
246 : : }
247 [ + - ][ + - ]: 2 : }
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
248 [ + - ]: 2 : }
249 : 2 : }
250 : :
251 : 0 : void SfxFrameHTMLWriter::Out_FrameDescriptor(
252 : : SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet,
253 : : rtl_TextEncoding eDestEnc, String *pNonConvertableChars )
254 : : {
255 : : try
256 : : {
257 : 0 : rtl::OStringBuffer sOut;
258 : 0 : ::rtl::OUString aStr;
259 [ # # ][ # # ]: 0 : uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString("FrameURL") );
260 [ # # ][ # # ]: 0 : if ( (aAny >>= aStr) && !aStr.isEmpty() )
[ # # ]
261 : : {
262 [ # # ][ # # ]: 0 : String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI );
[ # # ][ # # ]
263 [ # # ]: 0 : if( aURL.Len() )
264 : : {
265 : : aURL = URIHelper::simpleNormalizedMakeRelative(
266 [ # # ][ # # ]: 0 : rBaseURL, aURL );
[ # # ][ # # ]
267 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_src)
268 [ # # ]: 0 : .append(RTL_CONSTASCII_STRINGPARAM("=\""));
269 [ # # ]: 0 : rOut << sOut.makeStringAndClear().getStr();
270 [ # # ]: 0 : HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars );
271 [ # # ]: 0 : sOut.append('\"');
272 [ # # ]: 0 : }
273 : : }
274 : :
275 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameName") );
276 [ # # ][ # # ]: 0 : if ( (aAny >>= aStr) && !aStr.isEmpty() )
[ # # ]
277 : : {
278 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name)
279 [ # # ]: 0 : .append(RTL_CONSTASCII_STRINGPARAM("=\""));
280 [ # # ]: 0 : rOut << sOut.makeStringAndClear().getStr();
281 [ # # ][ # # ]: 0 : HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars );
[ # # ]
282 [ # # ]: 0 : sOut.append('\"');
283 : : }
284 : :
285 : 0 : sal_Int32 nVal = SIZE_NOT_SET;
286 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginWidth") );
287 [ # # ][ # # ]: 0 : if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
[ # # ]
288 : : {
289 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginwidth)
290 [ # # ][ # # ]: 0 : .append('=').append(nVal);
291 : : }
292 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginHeight") );
293 [ # # ][ # # ]: 0 : if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
[ # # ]
294 : : {
295 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginheight)
296 [ # # ][ # # ]: 0 : .append('=').append(nVal);
297 : : }
298 : :
299 : 0 : sal_Bool bVal = sal_True;
300 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoScroll") );
301 [ # # ][ # # ]: 0 : if ( (aAny >>= bVal) && !bVal )
[ # # ]
302 : : {
303 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsScrollingMode") );
304 [ # # ]: 0 : if ( aAny >>= bVal )
305 : : {
306 [ # # ]: 0 : const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
307 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolling)
308 [ # # ]: 0 : .append(pStr);
309 : : }
310 : : }
311 : :
312 : : // frame border (MS+Netscape-Extension)
313 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoBorder") );
314 [ # # ][ # # ]: 0 : if ( (aAny >>= bVal) && !bVal )
[ # # ]
315 : : {
316 [ # # ][ # # ]: 0 : aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsBorder") );
317 [ # # ]: 0 : if ( aAny >>= bVal )
318 : : {
319 [ # # ]: 0 : const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
320 [ # # ][ # # ]: 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_frameborder)
321 [ # # ][ # # ]: 0 : .append('=').append(pStr);
322 : : }
323 : : }
324 [ # # ][ # # ]: 0 : rOut << sOut.getStr();
325 : : }
326 : 0 : catch (const uno::Exception&)
327 : : {
328 : : }
329 : 0 : }
330 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|