Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
* #L%
*/

import com.condation.cms.api.module.SiteModuleContext;
import com.condation.cms.api.module.SiteRequestContext;
import com.condation.cms.api.ui.elements.Menu;
import com.condation.modules.api.ExtensionPoint;

/**
*
* @author t.marx
*/
public interface UIActionsExtensionPoint extends ExtensionPoint<SiteModuleContext, SiteRequestContext> {
public interface UIActionsExtensionPoint extends UIExtensionPoint {

public default void addMenuItems (Menu menu) {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.condation.cms.api.ui.extensions;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 - 2025 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.condation.cms.api.module.SiteModuleContext;
import com.condation.cms.api.module.SiteRequestContext;
import com.condation.modules.api.ExtensionPoint;

/**
*
* @author thmar
*/
public interface UIExtensionPoint extends ExtensionPoint<SiteModuleContext, SiteRequestContext> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
* #L%
*/

import com.condation.cms.api.module.SiteModuleContext;
import com.condation.cms.api.module.SiteRequestContext;
import com.condation.modules.api.ExtensionPoint;
import java.util.Map;

/**
*
* @author t.marx
*/
public interface UILocalizationExtensionPoint extends ExtensionPoint<SiteModuleContext, SiteRequestContext> {
public interface UILocalizationExtensionPoint extends UIExtensionPoint {

public Map<String, Map<String, String>> getLocalizations ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
* #L%
*/

import com.condation.cms.api.extensions.AbstractExtensionPoint;

/**
*
* @author t.marx
*/
public abstract class UIRemoteMethodExtensionPoint extends AbstractExtensionPoint {
public interface UIRemoteMethodExtensionPoint extends UIExtensionPoint{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.condation.cms.api.ui.extensions;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 - 2025 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.util.Map;

/**
*
* @author thmar
*/
public interface UIScriptActionSourceExtension extends UIExtensionPoint {

public Map<String, String> getActionSources ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static <A extends Annotation, R> List<CMSAnnotation<A, R>> process(Object

List<CMSAnnotation<A, R>> result = new ArrayList();
Class<?> clazz = target.getClass();
for (Method method : clazz.getDeclaredMethods()) {
for (Method method : clazz.getMethods()) {
if (!method.isAnnotationPresent(annotationClass)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.condation.cms.modules.example.ui;

/*-
* #%L
* example-module
* %%
* Copyright (C) 2023 - 2025 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.condation.cms.api.auth.Permissions;
import com.condation.cms.api.extensions.AbstractExtensionPoint;
import com.condation.cms.api.ui.annotations.MenuEntry;
import com.condation.cms.api.ui.annotations.ShortCut;
import com.condation.cms.api.ui.extensions.UIActionsExtensionPoint;
import com.condation.cms.api.ui.extensions.UIScriptActionSourceExtension;
import com.condation.modules.api.annotation.Extension;
import com.condation.modules.api.annotation.Extensions;
import java.util.Map;

/**
*
* @author thmar
*/
@Extensions({
@Extension(UIActionsExtensionPoint.class),
@Extension(UIScriptActionSourceExtension.class)
})
public class ExampleUiScriptActionSourceExtension extends AbstractExtensionPoint implements UIScriptActionSourceExtension, UIActionsExtensionPoint {

@Override
public Map<String, String> getActionSources() {
return Map.of("example/source", "// this is an example script source");
}

@MenuEntry(
id = "exampleMenu",
name = "Example",
permissions = {Permissions.CONTENT_EDIT},
position = 10
)
public void exampleMenu() {

}

@MenuEntry(
parent = "exampleMenu",
id = "example-action",
name = "Example action",
permissions = {Permissions.CONTENT_EDIT},
position = 1,
scriptAction = @com.condation.cms.api.ui.annotations.ScriptAction(module = "/manager/actions/example/source")
)
@ShortCut(
id = "example-action",
title = "Example Action",
permissions = {Permissions.CONTENT_EDIT},
section = "Example",
scriptAction = @com.condation.cms.api.ui.annotations.ScriptAction(module = "/manager/actions/example/source")
)
public void example_action() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

import com.condation.cms.api.db.DB;
import com.condation.cms.api.extensions.AbstractExtensionPoint;
import com.condation.cms.api.feature.features.AuthFeature;
import com.condation.cms.api.feature.features.DBFeature;
import com.condation.cms.api.feature.features.HookSystemFeature;
Expand All @@ -36,7 +37,7 @@
*
* @author thorstenmarx
*/
public abstract class AbstractRemoteMethodeExtension extends UIRemoteMethodExtensionPoint {
public abstract class AbstractRemoteMethodeExtension extends AbstractExtensionPoint implements UIRemoteMethodExtensionPoint {
protected String getUserName() {
if (getRequestContext().has(AuthFeature.class)) {
return getRequestContext().get(AuthFeature.class).username();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

import com.condation.cms.api.auth.Permissions;
import com.condation.cms.api.extensions.AbstractExtensionPoint;
import com.condation.cms.api.feature.features.HookSystemFeature;
import com.condation.cms.api.feature.features.ModuleManagerFeature;
import com.condation.cms.api.ui.extensions.UILocalizationExtensionPoint;
Expand All @@ -41,7 +42,7 @@
*/
@Slf4j
@Extension(UIRemoteMethodExtensionPoint.class)
public class LocalizationEnpoints extends UIRemoteMethodExtensionPoint {
public class LocalizationEnpoints extends AbstractExtensionPoint implements UIRemoteMethodExtensionPoint {



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.condation.cms.api.db.cms.ReadOnlyFile;
import com.condation.cms.api.eventbus.events.InvalidateContentCacheEvent;
import com.condation.cms.api.eventbus.events.ReIndexContentMetaDataEvent;
import com.condation.cms.api.extensions.AbstractExtensionPoint;
import com.condation.cms.api.feature.features.DBFeature;
import com.condation.cms.api.feature.features.EventBusFeature;
import com.condation.cms.api.feature.features.RequestFeature;
Expand Down Expand Up @@ -58,7 +59,7 @@
*/
@Slf4j
@Extension(UIRemoteMethodExtensionPoint.class)
public class RemoteContentEndpointsExtension extends UIRemoteMethodExtensionPoint {
public class RemoteContentEndpointsExtension extends AbstractExtensionPoint implements UIRemoteMethodExtensionPoint {

@RemoteMethod(name = "content.get", permissions = {Permissions.CONTENT_EDIT})
public Object getContent(Map<String, Object> parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.condation.cms.api.Constants;
import com.condation.cms.api.auth.Permissions;
import com.condation.cms.api.eventbus.events.InvalidateMediaCache;
import com.condation.cms.api.extensions.AbstractExtensionPoint;
import com.condation.cms.api.feature.features.DBFeature;
import com.condation.cms.api.feature.features.EventBusFeature;
import com.condation.cms.api.feature.features.SiteMediaServiceFeature;
Expand All @@ -46,7 +47,7 @@
*/
@Slf4j
@Extension(UIRemoteMethodExtensionPoint.class)
public class RemoteMediaEnpoints extends UIRemoteMethodExtensionPoint {
public class RemoteMediaEnpoints extends AbstractExtensionPoint implements UIRemoteMethodExtensionPoint {

@RemoteMethod(name = "media.meta.get", permissions = {Permissions.CONTENT_EDIT})
public Object getMediaMeta(Map<String, Object> parameters) throws RPCException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.condation.cms.api.feature.features.ModuleManagerFeature;
import com.condation.cms.api.module.SiteModuleContext;
import com.condation.cms.api.ui.extensions.UIScriptActionSourceExtension;
import com.condation.cms.api.utils.HTTPUtil;
import com.google.common.base.Strings;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jetty.http.HttpHeader;
Expand All @@ -48,24 +52,45 @@ public class JSActionHandler extends JettyHandler {

@Override
public boolean handle(Request request, Response response, Callback callback) throws Exception {
var resource = request.getHttpURI().getPath().replace(
managerURL("/manager/actions/", context), "") + ".js";

var files = fileSystem.getPath(base);

if (resource.startsWith("/")) {
resource = resource.substring(1);
var resourceName = request.getHttpURI().getPath().replace(
managerURL("/manager/actions/", context), "");

if (resourceName.startsWith("/")) {
resourceName = resourceName.substring(1);
}

var path = files.resolve(resource);
if (Files.exists(path)) {
response.getHeaders().put(HttpHeader.CONTENT_TYPE, "%s; charset=UTF-8".formatted(Files.probeContentType(path)));
Content.Sink.write(response, true, Files.readString(path, StandardCharsets.UTF_8), callback);

String scriptContent = "";

var moduleContent = getScriptContentFromModules(resourceName);
if (moduleContent.isPresent()) {
scriptContent = moduleContent.get();
} else {
var resourceFile = resourceName + ".js";
var files = fileSystem.getPath(base);
var path = files.resolve(resourceFile);
if (Files.exists(path)) {
scriptContent = Files.readString(path);
}
}


if (!Strings.isNullOrEmpty(scriptContent)) {
response.getHeaders().put(HttpHeader.CONTENT_TYPE, "application/javascript; charset=UTF-8");
Content.Sink.write(response, true, scriptContent, callback);
} else {
callback.succeeded();
}

return true;
}

private Optional<String> getScriptContentFromModules (String filename) {
return context.get(ModuleManagerFeature.class).moduleManager().extensions(UIScriptActionSourceExtension.class)
.stream()
.map(UIScriptActionSourceExtension::getActionSources)
.filter(source -> source.containsKey(filename))
.map(source -> source.get(filename))
.findFirst();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Menu createMenu() {
private List<ShortCutHolder> scanShortCuts(Object moduleInstance) {
List<ShortCutHolder> shortCuts = new ArrayList<>();

for (Method method : moduleInstance.getClass().getDeclaredMethods()) {
for (Method method : moduleInstance.getClass().getMethods()) {
var shortcutAnnotation = method.getAnnotation(com.condation.cms.api.ui.annotations.ShortCut.class);
if (shortcutAnnotation == null) {
continue;
Expand Down Expand Up @@ -156,7 +156,7 @@ private List<EntryHolder> scanMenuEntries(Object moduleInstance) {

List<EntryHolder> entries = new ArrayList<>();

for (Method method : moduleInstance.getClass().getDeclaredMethods()) {
for (Method method : moduleInstance.getClass().getMethods()) {
var menuAnn = method.getAnnotation(com.condation.cms.api.ui.annotations.MenuEntry.class);
if (menuAnn == null) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions test-server/hosts/demo/site.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ target = "/Users/thorstenmarx/entwicklung/backups"
[cache]
content = true

[modules]
active = ["example-module"]

[translation]
enabled = true
languages = ["de", "en"]
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions test-server/modules/example-module/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=example-module
name=example module
version=8.0.0
priority=HIGH