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

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

Introduction

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

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.eurekastreams.server.service.servlets.RequestUriToThemeUuidTransformer.java

/**
 * Parse theme uuid from request uri. Expecting to handle format of
 * /blah/whatever/somethemeversion<UUID_SEPARATOR>themuuid<FILE_EXTENSION>
 * //from   w  w w . j  av  a2s  .  c  o m
 * @param inTransformType
 *            Request uri.
 * @return lower case theme uuid from request uri.
 */
@Override
public String transform(final String inTransformType) {
    return inTransformType == null ? null
            : StringUtils.removeEndIgnoreCase(StringUtils.substringAfterLast(inTransformType, uuidSeparator),
                    fileExtension).toLowerCase();
}

From source file:org.exoplatform.ecm.webui.component.admin.action.UIActionTypeList.java

@Override
public void refresh(int currentPage) throws Exception {
    ActionServiceContainer actionsServiceContainer = getApplicationComponent(ActionServiceContainer.class);
    String repository = getAncestorOfType(UIECMAdminPortlet.class).getPreferenceRepository();
    ScriptServiceImpl scriptService = WCMCoreUtils.getService(ScriptServiceImpl.class);
    Collection<NodeType> actionList = actionsServiceContainer.getCreatedActionTypes(repository);
    List<ActionData> actions = new ArrayList<ActionData>(actionList.size());
    UIActionManager uiManager = getParent();
    for (NodeType action : actionList) {
        ActionData bean = new ActionData();
        String resourceName = scriptService.getResourceNameByNodeType(action);
        if (StringUtils.isEmpty(resourceName))
            continue;
        bean.setLabel(uiManager.getScriptLabel(action));
        if (resourceName.length() == 0)
            resourceName = action.getName();
        bean.setType(action.getName());//from   ww w.j  a v a  2s .  c  om
        bean.setName(StringUtils.substringAfterLast(resourceName, "/"));
        actions.add(bean);
    }
    Collections.sort(actions, new ActionComparator());
    LazyPageList<ActionData> dataPageList = new LazyPageList<ActionData>(
            new ListAccessImpl<ActionData>(ActionData.class, actions), getUIPageIterator().getItemsPerPage());
    getUIPageIterator().setTotalItems(actions.size());
    getUIPageIterator().setPageList(dataPageList);
    if (currentPage > getUIPageIterator().getAvailablePage())
        getUIPageIterator().setCurrentPage(getUIPageIterator().getAvailablePage());
    else
        getUIPageIterator().setCurrentPage(currentPage);
}

From source file:org.exoplatform.ecms.upgrade.sanitization.SanitizationUpgradePlugin.java

private void migrateViews() {
    try {//from w  w  w . j  a v a  2  s. c o  m
        Session session = WCMCoreUtils.getSystemSessionProvider().getSession(
                dmsConfiguration_.getConfig().getSystemWorkspace(), repoService_.getCurrentRepository());
        String[] oldViewTemplates = { "ListView", "ContentView", "ThumbnailsView", "IconView", "TimelineView",
                "CoverFlow", "SystemView", "SlideShowView" };
        if (LOG.isInfoEnabled()) {
            LOG.info("=====Start migrate data for all user views=====");
        }
        String statement = "SELECT * FROM exo:view ORDER BY exo:name DESC";
        QueryResult result = session.getWorkspace().getQueryManager().createQuery(statement, Query.SQL)
                .execute();
        NodeIterator nodeIter = result.getNodes();
        while (nodeIter.hasNext()) {
            Node viewNode = nodeIter.nextNode();
            String template = viewNode.getProperty("exo:template").getString();
            String templateName = StringUtils.substringAfterLast(template, "/");
            for (String oldTemp : oldViewTemplates) {
                if (templateName.equals(oldTemp)) {
                    if (isContainOldView(viewNode.getName())) {
                        if (LOG.isInfoEnabled()) {
                            LOG.info("=====Removing view '" + viewNode.getName() + "'=====");
                        }
                        viewNode.remove();
                    } else {
                        String newTemplate = "List";
                        if (templateName.equals("ListView"))
                            newTemplate = template.replace(templateName, "List");
                        else if (templateName.equals("ContentView"))
                            newTemplate = template.replace(templateName, "Content");
                        else if (templateName.equals("ThumbnailsView"))
                            newTemplate = template.replace(templateName, "Thumbnails");
                        else if (templateName.equals("IconView"))
                            newTemplate = template.replace(templateName, "Thumbnails");
                        else if (templateName.equals("TimelineView"))
                            newTemplate = template.replace(templateName, "List");
                        else if (templateName.equals("CoverFlow"))
                            newTemplate = template.replace(templateName, "Thumbnails");
                        else if (templateName.equals("SystemView"))
                            newTemplate = template.replace(templateName, "List");
                        else if (templateName.equals("SlideShowView"))
                            newTemplate = template.replace(templateName, "Thumbnails");
                        if (LOG.isInfoEnabled()) {
                            LOG.info("=====Modifying view '" + viewNode.getName() + "'=====");
                        }
                        viewNode.setProperty("exo:template", newTemplate);
                    }
                }
            }
        }
        session.save();
        if (LOG.isInfoEnabled()) {
            LOG.info("=====Completed the migration data for user views=====");
        }
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("An unexpected error occurs when migrate views", e);
        }
    }
}

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

