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

The following are Jave code examples for showing how to use defaultIfEmpty() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ProjectAltaria   File: GoogleCommandHandler.java   View Source Code Vote up 5 votes
private void shortenURL(@NotNull MessageReceivedEvent event, String url) throws RateLimitException, DiscordException, MissingPermissionsException {
    if (!UrlValidator.getInstance().isValid(url)) {
        EventUtils.sendIncorrectUsageMessage(event.getClient(), event.getMessage().getChannel(), "ShortUrl", "URL is not a valid http/https URL!");
        return;
    }
    try {
        Url shortUrl = GoogleClientServiceFactory.getInstance().getUrlShortenerService()
                                                 .url()
                                                 .insert(new Url().setLongUrl(url))
                                                 .execute();

        @NotNull StringBuilder builder = new StringBuilder(StringUtils.defaultIfEmpty(shortUrl.getId(), "URL was removed by google."));

        if (shortUrl.getStatus() != null && !"OK".equalsIgnoreCase(shortUrl.getStatus())) {
            builder.append("\n")
                   .append("Attention:")
                   .append("   ")
                   .append(shortUrl.getStatus());
        }

        new MessageBuilder(event.getClient())
                .withChannel(event.getMessage().getChannel())
                .withContent("Short URL: ")
                .appendContent(builder.toString(), Styles.UNDERLINE)
                .appendContent("\n")
                .appendContent("Full URL: ")
                .appendContent(url, Styles.UNDERLINE)
                .send();

    } catch (IOException e) {
        logger.error("I/O Error during call to URLShortening service", e);
        new MessageBuilder(event.getClient())
                .withChannel(event.getMessage().getChannel())
                .withContent("Fail during google URL Shortening API Contact.")
                .send();
    }
}
 
Example 2
Project: cas-5.1.0   File: SamlMetadataUIConfiguration.java   View Source Code Vote up 5 votes
@ConditionalOnMissingBean(name = "samlMetadataUIParserAction")
@Bean
public Action samlMetadataUIParserAction() {
    final String parameter = StringUtils.defaultIfEmpty(casProperties.getSamlMetadataUi().getParameter(),
            SamlProtocolConstants.PARAMETER_ENTITY_ID);
    return new SamlMetadataUIParserAction(parameter, chainingSamlMetadataUIMetadataResolverAdapter(),
            serviceFactory, servicesManager);
}
 
Example 3
Project: cas-5.1.0   File: LogoutAction.java   View Source Code Vote up 5 votes
@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response,
                                  final RequestContext context) throws Exception {

    boolean needFrontSlo = false;
    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
    if (logoutRequests != null) {
        needFrontSlo = logoutRequests
                .stream()
                .anyMatch(logoutRequest -> logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED);
    }

    final String paramName = StringUtils.defaultIfEmpty(logoutProperties.getRedirectParameter(), CasProtocolConstants.PARAMETER_SERVICE);
    LOGGER.debug("Using parameter name [{}] to detect destination service, if any", paramName);
    final String service = request.getParameter(paramName);
    LOGGER.debug("Located target service [{}] for redirection after logout", paramName);

    if (logoutProperties.isFollowServiceRedirects() && StringUtils.isNotBlank(service)) {
        final Service webAppService = webApplicationServiceFactory.createService(service);
        final RegisteredService rService = this.servicesManager.findServiceBy(webAppService);

        if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()) {
            LOGGER.debug("Redirecting to service [{}]", service);
            WebUtils.putLogoutRedirectUrl(context, service);
        } else {
            LOGGER.warn("Cannot redirect to [{}] given the service is unauthorized to use CAS. "
                    + "Ensure the service is registered with CAS and is enabled to allowed access", service);
        }
    } else {
        LOGGER.debug("No target service is located for redirection after logout, or CAS is not allowed to follow redirects after logout");
    }

    // there are some front services to logout, perform front SLO
    if (needFrontSlo) {
        LOGGER.debug("Proceeding forward with front-channel single logout");
        return new Event(this, FRONT_EVENT);
    }
    LOGGER.debug("Moving forward to finish the logout process");
    return new Event(this, FINISH_EVENT);
}
 
