use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_PropertyValuePatterns.
@Test
public void testNamePropertyUpdater_PropertyValuePatterns() throws Exception {
final Map<String, Object> config = new HashMap<String, Object>();
config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_VALUE_PATTERNS, new String[] { "^\\./.*" });
final CQIncludePropertyNamespaceServlet servlet = new CQIncludePropertyNamespaceServlet();
servlet.activate(config);
CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater visitor = servlet.new PropertyNamespaceUpdater("test");
final JSONObject json = new JSONObject();
json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
json.put("name", "./myValue");
json.put("fileName", "./image/myFile");
json.put("jcr:description", "words");
json.put("noDotSlash", "no dot slash");
visitor.accept(json);
assertEquals("./test/myValue", json.get("name"));
assertEquals("./test/image/myFile", json.get("fileName"));
assertEquals("words", json.get("jcr:description"));
assertEquals("no dot slash", json.get("noDotSlash"));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_MultiLevel.
@Test
public void testNamePropertyUpdater_MultiLevel() throws Exception {
final Map<String, Object> config = new HashMap<String, Object>();
config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_VALUE_PATTERNS, new String[] { "^\\./.*" });
config.put("namespace.multi-level", true);
final CQIncludePropertyNamespaceServlet servlet = new CQIncludePropertyNamespaceServlet();
servlet.activate(config);
CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater visitor = servlet.new PropertyNamespaceUpdater("test");
final JSONObject json = new JSONObject();
json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
json.put("xtype", "cqinclude");
json.put("path", "/apps/test.cqinclude.namespace.level-1.json");
visitor.accept(json);
assertEquals("/apps/test.cqinclude.namespace.test%252Flevel-1.json", json.get("path"));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class QrCodeServletTest method doGet.
@Test
public void doGet() throws Exception {
request.setResource(requestResource);
when(externalizer.publishLink(request.getResourceResolver(), "/content/externalize-me.html")).thenReturn("http://www.example.com/content/externalize-me.html");
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix("/content/externalize-me.html");
// requestPathInfo.setExtension("json");
qrCodeServlet.doGet(request, response);
JSONObject actual = new JSONObject(response.getOutputAsString());
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals(true, actual.getBoolean("enabled"));
assertEquals("http://www.example.com/content/externalize-me.html", actual.getString("publishURL"));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class QuicklyEngineImpl method getJSONResults.
private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws JSONException {
final JSONObject json = new JSONObject();
json.put(KEY_RESULTS, new JSONArray());
final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>());
// Collect all items collected from OSGi Properties
requestConfig.putAll(this.config);
// Add Request specific configurations
requestConfig.put(AuthoringUIMode.class.getName(), authoringUIModeService.getAuthoringUIMode(request));
for (final Result result : results) {
final JSONObject tmp = resultBuilder.toJSON(cmd, result, requestConfig);
if (tmp != null) {
json.accumulate(KEY_RESULTS, tmp);
}
}
return json;
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class QuicklyInitServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setHeader("Content-Type", " application/json; charset=UTF-8");
final JSONObject json = new JSONObject();
try {
json.put("user", request.getResourceResolver().getUserID());
json.put("throttle", 200);
response.getWriter().write(json.toString());
} catch (JSONException e) {
response.sendError(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().print("{\"status:\": \"error\"}");
}
}
Aggregations