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.runwaysdk.dataaccess.database.general.SQLServer.java

/**
 * Returns a list of string names of the attributes that participate in a
 * group unique with the given name.//  www. j a  v a 2s .  c o m
 *
 * @param indexName
 * @param conn it is up to the client to manage the connection object.
 * @param attributeNames
 */
public List<String> getGroupIndexAttributesFromIndexName(String table, String indexName, Connection conn) {
    String sqlStmt = "sp_helpindex " + table;

    ResultSet resultSet = this.query(sqlStmt, conn);

    List<String> attributeNames = new LinkedList<String>();

    try {
        while (resultSet.next()) {
            String attrName = resultSet.getString("index_keys").toLowerCase();
            //     String indexType =  ( ((DynaBean)result.get(i)).get("index_description").toString() ).toLowerCase();
            String keyName = resultSet.getString("index_name").toLowerCase();

            //     if (keyName.equals(indexName) && indexType.contains("unique"))
            if (keyName.equals(indexName)) {
                StringTokenizer st = new StringTokenizer(attrName, ",", false);

                while (st.hasMoreElements()) {
                    attributeNames.add(((String) st.nextElement()).trim());
                }
            }
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }
    return attributeNames;
}

From source file:org.globus.ftp.FTPClient.java

/**
 * Get info of a certain remote file in Mlsx format.
 *//*from  w  w  w .  j  av  a 2 s.c o m*/
public MlsxEntry mlst(String fileName) throws IOException, ServerException {
    try {
        Reply reply = controlChannel.execute(new Command("MLST", fileName));
        String replyMessage = reply.getMessage();
        StringTokenizer replyLines = new StringTokenizer(replyMessage, System.getProperty("line.separator"));
        if (replyLines.hasMoreElements()) {
            replyLines.nextElement();
        } else {
            throw new FTPException(FTPException.UNSPECIFIED, "Expected multiline reply");
        }
        if (replyLines.hasMoreElements()) {
            String line = (String) replyLines.nextElement();
            return new MlsxEntry(line);
        } else {
            throw new FTPException(FTPException.UNSPECIFIED, "Expected multiline reply");
        }
    } catch (FTPReplyParseException rpe) {
        throw ServerException.embedFTPReplyParseException(rpe);
    } catch (UnexpectedReplyCodeException urce) {
        throw ServerException.embedUnexpectedReplyCodeException(urce, "Server refused MLST command");
    } catch (FTPException e) {
        ServerException ce = new ServerException(ClientException.UNSPECIFIED, "Could not create MlsxEntry");
        ce.setRootCause(e);
        throw ce;
    }
}

From source file:fr.paris.lutece.plugins.calendar.web.CalendarJspBean.java

/**
 * Return the list//w  w  w .ja  va 2 s .  c  o  m
 * @param request The request
 * @return a refenceList
 */
private ReferenceList getStatusList(HttpServletRequest request) {
    ReferenceList list = new ReferenceList();
    StringTokenizer stStatus = new StringTokenizer(AppPropertiesService.getProperty(PROPERTY_EVENT_STATUS_LIST),
            Constants.COMMA);

    while (stStatus.hasMoreElements()) {
        String strStatus = stStatus.nextToken().trim();
        String strStatusValue = I18nService.getLocalizedString("calendar.event.status." + strStatus + ".value",
                getLocale());

        list.addItem(strStatus, strStatusValue);
    }

    return list;
}

From source file:fr.paris.lutece.plugins.calendar.web.CalendarJspBean.java

/**
 * Return the list [(0, no),(2,yes)]/* w w  w.j  av  a  2 s.  com*/
 * 
 * @return a refenceList
 */
private ReferenceList getTopEventList() {
    ReferenceList list = new ReferenceList();
    StringTokenizer st = new StringTokenizer(
            I18nService.getLocalizedString(PROPERTY_TOP_EVENT_LIST, getLocale()), ",");
    int i = 0;

    while (st.hasMoreElements()) {
        list.addItem(i++, st.nextToken().trim());
    }

    return list;
}

From source file:fr.paris.lutece.plugins.calendar.web.CalendarJspBean.java

/**
 * Return the list of time intervals declared in properties file
 * @return A ReferenceList of time interval
 * @param request The HttpRequest//from ww w  .java  2s  .com
 */
public ReferenceList getIntervalList(HttpServletRequest request) {
    StringTokenizer st = new StringTokenizer(AppPropertiesService.getProperty(PROPERTY_TIME_INTERVAL_LIST),
            ",");
    ReferenceList timeIntervalList = new ReferenceList();

    while (st.hasMoreElements()) {
        String strIntervalName = st.nextToken().trim();
        String strDescription = I18nService.getLocalizedString(
                "calendar.interval.periodicity." + strIntervalName + ".description", getLocale());
        int nDays = AppPropertiesService.getPropertyInt("calendar.interval." + strIntervalName + ".value", 7);
        timeIntervalList.addItem(nDays, strDescription);
    }

    return timeIntervalList;
}

From source file:org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager.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);
    // if user name contains domain name, remove domain name
    String[] userNames = userName.split(CarbonConstants.DOMAIN_SEPARATOR);
    if (userNames.length > 1) {
        userName = userNames[1];//w  ww . j ava2 s.co m
    }
    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 {

        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
        if (returnedResultList.hasMore()) {
            returnedUserEntry = returnedResultList.next().getName();
        }

    } catch (NamingException e) {
        String errorMessage = "Results could not be retrieved from the directory context for user : "
                + userName;
        if (log.isDebugEnabled()) {
            log.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 = null;
        attributeName = getClaimAtrribute(claimURI, userName, null);

        Attribute currentUpdatedAttribute = new BasicAttribute(attributeName);
        /* if updated attribute value is null, remove its values. */
        if (EMPTY_ATTRIBUTE_STRING.equals(value)) {
            currentUpdatedAttribute.clear();
        } else {
            if (attributeName.equals("uid") || attributeName.equals("sn")) {
                currentUpdatedAttribute.add(value);
            } else {
                String userAttributeSeparator = ",";
                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 (Exception e) {
        handleException(e, userName);
    } finally {
        JNDIUtil.closeContext(subDirContext);
        JNDIUtil.closeContext(dirContext);
    }

}

From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java

public static String[] getDeviceIds(String applianceId) {
    String[] deviceIds = new String[2];
    if (applianceId.equals(AHContainerAddress.ALL_ID_FILTER)) {
        deviceIds[0] = AHContainerAddress.ALL_ID_FILTER;
        deviceIds[1] = AHContainerAddress.ALL_ID_FILTER;
    } else {//  w  w  w. j  a v  a 2 s  .co m
        StringTokenizer st = new StringTokenizer(applianceId, APPLIANCE_ID_SEPARATOR);
        int i = 0;
        while (st.hasMoreElements()) {
            deviceIds[i++] = (String) st.nextElement();
        }
        if (i == 1)
            deviceIds[1] = AHContainerAddress.DEFAULT_END_POINT_ID;
    }
    return deviceIds;
}

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

/**
 * This method overwrites the method in LDAPUserStoreManager. This implements the functionality
 * of updating user's profile information in LDAP user store.
 *
 * @param userName//  ww w  . j a  va  2  s. c om
 * @param claims
 * @param profileName
 * @throws UserStoreException
 */
@Override
public void doSetUserClaimValues(String userName, Map<String, String> claims, 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);
    // if user name contains domain name, remove domain name
    String[] userNames = userName.split(CarbonConstants.DOMAIN_SEPARATOR);
    if (userNames.length > 1) {
        userName = userNames[1];
    }
    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 {
        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
        if (returnedResultList.hasMore()) {
            returnedUserEntry = returnedResultList.next().getName();
        }

    } catch (NamingException e) {
        String errorMessage = "Results could not be retrieved from the directory context for user : "
                + userName;
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    } finally {
        JNDIUtil.closeNamingEnumeration(returnedResultList);
    }

    if (profileName == null) {

        profileName = UserCoreConstants.DEFAULT_PROFILE;
    }

    if (claims.get(UserCoreConstants.PROFILE_CONFIGURATION) == null) {

        claims.put(UserCoreConstants.PROFILE_CONFIGURATION, UserCoreConstants.DEFAULT_PROFILE_CONFIGURATION);
    }
    try {
        Attributes updatedAttributes = new BasicAttributes(true);

        for (Map.Entry<String, String> claimEntry : claims.entrySet()) {
            String claimURI = claimEntry.getKey();
            // if there is no attribute for profile configuration in LDAP,
            // skip updating it.
            if (claimURI.equals(UserCoreConstants.PROFILE_CONFIGURATION)) {
                continue;
            }
            // get the claimMapping related to this claimURI
            String attributeName = getClaimAtrribute(claimURI, userName, null);
            //remove user DN from cache if changing username attribute
            if (realmConfig.getUserStoreProperty(LDAPConstants.USER_NAME_ATTRIBUTE).equals(attributeName)) {
                userCache.remove(userName);
            }
            // if uid attribute value contains domain name, remove domain
            // name
            if (attributeName.equals("uid")) {
                // if user name contains domain name, remove domain name
                String uidName = claimEntry.getValue();
                String[] uidNames = uidName.split(CarbonConstants.DOMAIN_SEPARATOR);
                if (uidNames.length > 1) {
                    uidName = uidNames[1];
                    claimEntry.setValue(uidName);
                }
                //                    claimEntry.setValue(escapeISSpecialCharacters(uidName));
            }
            Attribute currentUpdatedAttribute = new BasicAttribute(attributeName);
            /* if updated attribute value is null, remove its values. */
            if (EMPTY_ATTRIBUTE_STRING.equals(claimEntry.getValue())) {
                currentUpdatedAttribute.clear();
            } else {
                String userAttributeSeparator = ",";
                if (claimEntry.getValue() != null && !attributeName.equals("uid")
                        && !attributeName.equals("sn")) {
                    String claimSeparator = realmConfig.getUserStoreProperty(MULTI_ATTRIBUTE_SEPARATOR);
                    if (claimSeparator != null && !claimSeparator.trim().isEmpty()) {
                        userAttributeSeparator = claimSeparator;
                    }
                    if (claimEntry.getValue().contains(userAttributeSeparator)) {
                        StringTokenizer st = new StringTokenizer(claimEntry.getValue(), userAttributeSeparator);
                        while (st.hasMoreElements()) {
                            String newVal = st.nextElement().toString();
                            if (newVal != null && newVal.trim().length() > 0) {
                                currentUpdatedAttribute.add(newVal.trim());
                            }
                        }
                    } else {
                        currentUpdatedAttribute.add(claimEntry.getValue());
                    }
                } else {
                    currentUpdatedAttribute.add(claimEntry.getValue());
                }
            }
            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 (Exception e) {
        handleException(e, userName);
    } finally {
        JNDIUtil.closeContext(subDirContext);
        JNDIUtil.closeContext(dirContext);
    }

}

From source file:com.pureinfo.studio.db.xls2srm.impl.XlsImportRunner.java

private DolphinObject makeNewObject2(Class _clazz, DolphinObject _newObj, int _nChooseIfRepeat,
        boolean isToTemp) throws Exception {
    DolphinObject newObj = null;/*from w  w w  . j  av a  2  s. c o  m*/
    StringBuffer sbuff = null;
    boolean bStringProperty;
    String strSQL = m_xmlConfig.elementTextTrim("match-properties");
    if (strSQL != null && strSQL.length() > 0) {
        StringTokenizer st = new StringTokenizer(strSQL, ",", false);
        // 
        if (isToTemp) {
            sbuff = new StringBuffer("select * from {this}0 where ");
        } else {
            sbuff = new StringBuffer("select * from {this} where ");
        }
        try {
            String sValue;
            while (st.hasMoreElements()) {
                sValue = (String) st.nextElement();

                // sValue = StrUtil.sqlEncode(sValue);
                if (_newObj.getProperty(sValue) != null) {

                    bStringProperty = _newObj.getProperty(sValue) instanceof String
                            || _newObj.getProperty(sValue) instanceof Date;
                    if ((bStringProperty && _newObj.getPropertyAsString(sValue).trim().length() > 0)
                            || (!bStringProperty)) {
                        sbuff.append("{this.");
                        sbuff.append(sValue);
                        sbuff.append("}=");

                        if (bStringProperty)
                            sbuff.append("'");

                        String sPropertyValue = _newObj.getPropertyAsString(sValue);
                        //  
                        // sPropertyValue = sPropertyValue.replaceAll(":",
                        // "");
                        while (sPropertyValue.indexOf("{") >= 0) {
                            sPropertyValue = sPropertyValue.substring(0, sPropertyValue.indexOf("{"))
                                    + sPropertyValue.substring(sPropertyValue.indexOf("{") + 1,
                                            sPropertyValue.length());
                        }
                        while (sPropertyValue.indexOf("}") >= 0) {
                            sPropertyValue = sPropertyValue.substring(0, sPropertyValue.indexOf("}"))
                                    + sPropertyValue.substring(sPropertyValue.indexOf("}") + 1,
                                            sPropertyValue.length());
                        }
                        sPropertyValue = StrUtil.escapeEncode(sPropertyValue);
                        sPropertyValue = StrUtil.sqlEncode(sPropertyValue);
                        sPropertyValue = removeBlank(sPropertyValue);

                        sbuff.append(sPropertyValue);
                        if (bStringProperty)
                            sbuff.append("'");
                        sbuff.append(" and ");
                    }
                }
            }
            int nLength = sbuff.length() - 5;
            sbuff.setLength(nLength);
            strSQL = sbuff.toString();
        } finally {
            sbuff.setLength(0);
        }

        ISession session = getSession();
        logger.debug("to make new obj from sql:" + strSQL);
        IStatement query = session.createQuery(strSQL, _clazz, 1);
        IObjects objs = null;
        try {
            objs = query.executeQuery(false);
            newObj = objs.next();
            logger.debug(">>>>>>>>>>>>" + (newObj == null));
        } finally {
            DolphinHelper.clear(objs, query);
        }
    }

    if (newObj == null) {
        if (_nChooseIfRepeat == Xls2srmForm.MERGEDATAWHENREPEAT) {
            newObj = null;
        } else {
            newObj = _newObj;
        }
    } else {
        switch (_nChooseIfRepeat) {
        // 
        case Xls2srmForm.NEWDATAWHENREPEAT:
            newObj = _newObj;
            break;
        // 
        case Xls2srmForm.LEAPDATAWHENREPEAT:
            newObj = null;
            break;
        // 
        case Xls2srmForm.COVERDATAWHENREPEAT:
            String sExcludeProps = m_xmlConfig.elementTextTrim("exclude-props-overrite");
            if (sExcludeProps == null || sExcludeProps.length() == 0) {
                DolphinUtil.copyUpdateableProperties(_newObj, newObj);
            } else {
                Iterator iter = _newObj.getProperties(false).entrySet().iterator();
                sExcludeProps = ',' + sExcludeProps + ',';
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String sName = (String) entry.getKey();
                    if (entry.getValue() != null && sExcludeProps.indexOf("," + sName + ",") < 0) {
                        newObj.setProperty(sName, entry.getValue());
                    }
                }
            }
            break;
        // 
        case Xls2srmForm.MERGEDATAWHENREPEAT: {
            String strMatchSQL = m_xmlConfig.elementTextTrim("merge-properties");
            if (strMatchSQL != null && strMatchSQL.length() > 0) {
                StringTokenizer st2 = new StringTokenizer(strMatchSQL, ",", false);
                String sValue2;
                while (st2.hasMoreElements()) {
                    sValue2 = (String) st2.nextElement();
                    if (_newObj.getProperty(sValue2) != null) {
                        newObj.setProperty(sValue2, _newObj.getProperty(sValue2));
                    }
                }
            }
            // newObj.update();
            break;
        }

        default:
            throw new PureException(PureException.INVALID_VALUE, "");
        }

    }
    return newObj;
}

From source file:net.rim.ejde.internal.util.ImportUtils.java

static private void linkPackagableFiles(IJavaProject javaProject, IPackageFragmentRoot packageFragmentRoot,
        Map<String, Set<File>> packagableContainer, List<LinkBuffer> linkBuffers) throws JavaModelException {
    IResource resource;//from   www  .j  av  a  2  s .  co  m
    IFolder packageFolder;
    IPath filePath = null;
    IPath drfpath = null;
    IFile eclipseFileHandle = null, fileHandle = null;
    StringTokenizer tokenizer;
    IPackageFragment packageFragment;
    Set<File> packageableFiles;
    Set<String> packageIds = packagableContainer.keySet();
    for (String packageId : packageIds) {
        packageableFiles = packagableContainer.get(packageId);

        if (StringUtils.isBlank(packageId)) {
            packageId = "";
        }

        packageFragment = packageFragmentRoot.createPackageFragment(packageId, true, new NullProgressMonitor());

        if (IResource.FOLDER == packageFragment.getResource().getType()) {
            packageFolder = (IFolder) packageFragment.getResource();

            for (File file : packageableFiles) {
                filePath = new Path(file.getAbsolutePath());

                if (canIgnoreFile(filePath, javaProject)) {
                    continue;
                }

                tokenizer = new StringTokenizer(packageId, ".");

                drfpath = new Path("");

                while (tokenizer.hasMoreElements()) {
                    drfpath.append(tokenizer.nextToken());
                }

                assureFolderPath(packageFolder, drfpath);

                fileHandle = createFileHandle(packageFolder, file.getName());

                resource = javaProject.getProject()
                        .findMember(PackageUtils.deResolve(filePath, javaProject.getProject().getLocation()));

                if (resource != null)
                    eclipseFileHandle = javaProject.getProject().getWorkspace().getRoot()
                            .getFile(resource.getFullPath());
                else
                    eclipseFileHandle = null;

                if (!fileHandle.equals(eclipseFileHandle)) {
                    linkBuffers.add(new LinkBuffer(fileHandle, filePath));
                }
            }
        }
    }
}