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:net.sf.excelutils.tags.SumTag.java

public int[] parseTag(Object context, Workbook wb, Sheet sheet, Row curRow, Cell curCell)
        throws ExcelException {
    String cellstr = curCell.getStringCellValue();
    if (null == cellstr || "".equals(cellstr)) {
        return new int[] { 0, 0, 0 };
    }//ww w  .ja  va  2s  .  c  o  m
    LOG.debug("SumTag:" + cellstr);
    String property = "";
    String collectionName = "";
    String whereName = "";
    String whereStr = "";
    boolean bEquals = true;
    String hasStr = cellstr.substring(0, cellstr.indexOf(getTagName()));
    cellstr = cellstr.substring(cellstr.indexOf(getTagName()), cellstr.length());
    cellstr = cellstr.replaceAll("=", " = ");
    StringTokenizer st = new StringTokenizer(cellstr, " ");
    int pos = 0;
    while (st.hasMoreTokens()) {
        String str = st.nextToken();
        if (pos == 1) {
            property = str;
        }
        if (pos == 3) {
            collectionName = str;
        }
        if (pos == 5) {
            whereName = str;
        }
        if (pos == 6) {
            bEquals = "=".equals(str.trim());
        }
        if (pos == 7) {
            whereStr = str;
        }
        pos++;
    }

    double sum = 0;
    if (!"".equals(collectionName) && !"".equals(property)) {
        Object collection = ExcelParser.parseStr(context, collectionName);
        if (null == collection) {
            return new int[] { 0, 0, 0 };
        }
        // get the iterator of collection
        Iterator iterator = ExcelParser.getIterator(collection);
        // iterator for sum
        while (iterator.hasNext()) {
            Object model = iterator.next();
            if (null != model) {
                Object value = ExcelParser.getValue(model, property);
                if (null != value) {
                    // filter when
                    if (!"".equals(whereName) && !"".equals(whereStr)) {
                        Object where = ExcelParser.getValue(model, whereName);
                        Object whereValue = null;
                        if (whereStr.startsWith(ExcelParser.VALUED_DELIM)) {
                            whereValue = ExcelParser.parseStr(context, whereStr);
                        }
                        if (null == whereValue)
                            whereValue = whereStr;

                        if (null != where) {
                            if (bEquals) {
                                if (!where.toString().equals(whereValue.toString())) {
                                    continue;
                                }
                            } else {
                                if (where.toString().indexOf(whereValue.toString()) < 0) {
                                    continue;
                                }
                            }
                        }
                    }

                    // sum the value
                    if ("java.lang.Integer".equals(value.getClass().getName())
                            || "java.lang.Double".equals(value.getClass().getName())) {
                        sum += Double.parseDouble(value.toString());
                    }
                }
            }
        }
    }
    if (!"".equals(hasStr)) {
        // curCell.setEncoding(Workbook.ENCODING_UTF_16);
        curCell.setCellValue(hasStr + sum);
    } else {
        curCell.setCellValue(sum);
    }
    return new int[] { 0, 0, 0 };
}

From source file:com.sec.ose.osi.UIMain.java

private static double getJavaVersion() {

    Properties prop = System.getProperties();
    String java_specification_version = prop.getProperty("java.specification.version");

    StringTokenizer st = new StringTokenizer(java_specification_version, ".");

    String major = st.nextToken();
    String minor = st.nextToken();

    try {/*w  w w  .  j a  v  a2  s. c o  m*/

        double version = Double.parseDouble(major + "." + minor);
        return version;

    } catch (NumberFormatException e) {
        log.warn(e);
        return 0;
    }
}

From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java

/**
 * /*from  w ww. java 2 s .  co  m*/
 * @return
 */
public static String getWindowsMacAddress() {
    final String ipConfigResponse = executeCommand("ipconfig", "/all");
    if (ipConfigResponse == null) {
        return null;
    }

    String localHost = getLocalhostAddress();
    if (localHost == null) {
        return null;
    }

    String lastMacAddressCandidate = null;
    StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n");
    while (tokenizer.hasMoreTokens()) {
        String line = tokenizer.nextToken().trim();

        if ((line.indexOf(localHost) >= 0) && (lastMacAddressCandidate != null)) {
            return lastMacAddressCandidate;
        }

        int colon = line.indexOf(":");
        if (colon <= 0) {
            continue;
        }
        String candidate = line.substring(colon + 1).trim();
        if (isMacAddressCandidate(candidate)) {
            lastMacAddressCandidate = normalizeMacAddress(candidate);
        }
    }
    return lastMacAddressCandidate;
}

