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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:com.adobe.acs.commons.users.impl.AbstractAuthorizable.java

public AbstractAuthorizable(Map<String, Object> config) throws EnsureAuthorizableException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, getDefaultPath());
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(getDefaultPath(),
                StringUtils.removeEnd(tmp, this.principalName));
    } else {//  w  w w  . j av a  2  s  .  com
        this.principalName = tmp;
        this.intermediatePath = getDefaultPath();
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureAuthorizableException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedAuthorizables.isProtected(this.principalName)) {
        throw new EnsureAuthorizableException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        if (StringUtils.isNotBlank(entry)) {
            try {
                aces.add(new Ace(entry));
            } catch (EnsureAuthorizableException e) {
                log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                        + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
            }
        }
    }
}

From source file:com.adobe.acs.commons.users.impl.ServiceUser.java

public ServiceUser(Map<String, Object> config) throws EnsureServiceUserException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, PATH_SYSTEM_USERS);
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(PATH_SYSTEM_USERS,
                StringUtils.removeEnd(tmp, this.principalName));
    } else {/*w w  w.  j  a v  a  2 s .c  o m*/
        this.principalName = tmp;
        this.intermediatePath = "/home/users/system";
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureServiceUserException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedSystemUsers.isProtected(this.principalName)) {
        throw new EnsureServiceUserException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        try {
            aces.add(new Ace(entry));
        } catch (EnsureServiceUserException e) {
            log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                    + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
        }
    }
}

From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java

/**
 * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file
 * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file.
 * @param targetFolder the folder in which resources should be copied to
 * @throws java.io.IOException if the resources can be accessed or copied
 *///from  w w  w  .  j a  v  a 2  s. c o  m
static void copyWebTestResources(final File targetFolder) throws IOException {
    final String resourcesPrefix = "com/canoo/webtest/resources/";
    final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader()
            .getResource(resourcesPrefix + "webtest.xml");

    if (webtestXmlUrl == null) {
        throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml");
    } else if (webtestXmlUrl.toString().startsWith("jar:file")) {
        final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1");
        final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name());
        final JarFile jarFile = new JarFile(jarFileName);
        final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml");

        for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
            final JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().startsWith(resourcesPrefix)) {
                final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix);
                final URL url = new URL(urlPrefix + relativeName);
                final File targetFile = new File(targetFolder, relativeName);
                FileUtils.forceMkdir(targetFile.getParentFile());
                FileUtils.copyURLToFile(url, targetFile);
            }
        }
    } else if (webtestXmlUrl.toString().startsWith("file:")) {
        // we're probably developing and/or have a custom version of the resources in classpath
        final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl);
        final File resourceFolder = webtestXmlFile.getParentFile();

        FileUtils.copyDirectory(resourceFolder, targetFolder);
    } else {
        throw new IllegalStateException(
                "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl);
    }
}

From source file:com.aqnote.shared.cryptology.cert.tool.X509CertTool.java

private static byte[] getCertEncoded(String base64CrtFile) {
    if (StringUtils.isEmpty(base64CrtFile)) {
        return null;
    }/*  w  w w .ja  v  a2s.  co m*/

    String tmpBase64CrtFile = base64CrtFile;
    String headLine = BEGIN_CERT + lineSeparator;
    if (base64CrtFile.startsWith(headLine)) {
        tmpBase64CrtFile = StringUtils.removeStart(base64CrtFile, headLine);
    }
    if (tmpBase64CrtFile.endsWith(END_CERT)) {
        tmpBase64CrtFile = StringUtils.removeEnd(tmpBase64CrtFile, END_CERT);
    }

    return Base64.decodeBase64(tmpBase64CrtFile);
}

From source file:com.tlabs.eve.api.server.MessageOfTheDayParser.java

public MessageOfTheDayResponse parse(byte[] data) throws IOException {
    final int CACHE_IN_MN = /*60 * 8*/5;
    MessageOfTheDayResponse response = new MessageOfTheDayResponse();
    long now = System.currentTimeMillis();
    response.setCachedUntil(now - TimeZone.getDefault().getOffset(now) + CACHE_IN_MN * 60 * 1000);

    String message = new String(data);
    if (message.length() == 0) {
        //keep a content otherwise caching won't occur when the received data is empty
        message = "<br/>";
    } else {/*  w ww .  ja va2 s.  co m*/
        //The content is not great...we have a MOTD at start (sometimes)
        //or a <center>MOTD</center> or anything with such form
        //Also CCP found it funny to add shellexec: in front of <a> URLs.
        //A real XML would have been great.
        message = StringUtils.removeStart(message, "MOTD");
        message = StringUtils.remove(message, "shellexec:");
        message = StringUtils.replace(message, "<br>", "<br/>");
    }
    response.setMessage(message);
    return response;
}

