001
014
015 package com.liferay.portal.mobile.device.rulegroup.action.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.mobile.device.rulegroup.action.ActionHandler;
022 import com.liferay.portal.kernel.util.StringUtil;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portlet.mobiledevicerules.model.MDRAction;
025
026 import java.io.IOException;
027
028 import javax.servlet.http.HttpServletRequest;
029 import javax.servlet.http.HttpServletResponse;
030
031
034 public abstract class BaseRedirectActionHandler implements ActionHandler {
035
036 public void applyAction(
037 MDRAction mdrAction, HttpServletRequest request,
038 HttpServletResponse response)
039 throws PortalException, SystemException {
040
041 String url = getURL(mdrAction, request, response);
042
043 if (Validator.isNull(url)) {
044 if (_log.isInfoEnabled()) {
045 _log.info("URL is null");
046 }
047
048 return;
049 }
050
051 String requestURL = String.valueOf(request.getRequestURL());
052
053 if (StringUtil.contains(requestURL, url)) {
054 if (_log.isInfoEnabled()) {
055 _log.info(
056 "Skipping redirect. Current URL contains redirect URL.");
057 }
058
059 return;
060 }
061
062 try {
063 response.sendRedirect(url);
064 }
065 catch (IOException ioe) {
066 throw new PortalException("Unable to redirect to " + url, ioe);
067 }
068 }
069
070 protected abstract String getURL(
071 MDRAction mdrAction, HttpServletRequest request,
072 HttpServletResponse response)
073 throws PortalException, SystemException;
074
075 private static Log _log = LogFactoryUtil.getLog(
076 BaseRedirectActionHandler.class);
077
078 }