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

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

Introduction

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

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:com.thoughtworks.go.legacywrapper.StackTraceExtractor.java

public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    if ("build".equals(qName)) {
        readingBuild = true;/*from ww w  . j a  v a  2s  . c  o m*/
        error = StringUtils.defaultString(attributes.getValue("error"));
    }
    if ("stacktrace".equals(qName)) {
        readingStackTrace = true;
    }
}

From source file:com.apress.prospringintegration.batch.UserRegistrationValidationItemProcessor.java

private String stripNonNumbers(String input) {
    String output = StringUtils.defaultString(input);
    StringBuffer numbersOnly = new StringBuffer();
    for (char potentialDigit : output.toCharArray()) {
        if (Character.isDigit(potentialDigit)) {
            numbersOnly.append(potentialDigit);
        }/*  w w  w . j a  v  a2s  .c  om*/
    }
    return numbersOnly.toString();
}

From source file:com.tek271.reverseProxy.utils.FileTools.java

public static String readTextFileContent(File file) {
    if (file == null)
        return "";

    String text;//from  w w w.  j  a  va 2s.  c o m
    try {
        text = FileUtils.readFileToString(file);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not read file's text.", e);
    }
    return StringUtils.defaultString(text);
}

From source file:com.joshlong.lazyblogger.model.BlogPost.java

public void addSender(String sender) {
    String normalizedSender = StringUtils.defaultString(sender).trim().toLowerCase();

    if (!StringUtils.isEmpty(normalizedSender))
        senders.add(normalizedSender);//from w  ww  .ja v  a2s . c o m

}

From source file:edu.cornell.med.icb.util.VersionUtils.java

/**
 * Gets the Implementation-Version attribute from the manifest of the jar file a class
 * is loaded from./*from  w  w  w .jav a  2 s.  c  o  m*/
 * @param clazz The class to get the version for
 * @return The value of the Implementation-Version attribute or "UNKNOWN" if the
 * jar file cannot be read.
 */
public static String getImplementationVersion(final Class<?> clazz) {
    String version;
    try {
        final String classContainer = clazz.getProtectionDomain().getCodeSource().getLocation().toString();
        final URL manifestUrl = new URL("jar:" + classContainer + "!/" + JarFile.MANIFEST_NAME);
        final Manifest manifest = new Manifest(manifestUrl.openStream());
        final Attributes attributes = manifest.getMainAttributes();
        version = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
    } catch (Exception e) {
        // pretty much any error here is ok since we may not even have a jar to read from
        version = "UNKNOWN";
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(Attributes.Name.IMPLEMENTATION_VERSION + ": " + version);
    }
    return StringUtils.defaultString(version);
}

From source file:de.hybris.platform.ycommercewebservices.v2.controller.BaseController.java

protected static String logValue(final String paramValue) {
    return "'" + StringUtils.defaultString(paramValue);
}

From source file:com.autentia.intra.validator.NifValidator.java

/**
 * Efecta el proceso de validacin/*  www  .j  a  v a  2s .  co  m*/
 */
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    // Si el valor es null, lo transformamos en un valor vaco
    String valor = StringUtils.defaultString((String) value);
    // el valor debe tener 9 posiciones
    valor = valor.toUpperCase();
    // Las 8 primeras posiciones deben ser nmeros y la ltima una letra
    Pattern mask = Pattern.compile("[0-9]{8,8}[A-Z]");
    Matcher matcher = mask.matcher(valor);
    if (!matcher.matches())
        throw new ValidatorException(new FacesMessage("El componente " + component.getId()
                + " no contiene un NIF vlido. Las 8 primeras posiciones deben ser numricas"));

    String dni = valor.substring(0, 8);
    String digitoControl = valor.substring(8, 9);
    // Calculamos la letra de control
    String letras = "TRWAGMYFPDXBNJZSQVHLCKE";
    int posicion_modulo = Integer.parseInt(dni) % 23;
    String digitoControlCalculado = letras.substring(posicion_modulo, posicion_modulo + 1);
    if (!digitoControl.equalsIgnoreCase(digitoControlCalculado))
        throw new ValidatorException(
                new FacesMessage("El componente " + component.getId() + " no contiene un NIF vlido"));

}

From source file:jp.co.nemuzuka.entity.TodoModelEx.java

/**
 * @return ?
 */
public String getTag() {
    return StringUtils.defaultString(model.getTag());
}

From source file:info.magnolia.cms.security.Authenticator.java

/**
 * Authenticate authorization request using JAAS login module as configured
 * @param request as received by the servlet engine
 * @return boolean/*from  w w w  .  ja va 2s  .  c  om*/
 */
public static boolean authenticate(HttpServletRequest request) {
    String credentials = request.getHeader("Authorization");
    String userid;
    String pswd;
    CredentialsCallbackHandler callbackHandler;
    String loginModuleToInitialize = "magnolia"; // default login module

    if (StringUtils.isEmpty(credentials) || credentials.length() <= 6) {
        // check for form based login request
        if (StringUtils.isNotEmpty(request.getParameter(PARAMETER_USER_ID))) {
            userid = request.getParameter(PARAMETER_USER_ID);
            pswd = StringUtils.defaultString(request.getParameter(PARAMETER_PSWD));
            callbackHandler = new PlainTextCallbackHandler(userid, pswd.toCharArray());
        } else {
            // select login module to use if user is authenticated against the container
            if (request.getUserPrincipal() != null) {
                loginModuleToInitialize = "magnolia_authorization";
                callbackHandler = new PlainTextCallbackHandler(request.getUserPrincipal().getName(),
                        "".toCharArray());
            } else {
                // invalid auth request
                return false;
            }
        }
    } else {
        // its a basic authentication request
        callbackHandler = new Base64CallbackHandler(credentials);
    }

    Subject subject;
    try {
        LoginContext loginContext = new LoginContext(loginModuleToInitialize, callbackHandler);
        loginContext.login();
        subject = loginContext.getSubject();
        // ok, we NEED a session here since the user has been authenticated
        HttpSession httpsession = request.getSession(true);
        httpsession.setAttribute(ATTRIBUTE_JAAS_SUBJECT, subject);
    } catch (LoginException le) {
        if (log.isDebugEnabled())
            log.debug("Exception caught", le);

        HttpSession httpsession = request.getSession(false);
        if (httpsession != null) {
            httpsession.invalidate();
        }
        return false;
    }

    return true;
}

From source file:com.redhat.rhn.frontend.xmlrpc.serializer.DmiSerializer.java

/**
 * {@inheritDoc}//from www.  j a v a2s .  co  m
 */
protected void doSerialize(Object value, Writer output, XmlRpcSerializer serializer)
        throws XmlRpcException, IOException {
    SerializerHelper bean = new SerializerHelper(serializer);
    Dmi dmi = (Dmi) value;

    bean.add("vendor", StringUtils.defaultString(dmi.getVendor()));
    bean.add("system", StringUtils.defaultString(dmi.getSystem()));
    bean.add("product", StringUtils.defaultString(dmi.getProduct()));
    bean.add("asset", StringUtils.defaultString(dmi.getAsset()));
    bean.add("board", StringUtils.defaultString(dmi.getBoard()));
    if (dmi.getBios() != null) {
        bean.add("bios_release", StringUtils.defaultString(dmi.getBios().getRelease()));
        bean.add("bios_vendor", StringUtils.defaultString(dmi.getBios().getVendor()));
        bean.add("bios_version", StringUtils.defaultString(dmi.getBios().getVersion()));
    }
    bean.writeTo(output);
}