Hi Ariel!
Thank you for your answer about creating hyperlinks within a rectangle. Nice to
know that there is a solution in some cases.
I tried to write a code in ooRex where this also works. But I did not found a
solution. I get an error message when I try to insert the textfield. I think
this is one of the errors you wrote in your mail which will appear.
Here is my code:
****************************************************************
oDesktop = UNO.createDesktop()
xComponentLoader = oDesktop~XDesktop~XComponentLoader
url = "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0,
.UNO~noProps)
xDocumentFactory = xWriterComponent~XMultiServiceFactory
xTextDocument = xWriterComponent~XTextDocument
xText = xTextDocument~getText()
xTextCursor = xText~createTextCursor()
xDMsf = xTextDocument~XMultiServiceFactory
aHyperlinkObj = xDMsf~createInstance("com.sun.star.text.TextField.URL")
xPropSet = aHyperlinkObj~xPropertySet
xPropSet~setPropertyValue("URL", "hihi")
xPropSet~setPropertyValue("Representation", "hyperlink")
xcontent = aHyperlinkObj~xTextContent
-- insert the textfield
xText~insertTextContent(xTextCursor, xcontent, .false)
****************************************************************
This is the error message I get :
****************************************************************
Exception in thread "main" org.apache.bsf.BSFException: /// Java-exception (Rexx
AndJava) occurred: [com.sun.star.lang.IllegalArgumentException: unknown text con
tent] \\\
BSF4Rexx subfunction "invoke": object '[EMAIL PROTECTED]' - method [INSERTTEXTCO
NTENT], method not found or error (exception) executing method!
at org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBSF(RexxAndJava.java:
2764)
at org.rexxla.bsf.engines.rexx.RexxAndJava.jniRexxStart(Native Method)
at org.rexxla.bsf.engines.rexx.RexxEngine.apply(RexxEngine.java:318)
at org.rexxla.bsf.RexxDispatcher.main(RexxDispatcher.java:114)
853 *-* call BSF "invoke", "[EMAIL PROTECTED]", "INSERTTEXTCONTENT" , a.1 , a
.2 , a.3
36 *-* xText~insertTextContent(xTextCursor, xcontent, .false)
Error 40 running a_BSF4Rexx_program line 36: Incorrect call to routine
Error 40.1: External routine "BSF" failed
Exception of type 'org.apache.bsf.BSFException' thrown while invoking Rexx:
36 *-* xText~insertTextContent(xTextCursor, xcontent, .false)
Error 40 running a_BSF4Rexx_program line 36: Incorrect call to routine
Error 40.1: External routine "BSF" failed
****************************************************************
Is there a possibility with java to bypass this error?
Regards
Nicole
-------- Original-Nachricht --------
> Datum: Wed, 30 Jul 2008 14:01:58 -0300
> Von: Ariel Constenla-Haile <[EMAIL PROTECTED]>
> An: [email protected]
> Betreff: Re: [api-dev] Hyperlink within a shape
> Hello Nicole,
>
> Nicole Scholz escribió:
> > Hi!
> >
> > I tried to add a hyperlink to a text within a rectangle. Usually a
> hyperlink is set on the textproperties with setpropertyvalue and then the
> hyperlink for example:
> > xTextProps~setPropertyValue("HyperLinkURL", “www.google.at”)
> >
> > Now I would like to add the hyperlink to a shape. I tried it the same
> way with the xText within the shape.
> >
> > xShapeText = Shape~xText
> > xShapeTextCursor = xShapeText~createTextCursor
> > props = xShapeTextCursor~xPropertySet
> > props~setPropertyValue("HyperLinkURL", “www.google.at”)
> >
> > But this does not work. I get the exception that the method is not
> found. Can someone give me a hint why I get this error and how I can get the
> hyperlink into the shape?
>
> as you have realized, an hyperlink within a shape can not be set as a
> character property of the shape's text.
> You will also realize how to do this if you try in the graphical user
> interface:
>
> * open a new OOo Draw document
> * draw any shape, let's say an ellipse
> * double-click the shape in order to insert text inside it
> * type any URL, for example www.google.at
> * as soon as you press the space key, this text truns into an URL *field*
>
> So the key to the answer is: an hyperlink within a shape is inserted as
> an URL text field.
>
> Sure you have noticed that in Calc/Draw/Impress, when you select the
> menu "Insert" - "Hyperlink", an URL text field is inserted. In
> Draw/Impress case, the field is inside a text shape.
>
> In *theory*, as an API client, you can achieve this doing the following:
>
> * instantiate a shape at the doc. factory
> * add the shape to a draw page
> * instantiate a com.sun.star.text.texfield.URL
> [http://api.openoffice.org/docs/common/ref/com/sun/star/text/textfield/URL.html]
> at the doc. factory
> * get the shape's css.text.XText and insert the field as a text content
>
> In practice, I see the following issues (look at the macros in
> http://www.ArielConstenlaHaile.com.ar/ooo/temp/field_inside_shape.odt):
>
> * Writer:
> * com.sun.star.text.texfield.URL does not figure among the avaible
> services at the doc. factory, nor can be instantiated by this
> name. You have to use "com.sun.star.text.TextField.URL"
> * the document view does not know how to handle them, that is:
> * the pointer does not change from an ARROW to a REFHAND
> when the mouse is over the field
> * the URL is never dispatched when clicking the text field
> * if you double-click the shape to edit its text, then the
> field will look like an hyperlink (pointer changes to
> REFHAND when mouse over), but the URL is not dispatched
>
> * Calc
> * same issue with the service name, in fact all text field services
> names are in uppercase, while the name of the module is
> "textfield", NOT "TextField":
> com.sun.star.text.TextField.URL
> com.sun.star.text.TextField.PageNumber
> com.sun.star.text.TextField.PageCount
> com.sun.star.text.TextField.Date
> com.sun.star.text.TextField.Time
> com.sun.star.text.TextField.DocumentTitle
> com.sun.star.text.TextField.FileName
> com.sun.star.text.TextField.SheetName
> * you can instantiate a com.sun.star.text.TextField.URL at the
> doc.'s factory, but if you try to insert it as text content at a
> shape's XText, then you get an error. Looks like you can insert
> this field only inside a cell, not a shape
> [notice that in the macro I find a way to fool Calc, but that's
> just a trick and not how one must really proceed]
> * if you try in the GUI (drawing a shape, typying an URL inside it,
> etc), the field works as expected; so it's an API issue
>
> * Draw/Impress
> * here the desolation is bigger: there are no text field services
> available at the doc.'s service factory, nor can they be
> instantiated.
>
> Sometimes I have the feeling that some OOo developers don't care much
> about us API clients.
>
> Concerning the Draw/Impress issue, *just* adding the service names in
> the css.lang.XMultiServiceFactory implementation in
> SdXImpressDocument::createInstance() (and
> SdXImpressDocument::getAvailableServiceNames() for the sake of
> completness) in sd/source/ui/unoidl/unomodel.cxx solves the issue:
>
> //*****************************************************************
>
>
> uno::Reference< uno::XInterface > SAL_CALL
> SdXImpressDocument::createInstance( const OUString& aServiceSpecifier )
> throw(uno::Exception, uno::RuntimeException)
> {
> OGuard aGuard( Application::GetSolarMutex() );
>
> if( NULL == mpDoc )
> throw lang::DisposedException();
>
> //...
>
> //-----------------------------------------------------------------------------
>
> // corret case for textfield module
> if( ( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) ) ||
> ( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.DateTime") ) ) )
> {
> return (::cppu::OWeakObject * )new SvxUnoTextField(
> ID_EXT_DATEFIELD );
> }
>
> // add URL field
> if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.URL") ) )
> {
> return (::cppu::OWeakObject * )new SvxUnoTextField( ID_URLFIELD
> );
> }
>
> // add file field
> if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.FileName") ) )
> {
> return (::cppu::OWeakObject * )new SvxUnoTextField(
> ID_EXT_FILEFIELD );
> }
>
> // add author field
> if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.Author") ) )
> {
> return (::cppu::OWeakObject * )new SvxUnoTextField(
> ID_AUTHORFIELD );
> }
>
> // add page number field
> if( 0 == aServiceSpecifier.reverseCompareToAsciiL(
> RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.PageNumber") ) )
> {
> return (::cppu::OWeakObject * )new SvxUnoTextField(
> ID_PAGEFIELD );
> }
>
> //-----------------------------------------------------------------------------
>
> //...
> }
>
>
> //*******************************************************************
>
> uno::Sequence< OUString > SAL_CALL
> SdXImpressDocument::getAvailableServiceNames()
> throw(uno::RuntimeException)
> {
> OGuard aGuard( Application::GetSolarMutex() );
>
> if( NULL == mpDoc )
> throw lang::DisposedException();
>
> const uno::Sequence< OUString > aSNS_ORG(
> SvxFmMSFactory::getAvailableServiceNames() );
>
> uno::Sequence< OUString > aSNS( mbImpressDoc ? (40) : (25) );
>
> sal_uInt16 i(0);
>
> //...
>
> //-----------------------------------------------------------------------------
>
> // text fields
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.DateTime"));
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.DateTime"));
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.URL"));
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.FileName"));
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.Author"));
> aSNS[i++] = OUString(
> RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.PageNumber"));
>
> //-----------------------------------------------------------------------------
>
> //...
> }
>
> //****************************************************************
>
> This works fine (I debug it) because the doc. model and the doc. view
> *already* know how to handle this type of fields I added (one could of
> course think about adding *more* text field types, but one should then
> also modify the relevant parts of code).
>
> I didn't have the time to look at the Writer/Calc sources, but at least
> correcting the services names in Writer sounds easy.
>
> Regards
> Ariel.
>
>
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
> http://www.ArielConstenlaHaile.com.ar/ooo/
>
>
>
> "Aus der Kriegsschule des Lebens
> - Was mich nicht umbringt,
> macht mich härter."
> Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]