You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2021/07/15 13:50:25 UTC
[sling-project-archetype] branch feature/SLING-10608 created (now
adc2aae)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch feature/SLING-10608
in repository https://gitbox.apache.org/repos/asf/sling-project-archetype.git.
at adc2aae SLING-10608 - Refresh sample servlets
This branch includes the following new commits:
new adc2aae SLING-10608 - Refresh sample servlets
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-project-archetype] 01/01: SLING-10608 - Refresh sample
servlets
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch feature/SLING-10608
in repository https://gitbox.apache.org/repos/asf/sling-project-archetype.git
commit adc2aaec29853233cb96368ca81e37821e5f1a6a
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jul 15 16:47:04 2021 +0300
SLING-10608 - Refresh sample servlets
Add the correct ZipServlet
---
.../src/main/java/servlet/ZipServlet.java | 36 ++++++++++------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
index 7eae264..1beaf33 100644
--- a/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
+++ b/src/main/resources/archetype-resources/core.example/src/main/java/servlet/ZipServlet.java
@@ -21,6 +21,9 @@ package ${package}.servlet;
import java.io.IOException;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipEntry;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -58,31 +61,24 @@ import org.slf4j.LoggerFactory;
)
@SuppressWarnings("serial")
public class ZipServlet extends SlingSafeMethodsServlet {
-
- private final Logger log = LoggerFactory.getLogger(ByResourceTypeServlet.class);
@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
- Resource resource = request.getResource();
-
- Writer w = response.getWriter();
- w.write("<!DOCTYPE html PUBLIC ${symbol_escape}"-//IETF//DTD HTML 2.0//EN${symbol_escape}">");
- w.write("<html>");
- w.write("<head>");
- w.write("<title>Hello World Servlet</title>");
- w.write("</head>");
- w.write("<body>");
- w.write("<h1>Hello ");
- w.write(resource.getPath());
- w.write("</h1>");
- w.write("</body>");
- w.write("</html>");
-
- log.info("Hello World Servlet");
-
+ response.setContentType("application/content-stream");
+ try ( ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
+ for ( Resource child : request.getResource().getChildren() ) {
+ ZipEntry entry = new ZipEntry(child.getName() + ".txt");
+ zos.putNextEntry(entry);
+ StringBuilder sb = new StringBuilder();
+ sb
+ .append(child.getValueMap().get("jcr:title", String.class))
+ .append("\n\n")
+ .append(child.getValueMap().get("jcr:contents"));
+ zos.write(sb.toString().getBytes(StandardCharsets.UTF_8));
+ }
+ }
}
-
}