List Info

Thread: copy Paragraph content with markup (java api)




copy Paragraph content with markup (java api)
user name
2007-03-09 17:29:56
Hi list,

I 'm looping through a document, and I want to
"merge" some
paragraphs, ie past the contents of a paragraph in anothor.
I want to
keep the markup (italic, bold etc).
I think I got the right methods, yet I get
a "unknown text content" exception.  This seems to
be a recurring problem

(see eg.
http://www.oooforum.org/forum/viewtopic.phtm
l?t=51317&highlight=
)


My code looks like this

while ( xParaEnum.hasMoreElements() )
        {
        	
com.sun.star.uno.Any currElement = (Any)
xParaEnum.nextElement();

XTextContent paragraph = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, currElement);

...

    			
//This WORKS, but layout is lost
//mxDocText.insertString(
previousText.getAnchor().getEnd(),
//   paragraph.getAnchor().getString() , false );

//This gives execpton
mxDocText.insertTextContent (
previousText.getAnchor().getEnd(),
paragraph, false);



Exception:

com.sun.star.lang.IllegalArgumentException: unknown text
content
	at
com.sun.star.lib.uno.environments.remote.Job.remoteUnoReques
tRaisedException(Job.java:275)
	at
com.sun.star.lib.uno.environments.remote.Job.execute(Job.jav
a:141)
	at
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQ
ueue.java:377)
	at
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQ
ueue.java:346)
	at
com.sun.star.lib.uno.environments.remote.JavaThreadPool.ente
r(JavaThreadPool.java:106)
	at
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.
sendRequest(java_remote_bridge.java:860)
	at
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.
sendRequest(java_remote_bridge.java:809)
	at
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handle
r.request(ProxyFactory.java:159)
	at
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handle
r.invoke(ProxyFactory.java:141)
	at $Proxy7.insertTextContent(Unknown Source)
	

any clues, alternatives ?

thx !

Dominique

FYI: my enumerator is initialized like in the examples:

        XTextDocument mxDoc =
(XTextDocument)UnoRuntime.queryInterface(
            XTextDocument.class, source);

        // get a reference to the body text of the document
        XText mxDocText = mxDoc.getText();


        // Here, we access this interface
        XEnumerationAccess xParaAccess =
(XEnumerationAccess)
           
UnoRuntime.queryInterface(XEnumerationAccess.class,
mxDocText );
        // Call the XEnumerationAccess's only method to
access the actual
        // Enumeration
        XEnumeration xParaEnum =
xParaAccess.createEnumeration();

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-12 02:18:33
Hi Dominique,
Dominique De Munck schrieb:
> Hi list,
> 
> I 'm looping through a document, and I want to
"merge" some
> paragraphs, ie past the contents of a paragraph in
anothor. I want to
> keep the markup (italic, bold etc).

maybe the com.sun.star.datatransfer.XTransferableSupplier is
the best 
fitting interface for those purposes.

Peter

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-19 13:03:04
Hi,

Thx for the lead.
However, I don't find any indication how to use this
XTransferableSupplier interface.
Unfortunatly, the "currentController" does not
support this interface,
as you thought in
the following thread:


http://www.nabble.com/Sub-Document-Creation-Problem-(Jav
a)-t3407774.html

On another thread, they used the clipboard for such
operations, see eg.

http://www.oooforum.org/forum/viewtopic.phtml?t=10548

however I do not find any information how to put some
selected text in
the clipboard, or "paste" information via the
XClipboard interface or
its derivates. Yet I looked through  the dev guide and the
Clipboard
examples.

The only thing  that I can get working is the same stuff
they used in
the first link, using uno calls:

 xDispatchHelper.executeDispatch(
                                      xDispatchProvider,
                                     
".uno:Paste",
                                      "",
                                      0,
                                      new
PropertyValue[0]);


I'm having the impression that the Java interface does not
allow easy
copy paste instructions ?
I'll be using the Uno-calls for now...

thx,


Dominique



On 3/12/07, Peter Eberlein <pet.eberefofd.verwalt-berlin.de> wrote:
> Hi Dominique,
> Dominique De Munck schrieb:
> > Hi list,
> >
> > I 'm looping through a document, and I want to
"merge" some
> > paragraphs, ie past the contents of a paragraph in
anothor. I want to
> > keep the markup (italic, bold etc).
>
> maybe the
com.sun.star.datatransfer.XTransferableSupplier is the best
> fitting interface for those purposes.
>
> Peter
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail: dev-helpapi.openoffice.org
>
>


-- 
--
tel: (32)/(0)486 23 81 33

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-20 02:41:25
Dominique De Munck wrote:

