Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

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

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:com.glaf.core.util.FtpUtils.java

/**
 * FTP//from w w w. j  av  a 2s. co  m
 * 
 * @param remotePath
 *            FTP"/"
 */
public static void removeDirectory(String remotePath) {
    if (!remotePath.startsWith("/")) {
        throw new RuntimeException(" path must start with '/'");
    }
    try {

        getFtpClient().changeWorkingDirectory("/");

        if (remotePath.indexOf("/") != -1) {
            String tmp = "";
            List<String> dirs = new ArrayList<String>();
            StringTokenizer token = new StringTokenizer(remotePath, "/");
            while (token.hasMoreTokens()) {
                String str = token.nextToken();
                tmp = tmp + "/" + str;
                dirs.add(tmp);
            }
            for (int i = 0; i < dirs.size() - 1; i++) {
                getFtpClient().changeWorkingDirectory(dirs.get(i));
            }
            String dir = remotePath.substring(remotePath.lastIndexOf("/") + 1, remotePath.length());
            logger.debug("rm " + dir);
            getFtpClient().removeDirectory(dir);
        } else {
            getFtpClient().rmd(remotePath);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        logger.error("removeDirectory error", ex);
        throw new RuntimeException(ex);
    }
}

From source file:net.pms.encoders.Player.java

/**
 * This method populates the supplied {@link OutputParams} object with the correct audio track (aid)
 * based on the MediaInfo metadata and PMS configuration settings.
 *
 * @param media/*from  w  ww . ja  va2s  . co m*/
 * The MediaInfo metadata for the file.
 * @param params
 * The parameters to populate.
 */
public static void setAudioOutputParameters(DLNAMediaInfo media, OutputParams params) {
    // Use device-specific pms conf
    PmsConfiguration configuration = PMS.getConfiguration(params);
    if (params.aid == null && media != null && media.getFirstAudioTrack() != null) {
        // check for preferred audio
        DLNAMediaAudio dtsTrack = null;
        StringTokenizer st = new StringTokenizer(configuration.getAudioLanguages(), ",");
        while (st.hasMoreTokens()) {
            String lang = st.nextToken().trim();
            LOGGER.trace("Looking for an audio track with lang: " + lang);
            for (DLNAMediaAudio audio : media.getAudioTracksList()) {
                if (audio.matchCode(lang)) {
                    params.aid = audio;
                    LOGGER.trace("Matched audio track: " + audio);
                    return;
                }

                if (dtsTrack == null && audio.isDTS()) {
                    dtsTrack = audio;
                }
            }
        }

        // preferred audio not found, take a default audio track, dts first if available
        if (dtsTrack != null) {
            params.aid = dtsTrack;
            LOGGER.trace("Found priority audio track with DTS: " + dtsTrack);
        } else {
            params.aid = media.getAudioTracksList().get(0);
            LOGGER.trace("Chose a default audio track: " + params.aid);
        }
    }
}

From source file:com.icesoft.faces.component.util.CustomComponentUtils.java

/**
 * Gets the comma separated list of visibility user roles from the given
 * component and checks if current user is in one of these roles.
 *
 * @param component a user role aware component
 * @return true if no user roles are defined for this component or user is
 *         in one of these roles, false otherwise
 *///from  w ww. ja  v  a  2s  .c  o m
public static boolean isVisibleOnUserRole(UIComponent component) {
    String userRole;
    if (component instanceof UserRoleAware) {
        userRole = ((UserRoleAware) component).getVisibleOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(UserRoleAware.VISIBLE_ON_USER_ROLE_ATTR);
    }

    if (userRole == null) {
        // no restriction
        return true;
    }

    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringTokenizer st = new StringTokenizer(userRole, ",");
    while (st.hasMoreTokens()) {
        if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) {
            return true;
        }
    }
    return false;
}

From source file:com.icesoft.faces.component.util.CustomComponentUtils.java

/**
 * Gets the comma separated list of enabling user roles from the given
 * component and checks if current user is in one of these roles.
 *
 * @param component a user role aware component
 * @return true if no user roles are defined for this component or user is
 *         in one of these roles, false otherwise
 *//*  ww  w.j a v a2s .  co  m*/
