List of usage examples for java.time.format DateTimeFormatter withZone
public DateTimeFormatter withZone(ZoneId zone)
From source file:dhbw.clippinggorilla.external.mailserver.MailUtils.java
public static void sendClipping(Clipping clipping) { User user = UserUtils.getUser(clipping.getUserid()); String email = user.getEmail(); String html = CLIPPING_ROOT_HTML; String rows = ""; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd. LLLL. yyyy"); formatter.withZone(ZoneId.of("Europe/Berlin")); rows = clipping.getArticles().entrySet().stream().map((entry) -> { InterestProfile userprofile = entry.getKey(); LinkedHashSet<Article> articleSet = entry.getValue(); String profileRow = CLIPPING_GROUP_HTML.replace("[GROUPNAME]", userprofile.getName()); String articleRows = articleSet.stream() .map((article) -> CLIPPING_ARTICLE_HTML .replace("[ARTICLE_IMAGE_URL]", article.getUrlToImage().isEmpty() ? article.getSourceAsSource().getLogo().toExternalForm() : article.getUrlToImage()) .replace("[ARTICLE_TITLE]", article.getTitle()) .replace("[ARTICLE_DESCRIPTION]", article.getDescription().length() > 400 ? article.getDescription().substring(0, 400) + "..." : article.getDescription()) .replace("[SOURCE_NAME]", article.getSourceAsSource().getName()) .replace("[ARTICLE_DATE]", article.getPublishedAtAsLocalDateTime().toLocalDate().format(formatter)) .replace("[AUTHOR]", article.getAuthor())) .reduce("", String::concat); return profileRow + "\n" + articleRows; }).reduce(rows, String::concat); rows = clipping.getArticlesFromGroup().entrySet().stream().map((entry) -> { GroupInterestProfile groupprofile = entry.getKey(); LinkedHashSet<Article> articleSet = entry.getValue(); String profileRow = CLIPPING_GROUP_HTML.replace("[GROUPNAME]", groupprofile.getName()); String articleRows = articleSet.stream() .map((article) -> CLIPPING_ARTICLE_HTML .replace("[ARTICLE_IMAGE_URL]", article.getUrlToImage().isEmpty() ? article.getSourceAsSource().getLogo().toExternalForm() : article.getUrlToImage()) .replace("[ARTICLE_TITLE]", article.getTitle()) .replace("[ARTICLE_DESCRIPTION]", article.getDescription().length() > 400 ? article.getDescription().substring(0, 400) + "..." : article.getDescription()) .replace("[SOURCE_NAME]", article.getSourceAsSource().getName()) .replace("[ARTICLE_DATE]", article.getPublishedAtAsLocalDateTime().toLocalDate().format(formatter)) .replace("[AUTHOR]", article.getAuthor())) .reduce("", String::concat); return profileRow + "\n" + articleRows; }).reduce(rows, String::concat); String clippingText = Language.get(Word.CLIPPING_TEXT).replace("[FIRSTNAME]", user.getFirstName()) .replace("[LASTNAME]", user.getLastName()).replace("[DATE]", clipping.getDate().format(formatter)); html = html.replace("[CLIPPING_TEXT]", clippingText).replace("[GROUPS]", rows); // try { // Files.write(Paths.get(System.getProperty("user.home"), "Desktop", "email.html"), html.getBytes("UTF-8")); // } catch (IOException ex) { // Logger.getLogger(MailUtils.class.getName()).log(Level.SEVERE, null, ex); // }//from w w w. jav a 2s .c o m try { Mail.send(email, "ClippingGorilla Clippings", "Your email client does not support HTML messages", html); } catch (EmailException ex) { Log.error("Could not send Clipping to user " + user.getFirstName() + " " + user.getLastName() + " (" + user.getUsername() + ")", ex); } }
From source file:org.apache.metron.parsers.snort.BasicSnortParser.java
private DateTimeFormatter getDateFormatterWithZone(DateTimeFormatter formatter, Map<String, Object> parserConfig) { String timezone = (String) parserConfig.get("timeZone"); if (StringUtils.isNotEmpty(timezone)) { if (ZoneId.getAvailableZoneIds().contains(timezone)) { _LOG.info("Using timezone '{}'", timezone); return formatter.withZone(ZoneId.of(timezone)); } else {//from w w w. j av a2 s.com throw new IllegalArgumentException("Unable to find ZoneId '" + timezone + "'"); } } else { _LOG.info("Using default timezone '{}'", ZoneId.systemDefault()); return formatter.withZone(ZoneId.systemDefault()); } }