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
55 public class SitemapAction extends Action {
56
57 public ActionForward execute(
58 ActionMapping mapping, ActionForm form, HttpServletRequest request,
59 HttpServletResponse response)
60 throws Exception {
61
62 try {
63 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
64 WebKeys.THEME_DISPLAY);
65
66 long groupId = ParamUtil.getLong(request, "groupId");
67 boolean privateLayout = ParamUtil.getBoolean(
68 request, "privateLayout");
69
70 LayoutSet layoutSet = null;
71
72 if (groupId > 0) {
73 Group group = GroupLocalServiceUtil.getGroup(groupId);
74
75 if (group.isStagingGroup()) {
76 groupId = group.getLiveGroupId();
77 }
78
79 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
80 groupId, privateLayout);
81 }
82 else {
83 String host = PortalUtil.getHost(request);
84
85 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(host);
86 }
87
88 String sitemap = SitemapUtil.getSitemap(
89 layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
90 themeDisplay);
91
92 ServletResponseUtil.sendFile(
93 response, null, sitemap.getBytes(StringPool.UTF8),
94 ContentTypes.TEXT_XML_UTF8);
95 }
96 catch (NoSuchLayoutSetException nslse) {
97 PortalUtil.sendError(
98 HttpServletResponse.SC_NOT_FOUND, nslse, request, response);
99 }
100 catch (Exception e) {
101 if (_log.isWarnEnabled()) {
102 _log.warn(e, e);
103 }
104
105 PortalUtil.sendError(
106 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request,
107 response);
108 }
109
110 return null;
111 }
112
113 private static Log _log = LogFactoryUtil.getLog(SitemapAction.class);
114
115 }