Example usage for org.apache.commons.lang StringUtils substring

List of usage examples for org.apache.commons.lang StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substring.

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:cn.hxh.springside.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*from  w  w w  .ja  va 2 s. c  o  m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:cn.newtouch.util.orm.PropertyFilter.java

/**
 * @param filterName/*from  w w  w .  j av a 2s.c o  m*/
 *            ,???. eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value
 *            .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        this.matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        this.propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    this.propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ConvertUtils.convertStringToObject(value, this.propertyClass);
}

From source file:com.bjwg.back.util.PropertyFilter.java

/**
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value/*www. j  av  a  2 s .  c o m*/
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), filterName);
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:com.pearson.openideas.cq5.components.utils.ArticleUtils.java

/**
 * This method turns a tagged resource into an article object.
 * /*ww w .  jav a 2s.  c om*/
 * @param resource
 *            the resource to extract data from
 * @param article
 *            the article object to add data to
 * @param tagManager
 *            the tag manager instance
 * @param indexing
 *            A boolean to indicate whether to include the indexing fields or not.
 * @return the completed/populated article object
 */
public static Article createArticleObject(Resource resource, Article article, TagManager tagManager,
        boolean indexing) {

    List<String> countries = new ArrayList<String>();
    List<String> contributors = new ArrayList<String>();
    List<String> organisations = new ArrayList<String>();
    List<String> keywords = new ArrayList<String>();
    List<String> contributorBiogs = new ArrayList<String>();

    log.debug("Are we indexing? " + indexing);

    Calendar weekAgo = Calendar.getInstance();
    weekAgo.set(weekAgo.get(Calendar.YEAR), weekAgo.get(Calendar.MONTH),
            weekAgo.get(Calendar.DAY_OF_MONTH) - BEFOREDAYS);

    String path = resource.getPath();
    log.debug("path to resource: " + path);
    article.setUrl(StringUtils.substring(path, 0, path.lastIndexOf("/")));
    ValueMap articleMap = resource.getChild("articleBody").adaptTo(ValueMap.class);
    article.setShortSummary(articleMap.get("shortsummary", ""));
    article.setArticleTitle(articleMap.get("articletitle", ""));

    //pull the image from the article
    Image image = new Image(resource.getChild("articleBody").getChild("image"));
    image.setSelector(".img");
    article.setImage(image);

    //also, pull the thumbnail image from the article
    if (resource.getChild("articleBody").getChild("imagethumb") != null) {
        Image thumbnail = new Image(resource.getChild("articleBody").getChild("imagethumb"));
        thumbnail.setSelector(".img");
        log.debug("article thumbnail has an image: " + thumbnail.hasContent());
        article.setThumbnail(thumbnail);
    } else {
        log.debug("no thumbnail, falling back to article image");
        article.setThumbnail(image);
    }

    // second, we'll pull the contributor tags from however many contributor components we have
    Resource leadContribResource = resource.getChild("leadContributor");

    // pull an array of one to get the lead contributor name for rendering
    Tag[] leadContribTags = tagManager.getTags(leadContribResource);
    if (leadContribTags != null && leadContribTags.length > 0) {
        article.setAuthor(leadContribTags[0].getTitle());
    } else {
        log.warn("Article " + article.getArticleTitle() + "has no lead contributor set yet.");
    }

    if (StringUtils.isNotBlank(articleMap.get("newpublishdate", ""))) {
        Date newPubDateObject = null;
        SimpleDateFormat sdf = new SimpleDateFormat(DateFormatEnum.CQDATEFORMAT.getDateFormat());

        try {
            newPubDateObject = sdf.parse(articleMap.get("newpublishdate", ""));
        } catch (ParseException e) {
            log.error("Error parsing date", e);
        }

        if (newPubDateObject != null) {
            String newDateString = new SimpleDateFormat(DateFormatEnum.CLIENTDATEFORMAT.getDateFormat())
                    .format(newPubDateObject);
            article.setPubDate(newDateString);
            article.setPubDateObject(newPubDateObject);
            if (newPubDateObject.after(weekAgo.getTime())) {
                article.setSuitableForEmail(true);
            }

        } else {
            log.warn("new pub date object is null");
        }
    } else {
        log.debug("Trying to parse original date object");
        Date originalPubDateObject = resource.adaptTo(ValueMap.class).get("jcr:created", Date.class);
        log.debug("original pub date: " + originalPubDateObject.toString());
        String originalPublishDateString = new SimpleDateFormat(DateFormatEnum.CLIENTDATEFORMAT.getDateFormat())
                .format(originalPubDateObject);
        article.setPubDate(originalPublishDateString);
        article.setPubDateObject(originalPubDateObject);
        if (originalPubDateObject.after(weekAgo.getTime())) {
            article.setSuitableForEmail(true);
        }
    }

    Tag[] tags = tagManager.getTags(resource);
    for (Tag tagFromPage : tags) {
        String tagPath = tagFromPage.getPath();

        if (tagPath.contains(NamespaceEnum.THEME.getNamespace())) {
            article.setTheme(tagFromPage.getTitle());
        } else if (tagPath.contains(NamespaceEnum.CATEGORY.getNamespace())) {
            article.setCategory(tagFromPage.getTitle());
        } else if (indexing && tagPath.contains(NamespaceEnum.CONTRIBUTOR.getNamespace())) {
            contributors.add(tagFromPage.getTitle());
            contributorBiogs.add(tagFromPage.getDescription());
        } else if (indexing && tagPath.contains(NamespaceEnum.KEYWORD.getNamespace())) {
            keywords.add(tagFromPage.getTitle());
        } else if (indexing && tagPath.contains(NamespaceEnum.ORGANISATION.getNamespace())) {
            organisations.add(tagFromPage.getTitle());
        } else if (indexing && tagPath.contains(NamespaceEnum.COUNTRY.getNamespace())) {
            countries.add(tagFromPage.getTitle());
        }
    }

    if (indexing) {
        article.setContributors(contributors);
        article.setCountries(countries);
        article.setOrganisations(organisations);
        article.setKeywords(keywords);
        article.setContributorBiogs(contributorBiogs);
        article.setCitation(articleMap.get("citation", ""));
        String articleText = articleMap.get("text", "");

        Resource par = resource.getChild("par");

        if (par != null) {
            Iterator<Resource> parResources = par.listChildren();
            while (parResources.hasNext()) {
                Resource parResource = parResources.next();
                ValueMap resourceMap = parResource.adaptTo(ValueMap.class);
                String type = resourceMap.get("sling:resourceType", "");
                if (type.endsWith("articleText")) {
                    articleText += resourceMap.get("text", "");
                }
            }
        }
        article.setArticleText(articleText);
    }
    return article;

}

