Ejemplo n.º 1
0
  /** Tests that the author name is properly escaped and set. */
  public void testAuthor() {
    assertEquals("Author", comment.getAuthor());

    // blank or null author name defaults to "Anonymous"
    comment.setAuthor("");
    assertEquals("Anonymous", comment.getAuthor());
    comment.setAuthor(null);
    assertEquals("Anonymous", comment.getAuthor());

    // for security, special HTML characters aren't removed
    // (they are rendered out at runtime)
    comment.setAuthor("<Author>");
    assertEquals("<Author>", comment.getAuthor());
  }
  private Comment createComment(int i, UUID targetId) {
    Comment comment = new Comment();
    comment.setTargetId(targetId);
    comment.setAuthor("Pretentious Douchebag " + i);
    comment.setContent("This test sucks. 0/5 would not test again.");
    comment.setImage(bitmap);

    return comment;
  }
Ejemplo n.º 3
0
  protected void newComment() {
    if (commentEditText.getText().toString().length() > 0) {
      if (commentEditText.getText().toString().length() <= 160) {
        String displayName = Application.getDisplayName();
        ParseUser user = ParseUser.getCurrentUser();

        ParseGeoPoint myPoint = geoPointFromLatLng(MainActivity.getLatLng());

        Comment comment = new Comment();
        comment.setAuthor(user);
        comment.setPost(postId);
        comment.setCommentText(commentEditText.getText().toString());
        comment.setDisplayName(displayName);
        comment.setEpochTime();
        comment.setImageURL(imageUrl);
        comment.saveInBackground(
            new SaveCallback() {

              @Override
              public void done(ParseException e) {
                if (e == null) {
                  Toast.makeText(SinglePostView.this, R.string.sent, Toast.LENGTH_SHORT).show();
                  commentEditText.getText().clear();
                  adapter.clear();
                  adapter.loadObjects();
                  adapter.notifyDataSetChanged();
                } else {
                  Toast.makeText(
                          SinglePostView.this, "Error: " + e.getMessage(), Toast.LENGTH_SHORT)
                      .show();
                }
              }
            });
        Log.d(
            TAG,
            "new shout sent of length:"
                + commentEditText.getText().toString().length()
                + commentEditText.getText().toString());
        commentEditText.getText().clear();
      } else {
        Toast.makeText(
                this,
                "The length of your comment is too long: "
                    + commentEditText.getText().length()
                    + "/160",
                Toast.LENGTH_LONG)
            .show();
      }
    } else {
      Toast.makeText(
              this,
              "You have not entered any text! " + commentEditText.getText().length() + "/160",
              Toast.LENGTH_LONG)
          .show();
    }
  }
Ejemplo n.º 4
0
 public Comment addComment(String message, Account currAccount, Task task) {
   Hibernate.initialize(task.getComments());
   Comment comment = new Comment();
   comment.setTask(task);
   comment.setAuthor(currAccount);
   comment.setDate(new Date());
   comment.setMessage(message);
   wlSrv.addActivityLog(task, message, LogType.COMMENT);
   return save(comment);
 }
Ejemplo n.º 5
0
  public Comment getInstance() {
    if (instance == null) {
      log.info("create new comment instance");
      instance = new Comment();
      instance.setAuthor(user);
      instance.setBlogEntry(blogEntry);
    }

    log.info("return comment instance " + instance);

    return instance;
  }
  public void testDeleteComment() throws Exception {
    Comment c = new Comment();
    c.setAuthor("lolcat");
    c.setContent("Can I haz ID?");
    c.setTargetId(UUID.randomUUID());
    c.setId(UUID.randomUUID());

    boolean result = es.putComment(c);
    assertTrue(es.getErrorMessage(), result);

    System.out.println("Comment ID: " + c.getId());

    result = es.deleteComment(c.getId());
    assertTrue(es.getErrorMessage(), result);
  }
 /**
  * Select all data.
  *
  * @return the list of Items
  */
 public Map<String, Comment> selectAllCommentMap() {
   Map<String, Comment> map = new HashMap<String, Comment>();
   Cursor cursor = this.db.rawQuery("SELECT * FROM " + TABLE_COMMENTS, null);
   if (cursor.moveToFirst()) {
     do {
       Comment c = new Comment();
       c.setChatterId(cursor.getString(1));
       c.setCommentId(cursor.getString(2));
       c.setAuthor(cursor.getString(3));
       c.setBody(cursor.getString(4));
       map.put(c.getCommentId(), c);
     } while (cursor.moveToNext());
   }
   if (cursor != null && !cursor.isClosed()) {
     cursor.close();
   }
   return map;
 }
