Skip to content

Commit

Permalink
61 merge UI changes into main (#62)
Browse files Browse the repository at this point in the history
* #53 ui init

* #53 add resources to ui module

* update handler mapping

* update handler mapping

* working example of resourcehandler inside of module

* working example of resourcehandler inside of module

* #53 add servlet support

* #53 remove servlet test support

* #53 backend for filesystem manipulation

* #53 backend for filesystem manipulation

* #61 remove ui module

* #61 ready to merge

---------

Co-authored-by: Thorsten Marx <[email protected]>
  • Loading branch information
thmarx and Thorsten Marx authored Nov 7, 2023
1 parent 561d1b5 commit 0ccfb73
Show file tree
Hide file tree
Showing 59 changed files with 292 additions and 113 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ cms-server/modules/flexmark-module
cms-server/modules/markedjs-module
cms-server/modules/pebble-module
cms-server/modules/thymeleaf-module
cms-server/modules/freemarker-module
cms-server/modules/freemarker-module
cms-server/modules/ui-module
cms-server/modules/pug-module
5 changes: 5 additions & 0 deletions cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author t.marx
*/
public abstract class AbstractExtensionEndpoint implements ExtensionPoint<CMSModuleContext> {
public abstract class AbstractExtensionPoint implements ExtensionPoint<CMSModuleContext> {
@Getter
protected ModuleConfiguration moduleConfiguration;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author t.marx
*/
@Deprecated(since = "2.5.0")
public abstract class HttpHandlerExtensionPoint extends AbstractExtensionEndpoint implements ExtensionHttpHandler {
public abstract class HttpHandlerExtensionPoint extends AbstractExtensionPoint implements ExtensionHttpHandler {

abstract public boolean handles (String method, String uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@
* #L%
*/

import org.eclipse.jetty.server.Handler;

/**
*
* @author t.marx
*/
public abstract class JettyHttpHandlerExtensionPoint extends AbstractExtensionEndpoint {

abstract public String getContextPath();

abstract public Handler getHandler();

public abstract class JettyHttpHandlerExtensionPoint extends AbstractExtensionPoint {
abstract public Mapping getMapping();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.github.thmarx.cms.api.extensions;

/*-
* #%L
* cms-api
* %%
* 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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Handler;

/**
*
* @author thmar
*/
public class Mapping {

private Map<PathSpec, Handler> handlerMapping;

public Mapping () {
handlerMapping = new HashMap<>();
}

public void add (PathSpec pathSpec, Handler handler) {
handlerMapping.put(pathSpec, handler);
}

public Optional<Handler> getMatchingHandler (String uri) {
return handlerMapping.entrySet().stream().filter(entry -> entry.getKey().matches(uri)).map(entry -> entry.getValue()).findFirst();
}

public List<Handler> getHandlers () {
return new ArrayList<>(handlerMapping.values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author t.marx
*/
public abstract class MarkdownRendererProviderExtentionPoint extends AbstractExtensionEndpoint {
public abstract class MarkdownRendererProviderExtentionPoint extends AbstractExtensionPoint {

public abstract String getName ();
public abstract MarkdownRenderer getRenderer ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author t.marx
*/
public abstract class TemplateEngineProviderExtentionPoint extends AbstractExtensionEndpoint {
public abstract class TemplateEngineProviderExtentionPoint extends AbstractExtensionPoint {

public abstract String getName ();
public abstract TemplateEngine getTemplateEngine ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @author thmar
*/
public abstract class TemplateModelExtendingExtentionPoint extends AbstractExtensionEndpoint{
public abstract class TemplateModelExtendingExtentionPoint extends AbstractExtensionPoint{

public abstract void extendModel (TemplateEngine.Model model);

Expand Down
5 changes: 5 additions & 0 deletions cms-server/hosts/demo/content/.technical/test/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Das ist der neue Titel
---

Das ist der ganz aktuelle Inhalt
1 change: 1 addition & 0 deletions cms-server/hosts/demo/test/ui-module/directory-create.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POST http://localhost:1010/module/ui-module/file-system/create?path=.technical&filename=test&type=folder
1 change: 1 addition & 0 deletions cms-server/hosts/demo/test/ui-module/directory-delete.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE http://localhost:1010/module/ui-module/file-system/delete?path=.technical/test
8 changes: 8 additions & 0 deletions cms-server/hosts/demo/test/ui-module/file-create.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST http://localhost:1010/module/ui-module/file-system/create?path=.technical/test&filename=example.md&type=file

---
title: Das ist der Titel
---
\# Neue Datei

Das ist der Inhalt
1 change: 1 addition & 0 deletions cms-server/hosts/demo/test/ui-module/file-read.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET http://localhost:1010/module/ui-module/file-system/read?path=.technical/test/example.md
8 changes: 8 additions & 0 deletions cms-server/hosts/demo/test/ui-module/file-write.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PUT http://localhost:1010/module/ui-module/file-system/write?path=.technical/test/example.md

---
title: Das ist der neue Titel
---
# Neuerer Datei

Das ist der ganz aktuelle Inhalt
1 change: 1 addition & 0 deletions cms-server/hosts/demo/test/ui-module/list-files.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET http://localhost:1010/module/ui-module/file-system/list?path=.technical
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed cms-server/modules/pug-module/libs/gson-2.10.1.jar
Binary file not shown.
Binary file removed cms-server/modules/pug-module/libs/icu4j-70.1.jar
Binary file not shown.
Binary file removed cms-server/modules/pug-module/libs/js-21.3.2.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed cms-server/modules/pug-module/libs/pug4j-2.1.0.jar
Binary file not shown.
Binary file removed cms-server/modules/pug-module/libs/regex-21.3.2.jar
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions cms-server/modules/pug-module/module.properties

This file was deleted.

80 changes: 41 additions & 39 deletions cms-server/src/main/java/com/github/thmarx/cms/server/VHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public class VHost {
@Getter
private final EventBus eventBus;

protected SiteProperties properties;
protected SiteProperties siteProperties;

protected ModuleManager moduleManager;

protected final ServerProperties serverProperties;

public VHost(final Path hostBase, final ServerProperties serverProperties) {
this.eventBus = new DefaultEventBus();
this.fileSystem = new FileSystem(hostBase, eventBus);
Expand All @@ -97,46 +97,48 @@ public void shutdown() {
public void init(Path modules) throws IOException {

fileSystem.init();

var props = fileSystem.resolve("site.yaml");
properties = PropertiesLoader.hostProperties(props);
siteProperties = PropertiesLoader.hostProperties(props);

var classLoader = new ModuleAPIClassLoader(ClassLoader.getSystemClassLoader(),
var classLoader = new ModuleAPIClassLoader(ClassLoader.getSystemClassLoader(),
List.of(
"org.slf4j",
"org.slf4j",
"com.github.thmarx.cms",
"org.apache.logging",
"org.graalvm.polyglot",
"org.graalvm.js",
"org.eclipse.jetty"
));
this.moduleManager = ModuleManagerImpl.create(
modules.toFile(),
fileSystem.resolve("modules_data").toFile(),
new CMSModuleContext(properties, serverProperties, fileSystem, eventBus),
"org.eclipse.jetty",
"jakarta.servlet"
));
this.moduleManager = ModuleManagerImpl.create(modules.toFile(),
fileSystem.resolve("modules_data").toFile(),
new CMSModuleContext(siteProperties, serverProperties, fileSystem, eventBus),
classLoader
);
properties.activeModules().forEach(module_id -> {
try {
log.debug("activate module {}", module_id);
moduleManager.activateModule(module_id);
} catch (IOException ex) {
log.error(null, ex);
}
});

siteProperties.activeModules().stream()
.filter(module_id -> moduleManager.getModuleIds().contains(module_id))
.forEach(module_id -> {
try {
log.debug("activate module {}", module_id);
moduleManager.activateModule(module_id);
} catch (IOException ex) {
log.error(null, ex);
}
});

moduleManager.getModuleIds().stream()
.filter(id -> !properties.activeModules().contains(id))
.filter(id -> !siteProperties.activeModules().contains(id))
.forEach((module_id) -> {
try {
log.debug("deactivate module {}", module_id);
moduleManager.deactivateModule(module_id);
} catch (IOException ex) {
log.error(null, ex);
}
});
hostname = properties.hostname();
try {
log.debug("deactivate module {}", module_id);
moduleManager.deactivateModule(module_id);
} catch (IOException ex) {
log.error(null, ex);
}
});

hostname = siteProperties.hostname();

contentBase = fileSystem.resolve("content/");
assetBase = fileSystem.resolve("assets/");
Expand All @@ -149,7 +151,7 @@ public void init(Path modules) throws IOException {

templateEngine = resolveTemplateEngine();

contentRenderer = new ContentRenderer(contentParser, templateEngine, fileSystem, properties, moduleManager);
contentRenderer = new ContentRenderer(contentParser, templateEngine, fileSystem, siteProperties, moduleManager);
contentResolver = new ContentResolver(contentBase, contentRenderer, fileSystem);

eventBus.register(ContentChangedEvent.class, (EventListener<ContentChangedEvent>) (ContentChangedEvent event) -> {
Expand All @@ -163,11 +165,11 @@ public void init(Path modules) throws IOException {
}

protected TemplateEngine resolveTemplateEngine() {
var engine = this.properties.templateEngine();
var engine = this.siteProperties.templateEngine();

List<TemplateEngineProviderExtentionPoint> extensions = moduleManager.extensions(TemplateEngineProviderExtentionPoint.class);
Optional<TemplateEngineProviderExtentionPoint> extOpt = extensions.stream().filter((ext) -> ext.getName().equals(engine)).findFirst();

if (extOpt.isPresent()) {
return extOpt.get().getTemplateEngine();
} else {
Expand All @@ -176,11 +178,11 @@ protected TemplateEngine resolveTemplateEngine() {
}

protected MarkdownRenderer resolveMarkdownRenderer(final Context context) {
var engine = this.properties.markdownEngine();
var engine = this.siteProperties.markdownEngine();

List<MarkdownRendererProviderExtentionPoint> extensions = moduleManager.extensions(MarkdownRendererProviderExtentionPoint.class);
Optional<MarkdownRendererProviderExtentionPoint> extOpt = extensions.stream().filter((ext) -> ext.getName().equals(engine)).findFirst();

if (extOpt.isPresent()) {
return extOpt.get().getRenderer();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void startup() throws IOException {
host.init(Path.of("modules"));
vhosts.add(host);
} catch (IOException ex) {
ex.printStackTrace();
log.error(null, ex);
}
}
});
Expand Down
Loading

0 comments on commit 0ccfb73

Please sign in to comment.