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:ca.uhn.hl7v2.testpanel.model.msg.Hl7V2MessageBase.java

@Override
public void setSourceMessage(String theMessage) throws PropertyVetoException {
    theMessage = StringUtils.defaultString(theMessage);

    String original = mySourceMessage;
    if (mySourceMessage != null && mySourceMessage.equals(theMessage)) {
        return;/*from   w w  w  .ja  v a  2  s .  com*/
    }

    String sourceMessage = theMessage.trim();
    String text = sourceMessage.replaceAll("(\\r|\\n)+", "\r");

    updateParser();

    Message parsedMessage;
    try {

        ourLog.info("About to parse message");

        if (myRuntimeProfile != null) {
            Entry profile = determineRuntimeProfile(text);

            if (profile != null) {
                parsedMessage = ConformanceMessage.newInstanceFromStaticDef(
                        profile.getProfileProxy().getProfile().getMessage(), profile.getTablesId());
                parsedMessage.setParser(myParser);
                parsedMessage.parse(text);
            } else {
                parsedMessage = myParser.parse(text);
            }
        } else {
            parsedMessage = myParser.parse(text);
        }

        ourLog.info("Done parsing message");

    } catch (EncodingNotSupportedException e) {
        ourLog.error("Failed to parse message", e);
        throw new PropertyVetoException(e.getMessage(), null);
    } catch (HL7Exception e) {
        ourLog.error("Failed to parse message", e);
        throw new PropertyVetoException(e.getMessage(), null);
    } catch (IOException e) {
        ourLog.error("Failed to parse message", e);
        throw new PropertyVetoException(e.getMessage(), null);
    } catch (ProfileException e) {
        ourLog.error("Failed to parse message", e);
        throw new PropertyVetoException(e.getMessage(), null);
    }

    myParsedMessage = parsedMessage;
    mySourceMessage = sourceMessage;

    recalculateIndexes();

    firePropertyChange(PARSED_MESSAGE_PROPERTY, original, text);
}

From source file:mitm.common.security.ca.CAImpl.java

private void setNextUpdate(CertificateRequest certificateRequest) {
    int index = certificateRequest.getIteration();

    /*/*  w  ww  .j a v a 2s .c  o  m*/
     * Use last delay if we have no more delay's left
     */
    if (index > delayTimes.length - 1) {
        index = delayTimes.length - 1;
    }

    Date nextUpdate = DateUtils.addSeconds(new Date(), delayTimes[index]);

    logger.debug("Next update for " + StringUtils.defaultString(certificateRequest.getEmail()) + " set to "
            + nextUpdate);

    certificateRequest.setNextUpdate(nextUpdate);
}

From source file:net.erdfelt.android.sdkfido.configer.Configer.java

