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.squale.welcom.taglib.button.ButtonTag.java

/**
 * retourne vrai si par defaut on a les acces read/write
 * /*w  ww  .java  2 s  .c  o  m*/
 * @param buttonName le nom du bouton
 * @return vrai si on force read/write
 */
public boolean checkIfInDefaultForceReadWrite(final String buttonName) {
    final String bouttonForceReadWrite = WelcomConfigurator
            .getMessageWithCfgChartePrefix(".bouton.default.forceReadWrite");
    final StringTokenizer st = new java.util.StringTokenizer(bouttonForceReadWrite, ";", false);

    while (st.hasMoreElements()) {
        final String elements = (String) st.nextElement();

        if (Util.isEquals(elements.toLowerCase(), buttonName.toLowerCase())) {
            return true;
        }
    }

    return false;
}

From source file:org.squale.welcom.taglib.button.ButtonTag.java

/**
 * retourne vrai si par defaut on cause la validation
 * //from   ww w  .ja  va  2 s  . c  o m
 * @param buttonName le nom du bouton
 * @return vrai si validation
 */
public boolean checkIfInDefaultCausesValidation(final String buttonName) {
    final String bouttonCausesValidation = WelcomConfigurator
            .getMessageWithCfgChartePrefix(".bouton.default.causesValidation");
    final StringTokenizer st = new java.util.StringTokenizer(bouttonCausesValidation, ";", false);

    while (st.hasMoreElements()) {
        final String elements = (String) st.nextElement();

        if (Util.isEquals(elements.toLowerCase(), buttonName.toLowerCase())) {
            return true;
        }
    }

    return false;
}

From source file:org.alfresco.po.share.GroupsPage.java

/**
 * Get list of group members for any group in groups page
 * // ww w  . j av a  2s  .co  m
 * @return List of Users
 */
public List<UserProfile> getMembersList() {
    try {
        List<UserProfile> listOfUsers = new ArrayList<UserProfile>();
        List<WebElement> groupMembers = findAndWaitForElements(By.cssSelector(USER_NAMES));
        for (WebElement webElement : groupMembers) {
            UserProfile profile = new UserProfile();
            String text = webElement.getText();
            StringTokenizer userInfo = new StringTokenizer(text);

            int userDispalySize = 0;
            int userInfoSize = userInfo.countTokens();

            while (userInfo.hasMoreElements()) {

                if (userDispalySize == 0) {
                    profile.setfName((String) userInfo.nextElement());
                } else if (userDispalySize == 1 && userInfoSize > 2) {
                    profile.setlName((String) userInfo.nextElement());
                } else if (userDispalySize == 2 || (userDispalySize == 1 && userInfoSize == 2)) {
                    profile.setUsername((String) userInfo.nextElement());
                }
                userDispalySize++;
            }
            listOfUsers.add(profile);
        }
        return listOfUsers;

    } catch (TimeoutException e) {
        logger.error("Unable to get the list of members : ", e);
    }

    throw new PageOperationException("Unable to get the list of members  : ");
}

From source file:com.serena.rlc.provider.servicenow.ServiceNowBaseServiceProvider.java

private FieldInfo createSelectionList(String fieldName, String selectionValues) {
    logger.debug("Creating selection list from: {} - {}", fieldName, selectionValues);
    StringTokenizer st = new StringTokenizer(selectionValues, ",;");
    FieldInfo fieldInfo = new FieldInfo(fieldName);
    List<FieldValueInfo> values = new ArrayList<>();
    FieldValueInfo value;/* w ww. j  ava2  s.c o m*/
    String status;
    while (st.hasMoreElements()) {
        status = (String) st.nextElement();
        status = status.trim();
        value = new FieldValueInfo(status, status);
        values.add(value);
    }

    fieldInfo.setValues(values);
    return fieldInfo;
}

From source file:com.ibm.dbwkl.request.internal.LoggingHandler.java

