List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {/*from w w w . ja va 2 s . c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:jclparser.NewClass.java
public static File analyze(File f) { String procedure = StringUtils.substringBeforeLast(f.getName(), "."); if (f.exists()) { f.delete();/* w ww . j a va 2 s .c o m*/ } System.out.println("gepeto args2 = " + procedure); String tmp; PROC proc = parse(PROC.class, "SYS1.VIDA.PROCLIB", procedure); List<STEP> steps = proc.getListSTEP(); List<String> nodes = new ArrayList<>(); List<String> fromsTos = new ArrayList<>(); String nodeTemplate = "{\"key\": \"%s\", \"category\": \"program\", \"color\": \"lightblue\", \"label\": \"%s\", \"num\": \"%s\", \"card\": \"%s\"},"; String dsnTemplate = "{\"key\": \"%s\", \"color\": \"magenta\", \"label\": \"%s\"},"; String fromToTemplate = "{\"from\": \"%s\", \"to\": \"%s\"},"; Map<String, Integer> programs = new HashMap<>(); Set<String> files = new HashSet<>(); for (STEP step : steps) { String pgm = step.getProgram().getName(); String xxx = ""; CARD card = step.getProgram().getCard(); if (card != null) { if (card instanceof CARD_IKJEFT01) { pgm = ((CARD_IKJEFT01) card).getProgram(); } xxx = step.getProgram().getCard().toString(); System.out.println("VVV " + step.getProgram().getCard().toString()); // if (card instanceof CARD_SORT) { // pgm = ((CARD_SORT) card).getProgram(); // } } Integer num = programs.get(pgm); num = num == null ? 1 : num + 1; programs.put(pgm, num); if (num > 1) { pgm = pgm + " (" + num + ")"; } String t = String.format(nodeTemplate, pgm, "XXX", "XXX", xxx); nodes.add(t); List<DSN> dsns = step.getListDSN(); for (DSN dsn : dsns) { if (dsn.getName().trim().isEmpty()) { continue; } if (files.add(dsn.getName())) { String u = String.format(dsnTemplate, dsn.getName(), dsn.getLabel()); files.add(nodeTemplate); nodes.add(u); } String from = dsn.getMode().equals("INPUT") ? dsn.getName() : pgm; String to = !dsn.getMode().equals("INPUT") ? dsn.getName() : pgm; tmp = String.format(fromToTemplate, from, to); if (!pgm.equalsIgnoreCase("COPIADOR")) { fromsTos.add(tmp); } System.out.println("Label: " + StringUtils.rightPad(dsn.getLabel(), 8) + " Dsn: " + dsn.getName() + " Type: " + dsn.getType() + " Mode: " + dsn.getMode()); } } String lastNode = nodes.remove(nodes.size() - 1); lastNode = StringUtils.removeEnd(lastNode, ","); nodes.add(lastNode); String lastFromsTos = fromsTos.remove(fromsTos.size() - 1); lastFromsTos = StringUtils.removeEnd(lastFromsTos, ","); fromsTos.add(lastFromsTos); try { FileUtils.writeStringToFile(f, "{\"class\": \"go.GraphLinksModel\",\"nodeDataArray\": [", true); FileUtils.writeLines(f, nodes, true); FileUtils.writeStringToFile(f, "],", true); FileUtils.writeStringToFile(f, "\"linkDataArray\": [", true); FileUtils.writeLines(f, fromsTos, true); FileUtils.writeStringToFile(f, "]}", true); } catch (IOException ex) { Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("directoru " + f.getAbsolutePath()); // for (String node : nodes) { // System.out.println(node + ","); // } // // for (String fromTo : fromsTos) { // System.out.println(fromTo + ","); // } return f; }
From source file:com.cognifide.qa.bb.aem.touch.util.DataPathUtil.java
/** * Method normalizes data path. Checks if last character of path is digit, if yes, then returns substring * before last {@code _} occurrence./*from w w w. j ava2 s. com*/ * Example: for given in parameter string '/title_1234' method will return '/title' * * @param dataPath data path. * @return normalized data path. */ public static String normalize(String dataPath) { return Character.isDigit(dataPath.charAt(dataPath.length() - 1)) ? StringUtils.substringBeforeLast(dataPath, "_") : dataPath; }
From source file:com.lianggzone.freemarkerutils.utils.FreeMarkerFactory.java
/** * ?ftl?,???HTML/*from w w w . j a va 2s . com*/ * @param ftlPath FTL?,["c:/liang/template.ftl"] * @param filePath ?HMTL["d:/liang/lianggzone.html"] * @param data Map? * @param isCreate4NoExists ?? * @return */ public static boolean createHTML(String ftlPath, String filePath, Map<String, Object> data, boolean isCreate4NoExists) throws IOException { String fileDir = StringUtils.substringBeforeLast(filePath, "/"); // ?HMTL // String fileName = StringUtils.substringAfterLast(filePath, "/"); // ?HMTL?? String ftlDir = StringUtils.substringBeforeLast(ftlPath, "/"); // ?FTL String ftlName = StringUtils.substringAfterLast(ftlPath, "/"); // ?FTL?? //? if (isCreate4NoExists) { File realDirectory = new File(fileDir); if (!realDirectory.exists()) { realDirectory.mkdirs(); } } // step1 ?freemarker? Configuration freemarkerCfg = new Configuration(Configuration.VERSION_2_3_23); // step2 freemarker??() freemarkerCfg.setDirectoryForTemplateLoading(new File(ftlDir)); // step3 freemarker?? freemarkerCfg.setEncoding(Locale.getDefault(), CharEncoding.UTF_8); // step4 freemarker? Template template = freemarkerCfg.getTemplate(ftlName, CharEncoding.UTF_8); // step5 ?IO? try (Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(new File(filePath)), CharEncoding.UTF_8))) { writer.flush(); // step6 ?? template.process(data, writer); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:com.zht.common.codegen.excute.impl.DaoGeneratorImpl.java
public void genDaoInterface(String entityFullClassName) { DaoInterfaceModel daoModel = new DaoInterfaceModel(); //??/* ww w. j ava 2 s.c om*/ String entitySimpleName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String packageName = str + ".dao"; daoModel.setPackageName(packageName); daoModel.setEntitySimpleClassName(entitySimpleName); String className = "I" + entitySimpleName + "Dao"; Map<String, Object> data = new HashMap<String, Object>(); data.put("model", daoModel); String filePath = new String( GenConstant.project_path + "src/" + package2path(packageName) + "/" + className + ".java"); super.generate(GenConstant.daoInterface_template_dir, data, filePath); }
From source file:com.zht.common.codegen.excute.impl.ServiceGeneratorImpl.java
@Override public void genServiceInterface(String entityFullClassName) { ServiceInterfaceModel serviceModel = new ServiceInterfaceModel(); //??/*w w w . j a v a2 s .c om*/ String entitySimpleName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String packageName = str + ".service"; serviceModel.setPackageName(packageName); serviceModel.setEntitySimpleClassName(entitySimpleName); serviceModel.setEntityFullClassName(entityFullClassName); String className = "I" + entitySimpleName + "Service"; Map<String, Object> data = new HashMap<String, Object>(); data.put("model", serviceModel); String filePath = new String( GenConstant.project_path + "src/" + package2path(packageName) + "/" + className + ".java"); super.generate(GenConstant.serviceInterface_template_dir, data, filePath); }
From source file:dtu.ds.warnme.app.ws.client.restful.utils.RestUtils.java
public static String getAbsoluteAddress(RestClient rc, String... resourceSuffixes) { StringBuilder absoluteAddress = new StringBuilder(); absoluteAddress.append(HttpConstants.PROTOCOL_HTTPS).append(rc.getHost()).append(HttpConstants.COLON) .append(rc.getPort()).append(rc.getWsContextPath()); for (String resourceSuffix : resourceSuffixes) { if (!resourceSuffix.startsWith(HttpConstants.PATH_SEPARATOR)) { absoluteAddress.append(HttpConstants.PATH_SEPARATOR); }// ww w. ja va2s . com if (resourceSuffix.endsWith(HttpConstants.PATH_SEPARATOR)) { resourceSuffix = StringUtils.substringBeforeLast(resourceSuffix, HttpConstants.PATH_SEPARATOR); } absoluteAddress.append(resourceSuffix); } Log.d(TAG, "Constructed address: " + absoluteAddress.toString()); return absoluteAddress.toString(); }
From source file:com.zht.common.codegen.excute.impl.HiberModelgeneratorImpl.java
@Override public void generatorModel(String entityFullClassName, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { HIberEntityModel hiberModel = new HIberEntityModel(); //??/* w w w. j av a 2 s . c o m*/ String entitySimpleName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String packageName = str + ".model"; hiberModel.setPackageName(packageName); hiberModel.setEntitySimpleClassName(entitySimpleName); hiberModel.setEntityFullClassName(entityFullClassName); hiberModel.setGenEntity(genEntity); hiberModel.setGenEntityPropertyList(genEntityPropertyList); String className = entitySimpleName; Map<String, Object> data = new HashMap<String, Object>(); data.put("model", hiberModel); String filePath = new String( GenConstant.project_path + "src/" + package2path(packageName) + "/" + className + ".java"); super.generate(GenConstant.hiberModel_template_dir, data, filePath); }
From source file:com.zht.common.generator.excute.impl.ActionGeneratorImpl.java
@Override public void generatorAction(String entityFullClassName, String controllerNameSpace, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { ActionModel actionModel = new ActionModel(); //??//from w ww.j a v a2 s . c om String entitySimpleName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String packageName = str + ".web"; String servicePackageName = str + ".service"; actionModel.setPackageName(packageName); actionModel.setEntitySimpleClassName(entitySimpleName); actionModel.setServicePackageName(servicePackageName); actionModel.setEntityFullClassName(entityFullClassName); actionModel.setControllerNameSpace(controllerNameSpace); actionModel.setGenEntityPropertyList(genEntityPropertyList); actionModel.setGenEntity(genEntity); String className = entitySimpleName + "Controller"; Map<String, Object> data = new HashMap<String, Object>(); data.put("model", actionModel); String filePath = new String( GenConstant.project_path + "src/" + package2path(packageName) + "/" + className + ".java"); super.generate(GenConstant.action_template_dir, data, filePath); }
From source file:com.zht.common.codegen.excute.impl.ActionGeneratorImpl.java
@Override public void generatorAction(String entityFullClassName, String controllerNameSpace, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { ActionModel actionModel = new ActionModel(); //??// w w w .ja v a2 s . c o m String entitySimpleName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String packageName = str + ".web"; String servicePackageName = str + ".service"; actionModel.setPackageName(packageName); actionModel.setEntitySimpleClassName(entitySimpleName); actionModel.setServicePackageName(servicePackageName); actionModel.setEntityFullClassName(entityFullClassName); actionModel.setControllerNameSpace(controllerNameSpace); actionModel.setGenEntityPropertyList(genEntityPropertyList); actionModel.setGenEntity(genEntity); String className = entitySimpleName + "Controller"; Map<String, Object> data = new HashMap<String, Object>(); data.put("model", actionModel); String filePath = new String( GenConstant.project_path + "src/" + package2path(packageName) + "/" + className + ".java"); if (genEntity == null || genEntityPropertyList == null) { super.generate(GenConstant.action_template_just_from_main_dir, data, filePath); } else { super.generate(GenConstant.action_template_dir, data, filePath); } }