/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ package com.sun.star.wiki; import com.sun.star.awt.XDialog; import com.sun.star.awt.XWindowPeer; import com.sun.star.beans.PropertyValue; import com.sun.star.frame.DispatchDescriptor; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XController; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XDispatch; import com.sun.star.frame.XDispatchProvider; import com.sun.star.frame.XFrame; import com.sun.star.frame.XModel; import com.sun.star.frame.XStatusListener; import com.sun.star.frame.XStorable; import com.sun.star.io.XInputStream; import com.sun.star.lang.XComponent; import com.sun.star.lang.XInitialization; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.registry.XRegistryKey; import com.sun.star.lib.uno.helper.WeakBase; import com.sun.star.util.XCloseBroadcaster; import com.sun.star.view.XSelectionSupplier; import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.net.ssl.SSLException; public final class WikiEditorImpl extends WeakBase implements com.sun.star.lang.XServiceInfo, XDispatchProvider, XDispatch, XInitialization { private final XComponentContext m_xContext; private static final String m_implementationName = WikiEditorImpl.class.getName(); private static final String[] m_serviceNames = {"com.sun.star.wiki.WikiEditor" }; // information needed for component registration public static final String[] supportedServiceNames = {"com.sun.star.frame.ProtocolHandler"}; public static final Class implementationClass = WikiEditorImpl.class; // protocol name that this protocol handler handles public static final String protocolName = "vnd.com.sun.star.wiki:"; private Map m_statusListeners = new HashMap(); private XComponent xComp; private String sTempUrl; private XFrame m_xFrame; private XModel m_xModel; private Settings m_aSettings; private String m_aFilterName; public WikiEditorImpl( XComponentContext xContext ) { // Helper.trustAllSSL(); m_xContext = xContext; m_aSettings = Settings.getSettings( m_xContext ); }; public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { XSingleComponentFactory xFactory = null; if ( sImplementationName.equals( m_implementationName ) ) xFactory = Factory.createComponentFactory( WikiEditorImpl.class, m_serviceNames ); else if ( sImplementationName.equals( WikiOptionsEventHandlerImpl.m_sImplementationName ) ) xFactory = Factory.createComponentFactory( WikiOptionsEventHandlerImpl.class, WikiOptionsEventHandlerImpl.m_pServiceNames ); return xFactory; } public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) { boolean bResult = Factory.writeRegistryServiceInfo( m_implementationName, m_serviceNames, xRegistryKey ); return ( bResult && Factory.writeRegistryServiceInfo( WikiOptionsEventHandlerImpl.m_sImplementationName, WikiOptionsEventHandlerImpl.m_pServiceNames, xRegistryKey ) ); } // com.sun.star.lang.XServiceInfo: public String getImplementationName() { return m_implementationName; } public boolean supportsService( String sService ) { int len = m_serviceNames.length; for( int i=0; i < len; i++ ) { if ( sService.equals( m_serviceNames[i] )) return true; } return false; } public String[] getSupportedServiceNames() { return m_serviceNames; } private XSelectionSupplier m_sel; private XController m_ctrl; private boolean m_bInitialized; public synchronized void initialize( Object[] args ) throws com.sun.star.uno.Exception { if ( m_bInitialized ) { //logger.log( Level.SEVERE, "Extension instance was initialized again" ); } if ( args.length > 0 ) { m_bInitialized = true; m_xFrame = ( XFrame )UnoRuntime.queryInterface( XFrame.class, args[0] ); // become close listener XCloseBroadcaster cb = ( XCloseBroadcaster )UnoRuntime.queryInterface( XCloseBroadcaster.class, m_xFrame ); } } public void dispatch( final com.sun.star.util.URL aURL, com.sun.star.beans.PropertyValue[] propertyValue ) { final com.sun.star.util.URL myURL = aURL; //logger.log( Level.INFO, "received dispatch request for: "+aURL.Complete ); if ( aURL.Protocol.compareTo( protocolName ) == 0 ) { /* synchronized( this ) { if( m_bClosing ) return; else m_bActive = true; } **/ try { if ( myURL.Path.compareTo( "send" ) == 0 ) { sendArticle(); } } catch( java.lang.Throwable t ) { //logger.log( Level.WARNING, "exception while handling dispatch", t ); } /* synchronized( this ) { m_bActive = false; // if we became owner while we were active // we are responsible for closing the m_xFrame now if ( m_bOwner && m_xFrame != null ) { try { XCloseable xclose = ( XCloseable )UnoRuntime.queryInterface( XCloseable.class, m_xFrame ); xclose.close( true ); } catch ( CloseVetoException cve ) { logger.log( Level.SEVERE, "cannot close owned frame" ); } // relase reference to the m_xFrame; m_xFrame = null; } } */ } } public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL, String str, int param ) { if ( aURL.Protocol.equals( protocolName )) { // by default, we are responsible return this; } else { return null; } } public XDispatch[] queryDispatches( DispatchDescriptor[] seqDescripts ) { int nCount = seqDescripts.length; XDispatch[] lDispatcher = new XDispatch[nCount]; for( int i=0; i