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:org.wso2.carbon.andes.event.core.internal.subscription.registry.TopicManagerServiceImpl.java

/**
 * Admin user and user who had add topic permission create the hierarchy topic get permission to all level by default
 *
 * @param userRealm User's Realm/*from w ww  . j ava  2  s  .  c  om*/
 * @param topicId topic id
 * @param role admin role
 * @throws UserStoreException
 */
private static void grantPermissionToHierarchyLevel(UserRealm userRealm, String topicId, String role)
        throws UserStoreException {
    //tokenize resource path
    StringTokenizer tokenizer = new StringTokenizer(topicId, "/");
    StringBuilder resourcePathBuilder = new StringBuilder();
    //get token count
    int tokenCount = tokenizer.countTokens();
    int count = 0;
    Pattern pattern = Pattern.compile(PARENT_RESOURCE_PATH);

    while (tokenizer.hasMoreElements()) {
        //get each element in topicId resource path
        String resource = tokenizer.nextElement().toString();
        //build resource path again
        resourcePathBuilder.append(resource);
        //we want to give permission to any resource after event/topics/ in build resource path
        Matcher matcher = pattern.matcher(resourcePathBuilder.toString());
        if (matcher.find()) {
            // gives subscribe permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_SUBSCRIBE);
            // gives publish permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_PUBLISH);
            // gives change permissions to the internal role in the user store
            userRealm.getAuthorizationManager().authorizeRole(role, resourcePathBuilder.toString(),
                    EventBrokerConstants.EB_PERMISSION_CHANGE_PERMISSION);
        }
        count++;
        if (count < tokenCount) {
            resourcePathBuilder.append("/");
        }

    }
}

From source file:com.ckfinder.connector.utils.FileUtils.java

/**
 * rename file with double extension./*ww w. jav  a 2s . c o  m*/
 * @param fileName file name
 * @return new file name with . replaced with _ (but not last)
 */
public static String renameFileWithBadExt(final ResourceType type, final String fileName) {
    if (type == null || fileName == null) {
        return null;
    }

    if (fileName.indexOf('.') == -1) {
        return fileName;
    }

    StringTokenizer tokens = new StringTokenizer(fileName, ".");
    String cfileName = tokens.nextToken();
    String currToken = "";
    while (tokens.hasMoreTokens()) {
        currToken = tokens.nextToken();
        if (tokens.hasMoreElements()) {
            cfileName = cfileName.concat(checkSingleExtension(currToken, type) ? "." : "_");
            cfileName = cfileName.concat(currToken);
        } else {
            cfileName = cfileName.concat(".".concat(currToken));
        }
    }
    return cfileName;
}

From source file:org.wso2.carbon.registry.synchronization.operation.UpdateCommand.java

private static String refinedPathToPrint(String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, "/");

    StringBuilder refinedPath = new StringBuilder("");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        // if .. found ignore the next element
        if (!token.equals("..")) {
            refinedPath.append(token);//from ww w  .j  a v  a 2 s .c  o  m
            if (tokenizer.hasMoreElements()) {
                refinedPath.append("/");
            }
        }
    }
    return refinedPath.toString();
}

From source file:org.modeldriven.fuml.xmi.XmiInternalReferenceElement.java

private void construct() {
    String data = this.node.getData();
    if (data != null) {
        StringTokenizer st = new StringTokenizer(data);
        if (!st.hasMoreElements())
            throw new XmiException("one or more id's expected");
        while (st.hasMoreElements()) {
            String ref = st.nextToken();
            ids.add(ref);//ww w  . j a va2 s  .  com
        }
    } else {
        StreamNode eventNode = (StreamNode) node;
        QName name = new QName(eventNode.getContext().getXmiNamespace().getNamespaceURI(),
                XmiConstants.ATTRIBUTE_XMI_IDREF);
        Attribute idref = eventNode.getAttribute(name);
        if (idref != null) {
            ids.add(idref.getValue());
        } else
            throw new XmiException(
                    "expected character data or idref attribute for element, " + eventNode.getLocalName());
    }
}

