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

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

Introduction

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

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:edu.ku.brc.af.ui.db.TextFieldWithInfo.java

/**
 * Creates the UI for the ComboBox./* w  ww.ja  v a  2  s .  c om*/
 * @param objTitle the title of one object needed for the Info Button
 */
public void init(final String objTitle) {
    setControlSize(textField);

    fieldNames = split(StringUtils.deleteWhitespace(keyName), ","); //$NON-NLS-1$

    try {
        classObj = Class.forName(className);

    } catch (ClassNotFoundException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TextFieldWithInfo.class, ex);
        log.error(ex);
        throw new RuntimeException(ex);
    }

    PanelBuilder builder = new PanelBuilder(new FormLayout("p:g,1px,p", "c:p"), this); //$NON-NLS-1$ //$NON-NLS-2$
    CellConstraints cc = new CellConstraints();

    builder.add(textField, cc.xy(1, 1));

    if (StringUtils.isNotEmpty(displayInfoDialogName)) {
        infoBtn = new JButton(IconManager.getIcon("InfoIcon", IconManager.IconSize.Std16)); //$NON-NLS-1$
        infoBtn.setToolTipText(String.format(getResourceString("ShowRecordInfoTT"), new Object[] { objTitle })); //$NON-NLS-1$
        infoBtn.setFocusable(false);
        infoBtn.setMargin(new Insets(1, 1, 1, 1));
        infoBtn.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        builder.add(infoBtn, cc.xy(3, 1));

        infoBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                createInfoFrame();
            }
        });
    }

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

    bgColor = textField.getBackground();
    if (valtextcolor == null || requiredfieldcolor == null) {
        valtextcolor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        requiredfieldcolor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
    AppPreferences.getRemote().addChangeListener("ui.formatting.requiredfieldcolor", this); //$NON-NLS-1$
}

From source file:com.eluup.flume.sink.elasticsearch.ElasticSearchSink.java

public void configure(Context context) {
    if (!isLocal) {
        if (StringUtils.isNotBlank(context.getString(HOSTNAMES))) {
            serverAddresses = StringUtils.deleteWhitespace(context.getString(HOSTNAMES)).split(",");
        }/*from w w w  . ja v  a 2 s  . co m*/
        Preconditions.checkState(serverAddresses != null && serverAddresses.length > 0,
                "Missing Param:" + HOSTNAMES);
    }

    if (StringUtils.isNotBlank(context.getString(INDEX_NAME))) {
        this.indexName = context.getString(INDEX_NAME);
    }

    if (StringUtils.isNotBlank(context.getString(INDEX_TYPE))) {
        this.indexType = context.getString(INDEX_TYPE);
    }

    if (StringUtils.isNotBlank(context.getString(CLUSTER_NAME))) {
        this.clusterName = context.getString(CLUSTER_NAME);
    }

    if (StringUtils.isNotBlank(context.getString(BATCH_SIZE))) {
        this.batchSize = Integer.parseInt(context.getString(BATCH_SIZE));
    }

    if (StringUtils.isNotBlank(context.getString(TTL))) {
        this.ttlMs = parseTTL(context.getString(TTL));
        Preconditions.checkState(ttlMs > 0, TTL + " must be greater than 0 or not set.");
    }

    if (StringUtils.isNotBlank(context.getString(CLIENT_TYPE))) {
        clientType = context.getString(CLIENT_TYPE);
    }

    elasticSearchClientContext = new Context();

    elasticSearchClientContext.putAll(context.getSubProperties(CLIENT_PREFIX));

    String serializerClazz = DEFAULT_SERIALIZER_CLASS;
    if (StringUtils.isNotBlank(context.getString(SERIALIZER))) {
        serializerClazz = context.getString(SERIALIZER);
    }

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(SERIALIZER_PREFIX));

    try {
        @SuppressWarnings("unchecked")
        Class<? extends Configurable> clazz = (Class<? extends Configurable>) Class.forName(serializerClazz);
        Configurable serializer = clazz.newInstance();

        if (serializer instanceof ElasticSearchIndexRequestBuilderFactory) {
            indexRequestFactory = (ElasticSearchIndexRequestBuilderFactory) serializer;
            indexRequestFactory.configure(serializerContext);
        } else if (serializer instanceof ElasticSearchEventSerializer) {
            eventSerializer = (ElasticSearchEventSerializer) serializer;
            eventSerializer.configure(serializerContext);
        } else {
            throw new IllegalArgumentException(serializerClazz + " is not an ElasticSearchEventSerializer");
        }
    } catch (Exception e) {
        logger.error("Could not instantiate event serializer.", e);
        Throwables.propagate(e);
    }

    if (sinkCounter == null) {
        sinkCounter = new SinkCounter(getName());
    }

    String indexNameBuilderClass = DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(INDEX_NAME_BUILDER);
    }

    Context indexnameBuilderContext = new Context();
    serializerContext.putAll(context.getSubProperties(INDEX_NAME_BUILDER_PREFIX));

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(INDEX_NAME, indexName);
        indexNameBuilder.configure(indexnameBuilderContext);
    } catch (Exception e) {
        logger.error("Could not instantiate index name builder.", e);
        Throwables.propagate(e);
    }

    if (sinkCounter == null) {
        sinkCounter = new SinkCounter(getName());
    }

    Preconditions.checkState(StringUtils.isNotBlank(indexName), "Missing Param:" + INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType), "Missing Param:" + INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName), "Missing Param:" + CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, BATCH_SIZE + " must be greater than 0");
}

