1 package net.sourceforge.pmd; 2 3 import java.io.File ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 7 12 public class SourceTypeDiscoverer { 13 14 18 private Map mapExtensionOnSourceType = new HashMap (); 19 20 23 public SourceTypeDiscoverer() { 24 initialize(); 25 } 26 27 30 private void initialize() { 31 mapExtensionOnSourceType.put(SourceFileConstants.JSP_EXTENSION_UPPERCASE, SourceType.JSP); 32 mapExtensionOnSourceType.put(SourceFileConstants.JSPX_EXTENSION_UPPERCASE, SourceType.JSP); 33 34 mapExtensionOnSourceType.put(SourceFileConstants.JAVA_EXTENSION_UPPERCASE, SourceType.JAVA_14); 36 } 37 38 44 public SourceType getSourceTypeOfFile(File sourceFile) { 45 String fileName = sourceFile.getName(); 46 return getSourceTypeOfFile(fileName); 47 } 48 49 55 public SourceType getSourceTypeOfFile(String fileName) { 56 SourceType sourceType = null; 57 58 int extensionIndex = 1 + fileName.lastIndexOf('.'); 59 if (extensionIndex > 0) { 60 String extensionUppercase = fileName.substring(extensionIndex).toUpperCase(); 61 62 sourceType = (SourceType) mapExtensionOnSourceType 63 .get(extensionUppercase); 64 } 65 66 return sourceType; 67 } 68 69 75 public void setSourceTypeOfJavaFiles(SourceType sourceType) { 76 mapExtensionOnSourceType.put(SourceFileConstants.JAVA_EXTENSION_UPPERCASE, sourceType); 77 } 78 79 public SourceType getSourceTypeOfJavaFiles() { 80 return (SourceType) mapExtensionOnSourceType.get(SourceFileConstants.JAVA_EXTENSION_UPPERCASE); 81 } 82 } 83 | Popular Tags |