mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
57476: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 57286: Merged V4.1-BUG-FIX (4.1.7) to V4.2-BUG-FIX (4.2.1) 57220: MNT-9350: Registered Mimetypes WebScript doesn't know about the Alfresco Transformation Server - Added the notion of known workers and label message map - Added ability to override the label message map for custom implementations - Separated building of labels for complex and proxy transformers into their own methods - Added message formatting for bean names git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61818 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.content;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -34,6 +35,7 @@ import org.alfresco.repo.content.transform.ProxyContentTransformer;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
@@ -49,23 +51,25 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* @author Nick Burch
|
||||
* @since 3.4.b
|
||||
*/
|
||||
public class MimetypesGet extends DeclarativeWebScript implements ApplicationContextAware
|
||||
public class MimetypesGet extends DeclarativeWebScript implements ApplicationContextAware, InitializingBean
|
||||
{
|
||||
public static final String MODEL_MIMETYPES = "mimetypes";
|
||||
public static final String MODEL_EXTENSIONS = "extensions";
|
||||
public static final String MODEL_MIMETYPE_DETAILS = "details";
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private MimetypeService mimetypeService;
|
||||
private ContentTransformerRegistry contentTransformerRegistry;
|
||||
private MetadataExtracterRegistry metadataExtracterRegistry;
|
||||
|
||||
/** So we can spot if it goes via Direct OO */
|
||||
ContentTransformerWorker ooDirectWorker;
|
||||
protected static final String OODIRECT_WORKER_BEAN = "transformer.worker.OpenOffice";
|
||||
|
||||
/** So we can spot if it goes through JODConverter */
|
||||
ContentTransformerWorker jodWorker;
|
||||
private Map<String, String> knownWorkerBeanLabels;
|
||||
private Map<ContentTransformerWorker, String> knownWorkers;
|
||||
|
||||
protected static final String OODIRECT_WORKER_BEAN = "transformer.worker.OpenOffice";
|
||||
protected static final String JOD_WORKER_BEAN = "transformer.worker.JodConverter";
|
||||
protected static final String RTS_WORKER_BEAN = "transformer.worker.remoteServer";
|
||||
|
||||
protected static final String PROXY_LABEL_DEFAULT_MESSAGE = "Proxy via: {0} ({1})";
|
||||
|
||||
/**
|
||||
* Uses the context to find OpenOffice related beans.
|
||||
@@ -74,23 +78,34 @@ public class MimetypesGet extends DeclarativeWebScript implements ApplicationCon
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
if(applicationContext.containsBean(OODIRECT_WORKER_BEAN))
|
||||
{
|
||||
Object bean = applicationContext.getBean(OODIRECT_WORKER_BEAN);
|
||||
if(bean instanceof ContentTransformerWorker)
|
||||
{
|
||||
ooDirectWorker = (ContentTransformerWorker)bean;
|
||||
}
|
||||
}
|
||||
|
||||
if(applicationContext.containsBean(JOD_WORKER_BEAN))
|
||||
{
|
||||
Object bean = applicationContext.getBean(JOD_WORKER_BEAN);
|
||||
if(bean instanceof ContentTransformerWorker)
|
||||
{
|
||||
jodWorker = (ContentTransformerWorker)bean;
|
||||
}
|
||||
}
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
// If no override has been supplied use the default known list
|
||||
if (knownWorkerBeanLabels == null)
|
||||
{
|
||||
knownWorkerBeanLabels = new HashMap<String, String>();
|
||||
knownWorkerBeanLabels.put(OODIRECT_WORKER_BEAN, "Using a Direct Open Office Connection");
|
||||
knownWorkerBeanLabels.put(JOD_WORKER_BEAN, "Using JOD Converter / Open Office");
|
||||
knownWorkerBeanLabels.put(RTS_WORKER_BEAN, "Using the Remote Transformation Server v{1}");
|
||||
}
|
||||
|
||||
// Build the map of known worker bean instances to bean names
|
||||
knownWorkers = new HashMap<ContentTransformerWorker, String>();
|
||||
for (String workerName : knownWorkerBeanLabels.keySet())
|
||||
{
|
||||
if(applicationContext.containsBean(workerName))
|
||||
{
|
||||
Object bean = applicationContext.getBean(workerName);
|
||||
if(bean instanceof ContentTransformerWorker)
|
||||
{
|
||||
knownWorkers.put((ContentTransformerWorker) bean, workerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +134,17 @@ public class MimetypesGet extends DeclarativeWebScript implements ApplicationCon
|
||||
this.metadataExtracterRegistry = metadataExtracterRegistry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the map of content transformer worker bean names to
|
||||
* message formatting labels
|
||||
*
|
||||
* @param knownWorkerBeanLabels
|
||||
*/
|
||||
public void setKnownWorkerBeanLabels(Map<String, String> knownWorkerBeanLabels)
|
||||
{
|
||||
this.knownWorkerBeanLabels = knownWorkerBeanLabels;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
@@ -210,30 +235,67 @@ public class MimetypesGet extends DeclarativeWebScript implements ApplicationCon
|
||||
|
||||
if(ct instanceof ComplexContentTransformer)
|
||||
{
|
||||
ComplexContentTransformer cct = (ComplexContentTransformer)ct;
|
||||
String text = "Complex via: ";
|
||||
for(String imt : cct.getIntermediateMimetypes()) {
|
||||
text += imt + " ";
|
||||
}
|
||||
return text;
|
||||
return getComplexTransformerLabel((ComplexContentTransformer)ct);
|
||||
}
|
||||
|
||||
if(ct instanceof ProxyContentTransformer)
|
||||
{
|
||||
ProxyContentTransformer pct = (ProxyContentTransformer)ct;
|
||||
ContentTransformerWorker ctw = pct.getWorker();
|
||||
|
||||
if(ctw.equals(jodWorker))
|
||||
return "Using JOD Converter / Open Office";
|
||||
if(ctw.equals(ooDirectWorker))
|
||||
return "Using a Direct Open Office Connection";
|
||||
|
||||
String text = "Proxy via: " +
|
||||
ctw.getClass().getName() +
|
||||
"(" + ctw.getVersionString() + ")";
|
||||
return text;
|
||||
String proxyLabel = getProxyTransformerLabel((ProxyContentTransformer)ct);
|
||||
if (proxyLabel != null)
|
||||
{
|
||||
return proxyLabel;
|
||||
}
|
||||
}
|
||||
|
||||
return ct.getClass().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display label for complex transformers
|
||||
*
|
||||
* @param cct
|
||||
* @return the transformer display label
|
||||
*/
|
||||
protected String getComplexTransformerLabel(ComplexContentTransformer cct)
|
||||
{
|
||||
String text = "Complex via: ";
|
||||
for(String imt : cct.getIntermediateMimetypes()) {
|
||||
text += imt + " ";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display label for proxy content transformers
|
||||
*
|
||||
* @param pct
|
||||
* @return the transformer display label
|
||||
*/
|
||||
protected String getProxyTransformerLabel(ProxyContentTransformer pct)
|
||||
{
|
||||
ContentTransformerWorker ctw = pct.getWorker();
|
||||
|
||||
String message = PROXY_LABEL_DEFAULT_MESSAGE;
|
||||
|
||||
String beanName = getWorkerBeanName(ctw);
|
||||
if (beanName != null)
|
||||
{
|
||||
message = knownWorkerBeanLabels.get(beanName);
|
||||
}
|
||||
return MessageFormat.format(message, ctw.getClass().getName(), ctw.getVersionString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given ContentTransformerWorker's bean name from the cache of known workers
|
||||
* <p>
|
||||
* In the future ContentTransformerWorker may be made bean name aware.
|
||||
*
|
||||
* @param ctw
|
||||
* @return the bean name
|
||||
*/
|
||||
protected String getWorkerBeanName(ContentTransformerWorker ctw)
|
||||
{
|
||||
return knownWorkers.get(ctw);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user