| View previous topic :: View next topic |
| Author |
Message |
ooodummy. Guest
|
Posted: Mon Dec 22, 2003 5:13 am Post subject: Problems with uno:url for document internal macros |
|
|
Hi all,
i've written a small javaprogram, thats automatically opens a writertemplate and fills it with text and data... At least it has to execute a macro which do some simple formatings in an table in this temnplate before the doc is exported to pdf....I've inserted this macro in an global module/library so far...the uno:url for that is no problem....but i want to include this macro in the template, but i have difficulties with the url i have to call for an internal macro...
i've tried multible different style....for example:
macro:///Unnamed1/MyModule.MyLibrary.MyMacro
macro:///Unnamed1.MyModule.MyLibrary.MyMacro
macro:///Templatename.swt/MyModule.MyLibrary.MyMacro...and so on...
can somebody give me a small hint, how the currect url has to look like???
greetings,
ooodummy... |
|
| Back to top |
|
 |
Guest
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Dec 22, 2003 11:49 am Post subject: |
|
|
I create a new drawing. I did NOT save it to disk. In the Untitled drawing, I created a library named Meow, and a module named Mix. Within Mix is a function...
| Code: | Sub HelloWorld( cParam1, cParam2 )
Print "Hello World P1=|" + cParam1 + "| , P2=|" + cParam2 + "|"
End Sub
|
Now I can execute the macro of this untitled document like this....
| Code: | soffice.exe "macro://Untitled/Meow.Mix.HelloWorld(Giddy,Gat)"
|
A small Print dialog appears with this text...
| Code: | Hello World P1=|Giddy|, P2=|Gat|
[OK] [Cancel] |
Note that "Untitled" is inbetween the 2nd and 3rd slashes.
Note the strange way in which string parameters are handed from the URL to the formal arguments of the routine.
Hope this helps. Very few animals were harmed to discover this information. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
ooodummy Guest
|
Posted: Tue Dec 23, 2003 1:13 am Post subject: |
|
|
Hi Danny,
i do nearly the same from my small javaprog...
1.step: create new instance from exisiting writer template including the macros... (working)
2.step: fill some data/textfields/tables in this doc via uno and java... (working)
3.step: execute one document internal macro for some formatings...(NOT Working... )
4.step: export the doc as pdf...(working..)
everything is working...one step 3 makes problems...
here the code of my function that should handles the execution of my macro...
| Code: |
// Query the frame for right interface which provides access to all
// available dispatch objects.
private XDispatchProvider getXDispatchProvider() {
if (xDispatchProvider==null) {
XModel xModel = (XModel) UnoRuntime.queryInterface (
XModel.class, xDocument);
XController xController = xModel.getCurrentController();
XFrame xFrame = xController.getFrame();
xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (
XDispatchProvider .class, xFrame);
}
return xDispatchProvider;
}
private URL getURL(String pURL) throws Exception {
// Create and parse a valid URL
// Note: because it is an in/out parameter we must use an array of URLs
XURLTransformer xParser = (XURLTransformer)UnoRuntime.queryInterface (
XURLTransformer.class, openOffice.createInstance("com.sun.star.util.URLTransformer" ));
com.sun.star.util.URL[] aParseURL = new com.sun.star.util.URL[1];
aParseURL[0] = new com.sun.star.util.URL();
aParseURL[0].Complete = pURL;
xParser.parseStrict (aParseURL);
return aParseURL[0];
}
public boolean dispatch(String pOperationURL) throws Exception {
boolean answer = false;
XDispatchProvider lXDispatchProvider = getXDispatchProvider();
DispatchDescriptor[] dd = new DispatchDescriptor[1];
URL lURL = getURL(pOperationURL);
dd[0] = new DispatchDescriptor(lURL,"",0);
XDispatch[] dispatches = lXDispatchProvider.queryDispatches(dd );
try {
lURL = getURL(pOperationURL);
} catch (Exception e) {
e.printStackTrace();
System.out.println("URL ist fehlerhaft!!!! \n" +e.toString() );
}
if (dispatches!=null) {
int iD = dispatches.length;
XDispatch lXDispatcher = null;
System.out.println(iD + " Dispatches für URL gefunden!!!");
for (int i =0; i<iD;i++) {
lXDispatcher = dispatches[i];
}
if(lXDispatcher!=null) {
PropertyValue[] lProperties = new PropertyValue[0];
lXDispatcher.dispatch (lURL,lProperties);
answer = true;
} else {
System.out.println("ERROR: Dispatcher == NULL");
}
} else {
System.out.println("ERROR: DispatchProvider == NULL");
}
return answer;
}
|
A typical call looks like that...
| Code: |
....
myTmpOODoc.dispatch("macro:///Untitled/MyLibrary.MyModule.MyMacro");
....
|
But everytime i call it, it returns true, claimed that it had worked... But it doesnet...
Are there any naming differences between the englishversion and the germanversion???
Ist the a way the set "debugmode=on" in openoffice ans study some logs in ooo???
greetings
ooodummy |
|
| Back to top |
|
 |
