Search in sources :

Example 6 with Translator

use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.

the class NotificationsManagerImpl method processSubscribersByEmail.

private void processSubscribersByEmail(Identity ident) {
    if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
        // send only to active user
        return;
    }
    String userInterval = getUserIntervalOrDefault(ident);
    if ("never".equals(userInterval)) {
        return;
    }
    long start = System.currentTimeMillis();
    Date compareDate = getCompareDateFromInterval(userInterval);
    Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
    if (p != null) {
        Date latestEmail = new Date(p.getLongValue());
        if (latestEmail.after(compareDate)) {
            // nothing to do
            return;
        }
    }
    Date defaultCompareDate = getDefaultCompareDate();
    List<Subscriber> subscribers = getSubscribers(ident);
    if (subscribers.isEmpty()) {
        return;
    }
    String langPrefs = null;
    if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
        langPrefs = ident.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
    boolean veto = false;
    Subscriber latestSub = null;
    List<SubscriptionItem> items = new ArrayList<>();
    List<Subscriber> subsToUpdate = new ArrayList<>();
    for (Subscriber sub : subscribers) {
        Date latestEmail = sub.getLatestEmailed();
        SubscriptionItem subsitem = null;
        if (latestEmail == null || compareDate.after(latestEmail)) {
            // no notif. ever sent until now
            if (latestEmail == null) {
                latestEmail = defaultCompareDate;
            } else if (latestEmail.before(defaultCompareDate)) {
                // no notification older than a month
                latestEmail = defaultCompareDate;
            }
            subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
        } else if (latestEmail != null && latestEmail.after(compareDate)) {
        // already send an email within the user's settings interval
        // veto = true;
        }
        if (subsitem != null) {
            items.add(subsitem);
            subsToUpdate.add(sub);
        }
        latestSub = sub;
    }
    Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
    notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
Also used : Locale(java.util.Locale) SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) Subscriber(org.olat.core.commons.services.notifications.Subscriber) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property) Date(java.util.Date)

Example 7 with Translator

use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.

the class SubscriptionListItem method getHTMLContent.

private String getHTMLContent(Locale locale) {
    StringBuilder sb = new StringBuilder();
    Translator trans = Util.createPackageTranslator(ContextualSubscriptionController.class, locale);
    Formatter form = Formatter.getInstance(locale);
    String datePart = trans.translate("subscription.listitem.dateprefix", new String[] { form.formatDateAndTime(date) });
    sb.append("<li>");
    if (iconCssClass != null) {
        sb.append("<i class=\"o_icon o_icon-fw ");
        sb.append(iconCssClass);
        sb.append("\"></i>");
    }
    if (StringHelper.containsNonWhitespace(link)) {
        sb.append("<a href=\"");
        sb.append(link);
        sb.append("\">");
    }
    if (StringHelper.containsNonWhitespace(description)) {
        sb.append(new OWASPAntiSamyXSSFilter().filter(description.trim()));
    }
    if (StringHelper.containsNonWhitespace(link))
        sb.append("</a>");
    sb.append(" <span class='o_nowrap o_date'>").append(datePart.trim()).append("</span>");
    sb.append("</li>");
    return sb.toString();
}
Also used : OWASPAntiSamyXSSFilter(org.olat.core.util.filter.impl.OWASPAntiSamyXSSFilter) Translator(org.olat.core.gui.translator.Translator) Formatter(org.olat.core.util.Formatter)

Example 8 with Translator

use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.

the class NotificationsPortlet method createInstance.

/**
 * @see org.olat.gui.control.generic.portal.AbstractPortlet#createInstance(org.olat.core.gui.control.WindowControl, org.olat.core.gui.UserRequest, java.util.Map)
 */
public Portlet createInstance(WindowControl wControl, UserRequest ureq, Map<String, String> configuration) {
    Translator translator = Util.createPackageTranslator(NotificationsPortlet.class, ureq.getLocale());
    NotificationsPortlet p = new NotificationsPortlet();
    p.setName(this.getName());
    p.setConfiguration(configuration);
    p.setDefaultMaxEntries(getDefaultMaxEntries());
    p.setTranslator(translator);
    return p;
}
Also used : Translator(org.olat.core.gui.translator.Translator)

