Hi Nicole,

Nicole Scholz escribió:
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)

I know nothing about ooRex (shame on me), but did you try with the
following?

xText~insertTextContent(xTextCursor~getStart(), xcontent, .false)

As the error says "Incorrect call to routine". A TextCursor is a
TextRange, but I don't know how casting is implemented in this ooRex
bridge to OOo. So maybe you need to get/query explcitly an XTextRange by

xText~insertTextContent(xTextCursor~getStart(), xcontent, .false)
or
xText~insertTextContent(xTextCursor~XTextRange, xcontent, .false)

... just guessing, as I know nothing about ooRex :-(

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?


any way your code doesn't try insert the field inside the shape, but
inside the document text body.
The Java code below[1] inserts an URL field inside an Ellipse shape,
*BUT* note the issues:

* 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



Regards
Ariel.



[1] (fix line breaks  if copy&paste)

import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.TextContentAnchorType;
import com.sun.star.text.XText;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;

public class Demo {

    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext == null) {
System.err.println("ERROR: Could not bootstrap default Office.");
            }
            XMultiComponentFactory xMCF = xContext.getServiceManager();

            // get the XComponentLoader from the Desktop
            // to load a new document
            XComponentLoader xComponentLoader = (XComponentLoader)
                    UnoRuntime.queryInterface(
                        XComponentLoader.class,
                        xMCF.createInstanceWithContext(
                            "com.sun.star.frame.Desktop", xContext));

            // load a new Writer document
            XTextDocument xTextDocument = (XTextDocument)
                    UnoRuntime.queryInterface(
                        XTextDocument.class,
                        xComponentLoader.loadComponentFromURL(
                            "private:factory/swriter", "_blank",
                            0, new PropertyValue[]{} ) );

            // get the document text body
            XText xDocText = xTextDocument.getText();
            // create a text cursor
            XTextCursor xDocTextCursor = xDocText.createTextCursorByRange(
                    xDocText.getStart());

            // access the document factory to instantiate new objects
            XMultiServiceFactory xDocFactory = (XMultiServiceFactory)
                    UnoRuntime.queryInterface(
                        XMultiServiceFactory.class, xTextDocument);

            // create a shape
            XShape xShape = (XShape) UnoRuntime.queryInterface(
                    XShape.class, xDocFactory.createInstance(
                    "com.sun.star.drawing.EllipseShape"));

            // access the shape's properties
XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xShape );

            xShape.setSize( new Size( 8000, 8000) );
            xShapeProps.setPropertyValue( "AnchorType",
                    TextContentAnchorType.AT_PARAGRAPH);

            // create a text field at the document factory
XPropertySet xTextFieldProps = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xDocFactory.createInstance(
                    "com.sun.star.text.TextField.URL"));

            xTextFieldProps.setPropertyValue(
                    "Representation", "OpenOffice.org API Project");
            xTextFieldProps.setPropertyValue(
                    "TargetFrame", "_blank");
            xTextFieldProps.setPropertyValue(
                    "URL", "http://api.openoffice.org";);

            // get the XTextContent of the shape and the field
XTextContent xShapeTextContent = (XTextContent) UnoRuntime.queryInterface(
                    XTextContent.class, xShape );
XTextContent xFieldTextContent = (XTextContent) UnoRuntime.queryInterface(
                    XTextContent.class, xTextFieldProps );

            // the shape is inserted at the DOCUMENT text
xDocText.insertTextContent(xDocTextCursor, xShapeTextContent, false);

            // access the text inside the shape,
            // and create a text cursor
            XText xShapeText = (XText) UnoRuntime.queryInterface(
                    XText.class, xShape);
            XTextCursor xShapeTextCursor = xShapeText.createTextCursor();

            // insert the field at the SHAPE text
xShapeText.insertTextContent(xShapeTextCursor, xFieldTextContent, false);


        }
        catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }

}




--
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]

Reply via email to