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

📄 postaction.java

📁 javaBB,一套很不錯的JSP源碼,特共享給大家
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    	checkMessage();
    	checkSubject();
    	
    	Post alterPost = null;
    	User userLogado = null;
    	
    	try{
	        alterPost = _postTransaction.loadPost(_post.getId());
	        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;
	            }
	        }

//	      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 = getPostPopulated(_post);
        
        alterPost.setSig(getCheckSign());
        alterPost.setPostBody(getMessage());
        
        _postTransaction.updatePost(alterPost);

        Topic alterTopic = topicTransaction.loadTopic(_post.getTopic().getId());
//        alterTopic = getTopicPopulated(_post.getTopic());
        alterTopic.setTitleTopic(Utils.replaceHTML(getSubject()));
        alterTopic.setTopicModel(_post.getTopic().getTopicModel());
        alterTopic.setNotifyMe(_post.getTopic().getNotifyMe());
        
        if(userLogado.getAdmin().intValue() != 1){
        	alterTopic.setTopicModel(new Integer(0));
        }
        
        topicTransaction.updateTopic(alterTopic);
        
        setUrl("viewtopic.jbb?t=" + _post.getTopic().getIdTopic());

        
        // Atualiza a informacao dos posts
        _post.setIdPost(_post.getId());
        _forumTransaction.refreshPost(_post.getId());
        // Atualiza a informa鏰o dos topicos
        _forumTransaction.refreshTopic(_post.getTopic().getIdTopic());
        
        return SUCCESS;
    }

    /**
     * @return Action status
     */
    public String insertPost() throws Exception{
    	checkMessage();
    	
    	if(!"quick".equals(getTemp())){
	    	try{
		    	//Uploading all Post files
		    	Set files = PostSupport.uploadPostFiles(_post, ServletActionContext.getRequest());
		    	_post.setPostFiles(files);
	    	} catch (ExtensionInstallationException ex){
	    		throw new FileTransferException(getText("exception_file_extensionnotallowed"));
	    	} catch (Exception e){
	    		throw new FileTransferException(getText("exception_file_file_too_large"));
	    	}
    	}
    	
        Topic topic = _post.getTopic();
        topic = topicTransaction.loadTopic(topic.getId());

        // mark as unread
        UserContext.getContext().setTopicUnread(topic.getId());

        // Prote玢o contra flood... 7 segundos
        long currTime = System.currentTimeMillis();
        Long lastPost = (Long) getSessionAttribute("my_last_post");

        if ((lastPost != null) && ((currTime - lastPost.longValue()) < 7000)) {
            // 15 milisegundos
            this.addActionError(this.getText("message_so_quickly"));
            return ERROR;
            
        }
        setSessionAttribute("my_last_post", new Long(currTime));

        if ((topic.getTopicStatus() != null) && topic.getTopicStatus().equals(new Integer(1))) {
            this.addActionError(this.getText("answer_locked_topic"));
            return ERROR;
        }

        _post.setPostDate(new Date());
        _post.setIp(ServletActionContext.getRequest().getRemoteAddr());
        _post.setPost_state(new Integer(0));

        _post.setSubject(getSubject());
        _post.setPostBody(getMessage());
        _post.setSig(getCheckSign());
        _post.setTopic(topic);

		User up = UserContext.getContext().getUser();
		_post.setUser(up);

        Long idPost = _postTransaction.createPost(_post);

        
        topicTransaction.sumNumberReplysByTopic(_post.getTopic().getIdTopic());
        Date lastPostDate = new Date();
        topicTransaction.updateDatePostTopic(_post.getTopic().getIdTopic(), lastPostDate);
        
        topic.setLastPostDate(lastPostDate);
        UserContext.getContext().setForumTopic(topic.getForum().getId(), topic);
        
        if(getSessionAttribute("categoryChosed") != null){
        	_categoryId = (Long)getSessionAttribute("categoryChosed");
        	UserContext.getContext().setCatTopic(_categoryId, topic);
        } else {
        	UserContext.getContext().setCatTopic(topic.getForum().getCategory().getId(), topic);
        }

        _userTransaction.sumNumberMsgUser(up.getIdUser());

        // Getting number of page and setting for redirect
        Integer currentPage = _postTransaction.getPageOfLastPostByTopic(topic);
        setPage(currentPage.intValue());

        int lastId = idPost.intValue();
        int topicId = _post.getTopic().getIdTopic().intValue();
        String url = "viewtopic.jbb?t=" + topicId + "&page=" + currentPage + "#" + lastId;
        setUrl(url);

        // Atualiza a informacao dos posts
        _post.setIdPost(idPost);
        _forumTransaction.refreshPost(_post.getId());
        // Atualiza a informa鏰o dos topicos
        _forumTransaction.refreshTopic(_post.getTopic().getId());

//      Verify and send an email notification to User if the notify flag is set
        _postTransaction.notifyUserTopicByMail(topic);
        
//      Send an email to all users that watch this topic
        _postTransaction.nofityWatchUsers(topic, url, getText("watch_topics_message1"),
                getText("watch_topics_message2"), getText("topic"), 
                getText("watch_topic"));
        
        
        //Watching topic
        if(watchTopic == 1) {
        	//Insert a new Watched topic
        	topicTransaction.insertWatchTopicUser(new Long(topicId), _post.getUser().getId());
        }
        
        
        return SUCCESS;
    }

    /**
     * Insert a new topic and a new post
     * @return Action status
     */
    public String insertTopicPost() throws Exception{

    	checkMessage();
    	checkSubject();
    	
    	try{
	    	//Uploading all Post files
	    	Set files = PostSupport.uploadPostFiles(_post, ServletActionContext.getRequest());
	    	_post.setPostFiles(files);
    	} catch (ExtensionInstallationException ex){
    		throw new FileTransferException(getText("exception_file_extensionnotallowed"));
    	} catch (Exception e){
    		throw new FileTransferException(getText("exception_file_file_too_large"));
    	}
    	
    	Date lastPostDate = new Date();
        Long idTopicInserted = topicTransaction.createTopic(_topic, lastPostDate);

        _post.getUser().setId(UserContext.getContext().getUser().getId());
        _post.setPost_state(new Integer(0));
        _post.setPostDate(new Date());
        
        

//        _post.setSubject(badWordTransaction.verifyBadWords(_post.getSubject()));

        _post.setSubject(badWordTransaction.verifyBadWords(getSubject()));
        _post.setPostBody(getMessage());
        _post.setSig(getCheckSign());

        
        Topic topic = topicTransaction.loadTopic(idTopicInserted);
        topic.setTitleTopic(badWordTransaction.verifyBadWords(getSubject()));
        topic.setTopicStatus(new Integer(0));
        topic.setPageLastPost(new Integer(1));
        topic.setLastPostDate(lastPostDate);
        _post.setTopic(topic);

        Long lastPostId = _postTransaction.createPost(_post);
        _topic.setLastPost(_postTransaction.loadPost(lastPostId));

        UserContext.getContext().setForumTopic(topic.getForum().getId(), topic);
        
        if(getSessionAttribute("categoryChosed") != null){
        	_categoryId = (Long)getSessionAttribute("categoryChosed");
        	UserContext.getContext().setCatTopic(_categoryId, topic);
        } else {
        	UserContext.getContext().setCatTopic(topic.getForum().getCategory().getId(), topic);
        }
        
        
        // manuten玢o de mensagens do usu醨io
        User up = UserContext.getContext().getUser();
        _userTransaction.sumNumberMsgUser(up.getIdUser());

        int topicId = _post.getTopic().getIdTopic().intValue();
        setUrl("viewtopic.jbb?t=" + topicId + "#" + lastPostId.toString());
        
        // Atualiza a informacao dos posts
        _post.setIdPost(lastPostId);
        _forumTransaction.refreshPost(_post.getId());
        // Atualiza a informa鏰o dos topicos
        _forumTransaction.refreshTopic(topic.getId());
        
        
        return SUCCESS;
    }

    /**
     * @return Action status
     */
    public String deletePost() {
        Topic topic = null;
        Forum forum = null;

        // Obt閙 o usu醨io logado da sess鉶
        User up = UserContext.getContext().getUser();

        //Logging
        log.debug("Deleting post User:" + up.getUser());
        log.debug("Deleting post ID:" + up.getIdUser());
        
        // Verifica se o usu醨io tem privil間ios para excluir o post
        if (_postTransaction.canDeletePost(_post)) {

            // guardando referencias para refresh posterior
            topic = _post.getTopic();
            forum = topic.getForum();

            _postTransaction.deletePost(_post.getId());

            // manuten玢o de mensagens do usu醨io
            _userTransaction.subNumberMsgUser(_post.getUser().getId());

            // Verifica se o post que foi exclu韉o
            // 

⌨️ 快捷键说明

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