How to access resources from javascript

Post here questions and problems related to oXygen frameworks/document types.
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

How to access resources from javascript

Post by steve.cuzner »

I'm writing a javascript function to insert xml fragments which works well with authorAccess.getDocumentController().insertXMLFragment. I would like to store my fragments as resource files outside of the javascript. I've tried the javascript File object, but that doesn't seem to work. How can I read an external file into a javascript string variable that I can then pass to insertXMLFragment?
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: How to access resources from javascript

Post by steve.cuzner »

I've found some success using standard java:

Code: Select all

fileReader = new java.io.FileReader("T:\\custom\\Oxygen\\frameworks\\tmwbook.framework\\frag.xml");
br = new java.io.BufferedReader(fileReader);
sb = new java.lang.StringBuilder();
line = br.readLine()
while (line != null)
{
sb.append(line);
line = br.readLine();
}
frag = sb.toString();
authorAccess.getWorkspaceAccess().showInformationMessage(frag);
But this only works when I have a absolute path. The above code is in a function in commons.js which is in tmwbook.framework, the same directory as the frag.xml. Ideally, I would put frag.xml in a resources sub-directory of tmwbook.framework, but in any event, I need to find the path to the framework in the javascript. How can I do that?
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: How to access resources from javascript

Post by steve.cuzner »

Code: Select all

frameworkDir = authorAccess.getUtilAccess().expandEditorVariables("${frameworkDir}", null);
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: How to access resources from javascript

Post by alex_jitianu »

Hi Steve,

I see you're find the solutions faster that I can answer :) Yes, this is the way you can obtain the framework directory:

Code: Select all

frameworkDir = authorAccess.getUtilAccess().expandEditorVariables("${frameworkDir}", null);
Best regards,
Alex
Post Reply