mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
REPO-4615 T Engine - add sourceNodeRef parameter (#558)
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
@@ -139,62 +143,55 @@ public class LocalTransformImpl extends AbstractLocalTransform
|
|||||||
String sourceExtension, String targetExtension,
|
String sourceExtension, String targetExtension,
|
||||||
String renditionName, NodeRef sourceNodeRef) throws Exception
|
String renditionName, NodeRef sourceNodeRef) throws Exception
|
||||||
{
|
{
|
||||||
boolean removeSourceEncoding = false;
|
// At some point in the future, we may decide to only pass the sourceEncoding and other dynamic values like
|
||||||
try
|
// 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
|
String sourceEncoding = reader.getEncoding();
|
||||||
// it if they were supplied in the rendition definition without a value. The sourceEncoding value is also
|
transformOptions.put(SOURCE_ENCODING, sourceEncoding);
|
||||||
// supplied in the TransformRequest (message to the T-Router).
|
}
|
||||||
if (transformOptions.get("sourceEncoding") == null)
|
if (transformOptions.containsKey(SOURCE_NODE_REF) && transformOptions.get(SOURCE_NODE_REF) == null)
|
||||||
{
|
{
|
||||||
String sourceEncoding = reader.getEncoding();
|
transformOptions.put(SOURCE_NODE_REF, sourceNodeRef.toString());
|
||||||
transformOptions.put("sourceEncoding", sourceEncoding);
|
}
|
||||||
removeSourceEncoding = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build an array of option names and values and extract the timeout.
|
// Build an array of option names and values and extract the timeout.
|
||||||
long timeoutMs = 0;
|
long timeoutMs = 0;
|
||||||
int nonOptions = transformOptions.containsKey(RenditionDefinition2.TIMEOUT) ? 1 : 0;
|
int nonOptions = transformOptions.containsKey(RenditionDefinition2.TIMEOUT) ? 1 : 0;
|
||||||
int size = (transformOptions.size() - nonOptions + 3) * 2;
|
int size = (transformOptions.size() - nonOptions + 3) * 2;
|
||||||
String[] args = new String[size];
|
String[] args = new String[size];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Map.Entry<String, String> option : transformOptions.entrySet())
|
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();
|
if (value != null)
|
||||||
String value = option.getValue();
|
|
||||||
if (RenditionDefinition2.TIMEOUT.equals(name))
|
|
||||||
{
|
{
|
||||||
if (value != null)
|
timeoutMs = Long.parseLong(value);
|
||||||
{
|
|
||||||
timeoutMs = Long.parseLong(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
args[i++] = name;
|
|
||||||
args[i++] = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user