From source file:com.ckfinder.connector.utils.FileUtils.java

/**
 * creates file and all above folders that doesn"t exists.
 * @param file file to create.//from  ww w . j a v a 2  s.com
 * @param conf connector configuration
 * @param isFile if it is path to folder.
 * @throws IOException when io error occurs.
 */
public static void createPath(final File file, final IConfiguration conf, final boolean isFile)
        throws IOException {
    String path = file.getAbsolutePath();
    // on Linux first path char - "/" is removed by StringTokenizer
    StringTokenizer st = new StringTokenizer(path, File.separator);

    // if path include "/" as a first char of path we have to add it manually
    String checkPath = (path.indexOf(File.separator) == 0) ? File.separator : "";
    checkPath += (String) st.nextElement();
    while (st.hasMoreElements()) {
        String string = (String) st.nextElement();
        checkPath = checkPath.concat(File.separator + string);
        if (!(string.equals(file.getName()) && isFile)) {
            File dir = new File(checkPath);
            if (!dir.exists()) {
                mkdir(dir, conf);
            }
        } else {
            file.createNewFile();
        }
    }
}

From source file:org.webguitoolkit.ui.controls.util.validation.ListOfNumbersValidator.java

public void validate(String value) throws ValidationException {
    if (!StringUtils.isBlank(value)) {
        // validate input
        StringTokenizer st = new StringTokenizer(value, separator, false);
        while (st.hasMoreElements()) {
            // check if long
            String check = st.nextToken();
            if (StringUtils.isNotBlank(check)) {
                try {
                    Long.parseLong(check.trim());
                } catch (NumberFormatException e) {
                    throw new ValidationException(TextService.getString(errorMessage, separator));
                }//  ww w . j a v a2  s .  c  om
            }
        }
    }
}

From source file:org.obiba.onyx.print.impl.PdfTemplateReport.java

public void setFieldToVariableMap(String keyValuePairs) {
    fieldToVariableMap = new HashMap<String, String>();
    // Get list of strings separated by the delimiter
    StringTokenizer tokenizer = new StringTokenizer(keyValuePairs, ",");
    while (tokenizer.hasMoreElements()) {
        String token = tokenizer.nextToken();
        String[] entry = token.split("=");
        if (entry.length == 2) {
            fieldToVariableMap.put(entry[0].trim(), entry[1].trim());
        } else {/*from  ww w . java 2 s  . c  o  m*/
            log.error("Could not identify PDF field name to variable path mapping: " + token);
        }
    }
}

From source file:org.modeldriven.fuml.xmi.XmiReferenceAttribute.java

private void construct() {
    String data = this.attribute.getValue();
    if (data != null) {
        StringTokenizer st = new StringTokenizer(data);
        if (!st.hasMoreElements())
            throw new XmiException("one or more id's expected");
        while (st.hasMoreElements()) {
            String ref = st.nextToken();
            ids.add(ref);/*from   ww  w . j ava2 s.c o m*/
        }
    } else
        log.warn("expected value for attribute, " + this.attribute.getName().getLocalPart());
}

From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java

/**
 * This method splits the source string by separator string.
 * @param source/*from ww w . j a v a2  s  .co  m*/
 *        The initial string
 * @param separator
 *        The separator string between tokens
 * @return string list
 */
public static List<String> splitString(String source, String separator) {
    List<String> result = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(source, separator);
    while (st.hasMoreElements()) {
        String token = (String) st.nextElement();
        result.add(token);
    }
    return result;
}

From source file:org.dozer.fieldmap.HintContainer.java

public List<Class<?>> getHints() {
    if (hints == null) {
        List<Class<?>> list = new ArrayList<Class<?>>();
        StringTokenizer st = new StringTokenizer(this.hintName, ",");
        while (st.hasMoreElements()) {
            String theHintName = st.nextToken().trim();

            Class<?> clazz = MappingUtils.loadClass(theHintName);
            list.add(clazz);//from   www  .j  ava  2  s.co m
        }
        hints = list;
    }
    return hints;
}