001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.admin.poller;
016    
017    import com.liferay.portal.kernel.json.JSONFactoryUtil;
018    import com.liferay.portal.kernel.json.JSONObject;
019    import com.liferay.portal.kernel.poller.BasePollerProcessor;
020    import com.liferay.portal.kernel.poller.PollerRequest;
021    import com.liferay.portal.kernel.poller.PollerResponse;
022    import com.liferay.portal.kernel.xuggler.XugglerInstallStatus;
023    import com.liferay.portal.util.WebKeys;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpSession;
027    
028    /**
029     * @author Sergio González
030     */
031    public class AdminPollerProcessor extends BasePollerProcessor {
032    
033            @Override
034            protected void doReceive(
035                    PollerRequest pollerRequest, PollerResponse pollerResponse)
036                    throws Exception {
037    
038                    pollerResponse.setParameter(
039                            PollerResponse.POLLER_HINT_HIGH_CONNECTIVITY,
040                            Boolean.TRUE.toString());
041    
042                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
043    
044                    String statusLabel = "unknown";
045    
046                    XugglerInstallStatus xugglerInstallStatus = getXugglerInstallStatus(
047                            pollerRequest);
048    
049                    if (xugglerInstallStatus != null) {
050                            statusLabel = xugglerInstallStatus.getStatusLabel();
051                    }
052    
053                    jsonObject.put("status", statusLabel);
054    
055                    boolean success = false;
056    
057                    if (!statusLabel.equals("unknown")) {
058                            success = true;
059                    }
060    
061                    jsonObject.put("success", success);
062    
063                    pollerResponse.setParameter("status", jsonObject);
064            }
065    
066            @Override
067            protected void doSend(PollerRequest pollerRequest) throws Exception {
068                    return;
069            }
070    
071            protected XugglerInstallStatus getXugglerInstallStatus(
072                    PollerRequest pollerRequest) {
073    
074                    HttpServletRequest request = pollerRequest.getRequest();
075    
076                    HttpSession session = request.getSession();
077    
078                    return (XugglerInstallStatus)session.getAttribute(
079                            WebKeys.XUGGLER_INSTALL_STATUS);
080            }
081    
082    }