Line data Source code
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/embed/EmbedStates.hpp>
25 :
26 : #include <comphelper/embeddedobjectcontainer.hxx>
27 : #include <comphelper/classids.hxx>
28 : #include <com/sun/star/uno/Any.hxx>
29 : #include <svtools/embedhlp.hxx>
30 :
31 : using namespace com::sun::star;
32 :
33 : namespace {
34 :
35 : static char const sHTML_O_archive[] = "ARCHIVE";
36 : static char const sHTML_O_Archives[] = "ARCHIVES";
37 : static char const sHTML_O_Object[] = "OBJECT";
38 :
39 : }
40 :
41 0 : sal_uInt16 SwApplet_Impl::GetOptionType( const OUString& rName, sal_Bool bApplet )
42 : {
43 0 : sal_uInt16 nType = bApplet ? SWHTML_OPTTYPE_PARAM : SWHTML_OPTTYPE_TAG;
44 :
45 0 : switch( rName.toChar() )
46 : {
47 : case 'A':
48 : case 'a':
49 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_align ) ||
50 0 : rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_alt ) )
51 0 : nType = SWHTML_OPTTYPE_IGNORE;
52 0 : else if( bApplet &&
53 0 : (rName.equalsIgnoreAsciiCaseAscii( sHTML_O_archive ) ||
54 0 : rName.equalsIgnoreAsciiCaseAscii( sHTML_O_Archives )) )
55 0 : nType = SWHTML_OPTTYPE_TAG;
56 0 : break;
57 : case 'C':
58 : case 'c':
59 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_class ) ||
60 0 : (bApplet && (rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_code ) ||
61 0 : rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_codebase ))) )
62 0 : nType = SWHTML_OPTTYPE_IGNORE;
63 0 : break;
64 : case 'H':
65 : case 'h':
66 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_height ) )
67 0 : nType = SWHTML_OPTTYPE_SIZE;
68 0 : else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_hspace ) ||
69 0 : (!bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SW_HTML_O_Hidden )) )
70 0 : nType = SWHTML_OPTTYPE_IGNORE;
71 0 : break;
72 : case 'I':
73 : case 'i':
74 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_id ) )
75 0 : nType = SWHTML_OPTTYPE_IGNORE;
76 0 : break;
77 : case 'M':
78 : case 'm':
79 0 : if( bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
80 0 : nType = SWHTML_OPTTYPE_IGNORE;
81 0 : break;
82 : case 'N':
83 : case 'n':
84 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_name ) )
85 0 : nType = SWHTML_OPTTYPE_IGNORE;
86 0 : break;
87 : case 'O':
88 : case 'o':
89 0 : if( bApplet && rName.equalsIgnoreAsciiCaseAscii( sHTML_O_Object ) )
90 0 : nType = SWHTML_OPTTYPE_TAG;
91 0 : break;
92 : case 'S':
93 : case 's':
94 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_style ) ||
95 0 : (!bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_src )) )
96 0 : nType = SWHTML_OPTTYPE_IGNORE;
97 0 : break;
98 : case 'T':
99 : case 't':
100 0 : if( !bApplet && rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_type ) )
101 0 : nType = SWHTML_OPTTYPE_IGNORE;
102 0 : break;
103 : case 'V':
104 : case 'v':
105 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_vspace ) )
106 0 : nType = SWHTML_OPTTYPE_IGNORE;
107 0 : break;
108 : case 'W':
109 : case 'w':
110 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_width ) )
111 0 : nType = SWHTML_OPTTYPE_SIZE;
112 0 : break;
113 : }
114 :
115 0 : return nType;
116 : }
117 0 : SwApplet_Impl::SwApplet_Impl( SfxItemPool& rPool, sal_uInt16 nWhich1, sal_uInt16 nWhich2 ) :
118 0 : aItemSet( rPool, nWhich1, nWhich2 )
119 : {
120 0 : }
121 :
122 0 : void SwApplet_Impl::CreateApplet( const OUString& rCode, const OUString& rName,
123 : sal_Bool bMayScript, const OUString& rCodeBase,
124 : const OUString& rDocumentBaseURL )
125 : {
126 0 : comphelper::EmbeddedObjectContainer aCnt;
127 0 : OUString aName;
128 :
129 : // create Applet; it will be in running state
130 0 : xApplet = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_APPLET_CLASSID ).GetByteSequence(), aName );
131 0 : ::svt::EmbeddedObjectRef::TryRunningState( xApplet );
132 :
133 0 : INetURLObject aUrlBase(rDocumentBaseURL);
134 0 : aUrlBase.removeSegment();
135 :
136 0 : OUString sDocBase = aUrlBase.GetMainURL(INetURLObject::NO_DECODE);
137 0 : uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
138 0 : if ( xSet.is() )
139 : {
140 0 : xSet->setPropertyValue("AppletCode", uno::makeAny( rCode ) );
141 0 : xSet->setPropertyValue("AppletName", uno::makeAny( rName ) );
142 0 : xSet->setPropertyValue("AppletIsScript", uno::makeAny( sal_Bool(bMayScript) ) );
143 0 : xSet->setPropertyValue("AppletDocBase", uno::makeAny( sDocBase ) );
144 0 : if ( !rCodeBase.isEmpty() )
145 0 : xSet->setPropertyValue("AppletCodeBase", uno::makeAny( rCodeBase ) );
146 : else
147 0 : xSet->setPropertyValue("AppletCodeBase", uno::makeAny( sDocBase ) );
148 0 : }
149 0 : }
150 : #ifdef SOLAR_JAVA
151 0 : sal_Bool SwApplet_Impl::CreateApplet( const OUString& rBaseURL )
152 : {
153 0 : OUString aCode, aName, aCodeBase;
154 0 : sal_Bool bMayScript = sal_False;
155 :
156 0 : size_t nArgCount = aCommandList.size();
157 0 : for( size_t i = 0; i < nArgCount; i++ )
158 : {
159 0 : const SvCommand& rArg = aCommandList[i];
160 0 : const OUString& rName = rArg.GetCommand();
161 0 : if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_code ) )
162 0 : aCode = rArg.GetArgument();
163 0 : else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_codebase ) )
164 0 : aCodeBase = INetURLObject::GetAbsURL( rBaseURL, rArg.GetArgument() );
165 0 : else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_name ) )
166 0 : aName = rArg.GetArgument();
167 0 : else if( rName.equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
168 0 : bMayScript = sal_True;
169 0 : }
170 :
171 0 : if( aCode.isEmpty() )
172 0 : return sal_False;
173 0 : CreateApplet( aCode, aName, bMayScript, aCodeBase, rBaseURL );
174 0 : return sal_True;
175 : }
176 : #endif
177 :
178 0 : SwApplet_Impl::~SwApplet_Impl()
179 : {
180 0 : }
181 0 : void SwApplet_Impl::FinishApplet()
182 : {
183 0 : uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
184 0 : if ( xSet.is() )
185 : {
186 0 : uno::Sequence < beans::PropertyValue > aProps;
187 0 : aCommandList.FillSequence( aProps );
188 0 : xSet->setPropertyValue("AppletCommands", uno::makeAny( aProps ) );
189 0 : }
190 0 : }
191 :
192 : #ifdef SOLAR_JAVA
193 0 : void SwApplet_Impl::AppendParam( const OUString& rName, const OUString& rValue )
194 : {
195 0 : aCommandList.Append( rName, rValue );
196 99 : }
197 : #endif
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|