Exporting a page to a proprietary file format

My company uses a proprietary file format for some of our documentation. I’d like to use Confluence as an authoring tool for said format. I’ve created several macros and menu items to assist in the process. What I need now is something akin to the “Export to Word” or “Export to PDF” feature.

What advice can anyone offer on writing a custom exporter? I wondered about using a custom Device Type Renderer module, then saving the output to a file. Would that be the recommended path forward? If so, how does one invoke the custom renderer? From my custom tool menu action I can setOutputType() on the page context (and restore it when done), but where do I go from there?

If a Device Type Renderer isn’t the recommended path, what is?

Thanks in advance!

So I’m proceeding with creating my own renderer. I’m getting an error when the plugin is loaded however:

[INFO] [talledLocalContainer] 2021-10-01 23:00:06,153 WARN [ThreadPoolAsyncTaskExecutor::Thread 21] [scanner.runtime.impl.ComponentImportBeanFactoryPostProcessor] postProcessBeanFactory Unable to load class ‘com.atlassian.confluence.impl.content.render.prefetch.ContentResourcePrefetcher’ for component importation purposes. Skipping…

[INFO] [talledLocalContainer] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘mydocrenderer’: Resolution of declared constructors on bean Class [com.spm.plugin.document.impl.MyDocRenderer] from ClassLoader [com.spm.plugin.my-document [295]] failed; nested exception is java.lang.NoClassDefFoundError: com/atlassian/confluence/impl/content/render/prefetch/ContentResourcePrefetcher

I’m confused by this, because the class in question (ContentResourcePrefetcher) is imported at the start of MyDocRenderer. I did find one snippet in the Atlassian documentation that suggests that it may not be visible:

Package com.atlassian.confluence.impl Description

Subpackages of this package are NOT exposed to the plugin classpath, by being excluded in the packageScanningConfiguration of bootstrapContext.xml.

So my question is: if the class isn’t being included in my plugin because it’s not exposed, how do I get at it to meet the constructor requirements of the Device Type Renderer module?

For sake of reference –
Relevant plugin.xml lines:

<!--  My custom device renderer -->
<device-type-renderer key="mydocrenderer" i18n-name-key="mydocrenderer.name">
	<description>The renderer used for generating custom documentation from content in Confluence.</description>
	<device-type>mydoc</device-type>
</device-type-renderer>

The Spring context XML:

 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner/2"
 	xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.atlassian.com/schema/atlassian-scanner
         http://www.atlassian.com/schema/atlassian-scanner/atlassian-scanner.xsd">
 	<atlassian-scanner:scan-indexes />
     <bean id="mydocrenderer" class="com.spm.plugin.document.impl.MyDocRenderer" lazy-init="false">
     	<constructor-arg index="0">
     		<bean class="com.atlassian.confluence.content.render.xhtml.TransformerChain" />
 		</constructor-arg> 
     	<constructor-arg index="1">
     		<bean class="com.atlassian.confluence.util.i18n.I18NBeanFactory" />
 		</constructor-arg>
     	<constructor-arg index="2">
     		<bean class="com.atlassian.confluence.content.render.xhtml.compatibility.LegacyV2RendererContextInitialiser" />
 		</constructor-arg>
     	<constructor-arg index="3">
     		<bean class="com.atlassian.confluence.setup.settings.SettingsManager" />
 		</constructor-arg>
     	<constructor-arg index="4">
     		<bean class="com.atlassian.confluence.content.render.xhtml.RenderingEventPublisher" />
 		</constructor-arg>
     	<constructor-arg index="5">
     		<bean class="com.atlassian.confluence.impl.content.render.prefetch.ContentResourcePrefetcher" />
 		</constructor-arg>
 	</bean>
 </beans>

And lastly, MyDocRenderer.java:

package com.spm.plugin.document.impl;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.DefaultRenderer;
import com.atlassian.confluence.content.render.xhtml.RenderingEventPublisher;
import com.atlassian.confluence.content.render.xhtml.compatibility.LegacyV2RendererContextInitialiser;
import com.atlassian.confluence.content.render.xhtml.transformers.Transformer;
import com.atlassian.confluence.impl.content.render.prefetch.ContentResourcePrefetcher;
import com.atlassian.confluence.setup.settings.SettingsManager;
import com.atlassian.confluence.util.i18n.I18NBeanFactory;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.springframework.beans.factory.annotation.Autowired;

public class MyDocRenderer extends DefaultRenderer {
	@Autowired
	public MyDocRenderer( @ComponentImport Transformer transformer, 
						   @ComponentImport I18NBeanFactory i18nBeanFactory,
						   @ComponentImport LegacyV2RendererContextInitialiser legacyV2RendererConfigurationPropertySetter,
						   @ComponentImport SettingsManager settingsManager, 
						   @ComponentImport RenderingEventPublisher renderingEventPublisher,
						   @ComponentImport ContentResourcePrefetcher contentResourcePrefetcher) {
		super(transformer, i18nBeanFactory, legacyV2RendererConfigurationPropertySetter, 
				settingsManager, renderingEventPublisher, contentResourcePrefetcher);
	}

// Everything else is commented out for now.  We let 'super' handle everything until we can confirm the framework.
}

Any thoughts on why the ContentResourcePrefetcher isn’t found?

One other bit of info – the version information at the bottom of the POM file:

		<confluence.version>7.4.11</confluence.version>
		<confluence.data.version>7.4.11</confluence.data.version>
		<amps.version>8.1.2</amps.version>
		<plugin.testrunner.version>2.0.2</plugin.testrunner.version>
		<atlassian.spring.scanner.version>2.2.3</atlassian.spring.scanner.version>
		<!-- This property ensures consistency between the key in atlassian-plugin.xml 
			and the OSGi bundle's key. -->
		<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>