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:edu.mayo.cts2.framework.plugin.service.lexevs.naming.VersionNameConverter.java

/**
 * From cts2 code system version name./*ww w.j a va  2 s.c om*/
 *
 * @param cts2CodeSystemVersionName the cts2 code system version name
 * @return the name version pair
 * @throws InvaildVersionNameException 
 */
public NameVersionPair fromCts2VersionName(String cts2CodeSystemVersionName)
        throws InvaildVersionNameException {
    if (!this.isValidVersionName(cts2CodeSystemVersionName)) {
        throw new InvaildVersionNameException(cts2CodeSystemVersionName);
    }

    String version = StringUtils.substringAfterLast(cts2CodeSystemVersionName, SEPARATOR);
    String name = StringUtils.substringBeforeLast(cts2CodeSystemVersionName, SEPARATOR);

    return new NameVersionPair(this.codingSchemeNameTranslator.translateToLexGrid(name),
            this.unescapeVersion(version));
}

From source file:com.netflix.explorers.resources.MinifiedContentResource.java

@GET
@Path("/{subResources:.*}")
public Response get(@PathParam("subResources") String subResources) throws Exception {
    LOG.debug(subResources);//  www .  j  a  v a  2 s. co m

    String ext = StringUtils.substringAfterLast(subResources, ".");
    String mediaType = EXT_TO_MEDIATYPE.get(ext);

    final Map<String, Object> vars = new HashMap<String, Object>();
    RequestContext requestContext = manager.newRequestContext(null);
    vars.put("RequestContext", requestContext);
    vars.put("Global", manager.getGlobalModel());
    vars.put("Explorers", manager);

    try {
        CacheControl cc = new CacheControl();
        cc.setMaxAge(MAX_AGE);
        cc.setNoCache(false);
        return Response.ok(SharedFreemarker.getInstance().render(subResources + ".ftl", vars), mediaType)
                .cacheControl(cc).expires(new Date(System.currentTimeMillis() + 3600 * 1000))
                .tag(new String(
                        Hex.encodeHex(MessageDigest.getInstance("MD5").digest(subResources.getBytes()))))
                .build();
    } catch (Exception e) {
        LOG.error(e.getMessage());
        throw e;
    }
}

From source file:info.magnolia.importexport.BootstrapUtil.java

public static void bootstrap(String[] resourceNames, int importUUIDBehavior)
        throws IOException, RepositoryException {
    // sort by length --> import parent node first
    List<String> list = new ArrayList<String>(Arrays.asList(resourceNames));

    Collections.sort(list, new StringLengthComparator());

    for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
        String resourceName = iter.next();

        String name = getFilenameFromResource(resourceName, ".xml");
        String repository = getWorkspaceNameFromResource(resourceName);
        String pathName = getPathnameFromResource(resourceName);
        String fullPath = getFullpathFromResource(resourceName);
        String nodeName = StringUtils.substringAfterLast(fullPath, "/");

        log.debug("Will bootstrap {}", resourceName);

        final InputStream stream = BootstrapUtil.class.getResourceAsStream(resourceName);
        if (stream == null) {
            throw new IOException("Can't find resource to bootstrap at " + resourceName);
        }//from  w ww .ja v  a  2  s . co  m

        // if the node already exists we will keep the order
        String nameOfNodeAfterTheImportedNode = null;

        final HierarchyManager hm = MgnlContext.getHierarchyManager(repository);

        // if the path already exists --> delete it
        try {

            // HM can be null if module is not properly registered and the repository has not been created
            if (hm != null && hm.isExist(fullPath)) {
                // but keep the order
                Content node = hm.getContent(fullPath);
                SiblingsHelper siblings = SiblingsHelper.of(node);
                if (!siblings.isLast()) {
                    nameOfNodeAfterTheImportedNode = siblings.next().getName();
                }

                hm.delete(fullPath);
                log.warn("Deleted already existing node for bootstrapping: {}", fullPath);
            }
        } catch (RepositoryException e) {
            throw new RepositoryException("Can't check existence of node for bootstrap file: [" + name + "]",
                    e);
        }

        DataTransporter.importXmlStream(stream, repository, pathName, name, false, importUUIDBehavior, false,
                true);

        if (nameOfNodeAfterTheImportedNode != null) {
            Content newNode = hm.getContent(fullPath);
            newNode.getParent().orderBefore(nodeName, nameOfNodeAfterTheImportedNode);
        }

    }
}

