Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

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

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:com.bigdata.dastor.db.ColumnFamilyStore.java

public static int getGenerationFromFileName(String filename) {
    /*/*  w  w w.j  ava  2s. c  om*/
     * File name is of the form <table>-<column family>-<index>-Data.db.
     * This tokenizer will strip the .db portion.
     */
    StringTokenizer st = new StringTokenizer(filename, "-");
    /*
     * Now I want to get the index portion of the filename. We accumulate
     * the indices and then sort them to get the max index.
     */
    int count = st.countTokens();
    int i = 0;
    String index = null;
    while (st.hasMoreElements()) {
        index = (String) st.nextElement();
        if (i == (count - 2)) {
            break;
        }
        ++i;
    }
    return Integer.parseInt(index);
}

From source file:com.serena.rlc.provider.tfs.TFSDeploymentUnitProvider.java

@Getter(name = BUILD_STATUS_FILTER, displayName = "Build Status Filter", description = "Build Status Filter.")
public FieldInfo getBuildStatusFilterFieldValues(String fieldName, List<Field> properties)
        throws ProviderException {
    if (StringUtils.isEmpty(buildStatusFilter)) {
        return null;
    }/*  www  .  j ava 2 s . c  o  m*/

    StringTokenizer st = new StringTokenizer(buildStatusFilter, ",;");
    FieldInfo fieldInfo = new FieldInfo(fieldName);
    List<FieldValueInfo> values = new ArrayList<>();
    FieldValueInfo value;
    String status;
    while (st.hasMoreElements()) {
        status = (String) st.nextElement();
        status = status.trim();
        value = new FieldValueInfo(status, status);
        values.add(value);
    }

    fieldInfo.setValues(values);
    return fieldInfo;
}

From source file:com.serena.rlc.provider.tfs.TFSDeploymentUnitProvider.java

@Getter(name = BUILD_RESULT_FILTER, displayName = "Build Result Filter", description = "Build Result Filter.")
public FieldInfo getBuildResultFilterFieldValues(String fieldName, List<Field> properties)
        throws ProviderException {
    if (StringUtils.isEmpty(buildResultFilter)) {
        return null;
    }/*from www . ja va2 s  .c o  m*/

    StringTokenizer st = new StringTokenizer(buildResultFilter, ",;");
    FieldInfo fieldInfo = new FieldInfo(fieldName);
    List<FieldValueInfo> values = new ArrayList<>();
    FieldValueInfo value;
    String status;
    while (st.hasMoreElements()) {
        status = (String) st.nextElement();
        status = status.trim();
        value = new FieldValueInfo(status, status);
        values.add(value);
    }

    fieldInfo.setValues(values);
    return fieldInfo;
}

From source file:es.onebox.rest.utils.service.QueryService.java

/**
 * This method generates the string to be signed based on the following rules:
 *
 *  - Add the request method + \n//  w  ww.  ja va 2s. c o m
 *  - Add the timestamp + \n
 *  - Add the request URI
 *  - For each request parameter ordered alphabetically:
 *    - First parameter delimiter ?
 *    - Other parameters separated by &
 *    - Name of the parameter
 *    - Add = sign
 *    - value of the parameter
 *
 * For example:
 *
 *   Given a GET request with timestamp = 1316430943576 and uri = /uri_path/ejemplo with parameters,
 *     Bc = 'Prueba1'
 *     Aa = 'Prueba2'
 *     bc = 'aPrueba3'
 *     z1 = 'prueba4'
 *
 *   The String to sign is:
 *
 *     GET\n1316430943576\n/uri_path/ejemplo?amp;Aa=Prueba2&bc=aPrueba3&Bc=Prueba1&z1=prueba4
 *
 * @param uri
 * @param method
 * @param timestamp
 * @return
 * @throws SignatureException
 */