From source file:com.ewcms.publication.freemarker.directive.ArticleListDirectiveTest.java

@Test
public void testLoopsTemplate() throws Exception {
    ChannelPublishServiceable channelLoaderService = mock(ChannelPublishServiceable.class);
    Channel channel = new Channel();
    channel.setId(1);//from w w  w .  j  av  a 2  s . com
    channel.setPublicenable(true);
    when(channelLoaderService.getChannelByUrlOrPath(any(Integer.class), any(String.class))).thenReturn(channel);
    when(channelLoaderService.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel);

    ArticlePublishServiceable articleLoaderService = mock(ArticlePublishServiceable.class);
    when(articleLoaderService.findArticleReleasePage(1, 0, 25, true)).thenReturn(createArticleRow(25));
    ArticleListDirective directive = new ArticleListDirective(channelLoaderService, articleLoaderService);

    cfg.setSharedVariable("alist", directive);

    Template template = cfg.getTemplate(getTemplatePath("loop.html"));
    Map<String, Object> params = new HashMap<String, Object>();
    Site site = new Site();
    site.setId(1);
    params.put(GlobalVariable.SITE.toString(), site);
    String value = process(template, params);
    value = StringUtils.deleteWhitespace(value);

    StringBuilder expected = new StringBuilder();
    for (int i = 0; i < 25; i++) {
        expected.append("ewcms").append(i);
    }

    Assert.assertEquals(expected.toString(), value);
}

From source file:com.hisun.flume.sink.elasticsearch.ElasticSearchSink.java

@Override
public void configure(Context context) {
    if (!isLocal) {
        if (StringUtils.isNotBlank(context.getString(HOSTNAMES))) {
            serverAddresses = StringUtils.deleteWhitespace(context.getString(HOSTNAMES)).split(",");
        }//from w  w w . j ava 2 s  .  c om
        Preconditions.checkState(serverAddresses != null && serverAddresses.length > 0,
                "Missing Param:" + HOSTNAMES);
    }

    if (StringUtils.isNotBlank(context.getString(INDEX_NAME))) {
        this.indexName = context.getString(INDEX_NAME);
    }

    if (StringUtils.isNotBlank(context.getString(INDEX_TYPE))) {
        this.indexType = context.getString(INDEX_TYPE);
    }

    if (StringUtils.isNotBlank(context.getString(CLUSTER_NAME))) {
        this.clusterName = context.getString(CLUSTER_NAME);
    }

    if (StringUtils.isNotBlank(context.getString(BATCH_SIZE))) {
        this.batchSize = Integer.parseInt(context.getString(BATCH_SIZE));
    }

    if (StringUtils.isNotBlank(context.getString(TTL))) {
        this.ttlMs = parseTTL(context.getString(TTL));
        Preconditions.checkState(ttlMs > 0, TTL + " must be greater than 0 or not set.");
    }

    if (StringUtils.isNotBlank(context.getString(CLIENT_TYPE))) {
        clientType = context.getString(CLIENT_TYPE);
    }

    elasticSearchClientContext = new Context();
    elasticSearchClientContext.putAll(context.getSubProperties(CLIENT_PREFIX));

    String serializerClazz = DEFAULT_SERIALIZER_CLASS;
    if (StringUtils.isNotBlank(context.getString(SERIALIZER))) {
        serializerClazz = context.getString(SERIALIZER);
    }

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(SERIALIZER_PREFIX));

    try {
        @SuppressWarnings("unchecked")
        Class<? extends Configurable> clazz = (Class<? extends Configurable>) Class.forName(serializerClazz);
        Configurable serializer = clazz.newInstance();

        if (serializer instanceof ElasticSearchIndexRequestBuilderFactory) {
            indexRequestFactory = (ElasticSearchIndexRequestBuilderFactory) serializer;
            indexRequestFactory.configure(serializerContext);
        } else if (serializer instanceof ElasticSearchEventSerializer) {
            eventSerializer = (ElasticSearchEventSerializer) serializer;
            eventSerializer.configure(serializerContext);
        } else {
            throw new IllegalArgumentException(serializerClazz + " is not an ElasticSearchEventSerializer");
        }
    } catch (Exception e) {
        logger.error("Could not instantiate event serializer.", e);
        Throwables.propagate(e);
    }

    if (sinkCounter == null) {
        sinkCounter = new SinkCounter(getName());
    }

    String indexNameBuilderClass = DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(INDEX_NAME_BUILDER);
    }

    Context indexnameBuilderContext = new Context();
    serializerContext.putAll(context.getSubProperties(INDEX_NAME_BUILDER_PREFIX));

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(INDEX_NAME, indexName);
        indexNameBuilder.configure(indexnameBuilderContext);
    } catch (Exception e) {
        logger.error("Could not instantiate index name builder.", e);
        Throwables.propagate(e);
    }

    if (sinkCounter == null) {
        sinkCounter = new SinkCounter(getName());
    }

    Preconditions.checkState(StringUtils.isNotBlank(indexName), "Missing Param:" + INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType), "Missing Param:" + INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName), "Missing Param:" + CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, BATCH_SIZE + " must be greater than 0");
}

