1 package ch
.cyberduck
.core
.openstack
;
4 * Copyright (c) 2013 David Kocher. All rights reserved.
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
;
37 import ch
.iterate
.openstack
.swift
.model
.Region
;
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
;
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
>() {
59 public int compare(final Region r1
, final Region r2
) {
69 for(Region region
: regions
) {
70 if(StringUtils
.isBlank(region
.getRegionId())) {
71 // v1 authentication contexts do not have region support
74 locations
.add(new SwiftRegion(region
.getRegionId()));
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());
93 return new SwiftRegion(container
.attributes().getRegion());
96 public static final class SwiftRegion
extends Name
{
98 public SwiftRegion(String identifier
) {
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");