From 9160578c9a05cb00ece1c8cf382c0f44b258f771 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Thu, 26 Jan 2006 13:46:46 +0000 Subject: [PATCH] Mimetypes available for transform action in the UI are now defined in an overrideable bean git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2216 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web-client-application-context.xml | 15 +++ config/alfresco/web-client-config.xml | 2 + .../web/bean/wizard/BaseActionWizard.java | 97 +++++++++---------- source/web/WEB-INF/faces-config.xml | 8 ++ source/web/WEB-INF/web_TEMPLATE.xml | 2 +- 5 files changed, 70 insertions(+), 54 deletions(-) diff --git a/config/alfresco/web-client-application-context.xml b/config/alfresco/web-client-application-context.xml index 568fb33106..1988a00f2c 100644 --- a/config/alfresco/web-client-application-context.xml +++ b/config/alfresco/web-client-application-context.xml @@ -25,5 +25,20 @@ + + + + + + text/html + application/pdf + text/plain + text/xml + application/x-shockwave-flash + image/gif + image/jpeg + + + diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index 2f2c2e4dff..95b02d4390 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -304,6 +304,7 @@ + diff --git a/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java b/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java index 4a87c98508..ad24610bb6 100644 --- a/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java +++ b/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java @@ -18,6 +18,7 @@ package org.alfresco.web.bean.wizard; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,7 +42,6 @@ import org.alfresco.repo.action.executer.MoveActionExecuter; import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; import org.alfresco.repo.action.executer.TransformActionExecuter; -import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.AspectDefinition; @@ -99,6 +99,7 @@ public abstract class BaseActionWizard extends AbstractWizardBean protected DictionaryService dictionaryService; protected MimetypeService mimetypeService; protected List actions; + private List transformMimetypes; protected List transformers; protected List imageTransformers; protected List aspects; @@ -108,6 +109,16 @@ public abstract class BaseActionWizard extends AbstractWizardBean protected Map currentActionProperties; protected List objectTypes; + /** + * Set the available mimetypes to act as targets of transformations + * + * @param mimetypes a list of valid mimetypes + */ + public void setTransformMimetypes(List mimetypes) + { + this.transformMimetypes = mimetypes; + } + /** * Initialises the wizard */ @@ -615,60 +626,40 @@ public abstract class BaseActionWizard extends AbstractWizardBean */ public List getTransformers() { - if (this.transformers == null) + if (this.transformers != null) { - ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext( - FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE); - Config wizardCfg = svc.getConfig("Action Wizards"); - if (wizardCfg != null) - { - ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers"); - if (transformersCfg != null) - { - FacesContext context = FacesContext.getCurrentInstance(); - Map mimeTypes = this.mimetypeService.getDisplaysByMimetype(); - this.transformers = new ArrayList(); - for (ConfigElement child : transformersCfg.getChildren()) - { - String id = child.getAttribute("name"); - - // look for a client localized string - String label = null; - String msgId = child.getAttribute("displayLabelId"); - if (msgId != null) - { - label = Application.getMessage(context, msgId); - } - - // if there wasn't an externalized string look for one in the config - if (label == null) - { - label = child.getAttribute("displayLabel"); - } - - // if there wasn't a client based label get it from the mime type service - if (label == null) - { - label = mimeTypes.get(id); - } - - this.transformers.add(new SelectItem(id, label)); - } - - // make sure the list is sorted by the label - QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE); - sorter.sort(); - } - else - { - logger.warn("Could not find transformers configuration element"); - } - } - else - { - logger.warn("Could not find Action Wizards configuration section"); - } + return this.transformers; } + // check that the mimetypes are available + if (this.transformMimetypes == null) + { + logger.warn("'transformMimetypes' property was not set"); + this.transformMimetypes = Collections.emptyList(); + } + + this.transformers = new ArrayList(10); + + Map displaysByMimetype = this.mimetypeService.getDisplaysByMimetype(); + for (String mimetype : this.transformMimetypes) + { + // get the display label + String label = displaysByMimetype.get(mimetype); + if (label == null) + { + // unrecognized mimetype + logger.warn("Unrecognized mimetype given to 'transformMimetypes': " + mimetype); + // just ignore it + continue; + } + // create UI object + SelectItem item = new SelectItem(mimetype, label); + // add to collection + this.transformers.add(item); + } + + // sort + QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + sorter.sort(); return this.transformers; } diff --git a/source/web/WEB-INF/faces-config.xml b/source/web/WEB-INF/faces-config.xml index a8d556ce18..349441f116 100644 --- a/source/web/WEB-INF/faces-config.xml +++ b/source/web/WEB-INF/faces-config.xml @@ -488,6 +488,10 @@ rulesBean #{RulesBean} + + transformMimetypes + #{webClientTransformMimetypes} + @@ -525,6 +529,10 @@ mimetypeService #{MimetypeService} + + transformMimetypes + #{webClientTransformMimetypes} + diff --git a/source/web/WEB-INF/web_TEMPLATE.xml b/source/web/WEB-INF/web_TEMPLATE.xml index 6b94a0b59a..04feadc934 100644 --- a/source/web/WEB-INF/web_TEMPLATE.xml +++ b/source/web/WEB-INF/web_TEMPLATE.xml @@ -57,9 +57,9 @@ contextConfigLocation - classpath:alfresco/application-context.xml classpath:alfresco/web-client-application-context.xml classpath:web-services-application-context.xml + classpath:alfresco/application-context.xml Spring config file locations