1 31 32 package org.opencms.workplace.tools.content; 33 34 import org.opencms.importexport.CmsVfsImportExportHandler; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.CmsIllegalArgumentException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.main.OpenCms; 40 import org.opencms.util.CmsStringUtil; 41 import org.opencms.widgets.CmsCheckboxWidget; 42 import org.opencms.widgets.CmsSelectWidget; 43 import org.opencms.widgets.CmsSelectWidgetOption; 44 import org.opencms.widgets.CmsVfsFileWidget; 45 import org.opencms.workplace.CmsWidgetDialog; 46 import org.opencms.workplace.CmsWidgetDialogParameter; 47 import org.opencms.workplace.CmsWorkplaceSettings; 48 import org.opencms.workplace.explorer.CmsNewResourceXmlPage; 49 import org.opencms.workplace.tools.CmsToolDialog; 50 import org.opencms.workplace.tools.CmsToolManager; 51 52 import java.io.IOException ; 53 import java.util.ArrayList ; 54 import java.util.HashMap ; 55 import java.util.Iterator ; 56 import java.util.List ; 57 import java.util.Locale ; 58 import java.util.Map ; 59 import java.util.TreeMap ; 60 61 import javax.servlet.ServletException ; 62 import javax.servlet.http.HttpServletRequest ; 63 import javax.servlet.http.HttpServletResponse ; 64 import javax.servlet.jsp.PageContext ; 65 66 import org.apache.commons.logging.Log; 67 68 77 public class CmsElementChangeLocaleDialog extends CmsWidgetDialog { 78 79 80 public static final String KEY_PREFIX = "changelocale"; 81 82 83 public static final String [] PAGES = {"page1"}; 84 85 86 protected static final String CHANGELOCALE_ACTION_REPORT = PATH_WORKPLACE + "admin/contenttools/reports/changelocale.jsp"; 87 88 89 private static final Log LOG = CmsLog.getLog(CmsElementChangeLocaleDialog.class); 90 91 92 private CmsElementChangeLocaleSettings m_settings; 93 94 99 public CmsElementChangeLocaleDialog(CmsJspActionElement jsp) { 100 101 super(jsp); 102 } 103 104 111 public CmsElementChangeLocaleDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 112 113 this(new CmsJspActionElement(context, req, res)); 114 } 115 116 119 public void actionCommit() throws IOException , ServletException { 120 121 List errors = new ArrayList (); 122 setDialogObject(m_settings); 123 124 try { 125 126 if (m_settings.getOldLocale().equals(m_settings.getNewLocale())) { 127 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_CHANGEELEMENTLOCALE_LOCALE_EQUAL_0)); 129 } 130 131 Map params = new HashMap (); 132 params.put(CmsElementChangeLocaleReport.PARAM_CLASSNAME, this.getClass().getName()); 134 params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW); 136 params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/contenttools")); 138 getToolManager().jspForwardPage(this, CHANGELOCALE_ACTION_REPORT, params); 140 141 } catch (CmsIllegalArgumentException e) { 142 errors.add(e); 143 } 144 setCommitErrors(errors); 146 } 147 148 153 public List getLocaleConfigOptions() { 154 155 List result = new ArrayList (); 156 157 List locales = OpenCms.getLocaleManager().getAvailableLocales(); 158 Iterator i = locales.iterator(); 159 while (i.hasNext()) { 160 Locale locale = (Locale )i.next(); 161 String language = locale.toString(); 162 String displayLanguage = locale.getDisplayLanguage(getLocale()); 163 164 result.add(new CmsSelectWidgetOption(language, false, displayLanguage)); 165 } 166 167 return result; 168 } 169 170 175 public List getTemplateConfigOptions() { 176 177 List result = new ArrayList (); 178 result.add(new CmsSelectWidgetOption("", true, key(Messages.GUI_CHANGEELEMENTLOCALE_DIALOG_TEMPLATE_ALL_0))); 179 180 TreeMap templates = null; 181 try { 182 templates = CmsNewResourceXmlPage.getTemplates(getCms(), null); 184 } catch (CmsException e) { 185 if (LOG.isInfoEnabled()) { 187 LOG.info(e); 188 } 189 } 190 if (templates != null) { 191 Iterator i = templates.keySet().iterator(); 193 while (i.hasNext()) { 194 String key = (String )i.next(); 195 String path = (String )templates.get(key); 196 result.add(new CmsSelectWidgetOption(path, false, key)); 197 } 198 } 199 return result; 200 } 201 202 205 protected String createDialogHtml(String dialog) { 206 207 StringBuffer result = new StringBuffer (1024); 208 209 result.append(createWidgetTableStart()); 211 212 result.append(createWidgetErrorHeader()); 214 215 result.append(createWidgetBlockStart(key(Messages.GUI_CHANGEELEMENTLOCALE_DIALOG_BLOCK_SETTINGS_0))); 217 result.append(createDialogRowsHtml(0, 4)); 218 result.append(createWidgetBlockEnd()); 219 220 result.append(createWidgetTableEnd()); 222 223 return result.toString(); 224 } 225 226 229 protected void defineWidgets() { 230 231 initSettingsObject(); 233 234 setKeyPrefix(KEY_PREFIX); 236 237 addWidget(new CmsWidgetDialogParameter(m_settings, "vfsFolder", "/", PAGES[0], new CmsVfsFileWidget( 238 false, 239 getCms().getRequestContext().getSiteRoot()), 1, 1)); 240 241 addWidget(new CmsWidgetDialogParameter(m_settings, "includeSubFolders", PAGES[0], new CmsCheckboxWidget())); 242 addWidget(new CmsWidgetDialogParameter(m_settings, "template", PAGES[0], new CmsSelectWidget(getTemplateConfigOptions()))); 243 244 List localeSelections = getLocaleConfigOptions(); 245 addWidget(new CmsWidgetDialogParameter(m_settings, "oldLocale", PAGES[0], new CmsSelectWidget(localeSelections))); 246 addWidget(new CmsWidgetDialogParameter(m_settings, "newLocale", PAGES[0], new CmsSelectWidget(localeSelections))); 247 } 248 249 252 protected String [] getPageArray() { 253 254 return PAGES; 255 } 256 257 260 protected void initMessages() { 261 262 addMessages(Messages.get().getBundleName()); 264 addMessages("org.opencms.workplace.workplace"); 266 super.initMessages(); 268 } 269 270 273 protected void initSettingsObject() { 274 275 Object o; 276 277 if (CmsStringUtil.isEmpty(getParamAction())) { 278 o = new CmsVfsImportExportHandler(); 279 } else { 280 o = getDialogObject(); 282 } 283 284 if (!(o instanceof CmsElementChangeLocaleSettings)) { 285 m_settings = new CmsElementChangeLocaleSettings(); 287 } else { 288 m_settings = (CmsElementChangeLocaleSettings)o; 290 } 291 292 } 293 294 297 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 298 299 super.initWorkplaceRequestValues(settings, request); 301 302 setDialogObject(m_settings); 304 } 305 } | Popular Tags |