Search in sources :

Example 1 with SingleTopicContext

use of eu.esdihumboldt.hale.doc.util.context.SingleTopicContext in project hale by halestudio.

the class FunctionContextProvider method getContext.

/**
 * @see AbstractContextProvider#getContext(String, String)
 */
@Override
public IContext getContext(String contextId, String locale) {
    // It is not possible to use dots (.) in the context id to identify the
    // function, because it will be treated as part of the bundle name. So
    // the function identifier is encoded using ONameUtil
    int index = contextId.lastIndexOf('.');
    String pluginId = contextId.substring(0, index);
    String shortContextId = contextId.substring(index + 1);
    if (pluginId.equals(PLUGIN_ID)) {
        try {
            String functionId = ONameUtil.decodeName(shortContextId);
            FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, null);
            if (function != null) {
                FunctionTopic topic = new ContextFunctionTopic(function);
                String description = function.getDescription();
                if (description == null) {
                    description = function.getDisplayName();
                }
                return new SingleTopicContext(function.getDisplayName(), description, topic);
            // XXX add more info to context (e.g. title?)
            }
        } catch (DecoderException e) {
        // no valid function ID
        }
    }
    return null;
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) SingleTopicContext(eu.esdihumboldt.hale.doc.util.context.SingleTopicContext) FunctionTopic(eu.esdihumboldt.cst.doc.functions.internal.toc.FunctionTopic)

Aggregations

FunctionTopic (eu.esdihumboldt.cst.doc.functions.internal.toc.FunctionTopic)1 SingleTopicContext (eu.esdihumboldt.hale.doc.util.context.SingleTopicContext)1 DecoderException (org.apache.commons.codec.DecoderException)1