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    import java.util.Map;
021    
022    import com.jcraft.jsch.ChannelSftp;
023    import org.apache.camel.CamelContext;
024    import org.apache.camel.component.file.GenericFileEndpoint;
025    
026    /**
027     * Secure FTP Component
028     */
029    public class SftpComponent extends RemoteFileComponent<ChannelSftp.LsEntry> {
030    
031        public SftpComponent() {
032        }
033    
034        public SftpComponent(CamelContext context) {
035            super(context);
036        }
037    
038        @Override
039        protected GenericFileEndpoint<ChannelSftp.LsEntry> buildFileEndpoint(String uri, String remaining, Map parameters) throws Exception {
040            // get the base uri part before the options as they can be non URI valid such as the expression using $ chars
041            // and the URI constructor will regard $ as an illegal character and we dont want to enforce end users to
042            // to espace the $ for the expression (file language)
043            String baseUri = uri;
044            if (uri.indexOf("?") != -1) {
045                baseUri = uri.substring(0, uri.indexOf("?"));
046            }
047    
048            // lets make sure we create a new configuration as each endpoint can
049            // customize its own version
050            SftpConfiguration config = new SftpConfiguration(new URI(baseUri));
051    
052            return new SftpEndpoint(uri, this, config);
053        }
054    
055        protected void afterPropertiesSet(GenericFileEndpoint<ChannelSftp.LsEntry> endpoint) throws Exception {
056            // noop
057        }
058    
059    }
060