/**
 * add Resource/*from   ww  w .  j  a  v a 2s. c om*/
 * @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.fao.geonet.kernel.SpringLocalServiceInvoker.java

public Object invoke(HttpServletRequest request, HttpServletResponse response) throws Exception {

    HandlerExecutionChain handlerExecutionChain = requestMappingHandlerMapping.getHandler(request);
    HandlerMethod handlerMethod = (HandlerMethod) handlerExecutionChain.getHandler();

    ServletInvocableHandlerMethod servletInvocableHandlerMethod = new ServletInvocableHandlerMethod(
            handlerMethod);/*  w w w.java2  s .  c  om*/
    servletInvocableHandlerMethod.setHandlerMethodArgumentResolvers(argumentResolvers);
    servletInvocableHandlerMethod.setHandlerMethodReturnValueHandlers(returnValueHandlers);
    servletInvocableHandlerMethod.setDataBinderFactory(webDataBinderFactory);

    Object o = servletInvocableHandlerMethod.invokeForRequest(new ServletWebRequest(request, response), null,
            new Object[0]);
    // check whether we need to further process a "forward:" response
    if (o instanceof String) {
        String checkForward = (String) o;
        if (checkForward.startsWith("forward:")) {
            //
            // if the original url ends with the first component of the fwd url, then concatenate them, otherwise
            // just invoke it and hope for the best...
            // eg. local://srv/api/records/urn:marlin.csiro.au:org:1_organisation_name
            // returns forward:urn:marlin.csiro.au:org:1_organisation_name/formatters/xml
            // so we join the original url and the forwarded url as:
            // /api/records/urn:marlin.csiro.au:org:1_organisation_name/formatters/xml and invoke it.
            //
            String fwdUrl = StringUtils.substringAfter(checkForward, "forward:");
            String lastComponent = StringUtils.substringAfterLast(request.getRequestURI(), "/");
            if (lastComponent.length() > 0 && StringUtils.startsWith(fwdUrl, lastComponent)) {
                return invoke(request.getRequestURI() + StringUtils.substringAfter(fwdUrl, lastComponent));
            } else {
                return invoke(fwdUrl);
            }
        }
    }
    return o;
}

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

public ArtifactFile(File file, String version) {
    name = file.getName();/*from   w w w.  ja va  2 s  .  co  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;
    }
}

From source file:org.gradle.api.internal.project.AbstractProject.java

public Task findTask(String path) {
    if (!GUtil.isTrue(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }/*from  www . ja  v  a  2s .co m*/
    if (!path.contains(PATH_SEPARATOR)) {
        return taskEngine.findTask(path);
    }

    String projectPath = StringUtils.substringBeforeLast(path, PATH_SEPARATOR);
    Project project = findProject(!GUtil.isTrue(projectPath) ? PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    return project.task(StringUtils.substringAfterLast(path, PATH_SEPARATOR));
}

From source file:org.gradle.api.internal.resolve.LibraryPublishArtifact.java

private static String determineExtension(File file) {
    return StringUtils.substringAfterLast(file.getName(), ".");
}

From source file:org.gradle.api.internal.tasks.DefaultTaskContainer.java

public Task findByPath(String path) {
    if (!GUtil.isTrue(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }//from www . j  a  v a2s .  c om
    if (!path.contains(Project.PATH_SEPARATOR)) {
        return findByName(path);
    }

    String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR);
    ProjectInternal project = this.project
            .findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    projectAccessListener.beforeRequestingTaskByPath(project);

    return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR));
}

From source file:org.gradle.api.internal.tasks.testing.junit.report.ClassTestResults.java

public String getSimpleName() {
    String simpleName = StringUtils.substringAfterLast(name, ".");
    if (simpleName.equals("")) {
        return name;
    }//from   w  w w. j ava2s .  c o m
    return simpleName;
}