1 /*************************************************************************
3 * $RCSfile: InspectorAddon.java,v $
7 * last change: $Author: rt $ $Date: 2007-04-04 09:18:17 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
40 import com
.sun
.star
.beans
.XPropertySet
;
41 import com
.sun
.star
.frame
.DispatchDescriptor
;
42 import com
.sun
.star
.frame
.FrameSearchFlag
;
43 import com
.sun
.star
.frame
.XController
;
44 import com
.sun
.star
.frame
.XDesktop
;
45 import com
.sun
.star
.frame
.XDispatch
;
46 import com
.sun
.star
.frame
.XDispatchProvider
;
47 import com
.sun
.star
.frame
.XFrame
;
48 import com
.sun
.star
.frame
.XModel
;
49 import com
.sun
.star
.frame
.XStatusListener
;
50 import com
.sun
.star
.lang
.XInitialization
;
51 import com
.sun
.star
.lang
.XServiceInfo
;
52 import com
.sun
.star
.lang
.XSingleComponentFactory
;
53 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
54 import com
.sun
.star
.registry
.XRegistryKey
;
55 import com
.sun
.star
.uno
.UnoRuntime
;
56 import com
.sun
.star
.uno
.XComponentContext
;
57 import com
.sun
.star
.lib
.uno
.helper
.Factory
;
60 public class InspectorAddon
{
61 /** This class implements the component. At least the interfaces XServiceInfo,
62 * XTypeProvider, and XInitialization should be provided by the service.
64 public static class InspectorAddonImpl
extends WeakBase
implements XDispatchProvider
, XInitialization
, XServiceInfo
{
65 private static XModel xModel
= null;
66 org
.openoffice
.XInstanceInspector xInstInspector
= null;
67 // Dispatcher oDispatcher = null;
68 XFrame m_xFrame
= null;
70 private static final String
[] m_serviceNames
= {
71 "org.openoffice.InstanceInspectorAddon",
72 "com.sun.star.frame.ProtocolHandler" };
74 private XComponentContext m_xContext
= null;
76 /** Creates a new instance of InspectorAddon */
77 public InspectorAddonImpl(XComponentContext _xContext
) {
78 m_xContext
= _xContext
;
81 public XDispatch
queryDispatch( /*IN*/com
.sun
.star
.util
.URL aURL
, /*IN*/String sTargetFrameName
, /*IN*/int iSearchFlags
) {
82 XDispatch xRet
= null;
83 if ( aURL
.Protocol
.compareTo("org.openoffice.Office.addon.Inspector:") == 0 ) {
84 if ( aURL
.Path
.compareTo( "inspect" ) == 0 ){
85 // Todo: Check if the frame is already administered (use hashtable)
86 xRet
= new Dispatcher(m_xFrame
);
93 public XDispatch
[] queryDispatches( /*IN*/DispatchDescriptor
[] seqDescripts
) {
94 int nCount
= seqDescripts
.length
;
95 XDispatch
[] lDispatcher
= new XDispatch
[nCount
];
96 for( int i
=0; i
<nCount
; ++i
)
97 lDispatcher
[i
] = queryDispatch( seqDescripts
[i
].FeatureURL
, seqDescripts
[i
].FrameName
, seqDescripts
[i
].SearchFlags
);
102 public void initialize( Object
[] object
) throws com
.sun
.star
.uno
.Exception
{
103 if ( object
.length
> 0 ){
104 m_xFrame
= ( XFrame
) UnoRuntime
.queryInterface(XFrame
.class, object
[ 0 ] );
108 public class Dispatcher
implements XDispatch
{
109 private XFrame m_xFrame
= null;
110 private XModel xModel
= null;
112 public Dispatcher(XFrame _xFrame
){
114 if (m_xFrame
!= null){
115 XController xController
= m_xFrame
.getController();
116 if (xController
!= null){
117 xModel
= xController
.getModel();
123 public void dispatch( /*IN*/com
.sun
.star
.util
.URL _aURL
, /*IN*/com
.sun
.star
.beans
.PropertyValue
[] aArguments
) {
125 if ( _aURL
.Protocol
.compareTo("org.openoffice.Office.addon.Inspector:") == 0 ){
126 if ( _aURL
.Path
.equals("inspect")){
127 Object oUnoInspectObject
= xModel
;
128 com
.sun
.star
.lang
.XMultiComponentFactory xMCF
= m_xContext
.getServiceManager();
129 if (xInstInspector
== null){
130 Object obj
= xMCF
.createInstanceWithContext("org.openoffice.InstanceInspector", m_xContext
);
131 xInstInspector
= (org
.openoffice
.XInstanceInspector
)UnoRuntime
.queryInterface(org
.openoffice
.XInstanceInspector
.class, obj
);
133 if ((m_xFrame
== null) || (xModel
== null)){
134 Object oDesktop
= xMCF
.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext
);
135 m_xFrame
= (XFrame
) UnoRuntime
.queryInterface(XFrame
.class, oDesktop
);
136 oUnoInspectObject
= m_xFrame
;
138 XPropertySet xFramePropertySet
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class, m_xFrame
);
139 String sTitle
= (String
) xFramePropertySet
.getPropertyValue("Title");
140 String
[] sTitleList
= sTitle
.split(" - ");
141 if (sTitleList
.length
> 0){
142 sTitle
= sTitleList
[0];
144 xInstInspector
.inspect(oUnoInspectObject
, sTitle
);
147 } catch( Exception e
) {
148 System
.err
.println( e
+ e
.getMessage());
149 e
.printStackTrace(System
.out
);
152 public void addStatusListener( /*IN*/XStatusListener xControl
, /*IN*/com
.sun
.star
.util
.URL aURL
) {
155 public void removeStatusListener( /*IN*/XStatusListener xControl
, /*IN*/com
.sun
.star
.util
.URL aURL
) {
162 public static String
[] getServiceNames() {
163 return m_serviceNames
;
166 // Implement the interface XServiceInfo
167 /** Get all supported service names.
168 * @return Supported service names.
170 public String
[] getSupportedServiceNames() {
171 return getServiceNames();
174 // Implement the interface XServiceInfo
175 /** Test, if the given service will be supported.
176 * @param sService Service name.
177 * @return Return true, if the service will be supported.
179 public boolean supportsService( String sServiceName
) {
180 int len
= m_serviceNames
.length
;
182 for( int i
=0; i
< len
; i
++) {
183 if ( sServiceName
.equals( m_serviceNames
[i
] ) )
190 // Implement the interface XServiceInfo
191 /** Get the implementation name of the component.
192 * @return Implementation name of the component.
194 public String
getImplementationName() {
195 return InspectorAddonImpl
.class.getName();
202 * Gives a factory for creating the service.
203 * This method is called by the <code>JavaLoader</code>
205 * @return returns a <code>XSingleComponentFactory</code> for creating
207 * @param sImplName the name of the implementation for which a
209 * @see com.sun.star.comp.loader.JavaLoader
211 public static XSingleComponentFactory
__getComponentFactory( String sImplName
)
213 XSingleComponentFactory xFactory
= null;
214 if ( sImplName
.equals( InspectorAddonImpl
.class.getName() ) )
215 xFactory
= Factory
.createComponentFactory(InspectorAddonImpl
.class, InspectorAddonImpl
.getServiceNames());
220 * Writes the service information into the given registry key.
221 * This method is called by the <code>JavaLoader</code>
223 * @return returns true if the operation succeeded
224 * @param regKey the registryKey
225 * @see com.sun.star.comp.loader.JavaLoader
227 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
228 return Factory
.writeRegistryServiceInfo(InspectorAddonImpl
.class.getName(), InspectorAddonImpl
.getServiceNames(), regKey
);
231 // __create( XComponentContext ){