Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

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

Prototype

int MEDIUM

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

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:com.nttec.everychan.ui.downloading.HtmlBuilder.java

public void write(SerializablePage page) throws IOException {
    this.res = MainApplication.getInstance().resources;
    this.chan = MainApplication.getInstance().getChanModule(page.boardModel.chan);
    this.pageModel = page.pageModel;
    this.boardModel = page.boardModel;
    this.dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    this.dateFormat.setTimeZone(TimeZone.getTimeZone(boardModel.timeZoneId));

    String logo = (page.boardModel.boardDescription != null ? page.boardModel.boardDescription
            : page.boardModel.boardName);
    try {//from  w  w w .  j a va 2 s.  com
        String url = chan.buildUrl(pageModel);
        logo += " <a href=\"" + url + "\">(" + chan.getChanName() + ")</a>";
    } catch (Exception e) {
        /* ignore */ }

    buildHeader(buildTitle(page), logo);

    if (page.posts != null && page.posts.length != 0) {
        ThreadModel thread = new ThreadModel();
        thread.posts = page.posts;
        thread.threadNumber = page.posts[0].number;
        thread.postsCount = -1;
        thread.attachmentsCount = -1;
        buildThread(thread);
    }
    if (page.threads != null) {
        for (ThreadModel thread : page.threads)
            buildThread(thread);
    }
    buf.write(HTML_FOOTER);
    buf.flush();
}

From source file:org.sakaiproject.news.tool.NewsAction.java

/**
 * build the context for the Main (Layout) panel
 * /*from w w w  .  j av a2  s .c om*/
 * @return (optional) template name for this panel
 */
public String buildMainPanelContext(VelocityPortlet portlet, Context context, RunData rundata,
        SessionState state) {
    context.put("tlang", rb);

    String mode = (String) state.getAttribute(STATE_MODE);
    if (MODE_OPTIONS.equals(mode)) {
        return buildOptionsPanelContext(portlet, context, rundata, state);
    }

    context.put(GRAPHIC_VERSION_TEXT, state.getAttribute(GRAPHIC_VERSION_TEXT));
    context.put(FULL_STORY_TEXT, state.getAttribute(FULL_STORY_TEXT));

    // build the menu
    Menu bar = new MenuImpl(portlet, rundata, (String) state.getAttribute(STATE_ACTION));

    // add options if allowed
    addOptionsMenu(bar, (JetspeedRunData) rundata);
    if (!bar.getItems().isEmpty()) {
        context.put(Menu.CONTEXT_MENU, bar);
    }

    context.put(Menu.CONTEXT_ACTION, state.getAttribute(STATE_ACTION));
    context.put(GRAPHIC_VERSION_TEXT, state.getAttribute(GRAPHIC_VERSION_TEXT));
    context.put(FULL_STORY_TEXT, state.getAttribute(FULL_STORY_TEXT));

    String url = (String) state.getAttribute(STATE_CHANNEL_URL);

    NewsChannel channel = null;
    List items = new Vector();

    try {
        channel = NewsService.getChannel(url);
        items = NewsService.getNewsitems(url);
    } catch (NewsConnectionException e) {
        // display message
        addAlert(state, rb.getFormattedMessage("unavailable", new Object[] { e.getLocalizedMessage() }));
        if (log.isDebugEnabled()) {
            log.debug(e);
        }
    } catch (NewsFormatException e) {
        // display message
        addAlert(state, rb.getFormattedMessage("unavailable", new Object[] { e.getLocalizedMessage() }));
        if (log.isDebugEnabled()) {
            log.debug(e);
        }
    } catch (Exception e) {
        // display message
        addAlert(state, rb.getFormattedMessage("unavailable", new Object[] { e.getLocalizedMessage() }));
        if (log.isDebugEnabled()) {
            log.debug(e);
        }
    }

    context.put("channel", channel);
    context.put("news_items", items);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
            new ResourceLoader().getLocale());
    df.setTimeZone(TimeService.getLocalTimeZone());
    context.put("dateFormat", df);
    try {
        // tracking event
        if (state.getAttribute(FEED_ACCESS) == null) {
            if (state.getAttribute(STATE_DETECT_REGISTERED_EVENT) == null) {
                // is News tool
                EventTrackingService.post(EventTrackingService.newEvent(FEED_ACCESS,
                        "/news/site/"
                                + SiteService.getSite(ToolManager.getCurrentPlacement().getContext()).getId()
                                + "/placement/" + SessionManager.getCurrentToolSession().getPlacementId(),
                        false));
            }
        } else {
            // extends News tool
            EventTrackingService.post(EventTrackingService.newEvent((String) state.getAttribute(FEED_ACCESS),
                    "/news/site/" + SiteService.getSite(ToolManager.getCurrentPlacement().getContext()).getId()
                            + "/placement/" + SessionManager.getCurrentToolSession().getPlacementId(),
                    false));
        }

    } catch (IdUnusedException e) {
        //should NEVER actually happen
        if (Log.getLogger("chef").isDebugEnabled()) {
            Log.debug("chef", "failed to log news access event due to invalid siteId");
        }
    }

    return (String) getContext(rundata).get("template") + "-Layout";

}