> Hi,
> 
> Thx for the lead.
> However, I don't find any indication how to use this
> XTransferableSupplier interface.
> Unfortunatly, the "currentController" does
not support this interface,
> as you thought in
> the following thread:
> 
> 
http://www.nabble.com/Sub-Document-Creation-Problem-(Jav
a)-t3407774.html

This interface ATM is supported only in Writer. The usage is
simple:

obj = ThisComponent.CurrentController.getTransferable()

retrieves the current selection and stores it into the
variable "obj".
If you wanted to paste it into a new blank document you
could do:

dim noargs()
doc = StarDesktop.loadComponentFromURL( 
	"private:factory/swriter","_blank",0,no
args())
doc.CurrentController.insertTransferable(obj)

At least Calc will also support this interface in OOo2.3.

Ciao,
Mathias


-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
Please don't reply to "nospamformbagmx.de".
I use it for the OOo lists and only rarely read other mails
sent to it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-20 04:57:32
I'm working in Java and I'm not able to get those objects.
Are those
fields private or something ?
XComponent (= return type of loadComponentFromURL) does not
offer any
field "CurrentController".

XTextDocument has a a method getCurrentController() , but
this returns a
XController, and a cast to XTransferableSupplier  gives me
an error.



On 3/20/07, Mathias Bauer <nospamforMBAgmx.de> wrote:
> Dominique De Munck wrote:
>
> > Hi,
> >
> > Thx for the lead.
> > However, I don't find any indication how to use
this
> > XTransferableSupplier interface.
> > Unfortunatly, the "currentController"
does not support this interface,
> > as you thought in
> > the following thread:
> >
> > 
http://www.nabble.com/Sub-Document-Creation-Problem-(Jav
a)-t3407774.html
>
> This interface ATM is supported only in Writer. The
usage is simple:
>
> obj =
ThisComponent.CurrentController.getTransferable()
>
> retrieves the current selection and stores it into the
variable "obj".
> If you wanted to paste it into a new blank document you
could do:
>
> dim noargs()
> doc = StarDesktop.loadComponentFromURL( 
>        
"private:factory/swriter","_blank",0,noa
rgs())
> doc.CurrentController.insertTransferable(obj)
>
> At least Calc will also support this interface in
OOo2.3.
>
> Ciao,
> Mathias
>
>
> --
> Mathias Bauer (mba) - Project Lead OpenOffice.org
Writer
> OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
> Please don't reply to "nospamformbagmx.de".
> I use it for the OOo lists and only rarely read other
mails sent to it.
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail: dev-helpapi.openoffice.org
>
>


-- 
--
tel: (32)/(0)486 23 81 33

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-20 02:51:34
Hi Dominique,

Dominique De Munck schrieb:
> Hi,
> 
> Thx for the lead.
> However, I don't find any indication how to use this
> XTransferableSupplier interface.
> Unfortunatly, the "currentController" does
not support this interface,
> as you thought in
> the following thread:
> 

ok, let's try:

If you have selected your XTextRange, you can get the
transferable with

XTransferableSupplier xTransferableSupplier = 
(XTransferableSupplier) 			UnoRuntime.queryInterface(
     		XTransferableSupplier.class,
     		document.getCurrentController()
         );

XTransferable xTransferable =
xTransferableSupplier.getTransferable();

The same way you can insert your xTransferable on another
selection 
(maybe in another document):
xTransferableSupplier.insertTransferable(xTransferable);


Peter

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-20 13:25:08
Dominique De Munck wrote:

> I'm working in Java and I'm not able to get those
objects. Are those
> fields private or something ?
> XComponent (= return type of loadComponentFromURL) does
not offer any
> field "CurrentController".

Of course. You have to use the css.frame.XModel interface of
the
returned component.

> XTextDocument has a a method getCurrentController() ,
but this returns a
> XController, and a cast to XTransferableSupplier  gives
me an error.

You mean calling queryInterface from it, right? Casting
doesn't work here.

That's exactly the right object. Which version of OOo are
you using?

Ciao,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
Please don't reply to "nospamformbagmx.de".
I use it for the OOo lists and only rarely read other mails
sent to it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-21 06:28:20
Hi Mathias, Peter,

Thx for all the help, I got it finally working!
I tried in the past the queryInterface to get to our
XTransferableSupplier  but then I got stuck since the
resulting
xTransferable was empty. You must select contents first
apparently.

I'm using a XTextViewCursor for this, don't know how/if you
can this
more cleanly.

This is my code snippet for all you out there,  which 
copies the code
of one document to another (yes there is a
insertDocumentFromURL code
snippet also).
I will use it also for my paragraphs (just  select the
textRange via
the aragraph.getAnchor()).

			XComponent xComponent_sourceDoc =
