1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frmhtmlw.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
35 #include <svtools/inetdef.hxx>
37 #include "svtools/htmlkywd.hxx"
39 //!(dv) #include <chaos2/cntapi.hxx>
40 #include <rtl/tencinfo.h>
42 #include <unotools/configmgr.hxx>
43 #include "svtools/urihelper.hxx"
44 #include <tools/datetime.hxx>
46 #include <sfx2/frmhtmlw.hxx>
47 #include <sfx2/evntconf.hxx>
48 #include <sfx2/frame.hxx>
49 #include <sfx2/app.hxx>
50 #include <sfx2/viewfrm.hxx>
51 #include <sfx2/docfile.hxx>
52 #include "sfxresid.hxx"
53 #include <sfx2/objsh.hxx>
54 #include <sfx2/sfx.hrc>
57 #include <comphelper/string.hxx>
58 #include <comphelper/processfactory.hxx>
60 #include <com/sun/star/script/XTypeConverter.hpp>
61 #include <com/sun/star/document/XDocumentProperties.hpp>
64 // -----------------------------------------------------------------------
66 using namespace ::com::sun::star
;
68 static sal_Char __READONLY_DATA sHTML_SC_yes
[] = "YES";
69 static sal_Char __READONLY_DATA sHTML_SC_no
[] = "NO";
70 static sal_Char __READONLY_DATA sHTML_SC_auto
[] = "AUTO";
71 static sal_Char __READONLY_DATA sHTML_MIME_text_html
[] = "text/html; charset=";
74 static HTMLOutEvent __FAR_DATA aFrameSetEventTable[] =
76 { sHTML_O_SDonload, sHTML_O_onload, SFX_EVENT_OPENDOC },
77 { sHTML_O_SDonunload, sHTML_O_onunload, SFX_EVENT_PREPARECLOSEDOC },
78 { sHTML_O_SDonfocus, sHTML_O_onfocus, SFX_EVENT_ACTIVATEDOC },
79 { sHTML_O_SDonblur, sHTML_O_onblur, SFX_EVENT_DEACTIVATEDOC },
85 const sal_Char
SfxFrameHTMLWriter::sNewLine
[] = "\012";
87 const sal_Char __FAR_DATA
SfxFrameHTMLWriter::sNewLine
[] = "\015\012";
90 void SfxFrameHTMLWriter::OutMeta( SvStream
& rStrm
,
91 const sal_Char
*pIndent
,
93 const String
& rContent
, BOOL bHTTPEquiv
,
94 rtl_TextEncoding eDestEnc
,
95 String
*pNonConvertableChars
)
101 ByteString
sOut( '<' );
102 (((sOut
+= OOO_STRING_SVTOOLS_HTML_meta
) += ' ')
103 += (bHTTPEquiv
? OOO_STRING_SVTOOLS_HTML_O_httpequiv
: OOO_STRING_SVTOOLS_HTML_O_name
)) += "=\"";
104 rStrm
<< sOut
.GetBuffer();
106 HTMLOutFuncs::Out_String( rStrm
, rName
, eDestEnc
, pNonConvertableChars
);
108 ((sOut
= "\" ") += OOO_STRING_SVTOOLS_HTML_O_content
) += "=\"";
109 rStrm
<< sOut
.GetBuffer();
111 HTMLOutFuncs::Out_String( rStrm
, rContent
, eDestEnc
, pNonConvertableChars
) << "\">";
114 void SfxFrameHTMLWriter::Out_DocInfo( SvStream
& rStrm
, const String
& rBaseURL
,
115 const uno::Reference
<document::XDocumentProperties
> & i_xDocProps
,
116 const sal_Char
*pIndent
,
117 rtl_TextEncoding eDestEnc
,
118 String
*pNonConvertableChars
)
120 const sal_Char
*pCharSet
=
121 rtl_getBestMimeCharsetFromTextEncoding( eDestEnc
);
125 String aContentType
= String::CreateFromAscii( sHTML_MIME_text_html
);
126 aContentType
.AppendAscii( pCharSet
);
127 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_content_type
, aContentType
, TRUE
,
128 eDestEnc
, pNonConvertableChars
);
131 // Titel (auch wenn er leer ist)
135 HTMLOutFuncs::Out_AsciiTag( rStrm
, OOO_STRING_SVTOOLS_HTML_title
);
136 if( i_xDocProps
.is() )
138 const String
& rTitle
= i_xDocProps
->getTitle();
140 HTMLOutFuncs::Out_String( rStrm
, rTitle
, eDestEnc
, pNonConvertableChars
);
142 HTMLOutFuncs::Out_AsciiTag( rStrm
, OOO_STRING_SVTOOLS_HTML_title
, FALSE
);
145 if( i_xDocProps
.is() )
147 const String
& rTarget
= i_xDocProps
->getDefaultTarget();
154 ByteString
sOut( '<' );
155 (((sOut
+= OOO_STRING_SVTOOLS_HTML_base
) += ' ') += OOO_STRING_SVTOOLS_HTML_O_target
) += "=\"";
156 rStrm
<< sOut
.GetBuffer();
157 HTMLOutFuncs::Out_String( rStrm
, rTarget
, eDestEnc
, pNonConvertableChars
)
163 String
sGenerator( SfxResId( STR_HTML_GENERATOR
) );
164 sGenerator
.SearchAndReplaceAscii( "%1", String( DEFINE_CONST_UNICODE( TOOLS_INETDEF_OS
) ) );
165 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_generator
, sGenerator
, FALSE
, eDestEnc
, pNonConvertableChars
);
167 if( i_xDocProps
.is() )
170 if( (i_xDocProps
->getAutoloadSecs() != 0) ||
171 !i_xDocProps
->getAutoloadURL().equalsAscii("") )
173 String sContent
= String::CreateFromInt32(
174 i_xDocProps
->getAutoloadSecs() );
176 const String
&rReloadURL
= i_xDocProps
->getAutoloadURL();
177 if( rReloadURL
.Len() )
179 sContent
.AppendAscii( ";URL=" );
181 URIHelper::simpleNormalizedMakeRelative(
182 rBaseURL
, rReloadURL
));
185 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_refresh
, sContent
, TRUE
,
186 eDestEnc
, pNonConvertableChars
);
190 const String
& rAuthor
= i_xDocProps
->getAuthor();
192 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_author
, rAuthor
, FALSE
,
193 eDestEnc
, pNonConvertableChars
);
196 ::util::DateTime uDT
= i_xDocProps
->getCreationDate();
197 Date
aD(uDT
.Day
, uDT
.Month
, uDT
.Year
);
198 Time
aT(uDT
.Hours
, uDT
.Minutes
, uDT
.Seconds
, uDT
.HundredthSeconds
);
199 String sOut
= String::CreateFromInt32(aD
.GetDate());
201 sOut
+= String::CreateFromInt32(aT
.GetTime());
202 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_created
, sOut
, FALSE
,
203 eDestEnc
, pNonConvertableChars
);
206 const String
& rChangedBy
= i_xDocProps
->getModifiedBy();
207 if( rChangedBy
.Len() )
208 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_changedby
, rChangedBy
, FALSE
,
209 eDestEnc
, pNonConvertableChars
);
212 uDT
= i_xDocProps
->getModificationDate();
213 Date
aD2(uDT
.Day
, uDT
.Month
, uDT
.Year
);
214 Time
aT2(uDT
.Hours
, uDT
.Minutes
, uDT
.Seconds
, uDT
.HundredthSeconds
);
215 sOut
= String::CreateFromInt32(aD2
.GetDate());
217 sOut
+= String::CreateFromInt32(aT2
.GetTime());
218 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_changed
, sOut
, FALSE
,
219 eDestEnc
, pNonConvertableChars
);
222 const String
& rTheme
= i_xDocProps
->getSubject();
224 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_classification
, rTheme
, FALSE
,
225 eDestEnc
, pNonConvertableChars
);
228 const String
& rComment
= i_xDocProps
->getDescription();
230 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_description
, rComment
, FALSE
,
231 eDestEnc
, pNonConvertableChars
);
234 String Keywords
= ::comphelper::string::convertCommaSeparated(
235 i_xDocProps
->getKeywords());
237 OutMeta( rStrm
, pIndent
, OOO_STRING_SVTOOLS_HTML_META_keywords
, Keywords
, FALSE
,
238 eDestEnc
, pNonConvertableChars
);
240 uno::Reference
< script::XTypeConverter
> xConverter(
241 ::comphelper::getProcessServiceFactory()->createInstance(
242 ::rtl::OUString::createFromAscii("com.sun.star.script.Converter")),
243 uno::UNO_QUERY_THROW
);
244 uno::Reference
<beans::XPropertySet
> xUserDefinedProps(
245 i_xDocProps
->getUserDefinedProperties(), uno::UNO_QUERY_THROW
);
246 DBG_ASSERT(xUserDefinedProps
.is(), "UserDefinedProperties is null");
247 uno::Reference
<beans::XPropertySetInfo
> xPropInfo
=
248 xUserDefinedProps
->getPropertySetInfo();
249 DBG_ASSERT(xPropInfo
.is(), "UserDefinedProperties Info is null");
250 uno::Sequence
<beans::Property
> props
= xPropInfo
->getProperties();
251 for (sal_Int32 i
= 0; i
< props
.getLength(); ++i
) {
253 ::rtl::OUString name
= props
[i
].Name
;
255 uno::Any aStr
= xConverter
->convertToSimpleType(
256 xUserDefinedProps
->getPropertyValue(name
),
257 uno::TypeClass_STRING
);
260 valstr
.EraseTrailingChars();
261 OutMeta( rStrm
, pIndent
, name
, valstr
, FALSE
,
262 eDestEnc
, pNonConvertableChars
);
263 } catch (uno::Exception
&) {
264 // may happen with concurrent modification...
265 DBG_WARNING("SfxFrameHTMLWriter::Out_DocInfo: exception");
271 void SfxFrameHTMLWriter::OutHeader( rtl_TextEncoding eDestEnc )
275 // <TITLE>Titel</TITLE>
277 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_html ) << sNewLine;
278 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head );
280 Out_DocInfo( Strm(), &pDoc->GetDocInfo(), "\t", eDestEnc );
282 HTMLOutFuncs::Out_AsciiTag( Strm(), sHTML_head, FALSE ) << sNewLine;
284 //! OutScript(); // Hier fehlen noch die Scripten im Header
288 void SfxFrameHTMLWriter::Out_FrameDescriptor(
289 SvStream
& rOut
, const String
& rBaseURL
, const uno::Reference
< beans::XPropertySet
>& xSet
,
290 rtl_TextEncoding eDestEnc
, String
*pNonConvertableChars
)
295 ::rtl::OUString aStr
;
296 uno::Any aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameURL") );
297 if ( (aAny
>>= aStr
) && aStr
.getLength() )
299 String aURL
= INetURLObject( aStr
).GetMainURL( INetURLObject::DECODE_TO_IURI
);
302 aURL
= URIHelper::simpleNormalizedMakeRelative(
304 ((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_src
) += "=\"";
305 rOut
<< sOut
.GetBuffer();
306 HTMLOutFuncs::Out_String( rOut
, aURL
, eDestEnc
, pNonConvertableChars
);
311 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameName") );
312 if ( (aAny
>>= aStr
) && aStr
.getLength() )
314 ((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_name
) += "=\"";
315 rOut
<< sOut
.GetBuffer();
316 HTMLOutFuncs::Out_String( rOut
, aStr
, eDestEnc
, pNonConvertableChars
);
320 sal_Int32 nVal
= SIZE_NOT_SET
;
321 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginWidth") );
322 if ( (aAny
>>= nVal
) && nVal
!= SIZE_NOT_SET
)
323 (((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_marginwidth
) += '=') += ByteString::CreateFromInt32( nVal
);
324 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameMarginHeight") );
325 if ( (aAny
>>= nVal
) && nVal
!= SIZE_NOT_SET
)
326 (((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_marginheight
) += '=') += ByteString::CreateFromInt32( nVal
);
328 sal_Bool bVal
= sal_True
;
329 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoScroll") );
330 if ( (aAny
>>= bVal
) && !bVal
)
332 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsScrollingMode") );
335 const sal_Char
*pStr
= bVal
? sHTML_SC_yes
: sHTML_SC_no
;
336 (((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_scrolling
) += '=') += pStr
;
340 // frame border (MS+Netscape-Erweiterung)
341 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsAutoBorder") );
342 if ( (aAny
>>= bVal
) && !bVal
)
344 aAny
= xSet
->getPropertyValue( ::rtl::OUString::createFromAscii("FrameIsBorder") );
347 const char* pStr
= bVal
? sHTML_SC_yes
: sHTML_SC_no
;
348 (((sOut
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_frameborder
) += '=') += pStr
;
352 // TODO/LATER: currently not supported attributes
354 //if( !pFrame->IsResizable() )
355 // (sOut += ' ') += sHTML_O_noresize;
357 //if ( pFrame->GetWallpaper() )
359 // ((sOut += ' ') += sHTML_O_bordercolor) += '=';
360 // rOut << sOut.GetBuffer();
361 // HTMLOutFuncs::Out_Color( rOut, pFrame->GetWallpaper()->GetColor(), eDestEnc );
364 rOut
<< sOut
.GetBuffer();
366 catch ( uno::Exception
& )
371 String
SfxFrameHTMLWriter::CreateURL( SfxFrame
* pFrame
)
374 SfxObjectShell
* pShell
= pFrame
->GetCurrentDocument();
375 if( !aRet
.Len() && pShell
)
377 aRet
= pShell
->GetMedium()->GetName();
378 //!(dv) CntAnchor::ToPresentationURL( aRet );