1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include <SwAppletImpl.hxx>
27 #include <svtools/htmlkywd.hxx>
28 #include <svl/urihelper.hxx>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 
32 #include <comphelper/embeddedobjectcontainer.hxx>
33 #include <sot/clsids.hxx>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <svtools/embedhlp.hxx>
36 
37 using namespace com::sun::star;
38 
39 namespace {
40 
41 static char const sHTML_O_archive[] = "ARCHIVE";
42 static char const sHTML_O_Archives[] = "ARCHIVES";
43 static char const sHTML_O_Object[] = "OBJECT";
44 
45 }
46 
GetOptionType(const String & rName,sal_Bool bApplet)47 sal_uInt16 SwApplet_Impl::GetOptionType( const String& rName, sal_Bool bApplet )
48 {
49 	sal_uInt16 nType = bApplet ? SWHTML_OPTTYPE_PARAM : SWHTML_OPTTYPE_TAG;
50 
51 	switch( rName.GetChar(0) )
52 	{
53 	case 'A':
54 	case 'a':
55 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_align ) ||
56 			rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_alt ) )
57 			nType = SWHTML_OPTTYPE_IGNORE;
58 		else if( bApplet &&
59 				 (rName.EqualsIgnoreCaseAscii( sHTML_O_archive ) ||
60 				 rName.EqualsIgnoreCaseAscii( sHTML_O_Archives )) )
61 			nType = SWHTML_OPTTYPE_TAG;
62 		break;
63 	case 'C':
64 	case 'c':
65 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_class ) ||
66 			(bApplet && (rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_code ) ||
67 						 rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_codebase ))) )
68 			nType = SWHTML_OPTTYPE_IGNORE;
69 		break;
70 	case 'H':
71 	case 'h':
72 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_height ) )
73 			nType = SWHTML_OPTTYPE_SIZE;
74 		else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_hspace ) ||
75 			(!bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SW_HTML_O_Hidden )) )
76 			nType = SWHTML_OPTTYPE_IGNORE;
77 		break;
78 	case 'I':
79 	case 'i':
80 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_id ) )
81 			nType = SWHTML_OPTTYPE_IGNORE;
82 		break;
83 	case 'M':
84 	case 'm':
85 		if( bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
86 			nType = SWHTML_OPTTYPE_IGNORE;
87 		break;
88 	case 'N':
89 	case 'n':
90 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_name ) )
91 			nType = SWHTML_OPTTYPE_IGNORE;
92 		break;
93 	case 'O':
94 	case 'o':
95 		if( bApplet && rName.EqualsIgnoreCaseAscii( sHTML_O_Object ) )
96 			nType = SWHTML_OPTTYPE_TAG;
97 		break;
98 	case 'S':
99 	case 's':
100 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_style ) ||
101 			(!bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_src )) )
102 			nType = SWHTML_OPTTYPE_IGNORE;
103 		break;
104 	case 'T':
105 	case 't':
106 		if( !bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_type ) )
107 			nType = SWHTML_OPTTYPE_IGNORE;
108 		break;
109 	case 'V':
110 	case 'v':
111 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_vspace ) )
112 			nType = SWHTML_OPTTYPE_IGNORE;
113 		break;
114 	case 'W':
115 	case 'w':
116 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_width ) )
117 			nType = SWHTML_OPTTYPE_SIZE;
118 		break;
119 	}
120 
121 	return nType;
122 }
SwApplet_Impl(SfxItemPool & rPool,sal_uInt16 nWhich1,sal_uInt16 nWhich2)123 SwApplet_Impl::SwApplet_Impl( SfxItemPool& rPool, sal_uInt16 nWhich1, sal_uInt16 nWhich2 ) :
124 		aItemSet( rPool, nWhich1, nWhich2 )
125 {
126 }
127 
CreateApplet(const String & rCode,const String & rName,sal_Bool bMayScript,const String & rCodeBase,const String & rDocumentBaseURL)128 void SwApplet_Impl::CreateApplet( const String& rCode, const String& rName,
129                                       sal_Bool bMayScript, const String& rCodeBase,
130                                       const String& rDocumentBaseURL )
131 {
132     comphelper::EmbeddedObjectContainer aCnt;
133     ::rtl::OUString aName;
134 
135     // create Applet; it will be in running state
136     xApplet = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_APPLET_CLASSID ).GetByteSequence(), aName );
137     ::svt::EmbeddedObjectRef::TryRunningState( xApplet );
138 
139     INetURLObject aUrlBase(rDocumentBaseURL);
140     aUrlBase.removeSegment();
141 
142     String sDocBase = aUrlBase.GetMainURL(INetURLObject::NO_DECODE);
143     uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
144     if ( xSet.is() )
145     {
146         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCode"), uno::makeAny( ::rtl::OUString( rCode ) ) );
147         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletName"), uno::makeAny( ::rtl::OUString( rName ) ) );
148         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletIsScript"), uno::makeAny( sal_Bool(bMayScript) ) );
149         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletDocBase"), uno::makeAny( ::rtl::OUString(sDocBase) ) );
150         if ( rCodeBase.Len() )
151             xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), uno::makeAny( ::rtl::OUString( rCodeBase ) ) );
152         else
153             xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), uno::makeAny( ::rtl::OUString( sDocBase ) ) );
154     }
155 }
156 #ifdef SOLAR_JAVA
CreateApplet(const String & rBaseURL)157 sal_Bool SwApplet_Impl::CreateApplet( const String& rBaseURL )
158 {
159 	String aCode, aName, aCodeBase;
160 	sal_Bool bMayScript = sal_False;
161 
162 	sal_uInt32 nArgCount = aCommandList.Count();
163 	for( sal_uInt32 i=0; i<nArgCount; i++ )
164 	{
165 		const SvCommand& rArg = aCommandList[i];
166 		const String& rName = rArg.GetCommand();
167 		if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_code ) )
168 			aCode = rArg.GetArgument();
169 		else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_codebase ) )
170             aCodeBase = INetURLObject::GetAbsURL( rBaseURL, rArg.GetArgument() );
171 		else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_name ) )
172 			aName = rArg.GetArgument();
173 		else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
174 			bMayScript = sal_True;
175     }
176 
177 	if( !aCode.Len() )
178 		return sal_False;
179     CreateApplet( aCode, aName, bMayScript, aCodeBase, rBaseURL );
180 	return sal_True;
181 }
182 #endif
183 
~SwApplet_Impl()184 SwApplet_Impl::~SwApplet_Impl()
185 {
186 }
FinishApplet()187 void SwApplet_Impl::FinishApplet()
188 {
189     //xApplet->EnableSetModified( sal_True );
190     uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
191     if ( xSet.is() )
192     {
193         uno::Sequence < beans::PropertyValue > aProps;
194         aCommandList.FillSequence( aProps );
195         xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCommands"), uno::makeAny( aProps ) );
196     }
197 }
198 
199 #ifdef SOLAR_JAVA
AppendParam(const String & rName,const String & rValue)200 void SwApplet_Impl::AppendParam( const String& rName, const String& rValue )
201 {
202     aCommandList.Append( rName, rValue );
203 }
204 #endif
205