public void persist() throws IOException {
    Properties props = new Properties();

    String key, value;/*from  w ww.j  ava 2s  .  c o  m*/
    for (Configurable conf : configurables.values()) {
        if (conf.isInternal()) {
            continue; // skip Configuration internal configurables
        }
        key = conf.getKey();
        value = getValue(key);
        props.put(key, StringUtils.defaultString(value));
    }

    FileWriter writer = null;
    try {
        writer = new FileWriter(this.persistFile);
        props.store(writer, "Written by " + this.getClass().getName());
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:com.manydesigns.elements.xml.XhtmlBuffer.java

public void writeInputText(@Nullable String id, @Nullable String name, String value,
        @Nullable String placeholder, String htmlClass, @Nullable Integer size, @Nullable Integer maxLength) {
    openElement("input");
    addAttribute("id", id);
    addAttribute("type", "text");
    addAttribute("name", name);
    addAttribute("value", value);
    if (placeholder != null) {
        addAttribute("placeholder", placeholder);
    }/*from w  w w .  ja v  a 2 s .  c  om*/
    if (size != null) {
        addAttribute("size", Integer.toString(size));
        htmlClass = StringUtils.defaultString(htmlClass) + " mde-text-field-with-explicit-size";
    }
    addAttribute("class", htmlClass);
    if (maxLength != null) {
        addAttribute("maxlength", Integer.toString(maxLength));
    }
    closeElement("input");
}

From source file:com.redhat.rhn.manager.user.CreateUserCommand.java

/**
 * Private helper method to validate the user's login. Puts errors into the errors List.
 *//*from  w  w  w . j ava2s .  c  o  m*/
private void validateLogin() {
    int max = UserDefaults.get().getMaxUserLength();
    if (user == null) {
        errors.add(new ValidatorError("error.minlogin", "null"));
        return;
    }
    String login = StringUtils.defaultString(user.getLogin());
    /*
     * Check for login minimum length
     * Since login.getBytes().length >= login.length(), just check for min length
     */
    if (login.length() < UserDefaults.get().getMinUserLength()) {
        errors.add(new ValidatorError("error.minlogin", UserDefaults.get().getMinUserLength()));
        return;
    }
    /*
     * Check for login maximum length
     * Since we are allowing utf8 input, but not supporting it in the db, we need to
     * check the length of the bytes here as well.
     * TODO: Do better error checking here once the db and code is fully localized and
     * we are supporting it on logins
     */
    else if (login.length() > max || login.getBytes().length > max) {
        errors.add(new ValidatorError("error.maxlogin", login));
        return;
    }

    // validate using the webui code.  I must say that RequiredConstraint
    // is a stupid place for hiding username validation.  But nevertheless
    // I will continue to propogate this crap until we want to revisit
    // validation.
    ParsedConstraint rc = new ParsedConstraint("CreateUserCommand");
    if (!rc.isValidUserName(login)) {
        errors.add(new ValidatorError("errors.username", login));
        return;
    }

    // Make sure desiredLogin isn't taken already
    try {
        UserFactory.lookupByLogin(login);
        errors.add(new ValidatorError("error.login_already_taken", login));
    } catch (LookupException le) {
        // User is not taken
        // so we can coolly add him.
    }

}

From source file:com.flexive.shared.structure.FxStructureOption.java

/**
 * Get an option entry for the given key, if the key is invalid or not found a <code>FxStructureOption</code> object
 * will be returned with <code>set</code> set to <code>false</code>, overridable set to <code>false</code> and value
 * set to an empty String./*from w  w w  . j a v a 2  s  .  c  o  m*/
 *
 * @param key     option key
 * @param options the available options
 * @return the found option or an object that indicates that the option is not set
 */
public static FxStructureOption getOption(String key, List<FxStructureOption> options) {
    if (key != null)
        key = XPathElement.xpToUpperCase(key.trim());
    if (key == null || key.length() == 0 || options == null || options.size() == 0)
        return getUnknownOption(StringUtils.defaultString(key));
    for (FxStructureOption option : options)
        if (key.equals(option.getKey()))
            return option;
    return getUnknownOption(key);
}

From source file:mitm.common.util.MiscStringUtils.java

/**
 * Restricts the length of the input string to a maximum length. If addDots is true ... will be added if the string
 * is too long. The final length will always be smaller or equal to maxLength (ie the dots do not make it any longer)
 * There is one exception when the size < 3 and addDots is true.
 *//*from   w w  w .j a v  a  2 s.com*/
public static String restrictLength(String input, int maxLength, boolean addDots, String dots) {
    if (input == null) {
        return null;
    }

    if (maxLength < 0) {
        maxLength = 0;
    }

    if (input.length() > maxLength) {
        /*
         * reduce length if we add the dots
         */
        if (addDots) {
            maxLength = maxLength - 3;

            if (maxLength < 0) {
                maxLength = 0;
            }
        }

        input = input.substring(0, maxLength);

        if (addDots) {
            input = input + StringUtils.defaultString(dots);
        }
    }

    return input;
}

From source file:com.redhat.rhn.frontend.xmlrpc.packages.PackagesHandler.java

/**
 * Get a list of files associated with a package
 * @param loggedInUser The current user//  www . j  av  a2 s.  c om
 * @param pid The id of the package you're looking for
 * @return Returns an Array of maps representing a file
 * @throws FaultException A FaultException is thrown if the errata corresponding to
 * pid cannot be found.
 *
 * @xmlrpc.doc List the files associated with a package.
 * @xmlrpc.param #session_key()
 * @xmlrpc.param #param("int", "packageId")
 * @xmlrpc.returntype
 *   #array()
 *     #struct("file info")
 *       #prop("string", "path")
 *       #prop("string", "type")
 *       #prop("string", "last_modified_date")
 *       #prop("string", "checksum")
 *       #prop("string", "checksum_type")
 *       #prop("int", "size")
 *       #prop("string", "linkto")
 *     #struct_end()
 *   #array_end()
 */
public Object[] listFiles(User loggedInUser, Integer pid) throws FaultException {
    // Get the logged in user
    Package pkg = lookupPackage(loggedInUser, pid);

    List<PackageFileDto> dr = PackageManager.packageFiles(pkg.getId());

    List returnList = new ArrayList();

    /*
     * Loop through the data result and merge the data into the correct format
     */
    for (PackageFileDto file : dr) {
        Map<String, Object> row = new HashMap<String, Object>();

        // Default items (mtime and file_size cannot be null)
        row.put("path", StringUtils.defaultString(file.getName()));
        row.put("last_modified_date", file.getMtime());
        row.put("size", file.getFileSize());
        row.put("linkto", StringUtils.defaultString(file.getLinkto()));
        row.put("checksum", StringUtils.defaultString(file.getChecksum()));
        row.put("checksum_type", StringUtils.defaultString(file.getChecksumtype()));

        // Determine the file_type
        if (file.getChecksum() != null) {
            row.put("type", "file");
        } else {
            if (file.getLinkto() != null) {
                row.put("type", "symlink");
            } else {
                row.put("type", "directory");
            }
        }

        returnList.add(row);
    }

    return returnList.toArray();
}

From source file:dk.dma.epd.common.prototype.settings.EnavSettings.java

public void setProperties(Properties props) {
    props.put(PREFIX + "defaultWindWarnLimit", Double.toString(defaultWindWarnLimit));
    props.put(PREFIX + "defaultCurrentWarnLimit", Double.toString(defaultCurrentWarnLimit));
    props.put(PREFIX + "defaultWaveWarnLimit", Double.toString(defaultWaveWarnLimit));
    props.put(PREFIX + "defaultCurrentLow", Double.toString(defaultCurrentLow));
    props.put(PREFIX + "defaultCurrentMedium", Double.toString(defaultCurrentMedium));
    props.put(PREFIX + "defaultWaveLow", Double.toString(defaultWaveLow));
    props.put(PREFIX + "defaultWaveMedium", Double.toString(defaultWaveMedium));
    props.put(PREFIX + "serverName", serverName);
    props.put(PREFIX + "httpPort", Integer.toString(httpPort));
    props.put(PREFIX + "connectTimeout", Integer.toString(connectTimeout));
    props.put(PREFIX + "readTimeout", Integer.toString(readTimeout));
    props.put(PREFIX + "metocTtl", Integer.toString(metocTtl));
    props.put(PREFIX + "activeRouteMetocPollInterval", Integer.toString(activeRouteMetocPollInterval));
    props.put(PREFIX + "metocTimeDiffTolerance", Integer.toString(metocTimeDiffTolerance));
    props.put(PREFIX + "msiPollInterval", Integer.toString(msiPollInterval));
    props.put(PREFIX + "msiTextboxesVisibleAtScale", Integer.toString(msiTextboxesVisibleAtScale));
    props.put(PREFIX + "msiRelevanceGpsUpdateRange", Double.toString(msiRelevanceGpsUpdateRange));
    props.put(PREFIX + "msiRelevanceFromOwnShipRange", Double.toString(msiRelevanceFromOwnShipRange));
    props.put(PREFIX + "msiVisibilityFromNewWaypoint", Double.toString(msiVisibilityFromNewWaypoint));
    props.put(PREFIX + "msiFilter", Boolean.toString(msiFilter));
    props.put(PREFIX + "msiNmServiceId", StringUtils.defaultString(msiNmServiceId));
    props.put(PREFIX + "monaLisaServer", monaLisaServer);
    props.put(PREFIX + "monaLisaPort", Integer.toString(monaLisaPort));
    props.put(PREFIX + "routeTimeToLive", Long.toString(this.getRouteTimeToLive()));
    props.put(PREFIX + "filterDistance", Double.toString(this.getFilterDistance()));
    props.put(PREFIX + "markerDistance", Double.toString(this.getMarkerDistance()));
    props.put(PREFIX + "alertDistance", Double.toString(this.getAlertDistance()));
}

From source file:ca.uhn.hunit.iface.AbstractJmsInterfaceImpl.java

private void init() {
    myUsername = StringUtils.defaultString(myUsername);
    myPassword = StringUtils.defaultString(myPassword);
}