mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
3rd Party Service admin (OpenOffice, SWFTools, ImageMagick)
- All supporting classes moved out to thirdparty subsystem - Open Office service automatically started if available - All utility locations editable via JMX (and subsystem can be reinitialized with new values without rebooting tomcat) - New ContentTransformerWorker interface introduced in order to allow separation between ContentTransformer registry and third party utilities - Existing JMX query capabilities preserved git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13860 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,7 +39,6 @@ import org.alfresco.repo.content.ContentServicePolicies.OnContentUpdatePolicy;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.repo.content.transform.ContentTransformer;
|
||||
import org.alfresco.repo.content.transform.ContentTransformerRegistry;
|
||||
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformer;
|
||||
import org.alfresco.repo.policy.ClassPolicyDelegate;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
@@ -97,7 +96,7 @@ public class RoutingContentService implements ContentService, ApplicationContext
|
||||
private ContentStore store;
|
||||
/** the store for all temporarily created content */
|
||||
private ContentStore tempStore;
|
||||
private ImageMagickContentTransformer imageMagickContentTransformer;
|
||||
private ContentTransformer imageMagickContentTransformer;
|
||||
|
||||
/**
|
||||
* The policy component
|
||||
@@ -153,7 +152,7 @@ public class RoutingContentService implements ContentService, ApplicationContext
|
||||
this.avmService = service;
|
||||
}
|
||||
|
||||
public void setImageMagickContentTransformer(ImageMagickContentTransformer imageMagickContentTransformer)
|
||||
public void setImageMagickContentTransformer(ContentTransformer imageMagickContentTransformer)
|
||||
{
|
||||
this.imageMagickContentTransformer = imageMagickContentTransformer;
|
||||
}
|
||||
@@ -317,7 +316,6 @@ public class RoutingContentService implements ContentService, ApplicationContext
|
||||
Serializable propValue = nodeService.getProperty(nodeRef, propertyQName);
|
||||
if (propValue instanceof Collection)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Serializable> colPropValue = (Collection<Serializable>)propValue;
|
||||
if (colPropValue.size() > 0)
|
||||
{
|
||||
@@ -461,7 +459,6 @@ public class RoutingContentService implements ContentService, ApplicationContext
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformer
|
||||
* @deprecated
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void transform(ContentReader reader, ContentWriter writer, Map<String, Object> options)
|
||||
throws NoTransformerException, ContentIOException
|
||||
{
|
||||
|
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Serializable;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.document.XDocumentInfoSupplier;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ucb.XFileIdentifierConverter;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
/**
|
||||
* The class doing the actual work of the OpenOfficeMetadataExtracter, based around an OpenOffice connection.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class DefaultOpenOfficeMetadataWorker implements OpenOfficeMetadataWorker
|
||||
{
|
||||
private static final String KEY_AUTHOR = "author";
|
||||
private static final String KEY_TITLE = "title";
|
||||
private static final String KEY_DESCRIPTION = "description";
|
||||
|
||||
private OpenOfficeConnection connection;
|
||||
private MimetypeService mimetypeService;
|
||||
|
||||
public void setConnection(OpenOfficeConnection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param mimetypeService the mimetype service. Set this if required.
|
||||
*/
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns true if a connection to the Uno server could be established
|
||||
*/
|
||||
public boolean isConnected()
|
||||
{
|
||||
return connection.isConnected();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @seeorg.alfresco.repo.content.metadata.OpenOfficeMetadataWorker#extractRaw(org.alfresco.service.cmr.repository.
|
||||
* ContentReader)
|
||||
*/
|
||||
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
|
||||
{
|
||||
Map<String, Serializable> rawProperties = new HashMap<String, Serializable>(17);
|
||||
|
||||
String sourceMimetype = reader.getMimetype();
|
||||
|
||||
// create temporary files to convert from and to
|
||||
File tempFromFile = TempFileProvider.createTempFile("OpenOfficeMetadataExtracter-", "."
|
||||
+ this.mimetypeService.getExtension(sourceMimetype));
|
||||
|
||||
// download the content from the source reader
|
||||
reader.getContent(tempFromFile);
|
||||
|
||||
String sourceUrl = toUrl(tempFromFile, connection);
|
||||
|
||||
// UNO Interprocess Bridge *should* be thread-safe, but...
|
||||
XComponentLoader desktop = connection.getDesktop();
|
||||
XComponent document = desktop.loadComponentFromURL(sourceUrl, "_blank", 0, new PropertyValue[]
|
||||
{
|
||||
property("Hidden", Boolean.TRUE)
|
||||
});
|
||||
if (document == null)
|
||||
{
|
||||
throw new FileNotFoundException("could not open source document: " + sourceUrl);
|
||||
}
|
||||
try
|
||||
{
|
||||
XDocumentInfoSupplier infoSupplier = (XDocumentInfoSupplier) UnoRuntime.queryInterface(
|
||||
XDocumentInfoSupplier.class, document);
|
||||
XPropertySet propSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, infoSupplier
|
||||
.getDocumentInfo());
|
||||
|
||||
rawProperties.put(KEY_TITLE, propSet.getPropertyValue("Title").toString());
|
||||
rawProperties.put(KEY_DESCRIPTION, propSet.getPropertyValue("Subject").toString());
|
||||
rawProperties.put(KEY_AUTHOR, propSet.getPropertyValue("Author").toString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
document.dispose();
|
||||
}
|
||||
// Done
|
||||
return rawProperties;
|
||||
}
|
||||
|
||||
public String toUrl(File file, OpenOfficeConnection connection) throws ConnectException
|
||||
{
|
||||
Object fcp = connection.getFileContentProvider();
|
||||
XFileIdentifierConverter fic = (XFileIdentifierConverter) UnoRuntime.queryInterface(
|
||||
XFileIdentifierConverter.class, fcp);
|
||||
return fic.getFileURLFromSystemPath("", file.getAbsolutePath());
|
||||
}
|
||||
|
||||
private static PropertyValue property(String name, Object value)
|
||||
{
|
||||
PropertyValue property = new PropertyValue();
|
||||
property.Name = name;
|
||||
property.Value = value;
|
||||
return property;
|
||||
}
|
||||
}
|
@@ -22,28 +22,14 @@
|
||||
* http://www.alfresco.com/legal/licensing" */
|
||||
package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Serializable;
|
||||
import java.net.ConnectException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.document.XDocumentInfoSupplier;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ucb.XFileIdentifierConverter;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
/**
|
||||
* Extracts values from Star Office documents into the following:
|
||||
@@ -55,12 +41,8 @@ import com.sun.star.uno.UnoRuntime;
|
||||
*
|
||||
* @author Jesper Steen Møller
|
||||
*/
|
||||
public class OpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracter
|
||||
public class OpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracter implements OpenOfficeMetadataWorker
|
||||
{
|
||||
private static final String KEY_AUTHOR = "author";
|
||||
private static final String KEY_TITLE = "title";
|
||||
private static final String KEY_DESCRIPTION = "description";
|
||||
|
||||
public static String[] SUPPORTED_MIMETYPES = new String[] {
|
||||
MimetypeMap.MIMETYPE_STAROFFICE5_WRITER,
|
||||
MimetypeMap.MIMETYPE_STAROFFICE5_IMPRESS,
|
||||
@@ -68,16 +50,16 @@ public class OpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracte
|
||||
MimetypeMap.MIMETYPE_OPENOFFICE1_IMPRESS
|
||||
};
|
||||
|
||||
private OpenOfficeConnection connection;
|
||||
private OpenOfficeMetadataWorker worker;
|
||||
|
||||
public OpenOfficeMetadataExtracter()
|
||||
{
|
||||
super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
|
||||
}
|
||||
|
||||
public void setConnection(OpenOfficeConnection connection)
|
||||
public void setWorker(OpenOfficeMetadataWorker worker)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,19 +68,18 @@ public class OpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracte
|
||||
@Override
|
||||
public synchronized void init()
|
||||
{
|
||||
PropertyCheck.mandatory("OpenOfficeMetadataExtracter", "connection", connection);
|
||||
PropertyCheck.mandatory("OpenOfficeMetadataExtracter", "worker", worker);
|
||||
|
||||
// Base initialization
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns true if a connection to the Uno server could be
|
||||
* established
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.content.metadata.OpenOfficeMetadataWorker#isConnected()
|
||||
*/
|
||||
public boolean isConnected()
|
||||
{
|
||||
return connection.isConnected();
|
||||
return worker.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,67 +95,18 @@ public class OpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracte
|
||||
return super.isSupported(sourceMimetype);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.content.metadata.OpenOfficeMetadataWorker#extractRaw(org.alfresco.service.cmr.repository.ContentReader)
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
|
||||
{
|
||||
Map<String, Serializable> rawProperties = newRawMap();
|
||||
|
||||
String sourceMimetype = reader.getMimetype();
|
||||
|
||||
// create temporary files to convert from and to
|
||||
File tempFromFile = TempFileProvider.createTempFile(
|
||||
"OpenOfficeMetadataExtracter-", "."
|
||||
+ getMimetypeService().getExtension(sourceMimetype));
|
||||
// download the content from the source reader
|
||||
reader.getContent(tempFromFile);
|
||||
|
||||
String sourceUrl = toUrl(tempFromFile, connection);
|
||||
|
||||
// UNO Interprocess Bridge *should* be thread-safe, but...
|
||||
XComponentLoader desktop = connection.getDesktop();
|
||||
XComponent document = desktop.loadComponentFromURL(
|
||||
sourceUrl,
|
||||
"_blank",
|
||||
0,
|
||||
new PropertyValue[] { property("Hidden", Boolean.TRUE) });
|
||||
if (document == null)
|
||||
Map<String, Serializable> result = this.worker.extractRaw(reader);
|
||||
for (Map.Entry<String, Serializable> entry : result.entrySet())
|
||||
{
|
||||
throw new FileNotFoundException("could not open source document: " + sourceUrl);
|
||||
putRawValue(entry.getKey(), entry.getValue(), rawProperties);
|
||||
}
|
||||
try
|
||||
{
|
||||
XDocumentInfoSupplier infoSupplier = (XDocumentInfoSupplier) UnoRuntime.queryInterface(
|
||||
XDocumentInfoSupplier.class, document);
|
||||
XPropertySet propSet = (XPropertySet) UnoRuntime.queryInterface(
|
||||
XPropertySet.class,
|
||||
infoSupplier
|
||||
.getDocumentInfo());
|
||||
|
||||
putRawValue(KEY_TITLE, propSet.getPropertyValue("Title").toString(), rawProperties);
|
||||
putRawValue(KEY_DESCRIPTION, propSet.getPropertyValue("Subject").toString(), rawProperties);
|
||||
putRawValue(KEY_AUTHOR, propSet.getPropertyValue("Author").toString(), rawProperties);
|
||||
}
|
||||
finally
|
||||
{
|
||||
document.dispose();
|
||||
}
|
||||
// Done
|
||||
return rawProperties;
|
||||
}
|
||||
|
||||
public String toUrl(File file, OpenOfficeConnection connection) throws ConnectException
|
||||
{
|
||||
Object fcp = connection.getFileContentProvider();
|
||||
XFileIdentifierConverter fic = (XFileIdentifierConverter) UnoRuntime.queryInterface(
|
||||
XFileIdentifierConverter.class, fcp);
|
||||
return fic.getFileURLFromSystemPath("", file.getAbsolutePath());
|
||||
}
|
||||
|
||||
private static PropertyValue property(String name, Object value)
|
||||
{
|
||||
PropertyValue property = new PropertyValue();
|
||||
property.Name = name;
|
||||
property.Value = value;
|
||||
return property;
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,10 @@ public class OpenOfficeMetadataExtracterTest extends AbstractMetadataExtracterTe
|
||||
extracter = new OpenOfficeMetadataExtracter();
|
||||
extracter.setMimetypeService(mimetypeMap);
|
||||
extracter.setDictionaryService(dictionaryService);
|
||||
extracter.setConnection(connection);
|
||||
DefaultOpenOfficeMetadataWorker worker = new DefaultOpenOfficeMetadataWorker();
|
||||
worker.setConnection(connection);
|
||||
worker.setMimetypeService(mimetypeMap);
|
||||
extracter.setWorker(worker);
|
||||
extracter.init();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.content.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
|
||||
/**
|
||||
* An interface that allows separation between the metadata extractor registry and the third party subsystem owning the
|
||||
* open office connection.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public interface OpenOfficeMetadataWorker
|
||||
{
|
||||
/**
|
||||
* @return Returns true if a connection to the Uno server could be established
|
||||
*/
|
||||
public boolean isConnected();
|
||||
|
||||
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable;
|
||||
}
|
@@ -24,16 +24,12 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.ContentAccessor;
|
||||
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.service.cmr.repository.TransformationOptions;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -48,13 +44,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @author Derek Hulley
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class AbstractContentTransformer2 implements ContentTransformer
|
||||
public abstract class AbstractContentTransformer2 extends ContentTransformerHelper implements ContentTransformer
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(AbstractContentTransformer2.class);
|
||||
|
||||
private MimetypeService mimetypeService;
|
||||
private ContentTransformerRegistry registry;
|
||||
private List<ExplictTransformationDetails> explicitTransformations;
|
||||
private double averageTime = 0.0;
|
||||
private long count = 0L;
|
||||
|
||||
@@ -64,7 +58,6 @@ public abstract class AbstractContentTransformer2 implements ContentTransformer
|
||||
protected AbstractContentTransformer2()
|
||||
{
|
||||
averageTime = 0.0;
|
||||
explicitTransformations = new ArrayList<ExplictTransformationDetails>(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,31 +68,7 @@ public abstract class AbstractContentTransformer2 implements ContentTransformer
|
||||
public void setRegistry(ContentTransformerRegistry registry)
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper setter of the mimetype service. This is not always required.
|
||||
*
|
||||
* @param mimetypeService
|
||||
*/
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the mimetype helper
|
||||
*/
|
||||
protected MimetypeService getMimetypeService()
|
||||
{
|
||||
return mimetypeService;
|
||||
}
|
||||
|
||||
public void setExplicitTransformations(List<ExplictTransformationDetails> explicitTransformations)
|
||||
{
|
||||
this.explicitTransformations = explicitTransformations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
@@ -128,24 +97,6 @@ public abstract class AbstractContentTransformer2 implements ContentTransformer
|
||||
registry.addTransformer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience to fetch and check the mimetype for the given content
|
||||
*
|
||||
* @param content the reader/writer for the content
|
||||
* @return Returns the mimetype for the content
|
||||
* @throws AlfrescoRuntimeException if the content doesn't have a mimetype
|
||||
*/
|
||||
protected String getMimetype(ContentAccessor content)
|
||||
{
|
||||
String mimetype = content.getMimetype();
|
||||
if (mimetype == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Mimetype is mandatory for transformation: " + content);
|
||||
}
|
||||
// done
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to check the transformability of a transformation
|
||||
*
|
||||
@@ -270,26 +221,6 @@ public abstract class AbstractContentTransformer2 implements ContentTransformer
|
||||
this.transform(reader, writer, new TransformationOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation, override if need to extend logic
|
||||
*
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformer#isExplicitTransformation(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
|
||||
*/
|
||||
public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
boolean result = false;
|
||||
for (ExplictTransformationDetails explicitTransformation : this.explicitTransformations)
|
||||
{
|
||||
if (sourceMimetype.equals(explicitTransformation.getSourceMimetype()) == true &&
|
||||
targetMimetype.equals(explicitTransformation.getTargetMimetype()) == true)
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the calculated running average of the current transformations
|
||||
*/
|
||||
|
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.ContentAccessor;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
|
||||
/**
|
||||
* A class providing basic functionality shared by both {@link ContentTransformer}s and {@link ContentTransformerWorker}
|
||||
* s.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class ContentTransformerHelper
|
||||
{
|
||||
|
||||
private MimetypeService mimetypeService;
|
||||
private List<ExplictTransformationDetails> explicitTransformations;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ContentTransformerHelper()
|
||||
{
|
||||
setExplicitTransformations(Collections.<ExplictTransformationDetails> emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper setter of the mimetype service. This is not always required.
|
||||
*
|
||||
* @param mimetypeService
|
||||
*/
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the mimetype helper
|
||||
*/
|
||||
protected MimetypeService getMimetypeService()
|
||||
{
|
||||
return mimetypeService;
|
||||
}
|
||||
|
||||
public void setExplicitTransformations(List<ExplictTransformationDetails> explicitTransformations)
|
||||
{
|
||||
this.explicitTransformations = explicitTransformations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience to fetch and check the mimetype for the given content
|
||||
*
|
||||
* @param content
|
||||
* the reader/writer for the content
|
||||
* @return Returns the mimetype for the content
|
||||
* @throws AlfrescoRuntimeException
|
||||
* if the content doesn't have a mimetype
|
||||
*/
|
||||
protected String getMimetype(ContentAccessor content)
|
||||
{
|
||||
String mimetype = content.getMimetype();
|
||||
if (mimetype == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Mimetype is mandatory for transformation: " + content);
|
||||
}
|
||||
// done
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation, override if need to extend logic
|
||||
*
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformer#isExplicitTransformation(java.lang.String,
|
||||
* java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
|
||||
*/
|
||||
public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
boolean result = false;
|
||||
for (ExplictTransformationDetails explicitTransformation : this.explicitTransformations)
|
||||
{
|
||||
if (sourceMimetype.equals(explicitTransformation.getSourceMimetype()) == true
|
||||
&& targetMimetype.equals(explicitTransformation.getTargetMimetype()) == true)
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
|
||||
/**
|
||||
* An interface that allows separation between the content transformer registry and the various third party subsystems
|
||||
* performing the transformation.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public interface ContentTransformerWorker
|
||||
{
|
||||
/**
|
||||
* Checks if this worker is available.
|
||||
*
|
||||
* @return true if it is available
|
||||
*/
|
||||
public boolean isAvailable();
|
||||
|
||||
/**
|
||||
* Gets a string returning product and version information.
|
||||
*
|
||||
* @return the version string
|
||||
*/
|
||||
public String getVersionString();
|
||||
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options);
|
||||
|
||||
public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception;
|
||||
}
|
@@ -37,7 +37,7 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.content.transform.OpenOfficeContentTransformer
|
||||
* @see org.alfresco.repo.content.transform.OpenOfficeContentTransformerWorker
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
@@ -45,7 +45,8 @@ public class OpenOfficeContentTransformerTest extends AbstractContentTransformer
|
||||
{
|
||||
private static String MIMETYPE_RUBBISH = "text/rubbish";
|
||||
|
||||
private OpenOfficeContentTransformer transformer;
|
||||
private OpenOfficeContentTransformerWorker worker;
|
||||
private ContentTransformer transformer;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
@@ -54,11 +55,15 @@ public class OpenOfficeContentTransformerTest extends AbstractContentTransformer
|
||||
|
||||
OpenOfficeConnection connection = (OpenOfficeConnection) ctx.getBean("openOfficeConnection");
|
||||
|
||||
transformer = new OpenOfficeContentTransformer();
|
||||
this.worker = new OpenOfficeContentTransformerWorker();
|
||||
worker.setMimetypeService(mimetypeService);
|
||||
worker.setConnection(connection);
|
||||
worker.setDocumentFormatsConfiguration("classpath:alfresco/mimetype/openoffice-document-formats.xml");
|
||||
worker.afterPropertiesSet();
|
||||
ProxyContentTransformer transformer = new ProxyContentTransformer();
|
||||
transformer.setMimetypeService(mimetypeService);
|
||||
transformer.setConnection(connection);
|
||||
transformer.setDocumentFormatsConfiguration("classpath:alfresco/mimetype/openoffice-document-formats.xml");
|
||||
transformer.register();
|
||||
transformer.setWorker(worker);
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +82,7 @@ public class OpenOfficeContentTransformerTest extends AbstractContentTransformer
|
||||
|
||||
public void testReliability() throws Exception
|
||||
{
|
||||
if (!transformer.isConnected())
|
||||
if (!worker.isAvailable())
|
||||
{
|
||||
// no connection
|
||||
return;
|
||||
@@ -99,7 +104,7 @@ public class OpenOfficeContentTransformerTest extends AbstractContentTransformer
|
||||
*/
|
||||
public void testHtmlToPdf() throws Exception
|
||||
{
|
||||
if (!transformer.isConnected())
|
||||
if (!worker.isAvailable())
|
||||
{
|
||||
// no connection
|
||||
return;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -18,7 +18,7 @@
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
@@ -46,27 +46,25 @@ import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
|
||||
/**
|
||||
* Makes use of the {@link http://sourceforge.net/projects/joott/ JOOConverter} library to
|
||||
* perform OpenOffice-drive conversions.
|
||||
* Makes use of the {@link http://sourceforge.net/projects/joott/JOOConverter} library to perform OpenOffice-drive
|
||||
* conversions.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
public class OpenOfficeContentTransformerWorker extends ContentTransformerHelper implements ContentTransformerWorker, InitializingBean
|
||||
{
|
||||
private OpenOfficeConnection connection;
|
||||
private AbstractOpenOfficeDocumentConverter converter;
|
||||
private String documentFormatsConfiguration;
|
||||
private DocumentFormatRegistry formatRegistry;
|
||||
|
||||
public OpenOfficeContentTransformer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param connection the connection that the converter uses
|
||||
* @param connection
|
||||
* the connection that the converter uses
|
||||
*/
|
||||
public void setConnection(OpenOfficeConnection connection)
|
||||
{
|
||||
@@ -74,12 +72,13 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly set the converter to be used. The converter must use the same connection
|
||||
* set in {@link #setConnection(OpenOfficeConnection)}.
|
||||
* Explicitly set the converter to be used. The converter must use the same connection set in
|
||||
* {@link #setConnection(OpenOfficeConnection)}.
|
||||
* <p>
|
||||
* If not set, then the <code>OpenOfficeDocumentConverter</code> will be used.
|
||||
*
|
||||
* @param converter the converter to use.
|
||||
* @param converter
|
||||
* the converter to use.
|
||||
*/
|
||||
public void setConverter(AbstractOpenOfficeDocumentConverter converter)
|
||||
{
|
||||
@@ -89,51 +88,48 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
/**
|
||||
* 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
|
||||
* @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()
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return connection.isConnected();
|
||||
return this.connection.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register()
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory("OpenOfficeContentTransformer", "connection", connection);
|
||||
|
||||
PropertyCheck.mandatory("OpenOfficeContentTransformerWorker", "connection", this.connection);
|
||||
|
||||
// load the document conversion configuration
|
||||
if (documentFormatsConfiguration != null)
|
||||
if (this.documentFormatsConfiguration != null)
|
||||
{
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
try
|
||||
{
|
||||
InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream();
|
||||
formatRegistry = new XmlDocumentFormatRegistry(is);
|
||||
InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream();
|
||||
this.formatRegistry = new XmlDocumentFormatRegistry(is);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"Unable to load document formats configuration file: " + documentFormatsConfiguration);
|
||||
throw new AlfrescoRuntimeException("Unable to load document formats configuration file: "
|
||||
+ this.documentFormatsConfiguration);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
formatRegistry = new XmlDocumentFormatRegistry();
|
||||
this.formatRegistry = new XmlDocumentFormatRegistry();
|
||||
}
|
||||
|
||||
|
||||
// set up the converter
|
||||
if (converter == null)
|
||||
if (this.converter == null)
|
||||
{
|
||||
converter = new OpenOfficeDocumentConverter(connection);
|
||||
this.converter = new OpenOfficeDocumentConverter(this.connection);
|
||||
}
|
||||
|
||||
// Register
|
||||
super.register();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,12 +137,12 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (!isConnected())
|
||||
if (!isAvailable())
|
||||
{
|
||||
// The connection management is must take care of this
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// there are some conversions that fail, despite the converter believing them possible
|
||||
if (targetMimetype.equals(MimetypeMap.MIMETYPE_XHTML))
|
||||
{
|
||||
@@ -160,19 +156,19 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
DocumentFormat sourceFormat = this.formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
if (sourceFormat == null)
|
||||
{
|
||||
// no document format
|
||||
return false;
|
||||
}
|
||||
// query the registry for the target format
|
||||
DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// no document format
|
||||
@@ -193,10 +189,7 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
}
|
||||
}
|
||||
|
||||
protected void transformInternal(
|
||||
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);
|
||||
@@ -205,14 +198,14 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
// query the registry for the source format
|
||||
DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension);
|
||||
DocumentFormat sourceFormat = this.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);
|
||||
DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension);
|
||||
if (targetFormat == null)
|
||||
{
|
||||
// target format is not recognised
|
||||
@@ -223,38 +216,41 @@ public class OpenOfficeContentTransformer extends AbstractContentTransformer2
|
||||
// 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);
|
||||
// download the content from the source reader
|
||||
reader.getContent(tempFromFile);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
|
||||
this.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);
|
||||
}
|
||||
|
||||
|
||||
// upload the temp output to the writer given us
|
||||
writer.putContent(tempToFile);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformerWorker#getVersionString()
|
||||
*/
|
||||
public String getVersionString()
|
||||
{
|
||||
// Actual version information owned by OpenOfficeConnectionTester
|
||||
return "";
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import net.sf.jooreports.converter.DocumentFormatRegistry;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
|
||||
/**
|
||||
* Makes use of a {@link ContentTransformerWorker} to perform conversions.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class ProxyContentTransformer extends AbstractContentTransformer2
|
||||
{
|
||||
private ContentTransformerWorker worker;
|
||||
|
||||
public ProxyContentTransformer()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worker
|
||||
* the worker that the converter uses
|
||||
*/
|
||||
public void setWorker(ContentTransformerWorker worker)
|
||||
{
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DocumentFormatRegistry
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return this.worker.isTransformable(sourceMimetype, targetMimetype, options);
|
||||
}
|
||||
|
||||
protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
|
||||
throws Exception
|
||||
{
|
||||
this.worker.transform(reader, writer, options);
|
||||
}
|
||||
}
|
@@ -39,20 +39,20 @@ import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.exec.RuntimeExec;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.content.transform.RuntimeExecutableContentTransformer
|
||||
* @see org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class RuntimeExecutableContentTransformerTest extends BaseAlfrescoTestCase
|
||||
{
|
||||
private RuntimeExecutableContentTransformer transformer;
|
||||
private ContentTransformer transformer;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
transformer = new RuntimeExecutableContentTransformer();
|
||||
RuntimeExecutableContentTransformerWorker worker = new RuntimeExecutableContentTransformerWorker();
|
||||
// the command to execute
|
||||
RuntimeExec transformCommand = new RuntimeExec();
|
||||
Map<String, String> commandMap = new HashMap<String, String>(5);
|
||||
@@ -61,16 +61,21 @@ public class RuntimeExecutableContentTransformerTest extends BaseAlfrescoTestCas
|
||||
commandMap.put(".*", "cmd /c copy /Y \"${source}\" \"${target}\"");
|
||||
transformCommand.setCommandMap(commandMap);
|
||||
transformCommand.setErrorCodes("1, 2");
|
||||
transformer.setTransformCommand(transformCommand);
|
||||
transformer.setMimetypeService(serviceRegistry.getMimetypeService());
|
||||
worker.setTransformCommand(transformCommand);
|
||||
worker.setMimetypeService(serviceRegistry.getMimetypeService());
|
||||
// set the explicit transformations
|
||||
List<ExplictTransformationDetails> explicitTranformations = new ArrayList<ExplictTransformationDetails>(1);
|
||||
explicitTranformations.add(
|
||||
new ExplictTransformationDetails(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_XML));
|
||||
transformer.setExplicitTransformations(explicitTranformations);
|
||||
worker.setExplicitTransformations(explicitTranformations);
|
||||
|
||||
// initialise so that it doesn't score 0
|
||||
transformer.register();
|
||||
worker.afterPropertiesSet();
|
||||
|
||||
ProxyContentTransformer transformer = new ProxyContentTransformer();
|
||||
transformer.setMimetypeService(serviceRegistry.getMimetypeService());
|
||||
transformer.setWorker(worker);
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
public void testCopyCommand() throws Exception
|
||||
|
@@ -39,6 +39,7 @@ import org.alfresco.util.exec.RuntimeExec;
|
||||
import org.alfresco.util.exec.RuntimeExec.ExecutionResult;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* This configurable wrapper is able to execute any command line transformation that
|
||||
@@ -67,12 +68,12 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @since 1.1
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class RuntimeExecutableContentTransformer extends AbstractContentTransformer2
|
||||
public class RuntimeExecutableContentTransformerWorker extends ContentTransformerHelper implements ContentTransformerWorker, InitializingBean
|
||||
{
|
||||
public static final String VAR_SOURCE = "source";
|
||||
public static final String VAR_TARGET = "target";
|
||||
|
||||
private static Log logger = LogFactory.getLog(RuntimeExecutableContentTransformer.class);
|
||||
private static Log logger = LogFactory.getLog(RuntimeExecutableContentTransformerWorker.class);
|
||||
|
||||
private boolean available;
|
||||
private RuntimeExec checkCommand;
|
||||
@@ -81,7 +82,7 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
|
||||
/** Stores the output from the check command */
|
||||
private String versionString;
|
||||
|
||||
public RuntimeExecutableContentTransformer()
|
||||
public RuntimeExecutableContentTransformerWorker()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -130,13 +131,13 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
|
||||
throw new AlfrescoRuntimeException("content.runtime_exec.property_moved");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the check command, if present. Any errors will result in this component
|
||||
* being rendered unusable within the transformer registry, but may still be called
|
||||
* directly.
|
||||
*/
|
||||
@Override
|
||||
public void register()
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
if (transformCommand == null)
|
||||
{
|
||||
@@ -162,8 +163,6 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
|
||||
// no check - just assume it is available
|
||||
available = true;
|
||||
}
|
||||
// call the base class to make sure that it gets registered
|
||||
super.register();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +180,7 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isExplicitTransformation(sourceMimetype, targetMimetype, options) == true)
|
||||
if (isExplicitTransformation(sourceMimetype, targetMimetype, options))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -217,7 +216,7 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
|
||||
*
|
||||
* @see #transformInternal(File, File)
|
||||
*/
|
||||
protected final void transformInternal(
|
||||
public final void transform(
|
||||
ContentReader reader,
|
||||
ContentWriter writer,
|
||||
TransformationOptions options) throws Exception
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -18,7 +18,7 @@
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* FLOSS exception. You should have received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
@@ -30,30 +30,33 @@ import java.io.InputStream;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.filestore.FileContentWriter;
|
||||
import org.alfresco.repo.content.transform.AbstractContentTransformer2;
|
||||
import org.alfresco.repo.content.transform.ContentTransformerHelper;
|
||||
import org.alfresco.repo.content.transform.ContentTransformerWorker;
|
||||
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.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* Abstract helper for transformations based on <b>ImageMagick</b>
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public abstract class AbstractImageMagickContentTransformer extends AbstractContentTransformer2
|
||||
public abstract class AbstractImageMagickContentTransformerWorker extends ContentTransformerHelper implements ContentTransformerWorker, InitializingBean
|
||||
{
|
||||
/** the prefix for mimetypes supported by the transformer */
|
||||
public static final String MIMETYPE_IMAGE_PREFIX = "image/";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AbstractImageMagickContentTransformer.class);
|
||||
private static final Log logger = LogFactory.getLog(AbstractImageMagickContentTransformerWorker.class);
|
||||
|
||||
private boolean available;
|
||||
|
||||
public AbstractImageMagickContentTransformer()
|
||||
public AbstractImageMagickContentTransformerWorker()
|
||||
{
|
||||
this.available = false;
|
||||
}
|
||||
@@ -82,7 +85,7 @@ public abstract class AbstractImageMagickContentTransformer extends AbstractCont
|
||||
* <p>
|
||||
* If initialization is successful, then autoregistration takes place.
|
||||
*/
|
||||
public void init()
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
if (getMimetypeService() == null)
|
||||
{
|
||||
@@ -120,10 +123,7 @@ public abstract class AbstractImageMagickContentTransformer extends AbstractCont
|
||||
" to: " + outputFile);
|
||||
}
|
||||
// we can be sure that it works
|
||||
setAvailable(true);
|
||||
|
||||
// register
|
||||
super.register();
|
||||
setAvailable(true);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
@@ -171,8 +171,8 @@ public abstract class AbstractImageMagickContentTransformer extends AbstractCont
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!AbstractImageMagickContentTransformer.isSupported(sourceMimetype) ||
|
||||
!AbstractImageMagickContentTransformer.isSupported(targetMimetype))
|
||||
if (!AbstractImageMagickContentTransformerWorker.isSupported(sourceMimetype) ||
|
||||
!AbstractImageMagickContentTransformerWorker.isSupported(targetMimetype))
|
||||
{
|
||||
// only support IMAGE -> IMAGE (excl. RGB)
|
||||
return false;
|
||||
@@ -186,7 +186,7 @@ public abstract class AbstractImageMagickContentTransformer extends AbstractCont
|
||||
/**
|
||||
* @see #transformInternal(File, File)
|
||||
*/
|
||||
protected final void transformInternal(
|
||||
public final void transform(
|
||||
ContentReader reader,
|
||||
ContentWriter writer,
|
||||
TransformationOptions options) throws Exception
|
||||
@@ -196,8 +196,9 @@ public abstract class AbstractImageMagickContentTransformer extends AbstractCont
|
||||
String targetMimetype = getMimetype(writer);
|
||||
|
||||
// get the extensions to use
|
||||
String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
|
||||
String targetExtension = getMimetypeService().getExtension(targetMimetype);
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
String targetExtension = mimetypeService.getExtension(targetMimetype);
|
||||
if (sourceExtension == null || targetExtension == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unknown extensions for mimetypes: \n" +
|
@@ -29,6 +29,7 @@ import java.util.Collections;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
|
||||
import org.alfresco.repo.content.transform.ContentTransformer;
|
||||
import org.alfresco.repo.content.transform.ProxyContentTransformer;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.util.exec.RuntimeExec;
|
||||
|
||||
@@ -39,7 +40,8 @@ import org.alfresco.util.exec.RuntimeExec;
|
||||
*/
|
||||
public class ImageMagickContentTransformerTest extends AbstractContentTransformerTest
|
||||
{
|
||||
private ImageMagickContentTransformer transformer;
|
||||
private ImageMagickContentTransformerWorker worker;
|
||||
private ContentTransformer transformer;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
@@ -50,10 +52,15 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
|
||||
executer.setCommand(new String[] {"imconvert.exe", "${source}", "${options}", "${target}"});
|
||||
executer.setDefaultProperties(Collections.singletonMap("options", ""));
|
||||
|
||||
transformer = new ImageMagickContentTransformer();
|
||||
this.worker = new ImageMagickContentTransformerWorker();
|
||||
worker.setMimetypeService(mimetypeService);
|
||||
worker.setExecuter(executer);
|
||||
worker.afterPropertiesSet();
|
||||
|
||||
ProxyContentTransformer transformer = new ProxyContentTransformer();
|
||||
transformer.setMimetypeService(mimetypeService);
|
||||
transformer.setExecuter(executer);
|
||||
transformer.init();
|
||||
this.transformer = transformer;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +73,7 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
|
||||
|
||||
public void testReliability() throws Exception
|
||||
{
|
||||
if (!transformer.isAvailable())
|
||||
if (!this.worker.isAvailable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -41,7 +41,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class ImageMagickContentTransformer extends AbstractImageMagickContentTransformer
|
||||
public class ImageMagickContentTransformerWorker extends AbstractImageMagickContentTransformerWorker
|
||||
{
|
||||
/** options variable name */
|
||||
private static final String KEY_OPTIONS = "options";
|
||||
@@ -50,7 +50,7 @@ public class ImageMagickContentTransformer extends AbstractImageMagickContentTra
|
||||
/** target variable name */
|
||||
private static final String VAR_TARGET = "target";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ImageMagickContentTransformer.class);
|
||||
private static final Log logger = LogFactory.getLog(ImageMagickContentTransformerWorker.class);
|
||||
|
||||
/** the system command executer */
|
||||
private RuntimeExec executer;
|
||||
@@ -64,7 +64,7 @@ public class ImageMagickContentTransformer extends AbstractImageMagickContentTra
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ImageMagickContentTransformer()
|
||||
public ImageMagickContentTransformerWorker()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -110,31 +110,28 @@ public class ImageMagickContentTransformer extends AbstractImageMagickContentTra
|
||||
return this.versionString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks for the JMagick and ImageMagick dependencies, using the common
|
||||
* {@link #transformInternal(File, File) transformation method} to check
|
||||
* that the sample image can be converted.
|
||||
*/
|
||||
public void init()
|
||||
@Override
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
if (executer == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("System runtime executer not set");
|
||||
}
|
||||
super.init();
|
||||
super.afterPropertiesSet();
|
||||
if (isAvailable())
|
||||
{
|
||||
try
|
||||
{
|
||||
// On some platforms / versions, the -version command seems to return an error code whilst still
|
||||
// returning output, so let's not worry about the exit code!
|
||||
ExecutionResult result = this.checkCommand.execute();
|
||||
if (result.getSuccess())
|
||||
{
|
||||
this.versionString = result.getStdOut().trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
setAvailable(false);
|
||||
}
|
||||
this.versionString = result.getStdOut().trim();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
Reference in New Issue
Block a user