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

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

Introduction

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

Prototype

public static String defaultString(final String str) 

Source Link

Document

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

 StringUtils.defaultString(null)  = "" StringUtils.defaultString("")    = "" StringUtils.defaultString("bat") = "bat" 

Usage

From source file:org.blocks4j.reconf.client.constructors.StringParser.java

public StringParser(MethodData arg) {
    this.data = arg;

    if (StringUtils.isEmpty(data.getValue())) {
        return;//from   w  w w .  ja va 2s  .c o  m
    }

    String trimmed = StringUtils.defaultString(StringUtils.trim(data.getValue()));
    if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) {
        throw new RuntimeException(msg.format("error.complex.type", data.getMethod()));
    }

    String wholeValue = StringUtils.substring(trimmed, 1, trimmed.length() - 1);
    extractTokens(wholeValue);
    if (openClose.size() % 2 != 0) {
        throw new IllegalArgumentException(
                msg.format("error.invalid.string", data.getValue(), data.getMethod()));
    }
}

From source file:org.blocks4j.reconf.client.elements.FullPropertyElement.java

public static String from(String product, String component, String name) {
    return StringUtils.upperCase(StringUtils.defaultString(product)) + "/"
            + StringUtils.upperCase(StringUtils.defaultString(component)) + "/"
            + StringUtils.upperCase(StringUtils.defaultString(name));
}

From source file:org.blocks4j.reconf.client.proxy.Customization.java

@Override
public String toString() {
    return new StringBuilder().append("productPrefix[").append(StringUtils.defaultString(productPrefix))
            .append("] ").append("productSuffix[").append(StringUtils.defaultString(productSuffix)).append("] ")
            .append("componentPrefix [").append(StringUtils.defaultString(componentPrefix)).append("] ")
            .append("componentSuffix [").append(StringUtils.defaultString(componentSuffix)).append("] ")
            .append("keyPrefix [").append(StringUtils.defaultString(namePrefix)).append("] ")
            .append("keySuffix [").append(StringUtils.defaultString(nameSuffix)).append("] ").toString();
}

From source file:org.codice.git.hook.Hook.java

/**
 * Entry point for the git hook processing. Invoked by the individual git scripts
 * in the .git/hooks directory. Each script provides the class name of the (java) hook
 * to execute along with the parameters that git passed as part of the hook call.
 * <p/>//from w  ww .  j  av a 2s  .  c o  m
 * The java handler is instantiated, the class name is removed from the arguments,
 * and the executeHook method of the java hook is invoked.
 *
 * @param args class name of java hook handler plus original git arguments
 */
