Skip to content

Commit 6a1a131

Browse files
authored
Merge pull request #4 from shootercheng/main
update readme
2 parents aae3f53 + b3ebaaf commit 6a1a131

File tree

9 files changed

+334
-19
lines changed

9 files changed

+334
-19
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
88
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.github.catdou/param-validator/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.catdou/param-validator)
99

10-
demo project
10+
## demo project
11+
### SpringBoot
1112
[https://github.com/shootercheng/param-validator-demo](https://github.com/shootercheng/param-validator-demo)
13+
### web.xml
14+
[https://github.com/shootercheng/ssm_shiro_blog](https://github.com/shootercheng/ssm_shiro_blog)
1215

1316
## Maven
1417
```xml

src/main/java/org/catdou/validate/cache/ValidatorCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author James
2929
*/
3030
public class ValidatorCache {
31-
private Map<String, ParamValidator> paramValidatorMap = new ConcurrentHashMap<>();
31+
private Map<String, ParamValidator> paramValidatorMap = new ConcurrentHashMap<>(256);
3232

3333
public ValidatorCache() {
3434
add(ValidatorType.REGEXP.name(), new RegexpValidator());

src/main/java/org/catdou/validate/factory/JsonConfigLoader.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.catdou.validate.factory;
1818

1919
import com.alibaba.fastjson.JSONObject;
20-
import org.apache.commons.io.FileUtils;
2120
import org.catdou.validate.constant.ParamValidatorConstants;
22-
import org.catdou.validate.exception.ConfigException;
2321
import org.catdou.validate.exception.ParseException;
2422
import org.catdou.validate.io.FileResourcesUtils;
2523
import org.catdou.validate.log.ValidatorLog;
@@ -29,9 +27,7 @@
2927
import org.catdou.validate.model.config.UrlRuleBean;
3028
import org.springframework.core.io.Resource;
3129

32-
import java.io.File;
3330
import java.io.IOException;
34-
import java.nio.charset.StandardCharsets;
3531
import java.util.List;
3632

3733
/**

src/main/java/org/catdou/validate/util/HttpUtil.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.alibaba.fastjson.JSON;
2020
import org.apache.commons.lang3.exception.ExceptionUtils;
21-
import org.catdou.validate.constant.ParamValidatorConstants;
2221
import org.catdou.validate.log.ValidatorLog;
2322
import org.catdou.validate.log.ValidatorLogFactory;
2423
import org.catdou.validate.model.url.UrlPath;
@@ -61,19 +60,18 @@ public static UrlPath getUrlPath(String url) {
6160
int moveIndex = 0;
6261
UrlPath urlPath = new UrlPath();
6362
while (moveIndex < lenu && moveIndex != -1) {
64-
int temp = moveIndex;
6563
int next = -1;
66-
if (urlArr[temp] == ParamValidatorConstants.URL_SLASH) {
67-
next = findNext(temp + 1, urlArr, lenu);
64+
if (urlArr[moveIndex] == URL_SLASH) {
65+
next = findNext(moveIndex + 1, urlArr, lenu);
6866
}
69-
if (temp + 1 == next) {
67+
if (moveIndex + 1 == next) {
7068
LOGGER.debug("find two slash //");
7169
} else {
7270
String pathItem;
7371
if (next != -1) {
74-
pathItem = url.substring(temp + 1, next);
72+
pathItem = url.substring(moveIndex + 1, next);
7573
} else {
76-
pathItem = url.substring(temp + 1);
74+
pathItem = url.substring(moveIndex + 1);
7775
}
7876
urlPath.getPaths().add(pathItem);
7977
if (pathItem.startsWith(PATH_LEFT) && pathItem.endsWith(PATH_RIGHT)) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2021 catdou
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package scd.cache;
18+
19+
import org.catdou.validate.cache.ValidatorCache;
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import scd.util.define.DefineParamValidator;
23+
24+
/**
25+
* @author James
26+
*/
27+
public class ValidatorCacheTest {
28+
private ValidatorCache validatorCache = new ValidatorCache();
29+
30+
@Test
31+
public void testAdd() {
32+
validatorCache.add(DefineParamValidator.class.getName(), new DefineParamValidator());
33+
Assert.assertTrue(validatorCache.getParamValidatorMap().size() > 0);
34+
Object defineParamValidator = validatorCache.getParamValidatorMap().get(DefineParamValidator.class.getName());
35+
Assert.assertTrue(defineParamValidator instanceof DefineParamValidator);
36+
}
37+
}

src/test/java/scd/str/pattern/PathUrlTest.java renamed to src/test/java/scd/logger/JdkLoggerTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,28 @@
1414
* limitations under the License.
1515
*/
1616

17-
package scd.str.pattern;
17+
package scd.logger;
1818

19-
import org.catdou.validate.model.url.UrlPath;
20-
import org.catdou.validate.util.HttpUtil;
21-
import org.junit.Assert;
19+
import org.catdou.validate.log.jdk.JdkLogger;
20+
import org.junit.Before;
2221
import org.junit.Test;
2322

2423
/**
2524
* @author James
2625
*/
27-
public class PathUrlTest {
26+
public class JdkLoggerTest {
27+
private JdkLogger jdkLogger;
2828

29+
@Before
30+
public void before() {
31+
jdkLogger = new JdkLogger(JdkLoggerTest.class);
32+
}
33+
34+
@Test
35+
public void testLog() {
36+
jdkLogger.debug("hello ");
37+
jdkLogger.warn("hello ");
38+
jdkLogger.info("hello ");
39+
jdkLogger.error("hello ");
40+
}
2941
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021 catdou
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package scd.logger;
18+
19+
import org.catdou.validate.log.ValidatorLogFactory;
20+
import org.catdou.validate.log.slf4j.Slf4jLogger;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
24+
/**
25+
* @author James
26+
*/
27+
public class Slf4jLoggerTest {
28+
private Slf4jLogger slf4jLogger;
29+
30+
@Before
31+
public void before() {
32+
slf4jLogger = new Slf4jLogger(Slf4jLoggerTest.class);
33+
}
34+
35+
@Test
36+
public void testLog() {
37+
slf4jLogger.debug("hello ");
38+
slf4jLogger.warn("hello ");
39+
slf4jLogger.info("hello ");
40+
slf4jLogger.error("hello ");
41+
}
42+
}

0 commit comments

Comments
 (0)