1 package org.jahia.admin.languages; 2 3 import java.io.IOException ; 4 import java.util.ArrayList ; 5 import java.util.Enumeration ; 6 import java.util.HashSet ; 7 import java.util.Iterator ; 8 import java.util.Locale ; 9 import java.util.Map ; 10 import java.util.Set ; 11 import java.util.TreeMap ; 12 import java.util.Vector ; 13 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 import javax.servlet.http.HttpSession ; 18 19 import org.jahia.bin.Jahia; 20 import org.jahia.bin.JahiaAdministration; 21 import org.jahia.content.ContentPageKey; 22 import org.jahia.data.JahiaData; 23 import org.jahia.exceptions.JahiaException; 24 import org.jahia.params.ParamBean; 25 import org.jahia.registries.ServicesRegistry; 26 import org.jahia.resourcebundle.JahiaResourceBundle; 27 import org.jahia.services.pages.ContentPage; 28 import org.jahia.services.pages.JahiaPage; 29 import org.jahia.services.pages.JahiaPageService; 30 import org.jahia.services.sites.JahiaSite; 31 import org.jahia.services.sites.JahiaSiteTools; 32 import org.jahia.services.sites.SiteLanguageMapping; 33 import org.jahia.services.sites.SiteLanguageMappingPersistance; 34 import org.jahia.services.sites.SiteLanguageSettings; 35 import org.jahia.services.sites.SiteLanguagesPersistance; 36 import org.jahia.services.usermanager.JahiaUser; 37 import org.jahia.services.version.ActivationTestResults; 38 import org.jahia.services.version.EntryLoadRequest; 39 import org.jahia.services.version.JahiaSaveVersion; 40 import org.jahia.services.version.StateModificationContext; 41 import org.jahia.utils.LanguageCodeConverters; 42 import org.jahia.security.license.License; 43 44 53 54 public class ManageSiteLanguages { 55 56 private static org.apache.log4j.Logger logger = 57 org.apache.log4j.Logger.getLogger(ManageSiteLanguages.class); 58 59 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 60 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 61 62 private static final String MSG_INTERNAL_ERROR = new String ("Jahia Administration internal error"); 63 64 private JahiaSite site; 65 private JahiaUser user; 66 private ServicesRegistry sReg; 67 68 private License coreLicense; 69 70 78 public ManageSiteLanguages ( HttpServletRequest request, 79 HttpServletResponse response, 80 HttpSession session ) 81 throws Throwable 82 { 83 84 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 85 ParamBean jParams = null; 86 if (jData != null) { 87 jParams = jData.params(); 88 } 89 coreLicense = Jahia.getCoreLicense(); 90 if ( coreLicense == null ){ 91 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.invalidLicenseKey.label", 93 jParams, jParams.getLocale()); 94 request.setAttribute("jahiaDisplayMessage", dspMsg); 95 JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); 97 return; 98 } 99 100 userRequestDispatcher( request, response, session ); 101 } 103 104 105 114 private void userRequestDispatcher( HttpServletRequest request, 115 HttpServletResponse response, 116 HttpSession session ) 117 throws Throwable 118 { 119 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 120 ParamBean jParams = null; 121 if (jData != null) { 122 jParams = jData.params(); 123 } 124 125 String operation = request.getParameter("sub"); 126 127 sReg = ServicesRegistry.getInstance(); 128 129 user = (JahiaUser) session.getAttribute( ParamBean.SESSION_USER ); 131 site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 132 133 if ( site != null && user != null && sReg != null){ 134 135 if ( JahiaSiteTools.getAdminGroup(site).isMember(user) ){ 136 137 request.setAttribute( "site", site ); 139 140 if (operation.equals("display")) { 141 displayLanguageList( request, response, session ); 142 } else if (operation.equals("commit")) { 143 commitChanges( request, response, session ); 144 } else if (operation.equals("reallyDelete")) { 145 reallyDelete ( request, response, session ); 146 } else if (operation.equals("displayMappings")) { 147 displayMappings ( request, response, session ); 148 } else if (operation.equals("commitMappings")) { 149 commitMappings ( request, response, session ); 150 } else { 151 displayLanguageList ( request, response, session ); 152 } 153 154 } else { 155 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 157 jParams, jParams.getLocale()); 158 request.setAttribute("jahiaDisplayMessage", dspMsg); 159 JahiaAdministration.doRedirect( request, 160 response, 161 session, JSP_PATH + "menu.jsp" ); 162 } 163 } else { 164 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 165 jParams, jParams.getLocale()); 166 request.setAttribute("jahiaDisplayMessage", dspMsg); 167 JahiaAdministration.doRedirect( request, 168 response, 169 session, JSP_PATH + "menu.jsp" ); 170 } 171 } 173 174 175 private void displayLanguageList( HttpServletRequest request, 177 HttpServletResponse response, 178 HttpSession session ) 179 throws IOException , ServletException 180 { 181 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 182 ParamBean jParams = null; 183 if (jData != null) { 184 jParams = jData.params(); 185 } 186 try { 187 188 Vector siteLangSettings = site.getLanguageSettings(); 189 Vector languageMappings = site.getLanguageMappings(); 190 191 Set languageSet = new HashSet (); 194 Enumeration siteLangSettingsEnum = siteLangSettings.elements(); 195 while (siteLangSettingsEnum.hasMoreElements()) { 196 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLangSettingsEnum.nextElement(); 197 languageSet.add(curSetting.getCode()); 198 } 199 200 ContentPage contentPage = jParams.getSite().getHomeContentPage(); 202 Map langStates = contentPage.getLanguagesStates(false); 203 Set homePageLanguageSet = langStates.keySet(); 204 205 Locale [] availableLocales = Locale.getAvailableLocales(); 206 207 request.setAttribute("mixLanguages", new Boolean (site.isMixLanguagesActive())); 208 request.setAttribute("homePageLanguageSet", homePageLanguageSet); 209 request.setAttribute("languageSet", languageSet); 210 request.setAttribute("languageList", siteLangSettings.elements()); 211 request.setAttribute("mappingList", languageMappings.elements()); 212 213 JahiaAdministration.doRedirect( request, 214 response, 215 session, 216 JSP_PATH + "manage_languages.jsp" ); 217 218 } catch ( JahiaException je ){ 219 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 220 jParams, jParams.getLocale()); 221 request.setAttribute("jahiaDisplayMessage", dspMsg); 222 JahiaAdministration.doRedirect( request, 223 response, 224 session, 225 JSP_PATH + "menu.jsp" ); 226 } 227 228 229 } 230 231 private void displayLanguageDeleteConfirmation( 232 Vector languagesToDelete, 233 HttpServletRequest request, 234 HttpServletResponse response, 235 HttpSession session ) 236 throws IOException , ServletException { 237 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 238 ParamBean jParams = null; 239 if (jData != null) { 240 jParams = jData.params(); 241 } 242 243 try { 244 245 Vector siteLangSettings = site.getLanguageSettings(); 246 Vector languageMappings = site.getLanguageMappings(); 247 248 Set languageSet = new HashSet (); 251 Enumeration siteLangSettingsEnum = siteLangSettings.elements(); 252 while (siteLangSettingsEnum.hasMoreElements()) { 253 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLangSettingsEnum.nextElement(); 254 languageSet.add(curSetting.getCode()); 255 } 256 257 request.setAttribute("languagesToDelete", languagesToDelete); 258 259 Locale [] availableLocales = Locale.getAvailableLocales(); 260 261 JahiaAdministration.doRedirect( request, 262 response, 263 session, 264 JSP_PATH + "manage_languages_delete_confirmation.jsp" ); 265 266 } catch ( JahiaException je ){ 267 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 268 jParams, jParams.getLocale()); 269 request.setAttribute("jahiaDisplayMessage", dspMsg); 270 JahiaAdministration.doRedirect( request, 271 response, 272 session, 273 JSP_PATH + "menu.jsp" ); 274 } 275 276 } 277 278 279 280 281 private void commitChanges( HttpServletRequest request, 283 HttpServletResponse response, 284 HttpSession session ) 285 286 throws IOException , ServletException 287 { 288 289 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 290 ParamBean jParams = null; 291 if (jData != null) { 292 jParams = jData.params(); 293 } 294 295 try { 296 297 SiteLanguagesPersistance langSettingsSrv = SiteLanguagesPersistance.getInstance(); 298 Vector languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 299 300 request.setAttribute("warningMsg",""); 301 302 Map parameterMap = request.getParameterMap(); 305 306 String mixLanguages = request.getParameter("mixLanguages"); 308 if (mixLanguages != null) { 309 logger.debug("Setting language mix for site to active"); 310 site.setMixLanguagesActive(true); 311 } else { 312 logger.debug("Setting language mix for site to disabled"); 313 site.setMixLanguagesActive(false); 314 } 315 316 Enumeration siteLangSettings = site.getLanguageSettings().elements(); 318 Map languageSettingMap = new TreeMap (); 319 while (siteLangSettings.hasMoreElements()) { 320 SiteLanguageSettings curLangSettings = (SiteLanguageSettings) siteLangSettings.nextElement(); 321 String curLangRankStr = request.getParameter("rank_" + curLangSettings.getCode()); 322 int curLangRank = Integer.parseInt(curLangRankStr); 323 logger.debug("Rank " + curLangRank + " : " + curLangSettings.getCode()); 324 languageSettingMap.put(new Integer (curLangRank), curLangSettings); 325 } 326 327 Iterator languageRanks = languageSettingMap.keySet().iterator(); 329 int count = 1; 330 while (languageRanks.hasNext()) { 331 Integer curRank = (Integer ) languageRanks.next(); 332 SiteLanguageSettings curSetting = (SiteLanguageSettings) languageSettingMap.get(curRank); 333 logger.debug("Assigning rank " + count + " to language " + curSetting.getCode() + " using treemap entry " + curRank); 334 curSetting.setRank(count); 335 langSettingsSrv.updateSiteLanguageSettings(curSetting); 336 count++; 337 } 338 339 Vector languagesToDelete = new Vector (); 340 Enumeration siteLangSettingEnum = site.getLanguageSettings().elements(); 342 while (siteLangSettingEnum.hasMoreElements()) { 343 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLangSettingEnum.nextElement(); 344 String activeStr = request.getParameter("active_" + curSetting.getCode()); 345 if (activeStr != null) { 346 curSetting.setActivated(true); 347 } else { 348 curSetting.setActivated(false); 349 } 350 String mandatoryStr = request.getParameter("mandatory_" + curSetting.getCode()); 351 if (mandatoryStr != null) { 352 curSetting.setMandatory(true); 353 } else { 354 curSetting.setMandatory(false); 355 } 356 String deleteStr = request.getParameter("delete_" + curSetting.getCode()); 357 logger.debug("lang " + curSetting.getCode() + 358 " activeStr=[" + activeStr + 359 "] mandatoryStr=[" + mandatoryStr + 360 "] deleteStr=[" + deleteStr + "]"); 361 if (deleteStr != null) { 362 languagesToDelete.add(curSetting); 363 } else { 364 langSettingsSrv.updateSiteLanguageSettings(curSetting); 365 } 366 } 367 368 String [] newLanguages = request.getParameterValues("language_list"); 370 if (newLanguages != null) { 371 if (newLanguages.length > 0) { 372 for (int i=0; i < newLanguages.length; i++) { 373 SiteLanguageSettings newLanguage = 374 new SiteLanguageSettings(site.getID(), newLanguages[i], true, count+i, false); 375 langSettingsSrv.addSiteLanguageSettings(newLanguage); 376 377 Locale newLocale = LanguageCodeConverters.languageCodeToLocale(newLanguages[i]); 379 if (!"".equals(newLocale.getCountry())) { 380 if (!isLanguageCodeInSettings(newLocale.getLanguage(), site.getLanguageSettings())) { 385 if (!isLanguageCodeInFromMapping(newLocale.getLanguage(), languageMappings)) { 386 SiteLanguageMapping newMapping = 387 new SiteLanguageMapping( 388 site.getID(), newLocale.getLanguage(), 389 newLocale.toString()); 390 SiteLanguageMappingPersistance.getInstance().addSiteLanguageMapping(newMapping); 391 languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 392 } 393 } 394 } else { 395 SiteLanguageMapping existingMapping = getLanguageMapping(newLocale.toString(), languageMappings); 399 if (existingMapping != null) { 400 logger.debug("Removing existing mapping : " + 401 existingMapping.getFromLanguageCode() + 402 " -> " + 403 existingMapping.getToLanguageCode()); 404 SiteLanguageMappingPersistance.getInstance().removeSiteLanguageMapping(existingMapping.getId()); 405 languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 406 } 407 } 408 } 409 } 410 } 411 412 416 if (languagesToDelete.size() == 0) { 417 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.changeCommitted.label", 418 jParams, jParams.getLocale()); 419 request.setAttribute("jahiaDisplayMessage", dspMsg); 420 displayLanguageList(request, response, session); 421 } else { 422 session.setAttribute("languagesToDelete", languagesToDelete); 423 displayLanguageDeleteConfirmation(languagesToDelete, request, response, session); 424 } 425 } catch ( JahiaException je ){ 426 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 427 jParams, jParams.getLocale()); 428 request.setAttribute("jahiaDisplayMessage", dspMsg); 429 JahiaAdministration.doRedirect( request, 430 response, 431 session, 432 JSP_PATH + "menu.jsp" ); 433 } 434 435 436 } 438 private boolean isLanguageCodeInSettings(String languageCode, Vector siteLanguageSettings) { 439 Enumeration languagesEnum = siteLanguageSettings.elements(); 440 while (languagesEnum.hasMoreElements()) { 441 SiteLanguageSettings curSetting = (SiteLanguageSettings) languagesEnum.nextElement(); 442 if (curSetting.getCode().equals(languageCode)) { 443 return true; 444 } 445 } 446 return false; 447 } 448 449 private boolean isLanguageCodeInFromMapping(String fromLanguageCode, Vector mappings) { 450 Enumeration mappingEnum = mappings.elements(); 451 while (mappingEnum.hasMoreElements()) { 452 SiteLanguageMapping curMapping = (SiteLanguageMapping) mappingEnum.nextElement(); 453 if (curMapping.getFromLanguageCode().equals(fromLanguageCode)) { 454 return true; 455 } 456 } 457 return false; 458 } 459 460 private SiteLanguageMapping getLanguageMapping(String fromLanguageCode, Vector mappings) { 461 Enumeration mappingEnum = mappings.elements(); 462 while (mappingEnum.hasMoreElements()) { 463 SiteLanguageMapping curMapping = (SiteLanguageMapping) mappingEnum.nextElement(); 464 if (curMapping.getFromLanguageCode().equals(fromLanguageCode)) { 465 return curMapping; 466 } 467 } 468 return null; 469 } 470 471 private SiteLanguageMapping getReverseLanguageMapping(String toLanguageCode, Vector mappings) { 472 Enumeration mappingEnum = mappings.elements(); 473 while (mappingEnum.hasMoreElements()) { 474 SiteLanguageMapping curMapping = (SiteLanguageMapping) mappingEnum.nextElement(); 475 if (curMapping.getToLanguageCode().equals(toLanguageCode)) { 476 return curMapping; 477 } 478 } 479 return null; 480 } 481 482 483 private void reallyDelete ( HttpServletRequest request, 485 HttpServletResponse response, 486 HttpSession session ) 487 throws ServletException , IOException { 488 489 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 490 ParamBean jParams = null; 491 if (jData != null) { 492 jParams = jData.params(); 493 } 494 495 try { 496 497 SiteLanguagesPersistance langSettingsSrv = SiteLanguagesPersistance.getInstance(); 498 JahiaPageService pageSrv = ServicesRegistry.getInstance().getJahiaPageService(); 499 Vector languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 500 502 request.setAttribute("warningMsg",""); 503 504 Vector languagesToDelete = (Vector ) session.getAttribute("languagesToDelete"); 505 506 if (languagesToDelete.size() == 0) { 507 displayLanguageList(request, response, session); 508 } else { 509 510 session.removeAttribute("languagesToDelete"); 511 logger.debug("Really deleting languages..."); 512 JahiaPage siteHomePage = site.getHomePage(); 513 ContentPage siteHomeContentPage = pageSrv.lookupContentPage(siteHomePage.getID(), true); 514 Set languageCodeSet = new HashSet (); 515 Enumeration languagesToDeleteEnum = languagesToDelete.elements(); 516 ArrayList locales = new ArrayList (); 517 while (languagesToDeleteEnum.hasMoreElements()) { 518 SiteLanguageSettings curSetting = (SiteLanguageSettings) languagesToDeleteEnum.nextElement(); 519 locales.add(LanguageCodeConverters.languageCodeToLocale(curSetting.getCode())); 520 languageCodeSet.add(curSetting.getCode()); 521 } 522 523 EntryLoadRequest entryLoadRequest = new EntryLoadRequest( 525 EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, locales, true); 526 jParams.setSubstituteEntryLoadRequest(entryLoadRequest); 527 StateModificationContext stateModifContext = new 528 StateModificationContext(new ContentPageKey( 529 siteHomeContentPage.getID()), languageCodeSet); 530 stateModifContext.setDescendingInSubPages(true); 531 Iterator languageCodeIter = languageCodeSet.iterator(); 532 while (languageCodeIter.hasNext()) { 533 String curLanguageCode = (String ) languageCodeIter.next(); 534 logger.debug("Marking language code [" + curLanguageCode + "] for deletion..."); 535 siteHomeContentPage.markLanguageForDeletion(jParams.getUser(), 536 curLanguageCode, stateModifContext); 537 } 538 539 logger.debug("Now activating site in specified languages, activating the content marked for deletion..."); 540 541 ActivationTestResults activationResults = siteHomeContentPage. 542 activeStagingEntries(languageCodeSet, true, 543 new JahiaSaveVersion(true, true), 544 jParams.getUser(), 545 jParams, stateModifContext); 546 if (activationResults.getStatus() != ActivationTestResults.COMPLETED_OPERATION_STATUS) { 547 logger.debug("Activation results=" + activationResults.toString()); 548 } 549 550 jParams.resetSubstituteEntryLoadRequest(); 551 552 Vector siteLanguageSettings = langSettingsSrv.getSiteLanguages(site.getID()); 555 Enumeration siteLanguageEnum = siteLanguageSettings.elements(); 556 while (siteLanguageEnum.hasMoreElements()) { 557 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLanguageEnum.nextElement(); 558 if (languageCodeSet.contains(curSetting.getCode())) { 559 langSettingsSrv.removeSiteLanguageSettings(curSetting.getID()); 560 SiteLanguageMapping curMapping = getReverseLanguageMapping(curSetting.getCode(), languageMappings); 563 if (curMapping != null) { 564 String fromLanguageCode = curMapping.getFromLanguageCode(); 565 SiteLanguageMappingPersistance.getInstance().removeSiteLanguageMapping(curMapping.getId()); 566 languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 567 } 568 } 569 } 570 rebuildSiteMappings(site); 572 } 573 574 displayLanguageList(request, response, session); 575 } catch ( JahiaException je ){ 576 logger.debug("Exception deleting site language",je); 577 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 578 jParams, jParams.getLocale()); 579 request.setAttribute("jahiaDisplayMessage", dspMsg); 580 JahiaAdministration.doRedirect( request, 581 response, 582 session, 583 JSP_PATH + "menu.jsp" ); 584 } 585 586 } 587 588 private void rebuildSiteMappings (JahiaSite site) throws JahiaException { 589 SiteLanguagesPersistance langSettingsSrv = SiteLanguagesPersistance.getInstance(); 590 Vector languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 591 Vector siteLanguageSettings = langSettingsSrv.getSiteLanguages(site.getID()); 592 Enumeration siteLanguageEnum = siteLanguageSettings.elements(); 593 while (siteLanguageEnum.hasMoreElements()) { 594 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLanguageEnum.nextElement(); 595 Locale curLocale = LanguageCodeConverters.languageCodeToLocale(curSetting.getCode()); 596 if (!"".equals(curLocale.getCountry())) { 597 SiteLanguageMapping curMapping = getLanguageMapping(curLocale.getLanguage(), languageMappings); 598 if (curMapping == null) { 599 SiteLanguageMapping newMapping = 602 new SiteLanguageMapping( 603 site.getID(), curLocale.getLanguage(), 604 curLocale.toString()); 605 SiteLanguageMappingPersistance.getInstance().addSiteLanguageMapping(newMapping); 606 languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 607 } 608 } 609 } 610 } 611 612 private void displayMappings ( HttpServletRequest request, 614 HttpServletResponse response, 615 HttpSession session ) 616 throws ServletException , IOException { 617 618 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 619 ParamBean jParams = null; 620 if (jData != null) { 621 jParams = jData.params(); 622 } 623 624 try { 625 626 Vector siteLangSettings = site.getLanguageSettings(); 627 Vector languageMappings = site.getLanguageMappings(); 628 629 Map iso639ToLocale = new TreeMap (); 630 631 Set languageSet = new HashSet (); 634 Enumeration siteLangSettingsEnum = siteLangSettings.elements(); 635 while (siteLangSettingsEnum.hasMoreElements()) { 636 SiteLanguageSettings curSetting = (SiteLanguageSettings) siteLangSettingsEnum.nextElement(); 637 languageSet.add(curSetting.getCode()); 638 639 Locale curLocale = LanguageCodeConverters.languageCodeToLocale(curSetting.getCode()); 642 if (isLanguageCodeInFromMapping(curLocale.getLanguage(), languageMappings)) { 643 if (!"".equals(curLocale.getCountry())) { 644 if (!iso639ToLocale.containsKey(curLocale.getLanguage())) { 645 iso639ToLocale.put(curLocale.getLanguage(), new Vector ()); 646 } 647 Vector localizedLanguages = (Vector ) iso639ToLocale.get(curLocale.getLanguage()); 648 localizedLanguages.add(curLocale); 649 } 650 } 651 } 652 653 request.setAttribute("languageSet", languageSet); 654 request.setAttribute("languageList", siteLangSettings.elements()); 655 request.setAttribute("languageMappings", languageMappings); 656 request.setAttribute("mappingList", languageMappings.elements()); 657 request.setAttribute("iso639ToLocale", iso639ToLocale); 658 659 Locale [] availableLocales = Locale.getAvailableLocales(); 660 boolean acceptsUTF8 = false; 661 String acceptCharset = request.getHeader("accept-charset"); 662 if (acceptCharset != null) { 663 if (acceptCharset.toLowerCase().indexOf("utf-8") != -1) { 664 acceptsUTF8 = true; 665 } 666 } 667 request.setAttribute("acceptsUTF8", new Boolean (acceptsUTF8)); 668 669 JahiaAdministration.doRedirect( request, 670 response, 671 session, 672 JSP_PATH + "manage_languages_edit_mappings.jsp" ); 673 674 } catch ( JahiaException je ){ 675 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 676 jParams, jParams.getLocale()); 677 request.setAttribute("jahiaDisplayMessage", dspMsg); 678 JahiaAdministration.doRedirect( request, 679 response, 680 session, 681 JSP_PATH + "menu.jsp" ); 682 } 683 } 684 685 private void commitMappings ( HttpServletRequest request, 687 HttpServletResponse response, 688 HttpSession session ) 689 throws ServletException , IOException { 690 691 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 692 ParamBean jParams = null; 693 if (jData != null) { 694 jParams = jData.params(); 695 } 696 try { 697 698 SiteLanguagesPersistance langSettingsSrv = SiteLanguagesPersistance.getInstance(); 699 JahiaPageService pageSrv = ServicesRegistry.getInstance().getJahiaPageService(); 700 Vector languageMappings = SiteLanguageMappingPersistance.getInstance().getSiteLanguageMappings(site.getID()); 701 703 request.setAttribute("warningMsg",""); 704 705 Enumeration mappingsEnum = languageMappings.elements(); 706 while (mappingsEnum.hasMoreElements()) { 707 SiteLanguageMapping curMapping = (SiteLanguageMapping) mappingsEnum.nextElement(); 708 String newMapping = request.getParameter("mapping_" + curMapping.getFromLanguageCode()); 709 if ((newMapping != null) && (!"".equals(newMapping))) { 710 logger.debug("Changing mapping for " + curMapping.getFromLanguageCode() + " to " + newMapping); 711 curMapping.setToLanguageCode(newMapping); 712 SiteLanguageMappingPersistance.getInstance().updateSiteLanguageMapping(curMapping); 713 } 714 } 715 716 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.mappingUpdated.label", 717 jParams, jParams.getLocale()); 718 request.setAttribute("jahiaDisplayMessage", dspMsg); 719 displayMappings(request, response, session); 720 } catch ( JahiaException je ){ 721 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 722 jParams, jParams.getLocale()); 723 request.setAttribute("jahiaDisplayMessage", dspMsg); 724 JahiaAdministration.doRedirect( request, 725 response, 726 session, 727 JSP_PATH + "menu.jsp" ); 728 } 729 730 731 } 732 733 } 734 | Popular Tags |