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

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

Introduction

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

Prototype

public static int indexOf(String str, String searchStr) 

Source Link

Document

Finds the first index within a String, handling null.

Usage

From source file:org.sakaiproject.umem.tool.jsf.HtmlSortHeaderRenderer.java

public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
    // If this is a currently sorted sort header, always give it the
    // "currentSort" CSS style class
    try {//from   w w  w . j a  va2s.c  o  m
        if (component instanceof HtmlCommandSortHeader) {
            HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) component;
            String styleClass = StringUtils.trimToNull(getStyleClass(facesContext, component));
            String newStyleClass;
            String unStyleClass;
            if (sortHeader.findParentDataTable().getSortColumn().equals(sortHeader.getColumnName())) {
                newStyleClass = CURRENT_SORT_STYLE;
                unStyleClass = NOT_CURRENT_SORT_STYLE;
            } else {
                newStyleClass = NOT_CURRENT_SORT_STYLE;
                unStyleClass = CURRENT_SORT_STYLE;
            }
            if (StringUtils.indexOf(styleClass, newStyleClass) == -1) {
                if (StringUtils.indexOf(styleClass, unStyleClass) != -1) {
                    styleClass = StringUtils.replace(styleClass, unStyleClass, newStyleClass);
                } else if (styleClass != null) {
                    styleClass = (new StringBuilder(styleClass)).append(' ').append(newStyleClass).toString();
                } else {
                    styleClass = newStyleClass;
                }
                sortHeader.setStyleClass(styleClass);
            }
        }
    } catch (Exception e) {
        log.warn("Exception occurred in HtmlSortHeaderRenderer:" + e.getMessage());
    }
    super.encodeBegin(facesContext, component); // check for NP
}

From source file:org.talend.mdm.webapp.browserecords.server.servlet.SmartViewServlet.java

@Override
protected void doGet(final HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setCharacterEncoding("UTF-8");//$NON-NLS-1$ 
    response.setHeader("Cache-Control", "no-cache, must-revalidate");//$NON-NLS-1$ //$NON-NLS-2$
    response.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");//$NON-NLS-1$ //$NON-NLS-2$

    String idsString = request.getParameter("ids");//$NON-NLS-1$
    String concept = request.getParameter("concept");//$NON-NLS-1$
    if (concept == null || idsString == null) {
        return;/*from w  ww. ja va 2 s.c om*/
    }
    boolean isStaging = request.getParameter("isStaging") != null //$NON-NLS-1$
            ? Boolean.parseBoolean(request.getParameter("isStaging")) //$NON-NLS-1$
            : false;
    String[] ids = idsString.split("@");//$NON-NLS-1$
    String language = (request.getParameter("language") != null ? request.getParameter("language").toUpperCase() //$NON-NLS-1$//$NON-NLS-2$
            : "EN");//$NON-NLS-1$
    String smartViewName = request.getParameter("name");//$NON-NLS-1$
    String optname;
    if (StringUtils.indexOf(smartViewName, '#') > 0) {
        optname = StringUtils.substringAfterLast(smartViewName, "#"); //$NON-NLS-1$
    } else {
        optname = null;
    }

    String transformer = null;
    try {
        boolean transfo_lang = SmartViewUtil.checkSmartViewExistsByLangAndOptName(concept, language, optname,
                false);

        if (transfo_lang) {
            transformer = "Smart_view_" + concept + "_" + language.toUpperCase();//$NON-NLS-1$ //$NON-NLS-2$
            if (optname != null && optname.length() > 0) {
                transformer += "#" + optname;//$NON-NLS-1$
            }
        } else {
            // Fallback to the non-language one
            boolean transfo_no_lang = SmartViewUtil.checkSmartViewExistsByLangAndOptName(concept, null, optname,
                    false);
            if (transfo_no_lang) {
                transformer = "Smart_view_" + concept;//$NON-NLS-1$
                if (optname != null && optname.length() > 0) {
                    transformer += "#" + optname;//$NON-NLS-1$
                }
            } else {
                transformer = null;
            }
        }
    } catch (Exception e) {
        org.apache.log4j.Logger.getLogger(this.getClass()).error(e);
        throw new ServletException(e);
    }

    String content = "";//$NON-NLS-1$
    String contentType = "text/html";//$NON-NLS-1$
    if (transformer != null) {
        String dataClusterPK;
        try {
            dataClusterPK = org.talend.mdm.webapp.browserecords.server.util.CommonUtil
                    .getCurrentDataCluster(isStaging);
        } catch (Exception e) {
            String err = "Unable to get the cluster";
            org.apache.log4j.Logger.getLogger(this.getClass()).error(err, e);
            throw new ServletException(err, e);
        }
        try {
            // run the Transformer
            WSTransformerContextPipelinePipelineItem[] entries = Util.getPort()
                    .extractThroughTransformerV2(new WSExtractThroughTransformerV2(
                            new WSItemPK(new WSDataClusterPK(dataClusterPK), concept, ids),
                            new WSTransformerV2PK(transformer)))
                    .getPipeline().getPipelineItem();

            // Scan the entries - in priority, taka the content of the 'html' entry,
            // else take the content of the _DEFAULT_ entry
            for (WSTransformerContextPipelinePipelineItem entrie : entries) {
                if ("_DEFAULT_".equals(entrie.getVariable())) {//$NON-NLS-1$
                    content = new String(entrie.getWsTypedContent().getWsBytes().getBytes(), "UTF-8");//$NON-NLS-1$
                    contentType = entrie.getWsTypedContent().getContentType();
                }
                if ("html".equals(entrie.getVariable())) {//$NON-NLS-1$
                    content = new String(entrie.getWsTypedContent().getWsBytes().getBytes(), "UTF-8");//$NON-NLS-1$
                    contentType = entrie.getWsTypedContent().getContentType();
                    break;
                }
            }
        } catch (Exception e) {
            String err = "Unable to run the transformer '" + transformer + "'"; //$NON-NLS-1$//$NON-NLS-2$
            org.apache.log4j.Logger.getLogger(this.getClass()).error(err, e);
            throw new ServletException(err, e);
        }
    }

    if (contentType.startsWith("application/xhtml+xml")) { //$NON-NLS-1$
        response.setContentType("text/html");//$NON-NLS-1$
    } else {
        response.setContentType(contentType);
    }
    PrintWriter out = response.getWriter();
    out.write(content);
    out.close();
}

