Package com.composum.ai.aem.core.impl
Class BulkReplaceServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- org.apache.sling.api.servlets.SlingSafeMethodsServlet
-
- org.apache.sling.api.servlets.SlingAllMethodsServlet
-
- com.composum.ai.aem.core.impl.BulkReplaceServlet
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class BulkReplaceServlet extends org.apache.sling.api.servlets.SlingAllMethodsServlet
Servlet with functionality for the bulk replace tool.Operations: 1. Search: - POST (operation=search) Parameters: • rootPath: absolute page path to start search (e.g. /content/site/en) • term: literal search text Response: 202 Accepted with JSON payload {"jobId": "
"}. Note: The search parameters are stored in an internal LinkedHashMap (only the last 10 operations are kept). - GET (operation=search, jobId=
) Streams search results as text/event-stream based on the stored parameters. 2. Replace: - POST (operation=replace) Parameters: • rootPath, term, replacement, target (see bulkreplace.md) Response: JSON indicating replace result.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BulkReplaceServlet.Changed
protected static class
BulkReplaceServlet.Match
protected static class
BulkReplaceServlet.ReplacePageResponse
protected static class
BulkReplaceServlet.ReplaceRequest
protected static class
BulkReplaceServlet.SearchPageResponse
protected static class
BulkReplaceServlet.SearchParams
protected static class
BulkReplaceServlet.SummaryResponse
protected static class
BulkReplaceServlet.Target
-
Constructor Summary
Constructors Constructor Description BulkReplaceServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
abbreviateSurroundings(String text, Pattern termPattern, int surroundingChars)
Creates an excerpt from the given text around the search term.protected String
createExcerpt(String text, Pattern termPattern, int surroundingChars)
Creates an excerpt from the given text around the search term.protected void
doGet(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Handles GET requests to stream search results: the second step that does the actual search.protected void
doPost(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Handles POST requests for search and replace operations.protected String
toPlaintext(String text)
Use Jsoup to create plaintext from HTML.protected Pattern
whitespaceLenientPattern(String searchString)
A pattern that matches the search String case sensitively but being lenient on whitespaces: the pattern made from "a b c" should also match "a b\nc".-
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPut, getAllowedRequestMethods, isMethodValid, mayService
-
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
-
-
-
-
Method Detail
-
doPost
protected void doPost(@Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response) throws IOException
Handles POST requests for search and replace operations.- Overrides:
doPost
in classorg.apache.sling.api.servlets.SlingAllMethodsServlet
- Parameters:
request
- the SlingHttpServletRequest, not nullresponse
- the SlingHttpServletResponse, not null- Throws:
IOException
- if an I/O error occurs
-
doGet
protected void doGet(@Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response) throws IOException
Handles GET requests to stream search results: the second step that does the actual search.- Overrides:
doGet
in classorg.apache.sling.api.servlets.SlingSafeMethodsServlet
- Parameters:
request
- the SlingHttpServletRequest, not nullresponse
- the SlingHttpServletResponse, not null- Throws:
IOException
- if an I/O error occurs
-
createExcerpt
@Nonnull protected String createExcerpt(@Nonnull String text, @Nonnull Pattern termPattern, int surroundingChars)
Creates an excerpt from the given text around the search term.- Parameters:
text
- the full text, not nulltermPattern
- a pattern matching the search term, not null- Returns:
- an excerpt of the text surrounding the term
-
abbreviateSurroundings
@Nonnull protected String abbreviateSurroundings(@Nonnull String text, @Nonnull Pattern termPattern, int surroundingChars)
Creates an excerpt from the given text around the search term.- Parameters:
text
- the full text, not nulltermPattern
- a pattern matching the search term, not null- Returns:
- an excerpt of the text surrounding the term
-
toPlaintext
protected String toPlaintext(String text)
Use Jsoup to create plaintext from HTML. We assume it's HTML if it starts with < and ends with > , trimmed.
-
whitespaceLenientPattern
protected Pattern whitespaceLenientPattern(@Nonnull String searchString)
A pattern that matches the search String case sensitively but being lenient on whitespaces: the pattern made from "a b c" should also match "a b\nc". If there is a whitespace at the beginning or the end we treat it as word boundary.
-
-