1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwAppletImpl.cxx,v $
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
;
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) )
62 if( rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_align
) ||
63 rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_alt
) )
64 nType
= SWHTML_OPTTYPE_IGNORE
;
66 (rName
.EqualsIgnoreCaseAscii( sHTML_O_archive
) ||
67 rName
.EqualsIgnoreCaseAscii( sHTML_O_Archives
)) )
68 nType
= SWHTML_OPTTYPE_TAG
;
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
;
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
;
87 if( rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_id
) )
88 nType
= SWHTML_OPTTYPE_IGNORE
;
92 if( bApplet
&& rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_mayscript
) )
93 nType
= SWHTML_OPTTYPE_IGNORE
;
97 if( rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_name
) )
98 nType
= SWHTML_OPTTYPE_IGNORE
;
102 if( bApplet
&& rName
.EqualsIgnoreCaseAscii( sHTML_O_Object
) )
103 nType
= SWHTML_OPTTYPE_TAG
;
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
;
113 if( !bApplet
&& rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_type
) )
114 nType
= SWHTML_OPTTYPE_IGNORE
;
118 if( rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_vspace
) )
119 nType
= SWHTML_OPTTYPE_IGNORE
;
123 if( rName
.EqualsIgnoreCaseAscii( OOO_STRING_SVTOOLS_HTML_O_width
) )
124 nType
= SWHTML_OPTTYPE_SIZE
;
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
);
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
) ) );
160 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCodeBase"), uno::makeAny( ::rtl::OUString( sDocBase
) ) );
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
;
186 CreateApplet( aCode
, aName
, bMayScript
, aCodeBase
, rBaseURL
);
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
);
200 uno::Sequence
< beans::PropertyValue
> aProps
;
201 aCommandList
.FillSequence( aProps
);
202 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("AppletCommands"), uno::makeAny( aProps
) );
207 void SwApplet_Impl::AppendParam( const String
& rName
, const String
& rValue
)
209 aCommandList
.Append( rName
, rValue
);