Example usage for java.text DateFormat FULL

List of usage examples for java.text DateFormat FULL

Introduction

In this page you can find the example usage for java.text DateFormat FULL.

Prototype

int FULL

To view the source code for java.text DateFormat FULL.

Click Source Link

Document

Constant for full style pattern.

Usage

From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java

/**
 * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveRetailerContactMail(Localization localization, Customer customer, String velocityPath, RetailerContactEmailBean retailerContactEmailBean)
 *//*from w w  w  . j a va2  s  .  c  o m*/
public void buildAndSaveRetailerContactMail(final RequestData requestData, final Customer customer,
        final String velocityPath, final RetailerContactEmailBean retailerContactEmailBean) throws Exception {
    try {
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(retailerContactEmailBean);

        Map<String, Object> model = new HashMap<String, Object>();
        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put(CUSTOMER, customer);
        model.put("retailerContactEmailBean", retailerContactEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromAddress = handleFromAddress(retailerContactEmailBean.getFromAddress(), locale);
        String fromName = handleFromName(retailerContactEmailBean.getFromName(), locale);
        String toEmail = retailerContactEmailBean.getToEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_RETAILER_CONTACT, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { retailerContactEmailBean.getLastname(),
                retailerContactEmailBean.getFirstname() };
        mimeMessagePreparator.setSubject(
                coreMessageSource.getMessage("email.retailer_contact.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "retailer-contact-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                velocityPath + "retailer-contact-text-content.vm", model));

        Email email = new Email();
        email.setType(Email.EMAIl_TYPE_RETAILER_CONTACT);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
}

From source file:gob.dp.simco.intervencion.controller.IntervencionController.java

public boolean initJasper() throws JRException {
    List<ReportPlanIntervencionVO> lista = new ArrayList<>();
    ReportPlanIntervencionVO vo = new ReportPlanIntervencionVO();
    vo.setDescripcion(intervencion.getDescripcion());
    vo.setNombre(intervencion.getNombre());
    DateFormat df2 = DateFormat.getDateInstance(DateFormat.MEDIUM);
    DateFormat df4 = DateFormat.getDateInstance(DateFormat.FULL);
    if (intervencion.getId() != null) {
        List<IntervencionEtapa> etapasTotales = intervencionEtapaService
                .intervencionEtapaxIntervencion(intervencion.getId());
        for (IntervencionEtapa ei : etapasTotales) {
            List<IntervencionEtapaActuacion> listiea = intervencionEtapaActuacionService
                    .intervencionEtapaActuacionBuscarActividadGSA(ei.getId());
            ei.setIeas(listiea);// w ww  .  ja v  a2  s .co m
        }
        vo.setEtapasTotales(etapasTotales);

        List<IntervencionAccion> accionesSeleccionadas = intervencionAccionService
                .intervencionAccionBuscarxIntervencion(intervencion.getId());
        int j = 0;
        for (IntervencionAccion ia : accionesSeleccionadas) {
            j = ++j;
            ia.setNumero("3." + j + " Campo de accion " + j + ":");
            ia.setEtapas(intervencionEtapaService.intervencionEtapaxAccion(ia.getId()));
            int k = 0;
            for (IntervencionEtapa ie : ia.getEtapas()) {
                k = ++k;
                ie.setNumero1("3." + j + "." + k);
                String s4 = "";
                if (ie.getFechaLimite() != null) {
                    s4 = df4.format(ie.getFechaLimite());
                }
                if (ie.getDescripcion() == null) {
                    ie.setDescripcion("");
                }
                ie.setFechaLimiteString(s4);
                ie.setNumero2(ie.getNumero1() + ".1");
                ie.setNumero3(ie.getNumero1() + ".2");
                ie.setIeas(intervencionEtapaActuacionService
                        .intervencionEtapaActuacionBuscarActividad(ie.getId()));
                for (IntervencionEtapaActuacion etapaActuacion : ie.getIeas()) {
                    if (etapaActuacion.getActividadId() != null) {
                        etapaActuacion.setDetalleReporte(etapaActuacion.getDescripcion() + " (realizada el "
                                + df2.format(etapaActuacion.getFechaCulminacion()) + " - "
                                + etapaActuacion.getCodigoActividad() + " \" "
                                + etapaActuacion.getNombreActividad() + " \")");
                    } else {
                        etapaActuacion.setDetalleReporte(etapaActuacion.getDescripcion());
                    }
                }
                Integer porcentaje = defineAvanceReport(ie.getIeas());
                ie.setAvanceString("Actuaciones defensoriales planificadas(" + porcentaje + "% de avance)");
                String estadoReporte = "";
                if (porcentaje == 0) {
                    estadoReporte = "Planificado";
                }
                if (porcentaje < 100 && porcentaje > 0) {
                    estadoReporte = "En Ejecucion";
                }
                if (porcentaje == 100) {
                    estadoReporte = "Ejecutado";
                }
                ie.setDetalle(ie.getDetalle() + "(" + estadoReporte + ")");

                List<IntervencionMiembro> miembros = intervencionMiembroService
                        .intervencionMiembroBuscar(ie.getId());
                ie.setIms(miembros);
            }
        }

        vo.setAccionesSeleccionadas(accionesSeleccionadas);

        vo.setEtapas(listPlanificado);
        List<IntervencionAccion> ias = new ArrayList<>();
        int i = 0;
        for (IntervencionAccion ia : accions) {
            i++;
            ia.setNumero("2." + i);
            ias.add(ia);
        }
        vo.setAcciones(ias);
        vo.setImagePath(ConstantesUtil.BASE_URL_IMAGEPATH + "logoPlanIntervencion.png");

        lista.add(vo);

        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(lista);
        jasperPrint = JasperFillManager.fillReport(ConstantesUtil.BASE_URL_REPORT + "planIntervencion.jasper",
                new HashMap(), beanCollectionDataSource);
        return true;
    } else {
        msg.messageAlert("No existe un plan de intervencion para este caso", null);
        return false;
    }
}

From source file:GuestBookServlet.java

private void printComments(PrintWriter out, Locale loc) throws IOException {
    Connection conn = null;//w  w  w .  j  av a 2 s. c o  m

    try {
        DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, loc);
        ResultSet results;
        Statement stmt;
        int rows, count;

        conn = DriverManager.getConnection(jdbcURL, connectionProperties);
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        results = stmt.executeQuery("SELECT NAME, EMAIL, CMT_DATE, " + "COMMENT, COMMENT_ID " + "FROM COMMENT "
                + "ORDER BY CMT_DATE");
        out.println("<dl>");
        results.last();
        results.next();
        rows = results.getRow();
        // pick a random row
        rows = random.nextInt() % rows;
        if (rows < 4) {
            // if the random row is less than 4, print the first 4 rows
            results.afterLast();
        } else {
            // otherwise go to the specified row, print the prior 5 rows
            results.absolute(rows);
        }
        count = 0;
        // print up to 5 rows going backwards from the randomly
        // selected row
        while (results.previous() && (count < 5)) {
            String name, email, cmt;
            Date date;

            count++;
            name = results.getString(1);
            if (results.wasNull()) {
                name = "Unknown User";
            }
            email = results.getString(2);
            if (results.wasNull()) {
                email = "user@host";
            }
            date = results.getDate(3);
            if (results.wasNull()) {
                date = new Date((new java.util.Date()).getTime());
            }
            cmt = results.getString(4);
            if (results.wasNull()) {
                cmt = "No comment.";
            }
            out.println("<dt><b>" + name + "</b> (" + email + ") on " + fmt.format(date) + "</dt>");
            cmt = noXML(cmt);
            out.println("<dd> " + cmt + "</dd>");
        }
        out.println("</dl>");
    } catch (SQLException e) {
        out.println("A database error occurred: " + e.getMessage());
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
}

From source file:org.exoplatform.outlook.social.OutlookMessageActivity.java

/**
 * {@inheritDoc}//from   ww w .j  av  a 2 s  . c om
 */
@Override
public String getSummary(Node node) {
    try {
        if (node.isNodeType(OutlookService.MESSAGE_NODETYPE)) {
            String fromEmail = node.getProperty("mso:fromEmail").getString();
            String fromName = node.getProperty("mso:fromName").getString();
            Date time = node.getProperty("mso:created").getDate().getTime();

            Locale userLocale = null;
            RequestContext context = RequestContext.getCurrentInstance();
            OrganizationService orgService = getApplicationComponent(OrganizationService.class);
            try {
                UserProfile userProfile = orgService.getUserProfileHandler()
                        .findUserProfileByName(context.getRemoteUser());
                if (userProfile != null) {
                    String lang = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
                    if (lang != null) {
                        userLocale = LocaleContextInfo.getLocale(lang);
                    }
                } else if (LOG.isDebugEnabled()) {
                    LOG.debug("User profile not found for " + context.getRemoteUser());
                }
            } catch (Exception e) {
                LOG.warn("Error getting user profile for " + context.getRemoteUser(), e);
            }

            if (userLocale == null) {
                // try find locale from user request
                if (PortletRequestContext.class.isAssignableFrom(context.getClass())) {
                    userLocale = ((PortalRequestContext) PortletRequestContext.class.cast(context)
                            .getParentAppRequestContext()).getRequest().getLocale();
                } else if (PortalRequestContext.class.isAssignableFrom(context.getClass())) {
                    userLocale = PortalRequestContext.class.cast(context).getRequest().getLocale();
                }
                if (userLocale == null) {
                    // it's server locale in most cases
                    userLocale = context.getLocale();
                    if (userLocale == null) {
                        userLocale = Locale.ENGLISH;
                    }
                }
            }

            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, userLocale);
            DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, userLocale);

            ResourceBundle res = context.getApplicationResourceBundle();

            StringBuilder fromLine = new StringBuilder();
            fromLine.append(fromName);
            fromLine.append('<');
            fromLine.append(fromEmail);
            fromLine.append('>');

            StringBuilder summary = new StringBuilder();
            summary.append(res.getString("Outlook.activity.from"));
            summary.append(": <a href='mailto:");
            summary.append(fromEmail);
            summary.append("' target='_top'>");
            summary.append(ContentReader.simpleEscapeHtml(fromLine.toString()));
            summary.append("</a> ");
            summary.append(res.getString("Outlook.activity.on"));
            summary.append(' ');
            summary.append(dateFormat.format(time));
            summary.append(' ');
            summary.append(res.getString("Outlook.activity.at"));
            summary.append(' ');
            summary.append(timeFormat.format(time));

            return summary.toString();
        }
    } catch (RepositoryException e) {
        LOG.warn("Error generating info for Outlook message activity node " + node, e);
    }

    return super.getSummary(node);
}

