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

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

Introduction

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

Prototype

public static boolean equalsIgnoreCase(final CharSequence str1, final CharSequence str2) 

Source Link

Document

Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

null s are handled without exceptions.

Usage

From source file:com.glaf.mail.domain.MailTask.java

public boolean isUnSubscribe() {
    if (StringUtils.equalsIgnoreCase(isUnSubscribe, "1") || StringUtils.equalsIgnoreCase(isUnSubscribe, "Y")
            || StringUtils.equalsIgnoreCase(isUnSubscribe, "true")) {
        return true;
    }/*from w  w  w  . ja  v a  2 s. c o  m*/
    return false;
}

From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java

/**
 * Get distance information between two GPS
 * @param originLat//from   w w  w.j  a v a  2s.c om
 * @param originLon
 * @param destLat
 * @param destLon
 * @return
 */
public static String[] getDistanceInfo(double originLat, double originLon, double destLat, double destLon) {

    String[] infos = new String[] { "0", "0" };

    String address = Constants.GOOGLE_DISTANCE_MATRIX_ADDRESS;
    address += originLat + "," + originLon;
    address += "&destinations=";
    address += destLat + "," + destLon;
    address += "&mode=driving&units=metric&language=en&key=";
    address += Constants.GOOGLE_DISTANCE_MATRIX_API_KEY;
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(address).build();
    Response response = null;
    String dist = null;
    try {
        response = client.newCall(request).execute();
        dist = response.body().string();
    } catch (IOException e) {
        return infos;
    }

    Log.d("@@@@@@", dist);
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = null;
    try {
        jsonObject = (JSONObject) jsonParser.parse(dist);
    } catch (ParseException e) {
        return infos;
    }

    // status check as well

    JSONArray rows = (JSONArray) jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_ROWS);
    for (int i = 0; i < rows.size(); i++) {
        JSONObject obj = (JSONObject) rows.get(i);
        JSONArray elements = (JSONArray) obj.get(Constants.GOOGLE_DISTANCE_MATRIX_ELEMENTS);
        for (int j = 0; j < elements.size(); j++) {
            JSONObject datas = (JSONObject) elements.get(j);
            JSONObject distance = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DISTANCE);
            JSONObject duration = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DURATION);
            infos[0] = distance.get(Constants.GOOGLE_DISTANCE_MATRIX_VALUE) + "";
            infos[1] = duration.get(Constants.GOOGLE_DISTANCE_MATRIX_TEXT) + "";

        }

    }
    String status = jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_STATUS).toString();
    //        Log.d("@@@@@@", status);
    if (!StringUtils.equalsIgnoreCase(Constants.GOOGLE_DISTANCE_MATRIX_OK, status)) {
        return infos;
    }
    return infos;
}

From source file:com.widowcrawler.exo.parse.Parser.java

