List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:de.hybris.platform.acceleratorservices.process.email.context.impl.DefaultEmailContextFactory.java
protected void parseVariablesIntoEmailContext(final AbstractEmailContext<BusinessProcessModel> emailContext) { final Map<String, String> variables = getEmailContextVariables(); if (variables != null) { for (final Map.Entry<String, String> entry : variables.entrySet()) { final StringBuilder buffer = new StringBuilder(); final StringTokenizer tokenizer = new StringTokenizer(entry.getValue(), "{}"); while (tokenizer.hasMoreElements()) { final String token = tokenizer.nextToken(); if (emailContext.containsKey(token)) { final Object tokenValue = emailContext.get(token); if (tokenValue != null) { buffer.append(tokenValue.toString()); }//from ww w . j a v a 2 s . c o m } else { buffer.append(token); } } emailContext.put(entry.getKey(), buffer.toString()); } } }
From source file:sorcer.tools.shell.cmds.BootCmd.java
public void execute() throws Throwable { INetworkShell shell = NetworkShell.getInstance(); out = NetworkShell.getShellOutputStream(); input = shell.getCmd();//from w w w . j a v a 2s .c o m if (out == null) throw new NullPointerException("Must have an output PrintStream"); Options options = buildOptions(); CommandLineParser parser = new PosixParser(); StringTokenizer tok = new StringTokenizer(input); List<String> argsList = new ArrayList<String>(); String cmd = ""; int i = 0; while (tok.hasMoreElements()) { String arg = tok.nextToken(); if (i > 0) argsList.add(arg); else cmd = arg; i++; } CommandLine cmdLine = parser.parse(options, argsList.toArray(new String[0])); if (cmd.equalsIgnoreCase("boot")) { ILauncher sorcerLauncher = parseCommandLine(cmdLine); WaitingListener wait = new WaitingListener(); sorcerLauncher.addSorcerListener(wait); sorcerLauncher.addSorcerListener(new DestroyingListener(ProcessDestroyer.installShutdownHook(), false)); sorcerLauncher.preConfigure(); sorcerLauncher.start(); wait.wait(WaitMode.start); startedLaunchers.put(input + " [" + ((ForkingLauncher) sorcerLauncher).getPid() + "]", sorcerLauncher); } else { List<String> idsToStop = cmdLine.getArgList(); if (cmdLine.hasOption(ALL) || cmdLine.getArgList().contains(ALL)) { for (ILauncher launcher : startedLaunchers.values()) launcher.stop(); } else if (!idsToStop.isEmpty()) { List<Integer> idListToStop = new ArrayList<Integer>(); for (String idStr : idsToStop) { try { idListToStop.add(Integer.parseInt(idStr)); } catch (NumberFormatException ne) { out.println("Could not parse the service node id: " + idStr); } } int j = 0; List<String> launchersToRemove = new ArrayList<String>(); for (String launcherStr : startedLaunchers.keySet()) { if (idListToStop.contains(Integer.valueOf(j))) { out.println("stopping node " + j + " started by command: " + launcherStr); startedLaunchers.get(launcherStr).stop(); launchersToRemove.add(launcherStr); } j++; } for (String launcherStr : launchersToRemove) startedLaunchers.remove(launcherStr); } else { int j = 0; for (String launcherStr : startedLaunchers.keySet()) { out.println(j + "\t" + launcherStr); j++; } } } }
From source file:tvbrowser.core.search.booleansearch.BooleanSearcher.java
/** * Erzeugt einen neuen Suchbaum. Der Baum wird automatisch optimiert. Es kann * immer nur ein Konstruktor gleichzeitig laufen. Fuer Synchronization ist * gesorgt./*from w w w . j a v a2 s. com*/ * * @throws ParserException */ public BooleanSearcher(String pattern, boolean caseSensitive) throws ParserException { Hashtable<String, Object> matcherTab = new Hashtable<String, Object>(); mCaseSensitive = caseSensitive; mReplaceSpCh = true; pattern = pattern.trim(); int braceDifference = StringUtils.countMatches(pattern, "(") - StringUtils.countMatches(pattern, ")"); if (braceDifference > 0) { pattern = pattern + StringUtils.repeat(")", braceDifference); } pattern = pattern.replaceAll("\\\"", " "); pattern = pattern.replaceAll("\\(", " ( "); pattern = pattern.replaceAll("\\)", " ) "); StringTokenizer tokenizer = new StringTokenizer(pattern); Vector<Object> parts = new Vector<Object>(); while (tokenizer.hasMoreElements()) { String s = tokenizer.nextToken(); if (s.equals("(")) { parts.add(subPart(tokenizer)); } else { parts.add(s); } } mRootMatcher = getMatcher(parts, mCaseSensitive, matcherTab); mRootMatcher = mRootMatcher.optimize(); }
From source file:org.apache.webdav.lib.methods.OptionsMethod.java
/** * Process response headers. The contract of this method is that it only * parses the response headers.// w ww . j a v a 2 s. c o m * * @param state the state * @param conn the connection */ public void processResponseHeaders(HttpState state, HttpConnection conn) { Header davHeader = getResponseHeader("dav"); if (davHeader != null) { String davHeaderValue = davHeader.getValue(); StringTokenizer tokenizer = new StringTokenizer(davHeaderValue, ","); while (tokenizer.hasMoreElements()) { String davCapability = tokenizer.nextToken().trim(); davCapabilities.addElement(davCapability); } } Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { String allowHeaderValue = allowHeader.getValue(); StringTokenizer tokenizer = new StringTokenizer(allowHeaderValue, ","); while (tokenizer.hasMoreElements()) { String methodAllowed = tokenizer.nextToken().trim().toUpperCase(); methodsAllowed.addElement(methodAllowed); } } Header lengthHeader = getResponseHeader("content-length"); Header typeHeader = getResponseHeader("content-type"); if ((lengthHeader != null && Integer.parseInt(lengthHeader.getValue()) > 0) || (typeHeader != null && typeHeader.getValue().startsWith("text/xml"))) hasXMLBody = true; super.processResponseHeaders(state, conn); }
From source file:domain.FTP.java
public void subirArchivo(String archivo) { InputStream inputStream;/* w w w. j a va2 s. com*/ String archivo_sin_ruta = ""; StringTokenizer st = new StringTokenizer(archivo, "\\"); while (st.hasMoreElements()) { archivo_sin_ruta = st.nextToken(); } try { ftpClient.connect(server, port); ftpClient.login(user, password); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); // APPROACH #2: uploads second file using an OutputStream //File LocalFile = new File(rutaOrigenArchivo + "\\" + nombreArchivo); File LocalFile = new File(archivo); String RemoteFile = uploadpath + "\\" + archivo_sin_ruta; inputStream = new FileInputStream(LocalFile); log.log("Subiendo archivo " + archivo + " a " + uploadpath, false); OutputStream outputStream = ftpClient.storeFileStream(RemoteFile); byte[] bytesIn = new byte[4096]; int read = 0; while ((read = inputStream.read(bytesIn)) != -1) { outputStream.write(bytesIn, 0, read); } inputStream.close(); outputStream.close(); boolean completed = ftpClient.completePendingCommand(); if (completed) { log.log("el archivo a sido subido correctamente", false); } } catch (IOException ex) { log.log(ex.toString(), true); Logger.getLogger(FTP.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (ftpClient.isConnected()) { ftpClient.logout(); ftpClient.disconnect(); } } catch (IOException ex) { log.log(ex.toString(), true); ex.printStackTrace(); } } }
From source file:org.wso2.carbon.redirector.servlet.ui.filters.AllPagesFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { // no filtering return;// w w w. j a va 2 s. c o m } HttpServletRequest request = (HttpServletRequest) servletRequest; String requestedURI = request.getRequestURI(); String contextPath = request.getContextPath(); if (contextPath == null || ("/").equals(contextPath)) { contextPath = ""; } StringTokenizer tokenizer = new StringTokenizer(requestedURI.substring(contextPath.length() + 1), "/"); String[] firstUriTokens = new String[2]; int i = 0; while (tokenizer.hasMoreElements()) { firstUriTokens[i] = tokenizer.nextToken(); i++; if (i > 1) { break; } } if (i > 1 && firstUriTokens[0].equals("t")) { if (requestedURI.startsWith("//")) { requestedURI = requestedURI.replaceFirst("//", "/"); } String path = requestedURI .substring(contextPath.length() + firstUriTokens[0].length() + firstUriTokens[1].length() + 2); // need to validate the tenant exists String tenantDomain = firstUriTokens[1]; boolean tenantExists = true; boolean tenantActive = true; if (tenantExistMap.get(tenantDomain) == null) { // we have to call the service :( RedirectorServletServiceClient client; try { client = new RedirectorServletServiceClient(context, request.getSession()); } catch (Exception e) { String msg = "Error in constructing RedirectorServletServiceClient."; log.error(msg, e); throw new ServletException(msg, e); } try { String status = client.validateTenant(tenantDomain); tenantExists = !StratosConstants.INVALID_TENANT.equals(status); if (tenantExists && StratosConstants.ACTIVE_TENANT.equals(status)) { //tenantExists = true; tenantActive = true; } } catch (Exception e) { String msg = "Error in checking the existing of the tenant domain: " + tenantDomain + "."; log.error(msg, e); throw new ServletException(msg, e); } } // we have some backup stuff, if the tenant doesn't exists if (tenantExists) { if (tenantActive) { // we put this to hash only if the original tenant domain exist tenantExistMap.put(tenantDomain, true); } else { String errorPage = contextPath + "/carbon/admin/error.jsp?The Requested tenant domain: " + tenantDomain + " is inactive."; RequestDispatcher requestDispatcher = request.getRequestDispatcher(errorPage); requestDispatcher.forward(request, servletResponse); return; } } else { String errorPage = contextPath + "/carbon/admin/error.jsp?The Requested tenant domain: " + tenantDomain + " doesn't exist."; RequestDispatcher requestDispatcher = request.getRequestDispatcher(errorPage); requestDispatcher.forward(request, servletResponse); return; } request.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain); // if (path.indexOf("admin/login.jsp") >= 0) { // // we are going to apply the login.jsp filter + tenant specif filter both in here // path = path.replaceAll("admin/login.jsp", // "tenant-login/login_ajaxprocessor.jsp"); // request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); // } if (path.indexOf("/admin/index.jsp") >= 0) { // we are going to apply the login.jsp filter + tenant specific filter both in here path = path.replaceAll("/admin/index.jsp", "/tenant-dashboard/index.jsp"); request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); } if (path.indexOf("admin/docs/userguide.html") >= 0) { // we are going to apply the dasbhoard docs.jsp filter + // tenant specif filter both in here path = path.replaceAll("admin/docs/userguide.html", "tenant-dashboard/docs/userguide.html"); request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); } if ("".equals(path) || "/".equals(path) || "/carbon".equals(path) || "/carbon/".equals(path) || "/carbon/admin".equals(path) || "/carbon/admin/".equals(path)) { // we have to redirect the root to the login page directly path = contextPath + "/carbon/admin/login.jsp"; ((HttpServletResponse) servletResponse).sendRedirect(path); return; } RequestDispatcher requestDispatcher = request.getRequestDispatcher(path); requestDispatcher.forward(request, servletResponse); return; } }
From source file:org.apache.stratos.redirector.servlet.ui.filters.AllPagesFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { // no filtering return;/*from w w w. j ava2s .co m*/ } HttpServletRequest request = (HttpServletRequest) servletRequest; String requestedURI = request.getRequestURI(); String contextPath = request.getContextPath(); if (contextPath == null || ("/").equals(contextPath)) { contextPath = ""; } StringTokenizer tokenizer = new StringTokenizer(requestedURI.substring(contextPath.length() + 1), "/"); String[] firstUriTokens = new String[2]; int i = 0; while (tokenizer.hasMoreElements()) { firstUriTokens[i] = tokenizer.nextToken(); i++; if (i > 1) { break; } } if (i > 1 && firstUriTokens[0].equals("t")) { if (requestedURI.startsWith("//")) { requestedURI = requestedURI.replaceFirst("//", "/"); } String path = requestedURI .substring(contextPath.length() + firstUriTokens[0].length() + firstUriTokens[1].length() + 2); // need to validate the tenant exists String tenantDomain = firstUriTokens[1]; boolean tenantExists = true; boolean tenantActive = true; if (tenantExistMap.get(tenantDomain) == null) { // we have to call the service :( RedirectorServletServiceClient client; try { client = new RedirectorServletServiceClient(context, request.getSession()); } catch (Exception e) { String msg = "Error in constructing RedirectorServletServiceClient."; log.error(msg, e); throw new ServletException(msg, e); } try { String status = client.validateTenant(tenantDomain); tenantExists = !StratosConstants.INVALID_TENANT.equals(status); if (tenantExists && StratosConstants.ACTIVE_TENANT.equals(status)) { //tenantExists = true; tenantActive = true; } } catch (Exception e) { String msg = "Error in checking the existing of the tenant domain: " + tenantDomain + "."; log.error(msg, e); throw new ServletException(msg, e); } } // we have some backup stuff, if the tenant doesn't exists if (tenantExists) { if (tenantActive) { // we put this to hash only if the original tenant domain exist tenantExistMap.put(tenantDomain, true); } else { String errorPage = contextPath + "/carbon/admin/error.jsp?The Requested tenant domain: " + tenantDomain + " is inactive."; RequestDispatcher requestDispatcher = request.getRequestDispatcher(errorPage); requestDispatcher.forward(request, servletResponse); return; } } else { String errorPage = contextPath + "/carbon/admin/error.jsp?The Requested tenant domain: " + tenantDomain + " doesn't exist."; RequestDispatcher requestDispatcher = request.getRequestDispatcher(errorPage); requestDispatcher.forward(request, servletResponse); return; } request.setAttribute(MultitenantConstants.TENANT_DOMAIN, tenantDomain); // if (path.indexOf("admin/login.jsp") >= 0) { // // we are going to apply the login.jsp filter + tenant specif filter both in here // path = path.replaceAll("admin/login.jsp", // "tenant-login/login_ajaxprocessor.jsp"); // request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); // } if (path.indexOf("/admin/index.jsp") >= 0) { // we are going to apply the login.jsp filter + tenant specif filter both in here path = path.replaceAll("/admin/index.jsp", "/tenant-dashboard/index.jsp"); request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); } if (path.indexOf("admin/docs/userguide.html") >= 0) { // we are going to apply the dasbhoard docs.jsp filter + // tenant specif filter both in here path = path.replaceAll("admin/docs/userguide.html", "tenant-dashboard/docs/userguide.html"); request.setAttribute(StratosConstants.TENANT_SPECIFIC_URL_RESOLVED, "1"); } if ("".equals(path) || "/".equals(path) || "/carbon".equals(path) || "/carbon/".equals(path) || "/carbon/admin".equals(path) || "/carbon/admin/".equals(path)) { // we have to redirect the root to the login page directly path = contextPath + "/carbon/admin/login.jsp"; ((HttpServletResponse) servletResponse).sendRedirect(path); return; } RequestDispatcher requestDispatcher = request.getRequestDispatcher(path); requestDispatcher.forward(request, servletResponse); return; } }
From source file:org.kuali.ole.select.service.OLEInvoiceSearchService.java
public Map<String, List<String>> getSearchCriteria(Map<String, String> itemFields) throws Exception { Map<String, List<String>> searchCriteriaMap = new HashMap<String, List<String>>(); for (Map.Entry<String, String> entry : itemFields.entrySet()) { List<String> list = new ArrayList<String>(); if (entry.getKey().equalsIgnoreCase(OleSelectConstant.InvoiceSearch.PURAP_ID)) { StringTokenizer stringTokenizer = new StringTokenizer(entry.getValue(), ","); while (stringTokenizer.hasMoreElements()) { list.add(stringTokenizer.nextElement().toString()); }//from w ww . jav a 2 s. co m searchCriteriaMap.put(entry.getKey().toString(), list); } else { searchCriteriaMap.put(entry.getKey().toString(), new ArrayList<String>(Arrays.asList(entry.getValue().toString()))); } } return searchCriteriaMap; }
From source file:de.tor.tribes.util.parser.TroopsParser70.java
@Override public boolean parse(String pData) { StringTokenizer lineTokenizer = new StringTokenizer(pData, "\n\r"); List<String> lineList = new LinkedList<>(); while (lineTokenizer.hasMoreElements()) { String line = lineTokenizer.nextToken(); //"cheap snob rebuild linebreak"-hack if (line.trim().endsWith("+")) { line += lineTokenizer.nextToken(); }//from ww w. j a v a2s . com debug("Push line to stack: " + line); lineList.add(line); } // used to update group on the fly, if not "all" selected String groupName = null; // groups could be multiple lines, detection is easiest for first line (starts with "Gruppen:") boolean groupLines = false; // store visited villages, so we can add em to selected group List<Village> villages = new LinkedList<>(); int foundTroops = 0; TroopsManager.getSingleton().invalidate(); while (!lineList.isEmpty()) { String currentLine = lineList.remove(0); Village v = null; try { v = VillageParser.parseSingleLine(currentLine); } catch (Exception e) { //no village in line } if (v != null) { if (processEntry(v, currentLine, lineList)) { foundTroops++; // add village to list of villages in selected group if (groupName != null) villages.add(v); groupLines = false; //should already be false. set to false again, to avoid searching for group name in garbage if user copied nonsense } } else { // Check if current line is first group line. In case it is, store selected group if (currentLine.trim().startsWith(getVariable("overview.groups"))) groupLines = true; // Check if current line contains active group. In case it does, store group name and stop searching if (groupLines && currentLine.matches(".*>.*?<.*")) { groupLines = false; groupName = StringUtils.substringBetween(currentLine, ">", "<"); // = line.replaceAll(".*>|<.*",""); if we stop using Apache Commons debug("Found selected group in line '" + currentLine + "'"); debug("Selected group '" + groupName + "'"); } else debug("Dropping line '" + currentLine + "'"); } } boolean retValue = (foundTroops != 0); if (retValue) { try { DSWorkbenchMainFrame.getSingleton() .showSuccess("DS Workbench hat Truppeninformationen zu " + foundTroops + ((foundTroops == 1) ? " Dorf " : " Drfern ") + " in die Truppenbersicht eingetragen."); } catch (Exception e) { NotifierFrame.doNotification("DS Workbench hat Truppeninformationen zu " + foundTroops + ((foundTroops == 1) ? " Dorf " : " Drfern ") + " in die Truppenbersicht eingetragen.", NotifierFrame.NOTIFY_INFO); } } TroopsManager.getSingleton().revalidate(retValue); //update selected group, if any if (groupName != null && !groupName.equals(getVariable("groups.all"))) { HashMap<String, List<Village>> groupTable = new HashMap<>(); groupTable.put(groupName, villages); DSWorkbenchMainFrame.getSingleton().fireGroupParserEvent(groupTable); } return retValue; }
From source file:jobimtext.example.annotators.ParseAnnotator.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { StringTokenizer tok = new StringTokenizer(jcas.getDocumentText(), "\n"); int b = 0;/*from w w w . ja v a 2s .c om*/ int si = 0; int idxLine = 0; // add sentence while (tok.hasMoreElements()) { String line = tok.nextToken(); String[] sl = line.split("\t"); String strSentence = sl[0]; Sentence sentence = new Sentence(jcas, b, b + strSentence.length()); sentence.setPosTagString( new Annotation(jcas, sentence.getEnd() + 1, sentence.getEnd() + 1 + sl[1].length())); sentence.setParsesString(new Annotation(jcas, sentence.getPosTagString().getEnd() + 1, sentence.getPosTagString().getEnd() + 1 + sl[2].length())); sentence.setParsesTreeString(new Annotation(jcas, sentence.getParsesString().getEnd() + 1, sentence.getParsesString().getEnd() + 1 + sl[3].length())); sentence.setPosTreeString(new Annotation(jcas, sentence.getParsesTreeString().getEnd() + 1, sentence.getParsesTreeString().getEnd() + 1 + sl[4].length())); // String[] splitSentence = strSentence.split(" "); String[] splitPosTags = sl[1].split(" "); // if (splitSentence.length != splitPosTags.length) { // getLogger().log(Level.WARNING, // "Line "+idxLine+": Length of POS tag String and number of tokens in sentence differ"); // } List<Token> ts = new ArrayList<Token>(); if (!tokenizePosStanf) { si = 0; for (int i = 0; i < splitPosTags.length; i++) { int idx = splitPosTags[i].lastIndexOf("/"); Token token; // System.out.println(strSentence.substring(token.getBegin(),token.getEnd())); String strToken = splitPosTags[i].substring(0, idx); strToken = clean(strToken); strToken = strToken.replaceAll("-LRB-", "("); strToken = strToken.replaceAll("-LCB-", "{"); strToken = strToken.replaceAll("-RCB-", "}"); strSentence = strSentence.replaceAll("\\]", "("); strToken = strToken.replaceAll("-RRB-", ")"); strSentence = strSentence.replaceAll("\\]", ")"); if (strToken.equals("-RRB-") || strToken.equals("-LRB-")) { token = new Token(jcas, b + si, b + si + 1); si += 1; } else if (strSentence.substring(si).startsWith(strToken)) { token = new Token(jcas, b + si, b + si + strToken.length()); si += strToken.length(); } else if (strToken.matches("^[^a-zA-Z]+$")) { int six = 0; // System.out.println(strSentence.substring(si)); while (strSentence.length() > (si + six) && strSentence.substring(si + six, si + six + 1).matches("[^a-zA-Z]")) { six++; } token = new Token(jcas, b + si, b + si + six); si += six; // token = null; } else { token = new Token(jcas, b + si, b + si + idx); si += idx; } while (strSentence.length() > si && (strSentence.substring(si).matches("^[\\s].*") || strSentence.charAt(si) == 160)) { si += 1; } token.addToIndexes(); POS pos = new POS(jcas, token.getBegin(), token.getEnd()); int p = splitPosTags[i].lastIndexOf("/"); String[] postag = new String[] { splitPosTags[i].substring(0, p), splitPosTags[i].substring(p + 1) }; if (!postag[0].equals(token.getCoveredText())) { getLogger().log(Level.WARNING, "Line " + idxLine + ": Token and POS tag token are different ( " + token.getCoveredText() + " != " + postag[0] + " )"); //System.out.println("Line " + idxLine + ": Token and POS tag token are different ( " + token.getCoveredText() + " != " + postag[0] + " )"); } pos.setPosValue(postag[1]); token.setPos(pos); ts.add(token); } annotateParses(ts, sentence.getParsesTreeString()); } else { si = sentence.getPosTagString().getBegin(); // System.out.println(sentence.getPosTagString().getCoveredText()); for (String t : splitPosTags) { int idx = t.lastIndexOf("/"); Token token = new Token(jcas, si, si + idx); si += t.length() + 1; // System.out.println(token.getCoveredText() + "\t" + t); token.addToIndexes(); } sentence.setEnd(sentence.getPosTagString().getEnd()); } b = b + line.length() + 1; sentence.addToIndexes(); idxLine++; } }