Example usage for java.util StringTokenizer nextElement

List of usage examples for java.util StringTokenizer nextElement

Introduction

In this page you can find the example usage for java.util StringTokenizer nextElement.

Prototype

public Object nextElement() 

Source Link

Document

Returns the same value as the nextToken method, except that its declared return value is Object rather than String .

Usage

From source file:bboss.org.apache.velocity.util.StringUtils.java

/**
 * <p>//  ww w . j ava 2  s .  c o m
 * 'Camels Hump' replacement.
 * </p>
 *
 * <p>
 * Remove one string from another string but leave the capitalization of the
 * other letters unchanged.
 * </p>
 *
 * <p>
 * For example, removing "_" from <code>foo_barBar</code> becomes <code>FooBarBar</code>.
 * </p>
 *
 * @param data string to hump
 * @param replaceThis string to be replaced
 * @return String
 */
static public String removeAndHump(String data, String replaceThis) {
    String temp = null;
    StringBuffer out = new StringBuffer();
    temp = data;

    StringTokenizer st = new StringTokenizer(temp, replaceThis);

    while (st.hasMoreTokens()) {
        String element = (String) st.nextElement();
        out.append(capitalizeFirstLetter(element));
    } //while

    return out.toString();
}

From source file:org.hyperic.hq.product.DetectionUtil.java

/**
 * //from www . j  av  a  2s .c o m
 * @param wmiObjName
 * @param filter a name-value pair. The first '-' sign seperates between the name and the value. The rest which follows are part of the value's name
 * @param col
 * @param name
 * @return
 * @throws PluginException
 */
public static Set<String> getWMIObj(String namespace, String wmiObjName, Map<String, String> filters,
        String col, String name) throws PluginException {
    if (wmiObjName == null || "".equals(wmiObjName)) {
        throw new PluginException("object property not specified in the template of " + name);
    }
    StringBuilder sb = new StringBuilder().append("wmic /NAMESPACE:\\\\" + namespace + " path ")
            .append(wmiObjName);

    if (filters != null && !filters.isEmpty()) {
        sb.append(" WHERE \"");
        int num = 0;
        for (Entry<String, String> filterEntry : filters.entrySet()) {
            String filterFieldAndVal = filterEntry.getKey();
            String operator = filterEntry.getValue();
            int i = filterFieldAndVal.indexOf("-");
            sb.append(filterFieldAndVal.substring(0, i)).append(" ").append(operator).append(" '")
                    .append(filterFieldAndVal.substring(i + 1, filterFieldAndVal.length())).append("'");
            num++;
            if (num < filters.size()) {
                sb.append(" and ");
            }
        }
        sb.append("\"");
    }

    sb.append(" get");
    if (col != null && !"".equals(col)) {
        sb.append(" " + col);
    }

    sb.append(" /format:textvaluelist.xsl");
    String cmd = sb.toString();
    if (log.isDebugEnabled()) {
        log.debug("cmd=" + cmd);
    }

    BufferedReader input = null;
    try {
        Process process = Runtime.getRuntime().exec(cmd);
        input = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String line;
        Set<String> obj = new HashSet<String>();
        StringTokenizer st;
        while ((line = input.readLine()) != null) {
            line = line.trim();
            st = new StringTokenizer(line, "=");
            while (st.hasMoreElements()) {
                String k = ((String) st.nextElement()).trim();
                String v = ((String) st.nextElement()).trim();
                obj.add(v);
            }
        }
        return obj;
    } catch (IOException e) {
        throw new PluginException(e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                throw new PluginException(e);
            }
        }
    }
}

From source file:deprecate.compare.TokenizerJava_old.java

/**
 * Convert the tokens stored on disk onto a token source object
 * @param   tokenCode line from disk/*from www  . j  av  a 2s . c  o m*/
 * @return  the tokenSource object or null if some problem occurred    
 */
public static TokenSource decompress(final String tokenCode) {
    TokenizerJava_old tokens = new TokenizerJava_old();
    TokenSource result = new TokenSource();
    // split each method according to tabs
    //String[] methodTexts = tokenCode.split("\t");
    StringTokenizer stringTokenizer = new StringTokenizer(tokenCode, TokenSource.separatorMethod);

    // iterate and create the token methods
    //for(String methodText : methodTexts){
    while (stringTokenizer.hasMoreTokens()) {
        // create the token method
        SourceCodeSnippet method = new SourceCodeSnippet();
        final String line = stringTokenizer.nextElement().toString();
        int i1 = line.indexOf(TokenSource.separatorData);
        // feed the token data
        method.setTokens(line.substring(i1 + 1));

        // split the lines data in two lines
        final String lineData = line.substring(0, i1);
        final String[] lines = lineData.split("\\.\\.");
        // set the method lines
        method.setLineStart(Integer.parseInt(lines[0]));
        method.setLineEnd(Integer.parseInt(lines[1]));

        // add it to the result
        result.add(method);
    }
    // all done
    return result;
}

From source file:dynamicrefactoring.util.io.FileManager.java

/**
 * Permite obtener la ruta relativa de un fichero a partir de su ruta
 * absoluta.//from  w w  w  .  jav a  2s  .  c  o m
 * 
 * @param rutaAbsoluta
 *            ruta absoluta de un fichero.
 * @return devuelve la ruta relativa del fichero cuya rutaAbsoluta se ha
 *         introducido en al funcin.
 */
public static String AbsoluteToRelative(String rutaAbsoluta) {
    StringBuffer rutaRelativa = new StringBuffer();
    int contador = 0;
    boolean comun = false;
    Object absolute = null;
    Object actual = null;
    String rutaActual = new File(".").getAbsolutePath();

    String rAbsoluta = rutaAbsoluta.replace("/", File.separator);
    rAbsoluta = rAbsoluta.replace("" + File.separatorChar + "", File.separator);

    StringTokenizer st_absolute = new StringTokenizer(rAbsoluta, File.separator);
    StringTokenizer st_actual = new StringTokenizer(rutaActual, File.separator);

    while (st_absolute.hasMoreTokens() && st_actual.hasMoreElements()) {
        absolute = st_absolute.nextElement();
        actual = st_actual.nextElement();
        if (absolute.toString().equals(actual.toString())) {
            comun = true;
        } else {
            break;
        }
    }

    while (st_actual.hasMoreElements()) {
        st_actual.nextElement();
        contador++;
    }
    contador++;

    if (comun) {
        if (contador > 0) {
            for (int i = 1; i < contador; i++) {
                rutaRelativa.append(".." + File.separator);
            }
        } else if (contador == 0) {
            rutaRelativa.append("." + File.separator);
        }
        while (st_absolute.hasMoreElements()) {
            rutaRelativa.append(absolute.toString() + File.separator);
            absolute = st_absolute.nextElement();
        }
        rutaRelativa.append(absolute.toString());
        return rutaRelativa.toString().replace("" + File.separatorChar + "", "/");
    } else {
        return rAbsoluta; //estan en distinta unidad y por
        //tanto no se puede obtener su ruta relativa.
    }

}

From source file:azkaban.jobtype.HadoopSparkJob.java

private static String getSourcePathFromClass(final Class<?> containedClass) {
    File file = new File(containedClass.getProtectionDomain().getCodeSource().getLocation().getPath());

    if (!file.isDirectory() && file.getName().endsWith(".class")) {
        final String name = containedClass.getName();
        final StringTokenizer tokenizer = new StringTokenizer(name, ".");
        while (tokenizer.hasMoreTokens()) {
            tokenizer.nextElement();
            file = file.getParentFile();
        }/*  www  .j a  va  2 s  . co  m*/

        return file.getPath();
    } else {
        return containedClass.getProtectionDomain().getCodeSource().getLocation().getPath();
    }
}

From source file:org.rhq.core.util.StringUtil.java

/**
 * Split a string up by whitespace, taking into account quoted subcomponents. If there is an uneven number of
 * quotes, a parse error will be thrown.
 *
 * @param  arg String to parse//from  w  ww.  j  a  v  a2s .  c  o m
 *
 * @return an array of elements, the argument was split into
 *
 * @throws IllegalArgumentException indicating there was a quoting error
 */

public static String[] explodeQuoted(String arg) throws IllegalArgumentException {
    List<String> res = new ArrayList<String>();
    StringTokenizer quoteTok;
    boolean inQuote = false;

    arg = arg.trim();
    quoteTok = new StringTokenizer(arg, "\"", true);

    while (quoteTok.hasMoreTokens()) {
        String elem = (String) quoteTok.nextElement();

        if (elem.equals("\"")) {
            inQuote = !inQuote;
            continue;
        }

        if (inQuote) {
            res.add(elem);
        } else {
            StringTokenizer spaceTok = new StringTokenizer(elem.trim());

            while (spaceTok.hasMoreTokens()) {
                res.add(spaceTok.nextToken());
            }
        }
    }

    if (inQuote) {
        throw new IllegalArgumentException("Unbalanced quotation marks");
    }

    return res.toArray(new String[res.size()]);
}

From source file:org.libreplan.business.common.LibrePlanClassValidator.java

/**
 * Retrieve the property by path in a recursive way, including IndetifierProperty in the loop
 * If propertyName is null or empty, the IdentifierProperty is returned
 *///  w w  w. ja  v a  2s .c  om
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
    Property property = null;
    Property idProperty = associatedClass.getIdentifierProperty();
    String idName = idProperty != null ? idProperty.getName() : null;
    try {
        if (propertyName == null || propertyName.length() == 0 || propertyName.equals(idName)) {
            //default to id
            property = idProperty;
        } else {
            if (propertyName.indexOf(idName + ".") == 0) {
                property = idProperty;
                propertyName = propertyName.substring(idName.length() + 1);
            }
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        }
    } catch (MappingException e) {
        try {
            //if we do not find it try to check the identifier mapper
            if (associatedClass.getIdentifierMapper() == null)
                return null;
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getIdentifierMapper().getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        } catch (MappingException ee) {
            return null;
        }
    }
    return property;
}

From source file:marytts.util.string.StringUtils.java

public static String deblank(String str) {
    StringTokenizer s = new StringTokenizer(str, " ", false);
    StringBuilder strRet = new StringBuilder();

    while (s.hasMoreElements())
        strRet.append(s.nextElement());

    return strRet.toString();
}

From source file:org.apache.cloudstack.storage.datastore.util.DateraUtil.java

public static String getValue(String keyToMatch, String url, boolean throwExceptionIfNotFound) {
    String delimiter1 = ";";
    String delimiter2 = "=";

    StringTokenizer st = new StringTokenizer(url, delimiter1);

    while (st.hasMoreElements()) {
        String token = st.nextElement().toString();

        int index = token.indexOf(delimiter2);

        if (index == -1) {
            throw new CloudRuntimeException("Invalid URL format");
        }/*from w  w  w .j a  v  a 2 s . co m*/

        String key = token.substring(0, index);

        if (key.equalsIgnoreCase(keyToMatch)) {
            return token.substring(index + delimiter2.length());
        }
    }

    if (throwExceptionIfNotFound) {
        throw new CloudRuntimeException("Key not found in URL");
    }

    return null;
}

From source file:org.apache.cloudstack.storage.datastore.util.DateraUtil.java

public static String getModifiedUrl(String originalUrl) {
    StringBuilder sb = new StringBuilder();

    String delimiter = ";";

    StringTokenizer st = new StringTokenizer(originalUrl, delimiter);

    while (st.hasMoreElements()) {
        String token = st.nextElement().toString().toUpperCase();

        if (token.startsWith(DateraUtil.MANAGEMENT_VIP.toUpperCase())
                || token.startsWith(DateraUtil.STORAGE_VIP.toUpperCase())) {
            sb.append(token).append(delimiter);
        }//from   w  ww.  j  a v a 2  s . co  m
    }

    String modifiedUrl = sb.toString();
    int lastIndexOf = modifiedUrl.lastIndexOf(delimiter);

    if (lastIndexOf == (modifiedUrl.length() - delimiter.length())) {
        return modifiedUrl.substring(0, lastIndexOf);
    }

    return modifiedUrl;
}