/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.ui.icon.internal;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.eclipse.smarthome.io.rest.LocaleUtil;
import org.eclipse.smarthome.io.rest.RESTResource;
import org.eclipse.smarthome.ui.icon.IconProvider;
import org.eclipse.smarthome.ui.icon.IconSet;
/**
* This is a REST resource that provides information about available icon sets.
*
* @author Kai Kreuzer - Initial contribution
*/
@Path("iconsets")
public class IconSetResource implements RESTResource {
private List<IconProvider> iconProviders = new ArrayList<>(5);
protected void addIconProvider(IconProvider iconProvider) {
this.iconProviders.add(iconProvider);
}
protected void removeIconProvider(IconProvider iconProvider) {
this.iconProviders.remove(iconProvider);
}
@Context
UriInfo uriInfo;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAll(@HeaderParam("Accept-Language") String language) {
Locale locale = LocaleUtil.getLocale(language);
List<IconSet> iconSets = new ArrayList<>(iconProviders.size());
for (IconProvider iconProvider : iconProviders) {
iconSets.addAll(iconProvider.getIconSets(locale));
}
return Response.ok(iconSets).build();
}
}