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

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

Introduction

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

Prototype

public static String stripToEmpty(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning an empty String if null input.

Usage

From source file:gate.corpora.twitter.Population.java

private static Document newDocument(URL url, int counter, int digits) throws ResourceInstantiationException {
    Document document = Factory.newDocument("");
    String code = StringUtils.leftPad(Integer.toString(counter), digits, '0');
    String name = StringUtils.stripToEmpty(StringUtils.substring(url.getPath(), 1)) + "_" + code;
    document.setName(name);/*from   ww  w  .  j  a v  a2s. c o  m*/
    document.setSourceUrl(url);
    document.getFeatures().put(Document.DOCUMENT_MIME_TYPE_PARAMETER_NAME, TweetUtils.MIME_TYPE);
    document.getFeatures().put("gate.SourceURL", url.toString());
    return document;
}

From source file:com.adobe.acs.commons.users.impl.Ace.java

@SuppressWarnings("squid:S3776")
public Ace(String raw) throws EnsureAuthorizableException {
    String[] segments = StringUtils.split(raw, PARAM_DELIMITER);

    for (String segment : segments) {
        AbstractMap.SimpleEntry<String, String> entry = ParameterUtil.toSimpleEntry(segment,
                KEY_VALUE_SEPARATOR);/*www .j a v a  2 s  .c  o m*/

        if (entry == null) {
            continue;
        }
        if (StringUtils.equals(PROP_TYPE, entry.getKey())) {
            this.type = StringUtils.stripToNull(entry.getValue());
        } else if (StringUtils.equals(PROP_PATH, entry.getKey())) {
            this.path = StringUtils.stripToNull(entry.getValue());
        } else if (StringUtils.equals(PROP_REP_GLOB, entry.getKey())) {
            this.repGlob = StringUtils.stripToEmpty(entry.getValue());
        } else if (StringUtils.equals(PROP_REP_NT_NAMES, entry.getKey())) {
            this.repNtNames.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_REP_ITEM_NAMES, entry.getKey())) {
            this.repItemNames.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_REP_PREFIXES, entry.getKey())) {
            this.repPrefixes.addAll(Arrays
                    .asList(StringUtils.split(StringUtils.stripToEmpty(entry.getValue()), LIST_SEPARATOR)));
        } else if (StringUtils.equals(PROP_PRIVILEGES, entry.getKey())) {
            for (String privilege : StringUtils.split(entry.getValue(), LIST_SEPARATOR)) {
                privilege = StringUtils.stripToNull(privilege);
                if (privilege != null) {
                    this.privilegeNames.add(privilege);
                }
            }
        }
    }

    validate(this.type, this.path, this.privilegeNames);
}

From source file:com.activecq.api.utils.ValidationUtil.java

/**
 * Checks if the value @ key meets the length conditions
 *
 * @param form/*  www .j  a  v a 2 s .c o  m*/
 * @param key
 * @param comparison
 * @param length
 * @return
 */
public static boolean isLength(ActiveForm form, String key, Comparisons comparison, int length) {
    if (!isPresent(form, key)) {
        return false;
    }

    int dataLength;
    Object val = form.get(key);

    if (val instanceof String) {
        dataLength = StringUtils.stripToEmpty((String) val).length();
    } else {
        return false;
    }

    if (Comparisons.EQUAL_TO.equals(comparison)) {
        return (dataLength == length);
    } else if (Comparisons.GREATER_THAN.equals(comparison)) {
        return (dataLength > length);
    } else if (Comparisons.GREATER_THAN_OR_EQUAL_TO.equals(comparison)) {
        return (dataLength >= length);
    } else if (Comparisons.LESS_THAN.equals(comparison)) {
        return (dataLength < length);
    } else if (Comparisons.LESS_THAN_OR_EQUAL_TO.equals(comparison)) {
        return (dataLength <= length);
    } else {
        return false;
    }
}

From source file:com.adobe.acs.commons.contentfinder.querybuilder.impl.ContentFinderHitBuilder.java

/**
 * Derives and adds Asset related information to the map representing the hit.
 *
 * @param hit/*from www.  j  a  va2  s. c  o  m*/
 * @param map
 * @return
 * @throws javax.jcr.RepositoryException
 */
private static Map<String, Object> addAssetData(final Asset asset, final Hit hit, Map<String, Object> map)
        throws RepositoryException {

    String title = asset.getName();

    if (StringUtils.isNotBlank(asset.getMetadataValue(DamConstants.DC_TITLE))) {
        title = asset.getMetadataValue(DamConstants.DC_TITLE);
    }

    // Excerpt
    String excerpt = hit.getExcerpt();
    if (StringUtils.isBlank(hit.getExcerpt())) {
        excerpt = StringUtils.stripToEmpty(asset.getMetadataValue(DamConstants.DC_DESCRIPTION));
        if (excerpt.length() > MAX_EXCERPT_LENGTH) {
            excerpt = StringUtils.substring(excerpt, 0, (MAX_EXCERPT_LENGTH - ELLIPSE_LENGTH)) + "...";
        }
    }

    map.put(CF_PATH, asset.getPath());
    map.put(CF_NAME, asset.getName());
    map.put(CF_TITLE, title);
    map.put(CF_EXCERPT, excerpt);
    map.put(CF_MIMETYPE, asset.getMimeType());
    map.put(CF_SIZE, getSize(asset));
    map.put(CF_CACHE_KILLER, getCacheKiller(asset));
    map.put(CF_TYPE, "Asset");
    map.put(CF_LAST_MODIFIED, getLastModified(asset));

    return map;
}

From source file:com.adobe.acs.commons.forms.Form.java

