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

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

Introduction

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

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:eionet.cr.web.action.factsheet.BookmarksActionBean.java

/**
 * Returns selected projet name where the user wants to add the bookmark.
 *
 * @return project dropdown value// w ww . j  a  va 2  s.c o  m
 */
public String getProjectName() {
    if (isProjectBookmarks()) {
        return StringUtils.substringBeforeLast(FolderUtil.extractPathInFolder(uri), "/");
    }

    return "";
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private void combineXpathFilterQueries(SolrQuery query, List<SolrQuery> subQueries, String operator) {
    List<String> queryParams = new ArrayList<>();
    // Use Set to remove duplicates now that the namespaces have been stripped out
    Set<String> xpathFilters = new TreeSet<>();
    Set<String> xpathIndexes = new TreeSet<>();

    for (SolrQuery subQuery : subQueries) {
        String[] params = subQuery.getParams(FILTER_QUERY_PARAM_NAME);
        if (params != null) {
            for (String param : params) {
                if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX)) {
                    if (StringUtils.contains(param, XPATH_FILTER_QUERY_INDEX)) {
                        xpathIndexes/*  www  .jav a  2s .  c om*/
                                .add(StringUtils.substringAfter(StringUtils.substringBeforeLast(param, "\""),
                                        XPATH_FILTER_QUERY_INDEX + ":\""));
                    } else if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY)) {
                        xpathFilters.add(StringUtils.substringAfter(
                                StringUtils.substringBeforeLast(param, "\""), XPATH_FILTER_QUERY + ":\""));
                    }
                }
                Collections.addAll(queryParams, param);
            }
        }
    }

    if (xpathFilters.size() > 1) {
        // More than one XPath found, need to combine
        String filter = XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY + ":\"("
                + StringUtils.join(xpathFilters, operator.toLowerCase()) + ")\"";

        List<String> indexes = new ArrayList<>();
        for (String xpath : xpathIndexes) {
            indexes.add("(" + XPATH_FILTER_QUERY_INDEX + ":\"" + xpath + "\")");
        }
        // TODO DDF-1882 add pre-filter xpath index
        //String index = XPATH_QUERY_PARSER_PREFIX + StringUtils.join(indexes, operator);
        //query.setParam(FILTER_QUERY_PARAM_NAME, filter, index);
        query.setParam(FILTER_QUERY_PARAM_NAME, filter);
    } else if (queryParams.size() > 0) {
        // Pass through original filter queries if only a single XPath is present
        query.setParam(FILTER_QUERY_PARAM_NAME, queryParams.toArray(new String[queryParams.size()]));
    }
}

From source file:de.griffel.confluence.plugins.plantuml.type.ConfluenceLink.java

/**
 * Returns only the date string of the this link (w/o the Blog title).
 * // w  w  w .j a va2 s. c  om
 * If this link is not a Blog post, the result is undefined.
 * 
 * @return only the date string of the this link (w/o the Blog title).
 */
public String getBlogPostDate() {
    return StringUtils.substringBeforeLast(getPageTitle(), "/");
}

From source file:com.amalto.core.server.MetadataRepositoryAdminImpl.java

