Add session to cache with both hostname and address.
[cyberduck.git] / source / ch / cyberduck / core / AbstractProtocol.java
blob2f4018aa6d03733d45859cc66af03a5e7abd7dfb
1 package ch.cyberduck.core;
3 /*
4 * Copyright (c) 2007 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 * dkocher@cyberduck.ch
21 import ch.cyberduck.core.features.Location;
22 import ch.cyberduck.core.preferences.PreferencesFactory;
24 import org.apache.commons.lang3.StringUtils;
26 import java.util.Collections;
27 import java.util.Locale;
28 import java.util.Set;
30 /**
31 * @version $Id$
33 public abstract class AbstractProtocol implements Protocol {
35 @Override
36 public String getProvider() {
37 return this.getIdentifier();
40 @Override
41 public String getName() {
42 return this.getScheme().name().toUpperCase(Locale.ROOT);
45 @Override
46 public String favicon() {
47 return null;
50 @Override
51 public boolean isEnabled() {
52 return PreferencesFactory.get().getBoolean(String.format("connection.protocol.%s.enable", this.getIdentifier()));
55 @Override
56 public String[] getSchemes() {
57 return new String[]{this.getScheme().name()};
60 @Override
61 public String toString() {
62 return this.getProvider();
65 /**
66 * @return A mounted disk icon to display
68 @Override
69 public String disk() {
70 return String.format("%s.tiff", this.getIdentifier());
73 /**
74 * @return A small icon to display
76 @Override
77 public String icon() {
78 return this.disk();
81 @Override
82 public boolean isSecure() {
83 return this.getScheme().isSecure();
86 @Override
87 public boolean isHostnameConfigurable() {
88 return StringUtils.isBlank(this.getDefaultHostname());
91 /**
92 * @return False if the port to connect is static.
94 @Override
95 public boolean isPortConfigurable() {
96 return true;
99 @Override
100 public boolean isEncodingConfigurable() {
101 return false;
104 @Override
105 public boolean isAnonymousConfigurable() {
106 return true;
109 @Override
110 public boolean isUsernameConfigurable() {
111 return true;
114 @Override
115 public boolean isPasswordConfigurable() {
116 return true;
119 @Override
120 public boolean isUTCTimezone() {
121 return true;
124 @Override
125 public String getUsernamePlaceholder() {
126 return LocaleFactory.localizedString("Username", "Credentials");
129 @Override
130 public String getPasswordPlaceholder() {
131 return LocaleFactory.localizedString("Password", "Credentials");
134 @Override
135 public String getDefaultHostname() {
136 // Blank by default
137 return PreferencesFactory.get().getProperty("connection.hostname.default");
141 * @return Available regions for containers
143 @Override
144 public Set<Location.Name> getRegions() {
145 return Collections.emptySet();
149 * @return The default port this protocol connects to
151 @Override
152 public int getDefaultPort() {
153 return this.getScheme().getPort();
157 * @return Authentication path
159 @Override
160 public String getContext() {
161 return null;
164 @Override
165 public String getRegion() {
166 return null;
169 @Override
170 public Type getType() {
171 return Type.valueOf(this.getIdentifier());
174 @Override
175 public boolean validate(Credentials credentials, LoginOptions options) {
176 return this.getType().validate(credentials, options);
179 @Override
180 public boolean equals(Object o) {
181 if(this == o) {
182 return true;
184 if(!(o instanceof Protocol)) {
185 return false;
187 Protocol protocol = (Protocol) o;
188 if(this.getIdentifier() != null ? !this.getIdentifier().equals(protocol.getIdentifier()) : protocol.getIdentifier() != null) {
189 return false;
191 if(this.getScheme() != null ? !this.getScheme().equals(protocol.getScheme()) : protocol.getScheme() != null) {
192 return false;
194 if(this.getProvider() != null ? !this.getProvider().equals(protocol.getProvider()) : protocol.getProvider() != null) {
195 return false;
197 return true;
200 @Override
201 public int compareTo(final Protocol o) {
202 return this.getIdentifier().compareTo(o.getIdentifier());
205 @Override
206 public int hashCode() {
207 int result = this.getIdentifier() != null ? this.getIdentifier().hashCode() : 0;
208 result = 31 * result + (this.getScheme() != null ? this.getScheme().hashCode() : 0);
209 result = 31 * result + (this.getProvider() != null ? this.getProvider().hashCode() : 0);
210 return result;