Example 4
Project: atlas   File: Profiler.java   View Source Code Vote up 5 votes
public String getMessage() {
    String messageString = null;
    if (this.message instanceof String) {
        messageString = (String)this.message;
    } else if (this.message instanceof Profiler.Message) {
        Profiler.Message messageObject = (Profiler.Message)this.message;

        messageString = messageObject.getDetailedMessage();

    }

    return StringUtils.defaultIfEmpty(messageString, (String)null);
}
 
Example 5
Project: OperatieBRP   File: AfnemerindicatieVerzoekServiceImpl.java   View Source Code Vote up 5 votes
/**
 * Specifieke regel validatie voor het BRP bericht. Dit past niet niet in de 'generieke' valideer regels stap welke ook voor de GBA routes gebruikt
 * wordt. <br> LET OP! dit is een beetje suffe controle omdat het volgens koppelvlak meerdere partijen meegegeven kunnen worden terwijl ze eigenlijk
 * allemaal hetzelfde moeten zijn....
 */
@Bedrijfsregel(value = Regel.R2061)
private void valideerOnderhoudEigenPartij(final AfnemerindicatieVerzoek verzoek) throws StapException {
    final String zendendePartijCode = verzoek.getStuurgegevens().getZendendePartijCode();
    final String partijWaarvoorIndicatieGeplaatstWordt = verzoek.getAfnemerindicatie().getPartijCode();
    final String partijWaarvoorIndicatieGeplaatstWordt2 = StringUtils
            .defaultIfEmpty(verzoek.getDummyAfnemerCode(), zendendePartijCode);
    if (!StringUtils.equals(zendendePartijCode, partijWaarvoorIndicatieGeplaatstWordt)
            || !StringUtils.equals(zendendePartijCode, partijWaarvoorIndicatieGeplaatstWordt2)) {
        throw new StapMeldingException(Regel.R2061);
    }
}
 
Example 6
Project: OperatieBRP   File: BerichtGroepBuilder.java   View Source Code Vote up 5 votes
private static void schrijfWrapperAttributen(final MetaRecord metaRecord, final MetaGroep metaGroep, final BerichtElement.Builder berichtElement,
                                             final Berichtgegevens berichtgegevens) {
    berichtElement.metBerichtElementAttribuut(
            BerichtElementAttribuut.maakBuilder(BerichtConstanten.VOORKOMEN_SLEUTEL, String.valueOf(metaRecord.getVoorkomensleutel())));
    if (berichtgegevens.isMutatiebericht() && berichtgegevens.getVerwerkingssoort(metaRecord) != null) {
        berichtElement.metBerichtElementAttribuut(
                BerichtElementAttribuut.maakBuilder(BerichtConstanten.VERWERKINGSSOORT, berichtgegevens.getVerwerkingssoort(metaRecord).getNaam()));
    }

    /*
      als het record deel uitmaakt van een inverse object
      dan moet objectsleutel ook weggeschreven worden.
     */
    final boolean isRecordVanInverseObject = ElementHelper.getObjectAssociatiecode(metaGroep.getParentObject().getObjectElement()) != null;
    if (isRecordVanInverseObject
            && Element.PERSOON_OUDER_OUDERSCHAP != metaGroep.getGroepElement().getElement()
            && Element.GERELATEERDEOUDER_OUDERSCHAP != metaGroep.getGroepElement().getElement()
            || metaGroep.getGroepElement().isIndicatie()) {
        //zet de sleutel
        final String sleutel = StringUtils.defaultIfEmpty(berichtgegevens.getVersleuteldeObjectSleutel(metaGroep.getParentObject()),
                String.valueOf(metaGroep.getParentObject().getObjectsleutel()));
        berichtElement.metBerichtElementAttribuut(
                BerichtElementAttribuut.maakBuilder(BerichtConstanten.OBJECT_SLEUTEL, sleutel));

        final String objecttype;
        if (metaGroep.getGroepElement().isIndicatie()) {
            //indicaties hebben verschillende objecttypen en worden ook als losse objecten getoond, het objecttype moet echter PersoonIndicatie zijn
            // voor alle indicaties
            objecttype = Element.PERSOON_INDICATIE.getElementWaarde().getXmlNaam();
        } else {
            objecttype = metaGroep.getParentObject().getObjectElement().getTypeObjectElement().getXmlNaam();
        }
        berichtElement.metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.OBJECTTYPE, objecttype));
    }
}
 
