Skip to content

Commit

Permalink
Improved locale handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
tHerrmann committed Apr 10, 2012
1 parent 130ec3a commit 6434e5f
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 116 deletions.
30 changes: 15 additions & 15 deletions .classpath
Expand Up @@ -73,20 +73,20 @@
<classpathentry exported="true" kind="lib" path="lib/runtime/guava-r08-gwt.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/guava-r08.jar"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="lib" path="lib/runtime/lucene-analyzers-3.5.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/lucene-core-3.5.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/lucene-highlighter-3.5.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/lucene-memory-3.5.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/lucene-queries-3.5.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/commons-beanutils-1.8.3.jar"/>
<classpathentry kind="lib" path="lib/runtime/asm-4.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/ehcache-core-2.4.7.jar"/>
<classpathentry kind="lib" path="lib/runtime/geronimo-validation_1.0_spec-1.1.jar"/>
<classpathentry kind="lib" path="lib/runtime/openjpa-2.2.0.jar"/>
<classpathentry kind="lib" path="lib/runtime/org.apache.bval.bundle-0.3-incubating.jar"/>
<classpathentry kind="lib" path="lib/runtime/slf4j-api-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/runtime/slf4j-jdk14-1.6.1.jar"/>
<classpathentry kind="lib" path="webapp/setup/database/hsqldb/hsqldb-1.8.0.10.jar"/>
<classpathentry exported="true" kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/lucene-analyzers-3.5.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/lucene-core-3.5.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/lucene-highlighter-3.5.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/lucene-memory-3.5.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/lucene-queries-3.5.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/commons-beanutils-1.8.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/asm-4.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/ehcache-core-2.4.7.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/geronimo-validation_1.0_spec-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/openjpa-2.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/org.apache.bval.bundle-0.3-incubating.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/slf4j-api-1.6.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/runtime/slf4j-jdk14-1.6.1.jar"/>
<classpathentry exported="true" kind="lib" path="webapp/setup/database/hsqldb/hsqldb-1.8.0.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
44 changes: 25 additions & 19 deletions src-modules/org/opencms/workplace/tools/content/CmsMergePages.java
Expand Up @@ -424,19 +424,20 @@ private void collectFolder(String sourceMergeFolder, String targetMergefolder, i
Iterator i = folderResources.iterator();
int size = folderResources.size();
// now loop through all resources and check them against those in the target merge folder
m_report.println(Messages.get().container(
Messages.RPT_SCAN_PAGES_IN_FOLDER_BEGIN_2,
sourceMergeFolder,
new Integer(size)), I_CmsReport.FORMAT_HEADLINE);
m_report.println(
Messages.get().container(Messages.RPT_SCAN_PAGES_IN_FOLDER_BEGIN_2, sourceMergeFolder, new Integer(size)),
I_CmsReport.FORMAT_HEADLINE);
int count = 1;
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
String resName = m_cms.getSitePath(res);

m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)), I_CmsReport.FORMAT_NOTE);
m_report.print(
org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)),
I_CmsReport.FORMAT_NOTE);
m_report.println(Messages.get().container(Messages.RPT_PROCESS_1, resName), I_CmsReport.FORMAT_NOTE);

// now analyse the page and calculate the action to do
Expand Down Expand Up @@ -600,10 +601,12 @@ private void mergePages() throws CmsException {
resFolder1Name,
getParamFolder1(),
getParamFolder2());
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)), I_CmsReport.FORMAT_NOTE);
m_report.print(
org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)),
I_CmsReport.FORMAT_NOTE);
m_report.print(Messages.get().container(Messages.RPT_PROCESS_0), I_CmsReport.FORMAT_NOTE);
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
Expand Down Expand Up @@ -639,7 +642,7 @@ private void mergePages() throws CmsException {
I_CmsReport.FORMAT_OK);

// now get all the text elements from the resource in folder 2 which match the the locale of folder 2
Locale loc = new Locale(locale2);
Locale loc = CmsLocaleManager.getLocale(locale2);
List textElements2 = pageFolder2.getNames(loc);
Iterator j = textElements2.iterator();
while (j.hasNext()) {
Expand All @@ -655,8 +658,9 @@ private void mergePages() throws CmsException {
pageFolder1.addValue(textElementName, loc);
}
pageFolder1.setStringValue(m_cms, textElementName, loc, textElement);
m_report.println(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_OK_0), I_CmsReport.FORMAT_OK);
m_report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
}
// the resource in folder 1 now has all text elements in both locales, so update it in the vfs

