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:org.sakaiproject.poll.tool.producers.ResultsProducer.java

public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) {

    PollViewParameters ecvp = (PollViewParameters) viewparams;

    String strId = ecvp.id;/*from  w ww . j  av  a 2s .c  om*/
    LOG.debug("got id of " + strId);
    Poll poll = pollListManager.getPollById(Long.valueOf(strId));

    if (!pollListManager.isAllowedViewResults(poll, externalLogic.getCurrentUserId())) {
        tml.addMessage(
                new TargettedMessage("poll.noviewresult", new Object[] {}, TargettedMessage.SEVERITY_ERROR));
        return;

    }

    String locale = localegetter.get().toString();
    Map<String, String> langMap = new HashMap<String, String>();
    langMap.put("lang", locale);
    langMap.put("xml:lang", locale);

    UIOutput.make(tofill, "polls-html", null).decorate(new UIFreeAttributeDecorator(langMap));

    //get the number of votes
    int voters = pollVoteManager.getDisctinctVotersForPoll(poll);
    //Object[] args = new Object[] { Integer.valueOf(voters).toString()};
    if (poll.getMaxOptions() > 1)
        UIOutput.make(tofill, "poll-size",
                messageLocator.getMessage("results_poll_size", Integer.valueOf(voters).toString()));

    LOG.debug(voters + " have voted on this poll");

    UIOutput.make(tofill, "question", poll.getText());
    LOG.debug("got poll " + poll.getText());
    List<Option> pollOptions = poll.getPollOptions();

    LOG.debug("got a list of " + pollOptions.size() + " options");
    //Append an option for no votes
    if (poll.getMinOptions() == 0) {
        Option noVote = new Option(Long.valueOf(0));
        noVote.setOptionText(messageLocator.getMessage("result_novote"));
        noVote.setPollId(poll.getPollId());
        pollOptions.add(noVote);
    }

    List<Vote> votes = pollVoteManager.getAllVotesForPoll(poll);
    int totalVotes = votes.size();
    LOG.debug("got " + totalVotes + " votes");
    List<CollatedVote> collation = new ArrayList<CollatedVote>();

    for (int i = 0; i < pollOptions.size(); i++) {
        CollatedVote collatedVote = new CollatedVote();
        Option option = (Option) pollOptions.get(i);
        LOG.debug("collating option " + option.getOptionId());
        collatedVote.setoptionId(option.getOptionId());
        collatedVote.setOptionText(option.getOptionText());
        collatedVote.setDeleted(option.getDeleted());
        for (int q = 0; q < votes.size(); q++) {
            Vote vote = (Vote) votes.get(q);
            if (vote.getPollOption().equals(option.getOptionId())) {
                LOG.debug("got a vote for option " + option.getOptionId());
                collatedVote.incrementVotes();

            }

        }
        collation.add(collatedVote);

    }

    UILink title = UILink.make(tofill, "answers-title", messageLocator.getMessage("results_answers_title"),
            "#");
    title.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_title_tooltip")));
    UILink count = UILink.make(tofill, "answers-count", messageLocator.getMessage("results_answers_numbering"),
            "#");
    count.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_numbering_tooltip")));
    UILink avotes = UILink.make(tofill, "answers-votes", messageLocator.getMessage("results_answers_votes"),
            "#");
    avotes.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_votes_tooltip")));
    UILink apercent = UILink.make(tofill, "answers-percent", "%", "#");
    apercent.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_percent_tooltip")));
    UIBranchContainer adefault = UIBranchContainer.make(tofill, "answers-default:");
    adefault.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_answers_default_tooltip")));

    //output the votes
    Map<Long, String> chartTextData = new LinkedHashMap<Long, String>();
    Map<Long, String> chartValueData = new LinkedHashMap<Long, String>();
    NumberFormat nf = NumberFormat.getPercentInstance(localegetter.get());
    for (int i = 0; i < collation.size(); i++) {
        CollatedVote cv = (CollatedVote) collation.get(i);
        UIBranchContainer resultRow = UIBranchContainer.make(tofill, "answer-row:",
                cv.getoptionId().toString());

        String optionText = cv.getOptionText();
        if (cv.getDeleted()) {
            optionText += messageLocator.getMessage("deleted_option_tag_html");
        }

        UIVerbatim.make(resultRow, "answer-option", optionText);
        UIOutput.make(resultRow, "answer-count", Integer.valueOf(i + 1).toString());
        UIOutput.make(resultRow, "answer-numVotes", Long.valueOf(cv.getVotes()).toString());

        LOG.debug("about to do the calc: (" + cv.getVotes() + "/" + totalVotes + ")*100");
        double percent = (double) 0;
        if (totalVotes > 0 && poll.getMaxOptions() == 1)
            percent = ((double) cv.getVotes() / (double) totalVotes); //*(double)100;
        else if (totalVotes > 0 && poll.getMaxOptions() > 1)
            percent = ((double) cv.getVotes() / (double) voters); //*(double)100;
        else
            percent = (double) 0;

        //setup chartdata, use percentages for the values
        //also, remove the &nbsp; from the beginning of the label, POLL-139
        //we use the same number formatter which adds a % to the end of the data, remove that as well.
        chartTextData.put(cv.getoptionId(), StringUtils.removeStart(optionText, "&nbsp;"));
        chartValueData.put(cv.getoptionId(), StringUtils.removeEnd(nf.format(percent), "%"));

        LOG.debug("result is " + percent);
        UIOutput.make(resultRow, "answer-percVotes", nf.format(percent));

    }
    UIOutput.make(tofill, "votes-total", Integer.valueOf(totalVotes).toString());
    if (totalVotes > 0 && poll.getMaxOptions() == 1)
        UIOutput.make(tofill, "total-percent", "100%");

    /** CHART **/
    if (externalLogic.isResultsChartEnabled() && totalVotes > 0) {

        //chart selector label
        UIOutput.make(tofill, "chart-type-label", messageLocator.getMessage("results_chart_type"));

        //chart selector - no binding, JQuery handles it.
        String[] chartTypes = new String[] { "bar", "pie" };
        UISelect min = UISelect.make(tofill, "chart-type", chartTypes, "null", "bar");

        //setup bar chart
        //data separator is |
        StringBuilder sbBar = new StringBuilder();
        sbBar.append("https://chart.googleapis.com/chart?");
        sbBar.append("cht=bvg&");
        sbBar.append("chxt=y&");
        sbBar.append("chs=500x400&");
        sbBar.append("chd=t:" + StringUtils.join(chartValueData.values(), '|') + "&");
        sbBar.append("chdl=" + StringUtils.join(chartTextData.values(), '|') + "&");
        sbBar.append(
                "chco=FF0000,00FF00,0000FF,FFFF00,00FFFF,FF00FF,C0C0C0,800080,000080,808000,800000,FF00FF,008080,800000,008000");

        UILink barChart = UILink.make(tofill, "poll-chart-bar", sbBar.toString());
        LOG.debug("bar chart URL:" + sbBar.toString());

        //setup pie chart
        //data separator is ,
        StringBuilder sbPie = new StringBuilder();
        sbPie.append("https://chart.googleapis.com/chart?");
        sbPie.append("cht=p&");
        sbPie.append("chs=500x400&");
        sbPie.append("chd=t:" + StringUtils.join(chartValueData.values(), ',') + "&");
        sbPie.append("chl=" + StringUtils.join(chartTextData.values(), '|') + "&");
        sbPie.append(
                "chco=FF0000,00FF00,0000FF,FFFF00,00FFFF,FF00FF,C0C0C0,800080,000080,808000,800000,FF00FF,008080,800000,008000");

        UILink pieChart = UILink.make(tofill, "poll-chart-pie", sbPie.toString());
        LOG.debug("pie chart URL:" + sbPie.toString());

        //refresh link
        UIInternalLink resultsLink = UIInternalLink.make(tofill, "results-refresh",
                messageLocator.getMessage("action_refresh_results"),
                new PollViewParameters(ResultsProducer.VIEW_ID, poll.getPollId().toString()));
        resultsLink.decorators = new DecoratorList(new UITooltipDecorator(
                messageLocator.getMessage("action_refresh_results") + ":" + poll.getText()));
    }

    //the cancel button
    UIForm form = UIForm.make(tofill, "actform");
    UICommand cancel = UICommand.make(form, "cancel", messageLocator.getMessage("results_cancel"),
            "#{pollToolBean.cancel}");
    cancel.decorators = new DecoratorList(
            new UITooltipDecorator(messageLocator.getMessage("results_cancel_tooltip")));

    externalLogic.postEvent("poll.viewResult",
            "poll/site/" + externalLogic.getCurrentLocationId() + "/poll/" + poll.getPollId(), false);

}

