Coverage Report - org.apache.camel.component.file.remote.RemoteFileConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
RemoteFileConfiguration
88% 
100% 
1.273
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.file.remote;
 19  
 
 20  
 import org.apache.camel.RuntimeCamelException;
 21  
 
 22  
 import java.net.URI;
 23  
 
 24  
 public class RemoteFileConfiguration implements Cloneable {
 25  
     private String protocol;
 26  
     private String username;
 27  
     private String host;
 28  
     private int port;
 29  
     private String password;
 30  
     private String file;
 31  7
     private boolean binary = false;
 32  7
     private boolean directory = true;
 33  
 
 34  7
     public RemoteFileConfiguration() {
 35  7
     }
 36  
 
 37  0
     public RemoteFileConfiguration(URI uri) {
 38  0
         configure(uri);
 39  0
     }
 40  
 
 41  
     public RemoteFileConfiguration copy() {
 42  
         try {
 43  7
             return (RemoteFileConfiguration) clone();
 44  
         }
 45  0
         catch (CloneNotSupportedException e) {
 46  0
             throw new RuntimeCamelException(e);
 47  
         }
 48  
     }
 49  
 
 50  
     public void configure(URI uri) {
 51  7
         setProtocol(uri.getScheme());
 52  7
         setDefaultPort();
 53  7
         setUsername(uri.getUserInfo());
 54  7
         setHost(uri.getHost());
 55  7
         setPort(uri.getPort());
 56  7
         setFile(uri.getPath());
 57  7
     }
 58  
 
 59  
     protected void setDefaultPort() {
 60  7
         if ("ftp".equalsIgnoreCase(protocol)) {
 61  4
             setPort(21);
 62  4
         }
 63  3
         else if ("sftp".equalsIgnoreCase(protocol)) {
 64  3
             setPort(22);
 65  
         }
 66  7
     }
 67  
 
 68  
     public String getFile() {
 69  8
         return file;
 70  
     }
 71  
 
 72  
     public void setFile(String file) {
 73  7
         this.file = file;
 74  7
     }
 75  
 
 76  
     public String getHost() {
 77  9
         return host;
 78  
     }
 79  
 
 80  
     public void setHost(String host) {
 81  7
         this.host = host;
 82  7
     }
 83  
 
 84  
     public int getPort() {
 85  8
         return port;
 86  
     }
 87  
 
 88  
     public void setPort(int port) {
 89  14
         if (port != -1) { // use default
 90  12
             this.port = port;
 91  
         }
 92  14
     }
 93  
 
 94  
     public String getPassword() {
 95  2
         return password;
 96  
     }
 97  
 
 98  
     public void setPassword(String password) {
 99  7
         this.password = password;
 100  7
     }
 101  
 
 102  
     public String getProtocol() {
 103  10
         return protocol;
 104  
     }
 105  
 
 106  
     public void setProtocol(String protocol) {
 107  7
         this.protocol = protocol;
 108  7
     }
 109  
 
 110  
     public String getUsername() {
 111  8
         return username;
 112  
     }
 113  
 
 114  
     public void setUsername(String username) {
 115  7
         this.username = username;
 116  7
     }
 117  
 
 118  
     public boolean isBinary() {
 119  6
         return binary;
 120  
     }
 121  
 
 122  
     public void setBinary(boolean binary) {
 123  1
         this.binary = binary;
 124  1
     }
 125  
 
 126  
     public boolean isDirectory() {
 127  8
         return directory;
 128  
     }
 129  
 
 130  
     public void setDirectory(boolean directory) {
 131  1
         this.directory = directory;
 132  1
     }
 133  
 
 134  
     public String toString() {
 135  0
         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  
 }