Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / filter / html / SwAppletImpl.cxx
blob9c0d64bb7c01e201dcc33e9f73eccf922a174880
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
41 switch( rName[0] )
43 case 'A':
44 case 'a':
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;
48 else if( bApplet &&
49 (rName == u"ARCHIVE" || rName == u"ARCHIVES" ) )
50 nType = SwHtmlOptType::TAG;
51 break;
52 case 'C':
53 case 'c':
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;
58 break;
59 case 'H':
60 case 'h':
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;
66 break;
67 case 'I':
68 case 'i':
69 if( o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_id ) )
70 nType = SwHtmlOptType::IGNORE;
71 break;
72 case 'M':
73 case 'm':
74 if( bApplet && o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
75 nType = SwHtmlOptType::IGNORE;
76 break;
77 case 'N':
78 case 'n':
79 if( o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_name ) )
80 nType = SwHtmlOptType::IGNORE;
81 break;
82 case 'O':
83 case 'o':
84 if( bApplet && rName == u"OBJECT" )
85 nType = SwHtmlOptType::TAG;
86 break;
87 case 'S':
88 case 's':
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;
92 break;
93 case 'T':
94 case 't':
95 if( !bApplet && o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_type ) )
96 nType = SwHtmlOptType::IGNORE;
97 break;
98 case 'V':
99 case 'v':
100 if( o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_vspace ) )
101 nType = SwHtmlOptType::IGNORE;
102 break;
103 case 'W':
104 case 'w':
105 if( o3tl::equalsIgnoreAsciiCase( rName, OOO_STRING_SVTOOLS_HTML_O_width ) )
106 nType = SwHtmlOptType::SIZE;
107 break;
110 return nType;
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;
122 OUString aName;
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 );
133 if ( xSet.is() )
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 ) );
141 else
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 ) )
163 bMayScript = true;
166 if( aCode.isEmpty() )
167 return false;
168 CreateApplet( aCode, aName, bMayScript, aCodeBase, rBaseURL );
169 return true;
171 #endif
173 SwApplet_Impl::~SwApplet_Impl()
176 void SwApplet_Impl::FinishApplet()
178 uno::Reference < beans::XPropertySet > xSet( m_xApplet->getComponent(), uno::UNO_QUERY );
179 if ( xSet.is() )
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 );
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */