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.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.context.annotation.ImportResource;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@ -43,6 +44,7 @@ import io.micrometer.core.instrument.MeterRegistry;
|
|||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
|
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
|
||||||
|
@EnableConfigurationProperties()
|
||||||
@ImportResource({"classpath*:application-context.xml"})
|
@ImportResource({"classpath*:application-context.xml"})
|
||||||
public class Application {
|
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.commonmark.renderer.html.HtmlRenderer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component(CommonmarkTransformer.ID)
|
@Component(CommonmarkTransformer.ID)
|
||||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.commonmark")
|
|
||||||
public class CommonmarkTransformer implements Transformer {
|
public class CommonmarkTransformer implements Transformer {
|
||||||
|
|
||||||
public static final String ID = "commonmark";
|
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 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 final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
||||||
|
|
||||||
private List<String> defaultExtensions;
|
@Autowired
|
||||||
|
private CommonmarkConfig config;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
@ -101,8 +101,8 @@ public class CommonmarkTransformer implements Transformer {
|
|||||||
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
||||||
// include default extensions
|
// include default extensions
|
||||||
Set<String> extClassNames = new HashSet<>();
|
Set<String> extClassNames = new HashSet<>();
|
||||||
if (this.defaultExtensions != null)
|
if (this.config.getDefaultExtensions() != null)
|
||||||
extClassNames.addAll(this.defaultExtensions);
|
extClassNames.addAll(this.config.getDefaultExtensions());
|
||||||
|
|
||||||
// include/exclude based on passed in extensions
|
// include/exclude based on passed in extensions
|
||||||
String extClassNamesRaw = transformOptions.get(RequestParamConstants.EXT_CLASS_NAMES);
|
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.alfresco.transformer.executors.Transformer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -35,7 +35,6 @@ import com.vladsch.flexmark.util.data.MutableDataSet;
|
|||||||
import com.vladsch.flexmark.util.misc.Extension;
|
import com.vladsch.flexmark.util.misc.Extension;
|
||||||
|
|
||||||
@Component(FlexmarkTransformer.ID)
|
@Component(FlexmarkTransformer.ID)
|
||||||
@ConfigurationProperties(prefix = "transform.alfmarkdown.flexmark")
|
|
||||||
public class FlexmarkTransformer implements Transformer {
|
public class FlexmarkTransformer implements Transformer {
|
||||||
|
|
||||||
public static final String ID = "flexmark";
|
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 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 final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
||||||
|
|
||||||
private String defaultProfile;
|
@Autowired
|
||||||
|
private FlexmarkConfig config;
|
||||||
private List<String> defaultExtensions;
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
@ -75,7 +73,7 @@ public class FlexmarkTransformer implements Transformer {
|
|||||||
if (!MediaType.TEXT_MARKDOWN_VALUE.equals(sourceMimetype))
|
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");
|
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();
|
MutableDataSet options = new MutableDataSet();
|
||||||
options.setFrom(ParserEmulationProfile.valueOf(profile.toUpperCase()));
|
options.setFrom(ParserEmulationProfile.valueOf(profile.toUpperCase()));
|
||||||
@ -109,8 +107,8 @@ public class FlexmarkTransformer implements Transformer {
|
|||||||
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
private List<Extension> gatherExtensions(Map<String, String> transformOptions) {
|
||||||
// include default extensions
|
// include default extensions
|
||||||
Set<String> extClassNames = new HashSet<>();
|
Set<String> extClassNames = new HashSet<>();
|
||||||
if (this.defaultExtensions != null)
|
if (this.config.getDefaultExtensions() != null)
|
||||||
extClassNames.addAll(this.defaultExtensions);
|
extClassNames.addAll(this.config.getDefaultExtensions());
|
||||||
|
|
||||||
// include/exclude based on passed in extensions
|
// include/exclude based on passed in extensions
|
||||||
String extClassNamesRaw = transformOptions.get(RequestParamConstants.EXT_CLASS_NAMES);
|
String extClassNamesRaw = transformOptions.get(RequestParamConstants.EXT_CLASS_NAMES);
|
||||||
|
@ -14,6 +14,8 @@ import org.jsoup.Jsoup;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -25,6 +27,8 @@ import com.inteligr8.junit4.AssertRegex;
|
|||||||
@WebMvcTest(controllers = TransformerController.class)
|
@WebMvcTest(controllers = TransformerController.class)
|
||||||
public abstract class TransformerTest {
|
public abstract class TransformerTest {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(TransformerTest.class);
|
||||||
|
|
||||||
public abstract Transformer getTransformer();
|
public abstract Transformer getTransformer();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -52,7 +56,12 @@ public abstract class TransformerTest {
|
|||||||
this.getTransformer().transform(mediaTypePair[0], mediaTypePair[1], Collections.emptyMap(), null, null);
|
this.getTransformer().transform(mediaTypePair[0], mediaTypePair[1], Collections.emptyMap(), null, null);
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (TransformException te) {
|
} catch (TransformException te) {
|
||||||
Assert.assertEquals(te.getMessage(), HttpStatus.BAD_REQUEST.value(), te.getStatusCode());
|
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