final Map<String, List<String>> contextParams, boolean editMode, String configName,
HttpServletRequest request, HttpServletResponse response,
JCRSessionWrapper currentUserSession) throws GWTJahiaServiceException {
GWTRenderResult result = null;
try {
JCRNodeWrapper node = currentUserSession.getNode(path);
Resource r = new Resource(node, "html", template, configuration);
request.setAttribute("mode", "edit");
request = new HttpServletRequestWrapper(request) {
@Override
public String getParameter(String name) {
if (contextParams != null && contextParams.containsKey(name)) {
return contextParams.get(name).get(0);
}
return super.getParameter(name);
}
@Override
public Map getParameterMap() {
Map r = new HashMap(super.getParameterMap());
if (contextParams != null) {
for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
r.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
}
}
return r;
}
@Override
public Enumeration getParameterNames() {
return new Vector(getParameterMap().keySet()).elements();
}
@Override
public String[] getParameterValues(String name) {
if (contextParams != null && contextParams.containsKey(name)) {
List<String> list = contextParams.get(name);
return list.toArray(new String[list.size()]);
}
return super.getParameterValues(name);
}
};
RenderContext renderContext = new RenderContext(request, response, currentUserSession.getUser());
renderContext.setEditMode(editMode);
renderContext.setEditModeConfigName(configName);
renderContext.setMainResource(r);
String permission = null;
if (Edit.EDIT_MODE.equals(configName)) {
renderContext.setServletPath(Edit.getEditServletPath());
permission = "editModeAccess";
} else if (Studio.STUDIO_MODE.equals(configName)) {
renderContext.setServletPath(Studio.getStudioServletPath());
permission = "studioModeAccess";
} else {
renderContext.setServletPath(Render.getRenderServletPath());
}
if (permission != null) {
if (!node.hasPermission(permission)) {
throw new GWTJahiaServiceException("Access denied");
}
}
if (contextParams != null) {
for (Map.Entry<String, List<String>> entry : contextParams.entrySet()) {
r.getModuleParams().put(entry.getKey(), entry.getValue().get(0));
}
}
JCRSiteNode site = node.getResolveSite();
renderContext.setSite(site);
String res = renderService.render(r, renderContext);
Map<String, Set<String>> map = (Map<String, Set<String>>) renderContext.getRequest().getAttribute("staticAssets");
String constraints = ConstraintsHelper.getConstraints(node);
if (constraints == null) {
constraints = "";
}
Map<String, List<String>> m = new HashMap<String, List<String>>();
if (map != null) {
for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
m.put(entry.getKey(), new ArrayList<String>(entry.getValue()));
}
}
result = new GWTRenderResult(res, m, constraints, node.getDisplayableName());
} catch (PathNotFoundException e) {
throw new GWTJahiaServiceException(path + " not found for user " + currentUserSession.getUser().getName());
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
throw new GWTJahiaServiceException("Repository exception on path " + path);