List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:net.spfbl.data.Block.java
public static String findSender(String userEmail, String sender, String validation, String recipient, String recipientDomain, TreeSet<String> whoisSet, TreeSet<String> regexSet) { // Verifica o remetente. if (sender != null && sender.contains("@")) { sender = sender.toLowerCase();//from w w w .java 2s . c om if (sender.startsWith("srs0=") || sender.startsWith("srs0+")) { int index = sender.lastIndexOf('@'); String senderOriginal = sender.substring(0, index); if (senderOriginal.startsWith("srs0+")) { senderOriginal = senderOriginal.replaceFirst("^srs0\\+", "srs0="); } StringTokenizer tokenizer = new StringTokenizer(senderOriginal, "="); if (tokenizer.countTokens() == 5) { tokenizer.nextToken(); tokenizer.nextToken(); tokenizer.nextToken(); String senderDomain = tokenizer.nextToken(); String part = tokenizer.nextToken(); senderOriginal = part + '@' + senderDomain; String block = Block.find(userEmail, senderOriginal, false, true, true, false); if (block != null) { return block; } } } int index1 = sender.indexOf('@'); int index2 = sender.lastIndexOf('@'); String part = sender.substring(0, index1 + 1); String senderDomain = sender.substring(index2); String host; if (SET.contains(sender)) { return sender; } else if (SET.contains(sender + ';' + validation + '>' + recipient)) { return sender + ';' + validation + '>' + recipient; } else if (SET.contains(sender + ';' + validation + '>' + recipientDomain)) { return sender + ';' + validation + '>' + recipientDomain; } else if (SET.contains(sender + ';' + validation)) { return sender + ';' + validation; } else if (SET.contains(sender + ';' + validation + '>' + recipient)) { return sender + ';' + validation + '>' + recipient; } else if (SET.contains(sender + ';' + validation + '>' + recipientDomain)) { return sender + ';' + validation + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + sender)) { return userEmail + ':' + sender; } else if (userEmail != null && SET.contains(userEmail + ':' + sender + '>' + recipient)) { return userEmail + ':' + sender + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + sender + '>' + recipientDomain)) { return userEmail + ':' + sender + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + sender + ';' + validation)) { return userEmail + ':' + sender + ';' + validation; } else if (userEmail != null && SET.contains(userEmail + ':' + sender + ';' + validation + '>' + recipient)) { return userEmail + ':' + sender + ';' + validation + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + sender + ';' + validation + '>' + recipientDomain)) { return userEmail + ':' + sender + ';' + validation + '>' + recipientDomain; } else if (SET.contains(part)) { return part; } else if (SET.contains(part + '>' + recipient)) { return part + '>' + recipient; } else if (SET.contains(part + '>' + recipientDomain)) { return part + '>' + recipientDomain; } else if (SET.contains(part + ';' + validation)) { return part + ';' + validation; } else if (SET.contains(part + ';' + validation + '>' + recipient)) { return part + ';' + validation + '>' + recipient; } else if (SET.contains(part + ';' + validation + '>' + recipientDomain)) { return part + ';' + validation + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + part)) { return userEmail + ':' + part; } else if (userEmail != null && SET.contains(userEmail + ':' + part + '>' + recipient)) { return userEmail + ':' + part + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + part + '>' + recipientDomain)) { return userEmail + ':' + part + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + part + ';' + validation)) { return userEmail + ':' + part + ';' + validation; } else if (userEmail != null && SET.contains(userEmail + ':' + part + ';' + validation + '>' + recipient)) { return userEmail + ':' + part + ';' + validation + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + part + ';' + validation + '>' + recipientDomain)) { return userEmail + ':' + part + ';' + validation + '>' + recipientDomain; } else if (SET.contains(senderDomain)) { return senderDomain; } else if (SET.contains(senderDomain + '>' + recipient)) { return senderDomain + '>' + recipient; } else if (SET.contains(senderDomain + '>' + recipientDomain)) { return senderDomain + '>' + recipientDomain; } else if (SET.contains(senderDomain + ';' + validation)) { return senderDomain + ';' + validation; } else if (SET.contains(senderDomain + ';' + validation + '>' + recipient)) { return senderDomain + ';' + validation + '>' + recipient; } else if (SET.contains(senderDomain + ';' + validation + '>' + recipientDomain)) { return senderDomain + ';' + validation + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain)) { return userEmail + ':' + senderDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain + '>' + recipient)) { return userEmail + ':' + senderDomain + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain + '>' + recipientDomain)) { return userEmail + ':' + senderDomain + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain + ';' + validation)) { return userEmail + ':' + senderDomain + ';' + validation; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain + ';' + validation + '>' + recipient)) { return userEmail + ':' + senderDomain + ';' + validation + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + senderDomain + ';' + validation + '>' + recipientDomain)) { return userEmail + ':' + senderDomain + ';' + validation + '>' + recipientDomain; } else if ((host = findHost(userEmail, sender, "." + senderDomain.substring(1), validation, recipient, recipientDomain, whoisSet, regexSet, false)) != null) { return host; } else if (recipient != null && SET.contains("@>" + recipient)) { return "@>" + recipient; } else if (recipientDomain != null && SET.contains("@>" + recipientDomain)) { return "@>" + recipientDomain; } else if (recipient != null && userEmail != null && SET.contains(userEmail + ":@>" + recipient)) { return userEmail + ":@>" + recipient; } else if (recipientDomain != null && userEmail != null && SET.contains(userEmail + ":@>" + recipientDomain)) { return userEmail + ":@>" + recipientDomain; } else if (recipient != null && SET.contains("@;" + validation)) { return "@;" + validation; } else if (recipient != null && SET.contains("@;" + validation + ">" + recipient)) { return "@;" + validation + ">" + recipient; } else if (recipientDomain != null && SET.contains("@;" + validation + ">" + recipientDomain)) { return "@;" + validation + ">" + recipientDomain; } else if (recipient != null && userEmail != null && SET.contains(userEmail + ":@;" + validation)) { return userEmail + ":@;" + validation; } else if (recipient != null && userEmail != null && SET.contains(userEmail + ":@;" + validation + ">" + recipient)) { return userEmail + ":@;" + validation + ">" + recipient; } else if (recipientDomain != null && userEmail != null && SET.contains(userEmail + ":@;" + validation + ">" + recipientDomain)) { return userEmail + ":@;" + validation + ">" + recipientDomain; } else { int index3 = senderDomain.length(); while ((index3 = senderDomain.lastIndexOf('.', index3 - 1)) > index2) { String subdomain = senderDomain.substring(0, index3 + 1); if (SET.contains(subdomain)) { return subdomain; } else if (SET.contains(subdomain + '>' + recipient)) { return subdomain + '>' + recipient; } else if (SET.contains(subdomain + '>' + recipientDomain)) { return subdomain + '>' + recipientDomain; } else if (SET.contains(subdomain + ';' + validation)) { return subdomain + ';' + validation; } else if (SET.contains(subdomain + ';' + validation + '>' + recipient)) { return subdomain + ';' + validation + '>' + recipient; } else if (SET.contains(subdomain + ';' + validation + '>' + recipientDomain)) { return subdomain + ';' + validation + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + subdomain)) { return userEmail + ':' + subdomain; } else if (userEmail != null && SET.contains(userEmail + ':' + subdomain + '>' + recipient)) { return userEmail + ':' + subdomain + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + subdomain + '>' + recipientDomain)) { return userEmail + ':' + subdomain + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + subdomain + ';' + validation)) { return userEmail + ':' + subdomain + ';' + validation; } else if (userEmail != null && SET.contains(userEmail + ':' + subdomain + ';' + validation + '>' + recipient)) { return userEmail + ':' + subdomain + ';' + validation + '>' + recipient; } else if (userEmail != null && SET .contains(userEmail + ':' + subdomain + ';' + validation + '>' + recipientDomain)) { return userEmail + ':' + subdomain + ';' + validation + '>' + recipientDomain; } } int index4 = sender.length(); while ((index4 = sender.lastIndexOf('.', index4 - 1)) > index2) { String subsender = sender.substring(0, index4 + 1); if (SET.contains(subsender)) { return subsender; } else if (SET.contains(subsender + '>' + recipient)) { return subsender + '>' + recipient; } else if (SET.contains(subsender + '>' + recipientDomain)) { return subsender + '>' + recipientDomain; } else if (SET.contains(subsender + ';' + validation)) { return subsender + ';' + validation; } else if (SET.contains(subsender + ';' + validation + '>' + recipient)) { return subsender + ';' + validation + '>' + recipient; } else if (SET.contains(subsender + ';' + validation + '>' + recipientDomain)) { return subsender + ';' + validation + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + subsender)) { return userEmail + ':' + subsender; } else if (userEmail != null && SET.contains(userEmail + ':' + subsender + '>' + recipient)) { return userEmail + ':' + subsender + '>' + recipient; } else if (userEmail != null && SET.contains(userEmail + ':' + subsender + '>' + recipientDomain)) { return userEmail + ':' + subsender + '>' + recipientDomain; } else if (userEmail != null && SET.contains(userEmail + ':' + subsender + ';' + validation)) { return userEmail + ':' + subsender + ';' + validation; } else if (userEmail != null && SET.contains(userEmail + ':' + subsender + ';' + validation + '>' + recipient)) { return userEmail + ':' + subsender + ';' + validation + '>' + recipient; } else if (userEmail != null && SET .contains(userEmail + ':' + subsender + ';' + validation + '>' + recipientDomain)) { return userEmail + ':' + subsender + ';' + validation + '>' + recipientDomain; } } } if (senderDomain.endsWith(".br")) { whoisSet.add(senderDomain); } regexSet.add(sender); regexSet.add(senderDomain); } return null; }
From source file:com.skilrock.lms.web.scratchService.inventoryMgmt.common.AgentDispatchGameAction.java
public String verifyBookSeries() throws Exception { // update by arun Connection conn = DBConnect.getConnection(); try {//from www .jav a 2 s . com boolean isValid = false; boolean isSeriesValid = true; int gameId = getGameId(); HttpSession session = getRequest().getSession(); UserInfoBean userInfoBean = (UserInfoBean) session.getAttribute("USER_INFO"); int agtOrgId = userInfoBean.getUserOrgId(); List<BookBean> bookList = new ArrayList(); List<BookBean> bookSeriesList = new ArrayList(); List bookSeriesAll = new ArrayList(); session.setAttribute("BOOK_SERIES_ALL", bookSeriesAll); session.setAttribute("AGT_BOOK_LIST", bookList); session.setAttribute("BOOK_SERIES_LIST", bookSeriesList); StringTokenizer bookNbrFrmTok = new StringTokenizer(((String[]) bookNbrFromArr)[0], ","); StringTokenizer bookNbrToTok = new StringTokenizer(((String[]) bookNbrToArr)[0], ","); bookNbrFrmStr = new String[bookNbrFrmTok.countTokens()]; bookNbrToStr = new String[bookNbrToTok.countTokens()]; int frmTok = 0; while (bookNbrFrmTok.hasMoreTokens()) { bookNbrFrmStr[frmTok] = bookNbrFrmTok.nextToken(); bookNbrToStr[frmTok] = bookNbrToTok.nextToken(); frmTok = frmTok + 1; } System.out.println("---Series length" + bookNbrFrmStr); if (bookNbrFrmStr != null) { for (int seriesNo = 0; seriesNo < bookNbrFrmStr.length; seriesNo++) { if (bookNbrFrmStr[seriesNo] != "") { String bookNbrFrom = bookNbrFrmStr[seriesNo]; String bookNbrTo = bookNbrToStr[seriesNo]; int bookNbrFrmInt = Integer.parseInt(bookNbrFrom.replaceAll("-", "")); int bookNbrToInt = Integer.parseInt(bookNbrTo.replaceAll("-", "")); int noOfbooks = bookNbrToInt - bookNbrFrmInt; BookSeriesBean bookSeBean = new BookSeriesBean(); bookSeBean.setBookNbrFrom(bookNbrFrom); bookSeBean.setBookNbrTo(bookNbrTo); bookSeBean.setStatus(""); bookSeBean.setValid(isValid); for (int i = 0; i < noOfbooks + 1; i++) { String bookNbr = String.valueOf(bookNbrFrmInt); if (bookNbr != null && !bookNbr.trim().equals("")) { // add hyphens if necessary System.out.println(":::::::::" + bookNbr.indexOf("-")); if (bookNbr.indexOf("-") == -1) { OrderedGameBean orderedGameBean = (OrderedGameBean) session .getAttribute("AGT_ORDERED_GAME"); bookNbr = bookNbr.substring(0, orderedGameBean.getGameNbrDigits()) + "-" + bookNbr.substring(orderedGameBean.getGameNbrDigits()); System.out.println("New book nbr:::" + bookNbr); } System.out.println("---------------vvvvvvvvvvvvv----------" + bookNbr); AgentDispatchGameHelper helper = new AgentDispatchGameHelper(); isValid = helper.verifyBook(gameId, agtOrgId, bookNbr, conn, gameNbr); if (isValid) { BookBean bookBean = new BookBean(); bookBean.setValid(true); bookBean.setBookNumber(bookNbr); for (BookBean bean : bookSeriesList) { if (bookNbr.equals(bean.getBookNumber())) { isSeriesValid = false; bookSeBean.setStatus("Series Contains Tickets of Another Series"); break;// New series contains // ticket of old series } } if (isSeriesValid) { bookSeriesList.add(bookBean); } } else { isSeriesValid = false; bookSeBean.setStatus("Series Not Valid"); break;// Series not valid } } System.out.println("inside for of verifyBookSeries"); bookNbrFrmInt++; } if (isSeriesValid) { bookSeBean.setValid(true); session.setAttribute("BOOK_SERIES_LIST", bookSeriesList); } bookSeriesAll.add(bookSeBean); session.setAttribute("BOOK_SERIES_ALL", bookSeriesAll); // changeDispatchBooks(); // System.out.println("@@@@@@@@@@@@@################$$$$$$$$$$$$$%%%%%%%%%%%%%%%%"); } } } verifyIndividualBooks(bookList); for (int i = 0; i < bookSeriesList.size(); i++) { for (int j = 0; j < bookList.size(); j++) { // System.out.println(bookSeriesList.size()+"-Gaura // Test--"+bookList.size()); if (((BookBean) bookList.get(j)).getBookNumber() .equals(((BookBean) bookSeriesList.get(i)).getBookNumber())) { BookBean bean = (BookBean) bookList.get(j); bean.setValid(false); bean.setStatus("Book Number already in Book Series"); } } } setBookList(bookList); session.setAttribute("AGT_BOOK_LIST", bookList); changeDispatchBooks(); System.out.println("---------Trying to prevent caching------" + bookList); HttpServletResponse response = getResponse(); response.setHeader("Pragma", "no-cache"); // HTTP 1.0 response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1 response.setDateHeader("Expires", 0); // prevents caching at the // proxy server response.setHeader("Cache-Control", "private"); // HTTP 1.1 response.setHeader("Cache-Control", "no-store"); // HTTP 1.1 response.setHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 return SUCCESS; } finally { conn.close(); } }
From source file:com.alkacon.opencms.formgenerator.CmsFormHandler.java
/** * Creates a list of Internet addresses (email) from a semicolon separated String.<p> * //w w w . j ava2s. c o m * @param mailAddresses a semicolon separated String with email addresses * @return list of Internet addresses (email) * @throws AddressException if an email address is not correct */ protected List<InternetAddress> createInternetAddresses(String mailAddresses) throws AddressException { if (CmsStringUtil.isNotEmpty(mailAddresses)) { // at least one email address is present, generate list StringTokenizer T = new StringTokenizer(mailAddresses, ";"); List<InternetAddress> addresses = new ArrayList<InternetAddress>(T.countTokens()); while (T.hasMoreTokens()) { InternetAddress address = new InternetAddress(T.nextToken()); addresses.add(address); } return addresses; } else { // no address given, return empty list return Collections.emptyList(); } }
From source file:com.aurel.track.exchange.msProject.exporter.MsProjectExporterBL.java
/** * Add or update the task/* w w w . ja va 2s . c om*/ * * @param taskElement * @param workItemBean * @param msProjectTaskBean * @param taskID * @param outlineStructure * @param budgetBean * @param actualEstimatedBudgetBean * @param hoursPerWorkday * @param workItemCosts * @param hasChildren * @param defaultTaskType * @param durationFormat * @param isNew */ private static void addUpdateTask(ProjectFile project, Task taskElement, TWorkItemBean workItemBean, TMSProjectTaskBean msProjectTaskBean, int taskID, OutlineStructure outlineStructure, TComputedValuesBean computedValueBean, TActualEstimatedBudgetBean actualEstimatedBudgetBean, Double hoursPerWorkday, List<TCostBean> workItemCosts, boolean hasChildren, Integer defaultTaskType, Integer durationFormat, boolean isNew, Map<Integer, Map<String, List<String[]>>> calendarUIDBasedBaseCalendarExceptionWorkingTimes, Map<Integer, Map<Integer, List<String[]>>> calendarUIDBasedBaseCalendarWeekDayWorkingTimes, LocalLookupContainer localLookupContainer) { outlineStructure.incCurrentLevel(); SystemWBSRT systemWbs = new SystemWBSRT(); if (msProjectTaskBean.getUniqueID() != null) { if (taskElement == null) { taskElement = project.addTask(); } // taskElement.setUniqueID( msProjectTaskBean.getUniqueID()); taskElement.setConstraintType(ConstraintType.getInstance(msProjectTaskBean.getConstraintType())); taskElement.setConstraintDate(msProjectTaskBean.getConstraintDate()); taskElement.setDeadline(msProjectTaskBean.getDeadline()); } // taskElement.setID(Integer.valueOf(taskID)); taskElement.setName(workItemBean.getSynopsis()); taskElement.setUniqueID(workItemBean.getObjectID()); if (isNew && defaultTaskType != null) { taskElement.setType(TaskType.getInstance(defaultTaskType)); } taskElement.setCreateDate(workItemBean.getCreated()); String wbs = systemWbs.getShowValue(SystemFields.WBS, null, workItemBean.getWBSOnLevel(), workItemBean.getObjectID(), localLookupContainer, null); taskElement.setOutlineNumber(wbs); // taskElement.setID(workItemBean.getIDNumber()); StringTokenizer stringTokenizer = new StringTokenizer(wbs, "."); int numberOfLevels = stringTokenizer.countTokens() - 1; if (numberOfLevels == 0) { taskElement.setOutlineLevel(1); } else { taskElement.setOutlineLevel(numberOfLevels + 1); } /* * if(msProjectTaskBean.getOutlineNumber() != null) { * taskElement.setOutlineNumber(msProjectTaskBean.getOutlineNumber()); * }else { // * taskElement.setOutlineLevel(outlineStructure.getAbsoluteLevel()); } */ if (workItemBean.getStartDate() != null && workItemBean.getEndDate() != null) { taskElement.setStart(workItemBean.getTopDownStartDate()); taskElement.setActualStart(workItemBean.getStartDate()); taskElement.setActualFinish(workItemBean.getEndDate()); /* * taskElement.setEarlyStart(workItemBean.getStartDate()); * taskElement.setLateStart(workItemBean.getStartDate()); * taskElement.setEarlyFinish(workItemBean.getEndDate()); * taskElement.setLateFinish(workItemBean.getEndDate()); */ taskElement.setFinish(workItemBean.getTopDownEndDate()); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); if (formatter.format(workItemBean.getStartDate()) .compareTo(formatter.format(workItemBean.getEndDate())) == 0) { taskElement.setDuration(Duration.getInstance(1, TimeUnit.DAYS)); taskElement.setManualDuration(Duration.getInstance(1, TimeUnit.DAYS)); } else { int days = Days.daysBetween(new DateTime(workItemBean.getStartDate()), new DateTime(workItemBean.getEndDate())).getDays(); taskElement.setDuration(Duration.getInstance(days, TimeUnit.DAYS)); } } else if (workItemBean.getStartDate() != null && workItemBean.getEndDate() == null) { taskElement.setStart(workItemBean.getStartDate()); taskElement.setMilestone(true); } taskElement.setPercentageComplete(0); taskElement.setPercentageWorkComplete(0); taskElement.setNotes(workItemBean.getDescription()); // from budgetBean we need only the time unit because the // exported budget is the sum of actual work and remaining work if (computedValueBean != null) { // prepare this transformed values for hasChanged because the // MSProject work seems to be in hours TODO? /* * Double transformedHours = * AccountingBL.transformToTimeUnits(budgetBean.getEstimatedHours(), * hoursPerWorkday, budgetBean.getTimenit(), * AccountingBL.TIMEUNITS.HOURS); if (transformedHours!=null) { * plannedWorkHours = transformedHours.doubleValue(); } */ if (isNew && durationFormat == null) { // for new projects (without previous import the project level // durationFormat is null) if (AccountingBL.TIMEUNITS.HOURS.equals(computedValueBean.getMeasurementUnit())) { durationFormat = LAG_FORMAT.h; } else { durationFormat = LAG_FORMAT.d; } } } // TODO should we set the duration? // Element durationElement = // MsProjectExchangeDOMHelper.getChildByName(taskElement, // TASK_ELEMENTS.Duration); if (isNew && durationFormat != null) { // TODO setDuartionFormat method missing // MsProjectExchangeDOMHelper.setChildTextByName(taskElement, // TASK_ELEMENTS.DurationFormat, durationFormat.toString(), false); // taskElement.setDuration(Duration.getInstance(arg0, // durationFormat)); } int summary; if (hasChildren) { summary = TASK_SUMMARY_TYPE.SUMMARY; } else { summary = TASK_SUMMARY_TYPE.NOT_SUMMARY; } taskElement.setSummary(summary > 0 ? true : false); double actualHours = getSumOfActualWorks(workItemCosts); try { // taskElement.setActualDuration(Duration.getInstance(actualHours, // TimeUnit.HOURS)); } catch (Exception ex) { LOGGER.error("Date parse error: " + ex.getMessage()); } double remainingWorkHours = 0.0; if (actualEstimatedBudgetBean != null) { Double transformedHours = AccountingBL.transformToTimeUnits( actualEstimatedBudgetBean.getEstimatedHours(), hoursPerWorkday, actualEstimatedBudgetBean.getTimeUnit(), AccountingBL.TIMEUNITS.HOURS); if (transformedHours != null) { remainingWorkHours = transformedHours.doubleValue(); } } else { if (isNew && Math.abs(actualHours) < EPSILON && workItemBean.getStartDate() != null && workItemBean.getEndDate() != null) { // "simulate" a remaining value for issue in order to appear the // startDate and endDate in MSProject // as it was set in Genji although to work was set in Genji. Date dateFrom = workItemBean.getStartDate(); Calendar calendar = Calendar.getInstance(); calendar.setTime(dateFrom); CalendarUtil.clearTime(calendar); List<String[]> workingPeriods = null; while (calendar.getTime().before(workItemBean.getEndDate()) || calendar.getTime().getTime() == workItemBean.getEndDate().getTime()) { try { workingPeriods = getWorkingTimeForDay(null, null, calendarUIDBasedBaseCalendarExceptionWorkingTimes.values().iterator().next(), calendarUIDBasedBaseCalendarWeekDayWorkingTimes.values().iterator().next(), calendar.getTime()); } catch (Exception ex) { LOGGER.debug("Element missing: " + ex.getMessage()); } if (workingPeriods != null) { for (Iterator itrWorkPeriod = workingPeriods.iterator(); itrWorkPeriod.hasNext();) { // try each workingTime interval to see where the // work can be added String[] workingTime = (String[]) itrWorkPeriod.next(); String fromTime = workingTime[0]; String toTime = workingTime[1]; Map<String, Integer> timeUnitsMapFromTime = MsProjectExchangeBL .getTimeUnitsMapFromCalendarTime(fromTime); Map<String, Integer> timeUnitsMapToTime = MsProjectExchangeBL .getTimeUnitsMapFromCalendarTime(toTime); double hourDiff = MsProjectExchangeBL.getHoursDiff(timeUnitsMapFromTime, timeUnitsMapToTime); remainingWorkHours += hourDiff; } } calendar.add(Calendar.DATE, 1); } } } taskElement.setRemainingWork(Duration.getInstance(remainingWorkHours, TimeUnit.HOURS)); taskElement.setRemainingDuration(Duration.getInstance(remainingWorkHours, TimeUnit.HOURS)); // the planned work is forced to be the sum of actual work and actual // hours // (instead of the plannedWorkHours) because otherwise MSProject result // is not consistent taskElement.setWork(Duration.getInstance(remainingWorkHours + actualHours, TimeUnit.HOURS)); int days = Days .daysBetween(new DateTime(workItemBean.getStartDate()), new DateTime(workItemBean.getEndDate())) .getDays(); taskElement.setDuration(Duration.getInstance(days, TimeUnit.DAYS)); taskElement.setActualWork(null); // not really needed to update because in track+ UI they are not // modifiable: for new tasks // the msProjectTaskBean is new for existing tasks they can be taken // from the last imported file if (isNew && Math.abs(actualHours) < EPSILON) { if (workItemBean.getStartDate() != null) { msProjectTaskBean.setConstraintType(CONSTRAINT_TYPE.START_NO_EARLIER_THAN); msProjectTaskBean.setConstraintDate(workItemBean.getStartDate()); } else { if (workItemBean.getEndDate() != null) { msProjectTaskBean.setConstraintType(CONSTRAINT_TYPE.FINISH_NO_LATER_THAN); msProjectTaskBean.setConstraintDate(workItemBean.getEndDate()); } } } }
From source file:org.apache.click.service.XmlConfigService.java
private void loadLocale(Element rootElm) { String value = rootElm.getAttribute("locale"); if (value != null && value.length() > 0) { StringTokenizer tokenizer = new StringTokenizer(value, "_"); if (tokenizer.countTokens() == 1) { String language = tokenizer.nextToken(); locale = new Locale(language); } else if (tokenizer.countTokens() == 2) { String language = tokenizer.nextToken(); String country = tokenizer.nextToken(); locale = new Locale(language, country); }//from w w w . j a v a 2 s.co m } }
From source file:edu.jhu.cvrg.services.nodeDataService.DataStaging.java
private HSSFSheet consolidateAlgorithmFiles(int algorithmCode, HSSFSheet sheet, String subjectIds, String userId, String fileNames, boolean isPublic, ApacheCommonsFtpWrapper ftpClient) { boolean firstToken = true; StringTokenizer tokenizer = new StringTokenizer(subjectIds, "^"); StringTokenizer fileTokenizer = new StringTokenizer(fileNames, "^"); String currentSubject = null; int lineNumber = 0; String headerIndicator = null; switch (algorithmCode) { case 0:/*from w ww.j a v a2 s. c o m*/ headerIndicator = CHESNOKOV_HEADER_INDICATOR; break; case 1: headerIndicator = BERGER_HEADER_INDICATOR; break; } String directory = localFtpRoot + sep + userId + utils.generateTimeStamp(); while (tokenizer.hasMoreTokens() && fileTokenizer.hasMoreTokens()) { currentSubject = tokenizer.nextToken(); System.out.println(currentSubject); String file = fileTokenizer.nextToken(); String bareFile = file.substring(file.lastIndexOf("/") + 1); try { ftpClient.downloadFile(file, directory + bareFile); FileReader fi = new FileReader(directory + bareFile); BufferedReader br = new BufferedReader(fi); String thisLine = null, value = null; int inputLineNumber = 0; while ((thisLine = br.readLine()) != null) { boolean isHeader = false; isHeader = thisLine.contains(headerIndicator); if (thisLine != null && thisLine.length() > 0 && (firstToken || !isHeader)) { HSSFRow rowOut = sheet.createRow(lineNumber); StringTokenizer rowTokenizer = new StringTokenizer(thisLine, ","); HSSFCell cellOut; int colNumber = 0; while (rowTokenizer.hasMoreTokens()) { cellOut = rowOut.createCell(colNumber); String replacePipes = rowTokenizer.nextToken(); if (isHeader) { replacePipes = replacePipes.replaceAll("\\|", ","); value = replacePipes; StringTokenizer temp = new StringTokenizer(replacePipes, ","); if (temp.countTokens() > 1) { HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); link.setAddress(temp.nextToken()); cellOut.setHyperlink(link); value = temp.nextToken().trim(); } cellOut.setCellValue(value); sheet.setColumnWidth(colNumber, (value.length() + 3) * 256); } else { cellOut.setCellValue(replacePipes); if (sheet.getColumnWidth(colNumber) / 256 < replacePipes.length()) sheet.setColumnWidth(colNumber, replacePipes.length() * 256); } colNumber++; } lineNumber++; } inputLineNumber++; } fi.close(); br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //} firstToken = false; } return sheet; }
From source file:com.concursive.connect.web.modules.documents.utils.HttpMultiPartParser.java
/** * Description of the Method//from w ww . j a va 2 s. c o m * * @param saveInDir Description of Parameter * @param request Description of the Parameter * @return Description of the Returned Value * @throws IllegalArgumentException Description of Exception * @throws IOException Description of Exception */ private HashMap processData(HttpServletRequest request, String saveInDir) throws IllegalArgumentException, IOException { String contentType = request.getHeader("Content-type"); //TODO: use the contentLength for a progress bar int contentLength = request.getContentLength(); LOG.debug("HttpMultiPartParser Length: " + contentLength); if ((contentType == null) || (!contentType.startsWith("multipart/"))) { throw new IllegalArgumentException("Not a multipart message"); } int boundaryIndex = contentType.indexOf("boundary="); String boundary = contentType.substring(boundaryIndex + 9); LOG.debug("Request boundary: " + boundary); ServletInputStream is = request.getInputStream(); if (is == null) { throw new IllegalArgumentException("InputStream"); } if (boundary == null || boundary.trim().length() < 1) { throw new IllegalArgumentException("boundary"); } //Each content will begin with two dashes "--" plus the actual boundary string boundary = "--" + boundary; //Prepare to read in from request StringTokenizer stLine = null; StringTokenizer stFields = null; FileInfo fileInfo = null; HashMap dataTable = new HashMap(5); String line = null; String field = null; String paramName = null; boolean saveFiles = (saveInDir != null && saveInDir.trim().length() > 0); boolean isFile = false; boolean validFile = false; int fileCount = 0; //First line should be the boundary line = getLine(is); if (line == null || !line.startsWith(boundary)) { throw new IOException("Boundary not found;" + " boundary = " + boundary + ", line = " + line); } //Continue with the rest of the lines while (line != null) { LOG.trace(line); // Process boundary line ---------------------------------------- if (line == null || !line.startsWith(boundary)) { return dataTable; } // Process "Content-Disposition: " line -------------------------- line = getLine(is); if (line == null) { return dataTable; } // Split line into the following 3 tokens (or 2 if not a file): // 1. Content-Disposition: form-data // 2. name="LocalFile1" // 3. filename="C:\autoexec.bat" (only present if this is part of a HTML file INPUT tag) */ stLine = new StringTokenizer(line, ";\r\n"); if (stLine.countTokens() < 2) { throw new IllegalArgumentException("Bad data in second line"); } // Confirm that this is "form-data" line = stLine.nextToken().toLowerCase(); if (line.indexOf("form-data") < 0) { throw new IllegalArgumentException("Bad data in second line"); } // Now split token 2 from above into field "name" and it's "value" // e.g. name="LocalFile1" stFields = new StringTokenizer(stLine.nextToken(), "=\""); if (stFields.countTokens() < 2) { throw new IllegalArgumentException("Bad data in second line"); } // Get field name fileInfo = new FileInfo(); fileInfo.setVersion(version); fileInfo.setExtensionId(extensionId); stFields.nextToken(); paramName = stFields.nextToken(); // Now split token 3 from above into file "name" and it's "value" // e.g. filename="C:\autoexec.bat" isFile = false; if (stLine.hasMoreTokens()) { field = stLine.nextToken(); stFields = new StringTokenizer(field, "=\""); if (stFields.countTokens() > 1) { if (stFields.nextToken().trim().equalsIgnoreCase("filename")) { fileInfo.setName(paramName); String value = stFields.nextToken(); if (value != null && value.trim().length() > 0) { fileInfo.setClientFileName(value); isFile = true; ++fileCount; } else { // An error condition occurred, skip to next boundary line = getLine(is); // Skip "Content-Type:" line line = getLine(is); // Skip blank line line = getLine(is); // Skip blank line line = getLine(is); // Position to boundary line continue; } } } else if (field.toLowerCase().indexOf("filename") >= 0) { // An error condition occurred, skip to next boundary line = getLine(is); // Skip "Content-Type:" line line = getLine(is); // Skip blank line line = getLine(is); // Skip blank line line = getLine(is); // Position to boundary line continue; } } // Process "Content-Type: " line ---------------------------------- // e.g. Content-Type: text/plain boolean skipBlankLine = true; if (isFile) { line = getLine(is); if (line == null) { return dataTable; } // "Content-type" line not guaranteed to be sent by the browser if (line.trim().length() < 1) { skipBlankLine = false; } else { // Prevent re-skipping below stLine = new StringTokenizer(line, ": "); if (stLine.countTokens() < 2) { throw new IllegalArgumentException("Bad data in third line"); } stLine.nextToken(); // Content-Type fileInfo.setFileContentType(stLine.nextToken()); } } // Skip blank line ----------------------------------------------- if (skipBlankLine) { // Blank line already skipped above? line = getLine(is); if (line == null) { return dataTable; } } // Process data: If not a file, add to hashmap and continue if (!isFile) { line = getLine(is); if (line == null) { return dataTable; } StringBuffer sb = new StringBuffer(); sb.append(line); while (line != null && !line.startsWith(boundary)) { line = getLine(is); if (line != null && !line.startsWith(boundary)) { sb.append(System.getProperty("line.separator")); sb.append(line); } } LOG.debug(" HttpMultiPartParser ->Adding param: " + paramName); dataTable.put(paramName, sb.toString()); continue; } // Either save contents in memory or to a local file OutputStream os = null; String path = null; try { String tmpPath = null; String filenameToUse = null; if (saveFiles) { if (usePathParam) { tmpPath = saveInDir + fileInfo.getName() + fs; } else { tmpPath = saveInDir; } if (useDateForFolder) { SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy"); String datePathToUse1 = formatter1.format(new java.util.Date()); SimpleDateFormat formatter2 = new SimpleDateFormat("MMdd"); String datePathToUse2 = formatter2.format(new java.util.Date()); tmpPath += datePathToUse1 + fs + datePathToUse2 + fs; } // Create output directory in case it doesn't exist File f = new File(tmpPath); f.mkdirs(); //If specified, store files using a unique name, based on date if (useUniqueName) { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); filenameToUse = formatter.format(new java.util.Date()); if (fileCount > 1) { filenameToUse += String.valueOf(fileCount); } } else { filenameToUse = fileInfo.getClientFileName(); } fileInfo.setClientFileName(getFileName(fileInfo.getClientFileName())); //Append a version id for record keeping and uniqueness, prevents //multiple uploads from overwriting each other filenameToUse += (version == -1 ? "" : "^" + version) + (extensionId == -1 ? "" : "-" + extensionId); //Create the file to a file os = new FileOutputStream(path = getFileName(tmpPath, filenameToUse)); } else { //Store the file in memory os = new ByteArrayOutputStream(ONE_MB); } //Begin reading in the request boolean readingContent = true; byte previousLine[] = new byte[2 * ONE_MB]; byte temp[] = null; byte currentLine[] = new byte[2 * ONE_MB]; int read; int read3; //read in the first line, break out if eof if ((read = is.readLine(previousLine, 0, previousLine.length)) == -1) { line = null; break; } //read until next boundary and write the contents to OutputStream while (readingContent) { if ((read3 = is.readLine(currentLine, 0, currentLine.length)) == -1) { line = null; break; } //check if current line is a boundary if (compareBoundary(boundary, currentLine)) { if (read - 2 > 0) { validFile = true; } os.write(previousLine, 0, read - 2); os.flush(); line = new String(currentLine, 0, read3); break; } else { //current line is not a boundary, write previous line os.write(previousLine, 0, read); validFile = true; os.flush(); //reposition previousLine to be currentLine temp = currentLine; currentLine = previousLine; previousLine = temp; read = read3; } } os.close(); temp = null; previousLine = null; currentLine = null; //Store the completed file somewhere if (!saveFiles) { ByteArrayOutputStream baos = (ByteArrayOutputStream) os; fileInfo.setFileContents(baos.toByteArray()); } else { File thisFile = new File(path); if (validFile) { fileInfo.setLocalFile(thisFile); fileInfo.setSize((int) thisFile.length()); os = null; } else { thisFile.delete(); } } if (validFile) { LOG.debug("Adding file param: " + fileInfo.getName()); dataTable.put(paramName, fileInfo); } } catch (Exception e) { LOG.error("HttpMultiPartParser-> error: " + e.getMessage(), e); if (os != null) { os.close(); } if (saveFiles && path != null) { File thisFile = new File(path); if (thisFile.exists()) { thisFile.delete(); LOG.warn("HttpMultiPartParser-> Temporary file deleted"); } } } } return dataTable; }
From source file:it.classhidra.core.controller.bean.java
public boolean setCampoValueWithPoint(String name, Object value) throws Exception { try {//from w w w . j a v a2s.c om if (name.indexOf('.') == -1) { if (delegated != null) { boolean res = setValue(delegated, "set" + util_reflect.adaptMethodName(name.trim()), new Object[] { value }, false); if (!res) res = setValue(this, "set" + util_reflect.adaptMethodName(name.trim()), new Object[] { value }, false); return res; } else { boolean res = setValue(this, "set" + util_reflect.adaptMethodName(name.trim()), new Object[] { value }, false); if (!res) { if (parametersFly == null) parametersFly = new HashMap(); parametersFly.put(name, value); } return res; } } else { StringTokenizer st = new StringTokenizer(name, "."); /* Vector allfields=new Vector(); while(st.hasMoreTokens()) allfields.add(st.nextToken()); String complexName=""; for(int i=0;i<allfields.size()-1;i++){ complexName+=allfields.get(i); if(i!=allfields.size()-2) complexName+="."; } Object writeObj=get(complexName); if(writeObj==null) writeObj=get(this,complexName); if(writeObj==null) return false; String current_field_name = (String)allfields.get(allfields.size()-1); */ String current_field_name = null; String complexName = ""; while (st.hasMoreTokens()) { String token = st.nextToken(); if (st.countTokens() > 0) complexName += token; if (st.countTokens() > 1) complexName += "."; if (st.countTokens() == 0) current_field_name = token; } Object writeObj = get(complexName); if (writeObj == null) writeObj = get(this, complexName); if (writeObj == null) return false; if (writeObj != null && current_field_name != null) { try { setCampoValuePoint(writeObj, current_field_name, value); return true; } catch (Exception e) { return false; } } return false; } } catch (Exception e) { throw e; } // return true; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
/** parse string list into List * * @param in/*from ww w .j a v a 2s .c om*/ * @return */ private List<Double> createList(String in) { String vs = in; // String[] values = in.split("( *)+,+( *)"); // int count = java.lang.reflect.Array.getLength(values); StringTokenizer st = new StringTokenizer(in, DELIMITERS); int count = st.countTokens(); String[] values = new String[count]; for (int i = 0; i < count; i++) values[i] = st.nextToken(); List<Double> result = new java.util.ArrayList<Double>(); try { for (int i = 0; i < count; i++) { double v = Double.parseDouble(values[i]); result.add(new Double(v)); } } catch (NumberFormatException e) { System.out.println("Data format error!"); return null; } return result; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
/** parse string list into double array * * @param in//from w w w. j av a 2 s .c o m * @return */ private Double[] createValueList(String in) { String vs = in; // String[] values = in.split("( *)+,+( *)"); //int count = java.lang.reflect.Array.getLength(values); StringTokenizer st = new StringTokenizer(in, DELIMITERS); int count = st.countTokens(); String[] values = new String[count]; for (int i = 0; i < count; i++) values[i] = st.nextToken(); Double[] result = new Double[count]; try { for (int i = 0; i < count; i++) { double v = Double.parseDouble(values[i]); result[i] = new Double(v); } } catch (NumberFormatException e) { System.out.println("Data format error!"); return null; } return result; }