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.LogFactory;
import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
/**
* Content transformer which wraps the HTML Parser library for
@@ -138,6 +140,6 @@ public class HtmlParserContentTransformer extends AbstractRemoteContentTransform
timeoutMs, logger,
"sourceMimetype", sourceMimetype,
"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.util.Pair;
import java.util.HashMap;
import java.util.Map;
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.
*
@@ -139,62 +143,55 @@ public class LocalTransformImpl extends AbstractLocalTransform
String sourceExtension, String targetExtension,
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
// 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).
transformOptions = new HashMap<>(transformOptions);
if (transformOptions.get(SOURCE_ENCODING) == null)
{
// 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
// supplied in the TransformRequest (message to the T-Router).
if (transformOptions.get("sourceEncoding") == null)
{
String sourceEncoding = reader.getEncoding();
transformOptions.put("sourceEncoding", sourceEncoding);
removeSourceEncoding = true;
}
String sourceEncoding = reader.getEncoding();
transformOptions.put(SOURCE_ENCODING, sourceEncoding);
}
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.
long timeoutMs = 0;
int nonOptions = transformOptions.containsKey(RenditionDefinition2.TIMEOUT) ? 1 : 0;
int size = (transformOptions.size() - nonOptions + 3) * 2;
String[] args = new String[size];
int i = 0;
for (Map.Entry<String, String> option : transformOptions.entrySet())
// Build an array of option names and values and extract the timeout.
long timeoutMs = 0;
int nonOptions = transformOptions.containsKey(RenditionDefinition2.TIMEOUT) ? 1 : 0;
int size = (transformOptions.size() - nonOptions + 3) * 2;
String[] args = new String[size];
int i = 0;
for (Map.Entry<String, String> option : transformOptions.entrySet())
{
String name = option.getKey();
String value = option.getValue();
if (RenditionDefinition2.TIMEOUT.equals(name))
{
String name = option.getKey();
String value = option.getValue();
if (RenditionDefinition2.TIMEOUT.equals(name))
if (value != null)
{
if (value != null)
{
timeoutMs = Long.parseLong(value);
}
}
else
{
args[i++] = name;
args[i++] = value;
timeoutMs = Long.parseLong(value);
}
}
// These 3 values are commonly needed and are always supplied in the TransformRequest (message to the T-Router).
// The targetExtension is also supplied in the TransformRequest, but in the case of local and legacy transformers
// is added by the remoteTransformerClient.request call for historic reasons, so does not need to be added here.
args[i++] = "sourceMimetype";
args[i++] = sourceMimetype;
args[i++] = "sourceExtension";
args[i++] = sourceExtension;
args[i++] = "targetMimetype";
args[i++] = targetMimetype;
remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
timeoutMs, log, args);
}
finally
{
if (removeSourceEncoding)
else
{
transformOptions.remove("sourceEncoding");
args[i++] = name;
args[i++] = value;
}
}
// These 3 values are commonly needed and are always supplied in the TransformRequest (message to the T-Router).
// The targetExtension is also supplied in the TransformRequest, but in the case of local and legacy transformers
// is added by the remoteTransformerClient.request call for historic reasons, so does not need to be added here.
args[i++] = "sourceMimetype";
args[i++] = sourceMimetype;
args[i++] = "sourceExtension";
args[i++] = sourceExtension;
args[i++] = "targetMimetype";
args[i++] = targetMimetype;
remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
timeoutMs, log, args);
}
}

View File

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

View File

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

View File

@@ -100,6 +100,15 @@ public interface RenditionDefinition2
@Deprecated
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();