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
1 change: 1 addition & 0 deletions cms-api/src/main/java/com/condation/cms/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static class Folders {
public static final String MODULES = "modules/";
public static final String HOSTS = "hosts/";
public static final String THEMES = "themes/";
public static final String PUBLIC = "public/";
}

public static class NodeType {
Expand Down
2 changes: 2 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/theme/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface Theme {
Path extensionsPath ();

Path assetsPath ();

Path publicPath ();

ThemeProperties properties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,6 @@ public class ContentResolver {

private final DB db;

public Optional<ContentResponse> getStaticContent (String uri) {
if (uri.endsWith(".md")) {
return Optional.empty();
}
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
var contentBase = db.getReadOnlyFileSystem().contentBase();
ReadOnlyFile staticFile = contentBase.resolve(uri);
if (staticFile.isDirectory()) {
return Optional.empty();
}
try {
if (staticFile.exists()) {
return Optional.ofNullable(new DefaultContentResponse(
staticFile.getContent(),
staticFile.getContentType(),
null
));
}
} catch (IOException ex) {
log.error("", ex);
}
return Optional.empty();
}

public Optional<ContentResponse> getContent (final RequestContext context) {
return getContent(context, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ public Path assetsPath() {
}
return themePath.resolve(Constants.Folders.ASSETS);
}


@Override
public Path publicPath() {
if (themePath == null) {
return null;
}
return themePath.resolve(Constants.Folders.PUBLIC);
}

@Override
public Path templatesPath() {
if (themePath == null) {
Expand Down
125 changes: 64 additions & 61 deletions cms-media/src/test/java/com/condation/cms/media/TestTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/


import com.condation.cms.api.ThemeProperties;
import com.condation.cms.api.messages.MessageSource;
import com.condation.cms.api.theme.Theme;
Expand All @@ -33,63 +31,68 @@
* @author t.marx
*/
@RequiredArgsConstructor
public class TestTheme implements Theme{

private final ThemeProperties properties;

@Override
public String getName() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path templatesPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path extensionsPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path assetsPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public ThemeProperties properties() {
return this.properties;
}

@Override
public boolean empty() {
return false;
}

@Override
public MessageSource getMessages() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Theme getParentTheme() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveExtension(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveAsset(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveTemplate(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

public class TestTheme implements Theme {

private final ThemeProperties properties;

@Override
public String getName() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path templatesPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path extensionsPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path assetsPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path publicPath() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public ThemeProperties properties() {
return this.properties;
}

@Override
public boolean empty() {
return false;
}

@Override
public MessageSource getMessages() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Theme getParentTheme() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveExtension(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveAsset(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path resolveTemplate(String path) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void startup() throws IOException {
try {
var host = new VHost(site.id(), site.basePath(), ServerUtil.getPath(Constants.Folders.MODULES), globalInjector);
log.debug("warmup host {}", site.id());
host.warmup();
host.startUpWarmup();
log.debug("init host {}", site.id());
host.init();
vhosts.add(host);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.condation.cms.server.annotations;

/*-
* #%L
* CMS Server
* %%
* Copyright (C) 2023 - 2026 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;

@Target({ FIELD, PARAMETER, METHOD })
@Retention(RUNTIME)
public @interface Eager {}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.condation.cms.server.FileFolderPathResource;
import com.condation.cms.server.filter.InitRequestContextFilter;
import com.condation.cms.server.filter.PreviewFilter;
import com.condation.cms.server.handler.StaticFileHandler;
import com.condation.cms.server.handler.auth.JettyAuthenticationHandler;
import com.condation.cms.server.handler.content.JettyContentHandler;
import com.condation.cms.server.handler.content.JettyTaxonomyHandler;
Expand All @@ -56,6 +57,7 @@
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import java.util.List;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -103,15 +105,15 @@ public JettyModuleHandler moduleHandler(Theme theme, ModuleManager moduleManager

@Provides
@Singleton
@Named("site")
@Named("site.media")
public JettyMediaHandler mediaHandler(SiteMediaManager mediaManager) throws IOException {
return new JettyMediaHandler(mediaManager);
}

@Provides
@Singleton
@Named("site")
public ResourceHandler resourceHander (@Named("assets") Path assetBase, ServerProperties serverProperties) throws IOException {
@Named("site.assets")
public ResourceHandler assetsHandler (@Named("assets") Path assetBase, ServerProperties serverProperties) throws IOException {
ResourceHandler assetsHandler = new ResourceHandler();
assetsHandler.setDirAllowed(false);
assetsHandler.setBaseResource(new FileFolderPathResource(assetBase));
Expand All @@ -123,4 +125,11 @@ public ResourceHandler resourceHander (@Named("assets") Path assetBase, ServerPr

return assetsHandler;
}

@Provides
@Singleton
@Named("site.public")
public StaticFileHandler publicHandler (@Named("public") Path publicBase, ServerProperties serverProperties) throws IOException {
return new StaticFileHandler(List.of(publicBase));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.condation.cms.api.cache.ICache;
import com.condation.cms.api.configuration.Configuration;
import com.condation.cms.api.configuration.configs.ServerConfiguration;
import com.condation.cms.api.configuration.configs.SiteConfiguration;
import com.condation.cms.api.content.ContentParser;
import com.condation.cms.api.content.RenderContentFunction;
import com.condation.cms.api.db.DB;
Expand All @@ -53,7 +52,6 @@
import com.condation.cms.api.template.TemplateEngine;
import com.condation.cms.api.theme.Theme;
import com.condation.cms.auth.services.AuthService;
import com.condation.cms.auth.services.UserService;
import com.condation.cms.content.ContentRenderer;
import com.condation.cms.content.ContentResolver;
import com.condation.cms.content.DefaultContentParser;
Expand Down Expand Up @@ -87,6 +85,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.condation.cms.server.annotations.Eager;

/**
*
Expand Down Expand Up @@ -211,6 +210,13 @@ public Path assetsPath(DB db) {
return db.getFileSystem().resolve(Constants.Folders.ASSETS);
}

@Provides
@Singleton
@Named("public")
public Path publicPath(DB db) {
return db.getFileSystem().resolve(Constants.Folders.PUBLIC);
}

@Provides
@Singleton
@Named("templates")
Expand Down Expand Up @@ -241,7 +247,8 @@ public MessageSource messages(SiteProperties site, DB db, CacheManager cacheMana

@Provides
@Singleton
public DB fileDb(SiteProperties site, DefaultContentParser contentParser, Configuration configuration, EventBus eventBus) throws IOException {
@Eager
public DB fileDb(SiteProperties site, DefaultContentParser contentParser, Configuration configuration, EventBus eventBus) throws IOException {
var db = new FileDB(hostBase, eventBus, (file) -> {
try {
ReadOnlyFile cmsFile = new NIOReadOnlyFile(file, hostBase.resolve(Constants.Folders.CONTENT));
Expand Down
Loading