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.kchine.rpf.PoolUtils.java

public static String getAbsoluteClassPath() {
    StringBuffer result = new StringBuffer();
    StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"),
            System.getProperty("path.separator"));
    while (st.hasMoreElements()) {
        String element = (String) st.nextElement();
        try {/*from ww  w. j  av  a 2 s .c  o  m*/
            result.append(new File(element).getAbsolutePath());
            if (st.hasMoreElements()) {
                result.append(System.getProperty("path.separator"));
            }
        } catch (Exception e) {
            result.append(element);
            if (st.hasMoreElements()) {
                result.append(System.getProperty("path.separator"));
            }
        }
    }
    return result.toString();
}

From source file:com.neka.cordova.inappbrowser.InAppBrowser.java

/**
 * Put the list of features into a hash map
 * //from  w ww . j  ava 2  s.  com
 * @param optString
 * @return
 */
private HashMap<String, Boolean> parseFeature(String optString) {
    if (optString.equals(NULL)) {
        return null;
    } else {
        HashMap<String, Boolean> map = new HashMap<String, Boolean>();
        StringTokenizer features = new StringTokenizer(optString, ",");
        StringTokenizer option;
        while (features.hasMoreElements()) {
            option = new StringTokenizer(features.nextToken(), "=");
            if (option.hasMoreElements()) {
                String key = option.nextToken();
                if (key.equalsIgnoreCase(CLOSE_BUTTON_CAPTION)) {
                    this.buttonLabel = option.nextToken();
                } else {
                    Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE;
                    map.put(key, value);
                }
            }
        }
        return map;
    }
}

From source file:org.alfresco.util.exec.RuntimeExec.java

/**
 * A comma or space separated list of values that, if returned by the executed command,
 * indicate an error value.  This defaults to <b>"1, 2"</b>.
 * //  w ww .  j  a  v a 2 s  .c  o m
 * @param errCodesStr the error codes for the execution
 */
public void setErrorCodes(String errCodesStr) {
    errCodes.clear();
    StringTokenizer tokenizer = new StringTokenizer(errCodesStr, " ,");
    while (tokenizer.hasMoreElements()) {
        String errCodeStr = tokenizer.nextToken();
        // attempt to convert it to an integer
        try {
            int errCode = Integer.parseInt(errCodeStr);
            this.errCodes.add(errCode);
        } catch (NumberFormatException e) {
            throw new AlfrescoRuntimeException(
                    "Property 'errorCodes' must be comma-separated list of integers: " + errCodesStr);
        }
    }
}

From source file:com.wabacus.system.assistant.ReportAssistant.java

public String formatCondition(String src, String token) {
    if (src == null || src.trim().length() < 2 || token == null || token.trim().equals("")) {
        return src;
    }//from w w w .java2  s.c  o  m
    src = src.trim();
    String dest = "";
    if (token.equals("2")) {
        dest = src.substring(0, 1);
        for (int i = 1; i < src.length() - 1; i++) {
            if (src.charAt(i) != ' ') {
                dest = dest + "%" + src.charAt(i);
            }
        }
        dest = dest + "%" + src.substring(src.length() - 1);
    } else {
        if (token.equals("1")) {
            token = " ";
        }

        while (src.indexOf(token) == 0) {
            src = src.substring(1);
            src = src.trim();
        }
        while (src.endsWith(token)) {
            src = src.substring(0, src.length() - 1);
            src = src.trim();
        }

        StringTokenizer st = new StringTokenizer(src, token);
        while (st.hasMoreElements()) {
            dest = dest + ((String) st.nextElement()).trim() + "%";
            //                System.out.println(dest);
        }
        if (dest.endsWith("%")) {
            dest = dest.substring(0, dest.length() - 1);
        }
    }
    log.debug("?" + src + "?splitlike???" + dest);
    return dest;
}

From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java

/**
 * Put the list of features into a hash map
 *
 * @param optString/* www  .  jav a 2s  .co  m*/
 * @return
 */
