001
014
015 package com.liferay.portlet.search.action;
016
017 import com.liferay.portal.kernel.search.OpenSearch;
018 import com.liferay.portal.kernel.util.ContentTypes;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.search.PortalOpenSearchImpl;
021 import com.liferay.portal.util.PortalUtil;
022 import com.liferay.util.servlet.ServletResponseUtil;
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 public ActionForward execute(
038 ActionMapping mapping, ActionForm form, HttpServletRequest request,
039 HttpServletResponse response)
040 throws Exception {
041
042 try {
043 ServletResponseUtil.sendFile(
044 request, response, null, getXML(request),
045 ContentTypes.TEXT_XML_UTF8);
046
047 return null;
048 }
049 catch (Exception e) {
050 PortalUtil.sendError(e, request, response);
051
052 return null;
053 }
054 }
055
056 protected byte[] getXML(HttpServletRequest request) throws Exception {
057 OpenSearch search = new PortalOpenSearchImpl();
058
059 String xml = search.search(
060 request,
061 request.getRequestURL().toString() + StringPool.QUESTION +
062 request.getQueryString());
063
064 return xml.getBytes();
065 }
066
067 }