diff --git a/cms-server/hosts/demo/modules_data/moduleconfiguration.json b/cms-server/hosts/demo/modules_data/moduleconfiguration.json index 96dde16c..5c66505c 100644 --- a/cms-server/hosts/demo/modules_data/moduleconfiguration.json +++ b/cms-server/hosts/demo/modules_data/moduleconfiguration.json @@ -1 +1 @@ -{"modules":{"flexmark-module":{"active":false,"id":"flexmark-module","moduleDir":"flexmark-module"},"thymeleaf-module":{"active":true,"id":"thymeleaf-module","moduleDir":"thymeleaf-module"},"freemarker-module":{"active":false,"id":"freemarker-module","moduleDir":"freemarker-module"},"pug-module":{"active":false,"id":"pug-module","moduleDir":"pug-module"},"pebble-module":{"active":false,"id":"pebble-module","moduleDir":"pebble-module"},"example-module":{"active":true,"id":"example-module","moduleDir":"example-module"},"markedjs-module":{"active":true,"id":"markedjs-module","moduleDir":"markedjs-module"}}} \ No newline at end of file +{"modules":{"flexmark-module":{"active":false,"id":"flexmark-module","moduleDir":"flexmark-module"},"thymeleaf-module":{"active":true,"id":"thymeleaf-module","moduleDir":"thymeleaf-module"},"freemarker-module":{"active":false,"id":"freemarker-module","moduleDir":"freemarker-module"},"pug-module":{"active":false,"id":"pug-module","moduleDir":"pug-module"},"ui-module":{"active":false,"id":"ui-module","moduleDir":"ui-module"},"pebble-module":{"active":false,"id":"pebble-module","moduleDir":"pebble-module"},"example-module":{"active":true,"id":"example-module","moduleDir":"example-module"},"markedjs-module":{"active":true,"id":"markedjs-module","moduleDir":"markedjs-module"}}} \ No newline at end of file diff --git a/cms-server/hosts/demo/modules_data/ui-module/configuration.properties b/cms-server/hosts/demo/modules_data/ui-module/configuration.properties new file mode 100644 index 00000000..e69de29b diff --git a/cms-server/hosts/demo/site.yaml b/cms-server/hosts/demo/site.yaml index fc460540..deafb6cf 100644 --- a/cms-server/hosts/demo/site.yaml +++ b/cms-server/hosts/demo/site.yaml @@ -11,4 +11,5 @@ modules: - markedjs-module # - pebble-module - thymeleaf-module -# - freemarker-module \ No newline at end of file +# - freemarker-module +# - ui-module \ No newline at end of file diff --git a/cms-server/modules/ui-module/libs/checker-qual-3.37.0.jar b/cms-server/modules/ui-module/libs/checker-qual-3.37.0.jar new file mode 100644 index 00000000..b4f9db98 Binary files /dev/null and b/cms-server/modules/ui-module/libs/checker-qual-3.37.0.jar differ diff --git a/cms-server/modules/ui-module/libs/error_prone_annotations-2.21.1.jar b/cms-server/modules/ui-module/libs/error_prone_annotations-2.21.1.jar new file mode 100644 index 00000000..00f26ae1 Binary files /dev/null and b/cms-server/modules/ui-module/libs/error_prone_annotations-2.21.1.jar differ diff --git a/cms-server/modules/ui-module/libs/failureaccess-1.0.1.jar b/cms-server/modules/ui-module/libs/failureaccess-1.0.1.jar new file mode 100644 index 00000000..9b56dc75 Binary files /dev/null and b/cms-server/modules/ui-module/libs/failureaccess-1.0.1.jar differ diff --git a/cms-server/modules/ui-module/libs/gson-2.10.1.jar b/cms-server/modules/ui-module/libs/gson-2.10.1.jar new file mode 100644 index 00000000..a88c5bd9 Binary files /dev/null and b/cms-server/modules/ui-module/libs/gson-2.10.1.jar differ diff --git a/cms-server/modules/ui-module/libs/guava-32.1.3-jre.jar b/cms-server/modules/ui-module/libs/guava-32.1.3-jre.jar new file mode 100644 index 00000000..9dc82354 Binary files /dev/null and b/cms-server/modules/ui-module/libs/guava-32.1.3-jre.jar differ diff --git a/cms-server/modules/ui-module/libs/j2objc-annotations-2.8.jar b/cms-server/modules/ui-module/libs/j2objc-annotations-2.8.jar new file mode 100644 index 00000000..3595c4f9 Binary files /dev/null and b/cms-server/modules/ui-module/libs/j2objc-annotations-2.8.jar differ diff --git a/cms-server/modules/ui-module/libs/jsr305-3.0.2.jar b/cms-server/modules/ui-module/libs/jsr305-3.0.2.jar new file mode 100644 index 00000000..59222d9c Binary files /dev/null and b/cms-server/modules/ui-module/libs/jsr305-3.0.2.jar differ diff --git a/cms-server/modules/ui-module/libs/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar b/cms-server/modules/ui-module/libs/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar new file mode 100644 index 00000000..45832c05 Binary files /dev/null and b/cms-server/modules/ui-module/libs/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar differ diff --git a/cms-server/modules/ui-module/libs/ui-module-2.5.0-SNAPSHOT.jar b/cms-server/modules/ui-module/libs/ui-module-2.5.0-SNAPSHOT.jar new file mode 100644 index 00000000..95ea3936 Binary files /dev/null and b/cms-server/modules/ui-module/libs/ui-module-2.5.0-SNAPSHOT.jar differ diff --git a/cms-server/modules/ui-module/module.properties b/cms-server/modules/ui-module/module.properties new file mode 100644 index 00000000..64e7d04b --- /dev/null +++ b/cms-server/modules/ui-module/module.properties @@ -0,0 +1,4 @@ +id=ui-module +name=ui-module +version=2.5.0-SNAPSHOT +priority=HIGH \ No newline at end of file diff --git a/modules/example-module/src/main/java/com/github/thmarx/cms/modules/example/ExampleJettyHttpHandlerExtension.java b/modules/example-module/src/main/java/com/github/thmarx/cms/modules/example/ExampleJettyHttpHandlerExtension.java index 608d22ca..02569fe3 100644 --- a/modules/example-module/src/main/java/com/github/thmarx/cms/modules/example/ExampleJettyHttpHandlerExtension.java +++ b/modules/example-module/src/main/java/com/github/thmarx/cms/modules/example/ExampleJettyHttpHandlerExtension.java @@ -29,7 +29,6 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; -import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.PathMappingsHandler; import org.eclipse.jetty.util.Callback; diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/assets/index.html b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/assets/index.html new file mode 100644 index 00000000..4c6725ad --- /dev/null +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/assets/index.html @@ -0,0 +1,26 @@ + + + + + + UI + + diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/http/UIJettyHttpHandlerExtension.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/http/UIJettyHttpHandlerExtension.java new file mode 100644 index 00000000..610c2d29 --- /dev/null +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/http/UIJettyHttpHandlerExtension.java @@ -0,0 +1,68 @@ +package com.github.thmarx.cms.modules.ui.http; + +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ +import com.github.thmarx.cms.api.extensions.JettyHttpHandlerExtensionPoint; +import com.github.thmarx.modules.api.annotation.Extension; +import org.eclipse.jetty.http.pathmap.PathSpec; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.handler.PathMappingsHandler; +import org.eclipse.jetty.server.handler.ResourceHandler; +import org.eclipse.jetty.util.resource.PathResource; +import org.eclipse.jetty.util.resource.PathResourceFactory; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; + +/** + * + * @author t.marx + */ +@Extension(JettyHttpHandlerExtensionPoint.class) +public class UIJettyHttpHandlerExtension extends JettyHttpHandlerExtensionPoint { + + @Override + public String getContextPath() { + return "ui"; + } + + @Override + public Handler getHandler() { + + var classLoader = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(UIJettyHttpHandlerExtension.class.getClassLoader()); + + ResourceHandler resourceHandler = new ResourceHandler(); + resourceHandler.setBaseResource( + ResourceFactory.of(resourceHandler) + .newClassLoaderResource("com/github/thmarx/cms/modules/ui/assets/", true) + ); + + PathMappingsHandler pathMappingsHandler = new PathMappingsHandler(); + pathMappingsHandler.addMapping(PathSpec.from("/assets/*"), resourceHandler); + + return pathMappingsHandler; + + } finally { + Thread.currentThread().setContextClassLoader(classLoader); + } + } + +} diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/model/User.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/model/User.java index ea2602e3..1fe6acdc 100644 --- a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/model/User.java +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/model/User.java @@ -1,5 +1,25 @@ package com.github.thmarx.cms.modules.ui.model; +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + import com.google.common.base.Joiner; import com.google.common.base.Splitter; import java.util.List; @@ -123,4 +143,4 @@ public boolean equals(Object obj) { return true; } -} \ No newline at end of file +} diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileSystemService.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileSystemService.java new file mode 100644 index 00000000..d12cdf02 --- /dev/null +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileSystemService.java @@ -0,0 +1,77 @@ +package com.github.thmarx.cms.modules.ui.services; + +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + +import com.github.thmarx.cms.api.ModuleFileSystem; +import com.github.thmarx.cms.modules.ui.utils.PathUtil; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + * + * @author t.marx + */ +@RequiredArgsConstructor +@Slf4j +public class FileSystemService { + private final ModuleFileSystem fileSystem; + + public List listContent (String parent) { + + try { + var contentBase = fileSystem.resolve("content"); + + return Files.list(contentBase.resolve(parent)).map((path) -> { + var uri = PathUtil.toUri(path, contentBase); + return new Node(uri, path.getFileName().toString(), getIcon(path), hasChildren(path)); + }).toList(); + } catch (IOException ex) { + log.error(null, ex); + } + return Collections.emptyList(); + } + + private boolean hasChildren (Path path) { + try { + return Files.list(path).count() > 0; + } catch (IOException ex) { + log.error(null, ex); + } + return false; + } + + private String getIcon (Path path) { + if (Files.isDirectory(path)) { + return "folder"; + } else { + return "file"; + } + } + + public static record Node (String id, String text, String icon, boolean children){} +} diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileUserService.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileUserService.java index 6de763a0..ab09c929 100644 --- a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileUserService.java +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/FileUserService.java @@ -1,5 +1,25 @@ package com.github.thmarx.cms.modules.ui.services; +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + import com.github.thmarx.cms.modules.ui.model.User; import com.github.thmarx.cms.modules.ui.utils.Helper; import com.google.common.base.Charsets; @@ -143,4 +163,4 @@ public Collection all() { } -} \ No newline at end of file +} diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/UserService.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/UserService.java index 2e81b465..27370313 100644 --- a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/UserService.java +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/services/UserService.java @@ -1,5 +1,25 @@ package com.github.thmarx.cms.modules.ui.services; +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + import com.github.thmarx.cms.modules.ui.model.User; import java.util.Collection; @@ -38,4 +58,4 @@ public interface UserService { * @return */ public Collection all (); -} \ No newline at end of file +} diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/Helper.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/Helper.java index e574174c..35f3fe9e 100644 --- a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/Helper.java +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/Helper.java @@ -1,5 +1,25 @@ package com.github.thmarx.cms.modules.ui.utils; +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + import com.google.common.hash.Hashing; import java.math.BigInteger; import java.nio.charset.StandardCharsets; diff --git a/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/PathUtil.java b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/PathUtil.java new file mode 100644 index 00000000..9bb5166f --- /dev/null +++ b/modules/ui-module/src/main/java/com/github/thmarx/cms/modules/ui/utils/PathUtil.java @@ -0,0 +1,41 @@ +package com.github.thmarx.cms.modules.ui.utils; + +/*- + * #%L + * ui-module + * %% + * Copyright (C) 2023 Marx-Software + * %% + * 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. + * #L% + */ + +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author t.marx + */ +public class PathUtil { + + public static String toUri(final Path contentFile, final Path contentBase) { + Path relativize = contentBase.relativize(contentFile); + if (Files.isDirectory(contentFile)) { + relativize = relativize.resolve("index.md"); + } + var uri = relativize.toString(); + uri = uri.replaceAll("\\\\", "/"); + return uri; + } +} diff --git a/modules/ui-module/src/main/resources/com/github/thmarx/cms/modules/ui/assets/index.html b/modules/ui-module/src/main/resources/com/github/thmarx/cms/modules/ui/assets/index.html new file mode 100644 index 00000000..4c6725ad --- /dev/null +++ b/modules/ui-module/src/main/resources/com/github/thmarx/cms/modules/ui/assets/index.html @@ -0,0 +1,26 @@ + + + + + + UI + +