From source file:eionet.cr.filestore.ScriptTemplateDaoImpl.java

/**
 * {@inheritDoc}/*  w  w  w  .  j a  v a 2  s .  co  m*/
 */
@Override
public List<ScriptTemplateDTO> getScriptTemplates() {

    Map<String, ScriptTemplateDTO> scripts = new HashMap<String, ScriptTemplateDTO>();
    for (Object key : PROPERTIES.keySet()) {
        String id = StringUtils.substringBefore((String) key, ".");
        String property = StringUtils.substringAfterLast((String) key, ".");

        ScriptTemplateDTO script = scripts.get(id);
        if (script == null) {
            script = new ScriptTemplateDTO();
            script.setId(id);
            scripts.put(id, script);
        }

        if (property.equals("name")) {
            script.setName(PROPERTIES.getProperty((String) key).trim());
        }

        if (property.equals("script")) {
            script.setScript(PROPERTIES.getProperty((String) key).trim());
        }

    }

    return new ArrayList<ScriptTemplateDTO>(scripts.values());
}

From source file:com.careerly.common.support.resolver.ControllerExceptionResolver.java

@Override
public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {// ww w  .  j  a va  2s  .c  o m

    ControllerExceptionResolver.logger
            .error(String.format("ERROR ## [%s] happend error,the trace is ", request.getServletPath()), ex);

    String fullClazzName = StringUtils.substringAfterLast(handler.getClass().getName(), ".");
    String clazzName = StringUtils.substringBefore(fullClazzName, "$");

    if (clazzName.endsWith(ControllerExceptionResolver.DATA_CONTROLLER) || clazzName
            .endsWith(ControllerExceptionResolver.API_CONTROLLER)) /** ??DataAPI **/
    {
        if (ex instanceof BusinessException) /** BusinessException?message?ErrorJsonObject **/
        {
            BusinessException be = (BusinessException) ex;
            resolveDataException(request, response, handler,
                    StandardJsonObject.newErrorJsonObject(be.getErrorCode(), be.getLocalizedMessage()));
        } else/** ?BusinessExceptionException"api error"ErrorJsonObject **/
        {
            resolveDataException(request, response, handler,
                    StandardJsonObject.newErrorJsonObject("?!"));
        }

        return null;
    } else /** ?Page **/
    {
        if (ex instanceof BusinessException)/** BusinessException?error? **/
        {
            ModelAndView mv = new ModelAndView();
            mv.addObject("errMsg", ex.getLocalizedMessage());
            mv.setViewName("views/error");
            return mv;
        } else /** ?BusinessExceptionExceptionerror? **/
        {
            return super.doResolveException(request, response, handler, ex);
        }
    }

}

From source file:i18nplugin.TranslationNode.java

/**
 * Create Tree/*from   ww w. j  a va 2  s .co m*/
 * @param string Name of Tree-Node
 * @param file Jar-File with Properties
 */