private String getStringToSign(URI uri, String method, long timestamp, QueryForm queryForm)
        throws SignatureException {

    SortedMap<String, String> sortedMap = new TreeMap<String, String>();

    // Assuming GET. It actually processes URL parameters for all Method types
    if (uri.getRawQuery() != null) {

        StringTokenizer tokenizer = null;
        try {
            tokenizer = new StringTokenizer(URLDecoder.decode(uri.getRawQuery(), UTF_8), AMPERSAND);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        while (tokenizer.hasMoreElements()) {
            String token = tokenizer.nextToken();
            sortedMap.put(token.split(PARAM_NAME_VALUE_SEPARATOR)[0].toLowerCase()
                    + token.split(PARAM_NAME_VALUE_SEPARATOR)[1], token);
        }
    }

    // If POST process parameter map
    if (method.equals(HttpMethod.POST.name())) {
        for (String key : ((Set<String>) ((MultiMap) queryForm.getFormParameters()).keySet())) {
            for (String valor : ((List<String>) ((MultiMap) queryForm.getFormParameters()).get(key))) {
                sortedMap.put(key.toLowerCase() + PARAM_NAME_VALUE_SEPARATOR + valor,
                        key + PARAM_NAME_VALUE_SEPARATOR + valor);
            }
        }

    }

    // Generating String to sign
    StringBuilder stringToSign = new StringBuilder();
    stringToSign.append(method);
    stringToSign.append(HMAC_FIELD_SEPARATOR).append(timestamp);
    stringToSign.append(HMAC_FIELD_SEPARATOR).append(uri.getPath());

    boolean firstParam = true;

    for (String param : sortedMap.values()) {
        if (firstParam) {
            stringToSign.append(URI_PARAMETERS_SEPARATOR).append(param);
            firstParam = false;
        } else {
            stringToSign.append(PARAMETERS_SEPARATOR).append(param);
        }
    }

    return stringToSign.toString();
}

From source file:org.craftercms.cstudio.publishing.servlet.FileUploadServlet.java

/**
 * delete files form target//from w w w  .j a v a 2s  .c o m
 * @param parameters
 * @param target
 * @param changeSet
 */
protected void deleteFromTarget(Map<String, String> parameters, PublishingTarget target,
        PublishedChangeSet changeSet) {
    String deletedList = parameters.get(PARAM_DELETED_FILES);
    String site = parameters.get(PARAM_SITE);
    if (deletedList != null) {
        StringTokenizer tokens = new StringTokenizer(deletedList, FILES_SEPARATOR);
        List<String> deletedFiles = new ArrayList<String>(tokens.countTokens());
        while (tokens.hasMoreElements()) {
            String contentLocation = tokens.nextToken();
            contentLocation = StringUtils.trimWhitespace(contentLocation);
            String root = target.getParameter(CONFIG_ROOT);
            String fullPath = root + File.separator + target.getParameter(CONFIG_CONTENT_FOLDER)
                    + contentLocation;
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("deleting " + fullPath);
            }
            if (StringUtils.hasText(site)) {
                fullPath = fullPath.replaceAll(CONFIG_MULTI_TENANCY_VARIABLE, site);
            }
            File file = new File(fullPath);
            if (file.exists()) {
                if (file.isFile()) {
                    file.delete();
                    deletedFiles.add(contentLocation);
                } else {
                    deleteChildren(file.list(), fullPath, contentLocation, deletedFiles);
                    file.delete();
                }
            } else {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(fullPath + " is not deleted since it does not exsit.");
                }
            }
            fullPath = root + '/' + target.getParameter(CONFIG_METADATA_FOLDER) + contentLocation
                    + CONFIG_METADATA_FILENAME_SUFFIX;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("deleting " + fullPath);
            }
            if (StringUtils.hasText(site)) {
                fullPath = fullPath.replaceAll(CONFIG_MULTI_TENANCY_VARIABLE, site);
            }
            file = new File(fullPath);
            if (file.exists()) {
                file.delete();
            } else if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(fullPath + " is not deleted since it does not exsit.");
            }
        }
        changeSet.setDeletedFiles(deletedFiles);
    }
}

