⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagebuilder.java

📁 非常有影响的 j道 论 坛 源码 国外很有明的专家编写的 ....对java爱好者很有参考价值
💻 JAVA
字号:
/*
 * Copyright 2007 the original author or jdon.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.jdon.jivejdon.repository.builder;

import java.util.Collection;

import org.apache.log4j.Logger;

import com.jdon.controller.model.ModelIF;
import com.jdon.jivejdon.Constants;
import com.jdon.jivejdon.dao.MessageDao;
import com.jdon.jivejdon.dao.MessageQueryDao;
import com.jdon.jivejdon.dao.PropertyDao;
import com.jdon.jivejdon.manager.TreeManager;
import com.jdon.jivejdon.model.Forum;
import com.jdon.jivejdon.model.ForumMessage;
import com.jdon.jivejdon.model.ForumThread;
import com.jdon.jivejdon.repository.AccountFactory;
import com.jdon.jivejdon.repository.UploadRepository;

public class MessageBuilder {
	private final static Logger logger = Logger.getLogger(MessageBuilder.class);

	public final MessageDao messageDao;

	public final MessageQueryDao messageQueryDao;

	private final AccountFactory accountFactory;

	private final UploadRepository uploadRepository;

	public final TreeManager treeManager;

	private final PropertyDao propertyDao;

	private ForumAbstractFactory forumAbstractFactory;

	public MessageBuilder(MessageDao messageDao, MessageQueryDao messageQueryDao, AccountFactory accountFactory, UploadRepository uploadRepository, TreeManager treeManager, PropertyDao propertyDao) {
		super();
		this.messageDao = messageDao;
		this.messageQueryDao = messageQueryDao;
		this.accountFactory = accountFactory;
		this.uploadRepository = uploadRepository;
		this.treeManager = treeManager;
		this.propertyDao = propertyDao;
	}

	public void setForumAbstractFactory(ForumAbstractFactory forumAbstractFactory) {
		this.forumAbstractFactory = forumAbstractFactory;
	}

	public ForumMessage create(Long id) {
		return messageDao.getMessage(id);
	}

	public void buildPart(ForumMessage forumMessage, ForumThread forumThread, Forum forum) throws Exception {
		try {
			logger.debug("Embed  embed thread start");
			if ((forum == null) || (forum.getForumId().longValue() != forumMessage.getForum().getForumId().longValue()))
				forum = forumAbstractFactory.forumDirector.getForum(forumMessage.getForum().getForumId(), forumThread, forumMessage);
			forumMessage.setForum(forum);
			
			Long threadId = forumMessage.getForumThread().getThreadId();
			if ((forumThread == null) || (threadId.longValue() != forumThread.getThreadId().longValue())) {
				forumThread = forumAbstractFactory.threadDirector.getThread(threadId, forumMessage, forum);
			}			
			forumMessage.setForumThread(forumThread);
			
		} catch (Exception e) {
			String error = e + " buildPart forumMessageId=" + forumMessage.getMessageId();
			logger.error(error);
			throw new Exception(error);
		}

	}

	

	public void buildProperties(ForumMessage forumMessage) throws Exception {
		try {
			embedAccount(forumMessage);
			Collection uploadFiles = uploadRepository.getUploadFiles(forumMessage.getMessageId(), true);
			forumMessage.setUploadFiles(uploadFiles);

			// getMessageWithPropterty not use, mask property must be load with message
			Collection propertys = propertyDao.getProperties(Constants.MESSAGE, forumMessage.getMessageId());
			forumMessage.setPropertys(propertys);
		} catch (Exception e) {
			String error = e + " buildProperties forumMessageId=" + forumMessage.getMessageId();
			logger.error(error);
			throw new Exception(error);
		}

	}

	public void embedAccount(ForumMessage forumMessage) throws Exception {
		try {
			logger.debug(" embed getAccount ");
			com.jdon.jivejdon.model.Account account = accountFactory.getFullAccount(forumMessage.getAccount());
			if (!account.isAnonymous()) {
				// get messageCount of the account;
				int count = messageQueryDao.getMessageCountOfUser(account.getUserIdLong());
				account.setMessageCount(count);
			}
			logger.debug("  got the Account");
			forumMessage.setAccount(account);
		} catch (Exception e) {
			String error = e + " embedAccount forumMessageId=" + forumMessage.getMessageId();
			logger.error(error);
			throw new Exception(error);
		}
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -