Add callback for delete operation.
[cyberduck.git] / source / ch / cyberduck / core / openstack / SwiftLocationFeature.java
blobf472089f9ef721531cad6c41708e6ed22c55f938
1 package ch.cyberduck.core.openstack;
3 /*
4 * Copyright (c) 2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.ch
21 import ch.cyberduck.core.DisabledListProgressListener;
22 import ch.cyberduck.core.LocaleFactory;
23 import ch.cyberduck.core.Path;
24 import ch.cyberduck.core.PathContainerService;
25 import ch.cyberduck.core.exception.BackgroundException;
26 import ch.cyberduck.core.features.Location;
28 import org.apache.commons.lang3.StringUtils;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Comparator;
33 import java.util.LinkedHashSet;
34 import java.util.List;
35 import java.util.Set;
37 import ch.iterate.openstack.swift.model.Region;
39 /**
40 * @version $Id$
42 public class SwiftLocationFeature implements Location {
44 private SwiftSession session;
46 private PathContainerService containerService
47 = new SwiftPathContainerService();
49 public SwiftLocationFeature(final SwiftSession session) {
50 this.session = session;
53 @Override
54 public Set<Name> getLocations() {
55 final Set<Name> locations = new LinkedHashSet<Name>();
56 final List<Region> regions = new ArrayList<Region>(session.getClient().getRegions());
57 Collections.sort(regions, new Comparator<Region>() {
58 @Override
59 public int compare(final Region r1, final Region r2) {
60 if(r1.isDefault()) {
61 return -1;
63 if(r2.isDefault()) {
64 return 1;
66 return 0;
68 });
69 for(Region region : regions) {
70 if(StringUtils.isBlank(region.getRegionId())) {
71 // v1 authentication contexts do not have region support
72 continue;
74 locations.add(new SwiftRegion(region.getRegionId()));
76 return locations;
79 @Override
80 public Name getLocation(final Path file) throws BackgroundException {
81 final Path container = containerService.getContainer(file);
82 if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) {
83 final SwiftRegion region = new SwiftRegion(session.getHost().getRegion());
84 if(Location.unknown.equals(region)) {
85 for(Path c : new SwiftContainerListService(session, region, false, false).list(new DisabledListProgressListener())) {
86 if(c.getName().equals(container.getName())) {
87 return new SwiftRegion(c.attributes().getRegion());
91 return region;
93 return new SwiftRegion(container.attributes().getRegion());
96 public static final class SwiftRegion extends Name {
98 public SwiftRegion(String identifier) {
99 super(identifier);
102 @Override
103 public String toString() {
104 final String identifier = getIdentifier();
105 if(null == identifier) {
106 return LocaleFactory.localizedString("Unknown");
108 return LocaleFactory.localizedString(this.getIdentifier(), "Mosso");