protected HashMap<String, Boolean> parseFeature(String optString) {
    if (optString.equals(NULL)) {
        return null;
    } else {
        HashMap<String, Boolean> map = new HashMap<String, Boolean>();
        StringTokenizer features = new StringTokenizer(optString, ",");
        StringTokenizer option;
        while (features.hasMoreElements()) {
            option = new StringTokenizer(features.nextToken(), "=");
            if (option.hasMoreElements()) {
                String key = option.nextToken();
                Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE;
                map.put(key, value);
            }
        }
        return map;
    }
}

From source file:org.apache.tez.dag.app.web.AMWebController.java

List<String> splitString(String str, String delimiter, Integer limit) {
    List<String> items = new ArrayList<String>();

    StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
    for (int count = 0; tokenizer.hasMoreElements() && count < limit; count++) {
        items.add(tokenizer.nextToken());
    }//from   ww w. j  a v  a2 s.c  om

    return items;
}

From source file:org.springframework.security.oauth.consumer.CoreOAuthConsumerSupport.java

/**
 * Loads the OAuth parameters for the given resource at the given URL and the given token. These parameters include
 * any query parameters on the URL since they are included in the signature. The oauth parameters are NOT encoded.
 *
 * @param details      The resource details.
 * @param requestURL   The request URL./*from  w ww . j  a v  a  2 s.  com*/
 * @param requestToken The request token.
 * @param httpMethod   The http method.
 * @param additionalParameters Additional oauth parameters (outside of the core oauth spec).
 * @return The parameters.
 */
protected Map<String, Set<CharSequence>> loadOAuthParameters(ProtectedResourceDetails details, URL requestURL,
        OAuthConsumerToken requestToken, String httpMethod, Map<String, String> additionalParameters) {
    Map<String, Set<CharSequence>> oauthParams = new TreeMap<String, Set<CharSequence>>();

    if (additionalParameters != null) {
        for (Map.Entry<String, String> additionalParam : additionalParameters.entrySet()) {
            Set<CharSequence> values = oauthParams.get(additionalParam.getKey());
            if (values == null) {
                values = new HashSet<CharSequence>();
                oauthParams.put(additionalParam.getKey(), values);
            }
            if (additionalParam.getValue() != null) {
                values.add(additionalParam.getValue());
            }
        }
    }

    String query = requestURL.getQuery();
    if (query != null) {
        StringTokenizer queryTokenizer = new StringTokenizer(query, "&");
        while (queryTokenizer.hasMoreElements()) {
            String token = (String) queryTokenizer.nextElement();
            CharSequence value = null;
            int equalsIndex = token.indexOf('=');
            if (equalsIndex < 0) {
                token = urlDecode(token);
            } else {
                value = new QueryParameterValue(urlDecode(token.substring(equalsIndex + 1)));
                token = urlDecode(token.substring(0, equalsIndex));
            }

            Set<CharSequence> values = oauthParams.get(token);
            if (values == null) {
                values = new HashSet<CharSequence>();
                oauthParams.put(token, values);
            }
            if (value != null) {
                values.add(value);
            }
        }
    }

    String tokenSecret = requestToken == null ? null : requestToken.getSecret();
    String nonce = getNonceFactory().generateNonce();
    oauthParams.put(OAuthConsumerParameter.oauth_consumer_key.toString(),
            Collections.singleton((CharSequence) details.getConsumerKey()));
    if ((requestToken != null) && (requestToken.getValue() != null)) {
        oauthParams.put(OAuthConsumerParameter.oauth_token.toString(),
                Collections.singleton((CharSequence) requestToken.getValue()));
    }

    oauthParams.put(OAuthConsumerParameter.oauth_nonce.toString(), Collections.singleton((CharSequence) nonce));
    oauthParams.put(OAuthConsumerParameter.oauth_signature_method.toString(),
            Collections.singleton((CharSequence) details.getSignatureMethod()));
    oauthParams.put(OAuthConsumerParameter.oauth_timestamp.toString(),
            Collections.singleton((CharSequence) String.valueOf(System.currentTimeMillis() / 1000)));
    oauthParams.put(OAuthConsumerParameter.oauth_version.toString(),
            Collections.singleton((CharSequence) "1.0"));
    String signatureBaseString = getSignatureBaseString(oauthParams, requestURL, httpMethod);
    OAuthSignatureMethod signatureMethod = getSignatureFactory()
            .getSignatureMethod(details.getSignatureMethod(), details.getSharedSecret(), tokenSecret);
    String signature = signatureMethod.sign(signatureBaseString);
    oauthParams.put(OAuthConsumerParameter.oauth_signature.toString(),
            Collections.singleton((CharSequence) signature));
    return oauthParams;
}

