Am Donnerstag, den 29.07.2010, 23:10 +0200 schrieb Christian Lohmaier:
> Hallo Jochen, *,
> 
> 2010/7/29 Jochen Georges <gnu...@gnugeo.de>:
> >
> > ich möchte aus einer Java-Applikation heraus ein OO-Text (odt) erzeugen.
> > Das Dokument soll möglichst "im Hintergrund", also ohne sichtbares
> > Erscheinen von OO, erzeugt und gespeichert werden.

...snip...
> 
> > # Kann man mit Java auch "direkt" UNO ansprechen, also nur mit Java und
> > OO, ohne zusätzliche "toolkits"?
> 
> Klar. auch im Hintergrund. (mit -headless und/oder -invisible)
>
super 

...snip...

> >        - praktikabelste? (kleine libs, non-geek-geeignet)
> 
> Praktikabel für wen? Für die, die das Teil programmieren sollen, oder
> für die, die das nacher dann benutzen?

Für den Nutzer. Das Programm soll erstens schön klein bleiben, also
keine riesigen Monsterbibliotheken mitbringen und zweitens keine
Installationsorgien vom Nutzer verlangen.

> Java und OOo Programmierung: Da gibts entsprechende Einbindung in
> Netbeans und Eclipse, das OOo-SDK braucht man aber in beiden Fällen
> (um es zu programmieren), zum Ausführen reicht dann ein installiertes
> OOo.

Das klingt gut.

Diese Möglichkeit gefällt mir am besten (keine zusätzlichen Libs,
zukunfstsicher).
Mit NiceOfficeAccess habe ich einen erfolgreichen ersten Test: ein
Writer-Dokument wird geöffnet und eine math. Formel wird dargestellt.

Ich habe aber leider keine Ahnung, wie ich das nur mit Java und OO
hinbekommen kann.
Zwar habe ich etwas gefunden, wie man mit Java Makros schreibt 
(http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Writing_Macros),
aber noch nichts zu Java-Applikationen.
Kennt ihr eine kleines "JavaApplication-OO-HelloWorld"?
Gerne mit einer kurzen Anleitung (Voraussetzungen, Claspath, ..)

...snip...

