Page 1 of 1

Default folder for images

Posted: Thu Dec 19, 2013 3:30 am
by vrveerar
Hi,
I am currently moving from Arbortext to Oxygen and I have a bunch of DITA XMLs which have a fixed path the image src attributes (Arbortext allows one to set such folder locations in the preferences for inline display). These paths are not valid (what can I say, I used Arbortext :wink: ) and I am trying to move away from this practice by converting it in to relative paths.
In the meantime, is there anything I can do to make the images with the fixed path appear inline in the Author? I have looked at some options including:
  • Change path using the ChangeAttribute Author default operation. I am planning to change the fixed path to a relative path and thereby making it appear inline in the Author window (Question, is there any the operation can be triggered on document open in OxygenXML Author).
  • Using the Java API to change the fixed path to a relative path and thereby making it appear inline in the Author window(Again, any way to trigger this on document open)
Is there a better way to do this?

Thanks!
Nathan

PS: I am using Oxygen 15

Re: Default folder for images

Posted: Thu Dec 19, 2013 11:55 am
by Radu
Hello Nathan,

Could you give me an example of how such an image reference looks like?
Usually when inserting a reference to an image, Oxygen tries to make that reference relative to the DITA topic in which the image was inserted.
Unfortunately probably in your case a regular expression find-replace would not help because the relative image location needs to be composed depending on the current opened topic location and on the image location.
Probably the right option would indeed be this one:

Code: Select all

Using the Java API to change the fixed path to a relative path and thereby making it appear inline in the Author window(Again, any way to trigger this on document open)
Our Plugins SDK:

http://www.oxygenxml.com/oxygen_sdk.htm ... er_Plugins

contains a sample plugin type called Workspace Access.
Such a plugin is notified when Oxygen starts and it can do what you want in a couple of ways:

1) You add a listener which notifies you when the user opens an XML document. Then if the XML document is opened in the Author visual editing mode you can use our Author API to change attributes:

Code: Select all

    pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorOpened(java.net.URL)
*/
@Override
public void editorOpened(URL editorLocation) {
WSEditor openedEditor = pluginWorkspaceAccess.getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
if(openedEditor.getCurrentPage() instanceof WSAuthorEditorPage) {
WSAuthorEditorPage authPage = (WSAuthorEditorPage) openedEditor.getCurrentPage();
AuthorDocumentController docController = authPage.getDocumentController();
try {
//All changes will be undone by pressing Undo once.
docController.beginCompoundEdit();
fixupImageRefs(docController, docController.getAuthorDocumentNode());
} finally {
docController.endCompoundEdit();
}
}
}

private void fixupImageRefs(AuthorDocumentController docController,
AuthorNode authorNode) {
if(authorNode instanceof AuthorParentNode) {
//Recurse
List<AuthorNode> contentNodes = ((AuthorParentNode)authorNode).getContentNodes();
if(contentNodes != null) {
for (int i = 0; i < contentNodes.size(); i++) {
fixupImageRefs(docController, contentNodes.get(i));
}
}
}
if(authorNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement elem = (AuthorElement) authorNode;
if("image".equals(elem.getLocalName())) {
if(elem.getAttribute("href") != null) {
String originalHref = elem.getAttribute("href").getValue();
URL currentLocation = docController.getAuthorDocumentNode().getXMLBaseURL();
//TODO here you compute the new href.
String newHref = null;
docController.setAttribute("href", new AttrValue(newHref), elem);
}
}
}
}
}, StandalonePluginWorkspace.MAIN_EDITING_AREA);
2) You also have API to open XML documents in the application:

Code: Select all

ro.sync.exml.workspace.api.Workspace.open(URL)
So you can create up a plugin which automatically opens one by one XML documents from a certain folder in the application, makes modifications to them, saves the content by calling:

Code: Select all

ro.sync.exml.workspace.api.editor.WSEditorBase.save()
and then closes the editor:

Code: Select all

ro.sync.exml.workspace.api.Workspace.close(URL)
Regards,
Radu

Re: Default folder for images

Posted: Fri Dec 20, 2013 4:40 am
by vrveerar
Hi Radu,
My href looks something like this - 'href="xx/yy.png"'.
Another possibility that I was thinking of is to declare a environmental variable (containing the folder path of of the images) on the machine, pick that up in Oxygen as an editor variable, search for the href above (using XPath preferably) and replace it with the environmental variable + the href content.
  • Would Oxygen resolve the complete path and display the images?
  • What would the XML look like? - 'href="${env(VAR_NAME)}/xx/yy.png"' ?
  • How would I go about doing this if the above is possible and what would be the side effects of this?
The best outcome that I am looking for here is to have images with the partial path images displayed inline in the Author. Once everyone has started using Oxygen, I can look to change the partial paths to relative paths.

Thanks again for the quick reply,
Nathan.

Re: Default folder for images

Posted: Fri Dec 20, 2013 12:03 pm
by Radu
Hi Nathan,

The CSS-based solution Vincent proposed on the Oxygen Users List seems the quickest one if you just want to see the images when editing the XML content, I added some remarks to it:

http://www.oxygenxml.com/pipermail/oxyg ... 04906.html

The most important remark is that it will not work for publishing the DITA content from Oxygen.

Regards,
Radu