cancel
Showing results for 
Search instead for 
Did you mean: 

Refresh documents using java api

Solved
Occasional Contributor

Refresh documents using java api

Hello,

 

I want initialize and refresh documents using Java API.

 

I have a MegaCollection with my documents.

MegaCollection listDocs = mgRoot.getSelection("Select [Document]", "Nom");

for (MegaObject oSelection : listDocs) {

// reinitialize and refresh document

}

 Which method use to refresh document.

 

 In VB this code works

oSelection.InitializeDocument oSelection.RefreshDocument

 but I don't know call this method in java.

 

Thanks for the response.

 

--

N. Gibanel

17 Replies
Contributor

Re: Refresh documents using java api

Hi, 

 

Usually, when you know the method in VB, and its equivalent doesn't exist in the Java API, you can use the method callMethod(Object name, Object ... arg) if there's no return or the function callFunction(Object name, Object ... arg) if there's a return. 

 

For you problem, it would probably be something like : 

 

MegaCollection listDocs = mgRoot.getSelection("Select[Document]","Nom");

for(MegaObject oSelection : listDocs)
{
     oSelection.callMethod("InitializeDocument");
     oSelection.callMethod("RefreshDocument");
}

 

This would probably work. 

I hope it helps, 

 

Regards



Patrick Bobo
Occasional Contributor

Re: Refresh documents using java api

Thanks but it doesn't work...

 

I have this error :

Exception in thread "main" com.mega.modeling.api.MegaException: MEGA Error 1
at com.mega.modeling.api.jni.MappModuleJNI.InvokeMethod(Native Method)
at com.mega.modeling.api.jni.ComObjectProxy.invokeMethod(Unknown Source)

 

 

 

 

Contributor

Re: Refresh documents using java api

My bad, the error probably comes from the fact that the method signature includes an "arg" attribute that I didn't set in the sample code I gave you. 

 

This would probably be better :

 

MegaCollection listDocs = mgRoot.getSelection("Select[Document]","Nom");

for(MegaObject oSelection : listDocs)
{
     oSelection.callMethod("InitializeDocument",null);
     oSelection.callMethod("RefreshDocument",null);
}

 



Patrick Bobo
Occasional Contributor

Re: Refresh documents using java api

Ok it's work. 

 

Is there a way to improve performance? (for example doEvent in VB)

 

Thanks for your help.

 

 

--

N. Gibanel 

Contributor

Re: Refresh documents using java api

I'm glad to know that it works Smiley Wink

 

After a quick look in VB's documentation, the function doEvents is used to force the application to yield its processor use for one cycle, so it might slow down a bit your loop.

So what do you mean by "improving the performance" ? Do you want to improve your loop's speed?



Patrick Bobo
Occasional Contributor

Re: Refresh documents using java api

Document refresh takes considerable time (it's longer than manually).

 

Maybe  an optimization of this script ? I don't know.

Contributor

Re: Refresh documents using java api

Unfortunately, the RTF documents are pretty slow in general.

Thus, this script is the best you can do to refresh automatically several documents.

 

 

 



Patrick Bobo
Occasional Contributor

Re: Refresh documents using java api

ok.

thanks for your help.

 

 

--

N.Gibanel

Occasional Contributor

Re: Refresh documents using java api

When I refresh a document, at the end I have this exception launch:

 

com.mega.modeling.api.MegaException: MEGA Error 80040a00

 

but my document seems correct.

 

What means this exception or error code ?

 

Thanks