Example 7
Project: tauren   File: WebUtil.java   View Source Code Vote up 4 votes
/**
 * 获取请求路径
 */
public static String getRequestPath(HttpServletRequest request) {
    String servletPath = request.getServletPath();
    String pathInfo = StringUtils.defaultIfEmpty(request.getPathInfo(), "");
    return servletPath + pathInfo;
}
 
Example 8
Project: springboot-shiro-cas-mybatis   File: AbstractNamedMonitor.java   View Source Code Vote up 4 votes
/**
 * @return Monitor name.
 */
@Override
public String getName() {
    return StringUtils.defaultIfEmpty(this.name, getClass().getSimpleName());
}
 
Example 9
Project: springboot-shiro-cas-mybatis   File: AbstractNamedMonitor.java   View Source Code Vote up 4 votes
/**
 * @return Monitor name.
 */
public String getName() {
    return StringUtils.defaultIfEmpty(this.name, getClass().getSimpleName());
}
 
Example 10
Project: cas-5.1.0   File: JpaTicketRegistryConfiguration.java   View Source Code Vote up 4 votes
@Bean
public LockingStrategy lockingStrategy() {
    final TicketRegistryProperties registry = casProperties.getTicket().getRegistry();
    final String uniqueId = StringUtils.defaultIfEmpty(casProperties.getHost().getName(), InetAddressUtils.getCasServerHostName());
    return new JpaLockingStrategy(registry.getCleaner().getAppId(), uniqueId, registry.getJpa().getJpaLockingTimeout());
}
 
Example 11
Project: cas-5.1.0   File: CookieRetrievingCookieGenerator.java   View Source Code Vote up 4 votes
@Override
public void setCookieDomain(final String cookieDomain) {
    super.setCookieDomain(StringUtils.defaultIfEmpty(cookieDomain, null));
}
 
Example 12
Project: cas-5.1.0   File: AbstractNamedMonitor.java   View Source Code Vote up 4 votes
/**
 * @return Monitor name.
 */
@Override
public String getName() {
    return StringUtils.defaultIfEmpty(this.name, getClass().getSimpleName());
}
 
Example 13
Project: cas-server-4.2.1   File: AbstractNamedMonitor.java   View Source Code Vote up 4 votes
/**
 * @return Monitor name.
 */
@Override
public String getName() {
    return StringUtils.defaultIfEmpty(this.name, getClass().getSimpleName());
}
 
Example 14
Project: OperatieBRP   File: BerichtBuilder.java   View Source Code Vote up 4 votes
private BerichtElement.Builder maakWrapperVoorObject(final MetaObject metaObject) {
    final ObjectElement objectElement = metaObject.getObjectElement();
    final String objectElementNaam;
    final String objecttype;
    if (objectElement.isVanType(HUWELIJKGEREGISTREERD_PARTNERSCHAP)) {
        objectElementNaam = objectElement.getXmlNaam();
        //pak XML naam van relatie, het supertype
        //nog te doen ROOD-2021
        objecttype = ElementConstants.RELATIE.getXmlNaam();
    } else if (objectElement.isVanType(PERSOON_VERSTREKKINGSBEPERKING)) {
        //nog te doen ROOD-2021
        objectElementNaam = "verstrekkingsbeperking";
        objecttype = PERSOON_VERSTREKKINGSBEPERKING.getXmlNaam();
    } else {
        objectElementNaam = objectElement.getXmlNaam();
        objecttype = objectElement.getTypeObjectElement().getXmlNaam();
    }
    final BerichtElement.Builder berichtElement = BerichtElement.builder();
    berichtElement.metNaam(BerichtUtil.lowercaseFirst(objectElementNaam));
    //zet de sleutel
    final String sleutel = StringUtils.defaultIfEmpty(berichtgegevens.getVersleuteldeObjectSleutel(metaObject),
            String.valueOf(metaObject.getObjectsleutel()));
    berichtElement
            .metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.OBJECT_SLEUTEL, sleutel));
    berichtElement.metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.OBJECTTYPE, objecttype));
    if (berichtgegevens.isMutatiebericht()) {
        final Verwerkingssoort verwerkingssoort = berichtgegevens.getObjectVerwerkingssoort(metaObject);
        if (verwerkingssoort != null) {
            berichtElement
                    .metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.VERWERKINGSSOORT, verwerkingssoort.getNaam()));
        }
    }

    if (metaObject.getObjectElement().getElement() == Element.PERSOON && communicatieId != null) {
        berichtElement.metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.COMMUNICATIE_ID, communicatieId.toString()));
    }

    final String voorkomenSleutelBetrokkenheid = bepaalVoorkomenSleutelVoorBetrokkenheid(metaObject);
    if (voorkomenSleutelBetrokkenheid != null) {
        berichtElement.metBerichtElementAttribuut(BerichtElementAttribuut.maakBuilder(BerichtConstanten.VOORKOMEN_SLEUTEL, voorkomenSleutelBetrokkenheid));
    }
    return berichtElement;
}
 