From source file:DateUtil.java

/**
 * Parses given string according to specified locale and <code>DateFormat.MEDIUM</code> style
 *
 * @param source Source string to parse date and time from
 * @param locale Locale to use for parsing date and time
 * @return Date object corresponding to representation given in source string
 * @throws ParseException if given string could not be properly parsed according to given locale and <code>DateFormat.MEDIUM</code> style
 * @see java.text.DateFormat//from  w w  w .  j a  v  a  2s.c  om
 * @see java.text.DateFormat#MEDIUM
 */
public static Date parseDateTime(String source, Locale locale) throws ParseException {
    return parseDateTime(source, locale, DateFormat.MEDIUM, DateFormat.MEDIUM);
}

From source file:com.miz.mizuu.fragments.ShowEpisodeDetailsFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    if (thisEpisode != null) {
        cover = (ImageView) v.findViewById(R.id.traktIcon);
        playbutton = (ImageView) v.findViewById(R.id.imageView2);
        title = (TextView) v.findViewById(R.id.overviewMessage);
        plot = (TextView) v.findViewById(R.id.textView2);
        airdate = (TextView) v.findViewById(R.id.textView9);
        rating = (TextView) v.findViewById(R.id.textView11);
        director = (TextView) v.findViewById(R.id.textView7);
        writer = (TextView) v.findViewById(R.id.textView3);
        gueststars = (TextView) v.findViewById(R.id.TextView04);
        file = (TextView) v.findViewById(R.id.TextView07);

        // Set the episode details
        title.setText(thisEpisode.getTitle());
        title.setTypeface(tf);//w w  w.j  av a2 s  .co m
        if (MizLib.isGoogleTV(getActivity()))
            title.setTextSize(28f);
        title.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

        if (!thisEpisode.getDescription().equals(getString(R.string.stringNA))
                && !MizLib.isEmpty(thisEpisode.getDescription()))
            plot.setText(thisEpisode.getDescription());
        else
            plot.setText(getString(R.string.stringNoPlot));

        if (MizLib.isEmpty(thisEpisode.getReleasedate())
                || thisEpisode.getReleasedate().equals(getString(R.string.stringNA))) {
            v.findViewById(R.id.tableRow1).setVisibility(View.GONE);
        } else {
            // Set the genre first aired date
            try {
                String[] date = thisEpisode.getReleasedate().split("-");
                Calendar cal = Calendar.getInstance();
                cal.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));

                airdate.setText(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())
                        .format(cal.getTime()));
            } catch (Exception e) { // Fall back if something goes wrong
                airdate.setText(thisEpisode.getReleasedate());
            }
        }

        if (!thisEpisode.getRating().equals("0/10"))
            rating.setText(thisEpisode.getRating());
        else
            v.findViewById(R.id.tableRow2).setVisibility(View.GONE);

        if (MizLib.isEmpty(thisEpisode.getDirector())
                || thisEpisode.getDirector().equals(getString(R.string.stringNA))) {
            v.findViewById(R.id.tableRow3).setVisibility(View.GONE);
        } else {
            director.setText(thisEpisode.getDirector());
        }

        if (MizLib.isEmpty(thisEpisode.getWriter())
                || thisEpisode.getWriter().equals(getString(R.string.stringNA))) {
            v.findViewById(R.id.tableRow4).setVisibility(View.GONE);
        } else {
            writer.setText(thisEpisode.getWriter());
        }

        if (MizLib.isEmpty(thisEpisode.getGuestStars())
                || thisEpisode.getGuestStars().equals(getString(R.string.stringNA))) {
            v.findViewById(R.id.tableRow5).setVisibility(View.GONE);
        } else {
            gueststars.setText(thisEpisode.getGuestStars());
        }

        file.setText(thisEpisode.getFilepath());

        playbutton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                play();
            }
        });

        mPicasso.load(thisEpisode.getEpisodePhoto()).skipMemoryCache().placeholder(R.drawable.bg).into(cover,
                new Callback() {
                    @Override
                    public void onError() {
                        if (isAdded())
                            mPicasso.load(MizLib.getTvShowThumbFolder(getActivity()) + "/"
                                    + thisEpisode.getShowId() + ".jpg").skipMemoryCache()
                                    .placeholder(R.drawable.bg).error(R.drawable.nobackdrop).into(cover);
                    }

                    @Override
                    public void onSuccess() {
                    }
                });
    }
}

