Skip to content

Commit

Permalink
CLOUDSTACK-9842: Make UI JSP Free
Browse files Browse the repository at this point in the history
We use some JSP file just for translation of strings in the UI. This is
achievable purely in JavaScript. This removes those JSPs, simplifies
translation usage and workflow (purely JS based). The l10n js (dictionary)
files are generated from existing messages.properties files during client-ui
code generation phase.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
  • Loading branch information
rohityadavcloud committed Sep 28, 2016
1 parent 3a82636 commit 16913a9
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 2,632 deletions.
2 changes: 1 addition & 1 deletion client/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
<location>/error.html</location>
</error-page>

</web-app>
26 changes: 26 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<workingDirectory>${basedir}/marvin</workingDirectory>
<executable>python</executable>
<arguments>
<argument>${basedir}/../tools/transifex/gen-l10n.py</argument>
<argument>-i</argument>
<argument>${basedir}/WEB-INF/classes/resources/</argument>
<argument>-o</argument>
<argument>${basedir}/../ui/l10n/</argument>
<echo>Generating JS localization</echo>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ru.concerteza.buildnumber</groupId>
<artifactId>maven-jgit-buildnumber-plugin</artifactId>
Expand Down
1 change: 0 additions & 1 deletion client/tomcatconf/web.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>
1 change: 0 additions & 1 deletion packaging/centos7/tomcat7/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
<cs.jetty.version>9.2.15.v20160210</cs.jetty.version>
<cs.cxf.version>3.1.4</cs.cxf.version>
<cs.groovy.version>2.4.6</cs.groovy.version>
<cs.apache-jsp.version>9.2.15.v20160210</cs.apache-jsp.version>
<cs.nitro.version>10.1</cs.nitro.version>
</properties>

Expand Down Expand Up @@ -222,11 +221,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
<version>${cs.apache-jsp.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
Expand Down Expand Up @@ -876,6 +870,7 @@
<exclude>tools/devcloud/src/deps/boxes/basebox-build/preseed.cfg</exclude>
<exclude>tools/marvin/Marvin.egg-info/*</exclude>
<exclude>ui/css/token-input-facebook.css</exclude>
<exclude>ui/l10n/*</exclude>
<exclude>ui/lib/flot/jquery.colorhelpers.js</exclude>
<exclude>ui/lib/flot/jquery.flot.crosshair.js</exclude>
<exclude>ui/lib/flot/jquery.flot.fillbetween.js</exclude>
Expand Down
6 changes: 0 additions & 6 deletions scripts/installer/windows/client.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
<Fragment>
<DirectoryRef Id="WEBAPPS">
<Directory Id="dir96B1059B78BC5220348BC64D2C915517" Name="client">
<Component Id="cmp6F4C0541A24255F55077C2F2B9EA1716" Guid="{580A1DC7-692A-4C5E-BEFF-859FAEF9A4DD}">
<File Id="filE25D632D05B768505A4E7DD377130748" KeyPath="yes" Source="!(wix.SourceClient)\dictionary.jsp" />
</Component>
<Component Id="cmpA3EAE442A4EFCD423DEDE8C08275003B" Guid="{02C33DD0-F4B0-496B-AA37-EF8D398B3B04}">
<File Id="fil3725B99C98A189665F86E4F12796F408" KeyPath="yes" Source="!(wix.SourceClient)\index.jsp" />
</Component>
<Directory Id="dir1ACEF08E1E39353E790054E32AAB395B" Name="css">
<Component Id="cmp37A6D01A784CC885922881D8CC3D5BB8" Guid="{C7CDB7FC-BBC3-4D16-8841-0ADAAED648DA}">
<File Id="fil057A7F1A7D66E761998D3D3A2F236950" KeyPath="yes" Source="!(wix.SourceClient)\css\cloudstack3-ie7.css" />
Expand Down
10 changes: 0 additions & 10 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${cs.jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>${cs.jstl-api.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
106 changes: 106 additions & 0 deletions tools/transifex/gen-l10n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Usage: python gen-l10n.py <path to message properties file> <output directory>

import codecs
import json
import os
import sys
from optparse import OptionParser


def generateL10nFile(propFile, outputFile):
ts = {}
with open(propFile, 'r') as f:
for line in f.read().split('\n'):
if line.startswith('#') or line.startswith('\n') or line.startswith('\r') or line.strip() == "":
continue
key, _, value = line.partition('=')
if key in ts:
print("[Warning] Found a duplicate translation for key " + key)
value = value.replace('\#', '#') \
.replace('\=', '=') \
.replace('\!', '!') \
.replace('\:', ':') \
.replace('\+', '+') \
.replace('\,', ',') \
.replace('\>', '>') \
.replace('\<', '<') \
.replace('\\>', '>') \
.replace('\\<', '<') \
.replace('\\,', ',') \
.replace('\\ ', ' ') \
.replace('\\+', '+') \
.replace('\\\\', '') \
.decode('unicode-escape')
ts[key] = value

print("Exporting compiled dictionary: %s" % outputFile)
with codecs.open(outputFile, "w", "utf-8") as f:
f.write("// Licensed to the Apache Software Foundation (ASF) under one\n")
f.write("// or more contributor license agreements. See the NOTICE file\n")
f.write("// distributed with this work for additional information\n")
f.write("// regarding copyright ownership. The ASF licenses this file\n")
f.write("// to you under the Apache License, Version 2.0 (the\n")
f.write("// \"License\"); you may not use this file except in compliance\n")
f.write("// with the License. You may obtain a copy of the License at\n")
f.write("//\n")
f.write("// http://www.apache.org/licenses/LICENSE-2.0\n")
f.write("//\n")
f.write("// Unless required by applicable law or agreed to in writing,\n")
f.write("// software distributed under the License is distributed on an\n")
f.write("// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n")
f.write("// KIND, either express or implied. See the License for the\n")
f.write("// specific language governing permissions and limitations\n")
f.write("// under the License.\n")
f.write("var dictionary = ")
f.write(json.dumps(ts, ensure_ascii=False, separators=(',\n', ':',), sort_keys=True))
f.write(";")


def parseFileName(propFileName):
return propFileName.split('messages_')[-1] \
.replace('properties', 'js') \
.replace('messages.js', 'en.js')


def main():
parser = OptionParser()
parser.add_option("-o", "--output", dest="outputDir",
help="The path to the generated l10n js file")

parser.add_option("-i", "--input", dest="inputDir",
help="The path to source messages properties files")

(options, args) = parser.parse_args()
if options.inputDir is None or options.outputDir is None:
print("Please provide messages and l10n output directory paths")
sys.exit(1)

if not os.path.exists(options.outputDir):
os.makedirs(options.outputDir)

for propFile in os.listdir(options.inputDir):
inputFile = "%s/%s" % (options.inputDir, propFile)
outputFile = "%s/%s" % (options.outputDir, parseFileName(propFile))
generateL10nFile(inputFile, outputFile)


if __name__ == "__main__":
main()
Loading

0 comments on commit 16913a9

Please sign in to comment.