Beispiel #1
0
 private Topic getTopic(Node topicNode) throws Exception {
   if (topicNode == null) return null;
   Topic topicNew = new Topic();
   PropertyReader reader = new PropertyReader(topicNode);
   topicNew.setId(topicNode.getName());
   topicNew.setPath(topicNode.getPath());
   topicNew.setIcon(reader.string(ForumNodeTypes.EXO_ICON));
   topicNew.setTopicType(reader.string(ForumNodeTypes.EXO_TOPIC_TYPE, " "));
   topicNew.setTopicName(reader.string(ForumNodeTypes.EXO_NAME));
   topicNew.setOwner(reader.string(ForumNodeTypes.EXO_OWNER));
   topicNew.setCreatedDate(reader.date(ForumNodeTypes.EXO_CREATED_DATE));
   topicNew.setDescription(reader.string(ForumNodeTypes.EXO_DESCRIPTION));
   topicNew.setLastPostBy(reader.string(ForumNodeTypes.EXO_LAST_POST_BY));
   topicNew.setLastPostDate(reader.date(ForumNodeTypes.EXO_LAST_POST_DATE));
   topicNew.setIsSticky(reader.bool(ForumNodeTypes.EXO_IS_STICKY));
   if (topicNode.getParent().getProperty(ForumNodeTypes.EXO_IS_LOCK).getBoolean())
     topicNew.setIsLock(true);
   else topicNew.setIsLock(topicNode.getProperty(ForumNodeTypes.EXO_IS_LOCK).getBoolean());
   topicNew.setIsClosed(reader.bool(ForumNodeTypes.EXO_IS_CLOSED));
   topicNew.setIsApproved(reader.bool(ForumNodeTypes.EXO_IS_APPROVED));
   topicNew.setIsActive(reader.bool(ForumNodeTypes.EXO_IS_ACTIVE));
   topicNew.setIsWaiting(reader.bool(ForumNodeTypes.EXO_IS_WAITING));
   topicNew.setIsActiveByForum(reader.bool(ForumNodeTypes.EXO_IS_ACTIVE_BY_FORUM));
   topicNew.setIsPoll(reader.bool(ForumNodeTypes.EXO_IS_POLL));
   topicNew.setPostCount(reader.l(ForumNodeTypes.EXO_POST_COUNT));
   topicNew.setViewCount(reader.l(ForumNodeTypes.EXO_VIEW_COUNT));
   topicNew.setNumberAttachment(reader.l(ForumNodeTypes.EXO_NUMBER_ATTACHMENTS));
   topicNew.setUserVoteRating(reader.strings(ForumNodeTypes.EXO_USER_VOTE_RATING));
   topicNew.setVoteRating(reader.d(ForumNodeTypes.EXO_VOTE_RATING));
   // update more properties for topicNew.
   topicNew.setModifiedBy(reader.string(ForumNodeTypes.EXO_MODIFIED_BY));
   topicNew.setModifiedDate(reader.date(ForumNodeTypes.EXO_MODIFIED_DATE));
   topicNew.setIsModeratePost(reader.bool(ForumNodeTypes.EXO_IS_MODERATE_POST));
   topicNew.setIsNotifyWhenAddPost(
       reader.string(ForumNodeTypes.EXO_IS_NOTIFY_WHEN_ADD_POST, null));
   topicNew.setLink(reader.string(ForumNodeTypes.EXO_LINK));
   topicNew.setTagId(reader.strings(ForumNodeTypes.EXO_TAG_ID));
   topicNew.setCanView(reader.strings(ForumNodeTypes.EXO_CAN_VIEW, new String[] {}));
   topicNew.setCanPost(reader.strings(ForumNodeTypes.EXO_CAN_POST, new String[] {}));
   if (topicNode.isNodeType(ForumNodeTypes.EXO_FORUM_WATCHING))
     topicNew.setEmailNotification(
         reader.strings(ForumNodeTypes.EXO_EMAIL_WATCHING, new String[] {}));
   try {
     if (topicNew.getNumberAttachment() > 0) {
       //        String idFirstPost = topicNode.getName().replaceFirst(Utils.TOPIC, Utils.POST);
       //        Node FirstPostNode = topicNode.getNode(idFirstPost);
       //        topicNew.setAttachments(getAttachmentsByNode(FirstPostNode));
     }
   } catch (Exception e) {
     //      log.debug("Failed to set attachments in topicNew.", e);
   }
   return topicNew;
 }
  private Topic readTopic(int topicID) throws IOException {

    Topic topic = new Topic();

    record = new String();
    String topicString = "";
    boolean topicFounded = false;
    while ((record = br.readLine()) != null) {

      // System.out.println(record);
      if (record.indexOf("<num>") != -1
          && record.indexOf("Number:") != -1
          && record.indexOf(String.valueOf(topicID)) != -1) {
        topicFounded = true;
      }

      if (topicFounded) {
        topicString += record;
        if (record.indexOf("</top>") != -1) {

          // System.out.println(topicString);
          int titlePos = topicString.indexOf("<title>");
          int descPos = topicString.indexOf("<desc>");
          int narrPos = topicString.indexOf("<narr>");

          String title =
              topicString.substring(titlePos + 7, descPos).replaceFirst("Topic:", "").trim();

          String desc =
              topicString.substring(descPos + 6, narrPos).replaceFirst("Description:", "").trim();
          String narr =
              topicString
                  .substring(narrPos + 6, topicString.length() - 6)
                  .replaceFirst("Narrative:", "")
                  .trim();

          topic.setId(topicID);
          topic.setTitle(title);
          topic.setDescription(desc);
          topic.setNarrative(narr);

          return topic;
        }
      }
    }

    return null;
  }