@Override
public STAFResult execute() {
    StringBuilder resultString = new StringBuilder();

    // user for db logger
    String logdbuser = getRequestOption(Options.DB_USER);

    // password for db logger
    String logdbpassword = getRequestOption(Options.DB_PASSWORD);

    // URL for db logger
    String logdburl = getRequestOption(Options.DB_URL);

    if (hasRequestOption(Options.LOG_LOGTEST)) {
        for (int i = 0; i <= 25; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                //ignore
            }/* w w w.j a  v a 2  s  . co m*/
            Logger.log("LOGTEST:" + i, LogLevel.Debug);
        }
        return new STAFResult(STAFResult.Ok, "Logtest at Loglevel Debug executed!");
    }

    /*
     * everything went fine, thus do the changes and hope that all values are allowed
     */

    // level
    if (hasRequestOption(Options.LOG_LEVEL)) {
        String level = getRequestOption(Options.LOG_LEVEL);
        try {
            Logger.logLevel = LogLevel.getLevel(level);
            resultString.append("Log Level set to " + level + "\n");
        } catch (Exception e) {
            return new STAFResult(STAFResult.InvalidValue, "The value '" + level
                    + "' is not allowed as log level. Use one of the following instead: Debug Info Warning Error");
        }
    }

    // details
    if (hasRequestOption(Options.LOG_DETAILS)) {
        String details = getRequestOption(Options.LOG_DETAILS);
        try {
            Logger.details = new Boolean(details).booleanValue();
            resultString.append("Log Details now " + (Logger.details == true ? "ON" : "OFF") + "\n");
        } catch (Exception e) {
            return new STAFResult(STAFResult.InvalidValue, "The value '" + details
                    + "' is not allowed as detailed logging settings. Use either true or false as value.");
        }
    }

    // Cleaning the logger
    if (hasRequestOption(Options.LOG_CLEAN)) {
        String clean = getRequestOption(Options.LOG_CLEAN).trim();

        try {
            ILoggerService logger = getLoggerByName(clean);
            if (logger == null)
                return new STAFResult(STAFResult.DoesNotExist, "Logger could not be found!");

            logger.term();
            logger.clean();
            Logger.registeredLoggers.remove(logger);

            logger = logger.getClass().newInstance();
            Logger.addLogger(logger);

            resultString.append("Logger " + clean + " has been cleaned!");

        } catch (Exception e) {
            return new STAFResult(STAFResult.InvalidValue, "The logger '" + clean
                    + "' is unknown. Use one of the following: htmllogger filelogger dblogger sysout livelog livelogreceiver");
        }
    }

    // remove logger
    else if (hasRequestOption(Options.LOG_REMOVE)) {
        String remove = getRequestOption(Options.LOG_REMOVE).trim();

        try {
            if (remove.equalsIgnoreCase("LIVELOG")) {
                LiveLogger.getInstance().term();
                Logger.registeredLoggers.remove(LiveLogger.getInstance());
                resultString.append("Logger " + remove + " has been removed \n");
            } else {
                ILoggerService logger = getLoggerByName(remove);

                if (logger == null)
                    return new STAFResult(STAFResult.DoesNotExist, "Logger could not be found!");

                logger.term();
                Logger.registeredLoggers.remove(logger);

                resultString.append("Logger has been removed!");
            }

        } catch (Exception e) {
            return new STAFResult(STAFResult.InvalidValue,
                    "The logger '" + remove + "' to be removed is unknown.");
        }
    }

    // add logger
    else if (hasRequestOption(Options.LOG_ADD)) {
        String add = getRequestOption(Options.LOG_ADD);

        if (add.equalsIgnoreCase("FILELOGGER"))
            try {
                Logger.addLogger(new TextLogger());
            } catch (IOException e1) {
                return new STAFResult(STAFResult.JavaError, "Exception occurs while adding a FileLogger.");
            }
        else if (add.equalsIgnoreCase("DBLOGGER")) {
            try {
                Logger.addLogger(new DatabaseLogger(logdbuser, logdbpassword, logdburl));
            } catch (IOException e) {
                return new STAFResult(STAFResult.JavaError,
                        "Exception occurs while adding a DBLogger: " + e.getMessage());
            } catch (InterruptedException e) {
                //
            }
        }

        else if (add.equalsIgnoreCase("HTMLLOGGER"))
            try {
                Logger.addLogger(new HTMLLogger());
            } catch (IOException e) {
                return new STAFResult(STAFResult.JavaError, "Exception occurs while adding a HTMLLogger.");
            }
        else if (add.equalsIgnoreCase("LIVELOG")) {
            if (hasRequestOption(Options.SOCKET_HOST)) {
                if (getRequestOption(Options.SOCKET_HOST).length() != 0) {
                    LiveLogger liveLogger = LiveLogger.getInstance();
                    if (!Logger.getCopyOfLoggers().contains(liveLogger))
                        Logger.addLogger(liveLogger);
                    liveLogger.openServer(getRequestOption(Options.SOCKET_HOST).trim());
                    return new STAFResult(STAFResult.Ok,
                            "LiveLogger added, it will now accept a live logging connection!");
                }
            }
            Logger.log("Adding LiveLog not possible: Invalid Host", LogLevel.Error);
            return new STAFResult(STAFResult.JavaError, "Adding LiveLog not possible: Invalid Host");
        }

        else {
            Logger.log("Adding Logger failed: no such logger to add found: " + add, LogLevel.Error);
            return new STAFResult(STAFResult.JavaError,
                    "Adding Logger failed: no such logger to add found: " + add);
        }
        resultString.append("Logger " + add + " has been added \n");
    }

    else if (hasRequestOption(Options.LOG_SCHEMA)) {
        String xsd = null;
        try {
            xsd = XMLSerializer.createXMLSchema(LoggerEntry.class);
        } catch (IOException e) {
            Logger.log(e.getMessage(), LogLevel.Error);
            return new STAFResult(STAFResult.JavaError, e.getMessage());
        } catch (JAXBException e) {
            Logger.log(e.getMessage(), LogLevel.Error);
            return new STAFResult(STAFResult.JavaError, e.getMessage());
        }

        if (xsd != null)
            return new STAFResult(STAFResult.Ok, xsd);

        return new STAFResult(STAFResult.JavaError, "Error while creating the Schema");
    }

    // LIST shows logs on the console
    // schema:
    //      LIST <what> [FILTER <filter>] [COLUMNS <columns>]
    //          <what> = { , n} (empty=all, n=last n)
    //          <filter> = {LEVEL={DEBUG, INFO, WARNING, ERROR}*;REQID=<reqid>}
    //          <columns> = {REQUEST, THREAD, LOGLEVEL, MESSAGE}
    else if (hasRequestOption(Options.LOG_LIST)) {
        //read <what>
        String listValue = getRequestOption(Options.LOG_LIST);
        //the number of latest entries to retrieve
        int n = 0;
        if (listValue.equalsIgnoreCase("")) {
            //when n<=0, all entries are retrieved
            n = 0;
        } else {
            try {
                n = Integer.parseInt(listValue);
            } catch (NumberFormatException e) {
                return new STAFResult(STAFResult.InvalidValue,
                        "List option needs to be a positive number or empty");
            }
            if (n <= 0) {
                return new STAFResult(STAFResult.InvalidValue,
                        "List option needs to be a positive number or empty");
            }
        }

        //read <filter>
        String levels[] = null;
        int reqid = 0;
        if (hasRequestOption(Options.LOG_LIST_FILTER)) {
            String filter = getRequestOption(Options.LOG_LIST_FILTER).toLowerCase();
            StringTokenizer tokenizer = new StringTokenizer(filter, ";");
            while (tokenizer.hasMoreElements()) {
                String option = (String) tokenizer.nextElement();
                // an option is of the form key=value
                if (option.contains("=")) {
                    String key = option.substring(0, option.indexOf("="));
                    //read LEVEL={DEBUG,INFO,WARNING,ERROR}*
                    if (key.equalsIgnoreCase("level")) {
                        levels = option.substring(option.indexOf("=") + 1).split(",");
                        //Check if the given levels are supported.
                        if (!StringUtility.arrayContainsOnlyIgnoreCase(levels, LogLevel.Debug.toString().trim(),
                                LogLevel.Warning.toString().trim(), LogLevel.Error.toString().trim(),
                                LogLevel.Info.toString().trim())) {
                            return new STAFResult(STAFResult.InvalidValue,
                                    "Supporting only Log Levels: " + LogLevel.Debug.toString().trim() + ","
                                            + LogLevel.Warning.toString().trim() + ","
                                            + LogLevel.Error.toString().trim() + ","
                                            + LogLevel.Info.toString().trim());
                        }
                        //read REQID=<reqid>      
                    } else if (key.equals("reqid")) {
                        try {
                            reqid = Integer.parseInt(option.substring(option.indexOf("=") + 1));
                        } catch (NumberFormatException e) {
                            return new STAFResult(STAFResult.InvalidValue,
                                    "REQID needs to be a positive number.");
                        }
                        if (reqid <= 0) {
                            return new STAFResult(STAFResult.InvalidValue,
                                    "REQID needs to be a positive number.");
                        }
                    } else {
                        //option is not level= or reqid=
                        return new STAFResult(STAFResult.InvalidValue,
                                "Invalid option in the filter: " + option);
                    }
                } else {
                    //option doesn't have '='
                    return new STAFResult(STAFResult.InvalidValue,
                            "Invalid requestOptions in the filter: " + option);
                }
            }
        }

        //read <columns>
        String[] cols = null;
        if (hasRequestOption(Options.LOG_LIST_COL)) {
            cols = getRequestOption(Options.LOG_LIST_COL).toLowerCase().split(",");
            if (!StringUtility.arrayContainsOnlyIgnoreCase(cols, "request", "thread", "level", "message"))
                return new STAFResult(STAFResult.InvalidValue,
                        "Supporting only Columns: Request, Thread, Level, Message.");
        }

        // filter the entries accordingly
        List<LoggerEntry> logEntries = null;

        if (levels == null || levels.length == 0) {
            if (reqid == 0) {
                logEntries = Logger.getLogEntries(n);
            } else {
                logEntries = Logger.getLogEntries(n, reqid);
            }
        } else {
            if (reqid == 0) {
                logEntries = Logger.getLogEntries(n, levels);
            } else {
                logEntries = Logger.getLogEntries(n, levels, reqid);
            }
        }

        // print the lines, with selected columns.
        String ALLCOLUMNS[] = { "Request", "Thread", "Level", "Message" };
        String formats[] = { "%1$-8s", " %2$-12s", " %3$-7s", " %4$-100s" };

        //if no columns is set, display all columns
        if (cols == null || cols.length == 0) {
            cols = ALLCOLUMNS;
        }

        //check is one of the four columns exists, and construct the format string.
        boolean[] colExists = new boolean[ALLCOLUMNS.length];
        String format = "";

        for (int i = 0; i < ALLCOLUMNS.length; i++) {
            if (StringUtility.arrayContainsIgnoreCase(cols, ALLCOLUMNS[i])) {
                colExists[i] = true;
                format += formats[i];
            }
        }
        format += "\n";

        //print the table head
        resultString.append(String.format(format, colExists[0] ? "Request" : "", colExists[1] ? "Thread" : "",
                colExists[2] ? "Level" : "", colExists[3] ? "Message" : ""));

        resultString.append(String.format(format, colExists[0] ? "-------" : "", colExists[1] ? "------" : "",
                colExists[2] ? "-----" : "", colExists[3] ? "-------" : ""));

        //print the log entries
        for (LoggerEntry logEntry : logEntries) {

            if (colExists[3]) {
                //number of chars per row in the message column
                int charsPerRow = 100;
                //in case the message contains multiple lines.
                String msg = logEntry.getMessage();
                String[] lines = msg.split("\\n");
                for (int i = 0; i < lines.length; i++) {
                    //other columns should only appear once on the first row.
                    String formatedString = String.format(format,
                            (i == 0 && colExists[0]) ? logEntry.getRequestName() : "",
                            (i == 0 && colExists[1]) ? logEntry.getThread() : "",
                            (i == 0 && colExists[2]) ? logEntry.getLevel() : "",
                            StringUtils.left(lines[i], charsPerRow));
                    resultString.append(formatedString);

                    //if the line is longer than 'charsPerRow', split it into multiple rows
                    if (lines[i].length() > charsPerRow) {
                        //cut every 'charsPerRow' chars out, and put it in a new row.
                        String txt = "";
                        int j = 1;
                        while ((txt = StringUtils.mid(lines[i], charsPerRow * j, charsPerRow)).length() != 0) {
                            resultString.append(String.format(format, "", "", "", txt));
                            j++;
                        }
                    }
                }
            } else {
                String formatedString = String.format(format, colExists[0] ? logEntry.getRequestName() : "",
                        colExists[1] ? logEntry.getThread() : "", colExists[2] ? logEntry.getLevel() : "", "");
                resultString.append(formatedString);
            }
        }

    }

    return new STAFResult(STAFResult.Ok, resultString.toString());
}

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

