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.ecofactor.qa.automation.drapi.DRAPI_Execution_410_Test.java

/**
 * Fetch the Event Name after creation of DR Event.
 * @param response the response/*ww  w .j a  v a 2  s. c o  m*/
 * @return String.
 */
private String getDrEventName(final String response) {

    StringTokenizer st = new StringTokenizer(response, ",");
    String eventID = "";
    while (st.hasMoreElements()) {

        @SuppressWarnings("unused")
        String status = st.nextToken();
        eventID = st.nextToken();
    }
    String[] eventValues = eventID.split(":");
    final String eventName = eventValues[2];

    setLogString("DR EventName Fetched : " + eventName.substring(0, eventName.length() - 3), true);
    return eventName.substring(0, eventName.length() - 3);
}

From source file:eu.aniketos.scpm.userinterface.views.ScpmUI.java

/**
 * @see loadBPMN/*  w ww  . j av  a 2 s . c  o  m*/
 * @see getExtensions() When generates a *.activiti file from *.bpmn20.xml
 *      file, The Activiti designer only copes with the original
 *      tags/elements. Any security extensions that embedded in the
 *      composition plan by SCF have to be abstracted manually. This method
 *      saves security extensions into the activiti file.
 * 
 * @param id
 *            The ID of element to be saved.
 * @param attributes
 *            Value of the extended attributes.
 * @param bpmn2Element
 *            The element to be parsed.
 */

private static void setExtensions(String id, List<String> attributes, List<org.w3c.dom.Element> bpmn2Element) {

    for (int index = 0; index < bpmn2Element.size(); index++) {
        // System.out.println(getAttValue("id", bpmn2Element.get(index)));
        if (getAttValue("id", bpmn2Element.get(index)).equals(id)) {
            String fieldPosition = getAttValue("fieldExtensions", bpmn2Element.get(index));
            StringTokenizer str = new StringTokenizer(fieldPosition);

            int attNumber = 0;

            while (str.hasMoreElements()) {
                String pString = (String) str.nextElement();
                int pInt = Integer.parseInt(pString.substring(1));
                // System.out.println(pInt);
                bpmn2Element.get(pInt - 1).setAttribute("expression", attributes.get(attNumber));
                attNumber++;
            }
        }
    }
}

From source file:ch.epfl.lsir.xin.algorithm.core.SVDPlusPlus.java

