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

📄 postaction.java

📁 javaBB,一套很不錯的JSP源碼,特共享給大家
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.javabb.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.javabb.action.infra.BaseAction;
import org.javabb.component.PostFormatter;
import org.javabb.component.UserFormatter;
import org.javabb.exception.FileTransferException;
import org.javabb.infra.PostSupport;
import org.javabb.infra.UserContext;
import org.javabb.infra.Utils;
import org.javabb.transaction.BadWordTransaction;
import org.javabb.transaction.ForumTransaction;
import org.javabb.transaction.PostTransaction;
import org.javabb.transaction.TopicTransaction;
import org.javabb.transaction.UserTransaction;
import org.javabb.vo.Forum;
import org.javabb.vo.Post;
import org.javabb.vo.PostText;
import org.javabb.vo.Topic;
import org.javabb.vo.User;

import sun.misc.ExtensionInstallationException;

import com.opensymphony.webwork.ServletActionContext;

/*
 * Copyright 2004 JavaFree.org
 *
 * 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.
 */

/**
 * $Id: PostAction.java,v 1.43.2.1.4.16 2008/04/14 01:19:40 daltoncamargo Exp $
 * @author Dalton Camargo - <a href="mailto:dalton@javabb.org">dalton@javabb.org </a> <br>
 * @author Lucas Frare Teixeira - <a href="mailto:lucas@javabb.org">lucas@javabb.org </a> <br>
 * @author Ronald Tetsuo Miura
 */
public class PostAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private PostText _post = new PostText();

    private ForumTransaction _forumTransaction;

    private PostTransaction _postTransaction;

    private TopicTransaction topicTransaction;

    private Topic _topic = new Topic();

    private BadWordTransaction badWordTransaction;

    private UserTransaction _userTransaction;

    private PostFormatter postFormatter;
    
    private UserFormatter userFormatter;

    private List _posts = new ArrayList();

    private String quote;

    private String whoQuote;
    
    private String[] attachFiles;

    
    // ####################################################################
    // Dependencies
    // ####################################################################

    /**
     * @param forumTransaction The forumTransaction to set.
     */
    public void setForumTransaction(ForumTransaction forumTransaction) {
        this._forumTransaction = forumTransaction;
    }

    /**
     * @param userTransaction the new userTransaction value
     */
    public void setUserTransaction(UserTransaction userTransaction) {
        this._userTransaction = userTransaction;
    }

    /**
     * @param topicTransaction the new topicTransaction value
     */
    public void setTopicTransaction(TopicTransaction topicTransaction) {
        this.topicTransaction = topicTransaction;
    }

    /**
     * @param postFormatter the new postFormatter value
     */
    public void setPostFormatter(PostFormatter postFormatter) {
        this.postFormatter = postFormatter;
    }

    /**
     * @param postTransaction the new postTransaction value
     */
    public void setPostTransaction(PostTransaction postTransaction) {
        this._postTransaction = postTransaction;
    }

    /**
     * @param badWordComponent the new badWordComponent value
     */
    public void setBadWordTransaction(BadWordTransaction badWordComponent) {
        this.badWordTransaction = badWordComponent;
    }

    public void setUserFormatter(UserFormatter userFormatter) {
		this.userFormatter = userFormatter;
	}
    
    // ####################################################################
    // Actions
    // ####################################################################


    public String doUpload(){
    	return SUCCESS;
    }
    
    
	/**
     * @return Action status
     */
    public String listaPost() {
        _posts = _postTransaction.findByTopic(_post.getTopic().getIdTopic(), getPage());
        return SUCCESS;
    }

    /**
     * This method is used as much as to reply a post as to quote some text.
     * @return Action status
     */
    public String returnQuoteMsg() {
        if (log.isDebugEnabled()) {
            log.debug("whoQuote = '" + whoQuote + "'");
        }
        Post tmpPost = null;
        if (StringUtils.trimToNull(whoQuote) != null) {
        	tmpPost = _postTransaction.loadPost(_post.getId());
            quote = "[quote=\"" + whoQuote + "\"]" + tmpPost.getPostBody() + " [/quote]";
            _post = (PostText) tmpPost;
        }
        
        
        if(tmpPost != null){
        	_topic.setId(tmpPost.getTopic().getId());
        } else {
        	_topic.setId(_post.getTopic().getId());
        }
        
        if(_topic.getId() != null){
        	if (UserContext.getContext().isAuthenticated()) {
    			watchTopic = topicTransaction.isWatchTopic(_topic.getId(),
    					UserContext.getContext().getUser().getIdUser());
            }	
        }

        return SUCCESS;
    }

    /**
     * @return Action status
     */
    public String loadPost() {
        if(_post.getIdPost() != null){
            _postId = _post.getIdPost();
        }
        _post = (PostText) _postTransaction.loadPost(_postId);
        
        Long topicId = _post.getTopic().getId();
        if(topicId != null){
        	if (UserContext.getContext().isAuthenticated()) {
    			watchTopic = topicTransaction.isWatchTopic(topicId,
    					_post.getUser().getIdUser());
            }	
        }

        
        
        return SUCCESS;
    }

    /**
     * @return Action status
     */
    public String updatePost() throws Exception{
    	
    	checkMessage();
    	
        Post alterPost = _postTransaction.loadPost(_post.getId());
        User userLogado = UserContext.getContext().getUser();

        // se o usu醨io n鉶 for administrador:
        if (userLogado.getAdmin().equals(new Integer(0))) {
            // se ele n鉶 for o dono da mensagem:
            if (!alterPost.getUser().equals(userLogado)) {
            	addActionError(getText("you_can_edit_yours_messages"));

                return ERROR;
            }
        }

    	try{
	    	//Uploading all Post files
	    	Set files = PostSupport.uploadPostFiles(_post, ServletActionContext.getRequest());
	    	alterPost.setPostFiles(files);
    	} catch (ExtensionInstallationException ex){
    		throw new FileTransferException(getText("exception_file_extensionnotallowed"));
    	} catch (Exception e){
    		throw new FileTransferException(getText("exception_file_file_too_large"));
    	}         
        
        alterPost.setSubject(getSubject());
        alterPost.setPostBody(getMessage());
        alterPost.setSig(getCheckSign());;
    	
    	

        _postTransaction.updatePost(alterPost);

        if(getUrl() != null && "topic".equals(getUrl())){
            setUrl("viewtopic.jbb?t=" + _post.getTopic().getIdTopic());            
        } else {
            setUrl("viewtopic.jbb?t=" + _post.getTopic().getIdTopic() 
                    + "&page="+ _page + "#" + _post.getIdPost());
        }
        

        // Atualiza a informacao dos posts
        _post.setIdPost(_post.getId());
        _forumTransaction.refreshPost(_post.getId());

        
        
        return SUCCESS;
    }

    /**
     * @return Action status
     */
    public String updatePostTopic() throws Exception{

    	

⌨️ 快捷键说明

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