tengine config related fixes
This commit is contained in:
parent
0e110947fc
commit
7c2cf314bb
@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@ -43,6 +44,7 @@ import io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
|
||||
@EnableConfigurationProperties()
|
||||
@ImportResource({"classpath*:application-context.xml"})
|
||||
public class Application {
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.flexmark")
|
||||
public class CommonmarkConfig {
|
||||
|
||||
private List<String> defaultExtensions;
|
||||
|
||||
public List<String> getDefaultExtensions() {
|
||||
return this.defaultExtensions;
|
||||
}
|
||||
|
||||
void setDefaultExtensions(List<String> defaultExtensions) {
|
||||
this.defaultExtensions = defaultExtensions;
|
||||
}
|
||||
|
||||
}
|
@ -27,13 +27,12 @@ import org.commonmark.renderer.Renderer;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component(CommonmarkTransformer.ID)
|
||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.commonmark")
|
||||
public class CommonmarkTransformer implements Transformer {
|
||||
|
||||
public static final String ID = "commonmark";
|
||||
@ -42,7 +41,8 @@ public class CommonmarkTransformer implements Transformer {
|
||||
private final List<String> classSearchPrefixes = Arrays.asList("", "org.commonmark.ext.{name}.", "org.commonmark.ext.gfm.{name}.");
|
||||
private final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
||||
|
||||
private List<String> defaultExtensions;
|
||||
@Autowired
|
||||
private CommonmarkConfig config;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws Exception {
|
||||
@ -101,8 +101,8 @@ public class CommonmarkTransformer implements Transformer {
|
||||
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
||||
// include default extensions
|
||||
Set<String> extClassNames = new HashSet<>();
|
||||
if (this.defaultExtensions != null)
|
||||
extClassNames.addAll(this.defaultExtensions);
|
||||
if (this.config.getDefaultExtensions() != null)
|
||||
extClassNames.addAll(this.config.getDefaultExtensions());
|
||||
|
||||
// include/exclude based on passed in extensions
|
||||
String extClassNamesRaw = transformOptions.get(RequestParamConstants.EXT_CLASS_NAMES);
|
||||
|
29
tengine/src/main/java/com/inteligr8/alfresco/module/alfmarkdown/Config.java
Executable file
29
tengine/src/main/java/com/inteligr8/alfresco/module/alfmarkdown/Config.java
Executable file
@ -0,0 +1,29 @@
|
||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "transform.alfmarkdown")
|
||||
public class Config {
|
||||
|
||||
private FlexmarkConfig flexmark;
|
||||
private CommonmarkConfig commonmark;
|
||||
|
||||
public FlexmarkConfig getFlexmark() {
|
||||
return this.flexmark;
|
||||
}
|
||||
|
||||
void setFlexmark(FlexmarkConfig flexmark) {
|
||||
this.flexmark = flexmark;
|
||||
}
|
||||
|
||||
public CommonmarkConfig getCommonmark() {
|
||||
return this.commonmark;
|
||||
}
|
||||
|
||||
void setCommonmark(CommonmarkConfig commonmark) {
|
||||
this.commonmark = commonmark;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.flexmark")
|
||||
public class FlexmarkConfig {
|
||||
|
||||
private String defaultProfile;
|
||||
private List<String> defaultExtensions;
|
||||
|
||||
public String getDefaultProfile() {
|
||||
return this.defaultProfile;
|
||||
}
|
||||
|
||||
void setDefaultProfile(String defaultProfile) {
|
||||
this.defaultProfile = defaultProfile;
|
||||
}
|
||||
|
||||
public List<String> getDefaultExtensions() {
|
||||
return this.defaultExtensions;
|
||||
}
|
||||
|
||||
void setDefaultExtensions(List<String> defaultExtensions) {
|
||||
this.defaultExtensions = defaultExtensions;
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transformer.executors.Transformer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -35,7 +35,6 @@ import com.vladsch.flexmark.util.data.MutableDataSet;
|
||||
import com.vladsch.flexmark.util.misc.Extension;
|
||||
|
||||
@Component(FlexmarkTransformer.ID)
|
||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.flexmark")
|
||||
public class FlexmarkTransformer implements Transformer {
|
||||
|
||||
public static final String ID = "flexmark";
|
||||
@ -44,9 +43,8 @@ public class FlexmarkTransformer implements Transformer {
|
||||
private final List<String> classSearchPrefixes = Arrays.asList("", "com.vladsch.flexmark.ext.{name}.", "com.vladsch.flexmark.ext.");
|
||||
private final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
||||
|
||||
private String defaultProfile;
|
||||
|
||||
private List<String> defaultExtensions;
|
||||
@Autowired
|
||||
private FlexmarkConfig config;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws Exception {
|
||||
@ -75,7 +73,7 @@ public class FlexmarkTransformer implements Transformer {
|
||||
if (!MediaType.TEXT_MARKDOWN_VALUE.equals(sourceMimetype))
|
||||
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support source data of the '" + sourceMimetype + "' type");
|
||||
|
||||
String profile = transformOptions.getOrDefault(RequestParamConstants.PROFILE, this.defaultProfile);
|
||||
String profile = transformOptions.getOrDefault(RequestParamConstants.PROFILE, this.config.getDefaultProfile());
|
||||
|
||||
MutableDataSet options = new MutableDataSet();
|
||||
options.setFrom(ParserEmulationProfile.valueOf(profile.toUpperCase()));
|
||||
@ -109,8 +107,8 @@ public class FlexmarkTransformer implements Transformer {
|
||||
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
||||
// include default extensions
|
||||
Set<String> extClassNames = new HashSet<>();
|
||||
if (this.defaultExtensions != null)
|
||||
extClassNames.addAll(this.defaultExtensions);
|
||||
if (this.config.getDefaultExtensions() != null)
|
||||
extClassNames.addAll(this.config.getDefaultExtensions());
|
||||
|
||||
// include/exclude based on passed in extensions
|
||||
String extClassNamesRaw = transformOptions.get(RequestParamConstants.EXT_CLASS_NAMES);
|
||||
|
@ -14,6 +14,8 @@ import org.jsoup.Jsoup;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -25,6 +27,8 @@ import com.inteligr8.junit4.AssertRegex;
|
||||
@WebMvcTest(controllers = TransformerController.class)
|
||||
public abstract class TransformerTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(TransformerTest.class);
|
||||
|
||||
public abstract Transformer getTransformer();
|
||||
|
||||
@Test
|
||||
@ -52,7 +56,12 @@ public abstract class TransformerTest {
|
||||
this.getTransformer().transform(mediaTypePair[0], mediaTypePair[1], Collections.emptyMap(), null, null);
|
||||
Assert.fail();
|
||||
} catch (TransformException te) {
|
||||
try {
|
||||
Assert.assertEquals(te.getMessage(), HttpStatus.BAD_REQUEST.value(), te.getStatusCode());
|
||||
} catch (AssertionError ae) {
|
||||
this.logger.error(ae.getMessage(), te);
|
||||
throw ae;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user