From source file:ips1ap101.web.AbstractPageBean1.java

@Override
public String getManagedBeanName() {
    String path = getRequestPathInfo();
    String substring = StringUtils.removeEnd(StringUtils.removeStart(path, "/"), requestPathSuffix());
    String managedBeanName = substring.replace('/', '$');
    return managedBeanName;
}

From source file:com.cloudbees.plugins.credentials.ContextMenuIconUtils.java

/**
 * Combine segments of an URL in the style expected by {@link ModelObjectWithContextMenu.MenuItem}.
 *
 * @param segments the segments./*from  ww w.java  2s.  c  o  m*/
 * @return the combined URL.
 */
@NonNull
public static String buildUrl(String... segments) {
    StringBuilder result = new StringBuilder();
    boolean first = true;
    for (String segment : segments) {
        if (segment == null) {
            continue;
        }
        String str = StringUtils.removeEnd(StringUtils.removeStart(segment, "/"), "/");
        if (str.isEmpty()) {
            continue;
        }
        if (first) {
            first = false;
        } else {
            result.append('/');
        }
        result.append(str);
    }
    return result.toString();
}

From source file:com.fortify.processrunner.common.bugtracker.issue.SubmittedIssueCommentHelper.java

/**
 * Parse a {@link SubmittedIssue} from the given comment string that was previously generated using
 * {@link #getCommentForSubmittedIssue(String, SubmittedIssue)}
 * @param comment/*from   w ww .j av  a2 s  .c o m*/
 * @return
 */
public static final SubmittedIssue getSubmittedIssueFromComment(String comment) {
    try {
        Object[] fields = FMT_COMMENT.parse(comment);
        String id = StringUtils.removeStart(StringUtils.trim((String) fields[1]), "ID ");
        String deepLink = StringUtils.trim((String) fields[2]);
        return new SubmittedIssue(id, deepLink);
    } catch (Exception e) {
        throw new RuntimeException("Error parsing comment " + comment);
    }
}

From source file:com.hangum.tadpole.monitoring.core.jobs.UserJOB.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    StringBuffer sbMailContent = new StringBuffer();

    String strKey = context.getJobDetail().getKey().toString();
    if (logger.isDebugEnabled())
        logger.debug("start job is " + strKey);
    String[] keys = StringUtils.split(StringUtils.removeStart(strKey, "DEFAULT."),
            PublicTadpoleDefine.DELIMITER);

    int dbSeq = NumberUtils.createInteger(keys[0]);
    int scheduleSeq = NumberUtils.createInteger(keys[1]);

    boolean isResult = true;
    String strMessage = "";
    try {//from   ww  w  .  j a  v a2s. c  om
        UserDBDAO userDB = TadpoleSystem_UserDBQuery.getUserDBInstance(dbSeq);
        ScheduleMainDAO scheduleMainDao = TadpoleSystem_Schedule.findScheduleMain(scheduleSeq);
        List<ScheduleDAO> listSchedule = TadpoleSystem_Schedule.findSchedule(scheduleMainDao.getSeq());

        for (ScheduleDAO scheduleDAO : listSchedule) {
            try {
                sbMailContent.append(
                        DailySummaryReportJOB.executSQL(userDB, scheduleDAO.getName(), scheduleDAO.getSql()));
            } catch (Exception e) {
                sbMailContent.append("Rise Exception :" + e.getMessage());
                strMessage += e.getMessage() + "\n";
                isResult = false;
            }
        }

        DailySummaryReport report = new DailySummaryReport();
        String mailContent = report.makeFullSummaryReport(scheduleMainDao.getTitle(), sbMailContent.toString());

        Utils.sendEmail(scheduleMainDao.getUser_seq(), scheduleMainDao.getTitle(), mailContent);
        ;

        TadpoleSystem_Schedule.saveScheduleResult(scheduleSeq, isResult, strMessage);
    } catch (Exception e) {
        logger.error("execute User Job", e);

        try {
            TadpoleSystem_Schedule.saveScheduleResult(scheduleSeq, false, strMessage + e.getMessage());
        } catch (Exception e1) {
            logger.error("save schedule result", e1);
        }
    }

}

From source file:com.intel.cosbench.driver.iterator.NumericNameIterator.java

@Override
public String next(String curr, int idx, int all) {
    int value;/*from   w w w.  ja va2  s  .c om*/
    if (StringUtils.isEmpty(curr)) {
        if ((value = iterator.next(0, idx, all)) <= 0)
            return null;
        return StringUtils.join(new Object[] { prefix, value, suffix });
    }
    curr = StringUtils.removeStart(curr, prefix);
    curr = StringUtils.removeEnd(curr, suffix);
    if ((value = iterator.next(Integer.parseInt(curr), idx, all)) <= 0)
        return null;
    return StringUtils.join(new Object[] { prefix, value, suffix });
}