List of usage examples for java.util StringTokenizer nextElement
public Object nextElement()
From source file:org.trafodion.dtm.HBaseAuditControlPoint.java
public ArrayList<String> getRecordList(String controlPt) throws IOException { if (LOG.isTraceEnabled()) LOG.trace("getRecord"); ArrayList<String> transactionList = new ArrayList<String>(); Get g = new Get(Bytes.toBytes(controlPt)); Result r = table.get(g);/*from ww w . j ava2 s . c o m*/ byte[] currValue = r.getValue(CONTROL_POINT_FAMILY, ASN_HIGH_WATER_MARK); String recordString = new String(currValue); if (LOG.isDebugEnabled()) LOG.debug("recordString is " + recordString); StringTokenizer st = new StringTokenizer(recordString, ","); while (st.hasMoreElements()) { String token = st.nextElement().toString(); if (LOG.isDebugEnabled()) LOG.debug("token is " + token); transactionList.add(token); } if (LOG.isTraceEnabled()) LOG.trace("getRecord - exit with list size (" + transactionList.size() + ")"); return transactionList; }
From source file:org.psit.transwatcher.TransWatcher.java
private String getBroadcastIP() { String myIP = null;// w w w . j a v a 2s .c o m try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements() && myIP == null) { NetworkInterface current = interfaces.nextElement(); notifyMessage(current.toString()); notifyMessage("Name: " + current.getName()); if (!current.isUp() || current.isLoopback() || current.isVirtual() || !current.getName().startsWith("wl")) continue; Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress current_addr = addresses.nextElement(); if (current_addr.isLoopbackAddress()) continue; if (current_addr instanceof Inet4Address) { myIP = current_addr.getHostAddress(); break; } } } } catch (Exception exc) { notifyMessage("Error determining network interfaces:\n"); } if (myIP != null) { // broadcast for IPv4 StringTokenizer st = new StringTokenizer(myIP, "."); StringBuffer broadcastIP = new StringBuffer(); // hate that archaic string puzzle broadcastIP.append(st.nextElement()); broadcastIP.append("."); broadcastIP.append(st.nextElement()); broadcastIP.append("."); broadcastIP.append(st.nextElement()); broadcastIP.append("."); broadcastIP.append("255"); return broadcastIP.toString(); } return null; }
From source file:com.squid.kraken.v4.api.core.customer.CustomerServiceBaseImpl.java
/** * Request for access to the system. The process will be the following: * <ul>//from www . j a va 2s . c om * <li>Create a new Customer with given name.</li> * <li>Create a new User with Owner rights on Customer with given email.</li> * <li>Create 2 new Clients (admin_console and dashboard) with domain "api.squidsolutions.com" for this * Customer (Client.urls - new field in the Client model).</li> * <li>Send a welcome mail including a link to the API Console.</li> * </ul> * * @param request * http request * @param customerName * name of the new customer * @param email * email of the new user * @param login * login of the new user * @param password * password of the new user * @param locale * locale * @param domain * the caller domain (remote host) * @param linkURL * link to return in the email * @param emailHelper * util to send mail */ public AppContext accessRequest(AUTH_MODE authMode, String customerName, String email, String login, String password, String locale, String domain, String linkURL, String defaultClientURL, EmailHelper emailHelper) { // set defaults if (StringUtils.isEmpty(login) && StringUtils.isEmpty(email)) { login = "super"; password = "super123"; } if ((locale != null) && !locale.isEmpty()) { locale = locale.trim(); } else { locale = Locale.getDefault().toString(); } List<String> urls = new ArrayList<String>(); if (defaultClientURL != null) { if (defaultClientURL.contains(",")) { StringTokenizer st = new StringTokenizer(defaultClientURL, ","); while (st.hasMoreElements()) { urls.add(st.nextElement().toString()); } } else { urls.add(defaultClientURL); } } if (domain != null && ((defaultClientURL == null) || (!defaultClientURL.equals(domain)))) { urls.add(domain); } // clients List<Client> clients = new ArrayList<Client>(); clients.add(new Client(new ClientPK(null, CoreConstants.CONSOLE_CLIENT_ID), CoreConstants.CONSOLE_CLIENT_NAME, "" + UUID.randomUUID(), urls)); clients.add(new Client(new ClientPK(null, CoreConstants.DASHBOARD_CLIENT_ID), CoreConstants.DASHBOARD_CLIENT_NAME, "" + UUID.randomUUID(), urls)); String salt = UUID.randomUUID().toString(); AppContext ctx = createCustomer(authMode, customerName, locale, salt, login, password, email, clients); if (email != null) { // send welcome mail String linkAccessRequest = linkURL.replace('{' + CoreConstants.PARAM_NAME_CUSTOMER_ID + "}", ctx.getCustomerId()); String content = "Welcome to the SquidAnalytics API.\n\n"; content += "Your Customer ID is " + ctx.getCustomerId() + "\n\n"; content += "Please follow this link to access your API Console :\n" + linkAccessRequest; content += "\n\nThe SquidAnalytics Team."; String subject = "SquidAnalytics API access"; List<String> dests = Arrays.asList(email); try { logger.info("Sending API access request link (" + linkAccessRequest + ") to " + email + " " + ctx.getUser()); List<String> bccAddresses = new ArrayList<String>(); String bccAddress = KrakenConfig.getProperty("signup.email.bcc", true); if ((bccAddress != null) && !bccAddress.isEmpty()) { bccAddresses.add(bccAddress); } emailHelper.sendEmail(dests, bccAddresses, subject, content, null, EmailHelper.PRIORITY_NORMAL); } catch (MessagingException e) { throw new APIException(e, ctx.isNoError()); } } return ctx; }
From source file:org.apache.pdfbox.pdmodel.font.PDType1Font.java
/** * Tries to get the encoding for the type1 font. * *//*from w w w . j a va 2 s . c o m*/ private void getEncodingFromFont(boolean extractEncoding) { // This whole section of code needs to be replaced with an actual type1 font parser!! // Get the font program from the embedded type font. PDFontDescriptor fontDescriptor = getFontDescriptor(); if (fontDescriptor != null && fontDescriptor instanceof PDFontDescriptorDictionary) { PDStream fontFile = ((PDFontDescriptorDictionary) fontDescriptor).getFontFile(); if (fontFile != null) { BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(fontFile.createInputStream())); // this section parses the font program stream searching for a /Encoding entry // if it contains an array of values a Type1Encoding will be returned // if it encoding contains an encoding name the corresponding Encoding will be returned String line = ""; Type1Encoding encoding = null; while ((line = in.readLine()) != null) { if (extractEncoding) { if (line.startsWith("currentdict end")) { if (encoding != null) setFontEncoding(encoding); break; } if (line.startsWith("/Encoding")) { if (line.contains("array")) { StringTokenizer st = new StringTokenizer(line); // ignore the first token st.nextElement(); int arraySize = Integer.parseInt(st.nextToken()); encoding = new Type1Encoding(arraySize); } // if there is already an encoding, we don't need to // assign another one else if (getFontEncoding() == null) { StringTokenizer st = new StringTokenizer(line); // ignore the first token st.nextElement(); String type1Encoding = st.nextToken(); setFontEncoding(EncodingManager.INSTANCE .getEncoding(COSName.getPDFName(type1Encoding))); break; } } else if (line.startsWith("dup")) { StringTokenizer st = new StringTokenizer(line.replaceAll("/", " /")); // ignore the first token st.nextElement(); int index = Integer.parseInt(st.nextToken()); String name = st.nextToken(); if (encoding == null) log.warn( "Unable to get character encoding. Encoding defintion found without /Encoding line."); else encoding.addCharacterEncoding(index, name.replace("/", "")); } } // according to the pdf reference, all font matrices should be same, except for type 3 fonts. // but obviously there are some type1 fonts with different matrix values, see pdf sample // attached to PDFBOX-935 if (line.startsWith("/FontMatrix")) { String matrixValues = line.substring(line.indexOf("[") + 1, line.lastIndexOf("]")); StringTokenizer st = new StringTokenizer(matrixValues); COSArray array = new COSArray(); if (st.countTokens() >= 6) { try { for (int i = 0; i < 6; i++) { COSFloat floatValue = new COSFloat(Float.parseFloat(st.nextToken())); array.add(floatValue); } fontMatrix = new PDMatrix(array); } catch (NumberFormatException exception) { log.error("Can't read the fontmatrix from embedded font file!"); } } } } } catch (IOException exception) { log.error("Error: Could not extract the encoding from the embedded type1 font."); } finally { if (in != null) { try { in.close(); } catch (IOException exception) { log.error( "An error occurs while closing the stream used to read the embedded type1 font."); } } } } } }
From source file:padl.kernel.impl.Constituent.java
public void setCodeLines(final String someCode) { final List listOfLines = new ArrayList(); final StringTokenizer tokeniser = new StringTokenizer(someCode, "\n\r"); while (tokeniser.hasMoreTokens()) { final String line = (String) tokeniser.nextElement(); listOfLines.add(line);// w ww . j a va2 s . c o m } final String[] arrayOfLines = new String[listOfLines.size()]; listOfLines.toArray(arrayOfLines); this.setCodeLines(arrayOfLines); }
From source file:us.mn.state.health.lims.testmanagement.action.TestManagementCancelTestsAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); String selectedTestsString = (String) request.getParameter("selectedTests"); BaseActionForm dynaForm = (BaseActionForm) form; String accessionNumber = (String) dynaForm.get("accessionNumber"); // initialize the form dynaForm.initialize(mapping);//ww w .ja v a 2 s. c om ActionMessages errors = null; Map errorMap = new HashMap(); errorMap.put(HAS_AMENDED_TEST, new ArrayList()); errorMap.put(INVALID_STATUS_RESULTS_COMPLETE, new ArrayList()); errorMap.put(INVALID_STATUS_RESULTS_VERIFIED, new ArrayList()); Transaction tx = HibernateUtil.getSession().beginTransaction(); try { SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); TestDAO testDAO = new TestDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); ResultDAO resultDAO = new ResultDAOImpl(); NoteDAO noteDAO = new NoteDAOImpl(); AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl(); AnalysisQaEventActionDAO analysisQaEventActionDAO = new AnalysisQaEventActionDAOImpl(); List listOfIds = new ArrayList(); // bugzilla 1926 insert logging - get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); if (!StringUtil.isNullorNill(selectedTestsString)) { String idSeparator = SystemConfiguration.getInstance().getDefaultIdSeparator(); StringTokenizer st = new StringTokenizer(selectedTestsString, idSeparator); while (st.hasMoreElements()) { String id = (String) st.nextElement(); listOfIds.add(id); } //now set analysis status to canceled for these analysis ids for (int i = 0; i < listOfIds.size(); i++) { String id = (String) listOfIds.get(i); //bug 2532 (the ids are now analysis ids - not test ids) Analysis analysis = new Analysis(); analysis.setId(id); analysisDAO.getData(analysis); if (analysis != null && !StringUtil.isNullorNill(analysis.getId())) { if (analysis.getStatus() .equals(SystemConfiguration.getInstance().getAnalysisStatusAssigned())) { if (!analysis.getRevision().equals("0")) { List listOfAmendedTests = (ArrayList) errorMap.get(HAS_AMENDED_TEST); listOfAmendedTests.add(analysis); errorMap.put(HAS_AMENDED_TEST, listOfAmendedTests); } } else if (analysis.getStatus() .equals(SystemConfiguration.getInstance().getAnalysisStatusResultCompleted())) { List listOfCompletedTests = (ArrayList) errorMap.get(INVALID_STATUS_RESULTS_COMPLETE); listOfCompletedTests.add(analysis); errorMap.put(INVALID_STATUS_RESULTS_COMPLETE, listOfCompletedTests); continue; } else if (analysis.getStatus() .equals(SystemConfiguration.getInstance().getAnalysisStatusReleased())) { List listOfVerifiedTests = (ArrayList) errorMap.get(INVALID_STATUS_RESULTS_VERIFIED); listOfVerifiedTests.add(analysis); errorMap.put(INVALID_STATUS_RESULTS_VERIFIED, listOfVerifiedTests); continue; } analysis.setSysUserId(sysUserId); analysis.setStatus(SystemConfiguration.getInstance().getAnalysisStatusCanceled()); analysisDAO.updateData(analysis); } } } PropertyUtils.setProperty(dynaForm, ACCESSION_NUMBER, accessionNumber); tx.commit(); // introducing a confirmation message if (errorMap != null && errorMap.size() > 0) { //1) amended message List amendedTests = (ArrayList) errorMap.get(HAS_AMENDED_TEST); List completedTests = (ArrayList) errorMap.get(INVALID_STATUS_RESULTS_COMPLETE); List verifiedTests = (ArrayList) errorMap.get(INVALID_STATUS_RESULTS_VERIFIED); if ((amendedTests != null && amendedTests.size() > 0) || (completedTests != null && completedTests.size() > 0) || (verifiedTests != null && verifiedTests.size() > 0)) { errors = new ActionMessages(); if (amendedTests != null && amendedTests.size() > 0) { ActionError error = null; if (amendedTests.size() > 1) { StringBuffer stringOfTests = new StringBuffer(); for (int i = 0; i < amendedTests.size(); i++) { Analysis analysis = (Analysis) amendedTests.get(i); stringOfTests.append("\\n " + analysis.getTest().getTestDisplayValue()); } error = new ActionError("testsmanagement.message.multiple.test.not.canceled.amended", stringOfTests.toString(), null); } else { Analysis analysis = (Analysis) amendedTests.get(0); error = new ActionError("testsmanagement.message.one.test.not.canceled.amended", "\\n " + analysis.getTest().getTestDisplayValue(), null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); } if (completedTests != null && completedTests.size() > 0) { ActionError error = null; if (completedTests.size() > 1) { StringBuffer stringOfTests = new StringBuffer(); for (int i = 0; i < completedTests.size(); i++) { Analysis analysis = (Analysis) completedTests.get(i); stringOfTests.append("\\n " + analysis.getTest().getTestDisplayValue()); } error = new ActionError("testsmanagement.message.multiple.test.not.canceled.completed", stringOfTests.toString(), null); } else { Analysis analysis = (Analysis) completedTests.get(0); error = new ActionError("testsmanagement.message.one.test.not.canceled.completed", "\\n " + analysis.getTest().getTestDisplayValue(), null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); } if (verifiedTests != null && verifiedTests.size() > 0) { ActionError error = null; if (verifiedTests.size() > 1) { StringBuffer stringOfTests = new StringBuffer(); for (int i = 0; i < verifiedTests.size(); i++) { Analysis analysis = (Analysis) verifiedTests.get(i); stringOfTests.append("\\n " + analysis.getTest().getTestDisplayValue()); } error = new ActionError("testsmanagement.message.multiple.test.not.canceled.verified", stringOfTests.toString(), null); } else { Analysis analysis = (Analysis) verifiedTests.get(0); error = new ActionError("testsmanagement.message.one.test.not.canceled.verified", "\\n " + analysis.getTest().getTestDisplayValue(), null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); } saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); } } } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TestManagementCancelTests", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { error = new ActionError("errors.UpdateException", null, null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); request.setAttribute(ALLOW_EDITS_KEY, "false"); return mapping.findForward(FWD_FAIL); } finally { HibernateUtil.closeSession(); } return mapping.findForward(forward); }
From source file:com.gorillalogic.monkeytalk.ant.RunTask.java
public void sendReport() { try {// w ww. j a v a 2s . com File zippedReports = FileUtils.zipDirectory(reportdir, true, false); System.out.println(zippedReports.getAbsolutePath()); Map<String, String> additionalParams = new HashMap<String, String>(); StringTokenizer st2 = new StringTokenizer(jobrefparams, ","); while (st2.hasMoreElements()) { String param = (String) st2.nextElement(); StringTokenizer st3 = new StringTokenizer(param, ":"); additionalParams.put((String) st3.nextElement(), (String) st3.nextElement()); } sendFormPost(callbackurl, zippedReports, additionalParams); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.jengine.mbean.FTPHL7Client.java
private void initializeQueueConnection() { try {//from w w w. j a v a2s . c o m if (session != null) session.close(); ctx = getInitialContext(); factory = (QueueConnectionFactory) ctx.lookup(CONNECTION_FACTORY); connection = factory.createQueueConnection(); session = connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); StringTokenizer st = new StringTokenizer(QueueNames, ":"); while (st.hasMoreElements()) { queue = (Queue) ctx.lookup("queue/" + st.nextElement()); Queues.add(queue); qSender = session.createSender(queue); QSenders.add(qSender); } } catch (JMSException je) { je.printStackTrace(); } catch (NamingException ne) { ne.printStackTrace(); } }
From source file:com.sshtools.j2ssh.transport.AbstractKnownHostsKeyVerification.java
/** * <p>//from www. jav a2s. co m * Removes an allowed host. * </p> * * @param host the host to remove * * @since 0.2.0 */ public void removeAllowedHost(String host) { Iterator it = allowedHosts.keySet().iterator(); while (it.hasNext()) { StringTokenizer tokens = new StringTokenizer((String) it.next(), ","); while (tokens.hasMoreElements()) { String name = (String) tokens.nextElement(); if (name.equals(host)) { allowedHosts.remove(name); } } } }
From source file:util.IPChecker.java
private void validateIP4(final String ip, final IPForm ranges) { // get IP parts final List<String> parts = new ArrayList<String>(); final StringTokenizer tokenizer = new StringTokenizer(ip, "."); while (tokenizer.hasMoreElements()) { parts.add(tokenizer.nextElement().toString().trim()); }//from w ww. ja va 2 s .c o m // validate each part... if (isValidIP4Parts(parts)) { ranges.getIp4().add(ip); } else { ranges.getInvalidIPs().add(ip); } }