Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / bastyp / frmhtmlw.cxx
blobbcb60dac94b5dd31cbbbd8c742b9c018421ff893
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svl/inetdef.hxx>
31 #include "svtools/htmlkywd.hxx"
33 #include <rtl/tencinfo.h>
35 #include <unotools/configmgr.hxx>
36 #include "svl/urihelper.hxx"
37 #include <tools/datetime.hxx>
39 #include <sfx2/frmhtmlw.hxx>
40 #include <sfx2/evntconf.hxx>
41 #include <sfx2/frame.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <sfx2/docfile.hxx>
45 #include "sfx2/sfxresid.hxx"
46 #include <sfx2/objsh.hxx>
47 #include <sfx2/sfx.hrc>
48 #include "bastyp.hrc"
50 #include <comphelper/processfactory.hxx>
51 #include <comphelper/string.hxx>
53 #include <com/sun/star/script/XTypeConverter.hpp>
54 #include <com/sun/star/document/XDocumentProperties.hpp>
56 #include <rtl/bootstrap.hxx>
57 #include <rtl/strbuf.hxx>
60 // -----------------------------------------------------------------------
62 using namespace ::com::sun::star;
64 static sal_Char const sHTML_SC_yes[] = "YES";
65 static sal_Char const sHTML_SC_no[] = "NO";
66 static sal_Char const sHTML_SC_auto[] = "AUTO";
67 static sal_Char const sHTML_MIME_text_html[] = "text/html; charset=";
69 #if defined(UNX)
70 const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\012";
71 #else
72 const sal_Char SfxFrameHTMLWriter::sNewLine[] = "\015\012";
73 #endif
75 void SfxFrameHTMLWriter::OutMeta( SvStream& rStrm,
76 const sal_Char *pIndent,
77 const String& rName,
78 const String& rContent, sal_Bool bHTTPEquiv,
79 rtl_TextEncoding eDestEnc,
80 String *pNonConvertableChars )
82 rStrm << sNewLine;
83 if( pIndent )
84 rStrm << pIndent;
86 rtl::OStringBuffer sOut;
87 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta).append(' ')
88 .append(bHTTPEquiv ? OOO_STRING_SVTOOLS_HTML_O_httpequiv : OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
89 rStrm << sOut.makeStringAndClear().getStr();
91 HTMLOutFuncs::Out_String( rStrm, rName, eDestEnc, pNonConvertableChars );
93 sOut.append("\" ").append(OOO_STRING_SVTOOLS_HTML_O_content).append("=\"");
94 rStrm << sOut.makeStringAndClear().getStr();
96 HTMLOutFuncs::Out_String( rStrm, rContent, eDestEnc, pNonConvertableChars ) << "\">";
99 void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL,
100 const uno::Reference<document::XDocumentProperties> & i_xDocProps,
101 const sal_Char *pIndent,
102 rtl_TextEncoding eDestEnc,
103 String *pNonConvertableChars )
105 const sal_Char *pCharSet =
106 rtl_getBestMimeCharsetFromTextEncoding( eDestEnc );
108 if( pCharSet )
110 String aContentType = String::CreateFromAscii( sHTML_MIME_text_html );
111 aContentType.AppendAscii( pCharSet );
112 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_content_type, aContentType, sal_True,
113 eDestEnc, pNonConvertableChars );
116 // Titel (auch wenn er leer ist)
117 rStrm << sNewLine;
118 if( pIndent )
119 rStrm << pIndent;
120 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title );
121 if( i_xDocProps.is() )
123 const String& rTitle = i_xDocProps->getTitle();
124 if( rTitle.Len() )
125 HTMLOutFuncs::Out_String( rStrm, rTitle, eDestEnc, pNonConvertableChars );
127 HTMLOutFuncs::Out_AsciiTag( rStrm, OOO_STRING_SVTOOLS_HTML_title, sal_False );
129 // Target-Frame
130 if( i_xDocProps.is() )
132 const String& rTarget = i_xDocProps->getDefaultTarget();
133 if( rTarget.Len() )
135 rStrm << sNewLine;
136 if( pIndent )
137 rStrm << pIndent;
139 rtl::OStringBuffer sOut;
140 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_base).append(' ')
141 .append(OOO_STRING_SVTOOLS_HTML_O_target).append("=\"");
142 rStrm << sOut.makeStringAndClear().getStr();
143 HTMLOutFuncs::Out_String( rStrm, rTarget, eDestEnc, pNonConvertableChars )
144 << "\">";
148 // Who we are
149 String sGenerator( SfxResId( STR_HTML_GENERATOR ) );
150 ::rtl::OUString os( "$_OS" );
151 ::rtl::Bootstrap::expandMacros(os);
152 sGenerator.SearchAndReplaceAscii( "%1", os );
153 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_generator, sGenerator, sal_False, eDestEnc, pNonConvertableChars );
155 if( i_xDocProps.is() )
157 // Reload
158 if( (i_xDocProps->getAutoloadSecs() != 0) ||
159 !i_xDocProps->getAutoloadURL().isEmpty() )
161 String sContent = String::CreateFromInt32(
162 i_xDocProps->getAutoloadSecs() );
164 const String &rReloadURL = i_xDocProps->getAutoloadURL();
165 if( rReloadURL.Len() )
167 sContent.AppendAscii( ";URL=" );
168 sContent += String(
169 URIHelper::simpleNormalizedMakeRelative(
170 rBaseURL, rReloadURL));
173 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_refresh, sContent, sal_True,
174 eDestEnc, pNonConvertableChars );
177 // Author
178 const String& rAuthor = i_xDocProps->getAuthor();
179 if( rAuthor.Len() )
180 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_author, rAuthor, sal_False,
181 eDestEnc, pNonConvertableChars );
183 // created
184 ::util::DateTime uDT = i_xDocProps->getCreationDate();
185 Date aD(uDT.Day, uDT.Month, uDT.Year);
186 Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
187 String sOut = String::CreateFromInt32(aD.GetDate());
188 sOut += ';';
189 sOut += String::CreateFromInt32(aT.GetTime());
190 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_created, sOut, sal_False,
191 eDestEnc, pNonConvertableChars );
193 // changedby
194 const String& rChangedBy = i_xDocProps->getModifiedBy();
195 if( rChangedBy.Len() )
196 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changedby, rChangedBy, sal_False,
197 eDestEnc, pNonConvertableChars );
199 // changed
200 uDT = i_xDocProps->getModificationDate();
201 Date aD2(uDT.Day, uDT.Month, uDT.Year);
202 Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
203 sOut = String::CreateFromInt32(aD2.GetDate());
204 sOut += ';';
205 sOut += String::CreateFromInt32(aT2.GetTime());
206 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_changed, sOut, sal_False,
207 eDestEnc, pNonConvertableChars );
209 // Subject
210 const String& rTheme = i_xDocProps->getSubject();
211 if( rTheme.Len() )
212 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_classification, rTheme, sal_False,
213 eDestEnc, pNonConvertableChars );
215 // Description
216 const String& rComment = i_xDocProps->getDescription();
217 if( rComment.Len() )
218 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_description, rComment, sal_False,
219 eDestEnc, pNonConvertableChars);
221 // Keywords
222 String Keywords = ::comphelper::string::convertCommaSeparated(
223 i_xDocProps->getKeywords());
224 if( Keywords.Len() )
225 OutMeta( rStrm, pIndent, OOO_STRING_SVTOOLS_HTML_META_keywords, Keywords, sal_False,
226 eDestEnc, pNonConvertableChars);
228 uno::Reference < script::XTypeConverter > xConverter(
229 ::comphelper::getProcessServiceFactory()->createInstance(
230 ::rtl::OUString("com.sun.star.script.Converter")),
231 uno::UNO_QUERY_THROW );
232 uno::Reference<beans::XPropertySet> xUserDefinedProps(
233 i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
234 DBG_ASSERT(xUserDefinedProps.is(), "UserDefinedProperties is null");
235 uno::Reference<beans::XPropertySetInfo> xPropInfo =
236 xUserDefinedProps->getPropertySetInfo();
237 DBG_ASSERT(xPropInfo.is(), "UserDefinedProperties Info is null");
238 uno::Sequence<beans::Property> props = xPropInfo->getProperties();
239 for (sal_Int32 i = 0; i < props.getLength(); ++i)
243 ::rtl::OUString name = props[i].Name;
244 uno::Any aStr = xConverter->convertToSimpleType(
245 xUserDefinedProps->getPropertyValue(name),
246 uno::TypeClass_STRING);
247 ::rtl::OUString str;
248 aStr >>= str;
249 String valstr(comphelper::string::stripEnd(str, ' '));
250 OutMeta( rStrm, pIndent, name, valstr, sal_False,
251 eDestEnc, pNonConvertableChars );
253 catch (const uno::Exception&)
255 // may happen with concurrent modification...
256 DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
262 void SfxFrameHTMLWriter::Out_FrameDescriptor(
263 SvStream& rOut, const String& rBaseURL, const uno::Reference < beans::XPropertySet >& xSet,
264 rtl_TextEncoding eDestEnc, String *pNonConvertableChars )
268 rtl::OStringBuffer sOut;
269 ::rtl::OUString aStr;
270 uno::Any aAny = xSet->getPropertyValue( ::rtl::OUString("FrameURL") );
271 if ( (aAny >>= aStr) && !aStr.isEmpty() )
273 String aURL = INetURLObject( aStr ).GetMainURL( INetURLObject::DECODE_TO_IURI );
274 if( aURL.Len() )
276 aURL = URIHelper::simpleNormalizedMakeRelative(
277 rBaseURL, aURL );
278 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_src)
279 .append(RTL_CONSTASCII_STRINGPARAM("=\""));
280 rOut << sOut.makeStringAndClear().getStr();
281 HTMLOutFuncs::Out_String( rOut, aURL, eDestEnc, pNonConvertableChars );
282 sOut.append('\"');
286 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameName") );
287 if ( (aAny >>= aStr) && !aStr.isEmpty() )
289 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name)
290 .append(RTL_CONSTASCII_STRINGPARAM("=\""));
291 rOut << sOut.makeStringAndClear().getStr();
292 HTMLOutFuncs::Out_String( rOut, aStr, eDestEnc, pNonConvertableChars );
293 sOut.append('\"');
296 sal_Int32 nVal = SIZE_NOT_SET;
297 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginWidth") );
298 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
300 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginwidth)
301 .append('=').append(nVal);
303 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameMarginHeight") );
304 if ( (aAny >>= nVal) && nVal != SIZE_NOT_SET )
306 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_marginheight)
307 .append('=').append(nVal);
310 sal_Bool bVal = sal_True;
311 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoScroll") );
312 if ( (aAny >>= bVal) && !bVal )
314 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsScrollingMode") );
315 if ( aAny >>= bVal )
317 const sal_Char *pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
318 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_scrolling)
319 .append(pStr);
323 // frame border (MS+Netscape-Extension)
324 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsAutoBorder") );
325 if ( (aAny >>= bVal) && !bVal )
327 aAny = xSet->getPropertyValue( ::rtl::OUString("FrameIsBorder") );
328 if ( aAny >>= bVal )
330 const char* pStr = bVal ? sHTML_SC_yes : sHTML_SC_no;
331 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_frameborder)
332 .append('=').append(pStr);
335 rOut << sOut.getStr();
337 catch (const uno::Exception&)
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */