From 16913a982253a5b658ca8ee7a0c8939f13505d45 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Tue, 30 Aug 2016 15:55:00 +0530 Subject: [PATCH] CLOUDSTACK-9842: Make UI JSP Free 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 --- client/WEB-INF/web.xml | 2 +- client/pom.xml | 26 + client/tomcatconf/web.xml.in | 1 - packaging/centos7/tomcat7/web.xml | 1 - pom.xml | 7 +- scripts/installer/windows/client.wxs | 6 - server/pom.xml | 10 - tools/transifex/gen-l10n.py | 106 +++ ui/dictionary.jsp | 1158 -------------------------- ui/dictionary2.jsp | 1131 ------------------------- ui/{error.jsp => error.html} | 4 +- ui/{index.jsp => index.html} | 675 ++++++++------- 12 files changed, 495 insertions(+), 2632 deletions(-) create mode 100644 tools/transifex/gen-l10n.py delete mode 100644 ui/dictionary.jsp delete mode 100644 ui/dictionary2.jsp rename ui/{error.jsp => error.html} (99%) rename ui/{index.jsp => index.html} (74%) diff --git a/client/WEB-INF/web.xml b/client/WEB-INF/web.xml index a384f064794..73a755b501f 100644 --- a/client/WEB-INF/web.xml +++ b/client/WEB-INF/web.xml @@ -80,7 +80,7 @@ java.lang.Exception - /error.jsp + /error.html diff --git a/client/pom.xml b/client/pom.xml index f6d6fdce309..5787717be2e 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -390,6 +390,32 @@ + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + generate-sources + generate-sources + + exec + + + ${basedir}/marvin + python + + ${basedir}/../tools/transifex/gen-l10n.py + -i + ${basedir}/WEB-INF/classes/resources/ + -o + ${basedir}/../ui/l10n/ + Generating JS localization + + + + + ru.concerteza.buildnumber maven-jgit-buildnumber-plugin diff --git a/client/tomcatconf/web.xml.in b/client/tomcatconf/web.xml.in index 44b6eab07fe..8645a64da42 100644 --- a/client/tomcatconf/web.xml.in +++ b/client/tomcatconf/web.xml.in @@ -1182,7 +1182,6 @@ index.html index.htm - index.jsp diff --git a/packaging/centos7/tomcat7/web.xml b/packaging/centos7/tomcat7/web.xml index 44b6eab07fe..8645a64da42 100644 --- a/packaging/centos7/tomcat7/web.xml +++ b/packaging/centos7/tomcat7/web.xml @@ -1182,7 +1182,6 @@ index.html index.htm - index.jsp diff --git a/pom.xml b/pom.xml index e68191134e2..d0fbbd52d7f 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,6 @@ 9.2.15.v20160210 3.1.4 2.4.6 - 9.2.15.v20160210 10.1 @@ -222,11 +221,6 @@ - - org.eclipse.jetty - apache-jsp - ${cs.apache-jsp.version} - org.codehaus.groovy groovy-all @@ -876,6 +870,7 @@ tools/devcloud/src/deps/boxes/basebox-build/preseed.cfg tools/marvin/Marvin.egg-info/* ui/css/token-input-facebook.css + ui/l10n/* ui/lib/flot/jquery.colorhelpers.js ui/lib/flot/jquery.flot.crosshair.js ui/lib/flot/jquery.flot.fillbetween.js diff --git a/scripts/installer/windows/client.wxs b/scripts/installer/windows/client.wxs index f5aec48bde4..91b15fbd950 100644 --- a/scripts/installer/windows/client.wxs +++ b/scripts/installer/windows/client.wxs @@ -12,12 +12,6 @@ - - - - - - diff --git a/server/pom.xml b/server/pom.xml index ae3b7387f46..e379fc61f0c 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -69,16 +69,6 @@ javax.mail mail - - jstl - jstl - ${cs.jstl.version} - - - javax.servlet.jsp.jstl - javax.servlet.jsp.jstl-api - ${cs.jstl-api.version} - commons-codec commons-codec diff --git a/tools/transifex/gen-l10n.py b/tools/transifex/gen-l10n.py new file mode 100644 index 00000000000..0f1616bea3f --- /dev/null +++ b/tools/transifex/gen-l10n.py @@ -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 + +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() diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp deleted file mode 100644 index c15dae2ebdf..00000000000 --- a/ui/dictionary.jsp +++ /dev/null @@ -1,1158 +0,0 @@ -<%-- -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. ---%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> - - - - - -<%-- -**** -NOTE -**** - -Please use dictionary2.jsp for all new mappings. This is due to -file size constraints for JSP files. - -If you add anything else to this file, an error might occur at runtime! ---%> - -<% long now = System.currentTimeMillis(); %> - diff --git a/ui/dictionary2.jsp b/ui/dictionary2.jsp deleted file mode 100644 index f919b156d72..00000000000 --- a/ui/dictionary2.jsp +++ /dev/null @@ -1,1131 +0,0 @@ -<%-- -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. ---%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> - - - - -<% long now = System.currentTimeMillis(); %> - diff --git a/ui/error.jsp b/ui/error.html similarity index 99% rename from ui/error.jsp rename to ui/error.html index 9fecfb730c7..130fa6ed457 100644 --- a/ui/error.jsp +++ b/ui/error.html @@ -1,4 +1,4 @@ -<%-- + diff --git a/ui/index.jsp b/ui/index.html similarity index 74% rename from ui/index.jsp rename to ui/index.html index 34f6310f9c9..9402153937a 100644 --- a/ui/index.jsp +++ b/ui/index.html @@ -1,5 +1,4 @@ - -<%-- + @@ -34,13 +26,10 @@ - - - - + @@ -54,52 +43,35 @@
- +
- +
- +
- " /> +
- - - - - - - - - - - - - - - - -
@@ -109,14 +81,14 @@
    -
  • 1
  • -
  • 2
  • -
  • 3
  • -
  • 4
  • -
  • 5
  • -
  • 6
  • -
  • 7
  • -
  • 8
  • +
  • 1
  • +
  • 2
  • +
  • 3
  • +
  • 4
  • +
  • 5
  • +
  • 6
  • +
  • 7
  • +
  • 8
@@ -126,26 +98,25 @@
-

-

+

+

-

+

-
+
- +
-
+
@@ -157,14 +128,14 @@
-

+

    -
  • -
  • -
  • -
  • +
  • +
  • +
  • +
@@ -189,7 +160,7 @@
- +
@@ -198,14 +169,14 @@
-

+

    -
  • -
  • -
  • -
  • +
  • +
  • +
  • +