Search in sources :

Example 1 with GWTRenderResult

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;
}
Also used : JCRNodeWrapper(org.jahia.services.content.JCRNodeWrapper) AccessDeniedException(javax.jcr.AccessDeniedException) GWTStaticAssetEntry(org.jahia.ajax.gwt.client.data.GWTStaticAssetEntry) RenderException(org.jahia.services.render.RenderException) JCRSiteNode(org.jahia.services.content.decorator.JCRSiteNode) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) RenderContext(org.jahia.services.render.RenderContext) GWTRenderResult(org.jahia.ajax.gwt.client.data.GWTRenderResult) GWTStaticAssetEntry(org.jahia.ajax.gwt.client.data.GWTStaticAssetEntry) Channel(org.jahia.services.channels.Channel) Resource(org.jahia.services.render.Resource) RepositoryException(javax.jcr.RepositoryException) GWTJahiaServiceException(org.jahia.ajax.gwt.client.service.GWTJahiaServiceException) EditConfiguration(org.jahia.services.uicomponents.bean.editmode.EditConfiguration) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 2 with GWTRenderResult

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);
    }
}
Also used : PropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor) GWTRenderResult(org.jahia.ajax.gwt.client.data.GWTRenderResult) ComboBox(com.extjs.gxt.ui.client.widget.form.ComboBox) HTML(com.google.gwt.user.client.ui.HTML) FillLayout(com.extjs.gxt.ui.client.widget.layout.FillLayout) EditLinker(org.jahia.ajax.gwt.client.widget.edit.EditLinker) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) List(java.util.List) GWTJahiaValueDisplayBean(org.jahia.ajax.gwt.client.data.GWTJahiaValueDisplayBean) HashMap(java.util.HashMap) Map(java.util.Map) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 3 with GWTRenderResult

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;
}
Also used : VBoxLayout(com.extjs.gxt.ui.client.widget.layout.VBoxLayout) VBoxLayoutData(com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) Comparator(java.util.Comparator) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) GWTRenderResult(org.jahia.ajax.gwt.client.data.GWTRenderResult) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) CanUseComponentForEditCallback(org.jahia.ajax.gwt.client.widget.edit.mainarea.ModuleHelper.CanUseComponentForEditCallback) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer)

Example 4 with GWTRenderResult

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;
}
Also used : GridEvent(com.extjs.gxt.ui.client.event.GridEvent) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) BaseListLoader(com.extjs.gxt.ui.client.data.BaseListLoader) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) BaseAsyncCallback(org.jahia.ajax.gwt.client.core.BaseAsyncCallback) CenterLayout(com.extjs.gxt.ui.client.widget.layout.CenterLayout) ArrayList(java.util.ArrayList) List(java.util.List) Window(com.extjs.gxt.ui.client.widget.Window) GWTRenderResult(org.jahia.ajax.gwt.client.data.GWTRenderResult) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) com.extjs.gxt.ui.client.widget.grid(com.extjs.gxt.ui.client.widget.grid) GWTJahiaNodeUsage(org.jahia.ajax.gwt.client.data.node.GWTJahiaNodeUsage)

Aggregations

GWTRenderResult (org.jahia.ajax.gwt.client.data.GWTRenderResult)4 HTML (com.google.gwt.user.client.ui.HTML)3 BaseAsyncCallback (org.jahia.ajax.gwt.client.core.BaseAsyncCallback)3 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)2 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)2 BaseListLoader (com.extjs.gxt.ui.client.data.BaseListLoader)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 GridEvent (com.extjs.gxt.ui.client.event.GridEvent)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 Window (com.extjs.gxt.ui.client.widget.Window)1 ComboBox (com.extjs.gxt.ui.client.widget.form.ComboBox)1 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)1 com.extjs.gxt.ui.client.widget.grid (com.extjs.gxt.ui.client.widget.grid)1 CenterLayout (com.extjs.gxt.ui.client.widget.layout.CenterLayout)1 FillLayout (com.extjs.gxt.ui.client.widget.layout.FillLayout)1 VBoxLayout (com.extjs.gxt.ui.client.widget.layout.VBoxLayout)1 VBoxLayoutData (com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData)1