001
014
015 package com.liferay.portlet.layoutsadmin.action;
016
017 import com.liferay.portal.LayoutSetVirtualHostException;
018 import com.liferay.portal.NoSuchLayoutSetException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
022 import com.liferay.portal.kernel.util.ContentTypes;
023 import com.liferay.portal.kernel.util.StringPool;
024 import com.liferay.portal.model.LayoutSet;
025 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.RobotsUtil;
028
029 import javax.servlet.http.HttpServletRequest;
030 import javax.servlet.http.HttpServletResponse;
031
032 import org.apache.struts.action.Action;
033 import org.apache.struts.action.ActionForm;
034 import org.apache.struts.action.ActionForward;
035 import org.apache.struts.action.ActionMapping;
036
037
040 public class RobotsAction extends Action {
041
042 @Override
043 public ActionForward execute(
044 ActionMapping mapping, ActionForm form, HttpServletRequest request,
045 HttpServletResponse response)
046 throws Exception {
047
048 try {
049 String virtualHostname = PortalUtil.getHost(request);
050
051 LayoutSet layoutSet = null;
052
053 try {
054 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
055 virtualHostname);
056 }
057 catch (LayoutSetVirtualHostException lsvhe) {
058 }
059 catch (NoSuchLayoutSetException nslse) {
060 }
061
062 String robots = RobotsUtil.getRobots(layoutSet);
063
064 ServletResponseUtil.sendFile(
065 request, response, null, robots.getBytes(StringPool.UTF8),
066 ContentTypes.TEXT_PLAIN_UTF8);
067 }
068 catch (Exception e) {
069 if (_log.isWarnEnabled()) {
070 _log.warn(e, e);
071 }
072
073 PortalUtil.sendError(
074 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request,
075 response);
076 }
077
078 return null;
079 }
080
081 private static Log _log = LogFactoryUtil.getLog(RobotsAction.class);
082
083 }