> Oha - schwieriges Thema, da bleibt wohl nur OOo fernzusteuern. (warst
> Du es, der die Frage bzgl. Formeln und odftoolkit gestellt hat,

Ja.
Zur Darstellug einer math. Formel wird ein EmbeddedObject erzeugt und
dieses EmbeddedObject bekommt eine CLSID mit dem Wert
"078B7ABA-54FC-457F-8551-6147e776a997".
Dieser Wert definiert das EmbeddedObject als math. Formel.
Das erscheint mir ganz schön abenteuerlich, vor allem - weil ich in der
OO-API dazu nichts finden kann.
Wo sind diese Werte festgelegt?

Vielen Dank für alle Tipps!

Beste Grüße
Jochen


/**
 * 
 * From Markus Krueger NOA-Forum
http://ubion.ion.ag/mainForumFolder/noa_forum/0214/
 * Original name was "Math.java"
 * 
 * The code is unchanged, but the comments are added by gnugeo
 * 
 */
import java.util.HashMap;

import ag.ion.bion.officelayer.application.IOfficeApplication;
import ag.ion.bion.officelayer.application.OfficeApplicationRuntime;
import ag.ion.bion.officelayer.document.DocumentDescriptor;
import ag.ion.bion.officelayer.document.IDocument;
import ag.ion.bion.officelayer.document.IDocumentService;
import ag.ion.bion.officelayer.text.ITextDocument;

import com.sun.star.beans.XPropertySet;
import com.sun.star.document.XEmbeddedObjectSupplier2;
import com.sun.star.frame.XController;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.TextContentAnchorType;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextViewCursor;
import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.uno.UnoRuntime;

public class SimpleFormula {

        //where OO is installed
        private final static String OPEN_OFFICE_ORG_PATH =
"/usr/local/bin/openoffice.org3/program/soffice";
        //ag.ion.bion.officelayer.application.IOfficeApplication
        public static IOfficeApplication officeAplication     = null;

        public SimpleFormula(){
                HashMap configuration = new HashMap();
                configuration.put(IOfficeApplication.APPLICATION_HOME_KEY,
OPEN_OFFICE_ORG_PATH);
                configuration.put(IOfficeApplication.APPLICATION_TYPE_KEY,
IOfficeApplication.LOCAL_APPLICATION);

                try{
                        
//ag.ion.bion.officelayer.application.OfficeApplicationRuntime.getApplication:
                        //Returns office application on the basis of the 
submitted
configuration.
                        officeAplication =
OfficeApplicationRuntime.getApplication(configuration);

                        
//ag.ion.bion.officelayer.application.IOfficeApplication.activate:
                        //Activates office application.
                        officeAplication.activate();

                        //ag.ion.bion.officelayer.document.IDocumentService
                        IDocumentService documentService =
officeAplication.getDocumentService();

                        //ag.ion.bion.officelayer.document.IDocument
                        
//ag.ion.bion.officelayer.document.IDocumentService.constructNewDocument:
                        //Constructs new document.
                        IDocument doc = (IDocument)
documentService.constructNewDocument(IDocument.WRITER,
                                        DocumentDescriptor.DEFAULT);

                        //com.sun.star.lang.XMultiServiceFactory
                        //Factories support this interface creating instances 
giving a name,
e.g. a service name.
                        
                        //com.sun.star.uno.UnoRuntime.queryInterface: 
                        //Queries the given UNO object for the given UNO 
interface type. 
                        
                        
//ag.ion.bion.officelayer.document.IDocument.getXComponent:
                        //Returns com.sun.star.lang.XComponent, the 
OpenOffice.org XComponent
interface.
                        XMultiServiceFactory xMultiServiceFactory = 
                                (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class,doc.getXComponent());

                        //com.sun.star.text.XTextContent : 
                        //enables objects to be inserted into a text and to 
provide their
location in a text 
                        //once they are inserted into it. 
                        XTextContent embeddedObject = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class,

xMultiServiceFactory.createInstance("com.sun.star.text.TextEmbeddedObject"));
                        
                        //com.sun.star.beans.XPropertySet: 
                        //provides information about and access to the 
properties from an
implementation.
                        XPropertySet props = 
                                (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class,
embeddedObject);
                        
                        //this CLSID stands for a formula object and makes the 
embeddedObject
to a formula
                        //I did not find informations in the OO-API :-(
                        props.setPropertyValue("CLSID",
"078B7ABA-54FC-457F-8551-6147e776a997");
                        props.setPropertyValue("AnchorType",
TextContentAnchorType.AS_CHARACTER);

                        //com.sun.star.frame.XModel:
                        //represents a component which is created from an URL 
and arguments.
                        XModel xModel = (XModel) 
UnoRuntime.queryInterface(XModel.class,
doc.getXComponent());
                        
                        //com.sun.star.frame.XController:
                        //With this interface, components viewed in a Frame can 
serve events
(by supplying dispatches). 
                        XController xController = xModel.getCurrentController();
                        
                        //com.sun.star.text.XTextViewCursorSupplier:
                        //supplies access to the cursor in the view 
                        XTextViewCursorSupplier xTextViewCursorSupplier = 
                                (XTextViewCursorSupplier)
UnoRuntime.queryInterface(XTextViewCursorSupplier.class,xController);
                        
                        //com.sun.star.text.XTextViewCursor:
                        //describes a cursor in a text document's view. 
                        XTextViewCursor viewCursor = 
xTextViewCursorSupplier.getViewCursor();
                        
                        //com.sun.star.text.XTextCursor:
                        //extends a text range by method to modify its 
position. 
                        XTextCursor xTextCursor =
viewCursor.getText().createTextCursorByRange(viewCursor.getStart());
                        
                        //com.sun.star.text.XTextRange:
                        //describes the object's position in a text.
                        XTextRange range = xTextCursor.getStart();
                        
                        //com.sun.star.text.XTextRange.getText:
                        //returns the text interface in which the text position 
is contained.
                        range.getText().insertTextContent(range, 
embeddedObject, false);

                        //com.sun.star.document.XEmbeddedObjectSupplier2:
                        //represents something that provides an embedded object.
                        XEmbeddedObjectSupplier2 xEmbeddedObjectSupplier = 
                                (XEmbeddedObjectSupplier2)
UnoRuntime.queryInterface(XEmbeddedObjectSupplier2.class,embeddedObject);
                        
                        //com.sun.star.lang.XComponent:
                        //allows to exclicitly free resources and break cyclic 
references.
                        XComponent xEmbeddedObjectModel =
xEmbeddedObjectSupplier.getEmbeddedObject();

                        //see above
                        XPropertySet xFormulaProperties = 
                                (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,xEmbeddedObjectModel);
                        xFormulaProperties.setPropertyValue("Formula", "1 
{5}over{9} + 3
{5}over{9} = 5 {1}over{9}");
                }catch (Exception exception){
                        exception.printStackTrace();
                }
        }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@de.openoffice.org
For additional commands, e-mail: dev-h...@de.openoffice.org

Antwort per Email an