mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-10-01 14:41:17 +00:00
Save point: [skip ci]
* pick up alfresco-t-engine-base in 5 base t-engines * Switch over to using new base * Moved files in 5 base t-engines so we can remove the -boot package in the next round of changes
This commit is contained in:
@@ -20,12 +20,12 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>tests</classifier>
|
||||
<type>test-jar</type>
|
||||
|
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.misc;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.alfresco.transform.misc.SelectingTransformer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class Application
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Value("${container.name}")
|
||||
private String containerName;
|
||||
|
||||
@Bean
|
||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||
{
|
||||
return registry -> registry.config().commonTags("containerName", containerName);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void startup()
|
||||
{
|
||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||
Arrays.stream(SelectingTransformer.LICENCE.split("\\n")).forEach(logger::info);
|
||||
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
|
||||
logger.info("Starting application components... Done");
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.misc;
|
||||
|
||||
import org.alfresco.transformer.AbstractTransformerController;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.alfresco.transform.misc.transformers.SelectingTransformer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_HTML;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
||||
|
||||
@Controller
|
||||
public class MiscController extends AbstractTransformerController
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MiscController.class);
|
||||
|
||||
private SelectingTransformer transformer = new SelectingTransformer();
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "Miscellaneous Transformers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String version()
|
||||
{
|
||||
return getTransformerName() + " available";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbeTestTransform getProbeTestTransform()
|
||||
{
|
||||
// HtmlParserContentTransformer html -> text
|
||||
// See the Javadoc on this method and Probes.md for the choice of these values.
|
||||
return new ProbeTestTransform(this, "quick.html", "quick.txt",
|
||||
119, 30, 150, 1024,
|
||||
60 * 2 + 1, 60 * 2)
|
||||
{
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||
transformImpl("html", MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, parameters, sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
transformer.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
@@ -26,53 +26,59 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.alfresco.transform.base.logging.StandardMessages.COMMUNITY_LICENCE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_HTML;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
|
||||
@Component
|
||||
public class MiscTransformEngine implements TransformEngine
|
||||
{
|
||||
private static final String LICENCE =
|
||||
"This transformer uses Tika from Apache. See the license at http://www.apache.org/licenses/LICENSE-2.0. or in /Apache\\ 2.0.txt\n" +
|
||||
"This transformer uses ExifTool by Phil Harvey. See license at https://exiftool.org/#license. or in /Perl-Artistic-License.txt";
|
||||
private final Map<String, String> transformOptions = ImmutableMap.of(SOURCE_ENCODING, "UTF-8");
|
||||
|
||||
@Autowired
|
||||
private TransformConfigResourceReader transformConfigResourceReader;
|
||||
@Value("${transform.core.config.location:classpath:engine_config.json}")
|
||||
private String engineConfigLocation;
|
||||
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0001-Tika";
|
||||
return "0050-Misc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartupMessage() {
|
||||
return LICENCE;
|
||||
public String getStartupMessage()
|
||||
{
|
||||
return COMMUNITY_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" +
|
||||
"Additional libraries used:\n" +
|
||||
"* htmlparser http://htmlparser.sourceforge.net/license.html";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformConfig getTransformConfig()
|
||||
{
|
||||
return transformConfigResourceReader.read(engineConfigLocation);
|
||||
return transformConfigResourceReader.read("classpath:misc_engine_config.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
||||
{
|
||||
return new ProbeTestTransform("quick.pdf", "quick.txt",
|
||||
MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
||||
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||
return new ProbeTestTransform("quick.html", "quick.txt",
|
||||
MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, transformOptions,
|
||||
119, 30, 150, 1024, 60 * 2 + 1, 60 * 2);
|
||||
}
|
||||
}
|
||||
|
@@ -24,9 +24,11 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transformer.metadataExtractors;
|
||||
package org.alfresco.transform.misc.metadataExtractors;
|
||||
|
||||
import org.alfresco.transform.misc.transformers.SelectableTransformer;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.base.metadataExtractors.AbstractMetadataExtractor;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -39,11 +41,14 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.alfresco.transform.base.metadataExtractors.AbstractMetadataExtractor.Type.EXTRACTOR;
|
||||
|
||||
/**
|
||||
* Metadata extractor for HTML and XHTML.
|
||||
*
|
||||
@@ -61,7 +66,7 @@ import java.util.Map;
|
||||
* @author Derek Hulley
|
||||
* @author adavis
|
||||
*/
|
||||
public class HtmlMetadataExtractor extends AbstractMetadataExtractor implements SelectableTransformer
|
||||
public class HtmlMetadataExtractor extends AbstractMetadataExtractor implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HtmlMetadataExtractor.class);
|
||||
|
||||
@@ -71,10 +76,22 @@ public class HtmlMetadataExtractor extends AbstractMetadataExtractor implements
|
||||
|
||||
public HtmlMetadataExtractor()
|
||||
{
|
||||
super(logger);
|
||||
super(EXTRACTOR, logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO HtmlMetadataExtractor transform");
|
||||
}
|
||||
|
||||
public void extractMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -24,9 +24,11 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transformer.metadataExtractors;
|
||||
package org.alfresco.transform.misc.metadataExtractors;
|
||||
|
||||
import org.alfresco.transform.misc.transformers.SelectableTransformer;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.base.metadataExtractors.AbstractMetadataExtractor;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -38,6 +40,7 @@ import javax.mail.internet.MimeUtility;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
@@ -46,6 +49,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.alfresco.transform.base.metadataExtractors.AbstractMetadataExtractor.Type.EXTRACTOR;
|
||||
|
||||
/**
|
||||
* Metadata extractor for RFC822 mime emails.
|
||||
*
|
||||
@@ -66,9 +71,9 @@ import java.util.Set;
|
||||
* @author Derek Hulley
|
||||
* @author adavis
|
||||
*/
|
||||
public class RFC822MetadataExtractor extends AbstractMetadataExtractor implements SelectableTransformer
|
||||
public class RFC822MetadataExtractor extends AbstractMetadataExtractor implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HtmlMetadataExtractor.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(RFC822MetadataExtractor.class);
|
||||
|
||||
protected static final String KEY_MESSAGE_FROM = "messageFrom";
|
||||
protected static final String KEY_MESSAGE_TO = "messageTo";
|
||||
@@ -79,10 +84,16 @@ public class RFC822MetadataExtractor extends AbstractMetadataExtractor implement
|
||||
|
||||
public RFC822MetadataExtractor()
|
||||
{
|
||||
super(logger);
|
||||
super(EXTRACTOR, logger);
|
||||
}
|
||||
|
||||
@Override public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO RFC822MetadataExtractor transform");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -27,15 +27,20 @@
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
@@ -58,7 +63,8 @@ import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||
* @author eknizat
|
||||
* @since 4.0
|
||||
*/
|
||||
public class AppleIWorksContentTransformer implements SelectableTransformer
|
||||
@Component
|
||||
public class AppleIWorksContentTransformer implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(
|
||||
AppleIWorksContentTransformer.class);
|
||||
@@ -69,10 +75,22 @@ public class AppleIWorksContentTransformer implements SelectableTransformer
|
||||
private static final List<String> JPG_PATHS = ImmutableList.of(
|
||||
"QuickLook/Thumbnail.jpg", // iWorks 2008/9
|
||||
"preview.jpg"); // iWorks 2013/14 (720 x 552) We use the best quality image. Others are:
|
||||
// (225 x 173) preview-web.jpg
|
||||
// (53 x 41) preview-micro.jpg
|
||||
// (225 x 173) preview-web.jpg
|
||||
// (53 x 41) preview-micro.jpg
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "appleIWorks";
|
||||
}
|
||||
|
||||
@Override public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO appleIWorks transform");
|
||||
}
|
||||
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile)
|
||||
{
|
||||
|
@@ -26,9 +26,12 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import org.alfresco.transformer.fs.FileManager;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.base.fs.FileManager;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
@@ -43,6 +46,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
@@ -64,8 +68,8 @@ import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||
* </p>
|
||||
*/
|
||||
public class EMLTransformer implements SelectableTransformer
|
||||
|
||||
@Component
|
||||
public class EMLTransformer implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(EMLTransformer.class);
|
||||
|
||||
@@ -73,6 +77,18 @@ public class EMLTransformer implements SelectableTransformer
|
||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "rfc822";
|
||||
}
|
||||
|
||||
@Override public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO rfc822 transform");
|
||||
}
|
||||
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -26,15 +26,20 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.htmlparser.Parser;
|
||||
import org.htmlparser.beans.StringBean;
|
||||
import org.htmlparser.util.ParserException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URLConnection;
|
||||
@@ -71,12 +76,26 @@ import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
* @see org.htmlparser.beans.StringBean
|
||||
* @see <a href="http://sourceforge.net/tracker/?func=detail&aid=1644504&group_id=24399&atid=381401">HTML Parser</a>
|
||||
*/
|
||||
public class HtmlParserContentTransformer implements SelectableTransformer
|
||||
@Component
|
||||
public class HtmlParserContentTransformer implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(
|
||||
HtmlParserContentTransformer.class);
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "html";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO html transform");
|
||||
}
|
||||
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -26,6 +26,8 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||
@@ -33,10 +35,12 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Map;
|
||||
@@ -53,12 +57,25 @@ import java.util.Map;
|
||||
* @author Nick Burch
|
||||
* @author eknizat
|
||||
*/
|
||||
public class OOXMLThumbnailContentTransformer implements SelectableTransformer
|
||||
@Component
|
||||
public class OOXMLThumbnailContentTransformer implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(
|
||||
OOXMLThumbnailContentTransformer.class);
|
||||
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "ooXmlThumbnail";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO ooXmlThumbnail transform");
|
||||
}
|
||||
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implemented by transformers used by {@link SelectingTransformer}.
|
||||
*
|
||||
* @author eknizat
|
||||
*/
|
||||
public interface SelectableTransformer
|
||||
{
|
||||
default void transform(String sourceMimetype, String targetMimetype, Map<String, String> parameters,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
default void extractMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
default void embedMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Core
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transformer.executors.Transformer;
|
||||
import org.alfresco.transformer.logging.LogEntry;
|
||||
import org.alfresco.transformer.metadataExtractors.HtmlMetadataExtractor;
|
||||
import org.alfresco.transformer.metadataExtractors.RFC822MetadataExtractor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
|
||||
|
||||
/**
|
||||
* The SelectingTransformer selects a registered {@link SelectableTransformer}
|
||||
* and delegates the transformation to its implementation.
|
||||
*
|
||||
* @author eknizat
|
||||
*/
|
||||
public class SelectingTransformer implements Transformer
|
||||
{
|
||||
private static final String ID = "misc";
|
||||
|
||||
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" +
|
||||
"Additional libraries used:\n" +
|
||||
"* htmlparser http://htmlparser.sourceforge.net/license.html";
|
||||
|
||||
private final Map<String, SelectableTransformer> transformers = ImmutableMap
|
||||
.<String, SelectableTransformer>builder()
|
||||
.put("appleIWorks", new AppleIWorksContentTransformer())
|
||||
.put("html", new HtmlParserContentTransformer())
|
||||
.put("string", new StringExtractingContentTransformer())
|
||||
.put("textToPdf", new TextToPdfContentTransformer())
|
||||
.put("rfc822", new EMLTransformer())
|
||||
.put("ooXmlThumbnail", new OOXMLThumbnailContentTransformer())
|
||||
.put("HtmlMetadataExtractor", new HtmlMetadataExtractor())
|
||||
.put("RFC822MetadataExtractor", new RFC822MetadataExtractor())
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public String getTransformerId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
final SelectableTransformer transformer = transformers.get(transformName);
|
||||
logOptions(sourceFile, targetFile, transformOptions);
|
||||
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
||||
public void extractMetadata(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile) throws Exception
|
||||
{
|
||||
final SelectableTransformer transformer = transformers.get(transformName);
|
||||
logOptions(sourceFile, targetFile, transformOptions);
|
||||
transformer.extractMetadata(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
|
||||
private static void logOptions(File sourceFile, File targetFile, Map<String, String> parameters)
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(" ");
|
||||
parameters.forEach((k, v) ->
|
||||
{
|
||||
if (!TRANSFORM_NAME_PARAMETER.equals(k))
|
||||
{
|
||||
sj.add("--" + k + "=" + v);
|
||||
}
|
||||
}); // keeping the existing style used in other T-Engines
|
||||
sj.add(getExtension(sourceFile));
|
||||
sj.add(getExtension(targetFile));
|
||||
LogEntry.setOptions(sj.toString());
|
||||
}
|
||||
|
||||
private static String getExtension(File file)
|
||||
{
|
||||
final String name = file.getName();
|
||||
int i = name.lastIndexOf('.');
|
||||
return i == -1 ? "???" : name.substring(i + 1);
|
||||
}
|
||||
}
|
@@ -26,15 +26,20 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
@@ -58,11 +63,16 @@ import static org.alfresco.transform.common.RequestParamMap.TARGET_ENCODING;
|
||||
* @author Derek Hulley
|
||||
* @author eknizat
|
||||
*/
|
||||
public class StringExtractingContentTransformer implements SelectableTransformer
|
||||
@Component
|
||||
public class StringExtractingContentTransformer implements CustomTransformer
|
||||
{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(StringExtractingContentTransformer.class);
|
||||
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* Text to text conversions are done directly using the content reader and writer string
|
||||
* manipulation methods.
|
||||
@@ -72,6 +82,13 @@ public class StringExtractingContentTransformer implements SelectableTransformer
|
||||
* be unformatted but valid.
|
||||
*/
|
||||
@Override
|
||||
public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO string transform");
|
||||
}
|
||||
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -26,7 +26,8 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc.transformers;
|
||||
|
||||
import org.alfresco.transformer.util.RequestParamMap;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
@@ -34,6 +35,7 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||
import org.apache.pdfbox.tools.TextToPDF;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@@ -50,6 +52,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.alfresco.transform.common.RequestParamMap.PAGE_LIMIT;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
|
||||
/**
|
||||
@@ -62,7 +65,8 @@ import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
* @author Derek Hulley
|
||||
* @author eknizat
|
||||
*/
|
||||
public class TextToPdfContentTransformer implements SelectableTransformer
|
||||
@Component
|
||||
public class TextToPdfContentTransformer implements CustomTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(TextToPdfContentTransformer.class);
|
||||
|
||||
@@ -70,8 +74,6 @@ public class TextToPdfContentTransformer implements SelectableTransformer
|
||||
private static final byte FE = (byte) 0xFE;
|
||||
private static final byte FF = (byte) 0xFF;
|
||||
|
||||
public static final String PAGE_LIMIT = RequestParamMap.PAGE_LIMIT;
|
||||
|
||||
private final PagedTextToPDF transformer;
|
||||
|
||||
public TextToPdfContentTransformer()
|
||||
@@ -106,6 +108,17 @@ public class TextToPdfContentTransformer implements SelectableTransformer
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "textToPdf";
|
||||
}
|
||||
|
||||
@Override public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO textToPdf transform");
|
||||
}
|
||||
public void transform(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
|
||||
final File sourceFile, final File targetFile) throws Exception
|
||||
{
|
||||
|
@@ -2,6 +2,4 @@ queue:
|
||||
engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.misc.acs}
|
||||
transform:
|
||||
core:
|
||||
version: @project.version@
|
||||
config:
|
||||
location: classpath:misc_engine_config.json
|
||||
version: @project.version@
|
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.transform.misc;
|
||||
|
||||
import org.alfresco.transformer.AbstractHttpRequestTest;
|
||||
import org.alfresco.transform.base.AbstractHttpRequestTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
@@ -43,8 +43,8 @@ import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.alfresco.transformer.util.RequestParamMap.PAGE_LIMIT;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING;
|
||||
import static org.alfresco.transform.common.RequestParamMap.PAGE_LIMIT;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TextToPdfContentTransformerTest
|
||||
|
Reference in New Issue
Block a user