Hello Aaron,

On Thursday 09 April 2009, 15:54, Aaron Ehrensberger wrote:
> Any chance you know the corresponding java?  

as OOo API is a language independet specification, you may try to learn how to 
find what you want from 
http://api.openoffice.org/docs/common/ref/com/sun/star/module-ix.html

This would be more constructive than just giving you the Java code for 
copying&pasting.

There you could you go the "Index" for the "P" letter:

http://api.openoffice.org/docs/common/ref/index-files/index-16.html

and you'll find "PageCount"

PageCount - property in service ::com::sun::star::text:: .TextDocumentView
http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextDocumentView.html#PageCount

no idea what the css.text.TextDocumentView is? Well, 
http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextDocumentView.html
 
has a link to the respective documentation in the Dev's Guide:

http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Component/Controllers#Document_Specific_Controller_Services

There you'll learn that css.text.TextDocumentView is the css.frame.Controller 
implementation in Writer, and a link to the more specific 
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Text/Text_Document_Controller
Here you also learn that you get the Controller from the css.frame.XModel.

The whole picture for a Writer document

* if you load the component via css.frame.XComponentLoader, then you have a 
css.lang.XComponent. Query css.frame.XModel from it.

* get the controller from the model via 
css.frame.XModel.getCurrentController()

* you get a generic css.frame.XController reference, but you know you have its 
Writer implementation, a css.text.TextDocumentView. To get its property 
"PageCount", just query the css.beans.XPropertySet from this 
css.frame.XController, and use 
css.beans.XPropertySet.getPropertyValue("PageCount")

in code:

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

            com.sun.star.frame.XComponentLoader xComponentLoader =
                    (com.sun.star.frame.XComponentLoader)
                    com.sun.star.uno.UnoRuntime.queryInterface(
                    com.sun.star.frame.XComponentLoader.class,
                    xContext.getServiceManager().createInstanceWithContext(
                    "com.sun.star.frame.Desktop", xContext));

            com.sun.star.lang.XComponent xComponent =
                    xComponentLoader.loadComponentFromURL(
                    "private:factory/swriter",
                    "_default",
                    com.sun.star.frame.FrameSearchFlag.ALL,
                    new com.sun.star.beans.PropertyValue[0]);

            com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel)
                    com.sun.star.uno.UnoRuntime.queryInterface(
                    com.sun.star.frame.XModel.class, xComponent);

            com.sun.star.frame.XController xController =
                   xModel.getCurrentController();

            com.sun.star.beans.XPropertySet xPropertySet = 
                    (com.sun.star.beans.XPropertySet)
                    com.sun.star.uno.UnoRuntime.queryInterface(
                    com.sun.star.beans.XPropertySet.class, xController);

            int nPageCount = com.sun.star.uno.AnyConverter.toInt(
                    xPropertySet.getPropertyValue("PageCount"));

            System.out.printf("\"PageCount\" = %d%n", nPageCount);

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

notice that instead of simply querying the css.frame.XModel, it¡ll be more 
useful to query the css.text.XTextDocument (that is, Writer's XModel 
implementation):

            com.sun.star.text.XTextDocument xWriterModel =
                    (com.sun.star.text.XTextDocument)
                    com.sun.star.uno.UnoRuntime.queryInterface(
                    com.sun.star.text.XTextDocument.class, xComponent);

            com.sun.star.frame.XController xController =
                   xWriterModel.getCurrentController();



Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to