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