Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

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

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:com.agimatec.validation.jsr303.ConstraintDefaults.java

private Map<String, Class[]> loadDefaultConstraints(String resource) {
    Properties constraintProperties = new Properties();
    final ClassLoader classloader = getClassLoader();
    InputStream stream = classloader.getResourceAsStream(resource);
    if (stream != null) {
        try {/*www .j a v a 2 s. c om*/
            constraintProperties.load(stream);
        } catch (IOException e) {
            log.error("cannot load " + resource, e);
        }
    } else {
        log.warn("cannot find " + resource);
    }
    Map<String, Class[]> loadedConstraints = new HashMap();
    for (Map.Entry entry : constraintProperties.entrySet()) {

        StringTokenizer tokens = new StringTokenizer((String) entry.getValue(), ", ");
        LinkedList classes = new LinkedList();
        while (tokens.hasMoreTokens()) {
            final String eachClassName = tokens.nextToken();

            Class constraintValidatorClass = SecureActions.run(new PrivilegedAction<Class>() {
                public Class run() {
                    try {
                        return Class.forName(eachClassName, true, classloader);
                    } catch (ClassNotFoundException e) {
                        log.error("Cannot find class " + eachClassName, e);
                        return null;
                    }
                }
            });

            if (constraintValidatorClass != null)
                classes.add(constraintValidatorClass);

        }
        loadedConstraints.put((String) entry.getKey(), (Class[]) classes.toArray(new Class[classes.size()]));

    }
    return loadedConstraints;
}

From source file:com.redhat.winddrop.mdb.WindupExecutionQueueMDB.java

/**
 * @see MessageListener#onMessage(Message)
 *///w  w  w  . j  a  v a2s.  com
public void onMessage(Message message) {
    String jobDescription = null;
    try {
        if (message instanceof TextMessage) {
            jobDescription = ((TextMessage) message).getText();

            StringTokenizer t = new StringTokenizer(jobDescription, UploadService.TOKEN);
            String hashValue = t.nextToken();
            String packages = t.nextToken();
            String email = t.nextToken();
            LOG.info("Message received for Windup execution: " + jobDescription);
            LOG.info("hashValue: " + hashValue + " - email: " + email + " - packages: " + packages);
            buildAndUploadReport(hashValue, email, packages);
        } else {
            LOG.warning("Message of wrong type: " + message.getClass().getName());
        }
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "Error occured in onMessage for hashValue " + jobDescription, t);
    }
}

From source file:org.wicketstuff.gmap.api.GLatLng.java

/**
 * (37.34068368469045, -122.48519897460936)
 *//* ww w .  ja  v a 2 s  . c  o  m*/
public static GLatLng parse(String value) {
    try {
        StringTokenizer tokenizer = new StringTokenizer(value, "(, )");

        float lat = Float.valueOf(tokenizer.nextToken());
        float lng = Float.valueOf(tokenizer.nextToken());
        return new GLatLng(lat, lng);
    } catch (Exception e) {
        return null;
    }
}

From source file:com.sinosoft.one.mvc.web.var.FlashImpl.java

protected synchronized void readLastMessages() {
    if (lastRead) {
        return;//from  w  w  w  .j av  a2  s. com
    }
    lastRead = true;
    if (logger.isDebugEnabled()) {
        logger.debug("readLastMessages");
    }
    Cookie[] cookies = invocation.getRequest().getCookies();
    for (int i = 0; cookies != null && i < cookies.length; i++) {
        if (logger.isDebugEnabled()) {
            logger.debug("cookie " + cookies[i].getName() + "=" + cookies[i].getValue() + "; age="
                    + cookies[i].getMaxAge());
        }
        if (cookies[i].getValue() == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("ignore cookie: " + cookies[i].getName());
            }
            continue;
        }
        if (cookies[i].getName().startsWith(cookiePrefix)) {
            StringTokenizer st = new StringTokenizer(cookies[i].getName(), DELIM);
            String[] splits = new String[st.countTokens()];
            for (int j = 0; j < splits.length; j++) {
                splits[j] = st.nextToken();
            }
            if (splits.length < 2) {
                if (logger.isInfoEnabled()) {
                    logger.info("ignore flash cookie: " + cookies[i].getName());
                }
                continue;
            }
            String name = splits[1];
            String cookieValue = cookies[i].getValue();
            String flashMessage;
            if (cookieValue.length() == 0) {
                flashMessage = "";
            } else {
                try {
                    flashMessage = new String(base64.decodeFromString(cookieValue), "UTF-8");
                } catch (Exception e) {
                    logger.error("failed to decode '" + cookieValue + "' as" + " a base64 string", e);
                    flashMessage = cookieValue;
                }
            }
            if (last.size() == 0) {
                last = new LinkedHashMap<String, String>();
            }
            this.last.put(name, flashMessage);
            Cookie cookie = new Cookie(cookies[i].getName(), "");
            cookie.setPath("/");
            cookie.setMaxAge(0);
            invocation.getResponse().addCookie(cookie);
            if (logger.isDebugEnabled()) {
                logger.debug("found flash message:" + name + "=" + flashMessage);
            }
        }
    }
}

