
Originally Posted by
myjo@hotmail.com
Hi MIsha79,
Thank you for this e-mail. I'm sorry that our code is really difficult to understand. I have put in the 'Code Tags' around my code, and I have also formatted my code in more readable manner and have posted it out. The StoreProfileContextImpl class is having following code (I have put code tags around this code:
================================================== ===============================================
package com.follett.fheg.ecommerce.onlineadoptions.web.con text.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.MessageSource;
import com.follett.fheg.ecommerce.onlineadoptions.model.d omain.MaterialReqType;
import com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile;
import com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfileDescription;
import com.follett.fheg.ecommerce.onlineadoptions.web.con text.StoreProfileContext;
/**
* Implementation class for StoreProfileContext to manage store profile information.
*
* @author akesingh
*
*/
public class StoreProfileContextImpl implements StoreProfileContext {
@SuppressWarnings("unused")
private static final String cvsid = "$Id: StoreProfileContextImpl.java,v 1.11 2011/02/25 04:54:56 mnolan Exp $";
private static final String MESSAGE_SOURCE = "messageSource";
private static final long serialVersionUID = 3220177064920697756L;
private StoreProfile storeProfile;
private StoreProfileDescription storeProfileDescriptionForCurrentLocaleName;
private String localeName;
private boolean initialized = false;
private String contactSiteDomain;
private String imageServerDomain;
private final Map<String, Map<String, String>> defaultMessageMap = new HashMap<String, Map<String,String>>();
/**
* Clears the state for the current session.
*/
@Override
public void clear() {
this.localeName = null;
this.storeProfile = null;
// IMPORTANT: Do not clear the defaultMessageMap. This is needed later on.
}
@Override
public void setStoreProfile(final StoreProfile storeProfile) {
this.storeProfile = storeProfile;
if (StringUtils.isNotBlank(this.localeName)) {
getStoreProfileDescriptionForCurrentLocale();
}
}
private void getStoreProfileDescriptionForCurrentLocale() {
int localeNameId = -1;
if ("en_US".equals(this.localeName)) {
localeNameId = 1;
} else if ("fr_FR".equals(this.localeName)) {
localeNameId = 2;
}
for (final StoreProfileDescription spDesc : this.storeProfile.getStoreProfileDescription()) {
if (spDesc.getLocale() == localeNameId) {
this.storeProfileDescriptionForCurrentLocaleName = spDesc;
break;
}
}
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getExternalStoreNumber()
*/
public String getExternalStoreNumber() {
return (this.storeProfile != null) ? this.storeProfile.getExternalStoreNumber() : "";
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getLegalDisclosureAgreementFlag ()
*/
public String getLegalDisclosureAgreementFlag() {
return this.storeProfile.getLegalDisclosureAgreementFlag( );
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getMaterialRequirementTypeLabel s()
*/
public Map<String, String> getMaterialRequirementTypeLabels() {
return this.storeProfile.getMaterialRequirementTypeLabels ();
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getOaStoreId()
*/
public long getOaStoreId() {
return this.storeProfile.getOaStoreId();
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getStoreLogo()
*/
public String getStoreLogo() {
return this.imageServerDomain + "htmlroot/images/templates/storeLogos/CA/" + getExternalStoreNumber() + ".gif";
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#getStoreName()
*/
public String getStoreName() {
return (this.storeProfile != null) ? this.storeProfile.getStoreName() : "";
}
/**
* @return
* @see com.follett.fheg.ecommerce.onlineadoptions.model.d omain.StoreProfile#isGlobalStore()
*/
public boolean isGlobalStore() {
return this.storeProfile.isGlobalStore();
}
@Override
public String getCampusLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getProgramLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etProgramLabel();
} else {
//return this.messageSource.getMessage("common.label.campus ", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.campus");
}
}
@Override
public String getCourseLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getCourseLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etCourseLabel();
} else {
//return this.messageSource.getMessage("common.label.course ", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.course");
}
}
@Override
public String getDivisionLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getDivisionLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etDivisionLabel();
} else {
//return this.messageSource.getMessage("common.label.divisi on", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.division");
}
}
@Override
public String getDepartmentLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getDepartmentLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etDepartmentLabel();
} else {
//return this.messageSource.getMessage("common.label.depart ment", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.department");
}
}
@Override
public Map<String, String> getMaterialRequirementTypeLabel() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getSectionLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getSectionLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etSectionLabel();
} else {
//return this.messageSource.getMessage("common.label.sectio n", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.section");
}
}
@Override
public String getTermLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getTermLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etTermLabel();
} else {
//return this.messageSource.getMessage("common.label.term", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.term");
}
}
@Override
public String getInstructorLabel() {
if (StringUtils.isNotBlank(this.storeProfileDescripti onForCurrentLocaleName.getInstructorLabel())) {
return this.storeProfileDescriptionForCurrentLocaleName.g etInstructorLabel();
} else {
//return this.messageSource.getMessage("common.label.instru ctor", new Object[0], new Locale(this.localeName) );
return getDefaultMessageForKey(this.localeName, "common.label.instructor");
}
}
@Override
public void setLocale(final String localeName) {
this.localeName = localeName;
getStoreProfileDescriptionForCurrentLocale();
}
@Override
public Long getOaStoreProfileId() {
return this.storeProfile.getOaStoreId();
}
@Override
public boolean isInitialized() {
return this.initialized;
}
@Override
public void markInitialized() {
this.initialized = true;
}
@Override
public boolean isStoreProfileGlobal() {
return this.storeProfile.isGlobalStore();
}
@Override
public String getCTStoreNumber() {
return this.storeProfile.getCtStoreNumber();
}
}