/**
 * Copyright (c) 2000-2017 Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * pSubscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.portal.staging.web.internal.display.context;

import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.model.LayoutBranch;
import com.liferay.portal.model.LayoutBranchConstants;

import javax.servlet.jsp.PageContext;

/**
 * @author Mariano Alvaro Saiz
 */
public class LayoutBranchDisplayContext {

	public LayoutBranchDisplayContext(PageContext pageContext) {
		_pageContext = pageContext;
	}

	public String getLayoutBranchDisplayName(LayoutBranch layoutBranch) {
		return getLayoutBranchDisplayName(layoutBranch.getName());
	}

	public String getLayoutBranchDisplayName(String layoutBranchName) {
		if (_shouldTranslateLayoutBranchName(layoutBranchName)) {
			return LanguageUtil.get(_pageContext, layoutBranchName);
		}

		return layoutBranchName;
	}

	private boolean _shouldTranslateLayoutBranchName(
		LayoutBranch layoutBranch) {

		return _shouldTranslateLayoutBranchName(layoutBranch.getName());
	}

	private boolean _shouldTranslateLayoutBranchName(String layoutBranchName) {
		return LayoutBranchConstants.MASTER_BRANCH_NAME.equals(
			layoutBranchName);
	}

	private final PageContext _pageContext;

}