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 org.apache.camel.component.file.GenericFile; 020 import org.apache.camel.component.file.GenericFileMessage; 021 import org.apache.camel.util.FileUtil; 022 023 /** 024 * Represents a remote file of some sort of backing object 025 * 026 * @param <T> the type of file that these remote endpoints provide 027 */ 028 public class RemoteFile<T> extends GenericFile<T> implements Cloneable { 029 030 private String hostname; 031 032 /** 033 * Populates the {@link GenericFileMessage} relevant headers 034 * 035 * @param message the message to populate with headers 036 */ 037 public void populateHeaders(GenericFileMessage<T> message) { 038 if (message != null) { 039 super.populateHeaders(message); 040 message.setHeader("CamelFileHost", getHostname()); 041 } 042 } 043 044 public String getHostname() { 045 return hostname; 046 } 047 048 public void setHostname(String hostname) { 049 this.hostname = hostname; 050 } 051 052 @Override 053 public char getFileSeparator() { 054 // always use / as separator for FTP 055 return '/'; 056 } 057 058 @Override 059 protected boolean isAbsolute(String name) { 060 return name.startsWith("" + getFileSeparator()); 061 } 062 063 @Override 064 protected String normalizePath(String name) { 065 return name; 066 } 067 068 @Override 069 public void copyFromPopulateAdditional(GenericFile source, GenericFile result) { 070 RemoteFile remoteSource = (RemoteFile) source; 071 RemoteFile remoteResult = (RemoteFile) result; 072 073 remoteResult.setHostname(remoteSource.getHostname()); 074 } 075 076 protected String normalizePathToProtocol(String path) { 077 path = super.normalizePathToProtocol(path); 078 // strip leading / for FTP protocol to avoid files with absolute paths 079 return FileUtil.stripLeadingSeparator(path); 080 } 081 }