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