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
This commit is contained in:
Derek Hulley
2006-01-26 13:46:46 +00:00
parent b36a235769
commit 9160578c9a
5 changed files with 70 additions and 54 deletions

View File

@@ -26,4 +26,19 @@
</constructor-arg> </constructor-arg>
</bean> </bean>
<!-- the list of standard transformation mimetypes that are exposed in the UI -->
<bean id="webClientTransformMimetypes" class="java.util.ArrayList" >
<constructor-arg>
<list>
<value>text/html</value>
<value>application/pdf</value>
<value>text/plain</value>
<value>text/xml</value>
<value>application/x-shockwave-flash</value>
<value>image/gif</value>
<value>image/jpeg</value>
</list>
</constructor-arg>
</bean>
</beans> </beans>

View File

@@ -304,6 +304,7 @@
<!-- Example configuration to demonstrate how to expose aspect from exampleModel.xml --> <!-- Example configuration to demonstrate how to expose aspect from exampleModel.xml -->
<!-- <aspect name="my:imageClassification"/> --> <!-- <aspect name="my:imageClassification"/> -->
</aspects> </aspects>
<!--
<transformers> <transformers>
<transformer name="text/html"/> <transformer name="text/html"/>
<transformer name="application/pdf"/> <transformer name="application/pdf"/>
@@ -313,6 +314,7 @@
<transformer name="image/gif"/> <transformer name="image/gif"/>
<transformer name="image/jpeg"/> <transformer name="image/jpeg"/>
</transformers> </transformers>
-->
<image-transformers> <image-transformers>
<transformer name="image/gif"/> <transformer name="image/gif"/>
<transformer name="image/jpeg"/> <transformer name="image/jpeg"/>

View File

@@ -18,6 +18,7 @@ package org.alfresco.web.bean.wizard;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.SimpleWorkflowActionExecuter;
import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter;
import org.alfresco.repo.action.executer.TransformActionExecuter; 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.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
@@ -99,6 +99,7 @@ public abstract class BaseActionWizard extends AbstractWizardBean
protected DictionaryService dictionaryService; protected DictionaryService dictionaryService;
protected MimetypeService mimetypeService; protected MimetypeService mimetypeService;
protected List<SelectItem> actions; protected List<SelectItem> actions;
private List<String> transformMimetypes;
protected List<SelectItem> transformers; protected List<SelectItem> transformers;
protected List<SelectItem> imageTransformers; protected List<SelectItem> imageTransformers;
protected List<SelectItem> aspects; protected List<SelectItem> aspects;
@@ -108,6 +109,16 @@ public abstract class BaseActionWizard extends AbstractWizardBean
protected Map<String, Serializable> currentActionProperties; protected Map<String, Serializable> currentActionProperties;
protected List<SelectItem> objectTypes; protected List<SelectItem> objectTypes;
/**
* Set the available mimetypes to act as targets of transformations
*
* @param mimetypes a list of valid mimetypes
*/
public void setTransformMimetypes(List<String> mimetypes)
{
this.transformMimetypes = mimetypes;
}
/** /**
* Initialises the wizard * Initialises the wizard
*/ */
@@ -615,60 +626,40 @@ public abstract class BaseActionWizard extends AbstractWizardBean
*/ */
public List<SelectItem> getTransformers() public List<SelectItem> getTransformers()
{ {
if (this.transformers == null) if (this.transformers != null)
{ {
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext( return this.transformers;
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE); }
Config wizardCfg = svc.getConfig("Action Wizards"); // check that the mimetypes are available
if (wizardCfg != null) if (this.transformMimetypes == null)
{ {
ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers"); logger.warn("'transformMimetypes' property was not set");
if (transformersCfg != null) this.transformMimetypes = Collections.emptyList();
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> mimeTypes = this.mimetypeService.getDisplaysByMimetype();
this.transformers = new ArrayList<SelectItem>();
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 this.transformers = new ArrayList<SelectItem>(10);
Map<String, String> displaysByMimetype = this.mimetypeService.getDisplaysByMimetype();
for (String mimetype : this.transformMimetypes)
{
// get the display label
String label = displaysByMimetype.get(mimetype);
if (label == null) if (label == null)
{ {
label = child.getAttribute("displayLabel"); // 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);
} }
// if there wasn't a client based label get it from the mime type service // sort
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); QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort(); sorter.sort();
}
else
{
logger.warn("Could not find transformers configuration element");
}
}
else
{
logger.warn("Could not find Action Wizards configuration section");
}
}
return this.transformers; return this.transformers;
} }

View File

@@ -488,6 +488,10 @@
<property-name>rulesBean</property-name> <property-name>rulesBean</property-name>
<value>#{RulesBean}</value> <value>#{RulesBean}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>transformMimetypes</property-name>
<value>#{webClientTransformMimetypes}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>
@@ -525,6 +529,10 @@
<property-name>mimetypeService</property-name> <property-name>mimetypeService</property-name>
<value>#{MimetypeService}</value> <value>#{MimetypeService}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>transformMimetypes</property-name>
<value>#{webClientTransformMimetypes}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>

View File

@@ -57,9 +57,9 @@
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
classpath:alfresco/application-context.xml
classpath:alfresco/web-client-application-context.xml classpath:alfresco/web-client-application-context.xml
classpath:web-services-application-context.xml classpath:web-services-application-context.xml
classpath:alfresco/application-context.xml
</param-value> </param-value>
<description>Spring config file locations</description> <description>Spring config file locations</description>
</context-param> </context-param>