1 13 package org.pentaho.repository.filebased.solution; 14 15 import java.io.File ; 16 17 import org.pentaho.core.solution.ISolutionFile; 18 19 public class FileSolutionFile implements ISolutionFile { 20 String solutionName = ""; 22 String pathName = ""; 24 String fileName = ""; 26 int solutionAbsoluteStart = 0; 27 28 File file = null; 29 30 private FileSolutionFile(File file, int solutionAbsoluteStart, int solutionNameLength) { 31 this.solutionAbsoluteStart = solutionAbsoluteStart; 33 34 String fullName = file.getAbsolutePath().substring(solutionAbsoluteStart); 37 38 fullName = fullName.replace('\\', '/'); 41 42 solutionName = fullName.substring(0, solutionNameLength); 43 44 fileName = file.getName(); 45 if (file.isDirectory()) { 46 this.file = file; if (fullName.length() > solutionNameLength) { 49 pathName = fullName.substring(solutionNameLength + 1); 50 } 51 } else { 52 if (fullName.length() > (solutionNameLength + fileName.length() + 1)) { 53 pathName = fullName.substring(solutionNameLength + 1, fullName.length() - fileName.length() - 1); 54 } 55 } 56 } 57 58 public FileSolutionFile(File file, File solutionRoot) { 59 this(file, (solutionRoot == null) ? 0 : solutionRoot.getAbsolutePath().length() - solutionRoot.getName().length(), (solutionRoot == null) ? 0 : solutionRoot.getName().length()); 60 } 61 62 public boolean isDirectory() { 63 return (file != null); 64 } 65 66 public String getFileName() { 67 return (fileName); 68 } 69 70 public String getSolutionPath() { 71 return (pathName); 72 } 73 74 public String getSolution() { 75 return (solutionName); 76 } 77 78 public String getFullPath() { 79 String fullName = solutionName; 80 if (pathName.length() > 0) { 81 fullName += "/" + pathName; } 83 if (!isDirectory() && (fileName.length() > 0)) { 84 fullName += "/" + fileName; } 86 return (fullName); 87 } 88 89 public String getFileType() { 90 int dotIndex = fileName.lastIndexOf('.'); 91 return ((dotIndex < 0) ? "" : fileName.substring(dotIndex)); } 93 94 public ISolutionFile[] listFiles() { 95 if (file == null) { 96 return (null); 97 } 98 99 File files[] = file.listFiles(); 100 if (files == null) { 101 return (null); 102 } 103 104 ISolutionFile solFiles[] = new ISolutionFile[files.length]; 105 FileSolutionFile solFile; 106 for (int i = 0; i < files.length; ++i) { 107 solFile = new FileSolutionFile(files[i], solutionAbsoluteStart, solutionName.length()); 108 solFiles[i] = solFile; 109 } 110 111 return (solFiles); 112 } 113 114 public String toString() { 115 return (getSolution() + " : " + getSolutionPath() + " : " + getFileName() + " : " + getFileType()); } 117 118 public static void main(String [] args) { 119 File f = new File ("E:/eclipse/workspace/pentaho-samples/solutions/test-solution"); printRecursive(new FileSolutionFile(f, f)); 121 } 122 123 private static void printRecursive(ISolutionFile sFile) { 124 if (sFile.isDirectory()) { 125 ISolutionFile sFiles[] = sFile.listFiles(); 126 for (int i = 0; i < sFiles.length; ++i) { 127 printRecursive(sFiles[i]); 128 } 129 } 130 } 131 132 public boolean isRoot() { 133 return false; 135 } 136 137 } 138 | Popular Tags |