1 package org.apache.archiva.admin.model.beans;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import java.io.Serializable;
22 import java.security.KeyStore;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Locale;
27 import java.util.stream.Collectors;
30 * @author Olivier Lamy
33 public class AbstractRepository
34 implements Serializable
37 private Locale defaultLocale = Locale.getDefault();
46 private Map<Locale, String> name = new HashMap<>( );
51 private Map<Locale, String> description = new HashMap<>( );
53 private String layout = "default";
55 private String indexDirectory;
57 private String toStringCache = null;
60 public AbstractRepository()
65 public AbstractRepository(Locale defaultLocale) {
66 this.defaultLocale = defaultLocale;
69 public AbstractRepository( Locale defaultLocale, String id, String name, String layout )
71 this.defaultLocale = defaultLocale;
77 public AbstractRepository( String id, String name, String layout )
89 public void setId( String id )
91 this.toStringCache=null;
95 public String getName()
97 return name.get(defaultLocale);
100 public Map<String,String> getNames() {
101 if (this.name==null) {
102 return Collections.emptyMap();
104 return this.name.entrySet().stream().collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), Map.Entry::getValue ) );
107 public void setName( String name )
109 this.toStringCache=null;
110 this.name.put(defaultLocale, name);
113 public void setName( String languageTag, String name ) {
114 this.toStringCache=null;
115 final Locale loc = Locale.forLanguageTag( languageTag );
116 this.name.put(loc, name);
119 public String getLayout()
124 public void setLayout( String layout )
126 this.toStringCache=null;
127 this.layout = layout;
132 public String getIndexDirectory()
134 return indexDirectory;
137 public void setIndexDirectory( String indexDirectory )
139 this.indexDirectory = indexDirectory;
142 public String getDescription()
144 return this.description.get(defaultLocale);
147 public Map<String,String> getDescriptions() {
148 if (this.description==null) {
149 return Collections.emptyMap();
151 return this.description.entrySet().stream().filter( e -> e!=null && e.getKey()!=null )
152 .collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), e -> e.getValue()==null ? "" : e.getValue() ) );
156 public void setDescription( String description )
158 this.toStringCache=null;
159 this.description.put(defaultLocale, description);
162 public void setDescription( String languageTag, String description) {
163 this.toStringCache = null;
164 final Locale loc = Locale.forLanguageTag( languageTag );
165 this.description.put(loc, description);
169 public int hashCode()
172 result = 37 * result + ( id != null ? id.hashCode() : 0 );
177 public boolean equals( Object other )
184 if ( !( other instanceof AbstractRepository ) )
189 AbstractRepository that = (AbstractRepository) other;
190 boolean result = true;
191 result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
195 private String getLocaleString(Map<Locale, String> map) {
196 return map.entrySet().stream().map(entry -> entry.getKey().toLanguageTag()+'='+entry.getValue()).collect( Collectors.joining( ",") );
199 public String getType( )
204 public void setType(String type) {
209 public String toString()
211 if (toStringCache!=null) {
212 return toStringCache;
215 final StringBuilder sb = new StringBuilder( );
216 sb.append( "AbstractRepository" );
217 sb.append( "{id='" ).append( id ).append( '\'' );
218 sb.append(", type='").append(type).append('\'');
219 sb.append( ", name='" ).append( getLocaleString( name ) ).append( '\'' );
220 sb.append( ", layout='" ).append( layout ).append( '\'' );
221 sb.append( ", indexDirectory='" ).append( indexDirectory ).append( '\'' );
222 sb.append( ", description='" ).append( getLocaleString( description ) ).append( '\'' );
224 toStringCache=sb.toString( );
225 return toStringCache;