diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml new file mode 100644 index 0000000000..dcfea9ab2c --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-type-icon.get.desc.xml @@ -0,0 +1,29 @@ + + Get channel type icon + +
+
channelType
mandatory - the channel type for which the icon is required
+
iconSize
mandatory - the size of the icon required. Must be either "16" or "32"
+
+ Streams the requested icon if it can be found, otherwise returns a 404 status code. If either channelType or iconSize + are missing then a 400 status code is returned. + ]]>
+ + /api/publishing/channel-type/{channelType}/icon/{iconSize} + + user + required + public_api + + + channelType + The identifier of the channel type whose icon is wanted. + + + iconSize + The size (in pixels) of the required icon. Must be either "16" or "32". + + +
\ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 460a80d191..42b28d68c4 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1161,6 +1161,13 @@ + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java new file mode 100644 index 0000000000..8b89e038c5 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.web.scripts.publishing; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Map; + +import org.alfresco.service.cmr.publishing.channels.ChannelService; +import org.alfresco.service.cmr.publishing.channels.ChannelType; +import org.alfresco.service.cmr.repository.MimetypeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.core.io.Resource; +import org.springframework.extensions.webscripts.AbstractWebScript; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; +import org.springframework.util.FileCopyUtils; + +public class ChannelTypeIconGetWebScript extends AbstractWebScript +{ + private final static Log log = LogFactory.getLog(ChannelTypeIconGetWebScript.class); + private ChannelService channelService; + private MimetypeService mimetypeService; + + public void setChannelService(ChannelService channelService) + { + this.channelService = channelService; + } + + public void setMimetypeService(MimetypeService mimetypeService) + { + this.mimetypeService = mimetypeService; + } + + @Override + public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException + { + res.setContentType("text/html"); + res.setContentEncoding("UTF-8"); + + Map templateVars = req.getServiceMatch().getTemplateVars(); + String channelTypeId = templateVars.get("channelType"); + String iconSize = templateVars.get("iconSize"); + + if (channelTypeId == null || iconSize == null) + { + res.setStatus(400); //Bad request + return; + } + ChannelType channelType = channelService.getChannelType(channelTypeId); + if (channelType == null) + { + res.setStatus(404); // Not found + return; + } + + Resource iconFile = null; + if (iconSize.equals("16")) + { + iconFile = channelType.getIcon16(); + } + else if (iconSize.equals("32")) + { + iconFile = channelType.getIcon32(); + } + if (iconFile == null || !iconFile.exists()) + { + res.setStatus(404); //Not found + return; + } + + res.setHeader("Content-Length", "" + iconFile.contentLength()); + String mimeType = mimetypeService.getMimetype(channelType.getIconFileExtension()); + res.setContentType(mimeType); + OutputStream out = res.getOutputStream(); + InputStream in = iconFile.getInputStream(); + FileCopyUtils.copy(in, out); + in.close(); + } + +}