ooodummy Guest
|
Posted: Tue Dec 23, 2003 5:11 am Post subject: |
|
|
Hi all,
somebody said..if it dont work..make it simpler...
so i did make it simpler...according to the apidocs this should work...but it doesn't...
| Code: |
private XDispatchProvider getXDispatchProvider() {
if (xDispatchProvider==null) {
XModel xModel = (XModel) UnoRuntime.queryInterface (XModel.class, xDocument);
XController xController = xModel.getCurrentController();
XFrame xFrame = xController.getFrame();
xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);
}
return xDispatchProvider;
}
private URL getURL(String pURL) throws Exception {
XURLTransformer xParser = (XURLTransformer)UnoRuntime.queryInterface ( XURLTransformer.class, openOffice.createInstance("com.sun.star.util.URLTransformer" ));
com.sun.star.util.URL[] aParseURL = new com.sun.star.util.URL[1];
aParseURL[0] = new com.sun.star.util.URL();
aParseURL[0].Complete = pURL;
xParser.parseStrict (aParseURL);
return aParseURL[0];
}
public boolean dispatch(String pOperationURL) throws Exception {
URL aURL = getURL(pOperationURL);
XDispatchProvider mxFrame =getXDispatchProvider();
XDispatch xDispatcher = mxFrame.queryDispatch(aURL,"", com.sun.star.frame.FrameSearchFlag.GLOBAL);
if(xDispatcher!=null) {
xDispatcher.dispatch(aURL, new PropertyValue[0]);
return true;
} else {
return false;
}
|
thanks for your help and...merry x-mas to all of you....
ooodummy |
|
| Back to top |
|
 |
ooodummy Guest
|
Posted: Mon Dec 29, 2003 11:11 pm Post subject: |
|
|
Hi DannyB,
according to your pices of code, i tried another way to execue the macro...
here's the code...
| Code: |
try {
// BasicScript Macro für Tabellen aufrufen...(Hintergrund der Tabelle "einfärben")
// TODO: Performancemessung
//Externer Aufruf mit MakroUrl...
String os = System.getProperty("os.name");
if (os.startsWith("Windows")) {
os = "Windows";
}
String command = myProperties.getProperty("openOffice.exec."+os, null);
String newcommand = new StringTokenizer(command,"-",false).nextToken();
String[] test1 = new String[2];
test1[0] = newcommand.trim();
test1[1] = "macro://Unbenannt1/Library1.Tables.HintergrundHervorheben";
log.debug("Starte Macroprozess mit Befehl: " + test1[0] + " " + test1[1] );
Process myMacroProcess = Runtime.getRuntime().exec(test1);
// wenn prozess gestartet dann warte kurz das er arbeiten kann.
if (myMacroProcess != null) {
log.debug("Warte auf Makroprozess");
myMacroProcess.waitFor();
if (myMacroProcess.exitValue() == 0 ) {
log.debug("Makroprozess fertig (exitValue = 0)");
} else{
log.error("Makroprozess liefert Errorcode:" + myMacroProcess.exitValue());
}
} else {
log.error("Makroprozess ist NULL.");
}
// für den GC freigeben
myMacroProcess.destroy();
myMacroProcess = null;
} catch (Exception e) {
log.error("HintergrundHervorhebenMacro schlug mit einer Exception fehl:" + e.toString() + e.getMessage());
}
|
But it still doesn't work as expected....
When i start OOo in "headless" mode the code runs sucessfull, but the macro wasn't executes. It only workes when i start OOo in normalmode without headless and invisible. But then i have to change the name of the document in the call from Unbenannt1 to Unbenannt2, because OOo start with one empty writerdoc automatically...
Is this correct or is it a Bug??? When i start OOo (soffice) without any params it starts without an open docs, but when using -accept.... it opens a writerdoc by default....???
Are the more diffences between the normal startup and the headless startup than just the lack of the GUI????
Greetings ooodummy.... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|