oxy_link-text() and refresh

Post here questions and problems related to oXygen frameworks/document types.
Pascale
Posts: 40
Joined: Wed Jan 29, 2014 4:30 pm

oxy_link-text() and refresh

Post by Pascale » Thu Apr 24, 2014 5:59 pm

Hi,

I am using the oxy_link-text() function in my CSS.

Code: Select all


xref:empty {
content: oxy_link-text() ;
}
I have implemented a custom LinkTextResolver that returns different values depending on attributes set on the xref. For example, if @reftext=yes, I show the title of the target element; but if @reftext=no, I show some other text.

However, when I change the attribute value in my document, the value displayed by oxy_link-text() does not change unless I force a "reload F5" which then prompts me for saving the document before refreshing it.
Is there a way to automatically refresh without saving the doc ?

Thanks,
Pascale

alex_jitianu
Posts: 675
Joined: Wed Nov 16, 2005 11:11 am

Re: oxy_link-text() and refresh

Post by alex_jitianu » Fri Apr 25, 2014 12:34 pm

Hi Pascale,

Your link resolver should listen on document changes. When such an attribute changes, if it keeps some sort of cache it must clear what's outdated and must call refresh on the node. You can use the activated call of the resolver to add such a listener. Here is how we do it in the default DITA link text resolver:

Code: Select all

public class DitaLinkTextResolver extends LinkTextResolver {
/**
* @see ro.sync.ecss.extensions.api.AuthorExtensionStateListener#activated(ro.sync.ecss.extensions.api.AuthorAccess)
*/
@Override
public void activated(AuthorAccess authorAccess) {
this.authorAccess = authorAccess;
authorAccess.getDocumentController().addAuthorListener(authorListenerAdapter);
}

/**
* For a map/topicref the attributes locktitle and navtitle control the expanded text.
* So when they change we must also refresh.
*/
private AuthorListenerAdapter authorListenerAdapter = new AuthorListenerAdapter() {
@Override
public void attributeChanged(ro.sync.ecss.extensions.api.AttributeChangedEvent e) {
AuthorElement element = (AuthorElement) e.getOwnerAuthorNode();
String attrName = e.getAttributeName();

if (resolvesTopicrefs) {
// If the resolver was never for topicrefs used there is no point in refreshing.
// oxy_link_text() was encountered on topicref styles. Changing these two
// attributes will give a different text for the element so we'll refresh.
AttrValue classValue = element.getAttribute("class");
if (classValue != null
&& classValue.getValue().contains(" map/topicref ")) {
boolean depends = "locktitle".equals(attrName) ||
"navtitle".equals(attrName);
if (depends) {
// Refresh the node so that it's styles are recomputed.
authorAccess.getEditorAccess().refresh(element);
}
}
}
}
};
Another possible solution is to add a CSS rule that will mark the element as being dependent on an attribute. Oxygen will then automatically refresh the element when its attribute changes:

Code: Select all


/* This rule is just so that Oxygen refreshes the Styles of the element when the attribute changes*/
xref[reftext] {}
This second approach will be enough if your link text resolver doesn't keep an inner cache with the references it resolves. If it does, then you need to go with the first solution.

Best regards,
Alex

Pascale
Posts: 40
Joined: Wed Jan 29, 2014 4:30 pm

Re: oxy_link-text() and refresh

Post by Pascale » Fri Apr 25, 2014 3:01 pm

Thanks, Alex !

I used your first suggestion (using the activated() call of the resolver) and it works like a charm :D

Pascale

Post Reply