List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:reconf.client.constructors.MapConstructor.java
public Object construct(MethodData data) throws Throwable { if (data.hasAdapter()) { return data.getAdapter().adapt(data.getValue()); }/*from w w w .java2 s . c om*/ Class<?> returnClass = null; Type keyType = null; Type valueType = null; if (data.getReturnType() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) data.getReturnType(); returnClass = (Class<?>) parameterized.getRawType(); if (parameterized.getActualTypeArguments().length == 1) { Type first = parameterized.getActualTypeArguments()[0]; if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } if (parameterized.getActualTypeArguments()[0] instanceof TypeVariable) { keyType = first; valueType = parameterized.getActualTypeArguments()[1]; } else if (parameterized.getActualTypeArguments()[1] instanceof TypeVariable) { valueType = first; keyType = parameterized.getActualTypeArguments()[0]; } else { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } } } else { keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } } else if (data.getReturnType() instanceof Class) { returnClass = (Class<?>) data.getReturnType(); if (returnClass.getGenericSuperclass() != null && returnClass.getGenericSuperclass() instanceof ParameterizedType) { ParameterizedType parameterized = (ParameterizedType) returnClass.getGenericSuperclass(); if (parameterized.getActualTypeArguments().length != 2) { throw new IllegalArgumentException( msg.format("error.cant.build.type", data.getReturnType(), data.getMethod())); } keyType = parameterized.getActualTypeArguments()[0]; valueType = parameterized.getActualTypeArguments()[1]; } else { keyType = Object.class; valueType = Object.class; } } else { throw new IllegalArgumentException(msg.format("error.return", data.getMethod())); } if (returnClass.isInterface()) { returnClass = getDefaultImplementation(data, returnClass); } Constructor<?> constructor = returnClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); Map<Object, Object> mapInstance = (Map<Object, Object>) constructor .newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); if (null == data.getValue() || StringUtils.isEmpty(data.getValue())) { return mapInstance; } if ((!(keyType instanceof Class)) || (!StringUtils.startsWith(data.getValue(), "[") || !StringUtils.endsWith(data.getValue(), "]"))) { throw new IllegalArgumentException(msg.format("error.build", data.getValue(), data.getMethod())); } StringParser parser = new StringParser(data); for (Entry<String, String> each : parser.getTokensAsMap().entrySet()) { Object value = ObjectConstructorFactory.get(valueType) .construct(new MethodData(data.getMethod(), valueType, each.getValue())); mapInstance.put(ObjectConstructorFactory.get(keyType) .construct(new MethodData(data.getMethod(), keyType, each.getKey())), value); } return mapInstance; }
From source file:se.nrm.dina.logic.util.NamedQueries.java
/** * Creates a query string/* w w w. java2 s.c o m*/ * @param entityName * @param clazz * @param sort * @param orderBy * @return String */ public String createQueryFindAll(String entityName, Class clazz, String sort, List<String> orderBy) { StringBuilder sb = new StringBuilder(); sb.append("SELECT e From "); sb.append(entityName); sb.append(" e "); try { if (orderBy != null && !orderBy.isEmpty()) { buildOrderByString(clazz, orderBy, sort, sb); } else { buildSorting(clazz, sort, sb); } String string = sb.toString().trim(); if (StringUtils.endsWith(string, ",")) { string = StringUtils.substringBeforeLast(string, ","); } return string; } catch (DinaException e) { throw e; } }
From source file:se.nrm.dina.logic.util.NamedQueries.java
/** * Creates a query string//from ww w . j a v a 2s . com * @param entityName * @param clazz * @param sort * @param orderBy * @param isExact * @param criteria * @return String */ public String createQueryFindAllWithSearchCriteria(String entityName, Class clazz, String sort, List<String> orderBy, boolean isExact, Map<String, String> criteria) { StringBuilder sb = new StringBuilder(); sb.append("SELECT e From "); sb.append(entityName); sb.append(" e "); try { if (criteria != null && !criteria.isEmpty()) { String buildCriteria = " WHERE "; sb.append(buildCriteria); sb.append(buildSearchCriteria(clazz, criteria, isExact)); } if (orderBy != null && !orderBy.isEmpty()) { buildOrderByString(clazz, orderBy, sort, sb); } else { buildSorting(clazz, sort, sb); } String string = sb.toString().trim(); if (StringUtils.endsWith(string, ",")) { string = StringUtils.substringBeforeLast(string, ","); } return string; } catch (DinaException e) { throw e; } }
From source file:vng.paygate.domain.common.NumberUtils.java
public static boolean checkAccountName(String accountName) { if ((StringUtils.isBlank(accountName)) || (accountName.length() > 32) || (accountName.length() < 4)) { return false; }/*from w w w.j a va 2 s . c om*/ if ((StringUtils.startsWith(accountName, ".")) || (StringUtils.startsWith(accountName, "_")) || (StringUtils.endsWith(accountName, ".")) || (StringUtils.endsWith(accountName, "_")) || (StringUtils.contains(accountName, "__")) || (StringUtils.contains(accountName, "..")) || (StringUtils.contains(accountName, "_.")) || (StringUtils.contains(accountName, "._"))) { return false; } if ((StringUtils.contains(accountName, ".")) || (StringUtils.contains(accountName, "_"))) { String accountTemp = StringUtils.remove(accountName, "."); accountTemp = StringUtils.remove(accountTemp, "_"); if (StringUtils.isNumeric(accountTemp)) { return true; } } accountName = StringUtils.remove(accountName, "."); accountName = StringUtils.remove(accountName, "_"); if ((!StringUtils.isAlphanumeric(accountName)) || (!StringUtils.isAsciiPrintable(accountName))) { return false; } return true; }
From source file:webx.studio.projectcreation.ui.GeneralUtils.java
public static void processTemplate(File srcDir, File destDir, final Properties context, final List<String> templateNameList, NameRule nameRule, List<ModuleProjectInformation> webModuleProjectList, ModuleProjectInformation deployModuleProjectInformation) throws Exception { if (srcDir == null || destDir == null || !srcDir.exists()) return;/*from w w w. ja va2 s . c o m*/ if (destDir.exists()) { if (destDir.isDirectory() == false) { throw new IOException("Destination '" + destDir + "' exists but is not a directory"); } } else { if (destDir.mkdirs() == false) { throw new IOException("Destination '" + destDir + "' directory cannot be created"); } } File[] files = srcDir.listFiles(); for (File file : files) { if (SVN_DIRECTORY.equals(file.getName())) { continue; } File outFile = new File(destDir, file.getName()); if (file.isDirectory()) { processTemplate(file, outFile, context, templateNameList, nameRule, webModuleProjectList, deployModuleProjectInformation); } else { if (templateNameList.contains(file.getName())) { if (ProjectCreationConstants.SPECIAL_TEMPLATE_FILE.equalsIgnoreCase(file.getName())) { for (ModuleProjectInformation info : webModuleProjectList) { outFile = new File(destDir, getWebxDescriptionFileName(info.getInputName())); formatContext(context, nameRule, info.getInputName()); processTemplateFile(outFile, context, file); } } else if (ProjectCreationConstants.HELLOWORLD_TEMPLATE_FILE.equalsIgnoreCase(file.getName())) { for (ModuleProjectInformation info : webModuleProjectList) { String pkg = getScreenPackage(nameRule, info.getInputName()); File outDir = getPackageDir(info.getProjectDir(), pkg); outFile = new File(outDir, ProjectCreationConstants.HELLOWORLD_TEMPLATE_FILE); context.put(ProjectCreationConstants.PACKAGE_KEY, pkg); context.put(ProjectCreationConstants.MESSAGE_KEY, "HelloWorld comes from " + info.getArtfiactId()); processTemplateFile(outFile, context, file); } } else if (ProjectCreationConstants.HELLOWORLD_VM_FILE.equalsIgnoreCase(file.getName())) { for (ModuleProjectInformation info : webModuleProjectList) { outFile = new File( context.getProperty(ProjectCreationConstants.TEMPLATE_ROOT_KEY) + File.separator + info.getInputName() .substring(info.getInputName().lastIndexOf(".") + 1) + File.separator + "screen"); outFile.mkdirs(); FileUtils.copyFileToDirectory(file, outFile); // FileUtils.c } } else { processTemplateFile(outFile, context, file); } } else if (StringUtils.contains(file.getAbsolutePath(), "deploy") && (StringUtils.endsWith(file.getName(), ".vm") || StringUtils.equals(file.getName(), "auto-config.xml"))) { String content = org.apache.commons.io.FileUtils.readFileToString(file); content = StringUtils.replace(content, "@appName@", nameRule.getProjectName()); FileUtils.writeStringToFile(outFile, content); } else { FileUtils.copyFile(file, outFile); } } } }