Coverage Report - org.apache.camel.component.file.strategy.DefaultFileRenamer
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultFileRenamer
64% 
100% 
1.25
 
 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.strategy;
 19  
 
 20  
 import java.io.File;
 21  
 
 22  
 /**
 23  
  * @version $Revision: 1.1 $
 24  
  */
 25  
 public class DefaultFileRenamer implements FileRenamer {
 26  
     private String namePrefix;
 27  
     private String namePostfix;
 28  
 
 29  0
     public DefaultFileRenamer() {
 30  0
     }
 31  
 
 32  27
     public DefaultFileRenamer(String namePrefix, String namePostfix) {
 33  27
         this.namePrefix = namePrefix;
 34  27
         this.namePostfix = namePostfix;
 35  27
     }
 36  
 
 37  
     public File renameFile(File file) {
 38  30
         File parent = file.getParentFile();
 39  30
         String name = renameFileName(file);
 40  30
         return new File(parent, name);
 41  
     }
 42  
 
 43  
     public String getNamePostfix() {
 44  0
         return namePostfix;
 45  
     }
 46  
 
 47  
     /**
 48  
      * Sets the name postfix appended to moved files. For example
 49  
      * to rename all the files from * to *.done set this value to ".done"
 50  
      */
 51  
     public void setNamePostfix(String namePostfix) {
 52  0
         this.namePostfix = namePostfix;
 53  0
     }
 54  
 
 55  
     public String getNamePrefix() {
 56  0
         return namePrefix;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Sets the name prefix appended to moved files. For example
 61  
      * to move processed files into a hidden directory called ".camel"
 62  
      * set this value to ".camel/"
 63  
      */
 64  
     public void setNamePrefix(String namePrefix) {
 65  0
         this.namePrefix = namePrefix;
 66  0
     }
 67  
 
 68  
 
 69  
     protected String renameFileName(File file) {
 70  30
         StringBuffer buffer = new StringBuffer();
 71  30
         if (namePrefix != null) {
 72  12
             buffer.append(namePrefix);
 73  
         }
 74  30
         buffer.append(file.getName());
 75  30
         if (namePostfix != null) {
 76  27
             buffer.append(namePostfix);
 77  
         }
 78  30
         return buffer.toString();
 79  
     }
 80  
 }