Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * Devuelve el fully qualified name de un Group a partir * del path de una pagina (preferentemente el absoluto) */ public static String getImportGroup(String path) { File arch = new File(path); path = arch.getParent(); String packAux = ""; String CADENA_CORTE = "\\"; String CADENA_CORTE2 = "/"; String SOURCE = "src"; String USE_CASES = "useCases"; String PAGES = "pages"; try { packAux = path.substring((path.indexOf(CADENA_CORTE))); } catch (StringIndexOutOfBoundsException e) { packAux = path.substring((path.indexOf(CADENA_CORTE2))); } packAux = packAux.replace("/", "."); packAux = packAux.replace("\\", "."); if (packAux.endsWith(".")) { packAux = (String) packAux.subSequence(0, packAux.lastIndexOf(".")); } packAux = packAux.substring(CADENA_CORTE.length()); String packageF = packAux; String groupImport = packageF.substring(packageF.lastIndexOf(SOURCE)); groupImport = groupImport.replace(SOURCE + ".", ""); groupImport = groupImport.replace(PAGES, ""); String caseName = groupImport.substring(groupImport.lastIndexOf(USE_CASES)); caseName = caseName.replace(".", ""); caseName = caseName.replace(USE_CASES, ""); caseName = capitalize(caseName); return groupImport + caseName + "Group"; } public static String capitalize(String str) { return (str == null || str.length() == 0) ? "" : Character.toUpperCase(str.charAt(0)) + str.substring(1); } public static String toUpperCase(String str) { return str.toUpperCase(); } }