Java Code Examples for org.apache.commons.lang.StringUtils#substring()

The following examples show how to use org.apache.commons.lang.StringUtils#substring() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataEventListenerPostProcessor.java    From koper with Apache License 2.0 6 votes vote down vote up
/**
 * 根据Listener的数据对象名和方法名构造topic, 并向Listener注册中心注册。
 * 方法名: 例如: insertOrder_B, onCompoleteOrder, compoleteOrder, completeOrder_X
 *
 * @param listener
 * @param method
 */
private void registerDataEventListener(Object listener, String dataObjectName, Method method) {
    String methodName = method.getName();

    String topic = null;

    String eventName = methodName;
    if (methodName.startsWith("on")) {
        eventName = StringUtils.substring(methodName, 2);
        eventName = String.valueOf(eventName.charAt(0)).toLowerCase() + eventName.substring(1);
    }

    topic = dataObjectName + "." + eventName;
    //注册
    registerListener(listener, topic);
}
 
Example 2
Source File: FileUtils.java    From Aooms with Apache License 2.0 5 votes vote down vote up
/** 
 * 获取扩展名 不带点
 *  
 * @param fileName 
 * @return 
 */  
public static String getExtensionNoDot(String fileName) {  
    if (StringUtils.INDEX_NOT_FOUND == StringUtils.indexOf(fileName, DOT))  
        return StringUtils.EMPTY;  
    String ext = StringUtils.substring(fileName,  
            StringUtils.lastIndexOf(fileName, DOT) + 1);  
    return StringUtils.trimToEmpty(ext);  
}
 
Example 3
Source File: RangerPerfTracer.java    From ranger with Apache License 2.0 5 votes vote down vote up
public static RangerPerfTracer getPerfTracer(Log logger, String tag) {
	String data = "";
	String realTag = "";

	if (tag != null) {
		int indexOfTagEndMarker = StringUtils.indexOf(tag, tagEndMarker);
		if (indexOfTagEndMarker != -1) {
			realTag = StringUtils.substring(tag, 0, indexOfTagEndMarker);
			data = StringUtils.substring(tag, indexOfTagEndMarker);
		} else {
			realTag = tag;
		}
	}
	return RangerPerfTracerFactory.getPerfTracer(logger, realTag, data);
}
 
Example 4
Source File: CompositeImageName.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
static boolean containsTag(String imageName) {
  if (StringUtils.contains(imageName, ":")) {
    if (StringUtils.contains(imageName, "/")) {
      final String registryPart = StringUtils.substringBeforeLast(imageName, "/");
      final String imageNamePart = StringUtils.substring(imageName, registryPart.length() + 1);

      return StringUtils.contains(imageNamePart, ":");
    } else {
      return true;
    }
  }

  return false;
}
 
Example 5
Source File: BatchStepFileDescriptor.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
   * Retrieves the extension from the File
   *
   * @param runFile the semaphore file
   * @return the extension
   */
  private String getExtensionFromFile(File runFile) {
  	String runFileName = runFile.getName();
int indexOfExtension = runFileName.lastIndexOf(STEP_FILE_EXTENSION_SEPARATOR);
String extension = StringUtils.substring(runFileName, indexOfExtension+1);
return extension;
  }
 
Example 6
Source File: ModeUtils.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static String tryBuildYearlyPattern(String value) {
    String valueSuffix = StringUtils.substring(value, value.length() - 4);
    try {
        DateUtils.parseDate(valueSuffix, new String[]{"yyyy"});
        return StringUtils.substring(value, 0, value.length() - 4) + YEAR_SUFFIX;
    } catch (ParseException e) {
    }
    return value;
}
 
Example 7
Source File: LdapImportUsersCmd.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private Domain getDomainForName(String name) {
    Domain domain = null;
    if (StringUtils.isNotBlank(name)) {
        //removing all the special characters and trimming its length to 190 to make the domain valid.
        String domainName = StringUtils.substring(name.replaceAll("\\W", ""), 0, 190);
        if (StringUtils.isNotBlank(domainName)) {
            domain = _domainService.getDomainByName(domainName, Domain.ROOT_DOMAIN);
            if (domain == null) {
                domain = _domainService.createDomain(domainName, Domain.ROOT_DOMAIN, domainName, UUID.randomUUID().toString());
            }
        }
    }
    return domain;
}
 
Example 8
Source File: CodeInjectByJavassist.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * The injection of code for the specified jar package
 *
 * @param inJar
 * @param outJar
 * @throws IOException
 * @throws NotFoundException
 * @throws CannotCompileException
 */