From source file:org.pentaho.common.ui.metadata.service.MetadataService2.java

/**
 * Returns a Model object for the requested model. The model will include the basic metadata - categories and columns.
 * //w  w  w. jav a 2 s. c  om
 * @param domainId
 * @param modelId
 * @return
 */
@Override
public Model getModel(String id) {

    // parse out the id
    StringTokenizer tokenizer = new StringTokenizer(id, "~");

    String providerId = null;
    String domainId = null;
    String modelId = null;
    while (tokenizer.hasMoreElements()) {
        String str = tokenizer.nextToken();
        if (providerId == null) {
            providerId = str;
        } else if (domainId == null) {
            domainId = str;
        } else {
            modelId = str;
        }
    }

    if (domainId == null) {
        // we can't do this without a model
        error(Messages.getErrorString("MetadataService.ERROR_0003_NULL_DOMAIN")); //$NON-NLS-1$
        return null;
    }

    if (modelId == null) {
        // we can't do this without a model
        error(Messages.getErrorString("MetadataService.ERROR_0004_NULL_Model")); //$NON-NLS-1$
        return null;
    }

    // because it's lighter weight, check the thin model
    Domain domain = getMetadataRepository().getDomain(domainId);
    if (domain == null) {
        error(Messages.getErrorString("MetadataService.ERROR_0005_DOMAIN_NOT_FOUND", domainId)); //$NON-NLS-1$
        return null;
    }

    LogicalModel model = domain.findLogicalModel(modelId);

    if (model == null) {
        // the model cannot be found or cannot be loaded
        error(Messages.getErrorString("MetadataService.ERROR_0006_MODEL_NOT_FOUND", modelId)); //$NON-NLS-1$
        return null;
    }

    // create the thin metadata model and return it
    MetadataServiceUtil2 util = new MetadataServiceUtil2();
    util.setDomain(domain);
    Model thinModel = util.createThinModel(model, domainId);
    thinModel.setProvider(provider);
    return thinModel;

}

From source file:util.IPChecker.java

