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:Main.java

/**
 * Find the xpath element under the given root. As the xpath requirement is very
 * simple, so we avoid using XPath API//from w  ww.java2s . c o  m
 * @param root - the root element that search begins
 * @param xpath - the path from the root
 * @return - the xpath defined element under the given root.
 */
public static Element findXPathElement(Element root, String xpath) {
    if (root == null)
        return null;
    if (xpath == null || xpath.trim().equals(""))
        return root;
    xpath = toRelativePath(xpath, root.getNodeName());
    StringTokenizer st = new StringTokenizer(xpath, "/", false);
    String sitem;
    Element item = root;
    NodeList list;

    boolean first = true;
    while (st.hasMoreTokens()) {
        sitem = st.nextToken();
        if (first && sitem.equals(item.getNodeName())) {
            first = false;
        } else {
            list = item.getElementsByTagName(sitem);
            if (list.getLength() < 1)
                return null;
            item = (Element) (list.item(0));
        }
    }

    return item;
}

From source file:it.unipd.dei.ims.falcon.CmdLine.java

private static int[] parseIntArray(String s) {
    StringTokenizer t = new StringTokenizer(s, ",");
    int[] ia = new int[t.countTokens()];
    int ti = 0;/*  w  w  w  .j  av  a 2 s  .c  om*/
    while (t.hasMoreTokens())
        ia[ti] = Integer.parseInt(t.nextToken());
    return ia;
}

From source file:org.apache.geode.geospatial.utils.ToolBox.java

public static void configureDefaultClientPool(ClientCacheFactory clientCacheFactory, String locators) {
    StringTokenizer stringTokenizer = new StringTokenizer(locators, ",");
    clientCacheFactory.setPoolMaxConnections(-1);
    clientCacheFactory.setPoolPRSingleHopEnabled(true);

    while (stringTokenizer.hasMoreTokens()) {
        String curr = stringTokenizer.nextToken();
        DistributionLocatorId locatorId = new DistributionLocatorId(curr);
        String addr = locatorId.getBindAddress();
        if (addr != null && addr.trim().length() > 0) {
            clientCacheFactory.addPoolLocator(addr, locatorId.getPort());
        } else {/* www  .j  a v a 2s.c  om*/
            clientCacheFactory.addPoolLocator(locatorId.getHost().getHostName(), locatorId.getPort());
        }
    }
    clientCacheFactory.create();
}

From source file:com.bdaum.zoom.gps.internal.GpsUtilities.java

public static void getGeoAreas(IPreferenceStore preferenceStore, Collection<GeoArea> areas) {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
    nf.setMaximumFractionDigits(8);//from   w w  w  .j a v a 2 s.  co m
    nf.setGroupingUsed(false);
    String nogo = preferenceStore.getString(PreferenceConstants.NOGO);
    if (nogo != null) {
        int i = 0;
        double lat = 0, lon = 0, km = 0;
        String name = null;
        StringTokenizer st = new StringTokenizer(nogo, ";,", true); //$NON-NLS-1$
        while (st.hasMoreTokens()) {
            String s = st.nextToken();
            if (";".equals(s)) { //$NON-NLS-1$
                areas.add(new GeoArea(name, lat, lon, km));
                i = 0;
            } else if (",".equals(s)) //$NON-NLS-1$
                ++i;
            else
                try {
                    switch (i) {
                    case 0:
                        name = s;
                        break;
                    case 1:
                        lat = nf.parse(s).doubleValue();
                        break;
                    case 2:
                        lon = nf.parse(s).doubleValue();
                        break;
                    case 3:
                        km = nf.parse(s).doubleValue();
                        break;
                    }
                } catch (ParseException e) {
                    // do nothing
                }
        }
    }
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

public static Map<String, String[]> parseQueryString(String s) {
    String valArray[] = null;//from   w w w.  j  a  v  a  2 s.  co m
    if (s == null) {
        throw new IllegalArgumentException();
    }
    Map<String, String[]> ht = new HashMap<String, String[]>();
    StringTokenizer st = new StringTokenizer(s, "&");
    while (st.hasMoreTokens()) {
        String pair = (String) st.nextToken();
        int pos = pair.indexOf('=');
        if (pos == -1) {
            continue;
        }
        String key = pair.substring(0, pos);
        String val = pair.substring(pos + 1, pair.length());
        if (ht.containsKey(key)) {
            String oldVals[] = (String[]) ht.get(key);
            valArray = new String[oldVals.length + 1];
            for (int i = 0; i < oldVals.length; i++) {
                valArray[i] = oldVals[i];
            }
            valArray[oldVals.length] = val;
        } else {
            valArray = new String[1];
            valArray[0] = val;
        }
        ht.put(key, valArray);
    }
    return ht;
}

From source file:apim.restful.importexport.utils.AuthenticatorUtil.java

/**
 * Checks whether user has provided non blank username and password for authentication
 *
 * @param headers Http Headers of the request
 * @return boolean Whether a user name and password has been provided for authentication
 * @throws APIExportException If an error occurs while extracting username and password from
 *                            the header
 *///from  ww w .j a  v a2s  .  c  o  m
private static boolean isValidCredentials(HttpHeaders headers) throws APIExportException {

    //Fetch authorization header
    final List<String> authorization = headers.getRequestHeader(AUTHORIZATION_PROPERTY);

    //If no authorization information present; block access
    if (authorization == null || authorization.isEmpty()) {
        return false;
    }

    //Get encoded username and password
    final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");

    //Decode username and password
    String usernameAndPassword;
    usernameAndPassword = StringUtils.newStringUtf8(Base64.decodeBase64(encodedUserPassword.getBytes()));

    if (usernameAndPassword != null) {
        //Split username and password tokens
        final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");

        if (tokenizer.hasMoreTokens()) {
            username = tokenizer.nextToken();
        }

        if (tokenizer.hasMoreTokens()) {
            password = tokenizer.nextToken();
        }

        if (username != null && password != null) {
            return true;
        }
    }

    return false;
}

From source file:com.thruzero.common.core.infonode.builder.utils.SampleNodeBuilderUtils.java

public static String normalize(String elements) {
    StringBuilder result = new StringBuilder();
    elements = StringUtils.replace(elements, "\r", "");
    elements = StringUtils.replace(elements, "\n", "");
    StringTokenizer st = new StringTokenizer(elements, " ");

    while (st.hasMoreTokens()) {
        String token = st.nextToken();

        result.append(StringUtils.trimToEmpty(token));
    }// w  ww  .j  av a 2  s . c om

    return result.toString();
}

From source file:cz.incad.cdk.RepairVCProcess.java

@Process
public static void process() {
    try {/*  w  w  w. j  av a 2 s . c om*/
        FedoraAccessImpl fa = new FedoraAccessImpl(KConfiguration.getInstance(), null);
        String query = "*%20<fedora-model:hasModel>%20*";
        String ri = KConfiguration.getInstance().getProperty("FedoraResourceIndex");
        String fuser = KConfiguration.getInstance().getProperty("fedoraUser");
        String fpass = KConfiguration.getInstance().getProperty("fedoraPass");

        LOGGER.info("requesting resource index");
        InputStream istream = RESTHelper.inputStream(
                ri + "?type=triples&lang=spo&format=N-Triples&distinct=on&query=" + query, fuser, fpass);
        LOGGER.info("processing results");

        BufferedReader bReader = new BufferedReader(new InputStreamReader(istream));
        String line = null;
        while ((line = bReader.readLine()) != null) {
            StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
            if (tokenizer.hasMoreTokens()) {
                String nextToken = tokenizer.nextToken();
                nextToken = nextToken.trim().substring(1);
                nextToken = nextToken.substring(0, nextToken.lastIndexOf('>'));
                try {
                    PIDParser parser = new PIDParser(nextToken);
                    parser.disseminationURI();
                    String pid = parser.getObjectPid();
                    if (pid.startsWith("uuid")) {
                        LOGGER.info("processing '" + pid + "'");
                        Document relsExt = fa.getRelsExt(pid);
                        checkRelsExt(pid, relsExt, fa);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.err.println("skipping " + nextToken);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:Main.java

/**
 * /*www .  j a  v a  2  s .  c o  m*/
 * @param value
 * @return Object[]
 */
public static Object[] toArray(final String value) {
    if (value == null) {
        return new Object[] {};
    }

    final int BRACKET_LENGTH = 1;
    final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Object> collection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        collection.add(tokenizer.nextToken().trim());
    }

    return collection.toArray();
}

From source file:gsn.storage.SQLUtils.java

public static String getTableName(String query) {
    String q = SQLValidator.removeSingleQuotes(SQLValidator.removeQuotes(query)).toLowerCase();
    StringTokenizer tokens = new StringTokenizer(q, " ");
    while (tokens.hasMoreElements())
        if (tokens.nextToken().equalsIgnoreCase("from") && tokens.hasMoreTokens())
            return tokens.nextToken();
    return null;/*from  ww  w  .ja v a 2 s  . c o  m*/
}