From source file:org.hoteia.qalingo.core.service.EmailService.java

/**
 * @throws Exception //w w  w  .ja  v  a  2 s.c  o m
 */
public Email buildAndSaveContactMail(final RequestData requestData, final String velocityPath,
        final ContactEmailBean contactEmailBean) throws Exception {
    Email email = null;
    try {
        final String contextNameValue = requestData.getContextNameValue();
        final Localization localization = requestData.getMarketAreaLocalization();
        final Locale locale = localization.getLocale();

        // SANITY CHECK
        checkEmailAddresses(contactEmailBean);

        Map<String, Object> model = new HashMap<String, Object>();
        DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale);
        java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime());
        model.put(CURRENT_DATE, dateFormatter.format(currentDate));
        model.put("contactEmailBean", contactEmailBean);
        model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale));

        String fromAddress = handleFromAddress(contactEmailBean.getFromAddress(), contextNameValue);
        String fromName = handleFromName(contactEmailBean.getFromName(), locale);
        String toEmail = contactEmailBean.getToEmail();

        MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData,
                Email.EMAIl_TYPE_CONTACT, model);
        mimeMessagePreparator.setTo(toEmail);
        mimeMessagePreparator.setFrom(fromAddress);
        mimeMessagePreparator.setFromName(fromName);
        mimeMessagePreparator.setReplyTo(fromAddress);
        Object[] parameters = { contactEmailBean.getLastname(), contactEmailBean.getFirstname() };
        mimeMessagePreparator
                .setSubject(coreMessageSource.getMessage("email.contact.email_subject", parameters, locale));
        mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(),
                velocityPath + "contact-html-content.vm", model));
        mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils
                .mergeTemplateIntoString(getVelocityEngine(), velocityPath + "contact-text-content.vm", model));

        email = new Email();
        email.setType(Email.EMAIl_TYPE_CONTACT);
        email.setStatus(Email.EMAIl_STATUS_PENDING);
        saveOrUpdateEmail(email, mimeMessagePreparator);

    } catch (MailException e) {
        logger.error("Error, can't save the message :", e);
        throw e;
    } catch (VelocityException e) {
        logger.error("Error, can't build the message :", e);
        throw e;
    } catch (IOException e) {
        logger.error("Error, can't serializable the message :", e);
        throw e;
    }
    return email;
}

