Get URL of parent when resolving references.

Post here questions and problems related to oXygen frameworks/document types.
bogusz
Posts: 8

Get URL of parent when resolving references.

Tue Jun 06, 2017 8:27 am

Hello,

I'm working on a custom CMS integration. Thanks for documentation, it's been great so far!

I'm wondering if there is a way to get the URL of the document Oxygen is currently resolving references for. Right now I'm listening for editor opens/activations, and noting the location. Then when I process a reference URL with my custom protocol handler, I look at that noted URL to get the context I need. Is there a more direct way to get the URL of the parent document?

Thanks,

Jack
Radu
Posts: 5088

Re: Get URL of parent when resolving references.

Tue Jun 06, 2017 9:00 am

Hi Jack,

Good question.
Thing is that an URL is an absolute location pointing to a resource so it should have in its path everything needed to know where the resource is located. So this is why the URLConnection API (which is standard Java API) does not have this information of the parent URL available.
Could you elaborate on why you need the parent URL information? Is it in order to look for certain authentication information located on it? If so, on the callback ro.sync.exml.workspace.api.listeners.WSEditorChangeListener.editorAboutToBeOpened(URL) maybe you can keep a mapping between the URL host and the credentials and use that static mapping in the custom URL connection (which is more or less similar to what you are doing right now).
About resolving content references, this of course needs to be done when an XML document is opened but it also needs to be done during the editing of the XML, when for example users insert a new content reference in the document. So you also need to make sure this aspect works.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
bogusz
Posts: 8

Re: Get URL of parent when resolving references.

Tue Jun 06, 2017 6:08 pm

Hey Radu, thanks for the quick response.

Objects in our CMS can be localized and versioned. A full URL might look like cproto:/id-123=en-US=1=2.dita. However we don't want our users to have to deal with any of that in their references. So a conref might look like <p conref="id-123#id-123/elementid">. Then when we publish the en-US parent we resolve the references in en-US using the latest publishable versions.

I already have the relative reference resolver extension rewriting my references to the locale/version agnostic form. I just need to be able to get the locale back from the parent when we're getting those reference URLs in Oxygen.

Thanks,

Jack
Radu
Posts: 5088

Re: Get URL of parent when resolving references.

Wed Jun 07, 2017 8:57 am

Hi Jack,

When processing XML with Java there is this concept of URI resolver. Our API allows you to set a priority URI resolver when the plugin starts up, something like this:

Code: Select all

    PluginWorkspaceProvider.getPluginWorkspace().getXMLUtilAccess().addPriorityURIResolver(new URIResolver() {
     
      @Override
      public Source resolve(String href, String base) throws TransformerException {
        if(base != null && base.startsWith("cproto:/")){
          try {
            new URL(href);
          } catch (MalformedURLException e) {
            //Href is relative, try to add stuff to it from the base....
            try {
              return new StreamSource(new URL(new URL(base), href + "extraStuffTakenFromBase").toString());
            } catch (MalformedURLException e1) {
              e1.printStackTrace();
            }
          }
        }
//        System.err.println("HREF " + href + " base " + base);
        return null;
      }
    });


Oxygen will call the URI resolver in lots of places, you can first add some logging on the callback to see from where it gets called.
Basically before resolving the @conref attribute value to an URL using only the base URL, Oxygen will also pass through the URI resolver the @conref value and the base value and if the URI resolver resolves this to its own URL, Oxygen will use that instead of doing new URL(base, href).
So on the URIResolver you can take control over what the URL for the conref will look like, use the information in the base location and infuse it in the absolute location URL that you will propose for the reference.
But on the callback you do not know that it's a callback coming from conref resolution or image ref resolution or link resolution (when you click a link).
Oh, and as the "resolve" callback is called very often you need to act fast on it and avoid extra processing on the callback, add some caching if you feel the need for looking in various network locations...

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
bogusz
Posts: 8

Re: Get URL of parent when resolving references.

Wed Jun 07, 2017 6:15 pm

I'll give this a try. Thank you!

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

Who is online

Users browsing this forum: No registered users and 0 guests