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:info.magnolia.commands.impl.DeleteCommand.java

@Override
public boolean execute(Context ctx) throws Exception {
    log.debug("Going to remove node [{}].", getPath());

    String parentPath = StringUtils.substringBeforeLast(getPath(), "/");
    String label = StringUtils.substringAfterLast(getPath(), "/");

    Node parentNode = MgnlContext.getJCRSession(this.getRepository()).getNode(parentPath);
    Node toRemove = parentNode.getNode(label);
    toRemove.remove();/*from  ww  w.j av  a  2s  . co m*/
    parentNode.getSession().save();

    return true;
}

From source file:com.adobe.ac.pmd.rules.maintanability.ClassAndExtensionAreIdenticalRule.java

private String extractExtensionName(final String extensionName) {
    return extensionName.indexOf('.') == -1 ? extensionName
            : StringUtils.substringAfterLast(extensionName, ".");
}

From source file:info.magnolia.cms.Aggregator.java

/**
 * Collect content from the pre configured repository and attach it to the HttpServletRequest.
 * @throws PathNotFoundException/*from   ww  w  .j a  va2s  .com*/
 * @throws RepositoryException
 */
public static boolean collect(HttpServletRequest request) throws PathNotFoundException, RepositoryException {

    String uri = StringUtils.substringBeforeLast(Path.getURI(request), "."); //$NON-NLS-1$
    String extension = StringUtils.substringAfterLast(Path.getURI(request), "."); //$NON-NLS-1$

    HierarchyManager hierarchyManager = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE);

    Content requestedPage = null;
    NodeData requestedData = null;
    Template template = null;

    if (hierarchyManager.isPage(uri)) {
        requestedPage = hierarchyManager.getContent(uri); // ATOM

        // check if its a request for a versioned page
        if (request.getParameter(VERSION_NUMBER) != null) {
            // get versioned state
            try {
                requestedPage = requestedPage.getVersionedContent(request.getParameter(VERSION_NUMBER));
            } catch (RepositoryException re) {
                log.debug(re.getMessage(), re);
                log.error("Unable to get versioned state, rendering current state of " + uri);
            }
        }

        String templateName = requestedPage.getMetaData().getTemplate();

        if (StringUtils.isBlank(templateName)) {
            log.error("No template configured for page [{}].", requestedPage.getHandle()); //$NON-NLS-1$
        }

        template = TemplateManager.getInstance().getInfo(templateName, extension);

        if (template == null) {
            log.error("Template [{}] for page [{}] not found.", //$NON-NLS-1$
                    templateName, requestedPage.getHandle());
        }
    } else {
        if (hierarchyManager.isNodeData(uri)) {
            requestedData = hierarchyManager.getNodeData(uri);
        } else {
            // check again, resource might have different name
            int lastIndexOfSlash = uri.lastIndexOf("/"); //$NON-NLS-1$

            if (lastIndexOfSlash > 0) {
                uri = StringUtils.substringBeforeLast(uri, "/"); //$NON-NLS-1$
                try {
                    requestedData = hierarchyManager.getNodeData(uri);
                } catch (PathNotFoundException e) {
                    // no page available
                    return false;
                } catch (RepositoryException e) {
                    log.debug(e.getMessage(), e);
                    return false;
                }
            }
        }

        if (requestedData != null) {
            String templateName = requestedData.getAttribute("nodeDataTemplate"); //$NON-NLS-1$

            if (!StringUtils.isEmpty(templateName)) {
                template = TemplateManager.getInstance().getInfo(templateName, extension);
            }
        } else {
            return false;
        }
    }

    // Attach all collected information to the HttpServletRequest.
    if (requestedPage != null) {
        request.setAttribute(Aggregator.ACTPAGE, requestedPage);
        request.setAttribute(Aggregator.CURRENT_ACTPAGE, requestedPage);
    }
    if ((requestedData != null) && (requestedData.getType() == PropertyType.BINARY)) {
        File file = new File();
        file.setProperties(requestedData);
        file.setNodeData(requestedData);
        request.setAttribute(Aggregator.FILE, file);
    }

    request.setAttribute(Aggregator.HANDLE, uri);
    request.setAttribute(Aggregator.EXTENSION, extension);
    request.setAttribute(Aggregator.HIERARCHY_MANAGER, hierarchyManager);

    request.setAttribute(Aggregator.TEMPLATE, template);

    return true;
}

From source file:com.htmlhifive.tools.codeassist.core.proposal.checker.ControllerProposalChecker.java