From source file:org.codehaus.groovy.grails.plugins.acegi.GrailsFilterInvocationDefinition.java

public ConfigAttributeDefinition lookupAttributes(String url) {
    setUpSession();//www .j  a  va 2 s .  c  o  m

    //set LowerCase compulsorily
    url = url.toLowerCase();

    int pos = url.indexOf("?");
    if (pos > 0) {
        url = url.substring(0, pos);
    }

    //TODO more better way
    //create query
    url = url.replaceAll("\"", "");
    url = url.replaceAll("'", "");

    //TODO more better way
    if (!url.contains(".") || url.indexOf(".gsp") > -1 || url.indexOf(".jsp") > -1) {
        StringTokenizer stn = new StringTokenizer(url, "/");
        String hql = "from " + requestMapClass + " where " + requestMapPathFieldName + " = '/**' ";
        String path = "/";
        while (stn.hasMoreTokens()) {
            String element = (String) stn.nextToken();
            path += element + "/";
            hql += "or " + requestMapPathFieldName + " ='" + path + "**' ";
        }
        hql += "order by length(" + requestMapPathFieldName + ") desc";

        //find requestMap from DB by using GORM static method.
        GrailsDomainClass requestMapDomainClass = (GrailsDomainClass) getGrailsApplication()
                .getArtefact("Domain", requestMapClass);
        List reqMap = (List) InvokerHelper.invokeStaticMethod(requestMapDomainClass.getClazz(), "findAll", hql);

        if (reqMap != null) {
            Iterator iter = reqMap.iterator();
            while (iter.hasNext()) {
                GroovyObject gobj = (GroovyObject) iter.next();
                String _configAttribute = (String) InvokerHelper.invokeMethod(gobj,
                        requestMapConfigAttributeFieldMethod, null);
                String _url = (String) InvokerHelper.invokeMethod(gobj, requestMapPathFieldMethod, null);
                _url = _url.toLowerCase();
                boolean matched = pathMatcher.match(_url, url);
                if (matched) {
                    ConfigAttributeDefinition cad = new ConfigAttributeDefinition();
                    String[] configAttrs = StringUtils.commaDelimitedListToStringArray(_configAttribute);
                    for (int i = 0; i < configAttrs.length; i++) {
                        String configAttribute = configAttrs[i];
                        cad.addConfigAttribute(new SecurityConfig(configAttribute));
                    }
                    releaseSession();
                    return cad;
                }
            }
        }
    }

    releaseSession();
    return null;
}

From source file:cn.vlabs.duckling.vwb.VWBFilter.java

private static Locale getLocale(String lstr) {
    if (lstr == null || lstr.length() < 1) {
        return null;
    }/*from w ww  .  j ava  2  s .co  m*/
    Locale locale = locales.get(lstr.toLowerCase());
    if (locale != null) {
        return locale;
    } else {
        StringTokenizer localeTokens = new StringTokenizer(lstr, "_");
        String lang = null;
        String country = null;
        if (localeTokens.hasMoreTokens()) {
            lang = localeTokens.nextToken();
        }
        if (localeTokens.hasMoreTokens()) {
            country = localeTokens.nextToken();
        }
        locale = new Locale(lang, country);
        Locale crtls[] = Locale.getAvailableLocales();
        for (int i = 0; i < crtls.length; i++) {
            if (crtls[i].equals(locale)) {
                locale = crtls[i];
                break;
            }
        }
        locales.put(lstr.toLowerCase(), locale);
    }
    return locale;
}

