Beispiel #1
0
 private void fillComments(ContextBuilder context, AEntity entity) {
   CommentDao commentDao = (CommentDao) entity.getDaoService().getDaoByClass(Comment.class);
   Collection<Comment> comments = commentDao.getPublishedCommentsByParent(entity);
   comments = Utl.sort(comments);
   for (Comment comment : comments) {
     fillComment(context.addSubContext("comments"), comment);
   }
 }
Beispiel #2
0
 private Set<Comment> getLatest(Set<Comment> comments) {
   if (comments.size() < 2) return comments;
   Comment latest = null;
   for (Comment comment : comments) {
     if (latest == null || comment.getDateAndTime().isAfter(latest.getDateAndTime()))
       latest = comment;
   }
   assert latest != null;
   return Utl.toSet(latest);
 }
Beispiel #3
0
 public String getFixReleasesAsString() {
   Set<Release> releases = getFixReleases();
   if (releases.isEmpty()) return null;
   if (releases.size() == 1) return "Release " + Utl.getElement(releases, 0).getLabel();
   StringBuilder sb = new StringBuilder();
   sb.append("Releases ");
   boolean first = true;
   for (Release release : releases) {
     if (first) {
       first = false;
     } else {
       sb.append(", ");
     }
     sb.append(release.getLabel());
   }
   return sb.toString();
 }
Beispiel #4
0
 public static String getTextContent(Part part, String type) {
   if (part == null) return null;
   try {
     String contentType;
     try {
       contentType = part.getContentType();
     } catch (Throwable t) {
       contentType = "unknown";
     }
     if (contentType.toLowerCase().startsWith("text/" + type)) {
       // ContentType ct = new ContentType(contentType);
       // String charset = ct.getParameter("charset");
       try {
         Object content = part.getContent();
         if (content == null) return null;
         if (content instanceof String) return (String) content;
         if (content instanceof InputStream) {
           String encoding = charset;
           if (contentType.toLowerCase().contains("UTF")) encoding = IO.UTF_8;
           if (contentType.toLowerCase().contains("ISO")) encoding = IO.ISO_LATIN_1;
           return IO.readToString((InputStream) content, encoding);
         }
         return Utl.toStringWithType(content);
       } catch (UnsupportedEncodingException ex) {
         LOG.warn(ex);
         return null;
       } catch (IOException e) {
         String message = e.getMessage();
         if (message != null) {
           if ("No content".equals(message)) {
             return null;
           }
           if (message.toLowerCase().startsWith("unknown encoding")) {
             LOG.warn(e);
             return null;
           }
         }
         throw e;
       } catch (Throwable t) {
         LOG.warn(t);
         return Str.getStackTrace(t);
       }
     }
     if (contentType.toLowerCase().startsWith("multipart")) {
       MimeMultipart multipart;
       try {
         multipart = (MimeMultipart) part.getContent();
       } catch (NullPointerException ex) {
         LOG.warn(ex);
         return null;
       }
       int count = multipart.getCount();
       for (int i = 0; i < count; i++) {
         BodyPart subPart = multipart.getBodyPart(i);
         String filename = subPart.getFileName();
         if (filename != null) continue;
         String text = getTextContent(subPart, type);
         if (text != null) return text.trim();
       }
       return null;
     }
     return null;
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Beispiel #5
0
 @Override
 public int compare(Issue a, Issue b) {
   return Utl.compare(b.getDate(), a.getDate());
 }
Beispiel #6
0
 @Override
 public int compareTo(BlogEntry other) {
   return Utl.compare(getDateAndTime(), other.getDateAndTime()) * -1;
 }
Beispiel #7
0
 @Override
 public void onSleep(GwtConversation conversation, long millis) {
   Utl.sleep(millis);
 }