/**
 * Add all files under this directory to play list.
 * @param fsFile//from  w w w.ja v a 2  s.com
 */
private void addDir(File fsFile) {
    // Put all music file extension in a Vector
    String ext = config.getExtensions();
    StringTokenizer st = new StringTokenizer(ext, ", ");
    if (exts == null) {
        exts = new Vector();
        while (st.hasMoreTokens()) {
            exts.add("." + st.nextElement());
        }
    }
    // recursive
    Thread addThread = new AddThread(fsFile);
    addThread.start();
    // Refresh thread
    Thread refresh = new Thread("Refresh") {
        public void run() {
            while (isSearching) {
                resetScrollBar();
                repaint();
                try {
                    Thread.sleep(4000);
                } catch (Exception ex) {
                }
            }
        }
    };
    refresh.start();
}

From source file:henplus.commands.ConnectCommand.java

/**
 * execute the command given./*from  w w  w .j a  v a  2 s  .  co  m*/
 */
@Override
public int execute(final SQLSession currentSession, final String cmd, final String param) {
    SQLSession session = null;

    final StringTokenizer st = new StringTokenizer(param);
    final int argc = st.countTokens();

    if ("sessions".equals(cmd)) {
        showSessions();
        return SUCCESS;
    }

    else if ("connect".equals(cmd)) {
        if (argc < 1 || argc > 4) {
            return SYNTAX_ERROR;
        }
        String url = (String) st.nextElement();
        String alias = (argc >= 2) ? st.nextToken() : null;
        String user = (argc >= 3) ? st.nextToken() : null;
        String password = (argc >= 4) ? st.nextToken() : null;
        if (alias == null) {
            /*
             * we only got one parameter. So the that single parameter might
             * have been an alias. let's see..
             */
            if (_knownUrls.containsKey(url)) {
                final String possibleAlias = url;
                url = _knownUrls.get(url);
                if (!possibleAlias.equals(url)) {
                    alias = possibleAlias;
                }
            }
        }
        try {
            session = new SQLSession(url, user, password);
            _knownUrls.put(url, url);
            if (alias != null) {
                _knownUrls.put(alias, url);
            }
            _currentSessionName = createSessionName(session, alias);
            _sessionManager.addSession(_currentSessionName, session);
            _sessionManager.setCurrentSession(session);
        } catch (final Exception e) {
            HenPlus.msg().println(e.toString());
            return EXEC_FAILED;
        }
    } else if ("switch".equals(cmd)) {
        String sessionName = null;
        if (argc != 1 && _sessionManager.getSessionCount() != 2) {
            return SYNTAX_ERROR;
        }
        if (argc == 0 && _sessionManager.getSessionCount() == 2) {
            final Iterator<String> it = _sessionManager.getSessionNames().iterator();
            while (it.hasNext()) {
                sessionName = it.next();
                if (!sessionName.equals(_currentSessionName)) {
                    break;
                }
            }
        } else {
            sessionName = (String) st.nextElement();
        }
        session = _sessionManager.getSessionByName(sessionName);
        if (session == null) {
            HenPlus.msg().println("'" + sessionName + "': no such session");
            return EXEC_FAILED;
        }
        _currentSessionName = sessionName;
    } else if ("rename-session".equals(cmd)) {
        String sessionName = null;
        if (argc != 1) {
            return SYNTAX_ERROR;
        }
        sessionName = (String) st.nextElement();
        if (sessionName.length() < 1) {
            return SYNTAX_ERROR;
        }

        /*
         * // moved to sessionmanager.renameSession
         * 
         * if (_sessionManager.sessionNameExists(sessionName)) {
         * HenPlus.err().println("A session with that name already exists");
         * return EXEC_FAILED; }
         * 
         * session =
         * _sessionManager.removeSessionWithName(currentSessionName); if
         * (session == null) { return EXEC_FAILED; }
         * _sessionManager.addSession(sessionName, session);
         */
        final int renamed = _sessionManager.renameSession(_currentSessionName, sessionName);
        if (renamed == EXEC_FAILED) {
            return EXEC_FAILED;
        }

        _currentSessionName = sessionName;
        session = _sessionManager.getCurrentSession();
    } else if ("disconnect".equals(cmd)) {
        _currentSessionName = null;
        if (argc != 0) {
            return SYNTAX_ERROR;
        }
        _sessionManager.closeCurrentSession();
        HenPlus.msg().println("session closed.");

        if (_sessionManager.hasSessions()) {
            _currentSessionName = _sessionManager.getFirstSessionName();
            session = _sessionManager.getSessionByName(_currentSessionName);
        }
    }

    if (_currentSessionName != null) {
        _henplus.setPrompt(_currentSessionName + "> ");
    } else {
        _henplus.setDefaultPrompt();
    }
    _henplus.setCurrentSession(session);

    return SUCCESS;
}

