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

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

Introduction

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

Prototype

public static String trimToNull(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:mitm.application.djigzo.tools.CertManager.java

private String getSOAPHost() {
    String host = StringUtils.trimToNull(hostOption.getValue());

    if (host == null) {
        host = "127.0.0.1";
    }//from   w  w w.  j  a v a 2 s  .c o m

    return host;
}

From source file:com.siberhus.web.ckeditor.CkeditorTagConfig.java

public void addConfigItem(Map<String, Object> tagAttributes, boolean local) {
    for (Map.Entry<String, Object> entry : tagAttributes.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (this.skipAllowedItemsCheck || ALLOWED_CONFIG_ITEMS.contains(key) || key.startsWith("filebrowser")) {
            if (value instanceof String) {
                String tmp = StringUtils.trimToNull((String) value);
                if (tmp != null) {
                    if (!NumberUtils.isNumber(tmp) && !tmp.equalsIgnoreCase("true")
                            && !tmp.equalsIgnoreCase("false") && !tmp.startsWith("CKEDITOR.")) {
                        tmp = "'" + tmp + "'";
                    }/*from   w ww.j  av  a 2 s .  c o  m*/
                }
                if (local) {
                    this.localConfig.put(key, tmp);
                } else {
                    this.config.put(key, tmp);
                }
            } else {
                throw new UnknownOptionException(
                        "Unknown option: ${key}. Option names are case sensitive! Check the spelling.");
            }
        }
    }
}

From source file:mitm.djigzo.web.pages.portal.secure.Signup.java

protected Object onActivate() {
    if (!isBackendRunning()) {
        return null;
    }//from   w w  w  .j  a v  a  2  s.  co  m

    try {
        if (email == null) {
            email = EmailAddressUtils.canonicalizeAndValidate(request.getParameter("email"), true);
        }

        if (timestamp == 0) {
            timestamp = NumberUtils.toLong(request.getParameter("ts"), 0);
        }

        if (mac == null) {
            mac = StringUtils.trimToNull(request.getParameter("mac"));
        }

        if (email == null) {
            throw new ValidatorException("email is not set");
        }

        if (timestamp == 0) {
            throw new ValidatorException("timestamp is not set");
        }

        if (mac == null) {
            throw new ValidatorException("mac is not set");
        }

        if ((System.currentTimeMillis() - timestamp) > validity) {
            throw new ValidatorException(messages.get("sign-up-expired"));
        }

        if (StringUtils.isNotEmpty(getUserProperties().getPortalProperties().getPassword())) {
            /*
             * A password was already set. Redirect to login page (this is also used to redirect to the
             * login after the user has selected a portal password)
             */
            return resources.createPageLink(Login.class, false, email);
        }
    } catch (Exception e) {
        errorMessage = e.getMessage();
        error = true;
    }

    return null;
}

From source file:com.egt.core.util.JS.java

public static String getOnClickRowSelectorJavaScript(String value) {
    VelocityContext context = new VelocityContext();
    context.put("value", StringUtils.trimToNull(value));
    return merge("js-on-click-row-selector", context);
}

From source file:de.willuhn.jameica.hbci.passports.pintan.server.PassportHandleImpl.java

/**
 * @see de.willuhn.jameica.hbci.passport.PassportHandle#open()
 *///from ww  w .  ja  v a  2s  .  c  om
public HBCIHandler open() throws RemoteException, ApplicationException {

    if (isOpen())
        return handler;

    Logger.info("open pin/tan passport");
    try {

        if (config == null && this.passport == null)
            throw new ApplicationException(i18n.tr("Keine Konfiguration oder Konto ausgewhlt"));

        if (config == null && this.passport != null && this.passport.getKonto() != null)
            config = PinTanConfigFactory.findByKonto(this.passport.getKonto());

        // Mh, nichts da zum Laden, dann fragen wir mal den User
        if (config == null) {
            GenericIterator list = PinTanConfigFactory.getConfigs();

            if (list == null || list.size() == 0)
                throw new ApplicationException(i18n.tr("Bitte legen Sie zuerst eine PIN/TAN-Konfiguration an"));

            // Wir haben nur eine Config, dann brauchen wir den User nicht fragen
            if (list.size() == 1) {
                config = (PinTanConfig) list.next();
            } else {
                SelectConfigDialog d = new SelectConfigDialog(SelectConfigDialog.POSITION_CENTER, list);
                try {
                    config = (PinTanConfig) d.open();
                } catch (OperationCanceledException oce) {
                    throw oce;
                } catch (Exception e) {
                    Logger.error("error while choosing config", e);
                    throw new ApplicationException(i18n.tr("Fehler bei der Auswahl der PIN/TAN-Konfiguration"));
                }
            }
        }

        if (config == null)
            throw new ApplicationException(i18n.tr("Keine PIN/TAN-Konfiguration fr dieses Konto definiert"));

        Logger.debug("using passport file " + config.getFilename());

        AbstractPlugin plugin = Application.getPluginLoader().getPlugin(HBCI.class);
        HBCICallback callback = ((HBCI) plugin).getHBCICallback();
        if (callback != null && (callback instanceof HBCICallbackSWT))
            ((HBCICallbackSWT) callback).setCurrentHandle(this);

        hbciPassport = config.getPassport();

        {
            AbstractHBCIPassport ap = (AbstractHBCIPassport) hbciPassport;

            // Wir speichern die verwendete PIN/TAN-Config im Passport. Dann wissen wir
            // spaeter in den HBCI-Callbacks noch, aus welcher Config der Passport
            // erstellt wurde. Wird z.Bsp. vom Payment-Server benoetigt.
            ap.setPersistentData(CONTEXT_CONFIG, config);

            String cannationalacc = config.getCustomProperty("cannationalacc");
            if (cannationalacc != null)
                ap.setPersistentData("cannationalacc", cannationalacc);
        }

        String hbciVersion = config.getHBCIVersion();
        if (hbciVersion == null || hbciVersion.length() == 0)
            hbciVersion = HBCIVersion.HBCI_300.getId();

        Logger.info("[PIN/TAN] url         : " + config.getURL());
        Logger.info("[PIN/TAN] blz         : " + config.getBLZ());
        Logger.info("[PIN/TAN] filter      : " + config.getFilterType());
        Logger.info("[PIN/TAN] HBCI version: " + hbciVersion);

        //////////////////////
        // BUGZILLA 831
        // Siehe auch Stefans Mail vom 10.03.2010 - Betreff "Re: [hbci4java] Speicherung des TAN-Verfahrens im PIN/TAN-Passport-File?"
        PtSecMech mech = config.getStoredSecMech();
        String secmech = mech != null ? StringUtils.trimToNull(mech.getId()) : null;

        Logger.info("[PIN/TAN] using stored tan sec mech: " + (mech != null ? mech.toString() : "<ask-user>"));
        ((AbstractPinTanPassport) hbciPassport).setCurrentTANMethod(secmech);
        //////////////////////

        handler = new HBCIHandler(hbciVersion, hbciPassport);
        return handler;
    } catch (RemoteException re) {
        close();
        throw re;
    } catch (ApplicationException ae) {
        close();
        throw ae;
    } catch (OperationCanceledException oce) {
        close();
        throw oce;
    } catch (Exception e) {
        close();
        Logger.error("error while opening pin/tan passport", e);
        throw new RemoteException("error while opening pin/tan passport", e);
    }
}

From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java

private String getUniqueIdentifier(Element e) {
    Element uniqueId = e.element(getUniqueIdentifierElementName());
    if (uniqueId != null) {
        return StringUtils.trimToNull(uniqueId.getText());
    }/*from   w ww  .j  a  va 2 s .c o  m*/
    return null;
}

From source file:com.iyonger.apm.web.service.AgentManagerService.java

protected boolean hasSameInfo(GrinderAgentInfo grinderAgentInfo,
        AgentControllerIdentityImplementation agentIdentity) {
    return grinderAgentInfo != null
            && grinderAgentInfo.getPort() == agentManager.getAgentConnectingPort(agentIdentity)
            && StringUtils.equals(grinderAgentInfo.getRegion(), agentIdentity.getRegion())
            && StringUtils.equals(StringUtils.trimToNull(grinderAgentInfo.getVersion()),
                    StringUtils.trimToNull(agentManager.getAgentVersion(agentIdentity)));
}

From source file:ch.entwine.weblounge.security.sql.endpoint.SQLDirectoryProviderEndpoint.java

@POST
@Path("/account")
public Response createAccount(@FormParam("login") String login, @FormParam("password") String password,
        @FormParam("email") String eMail, @Context HttpServletRequest request) {

    // TODO: If not, return a one time pad that needs to be used when verifying
    // the e-mail

    // Check the arguments
    if (StringUtils.isBlank(login))
        return Response.status(Status.BAD_REQUEST).build();

    Response response = null;/*from   w  w  w  . j  a v  a 2s .c  o  m*/
    Site site = getSite(request);

    // Hash the password
    if (StringUtils.isNotBlank(password)) {
        logger.debug("Hashing password for user '{}@{}' using md5", login, site.getIdentifier());
        password = PasswordEncoder.encode(StringUtils.trim(password));
    }

    // Create the user
    try {
        JpaAccount account = directory.addAccount(site, login, password);
        account.setEmail(StringUtils.trimToNull(eMail));
        directory.updateAccount(account);
        response = Response
                .created(new URI(UrlUtils.concat(request.getRequestURL().toString(), account.getLogin())))
                .build();
    } catch (UserExistsException e) {
        logger.warn("Error creating account: {}", e.getMessage());
        return Response.status(Status.CONFLICT).build();
    } catch (UserShadowedException e) {
        logger.warn("Error creating account: {}", e.getMessage());
        return Response.status(Status.CONFLICT).build();
    } catch (Throwable t) {
        logger.warn("Error creating account: {}", t.getMessage());
        response = Response.serverError().build();
    }
    return response;
}

From source file:com.bluexml.xforms.generator.forms.modelelement.ModelElementBindSimple.java

/**
 * @param bindElement/*ww  w .j  a  va 2 s. c  o  m*/
 */
private void setRelevantAttrForGhostTemplate(Element bindElement) {
    // special processing added for telling Chiba not to validate the ghost section that
    // we use in repeaters as templates
    // example of what we want to obtain: relevant="index('field_456Repeater') &lt;
    // count(instance('minstance')/NewsletterTech/field_456/associationItem)"
    boolean first = true;
    int posStart = 0;
    String relevantStr = "";
    posStart = nodeset.indexOf("[index('", posStart);
    while (posStart != -1) { // there is a ghost template
        int posEnd = nodeset.indexOf("')]", posStart + 1);
        if (posEnd == -1) {
            // TODO: output message
            // if (logger.isErrorEnabled()) {
            // logger.error("Error when parsing a nodeset for repeater name");
            // }
        } else {
            String lvalue = nodeset.substring(posStart + 1, posEnd + 2);
            String rvalue = nodeset.substring(0, posStart);
            if (first) {
                first = false;
            } else {
                relevantStr += " and ";
            }
            relevantStr += "(" + lvalue + " < count(" + rvalue + "))";
        }
        posStart = nodeset.indexOf("[index('", posEnd + 1);
    }
    if (StringUtils.trimToNull(relevantStr) != null) {
        bindElement.setAttribute("relevant", relevantStr);
    }
}

From source file:com.bluexml.xforms.controller.alfresco.AlfrescoWebscriptException.java

/**
 * Returns the full name of the association that caused the integrity violation. This function
 * is tailored for the message returned by Alfresco 2.9B (as in the example above).
 * //www .j a v a 2 s.com
 * @param message
 * @param startpos
 *            the position in the string where to start searching for the violated association's
 *            full name. Needed because the message may reference several constraint violations.
 * @return the name of the association from the message or empty string if it can't be found
 */
private String getAssociationName(String message, int startpos) {
    String result;
    int pos = message.indexOf("Association: Association", startpos);
    if (pos == -1) {
        return "";
    }

    pos = message.indexOf("name={", pos + 1); // skip the class def's name
    if (pos == -1) {
        return "";
    }
    pos = message.indexOf("name={", pos + 1); // this is the association's name
    if (pos == -1) {
        return "";
    }
    int pos1 = message.indexOf('}', pos);
    int pos2 = message.indexOf(',', pos);
    if ((pos1 == -1) || (pos2 == -1)) {
        return "";
    }
    result = message.substring(pos1 + 1, pos2); // we get the complete name
    result = getController().getShortAssociationName(result, transaction.getFormId());
    if (StringUtils.trimToNull(result) == null) {
        return getAssociationName(message, pos2 + 1);
    }
    return result;
}