use of org.jahia.ajax.gwt.client.data.GWTRenderResult in project jahia by Jahia.
the class TemplateHelper method getRenderedContent.
/**
* Get rendered content
*
* @param path
* @param template
* @param configuration
* @param contextParams
* @param editMode
* @param configName
* @param request
* @param response
* @param currentUserSession
* @param uiLocale
* @param channelIdentifier
* @param channelVariant
*/
public GWTRenderResult getRenderedContent(String path, String template, String configuration, final Map<String, List<String>> contextParams, boolean editMode, String configName, HttpServletRequest request, HttpServletResponse response, JCRSessionWrapper currentUserSession, Locale uiLocale, String channelIdentifier, String channelVariant) 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);
if ("contributemode".equals(configName)) {
renderContext.setContributionMode(true);
}
renderContext.setMainResource(r);
EditConfiguration editConfiguration = null;
if (configName != null) {
editConfiguration = (EditConfiguration) SpringContextSingleton.getBean(configName);
}
renderContext.setEditModeConfig(editConfiguration);
String permission = null;
if (editConfiguration != null) {
permission = editConfiguration.getRequiredPermission();
renderContext.setServletPath(editConfiguration.getDefaultUrlMapping());
} else {
renderContext.setServletPath(Render.getRenderServletPath());
}
if (permission != null) {
if (!node.getResolveSite().hasPermission(permission)) {
throw new GWTJahiaServiceException(Messages.getInternal("label.gwt.error.access.denied", uiLocale));
}
}
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);
if (channelIdentifier != null) {
Channel activeChannel = channelService.getChannel(channelIdentifier);
if (activeChannel != null) {
renderContext.setChannel(activeChannel);
}
}
response.setCharacterEncoding(SettingsBean.getInstance().getCharacterEncoding());
String res = renderService.render(r, renderContext);
Map<String, Map<String, Map<String, String>>> map = (Map<String, Map<String, Map<String, String>>>) renderContext.getRequest().getAttribute("staticAssets");
String constraints = ConstraintsHelper.getConstraints(node);
if (constraints == null) {
constraints = "";
}
Map<String, List<GWTStaticAssetEntry>> m = new HashMap<String, List<GWTStaticAssetEntry>>();
if (map != null) {
for (Map.Entry<String, Map<String, Map<String, String>>> entry : map.entrySet()) {
List<GWTStaticAssetEntry> fileEntries = new ArrayList<GWTStaticAssetEntry>();
for (Map.Entry<String, Map<String, String>> filetypeEntries : entry.getValue().entrySet()) {
String filePath = filetypeEntries.getKey();
Map<String, String> fileOptions = filetypeEntries.getValue();
fileEntries.add(new GWTStaticAssetEntry(filePath, fileOptions));
}
m.put(entry.getKey(), fileEntries);
}
}
result = new GWTRenderResult(res, m, constraints, node.getDisplayableName());
} catch (PathNotFoundException e) {
throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.not.found.for.user", uiLocale, path, currentUserSession.getUser().getName()));
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.repository.exception.on.path", uiLocale, path));
} catch (RenderException e) {
if (e.getCause() instanceof AccessDeniedException) {
throw new GWTJahiaServiceException(Messages.getInternal("label.gwt.error.access.denied", uiLocale));
} else {
logger.error(e.getMessage(), e);
throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.render.exception", uiLocale, e.getMessage()));
}
}
return result;
}
use of org.jahia.ajax.gwt.client.data.GWTRenderResult in project jahia by Jahia.
the class LayoutTabItem method attachPropertiesEditor.
@Override
public void attachPropertiesEditor(final NodeHolder engine, final AsyncTabItem tab) {
if (engine.getNode() != null && engine.getLinker() instanceof EditLinker) {
final PropertiesEditor.PropertyAdapterField templateField = propertiesEditor.getFieldsMap().get("j:view");
final PropertiesEditor.PropertyAdapterField skinField = propertiesEditor.getFieldsMap().get("j:skin");
final PropertiesEditor.PropertyAdapterField subNodesViewField = propertiesEditor.getFieldsMap().get("j:subNodesView");
listener = new SelectionChangedListener<GWTJahiaValueDisplayBean>() {
public void selectionChanged(SelectionChangedEvent<GWTJahiaValueDisplayBean> se) {
Map<String, List<String>> contextParams = new HashMap<String, List<String>>();
if (skinField != null && skinField.getValue() != null) {
contextParams.put("forcedSkin", Arrays.asList(((ComboBox<GWTJahiaValueDisplayBean>) skinField.getField()).getValue().getValue()));
}
if (subNodesViewField != null && subNodesViewField.getValue() != null) {
contextParams.put("forcedSubNodesTemplate", Arrays.asList(((ComboBox<GWTJahiaValueDisplayBean>) subNodesViewField.getField()).getValue().getValue()));
}
String template = (templateField != null && templateField.getValue() != null) ? ((ComboBox<GWTJahiaValueDisplayBean>) templateField.getField()).getValue().getValue() : null;
if (engine.getNode() != null) {
JahiaContentManagementService.App.getInstance().getRenderedContent(engine.getNode().getPath(), null, LayoutTabItem.this.language, template, "preview", contextParams, false, null, null, null, new BaseAsyncCallback<GWTRenderResult>() {
public void onSuccess(GWTRenderResult result) {
HTML html = new HTML(result.getResult());
setHTML(html);
tab.layout();
}
});
} else {
setHTML(null);
}
}
};
if (templateField != null) {
((ComboBox<GWTJahiaValueDisplayBean>) templateField.getField()).addSelectionChangedListener(listener);
}
if (skinField != null) {
((ComboBox<GWTJahiaValueDisplayBean>) skinField.getField()).addSelectionChangedListener(listener);
}
if (subNodesViewField != null) {
((ComboBox<GWTJahiaValueDisplayBean>) subNodesViewField.getField()).addSelectionChangedListener(listener);
}
tab.setLayout(new FillLayout());
if (ctn == null) {
ctn = new LayoutContainer(new FitLayout());
tab.add(ctn);
htmlPreview = new LayoutContainer();
htmlPreview.addStyleName(cssWrapper);
htmlPreview.setStyleAttribute("background-color", "white");
FieldSet f = new FieldSet();
f.addStyleName("x-panel");
f.setHeadingHtml(Messages.get("label.preview", "Preview"));
f.setScrollMode(Style.Scroll.AUTO);
f.add(htmlPreview);
tab.add(f);
}
ctn.add(propertiesEditor);
} else {
super.attachPropertiesEditor(engine, tab);
}
}
use of org.jahia.ajax.gwt.client.data.GWTRenderResult in project jahia by Jahia.
the class LastContentBrowseTabItem method create.
@Override
public TabItem create(final GWTSidePanelTab config) {
super.create(config);
tab.addListener(Events.Select, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
fillStore();
tab.removeListener(Events.Select, this);
}
});
VBoxLayout l = new VBoxLayout();
l.setVBoxLayoutAlign(VBoxLayout.VBoxLayoutAlign.STRETCH);
tab.setLayout(l);
contentContainer = new LayoutContainer();
contentContainer.setBorders(true);
contentContainer.setScrollMode(Style.Scroll.AUTO);
contentContainer.setLayout(new FitLayout());
contentStore = new ListStore<GWTJahiaNode>();
contentStore.setStoreSorter(new StoreSorter<GWTJahiaNode>(new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
if (o1 instanceof String && o2 instanceof String) {
String s1 = (String) o1;
String s2 = (String) o2;
return Collator.getInstance().localeCompare(s1, s2);
} else if (o1 instanceof Comparable && o2 instanceof Comparable) {
return ((Comparable) o1).compareTo(o2);
}
return 0;
}
}));
List<ColumnConfig> displayColumns = new ArrayList<ColumnConfig>();
ColumnConfig col = new ColumnConfig("icon", "", 40);
col.setAlignment(Style.HorizontalAlignment.CENTER);
col.setRenderer(new GridCellRenderer<GWTJahiaNode>() {
@Override
public String render(GWTJahiaNode modelData, String s, ColumnData columnData, int i, int i1, ListStore<GWTJahiaNode> listStore, Grid<GWTJahiaNode> g) {
return ContentModelIconProvider.getInstance().getIcon(modelData).getHTML();
}
});
displayColumns.add(col);
col = new ColumnConfig("displayName", Messages.get("label.name"), 170);
col.setRenderer(NodeColumnConfigList.NAME_RENDERER);
displayColumns.add(col);
col = new ColumnConfig("jcr:lastModified", Messages.get("label.lastModif"), 100);
col.setDateTimeFormat(DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT));
displayColumns.add(col);
grid = new Grid<GWTJahiaNode>(contentStore, new ColumnModel(displayColumns));
contentContainer.add(grid);
grid.setContextMenu(createContextMenu(config.getTableContextMenu(), grid.getSelectionModel()));
grid.getStore().setMonitorChanges(true);
grid.setAutoExpandColumn("displayName");
previewLayoutContainer = new LayoutContainer();
previewLayoutContainer.setLayout(new FitLayout());
previewLayoutContainer.addStyleName(cssWrapper);
grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GWTJahiaNode>() {
@Override
public void selectionChanged(SelectionChangedEvent<GWTJahiaNode> evt) {
if (evt.getSelectedItem() != null) {
JahiaContentManagementService.App.getInstance().getRenderedContent(evt.getSelectedItem().getPath(), null, editLinker.getLocale(), "default", "preview", null, true, "editmode", editLinker.getActiveChannelIdentifier(), null, new BaseAsyncCallback<GWTRenderResult>() {
@Override
public void onSuccess(GWTRenderResult gwtRenderResult) {
previewLayoutContainer.removeAll();
previewLayoutContainer.add(new HTML(gwtRenderResult.getResult()));
previewLayoutContainer.layout(true);
}
});
} else {
previewLayoutContainer.removeAll();
previewLayoutContainer.layout(true);
}
}
});
grid.addListener(Events.OnDoubleClick, new Listener<GridEvent<GWTJahiaNode>>() {
@Override
public void handleEvent(GridEvent<GWTJahiaNode> baseEvent) {
final GWTJahiaNode gwtJahiaNode = baseEvent.getModel();
if (gwtJahiaNode != null && editLinker != null) {
ModuleHelper.checkCanUseComponentForEdit(gwtJahiaNode.getNodeTypes().get(0), new CanUseComponentForEditCallback() {
@Override
public void handle(boolean canUseComponentForEdit) {
if (canUseComponentForEdit) {
EngineLoader.showEditEngine(editLinker, gwtJahiaNode, null);
}
}
});
}
}
});
VBoxLayoutData contentVBoxData = new VBoxLayoutData();
contentVBoxData.setFlex(2);
tab.add(contentContainer, contentVBoxData);
contentVBoxData.setFlex(1);
tab.add(previewLayoutContainer, contentVBoxData);
tab.setId("JahiaGxtLastContentBrowseTab");
return tab;
}
use of org.jahia.ajax.gwt.client.data.GWTRenderResult in project jahia by Jahia.
the class NodeUsagesGrid method createUsageGrid.
public static Grid<GWTJahiaNodeUsage> createUsageGrid(final List<GWTJahiaNode> nodes, final String baseUsageUrl) {
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
ColumnConfig col = new ColumnConfig("pagePath", Messages.get("label.pageUrl", "Page URL"), 200);
col.setRenderer(new GridCellRenderer<GWTJahiaNodeUsage>() {
@Override
public Object render(GWTJahiaNodeUsage gwtJahiaNodeUsage, String s, ColumnData columnData, int i, int i1, ListStore<GWTJahiaNodeUsage> gwtJahiaNodeUsageListStore, com.extjs.gxt.ui.client.widget.grid.Grid<GWTJahiaNodeUsage> gwtJahiaNodeUsageGrid) {
if (gwtJahiaNodeUsage.getLanguage() == null) {
return "<a href=\"" + baseUsageUrl + gwtJahiaNodeUsage.getPagePath() + ".html\" target=\"_blank\">" + gwtJahiaNodeUsage.getPageTitle() + "<a>";
} else {
return "<a href=\"" + baseUsageUrl + "/../" + gwtJahiaNodeUsage.getLanguage() + gwtJahiaNodeUsage.getPagePath() + ".html\" target=\"_blank\">" + gwtJahiaNodeUsage.getPageTitle() + " (" + gwtJahiaNodeUsage.getLanguage() + ")<a>";
}
}
});
columns.add(col);
col = new ColumnConfig("path", Messages.get("label.path", "URL"), 600);
columns.add(col);
ColumnModel cm = new ColumnModel(columns);
final ListStore<GWTJahiaNodeUsage> usageStore = new ListStore<GWTJahiaNodeUsage>(new BaseListLoader(new RpcProxy<List<GWTJahiaNodeUsage>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<List<GWTJahiaNodeUsage>> asyncCallback) {
List<String> paths = new ArrayList<String>();
for (GWTJahiaNode selectedNode : nodes) {
paths.add(selectedNode.getPath());
}
instance.getUsages(paths, new BaseAsyncCallback<List<GWTJahiaNodeUsage>>() {
@Override
public void onApplicationFailure(Throwable throwable) {
Log.debug("Cannot retrieve usages", throwable);
}
@Override
public void onSuccess(List<GWTJahiaNodeUsage> gwtJahiaNodeUsages) {
asyncCallback.onSuccess(gwtJahiaNodeUsages);
}
});
}
}));
final Grid<GWTJahiaNodeUsage> tbl = new Grid<GWTJahiaNodeUsage>(usageStore, cm);
tbl.addListener(Events.RowDoubleClick, new Listener<GridEvent<?>>() {
@Override
public void handleEvent(GridEvent<?> tableEvent) {
Object url = tableEvent.getModel().get("path");
if (url != null && url instanceof String) {
instance.getRenderedContent((String) url, null, JahiaGWTParameters.getUILanguage(), null, "module", null, false, null, null, null, new BaseAsyncCallback<GWTRenderResult>() {
@Override
public void onSuccess(GWTRenderResult result) {
HTML html = new HTML(result.getResult());
Window w = new Window();
w.addStyleName("node-usage-dblclick-preview");
w.setScrollMode(Style.Scroll.AUTO);
w.setModal(true);
w.setClosable(true);
w.setMaximizable(true);
w.setSize(800, 600);
w.setBlinkModal(true);
w.setPlain(true);
w.setLayout(new CenterLayout());
w.add(html);
w.show();
}
});
}
}
});
usageStore.getLoader().load();
return tbl;
}
Aggregations