From source file:org.talend.metadata.managment.model.MetadataFillFactory.java

public static boolean isJdbcNetezza(String dbType, String driverClass) {
    if (!StringUtils.isBlank(dbType) && !StringUtils.isBlank(driverClass)) {
        return StringUtils.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName(), dbType)
                && StringUtils.indexOf(StringUtils.lowerCase(driverClass), "netezza") > -1; //$NON-NLS-1$    
    }/*from w w  w. java2s . co m*/
    return false;
}

From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseForm.java

private String getUppercaseNetezzaUrl(String url) {
    if (StringUtils.isBlank(url)) {
        return url;
    }//from   w w  w . ja v a  2s. c o m
    String uppcaseUrl = url;
    int lastIndexOf = StringUtils.lastIndexOf(url, "/"); //$NON-NLS-1$
    if (lastIndexOf > 0 && lastIndexOf < url.length() - 1) {
        String part1 = StringUtils.substring(url, 0, lastIndexOf + 1);
        String part2 = StringUtils.substring(url, lastIndexOf + 1);
        if (!StringUtils.isEmpty(part2)) {
            int indexOf = StringUtils.indexOf(part2, "?"); //$NON-NLS-1$
            if (indexOf > -1) {
                String sid = StringUtils.substring(part2, 0, indexOf);
                part2 = StringUtils.upperCase(sid) + StringUtils.substring(part2, indexOf, part2.length());
            } else {
                part2 = StringUtils.upperCase(part2);
            }
            uppcaseUrl = part1 + part2;
        }
    }
    return uppcaseUrl;
}

From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseWizard.java

/**
 * uppercase the sid and url of Netezza connection.
 * //  w  ww .ja v  a  2 s. c  om
 * @param netezzaConnection
 */
private void uppercaseNetezzaSidUrl(DatabaseConnection netezzaConnection) {
    if (netezzaConnection == null) {
        return;
    }
    netezzaConnection.setSID(StringUtils.upperCase(netezzaConnection.getSID()));
    String url = netezzaConnection.getURL();
    if (StringUtils.isBlank(url)) {
        return;
    }
    int lastIndexOf = StringUtils.lastIndexOf(url, "/"); //$NON-NLS-1$
    if (lastIndexOf > 0 && lastIndexOf < url.length() - 1) {
        String part1 = StringUtils.substring(url, 0, lastIndexOf + 1);
        String part2 = StringUtils.substring(url, lastIndexOf + 1);
        if (!StringUtils.isEmpty(part2)) {
            int indexOf = StringUtils.indexOf(part2, "?"); //$NON-NLS-1$
            if (indexOf > -1) {
                String sid = StringUtils.substring(part2, 0, indexOf);
                part2 = StringUtils.upperCase(sid) + StringUtils.substring(part2, indexOf, part2.length());
            } else {
                part2 = StringUtils.upperCase(part2);
            }
            netezzaConnection.setURL(part1 + part2);
        }
    }
}

From source file:org.telscenter.sail.webapp.presentation.util.impl.SessionNavLogImpl.java

/**
 * Given a <code>String</code> XML SockEntry, returns a <code>String</code>
 * with the XML header info removed/*  w w  w .j  a va2 s . c om*/
 * 
 * @param <code>String</code> s
 * @return <code>String</code>
 */
private String stripHead(String s) {
    return StringUtils.strip(s.substring(StringUtils.indexOf(s, '>') + 1, StringUtils.lastIndexOf(s, '>')));
}

From source file:org.telscenter.sail.webapp.presentation.util.impl.SessionNavLogImpl.java

