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:com.zxy.commons.email.MailMessageUtils.java

/**
 * smtp??//from www.j a  va  2 s. co  m
 * 
 * @param subject subject
 * @param htmlBody htmlBody
 * @param properties properties
 * @param from from
 * @param toList toList
 * @param ccList ccList
 * @param bccList bccList
 * @param embedUrls 
 * @throws EmailException EmailException
 */
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseStringBufferForStringAppends" })
public static void sendMail(String subject, String htmlBody, Map<String, String> properties, String from,
        List<String> toList, List<String> ccList, List<String> bccList, Map<String, URL> embedUrls)
        throws EmailException {
    HtmlEmail htmlEmail = getEmail();
    // from?
    if (!Strings.isNullOrEmpty(from)) {
        Address fromMailbox = parseMailbox(from);
        if (fromMailbox != null && StringUtils.isNotBlank(from)) {
            htmlEmail.setFrom(fromMailbox.getAddress(), fromMailbox.getName());
        }
    }
    // to?
    if (toList != null && !toList.isEmpty()) {
        for (String to : toList) {
            if (StringUtils.isNotBlank(to)) {
                Address toMailbox = parseMailbox(to);
                htmlEmail.addTo(toMailbox.getAddress(), toMailbox.getName());
            }
        }
    }
    // cc?
    if (ccList != null && !ccList.isEmpty()) {
        for (String cc : ccList) {
            if (StringUtils.isNotBlank(cc)) {
                Address ccMailbox = parseMailbox(cc);
                htmlEmail.addCc(ccMailbox.getAddress(), ccMailbox.getName());
            }
        }
    }
    // bcc?
    if (bccList != null && !bccList.isEmpty()) {
        for (String bcc : bccList) {
            if (StringUtils.isNotBlank(bcc)) {
                Address bccMailbox = parseMailbox(bcc);
                htmlEmail.addBcc(bccMailbox.getAddress(), bccMailbox.getName());
            }
        }
    }
    // 
    htmlEmail.setSubject(subject);
    htmlEmail.setHtmlMsg(htmlBody);
    htmlEmail.setSentDate(new Date());
    // 
    if (properties != null) {
        htmlEmail.setHeaders(properties);
    }
    // 
    if (embedUrls != null && !embedUrls.isEmpty()) {
        for (Map.Entry<String, URL> entry : embedUrls.entrySet()) {
            String cid = entry.getKey();
            URL url = entry.getValue();
            String fileName = StringUtils.substringAfterLast(url.getPath(), "/");
            if (StringUtils.isBlank(fileName)) {
                fileName = cid;
            } else {
                fileName += IdUtils.genStringId();
            }
            htmlEmail.embed(new URLDataSource(url), fileName, cid);
        }
    }
    htmlEmail.send();
}

From source file:es.urjc.mctwp.image.management.ImagePluginManager.java

private List<ImagePlugin> getPlugins(File file) {
    List<ImagePlugin> result = null;

    if (file != null) {
        String ext = StringUtils.substringAfterLast(file.getName(), FilenameUtils.EXTENSION_SEPARATOR_STR);
        result = plugins.get(ImageUtils.normalizeExtension(ext));
    }//  www. ja  v a  2  s  . co m

    return result;
}

From source file:de.awtools.basic.file.AWToolsFileUtils.java

