List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:fr.paris.lutece.portal.service.daemon.AccountLifeTimeDaemon.java
/** * Adds the parameters to model./*from ww w . ja va 2 s . co m*/ * * @param model the model * @param nIdUser the n id user */ protected void addParametersToModel(Map<String, String> model, Integer nIdUser) { AdminUser user = AdminUserHome.findByPrimaryKey(nIdUser); if (user.getAccountMaxValidDate() != null) { DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); String accountMaxValidDate = dateFormat.format(new Date(user.getAccountMaxValidDate().getTime())); String activationURL = AppPropertiesService.getProperty(PROPERTY_PROD_URL) + JSP_URL_REACTIVATE_ACCOUNT; model.put(MARK_DATE_VALID, accountMaxValidDate); model.put(MARK_URL, activationURL); } model.put(MARK_LAST_NAME, user.getLastName()); model.put(MARK_FIRST_NAME, user.getFirstName()); }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static String getDBtoUserFormatShortString(java.util.Date dbDate, Locale userLocale) { // the following line is for 1.1 release and will be removed when date // is localized userLocale = internalLocale;/* ww w .j ava 2 s. c o m*/ SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, userLocale); return format.format(dbDate); }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumLookupUserService.java
/** * Handles a NCIP LookupUser service by returning hard-coded data. * // ww w . ja v a 2 s .com * @param initData * the LookupUserInitiationData * @param serviceManager * provides access to remote services * @return LookupUserResponseData */ @Override public LookupUserResponseData performService(LookupUserInitiationData initData, RemoteServiceManager serviceManager) { String baseUrl = "https://" + IIIClassicBaseUrl + "/patroninfo%7ES0/"; final LookupUserResponseData responseData = new LookupUserResponseData(); String userId = initData.getUserId().getUserIdentifierValue(); MillenniumRemoteServiceManager millenniumSvcMgr = (MillenniumRemoteServiceManager) serviceManager; String strSessionId = millenniumSvcMgr.getIIISessionId(baseUrl); String redirectedUrl = millenniumSvcMgr.authenticate(authenticatedUserName, authenticatedUserPassword, baseUrl, strSessionId); // if the returned logIntoWebForm isn't null if (redirectedUrl != null) { // extract the iii id from the URL int start = redirectedUrl.indexOf("~S0/"); // Check to see if we're not redirected to the "top" int end = redirectedUrl.indexOf("/top"); if (end == -1) { end = redirectedUrl.indexOf("/items"); } String urid = redirectedUrl.substring(start, end).replace("~S0/", ""); authenticatedUserId = urid; } boolean getBlockOrTrap = false; boolean getAddress = true; boolean getVisibleUserID = true; boolean getFines = true; boolean getHolds = false; boolean getLoans = false; boolean getRecalls = false; boolean getMessages = false; // System.out.println("xcLookupUser authID: " + authenticatedUserId); // System.out.println("xcLookupUser redirUrl: " + redirectedUrl); // setup lookup method GetMethod lookupMethod = new GetMethod(redirectedUrl); lookupMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + strSessionId); try { try { client.executeMethod(lookupMethod); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String html = lookupMethod.getResponseBodyAsString(); // log.error(html); /** * Boolean Values to Return as objects */ // TODO xcLookupUser: Finish getBlockOrTrap // If getBlockOrTrap is true, the returned users list of blocks // must contain all blocks currently placed on the user represented // by the userId field. if (getBlockOrTrap) { // log.debug("Get Block or Trap"); System.out.println("Todo: Get Block or Trap"); } // TODO xcLookupUser: Finish getAddres (Temp Address) if possible // If getMessages is true, the returned users list of messages must // contain all messages applying the user represented by the userId if (getAddress) { // log.debug("Get Address"); Pattern address = Pattern.compile( "^<span(.*?)class=\"large\">(?s)(.*?)</form>(?s)(.*?)<p>(?s)(.*?)<br />(?s)(.*?)<p>(?s)(.*?)</span>$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher addressMatch = address.matcher(html); addressMatch.find(); // System.out.println(addressMatch.group(5)); String strAddress = addressMatch.group(5).replaceAll("<br />", "|").replaceAll("\\n", "") .replaceAll("||", ""); strAddress = strAddress.replace("||", ""); // returnUser.setAddress(strAddress); System.out.println("Found the home address " + strAddress); // + " for the patron with patron ID " + patronId) // log.debug("Found the home address " + returnUser.getAddress() // + " for the patron with patron ID " + patronId); } // if true, the user's fullName must be set to the correct value for // the user represented by the userId field if this value is known. if (getVisibleUserID) { // log.debug("get Visible User Id"); // If there were any results, build the full name string Pattern visibleId = Pattern.compile( "^<span(.*?)class=\"large\">(?s)(.*?)</form>(?s)(.*?)<p>(?s)(.*?)<br />(?s)(.*?)<p>(?s)(.*?)</span>$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher visibleIdMatch = visibleId.matcher(html); visibleIdMatch.find(); // System.out.println(visibleIdMatch.group(4)); // Clean up strName, removing tags String strName = visibleIdMatch.group(4).replace("<strong>", "").replace("</strong>", ""); // set full name to strName, removing any unneded whitespaces String fullName = strName.trim(); // Check to make sure it exists if (fullName.length() > 1) { // setFullName(fullName); System.out.println(fullName); // log.debug("Found the user's full name to be " // + returnUser.getFullName()); } else { // log // .info("Could not find the name information for the patron with patron ID " // + patronId); } } // TODO xcLookupUser: Finish getFines // if true the user's totalFinesCurrencyCode and totalFines fields // must be set to the correct values for the user represented by the // userId field if these values are known. In addition, the list of // fines must contain NCIPUserFine Objects for all fines the user // owes. if (getFines) { // log.debug("get Fines"); // https://jasmine.uncc.edu/patroninfo~S0/1205433/overdues System.out.println("Get Fines"); // System.out.println("Auth: " + authenticatedUserId); html = millenniumSvcMgr.getFines(authenticatedUserId, strSessionId); Pattern fines = Pattern.compile( "^(?s)(.*?)<table(.*?)class=\"patFunc\">(?s)(.*?)</table>(?s)(.*?)$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher finesMatch = fines.matcher(html); if (finesMatch.matches()) { finesTable = finesMatch.group(3).toString(); } System.out.println(finesTable); System.out.println("=================="); fines = Pattern.compile("^(?s)(.*?)<tr class=\"patFuncFinesEntryTitle\">(?s)(.*?)</tr>(?s)(.*?)$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); finesMatch = fines.matcher(finesTable); Pattern title = Pattern.compile("^(?s)(.*?)<em>(?s)(.*?)</em></td>(?s)(.*?)$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); while (finesMatch.find()) { //for (int i=0; i < finesMatch.groupCount(); i++) { System.out.println(finesMatch.group(2)); Matcher titleMatch = title.matcher(finesMatch.group(2)); // Grab the title out of the finesMatch string System.out.println("====="); if (titleMatch.matches()) { System.out.println(titleMatch.group(2)); } System.out.println("====="); //} } System.out.println("=================="); /* * <table border="1" width="100%" class="patFunc"> <tbody> * * </tbody> </table> */ // TODO Parse out fines, and add them to objects } // TODO xcLookupUser: Finish getHolds // If getHolds is true, the returned users list of holds must // contain NCIPUserRequestedItem Objects for all holds and callslips // the user represented by the userId field has placed. if (getHolds) { System.out.println("Todo: get holds"); /* * NCIPUserRequestedItem item = new * NCIPUserRequestedItem(results .getDate("date_hold_placed"), * // The date the request // was placed null, // The date the * request is expected to become // available newItem); // The * bibliographic ID of the item the // request is for * * // Add the item to the list of requested items * returnUser.addRequestedItem(item); */ } // If getLoans is true, the returned users list of checkedOutItems // must contain NCIPUserLoanedItem Objects for all items the user // represented by the userId field has checked out. if (getLoans) { System.out.println("get Loans"); // Setup Request URL String requestUrl = redirectedUrl.substring(0, redirectedUrl.lastIndexOf("/")) + "/items"; // setup getLoans method GetMethod getLoansMethod = new GetMethod(requestUrl); getLoansMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + strSessionId); // Grab items page try { client.executeMethod(getLoansMethod); String loansHtml = getLoansMethod.getResponseBodyAsString(); // Parse out the second page // System.out.println(loansHtml); // If there were any results, build the full name string Pattern loans = Pattern.compile( "^(?s)(.*?)<table(.*?)class=\"patFunc\">(?s)(.*?)<th(.*?)>(?s)(.*?)</th>(?s)(.*?)</tr>(?s)(.*?)</table>(?s)(.*?)$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher loansMatch = loans.matcher(loansHtml); if (loansMatch.matches()) { // System.out.println("Matches"); // System.out.println(loansMatch.groupCount()); // for (int i=0; i < loansMatch.groupCount(); i++) { // Add to String Buffer // System.out.println(loansMatch.group(7)); // } String loansTable = loansMatch.group(7).toString(); // loansTable = loansTable.replaceAll("\n\n",""); Pattern loansTwo = Pattern.compile( "^(.*?)<tr(.*?)class=\"patFuncEntry\">(?s)(.*?)</tr>(?s)(.*?)$", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher loansTwoMatch = loansTwo.matcher(loansTable); // initialize variables StringBuffer sb = new StringBuffer(); String lineMatch; String strCleanup; /* * Pattern loansThree = Pattern.compile( * "^(.*?)value=\"(.*?)\"(.*?)$", * Pattern.CASE_INSENSITIVE); */ // loop over each iteration while (loansTwoMatch.find()) { // Replacements to get pipe delmited output lineMatch = loansTwoMatch.group(3).replaceAll("\n", ""); lineMatch = lineMatch.replaceAll( "<td align=\"left\" class=\"patFuncMark\"><input type=\"checkbox\" name=\"renew(.*?)\" value=\"", ""); lineMatch = lineMatch.replaceAll("\"(.*?)href=\"(.*?)&", "'|'"); lineMatch = lineMatch.replaceAll("</a>(.*?)Barcode\">", "'|'"); lineMatch = lineMatch.replaceAll("</td>(.*?)patFuncStatus\">", "'|'"); lineMatch = lineMatch.replaceAll("</td>(.*?)patFuncCallNo\">", "'|'"); lineMatch = lineMatch.replaceAll("\"> ", "'|'"); lineMatch = lineMatch.replaceAll(" </td>", ""); // Append Pipe delimited to string buffer sb.append(lineMatch + "\n"); } // Convert to string for output strCleanup = sb.toString(); String aryTest[] = stringToArray(strCleanup, "\n"); // System.out.println(aryTest[1]); // Loop Over Loans for (int i = 0; i < aryTest.length; i++) { // Split up, and turn into array / assign to object String aryVal[] = aryTest[i].split("'|'"); /* * This is all we can get, itemid, bib, title, * barcode duedate and call number * System.out.println("--" + i); * System.out.print("| item: " + aryVal[0] + * "| bib: b" + aryVal[2] + "| title " + aryVal[4] + * "| barcode: " + aryVal[6] + "| due: " + aryVal[8] * + "| CN: " + aryVal[10]); * * System.out.println("--"); */ // set variables for loaned object String strAgencyId = strConfig.getProperty("defaultAgency");/* * configuration * .getProperty( * Constants. * CONFIG_ILS_DEFAULT_AGENCY * ); */ // Start Date Format Date dateDue = null; // set to null DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT); // create // formatter String strDate = aryVal[8].replaceAll("DUE ", "").replace("-", "/"); // format string // System.out.println(strDate); // for testing // parse the date try { dateDue = dateFormatter.parse(strDate); } catch (ParseException pe) { System.out.println("LookupUser ERROR: Cannot parse \"" + strDate + "\""); } // add b to the value for the bib String bibId = "b" + aryVal[2]; // Create a new item for each loaned item /* * NCIPUserLoanedItem item = new NCIPUserLoanedItem( * dateDue, new NCIPItem(new NCIPAgency( * strAgencyId), bibId)); */ // add object to returnUser // returnUser.addLoanedItem(item); System.out.println( "Added the user's loaned item with item ID " + bibId + " Due: " + dateDue); } } // end matches // Error handling } catch (HttpException e) { e.printStackTrace(); /* * throw new ILSException("HttpException thrown, exiting.", * Constants.ERROR_INTERNAL_ERROR, new StrictNcipError(true, * "NCIP General Processing Error", * "Temporary Processing Failure", "NCIPMessage", null)); */ } catch (IOException e) { e.printStackTrace(); /* * throw new ILSException("IOException thrown, exiting.", * Constants.ERROR_INTERNAL_ERROR, new StrictNcipError(true, * "NCIP General Processing Error", * "Temporary Processing Failure", "NCIPMessage", null)); */ } } // TODO xcLookupUser: Finish Recalls // If getRecalls is true, the returned users list of recalls must // contain XCUserRecalledItem Objects for all recalls the user // represented by the userId field has placed. if (getRecalls) { System.out.println("Todo: get Recalls"); } // TODO xcLookupUser: Finish getMessages // If getMessages is true, the returned users list of messages must // contain all messages applying the user represented by the userId. if (getMessages) { System.out.println("Todo: get Messages"); } // return returnUser; } catch (HttpException e) { e.printStackTrace(); /* * throw new ILSException( "HttpException thrown, exiting.", * Constants.ERROR_INTERNAL_ERROR, new StrictNcipError(true, * "NCIP General Processing Error", "Temporary Processing Failure", * "NCIPMessage", null)); */ } catch (IOException e) { e.printStackTrace(); /* * throw new ILSException( "IOException thrown, exiting.", * Constants.ERROR_INTERNAL_ERROR, new StrictNcipError(true, * "NCIP General Processing Error", "Temporary Processing Failure", * "NCIPMessage", null)); */ } user.setUserIdentifierValue(userId); responseData.setUserId(user); // Echo back the same item id that came in // responseData.setUserId(initData.getUserId()); return responseData; }
From source file:org.opencms.workflow.CmsExtendedWorkflowManager.java
/** * Generates the description for a new workflow project based on the user for whom it is created.<p> * * @param userCms the user's current CMS context * * @return the workflow project description *///w w w . j a v a 2s. c o m protected String generateProjectDescription(CmsObject userCms) { CmsUser user = userCms.getRequestContext().getCurrentUser(); OpenCms.getLocaleManager(); Locale locale = CmsLocaleManager.getDefaultLocale(); long time = System.currentTimeMillis(); Date date = new Date(time); DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); String dateString = format.format(date); String result = Messages.get().getBundle(locale).key(Messages.GUI_WORKFLOW_PROJECT_DESCRIPTION_2, user.getName(), dateString); return result; }
From source file:eu.trentorise.smartcampus.jp.MyRecurItineraryFragment.java
private String formatTime(String time) { SimpleDateFormat inFormat = new SimpleDateFormat("hh:mmaa", Locale.getDefault()); DateFormat outFormat = DateFormat.getTimeInstance(DateFormat.SHORT); try {//from w w w .j a v a 2 s . c om Date date = inFormat.parse(time); String out = outFormat.format(date); return out; } catch (ParseException e) { return time; } }
From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java
/** * return a timestamp Object which correspond with the string specified in * parameter.// w ww .ja v a 2 s . c o m * @param strDate the date who must convert * @param locale the locale * @return a timestamp Object which correspond with the string specified in * parameter. */ public static Timestamp getLastMinute(String strDate, Locale locale) { try { Date date; DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); dateFormat.setLenient(false); date = dateFormat.parse(strDate.trim()); Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, 0); caldate.set(Calendar.SECOND, 0); caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY)); caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE)); Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis()); return timeStamp; } catch (ParseException e) { return null; } }
From source file:org.robovm.eclipse.RoboVMPlugin.java
private static String now() { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); return df.format(new Date()); }
From source file:com.buzzdavidson.spork.client.OWAClient.java
/** * Fetch the body of the email message given a message URL. * * @param message Mime message to add body to * @param messageUrl URL of message (OWA WebDav) *//* w w w . j a va2 s . c o m*/ private void populateMessage(MimeMessage message, String messageUrl) { GetMethod get = new GetMethod(messageUrl); get.setRequestHeader("Translate", "F"); try { logger.info("Requesting message body via url [" + messageUrl + "]"); int status = client.executeMethod(get); if (logger.isDebugEnabled()) { logger.debug("Message request returned status code [" + status + "]"); } if (status == HttpStatus.SC_OK) { BufferedReader in = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream())); String contentType = OWAUtils.getSingleHeader(message, PARAM_CONTENT_TYPE); String contentEncoding = OWAUtils.getSingleHeader(message, PARAM_CONTENT_ENCODING); boolean needContentType = (contentType == null || contentType.length() < 1); // first set of entries are headers, followed by empty line. skip to first empty line. for (String line; (line = in.readLine()) != null;) { if (line != null && line.trim().length() == 0) { break; } } StringBuffer buf = new StringBuffer(); for (String line; (line = in.readLine()) != null;) { buf.append(line); buf.append(NEWLINE); } if (needContentType || contentType.contains(CONTENT_TYPE_TEXT_PLAIN)) { // OWA sometimes reports XML or HTML content as "text/plain"; check for this. if (logger.isDebugEnabled()) { logger.debug("checking content encoding"); } byte[] blob = buf.toString().getBytes(); if (logger.isDebugEnabled()) { logger.debug("blob length is " + blob.length + " bytes"); } if (contentEncoding.equals(BASE_64_ENCODING)) { if (logger.isDebugEnabled()) { logger.debug("blob is base64 encoded, decoding"); } byte[] newblob = Base64.decodeBase64(blob); if (logger.isDebugEnabled()) { logger.debug("decoded blob length is " + newblob.length + " bytes"); } String data = new String(newblob); buf = new StringBuffer(data); } else { if (logger.isDebugEnabled()) { logger.debug("blob is encoded with [" + contentEncoding + "], not decoding"); } } contentType = determineContentType(buf, message); } if (wantDiagnostics) { buf.append(NEWLINE); buf.append("-------------------------------------"); buf.append(NEWLINE); buf.append("SPORK Data"); buf.append(NEWLINE); buf.append("content-encoding: " + contentEncoding); buf.append(NEWLINE); buf.append("content-type: " + contentType); if (needContentType) { buf.append(" (calculated) " + contentType); buf.append(" Message processed " + DateFormat.getDateInstance(DateFormat.SHORT).format(new Date())); } } if (needContentType) { buf = cleanupBuffer(buf); } buf.append(NEWLINE); message.setText(buf.toString()); int len = buf.length(); message.setHeader(PARAM_CONTENT_LENGTH, Integer.valueOf(len).toString()); // close enough :) if (contentType != null && contentType.length() > 0) { message.setHeader(PARAM_CONTENT_TYPE, contentType); } message.saveChanges(); } } catch (HttpException ex) { logger.error("Received HttpException fetching message body", ex); } catch (UnsupportedEncodingException ex) { logger.error("Received UnsupportedEncodingException fetching message body", ex); } catch (IOException ex) { logger.error("Received IOException fetching message body", ex); } catch (MessagingException ex) { logger.error("Received MessagingException fetching message body", ex); } }
From source file:org.exoplatform.answer.webui.FAQUtils.java
public static String getShortDateFormat(Date myDate) { return getFormatDate(DateFormat.SHORT, myDate); }
From source file:org.sakaiproject.tool.gradebook.ui.GradebookDependentBean.java
/** * Generates a default filename (minus the extension) for a download from this Gradebook. * * @param prefix for filename/*w w w . j a v a2 s . c o m*/ * @return The appropriate filename for the export */ public String getDownloadFileName(String prefix) { Date now = new Date(); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, (new ResourceLoader()).getLocale()); StringBuilder fileName = new StringBuilder(prefix); String gbName = getGradebook().getName(); if (StringUtils.trimToNull(gbName) != null) { gbName = gbName.replaceAll("\\s", "_"); // replace whitespace with '_' fileName.append("-"); fileName.append(gbName); } fileName.append("-"); fileName.append(df.format(now)); return fileName.toString(); }