001/* 002 * (C) Copyright 2015-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.web.resources.core; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.apache.commons.lang3.builder.EqualsBuilder; 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeList; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.web.resources.api.ResourceBundle; 029 030/** 031 * @since 7.3 032 */ 033@XObject("bundle") 034public class ResourceBundleDescriptor implements ResourceBundle { 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 @Override 046 public String getName() { 047 return name; 048 } 049 050 @Override 051 public List<String> getResources() { 052 return resources; 053 } 054 055 public boolean isAppend() { 056 return append; 057 } 058 059 /** 060 * @since 7.4 061 */ 062 public void setName(String name) { 063 this.name = name; 064 } 065 066 /** 067 * @since 7.4 068 */ 069 public void setAppend(boolean append) { 070 this.append = append; 071 } 072 073 /** 074 * @since 7.4 075 */ 076 public void setResources(List<String> resources) { 077 this.resources = resources; 078 } 079 080 @Override 081 public ResourceBundleDescriptor clone() { 082 ResourceBundleDescriptor c = new ResourceBundleDescriptor(); 083 c.name = name; 084 c.append = append; 085 if (resources != null) { 086 c.resources = new ArrayList<>(resources); 087 } 088 return c; 089 } 090 091 @Override 092 public ResourceBundle merge(ResourceBundle other) { 093 if (other instanceof ResourceBundleDescriptor) { 094 boolean append = ((ResourceBundleDescriptor) other).isAppend(); 095 List<String> res = other.getResources(); 096 List<String> merged = new ArrayList<>(); 097 if (append && resources != null) { 098 merged.addAll(resources); 099 } 100 if (res != null) { 101 merged.addAll(res); 102 } 103 resources = merged; 104 } 105 return this; 106 } 107 108 @Override 109 public boolean equals(Object obj) { 110 if (!(obj instanceof ResourceBundleDescriptor)) { 111 return false; 112 } 113 if (obj == this) { 114 return true; 115 } 116 ResourceBundleDescriptor b = (ResourceBundleDescriptor) obj; 117 return new EqualsBuilder().append(name, b.name).append(append, b.append).append(resources, b.resources).isEquals(); 118 } 119 120}