From source file:com.glaf.core.web.springmvc.MxMembershipController.java

@ResponseBody
@RequestMapping("/delete")
public void delete(HttpServletRequest request, ModelMap modelMap) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String rowId = ParamUtils.getString(params, "rowId");
    String rowIds = request.getParameter("rowIds");
    if (StringUtils.isNotEmpty(rowIds)) {
        StringTokenizer token = new StringTokenizer(rowIds, ",");
        while (token.hasMoreTokens()) {
            String x = token.nextToken();
            if (StringUtils.isNotEmpty(x)) {

            }//from  w ww  .  ja va2  s  . c o  m
        }
    } else if (StringUtils.isNotEmpty(rowId)) {

    }
}

From source file:com.taurus.compratae.appservice.impl.EnvioArchivoFTPServiceImpl.java

public void conectarFTP(Archivo archivo) {
    FTPClient client = new FTPClient();
    /*String sFTP = "127.0.0.1";
    String sUser = "tae";//ww  w. j  a v  a  2s  .c o  m
    String sPassword = "tae";*/
    String sFTP = buscarParametros(FTP_SERVER);
    String sUser = buscarParametros(FTP_USER);
    String sPassword = buscarParametros(FTP_PASSWORD);
    ///////////////////////////////////
    //String[] lista;
    try {
        client.connect(sFTP);
        boolean login = client.login(sUser, sPassword);
        System.out.println("1. Directorio de trabajo: " + client.printWorkingDirectory());
        client.setFileType(FTP.BINARY_FILE_TYPE);
        BufferedInputStream buffIn = null;
        buffIn = new BufferedInputStream(new FileInputStream(archivo.getNombre()));
        client.enterLocalPassiveMode();
        StringTokenizer tokens = new StringTokenizer(archivo.getNombre(), "/");//Para separar el nombre de la ruta.
        int i = 0;
        String nombre = "";
        while (tokens.hasMoreTokens()) {
            if (i == 1) {
                nombre = tokens.nextToken();
                i++;
            } else {
                i++;
            }
        }
        client.storeFile(nombre, buffIn);
        buffIn.close();
        /*lista = client.listNames();
        for (String lista1 : lista) {
        System.out.println(lista1);
        }*/
        //client.changeWorkingDirectory("\\done");
        //System.out.println("2. Working Directory: " + client.printWorkingDirectory());
        client.logout();
        client.disconnect();
        System.out.println("Termin de conectarme al FTP!!");
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:net.fender.sql.WeightedLoadBalancingDataSource.java

@Override
public void init() throws Exception {
    super.init();
    if (dataSources == null || weights == null) {
        throw new IllegalStateException("dataSources and weights must not be null");
    }//from  w  w  w.  ja  v a 2s.  com
    StringTokenizer parser = new StringTokenizer(weights, ",");
    if (dataSources.size() != parser.countTokens()) {
        throw new IllegalStateException("dataSources and weights must be the same size");
    }
    List<DataSource> temp = new ArrayList<DataSource>();
    int bucket = 0;
    Iterator<DataSource> d = dataSources.iterator();
    while (parser.hasMoreTokens()) {
        int weight = Integer.parseInt(parser.nextToken().trim());
        DataSource dataSource = d.next();
        for (int j = bucket; j < bucket + weight; j++) {
            temp.add(dataSource);
        }
        bucket += weight;
    }
    size = temp.size();
    buckets = temp.toArray(new DataSource[size]);
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 *  If-None-Match Header,Etag.//from  w  ww.j a v  a 2 s  .c  o m
 * 
 * Etag,checkIfNoneMatchfalse, 304 not modify status.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!headerValue.equals("*")) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", etag);
            return false;
        }
    }
    return true;
}