use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.
the class TranslatableMessageConverter method convertOutbound.
@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
User user = Common.getHttpUser();
Locale locale = null;
if (user != null)
locale = Locale.forLanguageTag(user.getLocale());
if (locale == null)
locale = Common.getLocale();
TranslatableMessage message = (TranslatableMessage) data;
String s = message.translate(Translations.getTranslations(locale));
return super.convertOutbound(s, outctx);
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.
the class PasswordResetService method sendEmail.
public void sendEmail(User user, String token) throws TemplateException, IOException, AddressException {
URI uri = null;
try {
uri = this.generateResetUrl(token);
} catch (Exception e) {
}
Translations translations = Translations.getTranslations(user.getLocaleObject());
Jws<Claims> parsed = this.parse(token);
Date expiration = parsed.getBody().getExpiration();
Map<String, Object> model = new HashMap<>();
model.put("username", user.getUsername());
model.put("resetUri", uri != null ? uri : "");
model.put("token", token);
model.put("expiration", expiration);
TranslatableMessage subject = new TranslatableMessage("ftl.passwordReset.subject", user.getUsername());
MangoEmailContent content = new MangoEmailContent("passwordReset", model, translations, subject.translate(translations), Common.UTF8);
EmailWorkItem.queueEmail(user.getEmail(), content);
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.
the class MangoExpiredSessionStrategy method onExpiredSessionDetected.
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
HttpServletRequest request = event.getRequest();
HttpServletResponse response = event.getResponse();
if (log.isDebugEnabled()) {
log.debug(String.format("Expired session detected, request URI is %s", request.getRequestURI()));
}
if (response.isCommitted())
return;
if (this.browserHtmlRequestMatcher.matches(request)) {
String loginUri = DefaultPagesDefinition.getLoginUri(request, response);
response.sendRedirect(loginUri);
} else {
TranslatableMessage message = new TranslatableMessage("rest.exception.sessionExpired");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message.translate(Common.getTranslations()));
}
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.
the class SpreadsheetEmporter method prepareSheetExport.
public void prepareSheetExport(AbstractSheetEmporter sheetEmporter) {
if (wb == null) {
return;
}
// Setup Stats For Entire Workbook
rowsProcessed = 0;
rowErrors = 0;
errorMessages = new ArrayList<TranslatableMessage>();
Sheet currentSheet = wb.createSheet(sheetEmporter.getSheetName());
sheetEmporter.setSheet(currentSheet);
CreationHelper createHelper = wb.getCreationHelper();
CellStyle dateStyle = wb.createCellStyle();
dateStyle.setDataFormat(createHelper.createDataFormat().getFormat(this.getDateFormat()));
sheetEmporter.setDateStyle(dateStyle);
CellStyle percentStyle = wb.createCellStyle();
percentStyle.setDataFormat(createHelper.createDataFormat().getFormat(DeltamationCommon.decimalFormat));
sheetEmporter.setPercentStyle(percentStyle);
rowNum = 0;
int cellNum = 0;
Cell cell;
Row row;
// headers
CellStyle headerStyle = wb.createCellStyle();
Font headerFont = wb.createFont();
headerFont.setBold(true);
headerStyle.setFont(headerFont);
row = currentSheet.createRow(sheetEmporter.incrementRowNum());
int[] columnWidths = sheetEmporter.getColumnWidths();
for (String text : sheetEmporter.getHeaders()) {
cell = row.createCell(cellNum);
cell.setCellValue(text);
currentSheet.setColumnWidth(cellNum, columnWidths[cellNum]);
cell.setCellStyle(headerStyle);
cellNum++;
}
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.
the class EventInstanceEmporter method exportRow.
/**
* @param vo
*/
public void exportRow(EventInstanceVO vo) {
int cellNum = 0;
Cell cell;
Row row;
row = sheet.createRow(this.rowNum++);
// Set Event Id
cell = row.createCell(cellNum++);
cell.setCellValue(vo.getId());
// Alarm Level
cell = row.createCell(cellNum++);
cell.setCellValue(AlarmLevels.getAlarmLevelMessage(vo.getAlarmLevel()).translate(Common.getTranslations()));
// Active Time
cell = row.createCell(cellNum++);
cell.setCellValue(new Date(vo.getActiveTimestamp()));
cell.setCellStyle(dateStyle);
// Message (Remove any HTML)
cell = row.createCell(cellNum++);
String messageStringHTML = vo.getMessageString();
String messageString = StringEscapeUtils.unescapeHtml4(messageStringHTML);
// Since we have <br/> in the code and that isn't proper HTML we need to remove it by hand
messageString = messageString.replace("<br/>", "\n");
cell.setCellValue(messageString);
// Status
cell = row.createCell(cellNum++);
if (vo.isActive())
cell.setCellValue(Common.translate("common.active"));
else if (!vo.isRtnApplicable())
cell.setCellValue("");
else
cell.setCellValue(vo.getRtnTimestampString() + " - " + vo.getRtnMessageString());
// Ack Time
// Ack User
cell = row.createCell(cellNum++);
Cell ackMsgCell = row.createCell(cellNum++);
cell.setCellStyle(dateStyle);
if (vo.isAcknowledged()) {
cell.setCellValue(new Date(vo.getAcknowledgedTimestamp()));
TranslatableMessage ackMessage;
if (vo.getAcknowledgedByUserId() != 0) {
ackMessage = new TranslatableMessage("events.export.ackedByUser", vo.getAcknowledgedByUsername());
} else {
ackMessage = vo.getAlternateAckSource();
}
if (ackMessage != null)
ackMsgCell.setCellValue(ackMessage.translate(Common.getTranslations()));
} else {
// Do we need to set the cell to null explicitly
}
}
Aggregations