Example usage for java.util StringTokenizer countTokens

List of usage examples for java.util StringTokenizer countTokens

Introduction

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

Prototype

public int countTokens() 

Source Link

Document

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Usage

From source file:com.funambol.email.admin.EmailSyncSourceConfigPanel.java

/**
 * Set syncSource properties with the//  ww  w. j a  va 2 s. c  om
 * values provided by the user.
 */
public void getValues() {

    EmailSyncSource syncSource = (EmailSyncSource) getSyncSource();

    syncSource.setSourceURI(sourceUriValue.getText().trim());

    syncSource.setName(nameValue.getText().trim());

    syncSource.setContentProviderURL(contentProviderURLValue.getText().trim());

    syncSource.setFunambolSignature(signatureValue.getText().trim());

    boolean dtencr = dtEncryptValue.isSelected();
    String transformationsRequired = null;
    if (dtencr) {
        transformationsRequired = "des;b64";
    } else {
        transformationsRequired = null;
    }
    SyncSourceManagementObject mo = (SyncSourceManagementObject) getManagementObject();
    mo.setTransformationsRequired(transformationsRequired);

    StringTokenizer types = new StringTokenizer(infoTypesValue.getText(), ",");
    StringTokenizer versions = new StringTokenizer(infoVersionsValue.getText(), ",");

    ContentType[] contentTypes = new ContentType[types.countTokens()];

    for (int i = 0; i < contentTypes.length; ++i) {
        contentTypes[i] = new ContentType(types.nextToken().trim(), versions.nextToken().trim());
    }

    SyncSourceInfo info = new SyncSourceInfo(contentTypes, 0);

    info.setSupportHierarchicalSync(true);

    syncSource.setInfo(info);

}

From source file:com.izforge.izpack.event.RegistryInstallerListener.java

private byte[] extractBytes(IXMLElement element, String byteString) throws InstallerException {
    StringTokenizer st = new StringTokenizer(byteString, ",");
    byte[] retval = new byte[st.countTokens()];
    int i = 0;/*from  w w  w . ja va  2s .  com*/
    while (st.hasMoreTokens()) {
        byte value = 0;
        String token = st.nextToken().trim();
        try {
            // Unfortunately byte is signed ...
            int tval = Integer.parseInt(token, 16);
            if (tval < 0 || tval > 0xff) {
                throw new InstallerException("Byte value out of range: " + tval);
            }
            if (tval > 0x7f) {
                tval -= 0x100;
            }
            value = (byte) tval;
        } catch (NumberFormatException nfe) {
            spec.parseError(element, "Bad entry for REG_BINARY; a byte should be written as 2 digit hexvalue"
                    + "followed by a ','.");
        }
        retval[i++] = value;
    }
    return (retval);

}

From source file:edu.stanford.muse.index.IndexUtils.java

static String capTo2Tokens(String s) {
    StringTokenizer st = new StringTokenizer(s);
    int nTokens = st.countTokens();
    if (nTokens <= 2)
        return s;
    else/*from  www  .  j a  v a 2  s. co  m*/
        return st.nextToken() + " " + st.nextToken();
}

From source file:com.funambol.admin.module.panels.DefaultSyncSourceConfigPanel.java

/**
 * Sets the SyncSource's properties with the values provided by the user.
 *///from   w ww .  j av a2 s. co  m
private void getValues() throws AdminException {

    SyncSource syncSource = getSyncSource();

    Class c = syncSource.getClass();
    Method setSourceURI = null, setName = null, setInfo = null;
    try {

        setSourceURI = c.getMethod("setSourceURI", new Class[] { String.class });
        setName = c.getMethod("setName", new Class[] { String.class });
        setInfo = c.getMethod("setInfo", new Class[] { SyncSourceInfo.class });

    } catch (NoSuchMethodException e) {
        throw new AdminException(e.getMessage(), e);
    }

    try {
        setSourceURI.invoke(syncSource, new Object[] { sourceUriValue.getText().trim() });
        setName.invoke(syncSource, new Object[] { nameValue.getText().trim() });

        StringTokenizer types = new StringTokenizer(infoTypesValue.getText(), ",");
        StringTokenizer versions = new StringTokenizer(infoVersionsValue.getText(), ",");
        ContentType[] contentTypes = new ContentType[types.countTokens()];

        for (int i = 0; i < contentTypes.length; ++i) {
            contentTypes[i] = new ContentType(types.nextToken().trim(), versions.nextToken().trim());
        }

        setInfo.invoke(syncSource, new Object[] { new SyncSourceInfo(contentTypes, 0) });

        String transformationsRequired = null;
        if (encryption.isSelected()) {
            transformationsRequired = "des;b64";
        } else if (encoding.isSelected()) {
            transformationsRequired = "b64";
        }

        SyncSourceManagementObject mo = (SyncSourceManagementObject) getManagementObject();
        mo.setTransformationsRequired(transformationsRequired);
    } catch (IllegalAccessException e) {
        notifyError(new AdminException(e.getMessage(), e));
    } catch (InvocationTargetException e) {
        notifyError(new AdminException(e.getMessage(), e));
    }
}

