Java Code Examples for org.apache.commons.lang3.StringUtils#replaceIgnoreCase()

The following examples show how to use org.apache.commons.lang3.StringUtils#replaceIgnoreCase() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
String processRequestHeader(final int matchStartingPosition, final Request req, final String responseBody) {

        final String headerName = extractArgName(matchStartingPosition, ParamMatchTypeEnum.requestHeader, responseBody, false);
        final String headerValue = GeneralUtils.findHeaderIgnoreCase(req, sanitiseArgName(headerName));

        if (logger.isDebugEnabled()) {
            logger.debug("raw header: " + headerName);
            logger.debug("cleaned header: " + sanitiseArgName(headerName));
            logger.debug("header value: " + headerValue);
        }

        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.requestHeader + "(" + headerName + ")",
                (headerValue != null) ? headerValue : "",
                1);
    }
 
Example 2
String processRequestParameter(final int matchStartingPosition, final Request req, final String responseBody) {

        final String requestParamName = extractArgName(matchStartingPosition, ParamMatchTypeEnum.requestParameter, responseBody, false);
        final String requestParamValue = GeneralUtils.findRequestParamIgnoreCase(req, sanitiseArgName(requestParamName));

        if (logger.isDebugEnabled()) {
            logger.debug("RAW request param: " + requestParamName);
            logger.debug("Cleaned request param: " + sanitiseArgName(requestParamName));
            logger.debug("Request param value: " + requestParamValue);
        }

        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.requestParameter + "(" + requestParamName + ")",
                (requestParamValue != null) ? requestParamValue : "",
                1);

    }
 
Example 3
String processPathVariable(final String sanitizedUserCtxInboundPath, final int matchStartingPosition, final String mockPath, final String responseBody) {

        final String pathVariableName = extractArgName(matchStartingPosition, ParamMatchTypeEnum.pathVar, responseBody, false);
        final String pathVariableValue = GeneralUtils.findPathVarIgnoreCase(sanitizedUserCtxInboundPath, mockPath, sanitiseArgName(pathVariableName));

        if (logger.isDebugEnabled()) {
            logger.debug("RAW path var: " + pathVariableName);
            logger.debug("Cleaned path var : " + sanitiseArgName(pathVariableName));
            logger.debug("Path var value: " + pathVariableValue);
        }

        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.pathVar + "(" + pathVariableName + ")",
                (pathVariableValue != null) ? pathVariableValue : "",
                1);

    }
 
Example 4
@Test
public void givenTestStrings_whenStringUtilsMethods_thenProcessedStrings() {

    String master = "Hello World Baeldung!";
    String target = "Baeldung";
    String replacement = "Java";

    String processed = StringUtils.replace(master, target, replacement);
    assertTrue(processed.contains(replacement));

    String master2 = "Hello World Baeldung!";
    String target2 = "baeldung";
    String processed2 = StringUtils.replaceIgnoreCase(master2, target2, replacement);
    assertFalse(processed2.contains(target));

}
 
Example 5
String processRandomNumber(final int matchStartingPosition, final String responseBody) {

        final String randomNumberContent = extractArgName(matchStartingPosition, ParamMatchTypeEnum.randomNumber, responseBody, false);

        if (logger.isDebugEnabled()) {
            logger.debug("Random number params: " + randomNumberContent);
        }

        if (randomNumberContent == null) {
            throw new IllegalArgumentException(ParamMatchTypeEnum.randomNumber.name() + " is missing args");
        }

        final String[] randomNumberContentParams = StringUtils.split(randomNumberContent, ",");

        if (randomNumberContentParams.length == 0) {
            throw new IllegalArgumentException(ParamMatchTypeEnum.randomNumber.name() + " is missing args");
        }

        if (randomNumberContentParams.length > 2) {
            throw new IllegalArgumentException(ParamMatchTypeEnum.randomNumber.name() + " has too many args");
        }

        final int startInc = (randomNumberContentParams.length == 2) ? Integer.parseInt(randomNumberContentParams[0].trim()) : 0;
        final int endExcl = (randomNumberContentParams.length == 2) ? Integer.parseInt(randomNumberContentParams[1].trim()) : Integer.parseInt(randomNumberContentParams[0].trim());
        final int randomValue = RandomUtils.nextInt(startInc, endExcl);

        if (logger.isDebugEnabled()) {
            logger.debug("Random number value: " + randomValue);
        }

        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.randomNumber + "(" + randomNumberContent + ")",
                String.valueOf(randomValue),
                1);
    }
 
Example 6
Source Project: Insights   File: Neo4jDBImpl.java    License: Apache License 2.0 5 votes vote down vote up
protected String getNeo4jQueryWithDates(JobSchedule schedule, String neo4jQuery) {
	Long fromDate = InsightsUtils.getDataFromTime(schedule.name());
	Long toDate = InsightsUtils.getDataToTime(schedule.name());
	String whereClause = " WHERE n." + inferenceConfigDefinition.getStartTimeField() + " > " + fromDate + " AND n."
			+ inferenceConfigDefinition.getStartTimeField() + " < " + toDate;
	if (StringUtils.containsIgnoreCase(neo4jQuery, "WHERE")) {
		neo4jQuery = StringUtils.replaceIgnoreCase(neo4jQuery, "WHERE", whereClause + " AND ");
	} else if (StringUtils.containsIgnoreCase(neo4jQuery, "RETURN")
			&& !StringUtils.containsIgnoreCase(neo4jQuery, "WHERE")) {
		neo4jQuery = StringUtils.replaceIgnoreCase(neo4jQuery, "RETURN", whereClause + " RETURN  ");
	}
	return neo4jQuery;
}
 
