001/* 002 * (C) Copyright 2015 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-2.1.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.ecm.web.resources.core; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.apache.commons.lang.builder.EqualsBuilder; 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XNodeList; 025import org.nuxeo.common.xmap.annotation.XObject; 026import org.nuxeo.ecm.web.resources.api.ResourceBundle; 027 028/** 029 * @since 7.3 030 */ 031@XObject("bundle") 032public class ResourceBundleDescriptor implements ResourceBundle { 033 034 private static final long serialVersionUID = 1L; 035 036 @XNode("@name") 037 public String name; 038 039 @XNode("resources@append") 040 boolean append; 041 042 @XNodeList(value = "resources/resource", type = ArrayList.class, componentType = String.class) 043 List<String> resources; 044 045 public String getName() { 046 return name; 047 } 048 049 public List<String> getResources() { 050 return resources; 051 } 052 053 public boolean isAppend() { 054 return append; 055 } 056 057 /** 058 * @since 7.4 059 */ 060 public void setName(String name) { 061 this.name = name; 062 } 063 064 /** 065 * @since 7.4 066 */ 067 public void setAppend(boolean append) { 068 this.append = append; 069 } 070 071 /** 072 * @since 7.4 073 */ 074 public void setResources(List<String> resources) { 075 this.resources = resources; 076 } 077 078 public ResourceBundleDescriptor clone() { 079 ResourceBundleDescriptor c = new ResourceBundleDescriptor(); 080 c.name = name; 081 c.append = append; 082 if (resources != null) { 083 c.resources = new ArrayList<String>(resources); 084 } 085 return c; 086 } 087 088 @Override 089 public ResourceBundle merge(ResourceBundle other) { 090 if (other instanceof ResourceBundleDescriptor) { 091 boolean append = ((ResourceBundleDescriptor) other).isAppend(); 092 List<String> res = other.getResources(); 093 List<String> merged = new ArrayList<String>(); 094 if (append && resources != null) { 095 merged.addAll(resources); 096 } 097 if (res != null) { 098 merged.addAll(res); 099 } 100 resources = merged; 101 } 102 return this; 103 } 104 105 @Override 106 public boolean equals(Object obj) { 107 if (!(obj instanceof ResourceBundleDescriptor)) { 108 return false; 109 } 110 if (obj == this) { 111 return true; 112 } 113 ResourceBundleDescriptor b = (ResourceBundleDescriptor) obj; 114 return new EqualsBuilder().append(name, b.name).append(append, b.append).append(resources, b.resources).isEquals(); 115 } 116 117}