Monday, April 12, 2010

convert microsoftword to docbook(xml) openoffice - java

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.comp.helper.BootstrapException;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XCloseable;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;


public class Save
{
public static void main(String args[])
{
// Get the remote office component context
try {
XComponentContext xContext = Bootstrap.bootstrap();

// Get the remote office service manager
XMultiComponentFactory xMCF = xContext.getServiceManager();

// Get the root frame (i.e. desktop) of openoffice framework.
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);

// Desktop has 3 interfaces. The XComponentLoader interface provides ability to load components.
XComponentLoader xCLoader = ( XComponentLoader ) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);

PropertyValue[] myProperties = new PropertyValue[1];
myProperties[0] = new PropertyValue();
myProperties[0].Name = "Hidden";
// for open document and do not show user interface use "true"
myProperties[0].Value = new Boolean(false);

// Create a document
XComponent document = xCLoader.loadComponentFromURL("file:///F:/Rajesh/convert/Java1.5.doc", "_blank", 0, myProperties);





String storeUrl = "file:///F:/Rajesh/convert/Java1.5.xml";
// Save the document
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "DocBook File";

xStorable.storeAsURL(storeUrl, storeProps);
// close document
document.dispose();
XCloseable xcloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document);
if(xcloseable!=null)
{
xcloseable.close();
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BootstrapException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

2 comments:

www.bogy.in said...

தமிழர்கள் அனைவருக்கும் தமிழ் புத்தாண்டு வாழ்த்துக்கள்

இந்த ஆண்டு உங்கள் வாழ்வில் எல்லையில்லா மகிழ்ச்சியும், நோயற்ற வாழ்வும், குறைவற்ற செல்வமும், நீண்ட ஆயுளும் மற்றும் அனைத்து நலங்களும், வளங்களும் பெற்று வாழ வாழ்த்துகிறோம்.

அன்புடன்
www.bogy.in

Anonymous said...

I would like to exchange links with your site rajeshkannanforindia.blogspot.com
Is this possible?