public static List<String> inject(ClassPool pool,
                                  File inJar,
                                  File outJar,
                                  InjectParam injectParam) throws Exception {
    List<String> errorFiles = new ArrayList<String>();
    JarFile jarFile = newJarFile(inJar);

    outJar.getParentFile().mkdirs();
    FileOutputStream fileOutputStream = new FileOutputStream(outJar);
    JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
    Enumeration<JarEntry> jarFileEntries = jarFile.entries();
    JarEntry jarEntry = null;
    while (jarFileEntries.hasMoreElements()) {
        jarEntry = jarFileEntries.nextElement();
        String name = jarEntry.getName();
        String className = StringUtils.replace(name, File.separator, "/");
        className = StringUtils.replace(className, "/", ".");
        className = StringUtils.substring(className, 0, className.length() - 6);
        if (!StringUtils.endsWithIgnoreCase(name, ".class")) {
            InputStream inputStream = jarFile.getInputStream(jarEntry);
            copyStreamToJar(inputStream, jos, name, jarEntry.getTime(), jarEntry);
            IOUtils.closeQuietly(inputStream);
        } else {
            byte[] codes;

            codes = inject(pool, className, injectParam);
            InputStream classInstream = new ByteArrayInputStream(codes);
            copyStreamToJar(classInstream, jos, name, jarEntry.getTime(), jarEntry);

        }
    }
    jarFile.close();
    IOUtils.closeQuietly(jos);
    return errorFiles;
}
 
Example 9
Source File: RegistryParser.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
public RegistryKey parseFile(File registryFile, String rootName) {
    try (BufferedReader bufferReader = new BufferedReader(new FileReader(registryFile))) {
        final RegistryKey root = new RegistryKey(rootName);
        RegistryKey lastNode = null;
        int lineNumber = 1;
        for (String currentLine = bufferReader.readLine(); currentLine != null; currentLine = bufferReader
                .readLine()) {

            while (currentLine.trim().endsWith("\\")) {
                currentLine = StringUtils.substring(currentLine.trim(), 0, -1) + bufferReader.readLine().trim();
            }

            if (currentLine.startsWith(";") || currentLine.startsWith("#") || StringUtils.isBlank(currentLine)
                    || currentLine.startsWith("@")) {
                lineNumber++;
                continue;
            }

            if (currentLine.startsWith("[")) {
                lastNode = this.parseDirectoryLine(root, currentLine);
            } else if (lineNumber == 1) {
                lineNumber++;
                continue;
            } else if (lastNode == null) {
                throw new ParseException(String.format(PARSE_ERROR_MESSAGE, lineNumber), 0);
            } else {
                this.parseValueLine(lastNode, currentLine, lineNumber);
            }

            lineNumber++;
        }

        return root;
    } catch (IOException | ParseException e) {
        throw new IllegalArgumentException("Error while parsing the registry", e);
    }
}
 
Example 10
Source File: JobController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
@RequestMapping("")
    public String index(HttpServletRequest request, HttpServletResponse response, @RequestParam(defaultValue = "1") Integer pageIndex,
                        @RequestParam(defaultValue = "20") Integer pageSize){
        JobTalkExample example = new JobTalkExample();
        example.setOrderByClause("create_time desc");
        PageHelper.startPage(pageIndex,pageSize);
        List<JobTalkUserDetail> jobTalkList = jobTalkService.selectWithUserByExample(example);
        PageInfo page = new PageInfo(jobTalkList);
//        Integer count = jobTalkService.countByExample(example);
        request.setAttribute("count",page.getTotal());
        String content = "";
        Pattern pattern = Pattern.compile("<img.*src=(.*?)[^>]*?>");
        List<String> imgUrlList = null;
        for(JobTalkUserDetail jobTalkUserDetail : jobTalkList){
            content = jobTalkUserDetail.getContent();
            int imgIndex = content.indexOf("<img");
            if(imgIndex >= 0){
                imgUrlList = ReUtil.getAllGroups(pattern,content);
                content = ReUtil.delAll(pattern,content);
                if(content.length() > 50){
                    content = StringUtils.substring(content,0,50) +"...<br>"+ StringUtils.join(imgUrlList.toArray());;
                }else {
                    content+= StringUtils.join(imgUrlList.toArray());
                }
            }else {
                if(content.length() > 50){
                    content = StringUtils.substring(content,0,50) +"...";
                }
            }
            jobTalkUserDetail.setContent(content);
        }
        request.setAttribute("jobTalkList",jobTalkList);
        request.setAttribute("pageIndex",pageIndex);
        return "/job/index.html";
    }
 
Example 11
Source File: FileUtils.java    From Aooms with Apache License 2.0 5 votes vote down vote up
/** 
 * 获取扩展名 
 *  
 * @param fileName 
 * @return 
 */  
public static String getExtension(String fileName) {  
    if (StringUtils.INDEX_NOT_FOUND == StringUtils.indexOf(fileName, DOT))  
        return StringUtils.EMPTY;  
    String ext = StringUtils.substring(fileName,  
            StringUtils.lastIndexOf(fileName, DOT));  
    return StringUtils.trimToEmpty(ext);  
}
 
Example 12
Source File: DefaultInfluxDbMetricsRetriever.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns node id from full name.
 * The elements in full name is split by using '.';
 * We assume that the node id always comes before the last three '.'
 *
 * @param fullName full name
 * @return node id
 */
private String getNodeId(String fullName) {
    int index = StringUtils.lastOrdinalIndexOf(fullName,
            METRIC_DELIMITER, NUB_OF_DELIMITER);
    if (index != -1) {
        return StringUtils.substring(fullName, 0, index);
    } else {
        log.warn("Database {} contains malformed node id.", database);
        return null;
    }
}
 
