public class StylesSelectAction extends ConfigAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
UserContainer user, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
final StylesSelectForm selectForm = (StylesSelectForm) form;
final String action = selectForm.getAction();
String styleId = selectForm.getSelectedStyle();
if(styleId.endsWith("*")){
styleId = styleId.substring(0,styleId.lastIndexOf("*"));
}
Locale locale = (Locale) request.getLocale();
DataConfig config = getDataConfig();
MessageResources messages = servlet.getResources();
// Need locale wording for edit and delete
final String EDIT = HTMLEncoder.decode(messages.getMessage(locale, "label.edit"));
final String DELETE = HTMLEncoder.decode(messages.getMessage(locale, "label.delete"));
final String DEFAULT = HTMLEncoder.decode(messages.getMessage(locale, "label.default"));
StyleConfig style = config.getStyle( styleId );
if( style == null ){
ActionErrors errors = new ActionErrors();
errors.add("selectedStyle",
new ActionError("error.style.invalid", styleId ));
request.setAttribute(Globals.ERROR_KEY, errors);
return mapping.findForward("config.data.style");
}
// Something is selected lets do the requested action
//
if (action.equals(DELETE)) {
config.removeStyle( styleId );
getApplicationState().notifyConfigChanged();
selectForm.setSelectedStyle(null);
selectForm.reset(mapping, request);
return mapping.findForward("config.data.style");
}
if (action.equals(DEFAULT)) {
Map m = config.getStyles();
Iterator i = m.values().iterator();
while(i.hasNext()){
StyleConfig sc = (StyleConfig)i.next();
if(sc.isDefault()){
if(sc.getId()!=null && !sc.getId().equals(styleId)){
sc.setDefault(false);
getApplicationState().notifyConfigChanged();
}
}else{
if(sc.getId()!=null && sc.getId().equals(styleId)){
sc.setDefault(true);
getApplicationState().notifyConfigChanged();
}
}
}
selectForm.setSelectedStyle(null);
selectForm.reset(mapping, request);
return mapping.findForward("config.data.style");
}
if( action.equals(EDIT)){
user.setStyle( new StyleConfig( style ) );
return mapping.findForward("config.data.style.editor");