Example usage for org.apache.commons.lang3 StringUtils indexOf

List of usage examples for org.apache.commons.lang3 StringUtils indexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils indexOf.

Prototype

public static int indexOf(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Finds the first index within a CharSequence, handling null .

Usage

From source file:org.kuali.kra.coi.disclosure.CoiDisclosureAction.java

/**
 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//* ww w.  java2s .  c o m*/
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward forward = super.refresh(mapping, form, request, response);
    if (request.getParameter("refreshCaller") != null
            && request.getParameter("refreshCaller").toString().equals("kualiLookupable")) {
        // Lookup field 'onchange' is not working if it is return a value from 'lookup', so do it on server side
        for (Object obj : request.getParameterMap().keySet()) {
            if (StringUtils.indexOf((String) obj,
                    ((CoiDisclosureForm) form).getQuestionnaireFieldStarter()) == 0) {
                ((CoiDisclosureForm) form).getDisclosureQuestionnaireHelper()
                        .updateChildIndicator(Integer.parseInt(StringUtils.substringBetween((String) obj,
                                ((CoiDisclosureForm) form).getQuestionnaireFieldStarter(), "].answers[")));
            }
        }
    }
    return forward;
}

From source file:org.kuali.kra.iacuc.questionnaire.IacucProtocolQuestionnaireAction.java

/**
 * This is specifically for 'lookup' return a value.
 *//*from  w  w w.j  a v  a  2  s  .  com*/
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward forward = super.refresh(mapping, form, request, response);
    if (request.getParameter("refreshCaller") != null
            && request.getParameter("refreshCaller").toString().equals("kualiLookupable")) {
        // Lookup field 'onchange' is not working if it is return a value from 'lookup', so do it on server side
        for (Object obj : request.getParameterMap().keySet()) {
            if (StringUtils.indexOf((String) obj, "questionnaireHelper.answerHeaders[") == 0) {
                ((IacucProtocolForm) form).getQuestionnaireHelper()
                        .updateChildIndicator(Integer.parseInt(StringUtils.substringBetween((String) obj,
                                "questionnaireHelper.answerHeaders[", "].answers[")));
            }
        }
    }
    if (StringUtils.isBlank(((IacucProtocolForm) form).getDocId())) {
        // lookup return to submission questionnaire popup
        forward = mapping.findForward(SUBMISSION_QUESTIONNAIRE);
        ((IacucProtocolForm) form).getQuestionnaireHelper().resetHeaderLabels();
    }
    return forward;
}

From source file:org.kuali.kra.irb.questionnaire.ProtocolQuestionnaireAction.java

/**
 * This is specifically for 'lookup' return a value.
 * @see org.kuali.kra.irb.ProtocolAction#refresh(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from  w  ww. ja  v  a 2  s.c o  m*/
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward forward = super.refresh(mapping, form, request, response);
    if (request.getParameter("refreshCaller") != null
            && request.getParameter("refreshCaller").toString().equals("kualiLookupable")) {
        // Lookup field 'onchange' is not working if it is return a value from 'lookup', so do it on server side
        for (Object obj : request.getParameterMap().keySet()) {
            if (StringUtils.indexOf((String) obj, "questionnaireHelper.answerHeaders[") == 0) {
                ((ProtocolForm) form).getQuestionnaireHelper().updateChildIndicator(Integer.parseInt(StringUtils
                        .substringBetween((String) obj, "questionnaireHelper.answerHeaders[", "].answers[")));
            }
        }
    }
    return forward;
}

From source file:org.lockss.plugin.FormUrlHelper.java

/**
 * convert from a unencoded string url This routine should almost never be
 * called because  it is impossible to tell whether equal signs and ampersands
 * are part of the form parameters or being used as separators. Use
 * convertFromEncodedString instead.//from  w  w w.j a v a 2  s .  c o  m
 *
 * @param url
 * @return true if the url is valid
 */
public boolean convertFromString(String url) {
    // an invalid url if starts with ?, doesn't contain ?
    if (StringUtils.indexOf(url, "?") == -1 || StringUtils.indexOf(url, "?") == 0) {
        m_valid = false;
        return m_valid;
    }

    String prefix = StringUtils.substringBefore(url, "?");
    setBaseUrl(prefix);
    String rest = StringUtils.substringAfter(url, "?");
    String key;
    String value;
    if (logger.isDebug3())
        logger.debug3("rest=" + rest);
    while (rest != null && rest.length() > 0) {
        if (logger.isDebug3())
            logger.debug3("rest2=" + rest);

        if (StringUtils.indexOf(rest, "=") > 0) {
            key = StringUtils.substringBefore(rest, "=");
            rest = StringUtils.substringAfter(rest, "=");
            if (logger.isDebug3())
                logger.debug3("rest3=" + rest);
            if (rest != null && StringUtils.indexOf(rest, "&") != -1) {
                value = StringUtils.substringBefore(rest, "&");
                add(key, value);
                rest = StringUtils.substringAfter(rest, "&");
            } else {
                // last value
                value = rest;
                add(key, value);
                rest = "";
            }
        } else {
            //This indicates a form url missing the equals  sign,
            // stop processing at this point
            m_valid = false;
            rest = "";
        }
    }
    return m_valid;
}

From source file:org.lockss.plugin.FormUrlNormalizer.java

/**
 * Normalize a form urls. This does (optional) sorting,
 * limits and mandatory// w  w w  .  j  a  v a 2s.  com
 * encoding for GET urls
 *
 * @param url base url
 * @param au  The au to this plugin is targeting
 * @return the normalized url string
 * @throws PluginException
 * @see org.lockss.plugin.UrlNormalizer#normalizeUrl(java.lang.String,
 *      org.lockss.plugin.ArchivalUnit)
 */
