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