mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Changed forums icons to use browse bean's small icon resolver and required patch
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2513 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Patch to remove the '_large' from the icon property for all the forums
|
||||
* based space types i.e. fm:forums, fm:forum and fm:topic.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class ForumsIconsPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.forumsIcons.result";
|
||||
|
||||
private ImporterBootstrap importerBootstrap;
|
||||
private NodeService nodeService;
|
||||
private SearchService searchService;
|
||||
|
||||
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||
{
|
||||
this.importerBootstrap = importerBootstrap;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
int iconsChanged = 0;
|
||||
|
||||
// change all the fm:forums nodes
|
||||
iconsChanged += changeIcons(ForumModel.TYPE_FORUMS);
|
||||
|
||||
// change all the fm:forum nodes
|
||||
iconsChanged += changeIcons(ForumModel.TYPE_FORUM);
|
||||
|
||||
// change all the topic nodes
|
||||
iconsChanged += changeIcons(ForumModel.TYPE_TOPIC);
|
||||
|
||||
// return success message
|
||||
return I18NUtil.getMessage(MSG_SUCCESS, new Object[] {iconsChanged});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the '_large' from the icon property for the nodes of the given type
|
||||
*
|
||||
* @param typeName The qname of the type to change the icon property for
|
||||
* @return Returns the number of icons changed
|
||||
*/
|
||||
private int changeIcons(QName typeName)
|
||||
{
|
||||
int changed = 0;
|
||||
String query = "TYPE:\"" + typeName.toString() + "\"";
|
||||
ResultSet results = this.searchService.query(this.importerBootstrap.getStoreRef(),
|
||||
SearchService.LANGUAGE_LUCENE, query);
|
||||
|
||||
// if there are any results iterate through nodes and update icon property
|
||||
if (results.length() > 0)
|
||||
{
|
||||
for (NodeRef node : results.getNodeRefs())
|
||||
{
|
||||
String icon = (String)this.nodeService.getProperty(node, ContentModel.PROP_ICON);
|
||||
if (icon != null && icon.length() > 0)
|
||||
{
|
||||
int idx = icon.indexOf("_large");
|
||||
if (idx != -1)
|
||||
{
|
||||
String newIcon = icon.substring(0, idx);
|
||||
this.nodeService.setProperty(node, ContentModel.PROP_ICON, (Serializable)newIcon);
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user