Example usage for java.util StringTokenizer nextElement

List of usage examples for java.util StringTokenizer nextElement

Introduction

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

Prototype

public Object nextElement() 

Source Link

Document

Returns the same value as the nextToken method, except that its declared return value is Object rather than String .

Usage

From source file:org.apache.torque.engine.database.model.JavaNameGenerator.java

/**
 * Converts a database schema name to java object name.  Removes
 * <code>STD_SEPARATOR_CHAR</code> and <code>SCHEMA_SEPARATOR_CHAR</code>,
 * capitilizes first letter of name and each letter after the
 * <code>STD_SEPERATOR</code> and <code>SCHEMA_SEPARATOR_CHAR</code>,
 * converts the rest of the letters to lowercase.
 *
 * @param schemaName name to be converted.
 * @return converted name.//from  w ww.  java 2s .  c  om
 * @see org.apache.torque.engine.database.model.NameGenerator
 * @see #underscoreMethod(String)
 */
protected String underscoreMethod(String schemaName) {
    StringBuffer name = new StringBuffer();

    // remove the STD_SEPARATOR_CHARs and capitalize
    // the tokens
    StringTokenizer tok = new StringTokenizer(schemaName, String.valueOf(STD_SEPARATOR_CHAR));
    while (tok.hasMoreTokens()) {
        String namePart = ((String) tok.nextElement()).toLowerCase();
        name.append(StringUtils.capitalize(namePart));
    }

    // remove the SCHEMA_SEPARATOR_CHARs and capitalize
    // the tokens
    schemaName = name.toString();
    name = new StringBuffer();
    tok = new StringTokenizer(schemaName, String.valueOf(SCHEMA_SEPARATOR_CHAR));
    while (tok.hasMoreTokens()) {
        String namePart = (String) tok.nextElement();
        name.append(StringUtils.capitalize(namePart));
    }
    return name.toString();
}

From source file:io.starter.datamodel.ContentData.java

/**
 * assign categories to an item//w w w.j  a  v a  2  s  . c o m
 * 
 * @param obj
 * @param cats
 * @throws ServletException
 */
public static void setCategories(Integer objId, String cats, SqlSession session) throws ServletException {

    int rowsInserted = 0;

    StringTokenizer toker = new StringTokenizer(cats, ",");

    while (toker.hasMoreElements()) {

        String st = toker.nextElement().toString();
        if (st.contains("[")) {
            st = st.substring(1);
        }

        if (st.contains("]")) {

            st = st.substring(0, st.length() - 1);

        }
        Integer categoryId = Integer.parseInt(st);

        ContentCategoryIdx cat = new ContentCategoryIdx();
        cat.setCategoryId(categoryId);
        cat.setContentId(objId);

        rowsInserted = session.insert("io.starter.dao.ContentCategoryIdxMapper.insert", cat);

        session.commit();

    }

    if (rowsInserted > 0) {
        ;
    } else {
        throw new ServletException(
                "Null rows inserted in ContentCategory IDX -- could not assign categories to Content object.");
    }

}

From source file:org.craftercms.commons.mongo.MongoClientFactory.java

@Override
protected MongoClient createInstance() throws Exception {

    if (StringUtils.isBlank(connectionString)) {
        logger.info("No connection string specified, connecting to {}:{}", connectionString, DEFAULT_MONGO_HOST,
                DEFAULT_MONGO_PORT);//from w  w w .  j a v  a 2  s  .c  om

        return new MongoClient(new ServerAddress(DEFAULT_MONGO_HOST, DEFAULT_MONGO_PORT));
    }

    StringTokenizer st = new StringTokenizer(connectionString, ",");
    List<ServerAddress> addressList = new ArrayList<>();

    while (st.hasMoreElements()) {
        String server = st.nextElement().toString();

        logger.debug("Processing first server found with string {}", server);

        String[] serverAndPort = server.split(":");
        if (serverAndPort.length == 2) {
            logger.debug("Server string defines host {} and port {}", serverAndPort[0], serverAndPort[1]);

            if (StringUtils.isBlank(serverAndPort[0])) {
                throw new IllegalArgumentException("Given host can't be empty");
            }

            int portNumber = NumberUtils.toInt(serverAndPort[1]);
            if (portNumber == 0) {
                throw new IllegalArgumentException("Given port number " + portNumber + " is not valid");
            }

            addressList.add(new ServerAddress(serverAndPort[0], portNumber));
        } else if (serverAndPort.length == 1) {
            logger.debug("Server string defines host {} only. Using default port ", serverAndPort[0]);

            if (StringUtils.isBlank(serverAndPort[0])) {
                throw new IllegalArgumentException("Given host can't be empty");
            }

            addressList.add(new ServerAddress(serverAndPort[0], DEFAULT_MONGO_PORT));
        } else {
            throw new IllegalArgumentException("Given connection string is not valid");
        }
    }

    logger.debug("Creating MongoClient with addresses: {}", addressList);

    if (options != null) {
        return new MongoClient(addressList, options);
    } else {
        return new MongoClient(addressList);
    }
}