public static boolean isEnabledOnUserRole(UIComponent component) {
    String userRole;
    if (component instanceof UserRoleAware) {
        userRole = ((UserRoleAware) component).getEnabledOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(UserRoleAware.ENABLED_ON_USER_ROLE_ATTR);
    }

    if (userRole == null) {
        // no restriction
        return true;
    }

    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringTokenizer st = new StringTokenizer(userRole, ",");
    while (st.hasMoreTokens()) {
        if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) {
            return true;
        }
    }
    return false;
}

From source file:bioLockJ.Config.java

/**
 * Get a property as list (must be comma delimited)
 * @param propName//from ww  w .j av  a 2  s.  c  om
 * @return
 */
public static List<String> getList(final String propName) {
    final List<String> list = new ArrayList<>();
    final String val = getAProperty(propName);
    if (val != null) {
        final StringTokenizer st = new StringTokenizer(val, ",");
        while (st.hasMoreTokens()) {
            list.add(st.nextToken().trim());
        }
    }

    return list;
}

From source file:com.floreantpos.util.StringUtils.java

/**
 * <p>//from   w w  w .  j a v a 2 s  .c  om
 * '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
 */
public static String removeAndHump(String data, String replaceThis) {
    String temp = null;
    StringBuilder out = new StringBuilder();
    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:bboss.org.apache.velocity.util.StringUtils.java

/**
 * <p>/*from  ww  w  .  j  a  v a  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:com.salesmanager.core.util.FileUtil.java

/**
 * Decrypt & Parses a url with tokens for displaying invoice page
 * /*from   w  ww  . j ava2 s  .c om*/
 * @param token
 * @return
 * @throws Exception
 */
public static Map<String, String> getInvoiceTokens(String token) throws Exception {

    if (StringUtils.isBlank(token)) {
        throw new Exception("token (url parameter) is empty");
    }

    String decrypted = EncryptionUtil.decrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant), token);

    StringTokenizer st = new StringTokenizer(decrypted, "|");
    String orderId = "";
    String customerId = "";

    int i = 0;
    while (st.hasMoreTokens()) {
        String t = st.nextToken();
        if (i == 0) {
            orderId = t;
        } else if (i == 1) {
            customerId = t;
        } else {
            break;
        }
        i++;
    }

    if (StringUtils.isBlank(orderId) || StringUtils.isBlank(customerId)) {
        throw new Exception("Invalid URL parameters for getInvoiceTokens " + token);
    }

    Map response = new HashMap();
    response.put("order.orderId", orderId);
    response.put("customer.customerId", customerId);

    return response;
}

From source file:de.micromata.genome.util.text.TextSplitterUtils.java

/**
 * Parses the string tokens./*from w  w  w .j a  v  a  2s.c  om*/
 *
 * @param text the text
 * @param tokens the tokens
 * @param returnDelimiter the return delimiter
 * @return the list
 */
public static List<String> parseStringTokens(String text, char[] tokens, boolean returnDelimiter) {
    List<String> result = new ArrayList<String>();
    String t = new String(tokens);
    StringTokenizer st = new StringTokenizer(text, t, returnDelimiter);
    while (st.hasMoreTokens() == true) {
        result.add(st.nextToken());
    }
    return result;
}

From source file:com.thoughtworks.go.util.SelectorUtils.java

/**
 * "Flattens" a string by removing all whitespace (space, tab, linefeed,
 * carriage return, and formfeed). This uses StringTokenizer and the
 * default set of tokens as documented in the single arguement constructor.
 *
 * @param input a String to remove all whitespace.
 * @return a String that has had all whitespace removed.
 *///from ww  w  . j ava 2s  . co m
public static String removeWhitespace(String input) {
    StringBuilder result = new StringBuilder();
    if (input != null) {
        StringTokenizer st = new StringTokenizer(input);
        while (st.hasMoreTokens()) {
            result.append(st.nextToken());
        }
    }
    return result.toString();
}