mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge V4.1-BUG-FIX (4.1.1) to HEAD
38859: ALF-14240: Merged V3.4-BUG-FIX (3.4.11) to V4.1-BUG-FIX (4.1.1) 38858: ALF-15012 CLONE - New properties for "baseContentTransformer" prevent a remote OpenOffice configuration to start - Turns out that the 'New properties' that I added in 3.4.8 made it harder to get a remote OpenOffice instance working, but it has not been possible to do OpenOffice transformations on a remote machine for some time in the way described on the wiki https://wiki.alfresco.com/wiki/Running_OpenOffice_From_Remote_Machine#Remote_Machine_Setup - The following issues were all closed as "Not a Bug - Unsupported use case", even though the wiki describes it. They all work now - Only discovered these after I had fixed the code. ALF-236: (Alfresco 3.1.1) RemoteOpenOfficeContentTransformer fails to transform txt to odt ALF-4049: (Alfresco 3.2.2) RemoteOpenOfficeContentTransformer can't be used in a sub-system... ALF-8440: (Alfresco 3.3.3) Indicates moving OpenOffice transformations to the subsystem OOoDirect requires different spring bean overrides. - Having worked out that RemoteOpenOfficeContentTransformer was really just a very early version of OpenOfficeContentTransformerWorker, I have removed RemoteOpenOfficeContentTransformer and the remote-openoffice-context.xml.sample and modified OpenOfficeContentTransformerWorker to support remote OpenOffice instances. Rather than having to override spring beans it is now possible to do the configuration using Alfresco global properties. Introduced one new one: ooo.host This must be set to the name or ip of the remote system, ooo.port (already existed) must be set to the port used by the remote OppenOffice instance and ooo.enabled (already existed) must be set to false so that a local instance is not started. - As a side effect of using OpenOfficeContentTransformerWorker, all bug fixes that have been added to this class will now also be available to remote OpenOffice instances. - Added extra change to share-form-config.xml (not in 3.4) to include the host as a field 38742: ALF-14801 - Overwrite or delete a folder containing multiple files and folders via CIFS on Lion OS X fails with StringIndexOutOfBoundsException 38679: ALF-14857 - Importing .eml messages generated from Lotus Notes doesn't work 38675: ALF-14942 Cast operation will always fail in MoveFileOperation 38666: Merged V4.1 to V4.1-BUG-FIX 38665: ALF-13260: Mysql does an awful planification of ibatis "select_ChildAssocOfParentByName" query after some heavy load - improved "select_ChildAssocOfParentByName" where clause to engage existing index 38598: New Chinese translations from Gloria plus Bitrock configuration to enable them git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@38860 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -38,6 +38,7 @@ 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.PropertyCheck;
|
||||
import org.alfresco.util.SocketOpenOfficeConnection;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.pdfbox.exceptions.COSVisitorException;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
@@ -97,40 +98,48 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return this.connection.isConnected();
|
||||
return connection.isConnected();
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory("OpenOfficeContentTransformerWorker", "connection", this.connection);
|
||||
PropertyCheck.mandatory("OpenOfficeContentTransformerWorker", "connection", connection);
|
||||
|
||||
// load the document conversion configuration
|
||||
if (this.documentFormatsConfiguration != null)
|
||||
if (documentFormatsConfiguration != null)
|
||||
{
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
try
|
||||
{
|
||||
InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream();
|
||||
this.formatRegistry = new XmlDocumentFormatRegistry(is);
|
||||
InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream();
|
||||
formatRegistry = new XmlDocumentFormatRegistry(is);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to load document formats configuration file: "
|
||||
+ this.documentFormatsConfiguration);
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Unable to load document formats configuration file: " +
|
||||
documentFormatsConfiguration);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.formatRegistry = new XmlDocumentFormatRegistry();
|
||||
formatRegistry = new XmlDocumentFormatRegistry();
|
||||
}
|
||||
|
||||
// set up the converter
|
||||
if (this.converter == null)
|
||||
if (converter == null)
|
||||
{
|
||||
this.converter = new OpenOfficeDocumentConverter(this.connection);
|
||||
converter = getDefaultConverter(connection);
|
||||
}
|
||||
}
|
||||
|
||||
protected AbstractOpenOfficeDocumentConverter getDefaultConverter(OpenOfficeConnection connection)
|
||||
{
|
||||
return (connection instanceof SocketOpenOfficeConnection)
|
||||
? ((SocketOpenOfficeConnection)connection).getDefaultConverter()
|
||||
: new OpenOfficeDocumentConverter(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DocumentFormatRegistry
|
||||
*/
|
||||
@@ -157,14 +166,14 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
// query the registry for the source format
|
||||
DocumentFormat sourceFormat = this.formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
if (sourceFormat == null)
|
||||
{
|
||||
// no document format
|
||||
return false;
|
||||
}
|
||||
// query the registry for the target format
|
||||
DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// no document format
|
||||
@@ -185,7 +194,10 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
}
|
||||
}
|
||||
|
||||
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
|
||||
public void transform(
|
||||
ContentReader reader,
|
||||
ContentWriter writer,
|
||||
TransformationOptions options) throws Exception
|
||||
{
|
||||
String sourceMimetype = getMimetype(reader);
|
||||
String targetMimetype = getMimetype(writer);
|
||||
@@ -194,14 +206,14 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
// query the registry for the source format
|
||||
DocumentFormat sourceFormat = this.formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
if (sourceFormat == null)
|
||||
{
|
||||
// source format is not recognised
|
||||
throw new ContentIOException("No OpenOffice document format for source extension: " + sourceExtension);
|
||||
}
|
||||
// query the registry for the target format
|
||||
DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// target format is not recognised
|
||||
@@ -212,15 +224,19 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
// does the format support the conversion
|
||||
if (!targetFormat.isExportableFrom(sourceFamily))
|
||||
{
|
||||
throw new ContentIOException("OpenOffice conversion not supported: \n" + " reader: " + reader + "\n"
|
||||
+ " writer: " + writer);
|
||||
throw new ContentIOException(
|
||||
"OpenOffice conversion not supported: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" writer: " + writer);
|
||||
}
|
||||
|
||||
// create temporary files to convert from and to
|
||||
File tempFromFile = TempFileProvider.createTempFile("OpenOfficeContentTransformer-source-", "."
|
||||
+ sourceExtension);
|
||||
File tempToFile = TempFileProvider
|
||||
.createTempFile("OpenOfficeContentTransformer-target-", "." + targetExtension);
|
||||
File tempFromFile = TempFileProvider.createTempFile(
|
||||
"OpenOfficeContentTransformer-source-",
|
||||
"." + sourceExtension);
|
||||
File tempToFile = TempFileProvider.createTempFile(
|
||||
"OpenOfficeContentTransformer-target-",
|
||||
"." + targetExtension);
|
||||
|
||||
|
||||
final long documentSize = reader.getSize();
|
||||
@@ -247,14 +263,17 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
// it is preferred over PDFBox.
|
||||
try
|
||||
{
|
||||
this.converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
|
||||
converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
|
||||
// conversion success
|
||||
}
|
||||
catch (OpenOfficeException e)
|
||||
{
|
||||
throw new ContentIOException("OpenOffice server conversion failed: \n" + " reader: " + reader + "\n"
|
||||
+ " writer: " + writer + "\n" + " from file: " + tempFromFile + "\n" + " to file: "
|
||||
+ tempToFile, e);
|
||||
throw new ContentIOException("OpenOffice server conversion failed: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" writer: " + writer + "\n" +
|
||||
" from file: " + tempFromFile + "\n" +
|
||||
" to file: " + tempToFile,
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,57 +286,61 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel
|
||||
* This method produces an empty PDF file at the specified File location.
|
||||
* Apache's PDFBox is used to create the PDF file.
|
||||
*/
|
||||
private void produceEmptyPdfFile(File tempToFile)
|
||||
{
|
||||
// If improvement PDFBOX-914 is incorporated, we can do this with a straight call to
|
||||
// org.apache.pdfbox.TextToPdf.createPDFFromText(new StringReader(""));
|
||||
// https://issues.apache.org/jira/browse/PDFBOX-914
|
||||
|
||||
private void produceEmptyPdfFile(File tempToFile)
|
||||
{
|
||||
// If improvement PDFBOX-914 is incorporated, we can do this with a straight call to
|
||||
// org.apache.pdfbox.TextToPdf.createPDFFromText(new StringReader(""));
|
||||
// https://issues.apache.org/jira/browse/PDFBOX-914
|
||||
|
||||
PDDocument pdfDoc = null;
|
||||
PDPageContentStream contentStream = null;
|
||||
try
|
||||
{
|
||||
pdfDoc = new PDDocument();
|
||||
PDPage pdfPage = new PDPage();
|
||||
// Even though, we want an empty PDF, some libs (e.g. PDFRenderer) object to PDFs
|
||||
// that have literally nothing in them. So we'll put a content stream in it.
|
||||
// Even though, we want an empty PDF, some libs (e.g. PDFRenderer) object to PDFs
|
||||
// that have literally nothing in them. So we'll put a content stream in it.
|
||||
contentStream = new PDPageContentStream(pdfDoc, pdfPage);
|
||||
pdfDoc.addPage(pdfPage);
|
||||
|
||||
// Now write the in-memory PDF document into the temporary file.
|
||||
|
||||
// Now write the in-memory PDF document into the temporary file.
|
||||
pdfDoc.save(tempToFile.getAbsolutePath());
|
||||
|
||||
}
|
||||
catch (COSVisitorException cvx)
|
||||
{
|
||||
throw new ContentIOException("Error creating empty PDF file", cvx);
|
||||
throw new ContentIOException("Error creating empty PDF file", cvx);
|
||||
}
|
||||
catch (IOException iox)
|
||||
{
|
||||
throw new ContentIOException("Error creating empty PDF file", iox);
|
||||
throw new ContentIOException("Error creating empty PDF file", iox);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (contentStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentStream.close();
|
||||
} catch (IOException ignored) {
|
||||
// Intentionally empty
|
||||
}
|
||||
}
|
||||
if (pdfDoc != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pdfDoc.close();
|
||||
} catch (IOException ignored) {
|
||||
// Intentionally empty.
|
||||
}
|
||||
}
|
||||
if (contentStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentStream.close();
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
}
|
||||
if (pdfDoc != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pdfDoc.close();
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
// Intentionally empty.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.jooreports.converter.DocumentFamily;
|
||||
import net.sf.jooreports.converter.DocumentFormat;
|
||||
import net.sf.jooreports.converter.DocumentFormatRegistry;
|
||||
import net.sf.jooreports.converter.XmlDocumentFormatRegistry;
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeException;
|
||||
import net.sf.jooreports.openoffice.converter.StreamOpenOfficeDocumentConverter;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.transform.AbstractContentTransformer;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
|
||||
/**
|
||||
* Makes use of the {@link http://sourceforge.net/projects/joott/JOOConverter} library to
|
||||
* perform OpenOffice-drive conversions.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @author Juan David Zuluaga Arboleda
|
||||
* @author Jared Ottley
|
||||
*
|
||||
*/
|
||||
public class RemoteOpenOfficeContentTransformer extends AbstractContentTransformer
|
||||
{
|
||||
private OpenOfficeConnection connection;
|
||||
private StreamOpenOfficeDocumentConverter converter;
|
||||
private String documentFormatsConfiguration;
|
||||
private DocumentFormatRegistry formatRegistry;
|
||||
|
||||
public RemoteOpenOfficeContentTransformer()
|
||||
{
|
||||
}
|
||||
|
||||
public void setConnection(OpenOfficeConnection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a non-default location from which to load the document format mappings.
|
||||
*
|
||||
* @param path a resource location supporting the <b>file:</b> or <b>classpath:</b> prefixes
|
||||
*/
|
||||
public void setDocumentFormatsConfiguration(String path)
|
||||
{
|
||||
this.documentFormatsConfiguration = path;
|
||||
}
|
||||
|
||||
public boolean isConnected()
|
||||
{
|
||||
return connection.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register()
|
||||
{
|
||||
PropertyCheck.mandatory("OpenOfficeContentTransformer", "connection", connection);
|
||||
|
||||
// load the document conversion configuration
|
||||
if (documentFormatsConfiguration != null)
|
||||
{
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
try
|
||||
{
|
||||
InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream();
|
||||
formatRegistry = new XmlDocumentFormatRegistry(is);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Unable to load document formats configuration file: " + documentFormatsConfiguration);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
formatRegistry = new XmlDocumentFormatRegistry();
|
||||
}
|
||||
|
||||
// set up the converter
|
||||
converter = new StreamOpenOfficeDocumentConverter(connection);
|
||||
|
||||
// Register
|
||||
super.register();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DocumentFormatRegistry
|
||||
*/
|
||||
public double getReliability(String sourceMimetype, String targetMimetype)
|
||||
{
|
||||
if (!isConnected())
|
||||
{
|
||||
// The connection management is must take care of this
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// there are some conversions that fail, despite the converter believing them possible
|
||||
if (targetMimetype.equals(MimetypeMap.MIMETYPE_XHTML))
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else if (targetMimetype.equals(MimetypeMap.MIMETYPE_WORDPERFECT))
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
// query the registry for the source format
|
||||
DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
if (sourceFormat == null)
|
||||
{
|
||||
// no document format
|
||||
return 0.0;
|
||||
}
|
||||
// query the registry for the target format
|
||||
DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// no document format
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// get the family of the target document
|
||||
DocumentFamily sourceFamily = sourceFormat.getFamily();
|
||||
// does the format support the conversion
|
||||
if (!targetFormat.isExportableFrom(sourceFamily))
|
||||
{
|
||||
// unable to export from source family of documents to the target format
|
||||
return 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
protected void transformInternal(
|
||||
ContentReader reader,
|
||||
ContentWriter writer,
|
||||
Map<String, Object> options) throws Exception
|
||||
{
|
||||
String sourceMimetype = getMimetype(reader);
|
||||
String targetMimetype = getMimetype(writer);
|
||||
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
// query the registry for the source format
|
||||
DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
if (sourceFormat == null)
|
||||
{
|
||||
// source format is not recognised
|
||||
throw new ContentIOException("No OpenOffice document format for source extension: " + sourceExtension);
|
||||
}
|
||||
// query the registry for the target format
|
||||
DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// target format is not recognised
|
||||
throw new ContentIOException("No OpenOffice document format for target extension: " + targetExtension);
|
||||
}
|
||||
// get the family of the target document
|
||||
DocumentFamily sourceFamily = sourceFormat.getFamily();
|
||||
// does the format support the conversion
|
||||
if (!targetFormat.isExportableFrom(sourceFamily))
|
||||
{
|
||||
throw new ContentIOException(
|
||||
"OpenOffice conversion not supported: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" writer: " + writer);
|
||||
}
|
||||
|
||||
// create temporary files to convert from and to
|
||||
File tempFromFile = TempFileProvider.createTempFile(
|
||||
"OpenOfficeContentTransformer-source-",
|
||||
"." + sourceExtension);
|
||||
File tempToFile = TempFileProvider.createTempFile(
|
||||
"OpenOfficeContentTransformer-target-",
|
||||
"." + targetExtension);
|
||||
// download the content from the source reader
|
||||
reader.getContent(tempFromFile);
|
||||
|
||||
try
|
||||
{
|
||||
converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
|
||||
// conversion success
|
||||
}
|
||||
catch (OpenOfficeException e)
|
||||
{
|
||||
throw new ContentIOException("OpenOffice server conversion failed: \n" +
|
||||
" reader: " + reader + "\n" +
|
||||
" writer: " + writer + "\n" +
|
||||
" from file: " + tempFromFile + "\n" +
|
||||
" to file: " + tempToFile,
|
||||
e);
|
||||
}
|
||||
|
||||
// upload the temp output to the writer given us
|
||||
writer.putContent(tempToFile);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user