From source file:org.wso2.carbon.identity.entitlement.pip.DefaultAttributeFinder.java

public Set<String> getAttributeValues(String subjectId, String resourceId, String actionId,
        String environmentId, String attributeId, String issuer) throws Exception {
    Set<String> values = new HashSet<String>();

    subjectId = MultitenantUtils.getTenantAwareUsername(subjectId);
    if (UserCoreConstants.ClaimTypeURIs.ROLE.equals(attributeId)) {
        if (log.isDebugEnabled()) {
            log.debug("Looking for roles via DefaultAttributeFinder");
        }//from   w w  w .ja va  2s  .co m
        String[] roles = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager()
                .getRoleListOfUser(subjectId);
        if (roles != null && roles.length > 0) {
            for (String role : roles) {
                if (log.isDebugEnabled()) {
                    log.debug(String.format("User %1$s belongs to the Role %2$s", subjectId, role));
                }
                values.add(role);
            }
        }
    } else {
        String claimValue = null;
        try {
            claimValue = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager()
                    .getUserClaimValue(subjectId, attributeId, null);
        } catch (UserStoreException e) {
            if (e.getMessage().startsWith(IdentityCoreConstants.USER_NOT_FOUND)) {
                if (log.isDebugEnabled()) {
                    log.debug("User: " + subjectId + " not found in user store");
                }
            } else {
                throw e;
            }
        }
        if (claimValue == null && log.isDebugEnabled()) {
            log.debug(String.format("Request attribute %1$s not found", attributeId));
        }
        // Fix for multiple claim values
        if (claimValue != null) {
            String claimSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm()
                    .getRealmConfiguration()
                    .getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
            if (StringUtils.isBlank(claimSeparator)) {
                claimSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT;
            }
            if (claimValue.contains(claimSeparator)) {
                StringTokenizer st = new StringTokenizer(claimValue, claimSeparator);
                while (st.hasMoreElements()) {
                    String attributeValue = st.nextElement().toString();
                    if (StringUtils.isNotBlank(attributeValue)) {
                        values.add(attributeValue);
                    }
                }
            } else {
                values.add(claimValue);
            }
        }
    }
    return values;
}

From source file:org.aries.maven.plugin.GeneratorMojo.java

protected GenerationContext createGenerationContext() {
    GenerationContext context = new GenerationContext();
    if (!StringUtils.isEmpty(projectName))
        context.setProjectName(projectName);
    if (!StringUtils.isEmpty(templateHome))
        context.setTemplateHome(templateHome);
    if (!StringUtils.isEmpty(templateName))
        context.setTemplateName(templateName);
    if (!StringUtils.isEmpty(targetHome))
        context.setTargetHome(targetHome);
    if (!StringUtils.isEmpty(targetWorkspace))
        context.setTargetWorkspace(targetWorkspace);
    if (!StringUtils.isEmpty(subsetType)) {
        context.getSubsets().clear();//from  w w  w  .j ava 2s  . com
        StringTokenizer tokenizer = new StringTokenizer(subsetType);
        while (tokenizer.hasMoreElements()) {
            String subset = (String) tokenizer.nextElement();
            context.addSubset(subset);
        }
    }
    return context;
}

From source file:nl.toolforge.karma.core.vc.cvsimpl.CVSResponseAdapter.java

public Object[] getArguments(String args) {

    if (arguments == null) {
        return null;
    }//  w  w w . j  a v  a 2s. co m

    List argList = new ArrayList();
    StringTokenizer tokenizer = new StringTokenizer(args, ",");
    while (tokenizer.hasMoreTokens()) {
        argList.add(((String) tokenizer.nextElement()).trim());
    }

    // First pass ... count actual available parameters; is there a value for each requested key ?
    //

    int j = 0;
    for (Iterator i = argList.iterator(); i.hasNext();) {
        String value = (String) arguments.get((String) i.next());
        j = (value == null ? j : (j += 1));
    }

    // Second pass ... assign values
    //

    Object[] argArray = new Object[j];
    j = 0; // Reset
    for (Iterator i = argList.iterator(); i.hasNext();) {
        String value = (String) arguments.get((String) i.next());
        if (value != null) {
            argArray[j] = value;
            j++;
        }
    }

    arguments = null; // Reset this session ...

    return argArray;
}

From source file:org.trafodion.dtm.TmAuditTlog.java

