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

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

Introduction

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

Prototype

public static int indexOf(String str, String searchStr) 

Source Link

Document

Finds the first index within a String, handling null.

Usage

From source file:com.egt.core.jsf.JSF.java

private static String addRequestPostBackParameters(String url, Long id) {
    if (StringUtils.isBlank(url)) {
        return null;
    }//from w  w  w  .  jav a 2s .  c  o m
    String param = "";
    if (id != null) {
        param += StringUtils.indexOf(url, "?") < 0 ? "?" : "&";
        param += Global.PARAMETRO_RETRUCAR + "=" + true;
        param += "&" + CPP.ID_RECURSO + "=" + id + Global.PREFIJO_ENLACE_URL_HTTP;
    }
    return url + param;
}

From source file:ips1ap101.lib.core.jsf.JSF.java

private static String addRequestPostBackParameters(String url) {
    if (StringUtils.isBlank(url)) {
        return null;
    }/* w ww.ja v  a 2 s .c om*/
    String param = "";
    String state = getRequestParameter(Global.PARAMETRO_RETRUQUE);
    if (StringUtils.isNotBlank(state)) {
        param += StringUtils.indexOf(url, "?") < 0 ? "?" : "&";
        param += Global.PARAMETRO_RETRUCAR + "=" + true;
        //          param += "&" + Global.PARAMETRO_RETRUQUE + "=" + state;
    }
    return url + param;
}

From source file:net.triptech.metahive.model.Person.java

/**
 * Build the option map if any search options exist.
 *//*from  w ww. jav a  2 s .c  o  m*/
@PostLoad
public final void postLoad() {
    this.searchOptionsMap = new HashMap<String, Boolean>();

    if (StringUtils.isNotBlank(this.searchOptions)) {
        // Parse the search options
        StringTokenizer st = new StringTokenizer(this.searchOptions, "|");
        while (st.hasMoreTokens()) {
            String t = st.nextToken();
            String key = StringUtils.substring(t, 0, StringUtils.indexOf(t, "="));
            String vl = StringUtils.substring(t, StringUtils.indexOf(t, "=") + 1);

            // Parse the value to a boolean
            try {
                boolean bl = Boolean.parseBoolean(vl);
                this.searchOptionsMap.put(key, bl);
            } catch (Exception e) {
                // Error casting string to boolean
            }
        }
    }
}

From source file:nl.ucan.navigate.NestedPath.java

