1 package org.apache.archiva.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.cronutils.model.CronType;
23 import com.cronutils.model.definition.CronDefinition;
24 import com.cronutils.model.definition.CronDefinitionBuilder;
25 import com.cronutils.parser.CronParser;
26 import org.apache.archiva.repository.features.RepositoryFeature;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.Locale;
37 * Implementation of a repository with the necessary fields for a bare repository.
38 * No features are provided. Capabilities and features must be implemented by concrete classes.
41 public abstract class AbstractRepository implements EditableRepository
44 private final RepositoryType type;
45 private final String id;
46 private Map<Locale, String> names = new HashMap<>( );
47 private Map<Locale, String> descriptions = new HashMap<>( );
49 private Locale primaryLocale = new Locale("en_US");
51 private Set<URI> failoverLocations = new HashSet<>( );
52 private Set<URI> uFailoverLocations = Collections.unmodifiableSet( failoverLocations );
53 private boolean scanned = true;
54 String schedulingDefinition = "0 0 02 * *";
55 private boolean index = true;
56 private String layout;
57 public static final CronDefinition CRON_DEFINITION = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
59 public AbstractRepository(RepositoryType type, String id, String name) {
61 this.names.put( primaryLocale, name);
65 public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name) {
66 setPrimaryLocale( primaryLocale );
68 this.names.put( primaryLocale, name);
72 protected void setPrimaryLocale(Locale locale) {
73 this.primaryLocale = locale;
77 public String getId( )
83 public String getName( )
85 return getName( primaryLocale );
89 public String getName( Locale locale )
91 return names.get(locale);
95 public String getDescription( )
97 return getDescription( primaryLocale );
101 public String getDescription( Locale locale )
103 return descriptions.get(primaryLocale);
107 public RepositoryType getType( )
113 public URI getLocation( )
119 public Set<URI> getFailoverLocations( )
121 return uFailoverLocations;
125 public boolean isScanned( )
131 public String getSchedulingDefinition( )
133 return schedulingDefinition;
137 public boolean hasIndex( )
143 public String getLayout( )
149 public abstract RepositoryCapabilities getCapabilities( );
152 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
154 throw new UnsupportedFeatureException( "Feature "+clazz+" not supported" );
158 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
164 public Locale getPrimaryLocale( )
166 return primaryLocale;
170 public void setName( Locale locale, String name )
172 names.put(locale, name);
176 public void setDescription( Locale locale, String description )
178 descriptions.put(locale, description);
182 public void setLocation( URI location )
184 this.location = location;
188 public void addFailoverLocation( URI location )
190 this.failoverLocations.add(location);
194 public void removeFailoverLocation( URI location )
196 this.failoverLocations.remove( location );
200 public void clearFailoverLocations( )
202 this.failoverLocations.clear();
206 public void setScanned( boolean scanned )
208 this.scanned = scanned;
212 public void setIndex( boolean hasIndex )
214 this.index = hasIndex;
218 public void setLayout( String layout )
220 this.layout = layout;
224 public void setSchedulingDefinition(String cronExpression) {
225 CronParser parser = new CronParser(CRON_DEFINITION);
226 parser.parse(cronExpression).validate();
227 this.schedulingDefinition = cronExpression;