From d625185aa7c59c1d836da22f23ac4446f88e08aa Mon Sep 17 00:00:00 2001 From: James Chu Date: Fri, 6 Oct 2023 09:54:21 +0800 Subject: [PATCH] remove registry --- bin/genmd5sign | 99 ----------- bin/md5java | 102 ----------- build | 17 +- build.target.xml | 24 +-- build.xml | 6 - .../org/zkoss/zhtml/impl/PageRenderer.java | 13 -- zk/format | 4 +- zk/src/org/zkoss/zk/ui/http/SimpleWebApp.java | 4 - zk/src/org/zkoss/zk/ui/http/WebManager.java | 4 - zk/src/org/zkoss/zk/ui/sys/ConfigParser.java | 23 --- zk/src/org/zkoss/zk/ui/sys/Registry.java | 163 ------------------ zul/src/org/zkoss/zul/impl/PageRenderer.java | 4 - 12 files changed, 3 insertions(+), 460 deletions(-) delete mode 100644 bin/genmd5sign delete mode 100644 bin/md5java delete mode 100644 zk/src/org/zkoss/zk/ui/sys/Registry.java diff --git a/bin/genmd5sign b/bin/genmd5sign deleted file mode 100644 index a0504e3e6e6..00000000000 --- a/bin/genmd5sign +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -# genmd5sign -# -# Purpose: -# -# Description: -# -# History: -# Wed Feb 24 17:46:58 CST 2016, Created by jumperchen -# -#Copyright (C) 2016 Potix Corporation. All Rights Reserved. -# -function showhelp -{ - echo "genmd5sign - generate the file md5 from the signclasses" - echo "Copyright (C) 2016 Potix Corporation. All Rights Reserved." - echo - echo "Usage:" - echo " genmd5sign [-h] [dstfl] [classes] [classpath] [build stamp path] [maindir]" - echo - echo "dstfl" - echo " The destination file, if exists, it will be removed first" - echo - echo "classes" - echo " The list of the classes to be output to stdout with md5 format, each of classes is sepecated by a comma ','" - echo " For example," - echo " foo.bar,foo.bar1,foo.bar2" - echo - echo "classpath" - echo " A directory where to put those classes." - echo - echo "build stamp path" - echo " A file path where to output the zk build stamp" - echo - echo "maindir" - echo " The ZK source directory" -} - -if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then - showhelp - exit 0 -fi -os="$(uname)" - -dstfl=$1 -classes=$2 -debugdir=$3 -build=$4 -maindir=$5 - -mkdir -p "${dstfl%/*}" - -if [ -f $build ] ; then - build=$(cat $build) -elif [ -f $maindir/zk/format ] ; then - build=$(grep '^time=' $maindir/zk/format) - build=${build#time=} - - if [ -f $maindir/zk/codegen/$build ] ; then - build=$(cat $maindir/zk/codegen/$build) - else - echo "the build stamp path is not specified!" - exit -1 - fi -else - echo "the build stamp path is not specified!" - exit -1 -fi - -if [ -f $dstfl ] ; then - rm $dstfl -fi -echo $maindir - -function md5java { - local src="$1" - if [ "$TERM" = "cygwin" ] || [ "$OSTYPE" = "cygwin" ] ; then - # need to parse with cygpath for correct path on cygwin/windows - # also need semi-colon instead of colon for java classpath - java -cp "$maindir/dist/lib/ext/commons-codec.jar;$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $(cygpath -mp $maindir/bin/md5java) $src - elif [ "$OSTYPE" = "msys" ] ; then - # MinGW, git-bash - java -cp "$maindir/dist/lib/ext/commons-codec.jar;$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $maindir/bin/md5java $src - else - java -cp "$maindir/dist/lib/ext/commons-codec.jar:$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $maindir/bin/md5java $src - fi -} - -export IFS="," -echo "Generate md5 sign" -for cls in $classes; do - echo "class => $cls" - clsdir=$(echo $cls | sed 's/\./\//g') - filemd5=`md5java "$debugdir/$clsdir.class"` - filemd5=`md5java "$filemd5$build"` - name=`md5java "$cls"` - # remove line break at the end for windows/cygwin compatility - echo "$(echo $name | tr -d '\r')=$filemd5" >> $dstfl -done diff --git a/bin/md5java b/bin/md5java deleted file mode 100644 index 74215964f70..00000000000 --- a/bin/md5java +++ /dev/null @@ -1,102 +0,0 @@ -String[] args = this.interpreter.get("bsh.args"); -if (args == null || args.length != 1) { - System.err.println("The source string must be specified"); - System.exit(-1); -} - -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.io.*; - -String md5Hex(String data) { - return encodeHexString(md5(data)); -} - -String md5Hex(InputStream data) throws IOException { - return encodeHexString(md5(data)); -} - -byte[] md5(String data) { - return md5(getBytesUtf8(data)); -} - -byte[] md5(InputStream data) throws IOException { - MessageDigest md = getMd5Digest(); - final byte[] buf = new byte[1024 * 4]; - for (int v; (v = data.read(buf)) >= 0;) { - if (v > 0) - md.update(buf, 0, v); - } - return md.digest(); -} - -byte[] getBytesUtf8(String string) { - return getBytes(string, Charset.forName("UTF-8")); -} - -byte[] getBytes(String string, Charset charset) { - return string == null?null:string.getBytes(charset); -} - -byte[] md5(byte[] data) { - return getMd5Digest().digest(data); -} - -MessageDigest getMd5Digest() { - return getDigest("MD5"); -} - -MessageDigest getDigest(String algorithm) { - try { - return MessageDigest.getInstance(algorithm); - } catch (java.security.NoSuchAlgorithmException var2) { - throw new java.lang.IllegalArgumentException(var2); - } -} - -String encodeHexString(byte[] data) { - return new String(encodeHex(data)); -} - -char[] encodeHex(byte[] data) { - return encodeHex(data, true); -} - -char[] encodeHex(byte[] data, boolean toLowerCase) { - return encodeHex(data, toLowerCase? DIGITS_LOWER : DIGITS_UPPER); -} - -char[] DIGITS_LOWER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; -char[] DIGITS_UPPER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - -char[] encodeHex(byte[] data, char[] toDigits) { - int l = data.length; - char[] out = new char[l << 1]; - int i = 0; - - for(int j = 0; i < l; ++i) { - out[j++] = toDigits[(240 & data[i]) >>> 4]; - out[j++] = toDigits[15 & data[i]]; - } - - return out; -} - -if (args[0].endsWith(".class")) { - InputStream is = null; - try { - is = new FileInputStream(args[0]); - System.out.println(md5Hex(is)); - } catch (Exception e) { - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - } - } - } -} else { - System.out.println(md5Hex(args[0])); -} - diff --git a/build b/build index a23031dc924..d2a43dbd94b 100755 --- a/build +++ b/build @@ -116,7 +116,7 @@ if [ "$1" = "" ] || [ "$1" = "lessc" ] || [ "$1" = "checkstyle" ] ; then fi #-- parsing cmd -cmdList=" bd br cd cr ud ur doc jsrc build.debug build.release clean clean.debug clean.release utest.debug utest.release javadoc jsdoc zipjs lessc tsmin dev help checkstyle " +cmdList=" bd br cd cr ud ur doc jsrc build.debug build.release clean clean.debug clean.release utest.debug utest.release javadoc jsdoc zipjs lessc tsmin help checkstyle " if [ \( $# != 0 \) -a \( "${cmdList#* $1 }" != "$cmdList" \) ] ; then cmd=$1 shift @@ -493,20 +493,6 @@ function invoke_ant else gentime=$(grep '^time=' format) gentime=${gentime#time=} - signdir=$(grep '^signdir=' format) - signdir=${signdir#signdir=} - signclasses=$(grep '^signclasses=' format) - signclasses=${signclasses#signclasses=} - if [ "$gentime" = "" ] && [ "$signdir" != "" ] && [ "$cmd" = "build" ] ; then - buildstamp=$(grep '^buildstamp=' format) - buildstamp=${buildstamp#buildstamp=} - if [ ! -f $maindir/zk/codegen/$buildstamp ] ; then - echo "zk's build stamp is not found, please build zk first" - exit -1 - fi - else - buildstamp=$gentime - fi CLASSPATH="$DCP" ANT_OPTS=-Xmx160M ant $verbose $class_test \ $doall -Dformat="$format" -Ddeploy="$deploy" \ -Dcheckstyle.java="$checkstyleJava" -Dcheckstyle.js="$checkstyleJs" \ @@ -527,7 +513,6 @@ function invoke_ant -Dshare.javadoc.dir="$javadocdir" \ -Djavadoc.class.path="$DCP" -Dapp.name=$app $unziplist \ -Droot.context=$rootContext -Dgentime=$gentime \ - -Dsigndir=$signdir -Dsignclasses=$signclasses -Dbuildstamp=$buildstamp \ $dfnList -buildfile $maindir/build.xml $1 fi diff --git a/build.target.xml b/build.target.xml index 1b9e3464052..6d0b1c8b45b 100755 --- a/build.target.xml +++ b/build.target.xml @@ -137,18 +137,6 @@ if="deploy.tomcat.required"> - - - - - - - - - - - - @@ -201,7 +189,7 @@ if="deploy.tomcat.required"> - + @@ -261,16 +249,6 @@ if="deploy.tomcat.required"> - - - - - - - - - - diff --git a/build.xml b/build.xml index 429a81c61bb..9f48986d026 100644 --- a/build.xml +++ b/build.xml @@ -112,12 +112,6 @@ Copyright (C) 2002 Potix Corporation. All Rights Reserved. - - - - - - diff --git a/zhtml/src/org/zkoss/zhtml/impl/PageRenderer.java b/zhtml/src/org/zkoss/zhtml/impl/PageRenderer.java index 88d126e4c5f..08e689b4ab4 100644 --- a/zhtml/src/org/zkoss/zhtml/impl/PageRenderer.java +++ b/zhtml/src/org/zkoss/zhtml/impl/PageRenderer.java @@ -25,7 +25,6 @@ import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.UiException; -import org.zkoss.zk.ui.WebApp; import org.zkoss.zk.ui.sys.Attributes; import org.zkoss.zk.ui.sys.ComponentCtrl; import org.zkoss.zk.ui.sys.ExecutionsCtrl; @@ -156,14 +155,8 @@ public static void afterRenderHtml(Execution exec, Page page, Writer out, Object final TagRenderContext rc = (TagRenderContext) param; String rcs = rc.complete(); - WebApp webApp = exec.getDesktop().getWebApp(); if (rcs.length() > 0) { - Object notice = webApp.getAttribute("org.zkoss.zk.ui.client.notice"); - if (notice instanceof String) { - rcs += '\n' + ((String) notice); - } - if (out instanceof StringWriter) { final StringBuffer buf = ((StringWriter) out).getBuffer(); int j = buf.lastIndexOf(""); @@ -179,12 +172,6 @@ public static void afterRenderHtml(Execution exec, Page page, Writer out, Object } write(out, HtmlPageRenders.outHeaderZkTags(exec, page)); - if (rcs.length() == 0) { - Object notice = webApp.getAttribute("org.zkoss.zk.ui.client.notice"); - if (notice instanceof String) { - out.write((String) notice); - } - } writeln(out, HtmlPageRenders.outUnavailable(exec)); afterRenderTag(exec, param); } diff --git a/zk/format b/zk/format index e65cccd2a7a..4ef66f41e6c 100644 --- a/zk/format +++ b/zk/format @@ -1,4 +1,2 @@ jar -time=archive/metainfo/zk/build -signdir=archive/metainfo/zk/buildsign -signclasses=org.zkoss.zk.ui.sys.WebAppFactoryImpl,org.zkoss.zk.ui.http.WebManager,org.zkoss.zk.ui.sys.Registry \ No newline at end of file +time=archive/metainfo/zk/build \ No newline at end of file diff --git a/zk/src/org/zkoss/zk/ui/http/SimpleWebApp.java b/zk/src/org/zkoss/zk/ui/http/SimpleWebApp.java index 8cbb9583eef..152fd23562c 100644 --- a/zk/src/org/zkoss/zk/ui/http/SimpleWebApp.java +++ b/zk/src/org/zkoss/zk/ui/http/SimpleWebApp.java @@ -34,8 +34,6 @@ import org.zkoss.zk.ui.ext.ScopeListener; import org.zkoss.zk.ui.impl.AbstractWebApp; import org.zkoss.zk.ui.impl.ScopeListeners; -import org.zkoss.zk.ui.sys.Registry; -import org.zkoss.zk.ui.sys.WebAppFactoryImpl; import org.zkoss.zk.ui.util.Configuration; /** @@ -56,8 +54,6 @@ public void init(Object context, Configuration config) { throw new IllegalArgumentException("context"); _ctx = (ServletContext) context; super.init(context, config); - - Registry.sign(this, Registry.class, WebManager.class, WebAppFactoryImpl.class); } private final Map _attrs = new AttributesMap() { diff --git a/zk/src/org/zkoss/zk/ui/http/WebManager.java b/zk/src/org/zkoss/zk/ui/http/WebManager.java index 450aae45492..e9e526c4b1d 100644 --- a/zk/src/org/zkoss/zk/ui/http/WebManager.java +++ b/zk/src/org/zkoss/zk/ui/http/WebManager.java @@ -63,13 +63,11 @@ import org.zkoss.zk.ui.sys.ConfigParser; import org.zkoss.zk.ui.sys.DesktopCtrl; import org.zkoss.zk.ui.sys.ExecutionsCtrl; -import org.zkoss.zk.ui.sys.Registry; import org.zkoss.zk.ui.sys.RequestInfo; import org.zkoss.zk.ui.sys.SessionsCtrl; import org.zkoss.zk.ui.sys.UiFactory; import org.zkoss.zk.ui.sys.WebAppCtrl; import org.zkoss.zk.ui.sys.WebAppFactory; -import org.zkoss.zk.ui.sys.WebAppFactoryImpl; import org.zkoss.zk.ui.sys.WebAppsCtrl; import org.zkoss.zk.ui.util.Configuration; @@ -284,8 +282,6 @@ public WebManager(ServletContext ctx, String updateURI, String resourceURI) { } } } - - Registry.sign(_wapp, Registry.class, WebManager.class, WebAppFactoryImpl.class); } private void checkAndAddExtendlet(String ext, Extendlet extlet) { diff --git a/zk/src/org/zkoss/zk/ui/sys/ConfigParser.java b/zk/src/org/zkoss/zk/ui/sys/ConfigParser.java index 0970b19c61f..b41a823e397 100644 --- a/zk/src/org/zkoss/zk/ui/sys/ConfigParser.java +++ b/zk/src/org/zkoss/zk/ui/sys/ConfigParser.java @@ -28,7 +28,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import org.slf4j.Logger; @@ -175,33 +174,11 @@ else if (config == null) final List xmls = locator.getDependentXMLResources("metainfo/zk/config.xml", "config-name", "depends"); - Registry reg = Registry.getInstance(); for (XMLResourcesLocator.Resource res : xmls) { if (log.isDebugEnabled()) log.debug("Loading " + res.url); try { if (checkVersion(res.url, res.document)) { - try { - String path = res.url.toExternalForm(); - int end = path.lastIndexOf('/'); // no need to use OS's separator - if (end >= 0) { - InputStream inputStream = null; - try { - path = path.substring(0, end + 1) + Strings.toString(Registry.PREFS_0); - inputStream = new URL(path).openStream(); - if (inputStream != null) { - Properties props = new Properties(); - props.load(inputStream); - for (Map.Entry me : props.entrySet()) - reg.addKeys((String) me.getKey(), (String) me.getValue()); - } - } finally { - if (inputStream != null) - inputStream.close(); - } - } - } catch (Exception ignored) { - } final Element el = res.document.getRootElement(); if (!syscfgLoaded) { parseSubZScriptConfig(el); diff --git a/zk/src/org/zkoss/zk/ui/sys/Registry.java b/zk/src/org/zkoss/zk/ui/sys/Registry.java deleted file mode 100644 index 0af978f493f..00000000000 --- a/zk/src/org/zkoss/zk/ui/sys/Registry.java +++ /dev/null @@ -1,163 +0,0 @@ -/* Registry.java - - Purpose: - - Description: - - History: - 12:41 PM 2/25/16, Created by jumperchen - -Copyright (C) 2016 Potix Corporation. All Rights Reserved. -*/ -package org.zkoss.zk.ui.sys; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.zkoss.lang.Strings; -import org.zkoss.zk.ui.WebApp; -import org.zkoss.zk.ui.WebApps; -import org.zkoss.zk.ui.impl.AbstractWebApp; - -/** - * A helper class for class registry for internal use only. - * @author jumperchen - * @since 8.0.2 - */ -public class Registry { - private static final Registry INSTANCE = new Registry(); - private final Map keys = new ConcurrentHashMap(10); - private final Map signs = new ConcurrentHashMap(10); - private final Map values = new ConcurrentHashMap(10); - private static final Map BYTE_MAP = new HashMap(10); - - public static final byte[] PREFS_0; - public static final byte[] PREFS_1; - public static final byte[] PREFS_2; - - static { - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 48 }), - PREFS_0 = new byte[] { 98, 117, 105, 108, 100, 115, 105, 103, 110 }); - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 49 }), - PREFS_1 = new byte[] { 111, 114, 103, 46, 122, 107, 111, 115, 115, 46, 122, 107, 46, 117, 105, 46, 99, - 108, 105, 101, 110, 116, 46, 110, 111, 116, 105, 99, 101 }); - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 50 }), - PREFS_2 = new byte[] { 89, 111, 117, 114, 32, 90, 75, 32, 98, 105, 110, 97, 114, 121, 32, 105, 115, 32, - 98, 101, 105, 110, 103, 32, 97, 108, 116, 101, 114, 101, 100, 32, 97, 110, 100, 32, 109, 97, - 121, 32, 110, 111, 116, 32, 119, 111, 114, 107, 32, 97, 115, 32, 101, 120, 112, 101, 99, 116, - 101, 100, 46, 32, 80, 108, 101, 97, 115, 101, 32, 99, 111, 110, 116, 97, 99, 116, 32, 117, 115, - 32, 97, 116, 32, 105, 110, 102, 111, 64, 122, 107, 111, 115, 115, 46, 111, 114, 103, 32, 102, - 111, 114, 32, 97, 115, 115, 105, 115, 116, 97, 110, 99, 101, 46 }); - BYTE_MAP.put(toString(new byte[] { 109, 115, 103, 48 }), - new byte[] { 10, 60, 115, 99, 114, 105, 112, 116, 32, 99, 108, 97, 115, 115, 61, 34, 122, 45, 114, 117, - 110, 111, 110, 99, 101, 34, 32, 116, 121, 112, 101, 61, 34, 116, 101, 120, 116, 47, 106, 97, - 118, 97, 115, 99, 114, 105, 112, 116, 34, 62, 10, 122, 65, 117, 46, 115, 104, 111, 119, 69, 114, - 114, 111, 114, 40, 39, 70, 65, 73, 76, 69, 68, 95, 84, 79, 95, 80, 82, 79, 67, 69, 83, 83, 39, - 44, 32, 39, 37, 49, 36, 115, 39, 44, 39, 37, 50, 36, 115, 39, 41, 59, 10, 60, 47, 115, 99, 114, - 105, 112, 116, 62 }); - } - - private Registry() { - } - - public static Registry getInstance() { - return INSTANCE; - } - - /*package*/ final void addKeys(String key, String value) { - if (key != null && value != null) - signs.put(key, value); - } - - public boolean isValid(Class cls) { - final String key = getKey(cls); - - if (signs.containsKey(key)) { - String value = values.get(key); - if (value == null) { - synchronized (values) { - if (!values.containsKey(key)) { - value = DigestUtilsHelper.md5Hex(loadValue(cls) + AbstractWebApp.getBuildStamp()); - values.put(key, value); - } - } - } - return signs.get(key).equals(value); - } - return false; - } - - public String getKey(Class cls) { - final String name = cls.getName(); - if (!keys.containsKey(name)) { - final String key = DigestUtilsHelper.md5Hex(name); - keys.put(cls.getName(), key); - return key; - } - return keys.get(name); - } - - public String getSign(Class cls) { - return signs.get(getKey(cls)); - } - - // sign the cls to the webapp - public static void sign(WebApp wapp, Class... clses) { - if (wapp == null || "CE".equals(WebApps.getEdition()) - || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) { - for (Class cls : clses) { - if (!INSTANCE.isValid(cls)) { - String sign = INSTANCE.getSign(cls); - String key = Strings.toString(Registry.PREFS_1); - if (sign == null) { - sign = INSTANCE.getKey(cls); - } - if (sign != null) { - if (sign.length() > 8) - sign = sign.substring(0, 9); - } - - wapp.setAttribute(key, gen(Strings.toString(Registry.PREFS_2), sign)); - return; // done - } - } - } - } - - private static String gen(String msg, String error) { - return String.format(toString(BYTE_MAP.get(toString(new byte[] { 109, 115, 103, 48 }))), msg, - error != null ? toString(new byte[] { 69, 114, 114, 111, 114, 58 }) + error : ""); - } - - private synchronized String loadValue(Class cls) { - InputStream is = null; - try { - URL location = cls.getResource( - "/" + cls.getName().replace(".", "/") + toString(new byte[] { 46, 99, 108, 97, 115, 115 })); - is = location.openStream(); - return DigestUtilsHelper.md5Hex(is); - } catch (Exception ignored) { - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException ignored) { - } - } - } - return null; - } - - private static final String toString(byte[] data) { - try { - return new String(data, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return new String(data); - } - } -} diff --git a/zul/src/org/zkoss/zul/impl/PageRenderer.java b/zul/src/org/zkoss/zul/impl/PageRenderer.java index caace04f9ff..1ccdbc822c1 100644 --- a/zul/src/org/zkoss/zul/impl/PageRenderer.java +++ b/zul/src/org/zkoss/zul/impl/PageRenderer.java @@ -100,10 +100,6 @@ else if (!"true".equals(Library.getProperty("org.zkoss.zul.tablet.meta.viewport. writeln(out, HtmlPageRenders.outUnavailable(exec)); WebApp webApp = exec.getDesktop().getWebApp(); - Object notice = webApp.getAttribute("org.zkoss.zk.ui.client.notice"); - if (notice instanceof String) { - out.write((String) notice); - } out.write("\n\n\n"); }