Plugin API: force Oxygen to open a file in the archive browser

Post here questions and problems related to oXygen frameworks/document types.
nkutsche
Posts: 10
Joined: Wed Feb 25, 2015 5:10 pm

Plugin API: force Oxygen to open a file in the archive browser

Post by nkutsche »

Hi Oxygen team,

I hope you are all fine and you had a good start in the new year!

I'm currently trying to implement for an Oxygen plugin an option to open an archive that has a custrom file extension (which is not in the default list of known archive file extensions). Currently I do it this way:

Code: Select all

spw.open(url, EditorPageConstants.PAGE_UNKNOWN, "application/zip");
This works fine, but at the first time it shows the message: "Unknown archive extension 'ocf'. Do you want to map this extension to an archive type?" If the user chooses "Yes" the archive preference page opens and the extension was added to the list. After submitting the file is opened in the archive browser. But in case of "No" Oxygen tries to open the archive as text in the main area.

I think we can live with this, but the dialogs are maybe a bit surprising for the user. It would be a great enhancement if there is a way to force the Oxygen to open the file in the archive browser without this dialogs (e.g. ignoring un/known file extensions). Is there a way to do this?

An alternative would be to add the extension to the list of known archive types in the background. But I'm not sure how to do that. I think it should be possible by using the ro.sync.exml.workspace.api.options.WSOptionsStorage but I don't not know what option keys I have to use.

​Do you have any hint for me, how I could achieve one of the alternatives?

Best Regards,
Nico
Radu
Posts: 9343
Joined: Fri Jul 09, 2004 5:18 pm

Re: Plugin API: force Oxygen to open a file in the archive browser

Post by Radu »

Hello Nico,
Looking at our code, I do not see a way in which that dialog could be avoided unless the Preferences->"Archive" page has an entry for your custom archive extension.
The WSOptionsStorage is a way to store/retrieve your own key/value pairs without interfering with Oxygen's preferences.

We do have another global options storage through which you could influence the global options.
The code would look something like this:

Code: Select all

   @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      ro.sync.exml.zip.ArchiveDescriptor[] archiveDescriptors = (ArchiveDescriptor[]) pluginWorkspaceAccess.getGlobalObjectProperty(APIAccessibleOptionTags.ARCHIVE_DESCRIPTORS);
      boolean addExtra = true;
      for (int i = 0; i < archiveDescriptors.length; i++) {
        String[] extensions = archiveDescriptors[i].getExtensions();
        if(Arrays.toString(extensions).contains("zup")) {
          addExtra = false;
          break;
        }
      }
      if(addExtra) {
        List<ArchiveDescriptor> newDescriptors = new ArrayList<>(Arrays.asList(archiveDescriptors));
        newDescriptors.add(new ArchiveDescriptor("zup descr", new String[] {"zup"}, ArchiveDescriptor.ARCHIVE_TYPE_ZIP));
        pluginWorkspaceAccess.setGlobalObjectProperty(APIAccessibleOptionTags.ARCHIVE_DESCRIPTORS, newDescriptors.toArray(new ArchiveDescriptor[0]));
      }
but from what I tested it would take effect on the second time you start Oxygen.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
nkutsche
Posts: 10
Joined: Wed Feb 25, 2015 5:10 pm

Re: Plugin API: force Oxygen to open a file in the archive browser

Post by nkutsche »

Thanks, Radu! I will try this out.

It just comes to my mind: The GlobalOptionsStorage.setGlobalObjectProperty() points to the global preferences of Oxygen. If the user has open a project which overwrites this settings it has no effect, right?

Well, I can try that out as well...
Radu
Posts: 9343
Joined: Fri Jul 09, 2004 5:18 pm

Re: Plugin API: force Oxygen to open a file in the archive browser

Post by Radu »

Hi,
The project level options come as a layer over the global options.
From what I think if that particular Preferences->"Archive" page would be switched to "Project options", then using the API will change the setting directly in the project xpr options so that would still work.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply