use of org.apache.sling.commons.json.JSONException in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImpl method getGetForm.
/**
* Derives the form from the request's Query Parameters as best it can
* <p>
* Falls back to an empty form if it runs into problems.
* Fallback is due to ease of (inadvertent) tampering with query params
*
* @param formName
* @param request
* @return
*/
protected Form getGetForm(final String formName, final SlingHttpServletRequest request, final SlingHttpServletResponse response) {
Map<String, String> data = new HashMap<String, String>();
Map<String, String> errors = new HashMap<String, String>();
final String requestData = getRawFormData(formName, request, response);
if (StringUtils.isBlank(requestData)) {
return new FormImpl(formName, request.getResource().getPath());
}
try {
final JSONObject jsonData = new JSONObject(requestData);
final String incomingFormName = jsonData.optString(KEY_FORM_NAME);
// Double-check the form names; only inject matching forms
if (StringUtils.equals(incomingFormName, formName)) {
final JSONObject incomingJsonForm = jsonData.optJSONObject(KEY_FORM);
if (incomingJsonForm != null) {
data = TypeUtil.toMap(incomingJsonForm, String.class);
log.debug("Form data: {}", data);
}
final JSONObject incomingJsonErrors = jsonData.optJSONObject(KEY_ERRORS);
if (incomingJsonErrors != null) {
errors = TypeUtil.toMap(incomingJsonErrors, String.class);
log.debug("Form data: {}", errors);
}
}
} catch (JSONException e) {
log.warn("Cannot parse query parameters for request: {}", requestData);
return new FormImpl(formName, request.getResource().getPath());
}
return new FormImpl(formName, request.getResource().getPath(), this.getProtectedData(data), this.getProtectedErrors(errors));
}
use of org.apache.sling.commons.json.JSONException in project acs-aem-commons by Adobe-Consulting-Services.
the class RTEConfigurationServlet method doGet.
@Override
@SuppressWarnings("squid:S3776")
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String componentPath = request.getResource().getPath();
String configName = PathInfoUtil.getSelector(request, 1, DEFAULT_CONFIG_NAME);
// the actual property name
String rteName = PathInfoUtil.getSelector(request, 2, "text");
Resource root = request.getResourceResolver().getResource(rootPath);
if (root != null) {
Iterator<Resource> children = root.listChildren();
while (children.hasNext()) {
Resource child = children.next();
if (matches(componentPath, child)) {
Resource config = child.getChild(configName);
if (config == null) {
config = child.getChild(DEFAULT_CONFIG_NAME);
}
if (config != null) {
try {
writeConfigResource(config, rteName, request, response);
} catch (JSONException e) {
throw new ServletException(e);
}
return;
}
}
}
}
returnDefault(rteName, request, response);
}
use of org.apache.sling.commons.json.JSONException in project acs-aem-commons by Adobe-Consulting-Services.
the class RTEConfigurationServlet method returnDefault.
private void returnDefault(String rteName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException {
response.setContentType("application/json");
try {
Resource root = request.getResourceResolver().getResource(DEFAULT_CONFIG);
if (root == null) {
writeEmptyWidget(rteName, response);
return;
}
writeConfigResource(root, rteName, request, response);
} catch (JSONException e) {
throw new ServletException(e);
}
}
use of org.apache.sling.commons.json.JSONException in project acs-aem-commons by Adobe-Consulting-Services.
the class TagWidgetConfigurationServlet method returnDefault.
private void returnDefault(String propertyName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException {
response.setContentType("application/json");
try {
Resource root = request.getResourceResolver().getResource(DEFAULT_CONFIG);
if (root == null) {
writeEmptyWidget(propertyName, response);
return;
}
writeConfigResource(root, propertyName, request, response);
} catch (JSONException e) {
throw new ServletException(e);
}
}
use of org.apache.sling.commons.json.JSONException in project acs-aem-commons by Adobe-Consulting-Services.
the class TagWidgetConfigurationServlet method doGet.
@Override
@SuppressWarnings("squid:S3776")
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String componentPath = request.getResource().getPath();
String configName = PathInfoUtil.getSelector(request, 1, DEFAULT_CONFIG_NAME);
// the actual property name
String propertyName = PathInfoUtil.getSelector(request, 2, "tags");
Resource root = request.getResourceResolver().getResource(rootPath);
if (root != null) {
Iterator<Resource> children = root.listChildren();
while (children.hasNext()) {
Resource child = children.next();
if (matches(componentPath, child)) {
Resource config = child.getChild(configName);
if (config == null) {
config = child.getChild(DEFAULT_CONFIG_NAME);
}
if (config != null) {
try {
writeConfigResource(config, propertyName, request, response);
} catch (JSONException e) {
throw new ServletException(e);
}
return;
}
}
}
}
returnDefault(propertyName, request, response);
}
Aggregations