+ * formatter for NgxEntry + *
+ * @author ${Author} + * @version ${Version} + * @since 8.1.0 + * + */ +public interface EntryFormatter{ + + StringBuffer formattedText(NgxEntry entry); + + NgxEntryType[] supportedEntryTypes(); +} diff --git a/src/main/java/com/github/odiszapc/common/formatter/FormatterRepository.java b/src/main/java/com/github/odiszapc/common/formatter/FormatterRepository.java new file mode 100644 index 0000000..c9bd265 --- /dev/null +++ b/src/main/java/com/github/odiszapc/common/formatter/FormatterRepository.java @@ -0,0 +1,94 @@ +package com.github.odiszapc.common.formatter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.github.odiszapc.common.formatter.impl.DefaultEntryFormatter; +import com.github.odiszapc.common.formatter.impl.NgxBlockFormatter; +import com.github.odiszapc.common.formatter.impl.NgxConfigFormatter; +import com.github.odiszapc.nginxparser.NgxEntry; +import com.github.odiszapc.nginxparser.NgxEntryType; + +public class FormatterRepository { + + private static final EntryFormatter NULL_INDENT_SETTABLE_FORMATTER = new NullEntryFormatter(); + private Map+ * common util for NgxEntry + *
+ * @author ${Author} + * @version ${Version} + * + */ +public class NgxEntrys { + + private static final NgxEntrySerializer serializer = new DefaultNgxEntrySerializer(); + + /** + * + *+ * parse a object to NgxEntry + *
+ * @param obj + * @return + */ + public static NgxEntry parse(Object obj) { + if (obj == null) { + throw new IllegalArgumentException("obj should not be null"); + } + return serializer.serialize(null, obj); + } + +} diff --git a/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxTokenValue.java b/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxTokenValue.java new file mode 100644 index 0000000..366b06f --- /dev/null +++ b/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxTokenValue.java @@ -0,0 +1,13 @@ +package com.github.odiszapc.nginxparser.annotation; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface NgxTokenValue { + +} diff --git a/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxType.java b/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxType.java new file mode 100644 index 0000000..2907726 --- /dev/null +++ b/src/main/java/com/github/odiszapc/nginxparser/annotation/NgxType.java @@ -0,0 +1,12 @@ +package com.github.odiszapc.nginxparser.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface NgxType { + String name() default "name"; +} diff --git a/src/test/java/com/github/odiszapc/nginxparser/NgxEntrysTest.java b/src/test/java/com/github/odiszapc/nginxparser/NgxEntrysTest.java new file mode 100644 index 0000000..65ce4ca --- /dev/null +++ b/src/test/java/com/github/odiszapc/nginxparser/NgxEntrysTest.java @@ -0,0 +1,36 @@ +package com.github.odiszapc.nginxparser; + +import java.util.Collection; + +import org.junit.Assert; +import org.junit.Test; + +import com.github.odiszapc.nginxparser.annotation.NgxTokenValue; + +public class NgxEntrysTest { + + @Test + public void testParse() { + Server testObj = new Server(); + testObj.realm = "*"; + testObj.listen = "80"; + testObj.serverName = "localhost"; + NgxEntry result = NgxEntrys.parse(testObj); + TestUtils.assertBlock(result, "server", testObj.realm); + NgxBlock resultBlock = (NgxBlock) result; + Collection