001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.file.remote;
018
019 import java.net.URI;
020
021 import org.apache.camel.RuntimeCamelException;
022
023 public class RemoteFileConfiguration implements Cloneable {
024 private String protocol;
025 private String username;
026 private String host;
027 private int port;
028 private String password;
029 private String file;
030 private boolean binary;
031 private boolean directory = true;
032
033 public RemoteFileConfiguration() {
034 }
035
036 public RemoteFileConfiguration(URI uri) {
037 configure(uri);
038 }
039
040 public RemoteFileConfiguration copy() {
041 try {
042 return (RemoteFileConfiguration)clone();
043 } catch (CloneNotSupportedException e) {
044 throw new RuntimeCamelException(e);
045 }
046 }
047
048 public String toString() {
049 return protocol + ":\\" + username + "@" + host + ":" + port + "/" + directory;
050 }
051
052 public void configure(URI uri) {
053 setProtocol(uri.getScheme());
054 setDefaultPort();
055 setUsername(uri.getUserInfo());
056 setHost(uri.getHost());
057 setPort(uri.getPort());
058 setFile(uri.getPath());
059 }
060
061 protected void setDefaultPort() {
062 if ("ftp".equalsIgnoreCase(protocol)) {
063 setPort(21);
064 } else if ("sftp".equalsIgnoreCase(protocol)) {
065 setPort(22);
066 }
067 }
068
069 public String getFile() {
070 return file;
071 }
072
073 public void setFile(String file) {
074 this.file = file;
075 }
076
077 public String getHost() {
078 return host;
079 }
080
081 public void setHost(String host) {
082 this.host = host;
083 }
084
085 public int getPort() {
086 return port;
087 }
088
089 public void setPort(int port) {
090 if (port != -1) { // use default
091 this.port = port;
092 }
093 }
094
095 public String getPassword() {
096 return password;
097 }
098
099 public void setPassword(String password) {
100 this.password = password;
101 }
102
103 public String getProtocol() {
104 return protocol;
105 }
106
107 public void setProtocol(String protocol) {
108 this.protocol = protocol;
109 }
110
111 public String getUsername() {
112 return username;
113 }
114
115 public void setUsername(String username) {
116 this.username = username;
117 }
118
119 public boolean isBinary() {
120 return binary;
121 }
122
123 public void setBinary(boolean binary) {
124 this.binary = binary;
125 }
126
127 public boolean isDirectory() {
128 return directory;
129 }
130
131 public void setDirectory(boolean directory) {
132 this.directory = directory;
133 }
134
135 public String dump() {
136 return "RemoteFileConfiguration{" + "protocol='" + protocol + '\'' + ", username='" + username + '\'' + ", host='" + host + '\'' + ", port=" + port + ", password='" + password + '\''
137 + ", file='" + file + '\'' + ", binary=" + binary + ", directory=" + directory + '}';
138 }
139 }