How to access resources from javascript

Post here questions and problems related to oXygen frameworks/document types.
steve.cuzner
Posts: 69

How to access resources from javascript

Tue Aug 09, 2016 4:59 pm

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: 69

Re: How to access resources from javascript

Tue Aug 09, 2016 6:34 pm

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: 69

Re: How to access resources from javascript

Tue Aug 09, 2016 7:17 pm

Code: Select all

frameworkDir = authorAccess.getUtilAccess().expandEditorVariables("${frameworkDir}", null);
alex_jitianu
Posts: 632

Re: How to access resources from javascript

Wed Aug 10, 2016 10:19 am

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

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests