On 11/17/06, Stephan Bergmann <[EMAIL PROTECTED]> wrote:
Tabish F. Mufti wrote:
> ------------------------------------------------------------------------
>
> #ifndef __com_sun_star_ex_comp_Sentence_idl__
> #define __com_sun_star_ex_comp_Sentence_idl__
>
>
> // Avoid redefinition of already included types or interface, for
instance,
> // the following case, com/sun/star/foo/Bar.idl have XSentence interface
> // definition.
>
> #ifndef __com_sun_star_foo_Bar_idl__
> #include "XSentence.idl"
> #endif
You do not need the above include, the below forward declaration is
enough.
> module com { module sun { module star { module ex { module comp {
>
> interface com::sun::star::ex::comp::XSentence;
> singleton theSentence:XSentence
missing ;
> }; }; }; }; };
>
> #endif
>
>
> ------------------------------------------------------------------------
>
> /*
> * SentenceProtocolHandler.java
> *
> * Protocol Handler
> *
> * $Id: SentenceProtocolHandler.java,v 1.1.1.1 2005/11/04 05:57:10
toshi Exp $
> */
>
>
/*************************************************************************
> *
> * The Contents of this file are made available subject to the terms of
> * the BSD license.
> *
> * Copyright (c) 2004-2005 SAITOU Toshihide <[EMAIL PROTECTED]>
> * All rights reserved.
> *
> * Redistribution and use in source and binary forms, with or without
> * modification, are permitted provided that the following conditions
> * are met:
> * 1. Redistributions of source code must retain the above copyright
> * notice, this list of conditions and the following disclaimer.
> * 2. Redistributions in binary form must reproduce the above copyright
> * notice, this list of conditions and the following disclaimer in
the
> * documentation and/or other materials provided with the
distribution.
> * 3. The name of the author may be used to endorse or promote products
> * derived from this software without specific prior written
permission.
> *
> * THIS SOFTWARE IS PROVIDED BY SAITOU Toshihide AND CONTRIBUTORS "AS
IS"
> * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO,
> * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR
> * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SAITOU Toshihide OR
> * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL,
> * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
> * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF
> * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> *
> *************************************************************************/
>
> // Integrate Components into OpenOffice.org
> //
> // To call from OpenOffice.org user interface, it must be able to take
> // part in the communication between the UI layer and the application
> // objects. OpenOffice.org uses command URLs for this purpose.
> // ...
> // From version 1.1, OpenOffice.org provides user interface support
> // for custom components by two basic mechanisms:
> // (Developer's Guide June 2003, Sun Microsystems, Inc, pp. 230.)
> //
> // 1. Add components that can be enabled to process command URLs
> // (a) make a protocol handler for them(command URLs)
> // (b) integrate them into the job execution environment
> //
> // 2. The user interface can be adjust to new components.
> // In short replacement. This also means, it is possible to
> // disable existing command. This dose not need a additional
> // components differ from the 1.
> //
> // * This example is 1. (a).
>
> package com.sun.star.ex.comp;
> // For the above this component implements as inner class with
> // Sentence component. Look the work directory and the Sentence.java.
>
> import com.sun.star.ex.comp.XSentence;
>
> import com.sun.star.beans.PropertyValue;
> import com.sun.star.container.XIndexAccess;
> import com.sun.star.frame.DispatchDescriptor;
> 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.lang.XInitialization;
> import com.sun.star.lang.XMultiComponentFactory;
> import com.sun.star.lang.XServiceInfo;
> import com.sun.star.lib.uno.helper.ComponentBase;
> import com.sun.star.text.XTextRange;
> import com.sun.star.uno.UnoRuntime;
> import com.sun.star.uno.XComponentContext;
> import com.sun.star.util.URL;
>
>
> /** SentenceProtocolHandler service implementation */
>
> public class SentenceProtocolHandler
> extends ComponentBase
> implements XServiceInfo,
> XDispatchProvider,
> XInitialization
> {
>
> /** points to the component context in which this handler object
creates,
> is set in SentenceProtocolHandler(). constructor
> */
> private XComponentContext xContext;
>
> /** points to the frame context in which this handler runs, is set
in
> initialize()
> */
> private XFrame xFrame;
>
>
> /** Dispatch object as inner class */
> class OwnDispatch implements XDispatch {
>
> /** take over all necessary parameters from outside. */
> public OwnDispatch(XComponentContext context, XFrame frame) {
> xContext = context;
> xFrame = frame;
> }
>
> /** execute the functionality, which is described by this URL. */
> public void dispatch(URL aURL, PropertyValue[] lArgs)
> {
> try
> {
>
> // ------------------------------
> // creates an instance of the XSentence
>
> //XMultiComponentFactory factory =
xContext.getServiceManager();
> //Object transObj =
factory.createInstanceWithContext("/singletons/com.sun.star.ex.comp.theSentence",
xContext);
> //XSentence sentence =
(XSentence)UnoRuntime.queryInterface(XSentence.class, transObj);
>
> XSentence sentence = theSentence.get(xContext);
XSentence and theSentence are both in package com.sun.star.ex.comp.
> System.out.println("In dispatch in ProtocolHandler: "
+ aURL.Protocol);
>
> if (aURL.Protocol.equals("Reverse:"))
> {
> //call reverse method of Sentence service
> sentence.reverse();
> }
> else if (aURL.Protocol.equals("myInput:"))
> {
> //call getInput method of Sentence service
> sentence.getInput();
>
> }
> else
> {
> //targetText = aURL.Main.toString();
> aURL.Main.toString();
> }
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> }
>
> /** register a new listener and bind it toe given URL. */
> public void addStatusListener(XStatusListener l, URL url)
> {}
>
> /** deregister a listener for this URL. */
> public void removeStatusListener(XStatusListener l, URL url)
> {}
>
> }
>
>
> /** initialize a new instance of this class with default values. */
> public SentenceProtocolHandler( XComponentContext context )
> {
> xContext = context;
> }
>
>
> // ------------------------------------------------------------
>
> /** XInitialization implementation */
>
> public void initialize(Object[] object) throws
com.sun.star.uno.Exception
> {
>
> if (object.length > 0)
> {
> xFrame = (XFrame)UnoRuntime.queryInterface(XFrame.class,
object[0]);
> }
> }
>
>
> // ------------------------------------------------------------
>
> /** XDispatchProvider implementation */
>
> // should return a valid dispatch object for the given URL.
> //
> // In case the URL is not valid an empty reference can be
returned. The
> // parameter sTarget and nFlags can be ignored. These will be
"_self" and 0
> // everytime.
> // (Developer's Guide June 2003, Sun Microsystems, Inc, pp. 236.)
>
> public XDispatch queryDispatch(com.sun.star.util.URL aURL, String
sTarget, int nFlags )
> {
> System.out.println("In queryDispatch in ProtocolHandler: " +
aURL.Protocol);
>
> if (aURL.Protocol.equals("Reverse:"))
> {
> return new OwnDispatch( xContext, xFrame );
> }
> if (aURL.Protocol.equals("myInput:"))
> {
> return new OwnDispatch( xContext, xFrame );
> }
> return null;
> }
>
> // optimized API call for remote.
> //
> // It should be forwarded to queryDispatch() for every request item
of the
> // given DispatchDescriptor list.
> //
> // But note: it is not allowed to pack the return list of dispatch
objects.
> // Every request in source list must match to a reference (null or
valid) in
> // the destination list!
> // (Developer's Guide June 2003, Sun Microsystems, Inc, pp. 236.)
>
> public XDispatch[] queryDispatches(DispatchDescriptor[] descs)
> {
> XDispatch[] lDispatcher = new XDispatch[descs.length];
>
> System.out.println("In queryDispatches in ProtocolHandler descs
length: " + descs.length);
>
> for(int i = 0; i < descs.length; ++i ) {
> lDispatcher[i] = queryDispatch(descs[i].FeatureURL,
> descs[i].FrameName,
> descs[i].SearchFlags );
> }
>
> return lDispatcher;
> }
>
>
> // ------------------------------------------------------------
>
> /** XServiceInfo implementation */
>
> static final String SERVICENAME = "
com.sun.star.frame.ProtocolHandler";
>
> public String getImplementationName() {
> return getClass().getName();
> }
>
> public boolean supportsService(String serviceName) {
> if (serviceName.equals(SERVICENAME))
> return true;
> return false;
> }
>
> public String[] getSupportedServiceNames() {
> return new String[] {
> SERVICENAME
> };
> }
>
> }
>
> // End of file.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
I put a semicolon at the end of the line:
singleton theSentence:XSentence
I still get the errors:
/home/tfm/ooo/myAddon/theSentence.idl(15) : Malformed interface declaration:
syntax error, unexpected IDL_SCOPESEPARATOR, expecting ';'
/home/tfm/ooo/myAddon/theSentence.idl(18) : Statement can not be parsed:
interface definition
/home/tfm/ooo/myAddon/theSentence.idl(21) : Illegal syntax following module
export(s): syntax error, unexpected $end, expecting '}'