From source file:mitm.djigzo.web.services.security.HMACFilterImpl.java

private String calculateHMAC(String input, boolean createASOIfNotExist)
        throws InvalidKeyException, NoSuchAlgorithmException {
    /*/*from  w  w  w .  j  a  v  a 2s  .c  om*/
     * Canonicalize the input before calculating the HMAC
     */
    input = StringUtils.deleteWhitespace(StringUtils.defaultString(input));

    String calculated = null;

    if (createASOIfNotExist || asm.exists(HMAC.class)) {
        calculated = asm.get(HMAC.class).calculateHMAC(input);
    }

    return calculated;
}

From source file:com.ewcms.publication.freemarker.directive.ArticleListDirectiveTest.java

@Test
public void testDefaultRowTemplate() throws Exception {
    ChannelPublishServiceable channelLoaderService = mock(ChannelPublishServiceable.class);
    Channel channel = new Channel();
    channel.setId(1);//from w ww.j  a va 2s .  c om
    channel.setListSize(12);
    channel.setPublicenable(true);
    when(channelLoaderService.getChannelByUrlOrPath(any(Integer.class), any(String.class))).thenReturn(channel);
    when(channelLoaderService.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel);

    ArticlePublishServiceable articleLoaderService = mock(ArticlePublishServiceable.class);
    when(articleLoaderService.findArticleReleasePage(1, 0, 12, false)).thenReturn(createArticleRow(12));
    ArticleListDirective directive = new ArticleListDirective(channelLoaderService, articleLoaderService);

    cfg.setSharedVariable("alist", directive);

    Template template = cfg.getTemplate(getTemplatePath("defaultrow.html"));
    Map<String, Object> params = new HashMap<String, Object>();
    Site site = new Site();
    site.setId(1);
    params.put(GlobalVariable.SITE.toString(), site);
    params.put(GlobalVariable.CHANNEL.toString(), channel);
    String value = process(template, params);
    value = StringUtils.deleteWhitespace(value);

    StringBuilder expected = new StringBuilder();
    for (int i = 0; i < 12; i++) {
        expected.append(i + 1).append(".ewcms").append(i);
    }

    Assert.assertEquals(expected.toString(), value);
}

From source file:com.fortify.bugtracker.common.tgt.processor.AbstractTargetProcessorUpdateIssues.java

/**
 * Compare the current field value from the target against the new value generated
 * based on configuration. If both values are instances of String, this default
 * implementation ignores any whitespace and (HTML) tags, and ignores any 
 * surrounding text/elements in the current field value from the target.
 * @param valueFromTarget//  ww w .j av  a2 s.co m
 * @param valueFromConfig
 * @return true if field values are different, false if they are the same
 */
protected boolean areFieldValuesDifferent(Object valueFromTarget, Object valueFromConfig) {
    if (valueFromTarget.equals(valueFromConfig)) {
        return false;
    } else if (valueFromTarget instanceof String && valueFromConfig instanceof String) {
        String valueFromTargetString = (String) valueFromTarget;
        String valueFromConfigString = (String) valueFromConfig;
        valueFromTargetString = StringUtils.deleteWhitespace(valueFromTargetString).replaceAll("\\<.*?\\>", "");
        valueFromConfigString = StringUtils.deleteWhitespace(valueFromConfigString).replaceAll("\\<.*?\\>", "");

        return !valueFromTargetString.contains(valueFromConfigString);
    } else if (valueFromTarget instanceof Collection && valueFromConfig instanceof Collection) {
        return !CollectionUtils.isEqualCollection((Collection<?>) valueFromTarget,
                (Collection<?>) valueFromConfig);
    }
    return true;
}

