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:com.wavemaker.json.JSONMarshallerTest.java

public void testWithArray() throws Exception {

    ObjectWithArray owl = new ObjectWithArray();
    owl.setStringArray(new String[] { "a", "b" });

    String s = JSONMarshaller.marshal(owl);
    assertEquals("{\"stringArray\":[\"a\",\"b\"]}", s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}

From source file:net.sf.sail.webapp.service.file.impl.AuthoringJNLPModifierTest.java

public void testmodifyJNLP() throws Exception {
    AuthoringJNLPModifier modifier = new AuthoringJNLPModifier();
    assertEquals(StringUtils.deleteWhitespace(outputJnlp),
            StringUtils.deleteWhitespace(modifier.modifyJnlp(inputJnlp, curnitURL, PROJECTID)));
}

From source file:com.zack6849.superlogger.Main.java

public void loadSettings() {
    if (!getConfig().isConfigurationSection("log") | this.getConfig().getConfigurationSection("log") == null) {
        //TODO: Clean this code up somehow?
        logger.info("Doing one-time config conversion");
        getConfig().set("auto-update", getConfig().getBoolean("auto-update"));
        getConfig().set("update-notify", true);
        getConfig().set("debug", false);
        getConfig().set("log.commands", getConfig().getBoolean("log-commands"));
        getConfig().set("log.check-command-exists", getConfig().getBoolean("check-commands"));
        getConfig().set("log.chat", getConfig().getBoolean("log-chat"));
        getConfig().set("log.join", getConfig().getBoolean("log-join"));
        getConfig().set("log.quit", getConfig().getBoolean("log-quit"));
        getConfig().set("log.kick", getConfig().getBoolean("log-kick"));
        getConfig().set("log.death", getConfig().getBoolean("log-death"));
        getConfig().set("log.failed-connections", getConfig().getBoolean("log-disallowed-connections"));
        getConfig().set("log.player-ip", getConfig().getBoolean("log-ip"));
        getConfig().set("log.player-uuid", true);
        getConfig().set("log.coordinates", true);
        getConfig().set("blacklist", getConfig().getStringList("filters"));

        //remove old config nodes
        List<String> oldpaths = Arrays.asList(
                "log-commands log-chat log-join log-quit log-kick log-death log-ip log-death-location log-disallowed-connections use-old-logging use-permissions notify-update use-command-whitelist check-commands whitelist filters"
                        .split(" "));
        for (String path : oldpaths) {
            getConfig().set(path, null);
        }//  w w  w. j a v  a2  s  .c o m
        //save and reload config
        try {
            getConfig().save(new File(getDataFolder(), "config.yml"));
            reloadConfig();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    this.settings = new Settings();
    settings.setDebug(getConfig().getBoolean("debug", true));
    settings.setAutoUpdate(getConfig().getBoolean("auto-update", true));
    settings.setUpdateNotify(getConfig().getBoolean("update-notify", true));
    settings.setLogChat(getConfig().getBoolean("log.chat", true));
    settings.setLogCommands(getConfig().getBoolean("log.commands", true));
    settings.setLogCoordinates(getConfig().getBoolean("log.coordinates", true));
    settings.setLogDeath(getConfig().getBoolean("log.death", true));
    settings.setLogJoin(getConfig().getBoolean("log.join", true));
    settings.setLogQuit(getConfig().getBoolean("log.quit", true));
    settings.setLogKick(getConfig().getBoolean("log.kick", true));
    settings.setLogDisallowedConnections(getConfig().getBoolean("log.failed-connections", true));
    settings.setLogPlayerIp(getConfig().getBoolean("log.player-ip", true));
    settings.setLogPlayerUUID(getConfig().getBoolean("log.player-uuid", true));
    settings.setCheckCommandExists(getConfig().getBoolean("log.check-command-exists", false));
    settings.setFilteredCommands(new HashSet<String>());
    for (String command : getConfig().getStringList("blacklist")) {
        //lowercase all commands so it's easier to check
        settings.getFilteredCommands().add(StringUtils.deleteWhitespace(command));
    }
    if (getSettings().isLogPlayerUUID()) {
        debug("UUID support is enabled, checking to see if server supports UUIDs");
        double version = Double.valueOf(StringUtils.join(
                getServer().getVersion().split("\\(")[1].split("\\)")[0].split("MC: ")[1].split("\\."), ".", 0,
                2));
        debug("Found minecraft version " + version + " from version string " + getServer().getVersion());
        //actual UUID support is only in minecraft 1.7+
        if (version < 1.7) {
            logger.warning("Player UUID Logging is enabled, but your server version doesn't have it!");
            logger.warning("Disabling UUID Logging..");
            getSettings().setLogPlayerUUID(false);
        }
    }
}

From source file:com.ebiznext.flume.elasticsearch.SearchGuardElasticSearchSink.java

@Override
public void configure(Context context) {
    if (StringUtils.isNotBlank(context.getString(HOSTNAMES))) {
        serverAddresses = StringUtils.deleteWhitespace(context.getString(HOSTNAMES)).split(",");
    }/*from   w  ww.j a v  a2 s  .  c o 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.");
    }

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

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

    indexRequestFactory = new ElasticSearchEventSerializerWithTypeMappings();
    indexRequestFactory.configure(serializerContext);

    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.wavemaker.json.JSONMarshallerTest.java

public void testTopLevelArray() throws Exception {

    String[] strs = new String[] { "a", "b" };
    String s = JSONMarshaller.marshal(strs);
    assertEquals("[\"a\",\"b\"]", s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}

From source file:net.sf.sail.webapp.service.file.impl.AuthoringJNLPModifierTest.java

public void testmodifyJNLP_2() throws Exception {
    // test calling the 4-parameter modifyJNLP() method.
    AuthoringJNLPModifier modifier = new AuthoringJNLPModifier();
    assertEquals(StringUtils.deleteWhitespace(outputJnlp2),
            StringUtils.deleteWhitespace(
                    modifier.modifyJnlp(inputJnlp, curnitURL, PROJECTID, "http://localhost:8080/webapp",
                            "http://localhost:8080/webapp/author/project/postproject.html?projectId=3")));
}

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

@Test
public void testChildrenTemplate() throws Exception {
    Channel channel = createChannel(1, true);
    ChannelPublishServiceable service = mock(ChannelPublishServiceable.class);
    when(service.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel);
    List<Channel> children = createChannelChildren(1, 5);
    when(service.getChannelChildren(any(Integer.class))).thenReturn(children);
    ChannelListDirective directive = new ChannelListDirective(service);

    cfg.setSharedVariable("clist", directive);

    Template template = cfg.getTemplate(getTemplatePath("child.html"));
    Map<String, Object> params = templateParameters();
    String value = process(template, params);
    value = StringUtils.deleteWhitespace(value);
    Assert.assertEquals("?_1_0?_1_2?_1_4", value);
}

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testNumericTypes() throws Exception {

    JSONState jc = new JSONState();

    ObjectWithTypes owt = new ObjectWithTypes();
    owt.setBigDecimal(BigDecimal.valueOf(12.2));
    owt.setIntVal(12);//www .  ja  v a2 s .  c o m
    owt.setFloatVal(13.3f);
    owt.setBigInteger(BigInteger.valueOf(13));
    owt.setBoolVal(false);

    String s = JSONMarshaller.marshal(owt, jc, false);
    assertEquals("{\"bigDecimal\":12.2,\"bigInteger\":13,\"boolVal\":false,\"floatVal\":13.3,\"intVal\":12}",
            s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}

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

@Test
public void testDebugValueTemplate() throws Exception {
    ChannelPublishServiceable channelLoaderService = mock(ChannelPublishServiceable.class);
    Channel channel = new Channel();
    channel.setId(1);/*  w  w w  .jav  a2  s  .  c om*/
    channel.setPublicenable(false);
    when(channelLoaderService.getChannel(any(Integer.class), any(Integer.class))).thenReturn(channel);

    ArticlePublishServiceable articleLoaderService = mock(ArticlePublishServiceable.class);
    when(articleLoaderService.findArticleReleasePage(1, 0, 10, false)).thenReturn(createArticleRow(10));

    ArticleListDirective directive = new ArticleListDirective(channelLoaderService, articleLoaderService);
    cfg.setSharedVariable("alist", directive);

    Template template = cfg.getTemplate(getTemplatePath("value.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.DEBUG.toString(), Boolean.TRUE);
    String value = process(template, params);
    value = StringUtils.deleteWhitespace(value);

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

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

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testMap() throws Exception {

    ObjectWithMap owm = new ObjectWithMap();
    owm.setStringDoubleMap(new HashMap<String, Double>());
    owm.getStringDoubleMap().put("b", Double.valueOf(12.2));
    owm.getStringDoubleMap().put("a", Double.valueOf(13.3));

    JSONState jc = new JSONState();

    String s = JSONMarshaller.marshal(owm, jc, true);
    assertEquals("{\"stringDoubleMap\":{\"a\":13.3,\"b\":12.2}}", s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}