Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

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

Prototype

int SHORT

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

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:hudson.model.Run.java

/**
 * Returns the build time stamp in the body.
 *///  www. j a  v  a 2 s  .co m
public void doBuildTimestamp(StaplerRequest req, StaplerResponse rsp, @QueryParameter String format)
        throws IOException {
    rsp.setContentType("text/plain");
    rsp.setCharacterEncoding("US-ASCII");
    rsp.setStatus(HttpServletResponse.SC_OK);
    DateFormat df = format == null
            ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.ENGLISH)
            : new SimpleDateFormat(format, req.getLocale());
    rsp.getWriter().print(df.format(getTime()));
}

From source file:org.mifos.accounts.business.AccountBO.java

protected void updateCustomFields(final List<CustomFieldDto> customFields) throws InvalidDateException {
    if (customFields == null) {
        return;//from w ww . j a v  a2s  . com
    }
    for (CustomFieldDto fieldView : customFields) {
        if (fieldView.getFieldType().equals(CustomFieldType.DATE.getValue())
                && org.apache.commons.lang.StringUtils.isNotBlank(fieldView.getFieldValue())) {
            SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT,
                    getUserContext().getPreferredLocale());
            String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern());
            fieldView.setFieldValue(DateUtils.convertUserToDbFmt(fieldView.getFieldValue(), userfmt));
        }
        if (getAccountCustomFields().size() > 0) {
            for (AccountCustomFieldEntity fieldEntity : getAccountCustomFields()) {
                if (fieldView.getFieldId().equals(fieldEntity.getFieldId())) {
                    fieldEntity.setFieldValue(fieldView.getFieldValue());
                }
            }
        } else {
            for (CustomFieldDto view : customFields) {
                this.getAccountCustomFields()
                        .add(new AccountCustomFieldEntity(this, view.getFieldId(), view.getFieldValue()));
            }
        }
    }
}

From source file:org.ejbca.core.model.ra.raadmin.EndEntityProfile.java

