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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:org.kuali.kra.award.web.struts.action.AwardPaymentReportsAndTermsAction.java

private int getAwardReportTermItemsIndex(HttpServletRequest request) {
    final String awardReportTermItemsIndexBase = "AwardReportTermItemsIndex";
    Map paramMap = request.getParameterMap();
    Iterator keys = paramMap.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next().toString();
        if (StringUtils.contains(key, awardReportTermItemsIndexBase)) {
            int startingSubStringIndex = StringUtils.indexOf(key, awardReportTermItemsIndexBase)
                    + awardReportTermItemsIndexBase.length();
            int endingSubStringIndex = key.length() - 2;
            String intValSubstring = key.substring(startingSubStringIndex, endingSubStringIndex);
            return Integer.valueOf(intValSubstring);
        }//from   w ww .j  ava  2 s  .  c o m
    }
    throw new IllegalArgumentException(
            awardReportTermItemsIndexBase + " was not found in the request, can't find the index.");
}

From source file:org.kuali.kra.external.Cfda.service.impl.CfdaServiceImpl.java

/**
 * This method gets the url from the parameter and creates the fileName and 
 * the actual URL used to FTP./*from   w  ww  . j  a v  a 2  s.co m*/
 */
protected void createGovURL() {
    // Example url ftp://ftp.cfda.gov/programs09187.csv
    String url = getParameterService().getParameterValueAsString(Constants.MODULE_NAMESPACE_AWARD,
            Constants.PARAMETER_COMPONENT_DOCUMENT, Constants.CFDA_GOV_URL_PARAMETER);
    String fileName = StringUtils.substringAfterLast(url, "/");
    url = StringUtils.substringBeforeLast(url, "/");

    if (StringUtils.contains(url, FTP_PREFIX)) {
        url = StringUtils.remove(url, FTP_PREFIX);
    }

    Calendar calendar = dateTimeService.getCurrentCalendar();
    // need to pull off the '20' in 2009
    String year = "" + calendar.get(Calendar.YEAR);
    year = year.substring(2, 4);
    fileName = fileName + year;

    // the last 3 numbers in the file name are the day of the year, but the files are from "yesterday"
    fileName = fileName + String.format("%03d", calendar.get(Calendar.DAY_OF_YEAR) - 1);
    fileName = fileName + ".csv";

    setGovURL(url);
    setCfdaFileName(fileName);
}

From source file:org.kuali.kra.protocol.specialreview.impl.ProtocolSpecialReviewServiceImplBase.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*from   w  w  w .j a  v a 2 s. c  o  m*/
public void populateSpecialReview(SpecialReview specialReview) {
    String protocolNumber = specialReview.getProtocolNumber();
    if (protocolNumber == null) {
        return;
    }
    String lastApprovedProtocolNumber = protocolNumber;

    if (StringUtils.contains(protocolNumber, AMENDMENT_KEY)) {
        lastApprovedProtocolNumber = StringUtils.substringBefore(protocolNumber, AMENDMENT_KEY);
    } else if (StringUtils.contains(protocolNumber, RENEWAL_KEY)) {
        lastApprovedProtocolNumber = StringUtils.substringBefore(protocolNumber, RENEWAL_KEY);
    }

    ProtocolBase protocol = getProtocolFinderDao().findCurrentProtocolByNumber(lastApprovedProtocolNumber);

    if (protocol != null) {
        setSpecialReviewApprovalTypeHook(specialReview);

        if (specialReview.getClass().equals(ProposalSpecialReview.class)) {
            ProposalSpecialReview psr = (ProposalSpecialReview) specialReview;
            DevelopmentProposal dp = getPropososalDevelopment(psr.getDevelopmentProposal().getProposalNumber());
            if (dp != null
                    && (StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.APPROVED_AND_SUBMITTED)
                            || StringUtils.equals(dp.getProposalStateTypeCode(), ProposalState.DISAPPROVED)
                            || StringUtils.equals(dp.getProposalStateTypeCode(),
                                    ProposalState.APPROVED_POST_SUBMISSION)
                            || StringUtils.equals(dp.getProposalStateTypeCode(),
                                    ProposalState.DISAPPROVED_POST_SUBMISSION)
                            || StringUtils.equals(dp.getProposalStateTypeCode(),
                                    ProposalState.APPROVAL_PENDING_SUBMITTED))
                    && specialReview.getProtocolStatus() != null) {
                // if the proposal is complete, do not get the fresh copy of the IRB status
            } else {
                specialReview.setProtocolStatus(protocol.getProtocolStatus().getDescription());
            }
        } else {
            specialReview.setProtocolStatus(protocol.getProtocolStatus().getDescription());
        }

        specialReview.setProtocolNumber(protocol.getProtocolNumber());
        specialReview.setApplicationDate(protocol.getProtocolSubmission().getSubmissionDate());
        specialReview.setApprovalDate(protocol.getLastApprovalDate() == null ? protocol.getApprovalDate()
                : protocol.getLastApprovalDate());
        specialReview.setExpirationDate(protocol.getExpirationDate());

        setProtocolExemptStudiesCheckListItemHook(protocol, specialReview);

        specialReview.setLinkedToProtocol(true);
    }

}

