List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.java
public void configure(Configuration config) throws ConfigurationException { super.configure(config); String loadOnStartup = config.getChild("load-on-startup").getValue(null); if (loadOnStartup != null) { register(loadOnStartup);//from w ww .ja v a2 s . c o m } String debugger = config.getChild("debugger").getValue(null); enableDebugger = "enabled".equalsIgnoreCase(debugger); if (reloadScripts) { String classPath = config.getChild("classpath").getValue(null); synchronized (javaClassRepository) { if (classPath != null) { StringTokenizer izer = new StringTokenizer(classPath, ";"); int i = 0; javaSourcePath = new String[izer.countTokens() + 1]; javaSourcePath[javaSourcePath.length - 1] = ""; while (izer.hasMoreTokens()) { javaSourcePath[i++] = izer.nextToken(); } } else { javaSourcePath = new String[] { "" }; } updateSourcePath(); } } }
From source file:com.aimluck.eip.mail.util.ALMailUtils.java
/** * ???????/* w w w . j a va2 s .co m*/ * * @param line * ? * @param delim * * @return */ public static String[] getTokens(String line, String delim) { if (line == null || line.equals("")) { return null; } if (line.indexOf(delim) < 0) { if (delim.length() > 1 && !"\r\n".equals(delim)) { String regex = "^.*[" + delim + "].*"; if (!line.matches(regex)) { return new String[] { line }; } } else { return new String[] { line }; } } StringTokenizer st = new StringTokenizer(line, delim); int length = st.countTokens(); String[] tokens = new String[length]; for (int i = 0; i < length; i++) { tokens[i] = st.nextToken(); } return tokens; }
From source file:it.cnr.icar.eric.client.xml.registry.BusinessQueryManagerImpl.java
/** * Handles a quirk of the JAXR spec. Fix in JAXR 2.0 spec?? * Replace schemeName with schemeId./* www . ja v a 2s . c om*/ * Prefix value with wild card to account for fact that it may be in different place in ebXML Registry * */ private String fixConceptPathForEbXML(String path) { String newPath = path; //Get the first element of the path. StringTokenizer st = new StringTokenizer(path, "/"); int cnt = st.countTokens(); //JAXR 1.0 assumes only a single level below root scheme if (cnt == 2) { String firstElem = st.nextToken(); //Replace firstElem with schemeId if firstElem is a pre-defined concept //name as defined in Appendix A of the JAXR specification. //Prefix value with wild card to account for fact that it may be in different place in ebXML Registry if (!(firstElem.startsWith("urn:"))) { String schemeId = (schemeNameToIdMap.get(firstElem)); if (schemeId != null) { String value = st.nextToken(); newPath = "/" + schemeId + "%/" + value; } } } return newPath; }
From source file:com.aimluck.eip.mail.util.ALMailUtils.java
/** * ????? Recieved ??/*from w ww . j av a 2 s . co m*/ * * @param msg * @return */ public static Date getReceivedDate(MimeMessage msg) { try { String[] receivedHeaders = msg.getHeader("Received"); if (receivedHeaders == null || receivedHeaders.length == 0) { return null; } Date receivedDate = null; StringTokenizer st = new StringTokenizer(receivedHeaders[0], ";"); if (st.countTokens() == 2) { st.nextToken(); String receivedDateStr = st.nextToken(); if (receivedDateStr != null && !receivedDateStr.equals("")) { receivedDate = MailUtility.parseDate(receivedDateStr); } return receivedDate; } else { return null; } } catch (Exception e) { return null; } }
From source file:egovframework.oe1.cms.mrm.web.EgovOe1ResveMtgController.java
/** * ? ?//from ww w . ja va 2 s . c o m * @param egovOe1ResveMtgVO - ? VO * @param status * @return "forward:/cms/mrm/selectResveMtgList.do" * @exception Exception */ @RequestMapping("/cms/mrm/addResveMtgOK.do") public String addResveMtgOK(final MultipartHttpServletRequest multiRequest, @ModelAttribute("egovOe1ResveMtgVO") EgovOe1ResveMtgVO egovOe1ResveMtgVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { log.debug(this.getClass().getName() + " ==> ? ? "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1ResveMtgVO); // Server-Side Validation beanValidator.validate(egovOe1ResveMtgVO, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute("egovOe1ResveMtgVO", egovOe1ResveMtgVO); return "/cms/mrm/addResveMtg"; } // EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); //? List<EgovOe1FileVO> result = null; String atchFileId = ""; final Map<String, MultipartFile> files = multiRequest.getFileMap(); if (!files.isEmpty()) { result = fileUtil.parseFileInf(files, "MTR_", 3, "", ""); atchFileId = fileMngService.insertFileInfs(result); } egovOe1ResveMtgVO.setAtchFileId(atchFileId); //? egovOe1ResveMtgVO.setRegisterId(user.getMberId()); //??ID String shh = egovOe1ResveMtgVO.getStartHh(); String smm = egovOe1ResveMtgVO.getStartMm(); String fhh = egovOe1ResveMtgVO.getFinishHh(); String fmm = egovOe1ResveMtgVO.getFinishMm(); if ("001".equals(egovOe1ResveMtgVO.getInsRepeat())) { //? egovOe1ResveMtgVO.setMtgStartDate(egovOe1ResveMtgVO.getInsRepeatDate()); //??? egovOe1ResveMtgVO.setMtgEndDate(egovOe1ResveMtgVO.getInsRepeatDate()); //??? egovOe1ResveMtgVO.setMtgBeginTime(shh + smm); //? egovOe1ResveMtgVO.setMtgEndTime(fhh + fmm); //? egovOe1ResveMtgService.insertResveMtg(egovOe1ResveMtgVO); StringTokenizer st = new StringTokenizer(egovOe1ResveMtgVO.getAttendantId(), "|"); //???? int n = st.countTokens(); for (int j = 0; j < n; j++) { String token = st.nextToken(); egovOe1ResveMtgVO.setMtgAttenId(token); egovOe1ResveMtgService.insertMtGattenInfo(egovOe1ResveMtgVO); } } else {// //System.out.println("====>"+egovOe1ResveMtgVO.getInsRepeatCnt()); //System.out.println(" 1====>"+egovOe1ResveMtgVO.getInsRepeatDate()); //20100101201001022010010320100204 for (int i = 1; i <= Integer.parseInt(egovOe1ResveMtgVO.getInsRepeatCnt()); i++) { // //System.out.println(" =======>"+ i); //System.out.println(" =======>"+ ((i*8)-8)); //System.out.println("? =======>"+egovOe1ResveMtgVO.getInsRepeatDate().substring((i*8)-8, i*8)); egovOe1ResveMtgVO .setMtgStartDate(egovOe1ResveMtgVO.getInsRepeatDate().substring((i * 8) - 8, i * 8)); //??? egovOe1ResveMtgVO.setMtgEndDate(egovOe1ResveMtgVO.getInsRepeatDate().substring((i * 8) - 8, i * 8)); //??? if ("003".equals(egovOe1ResveMtgVO.getReptitSeCode())) { if (i == 1) { egovOe1ResveMtgVO.setMtgBeginTime(shh + smm); } else { egovOe1ResveMtgVO.setMtgBeginTime("0600"); } if (i == Integer.parseInt(egovOe1ResveMtgVO.getInsRepeatCnt())) { egovOe1ResveMtgVO.setMtgEndTime(fhh + fmm); } else { egovOe1ResveMtgVO.setMtgEndTime("2355"); } } else { egovOe1ResveMtgVO.setMtgBeginTime(shh + smm); egovOe1ResveMtgVO.setMtgEndTime(fhh + fmm); } egovOe1ResveMtgVO.getInsRepeatDate().substring((i * 8) - 8, i * 8); egovOe1ResveMtgService.insertResveMtg(egovOe1ResveMtgVO); StringTokenizer st = new StringTokenizer(egovOe1ResveMtgVO.getAttendantId(), "|"); int n = st.countTokens(); for (int j = 0; j < n; j++) { String token = st.nextToken(); egovOe1ResveMtgVO.setMtgAttenId(token); egovOe1ResveMtgService.insertMtGattenInfo(egovOe1ResveMtgVO); } } } status.setComplete(); if (status.isComplete()) { model.addAttribute("resultMsg", "? ? "); } else { model.addAttribute("resultMsg", "? ? "); } return "forward:/cms/mrm/selectResveMtgList.do"; }
From source file:de.mpg.mpdl.inge.pubman.web.sword.SwordUtil.java
/** * Logs in the given user with the given password. * //from w w w .j ava2s .com * @param userid The id of the user to log in. * @param password The password of the user to log in. * @return The handle for the logged in user. * @throws HttpException * @throws IOException * @throws ServiceException * @throws URISyntaxException */ @Deprecated public String loginUser(String userid, String password) throws HttpException, IOException, ServiceException, URISyntaxException { String frameworkUrl = PropertyReader.getFrameworkUrl(); StringTokenizer tokens = new StringTokenizer(frameworkUrl, "//"); if (tokens.countTokens() != NUMBER_OF_URL_TOKENS) { throw new IOException( "Url in the config file is in the wrong format, needs to be http://<host>:<port>"); } tokens.nextToken(); StringTokenizer hostPort = new StringTokenizer(tokens.nextToken(), ":"); if (hostPort.countTokens() != NUMBER_OF_URL_TOKENS) { throw new IOException( "Url in the config file is in the wrong format, needs to be http://<host>:<port>"); } String host = hostPort.nextToken(); int port = Integer.parseInt(hostPort.nextToken()); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(host, port, "http"); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); PostMethod login = new PostMethod(frameworkUrl + "/aa/j_spring_security_check"); login.addParameter("j_username", userid); login.addParameter("j_password", password); client.executeMethod(login); login.releaseConnection(); CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); Cookie[] logoncookies = cookiespec.match(host, port, "/", false, client.getState().getCookies()); Cookie sessionCookie = logoncookies[0]; PostMethod postMethod = new PostMethod(LOGIN_URL); postMethod.addParameter("target", frameworkUrl); client.getState().addCookie(sessionCookie); client.executeMethod(postMethod); if (HttpServletResponse.SC_SEE_OTHER != postMethod.getStatusCode()) { throw new HttpException("Wrong status code: " + login.getStatusCode()); } String userHandle = null; Header[] headers = postMethod.getResponseHeaders(); for (int i = 0; i < headers.length; ++i) { if ("Location".equals(headers[i].getName())) { String location = headers[i].getValue(); int index = location.indexOf('='); userHandle = new String(Base64.decode(location.substring(index + 1, location.length()))); } } if (userHandle == null) { throw new ServiceException("User not logged in."); } return userHandle; }
From source file:com.aimluck.eip.mail.util.ALMailUtils.java
/** * String ? InternetAddress ? ???//from w ww.ja v a 2 s . c o m * * @param addr * @return */ public static InternetAddress getInternetAddress(String addr) { InternetAddress address = null; StringTokenizer st = new StringTokenizer(addr, "<>"); int count = st.countTokens(); try { if (count <= 0) { return null; } else if (count == 1) { address = new InternetAddress(st.nextToken().trim()); } else if (count == 2) { String name = st.nextToken().trim(); String addressStr = st.nextToken().trim(); address = new InternetAddress(addressStr, ALMailUtils.encodeWordJIS(name)); } else if (count > 2) { String name = ""; String addressStr = ""; while (st.hasMoreTokens()) { String tmp = st.nextToken().trim(); if (ALStringUtil.isMailAddress(tmp)) { addressStr = tmp; } } if (!"".equals(addressStr)) { String tmpName = addr.replace("<" + addressStr + ">", "").trim(); if (!("\"".equals(tmpName.substring(0, 1)) && "\"".equals(tmpName.substring(tmpName.length() - 1, tmpName.length())))) { name = "\"" + tmpName + "\""; } else { name = tmpName; } } address = new InternetAddress(addressStr, ALMailUtils.encodeWordJIS(name)); } } catch (Exception e) { logger.error("ALMailUtils.getInternetAddress", e); return null; } return address; }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
private void copyBBToExternalClipboardEvent() { try {// ww w.j av a2 s. co m List<Attack> attacks = getSelectedAttacks(); if (attacks.isEmpty()) { showInfo("Keine Angriffe ausgewhlt"); return; } boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this, "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code", "Nein", "Ja") == JOptionPane.YES_OPTION); StringBuilder buffer = new StringBuilder(); if (extended) { buffer.append("[u][size=12]Angriffsplan[/size][/u]\n\n"); } else { buffer.append("[u]Angriffsplan[/u]\n\n"); } buffer.append(new AttackListFormatter().formatElements(attacks, extended)); if (extended) { buffer.append("\n[size=8]Erstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n"); } else { buffer.append("\nErstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n"); } String b = buffer.toString(); StringTokenizer t = new StringTokenizer(b, "["); int cnt = t.countTokens(); if (cnt > 1000) { if (JOptionPaneHelper.showQuestionConfirmBox(this, "Die ausgewhlten Angriffe bentigen mehr als 1000 BB-Codes\n" + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?", "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) { return; } } Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null); String result = "Daten in Zwischenablage kopiert."; showSuccess(result); } catch (Exception e) { logger.error("Failed to copy data to clipboard", e); String result = "Fehler beim Kopieren in die Zwischenablage."; showError(result); } }
From source file:de.mpg.escidoc.pubman.sword.SwordUtil.java
/** * Logs in the given user with the given password. * @param userid The id of the user to log in. * @param password The password of the user to log in. * @return The handle for the logged in user. * @throws HttpException/*from ww w. j a v a 2 s .co m*/ * @throws IOException * @throws ServiceException * @throws URISyntaxException */ @Deprecated public String loginUser(String userid, String password) throws HttpException, IOException, ServiceException, URISyntaxException { String frameworkUrl = ServiceLocator.getFrameworkUrl(); StringTokenizer tokens = new StringTokenizer(frameworkUrl, "//"); if (tokens.countTokens() != NUMBER_OF_URL_TOKENS) { throw new IOException( "Url in the config file is in the wrong format, needs to be http://<host>:<port>"); } tokens.nextToken(); StringTokenizer hostPort = new StringTokenizer(tokens.nextToken(), ":"); if (hostPort.countTokens() != NUMBER_OF_URL_TOKENS) { throw new IOException( "Url in the config file is in the wrong format, needs to be http://<host>:<port>"); } String host = hostPort.nextToken(); int port = Integer.parseInt(hostPort.nextToken()); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(host, port, "http"); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); PostMethod login = new PostMethod(frameworkUrl + "/aa/j_spring_security_check"); login.addParameter("j_username", userid); login.addParameter("j_password", password); client.executeMethod(login); login.releaseConnection(); CookieSpec cookiespec = CookiePolicy.getDefaultSpec(); Cookie[] logoncookies = cookiespec.match(host, port, "/", false, client.getState().getCookies()); Cookie sessionCookie = logoncookies[0]; PostMethod postMethod = new PostMethod(LOGIN_URL); postMethod.addParameter("target", frameworkUrl); client.getState().addCookie(sessionCookie); client.executeMethod(postMethod); if (HttpServletResponse.SC_SEE_OTHER != postMethod.getStatusCode()) { throw new HttpException("Wrong status code: " + login.getStatusCode()); } String userHandle = null; Header[] headers = postMethod.getResponseHeaders(); for (int i = 0; i < headers.length; ++i) { if ("Location".equals(headers[i].getName())) { String location = headers[i].getValue(); int index = location.indexOf('='); userHandle = new String(Base64.decode(location.substring(index + 1, location.length()))); } } if (userHandle == null) { throw new ServiceException("User not logged in."); } return userHandle; }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminSpawn.java
@Override public boolean useAdminCommand(String command, L2Player activeChar) { StringTokenizer st = new StringTokenizer(command, " "); String cmd = st.nextToken(); // get command if (cmd.equals("admin_spawn_menu")) { AdminHelpPage.showHelpPage(activeChar, "spawns.htm"); } else if (cmd.equals("admin_spawnsearch_menu")) { if (st.countTokens() < 2) { AdminHelpPage.showHelpPage(activeChar, "spawns.htm"); } else {/*from ww w. j a v a 2s . co m*/ String mode = null; String string = null; int page = 0; try { mode = st.nextToken(); string = st.nextToken(); page = Integer.parseInt(st.nextToken()); showNpcs(activeChar, mode.toLowerCase(), string.toLowerCase(), page); } catch (Exception e) { AdminHelpPage.showHelpPage(activeChar, "spawns.htm"); } } } else if (cmd.equals("admin_spawnlist")) { int npcId = 0; String npcName = ""; try { npcName = st.nextToken(); try { npcId = Integer.parseInt(npcName); } catch (NumberFormatException e) { } } catch (Exception e) { showAdminCommandHelp(activeChar, cmd); } if (npcId > 0) showSpawns(activeChar, npcId); else if (npcName.length() > 0) showSpawns(activeChar, npcName); else showAdminCommandHelp(activeChar, cmd); } else if (cmd.equals("admin_spawnlist_menu")) { int npcId = 0; String npcName = ""; int page = 0; try { npcName = st.nextToken(); try { npcId = Integer.parseInt(npcName); } catch (NumberFormatException e) { } if (st.hasMoreTokens()) page = Integer.parseInt(st.nextToken()); } catch (Exception e) { AdminHelpPage.showHelpPage(activeChar, "spawns.htm"); } if (npcId > 0) showSpawns(activeChar, npcId, page, true); else if (npcName.length() > 0) showSpawns(activeChar, npcName, page, true); else AdminHelpPage.showHelpPage(activeChar, "spawns.htm"); } else if (cmd.equals("admin_spawndelay")) { int delay = 0; if (st.hasMoreTokens()) { try { delay = Integer.parseInt(st.nextToken()); Config.STANDARD_RESPAWN_DELAY = delay; } catch (Exception e) { showAdminCommandHelp(activeChar, cmd); } } activeChar .sendMessage("Current default respawn delay is " + Config.STANDARD_RESPAWN_DELAY + " seconds."); } else if (cmd.equals("admin_delay")) { int delay = 0; L2Npc target = null; if (activeChar.getTarget() instanceof L2Npc) target = (L2Npc) activeChar.getTarget(); if (st.hasMoreTokens() && target != null) { try { delay = Integer.parseInt(st.nextToken()); L2Spawn spawn = target.getSpawn(); if (spawn.isRespawnable()) { SpawnTable.getInstance().deleteSpawn(spawn, true); target.deleteMe(); spawn.setRespawnDelay(delay); SpawnTable.getInstance().addNewSpawn(spawn, true); target.setSpawn(spawn); target.spawnMe(); activeChar.sendMessage( "Respawn delay for " + target.getName() + " changed to " + delay + " seconds."); } else activeChar.sendMessage("Respawn delay for " + target.getName() + " cant be changed."); } catch (Exception e) { showAdminCommandHelp(activeChar, cmd); } } else showAdminCommandHelp(activeChar, cmd); } else if (cmd.equals("admin_spawn") || cmd.equals("admin_cspawn") || cmd.equals("admin_otspawn") || cmd.equals("admin_spawn_once")) { boolean custom = cmd.equals("admin_cspawn"); boolean respawn = !cmd.equals("admin_spawn_once"); boolean storeInDb = !cmd.equals("admin_otspawn") && respawn; int npcId = 0; String npcName = ""; int count = 1; int radius = 300; try { npcName = st.nextToken(); try { npcId = Integer.parseInt(npcName); } catch (NumberFormatException e) { } if (st.hasMoreTokens()) count = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) radius = Integer.parseInt(st.nextToken()); if (npcId > 0) spawnNpc(activeChar, npcId, count, radius, storeInDb, respawn, custom); else if (npcName.length() > 0) spawnNpc(activeChar, npcName, count, radius, storeInDb, respawn, custom); else showAdminCommandHelp(activeChar, cmd); } catch (Exception e) { showAdminCommandHelp(activeChar, cmd); } } else if (cmd.equals("admin_unspawnall")) { for (L2Player player : L2World.getInstance().getAllPlayers()) { player.sendPacket(SystemMessageId.NPC_SERVER_NOT_OPERATING); } RaidBossSpawnManager.getInstance().cleanUp(); DayNightSpawnManager.getInstance().cleanUp(); L2World.getInstance().deleteVisibleNpcSpawns(); activeChar.sendMessage("All NPCs unspawned."); } else if (cmd.equals("admin_spawnday")) { DayNightSpawnManager.getInstance().spawnDayCreatures(); activeChar.sendMessage("All daylight NPCs spawned."); } else if (cmd.equals("admin_spawnnight")) { DayNightSpawnManager.getInstance().spawnNightCreatures(); activeChar.sendMessage("All nightly NPCs spawned."); } else if (cmd.equals("admin_respawnall")) { activeChar.sendMessage("NPCs respawn sequence initiated."); RaidBossSpawnManager.getInstance().cleanUp(); DayNightSpawnManager.getInstance().cleanUp(); L2World.getInstance().deleteVisibleNpcSpawns(); NpcTable.getInstance().cleanUp(); NpcTable.getInstance().reloadAll(false); // quest reloading will be done 6 lines under SpawnTable.getInstance().reloadAll(); RaidBossSpawnManager.getInstance().reloadBosses(); AutoSpawnManager.getInstance().reload(); AutoChatManager.getInstance().reload(); SevenSigns.getInstance().spawnSevenSignsNPC(); QuestManager.getInstance().reloadAllQuests(); activeChar.sendMessage("NPCs respawn sequence complete."); } return true; }