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

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

Introduction

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

Prototype

public static String trimToNull(final 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:net.lmxm.ute.executers.tasks.FileSystemDeleteTaskExecuter.java

/**
 * Delete files.//from w  ww .  j ava  2  s. c om
 *
 * @param path        the path
 * @param files       the files
 * @param stopOnError the stop on error
 */
protected void deleteFiles(final String path, final List<FileReference> files, final boolean stopOnError) {
    final String prefix = "execute() :";

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("{} entered", prefix);
        LOGGER.debug("{} path={}", prefix, path);
        LOGGER.debug("{} files={}", prefix, files);
        LOGGER.debug("{} stopOnError={}", prefix, stopOnError);
    }

    final String pathTrimmed = StringUtils.trimToNull(path);

    checkArgument(pathTrimmed != null, "Path may not be blank");

    final File pathFile = new File(pathTrimmed);

    if (!pathFile.exists()) {
        LOGGER.debug("{} path does not exist, returning", prefix);
        StatusChangeEventBus.info(FILE_DELETE_PATH_DOES_NOT_EXIST_ERROR, getJob(), pathFile.getAbsolutePath());
        return;
    }

    if (pathFile.isFile()) {
        LOGGER.debug("{} deleting file {}", prefix, pathFile.getName());

        StatusChangeEventBus.info(FILE_DELETE_FILE_DELETE_STARTED, getJob(), pathFile.getAbsolutePath());

        if (forceDelete(pathFile, stopOnError)) {
            StatusChangeEventBus.info(FILE_DELETE_FILE_DELETE_FINISHED, getJob(), pathFile.getAbsolutePath());
        }
    } else if (pathFile.isDirectory()) {
        LOGGER.debug("{} path is a directory", prefix);

        if (CollectionUtils.isEmpty(files)) {
            LOGGER.debug("{} deleting directory {}", prefix, pathFile.getName());

            StatusChangeEventBus.info(FILE_DELETE_DIRECTORY_DELETE_STARTED, getJob(),
                    pathFile.getAbsolutePath());

            if (forceDelete(pathFile, stopOnError)) {
                StatusChangeEventBus.info(FILE_DELETE_DIRECTORY_DELETE_FINISHED, getJob(),
                        pathFile.getAbsolutePath());
            }
        } else {
            LOGGER.debug("{} deleting {} files in a directory", prefix, prefix);

            for (final FileReference file : files) {
                final String fileName = file.getName();

                LOGGER.debug("{} deleting file {}", prefix, fileName);

                StatusChangeEventBus.info(FILE_DELETE_FILE_DELETE_STARTED, getJob(), fileName);

                if (forceDelete(new File(pathFile, fileName), stopOnError)) {
                    StatusChangeEventBus.info(FILE_DELETE_FILE_DELETE_FINISHED, getJob(), fileName);
                }
            }
        }
    } else {
        LOGGER.error("{} path is not a file or directory, returning", prefix);
    }

    LOGGER.debug("{} leaving", prefix);
}

From source file:io.hakbot.controller.plugin.RemoteInstanceAutoConfig.java

private RemoteInstance generateInstance(Plugin.Type pluginType, String pluginId, String instanceIdentifier) {
    final String type = pluginType.name().toLowerCase();
    final RemoteInstance instance = new RemoteInstance();
    instance.setAlias(StringUtils.trimToNull(
            Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".alias")));
    instance.setUsername(StringUtils.trimToNull(
            Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".username")));
    instance.setPassword(StringUtils.trimToNull(
            Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".password")));
    instance.setApiKey(StringUtils.trimToNull(
            Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".apikey")));
    instance.setToken(StringUtils.trimToNull(
            Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".token")));
    try {/*w  ww .  ja v  a2  s . c  o m*/
        instance.setURL(new URL(StringUtils.trimToNull(
                Config.getInstance().getProperty(type + "." + pluginId + "." + instanceIdentifier + ".url"))));
    } catch (MalformedURLException e) {
        LOGGER.error("The URL specified for the server instance is not valid. " + e.getMessage());
    }
    return instance;
}

