DITALinkTextResolver.resolveReference sample

Post here questions and problems related to oXygen frameworks/document types.
pierat
Posts: 9
Location: Paris, France

DITALinkTextResolver.resolveReference sample

Tue Oct 11, 2016 8:32 am

Hi,

I try to extend the DITALinkTextResolver.resolveReference and instead of reinvent everything, I would be interesting to get either the standard oXygen DITA implementation or any other implementation made by this forum user.

My implementation needs to concatenate some prolog metadata (if there are some) to the topic title.

Thanks for sharing, Pierre
alex_jitianu
Posts: 601

Re: DITALinkTextResolver.resolveReference sample

Tue Oct 11, 2016 10:24 am

Hello,

The code for DITALinkTextResolver is open source and it's available in the oxygen-sample-framework module from our SDK sample project. After you set up the project, you need to run mvn generate-resources (the sample project is a Maven multi-module project) inside the oxygen-sample-framework module. This will create a directory oxygen-sample-framework/samples in which you can find all framework specific Java extensions. For convenience, I will also send you the source code directly on your email address.

Best regards,
Alex
pierat
Posts: 9
Location: Paris, France

Re: DITALinkTextResolver.resolveReference sample

Tue Oct 11, 2016 12:47 pm

alex_jitianu wrote:This will create a directory oxygen-sample-framework/samples in which you can find all framework specific Java extensions.


Thanks a lot for your answer.

I've got the framework downloaded but it seems that the

Code: Select all

ro.sync.ecss.dita.DITAAccess
class is not part of this maven project (only the documentation).
Looking at the code, it is exactely the

Code: Select all

DITAAccess.computeLinkText
method which is interesting for me.

So is this an other project to download ? How to get that part of the framework ?

Pierre
alex_jitianu
Posts: 601

Re: DITALinkTextResolver.resolveReference sample

Tue Oct 11, 2016 3:34 pm

Hello,

Unfortunately DITAAccess code is not API but more of a gateway between API and private code. I will file in a request to enhance our API to allow you to extract additional content from the target of the link. Meanwhile, you probably have to identify the case where the link is a topic (from the ID structure) and extract the metadata yourself. For that you could:
- parse the document using the DOM model and search through it, or
- using our API you can create an XSLT or XQuery transformer and execute a query that will extract that metadata from the target document:

Code: Select all

public class DitaLinkTextResolver extends LinkTextResolver {
 
  /**
   * Caching this object will ensure a much faster DITA topic parsing.
   */
  Object grammarToken = null;
 
  /**
   * @throws TransformerException
   */
  private String getMetaData(URL target) throws TransformerException {
    XMLUtilAccess xmlUtilAccess = PluginWorkspaceProvider.getPluginWorkspace().getXMLUtilAccess();
    Source xsltSource = new StreamSource(new StringReader(
        // TODO Build a proper XSLT based on the link href. You could also build
        // an XSLT in which the variables parts (like the topic ID perhaps) are
        // expressed as parameters. 
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n" +
        "  xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
        "  exclude-result-prefixes=\"xs\"\n" +
        "  version=\"2.0\">\n" +
        "  <xsl:template match=\"/topic/prolog\"></xsl:template>\n" +
        "</xsl:stylesheet>"));
    //  xmlUtilAccess.createXQueryTransformer(xquerySource, null, XMLUtilAccess.TRANSFORMER_SAXON_ENTERPRISE_EDITION);
    Transformer transfomer = xmlUtilAccess.createXSLTTransformer(xsltSource, null, XMLUtilAccess.TRANSFORMER_SAXON_ENTERPRISE_EDITION);
    XMLReaderWithGrammar readerAndCache = xmlUtilAccess.newNonValidatingXMLReader(grammarToken);
    XMLReader reader = readerAndCache.getXmlReader();
    // Caching this object will ensure a much faster DITA topic parsing.
    grammarToken = readerAndCache.getGrammarCache();
   
    SAXSource xmlSource = new SAXSource(reader, new InputSource(target.toExternalForm()));
   
    StringWriter writer = new StringWriter();
    transfomer.transform(xmlSource, new StreamResult(writer));

    return writer.toString();
  }


Personally, I would go with the second solution...

Best regards,
Alex

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest