package tiles.refactor; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import tiles.refactor.beans.ModuleTiles; public class TilesUtils { public static final String SOURCE_FILE_PREPEND = "home/nmld/runtime-EclipseApplication/fenix-mod-struts/src/"; public static final String PROPERTIES_FILE_OF_TILES_FILES = "/home/nmld/workspace/struts-parser/tiles.definitions.index"; public static final String ANNOTATED_ACTIONS_LIST = "/home/nmld/workspace/struts-parser/actions.annotated.list"; public static final String DEFAULT_TILES_FOLDER = "layouts"; public static final String DEFAULT_MODULE = "default"; public static List fetchTilesFilesNames() { List resultList = new ArrayList(); try { Map tilesMap = new HashMap(); Properties properties = new Properties(); FileInputStream in = new FileInputStream(PROPERTIES_FILE_OF_TILES_FILES); properties.load(in); in.close(); String tilesFiles = properties.getProperty("tiles.files"); for (String filename : tilesFiles.split(",")) { String tmp = filename.substring(filename.lastIndexOf("tiles/") + 6); String moduleName = tmp.substring(0, tmp.lastIndexOf('/')); if (moduleName.equals(DEFAULT_TILES_FOLDER)) { moduleName = "default"; } ModuleTiles moduleTiles; if (!tilesMap.containsKey(moduleName)) { moduleTiles = new ModuleTiles(moduleName); tilesMap.put(moduleName, moduleTiles); } else { moduleTiles = tilesMap.get(moduleName); } moduleTiles.addModuleTilesFile(filename); } resultList.addAll(tilesMap.values()); } catch (IOException e) { e.printStackTrace(); } return resultList; } public static List fetchAnnotatedClasses() throws Exception { List result = new ArrayList(); BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(ANNOTATED_ACTIONS_LIST)))); String strLine; while ((strLine = in.readLine()) != null) { result.add(strLine); } } finally { if (in != null) in.close(); } return result; } public static String fetchCompilationUnitName(String fullPathName) { return fullPathName.substring(SOURCE_FILE_PREPEND.length() + 1, fullPathName.length() - 5).replace('/', '.'); } }