Expand Down Expand Up @@ -753,10 +757,12 @@ private void reportList(List collected, boolean doReport) {
Iterator i = collected.iterator();
while (i.hasNext()) {
String resName = (String)i.next();
m_report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)), I_CmsReport.FORMAT_NOTE);
m_report.print(
org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(count++),
String.valueOf(size)),
I_CmsReport.FORMAT_NOTE);
m_report.println(Messages.get().container(Messages.RPT_PROCESS_1, resName), I_CmsReport.FORMAT_NOTE);
}
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
Expand Down Expand Up @@ -228,7 +229,7 @@ public String getShortName() {
public void init(CmsObject cms) {

m_cms = cms;
m_locale = new Locale("en");
m_locale = CmsLocaleManager.getLocale("en");
}

/**
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.opencms.file.types.CmsResourceTypePointer;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.importexport.CmsImportExportException;
import org.opencms.loader.CmsLoaderException;
Expand Down Expand Up @@ -1127,7 +1128,7 @@ private void createFile(String filename, int position, String content, Hashtable
}

// create new XML page
Locale locale = new Locale(m_locale);
Locale locale = CmsLocaleManager.getLocale(m_locale);
CmsXmlPage page = new CmsXmlPage(locale, OpenCms.getSystemInfo().getDefaultEncoding());
page.addValue(m_element, locale);
page.setStringValue(m_cmsObject, m_element, locale, content);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsVfsResourceNotFoundException;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.CmsRuntimeException;
Expand Down Expand Up @@ -62,7 +63,7 @@
public class CmsConfigurationReader {

/** The default locale for configuration objects. */
public static final Locale DEFAULT_LOCALE = new Locale("en");
public static final Locale DEFAULT_LOCALE = CmsLocaleManager.getLocale("en");

/** The folder name node name. */
public static final String N_FOLDER_NAME = "Name";
Expand Down
35 changes: 19 additions & 16 deletions src/org/opencms/ade/containerpage/CmsContainerpageService.java
Expand Up @@ -48,6 +48,7 @@
import org.opencms.gwt.CmsGwtService;
import org.opencms.gwt.CmsRpcException;
import org.opencms.gwt.shared.CmsModelResourceInfo;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsLog;
Expand Down Expand Up @@ -171,7 +172,10 @@ public CmsCreateElementData checkCreateNewElement(
if (modelResources.isEmpty()) {
result.setCreatedElement(createNewElement(pageStructureId, clientId, resourceType, null, locale));
} else {
result.setModelResources(generateModelResourceList(resourceType, modelResources, new Locale(locale)));
result.setModelResources(generateModelResourceList(
resourceType,
modelResources,
CmsLocaleManager.getLocale(locale)));
}
} catch (CmsException e) {
error(e);
Expand Down Expand Up @@ -226,7 +230,7 @@ public CmsContainerElement createNewElement(
CmsADEConfigData configData = OpenCms.getADEManager().lookupConfiguration(cms, pageResource.getRootPath());
CmsResourceTypeConfig typeConfig = configData.getResourceType(resourceType);
CmsObject cloneCms = OpenCms.initCmsObject(cms);
cloneCms.getRequestContext().setLocale(new Locale(locale));
cloneCms.getRequestContext().setLocale(CmsLocaleManager.getLocale(locale));
CmsResource modelResource = null;
if (modelResourceStructureId != null) {
modelResource = cms.readResource(modelResourceStructureId);
Expand Down Expand Up @@ -265,7 +269,7 @@ public Map<String, CmsContainerElementData> getElementsData(
ensureSession();
CmsResource pageResource = getCmsObject().readResource(pageStructureId);
String containerpageUri = getCmsObject().getSitePath(pageResource);
result = getElements(clientIds, containerpageUri, containers, new Locale(locale));
result = getElements(clientIds, containerpageUri, containers, CmsLocaleManager.getLocale(locale));
} catch (Throwable e) {
error(e);
}
Expand Down Expand Up @@ -294,11 +298,11 @@ public CmsContainerElementData getElementWithSettings(
containerpageUri,
getRequest(),
getResponse(),
new Locale(locale));
CmsLocaleManager.getLocale(locale));
CmsContainerElementBean elementBean = getCachedElement(clientId);
elementBean = CmsContainerElementBean.cloneWithSettings(elementBean, convertSettingValues(
elementBean.getResource(),
settings));
elementBean = CmsContainerElementBean.cloneWithSettings(
elementBean,
convertSettingValues(elementBean.getResource(), settings));
getSessionCache().setCacheContainerElement(elementBean.editorHash(), elementBean);
element = elemUtil.getElementData(elementBean, containers);
} catch (Throwable e) {
Expand All @@ -324,7 +328,7 @@ public List<CmsContainerElementData> getFavoriteList(
OpenCms.getADEManager().getFavoriteList(getCmsObject()),
containerpageUri,
containers,
new Locale(locale));
CmsLocaleManager.getLocale(locale));
} catch (Throwable e) {
error(e);
}
Expand All @@ -346,7 +350,7 @@ public CmsContainerElementData getNewElementData(
ensureSession();
CmsResource pageResource = getCmsObject().readResource(pageStructureId);
String containerpageUri = getCmsObject().getSitePath(pageResource);
Locale locale = new Locale(localeName);
Locale locale = CmsLocaleManager.getLocale(localeName);
result = getNewElement(resourceType, containerpageUri, containers, locale);
} catch (Throwable e) {
error(e);
Expand All @@ -371,7 +375,7 @@ public List<CmsContainerElementData> getRecentList(
OpenCms.getADEManager().getRecentList(getCmsObject()),
containerpageUri,
containers,
new Locale(locale));
CmsLocaleManager.getLocale(locale));
} catch (Throwable e) {
error(e);
}
Expand Down Expand Up @@ -418,7 +422,7 @@ public void saveContainerpage(CmsUUID pageStructureId, List<CmsContainer> contai
ensureSession();
CmsResource containerpage = cms.readResource(pageStructureId);
String containerpageUri = cms.getSitePath(containerpage);
Locale contentLocale = new Locale(locale);
Locale contentLocale = CmsLocaleManager.getLocale(locale);
List<CmsContainerBean> containerBeans = new ArrayList<CmsContainerBean>();
for (CmsContainer container : containers) {
CmsContainerBean containerBean = getContainerBean(container, containerpage, locale);
Expand Down Expand Up @@ -509,10 +513,9 @@ private Map<String, String> convertSettingValues(CmsResource resource, Map<Strin
for (Map.Entry<String, String> entry : settings.entrySet()) {
String settingName = entry.getKey();
String settingType = settingsConf.get(settingName).getType();
changedSettings.put(settingName, CmsXmlContentPropertyHelper.getPropValueIds(
getCmsObject(),
settingType,
entry.getValue()));
changedSettings.put(
settingName,
CmsXmlContentPropertyHelper.getPropValueIds(getCmsObject(), settingType, entry.getValue()));
}
}
return changedSettings;
Expand Down Expand Up @@ -987,7 +990,7 @@ private CmsContainerElement internalSaveGroupContainer(
cms.lockResourceTemporary(groupContainerResource);
CmsFile groupContainerFile = cms.readFile(groupContainerResource);
CmsXmlGroupContainer xmlGroupContainer = CmsXmlGroupContainerFactory.unmarshal(cms, groupContainerFile);
xmlGroupContainer.save(cms, groupContainerBean, new Locale(locale));
xmlGroupContainer.save(cms, groupContainerBean, CmsLocaleManager.getLocale(locale));
cms.unlockResource(groupContainerResource);

CmsContainerElement element = new CmsContainerElement();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.main.CmsException;
import org.opencms.util.CmsUUID;
import org.opencms.xml.I_CmsXmlDocument;
Expand Down Expand Up @@ -180,7 +181,7 @@ private void writeDetailPageInfos(List<CmsDetailPageInfo> infos, CmsUUID newId)
*/
private void writeValue(String type, CmsUUID id, int index) {

Locale locale = new Locale("en");
Locale locale = CmsLocaleManager.getLocale("en");
// todo: check actual locale.
m_document.addValue(m_cms, N_DETAIL_PAGE, locale, index);
String typePath = N_DETAIL_PAGE + "[" + (1 + index) + "]/" + N_TYPE;
Expand Down
3 changes: 2 additions & 1 deletion src/org/opencms/ade/galleries/CmsPreviewService.java
Expand Up @@ -39,6 +39,7 @@
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.gwt.CmsGwtService;
import org.opencms.gwt.CmsRpcException;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.util.CmsJspStandardContextBean;
import org.opencms.loader.CmsImageScaler;
import org.opencms.loader.CmsTemplateLoaderFacade;
Expand Down Expand Up @@ -178,7 +179,7 @@ public void readResourceInfo(CmsObject cms, CmsResource resource, CmsResourceInf
}
}
resInfo.setProperties(props);
resInfo.setPreviewContent(getPreviewContent(cms, resource, new Locale(locale)));
resInfo.setPreviewContent(getPreviewContent(cms, resource, CmsLocaleManager.getLocale(locale)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/org/opencms/db/CmsDriverManager.java
Expand Up @@ -6165,7 +6165,7 @@ public String readBestUrlName(CmsDbContext dbc, CmsUUID id, Locale locale, List<
CmsLocaleManager localeManager = OpenCms.getLocaleManager();
List<Locale> availableLocales = new ArrayList<Locale>();
for (CmsUrlNameMappingEntry entry : lastEntries) {
availableLocales.add(new Locale(entry.getLocale()));
availableLocales.add(CmsLocaleManager.getLocale(entry.getLocale()));
}
Locale bestLocale = localeManager.getBestMatchingLocale(locale, defaultLocales, availableLocales);
String bestLocaleStr = bestLocale.getLanguage();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.opencms.db.CmsSecurityManager;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.i18n.CmsLocaleManager;

import java.util.List;
import java.util.Locale;
Expand All @@ -51,7 +52,7 @@ protected Locale getLocaleForNewContent(
String resourcename,
List<CmsProperty> properties) {

return new Locale("en");
return CmsLocaleManager.getLocale("en");
}

}

0 comments on commit 6434e5f

Please sign in to comment.