From source file:com.silverpeas.tags.navigation.links.LinkGeneratorImpl.java

/**
 * Construction de l'url de l'item./*from   w ww  .j a v  a  2 s  .  com*/
 * @param pageContext
 * @param themetracker
 * @param node
 * @param idsTopicsRoots
 * @param pub
 * @param prefixId
 * @return
 * @throws RemoteException
 */
public String generateFullSemanticPath(PageContext pageContext, KmeliaTagUtil themetracker, NodeDetail node,
        String idsTopicsRoots, PublicationDetail pub, String prefixId) throws RemoteException {
    StringBuffer path = new StringBuffer();
    path.append(((HttpServletRequest) pageContext.getRequest()).getContextPath());
    path.append("/");
    StringTokenizer nodes = new StringTokenizer(node.getPath(), "/");
    boolean beginPath = false;
    while (nodes.hasMoreTokens()) {
        String nodeId = nodes.nextToken();
        if (beginPath) {
            NodeDetail n = themetracker.getTopic(nodeId);
            path.append(tranformName(n.getName()));
            path.append("/");
        } else {
            beginPath = isRootTopic(nodeId, idsTopicsRoots);
        }
    }
    path.append(tranformName(node.getName()));
    path.append("/");
    if (pub != null) {
        path.append(tranformName(pub.getName()));
        path.append("/");
    }
    if (prefixId != null) {
        path.append(prefixId);
    }
    path.append(node.getId());
    return path.toString();
}

From source file:net.sf.j2ep.model.AllowedMethodHandler.java

/**
 * Will set the allowed methods, both by setting the string
 * and also by adding all the methods to the set of allowed.
 * @param allowed The list of allowed methods, should be comma separated
 *//*w  w w.  ja  v a2  s . co  m*/
@SuppressWarnings("unchecked")
public synchronized static void setAllowedMethods(String allowed) {
    allowedMethods = new HashSet();
    allowString = allowed;
    StringTokenizer tokenizer = new StringTokenizer(allowed, ",");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken().trim().toUpperCase();
        allowedMethods.add(token);
    }
}

From source file:net.sf.l2j.gameserver.model.actor.instance.L2FactionInstance.java

