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

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

Introduction

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

Prototype

public static String trimToNull(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .

Usage

From source file:com.hubrick.vertx.s3.client.S3Client.java

public void putObjectAcl(String bucket, String key, PutObjectAclRequest putObjectAclRequest,
        Handler<Response<CommonResponseHeaders, Void>> handler, Handler<Throwable> exceptionHandler) {
    checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null");
    checkNotNull(StringUtils.trimToNull(key), "key must not be null");
    checkNotNull(putObjectAclRequest, "putObjectAclRequest must not be null");
    checkNotNull(handler, "handler must not be null");
    checkNotNull(exceptionHandler, "exceptionHandler must not be null");

    final S3ClientRequest request = createPutAclRequest(bucket, key,
            Optional.ofNullable(putObjectAclRequest.getAclHeadersRequest()),
            new HeadersResponseHandler("putObjectAcl", jaxbUnmarshaller, new PutResponseHeadersMapper(),
                    handler, exceptionHandler, false));
    request.exceptionHandler(exceptionHandler);

    if (putObjectAclRequest.getAccessControlPolicy() != null) {
        try {// w  w w  .ja  v a 2  s.c om
            final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            jaxbMarshaller.marshal(putObjectAclRequest.getAccessControlPolicy(), outputStream);
            request.putHeader(Headers.CONTENT_TYPE, "application/xml");
            request.end(Buffer.buffer(outputStream.toByteArray()));
        } catch (JAXBException e) {
            exceptionHandler.handle(e);
        }
    } else {
        request.end();
    }
}

From source file:com.blackducksoftware.integration.hub.builder.HubServerConfigBuilder.java

public void setHubUrl(final String hubUrl) {
    this.hubUrl = StringUtils.trimToNull(hubUrl);
}

From source file:com.blackducksoftware.integration.hub.builder.HubScanJobConfigBuilder.java

public void setProjectName(final String projectName) {
    this.projectName = StringUtils.trimToNull(projectName);
}

From source file:com.blackducksoftware.integration.hub.builder.HubScanJobConfigBuilder.java

public void setVersion(final String version) {
    this.version = StringUtils.trimToNull(version);
}

From source file:alfio.manager.NotificationManager.java

public Pair<Integer, List<LightweightMailMessage>> loadAllMessagesForEvent(int eventId, Integer page,
        String search) {//from  w w w  .  j a v  a 2  s.c  o  m
    final int pageSize = 50;
    int offset = page == null ? 0 : page * pageSize;
    String toSearch = StringUtils.trimToNull(search);
    toSearch = toSearch == null ? null : ("%" + toSearch + "%");
    return Pair.of(emailMessageRepository.countFindByEventId(eventId, toSearch),
            emailMessageRepository.findByEventId(eventId, offset, pageSize, toSearch));
}

From source file:hoot.services.writers.review.ReviewedItemsWriter.java

private void addUpdatedOsmRecord(final long reviewedItemOsmId, final ElementType reviewedItemOsmType,
        final String reviewedAgainstItemUniqueId, final boolean isDuplicate) throws Exception {
    Set<Long> elementIds = new HashSet<Long>();
    elementIds.add(reviewedItemOsmId);//  ww w.j a va 2 s .c  om
    //final Element prototype = ElementFactory.getInstance().create(reviewedItemOsmType, conn);
    //there should just either be one record returned here, or none at all, if the client has
    //already deleted the feature
    List<?> reviewedElementRecords = Element.getElementRecords(mapId, reviewedItemOsmType, elementIds, conn);
    if (reviewedElementRecords != null && reviewedElementRecords.size() != 0
            && reviewedElementRecords.get(0) != null) {
        Object reviewedElementRecord = reviewedElementRecords.get(0);
        boolean tagChanged = false;
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(
                (PGobject) MethodUtils.invokeMethod(reviewedElementRecord, "getTags", new Object[] {}));

        if (tags.containsKey("uuid")) {
            String uuid = tags.get("uuid");
            if (!isDuplicate && !uuid.contains(reviewedAgainstItemUniqueId)) {
                //update the reviewed item's osm element's uuid tag; append
                uuid += ";" + reviewedAgainstItemUniqueId;
                tags.put("uuid", uuid);
                tagChanged = true;
            }
        } else {
            log.warn("uuid tag removed from reviewed element with ID: " + reviewedItemOsmId + " and type: "
                    + reviewedItemOsmType);
        }

        if (tags.containsKey("uuid")) {
            String reviewAgainstUuids = tags.get("hoot:review:uuid");
            if (StringUtils.trimToNull(reviewAgainstUuids) == null) {
                reviewAgainstUuids = "";
            }
            if (reviewAgainstUuids.contains(reviewedAgainstItemUniqueId)) {
                //update the reviewed item's osm element's hoot:review:uuid tag; remove
                String reviewedAgainstItemUniqueIdReplaceStr = "\\{"
                        + reviewedAgainstItemUniqueId.replaceAll("\\{", "").replaceAll("\\}", "") + "\\}";
                reviewAgainstUuids = reviewAgainstUuids
                        .replaceAll(reviewedAgainstItemUniqueIdReplaceStr + ";", "")
                        .replaceAll(reviewedAgainstItemUniqueIdReplaceStr, "");
                if (!isDuplicate && StringUtils.trimToNull(reviewAgainstUuids) != null
                        && StringUtils.trimToNull(reviewAgainstUuids) != ";") {
                    tags.put("hoot:review:uuid", reviewAgainstUuids);
                    log.debug("Updated hoot:review:uuid tag to: " + reviewAgainstUuids);
                } else {
                    //nothing else to review against, so remove all review tags on the reviewed item
                    List<String> reviewTagKeys = new ArrayList<String>();
                    for (Map.Entry<String, String> tagEntry : tags.entrySet()) {
                        if (tagEntry.getKey().contains("hoot:review")) {
                            reviewTagKeys.add(tagEntry.getKey());
                        }
                    }
                    for (String reviewTagKey : reviewTagKeys) {
                        tags.remove(reviewTagKey);
                        log.debug("Removed review tag: " + reviewTagKey);
                    }
                }
                tagChanged = true;
            }
        } else {
            log.warn("hoot:review:uuid tag removed from reviewed element with ID: " + reviewedItemOsmId
                    + " and type: " + reviewedItemOsmType);
        }

        if (tagChanged) {
            Element reviewedElement = ElementFactory.getInstance().create(mapId, reviewedItemOsmType,
                    reviewedItemOsmId, conn);
            reviewedElement.setVersion(reviewedElement.getVersion() + 1);
            reviewedElement.setTags(tags);
            if (osmRecordsToUpdate.get(reviewedItemOsmType) == null) {
                osmRecordsToUpdate.put(reviewedItemOsmType, new ArrayList<Object>());
            }
            osmRecordsToUpdate.get(reviewedItemOsmType).add(reviewedElement.getRecord());
            log.debug("Added OSM record with ID: " + reviewedItemOsmId + " and type: " + reviewedItemOsmType
                    + " to collection for updating.");
            //          log.debug("updated tags: ");
            //          for (Map.Entry<String, String> tagEntry : reviewedElement.getTags().entrySet())
            //          {
            //            if(tagEntry.getKey().contains("hoot:review"))
            //            {
            //              log.debug("key: " + tagEntry.getKey() + " value: " + tagEntry.getValue());
            //            }
            //          }
        }
    } else {
        log.warn("No OSM feature exists for reviewed item with ID: " + reviewedItemOsmId + " type: "
                + reviewedItemOsmType + " and review against ID: " + reviewedAgainstItemUniqueId);
    }
}

From source file:alfio.manager.TicketReservationManager.java

public Pair<List<TicketReservation>, Integer> findAllReservationsInEvent(int eventId, Integer page,
        String search, List<TicketReservationStatus> status) {
    final int pageSize = 50;
    int offset = page == null ? 0 : page * pageSize;
    String toSearch = StringUtils.trimToNull(search);
    toSearch = toSearch == null ? null : ("%" + toSearch + "%");
    List<String> toFilter = (status == null || status.isEmpty()
            ? Arrays.asList(TicketReservationStatus.values())
            : status).stream().map(TicketReservationStatus::toString).collect(toList());
    return Pair.of(
            ticketReservationRepository.findAllReservationsInEvent(eventId, offset, pageSize, toSearch,
                    toFilter),/*w w w.j a  va 2 s.  co  m*/
            ticketReservationRepository.countAllReservationsInEvent(eventId, toSearch, toFilter));
}

From source file:me.mayo.telnetkek.MainPanel.java

public final ServerEntry saveServers() {
    final Object selectedItem = txtServer.getSelectedItem();
    if (selectedItem == null) {
        return null;
    }/*from w  w w  .j  a va 2 s  .  c  om*/

    ServerEntry entry;
    if (selectedItem instanceof ServerEntry) {
        entry = (ServerEntry) selectedItem;
    } else {
        final String serverAddress = StringUtils.trimToNull(selectedItem.toString());
        if (serverAddress == null) {
            return null;
        }

        String serverName = JOptionPane.showInputDialog(this, "Enter server name:", "Server Name",
                JOptionPane.PLAIN_MESSAGE);
        if (serverName == null) {
            return null;
        }

        serverName = StringUtils.trimToEmpty(serverName);
        if (serverName.isEmpty()) {
            serverName = "Unnamed";
        }

        entry = new ServerEntry(serverName, serverAddress);

        TelnetKek.config.getServers().add(entry);
    }

    TelnetKek.config.save();
    return entry;
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

/**
 * Adaptively upload a file to S3 and take away the burden to choose between direct or multipart upload.
 * Since the minimum size of the multipart part has to be 5MB this method handles the upload automatically.
 * It either chooses between the direct upload if the stream contains less then 5MB or the multipart upload
 * if the stream is bigger then 5MB.//from   ww  w  .  j  a v a  2s . c  o m
 *
 * @param bucket                The bucket
 * @param key                   The key of the final file
 * @param adaptiveUploadRequest The request
 * @param handler               Success handler
 * @param exceptionHandler      Exception handler
 */
public void adaptiveUpload(String bucket, String key, AdaptiveUploadRequest adaptiveUploadRequest,
        Handler<Response<CommonResponseHeaders, Void>> handler, Handler<Throwable> exceptionHandler) {
    checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null");
    checkNotNull(StringUtils.trimToNull(key), "key must not be null");
    checkNotNull(adaptiveUploadRequest, "adaptiveUploadRequest must not be null");
    checkNotNull(handler, "handler must not be null");
    checkNotNull(exceptionHandler, "exceptionHandler must not be null");

    final ChunkedBufferReadStream chunkedBufferReadStream = new ChunkedBufferReadStream(vertx,
            adaptiveUploadRequest.getReadStream(), FIVE_MB_IN_BYTES);
    chunkedBufferReadStream.exceptionHandler(throwable -> exceptionHandler.handle(throwable));
    chunkedBufferReadStream.setChunkHandler(chunk -> {
        if (chunkedBufferReadStream.numberOfChunks() == 0) {
            if (chunk.length() < FIVE_MB_IN_BYTES) {
                final Buffer buffer = Buffer.buffer();
                chunkedBufferReadStream.handler(buffer::appendBuffer);
                chunkedBufferReadStream.endHandler(aVoid -> {
                    putObject(bucket, key,
                            mapAdaptiveUploadRequestToPutObjectRequest(buffer, adaptiveUploadRequest),
                            event -> handler.handle(new HeaderOnlyResponse(event.getHeader())),
                            exceptionHandler);
                });
                chunkedBufferReadStream.resume();
            } else {
                chunkedBufferReadStream.pause();
                initMultipartUpload(bucket, key,
                        mapAdaptiveUploadRequestToInitMultipartUploadRequest(adaptiveUploadRequest), event -> {
                            try {
                                if (adaptiveUploadRequest.getWriteQueueMaxSize() != null) {
                                    event.getData()
                                            .setWriteQueueMaxSize(adaptiveUploadRequest.getWriteQueueMaxSize());
                                }
                                if (adaptiveUploadRequest.getBufferSize() != null) {
                                    event.getData().bufferSize(adaptiveUploadRequest.getBufferSize());
                                }
                                event.getData()
                                        .exceptionHandler(throwable -> exceptionHandler.handle(throwable));
                                Pump.pump(chunkedBufferReadStream, event.getData()).start();
                                chunkedBufferReadStream
                                        .endHandler(aVoid -> event.getData().end(endResponse -> handler
                                                .handle(new HeaderOnlyResponse(event.getHeader()))));
                                chunkedBufferReadStream.resume();
                            } catch (Throwable t) {
                                exceptionHandler.handle(t);
                            }
                        }, exceptionHandler);
            }
        }
    });
    chunkedBufferReadStream.resume();
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenterServlet.java

private void handleMetrics(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws IOException {
    String format = StringUtils.trimToNull(httpServletRequest.getParameter("format"));
    String[] startsWithFilters = httpServletRequest.getParameterValues("startsWithFilter");

    if (FORMAT_GRAPHITE.equalsIgnoreCase(format)) {
        httpServletResponse.setContentType(CONTENT_TYPE_TEXT_PLAIN);

        try (PrintWriter printWriter = httpServletResponse.getWriter()) {
            SortedMap<String, Metric> metricsByNames = MonitoringCenter.getMetricsByNames(true,
                    startsWithFilters);/*from  w ww  .  jav  a  2 s.c  o m*/
            printWriter.write(graphiteMetricFormatter.format(metricsByNames));
        }
    } else {
        boolean appendPrefix = Boolean.TRUE.toString()
                .equalsIgnoreCase(StringUtils.trimToNull(httpServletRequest.getParameter("appendPrefix")));

        Map<String, SortedMap<String, ? extends Metric>> responseMap = new LinkedHashMap<>();
        responseMap.put("gauges", MonitoringCenter.getGaugesByNames(appendPrefix, startsWithFilters));
        responseMap.put("counters", MonitoringCenter.getCountersByNames(appendPrefix, startsWithFilters));
        responseMap.put("histograms", MonitoringCenter.getHistogramsByNames(appendPrefix, startsWithFilters));
        responseMap.put("meters", MonitoringCenter.getMetersByNames(appendPrefix, startsWithFilters));
        responseMap.put("timers", MonitoringCenter.getTimersByNames(appendPrefix, startsWithFilters));

        writeAsJson(httpServletRequest, httpServletResponse, responseMap);
    }
}