Hi,
By API I mean the OOo API in my question, in this case it is
XStorable::storeAsURL() method. If this method is not able to store a
document it should throw an exception. Which exception is thrown in this
case?
Best regards,
Mikhail.
yaungmin wrote:
Hi,
I don't quite understand your question. I am using Netbeans IDE to write my
programs. I don't pass any arguments to my saveDocument method. See below
for the method that I have so far. I am sure that the method just load a
document from a given location and save it to a different location, which is
not what I wanted to do. I would like to get the current active document and
save it to a given location.
Thanks,
Min
private void saveDocument(){
String loadpath = "C:/Users/min/Desktop/test.odt";
String storepath = "C:/Users/min/Desktop/savetest.odt";
com.sun.star.uno.XComponentContext xContext = gui.m_xContext;
try {
com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext);
com.sun.star.frame.XComponentLoader xCompLoader =
(com.sun.star.frame.XComponentLoader)
UnoRuntime.queryInterface(
com.sun.star.frame.XComponentLoader.class,
oDesktop);
java.io.File sourceFile = new java.io.File(loadpath);
StringBuffer sLoadUrl = new StringBuffer("file:///");
sLoadUrl.append(sourceFile.getCanonicalPath().replace('\\',
'/'));
sourceFile = new java.io.File(storepath);
StringBuffer sSaveUrl = new StringBuffer("file:///");
sSaveUrl.append(sourceFile.getCanonicalPath().replace('\\',
'/'));
com.sun.star.beans.PropertyValue[] propertyValue =
new com.sun.star.beans.PropertyValue[1];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Hidden";
propertyValue[0].Value = new Boolean(true);
Object oDocToStore = xCompLoader.loadComponentFromURL(
sLoadUrl.toString(), "_default", 0, propertyValue );
com.sun.star.frame.XStorable xStorable =
(com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
com.sun.star.frame.XStorable.class, oDocToStore );
propertyValue = new com.sun.star.beans.PropertyValue[ 2 ];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Overwrite";
propertyValue[0].Value = new Boolean(true);
propertyValue[1] = new com.sun.star.beans.PropertyValue();
propertyValue[1].Name = "FilterName";
propertyValue[1].Value = "StarOffice XML (Writer)";
xStorable.storeAsURL( sSaveUrl.toString(), propertyValue );
System.out.println("\nDocument \"" + sLoadUrl + "\" saved under
\"" +
sSaveUrl + "\"\n");
}
catch( Exception e ) {
e.printStackTrace(System.err);
System.exit(1);
}
}
Mikhail Voitenko wrote:
Hi,
Which API are you using currently to let the document be saved? Please
describe the arguments you provide to the API ( if any ) as well.
Best regards,
Mikhail.
yaungmin wrote:
Here is detail information about the project that I am working on.
I am using Java for this add-on program. This program is just for
openoffice.org writer, so I will only working with .odt format. I have
five
buttons on the tool bar which are Login, New, Open, Save and Logout.
After
the user login to the system, they are allowed to create new document,
open
existing document, save current document and logout from the system.
What I have so far is when I click on New, it shows me a new blank
document.
I can type some text on the document but I wasn’t able to save it when I
click on Save button. I will be saving the document to the database in
future but just for testing purpose, I am saving the document to my
desktop.
The format that I would like to save is odt (openoffice.org writer)
format.
Basically yes, I would like to replace the “Save/Save As” functionality
of
OOo, but my program will save to a given database instead of displaying a
file dialog to specify the folder to save in. Yes, I would like to have
my
own function call to save the current document when user click on the
save
button.
My code will be added to openoffice.org as an extension.
I tried to create a separate test program which creates a blank document
and
I saved it right after I created the document. The document was saved to
my
desktop as I specified but the title of the document is still “Untitled 2
–
Openoffice.org Writer” instead of the name of the document that I given.
In additional to that, I tried to type some text in the document and
tried
to save the document again, but additional text that I just typed in
weren’t
saved.
Thank you for your help in advance.
Min
Mathias Bauer wrote:
yaungmin wrote:
I am writing an Openoffice Add-on program which I need to write my own
save
function. Can someone please give me some advice on how to save an
Openoffice writer document which is active on the screen.
Thanks,
Min
With so little information it's close to impossible to give advice. So:
- do you want to have a file dialog to select a file name or folder to
save in?
- in which format or formats do you want to save the file?
- do you want to create a copy of the file or do you intend to replace
the "Save"/"SaveAs" functionality of OOo?
- if the answer to the last question is "yes", do you want your own
function called when the user selects the corresponding command in the
menu or toolbar?
- which programming language do you want to use?
- do you want to add your code to your own private build of OOo or do
you want to create an extension?
I'm sure I can present some more nice questions before I can give you a
*useful* advice, but let's start with those ones. :-9
Ciao,
Mathias
--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[EMAIL PROTECTED]".
I use it for the OOo lists and only rarely read other mails sent to it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]