Package org.apache.roller.ui.authoring.struts.formbeans

Examples of org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryFormEx


        try {
            RollerSession rses = RollerSession.getRollerSession(request);
            RollerRequest rreq = RollerRequest.getRollerRequest(request);
            if (rreq.getWebsite() != null
                    && rses.isUserAuthorized(rreq.getWebsite())) {
                WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
                form.initNew(request, response);
                form.setCreatorId(rses.getAuthenticatedUser().getId());
                form.setWebsiteId(rreq.getWebsite().getId());
                form.setAllowComments(rreq.getWebsite().getDefaultAllowComments());
                form.setCommentDays(new Integer(rreq.getWebsite().getDefaultCommentDays()));
               
                request.setAttribute("model",
                        new WeblogEntryPageModel(request, response, mapping,
                        (WeblogEntryFormEx)actionForm,
                        WeblogEntryPageModel.EDIT_MODE));
View Full Code Here


        try {
            RollerRequest rreq = RollerRequest.getRollerRequest(request);
            RollerSession rses = RollerSession.getRollerSession(request);
            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
            WeblogEntryData entry = rreq.getWeblogEntry();
            WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
            if (entry == null && form.getId() != null) {
                entry = wmgr.getWeblogEntry(form.getId());
            }
            if (entry == null) {
                ResourceBundle resources = ResourceBundle.getBundle(
                        "ApplicationResources", request.getLocale());
                request.setAttribute("javax.servlet.error.message",
                        resources.getString("weblogEntry.notFound"));
                forward = mapping.findForward("error");
            } else if (rses.isUserAuthorized(entry.getWebsite())
            || (rses.isUserAuthorized(entry.getWebsite()) && !entry.isPublished())) {
                form.copyFrom(entry, request.getLocale());
                WeblogEntryPageModel pageModel = new WeblogEntryPageModel(
                        request, response, mapping, form,
                        WeblogEntryPageModel.EDIT_MODE);
                pageModel.setWebsite(entry.getWebsite());
                request.setAttribute("model", pageModel);
View Full Code Here

            ActionForm          actionForm,
            HttpServletRequest  request,
            HttpServletResponse response)
            throws IOException, ServletException {
        // we need to save any new entries before Previewing
        WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
        if (form.getId() == null) {
            save(mapping, actionForm, request, response);
        }
        return display(WeblogEntryPageModel.PREVIEW_MODE,
                mapping, actionForm, request, response);
    }
View Full Code Here

            throws IOException, ServletException {
       
        ActionForward forward = mapping.findForward("weblogEdit.page");
        ActionMessages uiMessages = new ActionMessages();
        try {
            WeblogEntryFormEx  form = (WeblogEntryFormEx)actionForm;
            Roller           roller = RollerFactory.getRoller();
            RollerSession      rses = RollerSession.getRollerSession(request);
            UserManager     userMgr = roller.getUserManager();
            WeblogManager weblogMgr = roller.getWeblogManager();
            UserData           ud  = userMgr.getUser(form.getCreatorId());
            WebsiteData       site = userMgr.getWebsite(form.getWebsiteId());
            WeblogEntryData  entry = null;
           
            if ( rses.isUserAuthorizedToAuthor(site)
            || (rses.isUserAuthorized(site)
            && !form.getStatus().equals(WeblogEntryData.PUBLISHED) )) {
               
                ActionErrors errors = validateEntry(null, form);
                if (errors.size() > 0) {
                    saveErrors(request, errors);
                    request.setAttribute("model",
                            new WeblogEntryPageModel(request, response, mapping,
                            (WeblogEntryFormEx)actionForm,
                            WeblogEntryPageModel.EDIT_MODE));
                    return forward;
                }
               
                if (form.getId() == null || form.getId().trim().length()==0) {
                    entry = new WeblogEntryData();
                    entry.setCreator(ud);
                    entry.setWebsite( site );
                } else {
                    entry = weblogMgr.getWeblogEntry(form.getId());
                }
               
                mLogger.debug("setting update time now");
                form.setUpdateTime(new Timestamp(new Date().getTime()));
               
                if ("PUBLISHED".equals(form.getStatus()) &&
                        "0/0/0".equals(form.getDateString())) {
                    mLogger.debug("setting pubtime now");
                   
                    /* NOTE: the wf.copyTo() method will override this value
                     * based on data submitted with the form if that data is
                     * not null.  check the method to verify.
                     *
                     * this means that setting the pubtime here only takes
                     * effect if the entry is being published for the first
                     * time.
                     */
                    form.setPubTime(form.getUpdateTime());
                }
               
                mLogger.debug("copying submitted form data to entry object");
                form.copyTo(entry, request.getLocale(),request.getParameterMap());
               
                // Fetch MediaCast content type and length
                mLogger.debug("Checking MediaCast attributes");
                if (!checkMediaCast(entry, uiMessages)) {
                    mLogger.debug("Invalid MediaCast attributes");
                } else {
                    mLogger.debug("Validated MediaCast attributes");
                }
               
                // Store value object (creates new or updates existing)
                entry.setUpdateTime(new Timestamp(new Date().getTime()));
               
                // make sure we have an anchor value set
                if(entry.getAnchor() == null || entry.getAnchor().trim().equals("")) {
                    entry.setAnchor(weblogMgr.createAnchor(entry));
                }

                mLogger.debug("Saving entry");
                weblogMgr.saveWeblogEntry(entry);
                RollerFactory.getRoller().flush();
               
                mLogger.debug("Populating form");
                form.copyFrom(entry, request.getLocale());
               
                request.setAttribute(
                        RequestConstants.WEBLOGENTRY_ID, entry.getId());
               
                // Reindex entry, flush caches, etc.
                reindexEntry(RollerFactory.getRoller(), entry);
                mLogger.debug("Removing from cache");
                RollerRequest rreq = RollerRequest.getRollerRequest(request);
                //PageCacheFilter.removeFromCache(request, entry.getWebsite());
                CacheManager.invalidate(entry);
               
                // Queue applicable pings for this update.
                if(entry.isPublished()) {
                    RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(entry);
                }
               
                // Clean up session objects we used
                HttpSession session = request.getSession(true);
                session.removeAttribute("spellCheckEvents");
                session.removeAttribute("entryText");
               
                // Load up request with data for view
                request.setAttribute("model",
                        new WeblogEntryPageModel(request, response, mapping,
                        (WeblogEntryFormEx)actionForm,
                        WeblogEntryPageModel.EDIT_MODE));
               
                if (!rses.isUserAuthorizedToAuthor(site) &&
                        rses.isUserAuthorized(site) && entry.isPending()) {
                    // implies that entry just changed to pending
                    notifyWebsiteAuthorsOfPendingEntry(request, entry);
                    uiMessages.add(null,
                            new ActionMessage("weblogEdit.submittedForReview"));
                   
                    // so clear entry from editor
                    actionForm = new WeblogEntryFormEx();
                    request.setAttribute(mapping.getName(), actionForm);
                    forward = create(mapping, actionForm, request, response);
                } else {
                    uiMessages.add(null,
                            new ActionMessage("weblogEdit.changesSaved"));
View Full Code Here

            HttpServletResponse response)
            throws IOException, ServletException {
        ActionForward forward = mapping.findForward("weblogEntryRemove.page");
        try {
            Roller roller = RollerFactory.getRoller();
            WeblogEntryFormEx wf = (WeblogEntryFormEx)actionForm;
            WeblogEntryData wd =
                    roller.getWeblogManager().getWeblogEntry(wf.getId());
            RollerSession rses =
                    RollerSession.getRollerSession(request);
            if (     rses.isUserAuthorizedToAuthor(wd.getWebsite())
            || (rses.isUserAuthorized(wd.getWebsite()) && wd.isDraft()) ) {
                wf.copyFrom(wd, request.getLocale());
                if (wd == null || wd.getId() == null) {
                    ResourceBundle resources = ResourceBundle.getBundle(
                            "ApplicationResources", request.getLocale());
                    request.setAttribute("javax.servlet.error.message",
                            resources.getString("weblogEntry.notFound"));
View Full Code Here

        } catch (Exception e) {
            throw new ServletException(e);
        }
       
        // need to reset all values to empty (including 'id')
        actionForm = new WeblogEntryFormEx();
        actionForm.reset(mapping, request);
        request.setAttribute(mapping.getName(), actionForm);
        return create(mapping, actionForm, request, response);
    }
View Full Code Here

        ActionMessages resultMsg = new ActionMessages();
        ActionForward forward = mapping.findForward("weblogEdit.page");
        ActionErrors errors = new ActionErrors();
        WeblogEntryData entry = null;
        try {
            WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
            String entryid = form.getId();
            if ( entryid == null ) {
                entryid =
                        request.getParameter(RequestConstants.WEBLOGENTRY_ID);
            }
            Roller roller = RollerFactory.getRoller();
            RollerContext rctx= RollerContext.getRollerContext();
            WeblogManager wmgr= roller.getWeblogManager();
            entry = wmgr.getWeblogEntry(entryid);
           
            RollerSession rses = RollerSession.getRollerSession(request);
            if (rses.isUserAuthorizedToAuthor(entry.getWebsite())) {
                // Run entry through registered PagePlugins
                PluginManager ppmgr = roller.getPagePluginManager();
                Map plugins = ppmgr.getWeblogEntryPlugins(
                        entry.getWebsite());
               
                String content = "";
                if (!StringUtils.isEmpty(entry.getText())) {
                    content = entry.getText();
                } else {
                    content = entry.getSummary();
                }
                content = ppmgr.applyWeblogEntryPlugins(plugins, entry, content);

                String title = entry.getTitle();
                String excerpt = StringUtils.left( Utilities.removeHTML(content),255 );
               
                String url = entry.getPermalink();
                String blog_name = entry.getWebsite().getName();
               
                if (form.getTrackbackUrl() != null) {
                    // by default let all trackbacks to be sent
                    boolean allowTrackback = true;
                   
                    String allowedURLs = RollerConfig.getProperty("trackback.allowedURLs");
                    if (allowedURLs != null && allowedURLs.trim().length() > 0) {
                        // in the case that the administrator has enabled trackbacks
                        // for only specific URLs, set it to false by default
                        allowTrackback = false;
                        String[] splitURLs = allowedURLs.split("\\|\\|");
                        for (int i=0; i<splitURLs.length; i++) {
                            Matcher m = Pattern.compile(splitURLs[i]).matcher(form.getTrackbackUrl());
                            if (m.matches()) {
                                allowTrackback = true;
                                break;
                            }
                        }
                    }
                   
                    if(!allowTrackback) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("error.trackbackNotAllowed"));
                    } else {
                        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());
                            HttpURLConnection conn = (HttpURLConnection)tburl.openConnection();
                            conn.setDoOutput(true);
                           
                            OutputStreamWriter wr =
                                    new OutputStreamWriter(conn.getOutputStream());
                            BufferedReader rd = null;
                            try {
                                wr.write(data);
                                wr.flush();
                               
                                // Get the response
                                boolean inputAvailable = false;
                                try {
                                    rd = new BufferedReader(new InputStreamReader(
                                            conn.getInputStream()));
                                    inputAvailable = true;
                                } catch (Throwable e) {
                                    mLogger.debug(e);
                                }
                               
                                // read repsonse only if there is one
                                if (inputAvailable) {
                                    String line;
                                    StringBuffer resultBuff = new StringBuffer();
                                    while ((line = rd.readLine()) != null) {
                                        resultBuff.append(
                                            StringEscapeUtils.escapeHtml(line));
                                        resultBuff.append("<br />");
                                    }
                                    resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
                                            new ActionMessage("weblogEdit.trackbackResults",
                                            resultBuff));
                                }
                               
                                // add response code to messages
                                if (conn.getResponseCode() > 399) {
                                    errors.add(ActionErrors.GLOBAL_ERROR,
                                            new ActionError("weblogEdit.trackbackStatusCodeBad",
                                            new Integer(conn.getResponseCode())));
                                } else {
                                    resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
                                            new ActionMessage("weblogEdit.trackbackStatusCodeGood",
                                            new Integer(conn.getResponseCode())));
                                }
                            } finally {
                                if (wr != null) wr.close();
                                if (rd != null) 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
        {
View Full Code Here

        mapping.setParameter("method");
        strutsModule.addRequestParameter("weblog",testWeblog.getHandle());
        strutsModule.addRequestParameter("method","create");
       
        // Setup form bean
        WeblogEntryFormEx form = (WeblogEntryFormEx)
        strutsModule.createActionForm(WeblogEntryFormEx.class);
        form.setTitle("test_title");
        form.setText("Test blog text");
       
        try {
            RollerRequest rreq = new RollerRequest(strutsModule.getMockPageContext());
            rreq.setWebsite(testWeblog);
            strutsModule.setRequestAttribute(RollerRequest.ROLLER_REQUEST, rreq);
View Full Code Here

        } catch (Exception e) {
            throw new ServletException(e);
        }
       
        // need to reset all values to empty (including 'id')
        actionForm = new WeblogEntryFormEx();
        actionForm.reset(mapping, request);
        request.setAttribute(mapping.getName(), actionForm);
        return create(mapping, actionForm, request, response);
    }
View Full Code Here

        ActionMessages resultMsg = new ActionMessages();
        ActionForward forward = mapping.findForward("weblogEdit.page");
        ActionErrors errors = new ActionErrors();
        WeblogEntryData entry = null;
        try {
            WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
            String entryid = form.getId();
            if ( entryid == null ) {
                entryid =
                        request.getParameter(RequestConstants.WEBLOGENTRY_ID);
            }
            Roller roller = RollerFactory.getRoller();
            RollerContext rctx= RollerContext.getRollerContext();
            WeblogManager wmgr= roller.getWeblogManager();
            entry = wmgr.getWeblogEntry(entryid);
           
            RollerSession rses = RollerSession.getRollerSession(request);
            if (rses.isUserAuthorizedToAuthor(entry.getWebsite())) {
                // Run entry through registered PagePlugins
                PluginManager ppmgr = roller.getPagePluginManager();
                Map plugins = ppmgr.getWeblogEntryPlugins(
                        entry.getWebsite());
               
                String content = "";
                if (!StringUtils.isEmpty(entry.getText())) {
                    content = entry.getText();
                } else {
                    content = entry.getSummary();
                }
                content = ppmgr.applyWeblogEntryPlugins(plugins, entry, content);

                String title = entry.getTitle();
                String excerpt = StringUtils.left( Utilities.removeHTML(content),255 );
               
                String url = entry.getPermalink();
                String blog_name = entry.getWebsite().getName();
               
                if (form.getTrackbackUrl() != null) {
                    // by default let all trackbacks to be sent
                    boolean allowTrackback = true;
                   
                    String allowedURLs = RollerConfig.getProperty("trackback.allowedURLs");
                    if (allowedURLs != null && allowedURLs.trim().length() > 0) {
                        // in the case that the administrator has enabled trackbacks
                        // for only specific URLs, set it to false by default
                        allowTrackback = false;
                        String[] splitURLs = allowedURLs.split("\\|\\|");
                        for (int i=0; i<splitURLs.length; i++) {
                            Matcher m = Pattern.compile(splitURLs[i]).matcher(form.getTrackbackUrl());
                            if (m.matches()) {
                                allowTrackback = true;
                                break;
                            }
                        }
                    }
                   
                    if(!allowTrackback) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                                new ActionError("error.trackbackNotAllowed"));
                    } else {
                        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());
                            HttpURLConnection conn = (HttpURLConnection)tburl.openConnection();
                            conn.setDoOutput(true);
                           
                            OutputStreamWriter wr =
                                    new OutputStreamWriter(conn.getOutputStream());
                            BufferedReader rd = null;
                            try {
                                wr.write(data);
                                wr.flush();
                               
                                // Get the response
                                boolean inputAvailable = false;
                                try {
                                    rd = new BufferedReader(new InputStreamReader(
                                            conn.getInputStream()));
                                    inputAvailable = true;
                                } catch (Throwable e) {
                                    mLogger.debug(e);
                                }
                               
                                // read repsonse only if there is one
                                if (inputAvailable) {
                                    String line;
                                    StringBuffer resultBuff = new StringBuffer();
                                    while ((line = rd.readLine()) != null) {
                                        resultBuff.append(
                                            StringEscapeUtils.escapeHtml(line));
                                        resultBuff.append("<br />");
                                    }
                                    resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
                                            new ActionMessage("weblogEdit.trackbackResults",
                                            resultBuff));
                                }
                               
                                // add response code to messages
                                if (conn.getResponseCode() > 399) {
                                    errors.add(ActionErrors.GLOBAL_ERROR,
                                            new ActionError("weblogEdit.trackbackStatusCodeBad",
                                            new Integer(conn.getResponseCode())));
                                } else {
                                    resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
                                            new ActionMessage("weblogEdit.trackbackStatusCodeGood",
                                            new Integer(conn.getResponseCode())));
                                }
                            } finally {
                                if (wr != null) wr.close();
                                if (rd != null) 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
        {
View Full Code Here

TOP

Related Classes of org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryFormEx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.