From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat_Raw.java

/**
 * //from  w  w w.j a va2s  . c  o  m
 * @param in
 * @return
 */
protected Double[] createValueList(String in) {
    vs = in;
    //  String[] values = in.split("( *)+,+( *)");
    //int count = java.lang.reflect.Array.getLength(values);

    StringTokenizer st = new StringTokenizer(in, DELIMITERS);
    int count = st.countTokens();
    String[] values = new String[count];
    for (int i = 0; i < count; i++)
        values[i] = st.nextToken();

    Double[] result = new Double[count];

    for (int i = 0; i < count; i++) {
        // System.out.println(" SuperCat_stat_Raw: vlaues["+i+"]=*"+values[i]+"*");
        if (values[i] != null) {
            try {
                double v = Double.parseDouble(values[i]);
                result[i] = new Double(v);
            } catch (NumberFormatException e) {
                result[i] = Double.NaN;
            }

        } else
            result[i] = Double.NaN;

    }

    return result;
}

From source file:nl.nn.adapterframework.extensions.rekenbox.Adios2XmlPipe.java

protected void initializeConversionTables() throws ConfigurationException {
    // lees de template file en store het in een hashtable
    if (StringUtils.isNotEmpty(getAdiosDefinities())) {

        rubriek2nummer = new Hashtable(3000);
        record2nummer = new Hashtable(1000);
        nummer2rubriek = new Hashtable(3000);
        nummer2record = new Hashtable(1000);

        try {//from   w  w  w  .  j a v a2 s .  c  om
            handler = new Xml2AdiosHandler();
            SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
            saxParser = parserFactory.newSAXParser();
        } catch (Throwable e) {
            throw new ConfigurationException(getLogPrefix(null) + "cannot configure a parser", e);
        }

        try {
            URL url = ClassUtils.getResourceURL(classLoader, getAdiosDefinities());
            if (url == null) {
                throw new ConfigurationException(getLogPrefix(null)
                        + "cannot find adios definitions from resource [" + getAdiosDefinities() + "]");
            }
            BufferedReader bufinput = new BufferedReader(new InputStreamReader(url.openStream()));
            String line, labelnr, waarde;

            line = bufinput.readLine();

            labelnr = "";
            waarde = "";

            // read in the rubrieken
            while (line != null && !waarde.equals(recordIdentifier)) {
                StringTokenizer st = new StringTokenizer(line, "{};= \n");
                if (st.countTokens() >= 1) {
                    waarde = st.nextToken();
                    if (!waarde.equals(recordIdentifier)) {
                        waarde = waarde.substring(3);
                    }
                    if (st.hasMoreTokens()) {
                        labelnr = st.nextToken();
                        //System.out.println("Rubriek label: " + labelnr + "   \t" + waarde);
                        if (alldigits(labelnr)) {
                            //System.out.println("rubriek label: " + labelnr + "   \t" + waarde);

                            // als de key al bestaat betekend dit dat er een fout zit in de invoer
                            if (nummer2rubriek.containsKey(labelnr)) {
                                throw new ConfigurationException(getLogPrefix(null) + "rubriek [" + labelnr
                                        + "] komt meermaals voor. Waarde1: [" + nummer2rubriek.get(labelnr)
                                        + "], Waarde2: [" + waarde + "]");
                            }
                            nummer2rubriek.put(labelnr, waarde);
                            rubriek2nummer.put(waarde, labelnr);
                        }
                    }

                }
                line = bufinput.readLine();
            }

            // Read in the records
            while (line != null) {
                StringTokenizer st1 = new StringTokenizer(line, "{};= \n");
                if (st1.countTokens() >= 1) {
                    waarde = st1.nextToken();
                    waarde = waarde.substring(3);
                    if (st1.hasMoreTokens()) {
                        labelnr = st1.nextToken();
                        //System.out.println("Record label: " + labelnr + "   \t" + waarde);
                        if (alldigits(labelnr)) {
                            //labeln = Integer.parseInt(labelnr);
                            //System.out.println("record label: " + labelnr + "   \t" + waarde);

                            if (nummer2record.containsKey(labelnr)) {
                                throw new ConfigurationException(getLogPrefix(null) + "record [" + labelnr
                                        + "] komt meermaals voor. Waarde1: [" + nummer2record.get(labelnr)
                                        + "], Waarde2: [" + waarde + "]");
                            }
                            nummer2record.put(labelnr, waarde);
                            record2nummer.put(waarde, labelnr);
                        }
                    }

                }

                line = bufinput.readLine();
            }
            bufinput.close();
        } catch (IOException e) {
            throw new ConfigurationException(
                    getLogPrefix(null) + "IOException on [" + getAdiosDefinities() + "]", e);
        }
    }
}