/**
 * Siehe die Beschreibung in Methode/*from w w w  .  ja v a  2 s. c om*/
 * {@link #findFiles(java.io.File, java.lang.String, java.lang.String)}.
 *
 * @param basePath Basisverzeichnis.
 * @param fileName Die gesuchte Datei.
 * @return Eine Liste der gefundenen Dateien.
 *
 * @see #findFiles(java.io.File, java.lang.String, java.lang.String)
 */
public static List<File> findFiles(final File basePath, final String fileName) {

    String relativePath = "";
    String realFileName = fileName;

    if ((StringUtils.contains(fileName, "/"))) {
        relativePath = StringUtils.substringBeforeLast(fileName, "/");
        realFileName = StringUtils.substringAfterLast(fileName, "/");
    }

    if (log.isDebugEnabled()) {
        log.debug("basePath ......: " + basePath);
        log.debug("relativePath ..: " + relativePath);
        log.debug("realFileName ..: " + realFileName);
    }

    return AWToolsFileUtils.findFiles(basePath, relativePath, realFileName);
}

From source file:mitm.common.mail.EmailAddressUtils.java

/**
 * Returns the domain part ie. everything after the @. If there is no @ null is returned. The email address is 
 * not normalized or validated. It's up to the caller to validate the email address.
 *//*from w w w .j  a v  a2 s  .c o  m*/
public static String getDomain(String email) {
    String domain = StringUtils.substringAfterLast(email, "@");

    if (StringUtils.isEmpty(domain)) {
        domain = null;
    }

    return domain;
}

From source file:br.usp.ime.lapessc.xflow2.core.VCSMiner.java

private void fixFolder(Resource resource, Commit commit) {

    try {//  ww  w .j a v  a  2  s  .co m
        String path = resource.getPath();
        final int lastSlash = path.lastIndexOf("/");

        //Fim da recurso
        if (lastSlash != 0) {
            String parentFolderPath = StringUtils.substringBeforeLast(path, "/");

            Folder parentFolder = new FolderDAO().findFolderByPath(commit.getVcsMiningProject(),
                    parentFolderPath);

            if (parentFolder != null) {
                resource.setParentFolder(parentFolder);
            } else {
                parentFolder = new Folder();
                parentFolder.setPath(parentFolderPath);
                parentFolder.setName(StringUtils.substringAfterLast(parentFolder.getPath(), "/"));
                parentFolder.setOperationType('A');
                parentFolder.setCommit(commit);
                resource.setParentFolder(parentFolder);

                new FolderDAO().insert(parentFolder);

                fixFolder(parentFolder, commit);
            }
        }
    } catch (DatabaseException e) {
        e.printStackTrace();
    }
}

From source file:info.magnolia.setup.for4_5.UpdateSecurityFilterClientCallbacksConfiguration.java

private String simplifyClassName(String clazz) {
    return StringUtils.removeEnd(StringUtils.substringAfterLast(clazz, "."), "ClientCallback").toLowerCase();
}

From source file:com.amalto.core.storage.hibernate.HibernateStorageTransaction.java

/**
 * Dumps all current entities in <code>session</code> using data model information from <code>storage</code>.
 *
 * @param session The Hibernate session that failed to be committed.
 * @param storage A {@link com.amalto.core.storage.hibernate.HibernateStorage} that can be used to retrieve metadata information for all objects in
 *                <code>session</code>.
 *//*w  w w .  j  a v  a 2s. co  m*/
private static void dumpTransactionContent(Session session, HibernateStorage storage) {
    Level currentLevel = Level.INFO;
    if (LOGGER.isEnabledFor(currentLevel)) {
        Set<EntityKey> failedKeys = new HashSet<>(session.getStatistics().getEntityKeys()); // Copy content to avoid concurrent modification issues.
        int i = 1;
        ObjectDataRecordReader reader = new ObjectDataRecordReader();
        MappingRepository mappingRepository = storage.getTypeEnhancer().getMappings();
        StorageClassLoader classLoader = storage.getClassLoader();
        DataRecordXmlWriter writer = new DataRecordXmlWriter();
        ResettableStringWriter xmlContent = new ResettableStringWriter();
        for (EntityKey failedKey : failedKeys) {
            String entityTypeName = StringUtils.substringAfterLast(failedKey.getEntityName(), "."); //$NON-NLS-1$
            LOGGER.log(currentLevel,
                    "Entity #" + i++ + " (type=" + entityTypeName + ", id=" + failedKey.getIdentifier() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            try {
                storage.getClassLoader().bind(Thread.currentThread());
                Wrapper o = (Wrapper) ((SessionImpl) session).getPersistenceContext().getEntity(failedKey);
                if (!session.isReadOnly(o)) {
                    if (o != null) {
                        ComplexTypeMetadata type = classLoader
                                .getTypeFromClass(classLoader.loadClass(failedKey.getEntityName()));
                        if (type != null) {
                            DataRecord record = reader.read(mappingRepository.getMappingFromDatabase(type), o);
                            writer.write(record, xmlContent);
                            LOGGER.log(currentLevel, xmlContent + "\n(taskId='" + o.taskId() + "', timestamp='" //$NON-NLS-1$//$NON-NLS-2$
                                    + o.timestamp() + "')"); //$NON-NLS-1$
                        } else {
                            LOGGER.warn("Could not find data model type for object " + o); //$NON-NLS-1$
                        }
                    } else {
                        LOGGER.warn("Could not find an object for entity " + failedKey); //$NON-NLS-1$
                    }
                }
            } catch (ObjectNotFoundException missingRefException) {
                LOGGER.log(currentLevel, "Can not log entity: contains a unresolved reference to '" //$NON-NLS-1$
                        + missingRefException.getEntityName() + "' with id '" //$NON-NLS-1$
                        + missingRefException.getIdentifier() + "'"); //$NON-NLS-1$
            } catch (Exception serializationException) {
                LOGGER.log(currentLevel, "Failed to log entity content for type " + entityTypeName //$NON-NLS-1$
                        + " (enable DEBUG for exception details)."); //$NON-NLS-1$
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Serialization exception occurred.", serializationException); //$NON-NLS-1$
                }
            } finally {
                xmlContent.reset();
                storage.getClassLoader().unbind(Thread.currentThread());
            }
            if (i > TRANSACTION_DUMP_MAX) {
                if (!LOGGER.isDebugEnabled()) {
                    int more = failedKeys.size() - i;
                    if (more > 0) {
                        LOGGER.log(currentLevel, "and " + more + " more... (enable DEBUG for full dump)"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    return;
                } else {
                    currentLevel = Level.DEBUG; // Continue the dump but with a DEBUG level
                }
            }
        }
    }
}

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

private void createBinaryFilePropertiesFile(String source, String target) {
    List<String> lines = new ArrayList<>();
    String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties";
    String folder = StringUtils.substringBeforeLast(properties, FS);
    String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/");
    String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS)
            .replace(FS, "/").replace(project, PROJECT_ALIAS);
    path = replaceAliasWithRootFolderName(path);
    path = finalisePath(path);/*w ww.j  a v  a  2s. c o m*/
    String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS);
    lines.add("template = " + template);
    lines.add("template-type = document");
    lines.add("path = " + path);
    lines.add("file = " + file);
    lines.add("preserve = true");
    FilUtils.mkdirs(folder);
    if (write(properties, lines, WINDOWS_CHARSET)) {
        propertiesFilesCreated++;
    }
}

From source file:acromusashi.stream.tools.ConfigPutTool.java

/**
 * Put file to remote server./*from  ww w  .  j  av a  2 s . c  o m*/
 * 
 * @param connection Ssh Connection 
 * @param srcPath src Path
 * @param dstPath dst Path
 * @throws IOException Put failed
 */
private void putFile(Connection connection, String srcPath, String dstPath) throws IOException {
    SCPClient client = new SCPClient(connection);

    File srcFile = new File(srcPath);
    String dstFileDir = StringUtils.substringBeforeLast(dstPath, PATH_DELIMETER);
    String dstFileName = StringUtils.substringAfterLast(dstPath, PATH_DELIMETER);

    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcFile));
            SCPOutputStream out = client.put(dstFileName, srcFile.length(), dstFileDir, "0664");) {
        IOUtils.copy(in, out);
    } catch (IOException ex) {
        throw ex;
    }
}