Example 7
String processParamMatch(final Request req,
                         final String mockPath,
                         final String responseBody,
                         final String sanitizedUserCtxInboundPath,
                         final long mockOwnerUserId) {

    // Look up for any 'inbound param token' matches
    final Pair<ParamMatchTypeEnum, Integer> matchResult = findInboundParamMatch(responseBody);

    if (matchResult == null) {
        // No tokens found so do nothing.
        return null;
    }

    final ParamMatchTypeEnum paramMatchType = matchResult.getLeft();
    final int matchStartingPosition = matchResult.getRight();

    // Determine the matching token type, is it a requestHeader, requestParameter, pathVar, etc...
    if (ParamMatchTypeEnum.lookUpKvp.equals(paramMatchType)) {
        return processKvp(matchStartingPosition, sanitizedUserCtxInboundPath, mockPath, req, responseBody, mockOwnerUserId);
    }

    if (ParamMatchTypeEnum.requestHeader.equals(paramMatchType)) {
        return processRequestHeader(matchStartingPosition, req, responseBody);
    }

    if (ParamMatchTypeEnum.requestParameter.equals(paramMatchType)) {
        return processRequestParameter(matchStartingPosition, req, responseBody);
    }

    if (ParamMatchTypeEnum.pathVar.equals(paramMatchType)) {
        return processPathVariable(sanitizedUserCtxInboundPath, matchStartingPosition, mockPath, responseBody);
    }

    if (ParamMatchTypeEnum.requestBody.equals(paramMatchType)) {
        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.requestBody,
                (req.body() != null) ? req.body() : "",
                1);
    }

    if (ParamMatchTypeEnum.isoDate.equals(paramMatchType)) {
        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.isoDate,
                new SimpleDateFormat(GeneralUtils.ISO_DATE_FORMAT).format(GeneralUtils.getCurrentDate()),
                1);
    }

    if (ParamMatchTypeEnum.isoDatetime.equals(paramMatchType)) {
        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.isoDatetime,
                new SimpleDateFormat(GeneralUtils.ISO_DATETIME_FORMAT).format(GeneralUtils.getCurrentDate()),
                1);
    }

    if (ParamMatchTypeEnum.uuid.equals(paramMatchType)) {
        return StringUtils.replaceIgnoreCase(responseBody,
                ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.uuid,
                GeneralUtils.generateUUID(),
                1);
    }

    if (ParamMatchTypeEnum.randomNumber.equals(paramMatchType)) {
        return processRandomNumber(matchStartingPosition, responseBody);
    }

    throw new IllegalArgumentException("Unsupported token : " + matchResult);
}
 
Example 8
String processKvp(final int matchStartingPosition,
                  final String sanitizedUserCtxInboundPath,
                  final String mockPath,
                  final Request req,
                  final String responseBody,
                  final long mockOwnerUserId) {

    // Determine the matching token type, is it a requestHeader, requestParameter, pathVar, etc...

    final String kvpKey = extractArgName(matchStartingPosition, ParamMatchTypeEnum.lookUpKvp, responseBody, false);
    String sanitisedKvpKey = sanitiseArgName(kvpKey);

    if (sanitisedKvpKey.contains("(") && !sanitisedKvpKey.contains(")")) {
        sanitisedKvpKey = sanitisedKvpKey.concat(")");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("RAW KVP: " + kvpKey);
        logger.debug("Cleaned KVP : " + sanitisedKvpKey);
    }

    // Check if kvpKey is a nested ParamMatchTypeEnum itself
    final Pair<ParamMatchTypeEnum, Integer> kvpMatchResult = findInboundParamMatch(sanitisedKvpKey);
    final boolean isNested = (kvpMatchResult != null);

    if (isNested) {

        if (logger.isDebugEnabled()) {
            logger.debug("Nested KVP request type: " + kvpMatchResult.getLeft());
        }

        final String nestedRequestKey = extractArgName(kvpMatchResult.getRight(), kvpMatchResult.getLeft(), sanitisedKvpKey, isNested);

        if (logger.isDebugEnabled()) {
            logger.debug("Nested KVP request key: " + nestedRequestKey);
        }

        switch (kvpMatchResult.getLeft()) {
            case requestHeader:
                sanitisedKvpKey = GeneralUtils.findHeaderIgnoreCase(req, sanitiseArgName(nestedRequestKey));
                break;
            case requestParameter:
                sanitisedKvpKey = GeneralUtils.findRequestParamIgnoreCase(req, sanitiseArgName(nestedRequestKey));
                break;
            case pathVar:
                sanitisedKvpKey = GeneralUtils.findPathVarIgnoreCase(sanitizedUserCtxInboundPath, mockPath, sanitiseArgName(nestedRequestKey));
                break;
            case requestBody:
                sanitisedKvpKey = req.body();
                break;
            default:
                sanitisedKvpKey = null;
                break;
        }
    }

    final UserKeyValueDataDTO userKeyValueDataDTO = (sanitisedKvpKey != null)
            ? userKeyValueDataService.loadByKey(sanitisedKvpKey, mockOwnerUserId)
            : null;

    if (logger.isDebugEnabled()) {
        logger.debug("KVP value: " + ((userKeyValueDataDTO != null) ? userKeyValueDataDTO.getValue() : null));
    }

    return StringUtils.replaceIgnoreCase(responseBody,
            ParamMatchTypeEnum.PARAM_PREFIX + ParamMatchTypeEnum.lookUpKvp + "(" + kvpKey + ((kvpKey.contains("(")) ? "))" : ")"),
            (userKeyValueDataDTO != null) ? userKeyValueDataDTO.getValue() : "",
            1);
}
 