From source file:com.kabone.research.common.utils.FileUtil.java

/**
 * ?//  w w  w .  java 2s .c om
 * @param map
 * @param realPath
 * @param dirPath
 * @param thumbnail
 * @return
 * @throws IllegalStateException
 * @throws IOException
 */
public static List<Map<String, Object>> getFileInfo(MultiValueMap<String, MultipartFile> map, String realPath,
        String dirPath, boolean thumbnail) throws IllegalStateException, IOException {

    Date time = Calendar.getInstance().getTime();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssS");
    String formatDate = formatter.format(time);

    List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();

    Iterator<String> iterator = map.keySet().iterator();

    //  savePath ? /yyyy/mm/ ??   
    String savePath = dirPath + File.separator + StringUtils.substring(formatDate, 0, 4) + File.separator
            + StringUtils.substring(formatDate, 4, 6) + File.separator;

    String realFilePath = realPath + savePath;
    String logicalPath = savePath;

    if (File.separator.equalsIgnoreCase("\\")) {
        logicalPath = savePath.replaceAll("\\\\", "/");
    }

    while (iterator.hasNext()) {

        Map<String, Object> fileMap = new HashMap<String, Object>();

        String key = iterator.next();
        LinkedList<MultipartFile> df = (LinkedList<MultipartFile>) map.get(key);

        CommonsMultipartFile fileInfo = (CommonsMultipartFile) df.getFirst();
        if (fileInfo.getSize() > 0) {
            fileMap.put("key", key);

            int idx = fileInfo.getOriginalFilename().lastIndexOf(".");

            String extName = "";
            if (idx != -1) {
                extName = fileInfo.getOriginalFilename().substring(idx,
                        fileInfo.getOriginalFilename().length());
            }

            File fDir = new File(realFilePath);
            if (!fDir.exists()) {
                fDir.mkdirs();
            }

            File file1 = new File(realFilePath + formatDate + fileInfo.getName() + extName);
            fileInfo.transferTo(file1);

            logger.info("fileInfo.realFilePath() : " + realFilePath);
            logger.info("fileInfo.logicalPath() : " + logicalPath);
            logger.info("fileInfo.getOriginalFilename() : " + fileInfo.getOriginalFilename());
            logger.info("fileInfo.getName() : " + fileInfo.getName());
            logger.info("fileInfo.path() : " + logicalPath + formatDate + fileInfo.getName() + extName);

            fileMap.put("path", logicalPath + formatDate + fileInfo.getName() + extName);
            fileMap.put("name", fileInfo.getOriginalFilename());
            fileMap.put("size", "" + fileInfo.getSize());

            //??
            if (thumbnail) {
                int imageWidth = 0;
                int imageHeight = 0;
                //? ? ?? ?
                if ("mainImg".equals(fileInfo.getName())) {
                    logger.info("? ? ?? ?");
                    imageWidth = 645;
                    imageHeight = 485;
                } else if ("cardImg".equals(fileInfo.getName())) {
                    logger.info(" ? ?? ?");
                    imageWidth = 240;
                    imageHeight = 180;
                }

                if (imageWidth != 0 && imageHeight != 0) {
                    File originFileName = new File(realFilePath + formatDate + fileInfo.getName() + extName);
                    File thumbFileName = new File(
                            realFilePath + "thumbnail_" + formatDate + fileInfo.getName() + extName);

                    thumbnail(imageWidth, imageHeight, originFileName, thumbFileName);

                    fileMap.put("thumb",
                            logicalPath + "thumbnail_" + formatDate + fileInfo.getName() + extName);
                }
            }
            fileList.add(fileMap);
        }

    }

    return fileList;
}