@Override
public boolean existDefaultCodeAssist() {

    if (!StringUtils.contains(getCodeAssistStr(), '.')) {
        return true;
    }/*from  w ww.  ja  v  a2 s  .  c o m*/
    String str = StringUtils.substringAfterLast(getCodeAssistStr(), ".");
    return getBean().getRegExPattern().matcher(str).matches();
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ModelProviderBase.java

public ModelProviderBase(Object aObject, String aType) {
    this(aObject, StringUtils.substringAfterLast(aObject.getClass().getPackage().getName(), "."), aType);
}

From source file:com.qualitesys.sonarqcr4pblplugin.pbl.PblFile.java

/**
 * @param unitTest whether it is a unit test file or a source file
 *//*from   w w  w  .  ja v a2s. c o m*/
public PblFile(String key, boolean unitTest) {
    super();
    if (key != null && key.indexOf('$') >= 0) {
        throw new IllegalArgumentException("Pbl inner classes are not supported : " + key);
    }
    String realKey = StringUtils.trim(key);
    this.unitTest = unitTest;

    if (realKey.contains(".")) {
        this.filename = StringUtils.substringAfterLast(realKey, ".");
        this.packageKey = StringUtils.substringBeforeLast(realKey, ".");
        this.longName = realKey;

    } else {
        this.filename = realKey;
        this.longName = realKey;
        this.packageKey = PblPackage.DEFAULT_PACKAGE_NAME;
        realKey = new StringBuilder().append(PblPackage.DEFAULT_PACKAGE_NAME).append(".").append(realKey)
                .toString();
    }
    setKey(realKey);
}

From source file:info.magnolia.module.workflow.commands.simple.DeleteCommand.java

private void deleteNode(Context context, String path) throws Exception {
    String parentPath = StringUtils.substringBeforeLast(path, "/");
    String label = StringUtils.substringAfterLast(path, "/");
    deleteNode(context, parentPath, label);
}

From source file:com.nagarro.core.util.ws.impl.AddonAwareMessageSource.java

public AddonAwareMessageSource() {
    this.scanForAddons = true;
    this.dirFilter = n -> {
        final String base = StringUtils.substringAfterLast(n, baseAddonDir.getPathWithinContext());
        return StringUtils.contains(base, File.separator);
    };/*  ww  w .  j  a  v  a 2s  .co m*/
    this.fileFilter = n -> StringUtils.endsWithIgnoreCase(n, "xml")
            || StringUtils.endsWithIgnoreCase(n, "properties");
}

From source file:info.magnolia.cms.beans.runtime.Document.java

/**
 * Used to create a document pased on a existing file.
 * @param file//from  w w  w .  ja v  a2 s .  c o m
 * @param type
 */
public Document(java.io.File file, String type) {
    String fileName = file.getName();
    this.setFile(file);
    this.setType(type);
    this.setExtention(StringUtils.substringAfterLast(fileName, "."));
    this.setFileName(StringUtils.substringBeforeLast(fileName, "."));
}

From source file:com.opengamma.web.portfolio.WebPortfolioNodePositionsResource.java

@POST
@Produces(MediaType.TEXT_HTML)/* w  w w. j a v a2s . co  m*/
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response postHTML(@FormParam("positionurl") String positionUrlStr) {
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(new WebPortfolioNodeResource(this).getHTML()).build();
    }

    positionUrlStr = StringUtils.trimToNull(positionUrlStr);
    if (positionUrlStr == null) {
        FlexiBean out = createRootData();
        out.put("err_positionUrlMissing", true);
        String html = getFreemarker().build(HTML_DIR + "portfolionodepositions-add.ftl", out);
        return Response.ok(html).build();
    }
    UniqueId positionId = null;
    try {
        new URI(positionUrlStr); // validates whole URI
        String uniqueIdStr = StringUtils.substringAfterLast(positionUrlStr, "/positions/");
        uniqueIdStr = StringUtils.substringBefore(uniqueIdStr, "/");
        positionId = UniqueId.parse(uniqueIdStr);
        data().getPositionMaster().get(positionId); // validate position exists
    } catch (Exception ex) {
        FlexiBean out = createRootData();
        out.put("err_positionUrlInvalid", true);
        String html = getFreemarker().build(HTML_DIR + "portfolionodepositions-add.ftl", out);
        return Response.ok(html).build();
    }
    URI uri = addPosition(doc, positionId);
    return Response.seeOther(uri).build();
}