mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
fix mixed-line-ending
This commit is contained in:
86
.gitignore
vendored
86
.gitignore
vendored
@@ -1,43 +1,43 @@
|
|||||||
*.class
|
*.class
|
||||||
|
|
||||||
# Eclipse
|
# Eclipse
|
||||||
.classpath
|
.classpath
|
||||||
.settings
|
.settings
|
||||||
.project
|
.project
|
||||||
|
|
||||||
# Intellij
|
# Intellij
|
||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
# vscode
|
# vscode
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# Mac
|
# Mac
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Maven
|
# Maven
|
||||||
target
|
target
|
||||||
*.log
|
*.log
|
||||||
*.log.*
|
*.log.*
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
# Mobile Tools for Java (J2ME)
|
||||||
|
|
||||||
.mtj
|
.mtj
|
||||||
.tmp/
|
.tmp/
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
|
|
||||||
*.jar
|
*.jar
|
||||||
!quick.jar
|
!quick.jar
|
||||||
*.war
|
*.war
|
||||||
*.ear
|
*.ear
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
alf_data
|
alf_data
|
||||||
/src/main/resources/alfresco-global.properties
|
/src/main/resources/alfresco-global.properties
|
||||||
/src/main/resources/alfresco/extension/custom-log4j.properties
|
/src/main/resources/alfresco/extension/custom-log4j.properties
|
||||||
|
|
||||||
libreoffice-dist-*-linux.gz
|
libreoffice-dist-*-linux.gz
|
||||||
|
@@ -1,126 +1,126 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||||
import org.alfresco.transform.exceptions.TransformException;
|
import org.alfresco.transform.exceptions.TransformException;
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion;
|
import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion;
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.CONFIG_VERSION;
|
import static org.alfresco.transformer.util.RequestParamMap.CONFIG_VERSION;
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
||||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AIOController extends AbstractTransformerController
|
public class AIOController extends AbstractTransformerController
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AIOController.class);
|
private static final Logger logger = LoggerFactory.getLogger(AIOController.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AIOTransformRegistry transformRegistry;
|
private AIOTransformRegistry transformRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransformerName()
|
public String getTransformerName()
|
||||||
{
|
{
|
||||||
return "All in One Transformer";
|
return "All in One Transformer";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String version()
|
public String version()
|
||||||
{
|
{
|
||||||
return getTransformerName() + " available";
|
return getTransformerName() + " available";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO ATS-713 Currently uses the Misc probeTest. The implementation will need to be changed such that the test can be selected based on the required transform
|
// TODO ATS-713 Currently uses the Misc probeTest. The implementation will need to be changed such that the test can be selected based on the required transform
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getProbeTestTransform()
|
public ProbeTestTransform getProbeTestTransform()
|
||||||
{
|
{
|
||||||
// HtmlParserContentTransformer html -> text
|
// HtmlParserContentTransformer html -> text
|
||||||
// See the Javadoc on this method and Probes.md for the choice of these values.
|
// See the Javadoc on this method and Probes.md for the choice of these values.
|
||||||
return new ProbeTestTransform(this, "quick.html", "quick.txt",
|
return new ProbeTestTransform(this, "quick.html", "quick.txt",
|
||||||
119, 30, 150, 1024,
|
119, 30, 150, 1024,
|
||||||
60 * 2 + 1, 60 * 2)
|
60 * 2 + 1, 60 * 2)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||||
{
|
{
|
||||||
Map<String, String> parameters = new HashMap<>();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||||
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<TransformConfig> info(
|
public ResponseEntity<TransformConfig> info(
|
||||||
@RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion)
|
@RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion)
|
||||||
{
|
{
|
||||||
logger.info("GET Transform Config version: " + configVersion);
|
logger.info("GET Transform Config version: " + configVersion);
|
||||||
TransformConfig transformConfig = transformRegistry.getTransformConfig();
|
TransformConfig transformConfig = transformRegistry.getTransformConfig();
|
||||||
transformConfig = setOrClearCoreVersion(transformConfig, configVersion);
|
transformConfig = setOrClearCoreVersion(transformConfig, configVersion);
|
||||||
return new ResponseEntity<>(transformConfig, OK);
|
return new ResponseEntity<>(transformConfig, OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||||
{
|
{
|
||||||
logger.debug("Processing transform with: transformName; '{}', sourceFile '{}', targetFile '{}', transformOptions" +
|
logger.debug("Processing transform with: transformName; '{}', sourceFile '{}', targetFile '{}', transformOptions" +
|
||||||
" {}", transformName, sourceFile, targetFile, transformOptions);
|
" {}", transformName, sourceFile, targetFile, transformOptions);
|
||||||
|
|
||||||
Transformer transformer = transformRegistry.getByTransformName(transformName);
|
Transformer transformer = transformRegistry.getByTransformName(transformName);
|
||||||
if (transformer == null)
|
if (transformer == null)
|
||||||
{
|
{
|
||||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(), "No transformer mapping for - transform:"
|
throw new TransformException(INTERNAL_SERVER_ERROR.value(), "No transformer mapping for - transform:"
|
||||||
+ transformName + " sourceMimetype:" + sourceMimetype + " targetMimetype:" + targetMimetype);
|
+ transformName + " sourceMimetype:" + sourceMimetype + " targetMimetype:" + targetMimetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Performing transform with name '{}' using transformer with id '{}'.", transformName, transformer.getTransformerId());
|
logger.debug("Performing transform with name '{}' using transformer with id '{}'.", transformName, transformer.getTransformerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
||||||
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,123 +1,123 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||||
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
|
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
|
||||||
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
||||||
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
|
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
|
||||||
import org.alfresco.transformer.executors.TikaJavaExecutor;
|
import org.alfresco.transformer.executors.TikaJavaExecutor;
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.alfresco.transformer.transformers.SelectingTransformer;
|
import org.alfresco.transformer.transformers.SelectingTransformer;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class AIOCustomConfig
|
public class AIOCustomConfig
|
||||||
{
|
{
|
||||||
@Value("${transform.core.libreoffice.path}")
|
@Value("${transform.core.libreoffice.path}")
|
||||||
private String libreofficePath;
|
private String libreofficePath;
|
||||||
|
|
||||||
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
||||||
private String libreofficeMaxTasksPerProcess;
|
private String libreofficeMaxTasksPerProcess;
|
||||||
|
|
||||||
@Value("${transform.core.libreoffice.timeout}")
|
@Value("${transform.core.libreoffice.timeout}")
|
||||||
private String libreofficeTimeout;
|
private String libreofficeTimeout;
|
||||||
|
|
||||||
@Value("${transform.core.libreoffice.portNumbers}")
|
@Value("${transform.core.libreoffice.portNumbers}")
|
||||||
private String libreofficePortNumbers;
|
private String libreofficePortNumbers;
|
||||||
|
|
||||||
@Value("${transform.core.libreoffice.templateProfileDir}")
|
@Value("${transform.core.libreoffice.templateProfileDir}")
|
||||||
private String libreofficeTemplateProfileDir;
|
private String libreofficeTemplateProfileDir;
|
||||||
|
|
||||||
@Value("${transform.core.libreoffice.isEnabled}")
|
@Value("${transform.core.libreoffice.isEnabled}")
|
||||||
private String libreofficeIsEnabled;
|
private String libreofficeIsEnabled;
|
||||||
|
|
||||||
@Value("${transform.core.pdfrenderer.exe}")
|
@Value("${transform.core.pdfrenderer.exe}")
|
||||||
private String pdfRendererPath;
|
private String pdfRendererPath;
|
||||||
|
|
||||||
@Value("${transform.core.imagemagick.exe}")
|
@Value("${transform.core.imagemagick.exe}")
|
||||||
private String imageMagickExePath;
|
private String imageMagickExePath;
|
||||||
|
|
||||||
@Value("${transform.core.imagemagick.dyn}")
|
@Value("${transform.core.imagemagick.dyn}")
|
||||||
private String imageMagickDynPath;
|
private String imageMagickDynPath;
|
||||||
|
|
||||||
@Value("${transform.core.imagemagick.root}")
|
@Value("${transform.core.imagemagick.root}")
|
||||||
private String imageMagickRootPath;
|
private String imageMagickRootPath;
|
||||||
|
|
||||||
@Value("${transform.core.imagemagick.coders}")
|
@Value("${transform.core.imagemagick.coders}")
|
||||||
private String imageMagickCodersPath;
|
private String imageMagickCodersPath;
|
||||||
|
|
||||||
@Value("${transform.core.imagemagick.config}")
|
@Value("${transform.core.imagemagick.config}")
|
||||||
private String imageMagickConfigPath;
|
private String imageMagickConfigPath;
|
||||||
|
|
||||||
@Value("${transform.core.tika.pdfBox.notExtractBookmarksTextDefault:false}")
|
@Value("${transform.core.tika.pdfBox.notExtractBookmarksTextDefault:false}")
|
||||||
private boolean notExtractBookmarksTextDefault;
|
private boolean notExtractBookmarksTextDefault;
|
||||||
|
|
||||||
@Value("${transform.core.version}")
|
@Value("${transform.core.version}")
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return Override the TransformRegistryImpl used in {@link AbstractTransformerController}
|
* @return Override the TransformRegistryImpl used in {@link AbstractTransformerController}
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public TransformServiceRegistry aioTransformRegistry() throws Exception
|
public TransformServiceRegistry aioTransformRegistry() throws Exception
|
||||||
{
|
{
|
||||||
AIOTransformRegistry aioTransformRegistry = new AIOTransformRegistry();
|
AIOTransformRegistry aioTransformRegistry = new AIOTransformRegistry();
|
||||||
aioTransformRegistry.setCoreVersion(coreVersion);
|
aioTransformRegistry.setCoreVersion(coreVersion);
|
||||||
|
|
||||||
// T-Engines are sorted by name so they are combined in the same order as in the T-Router
|
// T-Engines are sorted by name so they are combined in the same order as in the T-Router
|
||||||
// and Content Repository with individual T-Engines. See TransformersConfigRegistry#retrieveRemoteConfig and
|
// and Content Repository with individual T-Engines. See TransformersConfigRegistry#retrieveRemoteConfig and
|
||||||
// LocalTransformServiceRegistry#getTEngineUrlsSortedByName.
|
// LocalTransformServiceRegistry#getTEngineUrlsSortedByName.
|
||||||
for (Transformer tEngine : getTEnginesSortedByName())
|
for (Transformer tEngine : getTEnginesSortedByName())
|
||||||
{
|
{
|
||||||
aioTransformRegistry.registerTransformer(tEngine); // now a poor name - should be combineTransformers
|
aioTransformRegistry.registerTransformer(tEngine); // now a poor name - should be combineTransformers
|
||||||
}
|
}
|
||||||
aioTransformRegistry.registerCombinedTransformers();
|
aioTransformRegistry.registerCombinedTransformers();
|
||||||
return aioTransformRegistry;
|
return aioTransformRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Transformer> getTEnginesSortedByName()
|
List<Transformer> getTEnginesSortedByName()
|
||||||
{
|
{
|
||||||
return Stream.of(new SelectingTransformer(),
|
return Stream.of(new SelectingTransformer(),
|
||||||
new TikaJavaExecutor(notExtractBookmarksTextDefault),
|
new TikaJavaExecutor(notExtractBookmarksTextDefault),
|
||||||
new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath),
|
new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath),
|
||||||
new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled),
|
new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled),
|
||||||
new PdfRendererCommandExecutor(pdfRendererPath))
|
new PdfRendererCommandExecutor(pdfRendererPath))
|
||||||
.sorted(Comparator.comparing(Transformer::getTransformerId))
|
.sorted(Comparator.comparing(Transformer::getTransformerId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,85 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
|
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
|
||||||
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
||||||
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
|
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
|
||||||
import org.alfresco.transformer.executors.TikaJavaExecutor;
|
import org.alfresco.transformer.executors.TikaJavaExecutor;
|
||||||
import org.alfresco.transformer.transformers.SelectingTransformer;
|
import org.alfresco.transformer.transformers.SelectingTransformer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
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.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class Application
|
public class Application
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
||||||
|
|
||||||
@Value("${container.name}")
|
@Value("${container.name}")
|
||||||
private String containerName;
|
private String containerName;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||||
{
|
{
|
||||||
return registry -> registry.config().commonTags("containerName", containerName);
|
return registry -> registry.config().commonTags("containerName", containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void startup()
|
public void startup()
|
||||||
{
|
{
|
||||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||||
logger.info(ImageMagickCommandExecutor.LICENCE);
|
logger.info(ImageMagickCommandExecutor.LICENCE);
|
||||||
logger.info(LibreOfficeJavaExecutor.LICENCE);
|
logger.info(LibreOfficeJavaExecutor.LICENCE);
|
||||||
Arrays.stream(TikaJavaExecutor.LICENCE.split("\\n")).forEach(logger::info);
|
Arrays.stream(TikaJavaExecutor.LICENCE.split("\\n")).forEach(logger::info);
|
||||||
logger.info(PdfRendererCommandExecutor.LICENCE);
|
logger.info(PdfRendererCommandExecutor.LICENCE);
|
||||||
Arrays.stream(SelectingTransformer.LICENCE.split("\\n")).forEach(logger::info);
|
Arrays.stream(SelectingTransformer.LICENCE.split("\\n")).forEach(logger::info);
|
||||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
logger.info("Starting application components... Done");
|
logger.info("Starting application components... Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,127 +1,127 @@
|
|||||||
The "Artistic License"
|
The "Artistic License"
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The intent of this document is to state the conditions under which a
|
The intent of this document is to state the conditions under which a
|
||||||
Package may be copied, such that the Copyright Holder maintains some
|
Package may be copied, such that the Copyright Holder maintains some
|
||||||
semblance of artistic control over the development of the package,
|
semblance of artistic control over the development of the package,
|
||||||
while giving the users of the package the right to use and distribute
|
while giving the users of the package the right to use and distribute
|
||||||
the Package in a more-or-less customary fashion, plus the right to make
|
the Package in a more-or-less customary fashion, plus the right to make
|
||||||
reasonable modifications.
|
reasonable modifications.
|
||||||
|
|
||||||
Definitions:
|
Definitions:
|
||||||
|
|
||||||
"Package" refers to the collection of files distributed by the
|
"Package" refers to the collection of files distributed by the
|
||||||
Copyright Holder, and derivatives of that collection of files
|
Copyright Holder, and derivatives of that collection of files
|
||||||
created through textual modification.
|
created through textual modification.
|
||||||
|
|
||||||
"Standard Version" refers to such a Package if it has not been
|
"Standard Version" refers to such a Package if it has not been
|
||||||
modified, or has been modified in accordance with the wishes
|
modified, or has been modified in accordance with the wishes
|
||||||
of the Copyright Holder as specified below.
|
of the Copyright Holder as specified below.
|
||||||
|
|
||||||
"Copyright Holder" is whoever is named in the copyright or
|
"Copyright Holder" is whoever is named in the copyright or
|
||||||
copyrights for the package.
|
copyrights for the package.
|
||||||
|
|
||||||
"You" is you, if you're thinking about copying or distributing
|
"You" is you, if you're thinking about copying or distributing
|
||||||
this Package.
|
this Package.
|
||||||
|
|
||||||
"Reasonable copying fee" is whatever you can justify on the
|
"Reasonable copying fee" is whatever you can justify on the
|
||||||
basis of media cost, duplication charges, time of people involved,
|
basis of media cost, duplication charges, time of people involved,
|
||||||
and so on. (You will not be required to justify it to the
|
and so on. (You will not be required to justify it to the
|
||||||
Copyright Holder, but only to the computing community at large
|
Copyright Holder, but only to the computing community at large
|
||||||
as a market that must bear the fee.)
|
as a market that must bear the fee.)
|
||||||
|
|
||||||
"Freely Available" means that no fee is charged for the item
|
"Freely Available" means that no fee is charged for the item
|
||||||
itself, though there may be fees involved in handling the item.
|
itself, though there may be fees involved in handling the item.
|
||||||
It also means that recipients of the item may redistribute it
|
It also means that recipients of the item may redistribute it
|
||||||
under the same conditions they received it.
|
under the same conditions they received it.
|
||||||
|
|
||||||
1. You may make and give away verbatim copies of the source form of the
|
1. You may make and give away verbatim copies of the source form of the
|
||||||
Standard Version of this Package without restriction, provided that you
|
Standard Version of this Package without restriction, provided that you
|
||||||
duplicate all of the original copyright notices and associated disclaimers.
|
duplicate all of the original copyright notices and associated disclaimers.
|
||||||
|
|
||||||
2. You may apply bug fixes, portability fixes and other modifications
|
2. You may apply bug fixes, portability fixes and other modifications
|
||||||
derived from the Public Domain or from the Copyright Holder. A Package
|
derived from the Public Domain or from the Copyright Holder. A Package
|
||||||
modified in such a way shall still be considered the Standard Version.
|
modified in such a way shall still be considered the Standard Version.
|
||||||
|
|
||||||
3. You may otherwise modify your copy of this Package in any way, provided
|
3. You may otherwise modify your copy of this Package in any way, provided
|
||||||
that you insert a prominent notice in each changed file stating how and
|
that you insert a prominent notice in each changed file stating how and
|
||||||
when you changed that file, and provided that you do at least ONE of the
|
when you changed that file, and provided that you do at least ONE of the
|
||||||
following:
|
following:
|
||||||
|
|
||||||
a) place your modifications in the Public Domain or otherwise make them
|
a) place your modifications in the Public Domain or otherwise make them
|
||||||
Freely Available, such as by posting said modifications to Usenet or
|
Freely Available, such as by posting said modifications to Usenet or
|
||||||
an equivalent medium, or placing the modifications on a major archive
|
an equivalent medium, or placing the modifications on a major archive
|
||||||
site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
||||||
your modifications in the Standard Version of the Package.
|
your modifications in the Standard Version of the Package.
|
||||||
|
|
||||||
b) use the modified Package only within your corporation or organization.
|
b) use the modified Package only within your corporation or organization.
|
||||||
|
|
||||||
c) rename any non-standard executables so the names do not conflict
|
c) rename any non-standard executables so the names do not conflict
|
||||||
with standard executables, which must also be provided, and provide
|
with standard executables, which must also be provided, and provide
|
||||||
a separate manual page for each non-standard executable that clearly
|
a separate manual page for each non-standard executable that clearly
|
||||||
documents how it differs from the Standard Version.
|
documents how it differs from the Standard Version.
|
||||||
|
|
||||||
d) make other distribution arrangements with the Copyright Holder.
|
d) make other distribution arrangements with the Copyright Holder.
|
||||||
|
|
||||||
4. You may distribute the programs of this Package in object code or
|
4. You may distribute the programs of this Package in object code or
|
||||||
executable form, provided that you do at least ONE of the following:
|
executable form, provided that you do at least ONE of the following:
|
||||||
|
|
||||||
a) distribute a Standard Version of the executables and library files,
|
a) distribute a Standard Version of the executables and library files,
|
||||||
together with instructions (in the manual page or equivalent) on where
|
together with instructions (in the manual page or equivalent) on where
|
||||||
to get the Standard Version.
|
to get the Standard Version.
|
||||||
|
|
||||||
b) accompany the distribution with the machine-readable source of
|
b) accompany the distribution with the machine-readable source of
|
||||||
the Package with your modifications.
|
the Package with your modifications.
|
||||||
|
|
||||||
c) give non-standard executables non-standard names, and clearly
|
c) give non-standard executables non-standard names, and clearly
|
||||||
document the differences in manual pages (or equivalent), together
|
document the differences in manual pages (or equivalent), together
|
||||||
with instructions on where to get the Standard Version.
|
with instructions on where to get the Standard Version.
|
||||||
|
|
||||||
d) make other distribution arrangements with the Copyright Holder.
|
d) make other distribution arrangements with the Copyright Holder.
|
||||||
|
|
||||||
5. You may charge a reasonable copying fee for any distribution of this
|
5. You may charge a reasonable copying fee for any distribution of this
|
||||||
Package. You may charge any fee you choose for support of this
|
Package. You may charge any fee you choose for support of this
|
||||||
Package. You may not charge a fee for this Package itself. However,
|
Package. You may not charge a fee for this Package itself. However,
|
||||||
you may distribute this Package in aggregate with other (possibly
|
you may distribute this Package in aggregate with other (possibly
|
||||||
commercial) programs as part of a larger (possibly commercial) software
|
commercial) programs as part of a larger (possibly commercial) software
|
||||||
distribution provided that you do not advertise this Package as a
|
distribution provided that you do not advertise this Package as a
|
||||||
product of your own. You may embed this Package's interpreter within
|
product of your own. You may embed this Package's interpreter within
|
||||||
an executable of yours (by linking); this shall be construed as a mere
|
an executable of yours (by linking); this shall be construed as a mere
|
||||||
form of aggregation, provided that the complete Standard Version of the
|
form of aggregation, provided that the complete Standard Version of the
|
||||||
interpreter is so embedded.
|
interpreter is so embedded.
|
||||||
|
|
||||||
6. The scripts and library files supplied as input to or produced as
|
6. The scripts and library files supplied as input to or produced as
|
||||||
output from the programs of this Package do not automatically fall
|
output from the programs of this Package do not automatically fall
|
||||||
under the copyright of this Package, but belong to whoever generated
|
under the copyright of this Package, but belong to whoever generated
|
||||||
them, and may be sold commercially, and may be aggregated with this
|
them, and may be sold commercially, and may be aggregated with this
|
||||||
Package. If such scripts or library files are aggregated with this
|
Package. If such scripts or library files are aggregated with this
|
||||||
Package via the so-called "undump" or "unexec" methods of producing a
|
Package via the so-called "undump" or "unexec" methods of producing a
|
||||||
binary executable image, then distribution of such an image shall
|
binary executable image, then distribution of such an image shall
|
||||||
neither be construed as a distribution of this Package nor shall it
|
neither be construed as a distribution of this Package nor shall it
|
||||||
fall under the restrictions of Paragraphs 3 and 4, provided that you do
|
fall under the restrictions of Paragraphs 3 and 4, provided that you do
|
||||||
not represent such an executable image as a Standard Version of this
|
not represent such an executable image as a Standard Version of this
|
||||||
Package.
|
Package.
|
||||||
|
|
||||||
7. C subroutines (or comparably compiled subroutines in other
|
7. C subroutines (or comparably compiled subroutines in other
|
||||||
languages) supplied by you and linked into this Package in order to
|
languages) supplied by you and linked into this Package in order to
|
||||||
emulate subroutines and variables of the language defined by this
|
emulate subroutines and variables of the language defined by this
|
||||||
Package shall not be considered part of this Package, but are the
|
Package shall not be considered part of this Package, but are the
|
||||||
equivalent of input as in Paragraph 6, provided these subroutines do
|
equivalent of input as in Paragraph 6, provided these subroutines do
|
||||||
not change the language in any way that would cause it to fail the
|
not change the language in any way that would cause it to fail the
|
||||||
regression tests for the language.
|
regression tests for the language.
|
||||||
|
|
||||||
8. Aggregation of this Package with a commercial distribution is always
|
8. Aggregation of this Package with a commercial distribution is always
|
||||||
permitted provided that the use of this Package is embedded; that is,
|
permitted provided that the use of this Package is embedded; that is,
|
||||||
when no overt attempt is made to make this Package's interfaces visible
|
when no overt attempt is made to make this Package's interfaces visible
|
||||||
to the end user of the commercial distribution. Such use shall not be
|
to the end user of the commercial distribution. Such use shall not be
|
||||||
construed as a distribution of this Package.
|
construed as a distribution of this Package.
|
||||||
|
|
||||||
9. The name of the Copyright Holder may not be used to endorse or promote
|
9. The name of the Copyright Holder may not be used to endorse or promote
|
||||||
products derived from this software without specific prior written permission.
|
products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
||||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
The End
|
The End
|
||||||
|
@@ -1,49 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||||
public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest
|
public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTransformerName()
|
protected String getTransformerName()
|
||||||
{
|
{
|
||||||
return "All in One Transformer";
|
return "All in One Transformer";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSourceExtension()
|
protected String getSourceExtension()
|
||||||
{
|
{
|
||||||
// Currently using same extension as ImageMagick tests
|
// Currently using same extension as ImageMagick tests
|
||||||
return "jpg";
|
return "jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,141 +1,141 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the AIOController ImageMagick transforms without a server.
|
* Test the AIOController ImageMagick transforms without a server.
|
||||||
* Super class includes tests for the AbstractTransformerController.
|
* Super class includes tests for the AbstractTransformerController.
|
||||||
*/
|
*/
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
public class AIOControllerImageMagickTest extends ImageMagickControllerTest
|
public class AIOControllerImageMagickTest extends ImageMagickControllerTest
|
||||||
{
|
{
|
||||||
// All tests contained in ImageMagickControllerTest
|
// All tests contained in ImageMagickControllerTest
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AIOTransformRegistry transformRegistry;
|
AIOTransformRegistry transformRegistry;
|
||||||
|
|
||||||
@BeforeEach @Override
|
@BeforeEach @Override
|
||||||
public void before() throws IOException
|
public void before() throws IOException
|
||||||
{
|
{
|
||||||
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||||
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||||
//Need to wire in the mocked commandExecutor into the controller...
|
//Need to wire in the mocked commandExecutor into the controller...
|
||||||
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
||||||
transformers.replace("imagemagick", commandExecutor);
|
transformers.replace("imagemagick", commandExecutor);
|
||||||
|
|
||||||
mockTransformCommand("jpg", "png", "image/jpeg", true);
|
mockTransformCommand("jpg", "png", "image/jpeg", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractTransformerController getController()
|
protected AbstractTransformerController getController()
|
||||||
{
|
{
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||||
String... params)
|
String... params)
|
||||||
{
|
{
|
||||||
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
||||||
.param("targetMimetype", targetMimetype)
|
.param("targetMimetype", targetMimetype)
|
||||||
.param("sourceMimetype", sourceMimetype);
|
.param("sourceMimetype", sourceMimetype);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTestValidity()
|
public void testTestValidity()
|
||||||
{
|
{
|
||||||
// just test that we are actually testing against the AIOController (instead of MiscController)
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void noTargetFileTest()
|
public void noTargetFileTest()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the AIO transforms will not be selected .
|
// Ignore the test in super class as the AIO transforms will not be selected .
|
||||||
// It is the mock that returns a zero length file for other transformers, when we supply an invalid targetExtension.
|
// It is the mock that returns a zero length file for other transformers, when we supply an invalid targetExtension.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfo()
|
public void testGetTransformConfigInfo()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfoExcludingCoreVersion()
|
public void testGetTransformConfigInfoExcludingCoreVersion()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithDuplicates()
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithNoTransformOptions()
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,119 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
/**
|
/**
|
||||||
* Test the AIOController without a server.
|
* Test the AIOController without a server.
|
||||||
* Super class includes tests for the LibreOfficeController and AbstractTransformerController.
|
* Super class includes tests for the LibreOfficeController and AbstractTransformerController.
|
||||||
*/
|
*/
|
||||||
public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest
|
public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest
|
||||||
{
|
{
|
||||||
//Tests contained in LibreOfficeControllerTest
|
//Tests contained in LibreOfficeControllerTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTestValidity()
|
public void testTestValidity()
|
||||||
{
|
{
|
||||||
// just test that we are actually testing against the AIOController (instead of MiscController)
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
|
assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AIOTransformRegistry transformRegistry;
|
AIOTransformRegistry transformRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
// Used by the super class to mock the javaExecutor, a different implementation is required here
|
// Used by the super class to mock the javaExecutor, a different implementation is required here
|
||||||
protected void setJavaExecutor(AbstractTransformerController controller, LibreOfficeJavaExecutor javaExecutor)
|
protected void setJavaExecutor(AbstractTransformerController controller, LibreOfficeJavaExecutor javaExecutor)
|
||||||
{
|
{
|
||||||
//Need to wire in the mocked javaExecutor into the controller...
|
//Need to wire in the mocked javaExecutor into the controller...
|
||||||
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
||||||
transformers.replace("libreoffice", javaExecutor);
|
transformers.replace("libreoffice", javaExecutor);
|
||||||
// No need to set the transform registry to the controller as it is @Autowired in
|
// No need to set the transform registry to the controller as it is @Autowired in
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||||
String... params)
|
String... params)
|
||||||
{
|
{
|
||||||
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
||||||
.param("targetMimetype", targetMimetype)
|
.param("targetMimetype", targetMimetype)
|
||||||
.param("sourceMimetype", sourceMimetype);
|
.param("sourceMimetype", sourceMimetype);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfo()
|
public void testGetTransformConfigInfo()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfoExcludingCoreVersion()
|
public void testGetTransformConfigInfoExcludingCoreVersion()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithDuplicates()
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithNoTransformOptions()
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,85 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
public class AIOControllerMiscTest extends MiscControllerTest
|
public class AIOControllerMiscTest extends MiscControllerTest
|
||||||
{
|
{
|
||||||
//Tests contained in MiscControllerTest
|
//Tests contained in MiscControllerTest
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTestValidity()
|
public void testTestValidity()
|
||||||
{
|
{
|
||||||
// just test that we are actually testing against the AIOController (instead of MiscController)
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfo()
|
public void testGetTransformConfigInfo()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfoExcludingCoreVersion()
|
public void testGetTransformConfigInfoExcludingCoreVersion()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithDuplicates()
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithNoTransformOptions()
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,119 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
/**
|
/**
|
||||||
* Test the AIOController PDF Renderer transforms without a server.
|
* Test the AIOController PDF Renderer transforms without a server.
|
||||||
* Super class includes tests for the AbstractTransformerController.
|
* Super class includes tests for the AbstractTransformerController.
|
||||||
*/
|
*/
|
||||||
public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerTest
|
public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerTest
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
AIOTransformRegistry transformRegistry;
|
AIOTransformRegistry transformRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setFields()
|
protected void setFields()
|
||||||
{
|
{
|
||||||
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||||
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||||
//Need to wire in the mocked commandExecutor into the controller...
|
//Need to wire in the mocked commandExecutor into the controller...
|
||||||
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
Map<String,Transformer> transformers = transformRegistry.getTransformerEngineMapping();
|
||||||
transformers.replace("pdfrenderer", commandExecutor);
|
transformers.replace("pdfrenderer", commandExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||||
String... params)
|
String... params)
|
||||||
{
|
{
|
||||||
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
||||||
.param("targetMimetype", targetMimetype)
|
.param("targetMimetype", targetMimetype)
|
||||||
.param("sourceMimetype", sourceMimetype);
|
.param("sourceMimetype", sourceMimetype);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTestValidity()
|
public void testTestValidity()
|
||||||
{
|
{
|
||||||
// just test that we are actually testing against the AIOController (instead of MiscController)
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
assertTrue(controller instanceof AIOController, "Wrong controller wired for test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfo()
|
public void testGetTransformConfigInfo()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfoExcludingCoreVersion()
|
public void testGetTransformConfigInfoExcludingCoreVersion()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithDuplicates()
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithNoTransformOptions()
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,93 +1,93 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_LATEST;
|
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_LATEST;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
public class AIOControllerTest //extends AbstractTransformerControllerTest
|
public class AIOControllerTest //extends AbstractTransformerControllerTest
|
||||||
{
|
{
|
||||||
@Value("${transform.core.version}")
|
@Value("${transform.core.version}")
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
AIOController aioController;
|
AIOController aioController;
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
protected void mockTransformCommand(String sourceExtension, String targetExtension, String sourceMimetype,
|
protected void mockTransformCommand(String sourceExtension, String targetExtension, String sourceMimetype,
|
||||||
boolean readTargetFileBytes) throws IOException {
|
boolean readTargetFileBytes) throws IOException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
protected AbstractTransformerController getController() {
|
protected AbstractTransformerController getController() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest) {
|
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyTest()
|
public void emptyTest()
|
||||||
{
|
{
|
||||||
ResponseEntity<TransformConfig> responseEntity = aioController.info(Integer.valueOf(CONFIG_VERSION_DEFAULT));
|
ResponseEntity<TransformConfig> responseEntity = aioController.info(Integer.valueOf(CONFIG_VERSION_DEFAULT));
|
||||||
responseEntity.getBody().getTransformers().forEach(transformer -> {
|
responseEntity.getBody().getTransformers().forEach(transformer -> {
|
||||||
assertNull(transformer.getCoreVersion(), transformer.getTransformerName() +
|
assertNull(transformer.getCoreVersion(), transformer.getTransformerName() +
|
||||||
" should have had a null coreValue but was " + transformer.getCoreVersion());
|
" should have had a null coreValue but was " + transformer.getCoreVersion());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyTestWithLatestVersion()
|
public void emptyTestWithLatestVersion()
|
||||||
{
|
{
|
||||||
ResponseEntity<TransformConfig> responseEntity = aioController.info(CONFIG_VERSION_LATEST);
|
ResponseEntity<TransformConfig> responseEntity = aioController.info(CONFIG_VERSION_LATEST);
|
||||||
responseEntity.getBody().getTransformers().forEach(transformer -> {
|
responseEntity.getBody().getTransformers().forEach(transformer -> {
|
||||||
assertNotNull(transformer.getCoreVersion(), transformer.getTransformerName() +
|
assertNotNull(transformer.getCoreVersion(), transformer.getTransformerName() +
|
||||||
" should have had a coreValue but was null. Should have been " + coreVersion);
|
" should have had a coreValue but was null. Should have been " + coreVersion);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,99 +1,99 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@WebMvcTest(AIOController.class)
|
@WebMvcTest(AIOController.class)
|
||||||
@Import(AIOCustomConfig.class)
|
@Import(AIOCustomConfig.class)
|
||||||
/**
|
/**
|
||||||
* Test the AIOController Tika transforms without a server.
|
* Test the AIOController Tika transforms without a server.
|
||||||
* Super class includes tests for the AbstractTransformerController.
|
* Super class includes tests for the AbstractTransformerController.
|
||||||
*/
|
*/
|
||||||
public class AIOControllerTikaTest extends TikaControllerTest
|
public class AIOControllerTikaTest extends TikaControllerTest
|
||||||
{
|
{
|
||||||
// All tests contained in TikaControllerTest
|
// All tests contained in TikaControllerTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTestValidity()
|
public void testTestValidity()
|
||||||
{
|
{
|
||||||
// just test that we are actually testing against the AIOController (instead of MiscController)
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
|
assertTrue(controller instanceof AIOController,"Wrong controller wired for test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfo()
|
public void testGetTransformConfigInfo()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetTransformConfigInfoExcludingCoreVersion()
|
public void testGetTransformConfigInfoExcludingCoreVersion()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithDuplicates()
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testGetInfoFromConfigWithNoTransformOptions()
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void xlsxEmbedTest()
|
public void xlsxEmbedTest()
|
||||||
{
|
{
|
||||||
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
// Ignore the test in super class as the way the AIO transformer provides config is fundamentally different.
|
||||||
// It uses the real class path rather than the test one.
|
// It uses the real class path rather than the test one.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
public class AIOImageMagickIT extends ImageMagickTransformationIT
|
public class AIOImageMagickIT extends ImageMagickTransformationIT
|
||||||
{
|
{
|
||||||
// Tests are in ImageMagickTransformationIT
|
// Tests are in ImageMagickTransformationIT
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
public class AIOLibreOfficeTransformationIT extends LibreOfficeTransformationIT
|
public class AIOLibreOfficeTransformationIT extends LibreOfficeTransformationIT
|
||||||
{
|
{
|
||||||
// Tests are in LibreOfficeTransformationIT
|
// Tests are in LibreOfficeTransformationIT
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
public class AIOMiscTransformsIT extends MiscTransformsIT
|
public class AIOMiscTransformsIT extends MiscTransformsIT
|
||||||
{
|
{
|
||||||
// Tests are in ImageMagickTransformationIT
|
// Tests are in ImageMagickTransformationIT
|
||||||
}
|
}
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT {
|
public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT {
|
||||||
// Tests are in AlfrescoPdfRendererTransformationIT
|
// Tests are in AlfrescoPdfRendererTransformationIT
|
||||||
}
|
}
|
||||||
|
@@ -1,60 +1,60 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author David Edwards
|
* @author David Edwards
|
||||||
* created on 21/04/2020
|
* created on 21/04/2020
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
properties = {"activemq.url=nio://localhost:61616"})
|
properties = {"activemq.url=nio://localhost:61616"})
|
||||||
public class AIOQueueTransformServiceIT extends AbstractQueueTransformServiceIT
|
public class AIOQueueTransformServiceIT extends AbstractQueueTransformServiceIT
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected TransformRequest buildRequest()
|
protected TransformRequest buildRequest()
|
||||||
{
|
{
|
||||||
return TransformRequest
|
return TransformRequest
|
||||||
.builder()
|
.builder()
|
||||||
.withRequestId(UUID.randomUUID().toString())
|
.withRequestId(UUID.randomUUID().toString())
|
||||||
.withSourceMediaType(MIMETYPE_HTML)
|
.withSourceMediaType(MIMETYPE_HTML)
|
||||||
.withTargetMediaType(MIMETYPE_TEXT_PLAIN)
|
.withTargetMediaType(MIMETYPE_TEXT_PLAIN)
|
||||||
.withTargetExtension("txt")
|
.withTargetExtension("txt")
|
||||||
.withSchema(1)
|
.withSchema(1)
|
||||||
.withClientData("ACS")
|
.withClientData("ACS")
|
||||||
.withSourceReference(UUID.randomUUID().toString())
|
.withSourceReference(UUID.randomUUID().toString())
|
||||||
.withSourceSize(32L)
|
.withSourceSize(32L)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
public class AIOTikaTransformationIT extends TikaTransformationIT
|
public class AIOTikaTransformationIT extends TikaTransformationIT
|
||||||
{
|
{
|
||||||
// Tests are in ImageMagickTransformationIT
|
// Tests are in ImageMagickTransformationIT
|
||||||
}
|
}
|
||||||
|
@@ -1,77 +1,77 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import org.alfresco.transformer.transformers.SelectingTransformer;
|
import org.alfresco.transformer.transformers.SelectingTransformer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
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.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class Application
|
public class Application
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
||||||
|
|
||||||
@Value("${container.name}")
|
@Value("${container.name}")
|
||||||
private String containerName;
|
private String containerName;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||||
{
|
{
|
||||||
return registry -> registry.config().commonTags("containerName", containerName);
|
return registry -> registry.config().commonTags("containerName", containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void startup()
|
public void startup()
|
||||||
{
|
{
|
||||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||||
Arrays.stream(SelectingTransformer.LICENCE.split("\\n")).forEach(logger::info);
|
Arrays.stream(SelectingTransformer.LICENCE.split("\\n")).forEach(logger::info);
|
||||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
logger.info("Starting application components... Done");
|
logger.info("Starting application components... Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,89 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||||
import org.alfresco.transformer.transformers.SelectingTransformer;
|
import org.alfresco.transformer.transformers.SelectingTransformer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MiscController extends AbstractTransformerController
|
public class MiscController extends AbstractTransformerController
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MiscController.class);
|
private static final Logger logger = LoggerFactory.getLogger(MiscController.class);
|
||||||
|
|
||||||
private SelectingTransformer transformer = new SelectingTransformer();
|
private SelectingTransformer transformer = new SelectingTransformer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransformerName()
|
public String getTransformerName()
|
||||||
{
|
{
|
||||||
return "Miscellaneous Transformers";
|
return "Miscellaneous Transformers";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String version()
|
public String version()
|
||||||
{
|
{
|
||||||
return getTransformerName() + " available";
|
return getTransformerName() + " available";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getProbeTestTransform()
|
public ProbeTestTransform getProbeTestTransform()
|
||||||
{
|
{
|
||||||
// HtmlParserContentTransformer html -> text
|
// HtmlParserContentTransformer html -> text
|
||||||
// See the Javadoc on this method and Probes.md for the choice of these values.
|
// See the Javadoc on this method and Probes.md for the choice of these values.
|
||||||
return new ProbeTestTransform(this, "quick.html", "quick.txt",
|
return new ProbeTestTransform(this, "quick.html", "quick.txt",
|
||||||
119, 30, 150, 1024,
|
119, 30, 150, 1024,
|
||||||
60 * 2 + 1, 60 * 2)
|
60 * 2 + 1, 60 * 2)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||||
{
|
{
|
||||||
Map<String, String> parameters = new HashMap<>();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||||
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||||
{
|
{
|
||||||
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
|
||||||
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,55 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
properties = {"activemq.url=nio://localhost:61616"})
|
properties = {"activemq.url=nio://localhost:61616"})
|
||||||
public class MiscQueueTransformServiceIT extends AbstractQueueTransformServiceIT
|
public class MiscQueueTransformServiceIT extends AbstractQueueTransformServiceIT
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected TransformRequest buildRequest()
|
protected TransformRequest buildRequest()
|
||||||
{
|
{
|
||||||
return TransformRequest
|
return TransformRequest
|
||||||
.builder()
|
.builder()
|
||||||
.withRequestId(UUID.randomUUID().toString())
|
.withRequestId(UUID.randomUUID().toString())
|
||||||
.withSourceMediaType(MIMETYPE_HTML)
|
.withSourceMediaType(MIMETYPE_HTML)
|
||||||
.withTargetMediaType(MIMETYPE_TEXT_PLAIN)
|
.withTargetMediaType(MIMETYPE_TEXT_PLAIN)
|
||||||
.withTargetExtension("txt")
|
.withTargetExtension("txt")
|
||||||
.withSchema(1)
|
.withSchema(1)
|
||||||
.withClientData("ACS")
|
.withClientData("ACS")
|
||||||
.withSourceReference(UUID.randomUUID().toString())
|
.withSourceReference(UUID.randomUUID().toString())
|
||||||
.withSourceSize(32L).build();
|
.withSourceSize(32L).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,48 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests MiscController with a server test harness.
|
* Tests MiscController with a server test harness.
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class MiscTransformerHttpRequestTest extends AbstractHttpRequestTest
|
public class MiscTransformerHttpRequestTest extends AbstractHttpRequestTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected String getTransformerName()
|
protected String getTransformerName()
|
||||||
{
|
{
|
||||||
return "Miscellaneous Transformers";
|
return "Miscellaneous Transformers";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSourceExtension()
|
protected String getSourceExtension()
|
||||||
{
|
{
|
||||||
return "html";
|
return "html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,30 +1,30 @@
|
|||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
||||||
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
||||||
Delivered-To: jane.doe@alfresco.com
|
Delivered-To: jane.doe@alfresco.com
|
||||||
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
||||||
Subject: Attachment test
|
Subject: Attachment test
|
||||||
From: <john.doe@alfresco.com>
|
From: <john.doe@alfresco.com>
|
||||||
To: <jane.doe@alfresco.com>
|
To: <jane.doe@alfresco.com>
|
||||||
Content-Type: multipart/alternative;
|
Content-Type: multipart/alternative;
|
||||||
boundary="----=_NextPart_000_0005_01D06C6A.DBA98EC0"
|
boundary="----=_NextPart_000_0005_01D06C6A.DBA98EC0"
|
||||||
|
|
||||||
This is a multipart message in MIME format.
|
This is a multipart message in MIME format.
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
||||||
Content-Type: text/plain;
|
Content-Type: text/plain;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: 7bit
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
alternative plain text
|
alternative plain text
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
||||||
Content-Type: text/html;
|
Content-Type: text/html;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
<div dir=3D"ltr">alternative html text</div>
|
<div dir=3D"ltr">alternative html text</div>
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0--
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0--
|
||||||
Parts form an multipart/alternative should represent the same content in different formats
|
Parts form an multipart/alternative should represent the same content in different formats
|
||||||
In this eml example the content differs with the purpose of determining if right part was used in transformation
|
In this eml example the content differs with the purpose of determining if right part was used in transformation
|
||||||
|
@@ -1,44 +1,44 @@
|
|||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
||||||
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
||||||
Delivered-To: jane.doe@alfresco.com
|
Delivered-To: jane.doe@alfresco.com
|
||||||
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
||||||
Subject: Attachment test
|
Subject: Attachment test
|
||||||
From: <john.doe@alfresco.com>
|
From: <john.doe@alfresco.com>
|
||||||
To: <jane.doe@alfresco.com>
|
To: <jane.doe@alfresco.com>
|
||||||
Content-Type: multipart/mixed;
|
Content-Type: multipart/mixed;
|
||||||
boundary="----=_NextPart_000_0000_01D06C6A.D04F3750"
|
boundary="----=_NextPart_000_0000_01D06C6A.D04F3750"
|
||||||
|
|
||||||
This is a multipart message in MIME format.
|
This is a multipart message in MIME format.
|
||||||
|
|
||||||
------=_NextPart_000_0000_01D06C6A.D04F3750
|
------=_NextPart_000_0000_01D06C6A.D04F3750
|
||||||
Content-Type: multipart/alternative;
|
Content-Type: multipart/alternative;
|
||||||
boundary="----=_NextPart_001_0001_01D06C6A.D04F3750"
|
boundary="----=_NextPart_001_0001_01D06C6A.D04F3750"
|
||||||
|
|
||||||
|
|
||||||
------=_NextPart_001_0001_01D06C6A.D04F3750
|
------=_NextPart_001_0001_01D06C6A.D04F3750
|
||||||
Content-Type: text/plain;
|
Content-Type: text/plain;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: 7bit
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
Mail with attachment content
|
Mail with attachment content
|
||||||
|
|
||||||
------=_NextPart_001_0001_01D06C6A.D04F3750
|
------=_NextPart_001_0001_01D06C6A.D04F3750
|
||||||
Content-Type: text/html;
|
Content-Type: text/html;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
<div dir=3D"ltr">Mail with attachment content</div>
|
<div dir=3D"ltr">Mail with attachment content</div>
|
||||||
|
|
||||||
------=_NextPart_001_0001_01D06C6A.D04F3750--
|
------=_NextPart_001_0001_01D06C6A.D04F3750--
|
||||||
|
|
||||||
------=_NextPart_000_0000_01D06C6A.D04F3750
|
------=_NextPart_000_0000_01D06C6A.D04F3750
|
||||||
Content-Type: text/plain;
|
Content-Type: text/plain;
|
||||||
name="alt.txt"
|
name="alt.txt"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
Content-ID: <796B1E07B04ACC41A78199F35721150F@eurprd04.prod.outlook.com>
|
Content-ID: <796B1E07B04ACC41A78199F35721150F@eurprd04.prod.outlook.com>
|
||||||
Content-Disposition: attachment;
|
Content-Disposition: attachment;
|
||||||
filename="alt.txt"
|
filename="alt.txt"
|
||||||
|
|
||||||
File attachment content
|
File attachment content
|
||||||
------=_NextPart_000_0000_01D06C6A.D04F3750--
|
------=_NextPart_000_0000_01D06C6A.D04F3750--
|
||||||
|
@@ -1,28 +1,28 @@
|
|||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
||||||
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
||||||
Delivered-To: jane.doe@alfresco.com
|
Delivered-To: jane.doe@alfresco.com
|
||||||
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
||||||
Subject: Attachment test
|
Subject: Attachment test
|
||||||
From: <john.doe@alfresco.com>
|
From: <john.doe@alfresco.com>
|
||||||
To: <jane.doe@alfresco.com>
|
To: <jane.doe@alfresco.com>
|
||||||
Content-Type: multipart/alternative;
|
Content-Type: multipart/alternative;
|
||||||
boundary="----=_NextPart_000_0005_01D06C6A.DBA98EC0"
|
boundary="----=_NextPart_000_0005_01D06C6A.DBA98EC0"
|
||||||
|
|
||||||
This is a multipart message in MIME format.
|
This is a multipart message in MIME format.
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
||||||
Content-Type: text/plain;
|
Content-Type: text/plain;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: 7bit
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
html special characters
|
html special characters
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0
|
||||||
Content-Type: text/html;
|
Content-Type: text/html;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
<div dir=3D"ltr">html special characters</div>
|
<div dir=3D"ltr">html special characters</div>
|
||||||
|
|
||||||
------=_NextPart_000_0005_01D06C6A.DBA98EC0--
|
------=_NextPart_000_0005_01D06C6A.DBA98EC0--
|
||||||
|
Binary file not shown.
@@ -1,41 +1,41 @@
|
|||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
||||||
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
||||||
Delivered-To: jane.doe@alfresco.com
|
Delivered-To: jane.doe@alfresco.com
|
||||||
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
||||||
Subject: Attachment test
|
Subject: Attachment test
|
||||||
From: <john.doe@alfresco.com>
|
From: <john.doe@alfresco.com>
|
||||||
To: <jane.doe@alfresco.com>
|
To: <jane.doe@alfresco.com>
|
||||||
Content-Type: multipart/related;
|
Content-Type: multipart/related;
|
||||||
boundary="--_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423";
|
boundary="--_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423";
|
||||||
type="multipart/alternative"
|
type="multipart/alternative"
|
||||||
|
|
||||||
This is a multi-part message in MIME format.
|
This is a multi-part message in MIME format.
|
||||||
|
|
||||||
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423
|
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423
|
||||||
Content-Type: multipart/alternative; boundary="--_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362"
|
Content-Type: multipart/alternative; boundary="--_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362"
|
||||||
|
|
||||||
|
|
||||||
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362
|
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362
|
||||||
Content-Type: text/plain; charset="utf-8"
|
Content-Type: text/plain; charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
nested alternative plain text
|
nested alternative plain text
|
||||||
|
|
||||||
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362
|
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362
|
||||||
Content-Type: text/html; charset="utf-8"
|
Content-Type: text/html; charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
<div dir=3D"ltr">nested alternative html text</div>
|
<div dir=3D"ltr">nested alternative html text</div>
|
||||||
|
|
||||||
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362--
|
----_=_NextPart0_f68fab3d-a986-41a5-9cf0-3a3aefb21362--
|
||||||
|
|
||||||
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423
|
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423
|
||||||
Content-Type: image/jpeg; name="image001.jpg"
|
Content-Type: image/jpeg; name="image001.jpg"
|
||||||
Content-Transfer-Encoding: base64
|
Content-Transfer-Encoding: base64
|
||||||
Content-ID: <image001.jpg@01D146F0.63006280>
|
Content-ID: <image001.jpg@01D146F0.63006280>
|
||||||
|
|
||||||
image
|
image
|
||||||
|
|
||||||
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423--
|
----_=_NextPart1_03fb5278-acd0-44a8-88cd-bfd1347fd423--
|
||||||
|
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
Received: by 10.000.0.000 with HTTP; Thu, 16 Aug 2012 08:13:29 -0700 (PDT)
|
||||||
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
Date: Thu, 16 Aug 2012 16:13:29 +0100
|
||||||
Delivered-To: jane.doe@alfresco.com
|
Delivered-To: jane.doe@alfresco.com
|
||||||
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
Message-ID: <CAL0uq1f9vPczLRinL3xB5U_oSSd5U0ob=408nBgosCY0OVFyBw@mail.alfresco.com>
|
||||||
Subject: The quick brown fox jumps over the lazy dog
|
Subject: The quick brown fox jumps over the lazy dog
|
||||||
From: <john.doe@alfresco.com>
|
From: <john.doe@alfresco.com>
|
||||||
To: <jane.doe@alfresco.com>
|
To: <jane.doe@alfresco.com>
|
||||||
Content-Type: multipart/alternative;
|
Content-Type: multipart/alternative;
|
||||||
boundary="----=_NextPart_000_0009_01D06BC5.14D754D0"
|
boundary="----=_NextPart_000_0009_01D06BC5.14D754D0"
|
||||||
|
|
||||||
This is a multipart message in MIME format.
|
This is a multipart message in MIME format.
|
||||||
|
|
||||||
------=_NextPart_000_0009_01D06BC5.14D754D0
|
------=_NextPart_000_0009_01D06BC5.14D754D0
|
||||||
Content-Type: text/plain;
|
Content-Type: text/plain;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: 8bit
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
El rápido zorro marrón salta sobre el perro perezoso
|
El rápido zorro marrón salta sobre el perro perezoso
|
||||||
|
|
||||||
|
|
||||||
------=_NextPart_000_0009_01D06BC5.14D754D0
|
------=_NextPart_000_0009_01D06BC5.14D754D0
|
||||||
Content-Type: text/html;
|
Content-Type: text/html;
|
||||||
charset="utf-8"
|
charset="utf-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
<div dir=3D"ltr">El r=C3=A1pido zorro marr=C3=B3n salta sobre el perro =
|
<div dir=3D"ltr">El r=C3=A1pido zorro marr=C3=B3n salta sobre el perro =
|
||||||
perezoso <br></div>
|
perezoso <br></div>
|
||||||
|
|
||||||
------=_NextPart_000_0009_01D06BC5.14D754D0--
|
------=_NextPart_000_0009_01D06BC5.14D754D0--
|
||||||
|
|
||||||
|
@@ -1,115 +1,115 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_JPEG;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts Apple iWorks files to JPEGs for thumbnailing and previewing.
|
* Converts Apple iWorks files to JPEGs for thumbnailing and previewing.
|
||||||
* The transformer will only work for iWorks 2013/14 files. Support for iWorks 2008/9 has been dropped as we cannot
|
* The transformer will only work for iWorks 2013/14 files. Support for iWorks 2008/9 has been dropped as we cannot
|
||||||
* support both, because the newer format does not contain a PDF. If we say this transformer supports PDF, Share will
|
* support both, because the newer format does not contain a PDF. If we say this transformer supports PDF, Share will
|
||||||
* assume incorrectly that we can convert to PDF and we would only get a preview for the older format and never the
|
* assume incorrectly that we can convert to PDF and we would only get a preview for the older format and never the
|
||||||
* newer one. Both formats have the same mimetype.
|
* newer one. Both formats have the same mimetype.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Neil Mc Erlean
|
* @author Neil Mc Erlean
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class AppleIWorksContentTransformer implements SelectableTransformer
|
public class AppleIWorksContentTransformer implements SelectableTransformer
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(
|
private static final Logger logger = LoggerFactory.getLogger(
|
||||||
AppleIWorksContentTransformer.class);
|
AppleIWorksContentTransformer.class);
|
||||||
|
|
||||||
// Apple's zip entry names for previews in iWorks have changed over time.
|
// Apple's zip entry names for previews in iWorks have changed over time.
|
||||||
private static final List<String> PDF_PATHS = ImmutableList.of(
|
private static final List<String> PDF_PATHS = ImmutableList.of(
|
||||||
"QuickLook/Preview.pdf"); // iWorks 2008/9
|
"QuickLook/Preview.pdf"); // iWorks 2008/9
|
||||||
private static final List<String> JPG_PATHS = ImmutableList.of(
|
private static final List<String> JPG_PATHS = ImmutableList.of(
|
||||||
"QuickLook/Thumbnail.jpg", // iWorks 2008/9
|
"QuickLook/Thumbnail.jpg", // iWorks 2008/9
|
||||||
"preview.jpg"); // iWorks 2013/14 (720 x 552) We use the best quality image. Others are:
|
"preview.jpg"); // iWorks 2013/14 (720 x 552) We use the best quality image. Others are:
|
||||||
// (225 x 173) preview-web.jpg
|
// (225 x 173) preview-web.jpg
|
||||||
// (53 x 41) preview-micro.jpg
|
// (53 x 41) preview-micro.jpg
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile)
|
final File sourceFile, final File targetFile)
|
||||||
{
|
{
|
||||||
logger.debug("Performing IWorks to jpeg transform with sourceMimetype={} targetMimetype={}",
|
logger.debug("Performing IWorks to jpeg transform with sourceMimetype={} targetMimetype={}",
|
||||||
sourceMimetype, targetMimetype);
|
sourceMimetype, targetMimetype);
|
||||||
|
|
||||||
// iWorks files are zip (or package) files.
|
// iWorks files are zip (or package) files.
|
||||||
// If it's not a zip file, the resultant ZipException will be caught as an IOException below.
|
// If it's not a zip file, the resultant ZipException will be caught as an IOException below.
|
||||||
try (ZipArchiveInputStream iWorksZip = new ZipArchiveInputStream(
|
try (ZipArchiveInputStream iWorksZip = new ZipArchiveInputStream(
|
||||||
new BufferedInputStream(new FileInputStream(sourceFile))))
|
new BufferedInputStream(new FileInputStream(sourceFile))))
|
||||||
{
|
{
|
||||||
// Look through the zip file entries for the preview/thumbnail.
|
// Look through the zip file entries for the preview/thumbnail.
|
||||||
List<String> paths = MIMETYPE_IMAGE_JPEG.equals(targetMimetype) ? JPG_PATHS : PDF_PATHS;
|
List<String> paths = MIMETYPE_IMAGE_JPEG.equals(targetMimetype) ? JPG_PATHS : PDF_PATHS;
|
||||||
ZipArchiveEntry entry;
|
ZipArchiveEntry entry;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while ((entry = iWorksZip.getNextZipEntry()) != null)
|
while ((entry = iWorksZip.getNextZipEntry()) != null)
|
||||||
{
|
{
|
||||||
String name = entry.getName();
|
String name = entry.getName();
|
||||||
if (paths.contains(name))
|
if (paths.contains(name))
|
||||||
{
|
{
|
||||||
Files.copy(iWorksZip, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(iWorksZip, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"The source " + sourceMimetype + " file did not contain a " + targetMimetype + " preview");
|
"The source " + sourceMimetype + " file did not contain a " + targetMimetype + " preview");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to transform " + sourceMimetype + " file. It should have been a zip format file.",
|
"Unable to transform " + sourceMimetype + " file. It should have been a zip format file.",
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,232 +1,232 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.alfresco.transformer.fs.FileManager;
|
import org.alfresco.transformer.fs.FileManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.Multipart;
|
import javax.mail.Multipart;
|
||||||
import javax.mail.Part;
|
import javax.mail.Part;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_MULTIPART_ALTERNATIVE;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_MULTIPART_ALTERNATIVE;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses javax.mail.MimeMessage to generate plain text versions of RFC822 email
|
* Uses javax.mail.MimeMessage to generate plain text versions of RFC822 email
|
||||||
* messages. Searches for all text content parts, and returns them. Any
|
* messages. Searches for all text content parts, and returns them. Any
|
||||||
* attachments are ignored. TIKA Note - could be replaced with the Tika email
|
* attachments are ignored. TIKA Note - could be replaced with the Tika email
|
||||||
* parser. Would require a recursing parser to be specified, but not the full
|
* parser. Would require a recursing parser to be specified, but not the full
|
||||||
* Auto one (we don't want attachments), just one containing text and html
|
* Auto one (we don't want attachments), just one containing text and html
|
||||||
* related parsers.
|
* related parsers.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class EMLTransformer implements SelectableTransformer
|
public class EMLTransformer implements SelectableTransformer
|
||||||
|
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(EMLTransformer.class);
|
private static final Logger logger = LoggerFactory.getLogger(EMLTransformer.class);
|
||||||
|
|
||||||
private static final String CHARSET = "charset";
|
private static final String CHARSET = "charset";
|
||||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
private static final String DEFAULT_ENCODING = "UTF-8";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile) throws Exception
|
final File sourceFile, final File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
logger.debug("Performing RFC822 to text transform.");
|
logger.debug("Performing RFC822 to text transform.");
|
||||||
// Use try with resource
|
// Use try with resource
|
||||||
try (InputStream contentInputStream = new BufferedInputStream(
|
try (InputStream contentInputStream = new BufferedInputStream(
|
||||||
new FileInputStream(sourceFile));
|
new FileInputStream(sourceFile));
|
||||||
Writer bufferedFileWriter = new BufferedWriter(new FileWriter(targetFile)))
|
Writer bufferedFileWriter = new BufferedWriter(new FileWriter(targetFile)))
|
||||||
{
|
{
|
||||||
MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()),
|
MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()),
|
||||||
contentInputStream);
|
contentInputStream);
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
Object content = mimeMessage.getContent();
|
Object content = mimeMessage.getContent();
|
||||||
if (content instanceof Multipart)
|
if (content instanceof Multipart)
|
||||||
{
|
{
|
||||||
processMultiPart((Multipart) content, sb);
|
processMultiPart((Multipart) content, sb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.append(content.toString());
|
sb.append(content.toString());
|
||||||
}
|
}
|
||||||
bufferedFileWriter.write(sb.toString());
|
bufferedFileWriter.write(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find "text" parts of message recursively and appends it to sb StringBuilder
|
* Find "text" parts of message recursively and appends it to sb StringBuilder
|
||||||
*
|
*
|
||||||
* @param multipart Multipart to process
|
* @param multipart Multipart to process
|
||||||
* @param sb StringBuilder
|
* @param sb StringBuilder
|
||||||
* @throws MessagingException
|
* @throws MessagingException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException,
|
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException,
|
||||||
IOException
|
IOException
|
||||||
{
|
{
|
||||||
boolean isAlternativeMultipart = multipart.getContentType().contains(
|
boolean isAlternativeMultipart = multipart.getContentType().contains(
|
||||||
MIMETYPE_MULTIPART_ALTERNATIVE);
|
MIMETYPE_MULTIPART_ALTERNATIVE);
|
||||||
if (isAlternativeMultipart)
|
if (isAlternativeMultipart)
|
||||||
{
|
{
|
||||||
processAlternativeMultipart(multipart, sb);
|
processAlternativeMultipart(multipart, sb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
||||||
{
|
{
|
||||||
Part part = multipart.getBodyPart(i);
|
Part part = multipart.getBodyPart(i);
|
||||||
if (part.getContent() instanceof Multipart)
|
if (part.getContent() instanceof Multipart)
|
||||||
{
|
{
|
||||||
processMultiPart((Multipart) part.getContent(), sb);
|
processMultiPart((Multipart) part.getContent(), sb);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
processPart(part, sb);
|
processPart(part, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the suitable part from an multipart/alternative and appends it's text content to StringBuilder sb
|
* Finds the suitable part from an multipart/alternative and appends it's text content to StringBuilder sb
|
||||||
*
|
*
|
||||||
* @param multipart
|
* @param multipart
|
||||||
* @param sb
|
* @param sb
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws MessagingException
|
* @throws MessagingException
|
||||||
*/
|
*/
|
||||||
private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws
|
private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws
|
||||||
IOException, MessagingException
|
IOException, MessagingException
|
||||||
{
|
{
|
||||||
Part partToUse = null;
|
Part partToUse = null;
|
||||||
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
||||||
{
|
{
|
||||||
Part part = multipart.getBodyPart(i);
|
Part part = multipart.getBodyPart(i);
|
||||||
if (part.getContentType().contains(MIMETYPE_TEXT_PLAIN))
|
if (part.getContentType().contains(MIMETYPE_TEXT_PLAIN))
|
||||||
{
|
{
|
||||||
partToUse = part;
|
partToUse = part;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (part.getContentType().contains(MIMETYPE_HTML))
|
else if (part.getContentType().contains(MIMETYPE_HTML))
|
||||||
{
|
{
|
||||||
partToUse = part;
|
partToUse = part;
|
||||||
}
|
}
|
||||||
else if (part.getContentType().contains(MIMETYPE_MULTIPART_ALTERNATIVE))
|
else if (part.getContentType().contains(MIMETYPE_MULTIPART_ALTERNATIVE))
|
||||||
{
|
{
|
||||||
if (part.getContent() instanceof Multipart)
|
if (part.getContent() instanceof Multipart)
|
||||||
{
|
{
|
||||||
processAlternativeMultipart((Multipart) part.getContent(), sb);
|
processAlternativeMultipart((Multipart) part.getContent(), sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (partToUse != null)
|
if (partToUse != null)
|
||||||
{
|
{
|
||||||
processPart(partToUse, sb);
|
processPart(partToUse, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds text on a given mail part. Accepted parts types are text/html and text/plain.
|
* Finds text on a given mail part. Accepted parts types are text/html and text/plain.
|
||||||
* Attachments are ignored
|
* Attachments are ignored
|
||||||
*
|
*
|
||||||
* @param part
|
* @param part
|
||||||
* @param sb
|
* @param sb
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws MessagingException
|
* @throws MessagingException
|
||||||
*/
|
*/
|
||||||
private void processPart(Part part, StringBuilder sb) throws IOException, MessagingException
|
private void processPart(Part part, StringBuilder sb) throws IOException, MessagingException
|
||||||
{
|
{
|
||||||
boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition());
|
boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition());
|
||||||
if (isAttachment)
|
if (isAttachment)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (part.getContentType().contains(MIMETYPE_TEXT_PLAIN))
|
if (part.getContentType().contains(MIMETYPE_TEXT_PLAIN))
|
||||||
{
|
{
|
||||||
sb.append(part.getContent().toString());
|
sb.append(part.getContent().toString());
|
||||||
}
|
}
|
||||||
else if (part.getContentType().contains(MIMETYPE_HTML))
|
else if (part.getContentType().contains(MIMETYPE_HTML))
|
||||||
{
|
{
|
||||||
String mailPartContent = part.getContent().toString();
|
String mailPartContent = part.getContent().toString();
|
||||||
|
|
||||||
//create a temporary html file with same mail part content and encoding
|
//create a temporary html file with same mail part content and encoding
|
||||||
File tempHtmlFile = FileManager.TempFileProvider.createTempFile("EMLTransformer_",
|
File tempHtmlFile = FileManager.TempFileProvider.createTempFile("EMLTransformer_",
|
||||||
".html");
|
".html");
|
||||||
String encoding = getMailPartContentEncoding(part);
|
String encoding = getMailPartContentEncoding(part);
|
||||||
try (OutputStreamWriter osWriter = new OutputStreamWriter(
|
try (OutputStreamWriter osWriter = new OutputStreamWriter(
|
||||||
new FileOutputStream(tempHtmlFile), encoding))
|
new FileOutputStream(tempHtmlFile), encoding))
|
||||||
{
|
{
|
||||||
osWriter.write(mailPartContent);
|
osWriter.write(mailPartContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
//transform html file's content to plain text
|
//transform html file's content to plain text
|
||||||
HtmlParserContentTransformer.EncodingAwareStringBean extractor = new HtmlParserContentTransformer.EncodingAwareStringBean();
|
HtmlParserContentTransformer.EncodingAwareStringBean extractor = new HtmlParserContentTransformer.EncodingAwareStringBean();
|
||||||
extractor.setCollapse(false);
|
extractor.setCollapse(false);
|
||||||
extractor.setLinks(false);
|
extractor.setLinks(false);
|
||||||
extractor.setReplaceNonBreakingSpaces(false);
|
extractor.setReplaceNonBreakingSpaces(false);
|
||||||
extractor.setURL(tempHtmlFile, encoding);
|
extractor.setURL(tempHtmlFile, encoding);
|
||||||
sb.append(extractor.getStrings());
|
sb.append(extractor.getStrings());
|
||||||
|
|
||||||
tempHtmlFile.delete();
|
tempHtmlFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMailPartContentEncoding(Part part) throws MessagingException
|
private String getMailPartContentEncoding(Part part) throws MessagingException
|
||||||
{
|
{
|
||||||
String encoding = DEFAULT_ENCODING;
|
String encoding = DEFAULT_ENCODING;
|
||||||
String contentType = part.getContentType();
|
String contentType = part.getContentType();
|
||||||
int startIndex = contentType.indexOf(CHARSET);
|
int startIndex = contentType.indexOf(CHARSET);
|
||||||
if (startIndex > 0)
|
if (startIndex > 0)
|
||||||
{
|
{
|
||||||
encoding = contentType.substring(startIndex + CHARSET.length() + 1)
|
encoding = contentType.substring(startIndex + CHARSET.length() + 1)
|
||||||
.replaceAll("\"", "");
|
.replaceAll("\"", "");
|
||||||
}
|
}
|
||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,192 +1,192 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.htmlparser.Parser;
|
import org.htmlparser.Parser;
|
||||||
import org.htmlparser.beans.StringBean;
|
import org.htmlparser.beans.StringBean;
|
||||||
import org.htmlparser.util.ParserException;
|
import org.htmlparser.util.ParserException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.IllegalCharsetNameException;
|
import java.nio.charset.IllegalCharsetNameException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content transformer which wraps the HTML Parser library for
|
* Content transformer which wraps the HTML Parser library for
|
||||||
* parsing HTML content.
|
* parsing HTML content.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Since HTML Parser was updated from v1.6 to v2.1, META tags
|
* Since HTML Parser was updated from v1.6 to v2.1, META tags
|
||||||
* defining an encoding for the content via http-equiv=Content-Type
|
* defining an encoding for the content via http-equiv=Content-Type
|
||||||
* will ONLY be respected if the encoding of the content item
|
* will ONLY be respected if the encoding of the content item
|
||||||
* itself is set to ISO-8859-1.
|
* itself is set to ISO-8859-1.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Tika Note - could be converted to use the Tika HTML parser,
|
* Tika Note - could be converted to use the Tika HTML parser,
|
||||||
* but we'd potentially need a custom text handler to replicate
|
* but we'd potentially need a custom text handler to replicate
|
||||||
* the current settings around links and non-breaking spaces.
|
* the current settings around links and non-breaking spaces.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
* @see <a href="http://htmlparser.sourceforge.net/">http://htmlparser.sourceforge.net</a>
|
* @see <a href="http://htmlparser.sourceforge.net/">http://htmlparser.sourceforge.net</a>
|
||||||
* @see org.htmlparser.beans.StringBean
|
* @see org.htmlparser.beans.StringBean
|
||||||
* @see <a href="http://sourceforge.net/tracker/?func=detail&aid=1644504&group_id=24399&atid=381401">HTML Parser</a>
|
* @see <a href="http://sourceforge.net/tracker/?func=detail&aid=1644504&group_id=24399&atid=381401">HTML Parser</a>
|
||||||
*/
|
*/
|
||||||
public class HtmlParserContentTransformer implements SelectableTransformer
|
public class HtmlParserContentTransformer implements SelectableTransformer
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(
|
private static final Logger logger = LoggerFactory.getLogger(
|
||||||
HtmlParserContentTransformer.class);
|
HtmlParserContentTransformer.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile) throws Exception
|
final File sourceFile, final File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
||||||
checkEncodingParameter(sourceEncoding, SOURCE_ENCODING);
|
checkEncodingParameter(sourceEncoding, SOURCE_ENCODING);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Performing HTML to text transform with sourceEncoding=" + sourceEncoding);
|
logger.debug("Performing HTML to text transform with sourceEncoding=" + sourceEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the extractor
|
// Create the extractor
|
||||||
EncodingAwareStringBean extractor = new EncodingAwareStringBean();
|
EncodingAwareStringBean extractor = new EncodingAwareStringBean();
|
||||||
extractor.setCollapse(false);
|
extractor.setCollapse(false);
|
||||||
extractor.setLinks(false);
|
extractor.setLinks(false);
|
||||||
extractor.setReplaceNonBreakingSpaces(false);
|
extractor.setReplaceNonBreakingSpaces(false);
|
||||||
extractor.setURL(sourceFile, sourceEncoding);
|
extractor.setURL(sourceFile, sourceEncoding);
|
||||||
// get the text
|
// get the text
|
||||||
String text = extractor.getStrings();
|
String text = extractor.getStrings();
|
||||||
|
|
||||||
// write it to the writer
|
// write it to the writer
|
||||||
try (Writer writer = new BufferedWriter(
|
try (Writer writer = new BufferedWriter(
|
||||||
new OutputStreamWriter(new FileOutputStream(targetFile))))
|
new OutputStreamWriter(new FileOutputStream(targetFile))))
|
||||||
{
|
{
|
||||||
writer.write(text);
|
writer.write(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEncodingParameter(String encoding, String parameterName)
|
private void checkEncodingParameter(String encoding, String parameterName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (encoding != null && !Charset.isSupported(encoding))
|
if (encoding != null && !Charset.isSupported(encoding))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
parameterName + "=" + encoding + " is not supported by the JVM.");
|
parameterName + "=" + encoding + " is not supported by the JVM.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalCharsetNameException e)
|
catch (IllegalCharsetNameException e)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
parameterName + "=" + encoding + " is not a valid encoding.");
|
parameterName + "=" + encoding + " is not a valid encoding.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name, originally implemented in alfresco-repository.
|
* This code is based on a class of the same name, originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* A version of {@link StringBean} which allows control of the
|
* A version of {@link StringBean} which allows control of the
|
||||||
* encoding in the underlying HTML Parser.
|
* encoding in the underlying HTML Parser.
|
||||||
* Unfortunately, StringBean doesn't allow easy over-riding of
|
* Unfortunately, StringBean doesn't allow easy over-riding of
|
||||||
* this, so we have to duplicate some code to control this.
|
* this, so we have to duplicate some code to control this.
|
||||||
* This allows us to correctly handle HTML files where the encoding
|
* This allows us to correctly handle HTML files where the encoding
|
||||||
* is specified against the content property (rather than in the
|
* is specified against the content property (rather than in the
|
||||||
* HTML Head Meta), see ALF-10466 for details.
|
* HTML Head Meta), see ALF-10466 for details.
|
||||||
*/
|
*/
|
||||||
public static class EncodingAwareStringBean extends StringBean
|
public static class EncodingAwareStringBean extends StringBean
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -9033414360428669553L;
|
private static final long serialVersionUID = -9033414360428669553L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the File to extract strings from, and the encoding
|
* Sets the File to extract strings from, and the encoding
|
||||||
* it's in (if known to Alfresco)
|
* it's in (if known to Alfresco)
|
||||||
*
|
*
|
||||||
* @param file The File that text should be fetched from.
|
* @param file The File that text should be fetched from.
|
||||||
* @param encoding The encoding of the input
|
* @param encoding The encoding of the input
|
||||||
*/
|
*/
|
||||||
public void setURL(File file, String encoding)
|
public void setURL(File file, String encoding)
|
||||||
{
|
{
|
||||||
String previousURL = getURL();
|
String previousURL = getURL();
|
||||||
String newURL = file.getAbsolutePath();
|
String newURL = file.getAbsolutePath();
|
||||||
|
|
||||||
if (previousURL == null || !newURL.equals(previousURL))
|
if (previousURL == null || !newURL.equals(previousURL))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URLConnection conn = getConnection();
|
URLConnection conn = getConnection();
|
||||||
|
|
||||||
if (null == mParser)
|
if (null == mParser)
|
||||||
{
|
{
|
||||||
mParser = new Parser(newURL);
|
mParser = new Parser(newURL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mParser.setURL(newURL);
|
mParser.setURL(newURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding != null)
|
if (encoding != null)
|
||||||
{
|
{
|
||||||
mParser.setEncoding(encoding);
|
mParser.setEncoding(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPropertySupport.firePropertyChange(StringBean.PROP_URL_PROPERTY, previousURL,
|
mPropertySupport.firePropertyChange(StringBean.PROP_URL_PROPERTY, previousURL,
|
||||||
getURL());
|
getURL());
|
||||||
mPropertySupport.firePropertyChange(StringBean.PROP_CONNECTION_PROPERTY, conn,
|
mPropertySupport.firePropertyChange(StringBean.PROP_CONNECTION_PROPERTY, conn,
|
||||||
mParser.getConnection());
|
mParser.getConnection());
|
||||||
setStrings();
|
setStrings();
|
||||||
}
|
}
|
||||||
catch (ParserException pe)
|
catch (ParserException pe)
|
||||||
{
|
{
|
||||||
updateStrings(pe.toString());
|
updateStrings(pe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEncoding()
|
public String getEncoding()
|
||||||
{
|
{
|
||||||
return mParser.getEncoding();
|
return mParser.getEncoding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,130 +1,130 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts out Thumbnail JPEGs from OOXML files for thumbnailing and previewing.
|
* Extracts out Thumbnail JPEGs from OOXML files for thumbnailing and previewing.
|
||||||
* This transformer will only work for OOXML files where thumbnailing was enabled,
|
* This transformer will only work for OOXML files where thumbnailing was enabled,
|
||||||
* which isn't on by default on Windows, but is more common on Mac.
|
* which isn't on by default on Windows, but is more common on Mac.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Nick Burch
|
* @author Nick Burch
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
*/
|
*/
|
||||||
public class OOXMLThumbnailContentTransformer implements SelectableTransformer
|
public class OOXMLThumbnailContentTransformer implements SelectableTransformer
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(
|
private static final Logger logger = LoggerFactory.getLogger(
|
||||||
OOXMLThumbnailContentTransformer.class);
|
OOXMLThumbnailContentTransformer.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile) throws Exception
|
final File sourceFile, final File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Performing OOXML to jpeg transform with sourceMimetype=" + sourceMimetype
|
logger.debug("Performing OOXML to jpeg transform with sourceMimetype=" + sourceMimetype
|
||||||
+ " targetMimetype=" + targetMimetype);
|
+ " targetMimetype=" + targetMimetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (OPCPackage pkg = OPCPackage.open(sourceFile.getPath()))
|
try (OPCPackage pkg = OPCPackage.open(sourceFile.getPath()))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Does it have a thumbnail?
|
// Does it have a thumbnail?
|
||||||
PackageRelationshipCollection rels = pkg.getRelationshipsByType(
|
PackageRelationshipCollection rels = pkg.getRelationshipsByType(
|
||||||
PackageRelationshipTypes.THUMBNAIL);
|
PackageRelationshipTypes.THUMBNAIL);
|
||||||
if (rels.size() > 0)
|
if (rels.size() > 0)
|
||||||
{
|
{
|
||||||
// Get the thumbnail part
|
// Get the thumbnail part
|
||||||
PackageRelationship tRel = rels.getRelationship(0);
|
PackageRelationship tRel = rels.getRelationship(0);
|
||||||
PackagePart tPart = pkg.getPart(tRel);
|
PackagePart tPart = pkg.getPart(tRel);
|
||||||
|
|
||||||
// Write it to the target
|
// Write it to the target
|
||||||
InputStream tStream = tPart.getInputStream();
|
InputStream tStream = tPart.getInputStream();
|
||||||
Files.copy(tStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(tStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
tStream.close();
|
tStream.close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.debug("No thumbnail present in file.");
|
logger.debug("No thumbnail present in file.");
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"No thumbnail present in file, unable to generate " + targetMimetype);
|
"No thumbnail present in file, unable to generate " + targetMimetype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Unable to transform file.", e);
|
throw new RuntimeException("Unable to transform file.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// TODO Add this back to engine_config.json when the transformer is fixed for java 11
|
// TODO Add this back to engine_config.json when the transformer is fixed for java 11
|
||||||
{
|
{
|
||||||
"transformerName": "ooxmlThumbnail",
|
"transformerName": "ooxmlThumbnail",
|
||||||
"supportedSourceAndTargetList": [
|
"supportedSourceAndTargetList": [
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-word.document.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-word.document.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-word.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-word.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-powerpoint.presentation.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-powerpoint.presentation.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-powerpoint.slideshow.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-powerpoint.slideshow.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.template", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.template", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-powerpoint.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-powerpoint.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-powerpoint.addin.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-powerpoint.addin.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.slide", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.slide", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-powerpoint.slide.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-powerpoint.slide.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.template", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.template", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-excel.sheet.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-excel.sheet.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-excel.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-excel.template.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-excel.addin.macroenabled.12", "targetMediaType": "image/jpeg"},
|
{"sourceMediaType": "application/vnd.ms-excel.addin.macroenabled.12", "targetMediaType": "image/jpeg"},
|
||||||
{"sourceMediaType": "application/vnd.ms-excel.sheet.binary.macroenabled.12", "targetMediaType": "image/jpeg"}
|
{"sourceMediaType": "application/vnd.ms-excel.sheet.binary.macroenabled.12", "targetMediaType": "image/jpeg"}
|
||||||
],
|
],
|
||||||
"transformOptions": [
|
"transformOptions": [
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@@ -1,53 +1,53 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemented by transformers used by {@link SelectingTransformer}.
|
* Implemented by transformers used by {@link SelectingTransformer}.
|
||||||
*
|
*
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
*/
|
*/
|
||||||
public interface SelectableTransformer
|
public interface SelectableTransformer
|
||||||
{
|
{
|
||||||
default void transform(String sourceMimetype, String targetMimetype, Map<String, String> parameters,
|
default void transform(String sourceMimetype, String targetMimetype, Map<String, String> parameters,
|
||||||
File sourceFile, File targetFile) throws Exception
|
File sourceFile, File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
default void extractMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
default void extractMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||||
File sourceFile, File targetFile) throws Exception
|
File sourceFile, File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
default void embedMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
default void embedMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||||
File sourceFile, File targetFile) throws Exception
|
File sourceFile, File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,114 +1,114 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
import org.alfresco.transformer.logging.LogEntry;
|
import org.alfresco.transformer.logging.LogEntry;
|
||||||
import org.alfresco.transformer.metadataExtractors.HtmlMetadataExtractor;
|
import org.alfresco.transformer.metadataExtractors.HtmlMetadataExtractor;
|
||||||
import org.alfresco.transformer.metadataExtractors.RFC822MetadataExtractor;
|
import org.alfresco.transformer.metadataExtractors.RFC822MetadataExtractor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SelectingTransformer selects a registered {@link SelectableTransformer}
|
* The SelectingTransformer selects a registered {@link SelectableTransformer}
|
||||||
* and delegates the transformation to its implementation.
|
* and delegates the transformation to its implementation.
|
||||||
*
|
*
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
*/
|
*/
|
||||||
public class SelectingTransformer implements Transformer
|
public class SelectingTransformer implements Transformer
|
||||||
{
|
{
|
||||||
private static final String ID = "misc";
|
private static final String ID = "misc";
|
||||||
|
|
||||||
public static final String LICENCE =
|
public static final String LICENCE =
|
||||||
"This transformer uses libraries from Apache. See the license at http://www.apache.org/licenses/LICENSE-2.0. or in /Apache\\\\ 2.0.txt\\n" +
|
"This transformer uses libraries from Apache. See the license at http://www.apache.org/licenses/LICENSE-2.0. or in /Apache\\\\ 2.0.txt\\n" +
|
||||||
"Additional libraries used:\n" +
|
"Additional libraries used:\n" +
|
||||||
"* htmlparser http://htmlparser.sourceforge.net/license.html";
|
"* htmlparser http://htmlparser.sourceforge.net/license.html";
|
||||||
|
|
||||||
private final Map<String, SelectableTransformer> transformers = ImmutableMap
|
private final Map<String, SelectableTransformer> transformers = ImmutableMap
|
||||||
.<String, SelectableTransformer>builder()
|
.<String, SelectableTransformer>builder()
|
||||||
.put("appleIWorks", new AppleIWorksContentTransformer())
|
.put("appleIWorks", new AppleIWorksContentTransformer())
|
||||||
.put("html", new HtmlParserContentTransformer())
|
.put("html", new HtmlParserContentTransformer())
|
||||||
.put("string", new StringExtractingContentTransformer())
|
.put("string", new StringExtractingContentTransformer())
|
||||||
.put("textToPdf", new TextToPdfContentTransformer())
|
.put("textToPdf", new TextToPdfContentTransformer())
|
||||||
.put("rfc822", new EMLTransformer())
|
.put("rfc822", new EMLTransformer())
|
||||||
.put("ooXmlThumbnail", new OOXMLThumbnailContentTransformer())
|
.put("ooXmlThumbnail", new OOXMLThumbnailContentTransformer())
|
||||||
.put("HtmlMetadataExtractor", new HtmlMetadataExtractor())
|
.put("HtmlMetadataExtractor", new HtmlMetadataExtractor())
|
||||||
.put("RFC822MetadataExtractor", new RFC822MetadataExtractor())
|
.put("RFC822MetadataExtractor", new RFC822MetadataExtractor())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransformerId()
|
public String getTransformerId()
|
||||||
{
|
{
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(String transformName, String sourceMimetype, String targetMimetype,
|
public void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||||
Map<String, String> transformOptions,
|
Map<String, String> transformOptions,
|
||||||
File sourceFile, File targetFile) throws Exception
|
File sourceFile, File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
final SelectableTransformer transformer = transformers.get(transformName);
|
final SelectableTransformer transformer = transformers.get(transformName);
|
||||||
logOptions(sourceFile, targetFile, transformOptions);
|
logOptions(sourceFile, targetFile, transformOptions);
|
||||||
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void extractMetadata(String transformName, String sourceMimetype, String targetMimetype,
|
public void extractMetadata(String transformName, String sourceMimetype, String targetMimetype,
|
||||||
Map<String, String> transformOptions,
|
Map<String, String> transformOptions,
|
||||||
File sourceFile, File targetFile) throws Exception
|
File sourceFile, File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
final SelectableTransformer transformer = transformers.get(transformName);
|
final SelectableTransformer transformer = transformers.get(transformName);
|
||||||
logOptions(sourceFile, targetFile, transformOptions);
|
logOptions(sourceFile, targetFile, transformOptions);
|
||||||
transformer.extractMetadata(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
transformer.extractMetadata(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logOptions(File sourceFile, File targetFile, Map<String, String> parameters)
|
private static void logOptions(File sourceFile, File targetFile, Map<String, String> parameters)
|
||||||
{
|
{
|
||||||
StringJoiner sj = new StringJoiner(" ");
|
StringJoiner sj = new StringJoiner(" ");
|
||||||
parameters.forEach((k, v) ->
|
parameters.forEach((k, v) ->
|
||||||
{
|
{
|
||||||
if (!TRANSFORM_NAME_PARAMETER.equals(k))
|
if (!TRANSFORM_NAME_PARAMETER.equals(k))
|
||||||
{
|
{
|
||||||
sj.add("--" + k + "=" + v);
|
sj.add("--" + k + "=" + v);
|
||||||
}
|
}
|
||||||
}); // keeping the existing style used in other T-Engines
|
}); // keeping the existing style used in other T-Engines
|
||||||
sj.add(getExtension(sourceFile));
|
sj.add(getExtension(sourceFile));
|
||||||
sj.add(getExtension(targetFile));
|
sj.add(getExtension(targetFile));
|
||||||
LogEntry.setOptions(sj.toString());
|
LogEntry.setOptions(sj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getExtension(File file)
|
private static String getExtension(File file)
|
||||||
{
|
{
|
||||||
final String name = file.getName();
|
final String name = file.getName();
|
||||||
int i = name.lastIndexOf('.');
|
int i = name.lastIndexOf('.');
|
||||||
return i == -1 ? "???" : name.substring(i + 1);
|
return i == -1 ? "???" : name.substring(i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,158 +1,158 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.IllegalCharsetNameException;
|
import java.nio.charset.IllegalCharsetNameException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.TARGET_ENCODING;
|
import static org.alfresco.transform.client.util.RequestParamMap.TARGET_ENCODING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts any textual format to plain text.
|
* Converts any textual format to plain text.
|
||||||
* <p>
|
* <p>
|
||||||
* The transformation is sensitive to the source and target string encodings.
|
* The transformation is sensitive to the source and target string encodings.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
*/
|
*/
|
||||||
public class StringExtractingContentTransformer implements SelectableTransformer
|
public class StringExtractingContentTransformer implements SelectableTransformer
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StringExtractingContentTransformer.class);
|
private static final Logger logger = LoggerFactory.getLogger(StringExtractingContentTransformer.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text to text conversions are done directly using the content reader and writer string
|
* Text to text conversions are done directly using the content reader and writer string
|
||||||
* manipulation methods.
|
* manipulation methods.
|
||||||
* <p>
|
* <p>
|
||||||
* Extraction of text from binary content attempts to take the possible character
|
* Extraction of text from binary content attempts to take the possible character
|
||||||
* encoding into account. The text produced from this will, if the encoding was correct,
|
* encoding into account. The text produced from this will, if the encoding was correct,
|
||||||
* be unformatted but valid.
|
* be unformatted but valid.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile) throws Exception
|
final File sourceFile, final File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
||||||
String targetEncoding = parameters.get(TARGET_ENCODING);
|
String targetEncoding = parameters.get(TARGET_ENCODING);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Performing text to text transform with sourceEncoding=" + sourceEncoding
|
logger.debug("Performing text to text transform with sourceEncoding=" + sourceEncoding
|
||||||
+ " targetEncoding=" + targetEncoding);
|
+ " targetEncoding=" + targetEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reader charReader = null;
|
Reader charReader = null;
|
||||||
Writer charWriter = null;
|
Writer charWriter = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Build reader
|
// Build reader
|
||||||
if (sourceEncoding == null)
|
if (sourceEncoding == null)
|
||||||
{
|
{
|
||||||
charReader = new BufferedReader(
|
charReader = new BufferedReader(
|
||||||
new InputStreamReader(new FileInputStream(sourceFile)));
|
new InputStreamReader(new FileInputStream(sourceFile)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkEncodingParameter(sourceEncoding, SOURCE_ENCODING);
|
checkEncodingParameter(sourceEncoding, SOURCE_ENCODING);
|
||||||
charReader = new BufferedReader(
|
charReader = new BufferedReader(
|
||||||
new InputStreamReader(new FileInputStream(sourceFile), sourceEncoding));
|
new InputStreamReader(new FileInputStream(sourceFile), sourceEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build writer
|
// Build writer
|
||||||
if (targetEncoding == null)
|
if (targetEncoding == null)
|
||||||
{
|
{
|
||||||
charWriter = new BufferedWriter(
|
charWriter = new BufferedWriter(
|
||||||
new OutputStreamWriter(new FileOutputStream(targetFile)));
|
new OutputStreamWriter(new FileOutputStream(targetFile)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkEncodingParameter(targetEncoding, TARGET_ENCODING);
|
checkEncodingParameter(targetEncoding, TARGET_ENCODING);
|
||||||
charWriter = new BufferedWriter(
|
charWriter = new BufferedWriter(
|
||||||
new OutputStreamWriter(new FileOutputStream(targetFile), targetEncoding));
|
new OutputStreamWriter(new FileOutputStream(targetFile), targetEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy from the one to the other
|
// copy from the one to the other
|
||||||
char[] buffer = new char[8192];
|
char[] buffer = new char[8192];
|
||||||
int readCount = 0;
|
int readCount = 0;
|
||||||
while (readCount > -1)
|
while (readCount > -1)
|
||||||
{
|
{
|
||||||
// write the last read count number of bytes
|
// write the last read count number of bytes
|
||||||
charWriter.write(buffer, 0, readCount);
|
charWriter.write(buffer, 0, readCount);
|
||||||
// fill the buffer again
|
// fill the buffer again
|
||||||
readCount = charReader.read(buffer);
|
readCount = charReader.read(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (charReader != null)
|
if (charReader != null)
|
||||||
{
|
{
|
||||||
try { charReader.close(); } catch (Throwable e) { logger.error("Failed to close charReader", e); }
|
try { charReader.close(); } catch (Throwable e) { logger.error("Failed to close charReader", e); }
|
||||||
}
|
}
|
||||||
if (charWriter != null)
|
if (charWriter != null)
|
||||||
{
|
{
|
||||||
try { charWriter.close(); } catch (Throwable e) { logger.error("Failed to close charWriter", e); }
|
try { charWriter.close(); } catch (Throwable e) { logger.error("Failed to close charWriter", e); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// done
|
// done
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEncodingParameter(String encoding, String paramterName)
|
private void checkEncodingParameter(String encoding, String paramterName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Charset.isSupported(encoding))
|
if (!Charset.isSupported(encoding))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
paramterName + "=" + encoding + " is not supported by the JVM.");
|
paramterName + "=" + encoding + " is not supported by the JVM.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalCharsetNameException e)
|
catch (IllegalCharsetNameException e)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
paramterName + "=" + encoding + " is not a valid encoding.");
|
paramterName + "=" + encoding + " is not a valid encoding.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,448 +1,448 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.alfresco.transformer.util.RequestParamMap;
|
import org.alfresco.transformer.util.RequestParamMap;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDPage;
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
import org.apache.pdfbox.tools.TextToPDF;
|
import org.apache.pdfbox.tools.TextToPDF;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PushbackInputStream;
|
import java.io.PushbackInputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* Makes use of the <a href="http://www.pdfbox.org/">PDFBox</a> library's <code>TextToPDF</code> utility.
|
* Makes use of the <a href="http://www.pdfbox.org/">PDFBox</a> library's <code>TextToPDF</code> utility.
|
||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
* @author eknizat
|
* @author eknizat
|
||||||
*/
|
*/
|
||||||
public class TextToPdfContentTransformer implements SelectableTransformer
|
public class TextToPdfContentTransformer implements SelectableTransformer
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TextToPdfContentTransformer.class);
|
private static final Logger logger = LoggerFactory.getLogger(TextToPdfContentTransformer.class);
|
||||||
|
|
||||||
private static final int UTF16_READ_AHEAD_BYTES = 16; // 8 characters including BOM if it exists
|
private static final int UTF16_READ_AHEAD_BYTES = 16; // 8 characters including BOM if it exists
|
||||||
private static final byte FE = (byte) 0xFE;
|
private static final byte FE = (byte) 0xFE;
|
||||||
private static final byte FF = (byte) 0xFF;
|
private static final byte FF = (byte) 0xFF;
|
||||||
|
|
||||||
public static final String PAGE_LIMIT = RequestParamMap.PAGE_LIMIT;
|
public static final String PAGE_LIMIT = RequestParamMap.PAGE_LIMIT;
|
||||||
|
|
||||||
private final PagedTextToPDF transformer;
|
private final PagedTextToPDF transformer;
|
||||||
|
|
||||||
public TextToPdfContentTransformer()
|
public TextToPdfContentTransformer()
|
||||||
{
|
{
|
||||||
transformer = new PagedTextToPDF();
|
transformer = new PagedTextToPDF();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStandardFont(String fontName)
|
public void setStandardFont(String fontName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transformer.setFont(PagedTextToPDF.getStandardFont(fontName));
|
transformer.setFont(PagedTextToPDF.getStandardFont(fontName));
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to set Standard Font for PDF generation: " + fontName, e);
|
"Unable to set Standard Font for PDF generation: " + fontName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFontSize(int fontSize)
|
public void setFontSize(int fontSize)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transformer.setFontSize(fontSize);
|
transformer.setFontSize(fontSize);
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to set Font Size for PDF generation: " + fontSize);
|
"Unable to set Font Size for PDF generation: " + fontSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||||
final File sourceFile, final File targetFile) throws Exception
|
final File sourceFile, final File targetFile) throws Exception
|
||||||
{
|
{
|
||||||
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
String sourceEncoding = parameters.get(SOURCE_ENCODING);
|
||||||
String stringPageLimit = parameters.get(PAGE_LIMIT);
|
String stringPageLimit = parameters.get(PAGE_LIMIT);
|
||||||
int pageLimit = -1;
|
int pageLimit = -1;
|
||||||
if (stringPageLimit != null)
|
if (stringPageLimit != null)
|
||||||
{
|
{
|
||||||
pageLimit = parseInt(stringPageLimit, PAGE_LIMIT);
|
pageLimit = parseInt(stringPageLimit, PAGE_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDDocument pdf = null;
|
PDDocument pdf = null;
|
||||||
try (InputStream is = new FileInputStream(sourceFile);
|
try (InputStream is = new FileInputStream(sourceFile);
|
||||||
Reader ir = new BufferedReader(buildReader(is, sourceEncoding));
|
Reader ir = new BufferedReader(buildReader(is, sourceEncoding));
|
||||||
OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile)))
|
OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile)))
|
||||||
{
|
{
|
||||||
//TransformationOptionLimits limits = getLimits(reader, writer, options);
|
//TransformationOptionLimits limits = getLimits(reader, writer, options);
|
||||||
//TransformationOptionPair pageLimits = limits.getPagesPair();
|
//TransformationOptionPair pageLimits = limits.getPagesPair();
|
||||||
pdf = transformer.createPDFFromText(ir, pageLimit);
|
pdf = transformer.createPDFFromText(ir, pageLimit);
|
||||||
pdf.save(os);
|
pdf.save(os);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (pdf != null)
|
if (pdf != null)
|
||||||
{
|
{
|
||||||
try { pdf.close(); } catch (Throwable e) {e.printStackTrace(); }
|
try { pdf.close(); } catch (Throwable e) {e.printStackTrace(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InputStreamReader buildReader(InputStream is, String encoding)
|
protected InputStreamReader buildReader(InputStream is, String encoding)
|
||||||
{
|
{
|
||||||
// If they gave an encoding, try to use it
|
// If they gave an encoding, try to use it
|
||||||
if (encoding != null)
|
if (encoding != null)
|
||||||
{
|
{
|
||||||
Charset charset = null;
|
Charset charset = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
charset = Charset.forName(encoding);
|
charset = Charset.forName(encoding);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.warn("JVM doesn't understand encoding '" + encoding +
|
logger.warn("JVM doesn't understand encoding '" + encoding +
|
||||||
"' when transforming text to pdf");
|
"' when transforming text to pdf");
|
||||||
}
|
}
|
||||||
if (charset != null)
|
if (charset != null)
|
||||||
{
|
{
|
||||||
// Handles the situation where there is a BOM even though the encoding indicates that normally
|
// Handles the situation where there is a BOM even though the encoding indicates that normally
|
||||||
// there should not be one for UTF-16BE and UTF-16LE. For extra flexibility includes UTF-16 too
|
// there should not be one for UTF-16BE and UTF-16LE. For extra flexibility includes UTF-16 too
|
||||||
// which optionally has the BOM. Rather than look at the BOM we look at the number of zero bytes
|
// which optionally has the BOM. Rather than look at the BOM we look at the number of zero bytes
|
||||||
// in the first few character. XML files even when not in European languages tend to have more
|
// in the first few character. XML files even when not in European languages tend to have more
|
||||||
// even zero bytes when big-endian encoded and more odd zero bytes when little-endian.
|
// even zero bytes when big-endian encoded and more odd zero bytes when little-endian.
|
||||||
// Think of: <?xml version="1.0"?> The normal Java decoder does not have this flexibility but
|
// Think of: <?xml version="1.0"?> The normal Java decoder does not have this flexibility but
|
||||||
// other transformers do.
|
// other transformers do.
|
||||||
String name = charset.displayName();
|
String name = charset.displayName();
|
||||||
if ("UTF-16".equals(name) || "UTF-16BE".equals(name) || "UTF-16LE".equals(name))
|
if ("UTF-16".equals(name) || "UTF-16BE".equals(name) || "UTF-16LE".equals(name))
|
||||||
{
|
{
|
||||||
logger.debug("Handle big and little endian UTF-16 text. Using UTF-16 rather than encoding " + name);
|
logger.debug("Handle big and little endian UTF-16 text. Using UTF-16 rather than encoding " + name);
|
||||||
charset = Charset.forName("UTF-16");
|
charset = Charset.forName("UTF-16");
|
||||||
is = new PushbackInputStream(is, UTF16_READ_AHEAD_BYTES)
|
is = new PushbackInputStream(is, UTF16_READ_AHEAD_BYTES)
|
||||||
{
|
{
|
||||||
boolean bomRead;
|
boolean bomRead;
|
||||||
boolean switchByteOrder;
|
boolean switchByteOrder;
|
||||||
boolean evenByte = true;
|
boolean evenByte = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] bytes, int off, int len) throws IOException
|
public int read(byte[] bytes, int off, int len) throws IOException
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int b = 0;
|
int b = 0;
|
||||||
for (; i<len; i++)
|
for (; i<len; i++)
|
||||||
{
|
{
|
||||||
b = read();
|
b = read();
|
||||||
if (b == -1)
|
if (b == -1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes[off+i] = (byte)b;
|
bytes[off+i] = (byte)b;
|
||||||
}
|
}
|
||||||
return i == 0 && b == -1 ? -1 : i;
|
return i == 0 && b == -1 ? -1 : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException
|
public int read() throws IOException
|
||||||
{
|
{
|
||||||
if (!bomRead)
|
if (!bomRead)
|
||||||
{
|
{
|
||||||
bomRead = true;
|
bomRead = true;
|
||||||
boolean switchBom = false;
|
boolean switchBom = false;
|
||||||
byte[] bytes = new byte[UTF16_READ_AHEAD_BYTES];
|
byte[] bytes = new byte[UTF16_READ_AHEAD_BYTES];
|
||||||
int end = in.read(bytes, 0, UTF16_READ_AHEAD_BYTES);
|
int end = in.read(bytes, 0, UTF16_READ_AHEAD_BYTES);
|
||||||
int evenZeros = countZeros(bytes, 0);
|
int evenZeros = countZeros(bytes, 0);
|
||||||
int oddZeros = countZeros(bytes, 1);
|
int oddZeros = countZeros(bytes, 1);
|
||||||
if (evenZeros > oddZeros)
|
if (evenZeros > oddZeros)
|
||||||
{
|
{
|
||||||
if (bytes[0] == FF && bytes[1] == FE)
|
if (bytes[0] == FF && bytes[1] == FE)
|
||||||
{
|
{
|
||||||
switchByteOrder = true;
|
switchByteOrder = true;
|
||||||
switchBom = true;
|
switchBom = true;
|
||||||
logger.warn("Little-endian BOM FFFE read, but characters are big-endian");
|
logger.warn("Little-endian BOM FFFE read, but characters are big-endian");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.debug("More even zero bytes, so normal read for big-endian");
|
logger.debug("More even zero bytes, so normal read for big-endian");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bytes[0] == FE && bytes[1] == FF)
|
if (bytes[0] == FE && bytes[1] == FF)
|
||||||
{
|
{
|
||||||
switchBom = true;
|
switchBom = true;
|
||||||
logger.debug("Big-endian BOM FEFF read, but characters are little-endian");
|
logger.debug("Big-endian BOM FEFF read, but characters are little-endian");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switchByteOrder = true;
|
switchByteOrder = true;
|
||||||
logger.debug("More odd zero bytes, so switch bytes from little-endian");
|
logger.debug("More odd zero bytes, so switch bytes from little-endian");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switchBom)
|
if (switchBom)
|
||||||
{
|
{
|
||||||
byte b = bytes[0];
|
byte b = bytes[0];
|
||||||
bytes[0] = bytes[1];
|
bytes[0] = bytes[1];
|
||||||
bytes[1] = b;
|
bytes[1] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = end-1; i>=0; i--)
|
for (int i = end-1; i>=0; i--)
|
||||||
{
|
{
|
||||||
unread(bytes[i]);
|
unread(bytes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switchByteOrder)
|
if (switchByteOrder)
|
||||||
{
|
{
|
||||||
if (evenByte)
|
if (evenByte)
|
||||||
{
|
{
|
||||||
int b1 = super.read();
|
int b1 = super.read();
|
||||||
int b2 = super.read();
|
int b2 = super.read();
|
||||||
if (b1 != -1)
|
if (b1 != -1)
|
||||||
{
|
{
|
||||||
unread(b1);
|
unread(b1);
|
||||||
}
|
}
|
||||||
if (b2 != -1)
|
if (b2 != -1)
|
||||||
{
|
{
|
||||||
unread(b2);
|
unread(b2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
evenByte = !evenByte;
|
evenByte = !evenByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.read();
|
return super.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Counts the number of even or odd 00 bytes
|
// Counts the number of even or odd 00 bytes
|
||||||
private int countZeros(byte[] b, int offset)
|
private int countZeros(byte[] b, int offset)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i=offset; i<UTF16_READ_AHEAD_BYTES; i+=2)
|
for (int i=offset; i<UTF16_READ_AHEAD_BYTES; i+=2)
|
||||||
{
|
{
|
||||||
if (b[i] == 0)
|
if (b[i] == 0)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
logger.debug("Processing plain text in encoding " + name);
|
logger.debug("Processing plain text in encoding " + name);
|
||||||
return new InputStreamReader(is, charset);
|
return new InputStreamReader(is, charset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back on the system default
|
// Fall back on the system default
|
||||||
logger.debug("Processing plain text using system default encoding");
|
logger.debug("Processing plain text using system default encoding");
|
||||||
return new InputStreamReader(is);
|
return new InputStreamReader(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PagedTextToPDF extends TextToPDF
|
private static class PagedTextToPDF extends TextToPDF
|
||||||
{
|
{
|
||||||
// REPO-1066: duplicating the following lines from org.apache.pdfbox.tools.TextToPDF because they made them private
|
// REPO-1066: duplicating the following lines from org.apache.pdfbox.tools.TextToPDF because they made them private
|
||||||
// before the upgrade to pdfbox 2.0.8, in pdfbox 1.8, this piece of code was public in org.apache.pdfbox.pdmodel.font.PDType1Font
|
// before the upgrade to pdfbox 2.0.8, in pdfbox 1.8, this piece of code was public in org.apache.pdfbox.pdmodel.font.PDType1Font
|
||||||
static PDType1Font getStandardFont(String name)
|
static PDType1Font getStandardFont(String name)
|
||||||
{
|
{
|
||||||
return STANDARD_14.get(name);
|
return STANDARD_14.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, PDType1Font> STANDARD_14 = new HashMap<>();
|
private static final Map<String, PDType1Font> STANDARD_14 = new HashMap<>();
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
STANDARD_14.put(PDType1Font.TIMES_ROMAN.getBaseFont(), PDType1Font.TIMES_ROMAN);
|
STANDARD_14.put(PDType1Font.TIMES_ROMAN.getBaseFont(), PDType1Font.TIMES_ROMAN);
|
||||||
STANDARD_14.put(PDType1Font.TIMES_BOLD.getBaseFont(), PDType1Font.TIMES_BOLD);
|
STANDARD_14.put(PDType1Font.TIMES_BOLD.getBaseFont(), PDType1Font.TIMES_BOLD);
|
||||||
STANDARD_14.put(PDType1Font.TIMES_ITALIC.getBaseFont(), PDType1Font.TIMES_ITALIC);
|
STANDARD_14.put(PDType1Font.TIMES_ITALIC.getBaseFont(), PDType1Font.TIMES_ITALIC);
|
||||||
STANDARD_14.put(PDType1Font.TIMES_BOLD_ITALIC.getBaseFont(),
|
STANDARD_14.put(PDType1Font.TIMES_BOLD_ITALIC.getBaseFont(),
|
||||||
PDType1Font.TIMES_BOLD_ITALIC);
|
PDType1Font.TIMES_BOLD_ITALIC);
|
||||||
STANDARD_14.put(PDType1Font.HELVETICA.getBaseFont(), PDType1Font.HELVETICA);
|
STANDARD_14.put(PDType1Font.HELVETICA.getBaseFont(), PDType1Font.HELVETICA);
|
||||||
STANDARD_14.put(PDType1Font.HELVETICA_BOLD.getBaseFont(), PDType1Font.HELVETICA_BOLD);
|
STANDARD_14.put(PDType1Font.HELVETICA_BOLD.getBaseFont(), PDType1Font.HELVETICA_BOLD);
|
||||||
STANDARD_14.put(PDType1Font.HELVETICA_OBLIQUE.getBaseFont(),
|
STANDARD_14.put(PDType1Font.HELVETICA_OBLIQUE.getBaseFont(),
|
||||||
PDType1Font.HELVETICA_OBLIQUE);
|
PDType1Font.HELVETICA_OBLIQUE);
|
||||||
STANDARD_14.put(PDType1Font.HELVETICA_BOLD_OBLIQUE.getBaseFont(),
|
STANDARD_14.put(PDType1Font.HELVETICA_BOLD_OBLIQUE.getBaseFont(),
|
||||||
PDType1Font.HELVETICA_BOLD_OBLIQUE);
|
PDType1Font.HELVETICA_BOLD_OBLIQUE);
|
||||||
STANDARD_14.put(PDType1Font.COURIER.getBaseFont(), PDType1Font.COURIER);
|
STANDARD_14.put(PDType1Font.COURIER.getBaseFont(), PDType1Font.COURIER);
|
||||||
STANDARD_14.put(PDType1Font.COURIER_BOLD.getBaseFont(), PDType1Font.COURIER_BOLD);
|
STANDARD_14.put(PDType1Font.COURIER_BOLD.getBaseFont(), PDType1Font.COURIER_BOLD);
|
||||||
STANDARD_14.put(PDType1Font.COURIER_OBLIQUE.getBaseFont(), PDType1Font.COURIER_OBLIQUE);
|
STANDARD_14.put(PDType1Font.COURIER_OBLIQUE.getBaseFont(), PDType1Font.COURIER_OBLIQUE);
|
||||||
STANDARD_14.put(PDType1Font.COURIER_BOLD_OBLIQUE.getBaseFont(),
|
STANDARD_14.put(PDType1Font.COURIER_BOLD_OBLIQUE.getBaseFont(),
|
||||||
PDType1Font.COURIER_BOLD_OBLIQUE);
|
PDType1Font.COURIER_BOLD_OBLIQUE);
|
||||||
STANDARD_14.put(PDType1Font.SYMBOL.getBaseFont(), PDType1Font.SYMBOL);
|
STANDARD_14.put(PDType1Font.SYMBOL.getBaseFont(), PDType1Font.SYMBOL);
|
||||||
STANDARD_14.put(PDType1Font.ZAPF_DINGBATS.getBaseFont(), PDType1Font.ZAPF_DINGBATS);
|
STANDARD_14.put(PDType1Font.ZAPF_DINGBATS.getBaseFont(), PDType1Font.ZAPF_DINGBATS);
|
||||||
}
|
}
|
||||||
//duplicating until here
|
//duplicating until here
|
||||||
|
|
||||||
// The following code is based on the code in TextToPDF with the addition of
|
// The following code is based on the code in TextToPDF with the addition of
|
||||||
// checks for page limits.
|
// checks for page limits.
|
||||||
// The calling code must close the PDDocument once finished with it.
|
// The calling code must close the PDDocument once finished with it.
|
||||||
public PDDocument createPDFFromText(Reader text, int pageLimit)
|
public PDDocument createPDFFromText(Reader text, int pageLimit)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
PDDocument doc = null;
|
PDDocument doc = null;
|
||||||
int pageCount = 0;
|
int pageCount = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final int margin = 40;
|
final int margin = 40;
|
||||||
float height = getFont().getFontDescriptor().getFontBoundingBox().getHeight() / 1000;
|
float height = getFont().getFontDescriptor().getFontBoundingBox().getHeight() / 1000;
|
||||||
|
|
||||||
//calculate font height and increase by 5 percent.
|
//calculate font height and increase by 5 percent.
|
||||||
height = height * getFontSize() * 1.05f;
|
height = height * getFontSize() * 1.05f;
|
||||||
doc = new PDDocument();
|
doc = new PDDocument();
|
||||||
BufferedReader data = (text instanceof BufferedReader) ? (BufferedReader) text : new BufferedReader(text);
|
BufferedReader data = (text instanceof BufferedReader) ? (BufferedReader) text : new BufferedReader(text);
|
||||||
String nextLine;
|
String nextLine;
|
||||||
PDPage page = new PDPage();
|
PDPage page = new PDPage();
|
||||||
PDPageContentStream contentStream = null;
|
PDPageContentStream contentStream = null;
|
||||||
float y = -1;
|
float y = -1;
|
||||||
float maxStringLength = page.getMediaBox().getWidth() - 2 * margin;
|
float maxStringLength = page.getMediaBox().getWidth() - 2 * margin;
|
||||||
|
|
||||||
// There is a special case of creating a PDF document from an empty string.
|
// There is a special case of creating a PDF document from an empty string.
|
||||||
boolean textIsEmpty = true;
|
boolean textIsEmpty = true;
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
while ((nextLine = data.readLine()) != null)
|
while ((nextLine = data.readLine()) != null)
|
||||||
{
|
{
|
||||||
// The input text is nonEmpty. New pages will be created and added
|
// The input text is nonEmpty. New pages will be created and added
|
||||||
// to the PDF document as they are needed, depending on the length of
|
// to the PDF document as they are needed, depending on the length of
|
||||||
// the text.
|
// the text.
|
||||||
textIsEmpty = false;
|
textIsEmpty = false;
|
||||||
|
|
||||||
String[] lineWords = nextLine.trim().split(" ");
|
String[] lineWords = nextLine.trim().split(" ");
|
||||||
int lineIndex = 0;
|
int lineIndex = 0;
|
||||||
while (lineIndex < lineWords.length)
|
while (lineIndex < lineWords.length)
|
||||||
{
|
{
|
||||||
final StringBuilder nextLineToDraw = new StringBuilder();
|
final StringBuilder nextLineToDraw = new StringBuilder();
|
||||||
float lengthIfUsingNextWord = 0;
|
float lengthIfUsingNextWord = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
nextLineToDraw.append(lineWords[lineIndex]);
|
nextLineToDraw.append(lineWords[lineIndex]);
|
||||||
nextLineToDraw.append(" ");
|
nextLineToDraw.append(" ");
|
||||||
lineIndex++;
|
lineIndex++;
|
||||||
if (lineIndex < lineWords.length)
|
if (lineIndex < lineWords.length)
|
||||||
{
|
{
|
||||||
String lineWithNextWord = nextLineToDraw.toString() + lineWords[lineIndex];
|
String lineWithNextWord = nextLineToDraw.toString() + lineWords[lineIndex];
|
||||||
lengthIfUsingNextWord =
|
lengthIfUsingNextWord =
|
||||||
(getFont().getStringWidth(
|
(getFont().getStringWidth(
|
||||||
lineWithNextWord) / 1000) * getFontSize();
|
lineWithNextWord) / 1000) * getFontSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (lineIndex < lineWords.length &&
|
while (lineIndex < lineWords.length &&
|
||||||
lengthIfUsingNextWord < maxStringLength);
|
lengthIfUsingNextWord < maxStringLength);
|
||||||
if (y < margin)
|
if (y < margin)
|
||||||
{
|
{
|
||||||
int test = pageCount + 1;
|
int test = pageCount + 1;
|
||||||
if (pageLimit > 0 && (pageCount++ >= pageLimit))
|
if (pageLimit > 0 && (pageCount++ >= pageLimit))
|
||||||
{
|
{
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have crossed the end-of-page boundary and need to extend the
|
// We have crossed the end-of-page boundary and need to extend the
|
||||||
// document by another page.
|
// document by another page.
|
||||||
page = new PDPage();
|
page = new PDPage();
|
||||||
doc.addPage(page);
|
doc.addPage(page);
|
||||||
if (contentStream != null)
|
if (contentStream != null)
|
||||||
{
|
{
|
||||||
contentStream.endText();
|
contentStream.endText();
|
||||||
contentStream.close();
|
contentStream.close();
|
||||||
}
|
}
|
||||||
contentStream = new PDPageContentStream(doc, page);
|
contentStream = new PDPageContentStream(doc, page);
|
||||||
contentStream.setFont(getFont(), getFontSize());
|
contentStream.setFont(getFont(), getFontSize());
|
||||||
contentStream.beginText();
|
contentStream.beginText();
|
||||||
y = page.getMediaBox().getHeight() - margin + height;
|
y = page.getMediaBox().getHeight() - margin + height;
|
||||||
contentStream.moveTextPositionByAmount(margin, y);
|
contentStream.moveTextPositionByAmount(margin, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentStream == null)
|
if (contentStream == null)
|
||||||
{
|
{
|
||||||
throw new IOException("Error:Expected non-null content stream.");
|
throw new IOException("Error:Expected non-null content stream.");
|
||||||
}
|
}
|
||||||
contentStream.moveTextPositionByAmount(0, -height);
|
contentStream.moveTextPositionByAmount(0, -height);
|
||||||
y -= height;
|
y -= height;
|
||||||
contentStream.drawString(nextLineToDraw.toString());
|
contentStream.drawString(nextLineToDraw.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the input text was the empty string, then the above while loop will have short-circuited
|
// If the input text was the empty string, then the above while loop will have short-circuited
|
||||||
// and we will not have added any PDPages to the document.
|
// and we will not have added any PDPages to the document.
|
||||||
// So in order to make the resultant PDF document readable by Adobe Reader etc, we'll add an empty page.
|
// So in order to make the resultant PDF document readable by Adobe Reader etc, we'll add an empty page.
|
||||||
if (textIsEmpty)
|
if (textIsEmpty)
|
||||||
{
|
{
|
||||||
doc.addPage(page);
|
doc.addPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentStream != null)
|
if (contentStream != null)
|
||||||
{
|
{
|
||||||
contentStream.endText();
|
contentStream.endText();
|
||||||
contentStream.close();
|
contentStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException io)
|
catch (IOException io)
|
||||||
{
|
{
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
{
|
{
|
||||||
doc.close();
|
doc.close();
|
||||||
}
|
}
|
||||||
throw io;
|
throw io;
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int parseInt(String s, String paramName)
|
private int parseInt(String s, String paramName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Integer.valueOf(s);
|
return Integer.valueOf(s);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(paramName + " parameter must be an integer.");
|
throw new IllegalArgumentException(paramName + " parameter must be an integer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
#
|
#
|
||||||
# HtmlMetadataExtractor - default mapping
|
# HtmlMetadataExtractor - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
|
@@ -1,162 +1,162 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.transformers;
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class HtmlParserContentTransformerTest
|
public class HtmlParserContentTransformerTest
|
||||||
{
|
{
|
||||||
private static final String SOURCE_MIMETYPE = "text/html";
|
private static final String SOURCE_MIMETYPE = "text/html";
|
||||||
private static final String TARGET_MIMETYPE = "text/plain";
|
private static final String TARGET_MIMETYPE = "text/plain";
|
||||||
|
|
||||||
HtmlParserContentTransformer transformer = new HtmlParserContentTransformer();
|
HtmlParserContentTransformer transformer = new HtmlParserContentTransformer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that we correctly handle text in different encodings,
|
* Checks that we correctly handle text in different encodings,
|
||||||
* no matter if the encoding is specified on the Content Property
|
* no matter if the encoding is specified on the Content Property
|
||||||
* or in a meta tag within the HTML itself. (ALF-10466)
|
* or in a meta tag within the HTML itself. (ALF-10466)
|
||||||
*
|
*
|
||||||
* On Windows, org.htmlparser.beans.StringBean.carriageReturn() appends a new system dependent new line
|
* On Windows, org.htmlparser.beans.StringBean.carriageReturn() appends a new system dependent new line
|
||||||
* so we must be careful when checking the returned text
|
* so we must be careful when checking the returned text
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEncodingHandling() throws Exception
|
public void testEncodingHandling() throws Exception
|
||||||
{
|
{
|
||||||
final String NEWLINE = System.getProperty("line.separator");
|
final String NEWLINE = System.getProperty("line.separator");
|
||||||
final String TITLE = "Testing!";
|
final String TITLE = "Testing!";
|
||||||
final String TEXT_P1 = "This is some text in English";
|
final String TEXT_P1 = "This is some text in English";
|
||||||
final String TEXT_P2 = "This is more text in English";
|
final String TEXT_P2 = "This is more text in English";
|
||||||
final String TEXT_P3 = "C'est en Fran\u00e7ais et Espa\u00f1ol";
|
final String TEXT_P3 = "C'est en Fran\u00e7ais et Espa\u00f1ol";
|
||||||
String partA = "<html><head><title>" + TITLE + "</title></head>" + NEWLINE;
|
String partA = "<html><head><title>" + TITLE + "</title></head>" + NEWLINE;
|
||||||
String partB = "<body><p>" + TEXT_P1 + "</p>" + NEWLINE +
|
String partB = "<body><p>" + TEXT_P1 + "</p>" + NEWLINE +
|
||||||
"<p>" + TEXT_P2 + "</p>" + NEWLINE +
|
"<p>" + TEXT_P2 + "</p>" + NEWLINE +
|
||||||
"<p>" + TEXT_P3 + "</p>" + NEWLINE;
|
"<p>" + TEXT_P3 + "</p>" + NEWLINE;
|
||||||
String partC = "</body></html>";
|
String partC = "</body></html>";
|
||||||
final String expected = TITLE + NEWLINE + TEXT_P1 + NEWLINE + TEXT_P2 + NEWLINE + TEXT_P3 + NEWLINE;
|
final String expected = TITLE + NEWLINE + TEXT_P1 + NEWLINE + TEXT_P2 + NEWLINE + TEXT_P3 + NEWLINE;
|
||||||
|
|
||||||
File tmpS = null;
|
File tmpS = null;
|
||||||
File tmpD = null;
|
File tmpD = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Content set to ISO 8859-1
|
// Content set to ISO 8859-1
|
||||||
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
||||||
writeToFile(tmpS, partA + partB + partC, "ISO-8859-1");
|
writeToFile(tmpS, partA + partB + partC, "ISO-8859-1");
|
||||||
|
|
||||||
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
||||||
|
|
||||||
Map<String, String> parameters = new HashMap<>();
|
Map<String, String> parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
|
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
|
||||||
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
||||||
|
|
||||||
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
||||||
tmpS.delete();
|
tmpS.delete();
|
||||||
tmpD.delete();
|
tmpD.delete();
|
||||||
|
|
||||||
// Content set to UTF-8
|
// Content set to UTF-8
|
||||||
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
||||||
writeToFile(tmpS, partA + partB + partC, "UTF-8");
|
writeToFile(tmpS, partA + partB + partC, "UTF-8");
|
||||||
|
|
||||||
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
||||||
parameters = new HashMap<>();
|
parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||||
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
||||||
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
||||||
tmpS.delete();
|
tmpS.delete();
|
||||||
tmpD.delete();
|
tmpD.delete();
|
||||||
|
|
||||||
// Content set to UTF-16
|
// Content set to UTF-16
|
||||||
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
||||||
writeToFile(tmpS, partA + partB + partC, "UTF-16");
|
writeToFile(tmpS, partA + partB + partC, "UTF-16");
|
||||||
|
|
||||||
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
||||||
parameters = new HashMap<>();
|
parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "UTF-16");
|
parameters.put(SOURCE_ENCODING, "UTF-16");
|
||||||
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
||||||
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
||||||
tmpS.delete();
|
tmpS.delete();
|
||||||
tmpD.delete();
|
tmpD.delete();
|
||||||
|
|
||||||
// Note - since HTML Parser 2.0 META tags specifying the
|
// Note - since HTML Parser 2.0 META tags specifying the
|
||||||
// document encoding will ONLY be respected if the original
|
// document encoding will ONLY be respected if the original
|
||||||
// content type was set to ISO-8859-1.
|
// content type was set to ISO-8859-1.
|
||||||
//
|
//
|
||||||
// This means there is now only one test which we can perform
|
// This means there is now only one test which we can perform
|
||||||
// to ensure that this now-limited overriding of the encoding
|
// to ensure that this now-limited overriding of the encoding
|
||||||
// takes effect.
|
// takes effect.
|
||||||
|
|
||||||
// Content set to ISO 8859-1, meta set to UTF-8
|
// Content set to ISO 8859-1, meta set to UTF-8
|
||||||
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
tmpS = File.createTempFile("AlfrescoTestSource_", ".html");
|
||||||
String str = partA +
|
String str = partA +
|
||||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" +
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" +
|
||||||
partB + partC;
|
partB + partC;
|
||||||
|
|
||||||
writeToFile(tmpS, str, "UTF-8");
|
writeToFile(tmpS, str, "UTF-8");
|
||||||
|
|
||||||
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
|
||||||
|
|
||||||
parameters = new HashMap<>();
|
parameters = new HashMap<>();
|
||||||
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
|
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
|
||||||
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
|
||||||
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
|
||||||
tmpS.delete();
|
tmpS.delete();
|
||||||
tmpD.delete();
|
tmpD.delete();
|
||||||
|
|
||||||
// Note - we can't test UTF-16 with only a meta encoding,
|
// Note - we can't test UTF-16 with only a meta encoding,
|
||||||
// because without that the parser won't know about the
|
// because without that the parser won't know about the
|
||||||
// 2 byte format so won't be able to identify the meta tag
|
// 2 byte format so won't be able to identify the meta tag
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (tmpS != null && tmpS.exists()) tmpS.delete();
|
if (tmpS != null && tmpS.exists()) tmpS.delete();
|
||||||
if (tmpD != null && tmpD.exists()) tmpD.delete();
|
if (tmpD != null && tmpD.exists()) tmpD.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeToFile(File file, String content, String encoding) throws Exception
|
private void writeToFile(File file, String content, String encoding) throws Exception
|
||||||
{
|
{
|
||||||
try (OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), encoding))
|
try (OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), encoding))
|
||||||
{
|
{
|
||||||
ow.append(content);
|
ow.append(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readFromFile(File file, final String encoding) throws Exception
|
private String readFromFile(File file, final String encoding) throws Exception
|
||||||
{
|
{
|
||||||
return new String(Files.readAllBytes(file.toPath()), encoding);
|
return new String(Files.readAllBytes(file.toPath()), encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,127 +1,127 @@
|
|||||||
The "Artistic License"
|
The "Artistic License"
|
||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The intent of this document is to state the conditions under which a
|
The intent of this document is to state the conditions under which a
|
||||||
Package may be copied, such that the Copyright Holder maintains some
|
Package may be copied, such that the Copyright Holder maintains some
|
||||||
semblance of artistic control over the development of the package,
|
semblance of artistic control over the development of the package,
|
||||||
while giving the users of the package the right to use and distribute
|
while giving the users of the package the right to use and distribute
|
||||||
the Package in a more-or-less customary fashion, plus the right to make
|
the Package in a more-or-less customary fashion, plus the right to make
|
||||||
reasonable modifications.
|
reasonable modifications.
|
||||||
|
|
||||||
Definitions:
|
Definitions:
|
||||||
|
|
||||||
"Package" refers to the collection of files distributed by the
|
"Package" refers to the collection of files distributed by the
|
||||||
Copyright Holder, and derivatives of that collection of files
|
Copyright Holder, and derivatives of that collection of files
|
||||||
created through textual modification.
|
created through textual modification.
|
||||||
|
|
||||||
"Standard Version" refers to such a Package if it has not been
|
"Standard Version" refers to such a Package if it has not been
|
||||||
modified, or has been modified in accordance with the wishes
|
modified, or has been modified in accordance with the wishes
|
||||||
of the Copyright Holder as specified below.
|
of the Copyright Holder as specified below.
|
||||||
|
|
||||||
"Copyright Holder" is whoever is named in the copyright or
|
"Copyright Holder" is whoever is named in the copyright or
|
||||||
copyrights for the package.
|
copyrights for the package.
|
||||||
|
|
||||||
"You" is you, if you're thinking about copying or distributing
|
"You" is you, if you're thinking about copying or distributing
|
||||||
this Package.
|
this Package.
|
||||||
|
|
||||||
"Reasonable copying fee" is whatever you can justify on the
|
"Reasonable copying fee" is whatever you can justify on the
|
||||||
basis of media cost, duplication charges, time of people involved,
|
basis of media cost, duplication charges, time of people involved,
|
||||||
and so on. (You will not be required to justify it to the
|
and so on. (You will not be required to justify it to the
|
||||||
Copyright Holder, but only to the computing community at large
|
Copyright Holder, but only to the computing community at large
|
||||||
as a market that must bear the fee.)
|
as a market that must bear the fee.)
|
||||||
|
|
||||||
"Freely Available" means that no fee is charged for the item
|
"Freely Available" means that no fee is charged for the item
|
||||||
itself, though there may be fees involved in handling the item.
|
itself, though there may be fees involved in handling the item.
|
||||||
It also means that recipients of the item may redistribute it
|
It also means that recipients of the item may redistribute it
|
||||||
under the same conditions they received it.
|
under the same conditions they received it.
|
||||||
|
|
||||||
1. You may make and give away verbatim copies of the source form of the
|
1. You may make and give away verbatim copies of the source form of the
|
||||||
Standard Version of this Package without restriction, provided that you
|
Standard Version of this Package without restriction, provided that you
|
||||||
duplicate all of the original copyright notices and associated disclaimers.
|
duplicate all of the original copyright notices and associated disclaimers.
|
||||||
|
|
||||||
2. You may apply bug fixes, portability fixes and other modifications
|
2. You may apply bug fixes, portability fixes and other modifications
|
||||||
derived from the Public Domain or from the Copyright Holder. A Package
|
derived from the Public Domain or from the Copyright Holder. A Package
|
||||||
modified in such a way shall still be considered the Standard Version.
|
modified in such a way shall still be considered the Standard Version.
|
||||||
|
|
||||||
3. You may otherwise modify your copy of this Package in any way, provided
|
3. You may otherwise modify your copy of this Package in any way, provided
|
||||||
that you insert a prominent notice in each changed file stating how and
|
that you insert a prominent notice in each changed file stating how and
|
||||||
when you changed that file, and provided that you do at least ONE of the
|
when you changed that file, and provided that you do at least ONE of the
|
||||||
following:
|
following:
|
||||||
|
|
||||||
a) place your modifications in the Public Domain or otherwise make them
|
a) place your modifications in the Public Domain or otherwise make them
|
||||||
Freely Available, such as by posting said modifications to Usenet or
|
Freely Available, such as by posting said modifications to Usenet or
|
||||||
an equivalent medium, or placing the modifications on a major archive
|
an equivalent medium, or placing the modifications on a major archive
|
||||||
site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
||||||
your modifications in the Standard Version of the Package.
|
your modifications in the Standard Version of the Package.
|
||||||
|
|
||||||
b) use the modified Package only within your corporation or organization.
|
b) use the modified Package only within your corporation or organization.
|
||||||
|
|
||||||
c) rename any non-standard executables so the names do not conflict
|
c) rename any non-standard executables so the names do not conflict
|
||||||
with standard executables, which must also be provided, and provide
|
with standard executables, which must also be provided, and provide
|
||||||
a separate manual page for each non-standard executable that clearly
|
a separate manual page for each non-standard executable that clearly
|
||||||
documents how it differs from the Standard Version.
|
documents how it differs from the Standard Version.
|
||||||
|
|
||||||
d) make other distribution arrangements with the Copyright Holder.
|
d) make other distribution arrangements with the Copyright Holder.
|
||||||
|
|
||||||
4. You may distribute the programs of this Package in object code or
|
4. You may distribute the programs of this Package in object code or
|
||||||
executable form, provided that you do at least ONE of the following:
|
executable form, provided that you do at least ONE of the following:
|
||||||
|
|
||||||
a) distribute a Standard Version of the executables and library files,
|
a) distribute a Standard Version of the executables and library files,
|
||||||
together with instructions (in the manual page or equivalent) on where
|
together with instructions (in the manual page or equivalent) on where
|
||||||
to get the Standard Version.
|
to get the Standard Version.
|
||||||
|
|
||||||
b) accompany the distribution with the machine-readable source of
|
b) accompany the distribution with the machine-readable source of
|
||||||
the Package with your modifications.
|
the Package with your modifications.
|
||||||
|
|
||||||
c) give non-standard executables non-standard names, and clearly
|
c) give non-standard executables non-standard names, and clearly
|
||||||
document the differences in manual pages (or equivalent), together
|
document the differences in manual pages (or equivalent), together
|
||||||
with instructions on where to get the Standard Version.
|
with instructions on where to get the Standard Version.
|
||||||
|
|
||||||
d) make other distribution arrangements with the Copyright Holder.
|
d) make other distribution arrangements with the Copyright Holder.
|
||||||
|
|
||||||
5. You may charge a reasonable copying fee for any distribution of this
|
5. You may charge a reasonable copying fee for any distribution of this
|
||||||
Package. You may charge any fee you choose for support of this
|
Package. You may charge any fee you choose for support of this
|
||||||
Package. You may not charge a fee for this Package itself. However,
|
Package. You may not charge a fee for this Package itself. However,
|
||||||
you may distribute this Package in aggregate with other (possibly
|
you may distribute this Package in aggregate with other (possibly
|
||||||
commercial) programs as part of a larger (possibly commercial) software
|
commercial) programs as part of a larger (possibly commercial) software
|
||||||
distribution provided that you do not advertise this Package as a
|
distribution provided that you do not advertise this Package as a
|
||||||
product of your own. You may embed this Package's interpreter within
|
product of your own. You may embed this Package's interpreter within
|
||||||
an executable of yours (by linking); this shall be construed as a mere
|
an executable of yours (by linking); this shall be construed as a mere
|
||||||
form of aggregation, provided that the complete Standard Version of the
|
form of aggregation, provided that the complete Standard Version of the
|
||||||
interpreter is so embedded.
|
interpreter is so embedded.
|
||||||
|
|
||||||
6. The scripts and library files supplied as input to or produced as
|
6. The scripts and library files supplied as input to or produced as
|
||||||
output from the programs of this Package do not automatically fall
|
output from the programs of this Package do not automatically fall
|
||||||
under the copyright of this Package, but belong to whoever generated
|
under the copyright of this Package, but belong to whoever generated
|
||||||
them, and may be sold commercially, and may be aggregated with this
|
them, and may be sold commercially, and may be aggregated with this
|
||||||
Package. If such scripts or library files are aggregated with this
|
Package. If such scripts or library files are aggregated with this
|
||||||
Package via the so-called "undump" or "unexec" methods of producing a
|
Package via the so-called "undump" or "unexec" methods of producing a
|
||||||
binary executable image, then distribution of such an image shall
|
binary executable image, then distribution of such an image shall
|
||||||
neither be construed as a distribution of this Package nor shall it
|
neither be construed as a distribution of this Package nor shall it
|
||||||
fall under the restrictions of Paragraphs 3 and 4, provided that you do
|
fall under the restrictions of Paragraphs 3 and 4, provided that you do
|
||||||
not represent such an executable image as a Standard Version of this
|
not represent such an executable image as a Standard Version of this
|
||||||
Package.
|
Package.
|
||||||
|
|
||||||
7. C subroutines (or comparably compiled subroutines in other
|
7. C subroutines (or comparably compiled subroutines in other
|
||||||
languages) supplied by you and linked into this Package in order to
|
languages) supplied by you and linked into this Package in order to
|
||||||
emulate subroutines and variables of the language defined by this
|
emulate subroutines and variables of the language defined by this
|
||||||
Package shall not be considered part of this Package, but are the
|
Package shall not be considered part of this Package, but are the
|
||||||
equivalent of input as in Paragraph 6, provided these subroutines do
|
equivalent of input as in Paragraph 6, provided these subroutines do
|
||||||
not change the language in any way that would cause it to fail the
|
not change the language in any way that would cause it to fail the
|
||||||
regression tests for the language.
|
regression tests for the language.
|
||||||
|
|
||||||
8. Aggregation of this Package with a commercial distribution is always
|
8. Aggregation of this Package with a commercial distribution is always
|
||||||
permitted provided that the use of this Package is embedded; that is,
|
permitted provided that the use of this Package is embedded; that is,
|
||||||
when no overt attempt is made to make this Package's interfaces visible
|
when no overt attempt is made to make this Package's interfaces visible
|
||||||
to the end user of the commercial distribution. Such use shall not be
|
to the end user of the commercial distribution. Such use shall not be
|
||||||
construed as a distribution of this Package.
|
construed as a distribution of this Package.
|
||||||
|
|
||||||
9. The name of the Copyright Holder may not be used to endorse or promote
|
9. The name of the Copyright Holder may not be used to endorse or promote
|
||||||
products derived from this software without specific prior written permission.
|
products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
||||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
The End
|
The End
|
||||||
|
Binary file not shown.
@@ -1,158 +1,158 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.metadataExtractors;
|
package org.alfresco.transformer.metadataExtractors;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.alfresco.transformer.tika.parsers.ExifToolParser;
|
import org.alfresco.transformer.tika.parsers.ExifToolParser;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.tika.metadata.Metadata;
|
import org.apache.tika.metadata.Metadata;
|
||||||
import org.apache.tika.parser.Parser;
|
import org.apache.tika.parser.Parser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class IPTCMetadataExtractor extends AbstractTikaMetadataExtractor
|
public class IPTCMetadataExtractor extends AbstractTikaMetadataExtractor
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(IPTCMetadataExtractor.class);
|
private static final Logger logger = LoggerFactory.getLogger(IPTCMetadataExtractor.class);
|
||||||
|
|
||||||
private static Set<String> IPTC_DATE_KEYS = Set.of("XMP-photoshop:DateCreated", "XMP-iptcExt:ArtworkDateCreated");
|
private static Set<String> IPTC_DATE_KEYS = Set.of("XMP-photoshop:DateCreated", "XMP-iptcExt:ArtworkDateCreated");
|
||||||
|
|
||||||
private static final Pattern YEAR_IPTC = Pattern.compile("(\\d{4}[:|-]\\d{2}[:|-]\\d{2})");
|
private static final Pattern YEAR_IPTC = Pattern.compile("(\\d{4}[:|-]\\d{2}[:|-]\\d{2})");
|
||||||
|
|
||||||
private ExifToolParser parser;
|
private ExifToolParser parser;
|
||||||
|
|
||||||
public IPTCMetadataExtractor()
|
public IPTCMetadataExtractor()
|
||||||
{
|
{
|
||||||
super(logger);
|
super(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Parser getParser()
|
protected Parser getParser()
|
||||||
{
|
{
|
||||||
if (this.parser == null) {
|
if (this.parser == null) {
|
||||||
this.parser = new ExifToolParser();
|
this.parser = new ExifToolParser();
|
||||||
}
|
}
|
||||||
return this.parser;
|
return this.parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Because some of the mimetypes that IPTCMetadataExtractor now parse, were previously handled
|
* Because some of the mimetypes that IPTCMetadataExtractor now parse, were previously handled
|
||||||
* by TikaAutoMetadataExtractor we call the TikaAutoMetadataExtractor.extractSpecific method to
|
* by TikaAutoMetadataExtractor we call the TikaAutoMetadataExtractor.extractSpecific method to
|
||||||
* ensure that the returned properties contains the expected entries.
|
* ensure that the returned properties contains the expected entries.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Serializable> extractSpecific(Metadata metadata, Map<String, Serializable> properties,
|
protected Map<String, Serializable> extractSpecific(Metadata metadata, Map<String, Serializable> properties,
|
||||||
Map<String, String> headers)
|
Map<String, String> headers)
|
||||||
{
|
{
|
||||||
properties = new TikaAutoMetadataExtractor().extractSpecific(metadata, properties, headers);
|
properties = new TikaAutoMetadataExtractor().extractSpecific(metadata, properties, headers);
|
||||||
ExifToolParser etParser = (ExifToolParser)this.getParser();
|
ExifToolParser etParser = (ExifToolParser)this.getParser();
|
||||||
if (etParser.getSeparator()!=null)
|
if (etParser.getSeparator()!=null)
|
||||||
{
|
{
|
||||||
for (String key : properties.keySet())
|
for (String key : properties.keySet())
|
||||||
{
|
{
|
||||||
if (properties.get(key) instanceof String)
|
if (properties.get(key) instanceof String)
|
||||||
{
|
{
|
||||||
String value = (String) properties.get(key);
|
String value = (String) properties.get(key);
|
||||||
String separator = etParser.getSeparator();
|
String separator = etParser.getSeparator();
|
||||||
if (value.contains(separator))
|
if (value.contains(separator))
|
||||||
{
|
{
|
||||||
if (value.contains(String.format("\"%s\"",separator)))
|
if (value.contains(String.format("\"%s\"",separator)))
|
||||||
{
|
{
|
||||||
separator = String.format("\"%s\"",separator);
|
separator = String.format("\"%s\"",separator);
|
||||||
}
|
}
|
||||||
String [] values = StringUtils.splitByWholeSeparator(value, separator);
|
String [] values = StringUtils.splitByWholeSeparator(value, separator);
|
||||||
// Change dateTime format. MM converted ':' to '-'
|
// Change dateTime format. MM converted ':' to '-'
|
||||||
if (IPTC_DATE_KEYS.contains(key)){
|
if (IPTC_DATE_KEYS.contains(key)){
|
||||||
values = iptcToIso8601DateStrings(values);
|
values = iptcToIso8601DateStrings(values);
|
||||||
}
|
}
|
||||||
putRawValue(key, (Serializable) Arrays.asList(values), properties);
|
putRawValue(key, (Serializable) Arrays.asList(values), properties);
|
||||||
}
|
}
|
||||||
else if (IPTC_DATE_KEYS.contains(key)) {
|
else if (IPTC_DATE_KEYS.contains(key)) {
|
||||||
// Handle property with a single date string
|
// Handle property with a single date string
|
||||||
putRawValue(key, (Serializable) iptcToIso8601DateString(value), properties);
|
putRawValue(key, (Serializable) iptcToIso8601DateString(value), properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a date or date time strings into Iso8601 format <p>
|
* Converts a date or date time strings into Iso8601 format <p>
|
||||||
*
|
*
|
||||||
* @param dateStrings
|
* @param dateStrings
|
||||||
* @return dateStrings in Iso8601 format
|
* @return dateStrings in Iso8601 format
|
||||||
* @see #iptcToIso8601DateString
|
* @see #iptcToIso8601DateString
|
||||||
*/
|
*/
|
||||||
protected String[] iptcToIso8601DateStrings(String[] dateStrings)
|
protected String[] iptcToIso8601DateStrings(String[] dateStrings)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < dateStrings.length; i++)
|
for (int i = 0; i < dateStrings.length; i++)
|
||||||
{
|
{
|
||||||
dateStrings[i] = iptcToIso8601DateString(dateStrings[i]);
|
dateStrings[i] = iptcToIso8601DateString(dateStrings[i]);
|
||||||
}
|
}
|
||||||
return dateStrings;
|
return dateStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a date or date time string into Iso8601 format <p>
|
* Converts a date or date time string into Iso8601 format <p>
|
||||||
* Converts any ':' in the year portion of a date string characters to '-'. <p>
|
* Converts any ':' in the year portion of a date string characters to '-'. <p>
|
||||||
* Expects the year in the format YYYY:MM:DD or YYYY-MM-DD <p>
|
* Expects the year in the format YYYY:MM:DD or YYYY-MM-DD <p>
|
||||||
* Will add the correct delimiter, 'T', to any dateTime strings, where | can be any char other than ,'T':
|
* Will add the correct delimiter, 'T', to any dateTime strings, where | can be any char other than ,'T':
|
||||||
* YYYY:MM:DD|HH:mm:ss.... or YYYY-MM-DD|HH:mm:ss....
|
* YYYY:MM:DD|HH:mm:ss.... or YYYY-MM-DD|HH:mm:ss....
|
||||||
* <p>
|
* <p>
|
||||||
* Examples: <p><ul>
|
* Examples: <p><ul>
|
||||||
* <li>"1919:10:16" will convert to "1919-10-16"</li>
|
* <li>"1919:10:16" will convert to "1919-10-16"</li>
|
||||||
* <li>"1901:02:01 00:00:00.000Z" will convert to "1901-02-01T00:00:00.000Z"</li>
|
* <li>"1901:02:01 00:00:00.000Z" will convert to "1901-02-01T00:00:00.000Z"</li>
|
||||||
* <li>"2001:02:01 16:15+00:00" will convert to "2001-02-01T16:15+00:00"</li>
|
* <li>"2001:02:01 16:15+00:00" will convert to "2001-02-01T16:15+00:00"</li>
|
||||||
* <li>"2021-06-11 05:36-01:00" will convert to "2021-06-11T05:36-01:00"</li>
|
* <li>"2021-06-11 05:36-01:00" will convert to "2021-06-11T05:36-01:00"</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param dateStr
|
* @param dateStr
|
||||||
* @return dateStr in Iso8601 format
|
* @return dateStr in Iso8601 format
|
||||||
*/
|
*/
|
||||||
protected String iptcToIso8601DateString(String dateStr)
|
protected String iptcToIso8601DateString(String dateStr)
|
||||||
{
|
{
|
||||||
char timeSeparator = 'T';
|
char timeSeparator = 'T';
|
||||||
Matcher yearMatcher = YEAR_IPTC.matcher(dateStr);
|
Matcher yearMatcher = YEAR_IPTC.matcher(dateStr);
|
||||||
if (yearMatcher.find())
|
if (yearMatcher.find())
|
||||||
{
|
{
|
||||||
String year = yearMatcher.group(1);
|
String year = yearMatcher.group(1);
|
||||||
dateStr = yearMatcher.replaceFirst(year.replaceAll(":", "-"));
|
dateStr = yearMatcher.replaceFirst(year.replaceAll(":", "-"));
|
||||||
if (dateStr.length()>year.length() && dateStr.charAt(year.length())!=timeSeparator)
|
if (dateStr.length()>year.length() && dateStr.charAt(year.length())!=timeSeparator)
|
||||||
{
|
{
|
||||||
dateStr = dateStr.replace(dateStr.charAt(year.length()), timeSeparator);
|
dateStr = dateStr.replace(dateStr.charAt(year.length()), timeSeparator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dateStr;
|
return dateStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,372 +1,372 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.tika.parsers;
|
package org.alfresco.transformer.tika.parsers;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_JPEG;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_TIFF;
|
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_TIFF;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.apache.tika.exception.TikaException;
|
import org.apache.tika.exception.TikaException;
|
||||||
import org.apache.tika.io.TemporaryResources;
|
import org.apache.tika.io.TemporaryResources;
|
||||||
import org.apache.tika.io.TikaInputStream;
|
import org.apache.tika.io.TikaInputStream;
|
||||||
import org.apache.tika.metadata.Metadata;
|
import org.apache.tika.metadata.Metadata;
|
||||||
import org.apache.tika.mime.MediaType;
|
import org.apache.tika.mime.MediaType;
|
||||||
import org.apache.tika.parser.ParseContext;
|
import org.apache.tika.parser.ParseContext;
|
||||||
import org.apache.tika.parser.Parser;
|
import org.apache.tika.parser.Parser;
|
||||||
import org.apache.tika.parser.external.ExternalParser;
|
import org.apache.tika.parser.external.ExternalParser;
|
||||||
import org.apache.tika.parser.external.ExternalParsersFactory;
|
import org.apache.tika.parser.external.ExternalParsersFactory;
|
||||||
import org.apache.tika.parser.image.ImageParser;
|
import org.apache.tika.parser.image.ImageParser;
|
||||||
import org.apache.tika.parser.image.TiffParser;
|
import org.apache.tika.parser.image.TiffParser;
|
||||||
import org.apache.tika.parser.image.JpegParser;
|
import org.apache.tika.parser.image.JpegParser;
|
||||||
import org.apache.tika.sax.XHTMLContentHandler;
|
import org.apache.tika.sax.XHTMLContentHandler;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class ExifToolParser extends ExternalParser {
|
public class ExifToolParser extends ExternalParser {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ExifToolParser.class);
|
private static final Logger logger = LoggerFactory.getLogger(ExifToolParser.class);
|
||||||
|
|
||||||
private static final String EXIFTOOL_PARSER_CONFIG = "parsers/external/config/exiftool-parser.xml";
|
private static final String EXIFTOOL_PARSER_CONFIG = "parsers/external/config/exiftool-parser.xml";
|
||||||
|
|
||||||
protected static final String DEFAULT_SEPARATOR = ", ";
|
protected static final String DEFAULT_SEPARATOR = ", ";
|
||||||
protected static final String SEPARATOR_SETTING = "-sep";
|
protected static final String SEPARATOR_SETTING = "-sep";
|
||||||
|
|
||||||
private String separator;
|
private String separator;
|
||||||
|
|
||||||
public ExifToolParser() {
|
public ExifToolParser() {
|
||||||
super();
|
super();
|
||||||
try {
|
try {
|
||||||
List<ExternalParser> eParsers = ExternalParsersFactory.create(getExternalParserConfigURL());
|
List<ExternalParser> eParsers = ExternalParsersFactory.create(getExternalParserConfigURL());
|
||||||
// if ExifTool is not installed then no parsers are returned
|
// if ExifTool is not installed then no parsers are returned
|
||||||
if (eParsers.size() > 0) {
|
if (eParsers.size() > 0) {
|
||||||
ExternalParser eParser = eParsers.get(0);
|
ExternalParser eParser = eParsers.get(0);
|
||||||
this.setCommand(eParser.getCommand());
|
this.setCommand(eParser.getCommand());
|
||||||
this.setIgnoredLineConsumer(eParser.getIgnoredLineConsumer());
|
this.setIgnoredLineConsumer(eParser.getIgnoredLineConsumer());
|
||||||
this.setMetadataExtractionPatterns(eParser.getMetadataExtractionPatterns());
|
this.setMetadataExtractionPatterns(eParser.getMetadataExtractionPatterns());
|
||||||
this.setSupportedTypes(eParser.getSupportedTypes());
|
this.setSupportedTypes(eParser.getSupportedTypes());
|
||||||
} else {
|
} else {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error creating ExifToolParser from config, ExifToolExtractions not enabled. Please check ExifTool is installed correctly.");
|
"Error creating ExifToolParser from config, ExifToolExtractions not enabled. Please check ExifTool is installed correctly.");
|
||||||
}
|
}
|
||||||
} catch (IOException | TikaException e) {
|
} catch (IOException | TikaException e) {
|
||||||
logger.error("Error creating ExifToolParser from config, ExifToolExtractions not enabled: ", e);
|
logger.error("Error creating ExifToolParser from config, ExifToolExtractions not enabled: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL getExternalParserConfigURL(){
|
private URL getExternalParserConfigURL(){
|
||||||
ClassLoader classLoader = ExifToolParser.class.getClassLoader();
|
ClassLoader classLoader = ExifToolParser.class.getClassLoader();
|
||||||
return classLoader.getResource(EXIFTOOL_PARSER_CONFIG);
|
return classLoader.getResource(EXIFTOOL_PARSER_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeparator(String sep) {
|
public void setSeparator(String sep) {
|
||||||
this.separator = sep;
|
this.separator = sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSeparator() {
|
public String getSeparator() {
|
||||||
return this.separator;
|
return this.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCommand(String... command){
|
public void setCommand(String... command){
|
||||||
super.setCommand(command);
|
super.setCommand(command);
|
||||||
if (command.length==1) {
|
if (command.length==1) {
|
||||||
setSeparator(findSeparator(command[0]));
|
setSeparator(findSeparator(command[0]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setSeparator(DEFAULT_SEPARATOR);
|
setSeparator(DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String findSeparator(String command) {
|
protected String findSeparator(String command) {
|
||||||
if (command.contains(SEPARATOR_SETTING)) {
|
if (command.contains(SEPARATOR_SETTING)) {
|
||||||
int start = command.indexOf(SEPARATOR_SETTING)+SEPARATOR_SETTING.length()+1;
|
int start = command.indexOf(SEPARATOR_SETTING)+SEPARATOR_SETTING.length()+1;
|
||||||
String separator = DEFAULT_SEPARATOR;
|
String separator = DEFAULT_SEPARATOR;
|
||||||
if (command.charAt(start)=='\"') {
|
if (command.charAt(start)=='\"') {
|
||||||
//get all chars up to the next \"
|
//get all chars up to the next \"
|
||||||
int end = command.indexOf("\"", start+1);
|
int end = command.indexOf("\"", start+1);
|
||||||
separator = command.substring(start+1, end);
|
separator = command.substring(start+1, end);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int end = command.indexOf(" ", start);
|
int end = command.indexOf(" ", start);
|
||||||
separator = command.substring(start, end);
|
separator = command.substring(start, end);
|
||||||
}
|
}
|
||||||
return separator;
|
return separator;
|
||||||
}
|
}
|
||||||
return DEFAULT_SEPARATOR;
|
return DEFAULT_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}
|
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}
|
||||||
* due to errors attempting to {@link #extractMetadata} from the errorStream in original implementation. <p>
|
* due to errors attempting to {@link #extractMetadata} from the errorStream in original implementation. <p>
|
||||||
* Executes the configured external command and passes the given document
|
* Executes the configured external command and passes the given document
|
||||||
* stream as a simple XHTML document to the given SAX content handler.
|
* stream as a simple XHTML document to the given SAX content handler.
|
||||||
* Metadata is only extracted if {@link #setMetadataExtractionPatterns(Map)}
|
* Metadata is only extracted if {@link #setMetadataExtractionPatterns(Map)}
|
||||||
* has been called to set patterns.
|
* has been called to set patterns.
|
||||||
*/
|
*/
|
||||||
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
|
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
|
||||||
throws IOException, SAXException, TikaException {
|
throws IOException, SAXException, TikaException {
|
||||||
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
|
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
|
||||||
|
|
||||||
MediaType mediaType = MediaType.parse(metadata.get(Metadata.CONTENT_TYPE));
|
MediaType mediaType = MediaType.parse(metadata.get(Metadata.CONTENT_TYPE));
|
||||||
TemporaryResources tmp = new TemporaryResources();
|
TemporaryResources tmp = new TemporaryResources();
|
||||||
try {
|
try {
|
||||||
TikaInputStream tis = TikaInputStream.get(stream, tmp);
|
TikaInputStream tis = TikaInputStream.get(stream, tmp);
|
||||||
if (this.getSupportedTypes().contains(mediaType)) {
|
if (this.getSupportedTypes().contains(mediaType)) {
|
||||||
parse(tis, xhtml, metadata, tmp);
|
parse(tis, xhtml, metadata, tmp);
|
||||||
}
|
}
|
||||||
switch (mediaType.getType()+"/"+mediaType.getSubtype()) {
|
switch (mediaType.getType()+"/"+mediaType.getSubtype()) {
|
||||||
case MIMETYPE_IMAGE_JPEG:
|
case MIMETYPE_IMAGE_JPEG:
|
||||||
parseAdditional(new JpegParser(), tis, handler, metadata, context, mediaType);
|
parseAdditional(new JpegParser(), tis, handler, metadata, context, mediaType);
|
||||||
break;
|
break;
|
||||||
case MIMETYPE_IMAGE_TIFF:
|
case MIMETYPE_IMAGE_TIFF:
|
||||||
parseAdditional(new TiffParser(), tis, handler, metadata, context, mediaType);
|
parseAdditional(new TiffParser(), tis, handler, metadata, context, mediaType);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
parseAdditional(new ImageParser(), tis, handler, metadata, context, mediaType);
|
parseAdditional(new ImageParser(), tis, handler, metadata, context, mediaType);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tmp.dispose();
|
tmp.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseAdditional(Parser parser, TikaInputStream tis, ContentHandler handler, Metadata metadata, ParseContext context,
|
private void parseAdditional(Parser parser, TikaInputStream tis, ContentHandler handler, Metadata metadata, ParseContext context,
|
||||||
MediaType mediaType) throws IOException, SAXException, TikaException {
|
MediaType mediaType) throws IOException, SAXException, TikaException {
|
||||||
if (parser.getSupportedTypes(context).contains(mediaType)) {
|
if (parser.getSupportedTypes(context).contains(mediaType)) {
|
||||||
parser.parse(tis, handler, metadata, context);
|
parser.parse(tis, handler, metadata, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parse(TikaInputStream stream, XHTMLContentHandler xhtml, Metadata metadata, TemporaryResources tmp)
|
private void parse(TikaInputStream stream, XHTMLContentHandler xhtml, Metadata metadata, TemporaryResources tmp)
|
||||||
throws IOException, SAXException, TikaException {
|
throws IOException, SAXException, TikaException {
|
||||||
boolean inputToStdIn = true;
|
boolean inputToStdIn = true;
|
||||||
boolean outputFromStdOut = true;
|
boolean outputFromStdOut = true;
|
||||||
boolean hasPatterns = (getMetadataExtractionPatterns() != null && !getMetadataExtractionPatterns().isEmpty());
|
boolean hasPatterns = (getMetadataExtractionPatterns() != null && !getMetadataExtractionPatterns().isEmpty());
|
||||||
|
|
||||||
File output = null;
|
File output = null;
|
||||||
|
|
||||||
// Build our getCommand()
|
// Build our getCommand()
|
||||||
String[] cmd;
|
String[] cmd;
|
||||||
if (getCommand().length == 1) {
|
if (getCommand().length == 1) {
|
||||||
cmd = getCommand()[0].split(" ");
|
cmd = getCommand()[0].split(" ");
|
||||||
} else {
|
} else {
|
||||||
cmd = new String[getCommand().length];
|
cmd = new String[getCommand().length];
|
||||||
System.arraycopy(getCommand(), 0, cmd, 0, getCommand().length);
|
System.arraycopy(getCommand(), 0, cmd, 0, getCommand().length);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < cmd.length; i++) {
|
for (int i = 0; i < cmd.length; i++) {
|
||||||
if (cmd[i].indexOf(INPUT_FILE_TOKEN) != -1) {
|
if (cmd[i].indexOf(INPUT_FILE_TOKEN) != -1) {
|
||||||
cmd[i] = cmd[i].replace(INPUT_FILE_TOKEN, stream.getFile().getPath());
|
cmd[i] = cmd[i].replace(INPUT_FILE_TOKEN, stream.getFile().getPath());
|
||||||
inputToStdIn = false;
|
inputToStdIn = false;
|
||||||
}
|
}
|
||||||
if (cmd[i].indexOf(OUTPUT_FILE_TOKEN) != -1) {
|
if (cmd[i].indexOf(OUTPUT_FILE_TOKEN) != -1) {
|
||||||
output = tmp.createTemporaryFile();
|
output = tmp.createTemporaryFile();
|
||||||
outputFromStdOut = false;
|
outputFromStdOut = false;
|
||||||
cmd[i] = cmd[i].replace(OUTPUT_FILE_TOKEN, output.getPath());
|
cmd[i] = cmd[i].replace(OUTPUT_FILE_TOKEN, output.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
Process process = null;
|
Process process = null;
|
||||||
try {
|
try {
|
||||||
if (cmd.length == 1) {
|
if (cmd.length == 1) {
|
||||||
process = Runtime.getRuntime().exec(cmd[0]);
|
process = Runtime.getRuntime().exec(cmd[0]);
|
||||||
} else {
|
} else {
|
||||||
process = Runtime.getRuntime().exec(cmd);
|
process = Runtime.getRuntime().exec(cmd);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (inputToStdIn) {
|
if (inputToStdIn) {
|
||||||
sendInput(process, stream);
|
sendInput(process, stream);
|
||||||
} else {
|
} else {
|
||||||
process.getOutputStream().close();
|
process.getOutputStream().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream out = process.getInputStream();
|
InputStream out = process.getInputStream();
|
||||||
InputStream err = process.getErrorStream();
|
InputStream err = process.getErrorStream();
|
||||||
|
|
||||||
if (hasPatterns) {
|
if (hasPatterns) {
|
||||||
|
|
||||||
if (outputFromStdOut) {
|
if (outputFromStdOut) {
|
||||||
extractOutput(out, xhtml);
|
extractOutput(out, xhtml);
|
||||||
} else {
|
} else {
|
||||||
extractMetadata(out, metadata);
|
extractMetadata(out, metadata);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ignoreStream(err);
|
ignoreStream(err);
|
||||||
|
|
||||||
if (outputFromStdOut) {
|
if (outputFromStdOut) {
|
||||||
extractOutput(out, xhtml);
|
extractOutput(out, xhtml);
|
||||||
} else {
|
} else {
|
||||||
ignoreStream(out);
|
ignoreStream(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the output if we haven't already
|
// Grab the output if we haven't already
|
||||||
if (!outputFromStdOut) {
|
if (!outputFromStdOut) {
|
||||||
extractOutput(new FileInputStream(output), xhtml);
|
extractOutput(new FileInputStream(output), xhtml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
||||||
* Starts a thread that extracts the contents of the standard output
|
* Starts a thread that extracts the contents of the standard output
|
||||||
* stream of the given process to the given XHTML content handler.
|
* stream of the given process to the given XHTML content handler.
|
||||||
* The standard output stream is closed once fully processed.
|
* The standard output stream is closed once fully processed.
|
||||||
*
|
*
|
||||||
* @param stream stream
|
* @param stream stream
|
||||||
* @param xhtml XHTML content handler
|
* @param xhtml XHTML content handler
|
||||||
* @throws SAXException if the XHTML SAX events could not be handled
|
* @throws SAXException if the XHTML SAX events could not be handled
|
||||||
* @throws IOException if an input error occurred
|
* @throws IOException if an input error occurred
|
||||||
*/
|
*/
|
||||||
private void extractOutput(InputStream stream, XHTMLContentHandler xhtml) throws SAXException, IOException {
|
private void extractOutput(InputStream stream, XHTMLContentHandler xhtml) throws SAXException, IOException {
|
||||||
try (Reader reader = new InputStreamReader(stream, UTF_8)) {
|
try (Reader reader = new InputStreamReader(stream, UTF_8)) {
|
||||||
xhtml.startDocument();
|
xhtml.startDocument();
|
||||||
xhtml.startElement("p");
|
xhtml.startElement("p");
|
||||||
char[] buffer = new char[1024];
|
char[] buffer = new char[1024];
|
||||||
for (int n = reader.read(buffer); n != -1; n = reader.read(buffer)) {
|
for (int n = reader.read(buffer); n != -1; n = reader.read(buffer)) {
|
||||||
xhtml.characters(buffer, 0, n);
|
xhtml.characters(buffer, 0, n);
|
||||||
}
|
}
|
||||||
xhtml.endElement("p");
|
xhtml.endElement("p");
|
||||||
xhtml.endDocument();
|
xhtml.endDocument();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
||||||
* Starts a thread that sends the contents of the given input stream
|
* Starts a thread that sends the contents of the given input stream
|
||||||
* to the standard input stream of the given process. Potential
|
* to the standard input stream of the given process. Potential
|
||||||
* exceptions are ignored, and the standard input stream is closed
|
* exceptions are ignored, and the standard input stream is closed
|
||||||
* once fully processed. Note that the given input stream is <em>not</em>
|
* once fully processed. Note that the given input stream is <em>not</em>
|
||||||
* closed by this method.
|
* closed by this method.
|
||||||
*
|
*
|
||||||
* @param process process
|
* @param process process
|
||||||
* @param stream input stream
|
* @param stream input stream
|
||||||
*/
|
*/
|
||||||
private void sendInput(final Process process, final InputStream stream) {
|
private void sendInput(final Process process, final InputStream stream) {
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
OutputStream stdin = process.getOutputStream();
|
OutputStream stdin = process.getOutputStream();
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(stream, stdin);
|
IOUtils.copy(stream, stdin);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
t.join();
|
t.join();
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
* Adapted from {@link org.apache.tika.parser.external.ExternalParser}<p>
|
||||||
* Starts a thread that reads and discards the contents of the
|
* Starts a thread that reads and discards the contents of the
|
||||||
* standard stream of the given process. Potential exceptions
|
* standard stream of the given process. Potential exceptions
|
||||||
* are ignored, and the stream is closed once fully processed.
|
* are ignored, and the stream is closed once fully processed.
|
||||||
*
|
*
|
||||||
* @param stream stream
|
* @param stream stream
|
||||||
*/
|
*/
|
||||||
private void ignoreStream(final InputStream stream) {
|
private void ignoreStream(final InputStream stream) {
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(stream, NullOutputStream.NULL_OUTPUT_STREAM);
|
IOUtils.copy(stream, NullOutputStream.NULL_OUTPUT_STREAM);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(stream);
|
IOUtils.closeQuietly(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
t.join();
|
t.join();
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractMetadata(final InputStream stream, final Metadata metadata) {
|
private void extractMetadata(final InputStream stream, final Metadata metadata) {
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
BufferedReader reader;
|
BufferedReader reader;
|
||||||
reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
|
reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
|
||||||
try {
|
try {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
for (Pattern p : getMetadataExtractionPatterns().keySet()) {
|
for (Pattern p : getMetadataExtractionPatterns().keySet()) {
|
||||||
Matcher m = p.matcher(line);
|
Matcher m = p.matcher(line);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
if (getMetadataExtractionPatterns().get(p) != null
|
if (getMetadataExtractionPatterns().get(p) != null
|
||||||
&& !getMetadataExtractionPatterns().get(p).equals("")) {
|
&& !getMetadataExtractionPatterns().get(p).equals("")) {
|
||||||
metadata.add(getMetadataExtractionPatterns().get(p), m.group(1));
|
metadata.add(getMetadataExtractionPatterns().get(p), m.group(1));
|
||||||
} else {
|
} else {
|
||||||
metadata.add(m.group(1), m.group(2));
|
metadata.add(m.group(1), m.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(reader);
|
IOUtils.closeQuietly(reader);
|
||||||
IOUtils.closeQuietly(stream);
|
IOUtils.closeQuietly(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
t.join();
|
t.join();
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
#
|
#
|
||||||
# DWGMetadataExtracter - default mapping
|
# DWGMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Nick Burch
|
# author: Nick Burch
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
|
@@ -1,30 +1,30 @@
|
|||||||
#
|
#
|
||||||
# MP3MetadataExtracter - default mapping
|
# MP3MetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
||||||
|
|
||||||
# Core mappings
|
# Core mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
created=cm:created
|
created=cm:created
|
||||||
|
|
||||||
# Audio descriptive mappings
|
# Audio descriptive mappings
|
||||||
xmpDM\:album=audio:album
|
xmpDM\:album=audio:album
|
||||||
xmpDM\:artist=audio:artist
|
xmpDM\:artist=audio:artist
|
||||||
xmpDM\:composer=audio:composer
|
xmpDM\:composer=audio:composer
|
||||||
xmpDM\:engineer=audio:engineer
|
xmpDM\:engineer=audio:engineer
|
||||||
xmpDM\:genre=audio:genre
|
xmpDM\:genre=audio:genre
|
||||||
xmpDM\:trackNumber=audio:trackNumber
|
xmpDM\:trackNumber=audio:trackNumber
|
||||||
xmpDM\:releaseDate=audio:releaseDate
|
xmpDM\:releaseDate=audio:releaseDate
|
||||||
#xmpDM:logComment
|
#xmpDM:logComment
|
||||||
|
|
||||||
# Audio specific mappings
|
# Audio specific mappings
|
||||||
xmpDM\:audioSampleRate=audio:sampleRate
|
xmpDM\:audioSampleRate=audio:sampleRate
|
||||||
xmpDM\:audioSampleType=audio:sampleType
|
xmpDM\:audioSampleType=audio:sampleType
|
||||||
xmpDM\:audioChannelType=audio:channelType
|
xmpDM\:audioChannelType=audio:channelType
|
||||||
xmpDM\:audioCompressor=audio:compressor
|
xmpDM\:audioCompressor=audio:compressor
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
#
|
#
|
||||||
# MailMetadataExtracter - default mapping
|
# MailMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
sentDate=cm:sentdate
|
sentDate=cm:sentdate
|
||||||
originator=cm:originator, cm:author
|
originator=cm:originator, cm:author
|
||||||
addressee=cm:addressee
|
addressee=cm:addressee
|
||||||
addressees=cm:addressees
|
addressees=cm:addressees
|
||||||
subjectLine=cm:subjectline, cm:description
|
subjectLine=cm:subjectline, cm:description
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
#
|
#
|
||||||
# OfficeMetadataExtracter - default mapping
|
# OfficeMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
subject=cm:description
|
subject=cm:description
|
||||||
createDateTime=cm:created
|
createDateTime=cm:created
|
||||||
lastSaveDateTime=cm:modified
|
lastSaveDateTime=cm:modified
|
||||||
|
@@ -1,21 +1,21 @@
|
|||||||
#
|
#
|
||||||
# OpenDocumentMetadataExtracter - default mapping
|
# OpenDocumentMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
creationDate=cm:created
|
creationDate=cm:created
|
||||||
creator=cm:author
|
creator=cm:author
|
||||||
date=
|
date=
|
||||||
description=
|
description=
|
||||||
generator=
|
generator=
|
||||||
initialCreator=
|
initialCreator=
|
||||||
keyword=
|
keyword=
|
||||||
language=
|
language=
|
||||||
printDate=
|
printDate=
|
||||||
printedBy=
|
printedBy=
|
||||||
subject=cm:description
|
subject=cm:description
|
||||||
title=cm:title
|
title=cm:title
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
#
|
#
|
||||||
# PdfBoxMetadataExtracter - default mapping
|
# PdfBoxMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Derek Hulley
|
# author: Derek Hulley
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
subject=cm:description
|
subject=cm:description
|
||||||
created=cm:created
|
created=cm:created
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
#
|
#
|
||||||
# PoiMetadataExtracter - default mapping
|
# PoiMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# author: Neil McErlean
|
# author: Neil McErlean
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
created=cm:created
|
created=cm:created
|
||||||
|
@@ -1,34 +1,34 @@
|
|||||||
#
|
#
|
||||||
# TikaAudioMetadataExtracter - audio mapping
|
# TikaAudioMetadataExtracter - audio mapping
|
||||||
#
|
#
|
||||||
# This is used to map from the Tika audio metadata onto your
|
# This is used to map from the Tika audio metadata onto your
|
||||||
# content model. This will be used for any Audio content
|
# content model. This will be used for any Audio content
|
||||||
# for which an explicit extractor isn't defined
|
# for which an explicit extractor isn't defined
|
||||||
#
|
#
|
||||||
# author: Nick Burch
|
# author: Nick Burch
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
||||||
|
|
||||||
# Core mappings
|
# Core mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
created=cm:created
|
created=cm:created
|
||||||
|
|
||||||
# Audio descriptive mappings
|
# Audio descriptive mappings
|
||||||
xmpDM\:album=audio:album
|
xmpDM\:album=audio:album
|
||||||
xmpDM\:artist=audio:artist
|
xmpDM\:artist=audio:artist
|
||||||
xmpDM\:composer=audio:composer
|
xmpDM\:composer=audio:composer
|
||||||
xmpDM\:engineer=audio:engineer
|
xmpDM\:engineer=audio:engineer
|
||||||
xmpDM\:genre=audio:genre
|
xmpDM\:genre=audio:genre
|
||||||
xmpDM\:trackNumber=audio:trackNumber
|
xmpDM\:trackNumber=audio:trackNumber
|
||||||
xmpDM\:releaseDate=audio:releaseDate
|
xmpDM\:releaseDate=audio:releaseDate
|
||||||
#xmpDM:logComment
|
#xmpDM:logComment
|
||||||
|
|
||||||
# Audio specific mappings
|
# Audio specific mappings
|
||||||
xmpDM\:audioSampleRate=audio:sampleRate
|
xmpDM\:audioSampleRate=audio:sampleRate
|
||||||
xmpDM\:audioSampleType=audio:sampleType
|
xmpDM\:audioSampleType=audio:sampleType
|
||||||
xmpDM\:audioChannelType=audio:channelType
|
xmpDM\:audioChannelType=audio:channelType
|
||||||
xmpDM\:audioCompressor=audio:compressor
|
xmpDM\:audioCompressor=audio:compressor
|
||||||
|
@@ -1,52 +1,52 @@
|
|||||||
#
|
#
|
||||||
# TikaAutoMetadataExtracter - default mapping
|
# TikaAutoMetadataExtracter - default mapping
|
||||||
#
|
#
|
||||||
# This is used to map from the Tika and standard namespaces
|
# This is used to map from the Tika and standard namespaces
|
||||||
# onto your content model. This will be used for any
|
# onto your content model. This will be used for any
|
||||||
# content for which an explicit extractor isn't defined,
|
# content for which an explicit extractor isn't defined,
|
||||||
# by using Tika's auto-selection facilities.
|
# by using Tika's auto-selection facilities.
|
||||||
#
|
#
|
||||||
# author: Nick Burch
|
# author: Nick Burch
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
namespace.prefix.cm=http://www.alfresco.org/model/content/1.0
|
||||||
namespace.prefix.exif=http://www.alfresco.org/model/exif/1.0
|
namespace.prefix.exif=http://www.alfresco.org/model/exif/1.0
|
||||||
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
namespace.prefix.audio=http://www.alfresco.org/model/audio/1.0
|
||||||
|
|
||||||
# Mappings
|
# Mappings
|
||||||
author=cm:author
|
author=cm:author
|
||||||
title=cm:title
|
title=cm:title
|
||||||
description=cm:description
|
description=cm:description
|
||||||
created=cm:created
|
created=cm:created
|
||||||
|
|
||||||
geo\:lat=cm:latitude
|
geo\:lat=cm:latitude
|
||||||
geo\:long=cm:longitude
|
geo\:long=cm:longitude
|
||||||
|
|
||||||
tiff\:ImageWidth=exif:pixelXDimension
|
tiff\:ImageWidth=exif:pixelXDimension
|
||||||
tiff\:ImageLength=exif:pixelYDimension
|
tiff\:ImageLength=exif:pixelYDimension
|
||||||
tiff\:Make=exif:manufacturer
|
tiff\:Make=exif:manufacturer
|
||||||
tiff\:Model=exif:model
|
tiff\:Model=exif:model
|
||||||
tiff\:Software=exif:software
|
tiff\:Software=exif:software
|
||||||
tiff\:Orientation=exif:orientation
|
tiff\:Orientation=exif:orientation
|
||||||
tiff\:XResolution=exif:xResolution
|
tiff\:XResolution=exif:xResolution
|
||||||
tiff\:YResolution=exif:yResolution
|
tiff\:YResolution=exif:yResolution
|
||||||
tiff\:ResolutionUnit=exif:resolutionUnit
|
tiff\:ResolutionUnit=exif:resolutionUnit
|
||||||
exif\:Flash=exif:flash
|
exif\:Flash=exif:flash
|
||||||
exif\:ExposureTime=exif:exposureTime
|
exif\:ExposureTime=exif:exposureTime
|
||||||
exif\:FNumber=exif:fNumber
|
exif\:FNumber=exif:fNumber
|
||||||
exif\:FocalLength=exif:focalLength
|
exif\:FocalLength=exif:focalLength
|
||||||
exif\:IsoSpeedRatings=exif:isoSpeedRatings
|
exif\:IsoSpeedRatings=exif:isoSpeedRatings
|
||||||
exif\:DateTimeOriginal=exif:dateTimeOriginal
|
exif\:DateTimeOriginal=exif:dateTimeOriginal
|
||||||
|
|
||||||
xmpDM\:album=audio:album
|
xmpDM\:album=audio:album
|
||||||
xmpDM\:artist=audio:artist
|
xmpDM\:artist=audio:artist
|
||||||
xmpDM\:composer=audio:composer
|
xmpDM\:composer=audio:composer
|
||||||
xmpDM\:engineer=audio:engineer
|
xmpDM\:engineer=audio:engineer
|
||||||
xmpDM\:genre=audio:genre
|
xmpDM\:genre=audio:genre
|
||||||
xmpDM\:trackNumber=audio:trackNumber
|
xmpDM\:trackNumber=audio:trackNumber
|
||||||
xmpDM\:releaseDate=audio:releaseDate
|
xmpDM\:releaseDate=audio:releaseDate
|
||||||
#xmpDM:logComment
|
#xmpDM:logComment
|
||||||
xmpDM\:audioSampleRate=audio:sampleRate
|
xmpDM\:audioSampleRate=audio:sampleRate
|
||||||
xmpDM\:audioSampleType=audio:sampleType
|
xmpDM\:audioSampleType=audio:sampleType
|
||||||
xmpDM\:audioChannelType=audio:channelType
|
xmpDM\:audioChannelType=audio:channelType
|
||||||
xmpDM\:audioCompressor=audio:compressor
|
xmpDM\:audioCompressor=audio:compressor
|
||||||
|
@@ -1,35 +1,35 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<external-parsers>
|
<external-parsers>
|
||||||
<parser>
|
<parser>
|
||||||
<check>
|
<check>
|
||||||
<command>exiftool -ver</command>
|
<command>exiftool -ver</command>
|
||||||
<error-codes>126,127</error-codes>
|
<error-codes>126,127</error-codes>
|
||||||
</check>
|
</check>
|
||||||
<command>env FOO=${OUTPUT} exiftool -args -G1 -sep "|||" ${INPUT}</command>
|
<command>env FOO=${OUTPUT} exiftool -args -G1 -sep "|||" ${INPUT}</command>
|
||||||
<mime-types>
|
<mime-types>
|
||||||
<mime-type>image/x-raw-hasselblad</mime-type>
|
<mime-type>image/x-raw-hasselblad</mime-type>
|
||||||
<mime-type>image/x-raw-sony</mime-type>
|
<mime-type>image/x-raw-sony</mime-type>
|
||||||
<mime-type>image/x-raw-canon</mime-type>
|
<mime-type>image/x-raw-canon</mime-type>
|
||||||
<mime-type>image/x-raw-adobe</mime-type>
|
<mime-type>image/x-raw-adobe</mime-type>
|
||||||
<mime-type>image/gif</mime-type>
|
<mime-type>image/gif</mime-type>
|
||||||
<mime-type>image/jp2</mime-type>
|
<mime-type>image/jp2</mime-type>
|
||||||
<mime-type>image/jpeg</mime-type>
|
<mime-type>image/jpeg</mime-type>
|
||||||
<mime-type>image/x-raw-kodak</mime-type>
|
<mime-type>image/x-raw-kodak</mime-type>
|
||||||
<mime-type>image/x-raw-minolta</mime-type>
|
<mime-type>image/x-raw-minolta</mime-type>
|
||||||
<mime-type>image/x-raw-nikon</mime-type>
|
<mime-type>image/x-raw-nikon</mime-type>
|
||||||
<mime-type>image/x-raw-olympus</mime-type>
|
<mime-type>image/x-raw-olympus</mime-type>
|
||||||
<mime-type>image/x-raw-pentax</mime-type>
|
<mime-type>image/x-raw-pentax</mime-type>
|
||||||
<mime-type>image/png</mime-type>
|
<mime-type>image/png</mime-type>
|
||||||
<mime-type>image/x-raw-fuji</mime-type>
|
<mime-type>image/x-raw-fuji</mime-type>
|
||||||
<mime-type>image/x-raw-panasonic</mime-type>
|
<mime-type>image/x-raw-panasonic</mime-type>
|
||||||
<mime-type>image/tiff</mime-type>
|
<mime-type>image/tiff</mime-type>
|
||||||
<mime-type>image/webp</mime-type>
|
<mime-type>image/webp</mime-type>
|
||||||
</mime-types>
|
</mime-types>
|
||||||
<metadata>
|
<metadata>
|
||||||
<!-- Default output-->
|
<!-- Default output-->
|
||||||
<match>\s*([A-Za-z0-9/ \(\)]+\S{1})\s+:\s+([A-Za-z0-9\(\)\[\] \:\-\.]+)\s*</match>
|
<match>\s*([A-Za-z0-9/ \(\)]+\S{1})\s+:\s+([A-Za-z0-9\(\)\[\] \:\-\.]+)\s*</match>
|
||||||
<!-- args format-->
|
<!-- args format-->
|
||||||
<match>^-([\S]+)\=(.*)</match>
|
<match>^-([\S]+)\=(.*)</match>
|
||||||
</metadata>
|
</metadata>
|
||||||
</parser>
|
</parser>
|
||||||
</external-parsers>
|
</external-parsers>
|
||||||
|
@@ -1,126 +1,126 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.executors;
|
package org.alfresco.transformer.executors;
|
||||||
|
|
||||||
import static org.alfresco.transformer.executors.Tika.NOT_EXTRACT_BOOKMARKS_TEXT;
|
import static org.alfresco.transformer.executors.Tika.NOT_EXTRACT_BOOKMARKS_TEXT;
|
||||||
import static org.alfresco.transformer.executors.Tika.TARGET_ENCODING;
|
import static org.alfresco.transformer.executors.Tika.TARGET_ENCODING;
|
||||||
import static org.alfresco.transformer.executors.Tika.TARGET_MIMETYPE;
|
import static org.alfresco.transformer.executors.Tika.TARGET_MIMETYPE;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.clearInvocations;
|
import static org.mockito.Mockito.clearInvocations;
|
||||||
import static org.mockito.Mockito.lenient;
|
import static org.mockito.Mockito.lenient;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class TikaJavaExecutorTest {
|
public class TikaJavaExecutorTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotExtractBookmarkTextDefault() throws Exception
|
public void testNotExtractBookmarkTextDefault() throws Exception
|
||||||
{
|
{
|
||||||
TikaJavaExecutor executorSpyDefaultTrue = spy(new TikaJavaExecutor(true));
|
TikaJavaExecutor executorSpyDefaultTrue = spy(new TikaJavaExecutor(true));
|
||||||
TikaJavaExecutor executorSpyDefaultFalse = spy(new TikaJavaExecutor(false));
|
TikaJavaExecutor executorSpyDefaultFalse = spy(new TikaJavaExecutor(false));
|
||||||
|
|
||||||
File mockSourceFile = mock(File.class);
|
File mockSourceFile = mock(File.class);
|
||||||
File mockTargetFile = mock(File.class);
|
File mockTargetFile = mock(File.class);
|
||||||
String transformName = "transformName";
|
String transformName = "transformName";
|
||||||
String sourceMimetype = "sourceMimetype";
|
String sourceMimetype = "sourceMimetype";
|
||||||
String targetMimetype = "targetMimetype";
|
String targetMimetype = "targetMimetype";
|
||||||
String defaultEncoding = "UTF-8";
|
String defaultEncoding = "UTF-8";
|
||||||
|
|
||||||
// no need to continue execution passed here or check values as we're checking the correct params passed to this method later.
|
// no need to continue execution passed here or check values as we're checking the correct params passed to this method later.
|
||||||
lenient().doNothing().when(executorSpyDefaultTrue).call(any(), any(), any(), any(), any(), any(), any());
|
lenient().doNothing().when(executorSpyDefaultTrue).call(any(), any(), any(), any(), any(), any(), any());
|
||||||
lenient().doNothing().when(executorSpyDefaultFalse).call(any(), any(), any(), any(), any(), any(), any());
|
lenient().doNothing().when(executorSpyDefaultFalse).call(any(), any(), any(), any(), any(), any(), any());
|
||||||
|
|
||||||
Map<String, String> transformOptions = new HashMap<String,String>();
|
Map<String, String> transformOptions = new HashMap<String,String>();
|
||||||
|
|
||||||
// use empty transformOptions to test defaults
|
// use empty transformOptions to test defaults
|
||||||
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
||||||
mockSourceFile, mockTargetFile);
|
mockSourceFile, mockTargetFile);
|
||||||
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
||||||
mockSourceFile, mockTargetFile);
|
mockSourceFile, mockTargetFile);
|
||||||
|
|
||||||
// when default set to true, with no options passed we should get a call method with NOT_EXTRACT_BOOKMARKS_TEXT
|
// when default set to true, with no options passed we should get a call method with NOT_EXTRACT_BOOKMARKS_TEXT
|
||||||
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
||||||
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
// when default set to false, with no options passed we should get a call method without NOT_EXTRACT_BOOKMARKS_TEXT
|
// when default set to false, with no options passed we should get a call method without NOT_EXTRACT_BOOKMARKS_TEXT
|
||||||
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
||||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
// use transforms with notExtractBookmarksText set to true
|
// use transforms with notExtractBookmarksText set to true
|
||||||
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
||||||
transformOptions.put("notExtractBookmarksText", "true");
|
transformOptions.put("notExtractBookmarksText", "true");
|
||||||
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
||||||
mockSourceFile, mockTargetFile);
|
mockSourceFile, mockTargetFile);
|
||||||
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions,
|
||||||
mockSourceFile, mockTargetFile);
|
mockSourceFile, mockTargetFile);
|
||||||
|
|
||||||
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT
|
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT
|
||||||
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
||||||
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null,
|
||||||
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
NOT_EXTRACT_BOOKMARKS_TEXT, TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
// use transforms with notExtractBookmarksText set to false
|
// use transforms with notExtractBookmarksText set to false
|
||||||
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
||||||
transformOptions.replace("notExtractBookmarksText", "true", "false");
|
transformOptions.replace("notExtractBookmarksText", "true", "false");
|
||||||
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
||||||
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
||||||
|
|
||||||
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT
|
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT
|
||||||
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
||||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
||||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + defaultEncoding);
|
||||||
|
|
||||||
// use full set of pdfbox transformOptions just to be safe
|
// use full set of pdfbox transformOptions just to be safe
|
||||||
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
clearInvocations(executorSpyDefaultTrue, executorSpyDefaultFalse);
|
||||||
transformOptions.put("targetEncoding", "anyEncoding");
|
transformOptions.put("targetEncoding", "anyEncoding");
|
||||||
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
executorSpyDefaultTrue.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
||||||
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
executorSpyDefaultFalse.transform(transformName, sourceMimetype, targetMimetype, transformOptions, mockSourceFile, mockTargetFile);
|
||||||
|
|
||||||
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT but the encoding will change
|
// both call methods should have NOT_EXTRACT_BOOKMARKS_TEXT but the encoding will change
|
||||||
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
verify(executorSpyDefaultTrue, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
||||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + "anyEncoding");
|
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + "anyEncoding");
|
||||||
|
|
||||||
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
verify(executorSpyDefaultFalse, times(1)).call(mockSourceFile, mockTargetFile, transformName, null, null,
|
||||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + "anyEncoding");
|
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + "anyEncoding");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,59 +1,59 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.tika.parsers;
|
package org.alfresco.transformer.tika.parsers;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ExifToolParserTest {
|
public class ExifToolParserTest {
|
||||||
|
|
||||||
ExifToolParser exifToolParser = new ExifToolParser();
|
ExifToolParser exifToolParser = new ExifToolParser();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindSeparator() {
|
public void testFindSeparator() {
|
||||||
|
|
||||||
String testCommand = "env FOO=${OUTPUT} exiftool -args -G1 " + ExifToolParser.SEPARATOR_SETTING
|
String testCommand = "env FOO=${OUTPUT} exiftool -args -G1 " + ExifToolParser.SEPARATOR_SETTING
|
||||||
+ " \"|||\" ${INPUT}";
|
+ " \"|||\" ${INPUT}";
|
||||||
String expected = "|||";
|
String expected = "|||";
|
||||||
String actual = exifToolParser.findSeparator(testCommand);
|
String actual = exifToolParser.findSeparator(testCommand);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
|
|
||||||
expected = "TESTWITHOUTQUOTES";
|
expected = "TESTWITHOUTQUOTES";
|
||||||
testCommand = "nothing matters until the " + ExifToolParser.SEPARATOR_SETTING + " " + expected
|
testCommand = "nothing matters until the " + ExifToolParser.SEPARATOR_SETTING + " " + expected
|
||||||
+ " now all this extra should be ignored";
|
+ " now all this extra should be ignored";
|
||||||
actual = exifToolParser.findSeparator(testCommand);
|
actual = exifToolParser.findSeparator(testCommand);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
|
|
||||||
expected = "Test something bonkers 112!£$%^£$^";
|
expected = "Test something bonkers 112!£$%^£$^";
|
||||||
testCommand = ExifToolParser.SEPARATOR_SETTING + " \""+expected+"\"";
|
testCommand = ExifToolParser.SEPARATOR_SETTING + " \""+expected+"\"";
|
||||||
actual = exifToolParser.findSeparator(testCommand);
|
actual = exifToolParser.findSeparator(testCommand);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,50 +1,50 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* Alfresco Transform Core
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
* -
|
* -
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* -
|
* -
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
* -
|
* -
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.util;
|
package org.alfresco.transformer.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the list of transform options with historic request parameters or 'extra' parameters used in testing
|
* Extends the list of transform options with historic request parameters or 'extra' parameters used in testing
|
||||||
* or communication in the all-in-one transformer.
|
* or communication in the all-in-one transformer.
|
||||||
*/
|
*/
|
||||||
public interface RequestParamMap extends org.alfresco.transform.client.util.RequestParamMap
|
public interface RequestParamMap extends org.alfresco.transform.client.util.RequestParamMap
|
||||||
{
|
{
|
||||||
// This property can be sent by acs repository's legacy transformers to force a transform,
|
// This property can be sent by acs repository's legacy transformers to force a transform,
|
||||||
// instead of letting this T-Engine determine it based on the request parameters.
|
// instead of letting this T-Engine determine it based on the request parameters.
|
||||||
// This allows clients to specify transform names as they appear in the engine config files, for example:
|
// This allows clients to specify transform names as they appear in the engine config files, for example:
|
||||||
// imagemagick, libreoffice, PdfBox, TikaAuto, ....
|
// imagemagick, libreoffice, PdfBox, TikaAuto, ....
|
||||||
// See ATS-731.
|
// See ATS-731.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
String TRANSFORM_NAME_PROPERTY = "transformName";
|
String TRANSFORM_NAME_PROPERTY = "transformName";
|
||||||
String TRANSFORM_NAME_PARAMETER = "alfresco.transform-name-parameter";
|
String TRANSFORM_NAME_PARAMETER = "alfresco.transform-name-parameter";
|
||||||
|
|
||||||
String FILE = "file";
|
String FILE = "file";
|
||||||
String SOURCE_EXTENSION = "sourceExtension";
|
String SOURCE_EXTENSION = "sourceExtension";
|
||||||
String SOURCE_MIMETYPE = "sourceMimetype";
|
String SOURCE_MIMETYPE = "sourceMimetype";
|
||||||
String TARGET_EXTENSION = "targetExtension";
|
String TARGET_EXTENSION = "targetExtension";
|
||||||
String TARGET_MIMETYPE = "targetMimetype";
|
String TARGET_MIMETYPE = "targetMimetype";
|
||||||
String TEST_DELAY = "testDelay";
|
String TEST_DELAY = "testDelay";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user