public Sitemap parse(InputStream inputStream) throws XMLStreamException, SitemapParseException {

    final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream, "utf-8");

    final Sitemap retval = new Sitemap(new HashSet<>());

    final Set<SitemapURL> sitemapURLs = new HashSet<>();
    SitemapURL.Builder urlBuilder = null;
    String urlContent;//from   w  ww.jav  a  2s .c  o m

    reader.getEventType();

    while (reader.hasNext()) {
        switch (state) {
        case START:
            reader.nextTag();

            if (StringUtils.equalsIgnoreCase(reader.getLocalName(), URLSET_TAG_NAME)) {
                state = State.URLSET;
            } else if (StringUtils.equalsIgnoreCase(reader.getLocalName(), SITEMAPINDEX_TAG_NAME)) {
                state = State.SITEMAPINDEX;
            } else {
                String message = "Invalid root element. Must be either urlset or sitemapindex";
                logger.error(message);
                throw new SitemapParseException(message);
            }

            break;

        case END:
            // consume all end tags
            if (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                String message = decorate("There should be only one root element in each sitemap.xml",
                        reader.getLocation());
                logger.error(message);
                throw new SitemapParseException(message);
            }

            reader.next();
            break;

        /////////////////////
        // URLSET Hierarchy
        /////////////////////
        case URLSET:
            // If we're done with the URLs, we're done overall
            if (reader.nextTag() == XMLStreamConstants.END_ELEMENT) {
                state = State.END;
                break;
            }

            // Check that we're entering into a <url> element
            if (!StringUtils.equalsIgnoreCase(reader.getLocalName(), URL_TAG_NAME)) {
                String message = "A <urlset> element can only contain <url> elements. Found: "
                        + reader.getLocalName();
                logger.error(message);
                throw new SitemapParseException(message);
            }

            urlBuilder = new SitemapURL.Builder();
            state = State.URL;
            break;

        case URL:
            reader.nextTag();

            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                //logger.info("reader.getLocalName(): " + reader.getLocalName());
                switch (StringUtils.lowerCase(reader.getLocalName())) {
                case LOC_TAG_NAME:
                    state = State.URL_PROP_LOC;
                    break;
                case LASTMOD_TAG_NAME:
                    state = State.URL_PROP_LASTMOD;
                    break;
                case CHANGEFREQ_TAG_NAME:
                    state = State.URL_PROP_CHANGEFREQ;
                    break;
                case PRIORITY_TAG_NAME:
                    state = State.URL_PROP_PRIORITY;
                    break;
                case MOBILE_TAG_NAME:
                    state = State.URL_PROP_MOBILE;
                    break;
                default:
                    String message = "Unexpected tag in url: " + reader.getLocalName();
                    logger.error(message);
                    throw new SitemapParseException(message);
                }
            } else if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
                // we're done collecting the data for this URL
                assert urlBuilder != null;
                sitemapURLs.add(urlBuilder.build());
                urlBuilder = new SitemapURL.Builder();
                state = State.URLSET;
            }
            break;

        case URL_PROP_LOC:
            urlContent = reader.getElementText();

            try {
                assert urlBuilder != null;
                urlBuilder.withLocation(new URL(StringUtils.trimToNull(urlContent)));

            } catch (MalformedURLException ex) {
                String message = String.format("Malformed URL found: %s", urlContent);
                logger.error(message);
                throw new SitemapParseException(message);
            }
            state = State.URL;
            break;

        case URL_PROP_LASTMOD:
            assert urlBuilder != null;
            urlBuilder.withLastModified(DateTime.parse(reader.getElementText()));
            state = State.URL;
            break;

        case URL_PROP_CHANGEFREQ:
            assert urlBuilder != null;
            urlBuilder.withChangeFrequency(ChangeFreq.valueOf(StringUtils.upperCase(reader.getElementText())));
            state = State.URL;
            break;

        case URL_PROP_PRIORITY:
            assert urlBuilder != null;
            urlBuilder.withPriority(Double.valueOf(reader.getElementText()));
            state = State.URL;
            break;

        case URL_PROP_MOBILE:
            assert urlBuilder != null;
            urlBuilder.withIsMobileContent(true);
            // consume until "end tag" of self-closing tag
            // Also works if someone puts content in
            reader.getElementText();
            state = State.URL;
            break;

        ///////////////////////////
        // SITEMAPINDEX Hierarchy
        ///////////////////////////
        case SITEMAPINDEX:
            // If we're done with all the Sitemaps, we're done overall
            if (reader.nextTag() == XMLStreamConstants.END_ELEMENT) {
                state = State.END;
                break;
            }

            state = State.SITEMAP;
            break;

        case SITEMAP:
            if (!StringUtils.equalsIgnoreCase(reader.getLocalName(), SITEMAP_TAG_NAME)) {
                throw new SitemapParseException("A <sitemapindex> element can only contain <sitemap> elements");
            }

            reader.nextTag();

            if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                switch (StringUtils.lowerCase(reader.getLocalName())) {
                case LOC_TAG_NAME:
                    state = State.URL_PROP_LOC;
                    break;
                case LASTMOD_TAG_NAME:
                    state = State.URL_PROP_LASTMOD;
                    break;
                default:
                    throw new SitemapParseException("Unexpected tag in sitemap: " + reader.getLocalName());
                }
            } else if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
                // we're done collecting the data for this URL
                assert urlBuilder != null;
                sitemapURLs.add(urlBuilder.build());
                urlBuilder = new SitemapURL.Builder();
                state = State.URLSET;
            }

        case SITEMAP_PROP_LOC:
            urlContent = reader.getElementText();

            try {
                URL sitemapURL = new URL(StringUtils.trimToNull(urlContent));

                Sitemap temp = Retry.retry(() -> {
                    try {
                        return Exo.parse(sitemapURL.toString());
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                });

                retval.merge(temp);

            } catch (MalformedURLException ex) {
                String message = String.format("Malformed URL found: %s", urlContent);
                logger.error(message);
                throw new SitemapParseException(message);

            } catch (InterruptedException e) {
                logger.warn("Thread interrupted while (re)trying");
                Thread.currentThread().interrupt();

            } catch (RetryFailedException e) {
                String message = String.format("Failed to retrieve sitemap of sitemap index at %s", urlContent);
                logger.error(message);
                throw new SitemapParseException(message);
            }

            state = State.URL;
            break;

        case SITEMAP_PROP_LASTMOD:
            // Do nothing with this data for now
            reader.getElementText();
            break;
        }

        //System.out.println(state);
    }

    return retval.merge(new Sitemap(sitemapURLs));
}