private boolean compareIP4(final String ip, final String ip_db) {

    try {// w ww  . j a  v a  2 s .c om

        String compare = ip_db.substring(ip.indexOf('.', ip.indexOf('.') + 1) + 1);

        final List<String> parts = new ArrayList<String>();
        final StringTokenizer tokenizer = new StringTokenizer(ip, ".");
        while (tokenizer.hasMoreElements()) {
            parts.add(tokenizer.nextElement().toString());
        }

        final String part3 = parts.get(2);
        String part4 = null;
        if (parts.size() == 4) {
            part4 = parts.get(3);
        }

        // Wildcard oder Bereich im dritten Oktett
        if (!compare.contains(".") || part4 == null) {
            // we may have an compare with .
            if (compare.contains(".")) {
                // reset compare to 3th part
                compare = compare.substring(0, compare.indexOf("."));
            }
            if ("*".equals(compare) || "*".equals(part3)) {
                // Wildcard in IP from request or from DB in 3th part
                return true;
            }
            if (compare.contains("-")) { // Bereich
                final int compStart = Integer.valueOf(compare.substring(0, compare.indexOf('-')));
                final int compEnd = Integer.valueOf(compare.substring(compare.indexOf('-') + 1));

                if (part3.contains("-")) {
                    // 3th part contains range
                    final int okt3Start = Integer.valueOf(part3.substring(0, part3.indexOf('-')));
                    final int okt3End = Integer.valueOf(part3.substring(part3.indexOf('-') + 1));
                    if (compStart <= okt3Start && okt3Start <= compEnd
                            || compStart <= okt3End && okt3End <= compEnd
                            || okt3Start <= compStart && compStart <= okt3End) {
                        return true;
                    }
                } else {
                    // 3th part is normal number
                    final int okt3 = Integer.valueOf(part3);
                    if (compStart <= okt3 && okt3 <= compEnd) {
                        return true;
                    }
                }
            } else if (part3.contains("-")) {
                final int part3Start = Integer.valueOf(part3.substring(0, part3.indexOf('-')));
                final int part3End = Integer.valueOf(part3.substring(part3.indexOf('-') + 1));

                // compare is normal number
                final int comp3 = Integer.valueOf(compare);
                if (part3Start <= comp3 && comp3 <= part3End) {
                    return true;
                }

            }

        } else { // Wildcard oder Bereich im vierten Oktett
            final String compare3 = compare.substring(0, compare.indexOf('.'));
            final String compare4 = compare.substring(compare.indexOf('.') + 1);
            if (compare3.equals(part3)) { // 3th part must match
                if ("*".equals(compare4) || "*".equals(part4)) {
                    // Wildcard in IP from request or from DB in 4th part
                    return true;
                }
                if (compare4.contains("-")) { // Bereich
                    final int compStart = Integer.valueOf(compare4.substring(0, compare4.indexOf('-')));
                    final int compEnd = Integer.valueOf(compare4.substring(compare4.indexOf('-') + 1));

                    if (part4.contains("-")) {
                        // 4th part contains range
                        final int okt4Start = Integer.valueOf(part4.substring(0, part4.indexOf('-')));
                        final int okt4End = Integer.valueOf(part4.substring(part4.indexOf('-') + 1));
                        if (compStart <= okt4Start && okt4Start <= compEnd
                                || compStart <= okt4End && okt4End <= compEnd
                                || okt4Start <= compStart && compStart <= okt4End) {
                            return true;
                        }
                    } else {
                        // 4th part is normal number
                        final int okt4 = Integer.valueOf(part4);
                        if (compStart <= okt4 && okt4 <= compEnd) {
                            return true;
                        }
                    }
                }
            }
        }

    } catch (final Exception e) {
        LOG.error("boolean compareIP4(String ip, String ip_db): " + e.toString());
    }

    return false;
}

From source file:com.liusoft.dlog4j.action.PhotoAction.java

/**
 * ??//from w ww . j ava  2 s .com
 * @param file
 * @return
 */
protected boolean accept(FormFile file) {
    String ext = StringUtils.getFileExtend(file.getFileName());
    if (ext == null)
        return false;
    String filesDenied = getServlet().getInitParameter("filesDenied");
    if (filesDenied == null)
        return true;

    StringTokenizer st = new StringTokenizer(filesDenied, ",");
    while (st.hasMoreElements()) {
        if (ext.equalsIgnoreCase(st.nextToken()))
            return false;
    }
    return true;
}