/**
 * Gets the error message//w  w  w.j  a va 2  s .c  o m
 *
 * @param key
 * @return
 */
public String getError(final String key) {
    final String val = this.errors.get(key);
    return StringUtils.stripToEmpty(val);
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java

public GenericServerConfigForm(final Project project, final UserCfg defaultUser, final Connector tester) {
    this.project = project;
    $$$setupUI$$$();/* ww w. j  av  a2  s  . com*/
    testConnection.addActionListener(
            new TestConnectionListener(project, tester, new TestConnectionListener.ServerDataProvider() {
                public ServerData getServer() {
                    synchronized (GenericServerConfigForm.this) {
                        saveData();
                        ServerData.Builder builder = new ServerData.Builder(serverCfg);
                        builder.defaultUser(defaultUser);
                        return builder.build();
                    }
                }
            }, this));
    serverUrl.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            adjustUrl();
        }
    });

    listener = new DocumentListener() {

        public void insertUpdate(DocumentEvent e) {
            setServerState();
        }

        public void removeUpdate(DocumentEvent e) {
            setServerState();
        }

        public void changedUpdate(DocumentEvent e) {
            setServerState();
        }
    };

    useDefault.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            enableDisableUserPassword();
        }
    });

    cbEnabled.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeEvent) {

        }
    });

    urlDocumentListener = new DocumentAdapter() {
        protected void textChanged(DocumentEvent documentEvent) {
            enableDisableSever(false);
        }
    };

    serverName.addFocusListener(new FocusAdapter() {
        public void focusLost(final FocusEvent e) {
            if (StringUtils.stripToEmpty(serverName.getText()).length() == 0) {
                serverName.setText(originalServerName);
            }
        }
    });

    enableDisableSever(true);
    enableDisableUserPassword();
}

From source file:com.inkubator.hrm.web.personalia.LoanCanceledFormController.java

public List<EmpData> doAutoCompleteEmployee(String param) {
    List<EmpData> empDatas = new ArrayList<EmpData>();
    try {/*  w  w w .  jav a2s  . c om*/
        empDatas = empDataService.getAllDataByNameOrNik(StringUtils.stripToEmpty(param),
                HrmUserInfoUtil.getCompanyId());
    } catch (Exception e) {
        LOGGER.error("Error", e);
    }
    return empDatas;
}

From source file:com.activecq.api.utils.ValidationUtil.java

/**
 * Checks if the value @ key matches regex
 *
 * @param form/*  w  w w  . j  a va  2s. co  m*/
 * @param key
 * @param regex
 * @return
 */
public static boolean isOfFormat(ActiveForm form, String key, String regex) {
    if (!isPresent(form, key)) {
        return false;
    }

    String val = StringUtils.stripToEmpty(form.get(key));

    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(val);

    return m.matches();
}

From source file:com.da.img.BoradList.java

protected void executeURL(String p_page) throws IOException, ClientProtocolException, URISyntaxException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//from  w ww  . j a  v a2s  . c o  m
        HttpGet httpget = executeLogin(httpclient);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = "";
        // /bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35788
        // String strUrl = "http://story.soraspace.info/bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35821";
        //  : http://photo.soraspace.info/album/theme/pic_list.php?p_anum=173&p_ix=3&p_gnum=351
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=1&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=2&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=351&p_gnum=351&p_soption=&p_stxt=

        String imgUrl;
        // 351 : mom , 481: lip
        String SaveFilePath = "c:/temp/173";
        String p_gnum = "351";
        List<ImageVo> lst = null;
        int max_page = 10000;
        String output = "";
        InputStream istream;
        int init_page = 1;
        if (!"".equals(StringUtils.stripToEmpty(p_page))) {
            init_page = Integer.parseInt(p_page);
        }
        for (int i = init_page; i < max_page; i++) {
            lst = getBoardList(httpclient, httpget, responseHandler, p_gnum, String.valueOf(i));
            for (ImageVo vo : lst) {
                // continue;
                imgUrl = vo.getImgUrl(); //"http://photo2.soraspace.info/thumbnail.php?p_imgwidth=1104&p_imgheight=1104&p_width=1104&p_height=1104&p_imgfile=%2F%2F201205%2F22%2Fsk650%2F%2F1501694.jpg&verify=%2F%90%F9%B7%D6%D0%12%0EF%17%B8M%DA%A4L%C4";
                istream = getDownloadUrlInputStream(httpclient, httpget, imgUrl);
                // System.out.println("result = " + istream.toString());
                output = SaveFilePath + "/" + p_gnum + "/"
                        + org.apache.commons.lang.StringUtils.leftPad(String.valueOf(i), 4, "0") + "/"
                        + vo.getFileName();
                fileDownCopy(output, istream);
                if (istream != null) {
                    istream.close();
                }
            }
        }

    } catch (Exception ex) {
        System.out.println("ERROR: " + ex.getLocalizedMessage());
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:gov.nih.nci.calims2.taglib.form.SingleSelectTag.java

@SuppressWarnings("unchecked")
private String getSelectedId() {
    if (selected == null) {
        return "";
    }//ww  w  .  ja  va 2s  . co m
    if (collectionType == SelectCollectionType.ENUMERATIONS) {
        return ((I18nEnumeration) selected).getName();
    }
    if (optionCreatorCallback != null) {
        OptionCreatorCallback<Object> callback = (OptionCreatorCallback<Object>) optionCreatorCallback;
        return StringUtils.stripToEmpty(callback.getId(selected));
    }
    Expression idProperty = propertyMap.get("id");
    EvaluationContext context = new StandardEvaluationContext(selected);
    return StringUtils.stripToEmpty(SingleSelectHelper.evaluateExpression(idProperty, context));
}