From source file:org.alfresco.web.bean.wcm.CreateWebContentWizard.java

/**
 * Save the specified content using the currently set wizard attributes
 *//*from   w  w  w  .jav  a  2s  . c o m*/
@SuppressWarnings("unchecked")
protected void saveContent() throws Exception {
    // get the parent path of the location to save the content
    String fileName = this.getFileName();
    String contentName = fileName;
    if (logger.isDebugEnabled())
        logger.debug("saving file content to " + fileName);

    final String cwd = AVMUtil.getCorrespondingPathInPreviewStore(this.avmBrowseBean.getCurrentPath());
    final Form form = (MimetypeMap.MIMETYPE_XML.equals(this.mimeType) ? this.getForm() : null);
    String path = cwd;

    final Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(1, 1.0f);
    final List<QName> aspects = new ArrayList<QName>(4);

    if (form != null) {
        path = form.getOutputPathForFormInstanceData(this.getInstanceDataDocument(), fileName, cwd,
                this.avmBrowseBean.getWebapp());
        this.content = XMLUtil.toString(this.getInstanceDataDocument(), false);
        final String[] sb = AVMNodeConverter.SplitBase(path);
        path = sb[0];
        fileName = sb[1];
        props.put(WCMAppModel.PROP_PARENT_FORM_NAME, new PropertyValue(null, form.getName()));
        props.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, new PropertyValue(null, cwd));
        aspects.add(WCMAppModel.ASPECT_FORM_INSTANCE_DATA);
    }
    props.put(ContentModel.PROP_TITLE, new PropertyValue(null, fileName));
    aspects.add(ContentModel.ASPECT_TITLED);

    if (logger.isDebugEnabled())
        logger.debug("creating all directories in path " + path);

    AVMUtil.makeAllDirectories(path);

    if (logger.isDebugEnabled())
        logger.debug("creating file " + fileName + " in " + path);

    // put the content of the file into the AVM store
    String filePath = AVMNodeConverter.ExtendAVMPath(path, fileName);
    try {
        /**
         *  create the new file 
         */
        getAvmService().createFile(path, fileName,
                new ByteArrayInputStream((this.content == null ? "" : this.content).getBytes("UTF-8")), aspects,
                props);
    } catch (AVMExistsException avmee) {
        String msg = Application.getMessage(FacesContext.getCurrentInstance(), "error_exists");
        msg = MessageFormat.format(msg, fileName);
        throw new AlfrescoRuntimeException(msg, avmee);
    }

    // remember the created path
    this.createdPath = filePath;

    // add titled aspect for the read/edit properties screens
    final NodeRef formInstanceDataNodeRef = AVMNodeConverter.ToNodeRef(-1, this.createdPath);

    /**
     * Generate form renditions.
     */
    if (form != null) {

        this.formInstanceData = getFormsService().getFormInstanceData(formInstanceDataNodeRef);
        this.renditions = new LinkedList<Rendition>();
        for (RenderingEngineTemplate ret : form.getRenderingEngineTemplates()) {
            try {
                path = ret.getOutputPathForRendition(this.formInstanceData, cwd, contentName);

                if (logger.isDebugEnabled())
                    logger.debug("About to render path: " + path);

                // generate the rendition
                this.renditions.add(ret.render(this.formInstanceData, path));
            } catch (Exception e) {
                // TODO - improve error handling, e.g. render could return list of errors rather than splitting on newline character
                StringTokenizer st = new StringTokenizer(e.getMessage(), "\n");
                if (st.hasMoreElements()) {
                    Utils.addErrorMessage(
                            "Error generating rendition using " + ret.getName() + ": " + st.nextToken(), e);
                    while (st.hasMoreElements()) {
                        Utils.addErrorMessage(st.nextToken(), e);
                    }
                } else {
                    Utils.addErrorMessage(
                            "Error generating rendition using " + ret.getName() + ": " + e.getMessage(), e);
                }
            }
        }
    } else {
        this.renditions = Collections.EMPTY_LIST;
    }
}

