Page 1 of 1

Map framework based on topics

Posted: Mon May 03, 2021 1:20 pm
by NicoAMP
Hello,

I would like to create a custom framework that extend "DITA map".
I would like that this framework runs when a specific topic (e.g. with "myCustomTopic" root name) is present in the map hierarchy.

I tried to use DITAMapResolvedReferencesCustomRuleMatcher java class like this but it doesn't work:
image.png
image.png (27.08 KiB) Viewed 249 times
Picture1.png
Picture1.png (47.47 KiB) Viewed 249 times
Is the behavior I'm trying to set up possible?

Thanks for your help.

Regards,
Nicolas

Re: Map framework based on topics

Posted: Tue May 04, 2021 7:33 am
by Radu
Hi Nicolas,

So when a "test.ditamap" is opened in Oxygen, if it has a topic reference to "test.dita", you want it to be matched by Oxygen with a certain framework configuration, correct? And if it does not have a topic reference to "test.dita", you want it to be matched with the default DITA Map framework.
You probably need to create your own Java extension for the "ro.sync.ecss.extensions.api.DocumentTypeAdvancedCustomRuleMatcher" API:

https://www.oxygenxml.com/InstData/Edit ... tcher.html

The most flexible "matches" callback receives a "contentReader" which would allow you to read through the entire content of the DITA Map to see if it should be matched with the framework or not.
And then in the framework configuration add in the "Classpath" tab a reference to your custom JAR library and in the association rules use your custom rule matcher implementation in an association rule.

Regards,
Radu

Re: Map framework based on topics

Posted: Tue May 04, 2021 4:26 pm
by NicoAMP
Hi Radu,

Thanks for your help.

I tried quickly this solution:

Code: Select all

public class DITAMapResolvedReferencesCustomRuleMatcherMyTest extends DocumentTypeAdvancedCustomRuleMatcher
{
    public boolean matches(final String systemID, final String rootNamespace, final String rootLocalName, final String doctypePublicID, final String doctypeSystemID, final Attributes rootAttributes, final Map<String, String> queryParameters, final Reader contentReader) throws IOException {
        boolean valuesMatch = false;

            int bufferSize = 1024;
            char[] buffer = new char[bufferSize];
            StringBuilder out = new StringBuilder();

            for (int numRead; (numRead = contentReader.read(buffer, 0, buffer.length)) > 0; ) {
                out.append(buffer, 0, numRead);
            }

            if (out.indexOf("<myElement") > -1) {
                valuesMatch = true;
            }
            
           return valuesMatch;
    }
}
But unfortunately, I have a Null Pointer Exception because it seems that contentReader is null.

Do you know why? Thanks.

Re: Map framework based on topics

Posted: Tue May 04, 2021 6:50 pm
by Radu
Hi Nicolas,

Hmm, it seems sometimes the "contentReader" may be null. Can you guard against this situation in your code? Return false if it's null and see if this works further for you.

Regards,
Radu