public TranslationNode(String string, File file) {
    super(string);

    try {
        JarFile jarfile = new JarFile(file);

        Enumeration<JarEntry> entries = jarfile.entries();

        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();

            if (entry.getName().endsWith(".properties")) {
                String name = entry.getName();

                name = name.substring(0, name.length() - 11);

                if (name.indexOf('/') >= 0) {
                    String dir = StringUtils.substringBeforeLast(name, "/");

                    if (dir.contains("/")) {
                        dir = StringUtils.substringAfterLast(dir, "/");
                    }

                    name = StringUtils.substringAfterLast(name, "/");

                    if (name.equals(dir)) {
                        addEntry(jarfile, entry);
                    }
                }
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.bstek.dorado.core.store.SqlBaseStoreSupport.java

public void setBeanName(String name) {
    if (StringUtils.isEmpty(namespace) && name.startsWith(BEAN_NAME_PREFIX)) {
        namespace = StringUtils.substringAfterLast(name, ".");
    }//from   www  .j  ava2s .  c om
}

From source file:info.magnolia.module.admininterface.DialogMVCServlet.java

/**
 *
 *//* w  w  w .j  a  v a 2s . c  om*/
protected MVCServletHandler getHandler(HttpServletRequest request, HttpServletResponse response) {
    String dialogName = RequestFormUtil.getParameter(request, "mgnlDialog"); //$NON-NLS-1$

    if (StringUtils.isEmpty(dialogName)) {
        if (StringUtils.isEmpty(dialogName)) {
            dialogName = (String) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
            if (StringUtils.isEmpty(dialogName)) {
                dialogName = (String) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
            }
            if (StringUtils.isEmpty(dialogName)) {
                dialogName = request.getRequestURI();
            }
            dialogName = StringUtils.replaceOnce(StringUtils.substringAfterLast(dialogName, "/dialogs/"), //$NON-NLS-1$
                    ".html", //$NON-NLS-1$
                    StringUtils.EMPTY);
        }
    }

    DialogMVCHandler handler = null;

    if (StringUtils.isNotBlank(dialogName)) {
        // try to get a registered handler
        try {
            handler = DialogHandlerManager.getInstance().getDialogHandler(dialogName, request, response);
        } catch (InvalidDialogHandlerException e) {
            log.info("can't find handler will try to load directly from the config", e); //$NON-NLS-1$
            Content configNode = ConfiguredDialog.getConfigNode(request, dialogName);
            // try to find a class property or return a ConfiguredDialog
            if (configNode != null) {
                handler = ConfiguredDialog.getConfiguredDialog(dialogName, configNode, request, response);
            } else {
                log.error("no config node found for dialog : " + dialogName); //$NON-NLS-1$
            }
        }
    }

    if (handler == null) {
        log.error(MessageFormat.format("Missing configuration for {0}. Check node {1}{0}", //$NON-NLS-1$
                new Object[] { dialogName, "/modules/templating/Paragraphs/" })); //$NON-NLS-1$

        throw new ConfigurationException(
                MessageFormat.format("Missing configuration for {0}. Check node {1}{0}", //$NON-NLS-1$
                        new Object[] { dialogName, "/modules/templating/Paragraphs/" })); //$NON-NLS-1$

    }

    return handler;
}

From source file:adalid.util.io.FileWrapper.java

public List<String> read() {
    String fileName = file.getName();
    String fileType = StringUtils.substringAfterLast(fileName, ".");
    if (StringUtils.isBlank(fileType)) {
        fileType = fileName;/*from w  w w .  j av  a 2  s  .  co  m*/
    } else {
        fileType = fileType.toLowerCase();
    }
    type = "binary";
    charset = null;
    for (Charset cs : STANDARD_CHARSETS) {
        try {
            list = Files.readAllLines(path, cs);
            if (isEmpty()) {
                readingWarnings++;
                logger.warn(file.getPath() + " is empty ");
            }
            type = "text/" + fileType;
            charset = cs;
            return list;
        } catch (IOException ex) {
            readingWarnings++;
            logger.warn(ex);
            logger.warn(file.getPath() + " could not be read using " + cs);
        }
    }
    readingErrors++;
    logger.error(file.getPath() + " could not be read using a standard charset ");
    return null;
}

From source file:com.netflix.explorers.resources.EmbeddedContentResource.java

@GET
@Path("/{subResources:.*}")
public Response get(@PathParam("subResources") String subResources) throws Exception {
    LOG.debug(subResources);/*from   ww w  .j a  v a 2  s . c  o m*/

    String ext = StringUtils.substringAfterLast(subResources, ".");
    String mediaType = EXT_TO_MEDIATYPE.get(ext);
    byte[] buffer = null;
    if (mediaType != null) {
        InputStream is = getClass().getResourceAsStream("/" + subResources);
        if (is == null) {
            throw new WebApplicationException(404);
        }
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            IOUtils.copy(is, os);
            buffer = os.toByteArray();
        } catch (IOException e) {
            LOG.warn(e.getMessage());
        }
    }

    if (buffer == null)
        throw new NotFoundException();
    else {
        if (CACHE_ENABLED) {
            CacheControl cc = new CacheControl();
            cc.setMaxAge(MAX_AGE);
            cc.setNoCache(false);
            return Response.ok(buffer, mediaType).cacheControl(cc)
                    .expires(new Date(System.currentTimeMillis() + 3600 * 1000))
                    .tag(new String(
                            Hex.encodeHex(MessageDigest.getInstance("MD5").digest(subResources.getBytes()))))
                    .build();
        } else {
            return Response.ok(buffer, mediaType).build();
        }
    }
}