DITALinkTextResolver.resolveReference sample

Post here questions and problems related to oXygen frameworks/document types.
pierat
Posts: 9
Joined: Tue Mar 26, 2013 12:00 am
Location: Paris, France
Contact:

DITALinkTextResolver.resolveReference sample

Post by pierat »

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: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: DITALinkTextResolver.resolveReference sample

Post by alex_jitianu »

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
Joined: Tue Mar 26, 2013 12:00 am
Location: Paris, France
Contact:

Re: DITALinkTextResolver.resolveReference sample

Post by pierat »

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: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: DITALinkTextResolver.resolveReference sample

Post by alex_jitianu »

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
Post Reply