This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.admin.model.beans;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import java.io.Serializable;
022import java.util.Collections;
023import java.util.HashMap;
024import java.util.Locale;
025import java.util.Map;
026import java.util.stream.Collectors;
027
028/**
029 * @author Olivier Lamy
030 * @since 1.4-M1
031 */
032public class AbstractRepository
033    implements Serializable
034{
035
036    private Locale defaultLocale = Locale.getDefault();
037
038    private String type;
039
040    private String id;
041
042    /*
043     * @since 3.0.0 as Map
044     */
045    private Map<Locale, String> name = new HashMap<>(  );
046
047    /*
048     * @since 3.0.0 as Map
049     */
050    private Map<Locale, String> description = new HashMap<>(  );
051
052    private String layout = "default";
053
054    private String indexDirectory;
055
056    /*
057     * @since 3.0.0
058     */
059    private String packedIndexDirectory;
060
061    private String toStringCache = null;
062
063
064    public AbstractRepository()
065    {
066        // no op
067    }
068
069    public AbstractRepository(Locale defaultLocale) {
070        this.defaultLocale = defaultLocale;
071    }
072
073    public AbstractRepository( Locale defaultLocale,  String id, String name, String layout )
074    {
075        this.defaultLocale = defaultLocale;
076        setId(id);
077        setName(name);
078        setLayout(layout);
079    }
080
081    public AbstractRepository( String id, String name, String layout )
082    {
083        setId(id);
084        setName(name);
085        setLayout(layout);
086    }
087
088    public String getId()
089    {
090        return id;
091    }
092
093    public void setId( String id )
094    {
095        this.toStringCache=null;
096        this.id = id;
097    }
098
099    public String getName()
100    {
101        return name.get(defaultLocale);
102    }
103
104    public Map<String,String> getNames() {
105        if (this.name==null) {
106            return Collections.emptyMap();
107        }
108        return this.name.entrySet().stream().collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), Map.Entry::getValue ) );
109    }
110
111    public void setName( String name )
112    {
113        this.toStringCache=null;
114        this.name.put(defaultLocale, name);
115    }
116
117    public void setName( String languageTag, String name ) {
118        this.toStringCache=null;
119        final Locale loc = Locale.forLanguageTag( languageTag );
120        this.name.put(loc, name);
121    }
122
123    public String getLayout()
124    {
125        return layout;
126    }
127
128    public void setLayout( String layout )
129    {
130        this.toStringCache=null;
131        this.layout = layout;
132    }
133
134
135
136    public String getIndexDirectory()
137    {
138        return indexDirectory;
139    }
140
141    public void setIndexDirectory( String indexDirectory )
142    {
143        this.toStringCache=null;
144        this.indexDirectory = indexDirectory;
145    }
146
147    public String getDescription()
148    {
149        return this.description.get(defaultLocale);
150    }
151
152    public Map<String,String> getDescriptions() {
153        if (this.description==null) {
154            return Collections.emptyMap();
155        }
156        return this.description.entrySet().stream().filter( e -> e!=null && e.getKey()!=null )
157            .collect( Collectors.toMap( e -> e.getKey().toLanguageTag(), e -> e.getValue()==null ? "" : e.getValue() ) );
158    }
159
160
161    public void setDescription( String description )
162    {
163        this.toStringCache=null;
164        this.description.put(defaultLocale, description);
165    }
166
167    public void setDescription( String languageTag, String description) {
168        this.toStringCache = null;
169        final Locale loc = Locale.forLanguageTag( languageTag );
170        this.description.put(loc, description);
171    }
172
173    @Override
174    public int hashCode()
175    {
176        int result = 17;
177        result = 37 * result + ( id != null ? id.hashCode() : 0 );
178        return result;
179    }
180
181    @Override
182    public boolean equals( Object other )
183    {
184        if ( this == other )
185        {
186            return true;
187        }
188
189        if ( !( other instanceof AbstractRepository ) )
190        {
191            return false;
192        }
193
194        AbstractRepository that = (AbstractRepository) other;
195        boolean result = true;
196        result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
197        return result;
198    }
199
200    private String getLocaleString(Map<Locale, String>  map) {
201        return map.entrySet().stream().map(entry -> entry.getKey().toLanguageTag()+'='+entry.getValue()).collect( Collectors.joining( ",") );
202    }
203
204    public String getType( )
205    {
206        return type;
207    }
208
209    public void setType(String type) {
210        toStringCache=null;
211        this.type = type;
212    }
213
214    public String getPackedIndexDirectory() {
215        return packedIndexDirectory;
216    }
217
218    public void setPackedIndexDirectory(String packedIndexDirectory) {
219        toStringCache=null;
220        this.packedIndexDirectory = packedIndexDirectory;
221    }
222
223    @Override
224    public String toString()
225    {
226        if (toStringCache!=null) {
227            return toStringCache;
228        } else
229        {
230            final StringBuilder sb = new StringBuilder( );
231            sb.append( "AbstractRepository" );
232            sb.append( "{ id=\"" ).append( id ).append( '"' );
233            sb.append( ", type=\"").append(type).append('"');
234            sb.append( ", name=\"" ).append( getLocaleString( name ) ).append( '"' );
235            sb.append( ", layout=\"" ).append( layout ).append( '"' );
236            sb.append( ", indexDirectory=\"" ).append( indexDirectory ).append( '"' );
237            sb.append( ", packedIndexDirectory=\"").append(packedIndexDirectory).append('"');
238            sb.append( ", description=\"" ).append( getLocaleString( description ) ).append( '"' );
239            sb.append( '}' );
240            toStringCache=sb.toString( );
241            return toStringCache;
242        }
243    }
244
245
246}