From 803719f5876ad8528dd7f07899d49c104f10beb0 Mon Sep 17 00:00:00 2001 From: Feng Date: Mon, 11 May 2020 10:32:26 +0800 Subject: [PATCH 01/17] =?UTF-8?q?KERNEL-3881=20=E7=8A=B6=E6=80=81=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8+=E9=9B=86=E7=BE=A4=E9=94=81=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E8=A7=A3=E8=80=A6=EF=BC=8C=E8=84=B1?= =?UTF-8?q?=E7=A6=BB=E4=BE=9D=E8=B5=96redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/clients/jedis/JedisCluster.java | 1989 +++++++++++++++++ .../redis/clients/jedis/JedisPubSub.java | 187 ++ 2 files changed, 2176 insertions(+) create mode 100644 fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisCluster.java create mode 100644 fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisCluster.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisCluster.java new file mode 100644 index 000000000..dd7de359d --- /dev/null +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisCluster.java @@ -0,0 +1,1989 @@ +package com.fr.third.redis.clients.jedis; + +import com.fr.third.redis.clients.jedis.params.GeoRadiusParam; +import com.fr.third.redis.clients.jedis.params.ZAddParams; +import com.fr.third.redis.clients.jedis.params.ZIncrByParams; +import com.fr.third.redis.clients.jedis.commands.JedisClusterCommands; +import com.fr.third.redis.clients.jedis.commands.JedisClusterScriptingCommands; +import com.fr.third.redis.clients.jedis.commands.MultiKeyJedisClusterCommands; +import com.fr.third.redis.clients.jedis.util.KeyMergeUtil; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.fr.third.org.apache.commons.pool2.impl.GenericObjectPoolConfig; + +import com.fr.third.redis.clients.jedis.params.SetParams; +import com.fr.third.redis.clients.jedis.util.JedisClusterHashTagUtil; + +public class JedisCluster extends BinaryJedisCluster implements JedisClusterCommands, + MultiKeyJedisClusterCommands, JedisClusterScriptingCommands { + + public JedisCluster(HostAndPort node) { + this(Collections.singleton(node)); + } + + public JedisCluster(HostAndPort node, int timeout) { + this(Collections.singleton(node), timeout); + } + + public JedisCluster(HostAndPort node, int timeout, int maxAttempts) { + this(Collections.singleton(node), timeout, maxAttempts); + } + + public JedisCluster(HostAndPort node, final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), poolConfig); + } + + public JedisCluster(HostAndPort node, int timeout, final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), timeout, poolConfig); + } + + public JedisCluster(HostAndPort node, int timeout, int maxAttempts, + final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), timeout, maxAttempts, poolConfig); + } + + public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout, + int maxAttempts, final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), connectionTimeout, soTimeout, maxAttempts, poolConfig); + } + + public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout, + int maxAttempts, String password, final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), connectionTimeout, soTimeout, maxAttempts, password, poolConfig); + } + + public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout, + int maxAttempts, String password, String clientName, final GenericObjectPoolConfig poolConfig) { + this(Collections.singleton(node), connectionTimeout, soTimeout, maxAttempts, password, clientName, poolConfig); + } + + public JedisCluster(Set nodes) { + this(nodes, DEFAULT_TIMEOUT); + } + + public JedisCluster(Set nodes, int timeout) { + this(nodes, timeout, DEFAULT_MAX_ATTEMPTS); + } + + public JedisCluster(Set nodes, int timeout, int maxAttempts) { + this(nodes, timeout, maxAttempts, new GenericObjectPoolConfig()); + } + + public JedisCluster(Set nodes, final GenericObjectPoolConfig poolConfig) { + this(nodes, DEFAULT_TIMEOUT, DEFAULT_MAX_ATTEMPTS, poolConfig); + } + + public JedisCluster(Set nodes, int timeout, final GenericObjectPoolConfig poolConfig) { + this(nodes, timeout, DEFAULT_MAX_ATTEMPTS, poolConfig); + } + + public JedisCluster(Set jedisClusterNode, int timeout, int maxAttempts, + final GenericObjectPoolConfig poolConfig) { + super(jedisClusterNode, timeout, maxAttempts, poolConfig); + } + + public JedisCluster(Set jedisClusterNode, int connectionTimeout, int soTimeout, + int maxAttempts, final GenericObjectPoolConfig poolConfig) { + super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, poolConfig); + } + + public JedisCluster(Set jedisClusterNode, int connectionTimeout, int soTimeout, + int maxAttempts, String password, final GenericObjectPoolConfig poolConfig) { + super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, password, poolConfig); + } + + public JedisCluster(Set jedisClusterNode, int connectionTimeout, int soTimeout, + int maxAttempts, String password, String clientName, final GenericObjectPoolConfig poolConfig) { + super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, password, clientName, poolConfig); +} + + @Override + public String set(final String key, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.set(key, value); + } + }.run(key); + } + + @Override + public String set(final String key, final String value, final SetParams params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.set(key, value, params); + } + }.run(key); + } + + @Override + public String get(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.get(key); + } + }.run(key); + } + + @Override + public Boolean exists(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.exists(key); + } + }.run(key); + } + + @Override + public Long exists(final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.exists(keys); + } + }.run(keys.length, keys); + } + + @Override + public Long persist(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.persist(key); + } + }.run(key); + } + + @Override + public String type(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.type(key); + } + }.run(key); + } + + @Override + public byte[] dump(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public byte[] execute(Jedis connection) { + return connection.dump(key); + } + }.run(key); + } + + @Override + public String restore(final String key, final int ttl, final byte[] serializedValue) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.restore(key, ttl, serializedValue); + } + }.run(key); + } + + @Override + public Long expire(final String key, final int seconds) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.expire(key, seconds); + } + }.run(key); + } + + @Override + public Long pexpire(final String key, final long milliseconds) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pexpire(key, milliseconds); + } + }.run(key); + } + + @Override + public Long expireAt(final String key, final long unixTime) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.expireAt(key, unixTime); + } + }.run(key); + } + + @Override + public Long pexpireAt(final String key, final long millisecondsTimestamp) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pexpireAt(key, millisecondsTimestamp); + } + }.run(key); + } + + @Override + public Long ttl(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.ttl(key); + } + }.run(key); + } + + @Override + public Long pttl(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pttl(key); + } + }.run(key); + } + + @Override + public Long touch(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.touch(key); + } + }.run(key); + } + + @Override + public Long touch(final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.touch(keys); + } + }.run(keys.length, keys); + } + + @Override + public Boolean setbit(final String key, final long offset, final boolean value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.setbit(key, offset, value); + } + }.run(key); + } + + @Override + public Boolean setbit(final String key, final long offset, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.setbit(key, offset, value); + } + }.run(key); + } + + @Override + public Boolean getbit(final String key, final long offset) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.getbit(key, offset); + } + }.run(key); + } + + @Override + public Long setrange(final String key, final long offset, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.setrange(key, offset, value); + } + }.run(key); + } + + @Override + public String getrange(final String key, final long startOffset, final long endOffset) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.getrange(key, startOffset, endOffset); + } + }.run(key); + } + + @Override + public String getSet(final String key, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.getSet(key, value); + } + }.run(key); + } + + @Override + public Long setnx(final String key, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.setnx(key, value); + } + }.run(key); + } + + @Override + public String setex(final String key, final int seconds, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.setex(key, seconds, value); + } + }.run(key); + } + + @Override + public String psetex(final String key, final long milliseconds, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.psetex(key, milliseconds, value); + } + }.run(key); + } + + @Override + public Long decrBy(final String key, final long decrement) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.decrBy(key, decrement); + } + }.run(key); + } + + @Override + public Long decr(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.decr(key); + } + }.run(key); + } + + @Override + public Long incrBy(final String key, final long increment) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.incrBy(key, increment); + } + }.run(key); + } + + @Override + public Double incrByFloat(final String key, final double increment) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.incrByFloat(key, increment); + } + }.run(key); + } + + @Override + public Long incr(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.incr(key); + } + }.run(key); + } + + @Override + public Long append(final String key, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.append(key, value); + } + }.run(key); + } + + @Override + public String substr(final String key, final int start, final int end) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.substr(key, start, end); + } + }.run(key); + } + + @Override + public Long hset(final String key, final String field, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hset(key, field, value); + } + }.run(key); + } + + @Override + public Long hset(final String key, final Map hash) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hset(key, hash); + } + }.run(key); + } + + @Override + public String hget(final String key, final String field) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.hget(key, field); + } + }.run(key); + } + + @Override + public Long hsetnx(final String key, final String field, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hsetnx(key, field, value); + } + }.run(key); + } + + @Override + public String hmset(final String key, final Map hash) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.hmset(key, hash); + } + }.run(key); + } + + @Override + public List hmget(final String key, final String... fields) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.hmget(key, fields); + } + }.run(key); + } + + @Override + public Long hincrBy(final String key, final String field, final long value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hincrBy(key, field, value); + } + }.run(key); + } + + @Override + public Boolean hexists(final String key, final String field) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.hexists(key, field); + } + }.run(key); + } + + @Override + public Long hdel(final String key, final String... field) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hdel(key, field); + } + }.run(key); + } + + @Override + public Long hlen(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hlen(key); + } + }.run(key); + } + + @Override + public Set hkeys(final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.hkeys(key); + } + }.run(key); + } + + @Override + public List hvals(final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.hvals(key); + } + }.run(key); + } + + @Override + public Map hgetAll(final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Map execute(Jedis connection) { + return connection.hgetAll(key); + } + }.run(key); + } + + @Override + public Long rpush(final String key, final String... string) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.rpush(key, string); + } + }.run(key); + } + + @Override + public Long lpush(final String key, final String... string) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.lpush(key, string); + } + }.run(key); + } + + @Override + public Long llen(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.llen(key); + } + }.run(key); + } + + @Override + public List lrange(final String key, final long start, final long stop) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.lrange(key, start, stop); + } + }.run(key); + } + + @Override + public String ltrim(final String key, final long start, final long stop) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.ltrim(key, start, stop); + } + }.run(key); + } + + @Override + public String lindex(final String key, final long index) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.lindex(key, index); + } + }.run(key); + } + + @Override + public String lset(final String key, final long index, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.lset(key, index, value); + } + }.run(key); + } + + @Override + public Long lrem(final String key, final long count, final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.lrem(key, count, value); + } + }.run(key); + } + + @Override + public String lpop(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.lpop(key); + } + }.run(key); + } + + @Override + public String rpop(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.rpop(key); + } + }.run(key); + } + + @Override + public Long sadd(final String key, final String... member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sadd(key, member); + } + }.run(key); + } + + @Override + public Set smembers(final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.smembers(key); + } + }.run(key); + } + + @Override + public Long srem(final String key, final String... member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.srem(key, member); + } + }.run(key); + } + + @Override + public String spop(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.spop(key); + } + }.run(key); + } + + @Override + public Set spop(final String key, final long count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.spop(key, count); + } + }.run(key); + } + + @Override + public Long scard(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.scard(key); + } + }.run(key); + } + + @Override + public Boolean sismember(final String key, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.sismember(key, member); + } + }.run(key); + } + + @Override + public String srandmember(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.srandmember(key); + } + }.run(key); + } + + @Override + public List srandmember(final String key, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.srandmember(key, count); + } + }.run(key); + } + + @Override + public Long strlen(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.strlen(key); + } + }.run(key); + } + + @Override + public Long zadd(final String key, final double score, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, score, member); + } + }.run(key); + } + + @Override + public Long zadd(final String key, final double score, final String member, + final ZAddParams params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, score, member, params); + } + }.run(key); + } + + @Override + public Long zadd(final String key, final Map scoreMembers) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, scoreMembers); + } + }.run(key); + } + + @Override + public Long zadd(final String key, final Map scoreMembers, final ZAddParams params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, scoreMembers, params); + } + }.run(key); + } + + @Override + public Set zrange(final String key, final long start, final long stop) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrange(key, start, stop); + } + }.run(key); + } + + @Override + public Long zrem(final String key, final String... members) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zrem(key, members); + } + }.run(key); + } + + @Override + public Double zincrby(final String key, final double increment, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.zincrby(key, increment, member); + } + }.run(key); + } + + @Override + public Double zincrby(final String key, final double increment, final String member, + final ZIncrByParams params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.zincrby(key, increment, member, params); + } + }.run(key); + } + + @Override + public Long zrank(final String key, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zrank(key, member); + } + }.run(key); + } + + @Override + public Long zrevrank(final String key, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zrevrank(key, member); + } + }.run(key); + } + + @Override + public Set zrevrange(final String key, final long start, final long stop) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrange(key, start, stop); + } + }.run(key); + } + + @Override + public Set zrangeWithScores(final String key, final long start, final long stop) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeWithScores(key, start, stop); + } + }.run(key); + } + + @Override + public Set zrevrangeWithScores(final String key, final long start, final long stop) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeWithScores(key, start, stop); + } + }.run(key); + } + + @Override + public Long zcard(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zcard(key); + } + }.run(key); + } + + @Override + public Double zscore(final String key, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.zscore(key, member); + } + }.run(key); + } + + @Override + public List sort(final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.sort(key); + } + }.run(key); + } + + @Override + public List sort(final String key, final SortingParams sortingParameters) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.sort(key, sortingParameters); + } + }.run(key); + } + + @Override + public Long zcount(final String key, final double min, final double max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zcount(key, min, max); + } + }.run(key); + } + + @Override + public Long zcount(final String key, final String min, final String max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zcount(key, min, max); + } + }.run(key); + } + + @Override + public Set zrangeByScore(final String key, final double min, final double max) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max); + } + }.run(key); + } + + @Override + public Set zrangeByScore(final String key, final String min, final String max) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max); + } + }.run(key); + } + + @Override + public Set zrevrangeByScore(final String key, final double max, final double min) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, max, min); + } + }.run(key); + } + + @Override + public Set zrangeByScore(final String key, final double min, final double max, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByScore(final String key, final String max, final String min) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, max, min); + } + }.run(key); + } + + @Override + public Set zrangeByScore(final String key, final String min, final String max, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByScore(final String key, final double max, final double min, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, max, min, offset, count); + } + }.run(key); + } + + @Override + public Set zrangeByScoreWithScores(final String key, final double min, final double max) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max); + } + }.run(key); + } + + @Override + public Set zrevrangeByScoreWithScores(final String key, final double max, final double min) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min); + } + }.run(key); + } + + @Override + public Set zrangeByScoreWithScores(final String key, final double min, final double max, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByScore(final String key, final String max, final String min, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, max, min, offset, count); + } + }.run(key); + } + + @Override + public Set zrangeByScoreWithScores(final String key, final String min, final String max) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max); + } + }.run(key); + } + + @Override + public Set zrevrangeByScoreWithScores(final String key, final String max, final String min) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min); + } + }.run(key); + } + + @Override + public Set zrangeByScoreWithScores(final String key, final String min, final String max, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByScoreWithScores(final String key, final double max, + final double min, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByScoreWithScores(final String key, final String max, + final String min, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min, offset, count); + } + }.run(key); + } + + @Override + public Long zremrangeByRank(final String key, final long start, final long stop) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByRank(key, start, stop); + } + }.run(key); + } + + @Override + public Long zremrangeByScore(final String key, final double min, final double max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByScore(key, min, max); + } + }.run(key); + } + + @Override + public Long zremrangeByScore(final String key, final String min, final String max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByScore(key, min, max); + } + }.run(key); + } + + @Override + public Long zlexcount(final String key, final String min, final String max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zlexcount(key, min, max); + } + }.run(key); + } + + @Override + public Set zrangeByLex(final String key, final String min, final String max) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByLex(key, min, max); + } + }.run(key); + } + + @Override + public Set zrangeByLex(final String key, final String min, final String max, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByLex(key, min, max, offset, count); + } + }.run(key); + } + + @Override + public Set zrevrangeByLex(final String key, final String max, final String min) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByLex(key, max, min); + } + }.run(key); + } + + @Override + public Set zrevrangeByLex(final String key, final String max, final String min, + final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByLex(key, max, min, offset, count); + } + }.run(key); + } + + @Override + public Long zremrangeByLex(final String key, final String min, final String max) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByLex(key, min, max); + } + }.run(key); + } + + @Override + public Long linsert(final String key, final ListPosition where, final String pivot, + final String value) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.linsert(key, where, pivot, value); + } + }.run(key); + } + + @Override + public Long lpushx(final String key, final String... string) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.lpushx(key, string); + } + }.run(key); + } + + @Override + public Long rpushx(final String key, final String... string) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.rpushx(key, string); + } + }.run(key); + } + + @Override + public Long del(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.del(key); + } + }.run(key); + } + + @Override + public Long unlink(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.unlink(key); + } + }.run(key); + } + + @Override + public Long unlink(final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.unlink(keys); + } + }.run(keys.length, keys); + } + + @Override + public String echo(final String string) { + // note that it'll be run from arbitary node + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.echo(string); + } + }.run(string); + } + + @Override + public Long bitcount(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.bitcount(key); + } + }.run(key); + } + + @Override + public Long bitcount(final String key, final long start, final long end) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.bitcount(key, start, end); + } + }.run(key); + } + + @Override + public Set keys(final String pattern) { + if (pattern == null || pattern.isEmpty()) { + throw new IllegalArgumentException(this.getClass().getSimpleName() + + " only supports KEYS commands with non-empty patterns"); + } + if (!JedisClusterHashTagUtil.isClusterCompliantMatchPattern(pattern)) { + throw new IllegalArgumentException(this.getClass().getSimpleName() + + " only supports KEYS commands with patterns containing hash-tags ( curly-brackets enclosed strings )"); + } + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.keys(pattern); + } + }.run(pattern); + } + + @Override + public ScanResult scan(final String cursor, final ScanParams params) { + + String matchPattern = null; + + if (params == null || (matchPattern = params.match()) == null || matchPattern.isEmpty()) { + throw new IllegalArgumentException(JedisCluster.class.getSimpleName() + + " only supports SCAN commands with non-empty MATCH patterns"); + } + + if (JedisClusterHashTagUtil.isClusterCompliantMatchPattern(matchPattern)) { + throw new IllegalArgumentException(JedisCluster.class.getSimpleName() + + " only supports SCAN commands with MATCH patterns containing hash-tags ( curly-brackets enclosed strings )"); + } + + return new JedisClusterCommand< ScanResult>(connectionHandler, maxAttempts) { + @Override + public ScanResult execute(Jedis connection) { + return connection.scan(cursor, params); + } + }.run(matchPattern); + } + + @Override + public ScanResult> hscan(final String key, final String cursor) { + return new JedisClusterCommand>>(connectionHandler, + maxAttempts) { + @Override + public ScanResult> execute(Jedis connection) { + return connection.hscan(key, cursor); + } + }.run(key); + } + + @Override + public ScanResult sscan(final String key, final String cursor) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public ScanResult execute(Jedis connection) { + return connection.sscan(key, cursor); + } + }.run(key); + } + + @Override + public ScanResult zscan(final String key, final String cursor) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public ScanResult execute(Jedis connection) { + return connection.zscan(key, cursor); + } + }.run(key); + } + + @Override + public Long pfadd(final String key, final String... elements) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pfadd(key, elements); + } + }.run(key); + } + + @Override + public long pfcount(final String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pfcount(key); + } + }.run(key); + } + + @Override + public List blpop(final int timeout, final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.blpop(timeout, key); + } + }.run(key); + } + + @Override + public List brpop(final int timeout, final String key) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.brpop(timeout, key); + } + }.run(key); + } + + @Override + public Long del(final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.del(keys); + } + }.run(keys.length, keys); + } + + @Override + public List blpop(final int timeout, final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.blpop(timeout, keys); + } + }.run(keys.length, keys); + + } + + @Override + public List brpop(final int timeout, final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.brpop(timeout, keys); + } + }.run(keys.length, keys); + } + + @Override + public List mget(final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.mget(keys); + } + }.run(keys.length, keys); + } + + @Override + public String mset(final String... keysvalues) { + String[] keys = new String[keysvalues.length / 2]; + + for (int keyIdx = 0; keyIdx < keys.length; keyIdx++) { + keys[keyIdx] = keysvalues[keyIdx * 2]; + } + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.mset(keysvalues); + } + }.run(keys.length, keys); + } + + @Override + public Long msetnx(final String... keysvalues) { + String[] keys = new String[keysvalues.length / 2]; + + for (int keyIdx = 0; keyIdx < keys.length; keyIdx++) { + keys[keyIdx] = keysvalues[keyIdx * 2]; + } + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.msetnx(keysvalues); + } + }.run(keys.length, keys); + } + + @Override + public String rename(final String oldkey, final String newkey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.rename(oldkey, newkey); + } + }.run(2, oldkey, newkey); + } + + @Override + public Long renamenx(final String oldkey, final String newkey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.renamenx(oldkey, newkey); + } + }.run(2, oldkey, newkey); + } + + @Override + public String rpoplpush(final String srckey, final String dstkey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.rpoplpush(srckey, dstkey); + } + }.run(2, srckey, dstkey); + } + + @Override + public Set sdiff(final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.sdiff(keys); + } + }.run(keys.length, keys); + } + + @Override + public Long sdiffstore(final String dstkey, final String... keys) { + String[] mergedKeys = KeyMergeUtil.merge(dstkey, keys); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sdiffstore(dstkey, keys); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public Set sinter(final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.sinter(keys); + } + }.run(keys.length, keys); + } + + @Override + public Long sinterstore(final String dstkey, final String... keys) { + String[] mergedKeys = KeyMergeUtil.merge(dstkey, keys); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sinterstore(dstkey, keys); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public Long smove(final String srckey, final String dstkey, final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.smove(srckey, dstkey, member); + } + }.run(2, srckey, dstkey); + } + + @Override + public Long sort(final String key, final SortingParams sortingParameters, final String dstkey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sort(key, sortingParameters, dstkey); + } + }.run(2, key, dstkey); + } + + @Override + public Long sort(final String key, final String dstkey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sort(key, dstkey); + } + }.run(2, key, dstkey); + } + + @Override + public Set sunion(final String... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public Set execute(Jedis connection) { + return connection.sunion(keys); + } + }.run(keys.length, keys); + } + + @Override + public Long sunionstore(final String dstkey, final String... keys) { + String[] wholeKeys = KeyMergeUtil.merge(dstkey, keys); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.sunionstore(dstkey, keys); + } + }.run(wholeKeys.length, wholeKeys); + } + + @Override + public Long zinterstore(final String dstkey, final String... sets) { + String[] wholeKeys = KeyMergeUtil.merge(dstkey, sets); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zinterstore(dstkey, sets); + } + }.run(wholeKeys.length, wholeKeys); + } + + @Override + public Long zinterstore(final String dstkey, final ZParams params, final String... sets) { + String[] mergedKeys = KeyMergeUtil.merge(dstkey, sets); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zinterstore(dstkey, params, sets); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public Long zunionstore(final String dstkey, final String... sets) { + String[] mergedKeys = KeyMergeUtil.merge(dstkey, sets); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zunionstore(dstkey, sets); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public Long zunionstore(final String dstkey, final ZParams params, final String... sets) { + String[] mergedKeys = KeyMergeUtil.merge(dstkey, sets); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.zunionstore(dstkey, params, sets); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public String brpoplpush(final String source, final String destination, final int timeout) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.brpoplpush(source, destination, timeout); + } + }.run(2, source, destination); + } + + @Override + public Long publish(final String channel, final String message) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.publish(channel, message); + } + }.runWithAnyNode(); + } + + @Override + public void subscribe(final JedisPubSub jedisPubSub, final String... channels) { + new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Integer execute(Jedis connection) { + connection.subscribe(jedisPubSub, channels); + return 0; + } + }.runWithAnyNode(); + } + + @Override + public void psubscribe(final JedisPubSub jedisPubSub, final String... patterns) { + new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Integer execute(Jedis connection) { + connection.psubscribe(jedisPubSub, patterns); + return 0; + } + }.runWithAnyNode(); + } + + @Override + public Long bitop(final BitOP op, final String destKey, final String... srcKeys) { + String[] mergedKeys = KeyMergeUtil.merge(destKey, srcKeys); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.bitop(op, destKey, srcKeys); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public String pfmerge(final String destkey, final String... sourcekeys) { + String[] mergedKeys = KeyMergeUtil.merge(destkey, sourcekeys); + + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.pfmerge(destkey, sourcekeys); + } + }.run(mergedKeys.length, mergedKeys); + } + + @Override + public long pfcount(final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.pfcount(keys); + } + }.run(keys.length, keys); + } + + @Override + public Object eval(final String script, final int keyCount, final String... params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.eval(script, keyCount, params); + } + }.run(keyCount, params); + } + + @Override + public Object eval(final String script, final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.eval(script); + } + }.run(sampleKey); + } + + @Override + public Object eval(final String script, final List keys, final List args) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.eval(script, keys, args); + } + }.run(keys.size(), keys.toArray(new String[keys.size()])); + } + + @Override + public Object evalsha(final String sha1, final int keyCount, final String... params) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.evalsha(sha1, keyCount, params); + } + }.run(keyCount, params); + } + + @Override + public Object evalsha(final String sha1, final List keys, final List args) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.evalsha(sha1, keys, args); + } + }.run(keys.size(), keys.toArray(new String[keys.size()])); + } + + @Override + public Object evalsha(final String sha1, final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Object execute(Jedis connection) { + return connection.evalsha(sha1); + } + }.run(sampleKey); + } + + @Override + public Boolean scriptExists(final String sha1, final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Boolean execute(Jedis connection) { + return connection.scriptExists(sha1); + } + }.run(sampleKey); + } + + @Override + public List scriptExists(final String sampleKey, final String... sha1) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.scriptExists(sha1); + } + }.run(sampleKey); + } + + @Override + public String scriptLoad(final String script, final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.scriptLoad(script); + } + }.run(sampleKey); + } + + @Override + public String scriptFlush(final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.scriptFlush(); + } + }.run(sampleKey); + } + + @Override + public String scriptKill(final String sampleKey) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public String execute(Jedis connection) { + return connection.scriptKill(); + } + }.run(sampleKey); + } + + @Override + public Long geoadd(final String key, final double longitude, final double latitude, + final String member) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.geoadd(key, longitude, latitude, member); + } + }.run(key); + } + + @Override + public Long geoadd(final String key, final Map memberCoordinateMap) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.geoadd(key, memberCoordinateMap); + } + }.run(key); + } + + @Override + public Double geodist(final String key, final String member1, final String member2) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.geodist(key, member1, member2); + } + }.run(key); + } + + @Override + public Double geodist(final String key, final String member1, final String member2, + final GeoUnit unit) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Double execute(Jedis connection) { + return connection.geodist(key, member1, member2, unit); + } + }.run(key); + } + + @Override + public List geohash(final String key, final String... members) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.geohash(key, members); + } + }.run(key); + } + + @Override + public List geopos(final String key, final String... members) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.geopos(key, members); + } + }.run(key); + } + + @Override + public List georadius(final String key, final double longitude, + final double latitude, final double radius, final GeoUnit unit) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.georadius(key, longitude, latitude, radius, unit); + } + }.run(key); + } + + @Override + public List georadius(final String key, final double longitude, + final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.georadius(key, longitude, latitude, radius, unit, param); + } + }.run(key); + } + + @Override + public List georadiusByMember(final String key, final String member, + final double radius, final GeoUnit unit) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.georadiusByMember(key, member, radius, unit); + } + }.run(key); + } + + @Override + public List georadiusByMember(final String key, final String member, + final double radius, final GeoUnit unit, final GeoRadiusParam param) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.georadiusByMember(key, member, radius, unit, param); + } + }.run(key); + } + + @Override + public List bitfield(final String key, final String... arguments) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { + @Override + public List execute(Jedis connection) { + return connection.bitfield(key, arguments); + } + }.run(key); + } + + @Override + public Long hstrlen(final String key, final String field) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { + @Override + public Long execute(Jedis connection) { + return connection.hstrlen(key, field); + } + }.run(key); + } + + //暴露出Client, 方便上层解耦 + public Client getClient() { + + Jedis jedis = this.connectionHandler.getConnection(); + if (jedis != null) { + return jedis.getClient(); + } + return null; + } +} diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java new file mode 100644 index 000000000..ef2973500 --- /dev/null +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java @@ -0,0 +1,187 @@ +package com.fr.third.redis.clients.jedis; + +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.MESSAGE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.PMESSAGE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.PSUBSCRIBE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.PUNSUBSCRIBE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.SUBSCRIBE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.UNSUBSCRIBE; +import static com.fr.third.redis.clients.jedis.Protocol.Keyword.PONG; + +import java.util.Arrays; +import java.util.List; + +import com.fr.third.redis.clients.jedis.exceptions.JedisConnectionException; +import com.fr.third.redis.clients.jedis.exceptions.JedisException; +import com.fr.third.redis.clients.jedis.util.SafeEncoder; + +public abstract class JedisPubSub { + + private static final String JEDIS_SUBSCRIPTION_MESSAGE = "JedisPubSub is not subscribed to a Jedis instance."; + private int subscribedChannels = 0; + private volatile Client client; + + public JedisPubSub() { + + } + + public JedisPubSub(Client client) { + this.client = client; + } + + public void onMessage(String channel, String message) { + } + + public void onPMessage(String pattern, String channel, String message) { + } + + public void onSubscribe(String channel, int subscribedChannels) { + } + + public void onUnsubscribe(String channel, int subscribedChannels) { + } + + public void onPUnsubscribe(String pattern, int subscribedChannels) { + } + + public void onPSubscribe(String pattern, int subscribedChannels) { + } + + public void onPong(String pattern) { + + } + + public void unsubscribe() { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.unsubscribe(); + client.flush(); + } + + public void unsubscribe(String... channels) { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.unsubscribe(channels); + client.flush(); + } + + public void subscribe(String... channels) { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.subscribe(channels); + client.flush(); + } + + public void psubscribe(String... patterns) { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.psubscribe(patterns); + client.flush(); + } + + public void punsubscribe() { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.punsubscribe(); + client.flush(); + } + + public void punsubscribe(String... patterns) { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.punsubscribe(patterns); + client.flush(); + } + + public void ping() { + if (client == null) { + throw new JedisConnectionException(JEDIS_SUBSCRIPTION_MESSAGE); + } + client.ping(); + client.flush(); + } + + public boolean isSubscribed() { + return subscribedChannels > 0; + } + + public void proceedWithPatterns(Client client, String... patterns) { + this.client = client; + client.psubscribe(patterns); + client.flush(); + process(client); + } + + public void proceed(Client client, String... channels) { + this.client = client; + client.subscribe(channels); + client.flush(); + process(client); + } + + private void process(Client client) { + + do { + List reply = client.getRawObjectMultiBulkReply(); + final Object firstObj = reply.get(0); + if (!(firstObj instanceof byte[])) { + throw new JedisException("Unknown message type: " + firstObj); + } + final byte[] resp = (byte[]) firstObj; + if (Arrays.equals(SUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel); + onSubscribe(strchannel, subscribedChannels); + } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel); + onUnsubscribe(strchannel, subscribedChannels); + } else if (Arrays.equals(MESSAGE.raw, resp)) { + final byte[] bchannel = (byte[]) reply.get(1); + final byte[] bmesg = (byte[]) reply.get(2); + final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel); + final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg); + onMessage(strchannel, strmesg); + } else if (Arrays.equals(PMESSAGE.raw, resp)) { + final byte[] bpattern = (byte[]) reply.get(1); + final byte[] bchannel = (byte[]) reply.get(2); + final byte[] bmesg = (byte[]) reply.get(3); + final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern); + final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel); + final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg); + onPMessage(strpattern, strchannel, strmesg); + } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern); + onPSubscribe(strpattern, subscribedChannels); + } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern); + onPUnsubscribe(strpattern, subscribedChannels); + } else if (Arrays.equals(PONG.raw, resp)) { + final byte[] bpattern = (byte[]) reply.get(1); + final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern); + onPong(strpattern); + } else { + throw new JedisException("Unknown message type: " + firstObj); + } + } while (isSubscribed()); + + /* Invalidate instance since this thread is no longer listening */ + this.client = null; + } + + public int getSubscribedChannels() { + return subscribedChannels; + } +} From e9065db9555dc28aa65ec35998b4abf92398644d Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 26 May 2020 11:38:18 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1,=E5=8F=8D?= =?UTF-8?q?=E5=90=91=E5=90=88=E4=BB=A3=E7=A0=81=E5=BC=95=E8=B5=B7=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=88=E5=A0=B5=E5=A1=9E=E6=89=93=E5=8C=85?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/IncCell.java | 5 +- .../text/html/simpleparser/IncTable.java | 2 +- .../text/html/utils}/BackgroundUtil.java | 96 +++++++++---------- 3 files changed, 50 insertions(+), 53 deletions(-) rename {fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/html/Utils => fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils}/BackgroundUtil.java (94%) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java index 8b8318bb1..eaf6ec573 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java @@ -47,16 +47,13 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; -import com.fr.third.v2.lowagie.text.html.Utils.BackgroundUtil; +import com.fr.third.v2.lowagie.text.html.utils.BackgroundUtil; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import com.fr.third.v2.lowagie.text.Element; import com.fr.third.v2.lowagie.text.ElementListener; import com.fr.third.v2.lowagie.text.TextElementArray; import com.fr.third.v2.lowagie.text.html.CSSUtils; -import com.fr.third.v2.lowagie.text.html.Markup; import com.fr.third.v2.lowagie.text.pdf.PdfPCell; import com.fr.third.v2.lowagie.text.Phrase; diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java index 0e99b6d65..3fca955a7 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java @@ -48,7 +48,7 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; import com.fr.third.v2.lowagie.text.html.HtmlTags; -import com.fr.third.v2.lowagie.text.html.Utils.BackgroundUtil; +import com.fr.third.v2.lowagie.text.html.utils.BackgroundUtil; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; diff --git a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/html/Utils/BackgroundUtil.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java similarity index 94% rename from fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/html/Utils/BackgroundUtil.java rename to fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java index 61c0ce452..23cc892df 100644 --- a/fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/html/Utils/BackgroundUtil.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java @@ -1,48 +1,48 @@ -package com.fr.third.v2.lowagie.text.html.Utils; - -import com.fr.third.v2.lowagie.text.html.CSSUtils; -import com.fr.third.v2.lowagie.text.html.simpleparser.ChainedProperties; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Hugh.C - * @version 1.0 - * Created by Hugh.C on 2020/2/26 - */ -public class BackgroundUtil { - - public static Map parse2RulesMap(ChainedProperties props) { - Map backgroundRules = new HashMap(); - String value = props.getProperty("bgcolor"); - if (value != null) { - backgroundRules.put("background-color", value); - } - value = props.getLastChainProperty("background-size"); - if (value != null) { - backgroundRules.put("background-size", value); - } - value = props.getLastChainProperty("background"); - if (value != null) { - Map backgroundStyles = CSSUtils.processBackground(value); - backgroundRules.putAll(backgroundStyles); - } - value = props.getLastChainProperty("background-color"); - if (value != null) { - backgroundRules.put("background-color", value); - } - value = props.getLastChainProperty("background-position"); - if (value != null) { - backgroundRules.put("background-position", value); - } - value = props.getLastChainProperty("background-repeat"); - if (value != null) { - backgroundRules.put("background-repeat", value); - } - value = props.getLastChainProperty("background-image"); - if (value != null) { - backgroundRules.put("background-image", value); - } - return backgroundRules; - } -} +package com.fr.third.v2.lowagie.text.html.utils; + +import com.fr.third.v2.lowagie.text.html.CSSUtils; +import com.fr.third.v2.lowagie.text.html.simpleparser.ChainedProperties; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Hugh.C + * @version 1.0 + * Created by Hugh.C on 2020/2/26 + */ +public class BackgroundUtil { + + public static Map parse2RulesMap(ChainedProperties props) { + Map backgroundRules = new HashMap(); + String value = props.getProperty("bgcolor"); + if (value != null) { + backgroundRules.put("background-color", value); + } + value = props.getLastChainProperty("background-size"); + if (value != null) { + backgroundRules.put("background-size", value); + } + value = props.getLastChainProperty("background"); + if (value != null) { + Map backgroundStyles = CSSUtils.processBackground(value); + backgroundRules.putAll(backgroundStyles); + } + value = props.getLastChainProperty("background-color"); + if (value != null) { + backgroundRules.put("background-color", value); + } + value = props.getLastChainProperty("background-position"); + if (value != null) { + backgroundRules.put("background-position", value); + } + value = props.getLastChainProperty("background-repeat"); + if (value != null) { + backgroundRules.put("background-repeat", value); + } + value = props.getLastChainProperty("background-image"); + if (value != null) { + backgroundRules.put("background-image", value); + } + return backgroundRules; + } +} From 169df5bc7e94a740bda3d670d92793d111010aa7 Mon Sep 17 00:00:00 2001 From: zhouping Date: Tue, 26 May 2020 16:17:11 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20third?= =?UTF-8?q?=20pom=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base-third-project/base-third-step1/pom.xml | 1 + fine-deprecated-utils/pom.xml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 fine-deprecated-utils/pom.xml diff --git a/base-third-project/base-third-step1/pom.xml b/base-third-project/base-third-step1/pom.xml index 14a81fd5e..f4471e75e 100644 --- a/base-third-project/base-third-step1/pom.xml +++ b/base-third-project/base-third-step1/pom.xml @@ -51,6 +51,7 @@ ../../fine-org-dom4j ../../fine-roaringbitmap ../../fine-sense4 + ../../fine-deprecated-utils ../../fine-third-default ../../fine-third-jdk8 ../../fine-third-jdk11 diff --git a/fine-deprecated-utils/pom.xml b/fine-deprecated-utils/pom.xml new file mode 100644 index 000000000..9944cdff3 --- /dev/null +++ b/fine-deprecated-utils/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + com.fr.third + step1 + ${revision} + ../base-third-project/base-third-step1 + + + fine-deprecated-utils + ${revision} + + + \ No newline at end of file From 7c0d5b85533fb42f652b4da3c2df180c911f8d73 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 15 Jun 2020 14:11:28 +0800 Subject: [PATCH 04/17] =?UTF-8?q?REPORT-33569=20=E6=97=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6PDF=E5=AF=BC=E5=87=BA-HTML=E8=A7=A3=E6=9E=90=EF=BC=9A?= =?UTF-8?q?=E5=9D=97=E5=85=83=E7=B4=A0=EF=BC=88=E5=A6=82=EF=BC=9Adiv?= =?UTF-8?q?=E3=80=81p=EF=BC=89=E6=94=AF=E6=8C=81background-image=E3=80=81b?= =?UTF-8?q?ackground-size=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../html/simpleparser/FactoryProperties.java | 11 +++-- .../text/html/utils/BackgroundUtil.java | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index b2e3ccf4f..392465cb1 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -50,9 +50,11 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; +import com.fr.third.v2.lowagie.text.html.utils.BackgroundUtil; import java.awt.Color; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import com.fr.third.v2.lowagie.text.Chunk; @@ -134,9 +136,12 @@ public class FactoryProperties { else if (value.equalsIgnoreCase("justify")) p.setAlignment(Element.ALIGN_JUSTIFIED); } - if(props.hasPropertyInChain("div", "background")){ - p.setBackground(props.getPropertyFromChain("div", "background")); - } + Map bgAttrMap = BackgroundUtil.parseBgAttr4BlockTag(props); + if (null != bgAttrMap) { + for (Map.Entry entry : bgAttrMap.entrySet()) { + p.setAttribute(entry.getKey(), entry.getValue()); + } + } if(props.hasProperty("line-height")){ p.setAttribute("line-height", props.getProperty("line-height")); } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java index 23cc892df..040491656 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java @@ -45,4 +45,44 @@ public class BackgroundUtil { } return backgroundRules; } + + /** + * 将块元素的背景属性转换成mp + * + * @param props + * @return + */ + public static Map parseBgAttr4BlockTag(ChainedProperties props) { + Map backgroundRules = new HashMap(); + String value = props.getPropertyFromChain("div", "bgcolor"); + if (value != null) { + backgroundRules.put("background-color", value); + } + value = props.getPropertyFromChain("div", "background-size"); + if (value != null) { + backgroundRules.put("background-size", value); + } + value = props.getPropertyFromChain("div", "background"); + if (value != null) { + Map backgroundStyles = CSSUtils.processBackground(value); + backgroundRules.putAll(backgroundStyles); + } + value = props.getPropertyFromChain("div", "background-color"); + if (value != null) { + backgroundRules.put("background-color", value); + } + value = props.getPropertyFromChain("div", "background-position"); + if (value != null) { + backgroundRules.put("background-position", value); + } + value = props.getPropertyFromChain("div", "background-repeat"); + if (value != null) { + backgroundRules.put("background-repeat", value); + } + value = props.getPropertyFromChain("div", "background-image"); + if (value != null) { + backgroundRules.put("background-image", value); + } + return backgroundRules; + } } From f537d21d8d37b9f4cdcb712462a558ce8e10dca0 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 15 Jun 2020 15:12:14 +0800 Subject: [PATCH 05/17] =?UTF-8?q?REPORT-33569=20review=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java index 040491656..3e95ef0c9 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java @@ -54,7 +54,7 @@ public class BackgroundUtil { */ public static Map parseBgAttr4BlockTag(ChainedProperties props) { Map backgroundRules = new HashMap(); - String value = props.getPropertyFromChain("div", "bgcolor"); + String value = props.getPropertyFromChain("div", "background-color"); if (value != null) { backgroundRules.put("background-color", value); } @@ -67,10 +67,6 @@ public class BackgroundUtil { Map backgroundStyles = CSSUtils.processBackground(value); backgroundRules.putAll(backgroundStyles); } - value = props.getPropertyFromChain("div", "background-color"); - if (value != null) { - backgroundRules.put("background-color", value); - } value = props.getPropertyFromChain("div", "background-position"); if (value != null) { backgroundRules.put("background-position", value); From 76fbc091832c3697a5ae7693cd2e0ee28e08d51e Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 16 Jun 2020 16:39:36 +0800 Subject: [PATCH 06/17] =?UTF-8?q?REPORT-33031=20=E6=97=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6PDF=E5=AF=BC=E5=87=BA-HTML=E8=A7=A3=E6=9E=90=EF=BC=9A?= =?UTF-8?q?=E5=9D=97=E5=85=83=E7=B4=A0=EF=BC=88=E5=A6=82=EF=BC=9Adiv?= =?UTF-8?q?=E3=80=81p=EF=BC=89=E6=94=AF=E6=8C=81=20border=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E2=80=9C=E5=85=A8=E5=AE=B6=E6=A1=B6=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/lowagie/text/Paragraph.java | 11 ++ .../fr/third/v2/lowagie/text/html/Border.java | 39 ++++++ .../v2/lowagie/text/html/BorderAttribute.java | 124 ++++++++++++++++++ .../v2/lowagie/text/html/BorderEnum.java | 79 +++++++++++ .../fr/third/v2/lowagie/text/html/Markup.java | 105 +++++++++++++++ .../text/html/ParseIndentAttrUtils.java | 16 +++ .../html/simpleparser/ChainedProperties.java | 17 +++ .../html/simpleparser/FactoryProperties.java | 7 + .../text/html/simpleparser/HtmlConstants.java | 34 +++++ .../lowagie/text/html/utils/BorderUtils.java | 83 ++++++++++++ 10 files changed, 515 insertions(+) create mode 100644 fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Border.java create mode 100644 fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java create mode 100644 fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderEnum.java create mode 100644 fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BorderUtils.java diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/Paragraph.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/Paragraph.java index d26401cf6..43bb1e6de 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/Paragraph.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/Paragraph.java @@ -49,6 +49,7 @@ package com.fr.third.v2.lowagie.text; +import com.fr.third.v2.lowagie.text.html.BorderAttribute; import java.util.HashMap; /** @@ -110,6 +111,8 @@ public class Paragraph extends Phrase { protected HashMap attributes = new HashMap(); + private BorderAttribute borderAttr; + public HashMap getAttributes() { return attributes; } @@ -527,4 +530,12 @@ public class Paragraph extends Phrase { return this.background; } + public BorderAttribute getBorderAttr() { + return borderAttr; + } + + public void setBorderAttrs(BorderAttribute borderAttrs) { + this.borderAttr = borderAttrs; + } + } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Border.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Border.java new file mode 100644 index 000000000..c4a355a58 --- /dev/null +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Border.java @@ -0,0 +1,39 @@ +package com.fr.third.v2.lowagie.text.html; + +import java.awt.Color; + +/** + * @author Hugh.C + * @version 1.0 + * Created by Hugh.C on 2020/6/15 + */ +public class Border { + private float width; + private String style; + private Color color = Color.BLACK; + + public float getWidth() { + return width; + } + + public void setWidth(float width) { + this.width = width; + } + + public String getStyle() { + return style; + } + + public void setStyle(String style) { + this.style = style; + } + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } + +} diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java new file mode 100644 index 000000000..f3365be29 --- /dev/null +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java @@ -0,0 +1,124 @@ +package com.fr.third.v2.lowagie.text.html; + +import java.awt.Color; +import java.util.Map; + +/** + * @author Hugh.C + * @version 1.0 + * Created by Hugh.C on 2020/6/15 + */ +public class BorderAttribute { + protected Border top = new Border(); + protected Border right = new Border(); + protected Border bottom = new Border(); + protected Border left = new Border(); + + public Border getTop() { + return top; + } + + public void setTop(Border top) { + this.top = top; + } + + public Border getRight() { + return right; + } + + public void setRight(Border right) { + this.right = right; + } + + public Border getBottom() { + return bottom; + } + + public void setBottom(Border bottom) { + this.bottom = bottom; + } + + public Border getLeft() { + return left; + } + + public void setLeft(Border left) { + this.left = left; + } + + /** + * 将解析好的边框属性转化为 BorderAttribute + * + * @param map + * @return + */ + public BorderAttribute applyBorderAttr(Map map) { + if (null == map || map.isEmpty()) { + return this; + } + String topWidth = map.get(Markup.CSS_KEY_BORDERWIDTHTOP); + String style = map.get(Markup.CSS_KEY_BORDERSTYLETOP); + if (verify(topWidth, style)) { + Color color = Markup.decodeColor(map.get(Markup.CSS_KEY_BORDERCOLORTOP)); + top.setWidth(CSSUtils.parseFloat(topWidth)); + top.setStyle(style); + top.setColor(null == color ? Color.BLACK : color); + } + String rightWidth = map.get(Markup.CSS_KEY_BORDERWIDTHRIGHT); + style = map.get(Markup.CSS_KEY_BORDERSTYLERIGHT); + if (verify(rightWidth, style)) { + Color color = Markup.decodeColor(map.get(Markup.CSS_KEY_BORDERCOLORRIGHT)); + right.setWidth(CSSUtils.parseFloat(rightWidth)); + right.setStyle(style); + right.setColor(null == color ? Color.BLACK : color); + } + String bottomWidth = map.get(Markup.CSS_KEY_BORDERWIDTHBOTTOM); + style = map.get(Markup.CSS_KEY_BORDERSTYLEBOTTOM); + if (verify(bottomWidth, style)) { + Color color = Markup.decodeColor(map.get(Markup.CSS_KEY_BORDERCOLORBOTTOM)); + bottom.setWidth(CSSUtils.parseFloat(bottomWidth)); + bottom.setStyle(style); + bottom.setColor(null == color ? Color.BLACK : color); + } + String leftWidth = map.get(Markup.CSS_KEY_BORDERWIDTHLEFT); + style = map.get(Markup.CSS_KEY_BORDERSTYLELEFT); + if (verify(leftWidth, style)) { + Color color = Markup.decodeColor(map.get(Markup.CSS_KEY_BORDERCOLORLEFT)); + left.setWidth(CSSUtils.parseFloat(leftWidth)); + left.setStyle(style); + left.setColor(null == color ? Color.BLACK : color); + } + return this; + } + + /** + * 将边框属性 拼接成 html style 中的值 + * + * @return + */ + public String toStyleAttr() { + StringBuffer sb = new StringBuffer(); + sb.append(border2StyleAttr(Markup.CSS_KEY_BORDERTOP, top)).append(border2StyleAttr(Markup.CSS_KEY_BORDERRIGHT, right)) + .append(border2StyleAttr(Markup.CSS_KEY_BORDERBOTTOM, bottom)).append(border2StyleAttr(Markup.CSS_KEY_BORDERLEFT, left)); + return sb.toString(); + } + + private String border2StyleAttr(String key, Border border) { + if (!verify(border)) { + return ""; + } + Color color = null == border.getColor() ? Color.BLACK : border.getColor(); + StringBuilder sb = new StringBuilder(); + sb.append(key).append(":").append(border.getWidth()).append("px ") + .append(border.getStyle()).append(" ").append(null == color ? "" : "rgb(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ");"); + return sb.toString(); + } + + private boolean verify(String width, String style) { + return null != width && width.length() > 0 && null != style && style.length() > 0; + } + + private boolean verify(Border border) { + return null != border && border.getWidth() > 0 && null != border.getStyle(); + } +} diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderEnum.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderEnum.java new file mode 100644 index 000000000..034ebc1da --- /dev/null +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderEnum.java @@ -0,0 +1,79 @@ +package com.fr.third.v2.lowagie.text.html; + +import java.util.List; +import java.util.Map; + +/** + * @author Hugh.C + * @version 1.0 + * Created by Hugh.C on 2020/6/15 + */ +public enum BorderEnum { + TOP { + @Override + public void fillAttr(Map map, List borderAttr) { + map.put(Markup.CSS_KEY_BORDERWIDTHTOP, borderAttr.get(0)); + map.put(Markup.CSS_KEY_BORDERSTYLETOP, borderAttr.get(1)); + map.put(Markup.CSS_KEY_BORDERCOLORTOP, borderAttr.get(2)); + } + }, + RIGHT { + @Override + public void fillAttr(Map map, List borderAttr) { + map.put(Markup.CSS_KEY_BORDERWIDTHRIGHT, borderAttr.get(0)); + map.put(Markup.CSS_KEY_BORDERSTYLERIGHT, borderAttr.get(1)); + map.put(Markup.CSS_KEY_BORDERCOLORRIGHT, borderAttr.get(2)); + } + }, + BOTTOM { + @Override + public void fillAttr(Map map, List borderAttr) { + map.put(Markup.CSS_KEY_BORDERWIDTHBOTTOM, borderAttr.get(0)); + map.put(Markup.CSS_KEY_BORDERSTYLEBOTTOM, borderAttr.get(1)); + map.put(Markup.CSS_KEY_BORDERCOLORBOTTOM, borderAttr.get(2)); + } + }, + LEFT { + public void fillAttr(Map map, List borderAttr) { + map.put(Markup.CSS_KEY_BORDERWIDTHLEFT, borderAttr.get(0)); + map.put(Markup.CSS_KEY_BORDERSTYLELEFT, borderAttr.get(1)); + map.put(Markup.CSS_KEY_BORDERCOLORLEFT, borderAttr.get(2)); + } + }, + + DEFAULT { + @Override + public void fillAttr(Map map, List borderAttr) { + } + }; + + public static BorderEnum get(String str) { + switch (str) { + case Markup.CSS_KEY_BORDERTOP: + return TOP; + case Markup.CSS_KEY_BORDERRIGHT: + return RIGHT; + case Markup.CSS_KEY_BORDERBOTTOM: + return BOTTOM; + case Markup.CSS_KEY_BORDERLEFT: + return LEFT; + default: + return DEFAULT; + } + } + + public abstract void fillAttr(Map map, List borderAttr); + + public void dealAttr(Map map, List borderAttr) { + if (null == map || null == borderAttr || borderAttr.size() > 3 || borderAttr.size() < 2) { + return; + } + //保证 borderAttr 大小为3,即 线条粗细、样式、颜色都需要具备 + if (2 == borderAttr.size()) { + borderAttr.add("black"); + } + fillAttr(map,borderAttr); + } + + +} diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java index 133c20a32..b33b51b9f 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java @@ -53,7 +53,10 @@ package com.fr.third.v2.lowagie.text.html; import java.awt.Color; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; +import java.util.StringTokenizer; /** * A class that contains all the possible tagnames and their attributes. @@ -173,12 +176,40 @@ public class Markup { /** the CSS tag for the margin of an object */ public static final String CSS_KEY_PADDINGBOTTOM = "padding-bottom"; + public static final String CSS_KEY_BORDERTOP = "border-top"; + + public static final String CSS_KEY_BORDERRIGHT= "border-right"; + + public static final String CSS_KEY_BORDERBOTTOM= "border-bottom"; + + public static final String CSS_KEY_BORDERLEFT= "border-left"; + + public static final String CSS_KEY_BORDERSTYLETOP = "border-top-style"; + + public static final String CSS_KEY_BORDERSTYLERIGHT= "border-right-style"; + + public static final String CSS_KEY_BORDERSTYLEBOTTOM= "border-bottom-style"; + + public static final String CSS_KEY_BORDERSTYLELEFT= "border-left-style"; + + public static final String CSS_KEY_BORDERCOLORTOP = "border-top-color"; + + public static final String CSS_KEY_BORDERCOLORRIGHT= "border-right-color"; + + public static final String CSS_KEY_BORDERCOLORBOTTOM= "border-bottom-color"; + + public static final String CSS_KEY_BORDERCOLORLEFT= "border-left-color"; + + public static final String CSS_KEY_BORDER = "border"; + /** the CSS tag for the margin of an object */ public static final String CSS_KEY_BORDERCOLOR = "border-color"; /** the CSS tag for the margin of an object */ public static final String CSS_KEY_BORDERWIDTH = "border-width"; + public static final String CSS_KEY_BORDERSTYLE = "border-style"; + /** the CSS tag for the margin of an object */ public static final String CSS_KEY_BORDERWIDTHLEFT = "border-left-width"; @@ -507,4 +538,78 @@ public class Markup { return result.toString(); } + /** + * 解析类似于 border:1px solid #000 中的值 + * + * @param attr 如 1px solid #000 or 1px solid + * @return list: 按粗细、样式、颜色的顺序返回 ,没有则为null + */ + public static List parseBorderAttr(String attr) { + if (null == attr) { + return null; + } + List list = new ArrayList(3); + StringTokenizer st = new StringTokenizer(attr); + while (st.hasMoreElements()) { + list.add(st.nextToken()); + } + switch (list.size()) { + case 2: + // 如 border:1px solid ,则默认颜色为黑色 + list.add("black"); + break; + case 3: + // 如 border:1px solid black ,已经写全了,不用做额外的处理 + break; + default: + // 如 border:1px ,此时浏览器是无法识别的 + list = null; + break; + } + return list; + } + + /** + * 解析类似于 margin: 10px 5px 15px 20px,中的值 + * NESW:北东南西(上右下左) + * + * @param attr 如10px 5px 15px 20px + * @return list: 按上左下右的顺序存放 ,要么四个方位的值都存在,要么都不存在(返回null) + */ + public static List parseNESW(String attr) { + if (null == attr) { + return null; + } + List list = new ArrayList(4); + StringTokenizer st = new StringTokenizer(attr); + while (st.hasMoreElements()) { + list.add(st.nextToken()); + } + switch (list.size()) { + case 1: + //如 margin:1px ,代表上下左右 的margin值都是 1px + for (int i = 0; i < 3; i++) { + list.add(list.get(0)); + } + break; + case 2: + //如 margin:1px 2px ,代表上下方位的margin值为1px, 左右方位的margin值为 2px + list.add(list.get(0)); + list.add(list.get(1)); + break; + case 3: + //如 margin:1px 2px 3px ,代表上下方位的margin值分别为1px、3px, 左右方位的margin值为 2px + list.add(list.get(1)); + break; + case 4: + //如 margin:1px 2px 3px 4px,就不用管了 + break; + default: + //如 margin:1px 2px 3px 4px 5px,超了就违反了规则,在浏览器中该属性失效 + list = null; + break; + } + return list; + } + } \ No newline at end of file diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/ParseIndentAttrUtils.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/ParseIndentAttrUtils.java index e96b74d5c..852275e24 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/ParseIndentAttrUtils.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/ParseIndentAttrUtils.java @@ -71,6 +71,22 @@ public class ParseIndentAttrUtils { return indentAttribute; } + public static IndentAttribute parseBorderAttribute(BorderAttribute borderAttr) { + IndentAttribute widthAttr = new IndentAttribute(); + if (null == borderAttr) { + return widthAttr; + } + widthAttr.setTop(verify(borderAttr.getTop()) ? borderAttr.getTop().getWidth() : 0); + widthAttr.setRight(verify(borderAttr.getRight()) ? borderAttr.getRight().getWidth() : 0); + widthAttr.setBottom(verify(borderAttr.getBottom()) ? borderAttr.getBottom().getWidth() : 0); + widthAttr.setBottom(verify(borderAttr.getLeft()) ? borderAttr.getLeft().getWidth() : 0); + return widthAttr; + } + + private static boolean verify(Border border) { + return null != border && 0 < border.getWidth() && null != border.getStyle(); + } + public static void createIndent(StringBuffer stringBuffer, String attr, IndentAttribute indentAttribute){ stringBuffer.append(attr).append("-").append("left").append(":").append(indentAttribute.getLeft()).append("px;") .append(attr).append("-").append("right").append(":").append(indentAttribute.getRight()).append("px;") diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java index eb709e343..870741bf5 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/ChainedProperties.java @@ -77,6 +77,9 @@ public class ChainedProperties { } public String getLastChainProperty(String key){ + if (0 == chain.size()) { + return null; + } Object obj[] = (Object[]) chain.get(chain.size()-1); HashMap prop = (HashMap) obj[1]; return (String) prop.get(key); @@ -199,5 +202,19 @@ public class ChainedProperties { return false; } + /** + * 获取位于最后的块标签 + * + * @return + */ + public String getLastBlockTag() { + for (int i = chain.size() - 1; i >= 0; --i) { + Object obj[] = (Object[]) chain.get(i); + if (HtmlConstants.BLOCK_ELEMENTS.contains(obj[0])) { + return (String) obj[0]; + } + } + return null; + } } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index 392465cb1..50f7c1716 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -50,7 +50,9 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; +import com.fr.third.v2.lowagie.text.html.BorderAttribute; import com.fr.third.v2.lowagie.text.html.utils.BackgroundUtil; +import com.fr.third.v2.lowagie.text.html.utils.BorderUtils; import java.awt.Color; import java.util.HashMap; import java.util.Iterator; @@ -161,6 +163,11 @@ public class FactoryProperties { } } + String lastBlockTag = props.getLastBlockTag(); + //这里解析的背景属性不能是table标签的 + if (null != lastBlockTag && !HtmlTags.TABLE.equals(lastBlockTag)) { + p.setBorderAttrs(new BorderAttribute().applyBorderAttr(BorderUtils.parse2RulesMap(props, false))); + } if(props.hasPropertyInChain("div", "text-indent")){ String ss = props.getPropertyFromChain("div", "text-indent"); p.setFirstLineIndent(Markup.parseLength(ss)); diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java index 7a94e1d51..46757a8a9 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HtmlConstants.java @@ -11,6 +11,8 @@ import java.util.List; * @date 2018/5/2 */ public class HtmlConstants { + //表格相关标签集合 + public static final List TABLE_LABEL_GROUP = new ArrayList(); //块级元素集合 public static final List BLOCK_ELEMENTS = new ArrayList(); //行内元素集合 @@ -18,7 +20,17 @@ public class HtmlConstants { //支持解析的属性 public static final List PADDING = new ArrayList(); public static final List MARGIN = new ArrayList(); + //边框属性 + public static final List BORDER = new ArrayList(); + public static final List BORDER_WIDTH = new ArrayList(); + public static final List BORDER_STYLE = new ArrayList(); + public static final List BORDER_COLOR = new ArrayList(); static { + TABLE_LABEL_GROUP.add(HtmlTags.TABLE); + TABLE_LABEL_GROUP.add(HtmlTags.ROW); + TABLE_LABEL_GROUP.add(HtmlTags.CELL); + TABLE_LABEL_GROUP.add(HtmlTags.HEADERCELL); + BLOCK_ELEMENTS.add(HtmlTags.DIV); BLOCK_ELEMENTS.add(HtmlTags.UNORDEREDLIST); BLOCK_ELEMENTS.add(HtmlTags.PARAGRAPH); @@ -41,5 +53,27 @@ public class HtmlConstants { MARGIN.add(Markup.CSS_KEY_MARGINRIGHT); MARGIN.add(Markup.CSS_KEY_MARGINTOP); MARGIN.add(Markup.CSS_KEY_MARGINBOTTOM); + + + //按照上 右 下 左 的顺序排 + BORDER.add(Markup.CSS_KEY_BORDERTOP); + BORDER.add(Markup.CSS_KEY_BORDERRIGHT); + BORDER.add(Markup.CSS_KEY_BORDERBOTTOM); + BORDER.add(Markup.CSS_KEY_BORDERLEFT); + + BORDER_WIDTH.add(Markup.CSS_KEY_BORDERWIDTHTOP); + BORDER_WIDTH.add(Markup.CSS_KEY_BORDERWIDTHRIGHT); + BORDER_WIDTH.add(Markup.CSS_KEY_BORDERWIDTHBOTTOM); + BORDER_WIDTH.add(Markup.CSS_KEY_BORDERWIDTHLEFT); + + BORDER_STYLE.add(Markup.CSS_KEY_BORDERSTYLETOP); + BORDER_STYLE.add(Markup.CSS_KEY_BORDERSTYLERIGHT); + BORDER_STYLE.add(Markup.CSS_KEY_BORDERSTYLEBOTTOM); + BORDER_STYLE.add(Markup.CSS_KEY_BORDERSTYLELEFT); + + BORDER_COLOR.add(Markup.CSS_KEY_BORDERCOLORTOP); + BORDER_COLOR.add(Markup.CSS_KEY_BORDERCOLORRIGHT); + BORDER_COLOR.add(Markup.CSS_KEY_BORDERCOLORBOTTOM); + BORDER_COLOR.add(Markup.CSS_KEY_BORDERCOLORLEFT); } } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BorderUtils.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BorderUtils.java new file mode 100644 index 000000000..62fca479e --- /dev/null +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BorderUtils.java @@ -0,0 +1,83 @@ +package com.fr.third.v2.lowagie.text.html.utils; + + +import com.fr.third.v2.lowagie.text.html.BorderEnum; +import com.fr.third.v2.lowagie.text.html.HtmlTags; +import com.fr.third.v2.lowagie.text.html.Markup; +import com.fr.third.v2.lowagie.text.html.simpleparser.ChainedProperties; +import com.fr.third.v2.lowagie.text.html.simpleparser.HtmlConstants; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Hugh.C + * @version 1.0 + * Created by Hugh.C on 2020/5/27 + */ +public class BorderUtils { + + /** + * 解析border属性 + * + * @param props + * @param lastTag true:解析最后一个tag 的边框属性 + */ + public static Map parse2RulesMap(ChainedProperties props, boolean lastTag) { + Map map = new HashMap(); + String value = lastTag ? props.getLastChainProperty(Markup.CSS_KEY_BORDER) : props.getPropertyFromChain(HtmlTags.DIV, Markup.CSS_KEY_BORDER); + //解析 border + if (null != value) { + List list = Markup.parseBorderAttr(value); + for (BorderEnum border : BorderEnum.values()) { + border.dealAttr(map, list); + } + } + + //解析 border-width + parseBorderAttr(Markup.CSS_KEY_BORDERWIDTH, HtmlConstants.BORDER_WIDTH, map, props, lastTag); + //解析 border-style + parseBorderAttr(Markup.CSS_KEY_BORDERSTYLE, HtmlConstants.BORDER_STYLE, map, props, lastTag); + //解析 border-color + parseBorderAttr(Markup.CSS_KEY_BORDERCOLOR, HtmlConstants.BORDER_COLOR, map, props, lastTag); + + //解析 border-top|right|bottom|left + for (String border : HtmlConstants.BORDER) { + value = lastTag ? props.getLastChainProperty(border) : props.getPropertyFromChain(HtmlTags.DIV, border); + if (null != value) { + BorderEnum.get(border).dealAttr(map, Markup.parseBorderAttr(value)); + } + } + + //解析 border-top|right|bottom|left-width + parseBorderAttr(HtmlConstants.BORDER_WIDTH, map, props, lastTag); + //解析 border-top|right|bottom|left-style + parseBorderAttr(HtmlConstants.BORDER_STYLE, map, props, lastTag); + //解析 border-top|right|bottom|left-color + parseBorderAttr(HtmlConstants.BORDER_COLOR, map, props, lastTag); + return map; + } + + private static void parseBorderAttr(List attrKeys, Map map, ChainedProperties props, boolean lastTag) { + String value = null; + for (String key : attrKeys) { + value = lastTag ? props.getLastChainProperty(key) : props.getPropertyFromChain(HtmlTags.DIV, key); + if (null != value) { + map.put(key, value); + } + } + } + + private static void parseBorderAttr(String key, List attrKeys, Map map, ChainedProperties props, boolean lastTag) { + String value = lastTag ? props.getLastChainProperty(key) : props.getPropertyFromChain(HtmlTags.DIV, key); + if (null != value) { + List list = Markup.parseNESW(value); + if (null != list) { + for (int i = 0; i < attrKeys.size() && i < list.size(); i++) { + map.put(attrKeys.get(i), list.get(i)); + } + } + } + } + +} \ No newline at end of file From 252c889448d5082248441ed11a3a7830d5706c3e Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 16 Jun 2020 16:53:03 +0800 Subject: [PATCH 07/17] =?UTF-8?q?REPORT-33031=20review=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/lowagie/text/html/BorderAttribute.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java index f3365be29..6960b9318 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/BorderAttribute.java @@ -14,38 +14,20 @@ public class BorderAttribute { protected Border bottom = new Border(); protected Border left = new Border(); - public Border getTop() { - return top; - } - - public void setTop(Border top) { - this.top = top; - } + public Border getTop() { return top; } public Border getRight() { return right; } - public void setRight(Border right) { - this.right = right; - } - public Border getBottom() { return bottom; } - public void setBottom(Border bottom) { - this.bottom = bottom; - } - public Border getLeft() { return left; } - public void setLeft(Border left) { - this.left = left; - } - /** * 将解析好的边框属性转化为 BorderAttribute * From d9019364170813c89c174a39f05c85f3442fabb8 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Fri, 19 Jun 2020 16:05:16 +0800 Subject: [PATCH 08/17] =?UTF-8?q?REPORT-34112=20HTML=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=EF=BC=9Atable=E6=A0=87=E7=AD=BE=E6=94=AF=E6=8C=81table-layout?= =?UTF-8?q?=20=E4=B8=AD=E7=9A=84fixed=20=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/lowagie/text/html/CSS.java | 2 + .../text/html/simpleparser/IncCell.java | 1 + .../text/html/simpleparser/IncTable.java | 48 +++- .../third/v2/lowagie/text/pdf/PdfPCell.java | 20 ++ .../third/v2/lowagie/text/pdf/PdfPTable.java | 240 ++++++++++++++++++ .../v2/lowagie/text/pdf/TableProperties.java | 20 ++ 6 files changed, 325 insertions(+), 6 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java index 7b6f60330..3c408f3fd 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java @@ -195,6 +195,8 @@ public class CSS{ public static final String BOTTOM = "bottom"; public static final String FLOAT = "float"; public static final String DIRECTION = "direction"; + + public static final String TABLE_LAYOUT = "table_layout"; } } \ No newline at end of file diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java index eaf6ec573..8c8a8c2a3 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java @@ -107,6 +107,7 @@ public class IncCell implements TextElementArray { //解析td上声明的width value = props.getLastChainProperty("width"); if (value != null) { + cell.setOriginalStyleWidth(value); cell.setStyleWidth(CSSUtils.parseFloat(value)); } //解析td上声明的height diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java index 3fca955a7..3b6fa35da 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java @@ -110,19 +110,21 @@ public class IncTable { public PdfPTable buildTable() { if (rows.isEmpty()) return new PdfPTable(1); - int ncol = 0; ArrayList c0 = (ArrayList) rows.get(0); + String[] firstColWidths = new String[c0.size()]; for (int k = 0; k < c0.size(); ++k) { - ncol += ((PdfPCell) c0.get(k)).getColspan(); + firstColWidths[k] = ((PdfPCell) c0.get(k)).getOriginalStyleWidth(); } + int ncol = getMaxColCount(); processColWidth(ncol); PdfPTable table = new PdfPTable(ncol); try { TableProperties tableProperties = parseTableProperties(); table.setTableProperties(tableProperties); + table.setFirstColWidths(firstColWidths); //相对宽度 float[] floats = new float[relativeColWidths.size()]; @@ -148,19 +150,44 @@ public class IncTable { } } for (int row = 0; row < rows.size(); ++row) { - ArrayList col = (ArrayList)rows.get(row); + ArrayList col = (ArrayList) rows.get(row); for (int k = 0; k < col.size(); ++k) { - table.addCell((PdfPCell)col.get(k)); + table.addCell((PdfPCell) col.get(k)); + } + //补充空白列 + for (int i = 0; i < ncol - c0.size(); i++) { + PdfPCell pdfPCell = new PdfPCell(); + pdfPCell.setInvalid(true); + table.addCell(pdfPCell); } } - processRowHeight(table); + table.adjustFixedLayoutColumnWidth(); }catch (Exception e){ e.printStackTrace(); } return table; } + /** + * 获取最大列数 + * + * @return + */ + public int getMaxColCount() { + int max = 0; + for (int row = 0; row < rows.size(); ++row) { + ArrayList col = (ArrayList) rows.get(row); + int ncol = 0; + for (int k = 0; k < col.size(); ++k) { + ncol += ((PdfPCell) col.get(k)).getColspan(); + } + max = Math.max(ncol, max); + } + return max; + } + + /** * 调整列宽,每列取最大值 * @@ -177,7 +204,7 @@ public class IncTable { for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) { ArrayList cols = (ArrayList) rows.get(rowIndex); int colSpan = 1; - for (int colIndex = 0; colIndex < cols.size(); colIndex+=colSpan) { + for (int colIndex = 0; colIndex < cols.size(); colIndex += colSpan) { PdfPCell pCell = ((PdfPCell) cols.get(colIndex)); colSpan = pCell.getColspan(); float avgWidth = pCell.getStyleWidth() / colSpan; @@ -290,6 +317,15 @@ public class IncTable { if(value != null){ tableProperties.setCellpadding(CSSUtils.parseFloat(value)); } + value = (String) props.get("width"); + if (value != null) { + tableProperties.setStyleWidth(value); + } + value = (String) props.get("table-layout"); + if (value != null) { + tableProperties.setLayout(value); + } + ChainedProperties properties = new ChainedProperties(); properties.addToChain(HtmlTags.TABLE, props); //解析background相关属性 diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java index 102e4e9d7..edb23a080 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPCell.java @@ -71,6 +71,8 @@ public class PdfPCell extends Rectangle { private float styleWidth = 0.0f; private float styleHeight = 0.0f; + private String originalStyleWidth; + public float getStyleHeight() { return styleHeight; } @@ -85,6 +87,8 @@ public class PdfPCell extends Rectangle { public Map background ; + private boolean invalid = false; + public Map getBackground() { return background; } @@ -97,6 +101,21 @@ public class PdfPCell extends Rectangle { this.styleWidth = styleWidth; } + public String getOriginalStyleWidth() { + return originalStyleWidth; + } + + public void setOriginalStyleWidth(String originalStyleWidth) { + this.originalStyleWidth = originalStyleWidth; + } + + public boolean isInvalid() { + return invalid; + } + + public void setInvalid(boolean invalid) { + this.invalid = invalid; + } private ColumnText column = new ColumnText(null); @@ -291,6 +310,7 @@ public class PdfPCell extends Rectangle { background = cell.background; styleWidth = cell.styleWidth; styleHeight = cell.styleHeight; + invalid=cell.invalid; } /** diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java index 38d9a250f..76ee0b451 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java @@ -49,6 +49,8 @@ package com.fr.third.v2.lowagie.text.pdf; +import com.fr.third.v2.lowagie.text.html.CSS; +import com.fr.third.v2.lowagie.text.html.CSSUtils; import java.util.ArrayList; import com.fr.third.v2.lowagie.text.DocumentException; @@ -59,6 +61,7 @@ import com.fr.third.v2.lowagie.text.Image; import com.fr.third.v2.lowagie.text.Phrase; import com.fr.third.v2.lowagie.text.Rectangle; import com.fr.third.v2.lowagie.text.pdf.events.PdfPTableEventForwarder; +import java.util.List; /** * This is a table that can be put at an absolute position but can also @@ -105,6 +108,8 @@ public class PdfPTable implements LargeElement { protected PdfPTableEvent tableEvent; private TableProperties tableProperties; + private String[] firstColWidths; + public TableProperties getTableProperties() { return tableProperties; } @@ -113,6 +118,10 @@ public class PdfPTable implements LargeElement { this.tableProperties = tableProperties; } + public void setFirstColWidths(String[] firstColWidths) { + this.firstColWidths = firstColWidths; + } + /** * Holds value of property headerRows. */ @@ -369,14 +378,245 @@ public class PdfPTable implements LargeElement { return; this.totalWidth = totalWidth; totalHeight = 0; + if (adjustFixedLayoutColumnWidth()) { + return; + } calculateWidths(); // calculateHeights(true); + adjustRowWidth(); + } + + private void adjustRowWidth() { for (int k = 0; k < rows.size(); ++k) { PdfPRow row = (PdfPRow) rows.get(k); row.setWidths(absoluteWidths); } } + /** + * 计算非内容区域的宽度(边框+cellpadding+cellspacing) + * + * @return + */ + private float calOutOfContentWidth() { + int numCols = getNumberOfColumns(); + float borderWidth = tableProperties.getBorderWidth(); + return tableProperties.getCellspacing() * (numCols + 1) + numCols * 2 * (borderWidth + tableProperties.getCellpadding()) + 2 * borderWidth; + } + + /** + * 调整固定布局(table-layout:fixed )的列宽 + * + * @return false : 不符合table-layout:fixed 的定义 + */ + public boolean adjustFixedLayoutColumnWidth() { + if (!needFixedLayout()) { + return false; + } + //是fixed 布局 且设置了width(仅设置 table-layout:fixed 而不设置width 时 前台依旧使用的是auto 布局) + + //内容区域外的宽度 + float outOfContentWidth = calOutOfContentWidth(); + //实际内容宽度 + float contentWidth = totalWidth - outOfContentWidth; + + //重新初始化一下 + absoluteWidths = new float[relativeWidths.length]; + + if (dealFirstLineHasNoWidth(contentWidth)) { + adjustRowWidth(); + return true; + } + + //第一行列宽 + float[] colWidths = new float[firstColWidths.length]; + //绝对宽度和 + float absWidthSum = 0; + //相对宽度和 + float relWidthSum = 0; + //绝对宽度 (如 10px) 的索引 + ArrayList absIndex = new ArrayList(); + //相对宽度 (如 10%) 的索引 + ArrayList relIndex = new ArrayList(); + + //初始化一下上述字段 + for (int i = 0; i < firstColWidths.length; i++) { + float w = CSSUtils.parseFloat(firstColWidths[i]); + if (null != firstColWidths[i]) { + if (firstColWidths[i].endsWith("%")) { + w = w / 100 * contentWidth; + relWidthSum += w; + relIndex.add(i); + } else { + absWidthSum += w; + absIndex.add(i); + } + } + colWidths[i] = w; + } + + //第一行td中指定的绝对宽度 >= table标签上指定的宽度,以td的宽度为准,将table撑开 + if (absWidthSum >= contentWidth) { + for (int i = 0; i < absIndex.size(); i++) { + absoluteWidths[absIndex.get(i)] = colWidths[absIndex.get(i)]; + } + totalWidth = outOfContentWidth + absWidthSum; + dealInvalidCell(absIndex); + adjustRowWidth(); + return true; + } + + //table 总的列数 + int colNum = getNumberOfColumns(); + //相对宽度与绝对宽度的列数和 + int absAndRelColNum = absIndex.size() + relIndex.size(); + //相对宽度与绝对宽度的列宽和 + float absAndRelColWidthSum = absWidthSum + relWidthSum; + + //第一行td中指定的绝对宽度+相对宽度小于table内容宽度 + if (absAndRelColWidthSum < contentWidth) { + //剩余宽度 + float remaindWidth = contentWidth - absAndRelColWidthSum; + //如果总列数大于第一行绝对宽度和相对宽度列数,则多余的宽度由剩余列平分 + if (colNum > absAndRelColNum) { + fillAbsoluteWidths(colWidths, absIndex); + fillAbsoluteWidths(colWidths, relIndex); + float remaindAvgWidth = remaindWidth / (colNum - absAndRelColNum); + for (int i = 0; i < absoluteWidths.length; i++) { + if (absIndex.contains(i) || relIndex.contains(i)) { + continue; + } + absoluteWidths[i] = remaindAvgWidth; + } + } else { + //按比例分摊剩余宽度 + for (int i = 0; i < absIndex.size(); i++) { + float width = colWidths[absIndex.get(i)]; + absoluteWidths[absIndex.get(i)] = width + remaindWidth * width / absAndRelColWidthSum; + } + for (int i = 0; i < relIndex.size(); i++) { + float width = colWidths[relIndex.get(i)]; + absoluteWidths[relIndex.get(i)] = width + remaindWidth * width / absAndRelColWidthSum; + } + + dealInvalidCell(absIndex, relIndex); + } + + } else { + //第一行td中指定的绝对宽度+相对宽度大于table标签上指定的宽度,剩余宽度由相对宽度平分 + fillAbsoluteWidths(colWidths, absIndex); + //剩余宽度 + float remaindWidth = contentWidth - absWidthSum; + for (int i = 0; i < relIndex.size(); i++) { + float width = colWidths[relIndex.get(i)]; + absoluteWidths[relIndex.get(i)] = remaindWidth * width / relWidthSum; + } + dealInvalidCell(absIndex, relIndex); + } + adjustRowWidth(); + return true; + } + + private boolean needFixedLayout() { + return totalWidth > 0 && rows.size() > 0 && CSS.Value.FIXED.equals(tableProperties.getLayout()) && null != tableProperties.getStyleWidth(); + } + + /** + * 获取列索引List + */ + public List getColIndexList() { + List list = new ArrayList<>(absoluteWidths.length); + for (int i = 0; i < absoluteWidths.length; i++) { + list.add(i); + } + return list; + } + + /** + * 填充最终宽度 + * + * @param colWidths 列宽 + * @param indexList 要设置的列索引List + */ + private void fillAbsoluteWidths(float[] colWidths, ArrayList indexList) { + for (int i = 0; i < indexList.size() && i < absoluteWidths.length; i++) { + Integer index = indexList.get(i); + absoluteWidths[index] = colWidths[index]; + } + } + + /** + * validIndexList 之外的列对应的单元格设置为无效的 + * + * @param validIndexList + */ + private void dealInvalidCell(List... validIndexList) { + if (null == validIndexList) { + return; + } + //计算无效列索引 + List invalidIndexList = getColIndexList(); + + List list = new ArrayList(); + for (List item : validIndexList) { + list.addAll(item); + } + invalidIndexList.removeAll(list); + for (int row = 0; row < rows.size(); row++) { + PdfPRow pdfRow = (PdfPRow) rows.get(row); + int index = 0; + PdfPCell[] cells = pdfRow.getCells(); + for (PdfPCell cell : cells) { + if (cell == null) { + index += 1; + continue; + } + if (invalidIndexList.contains(index)) { + cell.setInvalid(true); + } + index += cell.getColspan(); + } + } + //将无效列的多余宽度平分给其他列 + dealInvalidColWidth(invalidIndexList.size(), list); + } + + /** + * 处理无效列的内容区域外的宽度(平分给其他列) + * + * @param invalidColNum + * @param validIndexList + */ + private void dealInvalidColWidth(int invalidColNum, List validIndexList) { + if (0 == invalidColNum || null == validIndexList || 0 == validIndexList.size()) { + return; + } + float invalidColWidth = invalidColNum * tableProperties.getCellspacing() + 2 * invalidColNum * (tableProperties.getCellpadding() + tableProperties.getBorderWidth()); + float avgWidth = invalidColWidth / validIndexList.size(); + for (int i = 0; i < validIndexList.size() && i < absoluteWidths.length; i++) { + Integer index = validIndexList.get(i); + absoluteWidths[index] += avgWidth; + } + } + + /** + * 处理第一行没有设置width属性情况 + * + * @param contentWidth 内容宽度 + * @return + */ + private boolean dealFirstLineHasNoWidth(float contentWidth) { + if (null != firstColWidths && 0 != firstColWidths.length) { + return false; + } + //第一行的td都没有设置width属性,则所有列平分table宽度 + int length = absoluteWidths.length; + for (int i = 0; i < length; i++) { + absoluteWidths[i] = contentWidth / length; + } + return true; + } + /** * Sets the full width of the table from the absolute column width. * diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/TableProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/TableProperties.java index a886f136e..6e46128f7 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/TableProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/TableProperties.java @@ -11,7 +11,11 @@ public class TableProperties { private float cellspacing = 2.0f; private float cellpadding = 1.0f; private boolean collapse = false; + public Map background; + private String styleWidth = null; + + private String layout = null; public BorderStyle getBorderStyle() { return borderStyle; @@ -57,6 +61,22 @@ public class TableProperties { this.background = background; } + public String getStyleWidth() { + return styleWidth; + } + + public void setStyleWidth(String styleWidth) { + this.styleWidth = styleWidth; + } + + public String getLayout() { + return layout; + } + + public void setLayout(String layout) { + this.layout = layout; + } + public String toHtmlString(){ StringBuffer sb = new StringBuffer(); if(!isCollapse()){ From 5adfbcee15fefc16d5dab91935ab80dd3c3873b3 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Fri, 19 Jun 2020 16:17:43 +0800 Subject: [PATCH 09/17] =?UTF-8?q?REPORT-34112=20=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java index 76ee0b451..d5c7e563e 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java @@ -539,7 +539,7 @@ public class PdfPTable implements LargeElement { * @param indexList 要设置的列索引List */ private void fillAbsoluteWidths(float[] colWidths, ArrayList indexList) { - for (int i = 0; i < indexList.size() && i < absoluteWidths.length; i++) { + for (int i = 0; i < indexList.size() && indexList.get(i) < absoluteWidths.length; i++) { Integer index = indexList.get(i); absoluteWidths[index] = colWidths[index]; } From 9b86d9aefc6f638baf7924642842ef007b92c126 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Fri, 19 Jun 2020 16:20:58 +0800 Subject: [PATCH 10/17] =?UTF-8?q?REPORT-34112=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java index 3c408f3fd..7b6f60330 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/CSS.java @@ -195,8 +195,6 @@ public class CSS{ public static final String BOTTOM = "bottom"; public static final String FLOAT = "float"; public static final String DIRECTION = "direction"; - - public static final String TABLE_LAYOUT = "table_layout"; } } \ No newline at end of file From 6e890ef1a73353097e1b5bbf795b90cedb0d79d1 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Fri, 19 Jun 2020 16:29:12 +0800 Subject: [PATCH 11/17] =?UTF-8?q?REPORT-34112=20=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java index d5c7e563e..5112c6b3c 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java @@ -498,8 +498,6 @@ public class PdfPTable implements LargeElement { float width = colWidths[relIndex.get(i)]; absoluteWidths[relIndex.get(i)] = width + remaindWidth * width / absAndRelColWidthSum; } - - dealInvalidCell(absIndex, relIndex); } } else { From 71ad6c59cf5b9756de8aa09354d04d0d15f297cd Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 23 Jun 2020 11:43:10 +0800 Subject: [PATCH 12/17] =?UTF-8?q?REPORT-34112=20review=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../text/html/simpleparser/IncTable.java | 35 +++++++++++++++---- .../fr/third/v2/lowagie/text/pdf/PdfPRow.java | 15 +++++++- .../third/v2/lowagie/text/pdf/PdfPTable.java | 33 +++++++++-------- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java index 3b6fa35da..9b580d395 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncTable.java @@ -112,10 +112,7 @@ public class IncTable { return new PdfPTable(1); ArrayList c0 = (ArrayList) rows.get(0); - String[] firstColWidths = new String[c0.size()]; - for (int k = 0; k < c0.size(); ++k) { - firstColWidths[k] = ((PdfPCell) c0.get(k)).getOriginalStyleWidth(); - } + List firstLineColWidths = getFirstLineColWidths(); int ncol = getMaxColCount(); processColWidth(ncol); @@ -124,7 +121,7 @@ public class IncTable { try { TableProperties tableProperties = parseTableProperties(); table.setTableProperties(tableProperties); - table.setFirstColWidths(firstColWidths); + table.setFirstLineColWidths(firstLineColWidths); //相对宽度 float[] floats = new float[relativeColWidths.size()]; @@ -151,11 +148,13 @@ public class IncTable { } for (int row = 0; row < rows.size(); ++row) { ArrayList col = (ArrayList) rows.get(row); + int colCount=0; for (int k = 0; k < col.size(); ++k) { table.addCell((PdfPCell) col.get(k)); + colCount += ((PdfPCell) col.get(k)).getColspan(); } //补充空白列 - for (int i = 0; i < ncol - c0.size(); i++) { + for (int i = 0; i < ncol - colCount; i++) { PdfPCell pdfPCell = new PdfPCell(); pdfPCell.setInvalid(true); table.addCell(pdfPCell); @@ -169,6 +168,30 @@ public class IncTable { return table; } + /** + * 获取第一行的列宽 + * + * @return + */ + private List getFirstLineColWidths() { + ArrayList c0 = (ArrayList) rows.get(0); + List firstLineColWidths = new ArrayList(); + for (int i = 0; i < c0.size(); i++) { + PdfPCell pdfPCell = (PdfPCell) c0.get(i); + String width = pdfPCell.getOriginalStyleWidth(); + if (null != width && 1 < pdfPCell.getColspan()) { + float w = CSSUtils.parseFloat(width); + //平分且需要保持原始的样式(有百分号的需要加上百分百) + w /= pdfPCell.getColspan(); + width = width.endsWith("%") ? String.valueOf(w) + "%" : String.valueOf(w); + } + for (int j = 0; j < pdfPCell.getColspan(); j++) { + firstLineColWidths.add(width); + } + } + return firstLineColWidths; + } + /** * 获取最大列数 * diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java index 466ee0df8..38a03958b 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPRow.java @@ -141,7 +141,7 @@ public class PdfPRow { * @param widths * @return true if everything went right */ - public boolean setWidths(float widths[]) { + public boolean setWidths(float widths[], TableProperties tablePropertie) { if (widths.length != cells.length) return false; System.arraycopy(widths, 0, this.widths, 0, cells.length); @@ -160,6 +160,19 @@ public class PdfPRow { for (; k < last; ++k) total += widths[k]; --k; + float borderWidth=0; + float cellspacing=0; + float cellpadding=0; + if (null != tablePropertie) { + borderWidth = tablePropertie.getBorderWidth(); + cellspacing = tablePropertie.getCellspacing(); + cellpadding = tablePropertie.getCellpadding(); + } + if (cell.getColspan() > 1) { + total += ((cell.getColspan() - 1) * 2 * borderWidth); + total += ((cell.getColspan() - 1) * cellspacing); + total += ((cell.getColspan() - 1) * 2 * cellpadding); + } cell.setRight(total); cell.setTop(0); processColWidth(cell.getColumn().getCompositeElements(), cell.getWidth()); diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java index 5112c6b3c..737b16303 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/pdf/PdfPTable.java @@ -108,7 +108,7 @@ public class PdfPTable implements LargeElement { protected PdfPTableEvent tableEvent; private TableProperties tableProperties; - private String[] firstColWidths; + private List firstLineColWidths; public TableProperties getTableProperties() { return tableProperties; @@ -118,8 +118,8 @@ public class PdfPTable implements LargeElement { this.tableProperties = tableProperties; } - public void setFirstColWidths(String[] firstColWidths) { - this.firstColWidths = firstColWidths; + public void setFirstLineColWidths(List firstLineColWidths) { + this.firstLineColWidths = firstLineColWidths; } /** @@ -389,7 +389,7 @@ public class PdfPTable implements LargeElement { private void adjustRowWidth() { for (int k = 0; k < rows.size(); ++k) { PdfPRow row = (PdfPRow) rows.get(k); - row.setWidths(absoluteWidths); + row.setWidths(absoluteWidths, tableProperties); } } @@ -400,8 +400,10 @@ public class PdfPTable implements LargeElement { */ private float calOutOfContentWidth() { int numCols = getNumberOfColumns(); - float borderWidth = tableProperties.getBorderWidth(); - return tableProperties.getCellspacing() * (numCols + 1) + numCols * 2 * (borderWidth + tableProperties.getCellpadding()) + 2 * borderWidth; + float allCellspacingWidth = tableProperties.getCellspacing() * (numCols + 1); + float allCellpaddingWidth = numCols * 2 * tableProperties.getCellpadding(); + float allCellBorderWidth = (numCols + 1) * 2 * tableProperties.getBorderWidth(); + return allCellspacingWidth + allCellpaddingWidth + allCellBorderWidth; } /** @@ -429,7 +431,7 @@ public class PdfPTable implements LargeElement { } //第一行列宽 - float[] colWidths = new float[firstColWidths.length]; + float[] colWidths = new float[firstLineColWidths.size()]; //绝对宽度和 float absWidthSum = 0; //相对宽度和 @@ -440,10 +442,11 @@ public class PdfPTable implements LargeElement { ArrayList relIndex = new ArrayList(); //初始化一下上述字段 - for (int i = 0; i < firstColWidths.length; i++) { - float w = CSSUtils.parseFloat(firstColWidths[i]); - if (null != firstColWidths[i]) { - if (firstColWidths[i].endsWith("%")) { + for (int i = 0; i < firstLineColWidths.size(); i++) { + String widthStr = firstLineColWidths.get(i); + float w = CSSUtils.parseFloat(widthStr); + if (null != widthStr) { + if (widthStr.endsWith("%")) { w = w / 100 * contentWidth; relWidthSum += w; relIndex.add(i); @@ -591,7 +594,7 @@ public class PdfPTable implements LargeElement { } float invalidColWidth = invalidColNum * tableProperties.getCellspacing() + 2 * invalidColNum * (tableProperties.getCellpadding() + tableProperties.getBorderWidth()); float avgWidth = invalidColWidth / validIndexList.size(); - for (int i = 0; i < validIndexList.size() && i < absoluteWidths.length; i++) { + for (int i = 0; i < validIndexList.size() && validIndexList.get(i) < absoluteWidths.length; i++) { Integer index = validIndexList.get(i); absoluteWidths[index] += avgWidth; } @@ -604,7 +607,7 @@ public class PdfPTable implements LargeElement { * @return */ private boolean dealFirstLineHasNoWidth(float contentWidth) { - if (null != firstColWidths && 0 != firstColWidths.length) { + if (null != firstLineColWidths && 0 != firstLineColWidths.size()) { return false; } //第一行的td都没有设置width属性,则所有列平分table宽度 @@ -747,7 +750,7 @@ public class PdfPTable implements LargeElement { } PdfPRow row = new PdfPRow(currentRow); if (totalWidth > 0) { - row.setWidths(absoluteWidths); + row.setWidths(absoluteWidths, tableProperties); // totalHeight += row.getMaxHeights(); } rows.add(row); @@ -1114,7 +1117,7 @@ public class PdfPTable implements LargeElement { if (row == null) return 0; if (firsttime) - row.setWidths(absoluteWidths); + row.setWidths(absoluteWidths, tableProperties); float height = row.getMaxHeights(); PdfPCell cell; PdfPRow tmprow; From a36c5ab62f31c3e3261cffd9143ca297060a2242 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Thu, 16 Jul 2020 10:03:47 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E5=90=88=E4=BB=A3=E7=A0=81=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/lowagie/text/html/simpleparser/FactoryProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index db5f11f90..6b17e07c6 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -174,7 +174,7 @@ public class FactoryProperties { p.setHyphenation(getHyphenation(props)); setParagraphLeading(p, props.getProperty("leading")); - String value = props.getProperty("before"); + value = props.getProperty("before"); if (value != null) { try { p.setSpacingBefore(Float.parseFloat(value)); From 5717264b7b9a5067dd558528b14ffff1ed695fd3 Mon Sep 17 00:00:00 2001 From: charile_Lu Date: Wed, 19 Aug 2020 16:05:10 +0800 Subject: [PATCH 14/17] =?UTF-8?q?DEC-14434=20=E6=B7=BB=E5=8A=A0=E4=BE=9D?= =?UTF-8?q?=E8=B3=B4=EF=BC=8C=E6=94=B9=E5=8F=98=E6=97=A5=E5=BF=97=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=8C=E8=A7=A3=E5=86=B3not=20found=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=E4=BF=AE=E6=94=B9=E6=8A=A5=E9=94=99=E7=9A=84JavaDoc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fine-quartz/pom.xml | 6 ++++++ .../fr/third/v2/org/quartz/core/QuartzSchedulerThread.java | 4 ++-- .../v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fine-quartz/pom.xml b/fine-quartz/pom.xml index 8aae0bf55..b6289d2e6 100644 --- a/fine-quartz/pom.xml +++ b/fine-quartz/pom.xml @@ -104,5 +104,11 @@ system ${basedir}/lib/quartz-stubs-2.1.7.jar + + com.fr.third + fine-jboss-logging + 10.0-FEATURE-SNAPSHOT + compile + \ No newline at end of file diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzSchedulerThread.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzSchedulerThread.java index 658001956..57e1b9619 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzSchedulerThread.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/core/QuartzSchedulerThread.java @@ -375,7 +375,7 @@ public class QuartzSchedulerThread extends Thread { shell = qsRsrcs.getJobRunShellFactory().createJobRunShell(bndle); shell.initialize(qs); } catch (SchedulerException se) { - org.jboss.logging.Logger.getLogger(getClass()).error("---------error occur in job run shell initialize, jobKey:"+triggers.get(i).getJobKey(), se); + com.fr.third.org.jboss.logging.Logger.getLogger(getClass()).error("---------error occur in job run shell initialize, jobKey:"+triggers.get(i).getJobKey(), se); qsRsrcs.getJobStore().triggeredJobComplete(triggers.get(i), bndle.getJobDetail(), CompletedExecutionInstruction.SET_ALL_JOB_TRIGGERS_ERROR); continue; } @@ -386,7 +386,7 @@ public class QuartzSchedulerThread extends Thread { // a thread pool being used concurrently - which the docs // say not to do... getLog().error("ThreadPool.runInThread() return false!"); - org.jboss.logging.Logger.getLogger(getClass()).error("---------error occur in job shell run in thread, jobKey:"+triggers.get(i).getJobKey()); + com.fr.third.org.jboss.logging.Logger.getLogger(getClass()).error("---------error occur in job shell run in thread, jobKey:"+triggers.get(i).getJobKey()); qsRsrcs.getJobStore().triggeredJobComplete(triggers.get(i), bndle.getJobDetail(), CompletedExecutionInstruction.SET_ALL_JOB_TRIGGERS_ERROR); } diff --git a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index d244f55e7..02809f73a 100644 --- a/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/fine-quartz/src/main/java/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -1417,7 +1417,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { return getDelegate().selectJobDetail(conn, key, getClassLoadHelper()); } catch (ClassNotFoundException e) { - org.jboss.logging.Logger.getLogger(getClass()).error("---------job class not found, jobKey: "+key, e); + com.fr.third.org.jboss.logging.Logger.getLogger(getClass()).error("---------job class not found, jobKey: "+key, e); throw new JobPersistenceException( "Couldn't retrieve job because a required class was not found: " + e.getMessage(), e); @@ -3746,7 +3746,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { * the a transaction template. If no return value is required, execute * should just return null. * - * @see JobStoreSupport#executeInNonManagedTXLock(String, TransactionCallback) + * @see JobStoreSupport#executeInNonManagedTXLock(String, TransactionCallback, TransactionValidator) * @see JobStoreSupport#executeInLock(String, TransactionCallback) * @see JobStoreSupport#executeWithoutLock(TransactionCallback) */ @@ -3762,7 +3762,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { * Implement this interface to provide the code to execute within * the a transaction template that has no return value. * - * @see JobStoreSupport#executeInNonManagedTXLock(String, TransactionCallback) + * @see JobStoreSupport#executeInNonManagedTXLock(String, TransactionCallback, TransactionValidator) */ protected abstract class VoidTransactionCallback implements TransactionCallback { public final Void execute(Connection conn) throws JobPersistenceException { From 84ce62fe9757a61a01d2d898f7145e61a112d82e Mon Sep 17 00:00:00 2001 From: charile_Lu Date: Wed, 19 Aug 2020 16:09:17 +0800 Subject: [PATCH 15/17] =?UTF-8?q?DEC-14434=20=E4=BF=AE=E6=94=B9pom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fine-quartz/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fine-quartz/pom.xml b/fine-quartz/pom.xml index b6289d2e6..7719dec29 100644 --- a/fine-quartz/pom.xml +++ b/fine-quartz/pom.xml @@ -107,8 +107,7 @@ com.fr.third fine-jboss-logging - 10.0-FEATURE-SNAPSHOT - compile + ${revision} \ No newline at end of file From 35baf8b7fe667ad354174905f89a50c7ab0e1ea7 Mon Sep 17 00:00:00 2001 From: charile_Lu Date: Thu, 27 Aug 2020 16:28:25 +0800 Subject: [PATCH 16/17] =?UTF-8?q?DEC-14765=20=E6=A0=B9=E6=8D=AE2.11.2?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E5=8A=A8patch=E5=85=B6static=E5=9D=97?= =?UTF-8?q?=E8=87=B3third=E5=BA=93=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsontype/impl/SubTypeValidator.java | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/fine-jackson/src/main/java/com/fr/third/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java b/fine-jackson/src/main/java/com/fr/third/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java index e2e52655b..f781a663e 100644 --- a/fine-jackson/src/main/java/com/fr/third/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java +++ b/fine-jackson/src/main/java/com/fr/third/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java @@ -48,12 +48,18 @@ public class SubTypeValidator // [databind#1737]; 3rd party //s.add("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor"); // deprecated by [databind#1855] s.add("org.springframework.beans.factory.config.PropertyPathFactoryBean"); + // [databind#2680] + s.add("org.springframework.aop.config.MethodLocatingFactoryBean"); + s.add("org.springframework.beans.factory.config.BeanReferenceFactoryBean"); // s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource"); // deprecated by [databind#1931] // s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource"); // - "" - // [databind#1855]: more 3rd party s.add("org.apache.tomcat.dbcp.dbcp2.BasicDataSource"); s.add("com.sun.org.apache.bcel.internal.util.ClassLoader"); + // [databind#1899]: more 3rd party + s.add("org.hibernate.jmx.StatisticsService"); + s.add("org.apache.ibatis.datasource.jndi.JndiDataSourceFactory"); // [databind#2032]: more 3rd party; data exfiltration via xml parsed ext entities s.add("org.apache.ibatis.parsing.XPathParser"); @@ -64,8 +70,8 @@ public class SubTypeValidator s.add("oracle.jdbc.connector.OracleManagedConnectionFactory"); s.add("oracle.jdbc.rowset.OracleJDBCRowSet"); // [databind#1899]: more 3rd party - s.add("org.hibernate.jmx.StatisticsService"); - s.add("org.apache.ibatis.datasource.jndi.JndiDataSourceFactory"); +// s.add("org.hibernate.jmx.StatisticsService"); +// s.add("org.apache.ibatis.datasource.jndi.JndiDataSourceFactory"); // [databind#2097]: some 3rd party, one JDK-bundled s.add("org.slf4j.ext.EventData"); @@ -77,6 +83,7 @@ public class SubTypeValidator s.add("org.jboss.util.propertyeditor.DocumentEditor"); s.add("org.apache.openjpa.ee.RegistryManagedRuntime"); s.add("org.apache.openjpa.ee.JNDIManagedRuntime"); + s.add("org.apache.openjpa.ee.WASRegistryManagedRuntime"); // [#2670] addition s.add("org.apache.axis2.transport.jms.JMSOutTransportInfo"); // [databind#2326] (2.9.9) @@ -108,8 +115,10 @@ public class SubTypeValidator s.add("org.apache.commons.configuration.JNDIConfiguration"); s.add("org.apache.commons.configuration2.JNDIConfiguration"); - // [databind#2469]: xalan2 + // [databind#2469]: xalan s.add("org.apache.xalan.lib.sql.JNDIConnectionPool"); + // [databind#2469]: xalan2 + s.add("com.sun.org.apache.xalan.internal.lib.sql.JNDIConnectionPool"); // [databind#2478]: comons-dbcp, p6spy s.add("org.apache.commons.dbcp.datasources.PerUserPoolDataSource"); @@ -137,6 +146,62 @@ public class SubTypeValidator // [databind#2642]: javax.swing (jdk) s.add("javax.swing.JEditorPane"); + // [databind#2648], [databind#2653]: shire-core + s.add("org.apache.shiro.realm.jndi.JndiRealmFactory"); + s.add("org.apache.shiro.jndi.JndiObjectFactory"); + + // [databind#2658]: ignite-jta (, quartz-core) + s.add("org.apache.ignite.cache.jta.jndi.CacheJndiTmLookup"); + s.add("org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory"); + s.add("org.quartz.utils.JNDIConnectionProvider"); + + // [databind#2659]: aries.transaction.jms + s.add("org.apache.aries.transaction.jms.internal.XaPooledConnectionFactory"); + s.add("org.apache.aries.transaction.jms.RecoverablePooledConnectionFactory"); + + // [databind#2660]: caucho-quercus + s.add("com.caucho.config.types.ResourceRef"); + + // [databind#2662]: aoju/bus-proxy + s.add("org.aoju.bus.proxy.provider.RmiProvider"); + s.add("org.aoju.bus.proxy.provider.remoting.RmiProvider"); + + // [databind#2664]: activemq-core, activemq-pool, activemq-pool-jms + + s.add("org.apache.activemq.ActiveMQConnectionFactory"); // core + s.add("org.apache.activemq.ActiveMQXAConnectionFactory"); + s.add("org.apache.activemq.spring.ActiveMQConnectionFactory"); + s.add("org.apache.activemq.spring.ActiveMQXAConnectionFactory"); + s.add("org.apache.activemq.pool.JcaPooledConnectionFactory"); // pool + s.add("org.apache.activemq.pool.PooledConnectionFactory"); + s.add("org.apache.activemq.pool.XaPooledConnectionFactory"); + s.add("org.apache.activemq.jms.pool.XaPooledConnectionFactory"); // pool-jms + s.add("org.apache.activemq.jms.pool.JcaPooledConnectionFactory"); + + // [databind#2666]: apache/commons-jms + s.add("org.apache.commons.proxy.provider.remoting.RmiProvider"); + + // [databind#2682]: commons-jelly + s.add("org.apache.commons.jelly.impl.Embedded"); + + // [databind#2688]: apache/drill + s.add("oadd.org.apache.xalan.lib.sql.JNDIConnectionPool"); + + // [databind#2698]: weblogic w/ oracle/aq-jms + // (note: dependency not available via Maven Central, but as part of + // weblogic installation, possibly fairly old version(s)) + s.add("oracle.jms.AQjmsQueueConnectionFactory"); + s.add("oracle.jms.AQjmsXATopicConnectionFactory"); + s.add("oracle.jms.AQjmsTopicConnectionFactory"); + s.add("oracle.jms.AQjmsXAQueueConnectionFactory"); + s.add("oracle.jms.AQjmsXAConnectionFactory"); + + // [databind#2764]: org.jsecurity: + s.add("org.jsecurity.realm.jndi.JndiRealmFactory"); + + // [databind#2798]: com.pastdev.httpcomponents: + s.add("com.pastdev.httpcomponents.configuration.JndiConfiguration"); + DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s); } From b3bc412c4a46267b13891216b1a68c59954f4443 Mon Sep 17 00:00:00 2001 From: Harder <171449363@qq.com> Date: Fri, 4 Sep 2020 17:53:30 +0800 Subject: [PATCH 17/17] fix --- .../openxml4j/opc/internal/PackagePropertiesPart.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index 661c1b080..4f9dbad37 100644 --- a/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/fine-poi/src/main/java/com/fr/third/v2/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -571,10 +571,11 @@ public final class PackagePropertiesPart extends PackagePart implements df.setTimeZone(LocaleUtil.TIMEZONE_UTC); d = df.parse(dateTzStr, new ParsePosition(0)); } - if (d == null) { - throw new InvalidFormatException("Date " + dateTzStr + " not well formated, " - + "expected format " + DEFAULT_DATEFORMAT + " or " + ALTERNATIVE_DATEFORMAT); - } + // BI-72094 先解决问题 + // if (d == null) { + // throw new InvalidFormatException("Date " + dateTzStr + " not well formated, " + // + "expected format " + DEFAULT_DATEFORMAT + " or " + ALTERNATIVE_DATEFORMAT); + // } return new Nullable(d); }