From source file:org.sipfoundry.sipxconfig.freeswitch.FreeswitchCondition.java

public String getExtension() {
    return StringUtils.removeEnd(StringUtils.removeStart(m_expression, "^"), "$");
}

From source file:org.sipfoundry.sipxconfig.rest.OpenAcdLinesResource.java

private OpenAcdLineActionsBundleRestInfo createLineActionsBundleRestInfo(OpenAcdLine line) {
    OpenAcdLineActionsBundleRestInfo lineActionsBundleRestInfo;
    OpenAcdQueueRestInfo queueRestInfo;/* w w w.  jav a  2  s . com*/
    OpenAcdClientRestInfo clientRestInfo;
    List<OpenAcdLineActionRestInfo> customActions = new ArrayList<OpenAcdLineActionRestInfo>();
    OpenAcdLineActionRestInfo customActionRestInfo;

    OpenAcdQueue queue;
    String queueName = EMPTY_STRING;
    OpenAcdClient client;
    String clientIdentity = EMPTY_STRING;
    Boolean allowVoicemail = false;
    String allowVoicemailString = "false";
    Boolean isFsSet = false;
    Boolean isAgentSet = false;
    String answerSupervisionType = EMPTY_STRING;
    String welcomeMessage = EMPTY_STRING;

    List<FreeswitchAction> actions = line.getLineActions();
    for (FreeswitchAction action : actions) {
        String application = action.getApplication();
        String data = action.getData();

        if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.answer.toString())) {
            isFsSet = true;
        } else if (StringUtils.contains(data, OpenAcdLine.ERLANG_ANSWER)) {
            isAgentSet = true;
        } else if (StringUtils.contains(data, OpenAcdLine.Q)) {
            queueName = StringUtils.removeStart(data, OpenAcdLine.Q);
        } else if (StringUtils.contains(data, OpenAcdLine.BRAND)) {
            clientIdentity = StringUtils.removeStart(data, OpenAcdLine.BRAND);
        } else if (StringUtils.contains(data, OpenAcdLine.ALLOW_VOICEMAIL)) {
            allowVoicemailString = StringUtils.removeStart(data, OpenAcdLine.ALLOW_VOICEMAIL);
        } else if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.playback.toString())) {
            // web ui only displays filename and appends audio directory
            // welcomeMessage = StringUtils.removeStart(data,
            // m_openAcdContext.getSettings().getAudioDirectory() + "/");
            welcomeMessage = data;
        } else {
            customActionRestInfo = new OpenAcdLineActionRestInfo(action);
            customActions.add(customActionRestInfo);
        }
    }

    queue = m_openAcdContext.getQueueByName(queueName);
    queueRestInfo = new OpenAcdQueueRestInfo(queue);

    client = m_openAcdContext.getClientByIdentity(clientIdentity);
    clientRestInfo = new OpenAcdClientRestInfo(client);

    allowVoicemail = Boolean.parseBoolean(allowVoicemailString);

    if (isFsSet) {
        answerSupervisionType = SUPERVISION_TYPE_FS;
    } else if (isAgentSet) {
        answerSupervisionType = SUPERVISION_TYPE_AGENT;
    } else {
        answerSupervisionType = SUPERVISION_TYPE_ACD;
    }

    lineActionsBundleRestInfo = new OpenAcdLineActionsBundleRestInfo(queueRestInfo, clientRestInfo,
            allowVoicemail, customActions, answerSupervisionType, welcomeMessage);

    return lineActionsBundleRestInfo;
}