Ejemplo n.º 8
0
 public static BlogCommentList parse(InputStream inputStream) throws IOException, AppException {
   BlogCommentList commlist = new BlogCommentList();
   Comment comm = null;
   Reply reply = null;
   Refer refer = null;
   // 获得XmlPullParser解析器
   XmlPullParser xmlParser = Xml.newPullParser();
   try {
     xmlParser.setInput(inputStream, UTF8);
     // 获得解析到的事件类别,这里有开始文档,结束文档,开始标签,结束标签,文本等等事件。
     int evtType = xmlParser.getEventType();
     // 一直循环,直到文档结束
     while (evtType != XmlPullParser.END_DOCUMENT) {
       String tag = xmlParser.getName();
       switch (evtType) {
         case XmlPullParser.START_TAG:
           if (tag.equalsIgnoreCase("allCount")) {
             commlist.allCount = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("pageSize")) {
             commlist.pageSize = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("comment")) {
             comm = new Comment();
           } else if (comm != null) {
             if (tag.equalsIgnoreCase("id")) {
               comm.id = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase("portrait")) {
               comm.setFace(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("author")) {
               comm.setAuthor(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("authorid")) {
               comm.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("content")) {
               comm.setContent(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("pubDate")) {
               comm.setPubDate(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("appclient")) {
               comm.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("reply")) {
               reply = new Reply();
             } else if (reply != null && tag.equalsIgnoreCase("rauthor")) {
               reply.rauthor = xmlParser.nextText();
             } else if (reply != null && tag.equalsIgnoreCase("rpubDate")) {
               reply.rpubDate = xmlParser.nextText();
             } else if (reply != null && tag.equalsIgnoreCase("rcontent")) {
               reply.rcontent = xmlParser.nextText();
             } else if (tag.equalsIgnoreCase("refer")) {
               refer = new Refer();
             } else if (refer != null && tag.equalsIgnoreCase("refertitle")) {
               refer.refertitle = xmlParser.nextText();
             } else if (refer != null && tag.equalsIgnoreCase("referbody")) {
               refer.referbody = xmlParser.nextText();
             }
           }
           // 通知信息
           else if (tag.equalsIgnoreCase("notice")) {
             commlist.setNotice(new Notice());
           } else if (commlist.getNotice() != null) {
             if (tag.equalsIgnoreCase("atmeCount")) {
               commlist.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("msgCount")) {
               commlist.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("reviewCount")) {
               commlist.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("newFansCount")) {
               commlist.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(), 0));
             }
           }
           break;
         case XmlPullParser.END_TAG:
           // 如果遇到标签结束,则把对象添加进集合中
           if (tag.equalsIgnoreCase("comment") && comm != null) {
             commlist.getCommentlist().add(comm);
             comm = null;
           } else if (tag.equalsIgnoreCase("reply") && comm != null && reply != null) {
             comm.getReplies().add(reply);
             reply = null;
           } else if (tag.equalsIgnoreCase("refer") && comm != null && refer != null) {
             comm.getRefers().add(refer);
             refer = null;
           }
           break;
       }
       // 如果xml没有结束,则导航到下一个节点
       evtType = xmlParser.next();
     }
   } catch (XmlPullParserException e) {
     throw AppException.xml(e);
   } finally {
     inputStream.close();
   }
   return commlist;
 }
Ejemplo n.º 9
0
 public static BlogCommentList parse(InputStream inputStream) throws IOException, AppException {
   BlogCommentList commlist = new BlogCommentList();
   Comment comm = null;
   // Reply reply = null;
   // Refer refer = null;
   // 获得XmlPullParser解�器
   XmlPullParser xmlParser = Xml.newPullParser();
   try {
     xmlParser.setInput(inputStream, UTF8);
     // 获得解æž�到的事件类别,这里有开始文档,结æ�Ÿæ–‡æ¡£ï¼Œå¼€å§‹æ
     //  ‡ç­¾ï¼Œç»“æ�Ÿæ ‡ç­¾ï¼Œæ–‡æœ¬ç­‰ç­‰äº‹ä»¶ã€‚
     int evtType = xmlParser.getEventType();
     // 一直循环,直到文档结�
     while (evtType != XmlPullParser.END_DOCUMENT) {
       String tag = xmlParser.getName();
       switch (evtType) {
         case XmlPullParser.START_TAG:
           if (tag.equalsIgnoreCase("allCount")) {
             commlist.allCount = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("pageSize")) {
             commlist.pageSize = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("comment")) {
             comm = new Comment();
           } else if (comm != null) {
             if (tag.equalsIgnoreCase("id")) {
               comm.id = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase("portrait")) {
               comm.setFace(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("author")) {
               comm.setAuthor(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("authorid")) {
               comm.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("content")) {
               comm.setContent(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("pubDate")) {
               comm.setPubDate(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("appclient")) {
               comm.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0));
             }
             /*
             else if(tag.equalsIgnoreCase("reply"))
             {
             	reply = new Reply();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rauthor"))
             {
             	reply.rauthor = xmlParser.nextText();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rpubDate"))
             {
             	reply.rpubDate = xmlParser.nextText();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rcontent"))
             {
             	reply.rcontent = xmlParser.nextText();
             }
             else if(tag.equalsIgnoreCase("refer"))
             {
             	refer = new Refer();
             }
             else if(refer!=null && tag.equalsIgnoreCase("refertitle"))
             {
             	refer.refertitle = xmlParser.nextText();
             }
             else if(refer!=null && tag.equalsIgnoreCase("referbody"))
             {
             	refer.referbody = xmlParser.nextText();
             }
             */
           }
           /*
                 //通知信�
                 else if(tag.equalsIgnoreCase("notice"))
           {
                 	commlist.setNotice(new Notice());
           }
                 else if(commlist.getNotice() != null)
           {
           	if(tag.equalsIgnoreCase("atmeCount"))
                  {
           		commlist.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("msgCount"))
                  {
                  	commlist.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("reviewCount"))
                  {
                  	commlist.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("newFansCount"))
                  {
                  	commlist.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
           }
           */
           break;
         case XmlPullParser.END_TAG:
           // 如果�到标签结�,则把对象添加进集�中
           if (tag.equalsIgnoreCase("comment") && comm != null) {
             commlist.getCommentlist().add(comm);
             comm = null;
           }
           /*
           else if (tag.equalsIgnoreCase("reply") && comm!=null && reply!=null) {
           	comm.getReplies().add(reply);
           	reply = null;
           }
           else if(tag.equalsIgnoreCase("refer") && comm!=null && refer!=null) {
           	comm.getRefers().add(refer);
           	refer = null;
           }
           */
           break;
       }
       // 如果xml没有结�,则导航到下一个节点
       evtType = xmlParser.next();
     }
   } catch (XmlPullParserException e) {
     throw AppException.xml(e);
   } finally {
     inputStream.close();
   }
   return commlist;
 }