001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.theme.styling.service.registries; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.runtime.model.ContributionFragmentRegistry; 023import org.nuxeo.theme.styling.service.descriptors.SimpleStyle; 024 025/** 026 * Registry for theme style resources, handling merge of registered {@link SimpleStyle} elements. 027 * 028 * @since 5.5 029 */ 030public class StyleRegistry extends ContributionFragmentRegistry<SimpleStyle> { 031 032 protected Map<String, SimpleStyle> themePageStyles = new HashMap<String, SimpleStyle>(); 033 034 @Override 035 public String getContributionId(SimpleStyle contrib) { 036 return contrib.getName(); 037 } 038 039 @Override 040 public void contributionUpdated(String id, SimpleStyle contrib, SimpleStyle newOrigContrib) { 041 themePageStyles.put(id, contrib); 042 } 043 044 @Override 045 public void contributionRemoved(String id, SimpleStyle origContrib) { 046 themePageStyles.remove(id); 047 } 048 049 @Override 050 public SimpleStyle clone(SimpleStyle orig) { 051 SimpleStyle clone = new SimpleStyle(); 052 clone.setName(orig.getName()); 053 clone.setSrc(orig.getSrc()); 054 clone.setContent(orig.getContent()); 055 return clone; 056 } 057 058 @Override 059 public void merge(SimpleStyle src, SimpleStyle dst) { 060 // no merge => replace content 061 dst.setSrc(src.getSrc()); 062 dst.setContent(src.getContent()); 063 } 064 065 public SimpleStyle getStyle(String id) { 066 return themePageStyles.get(id); 067 } 068}