From source file:edu.ku.brc.specify.plugins.latlon.DDDDPanel.java

/**
 * @param doDisplay//from   w  w  w  .  jav a  2s  . c om
 * @param txtFields
 * @return
 */
protected String getStringFromFields(final boolean doDisplay, final boolean inclZeroes,
        final ValFormattedTextFieldSingle... txtFields) {
    String degrees = "\u00b0";

    sb.setLength(0);

    int cnt = 0;
    for (ValFormattedTextFieldSingle tf : txtFields) {
        String str = StringUtils.deleteWhitespace(tf.getText());
        if (StringUtils.isEmpty(str)) {
            if (inclZeroes) {
                str = "0";
            } else {
                str = "";
                continue;
            }
        }

        if (cnt > 0)
            sb.append(' ');

        sb.append(str);
        if (doDisplay) {
            if (cnt == 0) {
                sb.append(degrees);

            } else if (txtFields.length == 2) {
                sb.append("'");

            } else if (txtFields.length == 3) {
                sb.append(cnt == 1 ? "'" : "\"");
            }
        }
        cnt++;
    }
    //log.debug("["+sb.toString()+"]");
    return sb.toString();
}

From source file:edu.ku.brc.af.core.db.AutoNumberGeneric.java

/**
 * Builds a new string from a formatter.
 * @param formatter the formatter//from  w w w  .j  av  a2 s .c  o  m
 * @param value the existing largest value
 * @param yearAndIncVal a year,incVal pair
 * @return the new formatted value
 */
protected String buildNewNumber(final UIFieldFormatterIFace formatter, final String value,
        final Pair<BigInteger, BigInteger> yearAndIncVal) {
    String trimmedValue = StringUtils.deleteWhitespace(value);
    int fmtLen = formatter.getLength();
    if (trimmedValue.length() == 0 || (StringUtils.isNotEmpty(value) && formatter.isLengthOK(value.length()))) {
        Pair<Integer, Integer> pos = formatter.getIncPosition();
        if (pos != null) {
            if (pos.second != null) {
                BigInteger incVal = yearAndIncVal.second.add(new BigInteger("1"));

                StringBuilder sb = new StringBuilder(value.substring(0, pos.first));
                String formatStr = "%0" + (pos.second - pos.first) + "d"; //$NON-NLS-1$ //$NON-NLS-2$
                sb.append(String.format(formatStr, incVal));
                if (fmtLen > pos.second) {
                    sb.append(value.substring(pos.second, fmtLen));
                }

                UIFieldFormatterField yearField = formatter.getYear();
                if (yearField != null) {
                    Pair<Integer, Integer> yrPos = formatter.getYearPosition();
                    if (yrPos != null) {
                        sb.replace(yrPos.first, yrPos.second, yearAndIncVal.first.toString());
                    }
                } // else
                  //throw new RuntimeException("There was an error trying to obtain the highest number, there may be a bad value in the database.");
                return sb.toString();
            } // else
              //errorMsg = "There was an error trying to obtain the highest number, there may be a bad value in the database."; //$NON-NLS-1$
        }
        // else
        errorMsg = "Formatter [" + formatter.getName() + "] doesn't have an incrementer field."; //$NON-NLS-1$ //$NON-NLS-2$
    }
    return null;
}

From source file:edu.ku.brc.specify.plugins.latlon.DDDDPanel.java

/**
 * @param txtFields/*from   w ww .  j  a  va  2 s  .com*/
 * @return
 */
protected ValState evalState(final ValFormattedTextFieldSingle... txtFields) {
    for (ValFormattedTextFieldSingle tf : txtFields) {
        tf.setState(UIValidatable.ErrorType.Valid);
        tf.repaint();
    }

    ValState state = ValState.Empty;
    boolean isEmpty = false;
    ValFormattedTextFieldSingle prevTF = null;
    for (ValFormattedTextFieldSingle tf : txtFields) {
        String str = StringUtils.deleteWhitespace(tf.getText());
        if (StringUtils.isEmpty(str)) {
            isEmpty = true;

        } else if (tf.getState() == UIValidatable.ErrorType.Valid && tf.getText().length() > 0) {
            if (isEmpty) {
                if (prevTF != null) {
                    prevTF.setState(UIValidatable.ErrorType.Error);
                    prevTF.repaint();
                }
                return ValState.Error;
            }
            state = ValState.Valid;

        } else {
            return ValState.Error;
        }
        prevTF = tf;
    }
    return state;
}