Example 9 with Translator

use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.

the class Form method create.

/**
 * create a new form, where the caller is attached as component listener.
 * Caller receives form validation success or failure events.
 *
 * @param name
 * @param translator
 * @param rootFormContainer if null the default layout is choosen, otherwise
 *          the given layouting container is taken.
 * @param listener the component listener of this form, typically the caller
 * @return
 */
public static Form create(String id, String name, FormItemContainer formLayout, Controller listener) {
    Form form = new Form();
    // this is where the formitems go to
    form.formLayout = formLayout;
    form.formLayout.setRootForm(form);
    form.formListeners = new ArrayList<FormBasicController>(1);
    if (listener instanceof FormBasicController) {
        form.formListeners.add((FormBasicController) listener);
    }
    Translator translator = formLayout.getTranslator();
    if (translator == null) {
        throw new AssertException("please provide a translator in the FormItemContainer <" + formLayout.getName() + ">");
    }
    // renders header + <formLayout> + footer of html form
    form.formWrapperComponent = new FormWrapperContainer(id, name, translator, form);
    form.formWrapperComponent.addListener(listener);
    // form.formWrapperComponent.put(formLayout.getComponent().getComponentName(), formLayout.getComponent());
    // generate name for form and dispatch uri hidden field
    form.formName = Form.FORMID + form.formWrapperComponent.getDispatchID();
    form.dispatchFieldId = form.formName + "_dispatchuri";
    form.eventFieldId = form.formName + "_eventval";
    return form;
}
Also used : AssertException(org.olat.core.logging.AssertException) Translator(org.olat.core.gui.translator.Translator)

Example 10 with Translator

use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.

the class FormLayoutContainer method add.

@Override
public void add(String name, FormItem formComp) {
    if (!hasRootForm) {
        throw new AssertionError("first ensure that the layout container knows about its rootform!!");
    }
    // set the formtranslator, and parent
    Translator itemTranslator = formComp.getTranslator();
    if (itemTranslator != null && itemTranslator instanceof PackageTranslator) {
        // let the FormItem provide a more specialized translator
        PackageTranslator itemPt = (PackageTranslator) itemTranslator;
        itemTranslator = PackageTranslator.cascadeTranslators(itemPt, translator);
    } else {
        itemTranslator = translator;
    }
    formComp.setTranslator(itemTranslator);
    formComp.setRootForm(getRootForm());
    // 
    String formCompName = name;
    // book keeping of FormComponent order
    formComponentsNames.add(formCompName);
    formComponents.put(formCompName, formComp);
    /*
		 * add the gui representation
		 */
    formLayoutContainer.put(formCompName, formComp.getComponent());
    formLayoutContainer.put(formCompName + FormItem.ERRORC, formComp.getErrorC());
    formLayoutContainer.put(formCompName + FormItem.EXAMPLEC, formComp.getExampleC());
    formLayoutContainer.put(formCompName + FormItem.LABELC, formComp.getLabelC());
    // Check for multipart data, add upload limit to form
    if (formComp instanceof FormMultipartItem) {
        getRootForm().setMultipartEnabled(true);
    }
}
Also used : PackageTranslator(org.olat.core.gui.translator.PackageTranslator) Translator(org.olat.core.gui.translator.Translator) PackageTranslator(org.olat.core.gui.translator.PackageTranslator) FormMultipartItem(org.olat.core.gui.components.form.flexible.FormMultipartItem)

Aggregations

Translator (org.olat.core.gui.translator.Translator)586 Identity (org.olat.core.id.Identity)62 Date (java.util.Date)54 Controller (org.olat.core.gui.control.Controller)54 RepositoryEntry (org.olat.repository.RepositoryEntry)54 Locale (java.util.Locale)52 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)46 ArrayList (java.util.ArrayList)40 TabbableController (org.olat.core.gui.control.generic.tabbable.TabbableController)40 NodeEditController (org.olat.course.editor.NodeEditController)40 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)36 Roles (org.olat.core.id.Roles)36 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)36 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)32 Publisher (org.olat.core.commons.services.notifications.Publisher)30 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)30 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)30 MailBundle (org.olat.core.util.mail.MailBundle)28 ICourse (org.olat.course.ICourse)26 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)26