View Javadoc

1   package net_alchim31_maven_yuicompressor;
2   
3   import java.io.File;
4   
5   public class SourceFile {
6   
7       private File srcRoot_;
8       private File destRoot_;
9       private boolean destAsSource_;
10      private String rpath_;
11      private String extension_;
12  
13      public SourceFile(File srcRoot, File destRoot, String name, boolean destAsSource) throws Exception {
14          srcRoot_ = srcRoot;
15          destRoot_ = destRoot;
16          destAsSource_ = destAsSource;
17          rpath_ = name;
18          int sep = rpath_.lastIndexOf('.');
19          if (sep>0) {
20              extension_ = rpath_.substring(sep);
21              rpath_ = rpath_.substring(0, sep);
22          } else {
23              extension_ = "";
24          }
25      }
26  
27      public File toFile() {
28          String frpath = rpath_ + extension_;
29          if (destAsSource_) {
30              File defaultDest = new File(destRoot_, frpath);
31              if (defaultDest.exists() && defaultDest.canRead()) {
32                  return defaultDest;
33              }
34          }
35          return new File(srcRoot_, frpath);
36      }
37  
38      public File toDestFile(String suffix) {
39          return new File(destRoot_, rpath_ + suffix + extension_);
40      }
41  
42      public String getExtension() {
43          return extension_;
44      }
45  }