/**
 * Given a <code>String</code> XML SockEntry, returns the <code>String</code>
 * activityType//from  www  .j a va  2  s .co  m
 * 
 * @param <code>String</code> s
 * @return <code>String</code>
 */
public String activityType(String s) {
    String headless = stripHead(s);
    return StringUtils.strip(
            headless.substring(StringUtils.indexOf(headless, '<') + 1, StringUtils.indexOf(headless, ' ')));
}

From source file:org.telscenter.sail.webapp.presentation.util.impl.SessionNavLogImpl.java

/**
 * Given a <code>String</code> XML SockEntry, returns the <code>String</code>
 * podUUID/*from   www . ja v a 2 s .c o m*/
 * 
 * @param <code>String</code> s
 * @return <code>String</code>
 */
public String podUUID(String s) {
    String headless = stripHead(s);
    return StringUtils.strip(
            headless.substring(StringUtils.indexOf(headless, '"') + 1, StringUtils.lastIndexOf(headless, '"')));
}

From source file:org.telscenter.sail.webapp.presentation.web.controllers.student.brainstorm.BrainstormUtils.java

public static Map<String, String> parseChoices(String choiceList) {
    Map<String, String> choiceMap = new LinkedHashMap<String, String>();
    while (choiceList != null && choiceList != "" && StringUtils.contains(choiceList, "simpleChoice")) {
        choiceList = StringUtils.removeStart(choiceList, IDENTIFIER);
        String key = StringUtils.substring(choiceList, 0, StringUtils.indexOf(choiceList, "\""));
        choiceList = StringUtils.removeStart(choiceList, key);
        choiceList = StringUtils.removeStart(choiceList, BEFORECONTENT);
        String content = StringUtils.substring(choiceList, 0, StringUtils.indexOf(choiceList, AFTERCONTENT));
        choiceList = StringUtils.removeStart(choiceList, content);
        choiceList = StringUtils.removeStart(choiceList, AFTERCONTENT);
        choiceMap.put(key, replaceTags(content));
    }// w  w w. ja  va  2 s. c om
    return choiceMap;
}

From source file:org.vulpe.fox.apt.strategies.ForAllDAOTemplateStrategy.java

private void putMethod(final DecoratedClassDeclaration clazz, final DecoratedDAO dao, final String query,
        final String queryName, final QueryHint[] hints) {
    if (queryName.equals(dao.getName().concat(".read"))) {
        return;//from w w w.j a  v a2s.c  o  m
    }

    final DecoratedDAOMethod method = new DecoratedDAOMethod();

    if (StringUtils.indexOf(queryName, dao.getName().concat(".")) > -1) {
        method.setName(
                StringUtils.substring(queryName, StringUtils.indexOf(queryName, dao.getName().concat("."))
                        + new String(dao.getName().concat(".")).length()));
    } else {
        throw new VulpeSystemException("Name of definition in the query is incorrect. Must be on format: "
                .concat(dao.getName()).concat(".").concat(queryName));
    }

    boolean unique = false;
    String newQuery = StringUtils.replace(query, "\t", " ");
    final char dots = ':';
    final char space = ' ';
    while (newQuery.indexOf(dots) > -1) {
        newQuery = newQuery.substring(newQuery.indexOf(dots));
        String param = newQuery.substring(1);
        param = param.replace(")", "").replace("(", "");
        if (newQuery.indexOf(space) > -1) {
            param = newQuery.substring(1, newQuery.indexOf(space));
        }
        newQuery = newQuery.replace(":".concat(param), "");

        // get parameter type in annotations @Params and @QueryParameter
        String type = getType(param, hints);

        if (type == null) {
            final FieldDeclaration field = getField(clazz, param);
            if (field == null) {
                throw new VulpeSystemException(
                        "Parameter [".concat(param).concat("] not found on class: ").concat(dao.getName()));
            } else {
                if (param.equals("id")) {
                    unique = true;
                }
                type = field.getType().toString();
                // verified if is unique column or id
                if (!unique) {
                    final Column column = field.getAnnotation(Column.class);
                    if (column != null) {
                        unique = column.unique();
                    }
                    if (!unique) {
                        final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class);
                        if (field.getAnnotation(JoinColumn.class) != null) {
                            unique = joinColumn.unique();
                        }
                    }
                }
            }
        }

        final DecoratedDAOParameter parameter = new DecoratedDAOParameter();
        parameter.setName(param);
        parameter.setType(type);
        method.getParameters().add(parameter);
    }

    for (final QueryHint queryHint : hints) {
        if (queryHint.name().equals("limit")) {
            final DecoratedDAOParameter parameter = new DecoratedDAOParameter();
            parameter.setName("limit");
            parameter.setType("java.lang.Integer");
            parameter.setValue(Integer.valueOf(queryHint.value()));
            method.getParameters().add(0, parameter);
        }
    }
    setupReturn(dao, queryName, hints, method, unique);

    dao.getMethods().add(method);
}