diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index 9da13521b0..15252a49ba 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -318,24 +318,6 @@ - - - - - - - - - - - - - - - - - - - - - - + + class="org.alfresco.repo.content.transform.FailoverContentTransformer" + parent="baseContentTransformer" > + + + + + application/pdf + image/png + + + + application/pdf + application/eps + + + application/pdf + image/jp2 + + + application/pdf + image/cgm + + + application/pdf + image/gif + + + application/pdf + image/ief + + + application/pdf + image/bmp + + + application/pdf + image/jpeg + + + application/pdf + image/x-portable-bitmap + + + application/pdf + image/x-portable-graymap + + + application/pdf + image/x-portable-anymap + + + application/pdf + image/x-portable-pixmap + + + application/pdf + image/x-cmu-raster + + + application/pdf + image/tiff + + + application/pdf + image/x-xbitmap + + + application/pdf + image/x-xpixmap + + + application/pdf + image/x-xwindowdump + + + application/pdf + image/x-dwg + + + application/pdf + image/x-dwt + + + application/pdf image/jpeg - - application/pdf - image/png - application/pdf image/gif - - - - - - - - - image/png - - + + + + + + + + + + + + + + image/png + + + + + @@ -550,14 +612,6 @@ text/plain application/pdf - - text/csv - application/pdf - - - text/xml - application/pdf - ${content.transformer.PdfBox.TextToPdf.maxSourceSizeKBytes} @@ -819,6 +873,14 @@ + + + + application/pdf + image/png + + + diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 376f3d57e7..941b06c12f 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -478,4 +478,6 @@ patch.swsdpPatch.success=Successfully patched the Sample: Web Site Design Projec patch.swsdpPatch.skipped=Skipped, not required. patch.swsdpPatch.missingSurfConfig=surf-config folder is not present in Sample: Web Site Design Project. -patch.redeployParallelActivitiWorkflows.description=Patch that redeploys both parallel activiti workflows, completion-condition now takes into account if minimum approval percentage can still be achived. \ No newline at end of file +patch.redeployParallelActivitiWorkflows.description=Patch that redeploys both parallel activiti workflows, completion-condition now takes into account if minimum approval percentage can still be achived. + +patch.show.audit.success=show_audit.ftl was updated successfully diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 616ce2b65a..82bf1ff149 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -3233,4 +3233,25 @@ + + patch.show.audit + patch.show.audit.description + 0 + 6011 + 6012 + + + + + + + + + /${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.content.childname}/cm:show_audit.ftl + + + alfresco/templates/content/examples/show_audit.ftl + + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 4589071a8b..7d636c166b 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=6011 +version.schema=6012 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/UpdateAuditTemplatePatch.java b/source/java/org/alfresco/repo/admin/patch/impl/UpdateAuditTemplatePatch.java new file mode 100644 index 0000000000..ec4c898a8a --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/UpdateAuditTemplatePatch.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.io.InputStream; +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.importer.ImporterBootstrap; +import org.alfresco.service.cmr.admin.PatchException; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.springframework.extensions.surf.util.I18NUtil; + +/** + * Updates show_audit.ftl file for upgrade from v3.3.5 to v3.4.x (ALF-13929) + * @author alex.malinovsky + * + */ +public class UpdateAuditTemplatePatch extends AbstractPatch +{ + private static final String ERR_MULTIPLE_FOUND = "Multiple files for replacement were found"; + public static final String TEXT_CONTENT_MIMETYPE = "text/plain"; + private static final String MSG_CREATED = "patch.show.audit.success"; + + private ImporterBootstrap importerBootstrap; + private ContentService contentService; + private String copyPath; + private String fileName; + + + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + + public void setCopyPath(String copyPath) + { + this.copyPath = copyPath; + } + + public void setFileName(String fileName) + { + this.fileName = fileName; + } + + public void setImporterBootstrap(ImporterBootstrap importerBootstrap) + { + this.importerBootstrap = importerBootstrap; + } + + @Override + protected String applyInternal() throws Exception + { + StoreRef storeRef = importerBootstrap.getStoreRef(); + NodeRef rootNodeRef = nodeService.getRootNode(storeRef); + List results = searchService.selectNodes(rootNodeRef, copyPath, null, namespaceService, true); + if (results.size() > 1) + { + throw new PatchException(ERR_MULTIPLE_FOUND, copyPath); + } + else if (results.size() == 1) + { + makeCopy(results.get(0)); + return I18NUtil.getMessage(MSG_CREATED); + } + + + return null; + } + + private void makeCopy(NodeRef nodeRef) + { + InputStream resource = getClass().getClassLoader().getResourceAsStream(fileName); + if (resource != null) + { + ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); + writer.setEncoding("UTF-8"); + writer.setMimetype(TEXT_CONTENT_MIMETYPE); + writer.putContent(resource); + } + else throw new PatchException("Resource '"+fileName+"' not found"); + } + + +} diff --git a/source/java/org/alfresco/repo/content/ContentServiceImpl.java b/source/java/org/alfresco/repo/content/ContentServiceImpl.java index fc7bf530c7..1f88163b09 100644 --- a/source/java/org/alfresco/repo/content/ContentServiceImpl.java +++ b/source/java/org/alfresco/repo/content/ContentServiceImpl.java @@ -776,14 +776,16 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa MimetypeMap.MIMETYPE_IMAGE_PNG.equals(targetMimetype) && "debugTransformers.txt".equals(transformerDebug.getFileName(transformOptions, true, 0))) { - debugActiveTransformers(); + Map> explicitTransforms = debugExplicitTransforms(); + debugActiveTransformersByTransformer(explicitTransforms); + debugActiveTransformersByMimetypes(explicitTransforms); } } /** * Creates TransformerDebug that lists all the supported mimetype transformation for each transformer. */ - private void debugActiveTransformers() + private void debugActiveTransformersByTransformer(Map> explicitTransforms) { try { @@ -791,8 +793,6 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa transformerDebug.debug("Active and inactive transformers"); TransformationOptions options = new TransformationOptions(); - Map> explicitTransforms = debugExplicitTransforms(); - for (ContentTransformer transformer: transformerRegistry.getTransformers()) { try @@ -843,6 +843,62 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa } } + /** + * Creates TransformerDebug that lists all available transformers for each mimetype combination. + */ + private void debugActiveTransformersByMimetypes(Map> explicitTransforms) + { + try + { + transformerDebug.pushMisc(); + transformerDebug.debug("Transformers for each mimetype combination"); + TransformationOptions options = new TransformationOptions(); + + for (String sourceMimetype : mimetypeService.getMimetypes()) + { + for (String targetMimetype : mimetypeService.getMimetypes()) + { + try + { + transformerDebug.pushMisc(); + int transformerCount = 0; + for (ContentTransformer transformer: transformerRegistry.getTransformers()) + { + if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options)) + { + long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes( + sourceMimetype, targetMimetype, options); + + // Is this an explicit transform, ignored because there are explicit transforms + // or does not have explicit transforms. + Boolean explicit = transformer.isExplicitTransformation(sourceMimetype, + targetMimetype, options); + if (!explicit) + { + Set targetMimetypes = explicitTransforms.get(sourceMimetype); + explicit = (targetMimetypes == null || !targetMimetypes.contains(targetMimetype)) + ? null + : Boolean.FALSE; + } + transformerDebug.activeTransformer(sourceMimetype, targetMimetype, + transformerCount, transformer, maxSourceSizeKBytes, explicit, + transformerCount++ == 0); + } + } + } + finally + { + transformerDebug.popMisc(); + } + } + } + } + finally + { + transformerDebug.popMisc(); + } + } + /** * Returns the explicit mimetype transformations. Key is the source mimetype * and the value is a set of target mimetypes that are explicit. diff --git a/source/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java b/source/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java index f9531c8651..e0fb105d35 100644 --- a/source/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java +++ b/source/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java @@ -103,6 +103,7 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme // though they cannot transform the source to the target mimetype. return + isSupportedTransformation(sourceMimetype, targetMimetype, options) && isTransformableMimetype(sourceMimetype, targetMimetype, options) && isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options); } @@ -112,7 +113,6 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme * to the target mimetype. */ @Override - @SuppressWarnings("deprecation") public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) { return isTransformable(sourceMimetype, targetMimetype, options); diff --git a/source/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java b/source/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java index 6ffc4e7273..2cb309020d 100644 --- a/source/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java +++ b/source/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java @@ -174,6 +174,11 @@ public class ComplexContentTransformer extends AbstractContentTransformer2 imple public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) { + if (!isSupportedTransformation(sourceMimetype, targetMimetype, options)) + { + return false; + } + // Don't allow transformer to be its own child. if (parentTransformers.get().contains(this)) { diff --git a/source/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java b/source/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java index 25d6de9147..793fabde51 100644 --- a/source/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java +++ b/source/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2012 Alfresco Software Limited. * * This file is part of Alfresco * @@ -37,6 +37,7 @@ public class ContentTransformerHelper private MimetypeService mimetypeService; private List explicitTransformations; + private List supportedTransformations; /** * @@ -44,6 +45,7 @@ public class ContentTransformerHelper public ContentTransformerHelper() { setExplicitTransformations(Collections. emptyList()); + setSupportedTransformations(null); } /** @@ -64,11 +66,28 @@ public class ContentTransformerHelper return mimetypeService; } + /** + * Specifies transformations that are considered to be 'exceptional' so + * should be used in preference to other transformers that can perform + * the same transformation. + */ public void setExplicitTransformations(List explicitTransformations) { this.explicitTransformations = explicitTransformations; } + /** + * Restricts the transformations that may be performed even though the transformer + * may perform other transformations. An null value applies no additional restrictions. + * Even if a list is specified, the + * {@link ContentTransformer#isTransformableMimetype(String, String, TransformationOptions)} + * method will still be called. + */ + public void setSupportedTransformations(List supportedTransformations) + { + this.supportedTransformations = supportedTransformations; + } + /** * Convenience to fetch and check the mimetype for the given content * @@ -110,4 +129,22 @@ public class ContentTransformerHelper return result; } + public boolean isSupportedTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options) + { + boolean result = true; + if (supportedTransformations != null) + { + result = false; + for (SupportedTransformation suportedTransformation : supportedTransformations) + { + if (sourceMimetype.equals(suportedTransformation.getSourceMimetype()) == true + && targetMimetype.equals(suportedTransformation.getTargetMimetype()) == true) + { + result = true; + break; + } + } + } + return result; + } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java b/source/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java index 3503aa7c20..7dd1f7b664 100644 --- a/source/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java +++ b/source/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2012 Alfresco Software Limited. * * This file is part of Alfresco * @@ -18,38 +18,20 @@ */ package org.alfresco.repo.content.transform; -public class ExplictTransformationDetails +/** + * Specifies transformations that are considered to be 'exceptional' so + * should be used in preference to other transformers that can perform + * the same transformation. + */ +public class ExplictTransformationDetails extends SupportedTransformation { - private String sourceMimetype; - private String targetMimetype; - public ExplictTransformationDetails() { + super(); } public ExplictTransformationDetails(String sourceMimetype, String targetMimetype) { - this.sourceMimetype = sourceMimetype; - this.targetMimetype = targetMimetype; - } - - public void setSourceMimetype(String sourceMimetype) - { - this.sourceMimetype = sourceMimetype; - } - - public String getSourceMimetype() - { - return sourceMimetype; - } - - public void setTargetMimetype(String targetMimetype) - { - this.targetMimetype = targetMimetype; - } - - public String getTargetMimetype() - { - return targetMimetype; + super(sourceMimetype, targetMimetype); } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java b/source/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java index 8db591e7dc..638e7f581f 100644 --- a/source/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java +++ b/source/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java @@ -88,9 +88,11 @@ public class FailoverContentTransformer extends AbstractContentTransformer2 impl @Override public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) { - return // isTransformableSize must check the mimetype anyway - ((sourceSize >= 0) && isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options)) || - ((sourceSize < 0) && isTransformableMimetype(sourceMimetype,targetMimetype, options)); + return + isSupportedTransformation(sourceMimetype, targetMimetype, options) && + // isTransformableSize must check the mimetype anyway + (((sourceSize >= 0) && isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options)) || + ((sourceSize < 0) && isTransformableMimetype(sourceMimetype,targetMimetype, options))); } @Override diff --git a/source/java/org/alfresco/repo/content/transform/FailoverPdfToImageContentTransformer.java b/source/java/org/alfresco/repo/content/transform/FailoverPdfToImageContentTransformer.java deleted file mode 100644 index f39fcd10bc..0000000000 --- a/source/java/org/alfresco/repo/content/transform/FailoverPdfToImageContentTransformer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * 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 . - */ -package org.alfresco.repo.content.transform; - -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.service.cmr.repository.TransformationOptions; - -/** - * ALF-14303 Only support PDF to PNG rather than all the possible transformations from transformer.worker.ImageMagick - */ -public class FailoverPdfToImageContentTransformer extends FailoverContentTransformer -{ - @Override - public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) - { - return MimetypeMap.MIMETYPE_PDF.equals(sourceMimetype) && - MimetypeMap.MIMETYPE_IMAGE_PNG.equals(targetMimetype); - } -} diff --git a/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java b/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java index ae1d1a42a1..140ec15758 100644 --- a/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java +++ b/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2012 Alfresco Software Limited. * * This file is part of Alfresco * @@ -136,6 +136,12 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel */ public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options) { + // Use BinaryPassThroughContentTransformer if mimetypes are the same. + if (sourceMimetype.equals(targetMimetype)) + { + return false; + } + if (!isAvailable()) { // The connection management is must take care of this diff --git a/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformer.java b/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformer.java deleted file mode 100644 index 39736b8826..0000000000 --- a/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformer.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * 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 . - */ -package org.alfresco.repo.content.transform; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.List; - -import javax.imageio.ImageIO; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.TransformationOptions; -import org.alfresco.util.TempFileProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial; - -/** - * Makes use of the {@link http://www.pdfbox.org/ PDFBox} library to - * perform conversions from PDF files to images. - * - * @author Neil McErlean - */ -public class PdfBoxPdfToImageContentTransformer extends AbstractContentTransformer2 -{ - /** - * The PDF spec allows for a default user password of the empty string. - * See PDF Specification section 3.5 "Password Algorithms", specifically algorithms 3.6 - */ - private static final String PDF_DEFAULT_PASSWORD = ""; - private static Log logger = LogFactory.getLog(PdfBoxPdfToImageContentTransformer.class); - - @Override - public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) - { - // only support PDF -> PNG OR Adobe Illustrator -> PNG. - // Recent .ai file format is a .pdf file. - return ( (MimetypeMap.MIMETYPE_PDF.equals(sourceMimetype) || - MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR.equals(sourceMimetype)) - && MimetypeMap.MIMETYPE_IMAGE_PNG.equals(targetMimetype)); - } - - @SuppressWarnings("unchecked") - protected void transformInternal( - ContentReader reader, - ContentWriter writer, - TransformationOptions options) throws Exception - { - PDDocument document = null; - try - { - File file = TempFileProvider.createTempFile("pdfToImage", ".pdf"); - reader.getContent(file); - - document = PDDocument.load(file); - - if (document.isEncrypted()) - { - // Encrypted means password-protected, but PDF allows for two passwords: "owner" and "user". - // A "user" of a document should be able to read (but not modify) the content. - // - // We'll attempt to open the document using the common PDF default password. - document.openProtection(new StandardDecryptionMaterial(PDF_DEFAULT_PASSWORD)); - } - boolean canExtractContent = document.getCurrentAccessPermission().canExtractContent(); - if (!canExtractContent) - { - - String msg = "PDF document's intrinsic permissions forbid content extraction."; - if (logger.isDebugEnabled()) - { - logger.debug(msg); - } - throw new AlfrescoRuntimeException(msg); - } - - final int resolution = 16; // A rather arbitrary number for resolution (DPI) here. - - List pages = document.getDocumentCatalog().getAllPages(); - PDPage page = (PDPage)pages.get(0); - BufferedImage img = page.convertToImage(BufferedImage.TYPE_INT_ARGB, resolution); - - File outputFile = TempFileProvider.createTempFile(this.getClass().getSimpleName(), ".png"); - ImageIO.write(img, "png", outputFile); - - writer.putContent(outputFile); - } - catch (FileNotFoundException e1) - { - throw new AlfrescoRuntimeException("Unable to create image from pdf file.", e1); - } - catch (IOException e) - { - throw new AlfrescoRuntimeException("Unable to create image from pdf file.", e); - } - finally - { - if( document != null ) - { - document.close(); - } - } - } -} diff --git a/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformerTest.java b/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformerTest.java deleted file mode 100644 index ea3f0c0a32..0000000000 --- a/source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformerTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * 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 . - */ -package org.alfresco.repo.content.transform; - -import java.io.File; - -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.content.filestore.FileContentReader; -import org.alfresco.repo.content.filestore.FileContentWriter; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.TransformationOptions; -import org.alfresco.util.TempFileProvider; - -/** - * Tests for {@link PdfBoxPdfToImageContentTransformer}. - * - * @author Neil Mc Erlean - * @since 3.4.2. - */ -public class PdfBoxPdfToImageContentTransformerTest extends AbstractContentTransformerTest -{ - private PdfBoxPdfToImageContentTransformer transformer; - - @Override - public void setUp() throws Exception - { - super.setUp(); - - transformer = new PdfBoxPdfToImageContentTransformer(); - transformer.setMimetypeService(mimetypeService); - transformer.setTransformerDebug(transformerDebug); - } - - /** - * @return Returns the same transformer regardless - it is allowed - */ - protected ContentTransformer getTransformer(String sourceMimetype, String targetMimetype) - { - return transformer; - } - - public void testIsTransformable() throws Exception - { - assertTrue(transformer.isTransformable(MimetypeMap.MIMETYPE_PDF, -1, MimetypeMap.MIMETYPE_IMAGE_PNG, new TransformationOptions())); - } - - /** - * This test method checks that the PDFBox-based transformer is able to extract image content from a secured PDF file. - * See ALF-6650. - * - * @since 3.4.2 - */ - public void testExtractContentFromSecuredPdf() throws Exception - { - File securePdfFile = loadNamedQuickTestFile("quick-secured.pdf"); - assertNotNull("test file was null.", securePdfFile); - - ContentReader reader = new FileContentReader(securePdfFile); - reader.setMimetype(MimetypeMap.MIMETYPE_PDF); - reader.setEncoding("UTF-8"); - - ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(this.getClass().getSimpleName() + System.currentTimeMillis(), "txt")); - writer.setMimetype(MimetypeMap.MIMETYPE_IMAGE_PNG); - writer.setEncoding("UTF-8"); - - transformer.transform(reader, writer); - - // get a reader onto the transformed content and check - although the real test here is that exceptions weren't thrown during transformation. - ContentReader checkReader = writer.getReader(); - checkReader.setMimetype(MimetypeMap.MIMETYPE_IMAGE_PNG); - assertTrue("PNG output was empty", checkReader.getContentData().getSize() != 0l); - } - - /** - * This test method checks that the PDFBox-based transformer is able to transform an Adobe Illustrator file to image. - * Adobe Illustrator files (.ai) have been PostScript files in the past, but are now just pdf files. - * - * @since 3.5.0 - */ - public void testTransformAdobeIllustrator() throws Exception - { - for (String quickFile : new String[]{"quickCS3.ai", "quickCS5.ai"}) - { - File aiFile = loadNamedQuickTestFile(quickFile); - assertNotNull("test file was null.", aiFile); - ContentReader reader = new FileContentReader(aiFile); - reader.setMimetype(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR); - reader.setEncoding("UTF-8"); - ContentWriter writer = new FileContentWriter(TempFileProvider - .createTempFile(this.getClass().getSimpleName() - + System.currentTimeMillis(), "txt")); - writer.setMimetype(MimetypeMap.MIMETYPE_IMAGE_PNG); - writer.setEncoding("UTF-8"); - transformer.transform(reader, writer); - // get a reader onto the transformed content and check - although the real test here is that exceptions weren't thrown during transformation. - ContentReader checkReader = writer.getReader(); - checkReader.setMimetype(MimetypeMap.MIMETYPE_IMAGE_PNG); - assertTrue("PNG output was empty", checkReader.getContentData() - .getSize() != 0l); - } - } -} diff --git a/source/java/org/alfresco/repo/content/transform/PdfToImageContentTransformer.java b/source/java/org/alfresco/repo/content/transform/PdfToImageContentTransformer.java deleted file mode 100644 index 7e630d9cf7..0000000000 --- a/source/java/org/alfresco/repo/content/transform/PdfToImageContentTransformer.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * 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 . - */ -package org.alfresco.repo.content.transform; - -import java.awt.Rectangle; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; - -import javax.imageio.ImageIO; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.TransformationOptions; -import org.alfresco.util.TempFileProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.sun.pdfview.PDFFile; -import com.sun.pdfview.PDFPage; - -/** - * Makes use of the {@link https://pdf-renderer.dev.java.net/ PDFRenderer} library to - * perform conversions from PDF files to images. - * - * @author Roy Wetherall - */ -public class PdfToImageContentTransformer extends AbstractContentTransformer2 -{ - private static final Log logger = LogFactory.getLog(PdfToImageContentTransformer.class); - /** - * Currently the only transformation performed is that of text extraction from PDF documents. - */ - @Override - public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) - { - // only support PDF -> PNG OR Adobe Illustrator -> PNG. - // .ai is really just a .pdf file anyway - return ( (MimetypeMap.MIMETYPE_PDF.equals(sourceMimetype) || - MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR.equals(sourceMimetype)) - && MimetypeMap.MIMETYPE_IMAGE_PNG.equals(targetMimetype)); - } - - protected void transformInternal( - ContentReader reader, - ContentWriter writer, - TransformationOptions options) throws Exception - { - RandomAccessFile raf = null; - try - { - File file = TempFileProvider.createTempFile("pdfToImage", ".pdf"); - reader.getContent(file); - - raf = new RandomAccessFile(file, "r"); - FileChannel channel = raf.getChannel(); - - ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); - - PDFFile pdffile = new PDFFile(buf); - - // Log the PDF version of the file being transformed. - if (logger.isInfoEnabled()) - { - int pdfMajorVersion = pdffile.getMajorVersion(); - int pdfMinorVersion = pdffile.getMinorVersion(); - StringBuilder msg = new StringBuilder(); - msg.append("File being transformed is of pdf version ") - .append(pdfMajorVersion).append(".").append(pdfMinorVersion); - logger.info(msg.toString()); - } - - PDFPage page = pdffile.getPage(0, true); - if (page == null) - { - throw new AlfrescoRuntimeException("Unable to create image from pdf file."+ - "A PDFRender error took place which should have been sent to stdout."); - } - - //get the width and height for the doc at the default zoom - int width=(int)page.getBBox().getWidth(); - int height=(int)page.getBBox().getHeight(); - - Rectangle rect = new Rectangle(0,0,width,height); - int rotation=page.getRotation(); - Rectangle rect1=rect; - if (rotation==90 || rotation==270) - rect1=new Rectangle(0,0,rect.height,rect.width); - - //generate the image - BufferedImage img = (BufferedImage)page.getImage( - rect.width, rect.height, //width & height - rect1, // clip rect - null, // null for the ImageObserver - true, // fill background with white - true // block until drawing is done - ); - - File outputFile = TempFileProvider.createTempFile("pdfToImageOutput", ".png"); - ImageIO.write(img, "png", outputFile); - - writer.putContent(outputFile); - } - catch (FileNotFoundException e1) - { - throw new AlfrescoRuntimeException("Unable to create image from pdf file.", e1); - } - catch (Exception e) - { - throw new AlfrescoRuntimeException("Unable to create image from pdf file. "+e.getMessage(), e); - } - finally - { - if (raf != null) - { - try - { - raf.close(); - } - catch (IOException ignored) - { - // Intentionally empty - } - } - } - } -} diff --git a/source/java/org/alfresco/repo/content/transform/SupportedTransformation.java b/source/java/org/alfresco/repo/content/transform/SupportedTransformation.java new file mode 100644 index 0000000000..fb222a5c69 --- /dev/null +++ b/source/java/org/alfresco/repo/content/transform/SupportedTransformation.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.repo.content.transform; + +/** + * Represents a supported transformation. Normally used in a spring bean that limits + * the number of supported configures. + */ +public class SupportedTransformation +{ + private String sourceMimetype; + private String targetMimetype; + + public SupportedTransformation() + { + } + + public SupportedTransformation(String sourceMimetype, String targetMimetype) + { + this.sourceMimetype = sourceMimetype; + this.targetMimetype = targetMimetype; + } + + public void setSourceMimetype(String sourceMimetype) + { + this.sourceMimetype = sourceMimetype; + } + + public String getSourceMimetype() + { + return sourceMimetype; + } + + public void setTargetMimetype(String targetMimetype) + { + this.targetMimetype = targetMimetype; + } + + public String getTargetMimetype() + { + return targetMimetype; + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/content/transform/TransformerDebug.java b/source/java/org/alfresco/repo/content/transform/TransformerDebug.java index ea6db37f68..05530ff898 100644 --- a/source/java/org/alfresco/repo/content/transform/TransformerDebug.java +++ b/source/java/org/alfresco/repo/content/transform/TransformerDebug.java @@ -356,6 +356,21 @@ public class TransformerDebug (explicit == null ? "" : explicit ? " EXPLICIT" : " not explicit")); } + public void activeTransformer(String sourceMimetype, String targetMimetype, + int transformerCount, ContentTransformer transformer, long maxSourceSizeKBytes, + Boolean explicit, boolean firstTransformer) + { + String mimetypes = firstTransformer + ? getMimetypeExt(sourceMimetype)+getMimetypeExt(targetMimetype) + : spaces(10); + char c = (char)('a'+transformerCount); + log(mimetypes+ + " "+c+") "+getName(transformer)+' '+ms(transformer.getTransformationTime())+ + ' '+fileSize((maxSourceSizeKBytes > 0) ? maxSourceSizeKBytes*1024 : maxSourceSizeKBytes)+ + (maxSourceSizeKBytes == 0 || (explicit != null && !explicit) ? " disabled" : "")+ + (explicit == null ? "" : explicit ? " EXPLICIT" : " not explicit")); + } + private int getLongestTransformerNameLength(List transformers, Frame frame) {