From source file:com.bstek.dorado.view.resolver.PackageFileResolver.java

@Override
protected ResourcesWrapper createResourcesWrapper(HttpServletRequest request, DoradoContext context)
        throws Exception {
    String packageName = StringUtils.substringAfterLast(request.getRequestURI(), "/");

    String resourcePrefix = getResourcePrefix();
    String resourceSuffix = getUriSuffix(request);
    packageName = packageName.substring(0, packageName.length() - resourceSuffix.length());

    Resource[] resources;/*from   ww  w . j a va  2  s .c  om*/
    PackagesConfig packagesConfig = getPackagesConfigManager().getPackagesConfig();
    Map<String, Pattern> patterns = packagesConfig.getPatterns();
    Map<String, Package> packages = packagesConfig.getPackages();

    boolean cacheable = true;
    String[] pkgNames = packageName.split(",");
    List<FileInfo> fileInfos = new ArrayList<FileInfo>();
    for (int i = 0; i < pkgNames.length; i++) {
        String pkgName = pkgNames[i];
        Package pkg = packages.get(pkgName);
        if (pkg == null) {
            throw new FileNotFoundException("Package [" + pkgName + "] not found.");
        }

        if (i == 0) {
            String contentType = pkg.getContentType();
            if (StringUtils.isEmpty(contentType)) {
                Pattern pattern = patterns.get(pkg.getPattern());
                if (pattern != null) {
                    resourceSuffix = pattern.getResourceSuffix();
                    contentType = pattern.getContentType();
                }
            }

            if (StringUtils.isEmpty(resourceSuffix)) {
                if (HttpConstants.CONTENT_TYPE_CSS.equalsIgnoreCase(contentType)) {
                    resourceSuffix = STYLESHEET_SUFFIX;
                } else {
                    resourceSuffix = JAVASCRIPT_SUFFIX;
                }
            }
        }

        if (!pkg.isCacheable()) {
            cacheable = false;
        }

        collectFileInfos(context, fileInfos, pkg, resourcePrefix, resourceSuffix);
    }

    List<Resource> resourceList = new ArrayList<Resource>();
    for (FileInfo fileInfo : fileInfos) {
        Resource[] resourceArray = getResourcesByFileInfo(context, fileInfo, resourcePrefix, resourceSuffix);
        if (resourceArray != null) {
            for (int j = 0; j < resourceArray.length; j++) {
                resourceList.add(resourceArray[j]);
            }
        }
    }

    resources = new Resource[resourceList.size()];
    resourceList.toArray(resources);

    ResourcesWrapper resourcesWrapper = new ResourcesWrapper(resources,
            getResourceTypeManager().getResourceType(resourceSuffix));
    resourcesWrapper.setCacheable(cacheable);
    return resourcesWrapper;
}