Search in sources :

Example 51 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class InfoDisplayController method createInfoMessageForDisplay.

private InfoMessageForDisplay createInfoMessageForDisplay(InfoMessage info) {
    String message = info.getMessage();
    boolean html = StringHelper.isHtml(message);
    if (html) {
        message = message.toString();
    } else if (StringHelper.containsNonWhitespace(message)) {
        message = Formatter.escWithBR(info.getMessage()).toString();
        message = Formatter.formatURLsAsLinks(message);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    String modifier = null;
    if (info.getModifier() != null) {
        String formattedName = userManager.getUserDisplayName(info.getModifier());
        String creationDate = formatter.formatDateAndTime(info.getModificationDate());
        modifier = translate("display.modifier", new String[] { StringHelper.escapeHtml(formattedName), creationDate });
    }
    String authorName = userManager.getUserDisplayName(info.getAuthor());
    String creationDate = formatter.formatDateAndTime(info.getCreationDate());
    String infos;
    if (authorName.isEmpty()) {
        infos = translate("display.info.noauthor", new String[] { creationDate });
    } else {
        infos = translate("display.info", new String[] { StringHelper.escapeHtml(authorName), creationDate });
    }
    VFSLeaf attachment = infoMessageManager.getAttachment(info);
    return new InfoMessageForDisplay(info.getKey(), info.getTitle(), message, attachment, infos, modifier);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MailFormatter(org.olat.commons.info.manager.MailFormatter) Formatter(org.olat.core.util.Formatter)

Example 52 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class SubscriptionListItem method getPlaintextContent.

private String getPlaintextContent(Locale locale) {
    Translator trans = Util.createPackageTranslator(ContextualSubscriptionController.class, locale);
    Formatter form = Formatter.getInstance(locale);
    StringBuilder sb = new StringBuilder();
    String datePart = trans.translate("subscription.listitem.dateprefix", new String[] { form.formatDateAndTime(date) });
    sb.append("- ");
    sb.append(description.trim());
    sb.append(" ").append(datePart.trim());
    if (StringHelper.containsNonWhitespace(link))
        sb.append("\n").append("  ").append(link);
    return sb.toString();
}
Also used : Translator(org.olat.core.gui.translator.Translator) Formatter(org.olat.core.util.Formatter)

Example 53 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class SysinfoController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Formatter format = Formatter.getInstance(getLocale());
    // runtime informations
    FormLayoutContainer runtimeCont = FormLayoutContainer.createDefaultFormLayout("runtime", getTranslator());
    formLayout.add(runtimeCont);
    formLayout.add("runtime", runtimeCont);
    String startup = format.formatDateAndTime(new Date(WebappHelper.getTimeOfServerStartup()));
    uifactory.addStaticTextElement("runtime.startup", "runtime.startup", startup, runtimeCont);
    String time = format.formatDateAndTime(new Date()) + " (" + Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT, ureq.getLocale()) + ")";
    uifactory.addStaticTextElement("runtime.time", "runtime.time", time, runtimeCont);
    // memory
    uifactory.addMemoryView("memoryHeap", "runtime.memory", MemoryType.HEAP, runtimeCont);
    uifactory.addMemoryView("memoryNonHeap", "runtime.memory.permGen", MemoryType.NON_HEAP, runtimeCont);
    // controllers
    int controllerCnt = DefaultController.getControllerCount();
    uifactory.addStaticTextElement("controllercount", "runtime.controllercount", Integer.toString(controllerCnt), runtimeCont);
    int numOfDispatchingThreads = sessionStatsManager.getConcurrentCounter();
    uifactory.addStaticTextElement("dispatchingthreads", "runtime.dispatchingthreads", Integer.toString(numOfDispatchingThreads), runtimeCont);
    // sessions and clicks
    String sessionAndClicksPage = velocity_root + "/session_clicks.html";
    FormLayoutContainer sessionAndClicksCont = FormLayoutContainer.createCustomFormLayout("session_clicks", getTranslator(), sessionAndClicksPage);
    runtimeCont.add(sessionAndClicksCont);
    sessionAndClicksCont.setLabel("sess.and.clicks", null);
    Calendar lastLoginMonthlyLimit = Calendar.getInstance();
    // users monthly
    lastLoginMonthlyLimit.add(Calendar.MONTH, -1);
    Long userLastMonth = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    // -1 -5 = -6 for half a year
    lastLoginMonthlyLimit.add(Calendar.MONTH, -5);
    Long userLastSixMonths = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    // -1 -11 = -12 for one year
    lastLoginMonthlyLimit.add(Calendar.MONTH, -11);
    Long userLastYear = securityManager.countUniqueUserLoginsSince(lastLoginMonthlyLimit.getTime());
    sessionAndClicksCont.contextPut("users1month", userLastMonth.toString());
    sessionAndClicksCont.contextPut("users6month", userLastSixMonths.toString());
    sessionAndClicksCont.contextPut("usersyear", userLastYear.toString());
    // users daily
    Calendar lastLoginDailyLimit = Calendar.getInstance();
    lastLoginDailyLimit.add(Calendar.DAY_OF_YEAR, -1);
    Long userLastDay = securityManager.countUniqueUserLoginsSince(lastLoginDailyLimit.getTime());
    // -1 - 6 = -7 for last week
    lastLoginDailyLimit.add(Calendar.DAY_OF_YEAR, -6);
    Long userLast6Days = securityManager.countUniqueUserLoginsSince(lastLoginDailyLimit.getTime());
    sessionAndClicksCont.contextPut("userslastday", userLastDay.toString());
    sessionAndClicksCont.contextPut("userslastweek", userLast6Days.toString());
    // last 5 minutes
    long activeSessions = sessionStatsManager.getActiveSessions(300);
    sessionAndClicksCont.contextPut("count5Minutes", String.valueOf(activeSessions));
    SessionsStats stats = sessionStatsManager.getSessionsStatsLast(300);
    sessionAndClicksCont.contextPut("click5Minutes", String.valueOf(stats.getAuthenticatedClickCalls()));
    sessionAndClicksCont.contextPut("poll5Minutes", String.valueOf(stats.getAuthenticatedPollerCalls()));
    sessionAndClicksCont.contextPut("request5Minutes", String.valueOf(stats.getRequests()));
    sessionAndClicksCont.contextPut("minutes", String.valueOf(5));
    // last minute
    activeSessions = sessionStatsManager.getActiveSessions(60);
    sessionAndClicksCont.contextPut("count1Minute", String.valueOf(activeSessions));
    stats = sessionStatsManager.getSessionsStatsLast(60);
    sessionAndClicksCont.contextPut("click1Minute", String.valueOf(stats.getAuthenticatedClickCalls()));
    sessionAndClicksCont.contextPut("poll1Minute", String.valueOf(stats.getAuthenticatedPollerCalls()));
    sessionAndClicksCont.contextPut("request1Minute", String.valueOf(stats.getRequests()));
    sessionAndClicksCont.contextPut("oneMinute", "1");
    // server informations
    FormLayoutContainer serverCont = FormLayoutContainer.createDefaultFormLayout("server", getTranslator());
    formLayout.add(serverCont);
    formLayout.add("server", serverCont);
    // version
    uifactory.addStaticTextElement("version", "sysinfo.version", Settings.getFullVersionInfo(), serverCont);
    uifactory.addStaticTextElement("version.hg", "sysinfo.version.hg", WebappHelper.getChangeSet(), serverCont);
    String buildDate = format.formatDateAndTime(Settings.getBuildDate());
    uifactory.addStaticTextElement("version.date", "sysinfo.version.date", buildDate, serverCont);
    // cluster
    boolean clusterMode = "Cluster".equals(Settings.getClusterMode());
    MultipleSelectionElement clusterEl = uifactory.addCheckboxesHorizontal("cluster", "sysinfo.cluster", serverCont, new String[] { "xx" }, new String[] { "" });
    clusterEl.setEnabled(false);
    clusterEl.select("xx", clusterMode);
    String nodeId = StringHelper.containsNonWhitespace(Settings.getNodeInfo()) ? Settings.getNodeInfo() : "N1";
    uifactory.addStaticTextElement("node", "sysinfo.node", nodeId, serverCont);
    File baseDir = new File(WebappHelper.getContextRoot());
    String baseDirPath = null;
    try {
        baseDirPath = baseDir.getCanonicalPath();
    } catch (IOException e1) {
        baseDirPath = baseDir.getAbsolutePath();
    }
    uifactory.addStaticTextElement("sysinfo.basedir", "sysinfo.basedir", baseDirPath, serverCont);
    uifactory.addStaticTextElement("sysinfo.olatdata", "sysinfo.olatdata", WebappHelper.getUserDataRoot(), serverCont);
}
Also used : Formatter(org.olat.core.util.Formatter) Calendar(java.util.Calendar) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) IOException(java.io.IOException) Date(java.util.Date) SessionsStats(org.olat.admin.sysinfo.model.SessionsStats) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) File(java.io.File)