From source file:org.alfresco.filesys.auth.PassthruServerFactory.java

/**
 * Set the protocol order for passthru connections
 * /* ww  w .j a va 2 s  .  co  m*/
 * @param protoOrder
 *            a comma-delimited list containing one or more of "NetBIOS" and "TCPIP" in any order
 */
public void setProtocolOrder(String protoOrder) {
    // Parse the protocol order list

    StringTokenizer tokens = new StringTokenizer(protoOrder, ",");
    int primaryProto = Protocol.None;
    int secondaryProto = Protocol.None;

    // There should only be one or two tokens

    if (tokens.countTokens() > 2)
        throw new AlfrescoRuntimeException("Invalid protocol order list, " + protoOrder);

    // Get the primary protocol

    if (tokens.hasMoreTokens()) {
        // Parse the primary protocol

        String primaryStr = tokens.nextToken();

        if (primaryStr.equalsIgnoreCase("TCPIP"))
            primaryProto = Protocol.NativeSMB;
        else if (primaryStr.equalsIgnoreCase("NetBIOS"))
            primaryProto = Protocol.TCPNetBIOS;
        else
            throw new AlfrescoRuntimeException("Invalid protocol type, " + primaryStr);

        // Check if there is a secondary protocol, and validate

        if (tokens.hasMoreTokens()) {
            // Parse the secondary protocol

            String secondaryStr = tokens.nextToken();

            if (secondaryStr.equalsIgnoreCase("TCPIP") && primaryProto != Protocol.NativeSMB)
                secondaryProto = Protocol.NativeSMB;
            else if (secondaryStr.equalsIgnoreCase("NetBIOS") && primaryProto != Protocol.TCPNetBIOS)
                secondaryProto = Protocol.TCPNetBIOS;
            else
                throw new AlfrescoRuntimeException("Invalid secondary protocol, " + secondaryStr);
        }
    }

    // Set the protocol order used for passthru authentication sessions

    AuthSessionFactory.setProtocolOrder(primaryProto, secondaryProto);

    // DEBUG

    if (logger.isDebugEnabled())
        logger.debug("Protocol order primary=" + Protocol.asString(primaryProto) + ", secondary="
                + Protocol.asString(secondaryProto));
}

From source file:net.unicon.demetrius.fac.AbstractResourceFactory.java

public IResource getResource(String relativePath) throws DemetriusException {
    if (relativePath == null) {
        String msg = "Argument 'relativePath' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from  ww  w .  j a v  a 2s . com*/

    if (relativePath.equals(DELIMITER) || relativePath.trim().equals("")) {
        return this.getRoot();
    }
    StringTokenizer tokenizer = new StringTokenizer(relativePath, DELIMITER);
    String[] path = new String[tokenizer.countTokens()];
    int j = 0;
    while (tokenizer.hasMoreTokens()) {
        path[j] = tokenizer.nextToken();
        j++;
    }

    return getResource(path, this.getRoot());
}

From source file:br.com.anteros.android.synchronism.communication.HttpConnectionClient.java

private List<String[]> formatData(String dadosRetorno) {
    List<String[]> result = new ArrayList<String[]>();
    int i = 0;//from   w  ww.j av a 2s .  c  o  m
    String[] fieldsToReturn;
    StringTokenizer fields;
    for (StringTokenizer records = new StringTokenizer(dadosRetorno, "|"); records.hasMoreTokens(); result
            .add(fieldsToReturn)) {
        fields = new StringTokenizer(records.nextToken(), "$");
        fieldsToReturn = new String[fields.countTokens()];
        for (i = 0; fields.hasMoreTokens(); i++) {
            fieldsToReturn[i] = fields.nextToken();
            if (fieldsToReturn[i].equals("_"))
                fieldsToReturn[i] = "";
        }
    }
    fields = null;
    fieldsToReturn = null;

    return result;
}

From source file:henplus.commands.ConnectCommand.java

public ConnectCommand(final HenPlus henplus, final SessionManager sessionManager) {
    _henplus = henplus;//w  ww .ja  va 2s  .c om
    _sessionManager = sessionManager;
    _knownUrls = new TreeMap<String, String>();
    _config = henplus.createConfigurationContainer(CONNECTION_CONFIG);
    _config.read(new ConfigurationContainer.ReadAction() {

        @Override
        public void readConfiguration(final InputStream inStream) throws Exception {
            if (inStream == null) {
                return;
            }
            final BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
            String urlLine;
            while ((urlLine = in.readLine()) != null) {
                final StringTokenizer tok = new StringTokenizer(urlLine);
                String url;
                String alias;
                final int tokNum = tok.countTokens();
                if (tokNum == 1) {
                    url = tok.nextToken();
                    alias = url;
                } else if (tokNum == 2) {
                    url = tok.nextToken();
                    alias = tok.nextToken();
                } else {
                    continue;
                }
                _knownUrls.put(alias, url);
            }
        }
    });
}