From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java

public List<View> read() {
    try {/*from   ww w. j  av a 2s  .  c o  m*/
        JsonFactory jsonFactory = new JsonFactory();
        jp = jsonFactory.createParser(stream);
        jp.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);

        // Read the START_OBJECT
        JsonToken token = jp.nextToken();
        if (token != JsonToken.START_OBJECT)
            throw new ZeidonException("OI JSON stream doesn't start with object.");

        token = jp.nextToken();
        if (token != JsonToken.FIELD_NAME)
            throw new ZeidonException("OI JSON missing OI field name.");

        String fieldName = jp.getCurrentName();
        if (fieldName.equals(".meta")) {
            readFileMeta();

            JsonReader reader = getReaderForVersion();
            reader.process();
        } else {
            if (StringUtils.equalsIgnoreCase(fieldName, "version")) {
                token = jp.nextToken(); // Move to value.
                version = jp.getValueAsString();
                token = jp.nextToken(); // Move to next field name.
                assert token == JsonToken.FIELD_NAME;
                fieldName = jp.getCurrentName();
            } else if (StringUtils.isBlank(options.getVersion())) {
                throw new ZeidonException("First field must be version");
            }

            totalRootCount = null;
            if (StringUtils.equalsIgnoreCase(fieldName, "totalRootCount")) {
                token = jp.nextToken(); // Move to value.
                totalRootCount = jp.getValueAsInt();
                token = jp.nextToken(); // Move to next field name.
                assert token == JsonToken.FIELD_NAME;
                fieldName = jp.getCurrentName();
            }

            if (lodDef == null)
                throw new ZeidonException("JSON stream appears to start with the root entity name (%s)"
                        + " but the LodDef has not been specified.", fieldName);

            String rootName = lodDef.getRoot().getName();
            if (!fieldName.equalsIgnoreCase(rootName))
                throw new ZeidonException("The first field in the JSON stream must be the root entity name"
                        + " (%s) or '.meta' but was %s.", rootName, fieldName);

            view = task.activateEmptyObjectInstance(lodDef);
            returnList.add(view);
            if (totalRootCount != null)
                view.setTotalRootCount(totalRootCount);

            JsonReader reader = getSimpleReaderForVersion();
            reader.process();
        }

        jp.close();
    } catch (Exception e) {
        ZeidonException ze = ZeidonException.wrapException(e);
        JsonLocation loc = jp.getCurrentLocation();
        JsonToken token = jp.getCurrentToken();
        ze.appendMessage("Position line=%d col=%d, token=%s", loc.getLineNr(), loc.getColumnNr(),
                token == null ? "No Token" : token.name());
        throw ze;
    }

    return returnList;
}

From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java