From source file:org.lockss.util.ObjectSerializerTester.java

/**
 * <p>Tests that the deserializer behaves appropriately for its
 * mode when deserialization fails.</p>
 * @throws Exception if an unexpected or unhandled problem arises.
 *//*from  w  w  w  .  j a  va  2  s  .  c  o m*/
public void testFailedDeserializationMode() throws Exception {

    // Define variant actions
    RememberFile[] actions = new RememberFile[] {
            // With a File
            new RememberFile() {
                public void doSomething(ObjectSerializer serializer) throws Exception {
                    serializer.deserialize(file);
                }
            },
            // With a String
            new RememberFile() {
                public void doSomething(ObjectSerializer serializer) throws Exception {
                    serializer.deserialize(file.toString());
                }
            }, };

    // For each variant action...
    for (int action = 0; action < actions.length; ++action) {
        logger.debug("Begin with action " + action);

        // For each type of deserializer...
        ObjectSerializer[] deserializers = getObjectSerializers_ExtMapBean();
        for (int deserializer = 0; deserializer < deserializers.length; ++deserializer) {
            logger.debug("Begin with deserializer " + deserializer);

            try {
                // Create a bad input file
                actions[action].file = File.createTempFile("testfile", ".xml");
                actions[action].file.deleteOnExit();
                FileWriter writer = new FileWriter(actions[action].file);
                writer.write("BAD INPUT");
                writer.close();

                // Perform variant action
                actions[action].doSomething(deserializers[deserializer]);
                fail("Should have thrown SerializationException (" + action + "," + deserializer + ")");
            } catch (SerializationException ignore) {
                // success; keep going
            }

            // Verify results
            switch (deserializers[deserializer].getFailedDeserializationMode()) {
            case ObjectSerializer.FAILED_DESERIALIZATION_COPY:
                File[] files = actions[action].file.getParentFile().listFiles();
                File copy = null;
                for (int file = 0; file < files.length; ++file) {
                    String candidate = files[file].toString();
                    if (!candidate.startsWith(actions[action].file.toString())) {
                        continue; // not the right file
                    }
                    if (!StringUtils.contains(candidate,
                            CurrentConfig.getParam(ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION,
                                    ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION))) {
                        continue; // not the right file
                    }
                    String timestamp = StringUtils.substringAfterLast(candidate, ".");
                    if (StringUtil.isNullString(timestamp)) {
                        continue; // not the right file
                    }
                    try {
                        long time = Long.parseLong(timestamp);
                    } catch (NumberFormatException nfe) {
                        continue; // not the right file
                    }
                    copy = files[file]; // right file found
                    break;
                }
                assertNotNull(
                        "FAILED_DESERIALIZATION_COPY: copy not found (" + action + "," + deserializer + ")",
                        copy);
                copy.deleteOnExit(); // clean up
                assertTrue("FAILED_DESERIALIZATION_COPY: copy does not match (" + action + "," + deserializer
                        + ")", FileUtil.isContentEqual(actions[action].file, copy));
                break;
            case ObjectSerializer.FAILED_DESERIALIZATION_IGNORE:
                // nothing; keep going
                break;
            case ObjectSerializer.FAILED_DESERIALIZATION_RENAME:
                File rename = new File(actions[action].file.toString()
                        + CurrentConfig.getParam(ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION,
                                ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION));
                assertTrue("FAILED_DESERIALIZATION_RENAME: renamed file did not exist (" + action + ","
                        + deserializer + ")", rename.exists());
                rename.deleteOnExit(); // clean up
                break;
            default: // shouldn't happen
                fail("Unexpected failed deserialization mode (" + action + "," + deserializer + ")");
                break;
            }
        }
    }

}

