From a650a4f79149c168330a772580b3c63ce07295ba Mon Sep 17 00:00:00 2001 From: Oopsguy Date: Sun, 23 Dec 2018 22:00:10 +0800 Subject: [PATCH] Add javadoc plugin and example README.md --- kapcha-spring-boot-autoconfigure/pom.xml | 4 ++ kaptcha-spring-boot-parent/pom.xml | 6 +++ kaptcha-spring-boot-starter-example/README.md | 17 +++++++ .../google/code/kaptcha/NoiseProducer.java | 8 ++-- .../code/kaptcha/impl/DefaultNoise.java | 26 ++++++++--- .../com/google/code/kaptcha/util/Config.java | 45 +++++++++---------- .../code/kaptcha/util/ConfigException.java | 16 +++++++ .../code/kaptcha/util/ConfigHelper.java | 26 +++++++---- pom.xml | 36 +++++++-------- 9 files changed, 124 insertions(+), 60 deletions(-) create mode 100644 kaptcha-spring-boot-starter-example/README.md diff --git a/kapcha-spring-boot-autoconfigure/pom.xml b/kapcha-spring-boot-autoconfigure/pom.xml index f3a695e..3a7838c 100644 --- a/kapcha-spring-boot-autoconfigure/pom.xml +++ b/kapcha-spring-boot-autoconfigure/pom.xml @@ -33,6 +33,10 @@ javax.servlet javax.servlet-api + + javax.annotation + javax.annotation-api + diff --git a/kaptcha-spring-boot-parent/pom.xml b/kaptcha-spring-boot-parent/pom.xml index bc8650b..07fa851 100644 --- a/kaptcha-spring-boot-parent/pom.xml +++ b/kaptcha-spring-boot-parent/pom.xml @@ -41,6 +41,12 @@ 4.12 test + + + javax.annotation + javax.annotation-api + 1.3.2 + diff --git a/kaptcha-spring-boot-starter-example/README.md b/kaptcha-spring-boot-starter-example/README.md new file mode 100644 index 0000000..9b95de9 --- /dev/null +++ b/kaptcha-spring-boot-starter-example/README.md @@ -0,0 +1,17 @@ +# Kaptcha Spring Boot Starter Example + +This project is a demo based on Spring Boot, you can run it as a jar +or by following maven command: + +``` +mvn spring-boot:run +``` + +The project will run on port `8081`. + +You can view the results by browsing the links below: + + +- [`http://localhost:8081/index.html`](htpp://localhost:8081/index.html) +- [`http://localhost:8081/home/captcha`](htpp://localhost:8081/home/captcha) +- [`http://localhost:8081/captcha`](http://localhost:8081/captcha) \ No newline at end of file diff --git a/kaptcha/src/main/java/com/google/code/kaptcha/NoiseProducer.java b/kaptcha/src/main/java/com/google/code/kaptcha/NoiseProducer.java index d281a25..7420331 100644 --- a/kaptcha/src/main/java/com/google/code/kaptcha/NoiseProducer.java +++ b/kaptcha/src/main/java/com/google/code/kaptcha/NoiseProducer.java @@ -11,10 +11,10 @@ public interface NoiseProducer { * curve. * * @param image the image to add the noise to - * @param factorOne - * @param factorTwo - * @param factorThree - * @param factorFour + * @param factorOne factorOne + * @param factorTwo factorTwo + * @param factorThree factorThree + * @param factorFour factorFour */ public void makeNoise(BufferedImage image, float factorOne, float factorTwo, float factorThree, float factorFour); diff --git a/kaptcha/src/main/java/com/google/code/kaptcha/impl/DefaultNoise.java b/kaptcha/src/main/java/com/google/code/kaptcha/impl/DefaultNoise.java index 6bbee11..4259c80 100644 --- a/kaptcha/src/main/java/com/google/code/kaptcha/impl/DefaultNoise.java +++ b/kaptcha/src/main/java/com/google/code/kaptcha/impl/DefaultNoise.java @@ -1,3 +1,19 @@ +/** + * Copyright 2015-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.code.kaptcha.impl; import com.google.code.kaptcha.NoiseProducer; @@ -17,13 +33,13 @@ public class DefaultNoise extends Configurable implements NoiseProducer { /** * Draws a noise on the image. The noise curve depends on the factor values. - * Noise won't be visible if all factors have the value > 1.0f + * Noise won't be visible if all factors have the value > 1.0f * * @param image the image to add the noise to - * @param factorOne - * @param factorTwo - * @param factorThree - * @param factorFour + * @param factorOne factorOne + * @param factorTwo factorTwo + * @param factorThree factorThree + * @param factorFour factorFour */ public void makeNoise(BufferedImage image, float factorOne, float factorTwo, float factorThree, float factorFour) { diff --git a/kaptcha/src/main/java/com/google/code/kaptcha/util/Config.java b/kaptcha/src/main/java/com/google/code/kaptcha/util/Config.java index b8333af..387984b 100644 --- a/kaptcha/src/main/java/com/google/code/kaptcha/util/Config.java +++ b/kaptcha/src/main/java/com/google/code/kaptcha/util/Config.java @@ -1,3 +1,19 @@ +/** + * Copyright 2015-2018 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.code.kaptcha.util; import com.google.code.kaptcha.*; @@ -18,40 +34,34 @@ * specifies default values when no value is specified. */ public class Config { - /** */ + private Properties properties; - /** */ private ConfigHelper helper; - /** */ public Config(Properties properties) { this.properties = properties; this.helper = new ConfigHelper(); } - /** */ public boolean isBorderDrawn() { String paramName = Constants.KAPTCHA_BORDER; String paramValue = this.properties.getProperty(paramName); return this.helper.getBoolean(paramName, paramValue, true); } - /** */ public Color getBorderColor() { String paramName = Constants.KAPTCHA_BORDER_COLOR; String paramValue = this.properties.getProperty(paramName); return this.helper.getColor(paramName, paramValue, Color.BLACK); } - /** */ public int getBorderThickness() { String paramName = Constants.KAPTCHA_BORDER_THICKNESS; String paramValue = this.properties.getProperty(paramName); return this.helper.getPositiveInt(paramName, paramValue, 1); } - /** */ public Producer getProducerImpl() { String paramName = Constants.KAPTCHA_PRODUCER_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -59,7 +69,6 @@ public Producer getProducerImpl() { return producer; } - /** */ public TextProducer getTextProducerImpl() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -68,21 +77,18 @@ public TextProducer getTextProducerImpl() { return textProducer; } - /** */ public char[] getTextProducerCharString() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING; String paramValue = this.properties.getProperty(paramName); return this.helper.getChars(paramName, paramValue, "abcde2345678gfynmnpwx".toCharArray()); } - /** */ public int getTextProducerCharLength() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH; String paramValue = this.properties.getProperty(paramName); return this.helper.getPositiveInt(paramName, paramValue, 5); } - /** */ public Font[] getTextProducerFonts(int fontSize) { String paramName = Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES; String paramValue = this.properties.getProperty(paramName); @@ -91,28 +97,24 @@ public Font[] getTextProducerFonts(int fontSize) { }); } - /** */ public int getTextProducerFontSize() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE; String paramValue = this.properties.getProperty(paramName); return this.helper.getPositiveInt(paramName, paramValue, 40); } - /** */ public Color getTextProducerFontColor() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR; String paramValue = this.properties.getProperty(paramName); return this.helper.getColor(paramName, paramValue, Color.BLACK); } - /** */ public int getTextProducerCharSpace() { String paramName = Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE; String paramValue = properties.getProperty(paramName); return this.helper.getPositiveInt(paramName, paramValue, 2); } - /** */ public NoiseProducer getNoiseImpl() { String paramName = Constants.KAPTCHA_NOISE_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -121,14 +123,12 @@ public NoiseProducer getNoiseImpl() { return noiseProducer; } - /** */ public Color getNoiseColor() { String paramName = Constants.KAPTCHA_NOISE_COLOR; String paramValue = this.properties.getProperty(paramName); return this.helper.getColor(paramName, paramValue, Color.BLACK); } - /** */ public GimpyEngine getObscurificatorImpl() { String paramName = Constants.KAPTCHA_OBSCURIFICATOR_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -136,7 +136,6 @@ public GimpyEngine getObscurificatorImpl() { return gimpyEngine; } - /** */ public WordRenderer getWordRendererImpl() { String paramName = Constants.KAPTCHA_WORDRENDERER_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -145,7 +144,6 @@ public WordRenderer getWordRendererImpl() { return wordRenderer; } - /** */ public BackgroundProducer getBackgroundImpl() { String paramName = Constants.KAPTCHA_BACKGROUND_IMPL; String paramValue = this.properties.getProperty(paramName); @@ -154,28 +152,24 @@ public BackgroundProducer getBackgroundImpl() { return backgroundProducer; } - /** */ public Color getBackgroundColorFrom() { String paramName = Constants.KAPTCHA_BACKGROUND_CLR_FROM; String paramValue = this.properties.getProperty(paramName); return this.helper.getColor(paramName, paramValue, Color.LIGHT_GRAY); } - /** */ public Color getBackgroundColorTo() { String paramName = Constants.KAPTCHA_BACKGROUND_CLR_TO; String paramValue = this.properties.getProperty(paramName); return this.helper.getColor(paramName, paramValue, Color.WHITE); } - /** */ public int getWidth() { String paramName = Constants.KAPTCHA_IMAGE_WIDTH; String paramValue = this.properties.getProperty(paramName); return this.helper.getPositiveInt(paramName, paramValue, 200); } - /** */ public int getHeight() { String paramName = Constants.KAPTCHA_IMAGE_HEIGHT; String paramValue = this.properties.getProperty(paramName); @@ -185,6 +179,8 @@ public int getHeight() { /** * Allows one to override the key name which is stored in the users * HttpSession. Defaults to Constants.KAPTCHA_SESSION_KEY. + * + * @return session key */ public String getSessionKey() { return this.properties.getProperty(Constants.KAPTCHA_SESSION_CONFIG_KEY, Constants.KAPTCHA_SESSION_KEY); @@ -193,12 +189,13 @@ public String getSessionKey() { /** * Allows one to override the date name which is stored in the * users HttpSession. Defaults to Constants.KAPTCHA_SESSION_KEY. + * + * @return session date */ public String getSessionDate() { return this.properties.getProperty(Constants.KAPTCHA_SESSION_CONFIG_DATE, Constants.KAPTCHA_SESSION_DATE); } - /** */ public Properties getProperties() { return this.properties; } diff --git a/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigException.java b/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigException.java index 82db800..c522a87 100644 --- a/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigException.java +++ b/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigException.java @@ -1,3 +1,19 @@ +/** + * Copyright 2015-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.code.kaptcha.util; /** diff --git a/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigHelper.java b/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigHelper.java index 5516b7e..8c1a979 100644 --- a/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigHelper.java +++ b/kaptcha/src/main/java/com/google/code/kaptcha/util/ConfigHelper.java @@ -1,3 +1,19 @@ +/** + * Copyright 2015-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.code.kaptcha.util; import java.awt.*; @@ -8,7 +24,7 @@ * This class provides helper methods in parsing configuration values. */ public class ConfigHelper { - /** */ + public Color getColor(String paramName, String paramValue, Color defaultColor) { Color color; @@ -22,7 +38,6 @@ public Color getColor(String paramName, String paramValue, return color; } - /** */ public Color createColorFromCommaSeparatedValues(String paramName, String paramValue) { Color color; @@ -50,7 +65,6 @@ public Color createColorFromCommaSeparatedValues(String paramName, return color; } - /** */ public Color createColorFromFieldValue(String paramName, String paramValue) { Color color; try { @@ -66,7 +80,6 @@ public Color createColorFromFieldValue(String paramName, String paramValue) { return color; } - /** */ public Object getClassInstance(String paramName, String paramValue, Object defaultInstance, Config config) { Object instance; @@ -89,7 +102,6 @@ public Object getClassInstance(String paramName, String paramValue, return instance; } - /** */ public Font[] getFonts(String paramName, String paramValue, int fontSize, Font[] defaultFonts) { Font[] fonts; @@ -105,7 +117,6 @@ public Font[] getFonts(String paramName, String paramValue, int fontSize, return fonts; } - /** */ public int getPositiveInt(String paramName, String paramValue, int defaultInt) { int intValue; @@ -125,7 +136,6 @@ public int getPositiveInt(String paramName, String paramValue, return intValue; } - /** */ public char[] getChars(String paramName, String paramValue, char[] defaultChars) { char[] chars; @@ -137,7 +147,6 @@ public char[] getChars(String paramName, String paramValue, return chars; } - /** */ public boolean getBoolean(String paramName, String paramValue, boolean defaultValue) { boolean booleanValue; @@ -153,7 +162,6 @@ public boolean getBoolean(String paramName, String paramValue, return booleanValue; } - /** */ private void setConfigurable(Object object, Config config) { if (object instanceof Configurable) { ((Configurable) object).setConfig(config); diff --git a/pom.xml b/pom.xml index b8d14ad..8bf720c 100644 --- a/pom.xml +++ b/pom.xml @@ -93,24 +93,24 @@ - - - - - - - - - - - - - - - - - - + + org.apache.maven.plugins + maven-javadoc-plugin + + + package + + jar + + + + + UTF-8 + UTF-8 + UTF-8 + ${java.home}/bin/javadoc + + org.apache.maven.plugins maven-gpg-plugin