LibreOffice Module sw (master)  1
SwAppletImpl.cxx
Go to the documentation of this file.
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 <SwAppletImpl.hxx>
21 #include <svtools/htmlkywd.hxx>
22 #include <svl/urihelper.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 
28 #include <comphelper/classids.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <svtools/embedhlp.hxx>
31 #include <tools/globname.hxx>
32 #include <hintids.hxx>
33 
34 using namespace com::sun::star;
35 
36 SwHtmlOptType SwApplet_Impl::GetOptionType( const OUString& rName, bool bApplet )
37 {
39 
40  switch( rName.toChar() )
41  {
42  case 'A':
43  case 'a':
44  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_align ) ||
45  rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_alt ) )
46  nType = SwHtmlOptType::IGNORE;
47  else if( bApplet &&
48  (rName == "ARCHIVE" || rName == "ARCHIVES" ) )
49  nType = SwHtmlOptType::TAG;
50  break;
51  case 'C':
52  case 'c':
53  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_class ) ||
54  (bApplet && (rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_code ) ||
55  rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_codebase ))) )
56  nType = SwHtmlOptType::IGNORE;
57  break;
58  case 'H':
59  case 'h':
60  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_height ) )
61  nType = SwHtmlOptType::SIZE;
62  else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_hspace ) ||
63  (!bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SW_HTML_O_Hidden )) )
64  nType = SwHtmlOptType::IGNORE;
65  break;
66  case 'I':
67  case 'i':
68  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_id ) )
69  nType = SwHtmlOptType::IGNORE;
70  break;
71  case 'M':
72  case 'm':
73  if( bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
74  nType = SwHtmlOptType::IGNORE;
75  break;
76  case 'N':
77  case 'n':
78  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_name ) )
79  nType = SwHtmlOptType::IGNORE;
80  break;
81  case 'O':
82  case 'o':
83  if( bApplet && rName == "OBJECT" )
84  nType = SwHtmlOptType::TAG;
85  break;
86  case 'S':
87  case 's':
88  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_style ) ||
89  (!bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_src )) )
90  nType = SwHtmlOptType::IGNORE;
91  break;
92  case 'T':
93  case 't':
94  if( !bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_type ) )
95  nType = SwHtmlOptType::IGNORE;
96  break;
97  case 'V':
98  case 'v':
99  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_vspace ) )
100  nType = SwHtmlOptType::IGNORE;
101  break;
102  case 'W':
103  case 'w':
104  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_width ) )
105  nType = SwHtmlOptType::SIZE;
106  break;
107  }
108 
109  return nType;
110 }
112  aItemSet( rPool, svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END-1>{} )
113 {
114 }
115 
116 void SwApplet_Impl::CreateApplet( const OUString& rCode, const OUString& rName,
117  bool bMayScript, const OUString& rCodeBase,
118  const OUString& rDocumentBaseURL )
119 {
121  OUString aName;
122 
123  // create Applet; it will be in running state
124  xApplet = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_APPLET_CLASSID ).GetByteSequence(), aName );
126 
127  INetURLObject aUrlBase(rDocumentBaseURL);
128  aUrlBase.removeSegment();
129 
130  OUString sDocBase = aUrlBase.GetMainURL(INetURLObject::DecodeMechanism::NONE);
131  uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
132  if ( xSet.is() )
133  {
134  xSet->setPropertyValue("AppletCode", uno::makeAny( rCode ) );
135  xSet->setPropertyValue("AppletName", uno::makeAny( rName ) );
136  xSet->setPropertyValue("AppletIsScript", uno::makeAny( bMayScript ) );
137  xSet->setPropertyValue("AppletDocBase", uno::makeAny( sDocBase ) );
138  if ( !rCodeBase.isEmpty() )
139  xSet->setPropertyValue("AppletCodeBase", uno::makeAny( rCodeBase ) );
140  else
141  xSet->setPropertyValue("AppletCodeBase", uno::makeAny( sDocBase ) );
142  }
143 }
144 #if HAVE_FEATURE_JAVA
145 bool SwApplet_Impl::CreateApplet( const OUString& rBaseURL )
146 {
147  OUString aCode, aName, aCodeBase;
148  bool bMayScript = false;
149 
150  size_t nArgCount = aCommandList.size();
151  for( size_t i = 0; i < nArgCount; i++ )
152  {
153  const SvCommand& rArg = aCommandList[i];
154  const OUString& rName = rArg.GetCommand();
155  if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_code ) )
156  aCode = rArg.GetArgument();
157  else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_codebase ) )
158  aCodeBase = INetURLObject::GetAbsURL( rBaseURL, rArg.GetArgument() );
159  else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_name ) )
160  aName = rArg.GetArgument();
161  else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
162  bMayScript = true;
163  }
164 
165  if( aCode.isEmpty() )
166  return false;
167  CreateApplet( aCode, aName, bMayScript, aCodeBase, rBaseURL );
168  return true;
169 }
170 #endif
171 
173 {
174 }
176 {
177  uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
178  if ( xSet.is() )
179  {
180  uno::Sequence < beans::PropertyValue > aProps;
181  aCommandList.FillSequence( aProps );
182  xSet->setPropertyValue("AppletCommands", uno::makeAny( aProps ) );
183  }
184 }
185 
186 #if HAVE_FEATURE_JAVA
187 void SwApplet_Impl::AppendParam( const OUString& rName, const OUString& rValue )
188 {
189  aCommandList.Append( rName, rValue );
190 }
191 #endif
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define OOO_STRING_SVTOOLS_HTML_O_src
#define OOO_STRING_SVTOOLS_HTML_O_vspace
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
static SwHtmlOptType GetOptionType(const OUString &rName, bool bApplet)
#define OOO_STRING_SW_HTML_O_Hidden
SvCommandList aCommandList
size_t size() const
#define RES_FRMATR_END
Definition: hintids.hxx:236
#define OOO_STRING_SVTOOLS_HTML_O_id
#define OOO_STRING_SVTOOLS_HTML_O_alt
SwApplet_Impl(SfxItemPool &rPool)
#define OOO_STRING_SVTOOLS_HTML_O_height
FUNC_TYPE const nType
#define OOO_STRING_SVTOOLS_HTML_O_mayscript
static OUString GetAbsURL(OUString const &rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void CreateApplet(const OUString &rCode, const OUString &rName, bool bMayScript, const OUString &rCodeBase, const OUString &rBaseURL)
void FillSequence(css::uno::Sequence< css::beans::PropertyValue > &) const
#define OOO_STRING_SVTOOLS_HTML_O_code
#define OOO_STRING_SVTOOLS_HTML_O_hspace
#define OOO_STRING_SVTOOLS_HTML_O_class
const OUString & GetArgument() const
int i
void Append(const OUString &rCommand, const OUString &rArg)
SwHtmlOptType
#define OOO_STRING_SVTOOLS_HTML_O_name
#define SO3_APPLET_CLASSID
const OUString & GetCommand() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
#define OOO_STRING_SVTOOLS_HTML_O_codebase
#define OOO_STRING_SVTOOLS_HTML_O_align
#define OOO_STRING_SVTOOLS_HTML_O_style
OString const aName
#define OOO_STRING_SVTOOLS_HTML_O_type
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
#define RES_FRMATR_BEGIN
Definition: hintids.hxx:192
#define OOO_STRING_SVTOOLS_HTML_O_width
css::uno::Reference< css::embed::XEmbeddedObject > xApplet
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)