org.docx4j.spring.boot.Docx4jDocxTemplateAutoConfiguration Maven / Gradle / Ivy
package org.docx4j.spring.boot;
import java.io.IOException;
import org.docx4j.Docx4J;
import org.docx4j.convert.out.ConversionHTMLScriptElementHandler;
import org.docx4j.convert.out.ConversionHTMLStyleElementHandler;
import org.docx4j.convert.out.ConversionHyperlinkHandler;
import org.docx4j.template.WordprocessingMLDocxSaxTemplate;
import org.docx4j.template.WordprocessingMLDocxStAXTemplate;
import org.docx4j.template.WordprocessingMLDocxTemplate;
import org.docx4j.template.handler.OutputConversionHTMLScriptElementHandler;
import org.docx4j.template.handler.OutputConversionHTMLStyleElementHandler;
import org.docx4j.template.handler.OutputConversionHyperlinkHandler;
import org.docx4j.template.io.WordprocessingMLPackageExtractor;
import org.docx4j.template.io.WordprocessingMLPackageWriter;
import org.docx4j.template.io.WordprocessingMLTemplateWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@AutoConfigureAfter(Docx4jAutoConfiguration.class)
@ConditionalOnClass({ Docx4J.class, WordprocessingMLDocxTemplate.class })
@ConditionalOnProperty(prefix = Docx4jProperties.PREFIX, value = "enabled", havingValue = "true")
@EnableConfigurationProperties({ Docx4jDocxTemplateProperties.class })
public class Docx4jDocxTemplateAutoConfiguration {
protected static Logger LOG = LoggerFactory.getLogger(Docx4jDocxTemplateAutoConfiguration.class);
@Bean
public WordprocessingMLDocxTemplate wmlDocxTemplate()
throws IOException {
WordprocessingMLDocxTemplate template = new WordprocessingMLDocxTemplate();
return template;
}
@Bean
public WordprocessingMLDocxSaxTemplate wmlDocxSaxTemplate()
throws IOException {
WordprocessingMLDocxSaxTemplate template = new WordprocessingMLDocxSaxTemplate();
return template;
}
@Bean
public WordprocessingMLDocxStAXTemplate wmlDocxStAXTemplate()
throws IOException {
WordprocessingMLDocxStAXTemplate template = new WordprocessingMLDocxStAXTemplate();
return template;
}
@Bean
@ConditionalOnMissingBean
public ConversionHyperlinkHandler hyperlinkHandler() {
return OutputConversionHyperlinkHandler.getHyperlinkHandler();
}
@Bean
@ConditionalOnMissingBean
public ConversionHTMLStyleElementHandler styleElementHandler() {
return OutputConversionHTMLStyleElementHandler.getStyleElementHandler();
}
@Bean
@ConditionalOnMissingBean
public ConversionHTMLScriptElementHandler scriptElementHandler() {
return OutputConversionHTMLScriptElementHandler.getScriptElementHandler();
}
@Bean
@ConditionalOnMissingBean
public WordprocessingMLPackageExtractor wmlPackageExtractor() {
return WordprocessingMLPackageExtractor.getWMLPackageExtractor();
}
@Bean
@ConditionalOnMissingBean
public WordprocessingMLPackageWriter wmlPackageWriter(ConversionHyperlinkHandler hyperlinkHandler,
ConversionHTMLScriptElementHandler scriptElementHandler,
ConversionHTMLStyleElementHandler styleElementHandler) {
WordprocessingMLPackageWriter wmlPackageWriter = WordprocessingMLPackageWriter.getWMLPackageWriter();
wmlPackageWriter.setHyperlinkHandler(hyperlinkHandler);
wmlPackageWriter.setScriptElementHandler(scriptElementHandler);
wmlPackageWriter.setStyleElementHandler(styleElementHandler);
return wmlPackageWriter;
}
@Bean
@ConditionalOnMissingBean
public WordprocessingMLTemplateWriter wmlTemplateWriter() {
return WordprocessingMLTemplateWriter.getWMLTemplateWriter();
}
}