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.ewcms.publication.freemarker.directive.ChannelListDirectiveTest.java

@Test
public void testArrayTemplate() throws Exception {
    initMockArrayChannel();/*  www .ja v a2  s  . com*/

    Template template = cfg.getTemplate(getTemplatePath("array.html"));
    Map<String, Object> params = templateParameters();
    String value = process(template, params);
    value = StringUtils.deleteWhitespace(value);
    Assert.assertEquals("?1?2?3", value);
}

From source file:ch.cern.db.flume.sink.elasticsearch.ElasticSearchSink.java

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

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

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

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

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

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

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

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

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

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(ElasticSearchSinkConstants.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 = ElasticSearchSinkConstants.DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER);
    }

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

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(ElasticSearchSinkConstants.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:" + ElasticSearchSinkConstants.INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType),
            "Missing Param:" + ElasticSearchSinkConstants.INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName),
            "Missing Param:" + ElasticSearchSinkConstants.CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, ElasticSearchSinkConstants.BATCH_SIZE + " must be greater than 0");
}

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

@Test
public void testLoopTempalte() throws Exception {
    initMockArrayChannel();/*from   w w  w  . j av a  2s  .com*/

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

From source file:com.guilin.flume.ng.sink.elasticsearch.ElasticSearchSink.java

@Override
public void configure(Context context) {
    if (!isLocal) {
        if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.HOSTNAMES))) {
            serverAddresses = StringUtils
                    .deleteWhitespace(context.getString(ElasticSearchSinkConstants.HOSTNAMES)).split(",");
        }//from  www.ja  v a2s . co m
        Preconditions.checkState(serverAddresses != null && serverAddresses.length > 0,
                MISSING_PARAM + ElasticSearchSinkConstants.HOSTNAMES);
    }

    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.SHIELD_USER))) {
        this.shieldUser = context.getString(ElasticSearchSinkConstants.SHIELD_USER);
    }
    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.SHIELD_PWD))) {
        this.shieldPwd = context.getString(ElasticSearchSinkConstants.SHIELD_PWD);
    }

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

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

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

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

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

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

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

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

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(ElasticSearchSinkConstants.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 = ElasticSearchSinkConstants.DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER);
    }

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

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(ElasticSearchSinkConstants.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 + ElasticSearchSinkConstants.INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType),
            MISSING_PARAM + ElasticSearchSinkConstants.INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName),
            MISSING_PARAM + ElasticSearchSinkConstants.CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, ElasticSearchSinkConstants.BATCH_SIZE + " must be greater than 0");
}

From source file:com.frontier45.flume.sink.elasticsearch2.ElasticSearchSink.java

@Override
public void configure(Context context) {
    if (!isLocal) {
        if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.HOSTNAMES))) {
            serverAddresses = StringUtils
                    .deleteWhitespace(context.getString(ElasticSearchSinkConstants.HOSTNAMES)).split(",");
        }/*from  ww  w.  ja v  a 2  s.  c  om*/
        Preconditions.checkState(serverAddresses != null && serverAddresses.length > 0,
                MISSING_PARAM + ElasticSearchSinkConstants.HOSTNAMES);
    }

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

    keystorePath = context.getString("keystorePath",
            "/home/soft/elasticsearch/plugins/search-guard-2/sgconfig/admin-keystore.jks");
    keystorePass = context.getString("keystorePass", "changeit");
    truststorePath = context.getString("truststorePath",
            "/home/soft/elasticsearch/plugins/search-guard-2/sgconfig/truststore.jks");
    truststorePass = context.getString("truststorePass", "changeit");

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

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

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

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

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

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

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

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(ElasticSearchSinkConstants.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 = ElasticSearchSinkConstants.DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER);
    }

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

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(ElasticSearchSinkConstants.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 + ElasticSearchSinkConstants.INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType),
            MISSING_PARAM + ElasticSearchSinkConstants.INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName),
            MISSING_PARAM + ElasticSearchSinkConstants.CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, ElasticSearchSinkConstants.BATCH_SIZE + " must be greater than 0");
}

From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java

/**
 * @param tblName/*from ww  w  . j  a va2  s  . com*/
 * @param keyField
 */
private String createTableStr(final String tblName, final String keyField, final boolean doForceAll) {
    StringBuilder selectDB = new StringBuilder();
    for (FieldDef fd : fields) {
        String s = convertToAcsii(fd.getName());
        if (selectDB.length() > 0)
            selectDB.append(", ");
        selectDB.append(s);
        fd.setName(s);
    }

    fieldListString = selectDB.toString();

    int primaryIndex = -1;
    int i = 0;
    StringBuilder sb = new StringBuilder();
    sb.append("CREATE TABLE " + tblName + " (");
    for (FieldDef fd : fields) {
        if ((fd.getName() == null || fd.getMaxSize() == 0) && !doForceAll)
            continue;

        String fieldName = fd.getName();
        if ((i == 0 && keyField == null) || (keyField != null && keyField.equals(fieldName))) {
            primaryIndex = i;
            if (!fieldName.endsWith("ID")) {
                fieldName += "ID";
            }
            String keyName = StringUtils.deleteWhitespace(fieldName);
            sb.append(keyName);
            sb.append(" int(11) NOT NULL AUTO_INCREMENT,\n");

            fd.setName(fieldName);

        } else {
            sb.append(fd.getName());
            sb.append(" ");

            switch (fd.getType()) {
            case eText:
                int sz = ((int) (fd.getMaxSize() / 8.0) + 2) * 8;
                System.out.println(fd.getName() + "  [" + fd.getMaxSize() + "][" + sz + "]");
                if (sz > 255) {
                    //fd.setType(DataType.eMemo);
                    sb.append("text");
                } else {
                    sb.append("varchar(" + sz + ")");
                }

                break;

            case eNumber:
                sb.append(fd.isDouble() ? "double" : "int(11)");
                break;

            case eDate:
                sb.append("date");
                break;

            case eTime:
                sb.append("TIME");
                break;
            }
            sb.append(fd.isNullable() ? " DEFAULT NULL," : ",");
            sb.append("\n");
        }
        i++;
    }

    if (false) {
        sb.append("KEY `GenusIDX` (`SpeciesName`),");
        sb.append("KEY `SpeciesIDX` (`GenusName`),");
        sb.append("KEY `BarCDIDX` (`BarCD`),");
    }

    sb.append(String.format("PRIMARY KEY (`%s`)\n", fields.get(primaryIndex).getName()));
    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;\n");

    System.err.println(sb.toString());

    return sb.toString();
}

