|
List Info
Thread: Registering an XMailMergeListener - possible at all?
|
|
| Registering an XMailMergeListener -
possible at all? |

|
2007-02-09 08:58:37 |
Hi *,
Before I waste my time again I'd rather ask here:
Is it possible at all to register a mail-merge Listener?
My first attempts failed. I don't get any events/the method
notifyMailMergeEvent of my listener never is called.
Trying the same with a TerminateListener (as described in
the
Developer's guide) works fine. The methods are called.
The relevand Docs:
file:///opt/openoffice.org2.1_sdk/docs/common/ref/com/sun/st
ar/text/MailMerge.html
file:///opt/openoffice.org2.1_sdk/docs/common/ref/com/sun/st
ar/text/XMailMergeBroadcaster.html
file:///opt/openoffice.org2.1_sdk/docs/common/ref/com/sun/st
ar/text/XMailMergeListener.html
http://api.openoffice.org/docs/common
/ref//com/sun/star/text/MailMerge.html
http://api.openoffice.org
/docs/common/ref//com/sun/star/text/XMailMergeBroadcaster.ht
ml
http://api.openoffice.org/do
cs/common/ref//com/sun/star/text/XMailMergeListener.html
ciao
Christian
--
NP: Bif Naked - Any Day Now
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-12 04:19:27 |
Christian Lohmaier wrote:
> Hi *,
>
> Before I waste my time again I'd rather ask here:
> Is it possible at all to register a mail-merge
Listener?
>
> My first attempts failed. I don't get any events/the
method
> notifyMailMergeEvent of my listener never is called.
>
>
Hi,
at least the code (sw/source/ui/uno/unomailmerge.cxx,
sw/source/ui/dbui/dbmgr.cxx) says it is possible
I didn't verify that it actually works but added listeners
should be
notified for each print/save operation that is done.
Regards,
Oliver
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-13 07:50:41 |
Hi Oliver, *,
On Mon, Feb 12, 2007 at 11:19:27AM +0100, Oliver Specht
wrote:
> Christian Lohmaier wrote:
> >
> >Before I waste my time again I'd rather ask here:
> >Is it possible at all to register a mail-merge
Listener?
> >
> >My first attempts failed. I don't get any
events/the method
> >notifyMailMergeEvent of my listener never is
called.
>
> at least the code (sw/source/ui/uno/unomailmerge.cxx,
> sw/source/ui/dbui/dbmgr.cxx) says it is possible
>
> I didn't verify that it actually works but added
listeners should be
> notified for each print/save operation that is done.
I guess then it's time to show my code, maybe I just do
something very
wrong and you can point me to the right direction:
package org.openoffice.cloph.postnet.comp;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.lib.uno.helper.Factory;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.text.MailMergeEvent;
import com.sun.star.text.XMailMergeBroadcaster;
import com.sun.star.text.XMailMergeListener;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public final class PostNetJavaImpl extends WeakBase
implements com.sun.star.lang.XServiceInfo,
org.openoffice.cloph.postnet.XPostnetjava
{
private final XComponentContext m_xContext;
private static final String m_implementationName =
PostNetJavaImpl.class.getName();
private static final String[] m_serviceNames = {
"org.openoffice.cloph.postnet.Postnetjava"
};
public PostNetJavaImpl( XComponentContext context )
{
m_xContext = context;
};
public static XSingleComponentFactory
__getComponentFactory( String sImplementationName ) {
XSingleComponentFactory xFactory = null;
if ( sImplementationName.equals(
m_implementationName ) )
xFactory =
Factory.createComponentFactory(PostNetJavaImpl.class,
m_serviceNames);
return xFactory;
}
public static boolean __writeRegistryServiceInfo(
XRegistryKey xRegistryKey ) {
return
Factory.writeRegistryServiceInfo(m_implementationName,
m_serviceNames,
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 static class MailmergeEventListener implements
XMailMergeListener {
public void notifyMailMergeEvent(MailMergeEvent
mergeEvent) {
System.out.println("Listener called ");
}
}
// org.openoffice.cloph.postnet.XPostnetjava:
public void addMMEListener()
{
MailmergeEventListener MMListener = new
MailmergeEventListener();
XMultiComponentFactory xMCF =
m_xContext.getServiceManager();
Object mailMerge = null;
try {
mailMerge = xMCF.createInstanceWithContext(
"com.sun.star.text.MailMerge",
m_xContext);
} catch (Exception e) {
e.printStackTrace();
}
XMailMergeBroadcaster xMMB = null;
xMMB = (XMailMergeBroadcaster) UnoRuntime.queryInterface(
XMailMergeBroadcaster.class, mailMerge);
xMMB.addMailMergeEventListener(MMListener);
System.out.println("added listener");
}
}
ciao
Christian
--
NP: nichts
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-14 12:14:37 |
Hi Christian,
perhaps I am getting this wrong, because you shortened your
code to post
it here, but: you add a listener to a MailMerge object and
then throw
the object away?
Second, exactly what kind of event do you want to be
notified of?
Regards, Steffen
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-14 13:32:33 |
Hi Steffen,
On Wed, Feb 14, 2007 at 07:14:37PM +0100, Steffen Grund
wrote:
thank you for having a look!
> perhaps I am getting this wrong, because you shortened
your code to post
> it here, but: you add a listener to a MailMerge object
and then throw
> the object away?
Hmm - I don't mean to throw it away. I'm a novice, and I
don't see where
I throw it away. If you say it is thrown away, then this is
very likely
my problem, although with a terminate listener that way
works.
> Second, exactly what kind of event do you want to be
notified of?
? I don't have a choice to choose between events, do I?
There only is
that one listener with only that single notify-method.
But here's what I intend to do:
I want to write an extension for issue
http://www.openoffice.org/issues/show_bug.cgi?id=5948
to insert PostNet
Barcodes for envelopes.
A while back I hacked something together that used autoTexts
made of
drawing shapes to insert the barcode. That was a hackish
method that is
rather slow.
I now rewrote that thing in java and use barcode4j to
generate the
barcode in png format and insert the image into the
document. This is
much faster than the autotext approach.
But to be useful, this needs to be hooked-up to the
mailmerge, otherwise
you would have to manually print each envelope.
Wo what I hope for is a way to get notified with "Hey,
this doc is about
to get printed/saved: Do something with it", and then
my extensions gets
the chance to parse the address and insert the barcode and
proceed to
the next doc, or alternatively: Here's all the merged docs
in one single
document: Do something with it".
If the MailMerge-Listener is not the way to go here, what
else would you
suggest?
ciao
Christian
--
NP: Linkin Park - Hit The Floor
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-14 16:22:45 |
Am Mittwoch, den 14.02.2007, 20:32 +0100 schrieb Christian
Lohmaier:
> On Wed, Feb 14, 2007 at 07:14:37PM +0100, Steffen Grund
wrote:
>
> thank you for having a look!
>
> > perhaps I am getting this wrong, because you
shortened your code to post
> > it here, but: you add a listener to a MailMerge
object and then throw
> > the object away?
>
> Hmm - I don't mean to throw it away. I'm a novice, and
I don't see where
> I throw it away. If you say it is thrown away, then
this is very likely
> my problem, although with a terminate listener that way
works.
>
>From your other mail:
> // org.openoffice.cloph.postnet.XPostnetjava:
> public void addMMEListener()
> {
> MailmergeEventListener MMListener = new
MailmergeEventListener();
>
> XMultiComponentFactory xMCF =
m_xContext.getServiceManager();
>
> Object mailMerge = null;
^ here you define an object only visible in this
method
> try {
> mailMerge =
xMCF.createInstanceWithContext(
>
"com.sun.star.text.MailMerge", m_xContext);
> } catch (Exception e) {
> e.printStackTrace();
> }
now the empty object reference has a value
> XMailMergeBroadcaster xMMB = null;
> xMMB = (XMailMergeBroadcaster)
UnoRuntime.queryInterface(
> XMailMergeBroadcaster.class,
mailMerge);
here the value get's used
> xMMB.addMailMergeEventListener(MMListener);
> System.out.println("added
listener");
> }
... and if this exit point is reached the object is lost
because there
is no further reference to it. I don't know if the object is
really
needed, but if you want to store it you have to hold a
reference in a
variable, otherwise the java garbage collector will dispose
it at it's
next run.
You could simply do:
public final class PostNetJavaImpl extends WeakBase
implements com.sun.star.lang.XServiceInfo,
org.openoffice.cloph.postnet.XPostnetjava
{
private final XComponentContext m_xContext;
private static final String m_implementationName =
PostNetJavaImpl.class.getName();
private static final String[] m_serviceNames = {
"org.openoffice.cloph.postnet.Postnetjava"
};
--> private static final(?) Object mailMerge = null;
and only assign the retrieved object in the method
"addMMEListener()" to
it. This way the object stays alive until it's getting
disposed manually
or by disposing the surrounding "PostNetJavaImpl"
object.
That's the way java works. C++ is similar. It's one reason
for inventing
reference counting on object instances.
HTH,
Marc
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-16 11:41:59 |
Hi Marc, *,
On Wed, Feb 14, 2007 at 11:22:45PM +0100, Marc Santhoff
wrote:
> Am Mittwoch, den 14.02.2007, 20:32 +0100 schrieb
Christian Lohmaier:
> > On Wed, Feb 14, 2007 at 07:14:37PM +0100, Steffen
Grund wrote:
> > >[throwing away the mail-merge-object]
>
> >From your other mail:
> [variable scope: only within the method]
>
> ... and if this exit point is reached the object is
lost because there
> is no further reference to it. I don't know if the
object is really
> needed, but if you want to store it you have to hold a
reference in a
> variable, otherwise the java garbage collector will
dispose it at it's
> next run.
Hmm - Thanks for pointing this out, but I don't think the
object is
still necessary (but I'm not sure about this, so I tried
what you
suggested
> You could simply do:
>
> public final class PostNetJavaImpl extends WeakBase
> implements com.sun.star.lang.XServiceInfo,
>
org.openoffice.cloph.postnet.XPostnetjava
> {
> private final XComponentContext m_xContext;
>
> private static final String m_implementationName =
PostNetJavaImpl.class.getName();
> private static final String[] m_serviceNames = {
>
"org.openoffice.cloph.postnet.Postnetjava" };
>
> --> private static final(?) Object mailMerge =
null;
That unfortunately did not make any difference.
Does anybody have the solution or even a working sample at
hand?
I'd really appreciate it.
ciao
Christian
--
NP: As I Lay Dying - Meaning In Tragedy
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-16 13:54:13 |
Hi Christian,
>
> Does anybody have the solution or even a working sample
at hand?
> I'd really appreciate it.
>
> ciao
> Christian
> --
> NP: As I Lay Dying - Meaning In Tragedy
You'll find a sample (OOoBasic) here:
http://www.oooforum.org/forum/viewtopic.phtml?t=8393
Perhaps it helps you.
HTH
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-16 14:00:17 |
Am Freitag, den 16.02.2007, 18:41 +0100 schrieb Christian
Lohmaier:
> Hi Marc, *,
Hi Christian,
> Does anybody have the solution or even a working sample
at hand?
> I'd really appreciate it.
I did post another message quickly after the first one,
because I saw
that your solution could not work imo the way it is. That
message never
reached the list, so I quote it here again:
> Von:
> Marc Santhoff
> <M.Santhoff t-online.de>
> An:
> dev api.openoffice.org
> Betreff:
> Re: [api-dev] Registering an
> XMailMergeListener - possible at
> all?
> Datum:
> Wed, 14 Feb 2007 23:45:55 +0100
>
> Hi, me again,
>
> from reading your code I think you're on the Holzweg,
this
> implmentation
> cannot work.
>
> You create a mailmerge object instance, register the
listener and
> forget
> about the mailmerger.
>
> Since for each mail merge task a new individual
MailMerge-object is
> created, the listener has to attached to that one in
use currently.
>
> It seems you need to:
>
> - create a MailMerge-instance
> - create your PostNet-Service
> - hand over the MailMerge from the first step to the
PostNetImpl from
> the second step for registration (some method like
> "XPostnetjava.registerTo(MailMerge myMerger)"
or the like
> - start the mail merge
>
> I hope I got this right ...
> Marc
I hope this explanation helps,
Marc
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
| Re: Registering an XMailMergeListener -
possible at all? |

|
2007-02-19 08:43:39 |
Hi Noëlson, Marc, *,
On Fri, Feb 16, 2007 at 04:54:13PM -0300, Noelson Duarte
wrote:
> >
> > Does anybody have the solution or even a working
sample at hand?
> > I'd really appreciate it.
>
> You'll find a sample (OOoBasic) here:
>
http://www.oooforum.org/forum/viewtopic.phtml?t=8393
oProps must be Variant, not object here, but apart form that
this macro
shows that it is possible to use a mailmergelistener.
> Perhaps it helps you.
That snippet, along with Marcs answer "helped"
somewhat:
I know that the mailmerge listener is not suitable for my
case.
If I cannot use the builtin wizard, but have to ask the user
for the
desired Database, etc myself and have to start the mailmerge
from within
my extension, then this would be far too much effort and
thus pretty
useless to me.
If there would be a way to still use the wizard however,
then this could
work...
Mut the mailmerge-object requires a documentURL and other
properties
before it can be executed. (and the documentURL would
require the user
to save the document first, etc...), so I doubt that this is
possible
:-(
So thank you very much for the pointer & answers.
ciao
Christian
--
NP: Marilyn Manson - Kinderfeld
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|
|
|
|