public MetadataRepository get(String metadataRepositoryId) {
    assertMetadataRepositoryId(metadataRepositoryId);
    synchronized (metadataRepository) {
        MetadataRepository repository = metadataRepository.get(metadataRepositoryId);
        if (repository == null) {
            try {
                DataModelPOJOPK pk = new DataModelPOJOPK(
                        StringUtils.substringBeforeLast(metadataRepositoryId, "#")); //$NON-NLS-1$
                DataModelPOJO dataModel = loadDataModel(pk);
                if (dataModel == null) {
                    return null; // Expected per interface documentation (if not found, return null).
                }//from www  .j  ava 2 s .  c om
                repository = createMetadataRepository(dataModel);
                metadataRepository.put(metadataRepositoryId, repository);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return repository;
    }
}

From source file:com.amalto.core.save.context.PartialUpdateActionCreator.java

@Override
public List<Action> visit(ComplexTypeMetadata complexType) {
    if (mainType == null) {
        mainType = complexType;/*from  w  ww .ja  va  2s  .c  om*/
    }
    List<Action> actionList = super.visit(complexType);
    if (complexType == mainType) {
        if (!preserveCollectionOldValues) {
            /*
             * There might be elements not used for the update. In case overwrite=true, expected behavior is to append
             * unused elements at the end. The code below removes used elements in partial update (with overwrite=true)
             * then do a new partial update (with overwrite=false) so new elements are added at the end (this is the
             * behavior of a overwrite=false).
             */
            // TODO these code will be replaced by fhuaulme's new API
            List<Node> nodes = new ArrayList<Node>();
            for (String usedPath : usedPaths) {
                Accessor accessor = newDocument.createAccessor(usedPath);
                if (accessor.exist()) {
                    accessor.touch();
                    if (newDocument instanceof DOMMutableDocument) {
                        nodes.add(((DOMMutableDocument) newDocument).getLastAccessedNode());
                    }
                }
            }
            for (Node node : nodes) {
                if (node != null && node.getParentNode() != null) {
                    node.getParentNode().removeChild(node);
                }
            }
            // Since this a costly operation do this only if there are still elements under the pivot.
            int leftElementCount = newDocument
                    .createAccessor(StringUtils.substringBeforeLast(partialUpdatePivot, "/")).size(); //$NON-NLS-1$
            if (leftElementCount > 0) {
                preserveCollectionOldValues = true;
                mainType.accept(this);
            }
        }
    }
    return actionList;
}

From source file:de.griffel.confluence.plugins.plantuml.type.ConfluenceLink.java

Calendar getBlogPostDay() {
    final String dayString = StringUtils.stripStart(StringUtils.substringBeforeLast(getPageTitle(), "/"), "/");
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    final Calendar day = Calendar.getInstance();
    try {//from w  w w  . j a va2s.co m
        day.setTime(sdf.parse(dayString));
    } catch (ParseException e) {
        throw new RuntimeException("Cannot parse blog post date string: " + dayString, e);
    }
    return day;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.cfi.ContentFragmentImport.java

protected boolean createFolderNode(String path, String folderTitle, ResourceResolver r)
        throws RepositoryException, PersistenceException {
    if (path == null) {
        return false;
    }/* w ww  .  j ava 2 s  .c o m*/
    if (dryRunMode) {
        return true;
    }
    String parentPath = StringUtils.substringBeforeLast(path, "/");
    boolean titleProvided;
    String folderName = StringUtils.substringAfterLast(path, "/");
    if (folderTitle == null) {
        folderTitle = folderName;
        titleProvided = false;
    } else {
        titleProvided = true;
    }
    Session s = r.adaptTo(Session.class);
    if (s.nodeExists(path) && titleProvided) {
        return updateFolderTitle(s, path, folderTitle, r);
    } else if (!s.nodeExists(path)) {
        if (!s.nodeExists(parentPath)) {
            createFolderNode(parentPath, null, r);
        }
        Node child = s.getNode(parentPath).addNode(folderName, DEFAULT_FOLDER_TYPE);
        trackDetailedActivity(path, "Create Folder", "Create folder", 0L);
        setFolderTitle(child, folderTitle);
        incrementCount(createdFolders, 1L);
        r.commit();
        r.refresh();
        return true;
    }
    return false;
}

From source file:com.adobe.acs.commons.wcm.impl.PropertyMergePostProcessor.java

protected static String alignDestinationPath(String source, String destination) {
    if (source.contains(JcrConstants.JCR_CONTENT)) {
        return StringUtils.substringBeforeLast(source, JcrConstants.JCR_CONTENT) + destination;
    } else {//from  w  w w .  ja  v a  2s .  c  o  m
        return destination;
    }
}

From source file:com.timtripcony.AbstractSmartDocumentModel.java

/**
 * Gets a field or multi-value field as a String, using toString() method
 * /*w  w w . j a  va  2 s  .  co  m*/
 * @param name
 *            String Item name to get value from
 * @return String value of the Item
 */
public String getValueAsString(final String name) {
    String retVal_ = "";
    try {
        if (null != getValue(name)) {
            if (Vector.class.equals(getValue(name).getClass())) {
                String value = getValue(name).toString();
                value = StringUtils.substringAfter(value, "[");
                retVal_ = StringUtils.substringBeforeLast(value, "]");
            } else {
                retVal_ = getValue(name).toString();
            }
        }
    } catch (Throwable t) {
        AppUtils.handleException(t);
    }
    return retVal_;
}

From source file:adalid.util.velocity.BaseBuilder.java

private boolean copyBinaryFiles() {
    Collection<File> files = FileUtils.listFiles(projectFolder, binaryFileFilter(), binaryDirFilter());
    //      ColUtils.sort(files);
    String source, target, folder;
    for (File file : files) {
        source = file.getPath();/*from   w  w  w  .  ja  v a 2s.  c  o  m*/
        target = source.replace(projectFolderPath, velocityTemplatesTargetFolderPath);
        folder = StringUtils.substringBeforeLast(target, FS);
        FilUtils.mkdirs(folder);
        try {
            copy(source, target);
            binaryFilesCopied++;
            createBinaryFilePropertiesFile(source, target);
        } catch (IOException ex) {
            writingErrors++;
            logger.fatal(ex);
            logger.fatal("\t" + source + " could not be copied ");
        }
    }
    return true;
}