Changeset 7648

Show
Ignore:
Timestamp:
05/05/09 12:01:44 (15 months ago)
Author:
dragisak
Message:

Gracefully handle null bodies in annotation feed.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/struts2/AmbraFeedResult.java

    r7644 r7648  
    386386 
    387387  private String getBody(Annotea annot) throws UnsupportedEncodingException { 
    388     String body = null; 
    389     if (annot instanceof ArticleAnnotation) 
    390       body = new String(((ArticleAnnotation)annot).getBody().getBody(), annotationService.getEncodingCharset()); 
    391     else if (annot instanceof Reply) 
    392       body = new String(((Reply)annot).getBody().getBody(), annotationService.getEncodingCharset()); 
    393     else if (annot instanceof Rating) { 
     388    String body = ""; 
     389    if (annot instanceof ArticleAnnotation) { 
     390      ArticleAnnotation annotation = (ArticleAnnotation) annot; 
     391      if (annotation.getBody() != null) 
     392        body = new String(annotation.getBody().getBody(), annotationService.getEncodingCharset()); 
     393    } else if (annot instanceof Reply) { 
     394      Reply reply = (Reply) annot; 
     395      if (reply.getBody() != null) 
     396        body = new String(reply.getBody().getBody(), annotationService.getEncodingCharset()); 
     397    } else if (annot instanceof Rating) { 
    394398      RatingContent content = ((Rating) annot).getBody(); 
    395       StringBuilder ratingBody = new StringBuilder(); 
    396       ratingBody.append("<div><ul>"); 
    397       if (content.getSingleRatingValue() > 0) { 
    398         ratingBody.append("<li>Rating: ") 
    399                   .append(Integer.toString(content.getSingleRatingValue())) 
    400                   .append("</li>"); 
    401       } else { 
    402         ratingBody.append("<li>Insight: ") 
    403                   .append(Integer.toString(content.getInsightValue())) 
    404                   .append("</li>") 
    405                   .append("<li>Reliability: ") 
    406                   .append(Integer.toString(content.getReliabilityValue())) 
    407                   .append("</li>") 
    408                   .append("<li>Style: ") 
    409                   .append(Integer.toString(content.getStyleValue())) 
    410                   .append("</li>"); 
    411       } 
    412       ratingBody.append("</ul></div>") 
     399      if (content != null) { 
     400        StringBuilder ratingBody = new StringBuilder(); 
     401        ratingBody.append("<div><ul>"); 
     402        if (content.getSingleRatingValue() > 0) { 
     403          ratingBody.append("<li>Rating: ") 
     404                    .append(Integer.toString(content.getSingleRatingValue())) 
     405                    .append("</li>"); 
     406        } else { 
     407          ratingBody.append("<li>Insight: ") 
     408                    .append(Integer.toString(content.getInsightValue())) 
     409                    .append("</li>") 
     410                    .append("<li>Reliability: ") 
     411                    .append(Integer.toString(content.getReliabilityValue())) 
     412                    .append("</li>") 
     413                    .append("<li>Style: ") 
     414                    .append(Integer.toString(content.getStyleValue())) 
     415                    .append("</li>"); 
     416        } 
     417        ratingBody.append("</ul></div>") 
    413418                .append(content.getCommentValue()); 
    414       body = ratingBody.toString(); 
    415     } else if (annot instanceof Trackback) 
    416       body = ((Trackback)annot).getBody().getExcerpt(); 
     419        body = ratingBody.toString(); 
     420      } 
     421    } else if (annot instanceof Trackback) { 
     422      Trackback trackback = (Trackback) annot; 
     423      if (trackback.getBody() != null) { 
     424        body = trackback.getBody().getExcerpt(); 
     425      } 
     426    } 
    417427    return body; 
    418428  } 
     
    873883      title = annot.getTitle(); 
    874884    } else if (annot instanceof Rating) { 
    875       title = ((Rating) annot).getBody().getCommentTitle(); 
    876       if (title == null || title.trim().equals("")) 
     885      Rating rating = (Rating) annot; 
     886      if (rating.getBody() != null) { 
     887        title = rating.getBody().getCommentTitle(); 
     888        if (title == null || title.trim().equals("")) 
     889          title = "Rating"; 
     890      } else { 
    877891        title = "Rating"; 
     892      } 
    878893    } else if (annot instanceof Trackback) { 
    879       title = ((Trackback) annot).getBody().getTitle(); 
    880       if (title == null || title.trim().equals("")) 
     894      Trackback trackback = (Trackback) annot; 
     895      if (trackback.getBody() != null) { 
     896        title = trackback.getBody().getTitle(); 
     897        if (title == null || title.trim().equals("")) 
     898          title = "Trackback"; 
     899      } else { 
    881900        title = "Trackback"; 
     901      } 
    882902    } 
    883903