REPO-4615 T Engine - add sourceNodeRef parameter (#558)

This commit is contained in:
alandavis
2019-08-13 11:58:19 +01:00
committed by GitHub
parent f7029adcd1
commit 3640774d68
5 changed files with 64 additions and 51 deletions

View File

@@ -35,6 +35,8 @@ import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
/** /**
* Content transformer which wraps the HTML Parser library for * Content transformer which wraps the HTML Parser library for
@@ -138,6 +140,6 @@ public class HtmlParserContentTransformer extends AbstractRemoteContentTransform
timeoutMs, logger, timeoutMs, logger,
"sourceMimetype", sourceMimetype, "sourceMimetype", sourceMimetype,
"targetMimetype", targetMimetype, "targetMimetype", targetMimetype,
"sourceEncoding", sourceEncoding); SOURCE_ENCODING, sourceEncoding);
} }
} }

View File

@@ -32,9 +32,13 @@ import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_NODE_REF;
/** /**
* A local transformer using flat transform options. * A local transformer using flat transform options.
* *
@@ -138,18 +142,19 @@ public class LocalTransformImpl extends AbstractLocalTransform
String sourceMimetype, String targetMimetype, String sourceMimetype, String targetMimetype,
String sourceExtension, String targetExtension, String sourceExtension, String targetExtension,
String renditionName, NodeRef sourceNodeRef) throws Exception String renditionName, NodeRef sourceNodeRef) throws Exception
{
boolean removeSourceEncoding = false;
try
{ {
// At some point in the future, we may decide to only pass the sourceEncoding and other dynamic values like // At some point in the future, we may decide to only pass the sourceEncoding and other dynamic values like
// it if they were supplied in the rendition definition without a value. The sourceEncoding value is also // it if they were supplied in the rendition definition without a value. The sourceEncoding value is also
// supplied in the TransformRequest (message to the T-Router). // supplied in the TransformRequest (message to the T-Router).
if (transformOptions.get("sourceEncoding") == null) transformOptions = new HashMap<>(transformOptions);
if (transformOptions.get(SOURCE_ENCODING) == null)
{ {
String sourceEncoding = reader.getEncoding(); String sourceEncoding = reader.getEncoding();
transformOptions.put("sourceEncoding", sourceEncoding); transformOptions.put(SOURCE_ENCODING, sourceEncoding);
removeSourceEncoding = true; }
if (transformOptions.containsKey(SOURCE_NODE_REF) && transformOptions.get(SOURCE_NODE_REF) == null)
{
transformOptions.put(SOURCE_NODE_REF, sourceNodeRef.toString());
} }
// Build an array of option names and values and extract the timeout. // Build an array of option names and values and extract the timeout.
@@ -189,12 +194,4 @@ public class LocalTransformImpl extends AbstractLocalTransform
remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension, remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
timeoutMs, log, args); timeoutMs, log, args);
} }
finally
{
if (removeSourceEncoding)
{
transformOptions.remove("sourceEncoding");
}
}
}
} }

View File

@@ -37,6 +37,8 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
/** /**
* Converts any textual format to plain text. * Converts any textual format to plain text.
* <p> * <p>
@@ -184,7 +186,7 @@ public class StringExtractingContentTransformer extends AbstractRemoteContentTra
timeoutMs, logger, timeoutMs, logger,
"sourceMimetype", sourceMimetype, "sourceMimetype", sourceMimetype,
"targetMimetype", targetMimetype, "targetMimetype", targetMimetype,
"sourceEncoding", sourceEncoding, SOURCE_ENCODING, sourceEncoding,
"targetEncoding", targetEncoding); "targetEncoding", targetEncoding);
} }

View File

@@ -50,6 +50,9 @@ import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
/** /**
* 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.
* *
@@ -192,7 +195,7 @@ public class TextToPdfContentTransformer extends AbstractRemoteContentTransforme
timeoutMs, logger, timeoutMs, logger,
"sourceMimetype", sourceMimetype, "sourceMimetype", sourceMimetype,
"targetMimetype", targetMimetype, "targetMimetype", targetMimetype,
"sourceEncoding", sourceEncoding, SOURCE_ENCODING, sourceEncoding,
"pageLimit", String.valueOf(pageLimit)); "pageLimit", String.valueOf(pageLimit));
} }

View File

@@ -100,6 +100,15 @@ public interface RenditionDefinition2
@Deprecated @Deprecated
String FLASH_VERSION = "flashVersion"; String FLASH_VERSION = "flashVersion";
/**
* The encoding of a Source Node is automatically added to the Transform Options if not specified.
*/
public static final String SOURCE_ENCODING = "sourceEncoding";
/**
* The Source Node Ref is automatically added to the Transform Options if specified but without a value.
*/
public static final String SOURCE_NODE_REF = "sourceNodeRef";
String getRenditionName(); String getRenditionName();