@Override
public void onBypassFeedback(L2PcInstance player, String command) {
    player.sendPacket(ActionFailed.STATIC_PACKET);
    StringTokenizer st = new StringTokenizer(command, " ");
    String actualCommand = st.nextToken();
    String val = "";
    if (st.countTokens() >= 1) {
        val = st.nextToken();
    }//from w  w w .  j a v a 2s  .co m
    if (actualCommand.equalsIgnoreCase("delevel")) {
        setTarget(player);
        int lvl = player.getLevel();
        if (lvl > 40) {
            if (val.equalsIgnoreCase("1")) {
                long delexp = 0;
                delexp = player.getStat().getExp() - player.getStat().getExpForLevel(lvl - 1);
                player.getStat().addExp(-delexp);
                player.broadcastKarma();
                player.sendMessage("Delevel was Successfull.");
            } else {
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setFile("data/html/mods/Faction/delevel.htm");
                html.replace("%lvl%", String.valueOf(player.getLevel()));
                sendHtmlMessage(player, html);
            }
        } else {
            player.sendMessage("You have to be at least level 40 to use the delevel faction.");
        }
        return;
    } else if (actualCommand.equalsIgnoreCase("levelup")) {
        setTarget(player);
        int lvl = player.getLevel();
        if (val.equalsIgnoreCase("1")) {
            long addexp = 0;
            addexp = player.getStat().getExpForLevel(lvl + 1) - player.getStat().getExp();
            player.getStat().addExp(addexp);
            player.broadcastKarma();
            player.sendMessage("Level Up was Successfull.");
        } else {
            NpcHtmlMessage html = new NpcHtmlMessage(1);
            html.setFile("data/html/mods/Faction/levelup.htm");
            html.replace("%lvl%", String.valueOf(player.getLevel()));
            sendHtmlMessage(player, html);
        }
    } else if (actualCommand.equalsIgnoreCase("setnobless")) {
        setTarget(player);
        if (player.isNoble()) {
            player.sendMessage("You have allready nobless status.");
            player.sendPacket(ActionFailed.STATIC_PACKET);
        } else {
            player.setNoble(true);
            Connection connection = null;
            try {
                connection = L2DatabaseFactory.getInstance().getConnection();
                PreparedStatement statement = connection
                        .prepareStatement("SELECT obj_id FROM characters where char_name=?");
                statement.setString(1, player.getName());
                ResultSet rset = statement.executeQuery();
                int objId = 0;
                if (rset.next()) {
                    objId = rset.getInt(1);
                }
                rset.close();
                statement.close();
                if (objId == 0) {
                    connection.close();
                    return;
                }
                statement = connection.prepareStatement("UPDATE characters SET nobless=1 WHERE obj_id=?");
                statement.setInt(1, objId);
                statement.execute();
                statement.close();
                connection.close();
            } catch (Exception e) {
                _log.warn("Could not set Nobless status of char.");
            } finally {
                try {
                    connection.close();
                } catch (Exception e) {
                }
            }
            System.out.println("##KvN Engine## : Player " + player.getName() + " has gain noble status");
            player.sendMessage("You Gaine Nobless Status.");
        }
    } else if (actualCommand.equalsIgnoreCase("setkoof")) {
        setTarget(player);
        if (player.isKoof()) {
            player.sendMessage("You are allready a " + Config.KOOFS_NAME_TEAM + " faction.");
            player.sendPacket(ActionFailed.STATIC_PACKET);
        } else {
            if (player.isNoob()) {
                player.sendMessage("You Cant Change Faction.");
                player.sendPacket(ActionFailed.STATIC_PACKET);
            } else {
                // int getnoobs = L2World.getInstance().getAllnoobPlayers().size();
                // int getkoofs = L2World.getInstance().getAllkoofPlayers().size();
                // if (getkoofs > getnoobs)
                {
                    // player.sendMessage("It is more " + Config.KOOF_NAME_TEAM + " members online.");
                    // player.sendPacket(ActionFailed.STATIC_PACKET);
                    // } else
                    // {
                    player.setKoof(true);
                    Connection connection = null;
                    try {
                        connection = L2DatabaseFactory.getInstance().getConnection();
                        PreparedStatement statement = connection
                                .prepareStatement("SELECT obj_id FROM characters where char_name=?");
                        statement.setString(1, player.getName());
                        ResultSet rset = statement.executeQuery();
                        int objId = 0;
                        if (rset.next()) {
                            objId = rset.getInt(1);
                        }
                        rset.close();
                        statement.close();
                        if (objId == 0) {
                            connection.close();
                            return;
                        }
                        statement = connection.prepareStatement("UPDATE characters SET koof=1 WHERE obj_id=?");
                        statement.setInt(1, objId);
                        statement.execute();
                        statement.close();
                        connection.close();
                    } catch (Exception e) {
                        _log.warn("Could not set koof status of char:");
                    } finally {
                        try {
                            connection.close();
                        } catch (Exception e) {
                        }
                    }
                    System.out.println("##KvN Engine## : Player " + player.getName() + " has choose "
                            + Config.KOOFS_NAME_TEAM + " faction");
                    if (player.isKoof() == true) {
                        player.broadcastUserInfo();
                        player.sendMessage("You are fighiting now for " + Config.KOOFS_NAME_TEAM + " faction ");
                        player.getAppearance().setNameColor(Config.KOOFS_NAME_COLOR);
                        player.setTitle(Config.KOOFS_NAME_TEAM);
                        player.teleToLocation(146334, 25767, -2013);
                    }
                }
            }
        }
    } else if (actualCommand.equalsIgnoreCase("setnoob")) {
        setTarget(player);
        if (player.isNoob()) {
            player.sendMessage("You are allready a " + Config.NOOBS_NAME_TEAM + " faction.");
            player.sendPacket(ActionFailed.STATIC_PACKET);
        } else {
            if (player.isKoof()) {
                player.sendMessage("You cant change faction.");
                player.sendPacket(ActionFailed.STATIC_PACKET);
            } else {
                @SuppressWarnings("unused")
                int getnoobs = L2World.getInstance().getAllnoobPlayers().size();
                @SuppressWarnings("unused")
                int getkoofs = L2World.getInstance().getAllkoofPlayers().size();
                // if (getnoobs > getkoofs)
                {
                    // player.sendMessage("It is more " + Config.NOOB_NAME_TEAM + " members online.");
                    // player.sendPacket(ActionFailed.STATIC_PACKET);
                    // } else
                    // {
                    player.setNoob(true);
                    Connection connection = null;
                    try {
                        connection = L2DatabaseFactory.getInstance().getConnection();
                        PreparedStatement statement = connection
                                .prepareStatement("SELECT obj_id FROM characters where char_name=?");
                        statement.setString(1, player.getName());
                        ResultSet rset = statement.executeQuery();
                        int objId = 0;
                        if (rset.next()) {
                            objId = rset.getInt(1);
                        }
                        rset.close();
                        statement.close();
                        if (objId == 0) {
                            connection.close();
                            return;
                        }
                        statement = connection.prepareStatement("UPDATE characters SET noob=1 WHERE obj_id=?");
                        statement.setInt(1, objId);
                        statement.execute();
                        statement.close();
                        connection.close();
                    } catch (Exception e) {
                        _log.warn("Could not set noob status of char:");
                    } finally {
                        try {
                            connection.close();
                        } catch (Exception e) {
                        }
                    }
                    System.out.println("##KvN Engine## : player " + player.getName() + " Has choose "
                            + Config.NOOBS_NAME_TEAM + " Faction");
                    if (player.isNoob() == true) {
                        player.broadcastUserInfo();
                        player.sendMessage("You are fighiting now for " + Config.NOOBS_NAME_TEAM + " faction ");
                        player.getAppearance().setNameColor(Config.NOOBS_NAME_COLOR);
                        player.setTitle(Config.NOOBS_NAME_TEAM);
                        player.teleToLocation(59669, -42221, -2992);
                    }
                }
            }
        }
    } else {
        super.onBypassFeedback(player, command);
    }
}