public static void main(String[] args) {
    try {
        if (ArrayUtils.isEmpty(args)) {
            LOGGER.log(Level.WARNING, "Missing arguments");
            System.exit(ERROR_CODE);
        }
        if (args.length < 1) {
            LOGGER.log(Level.WARNING, "Missing basedir argument");
            System.exit(ERROR_CODE);
        }
        if (args.length < 2) {
            LOGGER.log(Level.WARNING, "Missing maven settings argument");
            System.exit(ERROR_CODE);
        }
        if (args.length < 3) {
            LOGGER.log(Level.WARNING, "Missing hook class argument");
            System.exit(ERROR_CODE);
        }
        final RepositoryHandler handler = new GitHandler(new File(args[0]));
        final String settings = StringUtils.defaultString(args[1]);
        final Hook hook = (Hook) Class.forName(args[2]).getConstructor(RepositoryHandler.class)
                .newInstance(handler);
        final String[] hargs = new String[args.length - 3];

        System.arraycopy(args, 3, hargs, 0, hargs.length);
        LOGGER.log(Level.FINE, "Hook being called with arguments: {0}", ArrayUtils.toString(args));
        GitHooks.downloadBlacklist(handler, settings, false);
        if (hook.executeHook(hargs)) {
            System.exit(ERROR_CODE);
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Exception caught: " + e.getMessage(), e);
        System.exit(ERROR_CODE);
    }
}

From source file:org.csstudio.diirt.util.core.preferences.DIIRTPreferences.java

/**
 * Check if the given name is used to save default values or not.
 *
 * @param preferenceName The preference name.
 * @return {@code true} if the given name is used to save default values.
 *//*w  w w  .  java 2 s .  c  o  m*/
public static boolean isDefaultPreferenceName(String preferenceName) {
    return StringUtils.defaultString(preferenceName).startsWith(DEFAULT_PREFIX);
}

From source file:org.csstudio.diirt.util.core.preferences.pojo.ChannelAccess.java

/**
 * Update defaults and values in the given preferences set.
 *
 * @param preferencesSet The preferences set.
 *//*from  ww w. ja  va2 s .c o m*/
public void updateDefaultsAndValues(DIIRTPreferences preferencesSet) {

    if (dataSourceOptions != null) {

        String vlaName = dataSourceOptions.variableArraySupport().representation();
        String mmName = dataSourceOptions.monitorMask().name();
        int mmcValue = dataSourceOptions.monitorMaskCustomValue();

        preferencesSet.setDefaultBoolean(PREF_DBE_PROPERTY_SUPPORTED, dataSourceOptions.dbePropertySupported);
        preferencesSet.setDefaultBoolean(PREF_HONOR_ZERO_PRECISION, dataSourceOptions.honorZeroPrecision);
        preferencesSet.setDefaultString(PREF_MONITOR_MASK, mmName);
        preferencesSet.setDefaultInteger(PREF_CUSTOM_MASK, mmcValue);
        preferencesSet.setDefaultBoolean(PREF_VALUE_RTYP_MONITOR, dataSourceOptions.rtypeValueOnly);
        preferencesSet.setDefaultString(PREF_VARIABLE_LENGTH_ARRAY, vlaName);

    }

    if (jcaContext != null) {

        preferencesSet.setDefaultString(PREF_ADDR_LIST, StringUtils.defaultString(jcaContext.addrList));
        preferencesSet.setDefaultBoolean(PREF_AUTO_ADDR_LIST, jcaContext.autoAddrList);
        preferencesSet.setDefaultDouble(PREF_BEACON_PERIOD, jcaContext.beaconPeriod);
        preferencesSet.setDefaultDouble(PREF_CONNECTION_TIMEOUT, jcaContext.connectionTimeout);
        preferencesSet.setDefaultInteger(PREF_MAX_ARRAY_SIZE, jcaContext.maxArrayBytes);
        //  JCA no more available since DIIRT 3.1.7 ---------------------------
        //preferencesSet.setDefaultBoolean(PREF_PURE_JAVA,         jcaContext.pureJava);
        //  -------------------------------------------------------------------
        preferencesSet.setDefaultInteger(PREF_REPEATER_PORT, jcaContext.repeaterPort);
        preferencesSet.setDefaultInteger(PREF_SERVER_PORT, jcaContext.serverPort);

    }

    updateValues(preferencesSet);

}

From source file:org.csstudio.diirt.util.core.preferences.pojo.ChannelAccess.java

/**
 * Update values in the given preferences set.
 *
 * @param preferencesSet The preferences set.
 *///from   w  ww .ja va 2  s  .  co  m
public void updateValues(DIIRTPreferences preferencesSet) {

    if (dataSourceOptions != null) {

        String vlaName = dataSourceOptions.variableArraySupport().representation();
        String mmName = dataSourceOptions.monitorMask().name();
        int mmcValue = dataSourceOptions.monitorMaskCustomValue();

        preferencesSet.setBoolean(PREF_DBE_PROPERTY_SUPPORTED, dataSourceOptions.dbePropertySupported);
        preferencesSet.setBoolean(PREF_HONOR_ZERO_PRECISION, dataSourceOptions.honorZeroPrecision);
        preferencesSet.setString(PREF_MONITOR_MASK, mmName);
        preferencesSet.setInteger(PREF_CUSTOM_MASK, mmcValue);
        preferencesSet.setBoolean(PREF_VALUE_RTYP_MONITOR, dataSourceOptions.rtypeValueOnly);
        preferencesSet.setString(PREF_VARIABLE_LENGTH_ARRAY, vlaName);

    }

    if (jcaContext != null) {
        preferencesSet.setString(PREF_ADDR_LIST, StringUtils.defaultString(jcaContext.addrList));
        preferencesSet.setBoolean(PREF_AUTO_ADDR_LIST, jcaContext.autoAddrList);
        preferencesSet.setDouble(PREF_BEACON_PERIOD, jcaContext.beaconPeriod);
        preferencesSet.setDouble(PREF_CONNECTION_TIMEOUT, jcaContext.connectionTimeout);
        preferencesSet.setInteger(PREF_MAX_ARRAY_SIZE, jcaContext.maxArrayBytes);
        //  JCA no more available since DIIRT 3.1.7 ---------------------------
        //preferencesSet.setBoolean(PREF_PURE_JAVA, jcaContext.pureJava);
        //  -------------------------------------------------------------------
        preferencesSet.setInteger(PREF_REPEATER_PORT, jcaContext.repeaterPort);
        preferencesSet.setInteger(PREF_SERVER_PORT, jcaContext.serverPort);
    }

}

From source file:org.dbflute.intro.app.logic.client.ClientUpdateLogic.java

private void replaceDfpropDatabaseInfoMap(ClientModel clientModel, String clientProject) {
    final File dfpropDatabaseInfoMap = clientPhysicalLogic.findDfpropDatabaseInfoMap(clientProject);
    final String databaseInfoMapPath = dfpropDatabaseInfoMap.toString();
    final DbConnectionBox box = clientModel.getDatabaseInfoMap().getDbConnectionBox();

    new FileTextIO().encodeAsUTF8().rewriteFilteringLine(databaseInfoMapPath, line -> {
        String trimmedLine = line.trim();
        if (trimmedLine.startsWith("; url") && line.contains("=")) {
            return "    ; url      = " + StringUtils.defaultString(box.getUrl());
        }//from   w  w w  .j ava  2  s  . co m
        if (trimmedLine.startsWith("; schema") && line.contains("=")) {
            return "    ; schema   = " + StringUtils.defaultString(box.getSchema());
        }
        if (trimmedLine.startsWith("; user") && line.contains("=")) {
            return "    ; user     = " + StringUtils.defaultString(box.getUser());
        }
        if (trimmedLine.startsWith("; password") && line.contains("=")) {
            return "    ; password = " + StringUtils.defaultString(box.getPassword());
        }
        return line;
    });
}

From source file:org.dbgl.model.Mount.java

public Mount(final String mount) throws InvalidMountstringException {
    init();//ww  w.  ja va 2s  . co m
    Matcher mountMatcher = MOUNT_PATRN.matcher(mount);
    Matcher imgmountMatcher = IMGMOUNT_PATRN.matcher(mount);

    if (mountMatcher.matches()) {
        if (mountMatcher.group(1) != null) {
            unmounted = true;
            driveletter = Character.toUpperCase(mountMatcher.group(1).charAt(0));
            return;
        }
        driveletter = Character.toUpperCase(mountMatcher.group(2).charAt(0));
        String mountLocation = StringUtils.strip(PlatformUtils.toNativePath(mountMatcher.group(3)), "\"");
        if (FileUtils.isPhysFS(mountLocation))
            initForPhysFS(mountLocation);
        else
            path = new File[] { FileUtils.makeRelativeToDosroot(FileUtils.canonicalToDosroot(mountLocation)) };
        mountAs = StringUtils.defaultString(mountMatcher.group(4));
        label = StringUtils.defaultString(mountMatcher.group(5));
        lowlevelCD = StringUtils.defaultString(mountMatcher.group(6));
        freesize = StringUtils.defaultString(mountMatcher.group(7));
        useCD = StringUtils.defaultString(mountMatcher.group(8));
    } else if (imgmountMatcher.matches()) {
        mountingType = MountingType.IMAGE;
        driveletter = Character.toUpperCase(imgmountMatcher.group(1).charAt(0));
        String[] paths = StringUtils.stripAll(PlatformUtils.toNativePath(imgmountMatcher.group(2)).trim()
                .split("\\s(?=([^\"]*\"[^\"]*\")*[^\"]*$)"), "\"");
        path = new File[paths.length];
        for (int i = 0; i < paths.length; i++)
            path[i] = FileUtils.makeRelativeToDosroot(FileUtils.canonicalToDosroot(paths[i]));
        mountAs = StringUtils.defaultString(imgmountMatcher.group(3));
        if (mountAs.equalsIgnoreCase("cdrom"))
            mountAs = "iso";
        fs = StringUtils.defaultString(imgmountMatcher.group(4));
        size = StringUtils.defaultString(imgmountMatcher.group(5));
    } else {
        throw new InvalidMountstringException();
    }
}

From source file:org.dbgl.util.searchengine.TheGamesDBSearchEngine.java

public WebProfile getEntryDetailedInformation(final WebProfile entry) throws UnknownHostException, IOException {
    WebProfile result = new WebProfile();

    result.setTitle(entry.getTitle());/*from   w ww  .ja v a2  s.com*/
    result.setYear(entry.getYear());
    result.setUrl(entry.getUrl());
    result.setPlatform(entry.getPlatform());

    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(getInputStream(entry.getUrl()));

        Element gameNode = (Element) doc.getFirstChild();

        result.setDeveloperName(StringUtils.defaultString(XmlUtils.getTextValue(gameNode, "Developer")));
        result.setPublisherName(StringUtils.defaultString(XmlUtils.getTextValue(gameNode, "Publisher")));
        result.setNotes(StringUtils.defaultString(XmlUtils.getTextValue(gameNode, "Overview")));
        String rating = XmlUtils.getTextValue(gameNode, "Rating");
        if (rating != null)
            result.setRank((int) ((Double.parseDouble(rating) * 10.0) + 0.5));
        else
            result.setRank(0);
        result.setCoreGameCoverUrl(XmlUtils.getTextValue(gameNode, "baseImgUrl"));
        result.setXmlElementWithAllImages(XmlUtils.getNode(gameNode, "Images"));

        StringBuffer genre = new StringBuffer();
        Element el = XmlUtils.getNode(gameNode, "Genres");
        if (el != null) {
            NodeList genreNodes = el.getChildNodes();
            for (int i = 0; i < genreNodes.getLength(); i++) {
                if (i > 0)
                    genre.append(", ");
                genre.append(genreNodes.item(i).getFirstChild().getNodeValue());
            }
        }
        result.setGenre(genre.toString());

        result.setUrl(absoluteUrl(THE_GAMES_DB_HOST_NAME, "/game/" + XmlUtils.getTextValue(gameNode, "id")));

    } catch (ParserConfigurationException | SAXException e) {
        throw new IOException(e);
    }

    return result;
}