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:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java

@Override
public void mapSourceToResource(final Resource resource) {
    if (resource != null && resource.getResourceSource() == null) {
        if (ResourceType.Type.RESOURCE.getType().equalsIgnoreCase(resource.getResourceType().getName())
                || ResourceType.Type.VIDEO.getType().equalsIgnoreCase(resource.getResourceType().getName())) {
            final String domainName = BaseUtil.getDomainName(resource.getUrl());
            if (domainName != null) {
                final ResourceSource resourceSource = this.getResourceRepository()
                        .findResourceSource(domainName);
                if (resourceSource != null) {
                    resource.setResourceSource(resourceSource);
                } else {
                    resource.setResourceSource(createResourcesourceAttribution(domainName,
                            StringUtils.substringBeforeLast(domainName, ".")));
                }/* www. j  a  va  2  s.  c  o m*/
                this.getResourceRepository().save(resource);
            }
        }
    }
}

From source file:org.ednovo.gooru.domain.service.revision_history.CollectionRevisionHistoryRollBack.java

@Override
protected Collection rollback(Collection entity, RevisionHistory history) {
    Collection collection = collectionRepository.getCollectionByGooruOid(entity.getGooruOid(), null);
    String revisionImagePath = "";
    String revisionFileNamePrefix = "";
    if (collection != null) {
        this.merge(entity, collection);
    } else {//from   w  w w .j a va2s  . c  om
        entity.setContentId(null);
        revisionImagePath = entity.getOrganization().getNfsStorageArea().getInternalPath() + entity.getFolder()
                + entity.getThumbnail();
        revisionFileNamePrefix = StringUtils.substringBeforeLast(entity.getThumbnail(), ".");
        collection = entity;
        collection.setFolder(null);
    }
    entity.setRevisionHistoryUid(history.getRevisionHistoryUid());

    collectionRepository.save(collection);
    for (CollectionItem collectionItem : collection.getCollectionItems()) {
        collectionItem.setCollection(collection);
        collectionRepository.save(collectionItem);
    }

    collectionRepository.flush();
    moveCollectionImage(collection, revisionImagePath, revisionFileNamePrefix);
    this.resourceImageUtil.setDefaultThumbnailImageIfFileNotExist((Resource) collection);

    collectionUtil.deleteCollectionFromCache(collection.getGooruOid(), COLLECTION);
    indexProcessor.index(collection.getGooruOid(), IndexProcessor.INDEX, COLLECTION);

    return collection;
}

From source file:org.ednovo.gooru.domain.service.revision_history.LearnguideRevisionHistoryRollBack.java