@Override
public String normalizeUrl(String url, ArchivalUnit au) throws PluginException {

    if (url == null) {
        return url;
    }
    //return all non-form urls unchanged
    if (StringUtils.indexOf(url, "?") == -1) {
        return url;
    }
    //if there is a problem converting the url, return the original url;
    if (!m_converter.convertFromEncodedString(url)) {
        return url;
    }

    if (m_sortAllUrls) {
        m_converter.sortKeyValues();
    }

    if (m_limits != null) {
        Set<String> limitedKeys = (Set<String>) m_limits.keySet();
        for (String key : limitedKeys) {
            m_converter.applyLimit(key, m_limits.get(key));
        }
    }

    String outputUrl = m_converter.toEncodedString();
    if (logger.isDebug() && !outputUrl.equals(url)) {
        logger.debug(" converted " + url + " to " + outputUrl);
    }
    return outputUrl;
}

From source file:org.maodian.flyingcat.xmpp.entity.JabberID.java

public static JabberID fromString(String str) {
    int atIndex = StringUtils.indexOf(str, "@");
    if (atIndex < 1) {
        // TODO: JID mailformed stanzs error
        throw new RuntimeException("JID not well formed");
    }/*from w w w.j  a v  a 2s.c o  m*/
    String uid = StringUtils.substring(str, 0, atIndex);
    int slashIndex = StringUtils.indexOf(str, "/");
    if (slashIndex == str.length()) {
        // TODO: JID mailformed stanzs error
        throw new RuntimeException("JID not well formed");
    }
    if (slashIndex != -1) {
        String domain = StringUtils.substring(str, atIndex + 1, slashIndex);
        String resource = StringUtils.substring(str, slashIndex);
        return new JabberID(uid, domain, resource);
    } else {
        String domain = StringUtils.substring(str, atIndex + 1);
        return new JabberID(uid, domain);
    }
}

From source file:org.massyframework.modules.launching.DefaultAssemblyResourceLoader.java

protected List<ClassLoader> parserClassLoader(String identifiers) throws ModuleLoadException {
    List<ClassLoader> result = new ArrayList<ClassLoader>();
    if (identifiers != null) {
        String[] names = StringUtils.split(identifiers, ",");
        for (String name : names) {
            name = StringUtils.deleteWhitespace(name);
            if (!"".equals(name)) {
                int index = StringUtils.indexOf(name, ":");
                String moduleName = name;
                String slot = "main";
                if (index != -1) {
                    moduleName = StringUtils.substring(name, 0, index);
                    slot = StringUtils.substring(name, index + 1, name.length());
                }//w ww . jav a 2  s .  co  m
                ModuleIdentifier identifier = ModuleIdentifier.create(moduleName, slot);
                Module module = this.moduleLoader.loadModule(identifier);
                result.add(module.getClassLoader());
            }
        }
    }

    return result;
}

From source file:org.massyframework.modules.launching.DefaultAssemblyResourceLoader.java

/**
 * ???/*from  w  w w  . j  a  v a 2s.co m*/
 * @param extensions
 */
protected Map<ModuleIdentifier, List<String>> parserAssemblyResources(String resources) {
    Map<ModuleIdentifier, List<String>> result = new LinkedHashMap<ModuleIdentifier, List<String>>();
    if (resources != null) {
        resources = StringUtils.replaceAll(resources, "", ",");
    }
    String[] texts = StringUtils.split(resources, ",");
    if (texts != null) {
        for (String text : texts) {
            int index = StringUtils.indexOf(text, "@");
            if (index < 0) {
                if (logger.isWarnEnabled()) {
                    logger.warn("incorrect format:" + text + ".");
                }
                continue;
            }

            String resource = StringUtils.substring(text, index);
            String moduleName = StringUtils.substring(text, index + 1, text.length());
            ModuleIdentifier identifier = ModuleIdentifierUtils.parse(moduleName);

            List<String> assemblyResources = result.get(identifier);
            if (assemblyResources == null) {
                assemblyResources = new ArrayList<String>();
                result.put(identifier, assemblyResources);
            }
            assemblyResources.add(resource);
        }
    }

    return result;
}

From source file:org.massyframework.modules.launching.ModuleIdentifierUtils.java

/**
 * ????ModuleIdentifier//  w ww  . ja va 2 s  .com
 * @param moduleName ???
 * @return {@link ModuleIdentifier}
 */
public static ModuleIdentifier parse(String moduleName) {
    if (moduleName == null)
        return null;

    int index = StringUtils.indexOf(moduleName, DELIMITER);
    if (index == -1) {
        return ModuleIdentifier.create(moduleName);
    } else {
        String name = StringUtils.substring(moduleName, 0, index);
        String slot = StringUtils.substring(moduleName, index + 1, moduleName.length());
        return ModuleIdentifier.create(name, slot);
    }

}

From source file:org.neo4art.importer.wikipedia.parser.util.WikipediaInfoboxParserUtils.java

/**
 * @param input//from  www.  j a  v  a2 s. co m
 * @return
 */
public static String getTextFromLink(String input) {

    String result = null;

    if (StringUtils.isNotBlank(input)) {

        result = input;
        result = StringUtils.remove(result, "[[");
        result = StringUtils.remove(result, "]]");

        if (StringUtils.indexOf(result, "|") != -1) {

            result = StringUtils.substring(result, 0, StringUtils.indexOf(result, "|"));
        }

        result = StringUtils.trim(result);
    }

    return result;
}