All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geomajas.internal.service.StyleServiceImpl Maven / Gradle / Ivy

The newest version!
/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2016 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.internal.service;

import org.geomajas.configuration.NamedStyleInfo;
import org.geomajas.layer.VectorLayer;
import org.geomajas.service.CacheService;
import org.geomajas.service.ConfigurationService;
import org.geomajas.service.StyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

/**
 * Default implementation of the style service.
 *
 * @author Oliver May
 *
 */
@Component
public class StyleServiceImpl implements StyleService {
	private static final String CACHE_KEY = StyleServiceImpl.class.toString();

	@Autowired
	private ConfigurationService configurationService;

	@Autowired
	private CacheService cacheService;

	@Override
	public String registerStyle(String layerId, NamedStyleInfo style) {
		String id = DigestUtils.md5DigestAsHex(style.getCacheId().getBytes());
		cacheService.put(CACHE_KEY, id, style);
		return id;
	}

	@Override
	public NamedStyleInfo retrieveStyle(String layerId, String styleName) {

		VectorLayer layer = configurationService.getVectorLayer(layerId);
		if (layer != null) {
			NamedStyleInfo namedStyle = layer.getLayerInfo().getNamedStyleInfo(styleName);
			if (namedStyle != null) {
				return namedStyle;
			} else {
				NamedStyleInfo nsi = cacheService.get(CACHE_KEY, styleName, NamedStyleInfo.class);
				if (null != nsi) {
					return nsi;
				}
			}
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy