mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2026-09-16 18:12:54 +00:00
ACS-10505 generating xcu file via script instead of officemanager
This commit is contained in:
+38
-50
@@ -36,6 +36,11 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Manages LibreOffice user profile templates for transformations.
|
||||
*
|
||||
* @author Sayan Bhattacharya
|
||||
*/
|
||||
public class LibreOfficeProfileManagerV2
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeProfileManagerV2.class);
|
||||
@@ -43,37 +48,20 @@ public class LibreOfficeProfileManagerV2
|
||||
private final String USER_DIR_NAME = "user";
|
||||
private final String REGISTRY_FILE_NAME = "registrymodifications.xcu";
|
||||
private final String LOCAL_TEMP_REGISTRY_FILE = "templateRegistrymodifications.xcu";
|
||||
private final String DEFAULT_TEMP_PROFILE = "libreoffice/templateProfile";
|
||||
private final String DEFAULT_LO_TEMPLATE_PROFILE = "libreoffice_templateProfile";
|
||||
private final String DEFAULT_ALFRESCO = "default_alfresco";
|
||||
|
||||
private final String userTemplateDir;
|
||||
private String systemTempUserDir = "";
|
||||
private final String configuredTemplateProfileDir;
|
||||
private String tempDefaultTemplateDir;
|
||||
|
||||
public LibreOfficeProfileManagerV2(String templateProfileDir)
|
||||
public LibreOfficeProfileManagerV2(String configuredTemplateProfileDir)
|
||||
{
|
||||
this.userTemplateDir = templateProfileDir;
|
||||
this.configuredTemplateProfileDir = configuredTemplateProfileDir;
|
||||
}
|
||||
|
||||
public String getTemplateProfileDir()
|
||||
public String getEffectiveTemplateProfileDir()
|
||||
{
|
||||
execute();
|
||||
|
||||
if (StringUtils.isNotBlank(userTemplateDir))
|
||||
{
|
||||
return userTemplateDir;
|
||||
}
|
||||
else if (StringUtils.isNotBlank(systemTempUserDir))
|
||||
{
|
||||
return systemTempUserDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void execute()
|
||||
{
|
||||
if (StringUtils.isNotBlank(userTemplateDir))
|
||||
if (isDefaultAlfrescoClasspath(configuredTemplateProfileDir))
|
||||
{
|
||||
validateAndCreateRegistryTemplate();
|
||||
}
|
||||
@@ -81,37 +69,37 @@ public class LibreOfficeProfileManagerV2
|
||||
{
|
||||
checkUserProvidedRegistry();
|
||||
}
|
||||
|
||||
return StringUtils.isBlank(tempDefaultTemplateDir) ? configuredTemplateProfileDir : tempDefaultTemplateDir;
|
||||
}
|
||||
|
||||
private boolean isDefaultAlfrescoClasspath(String templateDir)
|
||||
{
|
||||
return DEFAULT_ALFRESCO.equals(templateDir);
|
||||
}
|
||||
|
||||
private void validateAndCreateRegistryTemplate()
|
||||
{
|
||||
if (userTemplateDir.contains("classpath"))
|
||||
try (InputStream regStream = loadRegistryStream())
|
||||
{
|
||||
String[] split = userTemplateDir.split(":");
|
||||
if (split.length == 2)
|
||||
if (regStream == null)
|
||||
{
|
||||
String classpathTemplateProfileDir = split[1];
|
||||
if (DEFAULT_TEMP_PROFILE.equals(classpathTemplateProfileDir))
|
||||
{
|
||||
try (InputStream regStream = getClass().getClassLoader().getResourceAsStream(LOCAL_TEMP_REGISTRY_FILE))
|
||||
{
|
||||
if (regStream == null)
|
||||
{
|
||||
logger.error("Local temporary registry file not found: {}", LOCAL_TEMP_REGISTRY_FILE);
|
||||
return;
|
||||
}
|
||||
Path tempProfilePath = Files.createTempDirectory(DEFAULT_TEMP_PROFILE);
|
||||
File registryFile = getRegistryFile(tempProfilePath);
|
||||
Files.copy(regStream, registryFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
this.systemTempUserDir = tempProfilePath.toString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("Error creating temporary directory for LibreOffice profile", e);
|
||||
}
|
||||
}
|
||||
logger.error("Local temporary registry file not found: {}", LOCAL_TEMP_REGISTRY_FILE);
|
||||
return;
|
||||
}
|
||||
Path tempProfilePath = Files.createTempDirectory(DEFAULT_LO_TEMPLATE_PROFILE);
|
||||
Files.copy(regStream, getRegistryFile(tempProfilePath).toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
this.tempDefaultTemplateDir = tempProfilePath.toString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("Error creating temporary directory for LibreOffice profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream loadRegistryStream()
|
||||
{
|
||||
return getClass().getClassLoader().getResourceAsStream(LOCAL_TEMP_REGISTRY_FILE);
|
||||
}
|
||||
|
||||
private File getRegistryFile(Path tempProfilePath)
|
||||
@@ -130,10 +118,10 @@ public class LibreOfficeProfileManagerV2
|
||||
|
||||
private void checkUserProvidedRegistry()
|
||||
{
|
||||
File tempDir = new File(userTemplateDir);
|
||||
File tempDir = new File(configuredTemplateProfileDir);
|
||||
if (!tempDir.exists() || !tempDir.isDirectory())
|
||||
{
|
||||
logger.warn("The provided template profile directory does not exist or is not a directory: {}", userTemplateDir);
|
||||
logger.warn("The provided template profile directory does not exist or is not a directory: {}", configuredTemplateProfileDir);
|
||||
return;
|
||||
}
|
||||
File userDir = new File(tempDir, USER_DIR_NAME);
|
||||
|
||||
+3
-3
@@ -120,8 +120,8 @@ public class LibreOfficeTransformer implements JavaExecutor, CustomTransformerFi
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_IS_ENABLED variable must be set to true/false");
|
||||
}
|
||||
|
||||
LibreOfficeProfileManagerV2 lib = new LibreOfficeProfileManagerV2(templateProfileDir);
|
||||
String tempDir = lib.getTemplateProfileDir();
|
||||
LibreOfficeProfileManagerV2 profileManager = new LibreOfficeProfileManagerV2(templateProfileDir);
|
||||
String effectiveTemplateProfileDir = profileManager.getEffectiveTemplateProfileDir();
|
||||
|
||||
JodConverterSharedInstance sharedInstance = new JodConverterSharedInstance();
|
||||
jodconverter = sharedInstance;
|
||||
@@ -132,7 +132,7 @@ public class LibreOfficeTransformer implements JavaExecutor, CustomTransformerFi
|
||||
sharedInstance.setConnectTimeout(timeout);
|
||||
sharedInstance.setPortNumbers(portNumbers);
|
||||
sharedInstance.setEnabled(isEnabled);
|
||||
sharedInstance.setTemplateProfileDir(tempDir);
|
||||
sharedInstance.setTemplateProfileDir(effectiveTemplateProfileDir);
|
||||
sharedInstance.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ transform:
|
||||
maxTasksPerProcess: ${LIBREOFFICE_MAX_TASKS_PER_PROCESS:200}
|
||||
timeout: ${LIBREOFFICE_TIMEOUT:1200000}
|
||||
portNumbers: ${LIBREOFFICE_PORT_NUMBERS:8100}
|
||||
templateProfileDir: ${LIBREOFFICE_TEMPLATE_PROFILE_DIR:classpath:libreoffice/templateProfile}
|
||||
templateProfileDir: ${LIBREOFFICE_TEMPLATE_PROFILE_DIR:default_alfresco}
|
||||
isEnabled: ${LIBREOFFICE_IS_ENABLED:true}
|
||||
@@ -21,7 +21,7 @@
|
||||
<acs-compatible.java.version>11</acs-compatible.java.version>
|
||||
<image.tag>latest</image.tag>
|
||||
<image.registry>quay.io</image.registry>
|
||||
<dependency.pdfbox.version>3.0.6</dependency.pdfbox.version>
|
||||
<dependency.pdfbox.version>3.0.5</dependency.pdfbox.version>
|
||||
<dependency.alfresco-jodconverter-core.version>3.0.1.20</dependency.alfresco-jodconverter-core.version>
|
||||
<env.project_version>${project.version}</env.project_version>
|
||||
<dependency.jackson.version>2.19.2</dependency.jackson.version>
|
||||
|
||||
Reference in New Issue
Block a user