/** * Most of the code in the Qalingo project is copyrighted Hoteia and licensed * under the Apache License Version 2.0 (release version 0.8.0) * http://www.apache.org/licenses/LICENSE-2.0 * * Copyright (c) Hoteia, 2012-2014 * http://www.hoteia.com - http://twitter.com/hoteia - contact@hoteia.com * */ package org.hoteia.qalingo.core.web.mvc.viewbean; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.lang.StringUtils; import org.hoteia.qalingo.core.Constants; import org.hoteia.qalingo.core.util.CoreUtil; public class ProductAssociationLinkViewBean extends AbstractViewBean { /** * Generated UID */ private static final long serialVersionUID = 7398066505291279593L; protected int orderItem; protected String name; protected String description; protected String type; protected String i18nName; protected String i18nDescription; protected String i18nShortDescription; protected List<AssetViewBean> assets = new ArrayList<AssetViewBean>(); protected String productDetailsUrl; public int getOrderItem() { return orderItem; } public void setOrderItem(int orderItem) { this.orderItem = orderItem; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getI18nName() { if(StringUtils.isNotEmpty(i18nName)){ return i18nName; } return name; } public void setI18nName(String i18nName) { this.i18nName = i18nName; } public String getI18nTruncatedName() { int size = Constants.POJO_NAME_MAX_LENGTH; if (StringUtils.isNotEmpty(getI18nName())){ if(getI18nName().length() >= size){ return CoreUtil.handleTruncatedString(getI18nName(), size); } else { return getI18nName(); } } return ""; } public String getI18nDescription() { if(StringUtils.isNotEmpty(i18nDescription)){ return i18nDescription; } return description; } public void setI18nDescription(String i18nDescription) { this.i18nDescription = i18nDescription; } public String getI18nShortDescription() { return i18nShortDescription; } public void setI18nShortDescription(String i18nShortDescription) { this.i18nShortDescription = i18nShortDescription; } public String getI18nTruncatedDescription() { int size = Constants.POJO_DESCRIPTION_MAX_LENGTH; if(StringUtils.isNotEmpty(getI18nShortDescription())){ if(getI18nShortDescription().length() >= size){ return CoreUtil.handleTruncatedString(getI18nShortDescription(), size); } else { return getI18nShortDescription(); } } else if (StringUtils.isNotEmpty(getI18nDescription())){ if(getI18nDescription().length() >= size){ return CoreUtil.handleTruncatedString(getI18nDescription(), size); } else { return getI18nDescription(); } } return ""; } public List<AssetViewBean> getAssets() { return assets; } public String getAssetPath(String type) { for (Iterator<AssetViewBean> iterator = assets.iterator(); iterator.hasNext();) { AssetViewBean assetViewBean = (AssetViewBean) iterator.next(); if(assetViewBean.getType().equals(type)){ return assetViewBean.getPath(); } } return null; } public String getAssetAbsoluteWebPath(String type) { for (Iterator<AssetViewBean> iterator = assets.iterator(); iterator.hasNext();) { AssetViewBean assetViewBean = (AssetViewBean) iterator.next(); if(assetViewBean.getType().equals(type)){ return assetViewBean.getAbsoluteWebPath(); } } return null; } public String getAssetRelativeWebPath(String type) { for (Iterator<AssetViewBean> iterator = assets.iterator(); iterator.hasNext();) { AssetViewBean assetViewBean = (AssetViewBean) iterator.next(); if(assetViewBean.getType().equals(type)){ return assetViewBean.getRelativeWebPath(); } } return null; } public void setAssets(List<AssetViewBean> assets) { this.assets = assets; } public String getProductDetailsUrl() { return productDetailsUrl; } public void setProductDetailsUrl(String productDetailsUrl) { this.productDetailsUrl = productDetailsUrl; } }