Example 54 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class LectureBlockAuditLogExport method addHeaders.

@Override
protected void addHeaders(OpenXMLWorksheet exportSheet) {
    Row headerRow = exportSheet.newRow();
    int pos = 0;
    headerRow.addCell(pos++, translator.translate("export.header.entry", new String[] { entry.getDisplayname() }));
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    String[] args = new String[] { lectureBlock.getTitle(), formatter.formatDate(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getEndDate()) };
    headerRow.addCell(pos++, translator.translate("export.header.lectureblocks", args));
}
Also used : Formatter(org.olat.core.util.Formatter) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row)

Example 55 with Formatter

use of org.olat.core.util.Formatter in project OpenOLAT by OpenOLAT.

the class LecturesBlockPDFExport method create.

public void create(List<Identity> rows, List<LectureBlockRollCall> rollCalls) throws IOException, TransformerException {
    addPageLandscape();
    String lectureBlockTitle = lectureBlock.getTitle();
    String resourceTitle = entry.getDisplayname();
    addMetadata(lectureBlockTitle, resourceTitle, teacher);
    String title = resourceTitle + " - " + lectureBlockTitle;
    title = translator.translate("attendance.list.title", new String[] { title });
    addParagraph(title, 16, true, width);
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    String dates = translator.translate("pdf.table.dates", new String[] { formatter.formatDate(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getStartDate()), formatter.formatTimeShort(lectureBlock.getEndDate()) });
    addParagraph(dates, 12, true, width);
    float cellMargin = 5.0f;
    float fontSize = 10.0f;
    Row[] content = getRows(rows, rollCalls);
    int numOfRows = content.length;
    for (int offset = 0; offset < numOfRows; ) {
        offset += drawTable(content, offset, fontSize, cellMargin);
        closePage();
        if (offset < numOfRows) {
            addPageLandscape();
        }
    }
    addPageNumbers();
}
Also used : Formatter(org.olat.core.util.Formatter)

Aggregations

Formatter (org.olat.core.util.Formatter)80 Date (java.util.Date)30 ArrayList (java.util.ArrayList)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 IOException (java.io.IOException)6 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)6 Identity (org.olat.core.id.Identity)6 Translator (org.olat.core.gui.translator.Translator)5 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 COSVisitorException (org.apache.pdfbox.exceptions.COSVisitorException)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 OWASPAntiSamyXSSFilter (org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2