Skip to content

Commit

Permalink
#53 add resources to ui module
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Nov 3, 2023
1 parent 6ab1b90 commit d65b84d
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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"}}}
{"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"}}}
Empty file.
3 changes: 2 additions & 1 deletion cms-server/hosts/demo/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ modules:
- markedjs-module
# - pebble-module
- thymeleaf-module
# - freemarker-module
# - freemarker-module
# - ui-module
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.
4 changes: 4 additions & 0 deletions cms-server/modules/ui-module/module.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=ui-module
name=ui-module
version=2.5.0-SNAPSHOT
priority=HIGH
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
#%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%
-->
<!doctype html>
<html>
<head></head>
<body>
UI
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -123,4 +143,4 @@ public boolean equals(Object obj) {
return true;
}

}
}
Original file line number Diff line number Diff line change
@@ -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<Node> 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){}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -143,4 +163,4 @@ public Collection<User> all() {
}


}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -38,4 +58,4 @@ public interface UserService {
* @return
*/
public Collection<User> all ();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
#%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%
-->
<!doctype html>
<html>
<head></head>
<body>
UI
</body>
</html>

0 comments on commit d65b84d

Please sign in to comment.