From source file:org.kchine.rpf.PoolUtils.java

public static URL[] getURLS(String urlsStr) {
    StringTokenizer st = new StringTokenizer(urlsStr, " ");
    Vector<URL> result = new Vector<URL>();
    while (st.hasMoreElements()) {
        try {/*from  w  w w  . j  av a  2s. c  o  m*/
            result.add(new URL((String) st.nextElement()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return (URL[]) result.toArray(new URL[0]);
}

From source file:org.kchine.rpf.PoolUtils.java

public static String getAbsoluteClassPath() {
    StringBuffer result = new StringBuffer();
    StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"),
            System.getProperty("path.separator"));
    while (st.hasMoreElements()) {
        String element = (String) st.nextElement();
        try {/*from  w w w.  ja v a 2 s.  co m*/
            result.append(new File(element).getAbsolutePath());
            if (st.hasMoreElements()) {
                result.append(System.getProperty("path.separator"));
            }
        } catch (Exception e) {
            result.append(element);
            if (st.hasMoreElements()) {
                result.append(System.getProperty("path.separator"));
            }
        }
    }
    return result.toString();
}

From source file:com.wabacus.system.assistant.ReportAssistant.java

public String formatCondition(String src, String token) {
    if (src == null || src.trim().length() < 2 || token == null || token.trim().equals("")) {
        return src;
    }//  w  w w. j a v  a 2 s  .  c  o  m
    src = src.trim();
    String dest = "";
    if (token.equals("2")) {
        dest = src.substring(0, 1);
        for (int i = 1; i < src.length() - 1; i++) {
            if (src.charAt(i) != ' ') {
                dest = dest + "%" + src.charAt(i);
            }
        }
        dest = dest + "%" + src.substring(src.length() - 1);
    } else {
        if (token.equals("1")) {
            token = " ";
        }

        while (src.indexOf(token) == 0) {
            src = src.substring(1);
            src = src.trim();
        }
        while (src.endsWith(token)) {
            src = src.substring(0, src.length() - 1);
            src = src.trim();
        }

        StringTokenizer st = new StringTokenizer(src, token);
        while (st.hasMoreElements()) {
            dest = dest + ((String) st.nextElement()).trim() + "%";
            //                System.out.println(dest);
        }
        if (dest.endsWith("%")) {
            dest = dest.substring(0, dest.length() - 1);
        }
    }
    log.debug("?" + src + "?splitlike???" + dest);
    return dest;
}