From source file:at.bitfire.davdroid.ui.CreateAddressBookActivity.java

public void onCreateCollection(MenuItem item) {
    boolean ok = true;
    CollectionInfo info = new CollectionInfo();

    Spinner spinner = (Spinner) findViewById(R.id.home_sets);
    String homeSet = (String) spinner.getSelectedItem();

    EditText edit = (EditText) findViewById(R.id.display_name);
    info.displayName = edit.getText().toString();
    if (TextUtils.isEmpty(info.displayName)) {
        edit.setError(getString(R.string.create_collection_display_name_required));
        ok = false;//  w  w  w.j  a  va 2 s . co  m
    }

    edit = (EditText) findViewById(R.id.description);
    info.description = StringUtils.trimToNull(edit.getText().toString());

    if (ok) {
        info.type = CollectionInfo.Type.ADDRESS_BOOK;
        info.url = HttpUrl.parse(homeSet).resolve(UUID.randomUUID().toString() + "/").toString();
        CreateCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
    }
}

From source file:com.neocotic.blingaer.common.dao.DAOLocator.java

/**
 * Prevents external invocation to support singleton pattern.
 * /*from w ww.ja v a2  s  . c o  m*/
 * @throws BlingaerRuntimeException
 *             If datastore property could not be found.
 */
DAOLocator() throws BlingaerRuntimeException {
    dataStore = StringUtils.trimToNull(System.getProperty(DATA_STORE_PROPERTY));

    if (dataStore == null) {
        throw new BlingaerRuntimeException("Could not locate datastore property: " + DATA_STORE_PROPERTY);
    }
}

From source file:net.centro.rtb.monitoringcenter.infos.AppInfo.java

public static AppInfo create(String applicationName) {
    Preconditions.checkNotNull(applicationName);

    AppInfo appInfo = new AppInfo();

    appInfo.applicationName = applicationName;

    Properties properties = new Properties();
    try {// w  w w .  jav  a2 s .c om
        properties.load(AppInfo.class.getResourceAsStream(BUILD_INFO_PROPERTIES_FILE));
    } catch (Exception e) {
        logger.debug("Error loading the buildInfo file from the classpath: {}", BUILD_INFO_PROPERTIES_FILE, e);

        if (InterruptedException.class.isInstance(e)) {
            Thread.currentThread().interrupt();
        }

        return appInfo;
    }

    appInfo.applicationVersion = StringUtils.trimToNull(properties.getProperty("build.version"));
    appInfo.buildTimestamp = parseDate(properties.getProperty("build.timestamp"));
    appInfo.buildUsername = StringUtils.trimToNull(properties.getProperty("build.username"));

    appInfo.branchName = StringUtils.trimToNull(properties.getProperty("vcs.branch"));
    appInfo.commitId = StringUtils.trimToNull(properties.getProperty("vcs.commit.id"));
    appInfo.commitMessage = StringUtils.trimToNull(properties.getProperty("vcs.commit.message"));
    appInfo.commitTimestamp = parseDate(properties.getProperty("vcs.commit.timestamp"));
    appInfo.commitAuthor = StringUtils.trimToNull(properties.getProperty("vcs.commit.author"));

    return appInfo;
}

From source file:com.threewks.thundr.http.SyntheticHttpServletResponse.java

@Override
public void setCharacterEncoding(String charset) {
    this.characterEncoding = StringUtils.trimToNull(StringUtils.upperCase(charset));
}

From source file:hoot.services.validators.wps.ReviewInputParamsValidator.java

