How best invoke dita ot cmd from custom oxygen plugin
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Hi,
Oxygen XML Editor 23.0
We have written a custom Oxygen plugin to have menu option to display a form(Conversion Form) by extending WorkspaceAccessPluginExtension. On Form submission, we need to invoke a DITA-OT Plugin to convert xml to dita. I am able to extract the input data from user form and prepare a dita-ot command some thing as below.
'C:\dita-ot-2.4.6\bin\dita' \
'--format=xml2dita' \
'-Dxml2.release=21a' \
'--input=/dev/null' \
'-Dargs.input.dir=D:\xml2dita\input' \
'--output=D:\xml2dita\output' |
We have created and installed required custom DITA-OT plugin as well.
How best we can invoke the dita cmd from java? It would be great if you can suggest any pointer. Any best practices to make the Oxygen plugin robust with changes in Oxygen / DITA OT versions and installation paths?
Thanks,
Samba.
Oxygen XML Editor 23.0
We have written a custom Oxygen plugin to have menu option to display a form(Conversion Form) by extending WorkspaceAccessPluginExtension. On Form submission, we need to invoke a DITA-OT Plugin to convert xml to dita. I am able to extract the input data from user form and prepare a dita-ot command some thing as below.
'C:\dita-ot-2.4.6\bin\dita' \
'--format=xml2dita' \
'-Dxml2.release=21a' \
'--input=/dev/null' \
'-Dargs.input.dir=D:\xml2dita\input' \
'--output=D:\xml2dita\output' |
We have created and installed required custom DITA-OT plugin as well.
How best we can invoke the dita cmd from java? It would be great if you can suggest any pointer. Any best practices to make the Oxygen plugin robust with changes in Oxygen / DITA OT versions and installation paths?
Thanks,
Samba.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How best invoke dita ot cmd from custom oxygen plugin
Hi Samba,
If you want to run the DITA OT on your own from the Oxygen plugin you will probably need to start a new process from the Java code:
https://docs.oracle.com/javase/8/docs/a ... ocess.html
We also have two API methods for starting a new process:
ro.sync.exml.workspace.api.WorkspaceUtilities.startProcess(String, File, String, boolean)
ro.sync.exml.workspace.api.WorkspaceUtilities.createProcess(ProcessListener, String, File, String, boolean)
Regards,
Radu
If you want to run the DITA OT on your own from the Oxygen plugin you will probably need to start a new process from the Java code:
https://docs.oracle.com/javase/8/docs/a ... ocess.html
We also have two API methods for starting a new process:
ro.sync.exml.workspace.api.WorkspaceUtilities.startProcess(String, File, String, boolean)
ro.sync.exml.workspace.api.WorkspaceUtilities.createProcess(ProcessListener, String, File, String, boolean)
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Thanks Radu!
Tried with below code,
Error message in the console:
Please suggest clue to escape the space in java code. Some how I don't have luck with caret char(^) as well.
Thanks.
Tried with below code,
Code: Select all
command = "C\\:\\oxygen\\Oxygen XML Editor 23\\frameworks\\dita\\DITA-OT3.x\\bin\\dita" + " --format=xml2dita" + " -Dxml2.release=21a" + " --input=null" + " -Dargs.input.dir=D:\\xml2dita\\input'" + " --output=D:\\xml2dita\\output'";
boolean success = false;
try
{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
System.out.println("Gobbler output: " + pr.getInputStream());
pr.getInputStream();
}
catch(Exception e)
{
System.out.println(e.toString());
e.printStackTrace();
}
Code: Select all
java.io.IOException: Cannot run program "C\:\oxygen\Oxygen^": CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "C\:\oxygen\Oxygen^": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
Thanks.
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
It would be great if you can suggest better way to invoke in built in dita-ot from oxygen plugin. Instead of manually preparing the complete dita cmd as below,
Thanks in advance.
Code: Select all
command = "C\\:\\oxygen\\Oxygen XML Editor 23\\frameworks\\dita\\DITA-OT3.x\\bin\\dita" + " --format=xml2dita" + " -Dxml2.release=21a" + " --input=null" + " -Dargs.input.dir=D:\\xml2dita\\input'" + " --output=D:\\xml2dita\\output'";
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How best invoke dita ot cmd from custom oxygen plugin
Hi,
You can find the path to the DITA OT installation in Oxygen using something like this:
You need to surround in double quotes the path to the DITA OT because it may contain spaces (and it does contain spaces in your case).
So something like this:
If you want to read the input and error streams from the started process you can start threads which read them while the process runs:
https://stackoverflow.com/questions/334 ... ntime-exec
Also that --input=null parameter that you are passing does not look right.
Regards,
Radu
You can find the path to the DITA OT installation in Oxygen using something like this:
Code: Select all
String ditaExecutableCommand = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().expandEditorVariables("${configured.ditaot.dir}", null) + "\\bin\\dita";
So something like this:
Code: Select all
command ="\"" + ditaExecutableCommand + "\"" + .....
https://stackoverflow.com/questions/334 ... ntime-exec
Also that --input=null parameter that you are passing does not look right.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Thanks Radu!
It's really great feature to get dita-ot path in Oxygen Plugin. But some how, I am still having issue with space character.
Console Output:
Surprised with mix of forward & backward slashes in the path output i.e ditaExecutableCommand: C:\oxygen\Oxygen XML Editor 23\frameworks/dita/DITA-OT3.x\bin\dita
Could you suggest any clue on the IOException?
Thanks.
It's really great feature to get dita-ot path in Oxygen Plugin. But some how, I am still having issue with space character.
Code: Select all
String ditaExecutableCommand = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().expandEditorVariables("${configured.ditaot.dir}", null) + "\\bin\\dita";
System.out.println("ditaExecutableCommand:"+ditaExecutableCommand);
Code: Select all
ditaExecutableCommand: C:\oxygen\Oxygen XML Editor 23\frameworks/dita/DITA-OT3.x\bin\dita
java.io.IOException: Cannot run program ""C:\oxygen\Oxygen": CreateProcess error=193, %1 is not a valid Win32 application
Could you suggest any clue on the IOException?
Thanks.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How best invoke dita ot cmd from custom oxygen plugin
Hi,
I checked this and the quotes around the path to the executable do not help, it's best to give each parameter, including the path as separate entries in a command line array, also include the entire name of the executable "dita.bat", like for example on my side:
Regards,
Radu
I checked this and the quotes around the path to the executable do not help, it's best to give each parameter, including the path as separate entries in a command line array, also include the entire name of the executable "dita.bat", like for example on my side:
Code: Select all
List<String> cmdArray = new ArrayList<String>();
cmdArray.add("D:\\Program Files\\Oxygen XML Author 22.1\\frameworks\\dita\\DITA-OT3.x\\bin\\dita.bat");
cmdArray.add("-v");
//TODO add more parameters as separate values in the array
Runtime.getRuntime().exec(cmdArray.toArray(new String[0]));
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Thanks Radu!
It's working!
It's working!