@Override
protected Learnguide rollback(Learnguide entity, RevisionHistory history) {
    Learnguide learnguide = learnguideRepository.findByContent(entity.getGooruOid());
    String revisionImagePath = "";
    String revisionFileNamePrefix = "";
    if (learnguide != null) {
        deleteResourceInstances(learnguide.getResourceSegments());
        this.merge(entity, learnguide);
    } else {//from  ww w  . j  av a2 s  .  co m
        entity.setContentId(null);
        revisionImagePath = entity.getOrganization().getNfsStorageArea().getInternalPath() + entity.getFolder()
                + entity.getThumbnail();
        revisionFileNamePrefix = StringUtils.substringBeforeLast(entity.getThumbnail(), ".");
        learnguide = entity;
        learnguide.setFolder(null);
        deleteResourceInstances(learnguide.getResourceSegments());
    }
    entity.setRevisionHistoryUid(history.getRevisionHistoryUid());

    learnguideRepository.save(learnguide);
    moveCollectionImage(learnguide, revisionImagePath, revisionFileNamePrefix);
    this.resourceImageUtil.setDefaultThumbnailImageIfFileNotExist((Resource) learnguide);
    saveResourceInstances(entity.getResourceInstances());

    collectionUtil.deleteCollectionFromCache(learnguide.getGooruOid(), COLLECTION);
    indexProcessor.index(learnguide.getGooruOid(), IndexProcessor.INDEX, COLLECTION);

    return learnguide;
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.AuthorizationDaoSupport.java

protected final String generateAuthQueryWithDataNew(String alias) {
    if (isContentAdminAccess()) {
        return new StringBuilder(alias).append("organization.partyUid IN (")
                .append(getUserOrganizationUidsAsString()).append(") ").toString();
    } else {/*from   w  w  w .j  a va  2s  . com*/
        return new StringBuilder(" (exists ( FROM ContentPermission cps where cps.content = "
                + StringUtils.substringBeforeLast(alias, ".") + " AND cps.party.partyUid IN ( "
                + getPartyPermitsAsString() + " )) OR ").append(alias)
                        .append("sharing in ('public','anyonewithlink') OR ").append(alias)
                        .append("organization.partyUid IN (").append(getUserSubOrganizationUidsAsString())
                        .append(") OR ").append(alias).append("user.partyUid = '" + getCurrentUserUid() + "' ")
                        .append(" ) AND ").append(alias).append("organization.partyUid IN (")
                        .append(getUserOrganizationUidsAsString()).append(") ").toString();
    }
}

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.AuthorizationDaoSupport.java

protected static final String generateAuthQuery(String alias) {
    if (isContentAdminAccess()) {
        return new StringBuilder(alias).append("organization.partyUid IN ( :organizationUids ) ").toString();
    } else {//from   w ww  .  ja v a  2 s . co m
        return new StringBuilder(" (exists ( FROM ContentPermission cps where cps.content = "
                + StringUtils.substringBeforeLast(alias, ".") + " AND cps.party.partyUid IN ( "
                + getPartyPermitsAsString() + " )) OR ").append(alias)
                        .append("sharing in ('public', 'anyonewithlink') OR ").append(alias)
                        .append("organization.partyUid IN (").append(getUserSubOrganizationUidsAsString())
                        .append(") OR ").append(alias).append("user.partyUid = :currentUserUid ")
                        .append(" ) AND ").append(alias)
                        .append("organization.partyUid IN ( :organizationUids ) ").toString();
    }
}

From source file:org.exoplatform.services.cms.impl.BaseResourceLoaderService.java

/**
 * add Resource//  w  ww.  ja v  a 2  s  . c o m
 * @param resourcesHome     Node
 * @param resourceName      String
 * @param in                InputStream
 * @throws Exception
 */
public void addResource(Node resourcesHome, String resourceName, String resourceDescription, InputStream in)
        throws Exception {
    Node contentNode = null;
    if (resourceName.lastIndexOf("/") > -1) {
        String realParenPath = StringUtils.substringBeforeLast(resourceName, "/");
        Node parentResource = resourcesHome.getNode(realParenPath);
        resourcesHome = parentResource;
        resourceName = StringUtils.substringAfterLast(resourceName, "/");
    }
    try {
        Node script = resourcesHome.getNode(resourceName);
        contentNode = script.getNode(NodetypeConstant.JCR_CONTENT);
        if (!contentNode.isCheckedOut())
            contentNode.checkout();
    } catch (PathNotFoundException e) {
        Node script = resourcesHome.addNode(resourceName, NodetypeConstant.NT_FILE);
        contentNode = script.addNode(NodetypeConstant.JCR_CONTENT, NodetypeConstant.EXO_RESOURCES);
        contentNode.setProperty(NodetypeConstant.JCR_ENCODING, "UTF-8");
        contentNode.setProperty(NodetypeConstant.JCR_MIME_TYPE, "application/x-groovy");
    }
    contentNode.setProperty(NodetypeConstant.JCR_DATA, in);
    contentNode.setProperty(NodetypeConstant.DC_DESCRIPTION, new String[] { resourceDescription });
    contentNode.setProperty(NodetypeConstant.JCR_LAST_MODIFIED, new GregorianCalendar());
    resourcesHome.save();
}

From source file:org.exoplatform.services.wcm.publication.lifecycle.stageversion.ui.UIPortalNavigationExplorer.java

/**
 * Select tree node by uri.// w  w  w. j a  v  a 2s  .c  om
 *
 * @param uri the uri
 *
 * @throws Exception the exception
 */
@SuppressWarnings("unchecked")
public void selectTreeNodeByUri(String uri) throws Exception {
    UIPublicationTree tree = getChild(UIPublicationTree.class);
    if (currentNode == null) {
        List<TreeNode> sibbling = (List<TreeNode>) tree.getSibbling();
        for (TreeNode childNode : sibbling) {
            if (childNode.getUri().equals(uri)) {
                currentNode = childNode;
                break;
            }
        }
        tree.setSelected(currentNode);
        List<TreeNode> listChildNode = currentNode.getTreeNodeChildren();
        tree.setChildren(listChildNode);
        tree.setParentSelected(null);
        tree.setSibbling(sibbling);
        return;
    }
    if (tree.getId().equals("UIPortalTree")) {
        if (!uri.startsWith(currentNode.getUri())) {
            List<TreeNode> sibbling = (List<TreeNode>) tree.getSibbling();
            for (TreeNode childNode : sibbling) {
                if (childNode.getUri().equals(uri)) {
                    currentNode = childNode;
                    break;
                }
            }
            tree.setSelected(currentNode);
            List<TreeNode> listChildNode = currentNode.getTreeNodeChildren();
            tree.setChildren(listChildNode);
            tree.setParentSelected(null);
            tree.setSibbling(sibbling);
        }
    }
    TreeNode selected = currentNode.searchTreeNodeByURI(uri);
    if (selected == null)
        return;
    String parentURI = StringUtils.substringBeforeLast(uri, "/");
    TreeNode parent = currentNode.searchTreeNodeByURI(parentURI);
    if (!selected.isPageNode()) {
        if (!tree.getId().equals("UIPortalTree"))
            return;
        List<TreeNode> list = new ArrayList<TreeNode>();
        for (String portal : this.runningPortals) {
            UserPortal userPortal = Util.getPortalRequestContext().getUserPortalConfig().getUserPortal();
            UserNavigation userNavigation = NavigationUtils.getUserNavigationOfPortal(userPortal, portalName);
            UserNode userNode = userPortal.getNode(userNavigation, NavigationUtils.ECMS_NAVIGATION_SCOPE, null,
                    null);
            UIPortalApplication portalApplication = Util.getUIPortalApplication();
            LocaleConfig localeConfig = getApplicationComponent(LocaleConfigService.class)
                    .getLocaleConfig(portalApplication.getLocale().getLanguage());
            ResourceBundle res = localeConfig.getNavigationResourceBundle(userNavigation.getKey().getTypeName(),
                    userNavigation.getKey().getName());
            TreeNode treeNode = new TreeNode(portal, userNavigation, res, false);
            if (userNode != null)
                treeNode.setChildrenByUserNodes(userNode.getChildren());
            list.add(treeNode);
        }
        tree.setSibbling(list);
        tree.setSelected(selected);
        List<TreeNode> listChildNode = selected.getTreeNodeChildren();
        if (listChildNode == null)
            tree.setChildren(null);
        tree.setChildren(listChildNode);
        tree.setParentSelected(null);
        currentNode = selected;
        return;
    }
    if (parent.isPageNode()) {
        tree.setSelected(selected);
        tree.setChildren(selected.getTreeNodeChildren());
        tree.setParentSelected(parent);
        List<TreeNode> sibling = parent.getTreeNodeChildren();
        if (sibling != null)
            tree.setSibbling(sibling);
        currentNode = selected;
    } else if (!parent.isPageNode()) {
        tree.setSelected(selected);
        tree.setChildren(selected.getTreeNodeChildren());
        currentNode = selected;
        tree.setParentSelected(parent);
        List<TreeNode> sibbling = parent.getTreeNodeChildren();
        if (sibbling != null)
            tree.setSibbling(sibbling);
    }
}

From source file:org.fcrepo.indexer.persistence.BasePersistenceIndexer.java

/**
 * Return the path where a given record should be persisted.
 * @param id The record's URI//w  w w.  j ava 2  s  . c  o  m
 * @return the path where a given record should be persisted
 * @throws IOException if IO exception occurred
**/
protected Path pathFor(final URI id) throws IOException {

    // strip the http protocol and replace column(:) in front of the port number
    String fullPath = id.toString().substring(id.toString().indexOf("//") + 2);
    fullPath = StringUtils.substringBefore(fullPath, "/").replace(":", "/") + "/"
            + StringUtils.substringAfter(fullPath, "/");
    // URL encode the id
    final String idPath = URLEncoder.encode(substringAfterLast(fullPath, "/"), "UTF-8");

    // URL encode and build the file path
    final String[] pathTokens = StringUtils.substringBeforeLast(fullPath, "/").split("/");
    final StringBuilder pathBuilder = new StringBuilder();
    for (final String token : pathTokens) {
        if (StringUtils.isNotBlank(token)) {
            pathBuilder.append(URLEncoder.encode(token, "UTF-8") + "/");
        }
    }

    fullPath = pathBuilder.substring(0, pathBuilder.length() - 1).toString();

    final Path dir = Paths.get(pathName, fullPath);
    if (Files.notExists(dir, LinkOption.NOFOLLOW_LINKS)) {
        Files.createDirectories(Paths.get(pathName, fullPath));
    }
    return Paths.get(dir.toString(), idPath + extension);
}

From source file:org.glite.authz.pap.common.utils.PathNamingScheme.java

public static String getParentGroupName(String groupName) {

    checkSyntax(groupName);// w w  w.j  a va 2 s.  c  o m

    if (StringUtils.countMatches(groupName, "/") == 1)
        return groupName;
    else
        return StringUtils.substringBeforeLast(groupName, "/");
}

From source file:org.gradle.api.internal.artifacts.dsl.ArtifactFile.java

public ArtifactFile(File file, String version) {
    name = file.getName();/*from   ww w .j  av  a  2 s .  c  o m*/
    extension = "";
    classifier = "";
    boolean done = false;

    int startVersion = StringUtils.lastIndexOf(name, "-" + version);
    if (startVersion >= 0) {
        int endVersion = startVersion + version.length() + 1;
        if (endVersion == name.length()) {
            name = name.substring(0, startVersion);
            done = true;
        } else if (endVersion < name.length() && name.charAt(endVersion) == '-') {
            String tail = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            classifier = StringUtils.substringBeforeLast(tail, ".");
            extension = StringUtils.substringAfterLast(tail, ".");
            done = true;
        } else if (endVersion < name.length() && StringUtils.lastIndexOf(name, ".") == endVersion) {
            extension = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            done = true;
        }
    }
    if (!done) {
        extension = StringUtils.substringAfterLast(name, ".");
        name = StringUtils.substringBeforeLast(name, ".");
    }
    if (extension.length() == 0) {
        extension = null;
    }
    if (classifier.length() == 0) {
        classifier = null;
    }
}