Vidyasagar Venkatachalam wrote:
Hi,
Hi,
I'm a newbie to OpenOffice.org API.
Could anyone let me know how to convert text data into Open Document
format using OpenOffice,org API ?
i.e. Let us say we have a text - "Hi, Welcome to OpenOffice.org world!".
Using OpenOffice.org API how to generate the following documents for
storing the above text in Open Document format?
content.xml
meta.xml
settings.xml
styles.xml
META-INF\manifest.xml
You can simply use import / export filters to load the document as a
text file and store as OpenDocument file. The OpenDocument file saved is
basically just a ZIP file containing all of the sub streams (
context.xml, meta.xml, ... ) you have mentioned above.
Just use XComponentLoader.loadComponentFromURL with import filter
settings for a plain text file to load the text data and
XStorable.storeToURL with export filter settings for your target format
( eg. OpenDocument text file ) to save it.
Examples for both methods can be found in the following java codesnippets:
http://codesnippets.services.openoffice.org/Office/Office.OpenDocumentFromURL.snip
http://codesnippets.services.openoffice.org/Office/Office.ConvertDocuments.snip
And there is a basic codesnippet showing how to set encoding options for
the writer import filter for example
http://codesnippets.services.openoffice.org/Writer/Writer.ImportingAPlainTextEncodedWithAGivenCharacterSet.snip
http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XComponentLoader.html
http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XStorable.html
An Alternative to doing that would be to create an empty document using
a URL like "private:factory/swriter" as parameter to the
loadComponentFromURL method and than get a com.sun.star.text.Text
service for the document and use it´s com.sun.star.text.XText interface
to insert some text.
http://api.openoffice.org/docs/common/ref/com/sun/star/text/Text.html
http://api.openoffice.org/docs/common/ref/com/sun/star/text/XText.html
Other UNO Interfaces you need for doing that are XTextDocument and
XTextCursor
http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextDocument.html
http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextCursor.html
The code doing it would be like in the following java example:
private static void createTextDocument() throws
java.lang.Exception {
PropertyValue[] pPropValues = new
PropertyValue[2];
pPropValues[0] = new PropertyValue();
pPropValues[0].Name = "Hidden";
pPropValues[0].Value = new
Boolean(true);
xComponent =
xComponentLoader.loadComponentFromURL("
private:factory/swriter", "_blank", 0,
pPropValues);
XTextDocument xTextDocument =
(XTextDocument)UnoRuntime.queryInterfac
e(XTextDocument.class, xComponent);
XText xText = xTextDocument.getText();
XTextCursor xTextCursor =
xText.createTextCursor();
xText.insertString(xTextCursor, "Hi, Welcome to OpenOffice.org world!",
false);
}
Than again use XStorable.storeToURL to store the OpenDocument including
the generation of all it´s substreams you have been mentioning.
Another Alternative to create an OpenDocument file from text content
would be to not be using the OpenOffice.org API but instead using odfdom
from http://www.odftoolkit.org to create an empty document, insert the
text and than save it. The java classes included there again would take
care of creating the substreams like content.xml, settings.xml, ... of
the stored OdfDocument.
Your help is highly appreciated.
Thanks,
Sagar.
IBM India Pvt. Ltd .
Fortius Block,FB-2F-B156,First Technology Place,
EPIP White Field,Bangalore-560066.
Off: +91-80 226-70476
Mob: +91-97399-82566
Fax: +91-80 226-70266
Email: [email protected]
PTC Home Page: ptc.hursley.ibm.com
Kind regards,
Bernd Eilers
Sun Microsystems, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]