From source file:org.sipfoundry.sipxconfig.rest.OpenAcdLinesResource.java

private static String getQueueName(OpenAcdLine line) {
    String queueName = EMPTY_STRING;
    List<FreeswitchAction> actions = line.getLineActions();

    for (FreeswitchAction action : actions) {
        String data = action.getData();

        if (StringUtils.contains(data, OpenAcdLine.Q)) {
            queueName = StringUtils.removeStart(data, OpenAcdLine.Q);
        }//from  w  w w  .  j a va 2 s.  co m
    }

    return queueName;
}

From source file:org.sipfoundry.sipxconfig.rest.OpenAcdLinesResource.java

private static String getClientIdentity(OpenAcdLine line) {
    String clientIdentity = EMPTY_STRING;
    List<FreeswitchAction> actions = line.getLineActions();

    for (FreeswitchAction action : actions) {
        String data = action.getData();

        if (StringUtils.contains(data, OpenAcdLine.BRAND)) {
            clientIdentity = StringUtils.removeStart(data, OpenAcdLine.BRAND);
        }/* w w  w. j a v  a2  s . c  o m*/
    }

    return clientIdentity;
}

From source file:org.sipfoundry.sipxconfig.site.common.PluginSpecificationResolver.java

private IComponentSpecification findPluginSpecification(INamespace namespace, String name, String type) {
    String packages = namespace.getPropertyValue("org.apache.tapestry.plugin-packages");
    String className = StringUtils.removeStart(name, "plugin/").replace('/', '.');
    Class pageClass = m_clazzFinder.findClass(packages, className);
    if (pageClass == null) {
        return null;
    }//from   w ww  . ja v  a  2s .co m

    IComponentSpecification spec = new ComponentSpecification();
    Resource componentResource = m_resourceFactory.newResource(name + type);
    Location location = new LocationImpl(componentResource);
    spec.setLocation(location);
    spec.setSpecificationLocation(componentResource);
    spec.setComponentClassName(pageClass.getName());
    return spec;
}

From source file:org.sipfoundry.sipxconfig.site.openacd.EditOpenAcdLine.java

