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");
52 private Set<URI> failoverLocations = new HashSet<>( );
53 private Set<URI> uFailoverLocations = Collections.unmodifiableSet( failoverLocations );
54 private boolean scanned = true;
55 String schedulingDefinition = "0 0 02 * * ?";
56 private String layout = "default";
57 public static final CronDefinition CRON_DEFINITION = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
59 Map<Class<? extends RepositoryFeature<?>>, RepositoryFeature<?>> featureMap = new HashMap<>( );
61 public AbstractRepository(RepositoryType type, String id, String name) {
63 this.names.put( primaryLocale, name);
67 public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name) {
68 setPrimaryLocale( primaryLocale );
70 this.names.put( primaryLocale, name);
74 protected void setPrimaryLocale(Locale locale) {
75 this.primaryLocale = locale;
79 public String getId( )
85 public String getName( )
87 return getName( primaryLocale );
91 public String getName( Locale locale )
93 return names.get(locale);
97 public String getDescription( )
99 return getDescription( primaryLocale );
103 public String getDescription( Locale locale )
105 return descriptions.get(primaryLocale);
109 public RepositoryType getType( )
115 public URI getLocation( )
120 public URI getAbsoluteLocation() {
121 return baseUri.resolve( location );
125 public Set<URI> getFailoverLocations( )
127 return uFailoverLocations;
131 public boolean isScanned( )
137 public String getSchedulingDefinition( )
139 return schedulingDefinition;
143 public abstract boolean hasIndex( );
146 public String getLayout( )
152 public abstract RepositoryCapabilities getCapabilities( );
155 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
157 if (featureMap.containsKey( clazz )) {
158 return (RepositoryFeature<T>) featureMap.get(clazz);
161 throw new UnsupportedFeatureException( "Feature " + clazz + " not supported" );
166 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
168 return featureMap.containsKey( clazz );
172 public Locale getPrimaryLocale( )
174 return primaryLocale;
178 public void setName( Locale locale, String name )
180 names.put(locale, name);
184 public void setDescription( Locale locale, String description )
186 descriptions.put(locale, description);
190 public void setLocation( URI location )
192 this.location = location;
196 public void addFailoverLocation( URI location )
198 this.failoverLocations.add(location);
202 public void removeFailoverLocation( URI location )
204 this.failoverLocations.remove( location );
208 public void clearFailoverLocations( )
210 this.failoverLocations.clear();
214 public void setScanned( boolean scanned )
216 this.scanned = scanned;
220 public void setLayout( String layout )
222 this.layout = layout;
226 public void setBaseUri(URI baseUri) {
227 this.baseUri = baseUri;
231 public void setSchedulingDefinition(String cronExpression) {
232 CronParser parser = new CronParser(CRON_DEFINITION);
233 parser.parse(cronExpression).validate();
234 this.schedulingDefinition = cronExpression;
237 protected <T extends RepositoryFeature<T>> void addFeature(RepositoryFeature<T> feature) {
238 featureMap.put( (Class<? extends RepositoryFeature<?>>) feature.getClass(), feature);