Example 9
Source Project: yarg   File: AbstractInliner.java    License: Apache License 2.0 4 votes vote down vote up
private void putImage(WorksheetPart worksheetPart, SpreadsheetMLPackage pkg, BinaryPartAbstractImage imagePart, CTOneCellAnchor anchor) throws Docx4JException {
    PartName drawingPart = new PartName(StringUtils.replaceIgnoreCase(worksheetPart.getPartName().getName(),
            "worksheets/sheet", "drawings/drawing"));
    String imagePartName = imagePart.getPartName().getName();
    Part part = pkg.getParts().get(drawingPart);
    if (part != null && !(part instanceof Drawing))
        throw new ReportFormattingException("Wrong Class: not a Drawing");
    Drawing drawing = (Drawing) part;
    int currentId = 0;
    if (drawing == null) {
        drawing = new Drawing(drawingPart);
        drawing.setContents(new org.docx4j.dml.spreadsheetdrawing.CTDrawing());
        Relationship relationship = worksheetPart.addTargetPart(drawing);
        org.xlsx4j.sml.CTDrawing smlDrawing = new org.xlsx4j.sml.CTDrawing();
        smlDrawing.setId(relationship.getId());
        smlDrawing.setParent(worksheetPart.getContents());
        worksheetPart.getContents().setDrawing(smlDrawing);
    } else {
        currentId = drawing.getContents().getEGAnchor().size();
    }

    CTPicture picture = new CTPicture();

    CTBlipFillProperties blipFillProperties = new CTBlipFillProperties();
    blipFillProperties.setStretch(new CTStretchInfoProperties());
    blipFillProperties.getStretch().setFillRect(new CTRelativeRect());
    blipFillProperties.setBlip(new CTBlip());
    blipFillProperties.getBlip().setEmbed("rId" + (currentId + 1));
    blipFillProperties.getBlip().setCstate(STBlipCompression.PRINT);

    picture.setBlipFill(blipFillProperties);

    CTNonVisualDrawingProps nonVisualDrawingProps = new CTNonVisualDrawingProps();
    nonVisualDrawingProps.setId(currentId + 2);
    nonVisualDrawingProps.setName(imagePartName.substring(imagePartName.lastIndexOf("/") + 1));
    nonVisualDrawingProps.setDescr(nonVisualDrawingProps.getName());

    CTNonVisualPictureProperties nonVisualPictureProperties = new CTNonVisualPictureProperties();
    nonVisualPictureProperties.setPicLocks(new CTPictureLocking());
    nonVisualPictureProperties.getPicLocks().setNoChangeAspect(true);
    CTPictureNonVisual nonVisualPicture = new CTPictureNonVisual();

    nonVisualPicture.setCNvPr(nonVisualDrawingProps);
    nonVisualPicture.setCNvPicPr(nonVisualPictureProperties);

    picture.setNvPicPr(nonVisualPicture);

    CTShapeProperties shapeProperties = new CTShapeProperties();
    CTTransform2D transform2D = new CTTransform2D();
    transform2D.setOff(new CTPoint2D());
    transform2D.setExt(new CTPositiveSize2D());
    shapeProperties.setXfrm(transform2D);
    shapeProperties.setPrstGeom(new CTPresetGeometry2D());
    shapeProperties.getPrstGeom().setPrst(STShapeType.RECT);
    shapeProperties.getPrstGeom().setAvLst(new CTGeomGuideList());

    picture.setSpPr(shapeProperties);

    anchor.setPic(picture);
    anchor.setClientData(new CTAnchorClientData());

    drawing.getContents().getEGAnchor().add(anchor);

    Relationship rel = new Relationship();
    rel.setId("rId" + (currentId + 1));
    rel.setType(Namespaces.IMAGE);
    rel.setTarget(imagePartName);

    drawing.getRelationshipsPart().addRelationship(rel);
    RelationshipsPart relPart = drawing.getRelationshipsPart();
    pkg.getParts().remove(relPart.getPartName());
    pkg.getParts().put(relPart);
    pkg.getParts().remove(drawing.getPartName());
    pkg.getParts().put(drawing);
}