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