From source file:nz.co.senanque.workflow.WorkflowManagerMock.java

public WorkflowManagerMock(String messageNames, String computeNames) {
    if (messageNames != null) {
        StringTokenizer st = new StringTokenizer(messageNames, ",");
        MessageSender<String> ms = new MessageSender<String>() {

            @Override/*from w w  w .j a  v  a  2s. c  o  m*/
            public boolean send(String graph, long correlationId) {
                return false;
            }
        };
        while (st.hasMoreTokens()) {
            getMessages().put(st.nextToken(), ms);
        }
    }
    if (computeNames != null) {
        ComputeType<String> ct = new ComputeType<String>() {

            @Override
            public void execute(ProcessInstance processInstance, String context, Map<String, String> map) {
            }
        };
        StringTokenizer st = new StringTokenizer(computeNames, ",");
        while (st.hasMoreTokens()) {
            this.getComputeTypes().put(st.nextToken(), ct);
        }
    }
}

From source file:cz.incad.cdk.RepairVCProcess.java

@Process
public static void process() {
    try {/*from  w  ww  .  java  2  s .c  o m*/
        FedoraAccessImpl fa = new FedoraAccessImpl(KConfiguration.getInstance(), null);
        String query = "*%20<fedora-model:hasModel>%20*";
        String ri = KConfiguration.getInstance().getProperty("FedoraResourceIndex");
        String fuser = KConfiguration.getInstance().getProperty("fedoraUser");
        String fpass = KConfiguration.getInstance().getProperty("fedoraPass");

        LOGGER.info("requesting resource index");
        InputStream istream = RESTHelper.inputStream(
                ri + "?type=triples&lang=spo&format=N-Triples&distinct=on&query=" + query, fuser, fpass);
        LOGGER.info("processing results");

        BufferedReader bReader = new BufferedReader(new InputStreamReader(istream));
        String line = null;
        while ((line = bReader.readLine()) != null) {
            StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
            if (tokenizer.hasMoreTokens()) {
                String nextToken = tokenizer.nextToken();
                nextToken = nextToken.trim().substring(1);
                nextToken = nextToken.substring(0, nextToken.lastIndexOf('>'));
                try {
                    PIDParser parser = new PIDParser(nextToken);
                    parser.disseminationURI();
                    String pid = parser.getObjectPid();
                    if (pid.startsWith("uuid")) {
                        LOGGER.info("processing '" + pid + "'");
                        Document relsExt = fa.getRelsExt(pid);
                        checkRelsExt(pid, relsExt, fa);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.err.println("skipping " + nextToken);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }
}

From source file:com.idega.util.FileLocalizer.java

public static void readFile(File fileToRead, Properties props) {
    BufferedReader in = null;/*from w  ww  . j  a  v a2s. c  om*/
    try {
        if (fileToRead.isFile()) {
            in = new BufferedReader(new FileReader(fileToRead));
            String input = in.readLine();
            StringTokenizer st;
            String a, b;
            while (input != null) {
                int index = input.indexOf(stringToFind);
                if (index > -1) {
                    int i1 = input.indexOf("(", index);
                    int i2 = input.indexOf(")", index);
                    if (i2 > -1) {
                        a = input.substring(i1 + 2, i2 - 1);
                        b = "";
                        st = new StringTokenizer(a, "\",");
                        if (st.hasMoreTokens()) {
                            a = st.nextToken();
                            if (st.hasMoreTokens()) {
                                b = st.nextToken();
                            }
                            if (!props.containsKey(a)) {
                                props.setProperty(a, b);

                                // System.err.println(a+"="+b);
                            }
                        }
                    }
                }
                input = in.readLine();
            } // while ends
        } else {
            return;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.adito.security.tags.PermissionTag.java

public int doStartTag() {

    User user = null;//from  www . j  a v  a2s.  c  o  m
    try {
        user = LogonControllerFactory.getInstance().getUser(pageContext.getSession(), null);
        if (user == null) {
            return required ? SKIP_BODY : EVAL_BODY_INCLUDE;
        } else {

            ResourceType resourceType = null;
            if (resourceTypeId != -1) {
                if (permissionList.equals("")) {
                    throw new Error("No permissionMask attribute supplied.");
                }
                resourceType = PolicyDatabaseFactory.getInstance().getResourceType(resourceTypeId);
            }
            if (resourceType != null) {
                StringTokenizer t = new StringTokenizer(permissionList, ",");
                List allowed = new ArrayList();
                List denied = new ArrayList();
                while (t.hasMoreTokens()) {
                    String perm = t.nextToken();
                    if (perm.startsWith("!")) {
                        int id = Integer.parseInt(perm.substring(1));
                        Permission permInfo = resourceType.getPermission(id);
                        if (permInfo == null) {
                            throw new Error("No permission with ID of " + id + " in resource type "
                                    + resourceType.getResourceTypeId());
                        }
                        denied.add(permInfo);
                    } else {
                        int id = Integer.parseInt(perm);
                        Permission permInfo = resourceType.getPermission(id);
                        if (permInfo == null) {
                            throw new Error("No permission with ID of " + id + " in resource type "
                                    + resourceType.getResourceTypeId());
                        }
                        allowed.add(permInfo);
                    }
                }
                Permission[] allowedPerms = (Permission[]) allowed.toArray(new Permission[allowed.size()]);
                Permission[] deniedPerms = (Permission[]) denied.toArray(new Permission[denied.size()]);
                boolean allowedOk = allowedPerms.length == 0 ? true
                        : PolicyDatabaseFactory.getInstance().isPermitted(resourceType, allowedPerms, user,
                                all);
                boolean deniedOk = deniedPerms.length == 0 ? all
                        : !PolicyDatabaseFactory.getInstance().isPermitted(resourceType, deniedPerms, user,
                                all);
                if (all) {
                    if (allowedOk && deniedOk) {
                        return required ? EVAL_BODY_INCLUDE : SKIP_BODY;
                    } else {
                        return required ? SKIP_BODY : EVAL_BODY_INCLUDE;
                    }
                } else {
                    if (allowedOk || deniedOk) {
                        return required ? EVAL_BODY_INCLUDE : SKIP_BODY;
                    } else {
                        return required ? SKIP_BODY : EVAL_BODY_INCLUDE;
                    }
                }
            } else {
                if (!PolicyDatabaseFactory.getInstance().isAnyAccessRightAllowed(user, true, true, false)) {
                    return SKIP_BODY;
                } else {
                    return EVAL_BODY_INCLUDE;
                }
            }
        }
    } catch (Exception e) {
        log.error("Failed to term permissions.", e);
    }
    return SKIP_BODY;
}