@RequestMapping("/edit")
public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    String tableName = request.getParameter("tableName_enc");
    if (StringUtils.isNotEmpty(tableName)) {
        tableName = RequestUtils.decodeString(tableName);
    } else {//from w ww. ja  v a2 s . co m
        tableName = request.getParameter("tableName");
    }
    String businessKey = request.getParameter("businessKey");
    String primaryKey = null;
    ColumnDefinition idColumn = null;
    List<ColumnDefinition> columns = null;
    try {
        if (StringUtils.isNotEmpty(tableName)) {
            columns = DBUtils.getColumnDefinitions(tableName);
            modelMap.put("tableName", tableName);
            modelMap.put("tableName_enc", RequestUtils.encodeString(tableName));
            List<String> pks = DBUtils.getPrimaryKeys(tableName);
            if (pks != null && !pks.isEmpty()) {
                if (pks.size() == 1) {
                    primaryKey = pks.get(0);
                }
            }
            if (primaryKey != null) {
                for (ColumnDefinition column : columns) {
                    if (StringUtils.equalsIgnoreCase(primaryKey, column.getColumnName())) {
                        idColumn = column;
                        break;
                    }
                }
            }
            if (idColumn != null) {
                TableModel tableModel = new TableModel();
                tableModel.setTableName(tableName);
                ColumnModel idCol = new ColumnModel();
                idCol.setColumnName(idColumn.getColumnName());
                idCol.setJavaType(idColumn.getJavaType());
                if ("Integer".equals(idColumn.getJavaType())) {
                    idCol.setValue(Integer.parseInt(businessKey));
                } else if ("Long".equals(idColumn.getJavaType())) {
                    idCol.setValue(Long.parseLong(businessKey));
                } else {
                    idCol.setValue(businessKey);
                }
                tableModel.setIdColumn(idCol);
                Map<String, Object> dataMap = tableDataService.getTableDataByPrimaryKey(tableModel);
                Map<String, Object> rowMap = QueryUtils.lowerKeyMap(dataMap);
                for (ColumnDefinition column : columns) {
                    Object value = rowMap.get(column.getColumnName().toLowerCase());
                    column.setValue(value);
                }
                modelMap.put("idColumn", idColumn);
                modelMap.put("columns", columns);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error(ex);
    }

    String x_view = ViewProperties.getString("sys_table.edit");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/modules/sys/table/edit", modelMap);
}

From source file:com.ottogroup.bi.asap.operator.json.aggregator.JsonContentAggregator.java

/**
 * @see com.ottogroup.bi.asap.component.Component#init(java.util.Properties)
 *//*  www.ja  v a 2s. co m*/
public void init(Properties properties) throws RequiredInputMissingException {

    //////////////////////////////////////////////////////////////////////////
    // validate and set variables
    this.componentId = properties.getProperty(CFG_COMPONENT_ID);
    if (StringUtils.isBlank(this.componentId))
        throw new RequiredInputMissingException(
                "Missing input for required parameter '" + CFG_COMPONENT_ID + "'");
    this.pipelineId = properties.getProperty(CFG_PIPELINE_ID);
    if (StringUtils.isBlank(this.pipelineId))
        throw new RequiredInputMissingException(
                "Missing input for required parameter '" + CFG_PIPELINE_ID + "'");
    if (StringUtils.equals("false", properties.getProperty(CFG_FORWARD_RAW_DATA))) {
        this.storeForwardRawData = false;
    }
    //
    //////////////////////////////////////////////////////////////////////////

    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        String name = properties.getProperty(CFG_FIELD_PREFIX + i + ".name");
        if (StringUtils.isBlank(name))
            break;

        String path = properties.getProperty(CFG_FIELD_PREFIX + i + ".path");
        String valueType = properties.getProperty(CFG_FIELD_PREFIX + i + ".type");

        this.fields.add(new JsonContentAggregatorFieldSetting(name, path.split("\\."),
                StringUtils.equalsIgnoreCase("STRING", valueType) ? ValueType.STRING : ValueType.NUMERICAL));
    }
}

From source file:ching.icecreaming.actions.FileLink.java

@Action(value = "file-link", results = { @Result(name = "success", type = "stream", params = { "inputName",
        "imageStream", "contentType", "${contentType}", "contentDisposition", "attachment;filename=${fileName}",
        "allowCaching", "false", "bufferSize", "1024" }), @Result(name = "error", location = "errors.jsp") })