private NestedPath() {
    this.propertyInstance = new PropertyInstance() {
        public Object indexed(Object bean, String property, int index, Object value) {
            log.info("created indexed property " + property + " at " + index + " of bean " + bean
                    + " and will be set to " + value);
            return value;
        }/* w  ww.ja v  a2s. com*/

        public Object simple(Object bean, String property, Object value) {
            log.info("created simple property " + property + " of bean " + bean + " and will be set to "
                    + value);
            return value;
        }
    };
    this.propertyValue = new PropertyValue() {
        public Object indexed(Object bean, String property, int index, Object value) {
            log.info("value of indexed property " + property + " at " + index + " of bean " + bean
                    + " will be set to " + value);
            return value;
        }

        public Object mapped(Object bean, String property, Object key, Object value) {
            log.info("value of mapped property " + property + " at " + key + " of bean " + bean
                    + " will be set to " + value);
            return value;
        }

        public Object simple(Object bean, String property, Object value) {
            log.info("value of simple property " + property + " of bean " + bean + " will be set to " + value);
            return value;
        }

        public Object valueOf(Class clasz, String property, String value) {
            log.info("value of valueOf " + property + " will be set to " + value);
            return value;
        }
    };
    this.indexPointer = new IndexPointer() {
        public int size(Object bean) {
            return CollectionUtils.size(bean);
        }

        public Object get(Object bean, int idx) {
            return CollectionUtils.get(bean, idx);
        }

        public int firstIndexOf(Object bean, String undeterminedIndex)
                throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
                InstantiationException, IntrospectionException {
            this.setUndeterminedIndex(undeterminedIndex);
            for (int idx = 0; idx < size(bean); idx++) {
                Object object = get(bean, idx);
                if (object != null) {
                    if (evaluate(object, this.getUndeterminedIndex()))
                        return idx;
                }
            }
            return -1;
        }

        public void setIndexAsProperty(Object bean, String undeterminedIndex)
                throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
                InstantiationException, IntrospectionException {
            this.setUndeterminedIndex(undeterminedIndex);
            Object value = propertyValue.simple(bean, this.getProperty(), this.getValue());
            pub.setProperty(bean, this.getProperty(), value);
        }

        private String undeterminedIndex;

        private void setUndeterminedIndex(String undeterminedIndex) {
            this.undeterminedIndex = undeterminedIndex;
        }

        private String getUndeterminedIndex() {
            return this.undeterminedIndex;
        }

        private boolean evaluate(Object bean, String undeterminedIndex)
                throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
                InstantiationException, IntrospectionException {
            this.setUndeterminedIndex(undeterminedIndex);
            String property = getProperty();
            String valueOfIndex = getValue();
            Object valueOfBean = pub.getProperty(bean, property);
            return ObjectUtils.equals(valueOfIndex, valueOfBean);
        }

        private String getProperty() {
            Map.Entry<String, String> entry = getNamedIndex(this.getUndeterminedIndex());
            return entry.getKey();
        }

        private String getValue() {
            Map.Entry<String, String> entry = getNamedIndex(this.getUndeterminedIndex());
            return entry.getValue();
        }

        private Map.Entry<String, String> getNamedIndex(String value) {
            final String SEP = "=";
            Map<String, String> keyValuePair = new HashMap<String, String>();
            if (StringUtils.indexOf(value, SEP) == -1)
                return null;
            keyValuePair.put(StringUtils.substringBefore(value, SEP), StringUtils.substringAfter(value, SEP));
            return keyValuePair.entrySet().iterator().next();
        }
    };
    this.pub = BeanUtilsBean.getInstance().getPropertyUtils();
    this.pub.setResolver(new ResolverImpl());
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method checks that if the &lt;resource&gt; is local to the content
 * package, then a &lt;file&gt; element is required that represents the
 * &lt;resource&gt; itself. The href attribute of the &lt;file&gt; element
 * shall be identical to the href attribute of the &lt;resource&gt;
 * //from  w w w .ja  va  2s  .c om
 * @param iResourceNode
 *            - The &lt;resource&gt; element
 * @return boolean - Result of the overall check. True if the checks passed,
 *         false otherwise.
 */
private boolean checkResourceFileHref(Node iResourceNode) {
    boolean result = true;
    String msgText = "";

    // retrive the href and apply xml:base
    String resourceHref = DOMTreeUtility.getAttributeValue(iResourceNode, "href");

    // only continue check if the resourceHref exists
    if (!resourceHref.equals("")) {
        // remove all parameters from the end of the href, if they exist

        // first deal with ?
        int questionMarkIndex = StringUtils.indexOf(resourceHref, '?');
        if (questionMarkIndex > 0) {
            resourceHref = StringUtils.substring(resourceHref, 0, questionMarkIndex);
        }

        // also deal with #
        int poundIndex = StringUtils.indexOf(resourceHref, '#');
        if (poundIndex > 0) {
            resourceHref = StringUtils.substring(resourceHref, 0, poundIndex);
        }

        // we must manually retrieve the resource xml:base attribute value
        // the applyXMLBase is not aware of it at this time of processing
        String resourceXMLBase = DOMTreeUtility.getAttributeValue(iResourceNode, "base");

        // resourceID used for logging error messages
        String resourceID = DOMTreeUtility.getAttributeValue(iResourceNode, "identifier");
        mLogger.debug("Checking for this resource now " + resourceID);

        // apply XML Base to the href if it exists
        resourceHref = mXMLBase[0][1] + mXMLBase[1][1] + resourceXMLBase + resourceHref;

        // only need to perform this check on local resource
        if (!StringUtils.startsWith(resourceHref, "http:") && !StringUtils.startsWith(resourceHref, "https:")
                && !StringUtils.startsWith(resourceHref, "ftp:")
                && !StringUtils.startsWith(resourceHref, "ftps:")) {
            // we have a resource that is local to the package, must have a
            // file
            // href that is identifical to it

            List<String> files = mResourceTable.get(resourceID);

            if (files != null) {
                if (!files.contains(resourceHref)) {
                    // the resourceHref does not contain a matching file
                    // href when
                    // it should
                    result = false;

                    msgText = Messages.getString("CPValidator.628", resourceID);
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));
                }
            } else {
                // there are no files that exist for the local resource
                result = false;

                msgText = Messages.getString("CPValidator.628", resourceID);
                mLogger.debug("FAILED: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
            }
        }
    }
    return result;
}

From source file:org.apache.camel.component.avro.AvroConfiguration.java