@Override
public void pageBeginRender(PageEvent event) {
    super.pageEndRender(event);
    List<FreeswitchAction> actions = null;

    if (getOpenAcdLineId() == null) {
        actions = OpenAcdLine.getDefaultActions(getLocationsManager().getPrimaryLocation());
    } else {// w  ww . j  av a2 s  . c om
        OpenAcdLine line = (OpenAcdLine) getOpenAcdContext().getExtensionById(getOpenAcdLineId());
        actions = line.getLineActions();
        setName(line.getName());
        setDescription(line.getDescription());
        setLineNumber(line.getNumberCondition().getExtension());
        setAlias(line.getAlias());
        setDid(line.getDid());
        setRegex(line.getNumberCondition().isRegex());
    }

    List<ActionBean> actionBeans = new LinkedList<ActionBean>();
    boolean isFsSet = false;
    boolean isAgentSet = false;
    for (FreeswitchAction action : actions) {
        String application = action.getApplication();
        String data = action.getData();
        if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.answer.toString())) {
            isFsSet = true;
        } else if (StringUtils.contains(data, OpenAcdLine.ERLANG_ANSWER)) {
            isAgentSet = true;
        } else if (StringUtils.contains(data, OpenAcdLine.Q)) {
            if (getSelectedQueue() == null) {
                String queueName = StringUtils.removeStart(data, OpenAcdLine.Q);
                OpenAcdQueue queue = getOpenAcdContext().getQueueByName(queueName);
                setSelectedQueue(queue);
            }
        } else if (StringUtils.contains(data, OpenAcdLine.BRAND)) {
            if (getSelectedClient() == null) {
                String clientIdentity = StringUtils.removeStart(data, OpenAcdLine.BRAND);
                OpenAcdClient client = getOpenAcdContext().getClientByIdentity(clientIdentity);
                setSelectedClient(client);
            }
        } else if (StringUtils.contains(data, OpenAcdLine.ALLOW_VOICEMAIL)) {
            setAllowVoicemail(
                    BooleanUtils.toBoolean(StringUtils.removeStart(data, OpenAcdLine.ALLOW_VOICEMAIL)));
        } else if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.playback.toString())) {
            if (getWelcomeMessage() == null) {
                setWelcomeMessage(StringUtils.removeStart(data, getSettings().getAudioDirectory() + SLASH));
            }
        } else {
            actionBeans.add(new ActionBean(action));
        }
    }
    if (isFsSet) {
        setAnswerSupervisionType(FS);
    } else if (isAgentSet) {
        setAnswerSupervisionType(AGENT);
    } else {
        setAnswerSupervisionType(ACD);
    }

    if (getActions() == null) {
        setActions(actionBeans);
    }
    if (getRemoveAction() != null) {
        getActions().remove(getRemoveAction());
    }
}

From source file:org.sipfoundry.sipxconfig.site.openacd.OpenAcdLines.java

public String getQueue() {
    List<FreeswitchAction> actions = getCurrentRow().getLineActions();
    for (FreeswitchAction action : actions) {
        String data = action.getData();
        if (StringUtils.contains(data, OpenAcdLine.Q)) {
            return StringUtils.removeStart(data, OpenAcdLine.Q);
        }//from   w w w .  ja v  a  2  s.  c o m
    }
    return "";
}

From source file:org.sipfoundry.sipxconfig.site.openacd.OpenAcdLines.java

public String getClient() {
    List<FreeswitchAction> actions = getCurrentRow().getLineActions();
    for (FreeswitchAction action : actions) {
        String data = action.getData();
        if (StringUtils.contains(data, OpenAcdLine.BRAND)) {
            String clientIdentity = StringUtils.removeStart(data, OpenAcdLine.BRAND);
            OpenAcdClient client = getOpenAcdContext().getClientByIdentity(clientIdentity);
            return client.getName();
        }//  ww  w .j  a  va  2  s.  c o m
    }
    return StringUtils.EMPTY;
}

From source file:org.skb.lang.dal.DalPass3_Gen.java

public LinkedHashMap<String, String> fixKV(LinkedHashMap<String, List<StringTemplate>> kv) {
    LinkedHashMap<String, String> ret = new LinkedHashMap<String, String>();
    String key;//from   ww w .  j  a  va  2s.  com
    Set<String> o_set = kv.keySet();
    Iterator<String> key_it = o_set.iterator();
    while (key_it.hasNext()) {
        key = key_it.next();
        String value = "";
        List<StringTemplate> list = kv.get(key);
        for (int i = 0; i < list.size(); i++) {
            if (value.length() > 0)
                value += ", ";
            value += StringUtils.removeEnd(StringUtils.removeStart(list.get(i).toString(), "\""), "\"");
        }
        ret.put(key, value);
    }
    return ret;
}