Skip to content

Commit

Permalink
Changed workplace localization to read optional languages from JARs and
Browse files Browse the repository at this point in the history
abandon the use of VFS resources.
  • Loading branch information
tHerrmann committed Mar 29, 2017
1 parent 476202e commit 7404304
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 62 deletions.
43 changes: 35 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ jar {
attributes 'Implementation-Title': 'Alkacon OpenCms',
'Implementation-Version': version,
'JPA-PersistenceUnits': 'DATA_OPENJPA,DATA_OPENJPA_JTA',
'Meta-Persistence': 'META-INF/persistence.xml'
'Meta-Persistence': 'META-INF/persistence.xml',
'OpenCms-Localization': 'en'
}
baseName 'opencms-core'
archiveName 'opencms.jar'
Expand Down Expand Up @@ -544,6 +545,7 @@ task sourcesJarSetup(type: Jar) {
}

def preserveLibModules = ''
def localeModules = ''

// iterate all available modules and create the required tasks
allModuleNames.split(',').each{ moduleName ->
Expand All @@ -569,6 +571,7 @@ allModuleNames.split(',').each{ moduleName ->
}
def propertyFile = file("${moduleFolder}/module.properties")
def gwtRename = null
def workplacelocalization=null;
if (propertyFile.exists()){
Properties moduleProperties= new Properties()
moduleProperties.load(new FileInputStream(propertyFile))
Expand All @@ -583,6 +586,9 @@ allModuleNames.split(',').each{ moduleName ->
gwtRename=gwtModule
}
}
if (moduleProperties['workplacelocalization']!=null){
workplacelocalization=moduleProperties['workplacelocalization']
}
}
def manifestFile = file("${moduleFolder}/resources/manifest.xml")
def moduleDependencies=[]
Expand All @@ -595,7 +601,7 @@ allModuleNames.split(',').each{ moduleName ->
moduleVersion = parsedManifest.module[0].version[0].text()
}
def staticFolder=file("${moduleFolder}/static")
def requiresJar = gwtModule!=null || staticFolder.exists()
def requiresJar = gwtModule!=null || staticFolder.exists() || workplacelocalization!=null
if (!requiresJar){
// check if there are any java packages to include into the module's jar
modulePackages.split(',').each{ pack ->
Expand All @@ -614,6 +620,9 @@ allModuleNames.split(',').each{ moduleName ->
if (requiresJar){
preserveLibModules += "${moduleName},"
}
if (workplacelocalization!=null){
localeModules += "${moduleName},"
}

task "dist_$moduleName" (type: Zip){
ext.moduleName = moduleName
Expand Down Expand Up @@ -682,8 +691,12 @@ allModuleNames.split(',').each{ moduleName ->
task "jar_$moduleName" (type: Jar) {
ext.gwtModule = gwtModule
ext.moduleName = moduleName
ext.workplacelocalization=workplacelocalization
manifest {
attributes 'Implementation-Title': 'Alkacon OpenCms', 'Implementation-Version': version
if (workplacelocalization!=null) {
attributes 'OpenCms-Localization': workplacelocalization
}
}
from sourceSets[moduleName].output
from ("$moduleFolder") { include "META-INF/**" }
Expand All @@ -694,6 +707,9 @@ allModuleNames.split(',').each{ moduleName ->
into "OPENCMS/gwt"
}
}
if (workplacelocalization!=null) {
from ("$moduleFolder/resources/system/workplace/locales/$workplacelocalization/messages")
}
archiveName moduleName+'.jar'
baseName moduleName
exclude '**/.gitignore'
Expand Down Expand Up @@ -847,6 +863,7 @@ task war (dependsOn: [setupJar, widgetSetJar, allModules], type: Zip){
archiveName 'opencms.war'
baseName 'opencms-webapp'
extension 'war'
ext.localeModules=localeModules;

from ("${projectDir}/webapp"){
// exclude the database drivers
Expand Down Expand Up @@ -912,7 +929,12 @@ task war (dependsOn: [setupJar, widgetSetJar, allModules], type: Zip){
from (driverJar.path) { into '/WEB-INF/lib' }
}

from (modulesDistsDir) { into '/WEB-INF/packages/modules' }
from (modulesDistsDir) {
into '/WEB-INF/packages/modules'
localeModules.split(',').each{ localeModule ->
exclude "$localeModule-*.zip"
}
}

from("${projectDir}/lib/jni") { into "/WEB-INF/lib/jni" }
}
Expand Down Expand Up @@ -993,12 +1015,17 @@ task updater (dependsOn: [setupJar, widgetSetJar, allModules], type: Zip){
into '/WEB-INF/lib'
}
into ('/WEB-INF/lib') { from configurations.distribution }
tasks.findAll{dist_task -> dist_task.name.startsWith('dist_') && !(updater_excluded_modules.split(',').contains(dist_task.moduleName))}.each{ dist_task ->
from ("${modulesDistsDir}/${dist_task.archiveName}"){ into '/update/modules' }
if (dist_task.requiresJar.toBoolean()){
from ("${project.buildDir}/libs/${dist_task.moduleName}.jar"){ into 'WEB-INF/lib' }
}

from (modulesDistsDir) {
into '/WEB-INF/packages/modules'
localeModules.split(',').each{ localeModule ->
exclude "$localeModule-*.zip"
}
updater_excluded_modules.split(',').each{ localeModule ->
exclude "$localeModule-*.zip"
}
}

fileTree('webapp/setup/database'){ include '**/*.jar'}.each {File driverJar ->
// copy the database drivers into the lib folder
from (driverJar.path) { into '/WEB-INF/lib' }
Expand Down
1 change: 1 addition & 0 deletions modules/org.opencms.locale.cs/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=cs
1 change: 1 addition & 0 deletions modules/org.opencms.locale.da/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=da
1 change: 1 addition & 0 deletions modules/org.opencms.locale.de/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=de
1 change: 1 addition & 0 deletions modules/org.opencms.locale.es/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=es
1 change: 1 addition & 0 deletions modules/org.opencms.locale.it/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=it
1 change: 1 addition & 0 deletions modules/org.opencms.locale.ja/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=ja
1 change: 1 addition & 0 deletions modules/org.opencms.locale.ru/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=ru
1 change: 1 addition & 0 deletions modules/org.opencms.locale.zh/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workplacelocalization=zh
35 changes: 0 additions & 35 deletions modules/org.opencms.workplace/resources/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ chacc '/system/workplace/views/' 'ROLE' 'WORKPLACE_USER' '+I+O+R+V'
<resource uri="/system/workplace/commons/style/"/>
<resource uri="/system/workplace/commons/template/"/>
<resource uri="/system/workplace/galleries/"/>
<resource uri="/system/workplace/locales/de/readme.txt"/>
<resource uri="/system/workplace/resources/buttons/apply.png"/>
<resource uri="/system/workplace/resources/buttons/apply_in.png"/>
<resource uri="/system/workplace/resources/buttons/calendar.png"/>
Expand Down Expand Up @@ -4189,40 +4188,6 @@ chacc '/system/workplace/views/' 'ROLE' 'WORKPLACE_USER' '+I+O+R+V'
<type>folder</type>
<properties/>
</file>
<file>
<destination>system/workplace/locales/de</destination>
<type>folder</type>
<properties/>
</file>
<file>
<source>system/workplace/locales/de/readme.txt</source>
<destination>system/workplace/locales/de/readme.txt</destination>
<type>plain</type>
<uuidstructure>82ba5b6b-11b7-11db-91cd-fdbae480bac9</uuidstructure>
<uuidresource>20f0cab2-c0f9-11d7-8d80-80884c2772a5</uuidresource>
<datecreated>Mon, 27 Jun 2005 08:00:00 GMT</datecreated>
<flags>0</flags>
<properties/>
<relations/>
<accesscontrol/>
</file>
<file>
<destination>system/workplace/locales/en</destination>
<type>folder</type>
<properties/>
</file>
<file>
<source>system/workplace/locales/en/readme.txt</source>
<destination>system/workplace/locales/en/readme.txt</destination>
<type>plain</type>
<uuidstructure>82bf165f-11b7-11db-91cd-fdbae480bac9</uuidstructure>
<uuidresource>20fefb8d-c0f9-11d7-8d80-80884c2772a5</uuidresource>
<datecreated>Mon, 27 Jun 2005 08:00:00 GMT</datecreated>
<flags>0</flags>
<properties/>
<relations/>
<accesscontrol/>
</file>
<file>
<destination>system/workplace/resources/buttons</destination>
<type>folder</type>
Expand Down
8 changes: 8 additions & 0 deletions src-setup/org/opencms/setup/CmsUpdateBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public class CmsUpdateBean extends CmsSetupBean {
"org.opencms.ade.publish",
"org.opencms.ade.sitemap",
"org.opencms.ade.upload",
"org.opencms.locale.cs",
"org.opencms.locale.da",
"org.opencms.locale.de",
"org.opencms.locale.es",
"org.opencms.locale.it",
"org.opencms.locale.ja",
"org.opencms.locale.ru",
"org.opencms.locale.zh",
"org.opencms.workplace.help.de",
"org.opencms.workplace.help.en",
"org.opencms.workplace.help"};
Expand Down
81 changes: 62 additions & 19 deletions src/org/opencms/workplace/CmsWorkplaceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
import org.opencms.workplace.galleries.A_CmsAjaxGallery;
import org.opencms.workplace.tools.CmsToolManager;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -99,6 +102,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -168,6 +172,12 @@ public String getViewForType(String type) {
/** The default encoding for the workplace (UTF-8). */
public static final String DEFAULT_WORKPLACE_ENCODING = CmsEncoder.ENCODING_UTF_8;

/** The workplace localization manifest attribute name. */
public static final String LOCALIZATION_ATTRIBUTE_NAME = "OpenCms-Localization";

/** The manifest file resource name. */
public static final String MANIFEST_RESOURCE_NAME = "META-INF/MANIFEST.MF";

/** The id of the "requestedResource" parameter for the OpenCms login form. */
public static final String PARAM_LOGIN_REQUESTED_RESOURCE = "requestedResource";

Expand Down Expand Up @@ -2422,26 +2432,59 @@ private void initMenuRules() {
private List<Locale> initWorkplaceLocales(CmsObject cms) {

Set<Locale> locales = new HashSet<Locale>();
List<CmsResource> localeFolders;
try {
localeFolders = cms.getSubFolders(CmsWorkplace.VFS_PATH_LOCALES);
} catch (CmsException e) {
LOG.error(
Messages.get().getBundle().key(Messages.LOG_WORKPLACE_INIT_NO_LOCALES_1, CmsWorkplace.VFS_PATH_LOCALES),
e);
// can not throw exception here since then OpenCms would not even start in shell mode (runlevel 2)
localeFolders = new ArrayList<CmsResource>();

// collect locales from the VFS
if (cms.existsResource(CmsWorkplace.VFS_PATH_LOCALES)) {
List<CmsResource> localeFolders;
try {
localeFolders = cms.getSubFolders(CmsWorkplace.VFS_PATH_LOCALES);
} catch (CmsException e) {
LOG.warn(
Messages.get().getBundle().key(
Messages.LOG_WORKPLACE_INIT_NO_LOCALES_1,
CmsWorkplace.VFS_PATH_LOCALES),
e);
// can not throw exception here since then OpenCms would not even start in shell mode (runlevel 2)
localeFolders = new ArrayList<CmsResource>();
}
Iterator<CmsResource> i = localeFolders.iterator();
while (i.hasNext()) {
CmsFolder folder = (CmsFolder)i.next();
Locale locale = CmsLocaleManager.getLocale(folder.getName());
// add locale
locales.add(locale);
// add less specialized locale
locales.add(new Locale(locale.getLanguage(), locale.getCountry()));
// add even less specialized locale
locales.add(new Locale(locale.getLanguage()));
}
}
Iterator<CmsResource> i = localeFolders.iterator();
while (i.hasNext()) {
CmsFolder folder = (CmsFolder)i.next();
Locale locale = CmsLocaleManager.getLocale(folder.getName());
// add locale
locales.add(locale);
// add less specialized locale
locales.add(new Locale(locale.getLanguage(), locale.getCountry()));
// add even less specialized locale
locales.add(new Locale(locale.getLanguage()));
// collect locales from JAR manifests
try {
Enumeration<URL> resources = getClass().getClassLoader().getResources(MANIFEST_RESOURCE_NAME);

while (resources.hasMoreElements()) {
URL resUrl = resources.nextElement();
try {
Manifest manifest = new Manifest(resUrl.openStream());
String localeString = manifest.getMainAttributes().getValue(LOCALIZATION_ATTRIBUTE_NAME);
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(localeString)) {
Locale locale = CmsLocaleManager.getLocale(localeString);
// add locale
locales.add(locale);
// add less specialized locale
locales.add(new Locale(locale.getLanguage(), locale.getCountry()));
// add even less specialized locale
locales.add(new Locale(locale.getLanguage()));
}
} catch (IOException e) {
LOG.warn(
"Error reading manifest from " + resUrl + " while evaluating available workplace localization.",
e);
}
}
} catch (IOException e) {
LOG.error("Error evaluating available workplace localization from JAR manifests.", e);
}

// sort the result
Expand Down

0 comments on commit 7404304

Please sign in to comment.