From source file:net.joinedminds.masserr.Functions.java

public static String formatDate(Date dateTime) {
    StaplerRequest request = Stapler.getCurrentRequest();
    DateFormat format;//from w w  w .j  a  v  a  2  s .c o m
    if (request != null) {
        format = DateFormat.getDateInstance(DateFormat.MEDIUM, request.getLocale());
    } else {
        format = DateFormat.getDateInstance(DateFormat.MEDIUM);
    }
    return format.format(dateTime);
}

From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java

/**
 * <p>//from w  w w  .j av a  2s.c om
 *  ? ??? .
 * </p>
 * @param cmd
 *        <code>String[]</code>
 * @return ? ? ?
 * @throws FileSystemException
 */
public List ls(final String[] cmd) throws FileSystemException {
    List list = new ArrayList();

    int pos = 1;
    final boolean recursive;
    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = manager.resolveFile(basefile, cmd[pos]);
    } else {
        file = basefile;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        log.info("Contents of " + file.getName());
        log.info(listChildren(file, recursive, ""));
        // list.add(file.getName());
    } else {
        // Stat the file
        log.info(file.getName());
        final FileContent content = file.getContent();
        log.info("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        log.info("Last modified: " + lastMod);
    }

    return list;
}

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);//from   ww w. jav 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:org.jivesoftware.util.JiveGlobals.java

/**
 * Formats a Date object to return a date and time using the global locale.
 *
 * @param date the Date to format./* w  w w .jav a 2  s  . c  om*/
 * @return a String representing the date and time.
 */
public static String formatDateTime(Date date) {
    if (dateTimeFormat == null) {
        if (properties != null) {
            dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, getLocale());
            dateTimeFormat.setTimeZone(getTimeZone());
        } else {
            DateFormat instance = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                    getLocale());
            instance.setTimeZone(getTimeZone());
            return instance.format(date);
        }
    }
    return dateTimeFormat.format(date);
}

From source file:org.duniter.elasticsearch.synchro.SynchroService.java

