2
* AccessODF - Accessibility checker for OpenOffice.org and LibreOffice Writer.
4
* Copyright (c) 2011 by DocArch <http://www.docarch.be>.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation, either version 3 of the
9
* License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
package be.docarch.accessodf.ooo;
23
import java.util.logging.Logger;
24
import java.util.logging.Level;
25
import java.util.logging.Handler;
26
import java.util.logging.FileHandler;
27
import java.util.logging.SimpleFormatter;
29
import com.sun.star.beans.XPropertySet;
30
import com.sun.star.uno.UnoRuntime;
31
import com.sun.star.uno.XComponentContext;
32
import com.sun.star.frame.XModel;
33
import com.sun.star.frame.XFrame;
34
import com.sun.star.frame.XLayoutManager;
35
import com.sun.star.frame.XDesktop;
36
import com.sun.star.lang.XMultiComponentFactory;
37
import com.sun.star.lang.XComponent;
39
import com.sun.star.lang.XSingleComponentFactory;
40
import com.sun.star.registry.XRegistryKey;
41
import com.sun.star.lib.uno.helper.WeakBase;
42
import com.sun.star.lib.uno.helper.Factory;
44
import be.docarch.accessodf.Constants;
47
public final class AccessODFAddOn extends WeakBase
48
implements com.sun.star.lang.XInitialization,
49
com.sun.star.frame.XDispatch,
50
com.sun.star.lang.XServiceInfo,
51
com.sun.star.frame.XDispatchProvider
53
private final XComponentContext m_xContext;
54
private com.sun.star.frame.XFrame m_xFrame;
55
private static final String m_implementationName = AccessODFAddOn.class.getName();
56
private static final String[] m_serviceNames = {
57
"com.sun.star.frame.ProtocolHandler" };
59
private static final Logger logger = Logger.getLogger(Constants.LOGGER_NAME);
60
private static final String TMP_NAME = Constants.TMP_PREFIX;
61
private static final File TMP_DIR = Constants.getTmpDirectory();
62
private Handler fh = null;
63
private File logFile = null;
64
private int counter = 0;
66
public AccessODFAddOn( XComponentContext context )
72
logFile = File.createTempFile(TMP_NAME, ".log", TMP_DIR);
73
fh = new FileHandler(logFile.getAbsolutePath());
74
fh.setFormatter(new SimpleFormatter());
75
Logger.getLogger("").addHandler(fh);
76
Logger.getLogger("").setLevel(Level.FINEST);
78
} catch (java.io.IOException ex) {
79
logger.log(Level.SEVERE, null, ex);
80
} catch (RuntimeException ex) {
81
logger.log(Level.SEVERE, null, ex);
86
public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
87
XSingleComponentFactory xFactory = null;
89
if ( sImplementationName.equals( m_implementationName ) )
90
xFactory = Factory.createComponentFactory(AccessODFAddOn.class, m_serviceNames);
94
public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
95
return Factory.writeRegistryServiceInfo(m_implementationName,
100
// com.sun.star.lang.XInitialization:
101
public void initialize( Object[] object )
102
throws com.sun.star.uno.Exception
104
if ( object.length > 0 )
106
m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
107
com.sun.star.frame.XFrame.class, object[0]);
111
// com.sun.star.frame.XDispatch:
112
public void dispatch( com.sun.star.util.URL aURL,
113
com.sun.star.beans.PropertyValue[] aArguments ) {
115
logger.info(String.valueOf(counter++));
117
if ( aURL.Protocol.startsWith("be.docarch.accessodf.ooo.accessodfaddon")) {
119
if ( aURL.Path.compareTo("TaskPanelCommand") == 0 ) {
123
XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(
124
XMultiComponentFactory.class, m_xContext.getServiceManager());
125
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
126
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
127
XComponent doc = (XComponent)xDesktop.getCurrentComponent();
129
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, doc);
130
XFrame xFrame = xModel.getCurrentController().getFrame();
131
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
132
XPropertySet.class, xFrame);
133
XLayoutManager xLayoutManager = (XLayoutManager) UnoRuntime.queryInterface(
134
XLayoutManager.class, xPropertySet.getPropertyValue("LayoutManager"));
136
String toolPanel = "private:resource/toolpanel/be.docarch.accessibility.ooo.toolpanel";
138
if (xLayoutManager.isElementVisible(toolPanel)) { // geeft altijd false
139
xLayoutManager.hideElement(toolPanel);
141
xLayoutManager.showElement(toolPanel);
144
} catch (Exception e) {
145
logger.log(Level.SEVERE, null, e);
153
public void addStatusListener( com.sun.star.frame.XStatusListener xControl,
154
com.sun.star.util.URL aURL )
156
// add your own code here
159
public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,
160
com.sun.star.util.URL aURL )
162
// add your own code here
165
// com.sun.star.lang.XServiceInfo:
166
public String getImplementationName() {
167
return m_implementationName;
170
public boolean supportsService( String sService ) {
171
int len = m_serviceNames.length;
173
for( int i=0; i < len; i++) {
174
if (sService.equals(m_serviceNames[i]))
180
public String[] getSupportedServiceNames() {
181
return m_serviceNames;
184
// com.sun.star.frame.XDispatchProvider:
185
public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
186
String sTargetFrameName,
189
if ( aURL.Protocol.startsWith("be.docarch.accessodf.ooo.accessodfaddon"))
191
if ( aURL.Path.compareTo("TaskPanelCommand") == 0 )
197
// com.sun.star.frame.XDispatchProvider:
198
public com.sun.star.frame.XDispatch[] queryDispatches(
199
com.sun.star.frame.DispatchDescriptor[] seqDescriptors )
201
int nCount = seqDescriptors.length;
202
com.sun.star.frame.XDispatch[] seqDispatcher =
203
new com.sun.star.frame.XDispatch[seqDescriptors.length];
205
for( int i=0; i < nCount; ++i )
207
seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,
208
seqDescriptors[i].FrameName,
209
seqDescriptors[i].SearchFlags );
211
return seqDispatcher;