From source file:org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager.java

@Override
public void doSetUserClaimValue(String userName, String claimURI, String value, String profileName)
        throws UserStoreException {
    // get the LDAP Directory context
    DirContext dirContext = this.connectionSource.getContext();
    DirContext subDirContext = null;
    // search the relevant user entry by user name
    String userSearchBase = realmConfig.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);
    String userSearchFilter = realmConfig.getUserStoreProperty(LDAPConstants.USER_NAME_SEARCH_FILTER);
    userSearchFilter = userSearchFilter.replace("?", escapeSpecialCharactersForFilter(userName));

    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    searchControls.setReturningAttributes(null);

    NamingEnumeration<SearchResult> returnedResultList = null;
    String returnedUserEntry = null;

    try {/*from  w  w w. j  a  v a 2 s.  c o  m*/

        returnedResultList = dirContext.search(escapeDNForSearch(userSearchBase), userSearchFilter,
                searchControls);
        // assume only one user is returned from the search
        // TODO:what if more than one user is returned
        returnedUserEntry = returnedResultList.next().getName();
    } catch (NamingException e) {
        String errorMessage = "Results could not be retrieved from the directory context for user : "
                + userName;
        if (logger.isDebugEnabled()) {
            logger.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    } finally {
        JNDIUtil.closeNamingEnumeration(returnedResultList);
    }

    try {
        Attributes updatedAttributes = new BasicAttributes(true);
        // if there is no attribute for profile configuration in LDAP, skip
        // updating it.
        // get the claimMapping related to this claimURI
        String attributeName = getClaimAtrribute(claimURI, userName, null);

        if ("CN".equals(attributeName)) {
            subDirContext = (DirContext) dirContext.lookup(userSearchBase);
            subDirContext.rename(returnedUserEntry, "CN=" + value);
            return;
        }

        Attribute currentUpdatedAttribute = new BasicAttribute(attributeName);
        /* if updated attribute value is null, remove its values. */
        if (EMPTY_ATTRIBUTE_STRING.equals(value)) {
            currentUpdatedAttribute.clear();
        } else {
            String claimSeparator = realmConfig.getUserStoreProperty(MULTI_ATTRIBUTE_SEPARATOR);
            if (claimSeparator != null && !claimSeparator.trim().isEmpty()) {
                userAttributeSeparator = claimSeparator;
            }
            if (value.contains(userAttributeSeparator)) {
                StringTokenizer st = new StringTokenizer(value, userAttributeSeparator);
                while (st.hasMoreElements()) {
                    String newVal = st.nextElement().toString();
                    if (newVal != null && newVal.trim().length() > 0) {
                        currentUpdatedAttribute.add(newVal.trim());
                    }
                }
            } else {
                currentUpdatedAttribute.add(value);
            }
        }
        updatedAttributes.put(currentUpdatedAttribute);

        // update the attributes in the relevant entry of the directory
        // store

        subDirContext = (DirContext) dirContext.lookup(userSearchBase);
        subDirContext.modifyAttributes(returnedUserEntry, DirContext.REPLACE_ATTRIBUTE, updatedAttributes);

    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        String errorMessage = "Error in obtaining claim mapping for user : " + userName;
        if (logger.isDebugEnabled()) {
            logger.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    } catch (NamingException e) {
        handleException(e, userName);
    } finally {
        JNDIUtil.closeContext(subDirContext);
        JNDIUtil.closeContext(dirContext);
    }

}