1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <SwAppletImpl.hxx>
21 #include <svtools/htmlkywd.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 #include <comphelper/embeddedobjectcontainer.hxx>
27 #include <comphelper/classids.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <o3tl/string_view.hxx>
30 #include <svtools/embedhlp.hxx>
31 #include <tools/globname.hxx>
32 #include <tools/urlobj.hxx>
33 #include <hintids.hxx>
35 using namespace com::sun::star
;
37 SwHtmlOptType
SwApplet_Impl::GetOptionType( std::u16string_view rName
, bool bApplet
)
39 SwHtmlOptType nType
= bApplet
? SwHtmlOptType::PARAM
: SwHtmlOptType::TAG
;
45 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_align
) ||
46 o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_alt
) )
47 nType
= SwHtmlOptType::IGNORE
;
49 (rName
== u
"ARCHIVE" || rName
== u
"ARCHIVES" ) )
50 nType
= SwHtmlOptType::TAG
;
54 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_class
) ||
55 (bApplet
&& (o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_code
) ||
56 o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_codebase
))) )
57 nType
= SwHtmlOptType::IGNORE
;
61 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_height
) )
62 nType
= SwHtmlOptType::SIZE
;
63 else if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_hspace
) ||
64 (!bApplet
&& o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SW_HTML_O_Hidden
)) )
65 nType
= SwHtmlOptType::IGNORE
;
69 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_id
) )
70 nType
= SwHtmlOptType::IGNORE
;
74 if( bApplet
&& o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_mayscript
) )
75 nType
= SwHtmlOptType::IGNORE
;
79 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_name
) )
80 nType
= SwHtmlOptType::IGNORE
;
84 if( bApplet
&& rName
== u
"OBJECT" )
85 nType
= SwHtmlOptType::TAG
;
89 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_style
) ||
90 (!bApplet
&& o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_src
)) )
91 nType
= SwHtmlOptType::IGNORE
;
95 if( !bApplet
&& o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_type
) )
96 nType
= SwHtmlOptType::IGNORE
;
100 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_vspace
) )
101 nType
= SwHtmlOptType::IGNORE
;
105 if( o3tl::equalsIgnoreAsciiCase( rName
, OOO_STRING_SVTOOLS_HTML_O_width
) )
106 nType
= SwHtmlOptType::SIZE
;
112 SwApplet_Impl::SwApplet_Impl( SfxItemPool
& rPool
) :
113 m_aItemSet( rPool
, svl::Items
<RES_FRMATR_BEGIN
, RES_FRMATR_END
-1> )
117 void SwApplet_Impl::CreateApplet( const OUString
& rCode
, const OUString
& rName
,
118 bool bMayScript
, const OUString
& rCodeBase
,
119 std::u16string_view rDocumentBaseURL
)
121 comphelper::EmbeddedObjectContainer aCnt
;
124 // create Applet; it will be in running state
125 m_xApplet
= aCnt
.CreateEmbeddedObject( SvGlobalName( SO3_APPLET_CLASSID
).GetByteSequence(), aName
);
126 ::svt::EmbeddedObjectRef::TryRunningState( m_xApplet
);
128 INetURLObject
aUrlBase(rDocumentBaseURL
);
129 aUrlBase
.removeSegment();
131 OUString sDocBase
= aUrlBase
.GetMainURL(INetURLObject::DecodeMechanism::NONE
);
132 uno::Reference
< beans::XPropertySet
> xSet( m_xApplet
->getComponent(), uno::UNO_QUERY
);
135 xSet
->setPropertyValue("AppletCode", uno::Any( rCode
) );
136 xSet
->setPropertyValue("AppletName", uno::Any( rName
) );
137 xSet
->setPropertyValue("AppletIsScript", uno::Any( bMayScript
) );
138 xSet
->setPropertyValue("AppletDocBase", uno::Any( sDocBase
) );
139 if ( !rCodeBase
.isEmpty() )
140 xSet
->setPropertyValue("AppletCodeBase", uno::Any( rCodeBase
) );
142 xSet
->setPropertyValue("AppletCodeBase", uno::Any( sDocBase
) );
145 #if HAVE_FEATURE_JAVA
146 bool SwApplet_Impl::CreateApplet( std::u16string_view rBaseURL
)
148 OUString aCode
, aName
, aCodeBase
;
149 bool bMayScript
= false;
151 size_t nArgCount
= m_aCommandList
.size();
152 for( size_t i
= 0; i
< nArgCount
; i
++ )
154 const SvCommand
& rArg
= m_aCommandList
[i
];
155 const OUString
& rName
= rArg
.GetCommand();
156 if( rName
.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_code
) )
157 aCode
= rArg
.GetArgument();
158 else if( rName
.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_codebase
) )
159 aCodeBase
= INetURLObject::GetAbsURL( rBaseURL
, rArg
.GetArgument() );
160 else if( rName
.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_name
) )
161 aName
= rArg
.GetArgument();
162 else if( rName
.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_mayscript
) )
166 if( aCode
.isEmpty() )
168 CreateApplet( aCode
, aName
, bMayScript
, aCodeBase
, rBaseURL
);
173 SwApplet_Impl::~SwApplet_Impl()
176 void SwApplet_Impl::FinishApplet()
178 uno::Reference
< beans::XPropertySet
> xSet( m_xApplet
->getComponent(), uno::UNO_QUERY
);
181 uno::Sequence
< beans::PropertyValue
> aProps
;
182 m_aCommandList
.FillSequence( aProps
);
183 xSet
->setPropertyValue("AppletCommands", uno::Any( aProps
) );
187 #if HAVE_FEATURE_JAVA
188 void SwApplet_Impl::AppendParam( const OUString
& rName
, const OUString
& rValue
)
190 m_aCommandList
.Append( rName
, rValue
);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */