Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

/**
 * Creates the given directory if it does not exist.
 *//*from  w ww .  j  av a2 s.c  om*/
public static File makeDirectory(String directory) throws IOException {
    StringTokenizer tok = new StringTokenizer(directory, "\\/", false);

    File currDir = directory.startsWith("/") ? new File("/") : null;
    while (tok.hasMoreTokens()) {
        String thisDirName = tok.nextToken();

        currDir = new File(currDir, thisDirName); //if currDir null, defaults to 1 arg call

        if (!currDir.exists()) {
            //create
            currDir.mkdir();
            ;
        } else if (currDir.isFile()) {
            throw new IOException("Can't create directory " + thisDirName + " - file with same name exists.");
        }
    }

    return currDir;
}

From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java

public static IntegrationKeys stripCredentials(String configvalue) throws Exception {
    if (configvalue == null)
        return new IntegrationKeys();
    StringTokenizer st = new StringTokenizer(configvalue, ";");
    int i = 1;/*from w  w  w  .  j ava 2s . co m*/
    int j = 1;
    IntegrationKeys keys = new IntegrationKeys();
    while (st.hasMoreTokens()) {
        String value = st.nextToken();

        if (i == 1) {
            // decrypt
            keys.setUserid(value);
        } else if (i == 2) {
            // decrypt
            keys.setPassword(value);
        } else if (i == 3) {
            // decrypt
            keys.setTransactionKey(value);
        } else {
            if (j == 1) {
                keys.setKey1(value);
            } else if (j == 2) {
                keys.setKey2(value);
            } else if (j == 3) {
                keys.setKey3(value);
            }
            j++;
        }
        i++;
    }
    return keys;
}

From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.PennTreeUtils.java

public static PennTreeNode parsePennTree(String aTree) {
    StringTokenizer st = new StringTokenizer(aTree, "() ", true);

    PennTreeNode root = null;//from w  w  w.  j  a  v  a2 s.c  o  m
    Stack<PennTreeNode> stack = new Stack<PennTreeNode>();
    boolean seenLabel = false;
    int i = 0;
    while (st.hasMoreTokens()) {
        String t = st.nextToken().trim();
        if (t.length() == 0) {
            // Skip
        } else if ("(".equals(t)) {
            PennTreeNode n = new PennTreeNode();
            stack.push(n);
            if (root == null) {
                root = n;
            }
            seenLabel = false;
        } else if (")".equals(t)) {
            PennTreeNode n = stack.pop();
            if (!stack.isEmpty()) {
                PennTreeNode p = stack.peek();
                p.addChild(n);
            }
        } else if (seenLabel) {
            // If the node has two labels, its a leaf, add a new terminal node then.
            PennTreeNode p = stack.peek();
            PennTreeNode n = new PennTreeNode();
            n.setTokenIndex(i);
            i++;
            n.setLabel(t);
            p.addChild(n);
        } else {
            PennTreeNode n = stack.peek();
            n.setLabel(t);
            seenLabel = true;
        }
    }

    return root;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public static ArrayList stringToNodeList(String s, SpreadSheet spreadsheet, List fields,
        NodeModelDataFactory factory) {//  w ww .ja va  2s  . c  om
    ArrayList list = new ArrayList();
    StringTokenizer st = new StringTokenizer(s, "\n\r");
    Node node;
    while (st.hasMoreTokens()) {
        node = stringToNode(st.nextToken(), spreadsheet, fields, factory);
        if (node != null)
            list.add(node);
    }
    return list;
}

From source file:de.innovationgate.webgate.api.WGContentKey.java

/**
 * Parses a content key string and returns the according content key object. 
 * The database, whose content is meant needs to be provided to parse the struct key part.
  * If the database is ommitted the struct key will be left in it's string representation..
 * An additional parameter determines, if the unique mode key or the URL mode key is to be created.
 * @param key Content key string representation
 * @param db Content database, whose content is adressed by the content key. Omit to keep struct key in its string representation.
 * @param unique When true, creates unique content key (always use real version), else creates url mode key (if content is released, 0 is taken for version)
 * @return WGContentKey//ww  w .ja v a  2s. co m
 * @throws WGAPIException 
 */
public static WGContentKey parse(String key, WGDatabase db, boolean unique) throws WGAPIException {

    java.util.StringTokenizer tokens = new java.util.StringTokenizer(key, WGContentKey.TOKEN_DIVIDER);
    if (tokens.countTokens() != 3) {
        return null;
    }

    Object structKey = tokens.nextToken();
    if (db != null) {
        structKey = db.parseStructKey((String) structKey);
    }

    String strLanguage = tokens.nextToken();
    String strVersion = tokens.nextToken();

    int version = 0;
    try {
        version = Integer.parseInt(strVersion);
    } catch (NumberFormatException e) {
        // Everything ok. All non-numeric versions (p, mediakey) will get parsed as version 0
    }

    return new WGContentKey(structKey, strLanguage, version);

}

From source file:ddf.security.SubjectUtils.java

/**
 * Retrieves the user name from a given subject.
 *
 * @param subject Subject to get the user name from.
 * @param defaultName Name to send back if no user name was found.
 * @param returnDisplayName return formatted user name for displaying
 * @return String representation of the user name if available or defaultName if no user name
 *     could be found or incoming subject was null.
 *///from   w ww .  jav  a  2s.  c om
public static String getName(Subject subject, String defaultName, boolean returnDisplayName) {
    String name = defaultName;
    if (subject != null) {
        PrincipalCollection principals = subject.getPrincipals();
        if (principals != null) {
            SecurityAssertion assertion = principals.oneByType(SecurityAssertion.class);
            if (assertion != null) {
                Principal principal = assertion.getPrincipal();
                if (principal instanceof KerberosPrincipal) {
                    StringTokenizer st = new StringTokenizer(principal.getName(), "@");
                    st = new StringTokenizer(st.nextToken(), "/");
                    name = st.nextToken();
                } else {
                    name = principal.getName();
                }

                if (returnDisplayName) {
                    name = getDisplayName(principal, name);
                }

            } else {
                // send back the primary principal as a string
                name = principals.getPrimaryPrincipal().toString();
            }
        } else {
            LOGGER.debug(
                    "No principals located in the incoming subject, cannot look up user name. Using default name of {}.",
                    defaultName);
        }
    } else {
        LOGGER.debug("Incoming subject was null, cannot look up user name. Using default name of {}.",
                defaultName);
    }

    LOGGER.debug("Sending back name {}.", name);
    return name;
}

From source file:com.silverpeas.util.i18n.I18NHelper.java

static private String[] getLanguageAndTranslationId(String param) {
    if (StringUtil.isDefined(param)) {
        StringTokenizer tokenizer = new StringTokenizer(param, "_");
        String language = tokenizer.nextToken();
        String translationId = tokenizer.nextToken();
        String[] result = { language, translationId };
        return result;
    }/*w  w  w .  j a  v  a 2  s . c o  m*/
    return null;
}

From source file:net.lightbody.bmp.proxy.jetty.http.InclusiveByteRange.java

/** 
 * @param headers Enumeration of Range header fields.
 * @param size Size of the resource./*from   w  w w  . j  a v  a2s . co  m*/
 * @return LazyList of satisfiable ranges
 */
public static List satisfiableRanges(Enumeration headers, long size) {
    Object satRanges = null;

    // walk through all Range headers
    headers: while (headers.hasMoreElements()) {
        String header = (String) headers.nextElement();
        StringTokenizer tok = new StringTokenizer(header, "=,", false);
        String t = null;
        try {
            // read all byte ranges for this header 
            while (tok.hasMoreTokens()) {
                t = tok.nextToken().trim();

                long first = -1;
                long last = -1;
                int d = t.indexOf('-');
                if (d < 0 || t.indexOf("-", d + 1) >= 0) {
                    if ("bytes".equals(t))
                        continue;
                    log.warn("Bad range format: " + t);
                    continue headers;
                } else if (d == 0) {
                    if (d + 1 < t.length())
                        last = Long.parseLong(t.substring(d + 1).trim());
                    else {
                        log.warn("Bad range format: " + t);
                        continue headers;
                    }
                } else if (d + 1 < t.length()) {
                    first = Long.parseLong(t.substring(0, d).trim());
                    last = Long.parseLong(t.substring(d + 1).trim());
                } else
                    first = Long.parseLong(t.substring(0, d).trim());

                if (first == -1 && last == -1)
                    continue headers;

                if (first != -1 && last != -1 && (first > last))
                    continue headers;

                if (first < size) {
                    InclusiveByteRange range = new InclusiveByteRange(first, last);
                    satRanges = LazyList.add(satRanges, range);
                }
            }
        } catch (Exception e) {
            log.warn("Bad range format: " + t);
            LogSupport.ignore(log, e);
        }
    }
    return LazyList.getList(satRanges, true);
}

From source file:RequestUtil.java

static public String removeQueryStringParam(String queryString, String paramName) {
    String resultString = "";

    if (queryString == null) {
        return queryString;
    }/*from  w w  w  .  ja v  a  2 s . c  om*/
    StringTokenizer st = new StringTokenizer(queryString, "&");
    while (st.hasMoreTokens()) {
        String pair = (String) st.nextToken();
        int pos = pair.indexOf('=');
        if (pos != -1) {
            String key = pair.substring(0, pos);
            if (paramName.equals(key))
                continue;
        }

        if (resultString.length() > 0)
            resultString += "&";
        resultString += pair;
    }
    return resultString;
}

From source file:com.emaxcore.emaxdata.common.web.Servlets.java

/**
 * ?? If-None-Match Header, Etag?./* ww w  .j  av  a  2 s.  co  m*/
 *
 * Etag, checkIfNoneMatchfalse, 304 not modify status.
 *
 * @param etag ETag.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH);
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");
            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader(HttpHeaders.ETAG, etag);
            return false;
        }
    }
    return true;
}