Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:io.jari.geenstijl.API.API.java

private static Artikel parseArtikel(Element artikel_el, Context context) throws ParseException {
    Artikel artikel = new Artikel();

    //id/*from w  w w.jav a  2 s  .com*/
    artikel.id = Integer.parseInt(artikel_el.attr("id").substring(1));

    //summary
    artikel.summary = artikel_el.select("a.more").first() != null;

    //titel
    artikel.titel = artikel_el.select("h1").text();

    //plaatje
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_images", true)) {
        Element plaatje = artikel_el.select("img").first();
        if (plaatje != null) {
            try {
                String url = plaatje.attr("src");
                Log.d(TAG, "Downloading " + url);
                //                    artikel.plaatje = Drawable.createFromStream(((java.io.InputStream)new URL(plaatje.attr("src")).getContent()), null);
                artikel.plaatje = readBytes((InputStream) new URL(plaatje.attr("src")).getContent());
                artikel.groot_plaatje = plaatje.hasClass("groot");
                if (plaatje.hasAttr("width") && plaatje.hasAttr("height"))
                    if (!plaatje.attr("width").equals("100") || !plaatje.attr("height").equals("100"))
                        artikel.groot_plaatje = true;
                if (artikel.groot_plaatje)
                    Log.i(TAG, "    Done. Big image.");
                else
                    Log.i(TAG, "    Done.");
            } catch (Exception ex) {
                Log.w(TAG, "Unable to download image, Falling back... Reason: " + ex.getMessage());
                artikel.plaatje = null;
            }
        }
    }

    //embed
    if (artikel_el.select("div.embed").first() != null) {
        //atm alleen support voor iframes
        Element frame = artikel_el.select("div.embed>iframe").first();
        if (frame != null)
            artikel.embed = frame.attr("src");
    }

    //embed (geenstijl.tv)
    if (!domain.equals("www.geenstijl.nl")) {
        //extract url from script
        Element scriptEl = artikel_el.select("script").first();
        if (scriptEl != null) {
            String script = scriptEl.html();
            Pattern pattern = Pattern.compile("'(.*)', fall");
            Matcher matcher = pattern.matcher(script);
            if (matcher.find() && matcher.groupCount() == 1) {
                artikel.embed = matcher.group(1);
            }
        }
    }

    //footer shit
    Element footer = artikel_el.select("footer").first();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm", Locale.US);
    artikel.datum = simpleDateFormat.parse(footer.select("time").first().attr("datetime"));

    StringTokenizer footer_items = new StringTokenizer(footer.text(), "|");
    artikel.auteur = footer_items.nextToken().trim();

    artikel.reacties = Integer.parseInt(footer.select("a.comments").text().replace(" reacties", ""));

    artikel.link = footer.select("a").first().attr("href");

    //clean up
    artikel_el.select("h1").remove();
    artikel_el.select(".embed").remove();
    artikel_el.select("img").remove();
    artikel_el.select("footer").remove();
    artikel_el.select("a.more").remove();
    artikel_el.select("script").remove();

    //inhoud
    artikel.inhoud = artikel_el.html();

    return artikel;
}

From source file:com.aurel.track.item.SendItemEmailBL.java

public static List<TPersonBean> validateEmails(String emails, List<TPersonBean> groups) {
    if (emails == null || emails.length() == 0) {
        return new ArrayList<TPersonBean>();
    }/*from w w w.jav  a2s  .co  m*/
    List<TPersonBean> result = new ArrayList<TPersonBean>();
    StringTokenizer st = new StringTokenizer(emails, ";");
    Set<String> emailSet = new HashSet<String>();
    String emailFull;
    String email;
    while (st.hasMoreElements()) {
        emailFull = st.nextToken();
        email = extractEmail(emailFull);
        if (!verifyEmail(email)) {
            Integer groupID = isGroup(email, groups);
            if (groupID != null) {
                LOGGER.debug("Include group");
                List<TPersonBean> personsInGroup = PersonBL.loadPersonsForGroup(groupID);
                if (personsInGroup != null && !personsInGroup.isEmpty()) {
                    for (TPersonBean p : personsInGroup) {
                        if (!emailSet.contains(p.getEmail())) {
                            result.add(p);
                            emailSet.add(p.getEmail());
                        }
                    }
                }
            } else {
                LOGGER.debug("emailFull:" + emailFull + ", email:" + email + " not Valid!");
                return null;
            }
        } else {
            LOGGER.debug("emailFull:" + emailFull + ", email:" + email + " is Valid!");
            if (emailSet.contains(email)) {
                LOGGER.debug("Email already present");
            } else {
                TPersonBean person = new TPersonBean("", "", email);
                result.add(person);
                emailSet.add(email);
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("Valid emails:[");
        for (TPersonBean p : result) {
            sb.append(p.getEmail() + ";");
        }
        sb.append("]");
        LOGGER.debug(sb);
    }
    return result;
}

From source file:keel.Algorithms.Neural_Networks.IRPropPlus_Clas.KEELIRPropPlusWrapperClas.java

/**
 * <p>/*from  w ww. j a  v  a2  s. com*/
 * Reads schema from the KEEL file
 * 
 * @param jobFilename Name of the KEEL dataset file
 * </p>
 */

private static byte[] readSchema(String fileName) throws IOException, DatasetException {

    KeelDataSet dataset = new KeelDataSet(fileName);
    dataset.open();

    File file = new File(fileName);

    List<String> inputIds = new ArrayList<String>();
    List<String> outputIds = new ArrayList<String>();

    Reader reader = new BufferedReader(new FileReader(file));
    String line = ((BufferedReader) reader).readLine();
    StringTokenizer elementLine = new StringTokenizer(line);
    String element = elementLine.nextToken();

    while (!element.equalsIgnoreCase("@data")) {

        if (element.equalsIgnoreCase("@inputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    inputIds.add(commaTokenizer.nextToken());
            }
        } else if (element.equalsIgnoreCase("@outputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    outputIds.add(commaTokenizer.nextToken());
            }
        }

        // Next line of the file
        line = ((BufferedReader) reader).readLine();
        while (line.startsWith("%") || line.equalsIgnoreCase(""))
            line = ((BufferedReader) reader).readLine();

        elementLine = new StringTokenizer(line);
        element = elementLine.nextToken();
    }

    IMetadata metadata = dataset.getMetadata();
    byte[] schema = new byte[metadata.numberOfAttributes()];

    if (inputIds.isEmpty() || outputIds.isEmpty()) {
        for (int i = 0; i < schema.length; i++) {
            if (i != (schema.length - 1))
                schema[i] = 1;
            else {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            }
        }
    } else {
        for (int i = 0; i < schema.length; i++) {
            if (inputIds.contains(metadata.getAttribute(i).getName()))
                schema[i] = 1;
            else if (outputIds.contains(metadata.getAttribute(i).getName())) {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            } else
                schema[i] = -1;
        }
    }

    StringBuffer header = new StringBuffer();
    header.append("@relation " + dataset.getName() + "\n");
    for (int i = 0; i < metadata.numberOfAttributes(); i++) {
        IAttribute attribute = metadata.getAttribute(i);
        header.append("@attribute " + attribute.getName() + " ");
        if (attribute.getType() == AttributeType.Categorical) {
            CategoricalAttribute catAtt = (CategoricalAttribute) attribute;

            Interval interval = catAtt.intervalValues();

            header.append("{");
            for (int j = (int) interval.getLeft(); j <= interval.size() + 1; j++) {
                header.append(catAtt.show(j) + (j != interval.size() + 1 ? "," : "}\n"));
            }
        } else if (attribute.getType() == AttributeType.IntegerNumerical) {
            IntegerNumericalAttribute intAtt = (IntegerNumericalAttribute) attribute;
            header.append("integer[" + (int) intAtt.intervalValues().getLeft() + ","
                    + (int) intAtt.intervalValues().getRight() + "]\n");
        } else if (attribute.getType() == AttributeType.DoubleNumerical) {
            RealNumericalAttribute doubleAtt = (RealNumericalAttribute) attribute;
            header.append("real[" + doubleAtt.intervalValues().getLeft() + ","
                    + doubleAtt.intervalValues().getRight() + "]\n");
        }
    }
    header.append("@data\n");
    consoleReporter.setHeader(header.toString());

    dataset.close();
    return schema;
}

From source file:net.sf.excelutils.ExcelParser.java

/**
 * get a instance by the tag name.//from  ww w .j  a v  a  2  s  . c  om
 * 
 * @param str tag name
 * @return ITag instance
 */
public static ITag getTagClass(String str) {
    String tagName = "";
    int keytag = str.indexOf(KEY_TAG);
    if (keytag < 0)
        return null;
    if (!(keytag < str.length() - 1))
        return null;
    String tagRight = str.substring(keytag + 1, str.length());
    if (tagRight.startsWith(KEY_TAG) || "".equals(tagRight.trim()))
        return null;

    str = str.substring(str.indexOf(KEY_TAG) + KEY_TAG.length(), str.length());
    StringTokenizer st = new StringTokenizer(str, " ");
    if (st.hasMoreTokens()) {
        tagName = st.nextToken();
    }
    tagName = tagName.substring(0, 1).toUpperCase() + tagName.substring(1, tagName.length());
    tagName += "Tag";

    // find in tagMap first, if not exist, search in the package
    ITag tag = (ITag) tagMap.get(tagName);
    if (tag == null) {
        Iterator tagPackages = tagPackageMap.values().iterator();
        // seach the tag class
        while (tagPackages.hasNext() && null == tag) {
            String packageName = (String) tagPackages.next();
            try {
                Class clazz = Class.forName(packageName + "." + tagName);
                tag = (ITag) clazz.newInstance();
            } catch (Exception e) {
                tag = null;
            }
        }
        if (tag != null) {
            // find it, cache it
            tagMap.put(tagName, tag);
        }
    }
    return tag;
}

From source file:com.jims.oauth2.common.utils.OAuthUtils.java

public static Set<String> decodeScopes(String s) {
    Set<String> scopes = new HashSet<String>();
    if (!OAuthUtils.isEmpty(s)) {
        StringTokenizer tokenizer = new StringTokenizer(s, " ");

        while (tokenizer.hasMoreElements()) {
            scopes.add(tokenizer.nextToken());
        }/*from   w  w w.  ja  va  2s .  c  om*/
    }
    return scopes;

}

From source file:com.moviejukebox.tools.StringTools.java

public static String[] tokenizeToArray(String sourceString, String delimiter) {
    StringTokenizer st = new StringTokenizer(sourceString, delimiter);
    Collection<String> keywords = new ArrayList<>();
    while (st.hasMoreTokens()) {
        keywords.add(st.nextToken());
    }/*  w w  w  . j ava  2s  . c om*/
    return keywords.toArray(new String[keywords.size()]);
}

From source file:hudson.plugins.testlink.util.TestLinkHelper.java

/**
 * <p>Defines TestLink Java API Properties. Following is the list of available 
 * properties.</p>//  w  w  w.ja v  a2 s  . co  m
 * 
 * <ul>
 *     <li>xmlrpc.basicEncoding</li>
  *     <li>xmlrpc.basicPassword</li>
  *     <li>xmlrpc.basicUsername</li>
  *     <li>xmlrpc.connectionTimeout</li>
  *     <li>xmlrpc.contentLengthOptional</li>
  *     <li>xmlrpc.enabledForExceptions</li>
  *     <li>xmlrpc.encoding</li>
  *     <li>xmlrpc.gzipCompression</li>
  *     <li>xmlrpc.gzipRequesting</li>
  *     <li>xmlrpc.replyTimeout</li>
  *     <li>xmlrpc.userAgent</li>
 * </ul>
 * 
 * @param testLinkJavaAPIProperties
 * @param listener Jenkins Build listener
 */
public static void setTestLinkJavaAPIProperties(String testLinkJavaAPIProperties, BuildListener listener) {
    if (StringUtils.isNotBlank(testLinkJavaAPIProperties)) {
        final StringTokenizer tokenizer = new StringTokenizer(testLinkJavaAPIProperties, ",");

        if (tokenizer.countTokens() > 0) {
            while (tokenizer.hasMoreTokens()) {
                String systemProperty = tokenizer.nextToken();
                maybeAddSystemProperty(systemProperty, listener);
            }
        }
    }
}

From source file:eionet.cr.util.URLUtil.java

/**
 *
 * @param str//from   w  w w .j  av a 2  s. c  om
 * @param exceptions
 * @return
 * @throws UnsupportedEncodingException
 */
private static String decodeEncode(String str, String exceptions) throws UnsupportedEncodingException {

    if (StringUtils.isEmpty(str)) {
        return str;
    } else if (StringUtils.isEmpty(exceptions)) {
        return decodeEncode(str);
    }

    StringBuilder result = new StringBuilder();
    StringTokenizer tokenizer = new StringTokenizer(str, exceptions, true);
    while (tokenizer.hasMoreTokens()) {

        String token = tokenizer.nextToken();
        if (!token.isEmpty() && exceptions.contains(token)) {
            result.append(token);
        } else {
            result.append(decodeEncode(token));
        }
    }

    return result.toString();
}

From source file:org.bedework.timezones.server.MethodBase.java

/** Return a path, beginning with a "/", after "." and ".." are removed.
 * If the parameter path attempts to go above the root we return null.
 *
 * Other than the backslash thing why not use URI?
 *
 * @param path      String path to be fixed
 * @return String   fixed path//  ww  w.j  a  v a2s.c o  m
 * @throws ServletException
 */
public static ResourceUri fixPath(final String path) throws ServletException {
    if (path == null) {
        return new ResourceUri();
    }

    String decoded;
    try {
        decoded = URLDecoder.decode(path, "UTF8");
    } catch (final Throwable t) {
        throw new ServletException("bad path: " + path);
    }

    if (decoded == null) {
        return new ResourceUri();
    }

    /** Make any backslashes into forward slashes.
     */
    if (decoded.indexOf('\\') >= 0) {
        decoded = decoded.replace('\\', '/');
    }

    /** Ensure a leading '/'
     */
    if (!decoded.startsWith("/")) {
        decoded = "/" + decoded;
    }

    /** Remove all instances of '//'.
     */
    while (decoded.contains("//")) {
        decoded = decoded.replaceAll("//", "/");
    }
    /** Somewhere we may have /./ or /../
     */

    final StringTokenizer st = new StringTokenizer(decoded, "/");

    final ArrayList<String> al = new ArrayList<>();
    while (st.hasMoreTokens()) {
        final String s = st.nextToken();

        if (s.equals(".")) {
            // ignore
            continue;
        }

        if (s.equals("..")) {
            // Back up 1
            if (al.size() == 0) {
                // back too far
                return new ResourceUri();
            }

            al.remove(al.size() - 1);
            continue;
        }

        al.add(s);
    }

    final ResourceUri ruri = new ResourceUri();

    /** Reconstruct */
    for (final String s : al) {
        ruri.addPathElement(s);
    }

    return ruri;
}

From source file:com.github.dozermapper.core.util.ReflectionUtils.java

private static Method findMethodWithParam(Class<?> parentDestClass, String methodName, String params,
        BeanContainer beanContainer) throws NoSuchMethodException {
    List<Class<?>> list = new ArrayList<>();
    if (params != null) {
        StringTokenizer tokenizer = new StringTokenizer(params, ",");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            list.add(MappingUtils.loadClass(token, beanContainer));
        }//w  w w. j av a2  s .  c om
    }
    return getMethod(parentDestClass, methodName, list.toArray(new Class[list.size()]));
}