/**
 * Parses and validates a set of input parameters to a deegree WPS review service method
 * //from  w ww.j ava2s .c  om
 * @param name name of the parameter
 * @param type type of the parameter
 * @param rangeMin minimum allowable value for numeric parameters
 * @param rangeMax maximum allowable value for numeric parameters
 * @param optional if true; the parameter is considered optional and must not be present
 * @param defaultValue a default value to assign to the parameter, if it has no value
 * @return a parameter value
 * @throws Exception
 */
public Object validateAndParseInputParam(final String name, final Object type, final Object rangeMin,
        final Object rangeMax, final boolean optional, final Object defaultValue) throws Exception {
    Object paramValue = null;

    //special case
    if (name.equals("geospatialBounds")) {
        if (inputParams.getParameter("geospatialBounds") == null && defaultValue != null) {
            return new BoundingBox((String) defaultValue);
        } else {
            return new BoundingBox((BoundingBoxInput) inputParams.getParameter("geospatialBounds"));
        }
    }

    ProcessletInput param = inputParams.getParameter(name);
    if ((param == null || ((LiteralInput) param).getValue() == null
            || StringUtils.trimToNull(((LiteralInput) param).getValue().trim()) == null) && !optional) {
        throw new Exception("Invalid input parameter value.  Required parameter: " + name + " not sent to: "
                + ReflectUtils.getCallingClassName());
    }

    if (param == null && defaultValue != null) {
        if (!type.getClass().getName().equals(defaultValue.getClass().getName())) {
            throw new Exception("Invalid input parameter value.  Mismatching input parameter type: "
                    + type.toString() + " and default value type: " + defaultValue.toString()
                    + "for parameter: " + name + " sent to: " + ReflectUtils.getCallingClassName());
        }
        return defaultValue;
    }

    if (param != null) {
        if (((LiteralInput) param).getValue() == null
                || StringUtils.trimToNull(((LiteralInput) param).getValue().trim()) == null) {
            throw new Exception(
                    "Invalid input parameter: " + name + " sent to: " + ReflectUtils.getCallingClassName());
        }

        return validateAndParseParamValueString(((LiteralInput) param).getValue().trim(), name, type, rangeMin,
                rangeMax);
    }

    return paramValue;
}

From source file:com.jayway.restassured.path.xml.config.XmlPathConfig.java

private XmlPathConfig(JAXBObjectMapperFactory jaxbObjectMapperFactory, XmlParserType defaultParserType,
        XmlPathObjectDeserializer defaultDeserializer, String charset, Map<String, Boolean> features,
        Map<String, String> declaredNamespaces, Map<String, Object> properties) {
    charset = StringUtils.trimToNull(charset);
    if (charset == null)
        throw new IllegalArgumentException("Charset cannot be empty");
    this.charset = charset;
    this.defaultDeserializer = defaultDeserializer;
    this.defaultParserType = defaultParserType;
    this.jaxbObjectMapperFactory = jaxbObjectMapperFactory;
    this.features = features;
    this.declaredNamespaces = declaredNamespaces;
    this.properties = properties;
}

From source file:com.alibaba.dubboadmin.web.mvc.governance.WeightsController.java

@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "weights");
    BindingAwareModelMap newModel = (BindingAwareModelMap) model;
    String service = (String) newModel.get("service");
    String address = (String) newModel.get("address");
    service = StringUtils.trimToNull(service);
    address = Tool.getIP(address);
    List<Weight> weights;/* w  w  w.ja v a2s  .co  m*/
    if (service != null && service.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
    } else if (address != null && address.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
    } else {
        weights = OverrideUtils.overridesToWeights(overrideService.findAll());
    }
    model.addAttribute("weights", weights);
    return "governance/screen/weights/index";
}

From source file:eu.openanalytics.rsb.security.X509AuthenticationFilter.java

@Override
protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) {
    if (!StringUtils.equals(request.getHeader(SSL_VERIFIED_HEADER), "SUCCESS")) {
        return null;
    }//from  w  w w.j a  va2 s. co  m

    return StringUtils.trimToNull(request.getHeader(SSL_CLIENT_DN_HEADER));
}