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

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

Introduction

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

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:com.microsoft.alm.common.utils.UrlHelper.java

public static boolean isSshGitRemoteUrl(final String gitRemoteUrl) {
    if (isGitRemoteUrl(gitRemoteUrl) && isTeamServicesUrl(gitRemoteUrl)) {
        if (StringUtils.startsWithIgnoreCase(gitRemoteUrl, "https://")
                || StringUtils.startsWithIgnoreCase(gitRemoteUrl, "http://")) {
            return false;
        }//www  .  j a  va2  s.  c o m

        if (StringUtils.startsWithIgnoreCase(gitRemoteUrl, "ssh://")) {
            return true;
        }

        // check for @ in url - team project name, repo name, collection name and account name don't allow @
        // E.g of valid url formats:
        // ssh://account@account.visualstudio.com:22/Collection/_git/Repo
        // account@account.visualstudio.com:22/Collection/_git/Repo
        if (StringUtils.contains(gitRemoteUrl, "@")) {
            return true;
        }
    }
    return false;
}

From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java

/**
 * @param model/*from   w  w w .  j a v a2s  . c o  m*/
 * @return
 * @throws Exception
 */
public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception {
    // Find a Sans Serif Font on the System
    String fontName = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (java.awt.Font font : ge.getAllFonts()) {

        String fName = font.getFamily().toLowerCase();
        if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial")
                || StringUtils.contains(fName, "verdana")) {
            fontName = font.getFamily();
            break;
        }
    }

    if (fontName == null) {
        fontName = Font._FONT_TIMES_NEW_ROMAN;
    }

    /**
     * Creates the DynamicReportBuilder and sets the basic options for the report
     */
    FastReportBuilder drb = new FastReportBuilder();

    Style columDetail = new Style();
    //columDetail.setBorder(Border.THIN);

    Style columDetailWhite = new Style();
    //columDetailWhite.setBorder(Border.THIN);
    columDetailWhite.setBackgroundColor(Color.WHITE);
    columDetailWhite.setFont(new Font(10, fontName, false));
    columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER);
    columDetailWhite.setBlankWhenNull(true);

    Style columDetailWhiteBold = new Style();
    //columDetailWhiteBold.setBorder(Border.THIN);
    columDetailWhiteBold.setBackgroundColor(Color.WHITE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(12, fontName, true));

    // Odd Row Style
    Style oddRowStyle = new Style();
    //oddRowStyle.setBorder(Border.NO_BORDER);
    oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER);

    Color veryLightGrey = new Color(240, 240, 240);
    oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    // Create Column Headers for the Report
    for (int i = 0; i < model.getColumnCount(); i++) {
        String colName = model.getColumnName(i);

        Class<?> dataClass = model.getColumnClass(i);
        if (dataClass == Object.class) {
            if (model.getRowCount() > 0) {
                Object data = model.getValueAt(0, i);
                if (data != null) {
                    dataClass = data.getClass();
                } else {
                    // Column in first row was null so search down the rows
                    // for a non-empty cell
                    for (int j = 1; j < model.getRowCount(); j++) {
                        data = model.getValueAt(j, i);
                        if (dataClass != null) {
                            dataClass = data.getClass();
                            break;
                        }
                    }

                    if (dataClass == null) {
                        dataClass = String.class;
                    }
                }
            }
        }

        ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName());
        int bracketInx = colName.indexOf('[');
        if (bracketInx > -1) {
            colName = colName.substring(0, bracketInx - 1);
        }
        colBldr.setTitle(colName);

        colBldr.setStyle(columDetailWhite);

        AbstractColumn column = colBldr.build();
        drb.addColumn(column);

        Style headerStyle = new Style();
        headerStyle.setFont(new Font(11, fontName, true));
        //headerStyle.setBorder(Border.THIN);
        headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
        headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
        headerStyle.setBackgroundColor(new Color(80, 80, 80));
        headerStyle.setTransparency(Transparency.OPAQUE);
        headerStyle.setTextColor(new Color(255, 255, 255));
        column.setHeaderStyle(headerStyle);
    }

    drb.setTitle(pageSetupDlg.getPageTitle());
    drb.setTitleStyle(titleStyle);

    drb.setLeftMargin(20);
    drb.setRightMargin(20);
    drb.setTopMargin(10);
    drb.setBottomMargin(10);

    drb.setPrintBackgroundOnOddRows(true);
    drb.setOddRowBackgroundStyle(oddRowStyle);
    drb.setColumnsPerPage(new Integer(1));
    drb.setUseFullPageWidth(true);
    drb.setColumnSpace(new Integer(5));

    // This next line causes an exception
    // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3
    //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER);

    Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(),
            Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(),
            Page.Page_A4_Landscape() };
    int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3);
    drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]);

    DynamicReport dr = drb.build();

    return dr;
}

From source file:com.haulmont.cuba.core.UniqueNumbersTest.java

@Test
public void testConcurrentModification() throws Exception {
    int threadCnt = 8;
    ExecutorService executorService = Executors.newFixedThreadPool(threadCnt,
            new ThreadFactoryBuilder().setNameFormat("T%d").build());

    final Action[] actions = { new SleepAction(), new GetNumberAction(), new SetNumberAction(),
            new DeleteSequenceAction() };

    for (int i = 0; i < threadCnt; i++) {
        final int finalI = i;
        executorService.submit(new Runnable() {

            int runnableNo = finalI;

            @Override/*from w  w w. j av a  2s .  com*/
            public void run() {
                ThreadLocalRandom random = ThreadLocalRandom.current();
                for (int i = 0; i < 10; i++) {
                    int action = random.nextInt(0, 4);
                    System.out.println(
                            "Runnable " + runnableNo + " iteration " + i + " action " + actions[action]);
                    try {
                        int seqN = actions[action].perform(runnableNo);
                        actions[action].success(runnableNo, seqN);
                    } catch (Exception e) {
                        if (e instanceof IllegalStateException
                                && StringUtils.contains(e.getMessage(), "Attempt to delete")) {
                            System.err.println(e.getMessage());
                            continue;
                        }
                        System.err.println(e.getMessage());
                        exceptionCnt.incrementAndGet();
                    }
                }
                finishedThreads.incrementAndGet();
            }
        });
    }

    while (finishedThreads.get() < threadCnt) {
        System.out.println("Waiting...");
        TimeUnit.MILLISECONDS.sleep(200);
    }

    assertEquals(exceptionCnt.get(), 0);
}

From source file:cec.easyshop.storefront.controllers.pages.LoginPageController.java

protected void storeReferer(final String referer, final HttpServletRequest request,
        final HttpServletResponse response) {
    if (StringUtils.isNotBlank(referer) && !StringUtils.endsWith(referer, "/login")
            && StringUtils.contains(referer, request.getServerName())) {
        httpSessionRequestCache.saveRequest(request, response);
    }//from w ww  .j a va2  s  .co m
}

From source file:com.microsoft.alm.plugin.external.commands.SyncCommand.java

/**
 * Example output from TF Get:/*from   w  w  w.  j a v  a2  s. c  o m*/
 * D:\tmp\test:
 * Getting addFold
 * Getting addFold-branch
 * <p/>
 * D:\tmp\test\addFold-branch:
 * Getting testHereRename.txt
 * <p/>
 * D:\tmp\test\addFold:
 * Getting testHere3
 * Getting testHereRename7.txt
 * <p/>
 * D:\tmp\test:
 * Getting Rename2.txt
 * Getting test3.txt
 * Conflict test_renamed.txt - Unable to perform the get operation because you have a conflicting rename, edit
 * Getting TestAdd.txt
 * <p/>
 * ---- Summary: 1 conflicts, 0 warnings, 0 errors ----
 * Conflict D:\tmp\test\test_renamed.txt - Unable to perform the get operation because you have a conflicting rename, edit
 *
 * @param stdout
 * @param stderr
 * @return
 */
@Override
public SyncResults parseOutput(final String stdout, final String stderr) {
    final List<String> updatedFiles = new ArrayList<String>();
    final List<String> newFiles = new ArrayList<String>();
    final List<String> deletedFiles = new ArrayList<String>();
    final List<SyncException> exceptions = new ArrayList<SyncException>();

    if (StringUtils.contains(stdout, UP_TO_DATE_MSG)) {
        return new SyncResults();
    }

    // make note that conflicts exist but to get conflicts use resolve command
    final boolean conflictsExist = StringUtils.contains(stderr, CONFLICT_MESSAGE);

    // parse the exception to get individual exceptions instead of 1 large one
    exceptions.addAll(parseException(stderr));

    // parse output for file changes
    final String[] lines = getLines(stdout);
    String path = StringUtils.EMPTY;
    for (final String line : lines) {
        if (StringUtils.isNotEmpty(line) || StringUtils.startsWith(line, SUMMARY_PREFIX)) {
            if (isFilePath(line)) {
                path = getFilePath(line, StringUtils.EMPTY, StringUtils.EMPTY);
            } else if (StringUtils.startsWith(line, NEW_FILE_PREFIX)) {
                newFiles.add((new File(path, line.replaceFirst(NEW_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else if (StringUtils.startsWith(line, UPDATED_FILE_PREFIX)) {
                updatedFiles.add(
                        (new File(path, line.replaceFirst(UPDATED_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else if (StringUtils.startsWith(line, DELETED_FILE_PREFIX)) {
                deletedFiles.add(
                        (new File(path, line.replaceFirst(DELETED_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else {
                // TODO: check for other cases to cover here but no need to hinder user if case not covered
                logger.warn("Unknown response from 'tf get' command: " + line);
            }
        }
    }

    return new SyncResults(conflictsExist, updatedFiles, newFiles, deletedFiles, exceptions);
}

From source file:com.ewcms.content.resource.service.ResourceService.java

/**
 * ???// w w w .  ja  v a  2  s  . co m
 * 
 * @param name ??
 * @return
 */
String getSuffix(String name) {
    if (StringUtils.contains(name, ".")) {
        return StringUtils.substringAfterLast(name, ".");
    } else {
        return "";
    }
}

From source file:com.adobe.acs.livereload.impl.JavaScriptInjectionFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (!(servletRequest instanceof SlingHttpServletRequest)
            || !(servletResponse instanceof SlingHttpServletResponse)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;/*from   ww w.  j a  v a2  s.  c o  m*/
    }

    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

    if (!this.accepts(slingRequest)) {
        filterChain.doFilter(slingRequest, slingResponse);
        return;
    }

    final BufferingResponse capturedResponse = new BufferingResponse(slingResponse);

    filterChain.doFilter(slingRequest, capturedResponse);

    // Get contents
    final String contents = capturedResponse.getContents();

    if (contents != null) {
        if (StringUtils.contains(slingResponse.getContentType(), "html")) {

            final int bodyIndex = contents.indexOf("</body>");
            if (bodyIndex != -1) {

                final PrintWriter printWriter = slingResponse.getWriter();

                printWriter.write(contents.substring(0, bodyIndex));
                printWriter.write(String.format(
                        "<script type=\"text/javascript\" src=\"http://%s:%s/livereload.js\"></script>",
                        slingRequest.getServerName(), port));
                printWriter.write(contents.substring(bodyIndex));
                return;
            }
        }
    }

    if (contents != null) {
        slingResponse.getWriter().write(contents);
    }

}

From source file:com.hangum.tadpole.sql.util.sqlscripts.scripts.PostgreSQLDDLScript.java

@Override
public String getTableScript(TableDAO tableDAO) throws Exception {
    SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
    List<HashMap> srcList = client.queryForList("getTableScript", tableDAO.getName());

    StringBuilder result = new StringBuilder("");
    result.append("/* DROP TABLE " + tableDAO.getName() + " ; */ \n\n");
    result.append("CREATE TABLE " + tableDAO.getName() + "( \n");
    for (int i = 0; i < srcList.size(); i++) {
        HashMap<String, Object> source = srcList.get(i);

        result.append("\t");
        if (i > 0)
            result.append(",");
        result.append(source.get("column_name")).append(" ");
        result.append(source.get("data_type"));

        if (source.get("data_precision") != null && ((Integer) source.get("data_precision") > 0)) {
            result.append("(" + source.get("data_precision"));
            if (source.get("data_scale") != null && ((Integer) source.get("data_scale") > 0)) {
                result.append("," + source.get("data_scale"));
            }//w w  w . ja  va 2s . co m

            result.append(")");
        } else if ((Integer) source.get("data_length") > 0) {
            result.append("(" + source.get("data_length") + ")");
        } else {
            result.append(" ");
        }

        if (source.get("data_default") != null && !"NULL".equals(source.get("nullable"))) {
            if (StringUtils.contains((String) source.get("data_type"), "text")) {
                result.append(" DEFAULT '" + source.get("data_default") + "'");
            } else {
                result.append(" DEFAULT " + source.get("data_default"));
            }
        }

        if (!"NULL".equals(source.get("nullable"))) {
            result.append(" NOT NULL ");
        }
        result.append("\n");
    }
    result.append(");\n");

    // table, column comments
    result.append("\n\n");
    List<String> srcCommentList = client.queryForList("getTableScript.comments", tableDAO.getName());
    for (int i = 0; i < srcCommentList.size(); i++) {
        result.append(srcCommentList.get(i) + ";\n");
    }

    // foreign key

    // column constraint (? ?  )

    // partition table define

    // storage option

    // iot_type table define

    // table grant

    // table trigger

    // table synonyms

    return result.toString();
}

From source file:com.gewara.web.support.OpenMemberAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    Assert.isInstanceOf(OpenMemberAuthenticationToken.class, authentication,
            "OpenMemberAuthenticationProvider only supports OpenMemberAuthenticationToken");
    OpenMemberAuthenticationToken auth = (OpenMemberAuthenticationToken) authentication;
    Member member = daoService.getObject(Member.class, auth.getMemberid());
    if (StringUtils.equals(auth.getSource(), MemberConstant.SOURCE_DYNCODE)) {
        if (!StringUtils.equals(member.getMobile(), auth.getIdentity())
                || !ValidateUtil.isMobile(auth.getIdentity())) {
            dbLogger.warn("" + auth.getIdentity());
            throw new IllegalArgumentException("!");
        }/*from   w  ww  .ja va  2s  . co m*/
    } else {
        MemberInfo info = daoService.getObject(MemberInfo.class, auth.getMemberid());
        String mSource = VmUtils.getJsonValueByKey(info.getOtherinfo(), "openMember");
        if (!StringUtils.contains(mSource, auth.getSource())) {
            //TODO:openMember
            //if(!StringUtils.equals(mSource, auth.getSource())){
            dbLogger.warn("" + auth.getSource() + ", memberid=" + auth.getMemberid());
            throw new IllegalArgumentException("");
        }
    }
    Assert.notNull(member, "");
    preAuthenticationChecks.check(member);
    postAuthenticationChecks.check(member);
    Assert.notNull(member, "");
    return createSuccessAuthentication(auth, member);
}

From source file:com.googlecode.jtiger.modules.ecside.core.TableModelUtils.java

/**
 * Determine whether or not this is a resource bundle key. It is a resource
 * bundle key if the value has a '.' character in it.
 * /* w  ww.ja  va2 s.  c  o  m*/
 * @param value The value that will be inspected to find out if resource key
 * @return True if this is a resource bundle key
 */
public static boolean isResourceBundleProperty(String value) {
    if (StringUtils.contains(value, ".")) {
        return true;
    }

    return false;
}