de.mklinger.qetcher.liferay.client.impl.abstraction.PortalToolImpl Maven / Gradle / Ivy
/*
* Copyright 2013-present mklinger GmbH - http://www.mklinger.de
*
* All rights reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of mklinger GmbH and its suppliers, if any.
* The intellectual and technical concepts contained herein are
* proprietary to mklinger GmbH and its suppliers and are protected
* by trade secret or copyright law. Dissemination of this
* information or reproduction of this material is strictly forbidden
* unless prior written permission is obtained from mklinger GmbH.
*/
package de.mklinger.qetcher.liferay.client.impl.abstraction;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Company;
import com.liferay.portal.security.auth.CompanyThreadLocal;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextThreadLocal;
import de.mklinger.qetcher.liferay.abstraction.PortalTool;
/**
* @author Marc Klinger - mklinger[at]mklinger[dot]de
*/
public class PortalToolImpl implements PortalTool {
private static final Logger LOG = LoggerFactory.getLogger(PortalToolImpl.class);
@Override
public String getBaseUrl() {
final ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
if (serviceContext != null) {
String baseUrl = serviceContext.getLayoutFullURL();
if (baseUrl != null) {
LOG.debug("Have layout full url: {}", baseUrl);
return baseUrl;
}
baseUrl = serviceContext.getPortalURL();
if (baseUrl != null) {
LOG.debug("Have portal url: {}", baseUrl);
return baseUrl;
}
}
//PortalSessionThreadLocal
//PrincipalThreadLocal
final Long companyId = CompanyThreadLocal.getCompanyId();
if (companyId != null) {
Company company;
try {
company = CompanyLocalServiceUtil.getCompany(companyId);
} catch (PortalException | SystemException e) {
return null;
}
final String baseUrl = "http://" + company.getVirtualHostname();
LOG.debug("Have company virtual host url: {}", baseUrl);
return baseUrl;
}
return null;
}
@Override
public HttpServletRequest getHttpServletRequest() {
final ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
if (serviceContext == null) {
return null;
}
return serviceContext.getRequest();
}
}