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:org.opencms.ui.dialogs.CmsPublishScheduledDialog.java
/** * Creates the publish project's name for a given root path and publish date.<p> * * @param rootPath the publish resource's root path * @param date the publish date/*from w w w . j ava2 s. c om*/ * * @return the publish project name */ private String computeProjectName(String rootPath, Date date) { // create the temporary project, which is deleted after publishing // the publish scheduled date in project name String dateTime = CmsDateUtil.getDateTime(date, DateFormat.SHORT, getLocale()); // the resource name to publish scheduled String projectName = CmsVaadinUtils.getMessageText(Messages.GUI_PUBLISH_SCHEDULED_PROJECT_NAME_2, rootPath, dateTime); // the HTML encoding for slashes is necessary because of the slashes in english date time format // in project names slahes are not allowed, because these are separators for organizaional units projectName = projectName.replace("/", "/"); while (projectName.length() > 190) { rootPath = "..." + rootPath.substring(5, rootPath.length()); projectName = computeProjectName(rootPath, date); } return projectName; }
From source file:org.nuxeo.ecm.platform.ui.web.tag.fn.Functions.java
/** * Return the date format to handle date and time taking the user's locale into account. * * @since 5.9.1/* w ww . j a va2s . c om*/ */ public static String dateAndTimeFormatter(String formatLength) { // A map to store temporary available date format FacesContext context = FacesContext.getCurrentInstance(); Locale locale = context.getViewRoot().getLocale(); int style = DateFormat.SHORT; String styleString = mapOfDateLength.get(formatLength.toLowerCase()); boolean addCentury = false; if ("shortWithCentury".toLowerCase().equals(styleString)) { addCentury = true; } else { style = Integer.parseInt(styleString); } DateFormat aDateFormat = DateFormat.getDateTimeInstance(style, style, locale); // Cast to SimpleDateFormat to make "toPattern" method available SimpleDateFormat format = (SimpleDateFormat) aDateFormat; // return the date pattern String pattern = format.toPattern(); if (style == DateFormat.SHORT && addCentury) { // hack to add century on generated pattern pattern = YEAR_PATTERN.matcher(pattern).replaceAll("yyyy"); } return pattern; }
From source file:org.agnitas.web.UserActivityLogAction.java
/** * Gets date format according to current admin locale * @param admin current admin in session * @return SimpleDateFormat object//from ww w. ja va 2 s. c o m */ protected SimpleDateFormat getLocaleFormat(Admin admin) { Locale locale = admin.getLocale(); return (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT, locale); }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static java.sql.Date getLocaleDate(String value) { if (internalLocale != null && value != null && !value.equals("")) { try {/*from ww w. j a va 2s. com*/ SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, internalLocale); shortFormat.setLenient(false); String userPattern = shortFormat.toPattern(); String dbDate = convertUserToDbFmt(value, userPattern); return java.sql.Date.valueOf(dbDate); } catch (RuntimeException alreadyRuntime) { throw alreadyRuntime; } catch (Exception e) { throw new FrameworkRuntimeException(e); } } else { return null; } }
From source file:com.sample.solutionprofile.portlet.JSPPortlet.java
public void processAction(ActionRequest req, ActionResponse res) throws IOException, PortletException { String command = req.getParameter("command"); long userId = 0; userId = PortalUtil.getUserId(req);/*from www . ja v a 2 s. c o m*/ List companyIds = null; int companyId = 0; String company_name = req.getParameter("company_names"); if ((company_name != null) && (!company_name.isEmpty())) { try { companyId = CompanyItemDAO.getCompanyIdByName(company_name); System.out.println("Company for solution is" + String.valueOf(companyId)); } catch (Exception e) { System.out.println("Couldn't find the company"); } } // remove it for the moment, the user has choosed company ID /*try { companyIds = SolutionItemDAO.getCompanyIdsByUserId(userId) ; companyId = (Integer)companyIds.get(0); } catch (Exception e) { System.out.println("SolutionItemDAO.getCompanyIdsByUserId throws exception for userId = " + String.valueOf(userId)); }*/ int id = 0; try { id = Integer.parseInt(req.getParameter("id")); } catch (Exception e) { System.out.println("Bzz"); } //int companyId = 0; String partNumberStr = req.getParameter("partNumber"); long partNumber = 0; /*try { partNumber = Integer.parseInt(partNumberStr); }catch (Exception e) { System.out.println("Bzz2"); }*/ String solName = req.getParameter("solName"); String solDesc = req.getParameter("solDesc"); String partComSite = req.getParameter("partComSite"); //int solFocus = Integer.parseInt(req.getParameter("solFocus")); //int solStatusPartner = Integer.parseInt(req.getParameter("solStatusPartner"));; //int solStatusSAP = Integer.parseInt(req.getParameter("solStatusSAP")); String sapCertSince = req.getParameter("sapCertSince"); String lastReviewBySAP = req.getParameter("lastReviewBySAP"); int averTrainEndUser = 0; if (req.getParameter("averTrainEndUser") != null && !req.getParameter("averTrainEndUser").isEmpty()) averTrainEndUser = Integer.parseInt(req.getParameter("averTrainEndUser")); int averImplTrainingDays = 0; if (req.getParameter("averImplTrainingDays") != null && !req.getParameter("averImplTrainingDays").isEmpty()) averImplTrainingDays = Integer.parseInt(req.getParameter("averImplTrainingDays")); int averImplEffort = 0; if (req.getParameter("averImplEffort") != null && !req.getParameter("averImplEffort").isEmpty()) averImplEffort = Integer.parseInt(req.getParameter("averImplEffort")); int averImplDuration = 0; if (req.getParameter("averImplDuration") != null && !req.getParameter("averImplDuration").isEmpty()) averImplDuration = Integer.parseInt(req.getParameter("averImplDuration")); int averSizeImplTeam = 0; if (req.getParameter("averSizeImplTeam") != null && !req.getParameter("averSizeImplTeam").isEmpty()) averSizeImplTeam = Integer.parseInt(req.getParameter("averSizeImplTeam")); int averSaleCycle = 0; if (req.getParameter("averSaleCycle") != null && !req.getParameter("averSaleCycle").isEmpty()) averSaleCycle = Integer.parseInt(req.getParameter("averSaleCycle")); int noCustomers = 0; if (req.getParameter("noCustomers") != null && !req.getParameter("noCustomers").isEmpty()) noCustomers = Integer.parseInt(req.getParameter("noCustomers")); int smallImpl = 0; if (req.getParameter("smallImpl") != null && !req.getParameter("smallImpl").isEmpty()) smallImpl = Integer.parseInt(req.getParameter("smallImpl")); int largeImpl = 0; if (req.getParameter("largeImpl") != null && !req.getParameter("largeImpl").isEmpty()) largeImpl = Integer.parseInt(req.getParameter("largeImpl")); int smallImplTime = 0; if (req.getParameter("smallImplTime") != null && !req.getParameter("smallImplTime").isEmpty()) smallImplTime = Integer.parseInt(req.getParameter("smallImplTime")); int largeImplTime = 0; if (req.getParameter("largeImplTime") != null && !req.getParameter("largeImplTime").isEmpty()) largeImplTime = Integer.parseInt(req.getParameter("largeImplTime")); int smallImplTeamNo = 0; if (req.getParameter("smallImplTeamNo") != null && !req.getParameter("smallImplTeamNo").isEmpty()) smallImplTeamNo = Integer.parseInt(req.getParameter("smallImplTeamNo")); int largeImplTeamNo = 0; if (req.getParameter("largeImplTeamNo") != null && !req.getParameter("largeImplTeamNo").isEmpty()) largeImplTeamNo = Integer.parseInt(req.getParameter("largeImplTeamNo")); String solSite = req.getParameter("solSite"); //int countryPriceEuro = Integer.parseInt(req.getParameter("countryPriceEuro")); String refCustAvailForUse = req.getParameter("refCustAvailForUse"); if (refCustAvailForUse == null) //?WHY refCustAvailForUse = "No"; int totalAppBaseLinePrice = 0; if (req.getParameter("totalAppBaseLinePrice") != null && !req.getParameter("totalAppBaseLinePrice").isEmpty()) totalAppBaseLinePrice = Integer.parseInt(req.getParameter("totalAppBaseLinePrice")); int appPriceEur = 0;//Integer.parseInt(req.getParameter("appPriceEur")); int hardwareCost = 0; if (req.getParameter("hardwareCost") != null && !req.getParameter("hardwareCost").isEmpty()) hardwareCost = Integer.parseInt(req.getParameter("hardwareCost")); int hardwareCostEur = 0;//Integer.parseInt(req.getParameter("hardwareCostEur")); int averLicensePrice = 0; if (req.getParameter("averLicensePrice") != null && !req.getParameter("averLicensePrice").isEmpty()) averLicensePrice = Integer.parseInt(req.getParameter("averLicensePrice")); int averLicensePriceEur = 0;//Integer.parseInt(req.getParameter("averLicensePriceEur")); int addServiceCost = 0; if (req.getParameter("addServiceCost") != null && !req.getParameter("addServiceCost").isEmpty()) addServiceCost = Integer.parseInt(req.getParameter("addServiceCost")); int addServicePriceEur = 0;//Integer.parseInt(req.getParameter("addServicePriceEur")); int implCost = 0; if (req.getParameter("implCost") != null && !req.getParameter("implCost").isEmpty()) implCost = Integer.parseInt(req.getParameter("implCost")); int implCostEur = 0;//Integer.parseInt(req.getParameter("implCostEur")); String sapDiscount = req.getParameter("sapDiscount"); String dbUsed = req.getParameter("dbUsed"); String SAPBusUsed = req.getParameter("SAPBusUsed"); String SAPGUIUsed = req.getParameter("SAPGUIUsed"); String compA1B1Used = req.getParameter("compA1B1Used"); String thirdPartyUsed = req.getParameter("thirdPartyUsed"); String thirdPartyName = req.getParameter("thirdPartyName"); String otherIT = req.getParameter("otherIT"); String addRemarks = req.getParameter("addRemarks"); String solSAPMicroSite = req.getParameter("solSAPMicroSite"); String lastPartRevieDate = req.getParameter("solSAPMicroSite"); String reviewedBy = req.getParameter("reviewedBy"); if (reviewedBy == null) // WHY? reviewedBy = ""; String profileAdded = req.getParameter("profileAdded"); if (profileAdded == null) // WHY? profileAdded = ""; String dateCreated = req.getParameter("dateCreated"); String modifiedBy = req.getParameter("modifiedBy"); if (modifiedBy == null) // WHY? modifiedBy = ""; String dateUpdated = req.getParameter("dateUpdated"); String notificationProc = req.getParameter("notificationProc"); if (notificationProc == null) // WHY? notificationProc = ""; String notificationText = req.getParameter("notificationText"); if (notificationText == null) // WHY? notificationText = ""; // childs String sol_countryPriceEuro = req.getParameter("country"); String sol_solFocusStr = req.getParameter("solFocus"); String[] sol_geographic_coverage = req.getParameterValues("geographic_coverage"); String[] sol_industry = req.getParameterValues("industry"); String[] sol_mySAPAllInOneVers = req.getParameterValues("mySAPAllInOneVers"); String[] sol_mySAPOneProductVers = req.getParameterValues("mySAPOneProductVers"); String sol_maturity = req.getParameter("maturity"); String sol_statusByProvider = req.getParameter("statusByProvider"); String sol_statusBySAP = req.getParameter("statusBySAP"); String[] sol_targetCompSize = req.getParameterValues("targetCompSize"); String[] sol_categTarget = req.getParameterValues("categTarget"); String[] sol_langAvailable = req.getParameterValues("langAvailable"); String sol_userType = req.getParameter("userType"); String[] sol_progLang = req.getParameterValues("progLang"); String[] sol_os = req.getParameterValues("os"); String[] sol_aioBased = req.getParameterValues("aioBased"); //search related try { SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); Date tempDate = new Date(); if (command.equals("add")) { // user // user adress + phone // solution SolutionItem solutionItem = new SolutionItem(); //public int companyId; solutionItem.companyId = companyId; // get the first solutionItem.solName = solName; solutionItem.solDesc = solDesc; solutionItem.partComSite = partComSite; //solutionItem.solFocus = ; //solutionItem.solStatusPartner; //solutionItem.solStatusSAP; //solutionItem.solMaturity; //solutionItem.statusByProvider; //solutionItem.statusBySAP; //solutionItem.solUserType; //date if (sapCertSince != null && !sapCertSince.isEmpty()) { try { tempDate = format.parse(sapCertSince); String value = tempDate.toString(); System.out.println("date since = " + value); solutionItem.sapCertSince = tempDate; } catch (ParseException ex) { } } if (lastReviewBySAP != null && !lastReviewBySAP.isEmpty()) { try { tempDate = format.parse(lastReviewBySAP); String value = tempDate.toString(); solutionItem.lastReviewBySAP = tempDate; } catch (ParseException ex) { } } solutionItem.averTrainEndUser = averTrainEndUser; solutionItem.averImplTrainingDays = averImplTrainingDays; solutionItem.averImplEffort = averImplEffort; solutionItem.averImplDuration = averImplDuration; solutionItem.averSizeImplTeam = averSizeImplTeam; solutionItem.averSaleCycle = averSaleCycle; solutionItem.noCustomers = noCustomers; solutionItem.smallImpl = smallImpl; solutionItem.largeImpl = largeImpl; solutionItem.smallImplTime = smallImplTime; solutionItem.largeImplTime = largeImplTime; solutionItem.smallImplTeamNo = smallImplTeamNo; solutionItem.largeImplTeamNo = largeImplTeamNo; solutionItem.solSite = solSite; //solutionItem.countryPriceEuro; solutionItem.refCustAvailForUse = refCustAvailForUse; solutionItem.totalAppBaseLinePrice = totalAppBaseLinePrice; solutionItem.appPriceEur = appPriceEur; solutionItem.hardwareCost = hardwareCost; solutionItem.hardwareCostEur = hardwareCostEur; solutionItem.averLicensePrice = averLicensePrice; solutionItem.averLicensePriceEur = averLicensePriceEur; solutionItem.addServiceCost = addServiceCost; solutionItem.addServicePriceEur = addServicePriceEur; solutionItem.implCost = implCost; solutionItem.implCostEur = implCostEur; solutionItem.sapDiscount = sapDiscount; solutionItem.dbUsed = dbUsed; solutionItem.SAPBusUsed = SAPBusUsed; solutionItem.SAPGUIUsed = SAPGUIUsed; solutionItem.compA1B1Used = compA1B1Used; solutionItem.thirdPartyUsed = thirdPartyUsed; solutionItem.thirdPartyName = thirdPartyName; solutionItem.otherIT = otherIT; solutionItem.addRemarks = addRemarks; solutionItem.solSAPMicroSite = solSAPMicroSite; // date if (lastPartRevieDate != null && !lastPartRevieDate.isEmpty()) { try { tempDate = format.parse(lastPartRevieDate); String value = tempDate.toString(); solutionItem.lastPartRevieDate = tempDate; } catch (ParseException ex) { } } solutionItem.reviewedBy = reviewedBy; solutionItem.profileAdded = profileAdded; //date solutionItem.dateCreated = new Date(); solutionItem.modifiedBy = modifiedBy; //date solutionItem.dateUpdated = new Date(); solutionItem.notificationProc = notificationProc; solutionItem.notificationText = notificationText; SolutionItemDAO.addSolutionItem(solutionItem); // childs SolutionUtil.updateSolutionSolFocus(solutionItem, sol_solFocusStr); SolutionUtil.updateSolutionCountryPriceEuro(solutionItem, sol_countryPriceEuro); SolutionUtil.updateSolutionGeographicCoverage(solutionItem, sol_geographic_coverage); SolutionUtil.updateSolutionIndustry(solutionItem, sol_industry); SolutionUtil.updateMySAPAllInOneVers(solutionItem, sol_mySAPAllInOneVers); SolutionUtil.updateMySAPOneProductVers(solutionItem, sol_mySAPOneProductVers); SolutionUtil.updateMaturity(solutionItem, sol_maturity); SolutionUtil.updateSolStatusByProvider(solutionItem, sol_statusByProvider); SolutionUtil.updateSolStatusBySAP(solutionItem, sol_statusBySAP); SolutionUtil.updateSolTargetCompSize(solutionItem, sol_targetCompSize); SolutionUtil.updateSolCategTarget(solutionItem, sol_categTarget); SolutionUtil.updateSolUserType(solutionItem, sol_userType); SolutionUtil.updateSolProgLang(solutionItem, sol_progLang); SolutionUtil.updateSolOS(solutionItem, sol_os); SolutionUtil.updateSolAioBased(solutionItem, sol_aioBased); //perform extra update SolutionItemDAO.updateSolutionItem(solutionItem); } else if (command.equals("edit")) { //user SolutionItem solutionItem = SolutionItemDAO.getSolutionItem(id); //public int companyId; solutionItem.solName = solName; solutionItem.solDesc = solDesc; solutionItem.partComSite = partComSite; //solutionItem.solFocus = ; //solutionItem.solStatusPartner; //solutionItem.solStatusSAP; //solutionItem.solMaturity; //solutionItem.statusByProvider; //solutionItem.statusBySAP; //solutionItem.solUserType; //date if (sapCertSince != null && !sapCertSince.isEmpty()) { try { tempDate = format.parse(sapCertSince); String value = tempDate.toString(); System.out.println("date since = " + value); solutionItem.sapCertSince = tempDate; } catch (ParseException ex) { } } if (lastReviewBySAP != null && !lastReviewBySAP.isEmpty()) { try { tempDate = format.parse(lastReviewBySAP); String value = tempDate.toString(); solutionItem.lastReviewBySAP = tempDate; } catch (ParseException ex) { } } solutionItem.averTrainEndUser = averTrainEndUser; solutionItem.averImplTrainingDays = averImplTrainingDays; solutionItem.averImplEffort = averImplEffort; solutionItem.averImplDuration = averImplDuration; solutionItem.averSizeImplTeam = averSizeImplTeam; solutionItem.averSaleCycle = averSaleCycle; solutionItem.noCustomers = noCustomers; solutionItem.smallImpl = smallImpl; solutionItem.largeImpl = largeImpl; solutionItem.smallImplTime = smallImplTime; solutionItem.largeImplTime = largeImplTime; solutionItem.smallImplTeamNo = smallImplTeamNo; solutionItem.largeImplTeamNo = largeImplTeamNo; solutionItem.solSite = solSite; //solutionItem.countryPriceEuro; solutionItem.refCustAvailForUse = refCustAvailForUse; solutionItem.totalAppBaseLinePrice = totalAppBaseLinePrice; solutionItem.appPriceEur = appPriceEur; solutionItem.hardwareCost = hardwareCost; solutionItem.hardwareCostEur = hardwareCostEur; solutionItem.averLicensePrice = averLicensePrice; solutionItem.averLicensePriceEur = averLicensePriceEur; solutionItem.addServiceCost = addServiceCost; solutionItem.addServicePriceEur = addServicePriceEur; solutionItem.implCost = implCost; solutionItem.implCostEur = implCostEur; solutionItem.sapDiscount = sapDiscount; solutionItem.dbUsed = dbUsed; solutionItem.SAPBusUsed = SAPBusUsed; solutionItem.SAPGUIUsed = SAPGUIUsed; solutionItem.compA1B1Used = compA1B1Used; solutionItem.thirdPartyUsed = thirdPartyUsed; solutionItem.thirdPartyName = thirdPartyName; solutionItem.otherIT = otherIT; solutionItem.addRemarks = addRemarks; solutionItem.solSAPMicroSite = solSAPMicroSite; // date if (lastPartRevieDate != null && !lastPartRevieDate.isEmpty()) { try { tempDate = format.parse(lastPartRevieDate); String value = tempDate.toString(); solutionItem.lastPartRevieDate = tempDate; } catch (ParseException ex) { } } solutionItem.reviewedBy = reviewedBy; solutionItem.profileAdded = profileAdded; //date solutionItem.dateCreated = new Date(); solutionItem.modifiedBy = modifiedBy; //date solutionItem.dateUpdated = new Date(); solutionItem.notificationProc = notificationProc; solutionItem.notificationText = notificationText; // Do update in main table SolutionUtil.updateSolutionSolFocus(solutionItem, sol_solFocusStr); SolutionUtil.updateSolutionCountryPriceEuro(solutionItem, sol_countryPriceEuro); SolutionUtil.updateSolutionGeographicCoverage(solutionItem, sol_geographic_coverage); SolutionUtil.updateSolutionIndustry(solutionItem, sol_industry); SolutionUtil.updateMySAPAllInOneVers(solutionItem, sol_mySAPAllInOneVers); SolutionUtil.updateMySAPOneProductVers(solutionItem, sol_mySAPOneProductVers); SolutionUtil.updateMaturity(solutionItem, sol_maturity); SolutionUtil.updateSolStatusByProvider(solutionItem, sol_statusByProvider); SolutionUtil.updateSolStatusBySAP(solutionItem, sol_statusBySAP); SolutionUtil.updateSolTargetCompSize(solutionItem, sol_targetCompSize); SolutionUtil.updateSolCategTarget(solutionItem, sol_categTarget); SolutionUtil.updateSolUserType(solutionItem, sol_userType); SolutionUtil.updateSolProgLang(solutionItem, sol_progLang); SolutionUtil.updateSolOS(solutionItem, sol_os); SolutionUtil.updateSolAioBased(solutionItem, sol_aioBased); SolutionItemDAO.updateSolutionItem(solutionItem); } else if (command.equals("delete")) { System.out.println("a facut delete "); System.out.println("a facut delete cu " + String.valueOf(id)); SolutionItemDAO.deleteSolutionItem(id); } } catch (SQLException sqle) { throw new PortletException(sqle); } }
From source file:com.nma.util.sdcardtrac.GraphFragment.java
private void drawGraph(LinearLayout view, boolean redraw) { float textSize, dispScale, pointSize; // Determine text size dispScale = getActivity().getResources().getDisplayMetrics().density; textSize = (GRAPHVIEW_TEXT_SIZE_DIP * dispScale) + 0.5f; pointSize = (GRAPHVIEW_POINT_SIZE_DIP * dispScale) + 0.5f; storageGraph = new LineGraphView(getActivity(), graphLabel); storageGraph.setCustomLabelFormatter(new CustomLabelFormatter() { String prevDate = ""; @Override//ww w . j av a 2 s . c o m public String formatLabel(double value, boolean isValueX, int index, int lastIndex) { String retValue; boolean valueXinRange; valueXinRange = (index == 0) || (index == lastIndex); if (isValueX) { // Format time in human readable form if (valueXinRange) { String dateStr; Date currDate = new Date((long) value); dateStr = DateFormat.getDateInstance(DateFormat.MEDIUM).format(currDate); if (dateStr.equals(prevDate)) { // Show hh:mm retValue = DateFormat.getTimeInstance(DateFormat.SHORT).format(currDate); } else { retValue = dateStr; } prevDate = dateStr; //Log.d(getClass().getName(), "Label is : " + retValue); } else { retValue = " "; } } else { // Format size in human readable form retValue = DatabaseLoader.convertToStorageUnits(value); //prevDate = ""; } //return super.formatLabel(value, isValueX); // let the y-value be normal-formatted return retValue; } }); storageGraph.addSeries(graphSeries); storageGraph.setManualYAxis(true); storageGraph.setManualYAxisBounds(maxStorage, 0); storageGraph.setScalable(false); //storageGraph.setScrollable(true); storageGraph.getGraphViewStyle().setGridColor(Color.GREEN); storageGraph.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW); storageGraph.getGraphViewStyle().setVerticalLabelsColor(Color.RED); storageGraph.getGraphViewStyle().setTextSize(textSize); storageGraph.getGraphViewStyle().setNumHorizontalLabels(2); storageGraph.getGraphViewStyle().setNumVerticalLabels(5); storageGraph.getGraphViewStyle().setVerticalLabelsWidth((int) (textSize * 4)); //storageGraph.setMultiLineXLabel(true, ";"); ((LineGraphView) storageGraph).setDrawBackground(true); ((LineGraphView) storageGraph).setDrawDataPoints(true); ((LineGraphView) storageGraph).setDataPointsRadius(pointSize); //storageGraph.highlightSample(0, true, locData.size() - 1); // Add selector callback storageGraph.setSelectHandler(this); setViewport(redraw); if (view != null) { view.addView(storageGraph); } if (SettingsActivity.ENABLE_DEBUG) Log.d(getClass().getName(), "Drew the graph, redraw=" + redraw); }
From source file:com.netflix.governator.lifecycle.LifecycleManager.java
private Date parseDate(String configurationName, String value, Configuration configuration) { DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); formatter.setLenient(false);/*from w w w .jav a2s .co m*/ try { return formatter.parse(value); } catch (ParseException e) { // ignore as the fallback is the DatattypeConverter. } try { return DatatypeConverter.parseDateTime(value).getTime(); } catch (IllegalArgumentException e) { ignoreTypeMismtachIfConfigured(configuration, configurationName, e); } return null; }
From source file:org.agnitas.web.UserActivityLogAction.java
/** * Gets format for date and time according to current admin locale * @param admin current admin in session * @return SimpleDateFormat object/*from w ww . jav a2 s . com*/ */ protected SimpleDateFormat getLocaleTableFormat(Admin admin) { Locale locale = admin.getLocale(); return (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); }
From source file:se.streamsource.streamflow.web.application.pdf.CasePdfGenerator.java
private void generateCaselog(Input<CaseLogEntryValue, RuntimeException> caselog) throws IOException { // TODO This needs to be cleaned up. Translations should be in a better place! ResourceBundle bnd = ResourceBundle.getBundle(MessagesContext.class.getName(), locale); final Map<String, String> translations = new HashMap<String, String>(); for (String key : bnd.keySet()) { translations.put(key, bnd.getString(key)); }// w w w .j a v a2s . co m caselog.transferTo(new Output<CaseLogEntryValue, IOException>() { public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends CaseLogEntryValue, SenderThrowableType> sender) throws IOException, SenderThrowableType { document.changeColor(headingColor).println(bundle.getString("caselog"), valueFontBold) .changeColor(Color.BLACK); sender.sendTo(new Receiver<CaseLogEntryValue, IOException>() { public void receive(CaseLogEntryValue entry) throws IOException { UnitOfWork uow = module.unitOfWorkFactory().currentUnitOfWork(); String label = uow.get(Describable.class, entry.createdBy().get().identity()) .getDescription() + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale) .format(entry.createdOn().get()) + ": "; document.print(label, valueFontBold) .print(Translator.translate(entry.message().get(), translations), valueFont) .print("", valueFont); } }); } }); }
From source file:com.facultyshowcase.app.ui.ProfessorProfileViewer.java
@Override public void init() { // Make sure you call super.init() at the top of this method. /// See the Javadoc for #init() for more information about what it does. super.init(); // Set HTML element type and class names for presentation use on this Container component. setHTMLElement(HTMLElement.section); addClassName("user-profile-viewer"); // property_viewer is a standard class name. addClassName(UIUtil.PROP + "erty-viewer"); // Add microdata for programmatic / SEO use /// OR use RDFa support /// You typically only do this in viewers - not editors. setAttribute("itemscope", ""); setAttribute("itemtype", "http://schema.org/Person"); // setAttribute allows you to set any attribute as long as it will not interfere with a component's /// native HTML. For example, you cannot set the "value" attribute on a Field since /// it uses that attribute. // It's a good idea to *not* mark variables final that you don't want in the scope of event listeners. /// Hibernate/JPA entities are a great example of this pattern. You always need to re-attach /// entities before using them, so we should always call getProfessorProfile() in the context /// of handling an event. Note: our getProfessorProfile() method re-attaches the entity. ProfessorProfile ProfessorProfile = getProfessorProfile(); Name name = ProfessorProfile.getName(); // You can use a Field for displaying non-internationalized content. /// It is desirable to do this since you don't need to create a LocalizedText. /// However, you cannot change the HTMLElement of a Field at this time, /// so some of the following code uses a Label which does allow /// specification of the HTMLElement. final Field slug = new Field(ProfessorProfile.getSlug(), false); final Field namePrefix = new Field(name.getFormOfAddress(), false); final Field nameGiven = new Field(name.getFirst(), false); final Field nameFamily = new Field(name.getLast(), false); final Field nameSuffix = new Field(name.getSuffix(), false); // Sometimes it is easier and less error prone to make a component non-visible /// than checking for null on each use. Use this pattern with care. You don't /// want to consume a lot of resource unnecessarily. if (StringFactory.isEmptyString(namePrefix.getText())) namePrefix.setVisible(false);/*from w w w . ja v a 2 s . c om*/ if (StringFactory.isEmptyString(nameSuffix.getText())) nameSuffix.setVisible(false); // Address Address address = ProfessorProfile.getPostalAddress(); // Address lines are always on their own line so we make sure they are enclosed by a block element like a DIV.. final Label addressLine1 = new Label(); addressLine1.setHTMLElement(HTMLElement.div).addClassName(UIUtil.PROP).addClassName(UIUtil.ADDRESS_LINE); final Label addressLine2 = new Label(); addressLine2.setHTMLElement(HTMLElement.div).addClassName(UIUtil.PROP).addClassName(UIUtil.ADDRESS_LINE); if (address.getAddressLines().length > 0) addressLine1.setText(TextSources.create(address.getAddressLines()[0])); if (address.getAddressLines().length > 1) addressLine2.setText(TextSources.create(address.getAddressLines()[1])); final HTMLComponent city = new HTMLComponent(); // The "prop" class name is part of the standard HTML structure. It is always a good idea to also /// add a specific class name like "city" in this example. Please be consistent when using class names. /// For example, if everyone else is using "city", please use "city" too. Don't come up with another class name /// that means something similar like "town" or "locality". Consistency has a big impact on /// the time required to style HTML as well as the ability to reuse CSS. city.setHTMLElement(HTMLElement.span).addClassName(UIUtil.PROP).addClassName(UIUtil.CITY); if (!StringFactory.isEmptyString(address.getCity())) { // Our microdata for the city shouldn't include the comma, so this is a bit more complicated than the other examples. city.setText(TextSources.create("<span item" + UIUtil.PROP + "=\"" + UIUtil.ADDRESS + "Locality\">" + address.getCity() + "</span><span class=\"delimiter\">,</span>")); } else city.setVisible(false); final Label state = new Label(TextSources.create(address.getState())); state.addClassName(UIUtil.PROP).addClassName(UIUtil.STATE); final Label postalCode = new Label(TextSources.create(address.getPostalCode())); postalCode.addClassName(UIUtil.PROP).addClassName(UIUtil.POSTAL_CODE); // Other Contact final Field phoneNumber = new Field(ProfessorProfile.getPhoneNumber(), false); final Field emailAddress = new Field(ProfessorProfile.getEmailAddress(), false); // Social Contact final URILink twitterLink = ProfessorProfile.getTwitterLink() != null ? new URILink(_ProfessorProfileDAO.toURI(ProfessorProfile.getTwitterLink(), null)) : null; final URILink facebookLink = ProfessorProfile.getFacebookLink() != null ? new URILink(_ProfessorProfileDAO.toURI(ProfessorProfile.getFacebookLink(), null)) : null; final URILink linkedInLink = ProfessorProfile.getLinkedInLink() != null ? new URILink(_ProfessorProfileDAO.toURI(ProfessorProfile.getLinkedInLink(), null)) : null; // We are going to output HTML received from the outside, so we need to sanitize it first for security reasons. /// Sometimes you'll do this sanitation prior to persisting the data. It depends on whether or not you need to /// keep the original unsanitized HTML around. final HTMLComponent aboutMeProse = new HTMLComponent( UIUtil.scrubHtml(ProfessorProfile.getAboutMeProse(), Event.getRequest(), Event.getResponse())); Component aboutMeVideo = null; URL videoLink = ProfessorProfile.getAboutMeVideoLink(); if (videoLink != null) { // There are several ways to link to media (Youtube video URL, Vimeo video URL, Flickr URL, internally hosted media file, etc). /// You can link to it. /// You can embed it. See http://oembed.com/ for a common protocol for doing this. /// If the link is to the media itself, you can create a player for it. /// Below is an example of creating a link to the video as well as a player. final URI videoLinkURI = _ProfessorProfileDAO.toURI(videoLink, null); URILink videoLinkComponent = new URILink(videoLinkURI, TextSources.create("My Video")); videoLinkComponent.setTarget("_blank"); IMediaUtility util = MediaUtilityFactory.getUtility(); try { // Check if we can parse the media and it has a stream we like. /// In our made up example, we're only accepting H.264 video. We don't care about the audio in this example. IMediaMetaData mmd; if (util.isEnabled() && videoLinkURI != null && (mmd = util.getMetaData(videoLinkURI.toString())).getStreams().length > 0) { int width = 853, height = 480; // 480p default boolean hasVideo = false; for (IMediaStream stream : mmd.getStreams()) { if (stream.getCodec().getType() == ICodec.Type.video && "H264".equals(stream.getCodec().name())) { hasVideo = true; if (stream.getWidth() > 0) { width = stream.getWidth(); height = stream.getHeight(); } break; } } if (hasVideo) { Media component = new Media(); component.setMediaType(Media.MediaType.video); component.addSource(new MediaSource(videoLinkURI)); component.setFallbackContent(videoLinkComponent); component.setSize(new PixelMetric(width), new PixelMetric(height)); aboutMeVideo = component; } } } catch (IllegalArgumentException | RemoteException e) { _logger.error("Unable to get media information for " + videoLink, e); } if (aboutMeVideo == null) { // We could check for oEmbed support in case link was to youtube, vimeo, etc - http://oembed.com/ // Since this is an example, we'll just output the link. aboutMeVideo = videoLinkComponent; } } ImageComponent picture = null; final FileEntity ProfessorProfilePicture = ProfessorProfile.getPicture(); if (ProfessorProfilePicture != null) { picture = new ImageComponent(new Image(ProfessorProfilePicture)); picture.setImageCaching(ProfessorProfilePicture.getLastModifiedTime() .before(new Date(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(60)))); } // Professional Information // We are going to output HTML received from the outside, so we need to sanitize it first for security reasons. /// Sometimes you'll do this sanitation prior to persisting the data. It depends on whether or not you need to /// keep the original unsanitized HTML around. final HTMLComponent researchSpecialty = new HTMLComponent( UIUtil.scrubHtml(ProfessorProfile.getAboutMeProse(), Event.getRequest(), Event.getResponse())); final Field rank = ProfessorProfile.getProfessorRank() != null ? new Field(ObjectUtils.toString(ProfessorProfile.getProfessorRank()), false) : null; final DateFormat parser = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); final Field dateJoined = ProfessorProfile.getDateJoined() != null ? new Field(parser.format(ProfessorProfile.getDateJoined()), false) : null; final Field onSabbatical = new Field(BooleanUtils.toStringYesNo(ProfessorProfile.isOnSabbatical()), false); // Now that we've initialized most of the content, we'll add all the components to this View /// using the standard HTML structure for a property viewer. add(of(HTMLElement.section, UIUtil.PROP + "-group " + UIUtil.NAME, new Label(TextSources.create("Name")).setHTMLElement(HTMLElement.h1), slug.setAttribute("item" + UIUtil.PROP, UIUtil.USER_ID).addClassName(UIUtil.PROP) .addClassName(UIUtil.USER_ID), namePrefix.setAttribute("item" + UIUtil.PROP, "honorificPrefix").addClassName(UIUtil.PROP) .addClassName(UIUtil.PREFIX), nameGiven.setAttribute("item" + UIUtil.PROP, "givenName").addClassName(UIUtil.PROP) .addClassName(UIUtil.FIRST_NAME), nameFamily.setAttribute("item" + UIUtil.PROP, "familyName").addClassName(UIUtil.PROP) .addClassName(UIUtil.LAST_NAME), nameSuffix.setAttribute("item" + UIUtil.PROP, "honorificSuffix").addClassName(UIUtil.PROP) .addClassName(UIUtil.SUFFIX))); // Add wrapping DIV to group address lines if necessary. Component streetAddress = (!StringFactory.isEmptyString(addressLine1.getText()) && !StringFactory.isEmptyString(addressLine2.getText()) ? of(HTMLElement.div, UIUtil.ADDRESS_LINES, addressLine1, addressLine2) : (StringFactory.isEmptyString(addressLine1.getText()) ? addressLine2 : addressLine1) .setHTMLElement(HTMLElement.div)); streetAddress.setAttribute("item" + UIUtil.PROP, "streetAddress"); boolean hasAddress = (!StringFactory.isEmptyString(addressLine1.getText()) || !StringFactory.isEmptyString(addressLine2.getText()) || !StringFactory.isEmptyString(city.getText()) || !StringFactory.isEmptyString(state.getText()) || !StringFactory.isEmptyString(postalCode.getText())); boolean hasPhone = !StringFactory.isEmptyString(phoneNumber.getText()); boolean hasEmail = !StringFactory.isEmptyString(emailAddress.getText()); // We only want to output the enclosing HTML if we have content to display. if (hasAddress || hasPhone || hasEmail) { Container contactContainer = of(HTMLElement.section, "contact", new Label(TextSources.create("Contact Information")).setHTMLElement(HTMLElement.h1)); add(contactContainer); if (hasAddress) { contactContainer.add(of(HTMLElement.div, UIUtil.PROP_GROUP + " " + UIUtil.ADDRESS, // We are using an H2 here because are immediate ancestor is a DIV. If it was a SECTION, /// then we would use an H1. See the ProfessorProfileViewer for a comparison. new Label(TextSources.create("Address")).setHTMLElement(HTMLElement.h2), streetAddress, of(HTMLElement.div, UIUtil.PLACE, city, state.setAttribute("item" + UIUtil.PROP, UIUtil.ADDRESS + "Region"), postalCode.setAttribute("item" + UIUtil.PROP, "postalCode"))) .setAttribute("item" + UIUtil.PROP, UIUtil.ADDRESS) .setAttribute("itemscope", "") .setAttribute("itemtype", "http://schema.org/PostalAddress")); } if (hasPhone) { contactContainer.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.PHONE, new Label(TextSources.create("Phone")).setHTMLElement(HTMLElement.h2), phoneNumber.setAttribute("item" + UIUtil.PROP, "telephone"))); } if (hasEmail) { contactContainer.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.EMAIL, new Label(TextSources.create("Email")).setHTMLElement(HTMLElement.h2), emailAddress.setAttribute("item" + UIUtil.PROP, UIUtil.EMAIL))); } } if (twitterLink != null || facebookLink != null || linkedInLink != null) { Container social = of(HTMLElement.section, UIUtil.SOCIAL, new Label(TextSources.create("Social Media Links")).setHTMLElement(HTMLElement.h1)); add(social); if (twitterLink != null) { twitterLink.setTarget("_blank"); twitterLink.setText(TextSources.create("Twitter Link")); social.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.TWITTER, TextSources.create("Twitter"), twitterLink)); } if (facebookLink != null) { facebookLink.setTarget("_blank"); facebookLink.setText(TextSources.create("Facebook Link")); social.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.FACEBOOK, TextSources.create("Facebook"), facebookLink)); } if (linkedInLink != null) { linkedInLink.setTarget("_blank"); linkedInLink.setText(TextSources.create("LinkedIn Link")); social.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.LINKEDIN, TextSources.create("LinkedIn"), linkedInLink)); } } final boolean hasAboutMeProse = StringFactory.isEmptyString(aboutMeProse.getText()); if (!hasAboutMeProse || aboutMeVideo != null) { Container aboutMe = of(HTMLElement.section, UIUtil.ABOUT_ME, new Label(TextSources.create("About Me")).setHTMLElement(HTMLElement.h1)); add(aboutMe); if (picture != null) { aboutMe.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.PICTURE, TextSources.create("Picture"), picture)); } if (hasAboutMeProse) { aboutMe.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.PROSE, TextSources.create("Hobbies, Interests..."), aboutMeProse)); } if (aboutMeVideo != null) { Label label = new Label(TextSources.create("Video")).setHTMLElement(HTMLElement.label); label.addClassName("vl"); aboutMe.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.VIDEO, label, aboutMeVideo)); } } final boolean hasResearchSpecialty = StringFactory.isEmptyString(researchSpecialty.getText()); if (!hasResearchSpecialty || rank != null || dateJoined != null || onSabbatical != null) { Container professionalInformation = of(HTMLElement.section, UIUtil.PROFESSIONAL_INFORMATION, new Label(TextSources.create("Professional Information")).setHTMLElement(HTMLElement.h1)); add(professionalInformation); if (rank != null) { professionalInformation.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.RANK, TextSources.create("Professor Rank"), rank)); } if (dateJoined != null) { Label label = new Label(TextSources.create("Date Joined")).setHTMLElement(HTMLElement.label); professionalInformation .add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.DATE_JOINED, label, dateJoined)); } if (onSabbatical != null) { Label label = new Label(TextSources.create("On Sabbatical")).setHTMLElement(HTMLElement.label); professionalInformation .add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.ON_SABBATICAL, label, onSabbatical)); } if (hasResearchSpecialty) { professionalInformation.add(of(HTMLElement.div, UIUtil.PROP + " " + UIUtil.PROSE, TextSources.create("Research Specialty"), aboutMeProse)); } } }