List of usage examples for java.text NumberFormat parse
public Number parse(String source) throws ParseException
From source file:op.tools.SYSTools.java
public static Integer checkInteger(String txt) { Integer i = null;//w w w. j a va2s . c o m try { NumberFormat nf = DecimalFormat.getIntegerInstance(); Number number = nf.parse(txt); if (number instanceof Integer) { i = Integer.valueOf(number.intValue()); } else if (number instanceof Long) { i = Integer.valueOf(number.intValue()); } } catch (ParseException ex) { OPDE.debug(ex); // Pech } return i; }
From source file:org.gnucash.android.test.ui.TransactionsActivityTest.java
public void testToggleTransactionType() { mSolo.waitForText(DUMMY_ACCOUNT_NAME); validateTransactionListDisplayed();// w w w . ja v a 2s . c o m mSolo.clickOnText(TRANSACTION_NAME); mSolo.waitForText("Note"); validateEditTransactionFields(mTransaction); mSolo.clickOnButton(getActivity().getString(R.string.label_credit)); String amountString = mSolo.getEditText(1).getText().toString(); NumberFormat formatter = NumberFormat.getInstance(); try { amountString = formatter.parse(amountString).toString(); } catch (ParseException e) { e.printStackTrace(); } Money amount = new Money(amountString, Currency.getInstance(Locale.getDefault()).getCurrencyCode()); assertEquals("-9.99", amount.toPlainString()); clickSherlockActionBarItem(R.id.menu_save); mSolo.waitForText(DUMMY_ACCOUNT_NAME); TransactionsDbAdapter adapter = new TransactionsDbAdapter(getActivity()); List<Transaction> transactions = adapter.getAllTransactionsForAccount(DUMMY_ACCOUNT_UID); assertEquals(1, transactions.size()); Transaction trx = transactions.get(0); assertTrue(trx.getAmount().isNegative()); mSolo.goBack(); }
From source file:fr.ericlab.mabed.structure.Corpus.java
public void prepareCorpus() { System.out.println(Util.getDate() + " Preparing corpus..."); String[] fileArray = new File("input/").list(); nbTimeSlices = 0;//w ww.j a v a 2 s . co m NumberFormat formatter = new DecimalFormat("00000000"); ArrayList<Integer> list = new ArrayList<>(); for (String filename : fileArray) { if (filename.endsWith(".text")) { try { list.add(formatter.parse(filename.substring(0, 8)).intValue()); } catch (ParseException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } nbTimeSlices++; } } int a = Collections.min(list), b = Collections.max(list); LineIterator it = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S"); it = FileUtils.lineIterator(new File("input/" + formatter.format(a) + ".time"), "UTF-8"); if (it.hasNext()) { Date parsedDate = dateFormat.parse(it.nextLine()); startTimestamp = new java.sql.Timestamp(parsedDate.getTime()); } it = FileUtils.lineIterator(new File("input/" + formatter.format(b) + ".time"), "UTF-8"); String lastLine = ""; while (it.hasNext()) { lastLine = it.nextLine(); } Date parsedDate = dateFormat.parse(lastLine); endTimestamp = new java.sql.Timestamp(parsedDate.getTime()); } catch (IOException | ParseException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } finally { LineIterator.closeQuietly(it); } System.out.print(" - Computing word frequencies"); GlobalIndexer indexer = new GlobalIndexer(configuration.numberOfThreads, false); try { indexer.index("input/", configuration.stopwords); } catch (InterruptedException | IOException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } indexer = new GlobalIndexer(configuration.numberOfThreads, true); try { indexer.index("input/", configuration.stopwords); } catch (InterruptedException | IOException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(", 100% done."); }
From source file:op.tools.SYSTools.java
public static BigDecimal checkBigDecimal(String txt) { BigDecimal bd = null;// ww w. j av a 2 s .co m txt = assimilateDecimalSeparators(txt); try { NumberFormat nf = DecimalFormat.getNumberInstance(); Number number = nf.parse(txt); if (number instanceof Long) { bd = BigDecimal.valueOf(number.longValue()); } else if (number instanceof Double) { bd = BigDecimal.valueOf(number.doubleValue()); } else if (number instanceof BigDecimal) { bd = (BigDecimal) number; } } catch (ParseException ex) { OPDE.debug(ex); // Pech } return bd; }
From source file:web.DirectorygetblobController.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException/*from w w w. j a v a2s .c o m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // *************************************************************************** // This will initialize common data in the abstract class and // return result is of no value. // The abstract class initializes protected variables, // login, directoryid, logininfo. // Which can be accessed in all controllers if they want to. // *************************************************************************** logger.info("login = " + login); try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest", e); } if (!WebUtil.isProductRedbasinPortalDataCenter()) { if (!WebUtil.isLicenseProfessional(login)) { return handleError("Cannot access directory feature in deluxe version."); } if (WebUtil.isProductSecureBusinessDataCenter()) { outOfSession(request, response); if (RegexStrUtil.isNull(login) || loginInfo == null) { return handleUserpageError("Login or loginInfo is null, DirectorygetblobController"); } } } else { /* ok to access this in some portal product */ if (!WebUtil.isLicenseProfessional(login) && (!GlobalConst.hddomain.contains(DbConstants.INDIA_CENTURY))) { return handleError("Cannot access directory feature in deluxe version."); } } logger.info("login after checks = " + login); /** * users should be allowed to view the directory blobs without the session */ String directoryid = request.getParameter(DbConstants.DIRECTORY_ID); if (RegexStrUtil.isNull(directoryid)) { return handleError("request, directory is null, for directorygetblobController "); } if (directoryid.length() > GlobalConst.directoryidSize) { return handleError( "directoryid.length() > WebConstants.directoryidSize, for directorygetblobController "); } directoryid = RegexStrUtil.goodNameStr(directoryid); String blobtype = request.getParameter(DbConstants.BLOBTYPE); if (!RegexStrUtil.isNull(blobtype)) { int catValue = new Integer(blobtype).intValue(); if (catValue < GlobalConst.categoryMinSize || catValue > GlobalConst.categoryMaxSize) { return handleError("category/blobtype is > categoryMin/MaxSize, DirectorygetblobController"); } } DirectoryDao directoryDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (directoryDao == null) { return handleError("DirectoryDao is null in DirectorygetblobController directory"); } DirectoryStreamBlobDao blobDao = (DirectoryStreamBlobDao) daoMapper.getDao(DbConstants.DIR_BLOB); if (blobDao == null) { return handleError("DirectoryStreamBlobDao is null, DirectorygetblobController"); } String sortByStr = request.getParameter(DbConstants.SORT_BY); int sortBy = DbConstants.INTDATEDESC; if (!RegexStrUtil.isNull(sortByStr)) { logger.info("sortBy = " + sortByStr); sortBy = new Integer(sortByStr).intValue(); } String selection = DbConstants.DATE_DESC_STR; List tagList = null; Directory directory = null; List files = null; try { if (login != null && loginInfo != null) { // default is DATEASC directory = directoryDao.viewDirectory(directoryid, loginInfo.getValue(DbConstants.LOGIN_ID), login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_SLAVE, DbConstants.WEBSITE_READ_FROM_SLAVE); switch (sortBy) { case DbConstants.INTSIZEASC: files = blobDao.getFilesSortBySizeAsc(directoryid, blobtype, loginInfo.getValue(DbConstants.LOGIN_ID)); selection = DbConstants.SIZE_ASC_STR; break; case DbConstants.INTSIZEDESC: files = blobDao.getFilesSortBySizeDesc(directoryid, blobtype, loginInfo.getValue(DbConstants.LOGIN_ID)); selection = DbConstants.SIZE_DESC_STR; break; case DbConstants.INTNAMEASC: files = blobDao.getFilesSortByNameAsc(directoryid, blobtype, loginInfo.getValue(DbConstants.LOGIN_ID)); selection = DbConstants.NAME_ASC_STR; break; case DbConstants.INTNAMEDESC: files = blobDao.getFilesSortByNameDesc(directoryid, blobtype, loginInfo.getValue(DbConstants.LOGIN_ID)); selection = DbConstants.NAME_DESC_STR; break; case DbConstants.INTDATEASC: files = blobDao.getFilesSortByDateAsc(directoryid, blobtype, loginInfo.getValue(DbConstants.LOGIN_ID)); selection = DbConstants.DATE_ASC_STR; break; default: selection = DbConstants.DATE_DESC_STR; break; } } else { directory = directoryDao.viewDirectory(directoryid); } tagList = blobDao.getAllTags(directoryid, DbConstants.READ_FROM_SLAVE); } catch (BaseDaoException e) { return handleError("Exception occured in viewDirectory()/getAllTags/getFilesSortBy..() for directory() " + e.getMessage(), e); } if (directory == null) { return handleError("directory is null for directoryid = " + directoryid); } /** * collphotofolder or editblobfile - views */ String viewName = DbConstants.DIR_PHOTO_FOLDER; StringBuffer sb = new StringBuffer(); if (blobtype.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_DIR_BLOB_FILE; } /* else { */ if (tagList != null && tagList.size() > 0) { for (int i = 0; i < tagList.size(); i++) { Photo photo = (Photo) tagList.get(i); if (photo != null) { sb.append(photo.getValue(DbConstants.USER_TAGS)); sb.append(","); } } } /* } */ Directory cobrand = null; CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, DirectorygetblobController "); } try { cobrand = cobrandDao.getDirCobrand(directoryid); } catch (Exception e) { return handleError("exception getDirCobrand(), DirectorygetblobController ", e); } String pageNum = request.getParameter(DbConstants.PAGE_NUM); try { if (!RegexStrUtil.isNull(pageNum)) { NumberFormat nf = NumberFormat.getInstance(); Number mypageNum = nf.parse(pageNum); } } catch (ParseException e) { return handleError("pageNum has other than [0-9] characters, DirectorygetblobController.", e); } Map myModel = new HashMap(); myModel.put(DbConstants.LOGIN_INFO, loginInfo); if (sb != null) { myModel.put(DbConstants.USER_TAGS, sb.toString()); } else { myModel.put(DbConstants.USER_TAGS, " "); } myModel.put(DbConstants.DIRECTORY, directory); myModel.put(DbConstants.DIRNAME, directory.getValue(DbConstants.DIRNAME)); myModel.put(DbConstants.DIRECTORY_ID, directoryid); myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.IS_DIRECTORY, "1"); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); myModel.put(DbConstants.SORT_BY, sortByStr); myModel.put(DbConstants.PHOTOS, files); myModel.put(DbConstants.SELECTION, selection); return new ModelAndView(viewName, "model", myModel); }
From source file:com.concursive.connect.web.portal.PortalUtils.java
public static void populateObject(Object bean, ActionRequest request) { String nestedAttribute = "_"; Enumeration en = request.getParameterNames(); String paramName = null;//from w ww . j a va2 s . c o m while (en.hasMoreElements()) { paramName = (String) en.nextElement(); // a form has been submitted and requested to be auto-populated, // so we do that here..going through every element and trying // to call a setXXX() method on the bean object passed in for the value // of the request parameter currently being checked. String[] paramValues = request.getParameterValues(paramName); if (paramValues.length > 1) { ObjectUtils.setParam(bean, paramName, paramValues, nestedAttribute); } else { ObjectUtils.setParam(bean, paramName, paramValues[0], nestedAttribute); } } // TODO: currently for ticket and ticket history //ObjectUtils.invokeMethod(bean, "setRequestItems", new HttpRequestContext(request)); // Check for valid user User thisUser = (User) request.getAttribute(Constants.REQUEST_USER); if (thisUser != null) { // Populate date/time fields using the user's timezone and locale if (thisUser.getTimeZone() != null) { ArrayList timeParams = (ArrayList) ObjectUtils.getObject(bean, "TimeZoneParams"); if (timeParams != null) { Calendar cal = Calendar.getInstance(); Iterator i = timeParams.iterator(); while (i.hasNext()) { // The property that can be set String name = (String) i.next(); // See if it is in the request String value = request.getParameter(name); if (value != null) { // See if time is in request too String hourValue = request.getParameter(name + "Hour"); if (hourValue == null) { // Date fields: 1-1 mapping between HTML field and Java property ObjectUtils.setParam(bean, name, DateUtils.getUserToServerDateTimeString( TimeZone.getTimeZone(thisUser.getTimeZone()), DateFormat.SHORT, DateFormat.LONG, value, thisUser.getLocale())); } else { // Date & Time fields: 4-1 mapping between HTML fields and Java property try { Timestamp timestamp = DatabaseUtils.parseDateToTimestamp(value, thisUser.getLocale()); cal.setTimeInMillis(timestamp.getTime()); int hour = Integer.parseInt(hourValue); int minute = Integer.parseInt(request.getParameter(name + "Minute")); String ampmString = request.getParameter(name + "AMPM"); if (ampmString != null) { int ampm = Integer.parseInt(ampmString); if (ampm == Calendar.AM) { if (hour == 12) { hour = 0; } } else { if (hour < 12) { hour += 12; } } } cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.setTimeZone(TimeZone.getTimeZone(thisUser.getTimeZone())); ObjectUtils.setParam(bean, name, new Timestamp(cal.getTimeInMillis())); } catch (Exception dateE) { } } } } } } // Populate number fields using the user's locale if (thisUser.getLocale() != null) { ArrayList numberParams = (ArrayList) ObjectUtils.getObject(bean, "NumberParams"); if (numberParams != null) { NumberFormat nf = NumberFormat.getInstance(thisUser.getLocale()); Iterator i = numberParams.iterator(); while (i.hasNext()) { // The property that can be set String name = (String) i.next(); // See if it is in the request String value = (String) request.getParameter(name); if (value != null && !"".equals(value)) { try { // Parse the value ObjectUtils.setParam(bean, name, nf.parse(value).doubleValue()); } catch (Exception e) { //e.printStackTrace(System.out); } } } } } } }
From source file:fr.ericlab.mabed.structure.Corpus.java
public void loadCorpus(boolean parallelized) { output = "";/*from w w w. jav a2s. com*/ if (configuration.prepareCorpus) { prepareCorpus(); } String[] fileArray = new File("input/").list(); nbTimeSlices = 0; NumberFormat formatter = new DecimalFormat("00000000"); ArrayList<Integer> list = new ArrayList<>(); for (String filename : fileArray) { if (filename.endsWith(".text")) { try { list.add(formatter.parse(filename.substring(0, 8)).intValue()); } catch (ParseException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } nbTimeSlices++; } } int a = Collections.min(list), b = Collections.max(list); distribution = new int[nbTimeSlices]; messageCount = 0; LineIterator it = null; try { it = FileUtils.lineIterator(new File("input/" + formatter.format(a) + ".time"), "UTF-8"); if (it.hasNext()) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); Date parsedDate = dateFormat.parse(it.nextLine()); startTimestamp = new java.sql.Timestamp(parsedDate.getTime()); } it = FileUtils.lineIterator(new File("input/" + formatter.format(b) + ".time"), "UTF-8"); String timestamp = ""; while (it.hasNext()) { timestamp = it.nextLine(); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); Date parsedDate = dateFormat.parse(timestamp); endTimestamp = new java.sql.Timestamp(parsedDate.getTime()); } catch (IOException | ParseException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } finally { LineIterator.closeQuietly(it); } try { // Global index FileInputStream fisMatrix = new FileInputStream("input/indexes/frequencyMatrix.dat"); ObjectInputStream oisMatrix = new ObjectInputStream(fisMatrix); frequencyMatrix = (short[][]) oisMatrix.readObject(); FileInputStream fisVocabulary = new FileInputStream("input/indexes/vocabulary.dat"); ObjectInputStream oisVocabulary = new ObjectInputStream(fisVocabulary); vocabulary = (ArrayList<String>) oisVocabulary.readObject(); // Mention index FileInputStream fisMentionMatrix = new FileInputStream("input/indexes/mentionFrequencyMatrix.dat"); ObjectInputStream oisMentionMatrix = new ObjectInputStream(fisMentionMatrix); mentionFrequencyMatrix = (short[][]) oisMentionMatrix.readObject(); FileInputStream fisMentionVocabulary = new FileInputStream("input/indexes/mentionVocabulary.dat"); ObjectInputStream oisMentionVocabulary = new ObjectInputStream(fisMentionVocabulary); mentionVocabulary = (ArrayList<String>) oisMentionVocabulary.readObject(); // Message count String messageCountStr = FileUtils.readFileToString(new File("input/indexes/messageCount.txt")); messageCount = Integer.parseInt(messageCountStr); // Message count distribution FileInputStream fisDistribution = new FileInputStream("input/indexes/messageCountDistribution.dat"); ObjectInputStream oisDistribution = new ObjectInputStream(fisDistribution); distribution = (int[]) oisDistribution.readObject(); } catch (FileNotFoundException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex); } DecimalFormat df = new DecimalFormat("#,###"); System.out.println(Util.getDate() + " Loaded corpus:"); output += Util.getDate() + " Loaded corpus:\n"; info = " - time-slices: " + df.format(nbTimeSlices) + " time-slices of " + configuration.timeSliceLength + " minutes each\n"; info += " - first message: " + startTimestamp + "\n"; double datasetLength = (nbTimeSlices * configuration.timeSliceLength) / 60 / 24; info += " - last message: " + endTimestamp + " (" + datasetLength + " days)\n"; info += " - number of messages: " + df.format(messageCount); output += info; System.out.println(info); }
From source file:web.DirectoryupdateblobController.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException/*from w w w. j a va 2s. co m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // *************************************************************************** // This will initialize common data in the abstract class and the return result is of no value. // The abstract class initializes protected variables, login, directory, logininfo. // Which can be accessed in all controllers if they want to. // *************************************************************************** try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest", e); } if (!WebUtil.isLicenseProfessional(login)) { return handleError("Cannot manage directory feature in deluxe version."); } // *************************************************************************** // This is the only line of code you need to get all session info initialized! // Always be the first line before anything else is done. Add to each controller's // handlRequest method. Also redirectory to extend SessionObject. // *************************************************************************** outOfSession(request, response); if (RegexStrUtil.isNull(login)) { return handleUserpageError("Login is null in DirectoryupdateblobController."); } String directoryid = request.getParameter(DbConstants.DIRECTORY_ID); String entryid = request.getParameter(DbConstants.ENTRYID); String btitle = request.getParameter(DbConstants.BTITLE); String zoom = request.getParameter(DbConstants.ZOOM); String usertags = request.getParameter(DbConstants.USER_TAGS); String caption = request.getParameter(DbConstants.CAPTION); if (RegexStrUtil.isNull(directoryid) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(btitle)) { return handleError( "request, directoryid/entryid/btitle is null, directoryupdateblobController " + login); } if (directoryid.length() > GlobalConst.directoryidSize) { return handleError( "directoryid.length > WebConstants.directoryidSize, directoryupdateblobController " + login); } if (entryid.length() > GlobalConst.entryIdSize) { return handleError( "entryid.length > WebConstants.entryIdSize, directoryupdateblobController " + login); } if (btitle.length() > GlobalConst.blobTitleSize) { btitle = btitle.substring(0, GlobalConst.blobTitleSize); } if (!RegexStrUtil.isNull(caption)) { if (caption.length() > GlobalConst.refererSize) { caption = caption.substring(0, GlobalConst.refererSize); } caption = RegexStrUtil.goodText(caption); } if (!RegexStrUtil.isNull(usertags)) { if (usertags.length() > GlobalConst.usertagsSize) { usertags = usertags.substring(0, GlobalConst.usertagsSize); } usertags = RegexStrUtil.goodText(usertags); } DirectoryDao directoryDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (directoryDao == null) { return handleError("DirectoryDao is null in DirectoryupdateblobController directory, " + login); } DirectoryStreamBlobDao dirStreamBlobDao = (DirectoryStreamBlobDao) daoMapper.getDao(DbConstants.DIR_BLOB); if (dirStreamBlobDao == null) { return handleError("DirectoryDao is null in DirectoryupdateblobController directory, " + login); } if (!RegexStrUtil.isNull(zoom)) { int zoomVal = new Integer(zoom).intValue(); if (zoomVal < GlobalConst.zoomMinSize || zoomVal > GlobalConst.zoomMaxSize) { return handleError( "zoomVal is either < zoomMinSize or > zoomMaxSize, DirectoryupdateblobController directory, login=" + login); } } String loginId = null; if (loginInfo != null) { loginId = loginInfo.getValue(DbConstants.LOGIN_ID); } boolean def = request.getParameter(DbConstants.DEF) != null && request.getParameter(DbConstants.DEF).equalsIgnoreCase("ON"); directoryid = RegexStrUtil.goodNameStr(directoryid); entryid = RegexStrUtil.goodNameStr(entryid); btitle = RegexStrUtil.goodText(btitle); DirectoryStreamBlobDao blobDao = (DirectoryStreamBlobDao) daoMapper.getDao(DbConstants.DIR_BLOB); if (blobDao == null) { return handleError("DirectoryStreamBlobDao is null, DirectorygetblobController"); } List tagList = null; Directory directory = null; try { if (login != null && loginInfo != null) { directory = directoryDao.viewDirectory(directoryid, loginInfo.getValue(DbConstants.LOGIN_ID), login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_SLAVE, DbConstants.WEBSITE_READ_FROM_SLAVE); } else { directory = directoryDao.viewDirectory(directoryid); } tagList = blobDao.getAllTags(directoryid, DbConstants.READ_FROM_SLAVE); } catch (BaseDaoException e) { return handleError("Exception occured in viewDirectory()/getAllTags() for directory() " + directoryid, e); } /** * dirpath and dirname are required for sans * renameSanFile */ try { directoryDao.updateStreamBlob(entryid, directoryid, loginId, login, zoom, btitle, def, caption, directory.getValue(DbConstants.DIRPATH), directory.getValue(DbConstants.DIRNAME)); dirStreamBlobDao.updateTags(entryid, directoryid, usertags); // get the latest directory with the blobs updated information directory = directoryDao.viewDirectory(directoryid, loginInfo.getValue(DbConstants.LOGIN_ID), login, DbConstants.READ_FROM_SLAVE, DbConstants.BLOB_READ_FROM_MASTER, DbConstants.WEBSITE_READ_FROM_SLAVE); } catch (BaseDaoException e) { return handleError("Exception occured in updateStreamBlob()/updateTags()/viewDirectory() for member " + login + " directoryid = " + directoryid, e); } String viewName = DbConstants.DIR_PHOTO_FOLDER; String blobtype = request.getParameter(DbConstants.BLOBTYPE); if (!RegexStrUtil.isNull(blobtype)) { if (blobtype.equals(DbConstants.FILE_CATEGORY)) { viewName = DbConstants.EDIT_DIR_BLOB_FILE; } int catValue = new Integer(blobtype).intValue(); if (catValue < GlobalConst.categoryMinSize || catValue > GlobalConst.categoryMaxSize) { return handleError("category/blobtype is > categoryMin/MaxSize, DirectoryupdateblobController"); } } StringBuffer sb = new StringBuffer(); if (tagList != null && tagList.size() > 0) { for (int i = 0; i < tagList.size(); i++) { Photo photo = (Photo) tagList.get(i); if (photo != null) { sb.append(photo.getValue(DbConstants.USER_TAGS)); sb.append(" "); } } } Directory cobrand = null; CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, DirectorygetblobController "); } try { cobrand = cobrandDao.getDirCobrand(directoryid); } catch (Exception e) { return handleError("exception getDirCobrand(), DirectorygetblobController ", e); } String pageNum = request.getParameter(DbConstants.PAGE_NUM); try { if (!RegexStrUtil.isNull(pageNum)) { NumberFormat nf = NumberFormat.getInstance(); Number mypageNum = nf.parse(pageNum); } } catch (ParseException e) { return handleError("pageNum has other than [0-9] characters, DirectorygetblobController.", e); } Map myModel = new HashMap(); myModel.put(DbConstants.LOGIN_INFO, loginInfo); if (sb != null) { myModel.put(DbConstants.USER_TAGS, sb.toString()); } else { myModel.put(DbConstants.USER_TAGS, " "); } myModel.put(DbConstants.DIRECTORY, directory); myModel.put(DbConstants.DIRNAME, directory.getValue(DbConstants.DIRNAME)); myModel.put(DbConstants.DIRECTORY_ID, directoryid); myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.IS_DIRECTORY, "1"); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); myModel.put(DbConstants.SORT_BY, DbConstants.DATEDESC); myModel.put(DbConstants.SELECTION, DbConstants.DATE_DESC_STR); return new ModelAndView(viewName, "model", myModel); }
From source file:org.opentestsystem.shared.search.domain.SearchFilter.java
/** * Get the values to be searched on//from ww w . j a va2 s . c o m * * @param strings * @return */ public Object[] getSearchValue(final String... strings) { Object[] vals = new Object[strings.length]; int index = 0; NumberFormat format = NumberFormat.getInstance(Locale.US); for (String value : strings) { if (StringUtils.isNotEmpty(value)) { try { Object val = null; StringBuffer debugMsg = new StringBuffer("creating search value "); switch (this.dataType) { case Number: val = format.parse(value); debugMsg.append(value).append(" as number ").append(val); break; case MilliDate: val = new DateTime(format.parse(value).longValue()); debugMsg.append(value).append(" as date from millis ").append(val); break; case ISO8601Date: val = DateTime.parse(value); debugMsg.append(value).append(" as date from ISO-8601 String ").append(val); break; case Boolean: val = Boolean.parseBoolean(value); debugMsg.append(value).append(" as boolean ").append(val); break; case ObjectId: val = new ObjectId(value); debugMsg.append(value).append(" as Object ID from String ").append(val); break; default: val = value; debugMsg = new StringBuffer(SB_INIT_SIZE); debugMsg.append("keeping search value "); debugMsg.append(value); debugMsg.append(" as string"); break; } vals[index] = val; LOGGER.debug(debugMsg.toString()); } catch (ParseException e) { throw new RestException("search.criteria.invalid.format", e); } LOGGER.debug(""); } index++; } return vals; }
From source file:com.commander4j.util.JUtility.java
public static BigDecimal stringToBigDecimal(String str) { BigDecimal result;/* ww w . j a va2 s .c om*/ NumberFormat nf; nf = NumberFormat.getNumberInstance(Locale.getDefault()); try { Number myNumber = nf.parse(str); Double dbl = myNumber.doubleValue(); result = BigDecimal.valueOf(dbl); str = String.valueOf(dbl); } catch (ParseException e) { final Logger logger = Logger.getLogger(JUtility.class); logger.error(e.getMessage()); str = "0"; result = new BigDecimal("0"); } // result = new BigDecimal(str); return result; }