Example 13
Source File: XOPValidationHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public void characters(char[] ch, int start, int length) throws SAXException {
   if (this.xop) {
      String content = StringUtils.substring(new String(ch), start, start + length);
      if (StringUtils.isNotBlank(content)) {
         this.xop = false;
      }
   }

}
 
Example 14
Source File: DefaultInfluxDbMetricsRetriever.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns metric name from full name.
 * The elements in full name is split by using '.';
 * We assume that the metric name always comes after the last three '.'
 *
 * @param fullName full name
 * @return metric name
 */
private String getMetricName(String fullName) {
    int index = StringUtils.lastOrdinalIndexOf(fullName,
            METRIC_DELIMITER, NUB_OF_DELIMITER);
    if (index != -1) {
        return StringUtils.substring(fullName, index + 1);
    } else {
        log.warn("Database {} contains malformed metric name.", database);
        return null;
    }
}
 
Example 15
Source File: CommandLineHelper.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected int parseInteger(String value) {
    int result = 0;
    if (value.startsWith("0x")) {
        value = StringUtils.substring(value, 2);
        result = Integer.parseInt(value, 16);
    }
    else {
        result = Integer.parseInt(value);
    }
    return result;
}
 
Example 16
Source File: AuthService.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Override
public Jws<Claims> getJwt(String jwtToken) {
    if (jwtToken.startsWith(BEARER)) {
        jwtToken = StringUtils.substring(jwtToken, BEARER.length());
    }
    return Jwts.parser()  //得到DefaultJwtParser
            .setSigningKey(signingKey.getBytes()) //设置签名的秘钥
            .parseClaimsJws(jwtToken);
}
 
Example 17
Source File: CommandLineHelper.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected long parseLong(String value) {
    long result = 0;
    if (value.startsWith("0x")) {
        value = StringUtils.substring(value, 2);
        result = Long.parseLong(value, 16);
    }
    else {
        result = Long.parseLong(value);
    }
    return result;
}
 
Example 18
Source File: TestUnitHandler.java    From sofa-acts with Apache License 2.0 4 votes vote down vote up
/**
 * Replace table param.
 *
 * @param virtualTables the virtual tables
 * @param groupIds the group ids
 */
public void replaceTableParam(List<VirtualTable> virtualTables, String... groupIds) {
    for (VirtualTable virtualTable : virtualTables) {
        if ((ArrayUtils.isEmpty(groupIds) && StringUtils.isEmpty(virtualTable.getNodeGroup()))
            || ArrayUtils.contains(groupIds, virtualTable.getNodeGroup())) {
            for (Map<String, Object> row : virtualTable.getTableData()) {
                for (String key : row.keySet()) {
                    if (String.valueOf(row.get(key)).startsWith("$")) {

                        if (actsRuntimeContext.getParamMap().containsKey(
                            String.valueOf(row.get(key)).replace("$", ""))) {
                            row.put(
                                key,
                                actsRuntimeContext.getParamMap().get(
                                    String.valueOf(row.get(key)).replace("$", "")));
                        }
                    } else if (String.valueOf(row.get(key)).startsWith("@")) {
                        //parse variables in components
                        String str = String.valueOf(row.get(key));
                        String callString = str;
                        if (StringUtils.contains(str, "$")) {
                            String query = StringUtils.substringAfter(str, "?");
                            callString = StringUtils.substringBefore(str, "?") + "?";
                            if (StringUtils.isNotBlank(query)) {
                                String[] pairs = StringUtils.split(query, "&");
                                for (String pair : pairs) {
                                    if (StringUtils.isBlank(pair)) {
                                        continue;
                                    }
                                    Object value = StringUtils.substringAfter(pair, "=");
                                    replaceByFields(value, actsRuntimeContext.getParamMap());
                                    callString = callString
                                                 + StringUtils.substringBefore(pair, "=") + "="
                                                 + value + "&";

                                }
                                callString = StringUtils.substring(callString, 0,
                                    callString.length() - 1);

                            }

                        }
                        //执行组件化参数
                        String rs = (String) ActsComponentUtil.run(callString);
                        log.info("parameterization invoke:" + callString + " result:" + rs);
                        row.put(key, rs);
                    }
                }
            }
        }
    }
}
 
Example 19
Source File: RangerURLResourceMatcher.java    From ranger with Apache License 2.0 4 votes vote down vote up
static String getScheme(String url){
    return StringUtils.substring(url,0,(StringUtils.indexOf(url,":") + 3));
}
 
Example 20
Source File: KRADUtils.java    From rice with Educational Community License v2.0 2 votes vote down vote up
/**
 * Returns the primitive part of an attribute name string.
 *
 * @param attributeName
 * @return everything AFTER the last "." character in attributeName
 */
public static String getNestedAttributePrimitive(String attributeName) {
    int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(attributeName);

    return lastIndex != -1 ? StringUtils.substring(attributeName, lastIndex + 1) : attributeName;
}