Update ooo320-m1
[ooovba.git] / sw / source / filter / html / SwAppletImpl.cxx
blob25b071ed6df3914cc20f326290b41b5659e5145f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwAppletImpl.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <SwAppletImpl.hxx>
34 #include <svtools/htmlkywd.hxx>
35 #include <svtools/urihelper.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/embed/EmbedStates.hpp>
39 #include <comphelper/embeddedobjectcontainer.hxx>
40 #include <sot/clsids.hxx>
41 #include <com/sun/star/uno/Any.hxx>
42 #include <svtools/embedhlp.hxx>
44 using namespace com::sun::star;
46 namespace {
48 static char const sHTML_O_archive[] = "ARCHIVE";
49 static char const sHTML_O_Archives[] = "ARCHIVES";
50 static char const sHTML_O_Object[] = "OBJECT";
54 USHORT SwApplet_Impl::GetOptionType( const String& rName, BOOL bApplet )
56 USHORT nType = bApplet ? SWHTML_OPTTYPE_PARAM : SWHTML_OPTTYPE_TAG;
58 switch( rName.GetChar(0) )
60 case 'A':
61 case 'a':
62 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_align ) ||
63 rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_alt ) )
64 nType = SWHTML_OPTTYPE_IGNORE;
65 else if( bApplet &&
66 (rName.EqualsIgnoreCaseAscii( sHTML_O_archive ) ||
67 rName.EqualsIgnoreCaseAscii( sHTML_O_Archives )) )
68 nType = SWHTML_OPTTYPE_TAG;
69 break;
70 case 'C':
71 case 'c':
72 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_class ) ||
73 (bApplet && (rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_code ) ||
74 rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_codebase ))) )
75 nType = SWHTML_OPTTYPE_IGNORE;
76 break;
77 case 'H':
78 case 'h':
79 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_height ) )
80 nType = SWHTML_OPTTYPE_SIZE;
81 else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_hspace ) ||
82 (!bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SW_HTML_O_Hidden )) )
83 nType = SWHTML_OPTTYPE_IGNORE;
84 break;
85 case 'I':
86 case 'i':
87 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_id ) )
88 nType = SWHTML_OPTTYPE_IGNORE;
89 break;
90 case 'M':
91 case 'm':
92 if( bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
93 nType = SWHTML_OPTTYPE_IGNORE;
94 break;
95 case 'N':
96 case 'n':
97 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_name ) )
98 nType = SWHTML_OPTTYPE_IGNORE;
99 break;
100 case 'O':
101 case 'o':
102 if( bApplet && rName.EqualsIgnoreCaseAscii( sHTML_O_Object ) )
103 nType = SWHTML_OPTTYPE_TAG;
104 break;
105 case 'S':
106 case 's':
107 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_style ) ||
108 (!bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_src )) )
109 nType = SWHTML_OPTTYPE_IGNORE;
110 break;
111 case 'T':
112 case 't':
113 if( !bApplet && rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_type ) )
114 nType = SWHTML_OPTTYPE_IGNORE;
115 break;
116 case 'V':
117 case 'v':
118 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_vspace ) )
119 nType = SWHTML_OPTTYPE_IGNORE;
120 break;
121 case 'W':
122 case 'w':
123 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_width ) )
124 nType = SWHTML_OPTTYPE_SIZE;
125 break;
128 return nType;
130 SwApplet_Impl::SwApplet_Impl( SfxItemPool& rPool, USHORT nWhich1, USHORT nWhich2 ) :
131 aItemSet( rPool, nWhich1, nWhich2 )
135 void SwApplet_Impl::CreateApplet( const String& rCode, const String& rName,
136 BOOL bMayScript, const String& rCodeBase,
137 const String& rDocumentBaseURL )
139 comphelper::EmbeddedObjectContainer aCnt;
140 ::rtl::OUString aName;
142 // create Applet; it will be in running state
143 xApplet = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_APPLET_CLASSID ).GetByteSequence(), aName );
144 ::svt::EmbeddedObjectRef::TryRunningState( xApplet );
146 INetURLObject aUrlBase(rDocumentBaseURL);
147 aUrlBase.removeSegment();
149 String sDocBase = aUrlBase.GetMainURL(INetURLObject::NO_DECODE);
150 uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
151 if ( xSet.is() )
153 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCode"), uno::makeAny( ::rtl::OUString( rCode ) ) );
154 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletName"), uno::makeAny( ::rtl::OUString( rName ) ) );
155 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletIsScript"), uno::makeAny( sal_Bool(bMayScript) ) );
156 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletDocBase"), uno::makeAny( ::rtl::OUString(sDocBase) ) );
157 if ( rCodeBase.Len() )
158 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), uno::makeAny( ::rtl::OUString( rCodeBase ) ) );
159 else
160 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), uno::makeAny( ::rtl::OUString( sDocBase ) ) );
163 #ifdef SOLAR_JAVA
164 sal_Bool SwApplet_Impl::CreateApplet( const String& rBaseURL )
166 String aCode, aName, aCodeBase;
167 sal_Bool bMayScript = sal_False;
169 sal_uInt32 nArgCount = aCommandList.Count();
170 for( sal_uInt32 i=0; i<nArgCount; i++ )
172 const SvCommand& rArg = aCommandList[i];
173 const String& rName = rArg.GetCommand();
174 if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_code ) )
175 aCode = rArg.GetArgument();
176 else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_codebase ) )
177 aCodeBase = INetURLObject::GetAbsURL( rBaseURL, rArg.GetArgument() );
178 else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_name ) )
179 aName = rArg.GetArgument();
180 else if( rName.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_mayscript ) )
181 bMayScript = sal_True;
184 if( !aCode.Len() )
185 return sal_False;
186 CreateApplet( aCode, aName, bMayScript, aCodeBase, rBaseURL );
187 return sal_True;
189 #endif
191 SwApplet_Impl::~SwApplet_Impl()
194 void SwApplet_Impl::FinishApplet()
196 //xApplet->EnableSetModified( TRUE );
197 uno::Reference < beans::XPropertySet > xSet( xApplet->getComponent(), uno::UNO_QUERY );
198 if ( xSet.is() )
200 uno::Sequence < beans::PropertyValue > aProps;
201 aCommandList.FillSequence( aProps );
202 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCommands"), uno::makeAny( aProps ) );
206 #ifdef SOLAR_JAVA
207 void SwApplet_Impl::AppendParam( const String& rName, const String& rValue )
209 aCommandList.Append( rName, rValue );
211 #endif