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.ArrayList; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024import org.nuxeo.runtime.model.ContributionFragmentRegistry; 025import org.nuxeo.theme.styling.service.descriptors.PageDescriptor; 026 027/** 028 * Registry for theme page resources, handling merge of registered {@link PageDescriptor} elements. 029 * 030 * @since 5.5 031 */ 032public class PageRegistry extends ContributionFragmentRegistry<PageDescriptor> { 033 034 protected Map<String, PageDescriptor> pageResources = new HashMap<String, PageDescriptor>(); 035 036 @Override 037 public String getContributionId(PageDescriptor contrib) { 038 return contrib.getName(); 039 } 040 041 @Override 042 public void contributionUpdated(String id, PageDescriptor contrib, PageDescriptor newOrigContrib) { 043 pageResources.put(id, contrib); 044 } 045 046 @Override 047 public synchronized void removeContribution(PageDescriptor contrib) { 048 removeContribution(contrib, true); 049 } 050 051 @Override 052 public void contributionRemoved(String id, PageDescriptor origContrib) { 053 pageResources.remove(id); 054 } 055 056 @Override 057 public PageDescriptor clone(PageDescriptor orig) { 058 if (orig == null) { 059 return null; 060 } 061 return orig.clone(); 062 } 063 064 @Override 065 public void merge(PageDescriptor src, PageDescriptor dst) { 066 dst.merge(src); 067 } 068 069 public PageDescriptor getPage(String id) { 070 return pageResources.get(id); 071 } 072 073 /** 074 * @deprecated since 7.4: use {@link #getPage(String)} instead. 075 */ 076 @Deprecated 077 public PageDescriptor getThemePage(String id) { 078 return getPage(id); 079 } 080 081 public List<PageDescriptor> getPages() { 082 List<PageDescriptor> res = new ArrayList<PageDescriptor>(); 083 for (PageDescriptor page : pageResources.values()) { 084 if (page != null) { 085 res.add(page); 086 } 087 } 088 return res; 089 } 090 091 /** 092 * Returns all the page names. 093 * 094 * @since 7.10 095 */ 096 public List<String> getPageNames() { 097 return new ArrayList<String>(pageResources.keySet()); 098 } 099 100 /** 101 * @deprecated since 7.4: use {@link #getPages()} instead. 102 */ 103 @Deprecated 104 public List<PageDescriptor> getThemePages() { 105 return getPages(); 106 } 107 108 public PageDescriptor getConfigurationApplyingToAll() { 109 return pageResources.get("*"); 110 } 111 112 /** 113 * @deprecated since 7.4: use {@link #getConfigurationApplyingToAll()} instead. 114 */ 115 public PageDescriptor getConfigurationApplyingToAllThemes() { 116 return getConfigurationApplyingToAll(); 117 } 118 119}