我有一个java类代表值列表,我需要在其中强制使用语言环境。
如何确定区域设置?
以下类显示内容模型的约束值/标签。
package com.ds.ui.constraints;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.apache.log4j.Logger;
import com.ds.ui.bean.dialog.util.BeanUtil;
public class PositionPermissionsConstraints extends ListOfValuesConstraint
implements Serializable {
public void initialize(){
LOG.debug("PositionPermissionsConstraints Initializer");
super.setCaseSensitive(false);
preparePermissionList();
}
public void preparePermissionList(){
ResourceBundle bundle = null;
if(FacesContext.getCurrentInstance() != null){
if(FacesContext.getCurrentInstance().getExternalContext().getRequestLocale() != null)
bundle = ResourceBundle.getBundle(BeanUtil.RESOURECE_BUNDLE,
FacesContext.getCurrentInstance().getExternalContext().getRequestLocale());
}
else
bundle = ResourceBundle.getBundle(BeanUtil.RESOURECE_BUNDLE);
List<String> av = new ArrayList<String>();
av
.add(PositionPermissionsConstraints.
CREATE_ORGANIZATION_PERMISSION);
this.allowedLabels
.add(bundle.getString(CREATE_ORGANIZATION_PERMISSION));
av
.add(PositionPermissionsConstraints.
UPDATE_ORGANIZATION_PERMISSION);
this.allowedLabels
.add(bundle.getString(UPDATE_ORGANIZATION_PERMISSION));
av
.add(PositionPermissionsConstraints.
DELETE_ORGANIZATION_PERMISSION);
this.allowedLabels
.add(bundle.getString(DELETE_ORGANIZATION_PERMISSION));
av
.add(PositionPermissionsConstraints.
CREATE_ROOT_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(CREATE_ROOT_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
MANAGE_ROOT_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(MANAGE_ROOT_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
CREATE_SUBORDINATE_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(CREATE_SUBORDINATE_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
UPDATE_SUBORDINATE_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(UPDATE_SUBORDINATE_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
DELETE_SUBORDINATE_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(DELETE_SUBORDINATE_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
MANAGE_POSITION_PERMISSION);
this.allowedLabels
.add(bundle.getString(MANAGE_POSITION_PERMISSION));
av
.add(PositionPermissionsConstraints.
ASSIGN_POSITION_TO_USER_PERMISSION);
this.allowedLabels
.add(bundle.getString(ASSIGN_POSITION_TO_USER_PERMISSION));
this.setAllowedValues(av);
this.setAllowedLabels(allowedLabels);
}
public List<SelectItem> prepareSelectItemsList(){
ResourceBundle bundle = ResourceBundle.getBundle(BeanUtil.RESOURECE_BUNDLE);
List<SelectItem> selectItems = new ArrayList<SelectItem>();
for(String value : getAllowedValues()){
SelectItem selectItem = new SelectItem(value,bundle.getString(value));
selectItems.add(selectItem);
}
return selectItems;
}
private static final String CREATE_ORGANIZATION_PERMISSION = "CREATE_ORGANIZATION";
private static final String UPDATE_ORGANIZATION_PERMISSION = "UPDATE_ORGANIZATION";
private static final String DELETE_ORGANIZATION_PERMISSION = "DELETE_ORGANIZATION";
private static final String CREATE_ROOT_POSITION_PERMISSION = "CREATE_ROOT_POSITION";
private static final String MANAGE_ROOT_POSITION_PERMISSION = "MANAGE_ROOT_POSITION";
private static final String CREATE_SUBORDINATE_POSITION_PERMISSION = "CREATE_SUBORDINATE_POSITION";
private static final String UPDATE_SUBORDINATE_POSITION_PERMISSION = "UPDATE_SUBORDINATE_POSITION";
private static final String DELETE_SUBORDINATE_POSITION_PERMISSION = "DELETE_SUBORDINATE_POSITION";
private static final String MANAGE_POSITION_PERMISSION = "MANAGE_POSITION";
private static final String ASSIGN_POSITION_TO_USER_PERMISSION = "ASSIGN_POSITION_TO_USER";
private List<String> allowedLabels = new ArrayList<String>();
private static final long serialVersionUID = 1L;
private static Logger LOG = Logger.getLogger(PositionPermissionsConstraints.class);
public List<String> getAllowedLabels() {
return allowedLabels;
}
public void setAllowedLabels(List<String> allowedLabels) {
this.allowedLabels = allowedLabels;
}
}
由于
答案 0 :(得分:0)
如果您使用的是WebScript,那么I18NUtil就是您想要的。其上的方法public static Locale getLocale()
将返回当前运行的webscript的区域设置