-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Hi,
To the continuation of above thread, I am planning to use startProcess instead of Runtime.getRuntime().exec() to log the process into Oxygen window.
But some how, it's throwing exception as shown below, Found the same issue with 'dita.exe --version' command as well.
Please correct me if Iam wrong. Could you please suggest any pointed to use startProcess method.
String ditaExecutablePath = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().expandEditorVariables("${configured.ditaot.dir}", null) + "\\bin\\" ;
PluginWorkspaceProvider.getPluginWorkspace().startProcess(
"dita conversion",
new File(ditaExecutablePath),
"dita --version",
true);
Error Message:
Started: dita --version
Cannot run program "dita" (in directory "C:\oxygen\Oxygen XML Editor 23\frameworks\dita\DITA-OT3.x\bin"): CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "dita" (in directory "C:\oxygen\Oxygen XML Editor 23\frameworks\dita\DITA-OT3.x\bin"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at ro.sync.cmdline.h.b(Unknown Source)
at ro.sync.exml.workspace.b.c$5.kue(Unknown Source)
at ro.sync.ui.application.lb.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 4 more
Process ended with exit code: -1234567
Thanks.
To the continuation of above thread, I am planning to use startProcess instead of Runtime.getRuntime().exec() to log the process into Oxygen window.
But some how, it's throwing exception as shown below, Found the same issue with 'dita.exe --version' command as well.
Please correct me if Iam wrong. Could you please suggest any pointed to use startProcess method.
String ditaExecutablePath = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().expandEditorVariables("${configured.ditaot.dir}", null) + "\\bin\\" ;
PluginWorkspaceProvider.getPluginWorkspace().startProcess(
"dita conversion",
new File(ditaExecutablePath),
"dita --version",
true);
Error Message:
Started: dita --version
Cannot run program "dita" (in directory "C:\oxygen\Oxygen XML Editor 23\frameworks\dita\DITA-OT3.x\bin"): CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "dita" (in directory "C:\oxygen\Oxygen XML Editor 23\frameworks\dita\DITA-OT3.x\bin"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at ro.sync.cmdline.h.b(Unknown Source)
at ro.sync.exml.workspace.b.c$5.kue(Unknown Source)
at ro.sync.ui.application.lb.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 4 more
Process ended with exit code: -1234567
Thanks.
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Sorry for inconvenience. I got it with below change,
PluginWorkspaceProvider.getPluginWorkspace().startProcess(
"dita conversion",
new File(ditaExecutablePath),
"cmd.exe /c \"dita --version\"",
true);
Thanks.
PluginWorkspaceProvider.getPluginWorkspace().startProcess(
"dita conversion",
new File(ditaExecutablePath),
"cmd.exe /c \"dita --version\"",
true);
Thanks.
-
- Posts: 91
- Joined: Tue Jul 17, 2018 6:57 am
Re: How best invoke dita ot cmd from custom oxygen plugin
Post by msambasiva »
Hi,
Found 'The input line is too long.' issue with cmd.exe as I posted in the forum @ topic22985.html .
Could you suggest any clue to overcome this issue? Can we use powershell instead of cmd? If so, any pointer pls?
Thanks,
Samba.
Found 'The input line is too long.' issue with cmd.exe as I posted in the forum @ topic22985.html .
Could you suggest any clue to overcome this issue? Can we use powershell instead of cmd? If so, any pointer pls?
Thanks,
Samba.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How best invoke dita ot cmd from custom oxygen plugin
Hi Samba,
You are starting a process from Java, so I don't think using powershell is an option.
On that DITA OT issue:
https://github.com/dita-ot/dita-ot/issu ... -368855434
I mentioned there is a DITA OT plugin which adds lots of libraries:
dita-ot-3.x/plugins/org.lwdita
This particular plugin is for publishing markdown content as DITA and for publishing DITA content as markdown. If you do not need this functionality you can try to remove the "org.lwdita" plugin, re-run the DITA OT integrator and the command line will be shorter.
As I said the DITA OT bundled with Oxygen has various Java patches to overcome this limitation. So instead of your custom DITA OT distribution you could use ours (which is based on DITA OT 3.6) and install your plugins inside it:
https://www.oxygenxml.com/publishing_engine.html
Regards,
Radu
You are starting a process from Java, so I don't think using powershell is an option.
On that DITA OT issue:
https://github.com/dita-ot/dita-ot/issu ... -368855434
I mentioned there is a DITA OT plugin which adds lots of libraries:
dita-ot-3.x/plugins/org.lwdita
This particular plugin is for publishing markdown content as DITA and for publishing DITA content as markdown. If you do not need this functionality you can try to remove the "org.lwdita" plugin, re-run the DITA OT integrator and the command line will be shorter.
As I said the DITA OT bundled with Oxygen has various Java patches to overcome this limitation. So instead of your custom DITA OT distribution you could use ours (which is based on DITA OT 3.6) and install your plugins inside it:
https://www.oxygenxml.com/publishing_engine.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service