/** Implementation of UpgradableDataHashMap function upgrade. */
public void upgrade() {
    log.trace(">upgrade");
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        String msg = intres.getLocalizedMessage("ra.eeprofileupgrade", new Float(getVersion()));
        log.info(msg);//  ww w.j  a va  2  s.  co  m
        // New version of the class, upgrade
        if (getVersion() < 1) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberarray = (ArrayList<Integer>) data.get(NUMBERARRAY);
            while (numberarray.size() < 37) {
                numberarray.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberarray);
        }
        if (getVersion() < 2) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberarray = (ArrayList<Integer>) data.get(NUMBERARRAY);
            while (numberarray.size() < 39) {
                numberarray.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberarray);
            addField(AVAILCAS);
            addField(DEFAULTCA);
            setRequired(AVAILCAS, 0, true);
            setRequired(DEFAULTCA, 0, true);
        }
        if (getVersion() < 3) {
            // These fields have been removed in version 8, no need for this upgrade
            //setNotificationSubject("");
            //setNotificationSender("");
            //setNotificationMessage("");
        }
        if (getVersion() < 4) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
        }
        // Support for DirectoryName altname field in profile version 5
        if (getVersion() < 5) {
            addField(DnComponents.DIRECTORYNAME);
            setValue(DnComponents.DIRECTORYNAME, 0, "");
            setRequired(DnComponents.DIRECTORYNAME, 0, false);
            setUse(DnComponents.DIRECTORYNAME, 0, true);
            setModifyable(DnComponents.DIRECTORYNAME, 0, true);
        }
        // Support for Subject Directory Attributes field in profile version 6
        if (getVersion() < 6) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            data.put(SUBJECTDIRATTRFIELDORDER, new ArrayList<Integer>());

            for (int i = getParameterNumber(DnComponents.DATEOFBIRTH); i <= getParameterNumber(
                    DnComponents.COUNTRYOFRESIDENCE); i++) {
                addField(getParameter(i));
                setValue(getParameter(i), 0, "");
                setRequired(getParameter(i), 0, false);
                setUse(getParameter(i), 0, false);
                setModifyable(getParameter(i), 0, true);
            }
        }
        // Support for Start Time and End Time field in profile version 7
        if (getVersion() < 7) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            addField(STARTTIME);
            setValue(STARTTIME, 0, "");
            setRequired(STARTTIME, 0, false);
            setUse(STARTTIME, 0, false);
            setModifyable(STARTTIME, 0, true);
            addField(ENDTIME);
            setValue(ENDTIME, 0, "");
            setRequired(ENDTIME, 0, false);
            setUse(ENDTIME, 0, false);
            setModifyable(ENDTIME, 0, true);
        }
        // Notifications is now a more general mechanism in version 8
        if (getVersion() < 8) {
            log.debug("Upgrading User Notifications");
            if (data.get(UserNotification.NOTIFICATIONSENDER) != null) {
                UserNotification not = new UserNotification();
                not.setNotificationSender((String) data.get(UserNotification.NOTIFICATIONSENDER));
                if (data.get(UserNotification.NOTIFICATIONSUBJECT) != null) {
                    not.setNotificationSubject((String) data.get(UserNotification.NOTIFICATIONSUBJECT));
                }
                if (data.get(UserNotification.NOTIFICATIONMESSAGE) != null) {
                    not.setNotificationMessage((String) data.get(UserNotification.NOTIFICATIONMESSAGE));
                }
                // Add the statuschanges we used to send notifications about
                String events = UserNotification.EVENTS_EDITUSER;
                not.setNotificationEvents(events);
                // The old recipients where always the user
                not.setNotificationRecipient(UserNotification.RCPT_USER);
                addUserNotification(not);
            }
        }
        // Support for allowed requests in profile version 9
        if (getVersion() < 9) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            addField(ALLOWEDREQUESTS);
            setValue(ALLOWEDREQUESTS, 0, "");
            setRequired(ALLOWEDREQUESTS, 0, false);
            setUse(ALLOWEDREQUESTS, 0, false);
            setModifyable(ALLOWEDREQUESTS, 0, true);
        }
        // Support for merging DN from WS-API with default values in profile, in profile version 10
        if (getVersion() < 10) {
            setAllowMergeDnWebServices(false);
        }
        // Support for issuance revocation status in profile version 11
        if (getVersion() < 11) {
            setRequired(ISSUANCEREVOCATIONREASON, 0, false);
            setUse(ISSUANCEREVOCATIONREASON, 0, false);
            setModifyable(ISSUANCEREVOCATIONREASON, 0, true);
            setValue(ISSUANCEREVOCATIONREASON, 0, "" + RevokedCertInfo.NOT_REVOKED);
            setRequired(CARDNUMBER, 0, false);
            setUse(CARDNUMBER, 0, false);
            setModifyable(CARDNUMBER, 0, true);
        }
        // Support for maximum number of failed login attempts in profile version 12
        if (getVersion() < 12) {
            setRequired(MAXFAILEDLOGINS, 0, false);
            setUse(MAXFAILEDLOGINS, 0, false);
            setModifyable(MAXFAILEDLOGINS, 0, true);
            setValue(MAXFAILEDLOGINS, 0, Integer.toString(ExtendedInformation.DEFAULT_MAXLOGINATTEMPTS));
        }
        /* In EJBCA 4.0.0 we changed the date format to ISO 8601.
         * In the Admin GUI the example was:
         *     DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ejbcawebbean.getLocale())
         * but the only absolute format that could have worked is the same enforced by the 
         * doesUserFullfillEndEntityProfile check and this is what need to upgrade from:
         *       DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US)
         */
        if (getVersion() < 13) {
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
                    Locale.US);
            final FastDateFormat newDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm");
            try {
                final String oldStartTime = getValue(STARTTIME, 0);
                if (!isEmptyOrRelative(oldStartTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newStartTime = newDateFormat.format(oldDateFormat.parse(oldStartTime));
                    setValue(STARTTIME, 0, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + STARTTIME + " from \"" + oldStartTime + "\" to \""
                                + newStartTime + "\" in EndEntityProfile.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + STARTTIME
                        + " in EndEntityProfile! Manual interaction is required (edit and verify).", e);
            }
            try {
                final String oldEndTime = getValue(ENDTIME, 0);
                if (!isEmptyOrRelative(oldEndTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newEndTime = newDateFormat.format(oldDateFormat.parse(oldEndTime));
                    setValue(ENDTIME, 0, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ENDTIME + " from \"" + oldEndTime + "\" to \"" + newEndTime
                                + "\" in EndEntityProfile.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ENDTIME
                        + " in EndEntityProfile! Manual interaction is required (edit and verify).", e);
            }
        }
        /*
         * In version 13 we converted some dates to the "yyyy-MM-dd HH:mm" format using default Locale.
         * These needs to be converted to the same format but should be stored in UTC, so we always know what the times are.
         */
        if (getVersion() < 14) {
            final String[] timePatterns = { "yyyy-MM-dd HH:mm" };
            final String oldStartTime = getValue(STARTTIME, 0);
            if (!isEmptyOrRelative(oldStartTime)) {
                try {
                    final String newStartTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldStartTime, timePatterns));
                    setValue(STARTTIME, 0, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + STARTTIME + " from \"" + oldStartTime + "\" to \""
                                + newStartTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + STARTTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
            final String oldEndTime = getValue(ENDTIME, 0);
            if (!isEmptyOrRelative(oldEndTime)) {
                // We use an absolute time format, so we need to upgrade
                try {
                    final String newEndTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldEndTime, timePatterns));
                    setValue(ENDTIME, 0, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ENDTIME + " from \"" + oldEndTime + "\" to \"" + newEndTime
                                + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ENDTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
        }
        // Finally, update the version stored in the map to the current version
        data.put(VERSION, new Float(LATEST_VERSION));
    }
    log.trace("<upgrade");
}

From source file:org.opencms.ade.sitemap.CmsVfsSitemapService.java

/**
 * Converts a jsp navigation element into a client sitemap entry.<p>
 * //  w ww  . ja v a  2  s.  c  o  m
 * @param navElement the jsp navigation element
 * @param isRoot true if the entry is a root entry
 * 
 * @return the client sitemap entry 
 * @throws CmsException 
 */
private CmsClientSitemapEntry toClientEntry(CmsJspNavElement navElement, boolean isRoot) throws CmsException {

    CmsResource entryPage = null;
    CmsObject cms = getCmsObject();
    CmsClientSitemapEntry clientEntry = new CmsClientSitemapEntry();
    CmsResource entryFolder = null;

    CmsResource ownResource = navElement.getResource();
    clientEntry.setResourceState(ownResource.getState());
    CmsResource defaultFileResource = null;
    if (ownResource.isFolder()) {
        defaultFileResource = cms.readDefaultFile(ownResource, CmsResourceFilter.ONLY_VISIBLE);
    }

    Map<String, CmsClientProperty> ownProps = getClientProperties(cms, ownResource, false);

    Map<String, CmsClientProperty> defaultFileProps = null;
    if (defaultFileResource != null) {
        defaultFileProps = getClientProperties(cms, defaultFileResource, false);
        clientEntry.setDefaultFileId(defaultFileResource.getStructureId());
        clientEntry.setDefaultFileType(
                OpenCms.getResourceManager().getResourceType(defaultFileResource.getTypeId()).getTypeName());
    } else {
        defaultFileProps = new HashMap<String, CmsClientProperty>();
    }
    boolean isDefault = isDefaultFile(ownResource);
    clientEntry.setId(ownResource.getStructureId());
    clientEntry.setFolderDefaultPage(isDefault);
    if (navElement.getResource().isFolder()) {
        entryFolder = navElement.getResource();
        entryPage = defaultFileResource;
        clientEntry.setName(entryFolder.getName());
        if (entryPage == null) {
            entryPage = entryFolder;
        }
        if (!isRoot && isSubSitemap(navElement)) {
            clientEntry.setEntryType(EntryType.subSitemap);
            clientEntry.setDefaultFileType(null);
        }
        CmsLock folderLock = cms.getLock(entryFolder);
        clientEntry.setHasForeignFolderLock(
                !folderLock.isUnlocked() && !folderLock.isOwnedBy(cms.getRequestContext().getCurrentUser()));
        if (!cms.getRequestContext().getCurrentProject().isOnlineProject()) {
            List<CmsResource> blockingChildren = cms.getBlockingLockedResources(entryFolder);
            clientEntry.setBlockingLockedChildren((blockingChildren != null) && !blockingChildren.isEmpty());
        }
    } else {
        entryPage = navElement.getResource();
        clientEntry.setName(entryPage.getName());
        if (isRedirectType(entryPage.getTypeId())) {
            clientEntry.setEntryType(EntryType.redirect);
            CmsFile file = cms.readFile(entryPage);
            I_CmsXmlDocument content = CmsXmlContentFactory.unmarshal(cms, file);
            Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, entryPage);
            // ensure the content contains the default locale
            contentLocale = content.getBestMatchingLocale(contentLocale);
            if (contentLocale == null) {
                // no best matching locale, use the first available
                List<Locale> locales = content.getLocales();
                if (!locales.isEmpty()) {
                    contentLocale = locales.get(0);
                }
            }
            String link = "";
            if (contentLocale != null) {
                link = content.getValue(REDIRECT_LINK_TARGET_XPATH, contentLocale)
                        .getStringValue(getCmsObject());
            }
            clientEntry.setRedirectTarget(link);
        } else {
            clientEntry.setEntryType(EntryType.leaf);
        }
    }
    long dateExpired = navElement.getResource().getDateExpired();
    if (dateExpired != CmsResource.DATE_EXPIRED_DEFAULT) {
        clientEntry.setDateExpired(
                CmsDateUtil.getDate(new Date(dateExpired), DateFormat.SHORT, getWorkplaceLocale()));
    }
    long dateReleased = navElement.getResource().getDateReleased();
    if (dateReleased != CmsResource.DATE_RELEASED_DEFAULT) {
        clientEntry.setDateReleased(
                CmsDateUtil.getDate(new Date(dateReleased), DateFormat.SHORT, getWorkplaceLocale()));
    }
    clientEntry.setResleasedAndNotExpired(
            navElement.getResource().isReleasedAndNotExpired(System.currentTimeMillis()));
    String path = cms.getSitePath(entryPage);
    clientEntry.setVfsPath(path);
    clientEntry.setOwnProperties(ownProps);
    clientEntry.setDefaultFileProperties(defaultFileProps);
    clientEntry.setSitePath(entryFolder != null ? cms.getSitePath(entryFolder) : path);
    //CHECK: assuming that, if entryPage refers to the default file, the lock state of the folder 
    clientEntry.setLock(generateClientLock(entryPage));
    clientEntry.setInNavigation(isRoot || navElement.isInNavigation());
    String type = OpenCms.getResourceManager().getResourceType(ownResource).getTypeName();
    clientEntry.setResourceTypeName(type);
    return clientEntry;
}

From source file:es.caib.seycon.ng.servei.XarxaServiceImpl.java

@Override
protected Maquina handleRegisterDynamicIP(String nomMaquina, String ip, String serialNumber)
        throws es.caib.seycon.ng.exception.UnknownHostException, UnknownNetworkException {
    boolean anyChange = false;
    // First. Test if this IP belongs to anybody else
    MaquinaEntity old = getMaquinaEntityDao().findByAdreca(ip);
    MaquinaEntity maquina = null;/*from  www .  j a v a  2 s  .  c o m*/
    if (old != null) {
        if (serialNumber.equals(old.getSerialNumber())) {
            maquina = old;
            // Coincide serial number 
            if (!nomMaquina.equals(maquina.getNom())) {
                // Host name changed
                // Check if already exists such a name
                old = getMaquinaEntityDao().findByNom(nomMaquina);
                if (old != null) {
                    old.setDeleted(true);
                    getMaquinaEntityDao().update(old);
                }
                maquina.setNom(nomMaquina);
                anyChange = true;
            }
        } else {
            if (old.getDeleted().booleanValue() || old.getDynamicIP().booleanValue()) {
                old.setAdreca(null);
                old.setXarxa(null);
                getMaquinaEntityDao().update(old);
            } else {
                log.warn(String.format(Messages.getString("XarxaServiceImpl.HostsCollisionMessage"), //$NON-NLS-1$
                        nomMaquina, nomMaquina, ip, serialNumber));
                throw new UnknownHostException(
                        String.format(Messages.getString("XarxaServiceImpl.IPAssignedMessage"), //$NON-NLS-1$
                                ip, old.getNom()));
            }
        }
    }
    // Second. Test if this name belongs to anybody else
    if (maquina == null) {
        // Found a host with no serial number => Bind it
        old = getMaquinaEntityDao().findByNom(nomMaquina);
        if (old == null) {
            // Nothing to do
        } else if (old.getSerialNumber() == null && old.getDynamicIP().booleanValue()) {
            // Replace unused host
            maquina = old;
            maquina.setSerialNumber(serialNumber);
            maquina.setAdreca(ip);
            maquina.setLastSeen(new Date());
            getMaquinaEntityDao().update(maquina);
        } else if (serialNumber.equals(old.getSerialNumber())) {
            // Found host entry
            maquina = old;
        } else if (old.getDynamicIP().booleanValue()) {
            // Autodelete
            old.setDeleted(true);
            getMaquinaEntityDao().update(old);
        } else {
            log.warn(String.format(Messages.getString("XarxaServiceImpl.HostsCollisionMessage"), //$NON-NLS-1$
                    nomMaquina, nomMaquina, ip, serialNumber));
            throw new UnknownHostException(nomMaquina);
        }
    }
    // Third. Test if this serial is already used (with another name)
    if (maquina == null) {
        maquina = getMaquinaEntityDao().findBySerialNumber(serialNumber);
        if (maquina != null && !nomMaquina.equals(maquina.getNom())) {
            anyChange = true;
            maquina.setNom(nomMaquina);
        }
    }

    if (maquina == null) {
        try {
            InetAddress addr = InetAddress.getByName(ip);
            XarxaEntity x = guessNetwork(addr.getAddress());
            if (x == null) {
                String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), //$NON-NLS-1$
                        nomMaquina, ip);
                log.warn(msg);
                throw new UnknownNetworkException(msg);
            }
            maquina = getMaquinaEntityDao().newMaquinaEntity();
            maquina.setAdreca(ip);
            maquina.setCorreu("N"); //$NON-NLS-1$
            maquina.setDeleted(false);
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
            maquina.setDescripcio(Messages.getString("XarxaServiceImpl.AutocreatedMessage") + //$NON-NLS-1$
                    " " + // $NON-NLS-1$ //$NON-NLS-1$
                    df.format(new Date())); //$NON-NLS-1$
            maquina.setDynamicIP(new Boolean(true));
            maquina.setNom(nomMaquina);
            maquina.setOfimatica("N"); //$NON-NLS-1$
            maquina.setSerialNumber(serialNumber);
            maquina.setServidorImpressores("N"); //$NON-NLS-1$
            maquina.setOperatingSystem(getOsTypeEntityDao().findOSTypeByName("ALT")); //$NON-NLS-1$
            maquina.setXarxa(x);
            getMaquinaEntityDao().create(maquina);
        } catch (java.net.UnknownHostException e) {
            String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, //$NON-NLS-1$
                    "??"); //$NON-NLS-1$ 
            log.warn(msg);
            throw new UnknownNetworkException(msg);
        }
    }

    if (!ip.equals(maquina.getAdreca()) || maquina.getXarxa() == null
            || !Boolean.FALSE.equals(maquina.getDeleted())) {
        try {
            InetAddress addr = InetAddress.getByName(ip);
            XarxaEntity x = guessNetwork(addr.getAddress());
            if (x != null) {
                if (x.isDchpSupport()) {
                    anyChange = true;
                    maquina.setDeleted(Boolean.FALSE);
                    maquina.setAdreca(ip);
                    maquina.setXarxa(x);
                } else {
                    throw new UnknownNetworkException(
                            String.format(Messages.getString("XarxaServiceImpl.RequestWithoutDHCP"), //$NON-NLS-1$
                                    nomMaquina, ip, x.getCodi()));
                }
            } else {
                throw new UnknownNetworkException(String
                        .format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, ip)); //$NON-NLS-1$
            }
        } catch (java.net.UnknownHostException e) {
            String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, //$NON-NLS-1$
                    "??"); //$NON-NLS-1$ 
            log.warn(msg);
            throw new UnknownNetworkException(msg);
        }
    }
    if (anyChange || maquina.getLastSeen() == null
            || System.currentTimeMillis() - maquina.getLastSeen().getTime() > 8 * 60L * 60L * 1000L) // each 8 hours update last seen
    {
        maquina.setLastSeen(new Date());
        getMaquinaEntityDao().update(maquina);
    }

    return getMaquinaEntityDao().toMaquina(maquina);
}

From source file:org.exoplatform.outlook.OutlookServiceImpl.java

/**
 * Generate message summary text./*from w w  w. j av a  2s.  com*/
 * 
 * @param message {@link String}
 * @return {@link String}
 */
protected String messageSummary(OutlookMessage message) {
    String fromEmail = message.getFrom().getEmail();
    String fromName = message.getFrom().getDisplayName();
    Date time = message.getCreated().getTime();

    Locale locale = Locale.ENGLISH;
    ResourceBundle res = resourceBundleService.getResourceBundle("locale.outlook.Outlook", locale);

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

    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();
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/*  w  w  w  .  j a  v a 2  s. c o  m*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible().booleanValue();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        JRFontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance();
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {/*from w  w  w  .j  a  v a2 s  . co  m*/
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible.booleanValue()) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance();
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/* w  w  w  . j av  a2 s. co m*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        FontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(getFontUtil().getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//from  w  ww . ja va  2s . c o m
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}