From source file:org.lunarray.model.descriptor.util.DateFormatUtil.java

/**
 * Resolves the date format./*from w  ww .  j a  v  a 2  s  . com*/
 * 
 * @param locale
 *            The (optional) locale.
 * @return The format.
 */
private DateFormat resolveDateFormat(final Locale locale) {
    DateFormat defaultValue;
    if (CheckUtil.isNull(locale)) {
        defaultValue = DateFormat.getDateInstance(DateFormat.FULL);
    } else {
        defaultValue = DateFormat.getDateInstance(DateFormat.FULL, locale);
    }
    return this.resolve(DateFormatUtil.DEFAULT_DATE_KEY, defaultValue, locale);
}

From source file:me.ryanhamshire.PopulationDensity.DataStore.java

public void savePlayerData(OfflinePlayer player, PlayerData data) {
    //save that data in memory
    this.playerNameToPlayerDataMap.put(player.getUniqueId().toString(), data);

    BufferedWriter outStream = null;
    try {//from ww  w  .j  a  v a  2 s .  c o  m
        //open the player's file
        File playerFile = new File(playerDataFolderPath + File.separator + player.getUniqueId().toString());
        playerFile.createNewFile();
        outStream = new BufferedWriter(new FileWriter(playerFile));

        //first line is home region coordinates
        outStream.write(data.homeRegion.toString());
        outStream.newLine();

        //second line is last disconnection date,
        //note use of the ROOT locale to avoid problems related to regional settings on the server being updated
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.ROOT);
        outStream.write(dateFormat.format(data.lastDisconnect));
        outStream.newLine();

        //third line is login priority
        outStream.write(String.valueOf(data.loginPriority));
        outStream.newLine();
    }

    //if any problem, log it
    catch (Exception e) {
        PopulationDensity.AddLogEntry("PopulationDensity: Unexpected exception saving data for player \""
                + player.getName() + "\": " + e.getMessage());
    }

    try {
        //close the file
        if (outStream != null)
            outStream.close();
    } catch (IOException exception) {
    }
}