From source file:org.openiam.webadmin.res.ResourceApprovalFlowController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {

    log.info("onSubmit called");

    ResourceApprovalFlowCommand assocCmd = (ResourceApprovalFlowCommand) command;
    String resId = assocCmd.getResId();

    String userId = (String) request.getSession().getAttribute("userId");
    String domainId = (String) request.getSession().getAttribute("domainid");
    String login = (String) request.getSession().getAttribute("login");

    Resource res = resourceDataService.getResource(resId);

    String btn = request.getParameter("btn");
    if (btn.equalsIgnoreCase("Delete")) {
        List<ApproverAssociation> assocList = assocCmd.getApproverAssoc();
        if (assocList != null) {

            for (ApproverAssociation a : assocList) {
                if (a.getSelected()) {
                    String assocId = a.getApproverAssocId();
                    if (!assocId.equalsIgnoreCase("NEW")) {
                        managedSysService.removeApproverAssociation(assocId);

                        auditHelper.addLog("MODIFY", domainId, login, "WEBCONSOLE", userId, "0", "RESOURCE",
                                resId, null, "SUCCESS", null, "DELETE APPROVER", a.getApproverUserId(), null,
                                null, res.getName(), request.getRemoteHost());

                    }/*from   w  ww.j  a  v  a 2s .  c om*/
                }
            }

        }
    } else {

        List<ApproverAssociation> assocList = assocCmd.getApproverAssoc();

        if (assocList != null) {

            for (ApproverAssociation a : assocList) {
                if (a.getApproverRoleId() != null && a.getApproverRoleId().length() > 0) {
                    String roleStr = a.getApproverRoleId();
                    StringTokenizer st = new StringTokenizer(roleStr, "*");
                    if (st.hasMoreTokens()) {
                        a.setApproverRoleDomain(st.nextToken());
                    }
                    if (st.hasMoreElements()) {
                        a.setApproverRoleId(st.nextToken());
                    }

                } else {
                    a.setApproverRoleDomain(null);
                    a.setApproverRoleId(null);
                }

                if (a.getApproverAssocId() == null || a.getApproverAssocId().equalsIgnoreCase("NEW")) {

                    // new
                    if (a.getAssociationType() != null && a.getAssociationType().length() > 0) {
                        a.setApproverAssocId(null);
                        a.setRequestType(resId);
                        if (a.getApproverLevel() == null) {
                            a.setApproverLevel(1);
                        }

                        managedSysService.addApproverAssociation(a);

                        auditHelper.addLog("MODIFY", domainId, login, "WEBCONSOLE", userId, "0", "RESOURCE",
                                resId, null, "SUCCESS", null, "ADD APPROVER", a.getApproverUserId(), null, null,
                                res.getName(), request.getRemoteHost());
                    }
                } else {
                    // update
                    if (a.getAssociationType() != null && a.getAssociationType().length() > 0) {
                        if (a.getApproverLevel() == null) {
                            a.setApproverLevel(1);
                        }

                        managedSysService.updateApproverAssociation(a);

                        auditHelper.addLog("MODIFY", domainId, login, "WEBCONSOLE", userId, "0", "RESOURCE",
                                resId, null, "SUCCESS", null, "MODIFY APPROVER", a.getApproverUserId(), null,
                                null, res.getName(), request.getRemoteHost());
                    }
                }
            }

        }
    }
    log.info("refreshing attr list for resourceId=" + resId);
    String view = redirectView + "&menuid=RESAPPROVER&menugrp=SECURITY_RES&objId=" + resId;
    log.info("redirecting to=" + view);

    return new ModelAndView(new RedirectView(view, true));

}

From source file:importer.filters.PlayFilter.java

/**
 * Construct a list of what you know are definitely words
 * @param input the input text/*from www  .  j a v  a2 s  .  c  o  m*/
 * @return error log
 */
private String buildWordList(String input) {
    StringTokenizer st = new StringTokenizer(input, "\n\t ", true);
    int state = 0;
    while (st.hasMoreElements()) {
        String token = st.nextToken();
        if (token.length() == 0)
            break;
        switch (state) {
        // at line-start
        case 0:
            if (!Character.isWhitespace(token.charAt(0))) {
                if (endOfSentence(token))
                    state = 2;
                else
                    state = 1;
                token = strip(token);
                if (token.length() == 0)
                    break;
                if (isWord(token) && !words.contains(token))
                    words.add(token);
            }
            break;
        //not at line-start, not after full stop
        case 1:
            if (!Character.isWhitespace(token.charAt(0))) {
                if (endOfSentence(token))
                    state = 2;
                token = strip(token);
                if (token.length() == 0)
                    break;
                if (isWord(token)) {
                    if (!words.contains(token))
                        words.add(token);
                }
            } else if (token.equals("\n"))
                state = 0;
            break;
        // after sentence end
        case 2:
            if (!Character.isWhitespace(token.charAt(0))) {
                if (!endOfSentence(token))
                    state = 1;
                token = strip(token);
                if (token.length() == 0)
                    break;
                if (isWord(token)) {
                    if (!words.contains(token))
                        words.add(token);
                }
            } else if (token.equals("\n"))
                state = 0;
            break;
        }
    }
    // this will do for now
    return "";
}