diff --git a/source/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java b/source/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java index 3d5678d7f6..51ac27a5a4 100644 --- a/source/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java +++ b/source/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.repo.content.transform; import java.io.BufferedOutputStream; @@ -34,7 +34,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; -import java.util.Date; import com.sun.star.task.ErrorCodeIOException; import net.sf.jooreports.converter.DocumentFamily; @@ -50,7 +49,6 @@ import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.TransformationOptions; -import org.alfresco.util.GUID; import org.alfresco.util.TempFileProvider; import org.apache.commons.logging.Log; import org.apache.pdfbox.exceptions.COSVisitorException; @@ -345,27 +343,13 @@ public abstract class OOoContentTransformerHelper extends ContentTransformerHelp " writer: " + writer); } - // MNT-11279 fix. Because of the creating temp files for transformations the document's header with file name field - // could be changed to temporary file's name. - // Get the original file name which was on upload. - String origFileName = getOriginalFileName(options); - if (origFileName == null) - { - origFileName = "TemporaryFile-" + GUID.generate() + "." + sourceExtension; - } - // Create a temp folder and put source and target files into it. (i.e. tempFromFile and tempToFile will be placed - // into such folder) - File tempSubfolder = new File(TempFileProvider.getTempDir() + File.separator + - origFileName + "-" + getTempFilePrefix() + "-" - + getTempFilePrefix() + "-" + new Date().getTime()); - tempSubfolder.mkdir(); - // create temporary files to convert from and to - // The source file should have the name which was on upload - File tempFromFile = new File(tempSubfolder, origFileName ); + File tempFromFile = TempFileProvider.createTempFile( + getTempFilePrefix()+"-source-", + "." + sourceExtension); File tempToFile = TempFileProvider.createTempFile( - origFileName + "-" + getTempFilePrefix()+"-target-", - "." + targetExtension, tempSubfolder); + getTempFilePrefix()+"-target-", + "." + targetExtension); // There is a bug (reported in ALF-219) whereby JooConverter (the Alfresco Community Edition's 3rd party // OpenOffice connector library) struggles to handle zero-size files being transformed to pdf. @@ -438,12 +422,7 @@ public abstract class OOoContentTransformerHelper extends ContentTransformerHelp getLogger().debug("transformation successful"); } } - - private String getOriginalFileName(TransformationOptions options) - { - return transformerDebug == null ? null : transformerDebug.getFileName(options, true, -1); - } - + private boolean temporaryMsFile(TransformationOptions options) { String fileName = transformerDebug == null ? null : transformerDebug.getFileName(options, true, -1); diff --git a/source/test-java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerTest.java b/source/test-java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerTest.java index e3e6750dc0..c4af1e28d2 100644 --- a/source/test-java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerTest.java +++ b/source/test-java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerTest.java @@ -141,47 +141,6 @@ public class OpenOfficeContentTransformerTest extends AbstractContentTransformer transformer.transform(reader, writer); } - /** - * MNT-11279. Transform docx document that contains head with value "documentName" to pdf. - * - */ - public void testDocxFieldToPdf() - { - if (!worker.isAvailable()) - { - // no connection - return; - } - URL docxUrl = this.getClass().getClassLoader().getResource("misc/Test-Header-Office-2010.docx"); - assertNotNull("URL was unexpectedly null", docxUrl); - - File docxSourceFile = new File(docxUrl.getFile()); - assertTrue("Test file does not exist.", docxSourceFile.exists()); - - File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf"); - - ContentReader reader = new FileContentReader(docxSourceFile); - reader.setMimetype(MimetypeMap.MIMETYPE_WORD); - ContentWriter writer = new FileContentWriter(pdfTargetFile); - writer.setMimetype(MimetypeMap.MIMETYPE_PDF); - - transformer.transform(reader, writer); - - //Transform to txt for checking content - reader = new FileContentReader(pdfTargetFile); - reader.setMimetype(MimetypeMap.MIMETYPE_PDF); - - File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".txt"); - - writer = new FileContentWriter(txtTargetFile); - writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); - - transformer.transform(reader, writer); - - String txtContent = writer.getReader().getContentString(); - assertTrue("Transformed document must contains real document name", txtContent.contains("Document File Name: Test-Header-Office-2010Test-Header-Office-2010")); - } - /** * Some transformations fail intermittently within OOo on our test server. * Rather than exclude these transformations from product code, where they diff --git a/source/test-resources/misc/Test-Header-Office-2010.docx b/source/test-resources/misc/Test-Header-Office-2010.docx deleted file mode 100644 index dd9ebed78e..0000000000 Binary files a/source/test-resources/misc/Test-Header-Office-2010.docx and /dev/null differ