Browse Source

Add html servlet

master
Larry L 1 year ago
parent
commit
779d198fc8
  1. 7
      core/src/main/java/com/mcaps/core/models/CourseModel.java
  2. 49
      core/src/main/java/com/mcaps/core/servlets/HtmlServlet.java
  3. 2
      ui.apps/src/main/content/jcr_root/apps/mcaps-site/components/blankpage/blankpage.html

7
core/src/main/java/com/mcaps/core/models/CourseModel.java

@ -40,9 +40,8 @@ public class CourseModel {
.map(pm -> pm.getContainingPage(currentResource))
.map(Page::getPath).orElse("");
message = "Hello World!\n"
+ "Resource type is: " + resourceType + "\n"
+ "Current page is: " + currentPagePath + "\n";
message = "<p>Resource type is: " + resourceType
+ "</p><p>Current page is: " + currentPagePath + "</p>";
}
public String getMessage() {
@ -50,7 +49,7 @@ public class CourseModel {
}
public String getHtml() {
return "<body><h1>TESTING</h1><p>"+message+"</p></body>";
return "<div>"+message+"</div>";
}
}

49
core/src/main/java/com/mcaps/core/servlets/HtmlServlet.java

@ -0,0 +1,49 @@
package com.mcaps.core.servlets;
import com.day.cq.commons.jcr.JcrConstants;
import org.apache.commons.io.IOUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.propertytypes.ServiceDescription;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.InputStream;
/**
* Servlet that writes some sample content into the response. It is mounted for
* all resources of a specific Sling resource type. The
* {@link SlingSafeMethodsServlet} shall be used for HTTP methods that are
* idempotent. For write operations use the {@link SlingAllMethodsServlet}.
*/
@Component(service = { Servlet.class },property = {
"sling.servlet.paths=/content/dam/ms-mcaps" ,
"sling.servlet.methods=GET",
"sling.servlet.extensions=html"
})
public class HtmlServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
// Get the path of the requested HTML file
String path = request.getRequestPathInfo().getResourcePath();
// Read the content of the HTML file from DAM
InputStream htmlStream = request.getResource().adaptTo(InputStream.class);
// Set the content type
response.setContentType("text/html");
// Copy the content to the response
IOUtils.copy(htmlStream, response.getOutputStream());
}
}

2
ui.apps/src/main/content/jcr_root/apps/mcaps-site/components/blankpage/blankpage.html

@ -5,7 +5,7 @@
<head data-sly-call="${head.head @ page = page, pwa = pwa}"></head>
<body class="${page.cssClassNames}"
id="${page.id}">
<h1>SCORM Test</h1>
<h1>SCORM Package Unwrapped</h1>
<sly data-sly-include="course.html"></sly>
</sly>
</body>

Loading…
Cancel
Save