public static String getRecord(final String transidString) throws IOException {
    if (LOG.isTraceEnabled())
        LOG.trace("getRecord start");
    long lvTransid = Long.parseLong(transidString, 10);
    int lv_lockIndex = (int) (lvTransid & tLogHashKey);
    String lvTxState = new String("NO RECORD");
    try {/*from   w  ww . j  av a2s  . c om*/
        Get g;
        //create our own hashed key
        long key = (((lvTransid & tLogHashKey) << tLogHashShiftFactor) + (lvTransid & 0xFFFFFFFF));
        if (LOG.isTraceEnabled())
            LOG.trace("key: " + key + " hex: " + Long.toHexString(key));
        g = new Get(Bytes.toBytes(key));
        try {
            Result r = table[lv_lockIndex].get(g);
            byte[] value = r.getValue(TLOG_FAMILY, ASN_STATE);
            StringTokenizer st = new StringTokenizer(value.toString(), ",");
            String asnToken = st.nextElement().toString();
            String transidToken = st.nextElement().toString();
            lvTxState = st.nextElement().toString();
            if (LOG.isTraceEnabled())
                LOG.trace("transid: " + transidToken + " state: " + lvTxState);
        } catch (IOException e) {
            LOG.error("getRecord IOException");
            throw e;
        }
    } catch (Exception e) {
        LOG.error("getRecord Exception " + e);
        throw e;
    }
    if (LOG.isTraceEnabled())
        LOG.trace("getRecord end; returning String:" + lvTxState);
    return lvTxState;
}

From source file:org.wso2.carbon.apimgt.keymgt.token.APIMJWTGenerator.java

public String buildBody(JwtTokenInfoDTO jwtTokenInfoDTO) throws APIManagementException {

    Map<String, Object> standardClaims = populateStandardClaims(jwtTokenInfoDTO);

    //get tenantId
    int tenantId = APIUtil.getTenantId(jwtTokenInfoDTO.getEndUserName());

    String claimSeparator = getMultiAttributeSeparator(tenantId);
    if (StringUtils.isNotBlank(claimSeparator)) {
        userAttributeSeparator = claimSeparator;
    }/* w  ww .  j av a 2 s. c  o  m*/

    if (standardClaims != null) {
        JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder();

        Iterator<String> it = new TreeSet(standardClaims.keySet()).iterator();
        while (it.hasNext()) {
            String claimURI = it.next();

            Object claimValObj = standardClaims.get(claimURI);
            if (claimValObj instanceof String) {
                String claimVal = (String) claimValObj;
                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);
                        }
                    }
                    jwtClaimsSetBuilder.claim(claimURI, claimList.toArray(new String[claimList.size()]));
                } else if (APIConstants.EXP.equals(claimURI)) {
                    jwtClaimsSetBuilder.claim(APIConstants.EXP,
                            new Date(Long.valueOf((String) standardClaims.get(claimURI))));
                } else {
                    jwtClaimsSetBuilder.claim(claimURI, claimVal);
                }
            } else {
                if (claimValObj != null) {
                    jwtClaimsSetBuilder.claim(claimURI, claimValObj);
                }
            }
        }

        return jwtClaimsSetBuilder.build().toJSONObject().toJSONString();
    }
    return null;
}

From source file:com.headstrong.npi.raas.Utils.java

public static String removeBlankSpaces(String name) {

    StringTokenizer st = new StringTokenizer(name, " ", false);
    StringBuffer completelyFormattedValue = new StringBuffer();
    while (st.hasMoreElements())
        completelyFormattedValue.append(st.nextElement());
    return completelyFormattedValue.toString();
}

From source file:com.egeniuss.appmarket.controller.AppManagerController.java

@RequestMapping("/uploadApp.html")
public @ResponseBody Map<String, Object> uploadApp(@RequestParam(required = false) MultipartFile app,
        HttpServletRequest request) {//from ww  w .  j a  v a2  s.co m
    Date now = new Date();
    long time = now.getTime();
    String appFileName = app.getOriginalFilename();
    String realFileName = time + appFileName.substring(appFileName.lastIndexOf("."));
    Map<String, Object> msg = new HashMap<String, Object>();
    try {
        FileUtils.copyInputStreamToFile(app.getInputStream(), new File(appStore.concat(realFileName)));
    } catch (IOException e) {
        LOGGER.error("?", e);
        msg.put("errcode", -1);
        msg.put("errmsg", "<br/>" + e.getMessage());
        return msg;
    }
    SimpleDateFormat formator = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    StringTokenizer linemsg = new StringTokenizer(request.getParameter("releaseNote"), "\n");
    StringBuilder releaseNoteSb = new StringBuilder();
    while (linemsg.hasMoreElements()) {
        releaseNoteSb.append(linemsg.nextElement()).append("\\n");
    }
    Object[] args = new Object[] { time, request.getParameter("appKey"), request.getParameter("appPlatform"),
            request.getParameter("appEnv"), request.getParameter("versionNum"), app.getSize(),
            releaseNoteSb.toString(), realFileName, formator.format(now) };
    int[] argTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.DECIMAL, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR };
    jdbcTemplate.update(
            "insert into APP_MARKET (APP_ID, APP_KEY, APP_PLATFORM, APP_ENV, VERSION_NUM, APP_SIZE, RELEASE_NOTE, FILE_NAME, CREATE_TIME) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            args, argTypes);
    msg.put("errcode", 0);
    msg.put("errmsg", "ok");
    return msg;
}