001
014
015 package com.liferay.portlet.search.action;
016
017 import com.liferay.portal.kernel.search.OpenSearch;
018 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
019 import com.liferay.portal.kernel.util.ContentTypes;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.search.PortalOpenSearchImpl;
022 import com.liferay.portal.util.PortalUtil;
023
024 import javax.servlet.http.HttpServletRequest;
025 import javax.servlet.http.HttpServletResponse;
026
027 import org.apache.struts.action.Action;
028 import org.apache.struts.action.ActionForm;
029 import org.apache.struts.action.ActionForward;
030 import org.apache.struts.action.ActionMapping;
031
032
035 public class OpenSearchAction extends Action {
036
037 @Override
038 public ActionForward execute(
039 ActionMapping actionMapping, ActionForm actionForm,
040 HttpServletRequest request, HttpServletResponse response)
041 throws Exception {
042
043 try {
044 ServletResponseUtil.sendFile(
045 request, response, null, getXML(request),
046 ContentTypes.TEXT_XML_UTF8);
047
048 return null;
049 }
050 catch (Exception e) {
051 PortalUtil.sendError(e, request, response);
052
053 return null;
054 }
055 }
056
057 protected byte[] getXML(HttpServletRequest request) throws Exception {
058 OpenSearch search = new PortalOpenSearchImpl();
059
060 String xml = search.search(
061 request,
062 request.getRequestURL().toString() + StringPool.QUESTION +
063 request.getQueryString());
064
065 return xml.getBytes();
066 }
067
068 }