本文整理汇总了Java中org.apache.sling.api.SlingHttpServletResponse.getWriter方法的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletResponse.getWriter方法的具体用法?Java SlingHttpServletResponse.getWriter怎么用?Java SlingHttpServletResponse.getWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.SlingHttpServletResponse
的用法示例。
在下文中一共展示了SlingHttpServletResponse.getWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<JSONArray>() {
@Override
protected JSONArray initialValue() {
return new JSONArray();
}
};
loadElements(request);
out.write(threadLocal.get().toString());
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例2: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
threadLocal = new ThreadLocal<Map<String, String>>() {
@Override
protected Map<String, String> initialValue() {
return new HashMap<String, String>();
}
};
loadElements(request);
Set<String> keys = threadLocal.get().keySet();
for (String key : keys) {
String value = threadLocal.get().get(key);
out.write("<option value='" + value + "'>" + key + "</option>");
}
} catch (Exception e) {
throw new ServletException(e);
} finally {
out.flush();
threadLocal.remove();
}
}
示例3: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException
{
final Timer.Context t = metrics.timer(getClass().getSimpleName()).time();
try {
// Output the count of our child nodes
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
final PrintWriter w = response.getWriter();
w.print(request.getResource().getPath());
w.print(" has ");
w.print(countChildren(request.getResource(), ID));
w.print(" descendant nodes with an '");
w.print(ID);
w.print("' property. Sling instance ID is ");
w.print(settings.getSlingId());
w.println(".");
w.flush();
} finally {
t.stop();
}
}
示例4: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
try {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
Page currentPage = request.getResource().adaptTo(Page.class);
JSONWriter w = new JSONWriter(response.getWriter());
w.object();
w.key("name").value(currentPage.getTitle());
w.endObject();
} catch (Exception ex) {
log.error("Request failed", ex);
throw new ServletException(ex);
}
}
示例5: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
Resource resource = request.getResource();
if (resource != null && configurationProvider.hasConfig(resource.getResourceType())) {
JSONObject filteredContentMap = new JSONObject();
TemplateContentModel templateContentModel = (TemplateContentModel) contentModelFactoryService.getContentModel(request, response);
boolean clientAccessible = (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);
if (clientAccessible) {
// get list of contexts
Configuration configuration = configurationProvider.getFor(resource.getResourceType());
Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
String[] contexts = props.toArray(new String[0]);
// get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
filteredContentMap = templateContentModel.toJSONObject(contexts);
// add component id
String componentContentId = DigestUtils.md5Hex(resource.getPath());
filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
}
out.write(JSONObject.toJSONString(filteredContentMap));
} else {
out.write(new JSONObject().toJSONString());
}
} catch (Exception ew) {
throw new ServletException(ew);
}
}
示例6: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
Resource resource = request.getResource();
if (resource != null && configurationProvider.hasConfig(resource.getResourceType())) {
JSONObject filteredContentMap = new JSONObject();
TemplateContentModel templateContentModel = (TemplateContentModel) contentModelFactoryService.getContentModel(request, response);
boolean clientAccessible = (Boolean) templateContentModel.get(CONFIG_PROPERTIES_KEY + DOT + XK_CLIENT_ACCESSIBLE_CP);
if (clientAccessible) {
// get list of contexts
Configuration configuration = configurationProvider.getFor(resource.getResourceType());
Collection<String> props = configuration.asStrings(XK_CLIENT_MODEL_PROPERTIES_CP, Mode.MERGE);
String[] contexts = props.toArray(new String[0]);
// get content model json with the XK_CLIENT_MODEL_PROPERTIES_CP contexts
filteredContentMap = templateContentModel.toJSONObject(contexts);
// add component id
String componentContentId = DigestUtils.md5Hex(resource.getPath());
filteredContentMap.put(XK_CONTENT_ID_CP, componentContentId);
}
// add component list with clientaccessible as true on the resource page
filteredContentMap.put(PAGE_COMPONENT_RESOURCE_LIST_AN, getComponentList(resource));
out.write(JSONObject.toJSONString(filteredContentMap));
} else {
out.write(new JSONObject().toJSONString());
}
} catch (Exception ew) {
throw new ServletException(ew);
}
}
示例7: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
resp.setContentType("text/plain");
out.write("Annotation Demo Servlet - Felix - enabled: " + enabled + "\n");
out.write(sampleFelixService.getSettings());
}
示例8: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
resp.setContentType("text/plain");
out.write("Annotation Demo Servlet - OSGi - enabled: " + enabled + "\n");
out.write(sampleOsgiService.getSettings());
}
示例9: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException
{
final Timer.Context t = metrics.timer(getClass().getSimpleName()).time();
try {
final String id = UUID.randomUUID().toString();
Resource r = request.getResource();
final Map<String, Object> props = new HashMap<String, Object>();
r = addChild(r, getClass().getSimpleName(), props);
for(int i=0 ; i < 4; i+=2) {
r = addChild(r, id.substring(i, i+2), props);
}
props.put(RootGetServlet.ID, id);
r = addChild(r, id, props);
r.getResourceResolver().commit();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
final PrintWriter w = response.getWriter();
w.print("Added ");
w.println(r.getPath());
w.flush();
} finally {
t.stop();
}
}
示例10: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Writer out = response.getWriter();
// get previous/next sibling
Resource previousResource = null;
Resource currentResource = null;
Resource nextResource = null;
for (Resource sibling : request.getResource().getParent().getChildren()) {
if (currentResource!=null) {
nextResource = sibling;
break;
}
else if (StringUtils.equals(sibling.getPath(), request.getResource().getPath())) {
currentResource = request.getResource();
}
else {
previousResource = sibling;
}
}
// anchor for previous/next sibling
if (previousResource!=null) {
out.write(" | <a href=\"" + previousResource.getPath() + ".html\">Previous</a>");
}
if (nextResource!=null) {
out.write(" | <a href=\"" + nextResource.getPath() + ".html\">Next</a>");
}
}
示例11: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Writer out = response.getWriter();
// read comment via Sling Model
Comment comment = request.getResource().adaptTo(Comment.class);
// output comment as HTML
out.write("<p>");
out.write("<em>" + escapeHtml(comment.getAuthor())
+ " (" + DateFormat.getDateTimeInstance().format(comment.getCreated()) + ")</em><br/>");
out.write(escapeHtml(comment.getText()));
out.write("</p>");
}
示例12: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
listConfigurations();
writer.write("This Servlet is Registered at Resource Type " + resourceType + LINE_SEPARATOR);
writer.format("Map is : %s %s", factoryConfig, LINE_SEPARATOR);
writer.format("Service Configurations Length is : %s %s", serviceConfigurations , LINE_SEPARATOR);
}
示例13: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Return all comments on a GET request in order of newest to oldest.
*/
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
List<Resource> comments = commentService.getComments(request);
try {
JSONArray jsonArray = new JSONArray();
for (Resource comment : comments) {
final JSONObject json = new JSONObject();
final ValueMap properties = comment.getValueMap();
final Resource post = commentService.getParentPost(comment);
json.put(PublickConstants.COMMENT_PROPERTY_COMMENT,
properties.get(PublickConstants.COMMENT_PROPERTY_COMMENT, String.class));
json.put(JSON_ID, properties.get(JcrConstants.JCR_UUID, String.class));
json.put(JSON_EDITED, properties.get(PublickConstants.COMMENT_PROPERTY_EDITED, false));
json.put(JSON_REPLIES, commentService.numberOfReplies(comment));
json.put(JSON_SPAM, properties.get(PublickConstants.COMMENT_PROPERTY_SPAM, false));
json.put(JSON_POST, new JSONObject()
.put(JSON_POST_TEXT, post.getValueMap().get(PublickConstants.COMMENT_PROPERTY_TITLE, String.class))
.put(JSON_POST_LINK, linkRewriter.rewriteLink(post.getPath(), request.getServerName())));
jsonArray.put(json);
}
response.setStatus(SlingHttpServletResponse.SC_OK);
writer.write(jsonArray.toString());
} catch (JSONException e) {
LOGGER.error("Could not write JSON", e);
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
示例14: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Return all packages on a GET request in order of newest to oldest.
*/
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
List<JcrPackage> packages = packageService.getPackageList(request);
try {
JSONArray jsonArray = new JSONArray();
for (JcrPackage jcrPackage : packages) {
final JSONObject json = getJsonFromJcrPackage(jcrPackage);
jsonArray.put(json);
}
response.setStatus(SlingHttpServletResponse.SC_OK);
writer.write(jsonArray.toString());
} catch (JSONException | RepositoryException e) {
LOGGER.error("Could not write JSON", e);
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
示例15: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Save system properties on POST.
*
* @param request The Sling HTTP servlet request.
* @param response The Sling HTTP servlet response.
*/
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
final boolean allowWrite = userService.isAuthorable(request.getResourceResolver().adaptTo(Session.class));
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
if (allowWrite) {
final String blogName = request.getParameter(BLOG_NAME_PROPERTY);
final boolean extensionlessUrls = Boolean.parseBoolean(request.getParameter(EXTENSIONLESS_URLS_PROPERTY));
final String tempDir = request.getParameter(TEMPORARY_DIRECTORY_PROPERTY);
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(SystemSettingsService.SYSTEM_BLOG_NAME, blogName);
properties.put(SystemSettingsService.SYSTEM_EXTENSIONLESS_URLS, extensionlessUrls);
properties.put(SystemSettingsService.SYSTEM_TEMPORARY_DIRECTORY, tempDir);
boolean result = systemSettingsService.setProperties(properties);
if (result) {
response.setStatus(SlingHttpServletResponse.SC_OK);
sendResponse(writer, "OK", "Settings successfully updated.");
} else {
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
sendResponse(writer, "Error", "Settings failed to update.");
}
} else {
response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);
sendResponse(writer, "Error", "Current user not authorized.");
}
}