From source file:it.jugpadova.controllers.BinController.java

/**
 * Produce a certificate for a participant of an event.
 *//* w  ww .  j  a v  a 2s  . c o m*/
@RequestMapping
public ModelAndView participantCertificate(HttpServletRequest req, HttpServletResponse res) {
    try {
        Long id = new Long(req.getParameter("id"));
        Participant participant = participantBo.retrieveParticipant(id);
        Event event = participant.getEvent();
        eventBo.checkUserAuthorization(event);
        InputStream jugCertificateTemplate = null;
        String jugName = null;
        if (participant.getEvent().getOwner() != null) {
            JUG jug = participant.getEvent().getOwner().getJug();
            jugName = jug.getName();
            jugCertificateTemplate = jugBo.retrieveJugCertificateTemplate(jug.getId());
        } else {
            jugName = "";
        }
        byte[] jugCertificate = participantBo.buildCertificate(jugCertificateTemplate,
                participant.getFirstName() + " " + participant.getLastName(), participant.getEvent().getTitle(),
                event.getStartDate(), jugName);
        res.setContentType("application/pdf");
        res.setContentLength(jugCertificate.length);
        res.setHeader("Content-Disposition",
                "attachment; filename="
                        + StringUtils.deleteWhitespace(participant.getLastName() + participant.getFirstName())
                        + "Certificate.pdf");
        OutputStream out = new BufferedOutputStream(res.getOutputStream());
        out.write(jugCertificate);
        out.flush();
        out.close();
    } catch (Exception ex) {
        logger.error("Error producing the certificate", ex);
    }
    return null;
}

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

@Test
public void testValueTemplate() throws Exception {
    ChannelPublishServiceable channelLoaderService = mock(ChannelPublishServiceable.class);
    Channel channel = new Channel();
    channel.setId(1);//ww w. ja  v  a2 s .  co m
    channel.setPublicenable(true);
    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);
    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.vf.flume.sink.elasticsearch2.ElasticSearchSink.java

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

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

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

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

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

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

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

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

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

    Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(ElasticSearchSinkConstants.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 = ElasticSearchSinkConstants.DEFAULT_INDEX_NAME_BUILDER_CLASS;
    if (StringUtils.isNotBlank(context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER))) {
        indexNameBuilderClass = context.getString(ElasticSearchSinkConstants.INDEX_NAME_BUILDER);
    }

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

    try {
        @SuppressWarnings("unchecked")
        Class<? extends IndexNameBuilder> clazz = (Class<? extends IndexNameBuilder>) Class
                .forName(indexNameBuilderClass);
        indexNameBuilder = clazz.newInstance();
        indexnameBuilderContext.put(ElasticSearchSinkConstants.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 + ElasticSearchSinkConstants.INDEX_NAME);
    Preconditions.checkState(StringUtils.isNotBlank(indexType),
            MISSING_PARAM + ElasticSearchSinkConstants.INDEX_TYPE);
    Preconditions.checkState(StringUtils.isNotBlank(clusterName),
            MISSING_PARAM + ElasticSearchSinkConstants.CLUSTER_NAME);
    Preconditions.checkState(batchSize >= 1, ElasticSearchSinkConstants.BATCH_SIZE + " must be greater than 0");
}

From source file:de.devboost.emfcustomize.EcoreModelRefactorer.java

public Set<Method> getAnnotatedMethods(Class customClass) {
    Set<Method> annotatedMethods = new HashSet<Method>();

    List<Method> methods = customClass.getMethods();
    for (Method method : methods) {
        List<String> comments = method.getComments();
        if (comments != null && comments.size() > 0) {
            for (String comment : comments) {
                String[] lines = comment.split("[\\r\\n]+");
                for (String line : lines) {
                    String deleteWhitespace = StringUtils.deleteWhitespace(line);
                    if (StringUtils.endsWith(deleteWhitespace, MODEL_ANNOTATION)) {
                        String difference = StringUtils.removeEnd(deleteWhitespace, MODEL_ANNOTATION);
                        if (StringUtils.containsOnly(difference, VALID_PREFIX_CHARACTERS)
                                || difference.isEmpty()) {
                            annotatedMethods.add(method);
                        }//from   w ww .  ja va2  s.c  om
                    }
                }
            }
        }
    }
    return annotatedMethods;
}