From source file:com.blue.ssh.core.orm.PropertyFilter.java

/**
 * @param filterName//from  w w w.  j av a 2 s .co m
 *            ,???. eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value
 *            .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:com.haulmont.cuba.core.entity.FileDescriptor.java

public void setExtension(String extension) {
    this.extension = StringUtils.substring(extension, 0, 20);
}

From source file:com.cndatacom.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from   w  w w. ja v a2s .  c om
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    this.filterName = filterName;
    this.value = value;

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    //,EQ
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    //?,S?I
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    //propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);
    propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    if (propertyNameStr.indexOf(LEFT_JION) != -1) {
        isLeftJion = true;
    }
    //
    Object value_ = null;
    if (null == value || value.equals("")) {

        this.propertyValue = null;

    } else {
        this.propertyValue = ReflectionUtils.convertStringToObject(value, propertyType);
        value_ = propertyValue;
        //?1
        if (propertyType.equals(Date.class) && filterName.indexOf("LTD") > -1) {
            propertyValue = DateUtils.addDays((Date) propertyValue, 1);
        }
    }
    //request?
    String key = propertyNames[0].replace(".", "_").replace(":", "_");
    //      if(propertyType!=Date.class)
    ////      Struts2Utils.getRequest().setAttribute(key, propertyValue);
    ////      else{
    ////         if(Struts2Utils.getRequest().getAttribute(key)!=null){
    ////            String time_begin=Struts2Utils.getRequest().getAttribute(key)+"";
    ////            Struts2Utils.getRequest().setAttribute(key, time_begin+"="+com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd"));         
    ////         }else{
    ////      Struts2Utils.getRequest().setAttribute(key, com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd"));   
    ////         }
    //      
    //      }

}

From source file:eu.annocultor.converters.europeana.EuropeanaSolrDocumentTagger.java

public void addHash(SolrInputDocument document, String id) {
    final String hash = makeRecordHash(id);
    document.setField(FIELD_HASH_FIRST_SIX, StringUtils.substring(hash, 0, 6));
    document.setField(FIELD_HASH, hash);
    document.setField(FIELD_EDM_CLASS, "EuropeanaProxy");

}

From source file:de.forsthaus.backend.util.db.logging.ServiceLogging.java

public Object logging(ProceedingJoinPoint call) throws Throwable {
    startTimes.add(Long.valueOf(System.nanoTime()));
    try {/*ww  w  .j ava  2  s  .co m*/
        // LOG.info("Start call: " + call.toShortString());
        return call.proceed();
    } finally {
        methodName = call.toShortString();
        finishTime = (System.nanoTime() - startTimes.remove().longValue()) / 1000000;
        if (startTimes.isEmpty()) {
            methodName = StringUtils.substring(methodName, 10, -1);

            // LOG.info("Execution time: " + finishTime + "ms " +
            // methodName);
            loggingService.saveStatistics(statistics, methodName, finishTime);
            init();
        }
    }
}