xComponentLoader.loadComponentFromURL(
						url_odt_contents,
						"_blank",
						0,
						myProperties);
			
			XComponent xComponent_targetDoc =
xComponentLoader.loadComponentFromURL(
					url_template,
					"_blank",
					0,
					myProperties);
			
			
			XTextDocument xTextDocument_sourceDoc = (XTextDocument)
			UnoRuntime.queryInterface(XTextDocument.class,
xComponent_sourceDoc);
		
			
			XTextDocument xTextDocument_targetDoc = (XTextDocument)
			UnoRuntime.queryInterface(XTextDocument.class,
xComponent_targetDoc);
		
		    //the controllers
		    XController xController_sourceDoc =
xTextDocument_sourceDoc.getCurrentController();
		    XController xController_targetDoc =
xTextDocument_targetDoc.getCurrentController();
		
            //the cursor for the source document
		    XTextViewCursorSupplier xViewCursorSupplier_sourceDoc
=
(XTextViewCursorSupplier)
           
UnoRuntime.queryInterface(XTextViewCursorSupplier.class,
xController_sourceDoc);

            //selecting the whole source document
		    XTextViewCursor xTextViewCursor_sourceDoc =
xViewCursorSupplier_sourceDoc.getViewCursor();
            xTextViewCursor_sourceDoc.gotoEnd(true);


            //getting the data supplier of our source doc
            XTransferableSupplier
xTransferableSupplier_sourceDoc =
            	(XTransferableSupplier)
UnoRuntime.queryInterface(
            	               XTransferableSupplier.class,
            	               xController_sourceDoc
            	        );
            //saving the selected contents
            XTransferable xTransferable =
xTransferableSupplier_sourceDoc.getTransferable();

            //getting the data supplier of our target doc
            XTransferableSupplier
xTransferableSupplier_targetDoc =
                	(XTransferableSupplier)
UnoRuntime.queryInterface(
                	              
XTransferableSupplier.class,
                	               xController_targetDoc
                	        );
            	
            //the cursor for the target document
		    XTextViewCursorSupplier xViewCursorSupplier_targetDoc
=
(XTextViewCursorSupplier)
           
UnoRuntime.queryInterface(XTextViewCursorSupplier.class,
xController_targetDoc);
		    //going to the end of the source document
		    XTextViewCursor xTextViewCursor_targetDoc =
xViewCursorSupplier_targetDoc.getViewCursor();
		    xTextViewCursor_targetDoc.gotoEnd(false);
		    //inserting the source document there
		   
xTransferableSupplier_targetDoc.insertTransferable(xTransfer
able);



On 3/20/07, Mathias Bauer <nospamforMBAgmx.de> wrote:
> Dominique De Munck wrote:
>
> > I'm working in Java and I'm not able to get those
objects. Are those
> > fields private or something ?
> > XComponent (= return type of loadComponentFromURL)
does not offer any
> > field "CurrentController".
>
> Of course. You have to use the css.frame.XModel
interface of the
> returned component.
>
> > XTextDocument has a a method
getCurrentController() , but this returns a
> > XController, and a cast to XTransferableSupplier 
gives me an error.
>
> You mean calling queryInterface from it, right? Casting
doesn't work here.
>
> That's exactly the right object. Which version of OOo
are you using?
>
> Ciao,
> Mathias
>
> --
> Mathias Bauer (mba) - Project Lead OpenOffice.org
Writer
> OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
> Please don't reply to "nospamformbagmx.de".
> I use it for the OOo lists and only rarely read other
mails sent to it.
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail: dev-helpapi.openoffice.org
>
>


-- 
--
tel: (32)/(0)486 23 81 33

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: copy Paragraph content with markup (java api)
user name
2007-03-21 12:13:23
Dominique De Munck wrote:

> Hi Mathias, Peter,
> 
> Thx for all the help, I got it finally working!
> I tried in the past the queryInterface to get to our
> XTransferableSupplier  but then I got stuck since the
resulting
> xTransferable was empty. You must select contents first
apparently.

Of course. The transferable is a representation of the
currently
selected content. If nothing is selected an empty
transferable seems to
be a valid representation of it.

And this object "freezes" the current selection -
if you put it aside
and change the selection you have to retrieve the
transferable again to
now get the content of the current selection.

Ciao,
Mathias

-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/Gu
llFOSS
Please don't reply to "nospamformbagmx.de".
I use it for the OOo lists and only rarely read other mails
sent to it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1-9]

about | contact  Other archives ( Real Estate discussion Medical topics )