Search in sources :

Example 21 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TextToPdfContentTransformer method transformRemote.

@Override
protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension, String targetEncoding) throws Exception {
    String sourceEncoding = reader.getEncoding();
    long timeoutMs = options.getTimeoutMs();
    TransformationOptionLimits limits = getLimits(reader, writer, options);
    TransformationOptionPair pageLimits = limits.getPagesPair();
    int pageLimit = (int) pageLimits.getValue();
    remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension, timeoutMs, logger, "transformName", "textToPdf", "sourceMimetype", sourceMimetype, "targetMimetype", targetMimetype, "targetExtension", targetExtension, SOURCE_ENCODING, sourceEncoding, "pageLimit", String.valueOf(pageLimit));
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) TransformationOptionPair(org.alfresco.service.cmr.repository.TransformationOptionPair)

Example 22 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class ProxyContentTransformer method transformInternal.

protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception {
    TransformationOptionLimits original = options.getLimits();
    try {
        // Combine the transformer's limit values into the options so they are available to the worker
        options.setLimits(getLimits(reader, writer, options));
        // Perform the transformation
        this.worker.transform(reader, writer, options);
    } finally {
        options.setLimits(original);
    }
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits)

Example 23 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimits method newTransformationOptionLimits.

/**
 * Creates a new TransformationOptionLimits for the use, transformer and mimetype combination,
 * defaulting values from lower levels.
 * @param wildCardLimits if not null this is a limit found using a wildcard so should
 *        form the basis of the new object.
 */
private TransformationOptionLimits newTransformationOptionLimits(String transformerName, String sourceMimetype, String targetMimetype, TransformationOptionLimits wildCardLimits, String use) {
    int origLevel = getLevel(transformerName, sourceMimetype);
    TransformationOptionLimits limits = new TransformationOptionLimits();
    // defaults from the most general get used if there is not something more specific.
    for (int level = 0; level < origLevel; level++) {
        TransformationOptionLimits defaultLimits = level < 2 ? level == 0 ? // 0
        getOrCreateTransformerOptionLimits(DEFAULT_TRANSFORMER, ANY, ANY, use) : // 1
        getOrCreateTransformerOptionLimits(DEFAULT_TRANSFORMER, sourceMimetype, targetMimetype, use) : level == 2 ? // 2
        getOrCreateTransformerOptionLimits(transformerName, ANY, ANY, use) : // 3
        getOrCreateTransformerOptionLimits(transformerName, sourceMimetype, targetMimetype, use);
        defaultLimits.defaultTo(limits);
    }
    if (wildCardLimits != null) {
        wildCardLimits.defaultTo(limits);
    }
    debug("N", transformerName, sourceMimetype, targetMimetype, use, limits);
    return limits;
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits)

Example 24 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimits method getLimits.

/**
 * See {@link TransformerConfig#getLimits(ContentTransformer, String, String, String)}.
 */
public TransformationOptionLimits getLimits(ContentTransformer transformer, String sourceMimetype, String targetMimetype, String use) {
    String transformerName = (transformer == null) ? DEFAULT_TRANSFORMER : transformer.getName();
    if (sourceMimetype == null) {
        sourceMimetype = ANY;
    }
    if (targetMimetype == null) {
        targetMimetype = ANY;
    }
    if (use == null) {
        use = ANY;
    }
    debug(null, transformerName, sourceMimetype, targetMimetype, use, null);
    String searchUse = uses.contains(use) ? use : ANY;
    TransformationOptionLimits limits = getOrCreateTransformerOptionLimits(transformerName, sourceMimetype, targetMimetype, searchUse);
    debug("S", transformerName, sourceMimetype, targetMimetype, use, limits);
    return limits;
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits)

Example 25 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimits method getOrCreateTransformerOptionLimits.

/**
 * Returns the TransformationOptionLimits for the use, transformer and mimetype combination,
 * creating and adding one if not already included.
 */
private TransformationOptionLimits getOrCreateTransformerOptionLimits(String transformerName, String sourceMimetype, String targetMimetype, String use) {
    Map<String, DoubleMap<String, String, TransformationOptionLimits>> transformerLimits = limitsMap.get(use);
    if (transformerLimits == null) {
        transformerLimits = new ConcurrentHashMap<String, DoubleMap<String, String, TransformationOptionLimits>>();
        limitsMap.put(use, transformerLimits);
    }
    DoubleMap<String, String, TransformationOptionLimits> mimetypeLimits = transformerLimits.get(transformerName);
    if (mimetypeLimits == null) {
        mimetypeLimits = new DoubleMap<String, String, TransformationOptionLimits>(ANY, ANY);
        transformerLimits.put(transformerName, mimetypeLimits);
    }
    TransformationOptionLimits limits = mimetypeLimits.getNoWildcards(sourceMimetype, targetMimetype);
    if (limits == null) {
        // Try the wildcard version, and use any match as the basis for a new entry
        limits = mimetypeLimits.get(sourceMimetype, targetMimetype);
        limits = newTransformationOptionLimits(transformerName, sourceMimetype, targetMimetype, limits, use);
        mimetypeLimits.put(sourceMimetype, targetMimetype, limits);
    } else {
        debug("G", transformerName, sourceMimetype, targetMimetype, use, limits);
    }
    return limits;
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits)

Aggregations

TransformationOptionLimits (org.alfresco.service.cmr.repository.TransformationOptionLimits)39 Test (org.junit.Test)22 Map (java.util.Map)3 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)3 TimeoutException (java.util.concurrent.TimeoutException)2 AbstractContentReader (org.alfresco.repo.content.AbstractContentReader)2 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)2 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)2 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)2 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)2 TransformationOptionPair (org.alfresco.service.cmr.repository.TransformationOptionPair)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1