From 3ba7ffcca08c06064974d1174d358c56a678df6a Mon Sep 17 00:00:00 2001 From: Dave Ward Date: Thu, 21 Jun 2012 16:58:32 +0000 Subject: [PATCH] Merged V4.1-BUG-FIX to HEAD 38065: ALF-13725: yui-genXXX appears in the warning message while changing file name 38113: Merged BRANCHES/DEV/CLOUD1 to BRANCHES/DEV/V4.1-BUG-FIX 35857: Merged BRANCHES/DEV/THOR1 to BRANCHES/DEV/CLOUD1 33050: THOR-427: Decrease log level of 'Login Failed' 38117: Merged V4.1 to V4.1-BUG-FIX 38087: ALF-14725: Merged V3.4-BUG-FIX to V4.1 38086: ALF-14724: Upgrade to Java 1.6 u33 38118: Missing semicolons 38128: Merged V3.4-BUG-FIX to V4.1-BUG-FIX 37821: Fix for ALF-13658 - Direct access (SSO) to share user dashboard with external authentication fails and user is prompted to log on when browsing 37829: ALF-14340 CLONE: Alfresco crashes when viewing doclib / previewing - PDF with CMap This first part is general code (does not fix the specific issue) that could be merged to any branch. - TransformerDebug changes made to support investigation - Addition of 'supported mimetype transformations' to spring configuration (this is generally what people have thought EXPLICIT transformations were). - Tidy up of OpenOffice and JOD converters so that they don't say they can convert a mimetype to itself. There is a binary transformer that can just copy them. This also simplifies the Transformer debug output. 37831: ALF-14340 CLONE: Alfresco crashes when viewing doclib / previewing - PDF with CMap - missing file from last commit. 37832: ALF-14340 CLONE: Alfresco crashes when viewing doclib / previewing - PDF with CMap This second part that fixes the specific issue with reconfiguration of the transformers used. - Configuration of transformers changed to use ImageMagick with Ghostscript rather than PDFBox and PDFRenderer. The same transformations should be possible after this change. No combinations have been removed or added. - ImageMagick with Ghostscript now replaces both PDFBox and PDFRenderer for PDF to PNG. - A single or double ImageMagick with Ghostscript transformation (fails over to double when not possible with a single transformation) is now used by transformer.complex.PDF.Image - ImageMagick with Ghostscript rather than transformer.complex.PDF.Image now declares itself as having an EXPLICIT transformation for PDF to PNG. So normally there is no need to even look at the more complicated transformer.complex.PDF.Image unless it is included as a component of another transformer (there are 3). - PDFRenderer and 3rd party libs were only being used for PDF to PNG, so could be removed. NOT REMOVED AT THIS STAGE TO ALLOW CUSTOMISATION USE AND WORKAROUNDS OF ANY ISSUED THAT MIGHT BE FOUND. - PDFBox is still required for text to PDF, PDF to Text and metadata extraction. - Tidy up transformer.PdfBox.TextToPdf so that it does not declare csv to pdf and xml to pdf as EXPLICIT as this is the only transformer that can do it. 37834: ALF-10518 - Improvements to tagQuery.get.js for the Repository use case to remove the need to add //* PATH for CompanyHome query. 37835: Fix for ALF-14429 - Recently Modified dashlet takes up to 30 seconds to load after upgrade to Alfresco 3.4.6.23 37858: Merged V3.4 to V3.4-BUG-FIX (RECORD ONLY) 37592: Merged V3.4-BUG-FIX to V3.4 (3.4.10) 35103: Merged DEV to V3.4-BUG-FIX 37789: Merged V3.4-BUG-FIX to V3.4 37788: Second part of fix from Alex Mukha for ALF-11714 37841: ALF-14524: Merged PATCHES/V3.4.9 to V3.4 37840: ALF-14589: ALF-9861 breaks the JSON based error reporting for document library actions (by custom actions and code) - Fix by Mr Roast 37865: Merged DEV to V3.4-BUG-FIX (with corrections) 37845: ALF-13929: Error during processing of the 'show audit' template after upgrade New patch that updates show_audit.ftl to the newest version during upgrade 37877: Correction to corrections: 37865: Merged DEV to V3.4-BUG-FIX (with corrections) 37845: ALF-13929: Error during processing of the 'show audit' template after upgrade New patch that updates show_audit.ftl to the newest version during upgrade 37918: Merged DEV to V3.4-BUG-FIX 37548: ALF-11124: English language bundle properties have _en_US suffix Updated ant scripts to create properties files without _US suffix. 38090: ALF-14699: Merged DEV to V3.4-BUGFIX 38070: Search in Alfresco Explorer does not work 38124: Merged V3.4 to V3.4-BUG-FIX (RECORD ONLY) 38092: Merged V3.4-BUG-FIX to V3.4 38090: : Merged DEV to V3.4-BUGFIX 38070: ALF-14699: Search in Alfresco Explorer does not work git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@38135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/content-services-context.xml | 172 ++++++++++++------ .../messages/patch-service.properties | 4 +- .../alfresco/patch/patch-services-context.xml | 21 +++ config/alfresco/version.properties | 2 +- .../patch/impl/UpdateAuditTemplatePatch.java | 105 +++++++++++ .../repo/content/ContentServiceImpl.java | 64 ++++++- .../AbstractContentTransformerLimits.java | 2 +- .../transform/ComplexContentTransformer.java | 5 + .../transform/ContentTransformerHelper.java | 39 +++- .../ExplictTransformationDetails.java | 36 +--- .../transform/FailoverContentTransformer.java | 8 +- .../FailoverPdfToImageContentTransformer.java | 35 ---- .../OpenOfficeContentTransformerWorker.java | 8 +- .../PdfBoxPdfToImageContentTransformer.java | 127 ------------- ...dfBoxPdfToImageContentTransformerTest.java | 119 ------------ .../PdfToImageContentTransformer.java | 149 --------------- .../transform/SupportedTransformation.java | 59 ++++++ .../content/transform/TransformerDebug.java | 15 ++ 18 files changed, 446 insertions(+), 524 deletions(-) create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/UpdateAuditTemplatePatch.java delete mode 100644 source/java/org/alfresco/repo/content/transform/FailoverPdfToImageContentTransformer.java delete mode 100644 source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformer.java delete mode 100644 source/java/org/alfresco/repo/content/transform/PdfBoxPdfToImageContentTransformerTest.java delete mode 100644 source/java/org/alfresco/repo/content/transform/PdfToImageContentTransformer.java create mode 100644 source/java/org/alfresco/repo/content/transform/SupportedTransformation.java 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) {