@Override
public void readModel(String file) {
    // TODO Auto-generated method stub

    try {//from  w  w w.j a v a2  s  .c  om
        //read user bias
        BufferedReader ubReader = new BufferedReader(new FileReader(file + "_userBias"));
        String line = null;
        int index1 = 0;
        while ((line = ubReader.readLine()) != null) {
            this.userBias[index1++] = Double.parseDouble(line);
        }
        ubReader.close();

        //read item bias
        BufferedReader ibReader = new BufferedReader(new FileReader(file + "_itemBias"));
        int index2 = 0;
        while ((line = ibReader.readLine()) != null) {
            this.itemBias[index2++] = Double.parseDouble(line);
        }
        ibReader.close();

        //read user factors
        BufferedReader uReader = new BufferedReader(new FileReader(file + "_userFactors"));
        int index3 = 0;
        while ((line = uReader.readLine()) != null) {
            StringTokenizer tokens = new StringTokenizer(line);
            int index = 0;
            while (tokens.hasMoreElements()) {
                this.userMatrix.set(index3, index++, Double.parseDouble(tokens.nextToken()));
            }
            index3++;
        }
        uReader.close();

        //read item factors
        BufferedReader iReader = new BufferedReader(new FileReader(file + "_itemFactors"));
        int index4 = 0;
        while ((line = iReader.readLine()) != null) {
            StringTokenizer tokens = new StringTokenizer(line);
            int index = 0;
            while (tokens.hasMoreElements()) {
                this.itemMatrix.set(index4, index++, Double.parseDouble(tokens.nextToken()));
            }
            index4++;
        }
        iReader.close();

        //read item factors(Y)
        BufferedReader yReader = new BufferedReader(new FileReader(file + "_yFactors"));
        int index5 = 0;
        while ((line = yReader.readLine()) != null) {
            StringTokenizer tokens = new StringTokenizer(line);
            int index = 0;
            while (tokens.hasMoreElements()) {
                this.Y.set(index5, index++, Double.parseDouble(tokens.nextToken()));
            }
            index5++;
        }
        yReader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.wastl.webmail.xml.XMLSystemData.java

public WebMailVirtualDomain getVirtualDomain(String domname) {
    // Check if virtual domains are disabled
    if (getVirtuals() == false) {
        // No, default to localhost
        return new WebMailVirtualDomain() {
            public String getDomainName() {
                return "localhost";
            }//from ww  w  . j av  a  2 s. c o m

            public void setDomainName(String name) throws Exception {
                log.error("Ignoring DefaultDomain.setDomainName().  " + "Should not call this method.");
            }

            public String getDefaultServer() {
                return "localhost";
            }

            public void setDefaultServer(String name) {
                log.error("Ignoring DefaultDomain.setDomainServer().  " + "Should not call this method.");
            }

            public String getAuthenticationHost() {
                return "localhost";
            }

            public void setAuthenticationHost(String name) {
                log.error("Ignoring DefaultDomain.setAuthenticationHost().  " + "Should not call this method.");
            }

            public boolean isAllowedHost(String host) {
                return true;
            }

            public void setAllowedHosts(String hosts) {
                log.error("Ignoring DefaultDomain.setAllowedHosts().  " + "Should not call this method.");
            }

            public Enumeration<String> getAllowedHosts() {
                return new Enumeration<String>() {
                    int i = 0;

                    public boolean hasMoreElements() {
                        return i < 1;
                    }

                    public String nextElement() {
                        i++;
                        return "localhost";
                    }
                };
            }

            public void setHostsRestricted(boolean b) {
                log.error("Ignoring DefaultDomain.setHostsRestricted().  " + "Should not call this method.");
            }

            public boolean getHostsRestricted() {
                return false;
            }

            public String getImapBasedir() {
                return null;
            }
        };
    }
    // Virtual domains are allowed, get that wanted one
    NodeList nodel = sysdata.getElementsByTagName("DOMAIN");
    Element elem = null;
    int j;
    for (j = 0; j < nodel.getLength(); j++) {
        elem = (Element) nodel.item(j);
        elem.normalize();
        NodeList namel = elem.getElementsByTagName("NAME");
        if (namel.getLength() > 0) {
            if (XMLCommon.getElementTextValue((Element) namel.item(0)).equals(domname)) {
                break;
            }
        }
    }
    if (j < nodel.getLength() && elem != null) {
        final Element domain = elem;
        return new WebMailVirtualDomain() {
            public String getDomainName() {
                String value = XMLCommon.getTagValue(domain, "NAME");
                return value == null ? "unknown" : value;
            }

            public void setDomainName(String name) throws Exception {
                XMLCommon.setTagValue(domain, "NAME", name, true, "Virtual Domain names must be unique!");
            }

            public String getDefaultServer() {
                String value = XMLCommon.getTagValue(domain, "DEFAULT_HOST");
                return value == null ? "unknown" : value;
            }

            /* Override the IMAP base directory for this domain,
             * for imap and imaps protocols */
            public String getImapBaseDir() {
                String value = XMLCommon.getTagValue(domain, "IMAP_BASEDIR");
                return value == null ? "unknown" : value;
            }

            public void setDefaultServer(String name) {
                XMLCommon.setTagValue(domain, "DEFAULT_HOST", name);
            }

            public String getAuthenticationHost() {
                String value = XMLCommon.getTagValue(domain, "AUTHENTICATION_HOST");
                return value == null ? "unknown" : value;
            }

            public void setAuthenticationHost(String name) {
                XMLCommon.setTagValue(domain, "AUTHENTICATION_HOST", name);
            }

            public boolean isAllowedHost(String host) {
                if (getHostsRestricted()) {
                    Vector<String> v = new Vector<String>();
                    v.addElement(getDefaultServer());
                    Enumeration<String> e = getAllowedHosts();
                    while (e.hasMoreElements()) {
                        v.addElement(e.nextElement());
                    }
                    Enumeration<String> enumVar = v.elements();
                    while (enumVar.hasMoreElements()) {
                        String next = enumVar.nextElement();
                        if (host.toUpperCase().endsWith(next.toUpperCase())) {
                            return true;
                        }
                    }
                    return false;
                } else {
                    return true;
                }
            }

            public void setAllowedHosts(String hosts) {
                NodeList nl = domain.getElementsByTagName("ALLOWED_HOST");
                for (int i = 0; i < nl.getLength(); i++) {
                    domain.removeChild(nl.item(i));
                }
                StringTokenizer tok = new StringTokenizer(hosts, ", ");
                while (tok.hasMoreElements()) {
                    Element ahost = root.createElement("ALLOWED_HOST");
                    XMLCommon.setElementTextValue(ahost, tok.nextToken());
                    domain.appendChild(ahost);
                }
            }

            public Enumeration<String> getAllowedHosts() {
                final NodeList nl = domain.getElementsByTagName("ALLOWED_HOST");
                return new Enumeration<String>() {
                    int i = 0;

                    public boolean hasMoreElements() {
                        return i < nl.getLength();
                    }

                    public String nextElement() {
                        String value = XMLCommon.getElementTextValue((Element) nl.item(i++));
                        return value == null ? "error" : value;
                    }
                };
            }

            public void setHostsRestricted(boolean b) {
                NodeList nl = domain.getElementsByTagName("RESTRICTED");
                for (int i = 0; i < nl.getLength(); i++) {
                    domain.removeChild(nl.item(i));
                }
                if (b) {
                    domain.appendChild(root.createElement("RESTRICTED"));
                }
            }

            public boolean getHostsRestricted() {
                NodeList nl = domain.getElementsByTagName("RESTRICTED");
                return nl.getLength() > 0;
            }

            public String getImapBasedir() {
                NodeList nl = domain.getElementsByTagName("IMAP_BASEDIR");
                return ((nl.getLength() > 0) ? XMLCommon.getElementTextValue((Element) nl.item(0)) : null);
            }
        };
    } else {
        return null;
    }
}

From source file:org.hfoss.posit.android.sync.Communicator.java

/**
 * The data has the form: [attr=value, ...] or 'null'
 * @param cv//w  w  w  .j a v  a 2  s .  co  m
 * @param data
 */
static private void addExtraDataToContentValues(ContentValues cv, String data) {
    Log.i(TAG, "data = " + data + " " + data.length());
    if (data.equals("null"))
        return;
    data = data.trim();
    data = data.substring(1, data.length() - 1);
    StringTokenizer st = new StringTokenizer(data, ",");
    while (st.hasMoreElements()) {
        String attrvalpair = (String) st.nextElement();
        String attr = attrvalpair.substring(0, attrvalpair.indexOf("="));
        attr = attr.trim();
        String val = attrvalpair.substring(attrvalpair.indexOf("=") + 1);
        val = val.trim();
        Log.i(TAG, "Putting " + attr + "=" + val + " into CV");
        if (Integer.getInteger(val) != null)
            cv.put(attr, Integer.parseInt(val));
        //         else if (Boolean.getBoolean(val) != null)
        //            cv.put(attr, Boolean.parseBoolean(val))
        //         else if (Double.getDouble(val) != null))
        //            cv.put(attr, Double.parseDouble(val))
        else
            cv.put(attr, val);
    }

}

From source file:ru.runa.wfe.extension.handler.var.FormulaActionHandlerOperations.java

public String nameCaseRussian(String fio, int caseNumber, boolean sex, String mode) {
    StringTokenizer st = new StringTokenizer(fio);
    String family = st.hasMoreElements() ? st.nextToken() : "";
    String name = st.hasMoreElements() ? st.nextToken() : "";
    String parent = st.hasMoreElements() ? st.nextToken() : "";

    String answer = "";
    for (char c : mode.toCharArray()) {
        switch (c) {
        case 'F':
            answer += wordCaseRussian(family, caseNumber, sex, 1, false);
            break;
        case 'I':
            answer += wordCaseRussian(name, caseNumber, sex, 2, false);
            break;
        case 'O':
            answer += wordCaseRussian(parent, caseNumber, sex, 3, false);
            break;
        case 'f':
            answer += wordCaseRussian(family, caseNumber, sex, 1, true);
            break;
        case 'i':
            answer += wordCaseRussian(name, caseNumber, sex, 2, true);
            break;
        case 'o':
            answer += wordCaseRussian(parent, caseNumber, sex, 3, true);
            break;
        default:/*www . ja v  a2s.  co m*/
            answer += c;
        }
    }

    return answer;
}

From source file:org.tinygroup.jspengine.compiler.Compiler.java

private void addClassPath(String classPath, ArrayList<File> cpath, HashSet<String> paths) {
    if (classPath == null) {
        return;/*from   w ww  .jav  a  2 s . c  o  m*/
    }

    String sep = System.getProperty("path.separator");
    StringTokenizer tokenizer = new StringTokenizer(classPath, sep);
    while (tokenizer.hasMoreElements()) {
        String path = tokenizer.nextToken();
        if (!paths.contains(path)) {
            paths.add(path);
            cpath.add(new File(path));
        }
    }
}

From source file:org.picketlink.social.standalone.login.ExternalAuthentication.java

/**
 * A comma separated string that represents the roles the web app needs to pass authorization
 *
 * @param roleStr//from w ww  .j  a  va  2 s .  co m
 */
public void setRoleString(String roleStr) {
    if (roleStr == null)
        throw new RuntimeException("Role String is null in configuration");
    StringTokenizer st = new StringTokenizer(getSystemPropertyAsString(roleStr), ",");
    while (st.hasMoreElements()) {
        roles.add(st.nextToken());
    }
}

From source file:edu.duke.cabig.c3pr.web.ajax.BookRandomizationAjaxFacade.java

private void parseBookRandomizationWithoutStratification(String bookRandomizations, Epoch tEpoch)
        throws Exception {

    try {/*from   ww  w  .j a va2  s. co  m*/
        // we do not create a new instance of bookRandomization, we use the existing instance
        // which was created in StudyDesignTab.java
        // based on the randomizationType selected on the study_details page.
        BookRandomization randomization = null;
        if (tEpoch.getRandomization() instanceof BookRandomization) {
            randomization = (BookRandomization) tEpoch.getRandomization();
        } else {
            return;
        }

        List<BookRandomizationEntry> breList = randomization.getBookRandomizationEntry();
        //clear existing bookEntries
        breList.clear();
        clearStratumGroups(tEpoch);

        StringTokenizer outer = new StringTokenizer(bookRandomizations, "\n");
        String entry;
        String[] entries;
        Arm arm;
        BookRandomizationEntry bookRandomizationEntry = null;
        while (outer.hasMoreElements()) {
            entry = outer.nextToken();
            if (entry.trim().length() > 0) {
                entries = entry.split(",");
                bookRandomizationEntry = breList.get(breList.size());

                // set the position
                Integer position = null;
                try {
                    position = Integer.valueOf(entries[0].trim());
                } catch (NumberFormatException nfe) {
                    log.debug("Illegal Position Entered.");
                }
                bookRandomizationEntry.setPosition(position);
                // find the arm with this id and set it here even if its null
                // Empty stratum groups with negetive stratum Group Numbers and arms are checked
                // for while generating the table and replaced with the string 
                // "Invalid Entry" so the user can see which entries are incorrect.
                arm = getArmByName(tEpoch, entries[1].trim());
                bookRandomizationEntry.setArm(arm);
            }
        }
    } catch (Exception e) {
        log.error("parseBookRandomizationWithoutStratification Failed");
        log.error(e.getMessage());
        throw e;
    }
}

From source file:org.wso2.carbon.identity.oauth2.authcontext.JWTTokenGenerator.java

/**
 * Method that generates the JWT.//from w  w  w. j  a  v a 2 s.  c  o  m
 *
 * @return signed JWT token
 * @throws IdentityOAuth2Exception
 */
@Override
public void generateToken(OAuth2TokenValidationMessageContext messageContext) throws IdentityOAuth2Exception {

    String clientId = ((AccessTokenDO) messageContext.getProperty("AccessTokenDO")).getConsumerKey();
    long issuedTime = ((AccessTokenDO) messageContext.getProperty("AccessTokenDO")).getIssuedTime().getTime();
    String authzUser = messageContext.getResponseDTO().getAuthorizedUser();
    int tenantID = ((AccessTokenDO) messageContext.getProperty("AccessTokenDO")).getTenantID();
    String tenantDomain = OAuth2Util.getTenantDomain(tenantID);
    boolean isExistingUser = false;

    RealmService realmService = OAuthComponentServiceHolder.getRealmService();
    // TODO : Need to handle situation where federated user name is similar to a one we have in our user store
    if (realmService != null && tenantID != MultitenantConstants.INVALID_TENANT_ID
            && tenantID == OAuth2Util.getTenantIdFromUserName(authzUser)) {
        try {
            UserRealm userRealm = realmService.getTenantUserRealm(tenantID);
            if (userRealm != null) {
                UserStoreManager userStoreManager = (UserStoreManager) userRealm.getUserStoreManager();
                isExistingUser = userStoreManager
                        .isExistingUser(MultitenantUtils.getTenantAwareUsername(authzUser));
            }
        } catch (UserStoreException e) {
            log.error("Error occurred while loading the realm service", e);
        }
    }

    OAuthAppDAO appDAO = new OAuthAppDAO();
    OAuthAppDO appDO;
    try {
        appDO = appDAO.getAppInformation(clientId);
        // Adding the OAuthAppDO as a context property for further use
        messageContext.addProperty("OAuthAppDO", appDO);
    } catch (IdentityOAuth2Exception e) {
        log.debug(e.getMessage(), e);
        throw new IdentityOAuth2Exception(e.getMessage());
    } catch (InvalidOAuthClientException e) {
        log.debug(e.getMessage(), e);
        throw new IdentityOAuth2Exception(e.getMessage());
    }
    String subscriber = appDO.getUserName();
    String applicationName = appDO.getApplicationName();

    //generating expiring timestamp
    long currentTime = Calendar.getInstance().getTimeInMillis();
    long expireIn = currentTime + 1000 * 60 * getTTL();

    // Prepare JWT with claims set
    JWTClaimsSet claimsSet = new JWTClaimsSet();
    claimsSet.setIssuer(API_GATEWAY_ID);
    claimsSet.setSubject(authzUser);
    claimsSet.setIssueTime(new Date(issuedTime));
    claimsSet.setExpirationTime(new Date(expireIn));
    claimsSet.setClaim(API_GATEWAY_ID + "/subscriber", subscriber);
    claimsSet.setClaim(API_GATEWAY_ID + "/applicationname", applicationName);
    claimsSet.setClaim(API_GATEWAY_ID + "/enduser", authzUser);

    if (claimsRetriever != null) {

        //check in local cache
        String[] requestedClaims = messageContext.getRequestDTO().getRequiredClaimURIs();
        if (requestedClaims == null && isExistingUser) {
            // if no claims were requested, return all
            requestedClaims = claimsRetriever.getDefaultClaims(authzUser);
        }

        CacheKey cacheKey = null;
        Object result = null;

        if (requestedClaims != null) {
            cacheKey = new ClaimCacheKey(authzUser, requestedClaims);
            result = claimsLocalCache.getValueFromCache(cacheKey);
        }

        SortedMap<String, String> claimValues = null;
        if (result != null) {
            claimValues = ((UserClaims) result).getClaimValues();
        } else if (isExistingUser) {
            claimValues = claimsRetriever.getClaims(authzUser, requestedClaims);
            UserClaims userClaims = new UserClaims(claimValues);
            claimsLocalCache.addToCache(cacheKey, userClaims);
        }

        if (isExistingUser) {
            String claimSeparator = getMultiAttributeSeparator(authzUser, tenantID);
            if (StringUtils.isBlank(claimSeparator)) {
                userAttributeSeparator = claimSeparator;
            }
        }

        if (claimValues != null) {
            Iterator<String> it = new TreeSet(claimValues.keySet()).iterator();
            while (it.hasNext()) {
                String claimURI = it.next();
                String claimVal = claimValues.get(claimURI);
                List<String> claimList = new ArrayList<String>();
                if (userAttributeSeparator != null && claimVal.contains(userAttributeSeparator)) {
                    StringTokenizer st = new StringTokenizer(claimVal, userAttributeSeparator);
                    while (st.hasMoreElements()) {
                        String attValue = st.nextElement().toString();
                        if (StringUtils.isNotBlank(attValue)) {
                            claimList.add(attValue);
                        }
                    }
                    claimsSet.setClaim(claimURI, claimList.toArray(new String[claimList.size()]));
                } else {
                    claimsSet.setClaim(claimURI, claimVal);
                }
            }
        }
    }

    JWT jwt = null;
    if (!JWSAlgorithm.NONE.equals(signatureAlgorithm)) {
        JWSHeader header = new JWSHeader(JWSAlgorithm.RS256);
        header.setX509CertThumbprint(new Base64URL(getThumbPrint(tenantDomain, tenantID)));
        jwt = new SignedJWT(header, claimsSet);
        jwt = signJWT((SignedJWT) jwt, tenantDomain, tenantID);
    } else {
        jwt = new PlainJWT(claimsSet);
    }

    if (log.isDebugEnabled()) {
        log.debug("JWT Assertion Value : " + jwt.serialize());
    }
    OAuth2TokenValidationResponseDTO.AuthorizationContextToken token;
    token = messageContext.getResponseDTO().new AuthorizationContextToken("JWT", jwt.serialize());
    messageContext.getResponseDTO().setAuthorizationContextToken(token);
}