public String execute() throws Exception {
    Configuration propertiesConfiguration1 = new PropertiesConfiguration("mimeTypes.properties");
    File file1 = null, file2 = null;
    String string1 = null, fileExtension = null;
    fileExtension = FilenameUtils.getExtension(fileName);
    contentType = "application/octet-stream";
    if (!StringUtils.isBlank(fileExtension)) {
        if (propertiesConfiguration1.containsKey(fileExtension))
            contentType = propertiesConfiguration1.getString(fileExtension);
    } else {/*www . j a va2s. c  o m*/
        contentType = "image/png";
    }
    try {
        if (StringUtils.isBlank(sessionId)) {
            sessionId = httpServletRequest.getSession().getId();
        }
        string1 = System.getProperty("java.io.tmpdir") + File.separator + sessionId;
        if (StringUtils.isBlank(fileExtension))
            string1 += File.separator + FilenameUtils.getPath(fileName);
        fileName = FilenameUtils.getName(fileName);
        if (StringUtils.equalsIgnoreCase(fileExtension, "html")) {
            file2 = new File(string1, FilenameUtils.getBaseName(fileName) + ".zip");
            if (file2.exists()) {
                file1 = file2;
                contentType = "application/zip";
                fileName = file2.getName();
            } else {
                file1 = new File(string1, fileName);
            }
        } else {
            file1 = new File(string1, fileName);
        }
        if (file1.exists()) {
            imageStream = new BufferedInputStream(FileUtils.openInputStream(file1));
        }
    } catch (IOException exception1) {
        addActionError(exception1.getMessage());
        return ERROR;
    }
    return SUCCESS;
}

From source file:com.norconex.collector.http.robot.impl.StandardRobotsTxtProvider.java

private RobotData.Precision matchesUserAgent(String userAgent, String value) {
    if ("*".equals(value)) {
        return RobotData.Precision.WILD;
    }//from   w ww  .  j  a v  a2 s .c  om
    if (StringUtils.equalsIgnoreCase(userAgent, value)) {
        return RobotData.Precision.EXACT;
    }
    if (value.endsWith("*")) {
        String val = StringUtils.removeEnd(value, "*");
        if (StringUtils.startsWithIgnoreCase(userAgent, val)) {
            return RobotData.Precision.PARTIAL;
        }
    }
    if (StringUtils.containsIgnoreCase(userAgent, value)) {
        return RobotData.Precision.PARTIAL;
    }
    return RobotData.Precision.NOMATCH;
}

From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java

public void renameFile(File oldFile, File newFile) throws IOException {
    String oldName = getDirectoryNameFromFile(oldFile);

    indexByteBuffer.position(HEADER_SIZE);
    byte[] nameBuffer = new byte[LOG_FILE_NAME_SIZE];
    while (indexByteBuffer.position() + ROW_SIZE < indexChannel.size()) {
        indexByteBuffer.getInt();//from  w  ww. j a  v a2s  .com
        indexByteBuffer.get(nameBuffer);
        String trimmed = new String(nameBuffer).trim();
        String fnt = StringUtils.substring(oldName, 0, LOG_FILE_NAME_SIZE);
        if (StringUtils.equalsIgnoreCase(trimmed, fnt) == true) {
            String lwwrite = fileToStoredName(newFile);
            indexByteBuffer.position(indexByteBuffer.position() - LOG_FILE_NAME_SIZE);
            indexByteBuffer.put(lwwrite.getBytes(StandardCharsets.US_ASCII));
            break;
        }

    }
}

From source file:com.glaf.core.service.impl.MxDataModelServiceImpl.java

public DataModel getDataModel(String tableName, Long id) {
    List<ColumnDefinition> cols = tableDefinitionService.getColumnDefinitionsByTableName(tableName);
    if (cols != null && !cols.isEmpty()) {
        for (ColumnDefinition col : cols) {
            if (StringUtils.equalsIgnoreCase(col.getColumnName(), "ID_")) {
                TableModel tableModel = new TableModel();
                tableModel.setTableName(tableName);
                ColumnModel cm = new ColumnModel();
                cm.setColumnName("ID_");
                cm.setJavaType(col.getJavaType());
                cm.setLongValue(id);//from   w ww . j a va  2 s  .  com
                cm.setValue(id);
                tableModel.setIdColumn(cm);
                Map<String, Object> dataMap = tableDataMapper.getTableDataByPrimaryKey(tableModel);
                if (dataMap != null && !dataMap.isEmpty()) {
                    DataModelEntity model = this.populate(dataMap);
                    return model;
                }
            }
        }
    }

    return null;
}