Skip to content
Open
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
@@ -0,0 +1,28 @@
package com.condation.cms.api.eventbus.events;

/*-
* #%L
* CMS Api
* %%
* 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 com.condation.cms.api.eventbus.Event;
import java.nio.file.Path;

/** Published after collection metadata is refreshed; a directory requests a subtree refresh. */
public record CollectionChangedEvent(Path path) implements Event {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.condation.cms.api.eventbus.events;

/*-
* #%L
* CMS Api
* %%
* 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 com.condation.cms.api.eventbus.Event;

/** Requests rebuilding references after editor schemas have changed. */
public record ContentTypesChangedEvent() implements Event {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.condation.cms.api.ui.elements;

/*-
* #%L
* CMS Api
* %%
* 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 com.condation.cms.api.hooks.HookSystem;

/** Shared hook contract for the manager and background content processing. */
public final class ContentTypeProvider {
public static final String REGISTER_HOOK = "manager/contentTypes/register";

private ContentTypeProvider() {}

public static ContentTypes load(HookSystem hooks) {
return hooks.doFilter(REGISTER_HOOK, new ContentTypes());
}
}
30 changes: 30 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/usage/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.condation.cms.api.usage;

/*-
* #%L
* CMS Api
* %%
* 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%
*/

/** A direct editorial reference and its exact source location. */
public record Usage(UsageResource source, UsageResource target, String location,
Origin origin, String originalReference, String sourceTitle, String sourceStatus,
TargetStatus targetStatus) {
public enum Origin { CONTENT_TYPE, MARKDOWN, HTML }
public enum TargetStatus { EXISTS, MISSING, UNRESOLVED }
}
32 changes: 32 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/usage/UsageIndex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.condation.cms.api.usage;

/*-
* #%L
* CMS Api
* %%
* 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 java.util.List;

/** Site-scoped, rebuildable index of editorial references. Themes and dynamic queries are excluded. */
public interface UsageIndex {
List<Usage> incoming(UsageResource target);
List<Usage> outgoing(UsageResource source);
List<UsageProblem> problems();
void rebuild();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.condation.cms.api.usage;

/*-
* #%L
* CMS Api
* %%
* 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%
*/

/** An incomplete extraction must never be reported as proof that a resource is unused. */
public record UsageProblem(String site, String path, String message) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.condation.cms.api.usage;

/*-
* #%L
* CMS Api
* %%
* 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 java.util.Objects;

/** Identity within a site's content, assets or collections root; never a public context path. */
public record UsageResource(String site, Kind kind, String path) {
public enum Kind { CONTENT, MEDIA, COLLECTION_ITEM, UNRESOLVED_URL }

public UsageResource {
Objects.requireNonNull(site, "site");
Objects.requireNonNull(kind, "kind");
Objects.requireNonNull(path, "path");
path = path.replace('\\', '/').replaceAll("^/+", "");
if (site.isBlank() || path.contains("\u0000")) {
throw new IllegalArgumentException("invalid usage resource");
}
if (kind != Kind.UNRESOLVED_URL) {
path = java.nio.file.Path.of(path).normalize().toString().replace('\\', '/');
if (path.isBlank() || path.equals("..") || path.startsWith("../")) {
throw new IllegalArgumentException("invalid site-local resource path");
}
}
}
}
12 changes: 12 additions & 0 deletions cms-content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analysis-common</artifactId>
</dependency>
<dependency>
<groupId>com.condation.cms</groupId>
<artifactId>cms-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
*/
public class ImageLinkInlineRule implements InlineElementRule {

private final boolean modifyUrls;

public ImageLinkInlineRule() { this(true); }

/** Allows static consumers to inspect the stored URL without request transformations. */
public ImageLinkInlineRule(boolean modifyUrls) { this.modifyUrls = modifyUrls; }

static final Slugify SLUG = Slugify.builder().build();

static final String IMAGE_PATTERN = "!\\[(?<alt>[^\\[\\]]*)\\]\\((?<image>[^\\s\\)]+)(?: \"(?<title>[^\"]*)\")?\\)";
Expand All @@ -55,7 +62,7 @@ public InlineBlock next(InlineElementTokenizer tokenizer, String md) {



if (RequestContextScope.REQUEST_CONTEXT.isBound()
if (modifyUrls && RequestContextScope.REQUEST_CONTEXT.isBound()
&& isInternalUrl(href)) {

var requestContext = RequestContextScope.REQUEST_CONTEXT.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
*/
public class LinkInlineRule implements InlineElementRule {

private final boolean modifyUrls;

public LinkInlineRule() { this(true); }

/** Allows static consumers to inspect the stored URL without request transformations. */
public LinkInlineRule(boolean modifyUrls) { this.modifyUrls = modifyUrls; }

static final Slugify SLUG = Slugify.builder().build();

static final Pattern PATTERN = Pattern.compile("\\[(?<text>[^\\]]*)\\]\\((?<url>[^\\s)]+)(?: \"(?<title>[^\"]*)\")?\\)");
Expand All @@ -53,7 +60,7 @@ public InlineBlock next(InlineElementTokenizer tokenizer, String md) {
var id = SLUG.slugify(text);


if (RequestContextScope.REQUEST_CONTEXT.isBound()
if (modifyUrls && RequestContextScope.REQUEST_CONTEXT.isBound()
&& isInternalUrl(href)) {

var requestContext = RequestContextScope.REQUEST_CONTEXT.get();
Expand Down
Loading
Loading