From source file:org.apache.wicket.protocol.http.mock.MockHttpServletRequest.java

/**
 * @param name//from  w  w  w  .  j  a v a  2s.c om
 * @param date
 */
public void addDateHeader(String name, long date) {
    DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
    String dateString = df.format(new Date(date));
    addHeader(name, dateString);
}

From source file:org.pentaho.reporting.libraries.formula.typing.DefaultTypeRegistry.java

public String convertToText(final Type type1, final Object value) throws EvaluationException {
    if (value == null) {
        return "";
    }//from   ww  w  .  j  ava 2 s . c  om

    // already converted or compatible
    if (type1.isFlagSet(Type.TEXT_TYPE)) {
        // no need to check whatever it is a String
        return computeStringValue(value);
    }

    if (type1.isFlagSet(Type.LOGICAL_TYPE)) {
        if (value instanceof Boolean) {
            final Boolean b = (Boolean) value;
            if (Boolean.TRUE.equals(b)) {
                return "TRUE";
            } else {
                return "FALSE";
            }
        } else {
            throw TypeConversionException.getInstance();
        }
    }

    // 2 types of numeric : numbers and dates
    if (type1.isFlagSet(Type.NUMERIC_TYPE)) {
        final LocalizationContext localizationContext = context.getLocalizationContext();
        if (type1.isFlagSet(Type.DATETIME_TYPE) || type1.isFlagSet(Type.DATE_TYPE)
                || type1.isFlagSet(Type.TIME_TYPE)) {
            final Date d = convertToDate(type1, value);
            final List dateFormats = localizationContext.getDateFormats(type1);
            if (dateFormats != null && dateFormats.size() >= 1) {
                final DateFormat format = (DateFormat) dateFormats.get(0);
                return format.format(d);
            } else {
                // fallback
                return DateFormat
                        .getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, localizationContext.getLocale())
                        .format(d);
            }
        } else {
            try {
                final Number n = convertToNumber(type1, value);
                final List<NumberFormat> numberFormats = localizationContext.getNumberFormats();
                if (numberFormats.isEmpty()) {
                    // use the canonical format ..
                    return NumberFormat.getNumberInstance(localizationContext.getLocale()).format(n);
                } else {
                    numberFormats.get(0).format(n);
                }
            } catch (EvaluationException nfe) {
                // ignore ..
            }
        }
    }

    return computeStringValue(value);
}

From source file:org.lunarray.model.descriptor.util.DateFormatUtil.java

/**
 * Resolves the date time format./*  w w w. j  a v a  2  s. c om*/
 * 
 * @param locale
 *            The (optional) locale.
 * @return The format.
 */
private DateFormat resolveDateTimeFormat(final Locale locale) {
    DateFormat defaultValue;
    if (CheckUtil.isNull(locale)) {
        defaultValue = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
    } else {
        defaultValue = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale);
    }
    return this.resolve(DateFormatUtil.DEFAULT_DATE_TIME_KEY, defaultValue, locale);
}