Example 15
Project: obevo   File: TableChangeParser.java   View Source Code Vote up 4 votes
public ChangeIncremental value(TextMarkupDocumentSection section, String schema, String objectName,
                               int changeIndex) {
    ChangeType changeType = getChangeType(section);
    boolean drop = section.isTogglePresent(TOGGLE_DROP_TABLE);

    String changeName = section.getAttr(ATTR_NAME);
    Validate.notNull(changeName, "Must define name parameter");

    MutableList<String> baselinedChanges = section.getAttr(ATTR_BASELINED_CHANGES) == null ? FastList.<String>newList() : trimmedTokensToList(
            section.getAttr(ATTR_BASELINED_CHANGES), ",");

    boolean active = !section.isTogglePresent(TOGGLE_INACTIVE);

    TextMarkupDocumentSection rollbackIfAlreadyDeployedSection = section.getSubsections().detect(
            Predicates.attributeEqual(TextMarkupDocumentSection.TO_NAME,
                    TextMarkupDocumentReader.TAG_ROLLBACK_IF_ALREADY_DEPLOYED));
    // in case the section exists but no content, mark it as an empty string so that changes can still get dropped from the audit log
    String rollbackIfAlreadyDeployedCommand = rollbackIfAlreadyDeployedSection == null ? null : StringUtils.defaultIfEmpty(rollbackIfAlreadyDeployedSection.getContent(), "");

    TextMarkupDocumentSection rollbackSection = section.getSubsections()
            .detect(Predicates.attributeEqual(TextMarkupDocumentSection.TO_NAME,
                    TextMarkupDocumentReader.TAG_ROLLBACK));
    String rollbackContent = rollbackSection == null ? null : rollbackSection.getContent();

    String content = section.getContent() == null ? "" : section.getContent();
    if (StringUtils.isEmpty(content)) {
        LOG.warn("WARNING: Empty change defined in [Table={}, Change={}]; please avoid empty changes or correct/remove if possible", objectName, changeName);
    }
    if (rollbackSection != null && StringUtils.isBlank(rollbackContent)) {
        LOG.warn("WARNING: Empty rollback script defined in [Table={}, Change={}], which will be ignored. Please remove, or add content (e.g. a dummy SQL update if you want to force a rollback)", objectName, changeName);
    }
    ChangeIncremental change = new ChangeIncremental(changeType, schema, objectName, changeName,
            changeIndex, this.contentHashStrategy.hashContent(content), content,
            rollbackIfAlreadyDeployedCommand, active);
    change.setRollbackContent(rollbackContent);
    change.setBaselinedChanges(baselinedChanges);
    change.setDrop(drop);
    change.setKeepIncrementalOrder(drop);

    String applyGrantsStr = section.getAttr(ATTR_APPLY_GRANTS);
    change.setApplyGrants(applyGrantsStr == null ? null : Boolean.valueOf(applyGrantsStr));
    change.setChangeset(section.getAttr(ATTR_CHANGESET));
    change.setParallelGroup(section.getAttr(ATTR_PARALLEL_GROUP));
    return change;
}
 
Example 16
Project: opencron   File: MapResultTransFormer.java   View Source Code Vote up 2 votes
/**
 * 根据查询字段获取别名
 *
 * @param name
 * @return
 */
protected String getAlias(String name) {
    return StringUtils.defaultIfEmpty(aliasMap.get(name.toLowerCase()), name);
}