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

📄 weblogentryformaction.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    RollerSpellCheck.getSpellingErrors( wf.getText() );                session.setAttribute("spellCheckEvents", words);                request.setAttribute("model",                     new WeblogEntryPageModel(                       request, response, mapping,                        (WeblogEntryFormEx)actionForm,                       WeblogEntryPageModel.SPELL_MODE, words));            }            else            {                forward = mapping.findForward("access-denied");            }        }        catch (Exception e)        {            throw new ServletException(e);        }        return forward;    }    //-----------------------------------------------------------------------    /**     * Update selected comments: delete and/or mark as spam.     */    public ActionForward updateComments(        ActionMapping       mapping,        ActionForm          actionForm,        HttpServletRequest  request,        HttpServletResponse response)        throws IOException, ServletException    {        ActionForward forward = mapping.findForward("weblogEdit.page");        ActionErrors errors = new ActionErrors();        RollerRequest rreq = RollerRequest.getRollerRequest(request);        try        {            if ( rreq.isUserAuthorizedToEdit() )            {                WeblogEntryData wd = rreq.getWeblogEntry();                if (wd == null || wd.getId() == null)                {                  throw new NullPointerException("Unable to find WeblogEntry for "+                        request.getParameter(RollerRequest.WEBLOGENTRYID_KEY));                }                WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;                // If form indicates that comments should be deleted, then delete                WeblogManager mgr = rreq.getRoller().getWeblogManager();                String[] deleteIds = form.getDeleteComments();                if (deleteIds != null && deleteIds.length > 0)                {                    mgr.removeComments( deleteIds );                }                List comments = mgr.getComments( wd.getId(), false ); // spam too                if (form.getSpamComments() != null)                {                    // comments marked as spam                    List spamIds = Arrays.asList(form.getSpamComments());                    // iterate over all comments, check each to see if                    // is in the spamIds list.  If so, mark it as spam.                    Iterator it = comments.iterator();                    while (it.hasNext())                    {                        CommentData comment = (CommentData)it.next();                        if (spamIds.contains(comment.getId()))                        {                            comment.setSpam(Boolean.TRUE);                                                    }                        else                         {                            comment.setSpam(Boolean.FALSE);                        }                        comment.save();                    }                }                rreq.getRoller().commit();                                reindexEntry(rreq.getRoller(), wd);                                request.setAttribute("model",                        new WeblogEntryPageModel(request, response, mapping,                                 (WeblogEntryFormEx)actionForm,                                WeblogEntryPageModel.EDIT_MODE));            }            else            {                forward = mapping.findForward("access-denied");            }        }        catch (Exception e)        {            forward = mapping.findForward("error");            errors.add(ActionErrors.GLOBAL_ERROR,                new ActionError("error.edit.comment", e.toString()));            saveErrors(request,errors);            mLogger.error(getResources(request).getMessage("error.edit.comment")                + e.toString(),e);        }        return forward;    }    /**    *    */   public ActionForward sendTrackback(                   ActionMapping mapping,                    ActionForm actionForm,                   HttpServletRequest request,                    HttpServletResponse response) throws RollerException   {       ActionForward forward = mapping.findForward("weblogEdit.page");       ActionErrors errors = new ActionErrors();       WeblogEntryData entry = null;       try       {           RollerRequest rreq = RollerRequest.getRollerRequest(request);           if (rreq.isUserAuthorizedToEdit())           {               WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;               String entryid = form.getId();               if ( entryid == null )               {                   entryid= request.getParameter(RollerRequest.WEBLOGENTRYID_KEY);               }               RollerContext rctx= RollerContext.getRollerContext(request);               WeblogManager wmgr= rreq.getRoller().getWeblogManager();               entry = wmgr.retrieveWeblogEntry(entryid);               String title = entry.getTitle();               // Run entry through registered PagePlugins               PageHelper pageHelper = PageHelper.createPageHelper(request, response);               pageHelper.setSkipFlag(true); // don't process ReadMorePlugin               String excerpt = pageHelper.renderPlugins(entry);               excerpt = StringUtils.left( Utilities.removeHTML(excerpt),255 );               String url = rctx.createEntryPermalink(entry, request, true);               String blog_name = entry.getWebsite().getName();               if (form.getTrackbackUrl() != null)               {                   try                   {                       // Construct data                       String data = URLEncoder.encode("title", "UTF-8")                           +"="+URLEncoder.encode(title, "UTF-8");                       data += ("&" + URLEncoder.encode("excerpt", "UTF-8")                                 +"="+URLEncoder.encode(excerpt,"UTF-8"));                       data += ("&" + URLEncoder.encode("url", "UTF-8")                                 +"="+URLEncoder.encode(url,"UTF-8"));                       data += ("&" + URLEncoder.encode("blog_name", "UTF-8")                                 +"="+URLEncoder.encode(blog_name,"UTF-8"));                       // Send data                       URL tburl = new URL(form.getTrackbackUrl());                       URLConnection conn = tburl.openConnection();                       conn.setDoOutput(true);                       OutputStreamWriter wr =                           new OutputStreamWriter(conn.getOutputStream());                       BufferedReader rd = null;                       try                       {                           wr.write(data);                           wr.flush();                               // Get the response                           rd = new BufferedReader(                                   new InputStreamReader(conn.getInputStream()));                               String line;                           StringBuffer resultBuff = new StringBuffer();                           while ((line = rd.readLine()) != null)                           {                               resultBuff.append(Utilities.escapeHTML(line, true));                               resultBuff.append("<br />");                           }                                                      ActionMessages resultMsg = new ActionMessages();                           resultMsg.add(ActionMessages.GLOBAL_MESSAGE,                               new ActionMessage("weblogEdit.trackbackResults",                                resultBuff));                           saveMessages(request, resultMsg);                       }                       finally                       {                           wr.close();                           rd.close();                       }                   }                   catch (IOException e)                   {                       errors.add(ActionErrors.GLOBAL_ERROR,                           new ActionError("error.trackback",e));                   }               }               else               {                   errors.add(ActionErrors.GLOBAL_ERROR,                           new ActionError("error.noTrackbackUrlSpecified"));               }                              form.setTrackbackUrl(null);           }           else           {               forward = mapping.findForward("access-denied");           }       }       catch (Exception e) // unexpected       {           mLogger.error(e);           String msg = e.getMessage();           if ( msg == null )           {               msg = e.getClass().getName();           }           errors.add(ActionErrors.GLOBAL_ERROR,               new ActionError("error.general",msg));       }       if ( !errors.isEmpty() )       {           saveErrors(request, errors);       }              request.setAttribute("model",                       new WeblogEntryPageModel(request, response, mapping,                                (WeblogEntryFormEx)actionForm,                               WeblogEntryPageModel.EDIT_MODE));       return forward;    }    //-----------------------------------------------------------------------    public ActionForward cancel(        ActionMapping       mapping,        ActionForm          actionForm,        HttpServletRequest  request,        HttpServletResponse response)        throws IOException, ServletException    {        return (mapping.findForward("weblogEdit"));    }    //-----------------------------------------------------------------------    public ActionForward unspecified(        ActionMapping       mapping,        ActionForm          actionForm,        HttpServletRequest  request,        HttpServletResponse response)        throws Exception    {        return create(mapping, actionForm, request, response);    }        /**     * Attempts to remove the Entry from the Lucene index and     * then re-index the Entry if it is Published.  If the Entry     * is being deleted then mark it published = false.     * @param entry     */    private void reindexEntry(Roller roller, WeblogEntryData entry) throws RollerException    {         IndexManager manager = roller.getIndexManager();                // remove entry before (re)adding it, or in case it isn't Published        //manager.removeEntryIndexOperation(entry);                 // if published, index the entry        if (entry.getPublishEntry() == Boolean.TRUE)         {            manager.addEntryReIndexOperation(entry);        }    }}

⌨️ 快捷键说明

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