public void parseURI(URI uri, Map<String, Object> parameters, AvroComponent component) throws Exception {
    transport = uri.getScheme();/*from   w  w  w  .  j a  va2  s.  co  m*/

    if ((!AVRO_HTTP_TRANSPORT.equalsIgnoreCase(transport))
            && (!AVRO_NETTY_TRANSPORT.equalsIgnoreCase(transport))) {
        throw new IllegalArgumentException("Unrecognized Avro IPC transport: " + protocol + " for uri: " + uri);
    }

    setHost(uri.getHost());
    setPort(uri.getPort());

    if ((uri.getPath() != null) && (StringUtils.indexOf(uri.getPath(), AVRO_MESSAGE_NAME_SEPARATOR) != -1)) {
        String path = StringUtils.substringAfter(uri.getPath(), AVRO_MESSAGE_NAME_SEPARATOR);
        if (!path.contains(AVRO_MESSAGE_NAME_SEPARATOR)) {
            setMessageName(path);
        } else {
            throw new IllegalArgumentException("Unrecognized Avro message name: " + path + " for uri: " + uri);
        }
    }

    setUriAuthority(uri.getAuthority());
}

From source file:org.apache.gobblin.compaction.parser.CompactionPathParser.java

private void parseTimeAndDatasetName(FileSystemDataset dataset, CompactionParserResult rst) {
    String commonBase = rst.getSrcBaseDir();
    String fullPath = dataset.datasetURN();
    int startPos = fullPath.indexOf(commonBase) + commonBase.length();
    String relative = StringUtils.removeStart(fullPath.substring(startPos), "/");

    int delimiterStart = StringUtils.indexOf(relative, rst.getSrcSubDir());
    if (delimiterStart == -1) {
        throw new StringIndexOutOfBoundsException();
    }/* w  w w . java2s. c om*/
    int delimiterEnd = relative.indexOf("/", delimiterStart);
    String datasetName = StringUtils.removeEnd(relative.substring(0, delimiterStart), "/");
    String timeString = StringUtils.removeEnd(relative.substring(delimiterEnd + 1), "/");
    rst.datasetName = datasetName;
    rst.timeString = timeString;
    rst.time = getTime(timeString);
}

From source file:org.apache.hadoop.hive.common.cli.HiveFileProcessor.java

/**
 * process the Hive command by lines//from w w w. jav a  2 s  .  c  o m
 * @param line contains a legal Hive command
 * @return the return code of the execution result
 */
protected int processLine(String line) {
    int lastRet = 0, ret = 0;
    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.indexOf(oneCmd, "\\") != -1) {
            command += StringUtils.join(oneCmd.split("\\\\"));
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
        lastRet = ret;
        if (ret != 0) {
            return ret;
        }
    }
    return lastRet;
}

From source file:org.apache.hadoop.hive.ql.exec.Utilities.java

/**
 * Create a URL from a string representing a path to a local file.
 * The path string can be just a path, or can start with file:/, file:///
 * @param onestr  path string//from w  ww. j a  v a 2  s  .  c om
 * @return
 */
private static URL urlFromPathString(String onestr) {
    URL oneurl = null;
    try {
        if (StringUtils.indexOf(onestr, "file:/") == 0) {
            oneurl = new URL(onestr);
        } else {
            oneurl = new File(onestr).toURL();
        }
    } catch (Exception err) {
        LOG.error("Bad URL " + onestr + ", ignoring path");
    }
    return oneurl;
}

From source file:org.apache.hive.spark.client.SparkClientUtilities.java

/**
 * Create a URL from a string representing a path to a local file.
 * The path string can be just a path, or can start with file:/, file:///
 * @param path  path string/*from  w  w  w.j a va 2 s  .  c o m*/
 * @return
 */
private static URL urlFromPathString(String path, Long timeStamp, Configuration conf, File localTmpDir) {
    URL url = null;
    try {
        if (StringUtils.indexOf(path, "file:/") == 0) {
            url = new URL(path);
        } else if (StringUtils.indexOf(path, "hdfs:/") == 0 || StringUtils.indexOf(path, "viewfs:/") == 0) {
            Path remoteFile = new Path(path);
            Path localFile = new Path(localTmpDir.getAbsolutePath() + File.separator + remoteFile.getName());
            Long currentTS = downloadedFiles.get(path);
            if (currentTS == null) {
                currentTS = -1L;
            }
            if (!new File(localFile.toString()).exists() || currentTS < timeStamp) {
                LOG.info("Copying " + remoteFile + " to " + localFile);
                FileSystem remoteFS = remoteFile.getFileSystem(conf);
                remoteFS.copyToLocalFile(remoteFile, localFile);
                downloadedFiles.put(path, timeStamp);
            }
            return urlFromPathString(localFile.toString(), timeStamp, conf, localTmpDir);
        } else {
            url = new File(path).toURL();
        }
    } catch (Exception err) {
        LOG.error("Bad URL " + path + ", ignoring path", err);
    }
    return url;
}