1
22
23 package com.liferay.portlet.communities.action;
24
25 import com.liferay.portal.NoSuchLayoutSetException;
26 import com.liferay.portal.kernel.log.Log;
27 import com.liferay.portal.kernel.log.LogFactoryUtil;
28 import com.liferay.portal.kernel.util.ContentTypes;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.model.Group;
32 import com.liferay.portal.model.LayoutSet;
33 import com.liferay.portal.service.GroupLocalServiceUtil;
34 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
35 import com.liferay.portal.theme.ThemeDisplay;
36 import com.liferay.portal.util.PortalUtil;
37 import com.liferay.portal.util.SitemapUtil;
38 import com.liferay.portal.util.WebKeys;
39 import com.liferay.util.servlet.ServletResponseUtil;
40
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpServletResponse;
43
44 import org.apache.struts.action.Action;
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
54 public class SitemapAction extends Action {
55
56 public ActionForward execute(
57 ActionMapping mapping, ActionForm form, HttpServletRequest request,
58 HttpServletResponse response)
59 throws Exception {
60
61 try {
62 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
63 WebKeys.THEME_DISPLAY);
64
65 long groupId = ParamUtil.getLong(request, "groupId");
66 boolean privateLayout = ParamUtil.getBoolean(
67 request, "privateLayout");
68
69 LayoutSet layoutSet = null;
70
71 if (groupId > 0) {
72 Group group = GroupLocalServiceUtil.getGroup(groupId);
73
74 if (group.isStagingGroup()) {
75 groupId = group.getLiveGroupId();
76 }
77
78 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
79 groupId, privateLayout);
80 }
81 else {
82 String host = PortalUtil.getHost(request);
83
84 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(host);
85 }
86
87 String sitemap = SitemapUtil.getSitemap(
88 layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
89 themeDisplay);
90
91 ServletResponseUtil.sendFile(
92 response, null, sitemap.getBytes(StringPool.UTF8),
93 ContentTypes.TEXT_XML_UTF8);
94 }
95 catch (NoSuchLayoutSetException nslse) {
96 PortalUtil.sendError(
97 HttpServletResponse.SC_NOT_FOUND, nslse, request, response);
98 }
99 catch (Exception e) {
100 if (_log.isWarnEnabled()) {
101 _log.warn(e, e);
102 }
103
104 PortalUtil.sendError(
105 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request,
106 response);
107 }
108
109 return null;
110 }
111
112 private static Log _log = LogFactoryUtil.getLog(SitemapAction.class);
113
114 }