From source file:org.maodian.flyingcat.netty.handler.XMLFragmentDecoder.java

@Override
protected Object decode(ChannelHandlerContext ctx, String msg) throws Exception {
    if (StringUtils.endsWithAny(msg, INVALID_ELEMENT_TAILS)) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }/*ww  w  .ja v a2s.c o  m*/

    if (StringUtils.endsWith(msg, PROCESS_INSTRUCTION_TAIL) && !StringUtils.startsWith(msg, "<?xml ")) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }

    if (StringUtils.startsWithAny(msg, INVALID_ELEMENT_HEADS)) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }

    // always accept xml declaration to improve compability with some client
    if (StringUtils.startsWith(msg, "<?xml ")) {
        return msg;
        /*if (acceptXMLDeclaration) {
          acceptXMLDeclaration = false;
          return msg;
        } else {
          throw new XmppException("XML declaration has been already received before", StreamError.NOT_WELL_FORMED).set("xml", msg);
        }*/
    }

    // deal with stream tag
    if (StringUtils.contains(msg, ":stream")
            && (StringUtils.contains(msg, "<") || StringUtils.contains(msg, "</"))) {
        if (depth != 0) {
            throw new XmppException("Stream Open/Close Tag can only be root element", StreamError.INVALID_XML);
        }
        return msg;
    }

    // deal with empty element at first level
    if (depth == 0 && StringUtils.endsWith(msg, "/>")) {
        return msg;
    }

    if (xml == null) {
        xml = new StringBuilder(msg);
    } else {
        xml.append(msg);
    }

    // deal with nested empty element
    if (StringUtils.endsWith(msg, "/>")) {
        return null;
    }

    if (StringUtils.contains(msg, "</")) {
        depth--;
    } else if (StringUtils.contains(msg, "<")) {
        depth++;
    }

    if (depth == 0) {
        String fragment = xml.toString();
        xml = null;
        return fragment;
    }
    return null;
}

From source file:org.maodian.flyingcat.netty.handler.XmppXMLStreamHandler.java

@Override
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
    // discard xml declaration
    if (StringUtils.startsWith(msg, "<?xml ")) {
        return;/*from w  w w.j  a  v  a  2 s.co m*/
    }

    // deal with </stream:stream>
    if (StringUtils.contains(msg, ":stream") && StringUtils.contains(msg, "</")) {
        xmppContext.destroy();
        if (initCloseingStream) {
            log.info("Close Stream and underhood socket due to requested by server");
            ctx.channel().close();
        } else if (ctx.channel().isOpen()) {
            ctx.write("</stream:stream>").addListener(new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    log.info("Close Stream and underhood socket due to requested by client");
                    future.channel().close();
                }
            });
        } else {
            log.info(
                    "Won't respond client's close stream request since the channel has been closed (may because ssl has been closed)");
        }
        return;
    }

    xmppContext.parseXML(msg);
}

From source file:org.mortbay.jetty.load.generator.jenkins.result.LoadResultProjectAction.java

