Map framework based on topics

Post here questions and problems related to oXygen frameworks/document types.
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Map framework based on topics

Post 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 1254 times
Picture1.png
Picture1.png (47.47 KiB) Viewed 1254 times
Is the behavior I'm trying to set up possible?

Thanks for your help.

Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Map framework based on topics

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Re: Map framework based on topics

Post 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.
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Map framework based on topics

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply