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.industrieit.ohr.OHRJavassister.java

private static void setBaseMixinsPost(CtClass cc, boolean includeChecks, List<Integer> owned,
        PropertyDescriptor[] pds, StringBuilder constructBuilder, StringBuilder initBuilder)
        throws CannotCompileException, IOException, NotFoundException {
    //empty constrcutor
    constructBuilder.append("}");
    System.out.println(constructBuilder.toString());
    CtConstructor ctc = new CtConstructor(new CtClass[0], cc);
    ctc.setBody(constructBuilder.toString());
    cc.addConstructor(ctc);//from w  w  w.j  a va  2  s  .c  om

    initBuilder.append("\n}");
    System.out.println(initBuilder.toString());
    CtMethod initmeth = CtNewMethod.make(initBuilder.toString(), cc);
    cc.addMethod(initmeth);

    StringBuilder sb = new StringBuilder();
    sb.append("public void freeOwnedChildren() {");
    for (Integer i : owned) {
        String fnam = pds[i].getName();
        sb.append("com.industreiit.ohr.Reifier.freeOHR(" + pds[i].getReadMethod().getName() + "());");
    }
    sb.append("}");
    CtMethod owm = CtNewMethod.make(sb.toString(), cc);
    cc.addMethod(owm);

    String str = IOUtils.toString(OHRJavassister.class.getResourceAsStream("/ohr/base/basemethodspost.txt"));

    String checkplace = "";
    if (includeChecks) {
        checkplace = "doOHRCheck();";
    }

    str = str.replace("<<READCHECK>>", checkplace);
    str = str.replace("<<WRITECHECK>>", checkplace);

    StringTokenizer st = new StringTokenizer(str, "~~~");

    while (st.hasMoreElements()) {
        String meth = st.nextToken();
        //PL.pl("adding method: " + meth);
        CtMethod wmethod = CtNewMethod.make(meth, cc);
        cc.addMethod(wmethod);
    }

}

From source file:com.industrieit.ohr.OHRJavassister.java

private static void setBaseMixinsPre(CtClass cc, boolean includeChecks)
        throws CannotCompileException, IOException, NotFoundException {
    //add fields/*from  ww  w  .j  ava  2  s.  co  m*/

    //add basePtr
    //CtField cf = new CtField(CtClass.longType, "crapField", cc);
    //cf.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    //cc.addField(cf);

    //add basePtr
    CtField f = new CtField(CtClass.longType, "basePtr", cc);
    f.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    cc.addField(f);

    //add instmarker
    CtField fm = new CtField(CtClass.intType, "instmarker", cc);
    fm.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    cc.addField(fm);

    CtClass cu = getDefault().get("sun.misc.Unsafe");
    CtField f2 = new CtField(cu, "u", cc);
    f2.setModifiers(Modifier.STATIC | Modifier.PRIVATE);
    cc.addField(f2);

    //add check method
    String checkmeth = "public void doOHRCheck() { if (u.getInt(basePtr+4)!=instmarker) throw new com.industrieit.ohr.StaleHandleException(\"bad instmarker\"); }";
    //PL.pl(checkmeth);
    CtMethod cm = CtNewMethod.make(checkmeth, cc);
    cc.addMethod(cm);

    String str = IOUtils.toString(OHRJavassister.class.getResourceAsStream("/ohr/base/basemethodspre.txt"));

    String checkplace = "";
    if (includeChecks) {
        checkplace = "doOHRCheck();";
    }
    //place in prechecks if desired
    str = str.replace("<<READCHECK>>", checkplace);
    str = str.replace("<<WRITECHECK>>", checkplace);

    StringTokenizer st = new StringTokenizer(str, "~~~");

    while (st.hasMoreElements()) {
        String meth = st.nextToken();
        //PL.pl("adding method: " + meth);
        CtMethod wmethod = CtNewMethod.make(meth, cc);
        cc.addMethod(wmethod);
    }
}

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

/**
 * Example: src = "<a id="specialID"><br/> <img src="a.gif"/>my text</a>
 * findStr = "specialID" result = "my text"
 *
 * @param src html text/*from  ww w.ja v a  2 s.  co  m*/
 * @param findStr string to find in src
 * @param skip count of found texts to skip
 * @param fromIndex begin index in src
 * @return string from html text which is plain text without html tags
 */
public static String getTextAfterElem(String src, String findStr, int skip, int fromIndex) {
    if (src == null)
        return Movie.UNKNOWN;

    int beginIndex = src.indexOf(findStr, fromIndex);
    if (beginIndex == -1)
        return Movie.UNKNOWN;

    StringTokenizer st = new StringTokenizer(src.substring(beginIndex + findStr.length()), "<");
    int i = 0;
    while (st.hasMoreElements()) {
        String elem = st.nextToken().replaceAll("&nbsp;|&#160;", "").trim();
        if (elem.length() != 0 && !elem.endsWith(">") && i++ >= skip) {
            String[] elems = elem.split(">");
            if (elems.length > 1) {
                return HTMLTools.decodeHtml(elems[1].trim());
            }
            return HTMLTools.decodeHtml(elems[0].trim());
        }
    }
    return Movie.UNKNOWN;
}

From source file:org.commoncrawl.util.HttpHeaderInfoExtractor.java

static void populateCacheControlFlags(NIOHttpHeaders headers, CrawlURLMetadata metadataInOut)
        throws IOException {
    Iterator<String> i = headers.multiValueIterator("cache-control");
    while (i.hasNext()) {
        String ccValue = i.next();

        StringTokenizer tokenizer = new StringTokenizer(ccValue, ",");

        while (tokenizer.hasMoreElements()) {

            String value = tokenizer.nextToken();

            if (value.equals("no-cache")) {
                metadataInOut.setCacheControlFlags((byte) (metadataInOut.getCacheControlFlags()
                        | CrawlURLMetadata.CacheControlFlags.NO_CACHE));
            } else if (value.equals("no-store")) {
                metadataInOut.setCacheControlFlags((byte) (metadataInOut.getCacheControlFlags()
                        | CrawlURLMetadata.CacheControlFlags.NO_STORE));
            } else if (value.equals("must-revalidate")) {
                metadataInOut.setCacheControlFlags((byte) (metadataInOut.getCacheControlFlags()
                        | CrawlURLMetadata.CacheControlFlags.NO_STORE));
            } else if (value.equals("private")) {
                metadataInOut.setCacheControlFlags((byte) (metadataInOut.getCacheControlFlags()
                        | CrawlURLMetadata.CacheControlFlags.PRIVATE));
            }/*ww  w . j a va  2s.  c o  m*/

            else {
                if (value.length() > kMaxAgePrefix.length()) {
                    String valueLowerCase = value.toLowerCase();
                    if (valueLowerCase.startsWith(kMaxAgePrefix)) {
                        try {
                            long maxAgeInSeconds = Long.parseLong(value.substring(kMaxAgePrefix.length()));
                            metadataInOut.setMaxAge(maxAgeInSeconds);
                        } catch (NumberFormatException e) {

                        }
                    }
                }
            }
        }
    }
    Iterator<String> j = headers.multiValueIterator("pragma");
    while (j.hasNext()) {
        String value = j.next();
        if (value.equals("no-cache")) {
            metadataInOut.setCacheControlFlags((byte) (metadataInOut.getCacheControlFlags()
                    | CrawlURLMetadata.CacheControlFlags.NO_CACHE));
        }
    }

    String varyValue = headers.findValue("vary");
    if (varyValue != null && varyValue.equals("*")) {
        metadataInOut.setCacheControlFlags(
                (byte) (metadataInOut.getCacheControlFlags() | CrawlURLMetadata.CacheControlFlags.VARY));
    }
}

From source file:org.infoglue.deliver.portal.PathParser.java

private static String decodeValues(StringTokenizer tok, List buffer) {
    if (tok.hasMoreTokens()) {
        String entry = tok.nextToken();
        if (entry.startsWith(MULTI_VALUE)) {
            // Multi-value
            while (tok.hasMoreTokens() && entry.startsWith(MULTI_VALUE)) {
                buffer.add(entry.substring(MULTI_VALUE.length()));
                entry = tok.nextToken().replaceAll("%2F", "/");
            }/*from  w w w.ja  va  2  s.  co  m*/
            return entry;
        } else {
            // Single-value
            buffer.add(entry.replaceAll("%2F", "/"));
            return (tok.hasMoreElements() ? tok.nextToken() : null);
        }
    }
    return null;
}

From source file:com.amalto.workbench.editors.StoredProcedureMainPage.java

private static Set<String> getMessages(String msg) {
    StringTokenizer tokenizer = new StringTokenizer(msg, Messages.StoredProcedureMainPage_18);
    StringBuilder currentMessage = new StringBuilder();
    Set<String> messages = new HashSet<String>();

    int currentKeywordIndex = 0;

    while (tokenizer.hasMoreElements()) {
        String element = tokenizer.nextToken().trim();
        if (!element.matches(".*Exception:")) { //$NON-NLS-1$
            if (element.equals(KEYWORDS[currentKeywordIndex])) {
                currentKeywordIndex++;/*from   w  w w .  j a v a2s  . c  o m*/
                if (currentKeywordIndex == KEYWORDS.length - 1) {
                    String newMessage = currentMessage.toString();
                    messages.add(newMessage);
                    currentMessage = new StringBuilder();
                    currentKeywordIndex = 0;
                }
            } else {
                if (!element.equals("is:") && !element.equals("\n;")) { //$NON-NLS-1$ //$NON-NLS-2$
                    currentMessage.append(element.replace("\n;", "")).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                }
            }
        }
    }
    String newMessage = currentMessage.toString();
    messages.add(newMessage);

    return messages;
}

From source file:org.libreplan.business.common.LibrePlanClassValidator.java

/**
 * Retrieve the property by path in a recursive way, including IndetifierProperty in the loop
 * If propertyName is null or empty, the IdentifierProperty is returned
 *///from  w w w  . j av  a  2 s .  co m
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
    Property property = null;
    Property idProperty = associatedClass.getIdentifierProperty();
    String idName = idProperty != null ? idProperty.getName() : null;
    try {
        if (propertyName == null || propertyName.length() == 0 || propertyName.equals(idName)) {
            //default to id
            property = idProperty;
        } else {
            if (propertyName.indexOf(idName + ".") == 0) {
                property = idProperty;
                propertyName = propertyName.substring(idName.length() + 1);
            }
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        }
    } catch (MappingException e) {
        try {
            //if we do not find it try to check the identifier mapper
            if (associatedClass.getIdentifierMapper() == null)
                return null;
            StringTokenizer st = new StringTokenizer(propertyName, ".", false);
            while (st.hasMoreElements()) {
                String element = (String) st.nextElement();
                if (property == null) {
                    property = associatedClass.getIdentifierMapper().getProperty(element);
                } else {
                    if (!property.isComposite())
                        return null;
                    property = ((Component) property.getValue()).getProperty(element);
                }
            }
        } catch (MappingException ee) {
            return null;
        }
    }
    return property;
}

From source file:net.sf.jhylafax.fax.HylaFAXClientHelper.java

public final static Modem parseModemFmt(String response) {
    StringTokenizer st = new StringTokenizer(response, QUEUE_SEPARATOR);
    StringTokenizer jf = new StringTokenizer(MODEMFMT, QUEUE_SEPARATOR);
    Modem modem = new Modem();
    while (st.hasMoreElements() && jf.hasMoreElements()) {
        char c = jf.nextToken().charAt(1);
        String s = st.nextToken().trim();
        if (s.length() > 0) {
            try {
                switch (c) {
                case 'h':
                    modem.setHostname(s);
                    break;
                case 'l':
                    modem.setLocalIdentifier(s);
                    break;
                case 'm':
                    modem.setCanonicalName(s);
                    break;
                case 'n':
                    modem.setFaxNumber(s);
                    break;
                case 'r':
                    modem.setMaxPagesPerCall(Integer.parseInt(s));
                    break;
                case 's':
                    modem.setStatus(s);// w w  w. j  ava 2s  .  c  om
                    break;
                case 't': {
                    StringTokenizer t = new StringTokenizer(s, ":");
                    modem.setServerTracing(Integer.parseInt(t.nextToken()));
                    modem.setSessionTracing(Integer.parseInt(t.nextToken()));
                    break;
                }
                case 'v':
                    modem.setSpeakerVolume(getVolume(s.charAt(0)));
                    break;
                case 'z':
                    modem.setRunning("*".equals(s));
                    break;
                }
            } catch (NumberFormatException e) {
                logger.info("Error parsing respone", e);
            } catch (NoSuchElementException e) {
                logger.info("Error parsing response", e);
            }
        }
    }
    return modem;
}

From source file:com.ZLHW.util.StringUtils.java

/**
 * /*from   w w w.ja  va  2 s .  c o  m*/
 * @param tags
 * @return
 */
public static List stringToList(String tags) {
    if (tags == null)
        return null;
    ArrayList<String> tagList = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(tags);
    while (st.hasMoreElements()) {
        tagList.add(st.nextToken());
    }
    return tagList;
}

From source file:com.ZLHW.util.StringUtils.java

/**
 * ch/*  w  w  w  . jav  a  2  s  .  c  o  m*/
 * @param tags
 * @param ch
 * @return
 */
public static List stringToList(String tags, String ch) {
    if (tags == null)
        return null;
    ArrayList<String> tagList = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(tags, ch);
    while (st.hasMoreElements()) {
        tagList.add(st.nextToken());
    }
    return tagList;
}