public static List<RunInformations> searchRunInformations(String jettyVersion, ElasticHost elasticHost,
        int maxResult) throws IOException {

    String originalJettyVersion = jettyVersion;

    // jettyVersion 9.4.9*
    //in case jettyVersion is 9.4.9.v20180320 we need to replace with 9.4.9*
    if (StringUtils.contains(jettyVersion, 'v')) {
        jettyVersion = StringUtils.substringBeforeLast(jettyVersion, ".v");
    }/*  w w  w.j  av a 2 s.  c o m*/
    // FIXME investigate elastic but query such 9.4.10-SNAPSHOT doesn't work...
    // so using 9.4.10* then filter response back....
    if (StringUtils.contains(jettyVersion, "-SNAPSHOT")) {
        jettyVersion = StringUtils.substringBeforeLast(jettyVersion, "-SNAPSHOT");
    }

    // in case of 9.4.11-NO-LOGGER-SNAPSHOT still not working with elastic
    // here we must have only number or . so remove everything else

    StringBuilder versionQuery = new StringBuilder();
    CharacterIterator ci = new StringCharacterIterator(jettyVersion);
    for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) {
        if (NumberUtils.isCreatable(Character.toString(c)) || c == '.') {
            versionQuery.append(c);
        }
    }

    jettyVersion = versionQuery.toString() + "*";

    try (ElasticResultStore elasticResultStore = elasticHost.buildElasticResultStore(); //
            InputStream inputStream = LoadResultProjectAction.class
                    .getResourceAsStream("/versionResult.json")) {
        String versionResultQuery = IOUtils.toString(inputStream);
        Map<String, String> map = new HashMap<>(1);
        map.put("jettyVersion", jettyVersion);
        map.put("maxResult", Integer.toString(maxResult));
        versionResultQuery = StrSubstitutor.replace(versionResultQuery, map);

        String results = elasticResultStore.search(versionResultQuery);

        List<LoadResult> loadResults = ElasticResultStore
                .map(new HttpContentResponse(null, results.getBytes(), null, null));

        List<RunInformations> runInformations = //
                loadResults.stream() //
                        .filter(loadResult -> StringUtils.equalsIgnoreCase(originalJettyVersion, //
                                loadResult.getServerInfo().getJettyVersion())) //
                        .map(loadResult -> new RunInformations(
                                loadResult.getServerInfo().getJettyVersion() + ":"
                                        + loadResult.getServerInfo().getGitHash(), //
                                loadResult.getCollectorInformations(),
                                StringUtils.lowerCase(loadResult.getTransport())) //
                                        .jettyVersion(loadResult.getServerInfo().getJettyVersion()) //
                                        .estimatedQps(LoadTestResultBuildAction.estimatedQps(
                                                LoadTestResultBuildAction.getLoaderConfig(loadResult))) //
                                        .serverInfo(loadResult.getServerInfo())) //
                        .collect(Collectors.toList());

        Collections.sort(runInformations, Comparator.comparing(o -> o.getStartTimeStamp()));
        return runInformations;
    }

}

From source file:org.neo4art.importer.wikipedia.util.WikipediaInfoboxUtils.java

/**
 * @param text/*from w  ww  . j  ava 2 s . c  o  m*/
 * @return
 */
public static boolean isArtist(String text) {
    return StringUtils.contains(text, "{{Infobox artist");
}

From source file:org.neo4art.importer.wikipedia.util.WikipediaInfoboxUtils.java

/**
 * @param text/*w ww .j  a va  2 s. co  m*/
 * @return
 */
public static boolean isArtwork(String text) {
    return StringUtils.contains(text, "{{Infobox artwork");
}

From source file:org.neo4art.importer.wikipedia.util.WikipediaInfoboxUtils.java

/**
 * @param text//from   w w w.j  a va2s.  co m
 * @return
 */
public static boolean isArtMovement(String text) {
    return StringUtils.contains(text, "{{Infobox art movement");
}