Page 1 of 1
how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 10:02 am
by vishwavaranasi
Hello Team , we have a use case like this
1. Open a map in Author mode for editing
2. Select a topicref in the map, for example:
<topicref keyref="xxxx-639E21FB-6066-493B-A55E-xxxxxx" ... />
using java ..in my custom framworks , how to get the "keyref" attribute value?
Thanks,
vishwa
Re: how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 12:04 pm
by adrian_sorop
Hi,
In order for me to provide a specific response I will require more information, like, for example a code snippet.
For now, here are some generic hints:
If you identified the node and it's an AuthorElement you can use the AuthorElement.getAttribute(attributeName) API -
https://www.oxygenxml.com/InstData/Edit ... ement.html
If your node is not an AuthorElement you can check if the node is an instance of AuthorElement and, if the statement is true, cast it to AuthorElement and use the getAttribute API.
The getAttribute API returns an AttrValue -
https://www.oxygenxml.com/InstData/Edit ... Value.html
Regards,
Adrian S
Re: how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 12:36 pm
by vishwavaranasi
Hi Adrian , Thanks for the reply.
use case is when
1. Open a map in Author mode for editing
2. Select a topicref in the map, for example: <topicref keyref="xxxx-639E21FB-6066-493B-A55E-xxxxxx" ... />
and then my custom menu item from DITA is calling the the below custom class is from our custom frame work jar , we have attached a menu item from DITA -> and assigned the CustomOperation.java ..the menu item is invoking the class and it is printing currentRootMapURL.getFile(
BUT it is never entering addEditorChangeListener() method.
Code: Select all
public class CustomOperation implements AuthorOperation {
@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args) throws IllegalArgumentException, AuthorOperationException {
java.net.URL currentRootMapURL=ro.sync.ecss.dita.DITAAccess.getRootMapURL();
System.out.println("DefineKeysOperation--------doOperation"+currentRootMapURL.getFile());
JFrame oxygenFrame = (JFrame) authorAccess.getWorkspaceAccess().getParentFrame();
// it is never entering in to this method? addEditorChangeListener?
PluginWorkspaceProvider.getPluginWorkspace().addEditorChangeListener(new WSEditorChangeListener() {
public void editorSelected(URL editorLocation) {
try {
AuthorElement elem = (AuthorElement) authorAccess.getDocumentController().getNodeAtOffset(authorAccess.getEditorAccess().getCaretOffset());
System.out.println("DefineKeysOperation--------keyref 1 "+elem.getAttribute("keyref"));
AuthorNode authorNode=authorAccess.getDocumentController().getNodeAtOffset(authorAccess.getEditorAccess().getCaretOffset());
System.out.println("DefineKeysOperation--------keyref 2"+authorNode.getTextContent());
} catch (BadLocationException e) {
e.printStackTrace();
}
};
}, PluginWorkspace.MAIN_EDITING_AREA);
}
/**
* @return An array of {@link ArgumentDescriptor} representing
* the arguments this operation uses.
*/
@Override
public ArgumentDescriptor[] getArguments() {
return new ArgumentDescriptor[0];
}
/**
* @return The description of the extension.
*/
@Override
public String getDescription() {
return null;
}
}
Re: how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 1:13 pm
by adrian_sorop
Hi,
Let me know if I've undestood your use case correctly:
You open a ditamap in Author Page.
Then you select or click a node (a topicref).
Then you click this custom action that will invoke the custom author operation.
This action should print the value of the "keyref" attribute, if exists.
Try this:
Code: Select all
@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
try {
int currentOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(currentOffset);
if (nodeAtOffset instanceof AuthorElement) {
AuthorElement authorElement = (AuthorElement) nodeAtOffset;
AttrValue keyrefAttrValue = authorElement.getAttribute("keyref");
if (keyrefAttrValue != null) {
System.out.println("keyref: " + keyrefAttrValue.getValue());
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
Now, going to the second part:
BUT it is never entering addEditorChangeListener() method.
Here is the documentaion of the
addEditorChangeListener(WSEditorChangeListener editorListener, int editingArea) API:
addEditorChangeListener(WSEditorChangeListener editorListener, int editingArea)
Add listener for editor related events(for example editor opened, closed, page changed).
https://www.oxygenxml.com/InstData/Edit ... space.html
In your code, every time the action was invoked, a new listener over the current document will be added. When the editor will be selected next time, will try to print the value of the keyref attribute.
So, I belive this is not the result you were expecting.
Regards,
Adrian S
Re: how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 2:44 pm
by vishwavaranasi
Thanks
it's worked ,but if i do the below , nodeAtOffset it is selecting the parent of selected tag
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(currentOffset);
or else if i do
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(currentOffset-1);
it is correctly shows the current selected tag
is this something expected?
Re: how to get the "keyref" attribute value
Posted: Fri Oct 21, 2022 3:45 pm
by adrian_sorop
Hi,
Here is the documentation regading the
getNodeAtOffset(int) API -
https://www.oxygenxml.com/InstData/Edit ... ffset-int-
Regards,
Adrian S.
Re: how to get the "keyref" attribute value
Posted: Sat Oct 22, 2022 8:45 pm
by vishwavaranasi
Thanks Adrian ,
am able to retrieve the selected "topicref" node "keyref" attribute value also this node has attribute "keys"
Now i have opened a dialog , and the dialog displayed 2 text fields
Keyref :
keys:
and this dialog has a button called "remove key" , means delete keys attribute and its value from the selected topicref
how can we dynamically this change can be applied to the target node?
Example 1: the selected <topicref keyref="keyref1234567" keys="key_to_title"/> from diamap
dialog displays the 2 values , with a button "remove key"
Keyref=keyref1234567
Keys=key_to_title
when use clicks remove key am adding action listener
i wanted do inside action listener , means delete keys attribute and its value from the selected topicref and the diamap should applied with the change and updated.
the selected should become this
<topicref keyref="keyref1234567"/>
Re: how to get the "keyref" attribute value
Posted: Mon Oct 24, 2022 10:40 am
by adrian_sorop
Hi,
To remove an attribute and its values from a document use
ro.sync.ecss.extensions.api.AuthorDocumentController.removeAttribute(String, AuthorElement).
Here is the documetation of this API:
https://www.oxygenxml.com/InstData/Edit ... orElement-
Regards,
Adrian S.