Package org.apache.roller.business.pings

Examples of org.apache.roller.business.pings.PingTargetManager


     * Display the common ping targets with page
     */
    public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception {
        ActionForward forward = mapping.findForward(PING_SETUP_PAGE);
        RollerRequest rreq = RollerRequest.getRollerRequest(req);
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        WebsiteData website = rreq.getWebsite();
        try {
            if (!isAuthorized(rreq, website)) {
                return mapping.findForward("access-denied");
            }

            BasePageModel pageModel = new BasePageModel("pings.title", req, res, mapping);
            req.setAttribute("model", pageModel);

            List commonPingTargets = pingTargetMgr.getCommonPingTargets();
            req.setAttribute("commonPingTargets", commonPingTargets);

            Boolean allowCustomTargets = new Boolean(!PingConfig.getDisallowCustomTargets());
            req.setAttribute("allowCustomTargets", allowCustomTargets);

            List customPingTargets = allowCustomTargets.booleanValue() ? pingTargetMgr.getCustomPingTargets(website) : Collections.EMPTY_LIST;
            req.setAttribute("customPingTargets", customPingTargets);

            // Build isEnabled map (keyed by ping target id and values Boolean.TRUE/Boolean.FALSE)
            Map isEnabled = buildIsEnabledMap(rreq, commonPingTargets, customPingTargets);
            req.setAttribute("isEnabled", isEnabled);
View Full Code Here


    // TODO: Consider unifying with other RollerRequest methods
    // Private helper to get ping target specified by request
    private PingTargetData select(RollerRequest rreq) throws RollerException {
        String pingTargetId = rreq.getRequest().getParameter(RequestConstants.PINGTARGET_ID);
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        if (pingTargetId == null || pingTargetId.length() == 0) {
            throw new RollerException("Missing ping target id: " + pingTargetId);
        }

        PingTargetData pingTarget = pingTargetMgr.getPingTarget(pingTargetId);
        if (pingTarget == null) {
            throw new RollerException("No such ping target id: " + pingTargetId);
        }
        return pingTarget;
    }
View Full Code Here

     * @return the result of <code>view()</code> after the target is saved.
     * @throws Exception
     */
    public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception {
        RollerRequest rreq = RollerRequest.getRollerRequest(req);
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        PingTargetForm pingTargetForm = (PingTargetForm) form;
        try {
            BasePageModel pageModel = new BasePageModel(getPingTargetEditTitle(), req, res, mapping);
            req.setAttribute("model", pageModel);
            if (!hasRequiredRights(rreq, rreq.getWebsite())) {
                return mapping.findForward(ACCESS_DENIED_PAGE);
            }

            PingTargetData pingTarget = null;
            String pingTargetId = pingTargetForm.getId();
            if (pingTargetId != null && pingTargetId.length() > 0) {
                pingTarget = pingTargetMgr.getPingTarget(pingTargetForm.getId());
                if (pingTarget == null) throw new RollerException("No such ping target id: " + pingTargetId);
                pingTargetForm.copyTo(pingTarget, req.getLocale());
            } else {
                pingTarget = createPingTarget(rreq, pingTargetForm);
            }

            // Call private helper to validate ping target
            // If there are errors, go back to the target edit page.
            ActionMessages errors = validate(rreq, pingTarget);
            if (!errors.isEmpty()) {
                saveErrors(rreq.getRequest(), errors);
                return mapping.findForward(PING_TARGET_EDIT_PAGE);
            }

            // Appears to be ok. 
            // Save it, commit and return refreshed view of target list.
            pingTargetMgr.savePingTarget(pingTarget);
            RollerFactory.getRoller().flush();

            ActionMessages msgs = new ActionMessages();
            msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("pingTarget.saved"));
            saveMessages(req, msgs);
View Full Code Here

     * @throws Exception
     */
    public ActionForward deleteConfirmed(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception {
        RollerRequest rreq = RollerRequest.getRollerRequest(req);
        PingTargetForm pingTargetForm = (PingTargetForm) form;
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        try {
            if (!hasRequiredRights(rreq, rreq.getWebsite())) {
                return mapping.findForward(ACCESS_DENIED_PAGE);
            }
            String pingTargetId = pingTargetForm.getId();
            if (pingTargetId == null || pingTargetId.length() == 0) {
                throw new RollerException("Missing ping target id.");
            }
            PingTargetData ping = pingTargetMgr.getPingTarget(pingTargetId);
            pingTargetMgr.removePingTarget(ping);
            RollerFactory.getRoller().flush();
            return view(mapping, form, req, res);
        } catch (Exception e) {
            getLogger().error("ERROR in action", e);
            throw new ServletException(e);
View Full Code Here

     * @return the ping target specified by the id in the request
     * @throws RollerException
     */
    protected PingTargetData select(RollerRequest rreq) throws RollerException {
        String pingTargetId = rreq.getRequest().getParameter(RequestConstants.PINGTARGET_ID);
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        if (pingTargetId == null || pingTargetId.length() == 0) {
            throw new RollerException("Missing ping target id: " + pingTargetId);
        }

        PingTargetData pingTarget = pingTargetMgr.getPingTarget(pingTargetId);
        if (pingTarget == null) {
            throw new RollerException("No such ping target id: " + pingTargetId);
        }
        return pingTarget;
    }
View Full Code Here

     * @throws RollerException
     */
    private ActionMessages validate(RollerRequest rreq, PingTargetData pingTarget) throws RollerException {
        ActionMessages errors = new ActionMessages();

        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        if (!pingTargetMgr.isNameUnique(pingTarget)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("pingTarget.nameNotUnique"));
        }
        if (!pingTargetMgr.isUrlWellFormed(pingTarget)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("pingTarget.malformedUrl"));
        } else if (!pingTargetMgr.isHostnameKnown(pingTarget)) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("pingTarget.unknownHost"));
        }
        return errors;
    }
View Full Code Here

    /**
     * Test basic persistence operations ... Create, Update, Delete
     */
    public void testPingTargetCRUD() throws Exception {
       
        PingTargetManager mgr = RollerFactory.getRoller().getPingTargetManager();
        PingTargetData ping = null;
       
        // create common ping
        mgr.savePingTarget(testCommonPing);
        String commonId = testCommonPing.getId();
        TestUtils.endSession(true);
       
        // make sure common ping was stored
        ping = null;
        ping = mgr.getPingTarget(commonId);
        assertNotNull(ping);
        assertEquals(testCommonPing.getPingUrl(), ping.getPingUrl());
       
        // create custom ping
        testCustomPing.setWebsite(testWeblog);
        mgr.savePingTarget(testCustomPing);
        String customId = testCustomPing.getId();
        TestUtils.endSession(true);
       
        // make sure custom ping was stored
        ping = null;
        ping = mgr.getPingTarget(customId);
        assertNotNull(ping);
        assertEquals(testCustomPing.getPingUrl(), ping.getPingUrl());
       
        // update common ping
        ping = null;
        ping = mgr.getPingTarget(commonId);
        ping.setName("testtestCommon");
        mgr.savePingTarget(ping);
        TestUtils.endSession(true);
       
        // make sure common ping was updated
        ping = null;
        ping = mgr.getPingTarget(commonId);
        assertNotNull(ping);
        assertEquals("testtestCommon", ping.getName());
       
        // update custom ping
        ping = null;
        ping = mgr.getPingTarget(customId);
        ping.setName("testtestCustom");
        mgr.savePingTarget(ping);
        TestUtils.endSession(true);
       
        // make sure custom ping was updated
        ping = null;
        ping = mgr.getPingTarget(customId);
        assertNotNull(ping);
        assertEquals("testtestCustom", ping.getName());
       
        // delete common ping
        ping = null;
        ping = mgr.getPingTarget(commonId);
        mgr.removePingTarget(ping);
        TestUtils.endSession(true);
       
        // make sure common ping was deleted
        ping = null;
        ping = mgr.getPingTarget(commonId);
        assertNull(ping);
       
        // delete custom ping
        ping = null;
        ping = mgr.getPingTarget(customId);
        mgr.removePingTarget(ping);
        TestUtils.endSession(true);
       
        // make sure custom ping was deleted
        ping = null;
        ping = mgr.getPingTarget(customId);
        assertNull(ping);
    }
View Full Code Here

    /**
     * Test lookup mechanisms ... id, all common, all custom for weblog
     */
    public void testPingTargetLookups() throws Exception {
       
        PingTargetManager mgr = RollerFactory.getRoller().getPingTargetManager();
        PingTargetData ping = null;
       
        // create common ping
        mgr.savePingTarget(testCommonPing);
        String commonId = testCommonPing.getId();
        TestUtils.endSession(true);
       
        // create custom ping
        testCustomPing.setWebsite(testWeblog);
        mgr.savePingTarget(testCustomPing);
        String customId = testCustomPing.getId();
        TestUtils.endSession(true);
       
        // lookup by id
        ping = null;
        ping = mgr.getPingTarget(commonId);
        assertNotNull(ping);
        assertEquals(testCommonPing.getName(), ping.getName());
       
        // lookup all common pings
        List commonPings = mgr.getCommonPingTargets();
        assertNotNull(commonPings);
        assertEquals(1, commonPings.size());
       
        // lookup all custom pings for weblog
        List customPings = mgr.getCustomPingTargets(testWeblog);
        assertNotNull(customPings);
        assertEquals(1, customPings.size());
       
        // delete common ping
        ping = null;
        ping = mgr.getPingTarget(commonId);
        mgr.removePingTarget(ping);
        TestUtils.endSession(true);
       
        // delete custom ping
        ping = null;
        ping = mgr.getPingTarget(customId);
        mgr.removePingTarget(ping);
        TestUtils.endSession(true);
    }
View Full Code Here

        while(it.hasNext()) {
            this.strategy.remove((AutoPingData) it.next());
        }
       
        // Remove the website's custom ping targets
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        List pingtargets = pingTargetMgr.getCustomPingTargets(website);
        it = pingtargets.iterator();
        while(it.hasNext()) {
            this.strategy.remove((PingTargetData) it.next());
        }
       
View Full Code Here

                }
            }
        }
       
        // add any auto enabled ping targets
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
       
        Iterator pingTargets = pingTargetMgr.getCommonPingTargets().iterator();
        PingTargetData pingTarget = null;
        while(pingTargets.hasNext()) {
            pingTarget = (PingTargetData) pingTargets.next();
           
            if(pingTarget.isAutoEnabled()) {
View Full Code Here

TOP

Related Classes of org.apache.roller.business.pings.PingTargetManager

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.