/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private static String getExtension (final @Nonnull Document document) { try { final String ext = EXTENSION_MAP_BY_MIME_TYPE.get(document.get(MIME_TYPE)); return (ext == null) ? "" : "." + ext; } catch (NotFoundException e) { return ""; // no mime type } } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ private void write (final @Nonnull File file, final @Nonnull Document document) throws IOException { log.debug("write({}, {})", file.getAbsolutePath(), document); try { @Cleanup final FileWriter w = new FileWriter(file); w.write(document.get(BODY)); } catch (NotFoundException e) { // ok, no body } }
public void renderTo (View view, Object... extra) { final Document message = newsItemPM.as(Document.class); try { final String date = preferences.get().formatDateAndTime(message.get(PUB_DATE)); final TextView tvDate = (TextView)view.findViewById(R.id.tvDate); final TextView tvTitle = (TextView)view.findViewById(R.id.tvTitle); tvDate.setText(date); tvTitle.setText(message.get(TITLE)); final int icon = newsItemPM.as(Readable).isRead() ? android.R.drawable.star_off : android.R.drawable.star_on; ((ImageView)view.findViewById(R.id.ivRead)).setImageResource(icon); } catch (NotFoundException e) { } } };
public void populate (final @Nonnull PresentationModel newsItemPM) { try { final Document message = newsItemPM.as(Document.class); final String date = preferences.get().formatDateAndTime((Date)message.get(PUB_DATE)); ((TextView)findViewById(R.id.tvDate)).setText(date); ((TextView)findViewById(R.id.tvTitle)).setText(message.get(TITLE)); final String text = "<html><body>" + UriEncoder.uriEncoded(message.get(CONTENT)) + "</body></html>"; final WebView webView = (WebView)findViewById(R.id.wvContent); webView.setNetworkAvailable(false); webView.loadData(text, "text/html", "utf-8"); } catch (NotFoundException e) { throw new RuntimeException(e); } } }