public SynchroResult synchronizePeer(final Peer peer, boolean enableSynchroWebsocket) {
    long startExecutionTime = System.currentTimeMillis();

    // Check if peer alive and valid
    boolean isAliveAndValid = isAliveAndValid(peer);
    if (!isAliveAndValid) {
        logger.warn(String.format("[%s] [%s] Not reachable, or not running on this currency. Skipping.",
                peer.getCurrency(), peer));
        return null;
    }//from   w w  w.ja  va 2 s  .c  o m

    SynchroResult result = new SynchroResult();

    // Get the last execution time (or 0 is never synchronized)
    // If not the first synchro, add a delay to last execution time
    // to avoid missing data because incorrect clock configuration
    long lastExecutionTime = forceFullResync ? 0 : getLastExecutionTime(peer);
    if (logger.isDebugEnabled() && lastExecutionTime > 0) {
        logger.debug(String.format(
                "[%s] [%s] Found last synchronization execution at {%s}. Will apply time offset of {-%s ms}",
                peer.getCurrency(), peer, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM)
                        .format(new Date(lastExecutionTime * 1000)),
                pluginSettings.getSynchroTimeOffset()));
    }

    final long fromTime = lastExecutionTime > 0 ? lastExecutionTime - pluginSettings.getSynchroTimeOffset() : 0;

    if (logger.isInfoEnabled()) {
        if (fromTime == 0) {
            logger.info(String.format("[%s] [%s] Synchronization {ALL}...", peer.getCurrency(), peer));
        } else {
            logger.info(String.format("[%s] [%s] Synchronization delta since {%s}...", peer.getCurrency(), peer,
                    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM)
                            .format(new Date(fromTime * 1000))));
        }
    }

    // Execute actions
    List<SynchroAction> executedActions = actions.stream()
            .filter(a -> a.getEndPointApi().name().equals(peer.getApi())).map(a -> {
                try {
                    a.handleSynchronize(peer, fromTime, result);
                } catch (Exception e) {
                    logger.error(String.format("[%s] [%s] Failed to execute synchro action: %s",
                            peer.getCurrency(), peer, e.getMessage()), e);
                }
                return a;
            }).collect(Collectors.toList());

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("[%s] [%s] Synchronized in %s ms: %s", peer.getCurrency(), peer,
                System.currentTimeMillis() - startExecutionTime, result.toString()));
    }

    saveExecution(peer, result, startExecutionTime);

    // Start listen changes on this peer
    if (enableSynchroWebsocket) {
        startListenChangesOnPeer(peer, executedActions);
    }

    return result;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java

/**
 * RuntimePeriod get special handling, because they need two columns for one primitive type.
 * /* w  ww  .  j  a  v a  2 s .  co  m*/
 * @param instance
 * @param featureExpression
 * @param startCell
 * @param endCell
 */
private void importRuntimePeriodExpression(UniversalModelExpression instance,
        FeatureExpression<?> featureExpression, Cell startCell, Cell endCell) {

    try {
        Date startDate = (startCell != null) ? startCell.getDateCellValue() : null;
        Date endDate = (endCell != null) ? endCell.getDateCellValue() : null;

        if (startDate == null && endDate == null) {
            return;
        }

        if (startDate != null && endDate != null && startDate.getTime() > endDate.getTime()) {
            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, UserContext.getCurrentLocale());
            logError("Near cell {0}: RuntimePeriod: from {1} until {2} in instance {3}",
                    ExcelUtils.getFullCellName(startCell), df.format(startDate), df.format(endDate), instance);
        } else {
            RuntimePeriod rt = new RuntimePeriod(startDate, endDate);
            setValue(instance, (PropertyExpression<?>) featureExpression, rt, startCell);
        }
    } catch (Exception e) {
        logError("Near cell {0}: Error importing runtime period in {1}: {2}",
                ExcelUtils.getFullCellName(startCell), instance, e.getMessage());
    }
}